@visactor/react-vtable 1.5.2-alpha.1 → 1.5.3-alpha.0
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 +4 -4
- package/cjs/components/base-component.d.ts +1 -1
- package/cjs/components/base-component.js +27 -7
- package/cjs/components/base-component.js.map +1 -1
- package/cjs/components/custom/custom-layout.d.ts +2 -1
- package/cjs/components/custom/custom-layout.js +5 -5
- package/cjs/components/custom/custom-layout.js.map +1 -1
- package/cjs/components/list/list-column.d.ts +1 -1
- package/cjs/components/list/list-column.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/dist/react-vtable.js +51 -21
- package/dist/react-vtable.min.js +1 -1
- package/es/components/base-component.d.ts +1 -1
- package/es/components/base-component.js +28 -8
- package/es/components/base-component.js.map +1 -1
- package/es/components/custom/custom-layout.d.ts +2 -1
- package/es/components/custom/custom-layout.js +5 -5
- package/es/components/custom/custom-layout.js.map +1 -1
- package/es/components/list/list-column.d.ts +1 -1
- package/es/components/list/list-column.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -43,19 +43,19 @@ const option = {
|
|
|
43
43
|
header: [
|
|
44
44
|
{
|
|
45
45
|
field: "0",
|
|
46
|
-
|
|
46
|
+
title: "name",
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
field: "1",
|
|
50
|
-
|
|
50
|
+
title: "age",
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
field: "2",
|
|
54
|
-
|
|
54
|
+
title: "gender",
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
field: "3",
|
|
58
|
-
|
|
58
|
+
title: "hobby",
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
61
|
records: new Array(1000).fill(["John", 18, "male", "🏀"]),
|
|
@@ -5,7 +5,7 @@ export interface BaseComponentProps {
|
|
|
5
5
|
}
|
|
6
6
|
type ComponentProps = BaseComponentProps & {
|
|
7
7
|
updateId?: number;
|
|
8
|
-
componentId?:
|
|
8
|
+
componentId?: string;
|
|
9
9
|
componentIndex?: number;
|
|
10
10
|
};
|
|
11
11
|
export declare const createComponent: <T extends ComponentProps>(componentName: string, optionName: string, supportedEvents?: Record<string, string> | null, isSingle?: boolean) => React.FC<T>;
|
|
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
34
34
|
}), exports.createComponent = void 0;
|
|
35
35
|
|
|
36
36
|
const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vutils"), table_1 = __importDefault(require("../context/table")), eventsUtils_1 = require("../eventsUtils"), custom_layout_1 = require("./custom/custom-layout"), createComponent = (componentName, optionName, supportedEvents, isSingle) => {
|
|
37
|
-
const ignoreKeys = [ "id", "updateId", "
|
|
37
|
+
const ignoreKeys = [ "id", "updateId", "componentIndex", "children" ], notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
38
38
|
const context = (0, react_1.useContext)(table_1.default), eventsBinded = react_1.default.useRef(null), updateId = react_1.default.useRef(props.updateId);
|
|
39
39
|
if (props.updateId !== updateId.current) {
|
|
40
40
|
updateId.current = props.updateId;
|
|
@@ -42,17 +42,14 @@ const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vu
|
|
|
42
42
|
}
|
|
43
43
|
return (0, react_1.useEffect)((() => () => {
|
|
44
44
|
supportedEvents && (0, eventsUtils_1.bindEventsToTable)(context.table, null, eventsBinded.current, supportedEvents);
|
|
45
|
-
}), []),
|
|
46
|
-
componentIndex: props.componentIndex
|
|
47
|
-
}, child))) : null;
|
|
45
|
+
}), []), parseCustomChildren(props.children, props.componentId);
|
|
48
46
|
};
|
|
49
47
|
return Comp.displayName = componentName, Comp.parseOption = props => {
|
|
50
48
|
const newComponentOption = (0, vutils_1.pickWithout)(props, notOptionKeys);
|
|
51
49
|
if (props.children) {
|
|
52
50
|
const {children: children} = props;
|
|
53
|
-
react_1.default.Children.map(children, (child => {
|
|
54
|
-
|
|
55
|
-
"header-custom-layout" === child.props.role && (newComponentOption.headerCustomLayout = "react-custom-layout");
|
|
51
|
+
react_1.default.Children.map(children, ((child, index) => {
|
|
52
|
+
parseChild(child, props, newComponentOption, notOptionKeys, props.componentId + "-" + index);
|
|
56
53
|
}));
|
|
57
54
|
}
|
|
58
55
|
return {
|
|
@@ -63,4 +60,27 @@ const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vu
|
|
|
63
60
|
}, Comp;
|
|
64
61
|
};
|
|
65
62
|
|
|
63
|
+
function parseChild(child, componentProps, newComponentOption, notOptionKeys, componentId) {
|
|
64
|
+
if ("custom-layout" === child.props.role && (newComponentOption.customLayout = "react-custom-layout",
|
|
65
|
+
newComponentOption.customLayoutComponentId = componentId), "header-custom-layout" === child.props.role && (newComponentOption.headerCustomLayout = "react-custom-layout",
|
|
66
|
+
newComponentOption.headerCustomLayoutComponentId = componentId), "ListColumn" === child.type.displayName) {
|
|
67
|
+
newComponentOption.columns || (newComponentOption.columns = []);
|
|
68
|
+
const childOption = (0, vutils_1.pickWithout)(child.props, notOptionKeys);
|
|
69
|
+
newComponentOption.columns.push(childOption), childOption.componentId = componentId,
|
|
70
|
+
child.props.children && react_1.default.Children.map(child.props.children, ((child, index) => {
|
|
71
|
+
parseChild(child, componentProps, childOption, notOptionKeys, componentId + "-" + index);
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseCustomChildren(children, componentId) {
|
|
77
|
+
return isReactElement(children) || Array.isArray(children) ? react_1.default.Children.map(children, ((child, index) => child.props.children ? parseCustomChildren(child.props.children, componentId + "-" + index) : "custom-layout" === child.props.role || "header-custom-layout" === child.props.role ? react_1.default.createElement(custom_layout_1.CustomLayout, {
|
|
78
|
+
componentId: componentId
|
|
79
|
+
}, child) : null)) : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isReactElement(obj) {
|
|
83
|
+
return obj && obj.$$typeof === Symbol.for("react.element");
|
|
84
|
+
}
|
|
85
|
+
|
|
66
86
|
exports.createComponent = createComponent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/base-component.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAqD;AACrD,6CAA+D;AAG/D,6DAAgD;AAChD,gDAAmD;AAEnD,0DAAsD;AAS/C,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,UAAkB,EAClB,eAA+C,EAC/C,QAAkB,EAClB,EAAE;IACF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"sources":["components/base-component.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAqD;AACrD,6CAA+D;AAG/D,6DAAgD;AAChD,gDAAmD;AAEnD,0DAAsD;AAS/C,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,UAAkB,EAClB,eAA+C,EAC/C,QAAkB,EAClB,EAAE;IACF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;IACpE,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,IAAA,kBAAU,EAAC,eAAgB,CAAC,CAAC;QAG7C,MAAM,YAAY,GAAG,eAAK,CAAC,MAAM,CAAI,IAAI,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAS,KAAK,CAAC,QAAQ,CAAC,CAAC;Q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;SACJ;KACF;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAmB,EAAE,WAAmB;IACnE,IAAI,cAAc,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACvD,OAAO,eAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAwB,EAAE,CAAC,KAAmB,EAAE,KAAK,EAAE,EAAE;YACjF,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE;gBACxB,OAAO,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,QAAwB,EAAE,WAAW,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC;aAC7F;iBAAM,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE;gBAC9F,OAAO,eAAK,CAAC,aAAa,CAAC,4BAAY,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;aAC/E;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,GAAQ;IAC9B,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC7D,CAAC","file":"base-component.js","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport 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';\nimport { CustomLayout } from './custom/custom-layout';\n\nexport interface BaseComponentProps {\n id?: string | number;\n children?: React.ReactNode;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number; componentId?: string; componentIndex?: 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', 'componentIndex', 'children'];\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 // children are all custom layout temply\n // return props.children\n // ? React.cloneElement(props.children as ReactElement, { componentIndex: props.componentIndex })\n // : null;\n // if (props.children) {\n // return React.Children.map(props.children as ReactElement, (child: ReactElement) => {\n // if (child.props.role === 'custom-layout' || child.props.role === 'header-custom-layout') {\n // return React.createElement(CustomLayout, { componentId: props.componentId }, child);\n // }\n // });\n // }\n return parseCustomChildren(props.children, props.componentId);\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 // deal width customLayout\n if (props.children) {\n const { children } = props;\n React.Children.map(children as ReactElement, (child: ReactElement, index) => {\n parseChild(child, props, newComponentOption, notOptionKeys, props.componentId + '-' + index);\n });\n }\n // if (props.children && (props.children as React.ReactElement).props.role === 'custom-layout') {\n // (newComponentOption as any).customLayout = 'react-custom-layout';\n // }\n\n return {\n option: newComponentOption,\n optionName,\n isSingle\n };\n };\n\n return Comp;\n};\n\nfunction parseChild(\n child: ReactElement,\n componentProps: any,\n newComponentOption: any,\n notOptionKeys: string[],\n componentId: string\n) {\n if (child.props.role === 'custom-layout') {\n (newComponentOption as any).customLayout = 'react-custom-layout';\n (newComponentOption as any).customLayoutComponentId = componentId;\n }\n if (child.props.role === 'header-custom-layout') {\n (newComponentOption as any).headerCustomLayout = 'react-custom-layout';\n (newComponentOption as any).headerCustomLayoutComponentId = componentId;\n }\n if ((child.type as any).displayName === 'ListColumn') {\n if (!newComponentOption.columns) {\n newComponentOption.columns = [];\n }\n const childOption = pickWithout(child.props, notOptionKeys);\n newComponentOption.columns.push(childOption);\n childOption.componentId = componentId;\n if (child.props.children) {\n React.Children.map(child.props.children as ReactElement, (child: ReactElement, index) => {\n parseChild(child, componentProps, childOption, notOptionKeys, componentId + '-' + index);\n });\n }\n }\n}\n\nfunction parseCustomChildren(children: ReactNode, componentId: string): ReactNode | undefined {\n if (isReactElement(children) || Array.isArray(children)) {\n return React.Children.map(children as ReactElement, (child: ReactElement, index) => {\n if (child.props.children) {\n return parseCustomChildren(child.props.children as ReactElement, componentId + '-' + index);\n } else if (child.props.role === 'custom-layout' || child.props.role === 'header-custom-layout') {\n return React.createElement(CustomLayout, { componentId: componentId }, child);\n }\n return null;\n });\n }\n return null;\n}\n\nfunction isReactElement(obj: any) {\n return obj && obj.$$typeof === Symbol.for('react.element');\n}\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { CustomRenderFunctionArg } from '@visactor/vtable/src/ts-types';
|
|
3
3
|
type CustomLayoutProps = {
|
|
4
|
-
|
|
4
|
+
componentId: string;
|
|
5
5
|
};
|
|
6
6
|
export type CustomLayoutFunctionArg = Partial<CustomRenderFunctionArg> & {
|
|
7
7
|
role?: 'custom-layout' | 'header-custom-layout';
|
|
8
|
+
renderDefault?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export declare const CustomLayout: React.FC<CustomLayoutProps>;
|
|
10
11
|
export {};
|
|
@@ -34,7 +34,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
34
34
|
}), exports.CustomLayout = void 0;
|
|
35
35
|
|
|
36
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 {
|
|
37
|
+
const {componentId: componentId, children: children} = props;
|
|
38
38
|
if (!(0, react_1.isValidElement)(children)) return null;
|
|
39
39
|
const context = (0, react_1.useContext)(table_1.default), {table: table} = context, isHeaderCustomLayout = "header-custom-layout" === children.props.role, container = (0,
|
|
40
40
|
react_1.useRef)(new Map), createGraphic = (0, react_1.useCallback)((args => {
|
|
@@ -50,7 +50,7 @@ const react_1 = __importStar(require("react")), table_1 = __importDefault(requir
|
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
52
52
|
rootContainer: group,
|
|
53
|
-
renderDefault:
|
|
53
|
+
renderDefault: !!children.props.renderDefault
|
|
54
54
|
};
|
|
55
55
|
}), [ children ]), removeContainer = (0, react_1.useCallback)(((col, row) => {
|
|
56
56
|
const key = `${col}-${row}`;
|
|
@@ -61,9 +61,9 @@ const react_1 = __importStar(require("react")), table_1 = __importDefault(requir
|
|
|
61
61
|
}), []);
|
|
62
62
|
return (0, react_1.useLayoutEffect)((() => () => {}), []), (0, react_1.useLayoutEffect)((() => {
|
|
63
63
|
var _a, _b, _c, _d;
|
|
64
|
-
null == table || table.checkReactCustomLayout(), table && !(null === (_a = table.reactCustomLayout) || void 0 === _a ? void 0 : _a.hasReactCreateGraphic(
|
|
65
|
-
null === (_c = table.reactCustomLayout) || void 0 === _c || _c.setReactRemoveGraphic(
|
|
66
|
-
null === (_d = table.reactCustomLayout) || void 0 === _d || _d.updateCustomCell(
|
|
64
|
+
null == table || table.checkReactCustomLayout(), table && !(null === (_a = table.reactCustomLayout) || void 0 === _a ? void 0 : _a.hasReactCreateGraphic(componentId, isHeaderCustomLayout)) ? (null === (_b = table.reactCustomLayout) || void 0 === _b || _b.setReactCreateGraphic(componentId, createGraphic, isHeaderCustomLayout),
|
|
65
|
+
null === (_c = table.reactCustomLayout) || void 0 === _c || _c.setReactRemoveGraphic(componentId, removeContainer, isHeaderCustomLayout),
|
|
66
|
+
null === (_d = table.reactCustomLayout) || void 0 === _d || _d.updateCustomCell(componentId, isHeaderCustomLayout)) : table && container.current.forEach(((value, key) => {
|
|
67
67
|
const [col, row] = key.split("-").map(Number), width = table.getColWidth(col), height = table.getRowHeight(row), currentContainer = value, args = {
|
|
68
68
|
col: col,
|
|
69
69
|
row: row,
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAQnB,MAAM,YAAY,GAAgC,CAAC,KAA2C,EAAE,GAAG,EAAE,EAAE;IAC5G,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,CAAC,IAAA,sBAAc,EAAC,QAA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,SAAS,yBAAyB,CAAC,QAAsB,EAAE,gBAAqB,EAAE,KAAmB,EAAE,IAAS;IAC9G,uBAAU,CAAC,eAAe,CAAC,eAAK,CAAC,YAAY,CAAC,QAAQ,oBAAO,IAAI,EAAG,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAUhG,CAAC;AAED,SAAS,cAAc,CAAC,GAAG;IACzB,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC7D,CAAC","file":"custom-layout.js","sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\nimport type { PropsWithChildren, ReactElement } 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 = { componentId: string };\n\nexport type CustomLayoutFunctionArg = Partial<CustomRenderFunctionArg> & {\n role?: 'custom-layout' | 'header-custom-layout';\n renderDefault?: boolean;\n};\n\nexport const CustomLayout: React.FC<CustomLayoutProps> = (props: PropsWithChildren<CustomLayoutProps>, ref) => {\n const { componentId, 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: !!children.props.renderDefault\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(componentId, isHeaderCustomLayout)) {\n table.reactCustomLayout?.setReactCreateGraphic(\n componentId,\n createGraphic,\n // container.current,\n isHeaderCustomLayout\n ); // set customLayout function\n table.reactCustomLayout?.setReactRemoveGraphic(componentId, removeContainer, isHeaderCustomLayout); // set customLayout function\n table.reactCustomLayout?.updateCustomCell(componentId, 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: ReactElement, currentContainer: any, group: typeof Group, args: any) {\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,4 +1,4 @@
|
|
|
1
1
|
import type { BaseComponentProps } from '../base-component';
|
|
2
2
|
import type { ColumnDefine } from '@visactor/vtable';
|
|
3
|
-
export type ListColumnProps = ColumnDefine & BaseComponentProps;
|
|
3
|
+
export type ListColumnProps = Omit<ColumnDefine, 'columns'> & BaseComponentProps;
|
|
4
4
|
export declare const ListColumn: import("react").FC<ListColumnProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/list/list-column.tsx"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["components/list/list-column.tsx"],"names":[],"mappings":";;;AAEA,sDAAoD;AAKvC,QAAA,UAAU,GAAG,IAAA,gCAAe,EAAkB,YAAY,EAAE,SAAS,CAAC,CAAC","file":"list-column.js","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport type { BaseComponentProps } from '../base-component';\nimport { createComponent } from '../base-component';\nimport type { ColumnDefine } from '@visactor/vtable';\n\nexport type ListColumnProps = Omit<ColumnDefine, 'columns'> & BaseComponentProps;\n\nexport const ListColumn = createComponent<ListColumnProps>('ListColumn', 'columns');\n"]}
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -18,5 +18,5 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", {
|
|
19
19
|
value: !0
|
|
20
20
|
}), exports.version = void 0, __exportStar(require("./tables"), exports), __exportStar(require("./components"), exports),
|
|
21
|
-
__exportStar(require("./vtable"), exports), exports.version = "1.5.
|
|
21
|
+
__exportStar(require("./vtable"), exports), exports.version = "1.5.3-alpha.0";
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,2CAAyB;AAEZ,QAAA,OAAO,GAAG,eAAe,CAAC","file":"index.js","sourcesContent":["export * from './tables';\nexport * from './components';\nexport * from './vtable';\n\nexport const version = \"1.5.
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,2CAAyB;AAEZ,QAAA,OAAO,GAAG,eAAe,CAAC","file":"index.js","sourcesContent":["export * from './tables';\nexport * from './components';\nexport * from './vtable';\n\nexport const version = \"1.5.3-alpha.0\";\n"]}
|
package/dist/react-vtable.js
CHANGED
|
@@ -13457,7 +13457,7 @@
|
|
|
13457
13457
|
|
|
13458
13458
|
const { Group: Group$1 } = VTable.VRender;
|
|
13459
13459
|
const CustomLayout = (props, ref) => {
|
|
13460
|
-
const {
|
|
13460
|
+
const { componentId, children } = props;
|
|
13461
13461
|
if (!reactExports.isValidElement(children)) {
|
|
13462
13462
|
return null;
|
|
13463
13463
|
}
|
|
@@ -13481,7 +13481,7 @@
|
|
|
13481
13481
|
}
|
|
13482
13482
|
return {
|
|
13483
13483
|
rootContainer: group,
|
|
13484
|
-
renderDefault:
|
|
13484
|
+
renderDefault: !!children.props.renderDefault
|
|
13485
13485
|
};
|
|
13486
13486
|
}, [children]);
|
|
13487
13487
|
const removeContainer = reactExports.useCallback((col, row) => {
|
|
@@ -13501,10 +13501,10 @@
|
|
|
13501
13501
|
reactExports.useLayoutEffect(() => {
|
|
13502
13502
|
console.log('update props', props, table);
|
|
13503
13503
|
table?.checkReactCustomLayout();
|
|
13504
|
-
if (table && !table.reactCustomLayout?.hasReactCreateGraphic(
|
|
13505
|
-
table.reactCustomLayout?.setReactCreateGraphic(
|
|
13506
|
-
table.reactCustomLayout?.setReactRemoveGraphic(
|
|
13507
|
-
table.reactCustomLayout?.updateCustomCell(
|
|
13504
|
+
if (table && !table.reactCustomLayout?.hasReactCreateGraphic(componentId, isHeaderCustomLayout)) {
|
|
13505
|
+
table.reactCustomLayout?.setReactCreateGraphic(componentId, createGraphic, isHeaderCustomLayout);
|
|
13506
|
+
table.reactCustomLayout?.setReactRemoveGraphic(componentId, removeContainer, isHeaderCustomLayout);
|
|
13507
|
+
table.reactCustomLayout?.updateCustomCell(componentId, isHeaderCustomLayout);
|
|
13508
13508
|
}
|
|
13509
13509
|
else if (table) {
|
|
13510
13510
|
container.current.forEach((value, key) => {
|
|
@@ -13540,7 +13540,7 @@
|
|
|
13540
13540
|
}
|
|
13541
13541
|
|
|
13542
13542
|
const createComponent = (componentName, optionName, supportedEvents, isSingle) => {
|
|
13543
|
-
const ignoreKeys = ['id', 'updateId', '
|
|
13543
|
+
const ignoreKeys = ['id', 'updateId', 'componentIndex', 'children'];
|
|
13544
13544
|
const notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys;
|
|
13545
13545
|
const Comp = (props) => {
|
|
13546
13546
|
const context = reactExports.useContext(TableContext);
|
|
@@ -13562,25 +13562,15 @@
|
|
|
13562
13562
|
}
|
|
13563
13563
|
};
|
|
13564
13564
|
}, []);
|
|
13565
|
-
|
|
13566
|
-
return React.Children.map(props.children, (child) => {
|
|
13567
|
-
return React.createElement(CustomLayout, { componentIndex: props.componentIndex }, child);
|
|
13568
|
-
});
|
|
13569
|
-
}
|
|
13570
|
-
return null;
|
|
13565
|
+
return parseCustomChildren(props.children, props.componentId);
|
|
13571
13566
|
};
|
|
13572
13567
|
Comp.displayName = componentName;
|
|
13573
13568
|
Comp.parseOption = (props) => {
|
|
13574
13569
|
const newComponentOption = pickWithout(props, notOptionKeys);
|
|
13575
13570
|
if (props.children) {
|
|
13576
13571
|
const { children } = props;
|
|
13577
|
-
React.Children.map(children, (child) => {
|
|
13578
|
-
|
|
13579
|
-
newComponentOption.customLayout = 'react-custom-layout';
|
|
13580
|
-
}
|
|
13581
|
-
if (child.props.role === 'header-custom-layout') {
|
|
13582
|
-
newComponentOption.headerCustomLayout = 'react-custom-layout';
|
|
13583
|
-
}
|
|
13572
|
+
React.Children.map(children, (child, index) => {
|
|
13573
|
+
parseChild(child, props, newComponentOption, notOptionKeys, props.componentId + '-' + index);
|
|
13584
13574
|
});
|
|
13585
13575
|
}
|
|
13586
13576
|
return {
|
|
@@ -13591,6 +13581,46 @@
|
|
|
13591
13581
|
};
|
|
13592
13582
|
return Comp;
|
|
13593
13583
|
};
|
|
13584
|
+
function parseChild(child, componentProps, newComponentOption, notOptionKeys, componentId) {
|
|
13585
|
+
if (child.props.role === 'custom-layout') {
|
|
13586
|
+
newComponentOption.customLayout = 'react-custom-layout';
|
|
13587
|
+
newComponentOption.customLayoutComponentId = componentId;
|
|
13588
|
+
}
|
|
13589
|
+
if (child.props.role === 'header-custom-layout') {
|
|
13590
|
+
newComponentOption.headerCustomLayout = 'react-custom-layout';
|
|
13591
|
+
newComponentOption.headerCustomLayoutComponentId = componentId;
|
|
13592
|
+
}
|
|
13593
|
+
if (child.type.displayName === 'ListColumn') {
|
|
13594
|
+
if (!newComponentOption.columns) {
|
|
13595
|
+
newComponentOption.columns = [];
|
|
13596
|
+
}
|
|
13597
|
+
const childOption = pickWithout(child.props, notOptionKeys);
|
|
13598
|
+
newComponentOption.columns.push(childOption);
|
|
13599
|
+
childOption.componentId = componentId;
|
|
13600
|
+
if (child.props.children) {
|
|
13601
|
+
React.Children.map(child.props.children, (child, index) => {
|
|
13602
|
+
parseChild(child, componentProps, childOption, notOptionKeys, componentId + '-' + index);
|
|
13603
|
+
});
|
|
13604
|
+
}
|
|
13605
|
+
}
|
|
13606
|
+
}
|
|
13607
|
+
function parseCustomChildren(children, componentId) {
|
|
13608
|
+
if (isReactElement(children) || Array.isArray(children)) {
|
|
13609
|
+
return React.Children.map(children, (child, index) => {
|
|
13610
|
+
if (child.props.children) {
|
|
13611
|
+
return parseCustomChildren(child.props.children, componentId + '-' + index);
|
|
13612
|
+
}
|
|
13613
|
+
else if (child.props.role === 'custom-layout' || child.props.role === 'header-custom-layout') {
|
|
13614
|
+
return React.createElement(CustomLayout, { componentId: componentId }, child);
|
|
13615
|
+
}
|
|
13616
|
+
return null;
|
|
13617
|
+
});
|
|
13618
|
+
}
|
|
13619
|
+
return null;
|
|
13620
|
+
}
|
|
13621
|
+
function isReactElement(obj) {
|
|
13622
|
+
return obj && obj.$$typeof === Symbol.for('react.element');
|
|
13623
|
+
}
|
|
13594
13624
|
|
|
13595
13625
|
const ListColumn = createComponent('ListColumn', 'columns');
|
|
13596
13626
|
|
|
@@ -13718,7 +13748,7 @@
|
|
|
13718
13748
|
const Radio = 'radio';
|
|
13719
13749
|
const Checkbox = 'checkbox';
|
|
13720
13750
|
|
|
13721
|
-
const version = "1.5.
|
|
13751
|
+
const version = "1.5.3-alpha.0";
|
|
13722
13752
|
|
|
13723
13753
|
exports.VTable = VTable__namespace;
|
|
13724
13754
|
exports.Arc = Arc;
|
package/dist/react-vtable.min.js
CHANGED
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
*
|
|
44
44
|
* This source code is licensed under the MIT license found in the
|
|
45
45
|
* LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/"production"===process.env.NODE_ENV?Ee.exports=(we||(we=1,Ce.ConcurrentRoot=1,Ce.ContinuousEventPriority=4,Ce.DefaultEventPriority=16,Ce.DiscreteEventPriority=1,Ce.IdleEventPriority=536870912,Ce.LegacyRoot=0),Ce):Ee.exports=(xe||(xe=1,"production"!==process.env.NODE_ENV&&(_e.ConcurrentRoot=1,_e.ContinuousEventPriority=4,_e.DefaultEventPriority=16,_e.DiscreteEventPriority=1,_e.IdleEventPriority=536870912,_e.LegacyRoot=0)),_e);var Re=Ee.exports;const{application:Pe,createText:Te,REACT_TO_CANOPUS_EVENTS:Ne,Tag:ze}=n.VRender,Ie=ke({supportsMutation:!0,supportsPersistence:!1,createInstance:(e,n,t)=>{const r=function(e,n){if("tag"===e){return new ze(n.attribute)}if(!Pe.graphicService.creator[e])return;const t=Pe.graphicService.creator[e](n.attribute);return t}(e,n);if(r)return function(e,n){for(const t in n)Le(t,n)&&e.addEventListener(Ne[t],n[t])}(r,n),r},createTextInstance:(e,n)=>{},appendInitialChild:(e,n)=>{e.add(n)},finalizeInitialChildren:()=>!1,prepareUpdate:()=>!0,shouldSetTextContent:()=>!1,getRootHostContext:()=>null,getChildHostContext:()=>null,getPublicInstance:e=>e,prepareForCommit:()=>null,resetAfterCommit:()=>{},preparePortalMount:()=>null,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,isPrimaryRenderer:!1,getCurrentEventPriority:()=>Re.DefaultEventPriority,getInstanceFromNode:e=>null,beforeActiveInstanceBlur:()=>{},afterActiveInstanceBlur:()=>{},prepareScopeUpdate:()=>{},getInstanceFromScope:()=>{},detachDeletedInstance:()=>{},supportsHydration:!1,appendChild:(e,n)=>{e.add(n)},appendChildToContainer:(e,n)=>{e.add(n)},insertBefore:(e,n,t)=>{e.insertBefore(n,t)},insertInContainerBefore:(e,n,t)=>{e.insertBefore(n,t)},removeChild:(e,n)=>{n.delete()},removeChildFromContainer:(e,n)=>{n.delete()},commitUpdate:(e,n,t,r,a)=>{!function(e,n,t){for(const r in t)Le(r,t)&&t[r]!==n[r]&&e.removeEventListener(Ne[r],t[r]);for(const r in n)Le(r,n)&&t[r]!==n[r]&&e.addEventListener(Ne[r],n[r]);e.initAttributes(n.attribute),"image"===e.type&&e.loadImage(n.attribute.image)}(e,a,r)},hideInstance:e=>{e.setAttribute("visible",!1)},unhideInstance:(e,n)=>{e.setAttribute("visible",!0)},clearContainer:e=>{e.removeAllChild()},commitTextUpdate:(e,n,t)=>{}});function Le(e,n){return e.startsWith("on")&&h(n[e])}Ie.injectIntoDevTools({bundleType:"production"!==process.env.NODE_ENV?1:0,version:f.version,rendererPackageName:"react-vtable"});const{Group:De}=n.VRender,Me=(e,n)=>{const{
|
|
46
|
+
*/"production"===process.env.NODE_ENV?Ee.exports=(we||(we=1,Ce.ConcurrentRoot=1,Ce.ContinuousEventPriority=4,Ce.DefaultEventPriority=16,Ce.DiscreteEventPriority=1,Ce.IdleEventPriority=536870912,Ce.LegacyRoot=0),Ce):Ee.exports=(xe||(xe=1,"production"!==process.env.NODE_ENV&&(_e.ConcurrentRoot=1,_e.ContinuousEventPriority=4,_e.DefaultEventPriority=16,_e.DiscreteEventPriority=1,_e.IdleEventPriority=536870912,_e.LegacyRoot=0)),_e);var Re=Ee.exports;const{application:Pe,createText:Te,REACT_TO_CANOPUS_EVENTS:Ne,Tag:ze}=n.VRender,Ie=ke({supportsMutation:!0,supportsPersistence:!1,createInstance:(e,n,t)=>{const r=function(e,n){if("tag"===e){return new ze(n.attribute)}if(!Pe.graphicService.creator[e])return;const t=Pe.graphicService.creator[e](n.attribute);return t}(e,n);if(r)return function(e,n){for(const t in n)Le(t,n)&&e.addEventListener(Ne[t],n[t])}(r,n),r},createTextInstance:(e,n)=>{},appendInitialChild:(e,n)=>{e.add(n)},finalizeInitialChildren:()=>!1,prepareUpdate:()=>!0,shouldSetTextContent:()=>!1,getRootHostContext:()=>null,getChildHostContext:()=>null,getPublicInstance:e=>e,prepareForCommit:()=>null,resetAfterCommit:()=>{},preparePortalMount:()=>null,scheduleTimeout:setTimeout,cancelTimeout:clearTimeout,noTimeout:-1,isPrimaryRenderer:!1,getCurrentEventPriority:()=>Re.DefaultEventPriority,getInstanceFromNode:e=>null,beforeActiveInstanceBlur:()=>{},afterActiveInstanceBlur:()=>{},prepareScopeUpdate:()=>{},getInstanceFromScope:()=>{},detachDeletedInstance:()=>{},supportsHydration:!1,appendChild:(e,n)=>{e.add(n)},appendChildToContainer:(e,n)=>{e.add(n)},insertBefore:(e,n,t)=>{e.insertBefore(n,t)},insertInContainerBefore:(e,n,t)=>{e.insertBefore(n,t)},removeChild:(e,n)=>{n.delete()},removeChildFromContainer:(e,n)=>{n.delete()},commitUpdate:(e,n,t,r,a)=>{!function(e,n,t){for(const r in t)Le(r,t)&&t[r]!==n[r]&&e.removeEventListener(Ne[r],t[r]);for(const r in n)Le(r,n)&&t[r]!==n[r]&&e.addEventListener(Ne[r],n[r]);e.initAttributes(n.attribute),"image"===e.type&&e.loadImage(n.attribute.image)}(e,a,r)},hideInstance:e=>{e.setAttribute("visible",!1)},unhideInstance:(e,n)=>{e.setAttribute("visible",!0)},clearContainer:e=>{e.removeAllChild()},commitTextUpdate:(e,n,t)=>{}});function Le(e,n){return e.startsWith("on")&&h(n[e])}Ie.injectIntoDevTools({bundleType:"production"!==process.env.NODE_ENV?1:0,version:f.version,rendererPackageName:"react-vtable"});const{Group:De}=n.VRender,Me=(e,n)=>{const{componentId:t,children:r}=e;if(!c.isValidElement(r))return null;const a=c.useContext(d),{table:o}=a,l="header-custom-layout"===r.props.role,i=c.useRef(new Map),u=c.useCallback((e=>{const n=`${e.col}-${e.row}`;let t;if(i.current.has(n)){const a=i.current.get(n);Oe(r,a,t,e),t=a.containerInfo}else{t=new De({});const a=Ie.createContainer(t,Re.LegacyRoot,null,null,null,"custom",null,null);i.current.set(n,a),Oe(r,a,t,e)}return{rootContainer:t,renderDefault:!!r.props.renderDefault}}),[r]),s=c.useCallback(((e,n)=>{const t=`${e}-${n}`;if(i.current.has(t)){const e=i.current.get(t);Ie.updateContainer(null,e,null),i.current.delete(t)}}),[]);return c.useLayoutEffect((()=>(console.log("init",e,o),()=>{console.log("release",e,o)})),[]),c.useLayoutEffect((()=>{console.log("update props",e,o),o?.checkReactCustomLayout(),o&&!o.reactCustomLayout?.hasReactCreateGraphic(t,l)?(o.reactCustomLayout?.setReactCreateGraphic(t,u,l),o.reactCustomLayout?.setReactRemoveGraphic(t,s,l),o.reactCustomLayout?.updateCustomCell(t,l)):o&&i.current.forEach(((e,n)=>{const[t,a]=n.split("-").map(Number),l=o.getColWidth(t),i=o.getRowHeight(a),u=e,s={col:t,row:a,dataValue:o.getCellOriginValue(t,a),value:o.getCellValue(t,a)||"",rect:{left:0,top:0,right:l,bottom:i,width:l,height:i},table:o},c=u.containerInfo;Oe(r,u,c,s),o.scenegraph.updateNextFrame()}))})),null};function Oe(e,n,t,r){Ie.updateContainer(f.cloneElement(e,{...r}),n,null)}const Ue=(e,n,t,r)=>{const a=["id","updateId","componentIndex","children"],o=t?Object.keys(t).concat(a):a,l=e=>{const n=c.useContext(d),r=f.useRef(null),a=f.useRef(e.updateId);if(e.updateId!==a.current){a.current=e.updateId;!!t&&B(n.table,e,r.current,t)&&(r.current=e)}return c.useEffect((()=>()=>{t&&B(n.table,null,r.current,t)}),[]),je(e.children,e.componentId)};return l.displayName=e,l.parseOption=e=>{const t=P(e,o);if(e.children){const{children:n}=e;f.Children.map(n,((n,r)=>{Fe(n,e,t,o,e.componentId+"-"+r)}))}return{option:t,optionName:n,isSingle:r}},l};function Fe(e,n,t,r,a){if("custom-layout"===e.props.role&&(t.customLayout="react-custom-layout",t.customLayoutComponentId=a),"header-custom-layout"===e.props.role&&(t.headerCustomLayout="react-custom-layout",t.headerCustomLayoutComponentId=a),"ListColumn"===e.type.displayName){t.columns||(t.columns=[]);const o=P(e.props,r);t.columns.push(o),o.componentId=a,e.props.children&&f.Children.map(e.props.children,((e,t)=>{Fe(e,n,o,r,a+"-"+t)}))}}function je(e,n){return(t=e)&&t.$$typeof===Symbol.for("react.element")||Array.isArray(e)?f.Children.map(e,((e,t)=>e.props.children?je(e.props.children,n+"-"+t):"custom-layout"===e.props.role||"header-custom-layout"===e.props.role?f.createElement(Me,{componentId:n},e):null)):null;var t}const Ae=Ue("ListColumn","columns"),He=Ue("PivotColumnDimension","columns"),We=Ue("PivotRowDimension","rows"),$e=Ue("PivotIndicator","indicators"),Be=Ue("PivotColumnHeaderTitle","columnHeaderTitle",void 0,!0),Ve=Ue("PivotRowHeaderTitle","rowHeaderTitle",void 0,!0),Qe=Ue("PivotCorner","corner",void 0,!0),qe=Ue("Menu","menu",void 0,!0),Ye=Ue("Tooltip","tooltip",void 0,!0);function Ge(e,n){return E(e)?e:"string"==typeof e&&e.endsWith("%")?Number(e.slice(0,-1))/100*n:0}e.VTable=r,e.Arc="arc",e.Checkbox="checkbox",e.Circle="circle",e.CustomComponent=e=>{const n=c.useContext(d),{table:t}=n,r=function(e,n){const t=c.useMemo((()=>({...n})),[n]),r=c.useMemo((()=>{const n=R({},e);for(const e in t)void 0===n[e]&&(n[e]=t[e]);return n}),[e,t]);return r}(e,{style:{left:0,top:0},className:"vtable-custom-component",displayMode:"position",x:0,y:0,width:0,height:0,row:0,col:0,anchor:"top-left",dx:0,dy:0}),{displayMode:a,x:o,y:l,width:i,height:u,row:s,col:p,anchor:h,dx:m,dy:v,className:y,children:g,style:b}=r;let S,w,k,E;if("position"===a)S=o+m+"px",w=l+v+"px",k=i+"px",E=u+"px";else if("cell"===a){const e=t&&p>=0&&s>=0?t?.getCellRelativeRect(p,s):{width:0,height:0,left:-9999,top:-9999};k=Ge(i,e.width)+"px",E=Ge(u,e.height)+"px","top-left"===h?(S=e.left+Ge(m,e.width)+"px",w=e.top+Ge(v,e.height)+"px"):"top-right"===h?(S=e.left+Ge(m,e.width)+e.width+"px",w=e.top+Ge(v,e.height)+"px"):"bottom-left"===h?(S=e.left+Ge(m,e.width)+"px",w=e.top+Ge(v,e.height)+e.height+"px"):"bottom-right"===h&&(S=e.left+Ge(m,e.width)+e.width+"px",w=e.top+Ge(v,e.height)+e.height+"px")}const C=R({},b,{position:"absolute",zIndex:1e3,width:k,height:E,left:S,top:w});return f.createElement("div",{className:y,style:C},f.Children.map(g,(e=>e?f.cloneElement(e,{}):e)))},e.CustomLayout=Me,e.Group="group",e.Image="image",e.Line="line",e.ListColumn=Ae,e.ListTable=oe,e.Menu=qe,e.Path="path",e.PivotChart=ie,e.PivotColumnDimension=He,e.PivotColumnHeaderTitle=Be,e.PivotCorner=Qe,e.PivotIndicator=$e,e.PivotRowDimension=We,e.PivotRowHeaderTitle=Ve,e.PivotTable=le,e.Polygon="polygon",e.Radio="radio",e.Rect="rect",e.RichText="richtext",e.Symbol="symbol",e.Tag="tag",e.Text="text",e.Tooltip=Ye,e.registerChartModule=function(e,n){r.register.chartModule(e,n)},e.version="1.5.3-alpha.0"}));
|
|
@@ -5,7 +5,7 @@ export interface BaseComponentProps {
|
|
|
5
5
|
}
|
|
6
6
|
type ComponentProps = BaseComponentProps & {
|
|
7
7
|
updateId?: number;
|
|
8
|
-
componentId?:
|
|
8
|
+
componentId?: string;
|
|
9
9
|
componentIndex?: number;
|
|
10
10
|
};
|
|
11
11
|
export declare const createComponent: <T extends ComponentProps>(componentName: string, optionName: string, supportedEvents?: Record<string, string> | null, isSingle?: boolean) => React.FC<T>;
|
|
@@ -9,7 +9,7 @@ import { bindEventsToTable } from "../eventsUtils";
|
|
|
9
9
|
import { CustomLayout } from "./custom/custom-layout";
|
|
10
10
|
|
|
11
11
|
export const createComponent = (componentName, optionName, supportedEvents, isSingle) => {
|
|
12
|
-
const ignoreKeys = [ "id", "updateId", "
|
|
12
|
+
const ignoreKeys = [ "id", "updateId", "componentIndex", "children" ], notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
13
13
|
const context = useContext(RootTableContext), eventsBinded = React.useRef(null), updateId = React.useRef(props.updateId);
|
|
14
14
|
if (props.updateId !== updateId.current) {
|
|
15
15
|
updateId.current = props.updateId;
|
|
@@ -17,17 +17,14 @@ export const createComponent = (componentName, optionName, supportedEvents, isSi
|
|
|
17
17
|
}
|
|
18
18
|
return useEffect((() => () => {
|
|
19
19
|
supportedEvents && bindEventsToTable(context.table, null, eventsBinded.current, supportedEvents);
|
|
20
|
-
}), []),
|
|
21
|
-
componentIndex: props.componentIndex
|
|
22
|
-
}, child))) : null;
|
|
20
|
+
}), []), parseCustomChildren(props.children, props.componentId);
|
|
23
21
|
};
|
|
24
22
|
return Comp.displayName = componentName, Comp.parseOption = props => {
|
|
25
23
|
const newComponentOption = pickWithout(props, notOptionKeys);
|
|
26
24
|
if (props.children) {
|
|
27
25
|
const {children: children} = props;
|
|
28
|
-
React.Children.map(children, (child => {
|
|
29
|
-
|
|
30
|
-
"header-custom-layout" === child.props.role && (newComponentOption.headerCustomLayout = "react-custom-layout");
|
|
26
|
+
React.Children.map(children, ((child, index) => {
|
|
27
|
+
parseChild(child, props, newComponentOption, notOptionKeys, props.componentId + "-" + index);
|
|
31
28
|
}));
|
|
32
29
|
}
|
|
33
30
|
return {
|
|
@@ -36,4 +33,27 @@ export const createComponent = (componentName, optionName, supportedEvents, isSi
|
|
|
36
33
|
isSingle: isSingle
|
|
37
34
|
};
|
|
38
35
|
}, Comp;
|
|
39
|
-
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function parseChild(child, componentProps, newComponentOption, notOptionKeys, componentId) {
|
|
39
|
+
if ("custom-layout" === child.props.role && (newComponentOption.customLayout = "react-custom-layout",
|
|
40
|
+
newComponentOption.customLayoutComponentId = componentId), "header-custom-layout" === child.props.role && (newComponentOption.headerCustomLayout = "react-custom-layout",
|
|
41
|
+
newComponentOption.headerCustomLayoutComponentId = componentId), "ListColumn" === child.type.displayName) {
|
|
42
|
+
newComponentOption.columns || (newComponentOption.columns = []);
|
|
43
|
+
const childOption = pickWithout(child.props, notOptionKeys);
|
|
44
|
+
newComponentOption.columns.push(childOption), childOption.componentId = componentId,
|
|
45
|
+
child.props.children && React.Children.map(child.props.children, ((child, index) => {
|
|
46
|
+
parseChild(child, componentProps, childOption, notOptionKeys, componentId + "-" + index);
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function parseCustomChildren(children, componentId) {
|
|
52
|
+
return isReactElement(children) || Array.isArray(children) ? React.Children.map(children, ((child, index) => child.props.children ? parseCustomChildren(child.props.children, componentId + "-" + index) : "custom-layout" === child.props.role || "header-custom-layout" === child.props.role ? React.createElement(CustomLayout, {
|
|
53
|
+
componentId: componentId
|
|
54
|
+
}, child) : null)) : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isReactElement(obj) {
|
|
58
|
+
return obj && obj.$$typeof === Symbol.for("react.element");
|
|
59
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/base-component.tsx"],"names":[],"mappings":"AACA,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;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAStD,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,
|
|
1
|
+
{"version":3,"sources":["components/base-component.tsx"],"names":[],"mappings":"AACA,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;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAStD,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,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,GAAQ;IAC9B,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC7D,CAAC","file":"base-component.js","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport 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';\nimport { CustomLayout } from './custom/custom-layout';\n\nexport interface BaseComponentProps {\n id?: string | number;\n children?: React.ReactNode;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number; componentId?: string; componentIndex?: 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', 'componentIndex', 'children'];\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 // children are all custom layout temply\n // return props.children\n // ? React.cloneElement(props.children as ReactElement, { componentIndex: props.componentIndex })\n // : null;\n // if (props.children) {\n // return React.Children.map(props.children as ReactElement, (child: ReactElement) => {\n // if (child.props.role === 'custom-layout' || child.props.role === 'header-custom-layout') {\n // return React.createElement(CustomLayout, { componentId: props.componentId }, child);\n // }\n // });\n // }\n return parseCustomChildren(props.children, props.componentId);\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 // deal width customLayout\n if (props.children) {\n const { children } = props;\n React.Children.map(children as ReactElement, (child: ReactElement, index) => {\n parseChild(child, props, newComponentOption, notOptionKeys, props.componentId + '-' + index);\n });\n }\n // if (props.children && (props.children as React.ReactElement).props.role === 'custom-layout') {\n // (newComponentOption as any).customLayout = 'react-custom-layout';\n // }\n\n return {\n option: newComponentOption,\n optionName,\n isSingle\n };\n };\n\n return Comp;\n};\n\nfunction parseChild(\n child: ReactElement,\n componentProps: any,\n newComponentOption: any,\n notOptionKeys: string[],\n componentId: string\n) {\n if (child.props.role === 'custom-layout') {\n (newComponentOption as any).customLayout = 'react-custom-layout';\n (newComponentOption as any).customLayoutComponentId = componentId;\n }\n if (child.props.role === 'header-custom-layout') {\n (newComponentOption as any).headerCustomLayout = 'react-custom-layout';\n (newComponentOption as any).headerCustomLayoutComponentId = componentId;\n }\n if ((child.type as any).displayName === 'ListColumn') {\n if (!newComponentOption.columns) {\n newComponentOption.columns = [];\n }\n const childOption = pickWithout(child.props, notOptionKeys);\n newComponentOption.columns.push(childOption);\n childOption.componentId = componentId;\n if (child.props.children) {\n React.Children.map(child.props.children as ReactElement, (child: ReactElement, index) => {\n parseChild(child, componentProps, childOption, notOptionKeys, componentId + '-' + index);\n });\n }\n }\n}\n\nfunction parseCustomChildren(children: ReactNode, componentId: string): ReactNode | undefined {\n if (isReactElement(children) || Array.isArray(children)) {\n return React.Children.map(children as ReactElement, (child: ReactElement, index) => {\n if (child.props.children) {\n return parseCustomChildren(child.props.children as ReactElement, componentId + '-' + index);\n } else if (child.props.role === 'custom-layout' || child.props.role === 'header-custom-layout') {\n return React.createElement(CustomLayout, { componentId: componentId }, child);\n }\n return null;\n });\n }\n return null;\n}\n\nfunction isReactElement(obj: any) {\n return obj && obj.$$typeof === Symbol.for('react.element');\n}\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { CustomRenderFunctionArg } from '@visactor/vtable/src/ts-types';
|
|
3
3
|
type CustomLayoutProps = {
|
|
4
|
-
|
|
4
|
+
componentId: string;
|
|
5
5
|
};
|
|
6
6
|
export type CustomLayoutFunctionArg = Partial<CustomRenderFunctionArg> & {
|
|
7
7
|
role?: 'custom-layout' | 'header-custom-layout';
|
|
8
|
+
renderDefault?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export declare const CustomLayout: React.FC<CustomLayoutProps>;
|
|
10
11
|
export {};
|
|
@@ -11,7 +11,7 @@ import { LegacyRoot } from "react-reconciler/constants";
|
|
|
11
11
|
const {Group: Group} = VRender;
|
|
12
12
|
|
|
13
13
|
export const CustomLayout = (props, ref) => {
|
|
14
|
-
const {
|
|
14
|
+
const {componentId: componentId, children: children} = props;
|
|
15
15
|
if (!isValidElement(children)) return null;
|
|
16
16
|
const context = useContext(RootTableContext), {table: table} = context, isHeaderCustomLayout = "header-custom-layout" === children.props.role, container = useRef(new Map), createGraphic = useCallback((args => {
|
|
17
17
|
const key = `${args.col}-${args.row}`;
|
|
@@ -26,7 +26,7 @@ export const CustomLayout = (props, ref) => {
|
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
28
28
|
rootContainer: group,
|
|
29
|
-
renderDefault:
|
|
29
|
+
renderDefault: !!children.props.renderDefault
|
|
30
30
|
};
|
|
31
31
|
}), [ children ]), removeContainer = useCallback(((col, row) => {
|
|
32
32
|
const key = `${col}-${row}`;
|
|
@@ -37,9 +37,9 @@ export const CustomLayout = (props, ref) => {
|
|
|
37
37
|
}), []);
|
|
38
38
|
return useLayoutEffect((() => () => {}), []), useLayoutEffect((() => {
|
|
39
39
|
var _a, _b, _c, _d;
|
|
40
|
-
null == table || table.checkReactCustomLayout(), table && !(null === (_a = table.reactCustomLayout) || void 0 === _a ? void 0 : _a.hasReactCreateGraphic(
|
|
41
|
-
null === (_c = table.reactCustomLayout) || void 0 === _c || _c.setReactRemoveGraphic(
|
|
42
|
-
null === (_d = table.reactCustomLayout) || void 0 === _d || _d.updateCustomCell(
|
|
40
|
+
null == table || table.checkReactCustomLayout(), table && !(null === (_a = table.reactCustomLayout) || void 0 === _a ? void 0 : _a.hasReactCreateGraphic(componentId, isHeaderCustomLayout)) ? (null === (_b = table.reactCustomLayout) || void 0 === _b || _b.setReactCreateGraphic(componentId, createGraphic, isHeaderCustomLayout),
|
|
41
|
+
null === (_c = table.reactCustomLayout) || void 0 === _c || _c.setReactRemoveGraphic(componentId, removeContainer, isHeaderCustomLayout),
|
|
42
|
+
null === (_d = table.reactCustomLayout) || void 0 === _d || _d.updateCustomCell(componentId, isHeaderCustomLayout)) : table && container.current.forEach(((value, key) => {
|
|
43
43
|
const [col, row] = key.split("-").map(Number), width = table.getColWidth(col), height = table.getRowHeight(row), currentContainer = value, args = {
|
|
44
44
|
col: col,
|
|
45
45
|
row: row,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/custom/custom-layout.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChG,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,OAAO,EAAE,UAAU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GAAG;oBACX,GAAG;oBACH,GAAG;oBACH,SAAS,EAAE,KAAK,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC;oBAC7C,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE;oBACzC,IAAI,EAAE;wBACJ,IAAI,EAAE,CAAC;wBACP,GAAG,EAAE,CAAC;wBACN,KAAK,EAAE,KAAK;wBACZ,MAAM,EAAE,MAAM;wBACd,KAAK;wBACL,MAAM;qBACP;oBACD,KAAK;iBACN,CAAC;gBAEF,MAAM,KAAK,GAAG,gBAAgB,CAAC,aAAa,CAAC;gBAC7C,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;gBAEnE,KAAK,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC;YACrC,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,SAAS,yBAAyB,CAAC,QAAsB,EAAE,gBAAqB,EAAE,KAAmB,EAAE,IAAS;IAC9G,UAAU,CAAC,eAAe,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,oBAAO,IAAI,EAAG,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAUhG,CAAC;AAED,SAAS,cAAc,CAAC,GAAG;IACzB,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC7D,CAAC","file":"custom-layout.js","sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\nimport type { PropsWithChildren, ReactElement } 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 = { componentId: string };\n\nexport type CustomLayoutFunctionArg = Partial<CustomRenderFunctionArg> & {\n role?: 'custom-layout' | 'header-custom-layout';\n renderDefault?: boolean;\n};\n\nexport const CustomLayout: React.FC<CustomLayoutProps> = (props: PropsWithChildren<CustomLayoutProps>, ref) => {\n const { componentId, 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: !!children.props.renderDefault\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(componentId, isHeaderCustomLayout)) {\n table.reactCustomLayout?.setReactCreateGraphic(\n componentId,\n createGraphic,\n // container.current,\n isHeaderCustomLayout\n ); // set customLayout function\n table.reactCustomLayout?.setReactRemoveGraphic(componentId, removeContainer, isHeaderCustomLayout); // set customLayout function\n table.reactCustomLayout?.updateCustomCell(componentId, 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: ReactElement, currentContainer: any, group: typeof Group, args: any) {\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,4 +1,4 @@
|
|
|
1
1
|
import type { BaseComponentProps } from '../base-component';
|
|
2
2
|
import type { ColumnDefine } from '@visactor/vtable';
|
|
3
|
-
export type ListColumnProps = ColumnDefine & BaseComponentProps;
|
|
3
|
+
export type ListColumnProps = Omit<ColumnDefine, 'columns'> & BaseComponentProps;
|
|
4
4
|
export declare const ListColumn: import("react").FC<ListColumnProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/list/list-column.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["components/list/list-column.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKpD,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAkB,YAAY,EAAE,SAAS,CAAC,CAAC","file":"list-column.js","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport type { BaseComponentProps } from '../base-component';\nimport { createComponent } from '../base-component';\nimport type { ColumnDefine } from '@visactor/vtable';\n\nexport type ListColumnProps = Omit<ColumnDefine, 'columns'> & BaseComponentProps;\n\nexport const ListColumn = createComponent<ListColumnProps>('ListColumn', 'columns');\n"]}
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
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,cAAc,UAAU,CAAC;AAEzB,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","file":"index.js","sourcesContent":["export * from './tables';\nexport * from './components';\nexport * from './vtable';\n\nexport const version = \"1.5.
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AAEzB,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","file":"index.js","sourcesContent":["export * from './tables';\nexport * from './components';\nexport * from './vtable';\n\nexport const version = \"1.5.3-alpha.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/react-vtable",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3-alpha.0",
|
|
4
4
|
"description": "The react version of VTable",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@visactor/vtable": "1.5.
|
|
46
|
+
"@visactor/vtable": "1.5.3-alpha.0",
|
|
47
47
|
"@visactor/vutils": "~0.18.9",
|
|
48
48
|
"react-is": "^18.2.0",
|
|
49
49
|
"react-reconciler": "0.29.2"
|