@visactor/react-vtable 1.10.6-alpha.1 → 1.11.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/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/table-components/custom/custom-layout.js +2 -1
- package/cjs/table-components/custom/custom-layout.js.map +1 -1
- package/dist/react-vtable.js +66 -31
- package/dist/react-vtable.min.js +2 -2
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/table-components/custom/custom-layout.js +2 -1
- package/es/table-components/custom/custom-layout.js.map +1 -1
- package/package.json +6 -6
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,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAE7B,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAE7B,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","file":"index.js","sourcesContent":["export * from './tables';\nexport * from './table-components';\nexport * from './components';\n\nexport const version = \"1.11.0\";\n"]}
|
|
@@ -12,7 +12,8 @@ export const CustomLayout = (props, ref) => {
|
|
|
12
12
|
const {componentId: componentId, children: children} = props;
|
|
13
13
|
if (!isValidElement(children)) return null;
|
|
14
14
|
const context = useContext(RootTableContext), {table: table} = context, isHeaderCustomLayout = "header-custom-layout" === children.props.role, container = useRef(new Map), createGraphic = useCallback((args => {
|
|
15
|
-
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const key = `${null !== (_a = args.originCol) && void 0 !== _a ? _a : args.col}-${null !== (_b = args.originRow) && void 0 !== _b ? _b : args.row}`;
|
|
16
17
|
let group;
|
|
17
18
|
if (container.current.has(key)) {
|
|
18
19
|
const currentContainer = container.current.get(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["table-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,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AASxD,MAAM,CAAC,MAAM,YAAY,GAAgC,CAAC,KAA2C,EAAE,GAAG,EAAE,EAAE;IAC5G,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,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,GAAG,MAAM,CAAyB,IAAI,GAAG,EAAE,CAAC,CAAC;IAG5D,MAAM,aAAa,GAAqB,WAAW,CACjD,IAAI,CAAC,EAAE;QACL,MAAM,GAAG,GAAG,GAAI,IAAY,CAAC,SAAS,IAAK,IAAY,CAAC,SAAS,EAAE,CAAC;QACpE,IAAI,KAAK,CAAC;QACV,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAC9B,MAAM,gBAAgB,GAAG,SAAS,CAAC,OA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vD,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChG,OAAO,IAAI,CAAC;AACd,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 { Group } from '@visactor/vtable/es/vrender';\nimport type { ICustomLayoutFuc, CustomRenderFunctionArg } from '@visactor/vtable/es/ts-types';\nimport type { FiberRoot } from 'react-reconciler';\nimport { reconcilor } from './reconciler';\nimport { LegacyRoot } from 'react-reconciler/constants';\n\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 as any).originCol}-${(args as any).originRow}`;\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, args);\n group = currentContainer.containerInfo;\n // 这里更新group,可能会残留dx dy\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, 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 const removeAllContainer = useCallback(() => {\n container.current.forEach((value, key) => {\n const currentContainer = value;\n reconcilor.updateContainer(null, currentContainer, null);\n });\n container.current.clear();\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(removeAllContainer); // 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 table.reactCustomLayout?.setReactCreateGraphic(\n componentId,\n createGraphic,\n // container.current,\n isHeaderCustomLayout\n ); // update customLayout function\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 { width, height } = getCellRect(col, row, table);\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, 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, 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 getCellRect(col: number, row: number, table: any) {\n const range = table.getCellRange(col, row);\n const rect = table.getCellsRect(range.start.col, range.start.row, range.end.col, range.end.row);\n return rect;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["table-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,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AASxD,MAAM,CAAC,MAAM,YAAY,GAAgC,CAAC,KAA2C,EAAE,GAAG,EAAE,EAAE;IAC5G,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;I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;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,IAAI,CAAC,CAAC;gBAE5D,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,IAAS;IACzF,UAAU,CAAC,eAAe,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,oBAAO,IAAI,EAAG,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAUhG,CAAC;AAED,SAAS,WAAW,CAAC,GAAW,EAAE,GAAW,EAAE,KAAU;IACvD,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChG,OAAO,IAAI,CAAC;AACd,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 { Group } from '@visactor/vtable/es/vrender';\nimport type { ICustomLayoutFuc, CustomRenderFunctionArg } from '@visactor/vtable/es/ts-types';\nimport type { FiberRoot } from 'react-reconciler';\nimport { reconcilor } from './reconciler';\nimport { LegacyRoot } from 'react-reconciler/constants';\n\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.originCol ?? args.col}-${args.originRow ?? 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, args);\n group = currentContainer.containerInfo;\n // 这里更新group,可能会残留dx dy\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, 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 const removeAllContainer = useCallback(() => {\n container.current.forEach((value, key) => {\n const currentContainer = value;\n reconcilor.updateContainer(null, currentContainer, null);\n });\n container.current.clear();\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(removeAllContainer); // 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 table.reactCustomLayout?.setReactCreateGraphic(\n componentId,\n createGraphic,\n // container.current,\n isHeaderCustomLayout\n ); // update customLayout function\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 { width, height } = getCellRect(col, row, table);\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, 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, 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 getCellRect(col: number, row: number, table: any) {\n const range = table.getCellRange(col, row);\n const rect = table.getCellsRect(range.start.col, range.start.row, range.end.col, range.end.row);\n return rect;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/react-vtable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "The react version of VTable",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@visactor/vtable": "1.10.6-alpha.1",
|
|
47
46
|
"@visactor/vutils": "~0.18.14",
|
|
48
47
|
"react-is": "^18.2.0",
|
|
49
|
-
"react-reconciler": "0.29.2"
|
|
48
|
+
"react-reconciler": "0.29.2",
|
|
49
|
+
"@visactor/vtable": "1.11.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@visactor/vchart": "1.12.
|
|
52
|
+
"@visactor/vchart": "1.12.11",
|
|
53
53
|
"@rushstack/eslint-patch": "~1.1.4",
|
|
54
54
|
"react": "^18.0.0",
|
|
55
55
|
"react-dom": "^18.0.0",
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"@arco-design/web-react": "2.60.2",
|
|
93
93
|
"@types/react-reconciler": "0.28.8",
|
|
94
94
|
"@internal/bundler": "0.0.1",
|
|
95
|
-
"@internal/
|
|
96
|
-
"@internal/
|
|
95
|
+
"@internal/eslint-config": "0.0.1",
|
|
96
|
+
"@internal/ts-config": "0.0.1"
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
99
|
"start": "vite ./demo",
|