@visactor/react-vtable 1.3.3-alpha.0 → 1.3.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/cjs/components/base-component.d.ts +0 -2
- package/cjs/components/base-component.js +8 -20
- package/cjs/components/base-component.js.map +1 -1
- package/cjs/components/index.d.ts +0 -3
- package/cjs/components/index.js +1 -25
- package/cjs/components/index.js.map +1 -1
- package/cjs/eventsUtils.js +2 -1
- package/cjs/index.d.ts +3 -2
- package/cjs/index.js +19 -4
- package/cjs/index.js.map +1 -1
- package/cjs/tables/base-table.d.ts +1 -2
- package/cjs/tables/base-table.js +5 -14
- package/cjs/tables/base-table.js.map +1 -1
- package/dist/react-vtable.js +110 -10081
- package/dist/react-vtable.min.js +3 -30
- package/es/components/base-component.d.ts +0 -2
- package/es/components/base-component.js +7 -21
- package/es/components/base-component.js.map +1 -1
- package/es/components/index.d.ts +0 -3
- package/es/components/index.js +0 -6
- package/es/components/index.js.map +1 -1
- package/es/eventsUtils.js +2 -1
- package/es/index.d.ts +3 -2
- package/es/index.js +4 -3
- package/es/index.js.map +1 -1
- package/es/tables/base-table.d.ts +1 -2
- package/es/tables/base-table.js +4 -17
- package/es/tables/base-table.js.map +1 -1
- package/package.json +6 -8
- package/cjs/components/custom/component.d.ts +0 -12
- package/cjs/components/custom/component.js +0 -6
- package/cjs/components/custom/component.js.map +0 -1
- package/cjs/components/custom/custom-layout.d.ts +0 -10
- package/cjs/components/custom/custom-layout.js +0 -96
- package/cjs/components/custom/custom-layout.js.map +0 -1
- package/cjs/components/custom/graphic.d.ts +0 -32
- package/cjs/components/custom/graphic.js +0 -9
- package/cjs/components/custom/graphic.js.map +0 -1
- package/cjs/components/custom/reconciler.d.ts +0 -5
- package/cjs/components/custom/reconciler.js +0 -105
- package/cjs/components/custom/reconciler.js.map +0 -1
- package/cjs/components/custom/vtable-browser-env-contribution.d.ts +0 -2
- package/cjs/components/custom/vtable-browser-env-contribution.js +0 -35
- package/cjs/components/custom/vtable-browser-env-contribution.js.map +0 -1
- package/cjs/components/custom/vtable-react-attribute-plugin.d.ts +0 -17
- package/cjs/components/custom/vtable-react-attribute-plugin.js +0 -92
- package/cjs/components/custom/vtable-react-attribute-plugin.js.map +0 -1
- package/cjs/vtable.d.ts +0 -2
- package/cjs/vtable.js +0 -35
- package/cjs/vtable.js.map +0 -1
- package/es/components/custom/component.d.ts +0 -12
- package/es/components/custom/component.js +0 -2
- package/es/components/custom/component.js.map +0 -1
- package/es/components/custom/custom-layout.d.ts +0 -10
- package/es/components/custom/custom-layout.js +0 -70
- package/es/components/custom/custom-layout.js.map +0 -1
- package/es/components/custom/graphic.d.ts +0 -32
- package/es/components/custom/graphic.js +0 -22
- package/es/components/custom/graphic.js.map +0 -1
- package/es/components/custom/reconciler.d.ts +0 -5
- package/es/components/custom/reconciler.js +0 -105
- package/es/components/custom/reconciler.js.map +0 -1
- package/es/components/custom/vtable-browser-env-contribution.d.ts +0 -2
- package/es/components/custom/vtable-browser-env-contribution.js +0 -33
- package/es/components/custom/vtable-browser-env-contribution.js.map +0 -1
- package/es/components/custom/vtable-react-attribute-plugin.d.ts +0 -17
- package/es/components/custom/vtable-react-attribute-plugin.js +0 -86
- package/es/components/custom/vtable-react-attribute-plugin.js.map +0 -1
- package/es/vtable.d.ts +0 -2
- package/es/vtable.js +0 -4
- package/es/vtable.js.map +0 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface BaseComponentProps {
|
|
3
3
|
id?: string | number;
|
|
4
|
-
children?: React.ReactNode;
|
|
5
4
|
}
|
|
6
5
|
type ComponentProps = BaseComponentProps & {
|
|
7
6
|
updateId?: number;
|
|
8
7
|
componentId?: number;
|
|
9
|
-
componentIndex?: number;
|
|
10
8
|
};
|
|
11
9
|
export declare const createComponent: <T extends ComponentProps>(componentName: string, optionName: string, supportedEvents?: Record<string, string> | null, isSingle?: boolean) => React.FC<T>;
|
|
12
10
|
export {};
|
|
@@ -6,10 +6,8 @@ import RootTableContext from "../context/table";
|
|
|
6
6
|
|
|
7
7
|
import { bindEventsToTable } from "../eventsUtils";
|
|
8
8
|
|
|
9
|
-
import { CustomLayout } from "./custom/custom-layout";
|
|
10
|
-
|
|
11
9
|
export const createComponent = (componentName, optionName, supportedEvents, isSingle) => {
|
|
12
|
-
const ignoreKeys = [ "id", "updateId", "componentId"
|
|
10
|
+
const ignoreKeys = [ "id", "updateId", "componentId" ], notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
13
11
|
const context = useContext(RootTableContext), eventsBinded = React.useRef(null), updateId = React.useRef(props.updateId);
|
|
14
12
|
if (props.updateId !== updateId.current) {
|
|
15
13
|
updateId.current = props.updateId;
|
|
@@ -17,23 +15,11 @@ export const createComponent = (componentName, optionName, supportedEvents, isSi
|
|
|
17
15
|
}
|
|
18
16
|
return useEffect((() => () => {
|
|
19
17
|
supportedEvents && bindEventsToTable(context.table, null, eventsBinded.current, supportedEvents);
|
|
20
|
-
}), []),
|
|
21
|
-
componentIndex: props.componentIndex
|
|
22
|
-
}, child))) : null;
|
|
18
|
+
}), []), null;
|
|
23
19
|
};
|
|
24
|
-
return Comp.displayName = componentName, Comp.parseOption = props => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"custom-layout" === child.props.role && (newComponentOption.customLayout = "react-custom-layout"),
|
|
30
|
-
"header-custom-layout" === child.props.role && (newComponentOption.headerCustomLayout = "react-custom-layout");
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
option: newComponentOption,
|
|
35
|
-
optionName: optionName,
|
|
36
|
-
isSingle: isSingle
|
|
37
|
-
};
|
|
38
|
-
}, Comp;
|
|
20
|
+
return Comp.displayName = componentName, Comp.parseOption = props => ({
|
|
21
|
+
option: pickWithout(props, notOptionKeys),
|
|
22
|
+
optionName: optionName,
|
|
23
|
+
isSingle: isSingle
|
|
24
|
+
}), Comp;
|
|
39
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/base-component.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["components/base-component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAkB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/D,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AASnD,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,UAAkB,EAClB,eAA+C,EAC/C,QAAkB,EAClB,EAAE;IACF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;IACrD,MAAM,aAAa,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAErG,MAAM,IAAI,GAAgB,CAAC,KAAQ,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;QAG7C,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAI,IAAI,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAS,KAAK,CAAC,QAAQ,CAAC,CAAC;QAGtD,IAAI,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,OAAO,EAAE;YAEvC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC;YAGlC,MAAM,mBAAmB,GAAG,eAAe;gBACzC,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC;gBAChF,CAAC,CAAC,KAAK,CAAC;YACV,IAAI,mBAAmB,EAAE;gBACvB,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;aAC9B;SAQF;QAED,SAAS,CAAC,GAAG,EAAE;YACb,OAAO,GAAG,EAAE;gBACV,IAAI,eAAe,EAAE;oBACnB,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;iBAC/E;YAEH,CAAC,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;IAEhC,IAAY,CAAC,WAAW,GAAG,CAAC,KAAsD,EAAE,EAAE;QACrF,MAAM,kBAAkB,GAAe,WAAW,CAAI,KAAK,EAAE,aAAa,CAAC,CAAC;QAE5E,OAAO;YACL,MAAM,EAAE,kBAAkB;YAC1B,UAAU;YACV,QAAQ;SACT,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","file":"base-component.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { isEqual, isNil, pickWithout } from '@visactor/vutils';\n\nimport type { TableContextType } from '../context/table';\nimport RootTableContext from '../context/table';\nimport { bindEventsToTable } from '../eventsUtils';\nimport { uid } from '../util';\n\nexport interface BaseComponentProps {\n id?: string | number;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number; componentId?: number };\n\nexport const createComponent = <T extends ComponentProps>(\n componentName: string,\n optionName: string,\n supportedEvents?: Record<string, string> | null,\n isSingle?: boolean\n) => {\n const ignoreKeys = ['id', 'updateId', 'componentId'];\n const notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys;\n\n const Comp: React.FC<T> = (props: T) => {\n const context = useContext(RootTableContext);\n // const id = React.useRef<string | number>(isNil(props.id) ? uid(optionName) : props.id);\n\n const eventsBinded = React.useRef<T>(null);\n const updateId = React.useRef<number>(props.updateId);\n // const componentOption = React.useRef<Partial<T>>();\n\n if (props.updateId !== updateId.current) {\n // update triggered by table when table is rendered\n updateId.current = props.updateId;\n\n // rebind events after table render\n const hasPrevEventsBinded = supportedEvents\n ? bindEventsToTable(context.table, props, eventsBinded.current, supportedEvents)\n : false;\n if (hasPrevEventsBinded) {\n eventsBinded.current = props;\n }\n // } else {\n // const newComponentOption: Partial<T> = pickWithout<T>(props, notOptionKeys);\n\n // if (!isEqual(newComponentOption, componentOption.current)) {\n // componentOption.current = newComponentOption;\n // updateToContext(context, id.current, optionName, isSingle, newComponentOption);\n // }\n }\n\n useEffect(() => {\n return () => {\n if (supportedEvents) {\n bindEventsToTable(context.table, null, eventsBinded.current, supportedEvents);\n }\n // deleteToContext(context, id.current, optionName, isSingle);\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n\n (Comp as any).parseOption = (props: T & { updateId?: number; componentId?: string }) => {\n const newComponentOption: Partial<T> = pickWithout<T>(props, notOptionKeys);\n\n return {\n option: newComponentOption,\n optionName,\n isSingle\n };\n };\n\n return Comp;\n};\n\n// const updateToContext = (\n// context: TableContextType,\n// id: string | number,\n// optionName: string,\n// isSingle: boolean,\n// props: Partial<ComponentProps>\n// ) => {\n// if (!context.optionFromChildren) {\n// return;\n// }\n\n// if (isSingle) {\n// context.optionFromChildren[optionName] = { ...props };\n// } else {\n// if (!context.optionFromChildren[optionName]) {\n// context.optionFromChildren[optionName] = [];\n// }\n\n// const comps = context.optionFromChildren[optionName];\n// const index = comps.findIndex((entry: any) => entry.id === id);\n\n// if (index >= 0) {\n// comps[index] = {\n// id,\n// ...props\n// };\n// } else {\n// context.optionFromChildren[optionName].push({\n// id,\n// ...props\n// });\n// }\n// }\n// context.isChildrenUpdated = true;\n// };\n\n// const deleteToContext = (context: TableContextType, id: string | number, optionName: string, isSingle: boolean) => {\n// if (!context.optionFromChildren) {\n// return;\n// }\n\n// if (isSingle) {\n// context.optionFromChildren[optionName] = null;\n// } else {\n// const comps = context.optionFromChildren[optionName] ?? [];\n// const index = comps.findIndex((entry: any) => entry.id === id);\n\n// if (index >= 0) {\n// const newComps = comps.slice(0, index - 1).concat(comps.slice(index + 1));\n\n// context.optionFromChildren[optionName] = newComps;\n// context.isChildrenUpdated = true;\n// }\n// }\n// };\n"]}
|
package/es/components/index.d.ts
CHANGED
|
@@ -7,9 +7,6 @@ export { PivotCorner } from './pivot/pivot-corner';
|
|
|
7
7
|
export { Menu } from './component/menu';
|
|
8
8
|
export { Tooltip } from './component/tooltip';
|
|
9
9
|
export { CustomComponent } from './custom-component';
|
|
10
|
-
export { CustomLayout, type CustomLayoutFunctionArg } from './custom/custom-layout';
|
|
11
|
-
export * from './custom/graphic';
|
|
12
|
-
export * from './custom/component';
|
|
13
10
|
type Props = {
|
|
14
11
|
updateId?: number;
|
|
15
12
|
};
|
package/es/components/index.js
CHANGED
|
@@ -13,10 +13,4 @@ export { Menu } from "./component/menu";
|
|
|
13
13
|
export { Tooltip } from "./component/tooltip";
|
|
14
14
|
|
|
15
15
|
export { CustomComponent } from "./custom-component";
|
|
16
|
-
|
|
17
|
-
export { CustomLayout } from "./custom/custom-layout";
|
|
18
|
-
|
|
19
|
-
export * from "./custom/graphic";
|
|
20
|
-
|
|
21
|
-
export * from "./custom/component";
|
|
22
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC
|
|
1
|
+
{"version":3,"sources":["components/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC","file":"index.js","sourcesContent":["import type React from 'react';\nexport { ListColumn } from './list/list-column';\nexport { PivotColumnDimension, PivotRowDimension } from './pivot/pivot-dimension';\nexport { PivotIndicator } from './pivot/pivot-indicator';\nexport { PivotColumnHeaderTitle, PivotRowHeaderTitle } from './pivot/pivot-header-title';\nexport { PivotCorner } from './pivot/pivot-corner';\nexport { Menu } from './component/menu';\nexport { Tooltip } from './component/tooltip';\n\nexport { CustomComponent } from './custom-component';\n\ntype Props = { updateId?: number };\n\nexport interface IMarkElement extends React.ReactElement<Props, React.JSXElementConstructor<Props>> {\n id: string | number;\n}\n"]}
|
package/es/eventsUtils.js
CHANGED
|
@@ -70,4 +70,5 @@ export const bindEventsToTable = (table, newProps, prevProps, supportedEvents =
|
|
|
70
70
|
})), newEventProps && Object.keys(newEventProps).forEach((eventKey => {
|
|
71
71
|
prevEventProps && prevEventProps[eventKey] && prevEventProps[eventKey] === newEventProps[eventKey] || table.on(supportedEvents[eventKey], newEventProps[eventKey]);
|
|
72
72
|
})), !0;
|
|
73
|
-
};
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=eventsUtils.js.map
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import * as VTable from "@visactor/vtable";
|
|
2
|
+
|
|
1
3
|
export * from "./tables";
|
|
2
4
|
|
|
3
5
|
export * from "./components";
|
|
4
6
|
|
|
5
|
-
export
|
|
7
|
+
export { VTable };
|
|
6
8
|
|
|
7
|
-
export const version = "1.3.3-alpha.
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
9
|
+
export const version = "1.3.3-alpha.1";
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAE3C,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","file":"index.js","sourcesContent":["import * as VTable from '@visactor/vtable';\n\nexport * from './tables';\nexport * from './components';\nexport { VTable };\n\nexport const version = \"1.3.3-alpha.1\";\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as VTable from '@visactor/vtable';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { ContainerProps } from '../containers/withContainer';
|
|
4
4
|
import type { EventsProps } from '../eventsUtils';
|
|
@@ -12,7 +12,6 @@ export interface BaseTableProps extends EventsProps {
|
|
|
12
12
|
width?: number;
|
|
13
13
|
height?: number;
|
|
14
14
|
skipFunctionDiff?: boolean;
|
|
15
|
-
ReactDOM?: any;
|
|
16
15
|
onReady?: (instance: IVTable, isInitial: boolean) => void;
|
|
17
16
|
onError?: (err: Error) => void;
|
|
18
17
|
}
|
package/es/tables/base-table.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as VTable from "@visactor/vtable";
|
|
2
2
|
|
|
3
3
|
import React, { useState, useEffect, useRef, useImperativeHandle, useCallback } from "react";
|
|
4
4
|
|
|
@@ -14,14 +14,6 @@ import { REACT_PRIVATE_PROPS } from "../constants";
|
|
|
14
14
|
|
|
15
15
|
import { bindEventsToTable, TABLE_EVENTS_KEYS, TABLE_EVENTS } from "../eventsUtils";
|
|
16
16
|
|
|
17
|
-
import { VTableReactAttributePlugin } from "../components/custom/vtable-react-attribute-plugin";
|
|
18
|
-
|
|
19
|
-
import { reactEnvModule } from "../components/custom/vtable-browser-env-contribution";
|
|
20
|
-
|
|
21
|
-
const {container: container, isBrowserEnv: isBrowserEnv} = VTable.VRender;
|
|
22
|
-
|
|
23
|
-
isBrowserEnv() && container.load(reactEnvModule);
|
|
24
|
-
|
|
25
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 => {
|
|
26
18
|
const optionFromChildren = {};
|
|
27
19
|
return toArray(props.children).map(((child, index) => {
|
|
@@ -48,15 +40,11 @@ const notOptionKeys = [ ...REACT_PRIVATE_PROPS, ...TABLE_EVENTS_KEYS, "skipFunct
|
|
|
48
40
|
}) : Object.assign(Object.assign(Object.assign({
|
|
49
41
|
records: props.records
|
|
50
42
|
}, prevOption.current), optionFromChildren.current), {
|
|
51
|
-
clearDOM: !1
|
|
52
|
-
customConfig: {
|
|
53
|
-
createReactContainer: !0
|
|
54
|
-
}
|
|
43
|
+
clearDOM: !1
|
|
55
44
|
})), [ hasOption, hasRecords ]), createTable = useCallback((props => {
|
|
56
45
|
let vtable;
|
|
57
46
|
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)),
|
|
58
|
-
|
|
59
|
-
vtable.scenegraph.stage.params.ReactDOM = props.ReactDOM, tableContext.current = Object.assign(Object.assign({}, tableContext.current), {
|
|
47
|
+
tableContext.current = Object.assign(Object.assign({}, tableContext.current), {
|
|
60
48
|
table: vtable
|
|
61
49
|
}), isUnmount.current = !1;
|
|
62
50
|
}), [ parseOption ]), handleTableRender = useCallback((() => {
|
|
@@ -104,8 +92,7 @@ const notOptionKeys = [ ...REACT_PRIVATE_PROPS, ...TABLE_EVENTS_KEYS, "skipFunct
|
|
|
104
92
|
key: childId
|
|
105
93
|
}, React.cloneElement(child, {
|
|
106
94
|
updateId: updateId,
|
|
107
|
-
componentId: childId
|
|
108
|
-
componentIndex: index
|
|
95
|
+
componentId: childId
|
|
109
96
|
}));
|
|
110
97
|
})));
|
|
111
98
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["tables/base-table.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE7F,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,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAanD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,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C,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,CAAC,OAAO,IACnD,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAsB,EAAE,KAAa,EAAE,EAAE;QACrE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO;SACR;QAED,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAM7C,OAAO,CAML,oBAAC,KAAK,CAAC,QAAQ,IAAC,GAAG,EAAE,OAAO,IACzB,KAAK,CAAC,YAAY,CAAC,KAAkE,EAAE;YACtF,QAAQ,EAAE,QAAQ;YAClB,WAAW,EAAE,OAAO;YACpB,cAAc,EAAE,KAAK;SACtB,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 */\n// import * as VTable from '@visactor/vtable';\nimport { VTable } from '../vtable';\nimport React, { useState, useEffect, useRef, useImperativeHandle, useCallback } from 'react';\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';\nimport { VTableReactAttributePlugin } from '../components/custom/vtable-react-attribute-plugin';\nimport { reactEnvModule } from '../components/custom/vtable-browser-env-contribution';\nconst { container, isBrowserEnv } = VTable.VRender;\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 ReactDOM?: any;\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\n// for react-vtable\nif (isBrowserEnv()) {\n container.load(reactEnvModule);\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 clearDOM: false,\n records: props.records\n };\n }\n return {\n ...props.option,\n clearDOM: false\n };\n }\n return {\n records: props.records,\n ...prevOption.current,\n ...optionFromChildren.current,\n clearDOM: false,\n customConfig: {\n createReactContainer: true\n }\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 // vtable.scenegraph.stage.enableReactAttribute(ReactDOM);\n vtable.scenegraph.stage.reactAttribute = props.ReactDOM;\n vtable.scenegraph.stage.pluginService.register(new VTableReactAttributePlugin());\n vtable.scenegraph.stage.params.ReactDOM = props.ReactDOM;\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 // eslint-disable-next-line promise/catch-or-return\n tableContext.current.table.updateOption(parseOption(props));\n handleTableRender();\n eventsBinded.current = props;\n } else if (\n hasRecords &&\n !isEqual(eventsBinded.current.records, props.records, { skipFunction: skipFunctionDiff })\n ) {\n tableContext.current.table.setRecords(props.records as any[]);\n handleTableRender();\n eventsBinded.current = props;\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 eventsBinded.current = props;\n } else if (hasRecords && !isEqual(props.records, prevRecords.current, { skipFunction: skipFunctionDiff })) {\n prevRecords.current = props.records;\n tableContext.current.table.setRecords(props.records);\n handleTableRender();\n eventsBinded.current = props;\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 componentIndex: index\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"]}
|
|
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,OAAO,CAAC;AAE7F,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,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAanD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA8BpF,MAAM,aAAa,GAAG;IACpB,GAAG,mBAAmB;IACtB,GAAG,iBAAiB;IACpB,kBAAkB;IAClB,SAAS;IACT,SAAS;IACT,QAAQ;IACR,SAAS;IACT,WAAW;CACZ,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAsB,EAAE,KAAa,EAAE,EAAE;IAC/D,MAAM,aAAa,GAAG,KAAK,IAAK,KAAa,CAAC,IAAI,IAAI,CAAE,KAAa,CAAC,IAAI,CAAC,WAAW,IAAK,KAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpH,OAAO,GAAG,aAAa,IAAI,KAAK,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,KAAY,EAAE,EAAE;IAC/C,MAAM,kBAAkB,GAAwD,EAAE,CAAC;IAEnF,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC3C,MAAM,WAA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AC;QAC3B,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,CAAC,OAAO,IACnD,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAsB,EAAE,KAAa,EAAE,EAAE;QACrE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO;SACR;QAED,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAM7C,OAAO,CAML,oBAAC,KAAK,CAAC,QAAQ,IAAC,GAAG,EAAE,OAAO,IACzB,KAAK,CAAC,YAAY,CAAC,KAAkE,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 'react';\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 clearDOM: false,\n records: props.records\n };\n }\n return {\n ...props.option,\n clearDOM: false\n };\n }\n return {\n records: props.records,\n ...prevOption.current,\n ...optionFromChildren.current,\n clearDOM: false\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 // eslint-disable-next-line promise/catch-or-return\n tableContext.current.table.updateOption(parseOption(props));\n handleTableRender();\n eventsBinded.current = props;\n } else if (\n hasRecords &&\n !isEqual(eventsBinded.current.records, props.records, { skipFunction: skipFunctionDiff })\n ) {\n tableContext.current.table.setRecords(props.records as any[]);\n handleTableRender();\n eventsBinded.current = props;\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 eventsBinded.current = props;\n } else if (hasRecords && !isEqual(props.records, prevRecords.current, { skipFunction: skipFunctionDiff })) {\n prevRecords.current = props.records;\n tableContext.current.table.setRecords(props.records);\n handleTableRender();\n eventsBinded.current = props;\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/react-vtable",
|
|
3
|
-
"version": "1.3.3-alpha.
|
|
3
|
+
"version": "1.3.3-alpha.1",
|
|
4
4
|
"description": "The react version of VTable",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,13 +43,12 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@visactor/vtable": "1.3.3-alpha.
|
|
46
|
+
"@visactor/vtable": "1.3.3-alpha.1",
|
|
47
47
|
"@visactor/vutils": "~0.18.9",
|
|
48
|
-
"react-is": "^18.2.0"
|
|
49
|
-
"react-reconciler": "0.29.2"
|
|
48
|
+
"react-is": "^18.2.0"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@visactor/vchart": "1.11.
|
|
51
|
+
"@visactor/vchart": "1.11.4",
|
|
53
52
|
"@rushstack/eslint-patch": "~1.1.4",
|
|
54
53
|
"react": "^18.0.0",
|
|
55
54
|
"react-dom": "^18.0.0",
|
|
@@ -90,10 +89,9 @@
|
|
|
90
89
|
"axios": "^1.4.0",
|
|
91
90
|
"@types/react-is": "^17.0.3",
|
|
92
91
|
"@arco-design/web-react": "2.60.2",
|
|
93
|
-
"@types/react-reconciler": "0.28.8",
|
|
94
92
|
"@internal/bundler": "0.0.1",
|
|
95
|
-
"@internal/
|
|
96
|
-
"@internal/
|
|
93
|
+
"@internal/eslint-config": "0.0.1",
|
|
94
|
+
"@internal/ts-config": "0.0.1"
|
|
97
95
|
},
|
|
98
96
|
"scripts": {
|
|
99
97
|
"start": "vite ./demo",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode, Ref, JSXElementConstructor } from 'react';
|
|
2
|
-
import type { VRender } from '@visactor/vtable';
|
|
3
|
-
type IGraphic = VRender.IGraphic;
|
|
4
|
-
type TagAttributes = VRender.TagAttributes;
|
|
5
|
-
type IEventParamsType = VRender.IEventParamsType;
|
|
6
|
-
type GraphicProps<IGraphicGraphicAttribute> = {
|
|
7
|
-
attribute: IGraphicGraphicAttribute;
|
|
8
|
-
ref?: Ref<IGraphic>;
|
|
9
|
-
children?: ReactNode;
|
|
10
|
-
} & IEventParamsType;
|
|
11
|
-
export declare const Tag: (props: GraphicProps<TagAttributes>) => ReactElement<GraphicProps<TagAttributes>, JSXElementConstructor<GraphicProps<TagAttributes>>>;
|
|
12
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["components/custom/component.ts"],"names":[],"mappings":";;;AAYa,QAAA,GAAG,GAEqF,KAAY,CAAC","file":"component.js","sourcesContent":["import type { ReactElement, ReactNode, Ref, JSXElementConstructor } from 'react';\nimport type { VRender } from '@visactor/vtable';\ntype IGraphic = VRender.IGraphic;\ntype TagAttributes = VRender.TagAttributes;\ntype IEventParamsType = VRender.IEventParamsType;\n\ntype GraphicProps<IGraphicGraphicAttribute> = {\n attribute: IGraphicGraphicAttribute;\n ref?: Ref<IGraphic>;\n children?: ReactNode;\n} & IEventParamsType;\n\nexport const Tag: (\n props: GraphicProps<TagAttributes>\n) => ReactElement<GraphicProps<TagAttributes>, JSXElementConstructor<GraphicProps<TagAttributes>>> = 'tag' as any;\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { CustomRenderFunctionArg } from '@visactor/vtable/src/ts-types';
|
|
3
|
-
type CustomLayoutProps = {
|
|
4
|
-
componentIndex?: number;
|
|
5
|
-
};
|
|
6
|
-
export type CustomLayoutFunctionArg = Partial<CustomRenderFunctionArg> & {
|
|
7
|
-
role?: 'custom-layout' | 'header-custom-layout';
|
|
8
|
-
};
|
|
9
|
-
export declare const CustomLayout: React.FC<CustomLayoutProps>;
|
|
10
|
-
export {};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4
|
-
void 0 === k2 && (k2 = k);
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
|
|
7
|
-
enumerable: !0,
|
|
8
|
-
get: function() {
|
|
9
|
-
return m[k];
|
|
10
|
-
}
|
|
11
|
-
}), Object.defineProperty(o, k2, desc);
|
|
12
|
-
} : function(o, m, k, k2) {
|
|
13
|
-
void 0 === k2 && (k2 = k), o[k2] = m[k];
|
|
14
|
-
}), __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", {
|
|
16
|
-
enumerable: !0,
|
|
17
|
-
value: v
|
|
18
|
-
});
|
|
19
|
-
} : function(o, v) {
|
|
20
|
-
o.default = v;
|
|
21
|
-
}), __importStar = this && this.__importStar || function(mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (null != mod) for (var k in mod) "default" !== k && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
|
|
25
|
-
return __setModuleDefault(result, mod), result;
|
|
26
|
-
}, __importDefault = this && this.__importDefault || function(mod) {
|
|
27
|
-
return mod && mod.__esModule ? mod : {
|
|
28
|
-
default: mod
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
Object.defineProperty(exports, "__esModule", {
|
|
33
|
-
value: !0
|
|
34
|
-
}), exports.CustomLayout = void 0;
|
|
35
|
-
|
|
36
|
-
const react_1 = __importStar(require("react")), table_1 = __importDefault(require("../../context/table")), vtable_1 = require("@visactor/vtable"), reconciler_1 = require("./reconciler"), constants_1 = require("react-reconciler/constants"), {Group: Group} = vtable_1.VRender, CustomLayout = (props, ref) => {
|
|
37
|
-
const {componentIndex: componentIndex, children: children} = props;
|
|
38
|
-
if (!(0, react_1.isValidElement)(children)) return null;
|
|
39
|
-
const context = (0, react_1.useContext)(table_1.default), {table: table} = context, isHeaderCustomLayout = "header-custom-layout" === children.props.role, container = (0,
|
|
40
|
-
react_1.useRef)(new Map), createGraphic = (0, react_1.useCallback)((args => {
|
|
41
|
-
const key = `${args.col}-${args.row}`;
|
|
42
|
-
let group;
|
|
43
|
-
if (container.current.has(key)) {
|
|
44
|
-
const currentContainer = container.current.get(key);
|
|
45
|
-
reconcilorUpdateContainer(children, currentContainer, group, args), group = currentContainer.containerInfo;
|
|
46
|
-
} else {
|
|
47
|
-
group = new Group({});
|
|
48
|
-
const currentContainer = reconciler_1.reconcilor.createContainer(group, constants_1.LegacyRoot, null, null, null, "custom", null, null);
|
|
49
|
-
container.current.set(key, currentContainer), reconcilorUpdateContainer(children, currentContainer, group, args);
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
rootContainer: group,
|
|
53
|
-
renderDefault: !1
|
|
54
|
-
};
|
|
55
|
-
}), [ children ]), removeContainer = (0, react_1.useCallback)(((col, row) => {
|
|
56
|
-
const key = `${col}-${row}`;
|
|
57
|
-
if (container.current.has(key)) {
|
|
58
|
-
const currentContainer = container.current.get(key);
|
|
59
|
-
reconciler_1.reconcilor.updateContainer(null, currentContainer, null), container.current.delete(key);
|
|
60
|
-
}
|
|
61
|
-
}), []);
|
|
62
|
-
return (0, react_1.useLayoutEffect)((() => () => {}), []), (0, react_1.useLayoutEffect)((() => {
|
|
63
|
-
var _a, _b, _c, _d;
|
|
64
|
-
null == table || table.checkReactCustomLayout(), table && !(null === (_a = table.reactCustomLayout) || void 0 === _a ? void 0 : _a.hasReactCreateGraphic(componentIndex, isHeaderCustomLayout)) ? (null === (_b = table.reactCustomLayout) || void 0 === _b || _b.setReactCreateGraphic(componentIndex, createGraphic, isHeaderCustomLayout),
|
|
65
|
-
null === (_c = table.reactCustomLayout) || void 0 === _c || _c.setReactRemoveGraphic(componentIndex, removeContainer, isHeaderCustomLayout),
|
|
66
|
-
null === (_d = table.reactCustomLayout) || void 0 === _d || _d.updateCustomCell(componentIndex, isHeaderCustomLayout)) : table && container.current.forEach(((value, key) => {
|
|
67
|
-
const [col, row] = key.split("-").map(Number), width = table.getColWidth(col), height = table.getRowHeight(row), currentContainer = value, args = {
|
|
68
|
-
col: col,
|
|
69
|
-
row: row,
|
|
70
|
-
dataValue: table.getCellOriginValue(col, row),
|
|
71
|
-
value: table.getCellValue(col, row) || "",
|
|
72
|
-
rect: {
|
|
73
|
-
left: 0,
|
|
74
|
-
top: 0,
|
|
75
|
-
right: width,
|
|
76
|
-
bottom: height,
|
|
77
|
-
width: width,
|
|
78
|
-
height: height
|
|
79
|
-
},
|
|
80
|
-
table: table
|
|
81
|
-
}, group = currentContainer.containerInfo;
|
|
82
|
-
reconcilorUpdateContainer(children, currentContainer, group, args), table.scenegraph.updateNextFrame();
|
|
83
|
-
}));
|
|
84
|
-
})), null;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
function reconcilorUpdateContainer(children, currentContainer, group, args) {
|
|
88
|
-
reconciler_1.reconcilor.updateContainer(react_1.default.cloneElement(children, Object.assign({}, args)), currentContainer, null);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function isReactElement(obj) {
|
|
92
|
-
return obj && obj.$$typeof === Symbol.for("react.element");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
//# sourceMappingURL=custom-layout.js.map
|
|
96
|
-
exports.CustomLayout = CustomLayout;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["components/custom/custom-layout.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,+CAAgG;AAChG,gEAAmD;AACnD,6CAA2C;AAG3C,6CAA0C;AAC1C,0DAAwD;AAExD,MAAM,EAAE,KAAK,EAAE,GAAG,gBAAO,CAAC;AAOnB,MAAM,YAAY,GAAgC,CAAC,KAA2C,EAAE,GAAG,EAAE,EAAE;IAC5G,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3C,IAAI,CAAC,IAAA,sBAAc,EAAC,QAAQ,CAAC,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IACD,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,eAAgB,CAAC,CAAC;IAC7C,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAE1B,MAAM,oBAAoB,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,sBAAsB,CAAC;IAG5E,MAAM,SAAS,GA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AAC,eAAe,CAAC,CAAC;AAC7D,CAAC","file":"custom-layout.js","sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\nimport type { PropsWithChildren } from 'react';\nimport React, { isValidElement, useCallback, useContext, useLayoutEffect, useRef } from 'react';\nimport RootTableContext from '../../context/table';\nimport { VRender } from '@visactor/vtable';\nimport type { ICustomLayoutFuc, CustomRenderFunctionArg } from '@visactor/vtable/src/ts-types';\nimport type { FiberRoot } from 'react-reconciler';\nimport { reconcilor } from './reconciler';\nimport { LegacyRoot } from 'react-reconciler/constants';\n\nconst { Group } = VRender;\ntype CustomLayoutProps = { componentIndex?: number };\n\nexport type CustomLayoutFunctionArg = Partial<CustomRenderFunctionArg> & {\n role?: 'custom-layout' | 'header-custom-layout';\n};\n\nexport const CustomLayout: React.FC<CustomLayoutProps> = (props: PropsWithChildren<CustomLayoutProps>, ref) => {\n const { componentIndex, children } = props;\n if (!isValidElement(children)) {\n return null;\n }\n const context = useContext(RootTableContext);\n const { table } = context;\n\n const isHeaderCustomLayout = children.props.role === 'header-custom-layout';\n\n // react customLayout component container cache\n const container = useRef<Map<string, FiberRoot>>(new Map());\n\n // customLayout function for vtable\n const createGraphic: ICustomLayoutFuc = useCallback(\n args => {\n const key = `${args.col}-${args.row}`;\n let group;\n if (container.current.has(key)) {\n const currentContainer = container.current.get(key);\n // reconcilor.updateContainer(React.cloneElement(children, { ...args }), currentContainer, null);\n reconcilorUpdateContainer(children, currentContainer, group, args);\n group = currentContainer.containerInfo;\n } else {\n group = new Group({});\n const currentContainer = reconcilor.createContainer(group, LegacyRoot, null, null, null, 'custom', null, null);\n container.current.set(key, currentContainer);\n reconcilorUpdateContainer(children, currentContainer, group, args);\n // const ele = React.cloneElement(children, { ...args });\n // reconcilor.updateContainer(ele, currentContainer, null);\n }\n\n return {\n rootContainer: group,\n renderDefault: false\n };\n },\n [children]\n );\n\n const removeContainer = useCallback((col: number, row: number) => {\n const key = `${col}-${row}`;\n if (container.current.has(key)) {\n const currentContainer = container.current.get(key);\n reconcilor.updateContainer(null, currentContainer, null);\n // group = currentContainer.containerInfo;\n container.current.delete(key);\n }\n }, []);\n\n useLayoutEffect(() => {\n // init and release\n // eslint-disable-next-line no-undef\n console.log('init', props, table);\n // table && (table._reactCreateGraphic = createGraphic); // never go to here\n // table?.renderWithRecreateCells();\n return () => {\n // eslint-disable-next-line no-undef\n console.log('release', props, table);\n };\n }, []);\n\n useLayoutEffect(() => {\n // update props\n // eslint-disable-next-line no-undef\n console.log('update props', props, table);\n\n table?.checkReactCustomLayout(); // init reactCustomLayout component\n if (table && !table.reactCustomLayout?.hasReactCreateGraphic(componentIndex, isHeaderCustomLayout)) {\n table.reactCustomLayout?.setReactCreateGraphic(\n componentIndex,\n createGraphic,\n // container.current,\n isHeaderCustomLayout\n ); // set customLayout function\n table.reactCustomLayout?.setReactRemoveGraphic(componentIndex, removeContainer, isHeaderCustomLayout); // set customLayout function\n table.reactCustomLayout?.updateCustomCell(componentIndex, isHeaderCustomLayout); // update cell content\n } else if (table) {\n // update all container\n container.current.forEach((value, key) => {\n const [col, row] = key.split('-').map(Number);\n const width = table.getColWidth(col); // to be fixed: may be merge cell\n const height = table.getRowHeight(row); // to be fixed: may be merge cell\n const currentContainer = value;\n const args = {\n col,\n row,\n dataValue: table.getCellOriginValue(col, row),\n value: table.getCellValue(col, row) || '',\n rect: {\n left: 0,\n top: 0,\n right: width,\n bottom: height,\n width,\n height\n },\n table\n };\n // update element in container\n const group = currentContainer.containerInfo;\n reconcilorUpdateContainer(children, currentContainer, group, args);\n // reconcilor.updateContainer(React.cloneElement(children, { ...args }), currentContainer, null);\n table.scenegraph.updateNextFrame();\n });\n }\n });\n\n return null;\n};\n\nfunction reconcilorUpdateContainer(children, currentContainer, group, args) {\n reconcilor.updateContainer(React.cloneElement(children, { ...args }), currentContainer, null);\n // group = group.firstChild;\n // if (isReactElement(group.attribute.html?.dom)) {\n // const div = document.createElement('div');\n // const root = ReactDOM.createRoot(div as HTMLElement);\n // root.render(group.attribute.html.dom);\n // group.attribute.html.dom = div;\n // // debugger;\n // // group.html.dom = div;\n // }\n}\n\nfunction isReactElement(obj) {\n return obj && obj.$$typeof === Symbol.for('react.element');\n}\n"]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode, Ref, JSXElementConstructor } from 'react';
|
|
2
|
-
import type { VRender } from '@visactor/vtable';
|
|
3
|
-
type IGraphic = VRender.IGraphic;
|
|
4
|
-
type IGroupGraphicAttribute = VRender.IGroupGraphicAttribute;
|
|
5
|
-
type ITextGraphicAttribute = VRender.ITextGraphicAttribute;
|
|
6
|
-
type IEventParamsType = VRender.IEventParamsType;
|
|
7
|
-
type IArcGraphicAttribute = VRender.IArcGraphicAttribute;
|
|
8
|
-
type ICircleGraphicAttribute = VRender.ICircleGraphicAttribute;
|
|
9
|
-
type IImageGraphicAttribute = VRender.IImageGraphicAttribute;
|
|
10
|
-
type ILineGraphicAttribute = VRender.ILineGraphicAttribute;
|
|
11
|
-
type IPathGraphicAttribute = VRender.IPathGraphicAttribute;
|
|
12
|
-
type IRectGraphicAttribute = VRender.IRectGraphicAttribute;
|
|
13
|
-
type ISymbolGraphicAttribute = VRender.ISymbolGraphicAttribute;
|
|
14
|
-
type IRichTextGraphicAttribute = VRender.IRichTextGraphicAttribute;
|
|
15
|
-
type IPolygonGraphicAttribute = VRender.IPolygonGraphicAttribute;
|
|
16
|
-
type GraphicProps<IGraphicGraphicAttribute> = {
|
|
17
|
-
attribute: IGraphicGraphicAttribute;
|
|
18
|
-
ref?: Ref<IGraphic>;
|
|
19
|
-
children?: ReactNode;
|
|
20
|
-
} & IEventParamsType;
|
|
21
|
-
export declare const Group: (props: GraphicProps<IGroupGraphicAttribute>) => ReactElement<GraphicProps<IGroupGraphicAttribute>, JSXElementConstructor<GraphicProps<IGroupGraphicAttribute>>>;
|
|
22
|
-
export declare const Text: (props: GraphicProps<ITextGraphicAttribute>) => ReactElement<GraphicProps<ITextGraphicAttribute>, JSXElementConstructor<GraphicProps<ITextGraphicAttribute>>>;
|
|
23
|
-
export declare const Arc: (props: GraphicProps<IArcGraphicAttribute>) => ReactElement<GraphicProps<IArcGraphicAttribute>, JSXElementConstructor<GraphicProps<IArcGraphicAttribute>>>;
|
|
24
|
-
export declare const Circle: (props: GraphicProps<ICircleGraphicAttribute>) => ReactElement<GraphicProps<ICircleGraphicAttribute>, JSXElementConstructor<GraphicProps<ICircleGraphicAttribute>>>;
|
|
25
|
-
export declare const Image: (props: GraphicProps<IImageGraphicAttribute>) => ReactElement<GraphicProps<IImageGraphicAttribute>, JSXElementConstructor<GraphicProps<IImageGraphicAttribute>>>;
|
|
26
|
-
export declare const Line: (props: GraphicProps<ILineGraphicAttribute>) => ReactElement<GraphicProps<ILineGraphicAttribute>, JSXElementConstructor<GraphicProps<ILineGraphicAttribute>>>;
|
|
27
|
-
export declare const Path: (props: GraphicProps<IPathGraphicAttribute>) => ReactElement<GraphicProps<IPathGraphicAttribute>, JSXElementConstructor<GraphicProps<IPathGraphicAttribute>>>;
|
|
28
|
-
export declare const Rect: (props: GraphicProps<IRectGraphicAttribute>) => ReactElement<GraphicProps<IRectGraphicAttribute>, JSXElementConstructor<GraphicProps<IRectGraphicAttribute>>>;
|
|
29
|
-
export declare const Symbol: (props: GraphicProps<ISymbolGraphicAttribute>) => ReactElement<GraphicProps<ISymbolGraphicAttribute>, JSXElementConstructor<GraphicProps<ISymbolGraphicAttribute>>>;
|
|
30
|
-
export declare const RichText: (props: GraphicProps<IRichTextGraphicAttribute>) => ReactElement<GraphicProps<IRichTextGraphicAttribute>, JSXElementConstructor<GraphicProps<IRichTextGraphicAttribute>>>;
|
|
31
|
-
export declare const Polygon: (props: GraphicProps<IPolygonGraphicAttribute>) => ReactElement<GraphicProps<IPolygonGraphicAttribute>, JSXElementConstructor<GraphicProps<IPolygonGraphicAttribute>>>;
|
|
32
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: !0
|
|
5
|
-
}), exports.Polygon = exports.RichText = exports.Symbol = exports.Rect = exports.Path = exports.Line = exports.Image = exports.Circle = exports.Arc = exports.Text = exports.Group = void 0,
|
|
6
|
-
exports.Group = "group", exports.Text = "text", exports.Arc = "arc", exports.Circle = "circle",
|
|
7
|
-
exports.Image = "image", exports.Line = "line", exports.Path = "path", exports.Rect = "rect",
|
|
8
|
-
exports.Symbol = "symbol", exports.RichText = "richtext", exports.Polygon = "polygon";
|
|
9
|
-
//# sourceMappingURL=graphic.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["components/custom/graphic.ts"],"names":[],"mappings":";;;AA2Ba,QAAA,KAAK,GAGhB,OAAc,CAAC;AAEJ,QAAA,IAAI,GAGf,MAAa,CAAC;AAEH,QAAA,GAAG,GAGd,KAAY,CAAC;AAEF,QAAA,MAAM,GAGjB,QAAe,CAAC;AAEL,QAAA,KAAK,GAGhB,OAAc,CAAC;AAEJ,QAAA,IAAI,GAGf,MAAa,CAAC;AAEH,QAAA,IAAI,GAGf,MAAa,CAAC;AAEH,QAAA,IAAI,GAGf,MAAa,CAAC;AAEH,QAAA,MAAM,GAGjB,QAAe,CAAC;AAEL,QAAA,QAAQ,GAKjB,UAAiB,CAAC;AAET,QAAA,OAAO,GAKhB,SAAgB,CAAC","file":"graphic.js","sourcesContent":["// export const Group = 'group';\n// export const Rect = 'rect';\n// export const Text = 'text';\n\nimport type { ReactElement, ReactNode, Ref, JSXElementConstructor } from 'react';\nimport type { VRender } from '@visactor/vtable';\n\ntype IGraphic = VRender.IGraphic;\ntype IGroupGraphicAttribute = VRender.IGroupGraphicAttribute;\ntype ITextGraphicAttribute = VRender.ITextGraphicAttribute;\ntype IEventParamsType = VRender.IEventParamsType;\ntype IArcGraphicAttribute = VRender.IArcGraphicAttribute;\ntype ICircleGraphicAttribute = VRender.ICircleGraphicAttribute;\ntype IImageGraphicAttribute = VRender.IImageGraphicAttribute;\ntype ILineGraphicAttribute = VRender.ILineGraphicAttribute;\ntype IPathGraphicAttribute = VRender.IPathGraphicAttribute;\ntype IRectGraphicAttribute = VRender.IRectGraphicAttribute;\ntype ISymbolGraphicAttribute = VRender.ISymbolGraphicAttribute;\ntype IRichTextGraphicAttribute = VRender.IRichTextGraphicAttribute;\ntype IPolygonGraphicAttribute = VRender.IPolygonGraphicAttribute;\n\ntype GraphicProps<IGraphicGraphicAttribute> = {\n attribute: IGraphicGraphicAttribute;\n ref?: Ref<IGraphic>;\n children?: ReactNode;\n} & IEventParamsType;\n\nexport const Group: (\n props: GraphicProps<IGroupGraphicAttribute>\n) => ReactElement<GraphicProps<IGroupGraphicAttribute>, JSXElementConstructor<GraphicProps<IGroupGraphicAttribute>>> =\n 'group' as any;\n\nexport const Text: (\n props: GraphicProps<ITextGraphicAttribute>\n) => ReactElement<GraphicProps<ITextGraphicAttribute>, JSXElementConstructor<GraphicProps<ITextGraphicAttribute>>> =\n 'text' as any;\n\nexport const Arc: (\n props: GraphicProps<IArcGraphicAttribute>\n) => ReactElement<GraphicProps<IArcGraphicAttribute>, JSXElementConstructor<GraphicProps<IArcGraphicAttribute>>> =\n 'arc' as any;\n\nexport const Circle: (\n props: GraphicProps<ICircleGraphicAttribute>\n) => ReactElement<GraphicProps<ICircleGraphicAttribute>, JSXElementConstructor<GraphicProps<ICircleGraphicAttribute>>> =\n 'circle' as any;\n\nexport const Image: (\n props: GraphicProps<IImageGraphicAttribute>\n) => ReactElement<GraphicProps<IImageGraphicAttribute>, JSXElementConstructor<GraphicProps<IImageGraphicAttribute>>> =\n 'image' as any;\n\nexport const Line: (\n props: GraphicProps<ILineGraphicAttribute>\n) => ReactElement<GraphicProps<ILineGraphicAttribute>, JSXElementConstructor<GraphicProps<ILineGraphicAttribute>>> =\n 'line' as any;\n\nexport const Path: (\n props: GraphicProps<IPathGraphicAttribute>\n) => ReactElement<GraphicProps<IPathGraphicAttribute>, JSXElementConstructor<GraphicProps<IPathGraphicAttribute>>> =\n 'path' as any;\n\nexport const Rect: (\n props: GraphicProps<IRectGraphicAttribute>\n) => ReactElement<GraphicProps<IRectGraphicAttribute>, JSXElementConstructor<GraphicProps<IRectGraphicAttribute>>> =\n 'rect' as any;\n\nexport const Symbol: (\n props: GraphicProps<ISymbolGraphicAttribute>\n) => ReactElement<GraphicProps<ISymbolGraphicAttribute>, JSXElementConstructor<GraphicProps<ISymbolGraphicAttribute>>> =\n 'symbol' as any;\n\nexport const RichText: (\n props: GraphicProps<IRichTextGraphicAttribute>\n) => ReactElement<\n GraphicProps<IRichTextGraphicAttribute>,\n JSXElementConstructor<GraphicProps<IRichTextGraphicAttribute>>\n> = 'richtext' as any;\n\nexport const Polygon: (\n props: GraphicProps<IPolygonGraphicAttribute>\n) => ReactElement<\n GraphicProps<IPolygonGraphicAttribute>,\n JSXElementConstructor<GraphicProps<IPolygonGraphicAttribute>>\n> = 'polygon' as any;\n"]}
|