@visactor/openinula-vtable 0.21.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -0
- package/cjs/components/base-component.d.ts +9 -0
- package/cjs/components/base-component.js +54 -0
- package/cjs/components/base-component.js.map +1 -0
- package/cjs/components/component/menu.d.ts +9 -0
- package/cjs/components/component/menu.js +10 -0
- package/cjs/components/component/menu.js.map +1 -0
- package/cjs/components/component/tooltip.d.ts +7 -0
- package/cjs/components/component/tooltip.js +10 -0
- package/cjs/components/component/tooltip.js.map +1 -0
- package/cjs/components/index.js +79 -0
- package/cjs/components/index.js.map +1 -0
- package/cjs/components/list/list-column.d.ts +4 -0
- package/cjs/components/list/list-column.js +10 -0
- package/cjs/components/list/list-column.js.map +1 -0
- package/cjs/components/pivot/pivot-corner.d.ts +4 -0
- package/cjs/components/pivot/pivot-corner.js +10 -0
- package/cjs/components/pivot/pivot-corner.js.map +1 -0
- package/cjs/components/pivot/pivot-dimension.d.ts +6 -0
- package/cjs/components/pivot/pivot-dimension.js +11 -0
- package/cjs/components/pivot/pivot-dimension.js.map +1 -0
- package/cjs/components/pivot/pivot-header-title.d.ts +5 -0
- package/cjs/components/pivot/pivot-header-title.js +11 -0
- package/cjs/components/pivot/pivot-header-title.js.map +1 -0
- package/cjs/components/pivot/pivot-indicator.d.ts +4 -0
- package/cjs/components/pivot/pivot-indicator.js +10 -0
- package/cjs/components/pivot/pivot-indicator.js.map +1 -0
- package/cjs/constants.d.ts +1 -0
- package/cjs/constants.js +6 -0
- package/cjs/constants.js.map +1 -0
- package/cjs/containers/withContainer.js +64 -0
- package/cjs/containers/withContainer.js.map +1 -0
- package/cjs/context/table.d.ts +13 -0
- package/cjs/context/table.js +25 -0
- package/cjs/context/table.js.map +1 -0
- package/cjs/eventsUtils.d.ts +88 -0
- package/cjs/eventsUtils.js +72 -0
- package/cjs/eventsUtils.js.map +1 -0
- package/cjs/index.d.ts +5 -0
- package/cjs/index.js +38 -0
- package/cjs/index.js.map +1 -0
- package/cjs/tables/base-table.d.ts +21 -0
- package/cjs/tables/base-table.js +127 -0
- package/cjs/tables/base-table.js.map +1 -0
- package/cjs/tables/index.d.ts +3 -0
- package/cjs/tables/index.js +38 -0
- package/cjs/tables/index.js.map +1 -0
- package/cjs/tables/list-table.d.ts +9 -0
- package/cjs/tables/list-table.js +10 -0
- package/cjs/tables/list-table.js.map +1 -0
- package/cjs/tables/pivot-chart.d.ts +10 -0
- package/cjs/tables/pivot-chart.js +40 -0
- package/cjs/tables/pivot-chart.js.map +1 -0
- package/cjs/tables/pivot-table.d.ts +9 -0
- package/cjs/tables/pivot-table.js +10 -0
- package/cjs/tables/pivot-table.js.map +1 -0
- package/cjs/util.d.ts +9 -0
- package/cjs/util.js +75 -0
- package/cjs/util.js.map +1 -0
- package/es/components/base-component.d.ts +9 -0
- package/es/components/base-component.js +25 -0
- package/es/components/base-component.js.map +1 -0
- package/es/components/component/menu.d.ts +9 -0
- package/es/components/component/menu.js +4 -0
- package/es/components/component/menu.js.map +1 -0
- package/es/components/component/tooltip.d.ts +7 -0
- package/es/components/component/tooltip.js +4 -0
- package/es/components/component/tooltip.js.map +1 -0
- package/es/components/index.js +14 -0
- package/es/components/index.js.map +1 -0
- package/es/components/list/list-column.d.ts +4 -0
- package/es/components/list/list-column.js +4 -0
- package/es/components/list/list-column.js.map +1 -0
- package/es/components/pivot/pivot-corner.d.ts +4 -0
- package/es/components/pivot/pivot-corner.js +4 -0
- package/es/components/pivot/pivot-corner.js.map +1 -0
- package/es/components/pivot/pivot-dimension.d.ts +6 -0
- package/es/components/pivot/pivot-dimension.js +6 -0
- package/es/components/pivot/pivot-dimension.js.map +1 -0
- package/es/components/pivot/pivot-header-title.d.ts +5 -0
- package/es/components/pivot/pivot-header-title.js +6 -0
- package/es/components/pivot/pivot-header-title.js.map +1 -0
- package/es/components/pivot/pivot-indicator.d.ts +4 -0
- package/es/components/pivot/pivot-indicator.js +4 -0
- package/es/components/pivot/pivot-indicator.js.map +1 -0
- package/es/constants.d.ts +1 -0
- package/es/constants.js +2 -0
- package/es/constants.js.map +1 -0
- package/es/containers/withContainer.js +33 -0
- package/es/containers/withContainer.js.map +1 -0
- package/es/context/table.d.ts +13 -0
- package/es/context/table.js +16 -0
- package/es/context/table.js.map +1 -0
- package/es/eventsUtils.d.ts +88 -0
- package/es/eventsUtils.js +65 -0
- package/es/eventsUtils.js.map +1 -0
- package/es/index.d.ts +5 -0
- package/es/index.js +10 -0
- package/es/index.js.map +1 -0
- package/es/tables/base-table.d.ts +21 -0
- package/es/tables/base-table.js +103 -0
- package/es/tables/base-table.js.map +1 -0
- package/es/tables/index.d.ts +3 -0
- package/es/tables/index.js +6 -0
- package/es/tables/index.js.map +1 -0
- package/es/tables/list-table.d.ts +9 -0
- package/es/tables/list-table.js +4 -0
- package/es/tables/list-table.js.map +1 -0
- package/es/tables/pivot-chart.d.ts +10 -0
- package/es/tables/pivot-chart.js +10 -0
- package/es/tables/pivot-chart.js.map +1 -0
- package/es/tables/pivot-table.d.ts +9 -0
- package/es/tables/pivot-table.js +4 -0
- package/es/tables/pivot-table.js.map +1 -0
- package/es/util.d.ts +9 -0
- package/es/util.js +33 -0
- package/es/util.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as VTable from '@visactor/vtable';
|
|
2
|
+
import type { ContainerProps } from '../containers/withContainer';
|
|
3
|
+
import type { EventsProps } from '../eventsUtils';
|
|
4
|
+
export type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;
|
|
5
|
+
export type IOption = VTable.ListTableConstructorOptions | VTable.PivotTableConstructorOptions | VTable.PivotChartConstructorOptions;
|
|
6
|
+
export interface BaseTableProps extends EventsProps {
|
|
7
|
+
type?: string;
|
|
8
|
+
container?: HTMLDivElement;
|
|
9
|
+
option?: any;
|
|
10
|
+
records?: Record<string, unknown>[];
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
skipFunctionDiff?: boolean;
|
|
14
|
+
onReady?: (instance: IVTable, isInitial: boolean) => void;
|
|
15
|
+
onError?: (err: Error) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare const createTable: <T extends React.PropsWithChildren<BaseTableProps>>(componentName: string, type?: string, callback?: (props: T) => T) => import("openinula").ExoticComponent<import("openinula").PropsOmitRef<T & ContainerProps>> & {
|
|
18
|
+
key?: import("openinula").Key;
|
|
19
|
+
} & {
|
|
20
|
+
ref?: import("openinula").Ref<any>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as VTable from "@visactor/vtable";
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect, useRef, useImperativeHandle, useCallback } from "openinula";
|
|
4
|
+
|
|
5
|
+
import withContainer from "../containers/withContainer";
|
|
6
|
+
|
|
7
|
+
import RootTableContext from "../context/table";
|
|
8
|
+
|
|
9
|
+
import { isEqual, isNil, pickWithout } from "@visactor/vutils";
|
|
10
|
+
|
|
11
|
+
import { toArray } from "../util";
|
|
12
|
+
|
|
13
|
+
import { REACT_PRIVATE_PROPS } from "../constants";
|
|
14
|
+
|
|
15
|
+
import { bindEventsToTable, TABLE_EVENTS_KEYS, TABLE_EVENTS } from "../eventsUtils";
|
|
16
|
+
|
|
17
|
+
const notOptionKeys = [ ...REACT_PRIVATE_PROPS, ...TABLE_EVENTS_KEYS, "skipFunctionDiff", "onError", "onReady", "option", "records", "container" ], getComponentId = (child, index) => `${child && child.type && (child.type.displayName || child.type.name)}-${index}`, parseOptionFromChildren = props => {
|
|
18
|
+
const optionFromChildren = {};
|
|
19
|
+
return toArray(props.children).map(((child, index) => {
|
|
20
|
+
const parseOption = child && child.type && child.type.parseOption;
|
|
21
|
+
if (parseOption && child.props) {
|
|
22
|
+
const optionResult = parseOption(isNil(child.props.componentId) ? Object.assign(Object.assign({}, child.props), {
|
|
23
|
+
componentId: getComponentId(child, index)
|
|
24
|
+
}) : child.props);
|
|
25
|
+
optionResult.isSingle ? optionFromChildren[optionResult.optionName] = optionResult.option : (optionFromChildren[optionResult.optionName] || (optionFromChildren[optionResult.optionName] = []),
|
|
26
|
+
optionFromChildren[optionResult.optionName].push(optionResult.option));
|
|
27
|
+
}
|
|
28
|
+
})), optionFromChildren;
|
|
29
|
+
}, BaseTable = React.forwardRef(((props, ref) => {
|
|
30
|
+
const [updateId, setUpdateId] = useState(0), tableContext = useRef({});
|
|
31
|
+
useImperativeHandle(ref, (() => {
|
|
32
|
+
var _a;
|
|
33
|
+
return null === (_a = tableContext.current) || void 0 === _a ? void 0 : _a.table;
|
|
34
|
+
}));
|
|
35
|
+
const hasOption = !!props.option, hasRecords = !!props.records, isUnmount = useRef(!1), prevOption = useRef(pickWithout(props, notOptionKeys)), optionFromChildren = useRef(null), prevRecords = useRef(props.records), eventsBinded = React.useRef(null), skipFunctionDiff = !!props.skipFunctionDiff, parseOption = useCallback((props => hasOption && props.option ? hasRecords && props.records ? Object.assign(Object.assign({}, props.option), {
|
|
36
|
+
records: props.records
|
|
37
|
+
}) : props.option : Object.assign(Object.assign({
|
|
38
|
+
records: props.records
|
|
39
|
+
}, prevOption.current), optionFromChildren.current)), [ hasOption, hasRecords ]), createTable = useCallback((props => {
|
|
40
|
+
let vtable;
|
|
41
|
+
vtable = "pivot-table" === props.type ? new VTable.PivotTable(props.container, parseOption(props)) : "pivot-chart" === props.type ? new VTable.PivotChart(props.container, parseOption(props)) : new VTable.ListTable(props.container, parseOption(props)),
|
|
42
|
+
tableContext.current = Object.assign(Object.assign({}, tableContext.current), {
|
|
43
|
+
table: vtable
|
|
44
|
+
}), isUnmount.current = !1;
|
|
45
|
+
}), [ parseOption ]), handleTableRender = useCallback((() => {
|
|
46
|
+
if (!isUnmount.current) {
|
|
47
|
+
if (!tableContext.current || !tableContext.current.table) return;
|
|
48
|
+
bindEventsToTable(tableContext.current.table, props, eventsBinded.current, TABLE_EVENTS),
|
|
49
|
+
setUpdateId(updateId + 1), props.onReady && props.onReady(tableContext.current.table, 0 === updateId);
|
|
50
|
+
}
|
|
51
|
+
}), [ updateId, setUpdateId, props ]), renderTable = useCallback((() => {
|
|
52
|
+
tableContext.current.table && (tableContext.current.table.render(), handleTableRender());
|
|
53
|
+
}), [ handleTableRender ]);
|
|
54
|
+
return useEffect((() => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const newOptionFromChildren = hasOption ? null : parseOptionFromChildren(props);
|
|
57
|
+
if (!(null === (_a = tableContext.current) || void 0 === _a ? void 0 : _a.table)) return hasOption || (optionFromChildren.current = newOptionFromChildren),
|
|
58
|
+
createTable(props), renderTable(), void (eventsBinded.current = props);
|
|
59
|
+
if (hasOption) return void (isEqual(eventsBinded.current.option, props.option, {
|
|
60
|
+
skipFunction: skipFunctionDiff
|
|
61
|
+
}) ? hasRecords && !isEqual(eventsBinded.current.records, props.records, {
|
|
62
|
+
skipFunction: skipFunctionDiff
|
|
63
|
+
}) && (eventsBinded.current = props, tableContext.current.table.setRecords(props.records, {
|
|
64
|
+
restoreHierarchyState: props.option.restoreHierarchyState
|
|
65
|
+
}), handleTableRender()) : (eventsBinded.current = props, tableContext.current.table.updateOption(parseOption(props)),
|
|
66
|
+
handleTableRender()));
|
|
67
|
+
const newOption = pickWithout(props, notOptionKeys);
|
|
68
|
+
isEqual(newOption, prevOption.current, {
|
|
69
|
+
skipFunction: skipFunctionDiff
|
|
70
|
+
}) && isEqual(newOptionFromChildren, optionFromChildren.current, {
|
|
71
|
+
skipFunction: skipFunctionDiff
|
|
72
|
+
}) ? hasRecords && !isEqual(props.records, prevRecords.current, {
|
|
73
|
+
skipFunction: skipFunctionDiff
|
|
74
|
+
}) && (prevRecords.current = props.records, tableContext.current.table.setRecords(props.records, {
|
|
75
|
+
restoreHierarchyState: null === (_b = props.option) || void 0 === _b ? void 0 : _b.restoreHierarchyState
|
|
76
|
+
}), handleTableRender()) : (prevOption.current = newOption, optionFromChildren.current = newOptionFromChildren,
|
|
77
|
+
tableContext.current.table.updateOption(parseOption(props)), handleTableRender());
|
|
78
|
+
}), [ createTable, hasOption, hasRecords, parseOption, handleTableRender, renderTable, skipFunctionDiff, props ]),
|
|
79
|
+
useEffect((() => () => {
|
|
80
|
+
tableContext && tableContext.current && tableContext.current.table && (tableContext.current.table.release(),
|
|
81
|
+
tableContext.current = null), eventsBinded.current = null, isUnmount.current = !0;
|
|
82
|
+
}), []), React.createElement(RootTableContext.Provider, {
|
|
83
|
+
value: tableContext.current
|
|
84
|
+
}, toArray(props.children).map(((child, index) => {
|
|
85
|
+
if ("string" == typeof child) return;
|
|
86
|
+
const childId = getComponentId(child, index);
|
|
87
|
+
return React.createElement(React.Fragment, {
|
|
88
|
+
key: childId
|
|
89
|
+
}, React.cloneElement(child, {
|
|
90
|
+
updateId: updateId,
|
|
91
|
+
componentId: childId
|
|
92
|
+
}));
|
|
93
|
+
})));
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
export const createTable = (componentName, type, callback) => {
|
|
97
|
+
const Com = withContainer(BaseTable, componentName, (props => (props.type = type,
|
|
98
|
+
callback ? callback(props) : type ? Object.assign(Object.assign({}, props), {
|
|
99
|
+
type: type
|
|
100
|
+
}) : props)));
|
|
101
|
+
return Com.displayName = componentName, Com;
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=base-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["tables/base-table.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEjG,OAAO,aAAa,MAAM,6BAA6B,CAAC;AAExD,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,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,EAAE;YACtF,QAAQ,EAAE,QAAQ;YAClB,WAAW,EAAE,OAAO;SACrB,CAAC,CACa,CAClB,CAAC;IACJ,CAAC,CAAC,CACwB,CAC7B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAkB,aAAqB,EAAE,IAAa,EAAE,QAA0B,EAAE,EAAE;IAC/G,MAAM,GAAG,GAAG,aAAa,CAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAQ,EAAE,EAAE;QACzF,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAElB,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;SACxB;QAED,IAAI,IAAI,EAAE;YACR,uCAAY,KAAK,KAAE,IAAI,IAAG;SAC3B;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","file":"base-table.js","sourcesContent":["/* eslint-disable react/display-name */\nimport * as VTable from '@visactor/vtable';\nimport React, { useState, useEffect, useRef, useImperativeHandle, useCallback } from 'openinula';\nimport type { ContainerProps } from '../containers/withContainer';\nimport withContainer from '../containers/withContainer';\nimport type { TableContextType } from '../context/table';\nimport RootTableContext from '../context/table';\nimport { isEqual, isNil, pickWithout } from '@visactor/vutils';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport type { IMarkElement } from '../components';\nimport type {\n EventsProps\n // LegendEventProps,\n // ScrollBarEventProps,\n // BrushEventProps,\n // DataZoomEventProps,\n // PlayerEventProps,\n // DimensionEventProps,\n // HierarchyEventProps,\n // TableLifeCycleEventProps\n} from '../eventsUtils';\nimport { bindEventsToTable, TABLE_EVENTS_KEYS, TABLE_EVENTS } from '../eventsUtils';\n\nexport type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\nexport type IOption =\n | VTable.ListTableConstructorOptions\n | VTable.PivotTableConstructorOptions\n | VTable.PivotChartConstructorOptions;\n\nexport interface BaseTableProps extends EventsProps {\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /** option */\n option?: any;\n /** 数据 */\n records?: Record<string, unknown>[];\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n skipFunctionDiff?: boolean;\n\n /** 表格渲染完成事件 */\n onReady?: (instance: IVTable, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseTableProps>;\n\nconst notOptionKeys = [\n ...REACT_PRIVATE_PROPS,\n ...TABLE_EVENTS_KEYS,\n 'skipFunctionDiff',\n 'onError',\n 'onReady',\n 'option',\n 'records',\n 'container'\n];\n\nconst getComponentId = (child: React.ReactNode, index: number) => {\n const componentName = child && (child as any).type && ((child as any).type.displayName || (child as any).type.name);\n return `${componentName}-${index}`;\n};\n\nconst parseOptionFromChildren = (props: Props) => {\n const optionFromChildren: Omit<IOption, 'type' | 'data' | 'width' | 'height'> = {};\n\n toArray(props.children).map((child, index) => {\n const parseOption = child && (child as any).type && (child as any).type.parseOption;\n\n if (parseOption && (child as any).props) {\n const childProps = isNil((child as any).props.componentId)\n ? {\n ...(child as any).props,\n componentId: getComponentId(child, index)\n }\n : (child as any).props;\n\n const optionResult = parseOption(childProps);\n\n if (optionResult.isSingle) {\n optionFromChildren[optionResult.optionName] = optionResult.option;\n } else {\n if (!optionFromChildren[optionResult.optionName]) {\n optionFromChildren[optionResult.optionName] = [];\n }\n\n optionFromChildren[optionResult.optionName].push(optionResult.option);\n }\n }\n });\n\n return optionFromChildren;\n};\n\nconst BaseTable: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const tableContext = useRef<TableContextType>({});\n useImperativeHandle(ref, () => tableContext.current?.table);\n const hasOption = !!props.option;\n const hasRecords = !!props.records;\n const isUnmount = useRef<boolean>(false);\n const prevOption = useRef(pickWithout(props, notOptionKeys));\n const optionFromChildren = useRef<Omit<IOption, 'records'>>(null);\n const prevRecords = useRef(props.records);\n const eventsBinded = React.useRef<BaseTableProps>(null);\n const skipFunctionDiff = !!props.skipFunctionDiff;\n\n const parseOption = useCallback(\n (props: Props) => {\n if (hasOption && props.option) {\n if (hasRecords && props.records) {\n return {\n ...props.option,\n records: props.records\n };\n }\n return props.option;\n }\n return {\n records: props.records,\n ...prevOption.current,\n ...optionFromChildren.current\n // ...tableContext.current?.optionFromChildren\n } as IOption;\n },\n [hasOption, hasRecords]\n );\n\n const createTable = useCallback(\n (props: Props) => {\n let vtable;\n if (props.type === 'pivot-table') {\n vtable = new VTable.PivotTable(props.container, parseOption(props));\n } else if (props.type === 'pivot-chart') {\n vtable = new VTable.PivotChart(props.container, parseOption(props));\n } else {\n vtable = new VTable.ListTable(props.container, parseOption(props));\n }\n tableContext.current = { ...tableContext.current, table: vtable };\n isUnmount.current = false;\n },\n [parseOption]\n );\n\n const handleTableRender = useCallback(() => {\n if (!isUnmount.current) {\n if (!tableContext.current || !tableContext.current.table) {\n return;\n }\n // rebind events after render\n bindEventsToTable(tableContext.current.table, props, eventsBinded.current, TABLE_EVENTS);\n\n // to be fixed\n // will cause another useEffect\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(tableContext.current.table, updateId === 0);\n }\n }\n }, [updateId, setUpdateId, props]);\n\n const renderTable = useCallback(() => {\n if (tableContext.current.table) {\n // eslint-disable-next-line promise/catch-or-return\n tableContext.current.table.render();\n handleTableRender();\n }\n }, [handleTableRender]);\n\n useEffect(() => {\n const newOptionFromChildren = hasOption ? null : parseOptionFromChildren(props);\n\n if (!tableContext.current?.table) {\n if (!hasOption) {\n optionFromChildren.current = newOptionFromChildren;\n }\n\n createTable(props);\n renderTable();\n // bindEventsToTable(tableContext.current.table, props, null, TABLE_EVENTS);\n // tableContext.current = {\n // ...tableContext.current,\n // isChildrenUpdated: false\n // };\n eventsBinded.current = props;\n return;\n }\n\n if (hasOption) {\n if (!isEqual(eventsBinded.current.option, props.option, { skipFunction: skipFunctionDiff })) {\n eventsBinded.current = props;\n // eslint-disable-next-line promise/catch-or-return\n tableContext.current.table.updateOption(parseOption(props));\n handleTableRender();\n } else if (\n hasRecords &&\n !isEqual(eventsBinded.current.records, props.records, { skipFunction: skipFunctionDiff })\n ) {\n eventsBinded.current = props;\n tableContext.current.table.setRecords(props.records as any[], {\n restoreHierarchyState: props.option.restoreHierarchyState\n });\n handleTableRender();\n }\n return;\n }\n\n const newOption = pickWithout(props, notOptionKeys);\n\n if (\n !isEqual(newOption, prevOption.current, { skipFunction: skipFunctionDiff }) ||\n // tableContext.current.isChildrenUpdated\n !isEqual(newOptionFromChildren, optionFromChildren.current, { skipFunction: skipFunctionDiff })\n ) {\n prevOption.current = newOption;\n optionFromChildren.current = newOptionFromChildren;\n\n // eslint-disable-next-line promise/catch-or-return\n tableContext.current.table.updateOption(parseOption(props));\n handleTableRender();\n } else if (hasRecords && !isEqual(props.records, prevRecords.current, { skipFunction: skipFunctionDiff })) {\n prevRecords.current = props.records;\n tableContext.current.table.setRecords(props.records, {\n restoreHierarchyState: props.option?.restoreHierarchyState\n });\n handleTableRender();\n }\n // tableContext.current = {\n // ...tableContext.current,\n // isChildrenUpdated: false\n // };\n }, [createTable, hasOption, hasRecords, parseOption, handleTableRender, renderTable, skipFunctionDiff, props]);\n\n useEffect(() => {\n return () => {\n if (tableContext) {\n if (tableContext.current && tableContext.current.table) {\n tableContext.current.table.release();\n tableContext.current = null;\n }\n }\n eventsBinded.current = null;\n isUnmount.current = true;\n };\n }, []);\n\n return (\n <RootTableContext.Provider value={tableContext.current}>\n {toArray(props.children).map((child: React.ReactNode, index: number) => {\n if (typeof child === 'string') {\n return;\n }\n\n const childId = getComponentId(child, index);\n\n // const componentName =\n // child && (child as any).type && ((child as any).type.displayName || (child as any).type.name);\n // const childId = `${componentName}-${index}`;\n\n return (\n // <React.Fragment key={(child as any)?.props?.id ?? (child as any)?.id ?? `child-${index}`}>\n // {React.cloneElement(child as IMarkElement, {\n // updateId: updateId\n // })}\n // </React.Fragment>\n <React.Fragment key={childId}>\n {React.cloneElement(child as React.ReactElement<any, React.JSXElementConstructor<any>>, {\n updateId: updateId,\n componentId: childId\n })}\n </React.Fragment>\n );\n })}\n </RootTableContext.Provider>\n );\n});\n\nexport const createTable = <T extends Props>(componentName: string, type?: string, callback?: (props: T) => T) => {\n const Com = withContainer<ContainerProps, T>(BaseTable as any, componentName, (props: T) => {\n props.type = type;\n\n if (callback) {\n return callback(props);\n }\n\n if (type) {\n return { ...props, type };\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["tables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC","file":"index.js","sourcesContent":["export { ListTable } from './list-table';\nexport { PivotTable } from './pivot-table';\nexport { PivotChart, registerChartModule } from './pivot-chart';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ListTableConstructorOptions } from '@visactor/vtable';
|
|
2
|
+
import type { BaseTableProps } from './base-table';
|
|
3
|
+
export interface ListTableProps extends Omit<BaseTableProps, 'records' | 'type'>, Omit<ListTableConstructorOptions, 'container'> {
|
|
4
|
+
}
|
|
5
|
+
export declare const ListTable: import("openinula").ExoticComponent<Omit<any, "ref">> & {
|
|
6
|
+
key?: import("openinula").Key;
|
|
7
|
+
} & {
|
|
8
|
+
ref?: import("openinula").Ref<any>;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["tables/list-table.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAA0C,WAAW,EAAE,YAAY,CAAC,CAAC","file":"list-table.js","sourcesContent":["// import type React from 'react';\nimport type React from 'openinula';\nimport type { ListTableConstructorOptions } from '@visactor/vtable';\nimport type { BaseTableProps } from './base-table';\nimport { createTable } from './base-table';\n\nexport interface ListTableProps\n extends Omit<BaseTableProps, 'records' | 'type'>,\n Omit<ListTableConstructorOptions, 'container'> {}\n\nexport const ListTable = createTable<React.PropsWithChildren<ListTableProps>>('ListTable', 'list-table');\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PivotChartConstructorOptions } from '@visactor/vtable';
|
|
2
|
+
import type { BaseTableProps } from './base-table';
|
|
3
|
+
export interface PivotChartProps extends Omit<BaseTableProps, 'records' | 'type'>, Omit<PivotChartConstructorOptions, 'container'> {
|
|
4
|
+
}
|
|
5
|
+
export declare const PivotChart: import("openinula").ExoticComponent<Omit<any, "ref">> & {
|
|
6
|
+
key?: import("openinula").Key;
|
|
7
|
+
} & {
|
|
8
|
+
ref?: import("openinula").Ref<any>;
|
|
9
|
+
};
|
|
10
|
+
export declare function registerChartModule(name: string, chart: any): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as VTable from "@visactor/vtable";
|
|
2
|
+
|
|
3
|
+
import { createTable } from "./base-table";
|
|
4
|
+
|
|
5
|
+
export const PivotChart = createTable("PivotChart", "pivot-chart");
|
|
6
|
+
|
|
7
|
+
export function registerChartModule(name, chart) {
|
|
8
|
+
VTable.register.chartModule(name, chart);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=pivot-chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["tables/pivot-chart.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAG3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAA2C,YAAY,EAAE,aAAa,CAAC,CAAC;AAE7G,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,KAAU;IAC1D,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC","file":"pivot-chart.js","sourcesContent":["// import type React from 'react';\nimport type React from 'openinula';\nimport * as VTable from '@visactor/vtable';\nimport type { PivotChartConstructorOptions } from '@visactor/vtable';\nimport type { BaseTableProps } from './base-table';\nimport { createTable } from './base-table';\n\nexport interface PivotChartProps\n extends Omit<BaseTableProps, 'records' | 'type'>,\n Omit<PivotChartConstructorOptions, 'container'> {}\n\nexport const PivotChart = createTable<React.PropsWithChildren<PivotChartProps>>('PivotChart', 'pivot-chart');\n\nexport function registerChartModule(name: string, chart: any) {\n VTable.register.chartModule(name, chart);\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PivotTableConstructorOptions } from '@visactor/vtable';
|
|
2
|
+
import type { BaseTableProps } from './base-table';
|
|
3
|
+
export interface PivotTableProps extends Omit<BaseTableProps, 'records' | 'type'>, Omit<PivotTableConstructorOptions, 'container'> {
|
|
4
|
+
}
|
|
5
|
+
export declare const PivotTable: import("openinula").ExoticComponent<Omit<any, "ref">> & {
|
|
6
|
+
key?: import("openinula").Key;
|
|
7
|
+
} & {
|
|
8
|
+
ref?: import("openinula").Ref<any>;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["tables/pivot-table.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAA2C,YAAY,EAAE,aAAa,CAAC,CAAC","file":"pivot-table.js","sourcesContent":["// import type React from 'react';\nimport type React from 'openinula';\nimport type { PivotTableConstructorOptions } from '@visactor/vtable';\nimport type { BaseTableProps } from './base-table';\nimport { createTable } from './base-table';\n\nexport interface PivotTableProps\n extends Omit<BaseTableProps, 'records' | 'type'>,\n Omit<PivotTableConstructorOptions, 'container'> {}\n\nexport const PivotTable = createTable<React.PropsWithChildren<PivotTableProps>>('PivotTable', 'pivot-table');\n"]}
|
package/es/util.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InulaElement, InulaPortal } from 'openinula';
|
|
2
|
+
type InulaNode = InulaElement | string | number | Iterable<InulaNode> | InulaPortal | boolean | null | undefined;
|
|
3
|
+
export declare const uid: (prefix?: string) => string;
|
|
4
|
+
export declare const getDisplayName: (Comp: any) => any;
|
|
5
|
+
export declare const typeOfComponent: (component: any, customTypeKey?: string) => string;
|
|
6
|
+
export declare const toArray: <T = InulaNode, TC = InulaNode>(children: T) => TC[];
|
|
7
|
+
export declare const findAllByType: <T extends InulaNode, TC = unknown>(children: InulaNode, type: TC | TC[]) => T[];
|
|
8
|
+
export declare const findChildByType: <T extends InulaNode, TC = unknown>(children: InulaNode, type: TC) => T;
|
|
9
|
+
export {};
|
package/es/util.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isNil, isArray } from "@visactor/vutils";
|
|
2
|
+
|
|
3
|
+
import Inula, { isFragment } from "openinula";
|
|
4
|
+
|
|
5
|
+
let id = 0;
|
|
6
|
+
|
|
7
|
+
export const uid = prefix => prefix ? `${prefix}-${id++}` : "" + id++;
|
|
8
|
+
|
|
9
|
+
export const getDisplayName = Comp => "string" == typeof Comp ? Comp : Comp ? Comp.displayName || Comp.name : "";
|
|
10
|
+
|
|
11
|
+
export const typeOfComponent = (component, customTypeKey = "__TYPE") => (null == component ? void 0 : component.props) && component.props[customTypeKey] || "string" == typeof (null == component ? void 0 : component.type) && component.type || (null == component ? void 0 : component.type) && "symbol" == typeof component.type && "Symbol(react.fragment)" === component.type.toString() && "react.fragment" || "function" == typeof (null == component ? void 0 : component.type) && component.type || "object" == typeof (null == component ? void 0 : component.type) && "Symbol(react.forward_ref)" === component.type.$$typeof.toString() && "react.forward_ref" || "string" == typeof component && "string" || "function" == typeof component && "function" || void 0;
|
|
12
|
+
|
|
13
|
+
export const toArray = children => {
|
|
14
|
+
let result = [];
|
|
15
|
+
return Inula.Children.forEach(children, (child => {
|
|
16
|
+
isNil(child) || (isFragment(child) ? result = result.concat(toArray(child.props.children)) : result.push(child));
|
|
17
|
+
})), result;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const findAllByType = (children, type) => {
|
|
21
|
+
const result = [];
|
|
22
|
+
let types = [];
|
|
23
|
+
return types = isArray(type) ? type.map((t => getDisplayName(t))) : [ getDisplayName(type) ],
|
|
24
|
+
toArray(children).forEach((child => {
|
|
25
|
+
const childType = getDisplayName(typeOfComponent(child));
|
|
26
|
+
-1 !== types.indexOf(childType) && result.push(child);
|
|
27
|
+
})), result;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const findChildByType = (children, type) => {
|
|
31
|
+
const result = findAllByType(children, type);
|
|
32
|
+
return null == result ? void 0 : result[0];
|
|
33
|
+
};
|
package/es/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAuC,MAAM,kBAAkB,CAAC;AAEvF,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAI9C,IAAI,EAAE,GAAG,CAAC,CAAC;AAEX,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,MAAe,EAAE,EAAE;IACrC,IAAI,MAAM,EAAE;QACV,OAAO,GAAG,MAAM,IAAI,EAAE,EAAE,EAAE,CAAC;KAC5B;IAED,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC;AACnB,CAAC,CAAC;AAOF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAS,EAAE,EAAE;IAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,CAAC;K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M,aAAN,MAAM,uBAAN,MAAM,CAAG,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC","file":"util.js","sourcesContent":["import { isNil, isArray, isString, isFunction, isPlainObject } from '@visactor/vutils';\nimport type { InulaElement, InulaPortal } from 'openinula';\nimport Inula, { isFragment } from 'openinula';\n\ntype InulaNode = InulaElement | string | number | Iterable<InulaNode> | InulaPortal | boolean | null | undefined;\n\nlet id = 0;\n\nexport const uid = (prefix?: string) => {\n if (prefix) {\n return `${prefix}-${id++}`;\n }\n\n return `${id++}`;\n};\n\n/**\n * Get the display name of a component\n * @param {Object} Comp Specified Component\n * @return {String} Display name of Component\n */\nexport const getDisplayName = (Comp: any) => {\n if (typeof Comp === 'string') {\n return Comp;\n }\n if (!Comp) {\n return '';\n }\n return Comp.displayName || Comp.name;\n};\n\nexport const typeOfComponent = (component: any, customTypeKey = '__TYPE'): string => {\n return (\n (component?.props && component.props[customTypeKey]) ||\n (typeof component?.type === 'string' && component.type) ||\n (component?.type &&\n typeof component.type === 'symbol' &&\n component.type.toString() === 'Symbol(react.fragment)' &&\n 'react.fragment') ||\n (typeof component?.type === 'function' && component.type) ||\n (typeof component?.type === 'object' &&\n component.type.$$typeof.toString() === 'Symbol(react.forward_ref)' &&\n 'react.forward_ref') ||\n (typeof component === 'string' && 'string') ||\n (typeof component === 'function' && 'function') ||\n undefined\n );\n};\n\nexport const toArray = <T = InulaNode, TC = InulaNode>(children: T): TC[] => {\n let result: TC[] = [];\n\n Inula.Children.forEach(children, child => {\n if (isNil(child)) {\n return;\n }\n\n if (isFragment(child)) {\n result = result.concat(toArray(child.props.children));\n } else {\n result.push(child as unknown as TC);\n }\n });\n\n return result;\n};\n\n/*\n * Find and return all matched children by type. `type` can be a React element class or\n * string\n */\nexport const findAllByType = <T extends InulaNode, TC = unknown>(children: InulaNode, type: TC | TC[]): T[] => {\n const result: T[] = [];\n let types: string[] = [];\n\n if (isArray(type)) {\n types = type.map(t => getDisplayName(t));\n } else {\n types = [getDisplayName(type)];\n }\n\n toArray(children).forEach(child => {\n const childType = getDisplayName(typeOfComponent(child));\n\n if (types.indexOf(childType) !== -1) {\n result.push(child as T);\n }\n });\n\n return result;\n};\n/*\n * Return the first matched child by type, return null otherwise.\n * `type` can be a React element class or string.\n */\nexport const findChildByType = <T extends InulaNode, TC = unknown>(children: InulaNode, type: TC): T => {\n const result = findAllByType<T, TC>(children, type);\n\n return result?.[0];\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@visactor/openinula-vtable",
|
|
3
|
+
"version": "0.21.3-alpha.1",
|
|
4
|
+
"description": "The openinula version of VTable",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openinula",
|
|
7
|
+
"grid",
|
|
8
|
+
"table",
|
|
9
|
+
"pivottable",
|
|
10
|
+
"visualization",
|
|
11
|
+
"VTable",
|
|
12
|
+
"VisActor",
|
|
13
|
+
"spreadsheet",
|
|
14
|
+
"canvas",
|
|
15
|
+
"datagrid",
|
|
16
|
+
"datatable"
|
|
17
|
+
],
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "VisActor",
|
|
20
|
+
"url": "https://VisActor.io/"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "cjs/index.js",
|
|
25
|
+
"module": "es/index.js",
|
|
26
|
+
"types": "es/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"cjs",
|
|
29
|
+
"es",
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"require": "./cjs/index.js",
|
|
35
|
+
"import": "./es/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"unpkg": "latest",
|
|
39
|
+
"unpkgFiles": [
|
|
40
|
+
"dist/openinula-vtable.js"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@visactor/vtable": "0.21.3-alpha.1",
|
|
47
|
+
"@visactor/vutils": "~0.18.1",
|
|
48
|
+
"openinula": "0.1.2-SNAPSHOT"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@visactor/vchart": "1.9.6",
|
|
52
|
+
"@rushstack/eslint-patch": "~1.1.4",
|
|
53
|
+
"eslint": "~8.18.0",
|
|
54
|
+
"vite": "3.2.6",
|
|
55
|
+
"typescript": "4.9.5",
|
|
56
|
+
"@babel/core": "7.20.12",
|
|
57
|
+
"@babel/preset-env": "7.20.2",
|
|
58
|
+
"@types/chai": "4.2.22",
|
|
59
|
+
"@types/jest": "^26.0.0",
|
|
60
|
+
"@types/mocha": "9.0.0",
|
|
61
|
+
"@types/node": "*",
|
|
62
|
+
"@types/offscreencanvas": "2019.6.4",
|
|
63
|
+
"chai": "4.3.4",
|
|
64
|
+
"jest": "^26.0.0",
|
|
65
|
+
"jest-electron": "^0.1.12",
|
|
66
|
+
"jest-transform-stub": "^2.0.0",
|
|
67
|
+
"magic-string": "^0.25.7",
|
|
68
|
+
"mocha": "9.1.3",
|
|
69
|
+
"postcss": "8.4.21",
|
|
70
|
+
"rimraf": "3.0.2",
|
|
71
|
+
"sass": "1.43.5",
|
|
72
|
+
"ts-jest": "^26.0.0",
|
|
73
|
+
"ts-loader": "9.2.6",
|
|
74
|
+
"ts-node": "10.9.0",
|
|
75
|
+
"tslib": "2.3.1",
|
|
76
|
+
"ttypescript": "1.5.13",
|
|
77
|
+
"typescript-transform-paths": "3.3.1",
|
|
78
|
+
"json-formatter-js": "^2.3.4",
|
|
79
|
+
"inversify": "6.0.1",
|
|
80
|
+
"vite-plugin-markdown": "^2.1.0",
|
|
81
|
+
"markdown-it": "^13.0.0",
|
|
82
|
+
"node-fetch": "2.6.7",
|
|
83
|
+
"form-data": "~4.0.0",
|
|
84
|
+
"axios": "^1.4.0",
|
|
85
|
+
"@internal/bundler": "0.0.1",
|
|
86
|
+
"@internal/eslint-config": "0.0.1",
|
|
87
|
+
"@internal/ts-config": "0.0.1"
|
|
88
|
+
},
|
|
89
|
+
"scripts": {
|
|
90
|
+
"start": "vite ./demo",
|
|
91
|
+
"build": "bundle --clean"
|
|
92
|
+
}
|
|
93
|
+
}
|