fix: types

This commit is contained in:
zyc9012 2022-03-29 23:18:37 +08:00
parent bdf4b3b1f3
commit 73f03301fd
6 changed files with 52 additions and 49 deletions

View File

@ -4,5 +4,5 @@ export * from "./settings";
export * from "./events";
export * from "./locale";
export * from "./modules";
export * from "./types.d";
export * from "./utils";
export * from "./types";

View File

@ -1,50 +1,50 @@
import { Sheet } from "./types";
export type Settings = {
column: number;
row: number;
allowCopy: boolean;
showtoolbar: boolean;
showinfobar: boolean;
showsheetbar: boolean;
showstatisticBar: boolean;
pointEdit: boolean;
pointEditUpdate: any;
pointEditZoom: number;
column?: number;
row?: number;
allowCopy?: boolean;
showtoolbar?: boolean;
showinfobar?: boolean;
showsheetbar?: boolean;
showstatisticBar?: boolean;
pointEdit?: boolean;
pointEditUpdate?: any;
pointEditZoom?: number;
data: Sheet[];
config: any;
fullscreenmode: boolean;
devicePixelRatio: number;
allowEdit: boolean;
allowUpdate: boolean;
showConfigWindowResize: boolean;
enableAddRow: boolean;
enableAddBackTop: boolean;
autoFormatw: boolean;
accuracy?: number | string;
editMode: boolean;
beforeCreateDom?: () => void;
fireMousedown: any;
lang: string;
plugins: string[];
forceCalculation: boolean;
rowHeaderWidth: number;
columnHeaderHeight: number;
defaultColWidth: number;
defaultRowHeight: number;
defaultFontSize: number;
limitSheetNameLength: boolean;
defaultSheetNameMaxLength: number;
sheetFormulaBar: boolean;
showtoolbarConfig: string[];
showsheetbarConfig: any;
showstatisticBarConfig: any;
cellRightClickConfig: string[];
sheetRightClickConfig: any;
imageUpdateMethodConfig: any;
config?: any;
fullscreenmode?: boolean;
devicePixelRatio?: number;
allowEdit?: boolean;
allowUpdate?: boolean;
showConfigWindowResize?: boolean;
enableAddRow?: boolean;
enableAddBackTop?: boolean;
autoFormatw?: boolean;
accuracy?: number | string | null;
editMode?: boolean;
beforeCreateDom?: (() => void) | null;
fireMousedown?: any;
lang?: string;
plugins?: string[];
forceCalculation?: boolean;
rowHeaderWidth?: number;
columnHeaderHeight?: number;
defaultColWidth?: number;
defaultRowHeight?: number;
defaultFontSize?: number;
limitSheetNameLength?: boolean;
defaultSheetNameMaxLength?: number;
sheetFormulaBar?: boolean;
showtoolbarConfig?: string[];
showsheetbarConfig?: any;
showstatisticBarConfig?: any;
cellRightClickConfig?: string[];
sheetRightClickConfig?: any;
imageUpdateMethodConfig?: any;
};
export const defaultSettings: Settings = {
export const defaultSettings: Required<Settings> = {
column: 60, // 空表格默认的列数量
row: 84, // 空表格默认的行数据量
allowCopy: true, // 是否允许拷贝
@ -65,9 +65,9 @@ export const defaultSettings: Settings = {
enableAddRow: true, // 允许添加行
enableAddBackTop: true, // 允许回到顶部
autoFormatw: false, // 自动格式化超过4位数的数字为 亿万格式 例true or "true" or "TRUE"
accuracy: undefined, // 设置传输来的数值的精确位数小数点后n位 传参数为数字或数字字符串,例: "0" 或 0
accuracy: null, // 设置传输来的数值的精确位数小数点后n位 传参数为数字或数字字符串,例: "0" 或 0
editMode: false, // 是否为编辑模式
beforeCreateDom: undefined, // 表格创建之前的方法
beforeCreateDom: null, // 表格创建之前的方法
fireMousedown: undefined, // 单元格数据下钻
lang: "en", // language
plugins: [], // plugins, e.g. ['chart']

View File

@ -36,7 +36,7 @@ export type Cell = {
export type CellWithRowAndCol = {
r: number;
c: number;
v: Cell;
v: Cell | null;
};
export type CellMatrix = (Cell | null)[][];

View File

@ -2,7 +2,7 @@
"name": "@fortune-sheet/react",
"version": "0.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "dist/src/index.d.ts",
"module": "dist/index.esm.js",
"files": [
"dist"

View File

@ -31,7 +31,7 @@ import ContextMenu from "../ContextMenu";
import SVGDefines from "../SVGDefines";
const Workbook: React.FC<
Settings & { onChange: (data: SheetType[]) => void }
Settings & { onChange?: (data: SheetType[]) => void }
> = ({ onChange, ...props }) => {
const [context, setContext] = useState(defaultContext());
const cellInput = useRef<HTMLDivElement>(null);
@ -41,7 +41,10 @@ const Workbook: React.FC<
const cellArea = useRef<HTMLDivElement>(null);
const workbookContainer = useRef<HTMLDivElement>(null);
const globalCache = useRef<GlobalCache>({});
const mergedSettings = useMemo(() => assign(defaultSettings, props), [props]);
const mergedSettings = useMemo(
() => assign(defaultSettings, props) as Required<Settings>,
[props]
);
const setContextValue = useCallback(
<K extends keyof Context>(key: K, value: Context[K]) => {
setContext(

View File

@ -22,7 +22,7 @@ const WorkbookContext = React.createContext<{
setContext: React.Dispatch<React.SetStateAction<Context>>;
// eslint-disable-next-line
setContextValue: <K extends keyof Context>(key: K, value: Context[K]) => void;
settings: Settings;
settings: Required<Settings>;
refs: RefValues;
}>({
context: defaultContext(),