@visactor/react-vtable 1.3.3 → 1.4.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/components/base-component.d.ts +2 -0
- package/cjs/components/base-component.js +21 -10
- package/cjs/components/base-component.js.map +1 -1
- package/cjs/components/custom/component.d.ts +16 -0
- package/cjs/components/custom/component.js +7 -0
- package/cjs/components/custom/component.js.map +1 -0
- package/cjs/components/custom/custom-layout.d.ts +10 -0
- package/cjs/components/custom/custom-layout.js +96 -0
- package/cjs/components/custom/custom-layout.js.map +1 -0
- package/cjs/components/custom/graphic.d.ts +32 -0
- package/cjs/components/custom/graphic.js +9 -0
- package/cjs/components/custom/graphic.js.map +1 -0
- package/cjs/components/custom/reconciler.d.ts +5 -0
- package/cjs/components/custom/reconciler.js +105 -0
- package/cjs/components/custom/reconciler.js.map +1 -0
- package/cjs/components/custom/vtable-browser-env-contribution.d.ts +2 -0
- package/cjs/components/custom/vtable-browser-env-contribution.js +35 -0
- package/cjs/components/custom/vtable-browser-env-contribution.js.map +1 -0
- package/cjs/components/custom/vtable-react-attribute-plugin.d.ts +17 -0
- package/cjs/components/custom/vtable-react-attribute-plugin.js +92 -0
- package/cjs/components/custom/vtable-react-attribute-plugin.js.map +1 -0
- package/cjs/components/index.d.ts +3 -0
- package/cjs/components/index.js +25 -1
- package/cjs/components/index.js.map +1 -1
- package/cjs/containers/withContainer.js +2 -1
- package/cjs/eventsUtils.js +1 -2
- package/cjs/index.d.ts +2 -3
- package/cjs/index.js +4 -19
- package/cjs/index.js.map +1 -1
- package/cjs/tables/base-table.d.ts +2 -1
- package/cjs/tables/base-table.js +14 -5
- package/cjs/tables/base-table.js.map +1 -1
- package/cjs/vtable.d.ts +2 -0
- package/cjs/vtable.js +35 -0
- package/cjs/vtable.js.map +1 -0
- package/dist/react-vtable.js +10115 -137
- package/dist/react-vtable.min.js +30 -3
- package/es/components/base-component.d.ts +2 -0
- package/es/components/base-component.js +22 -9
- package/es/components/base-component.js.map +1 -1
- package/es/components/custom/component.d.ts +16 -0
- package/es/components/custom/component.js +6 -0
- package/es/components/custom/component.js.map +1 -0
- package/es/components/custom/custom-layout.d.ts +10 -0
- package/es/components/custom/custom-layout.js +70 -0
- package/es/components/custom/custom-layout.js.map +1 -0
- package/es/components/custom/graphic.d.ts +32 -0
- package/es/components/custom/graphic.js +22 -0
- package/es/components/custom/graphic.js.map +1 -0
- package/es/components/custom/reconciler.d.ts +5 -0
- package/es/components/custom/reconciler.js +105 -0
- package/es/components/custom/reconciler.js.map +1 -0
- package/es/components/custom/vtable-browser-env-contribution.d.ts +2 -0
- package/es/components/custom/vtable-browser-env-contribution.js +33 -0
- package/es/components/custom/vtable-browser-env-contribution.js.map +1 -0
- package/es/components/custom/vtable-react-attribute-plugin.d.ts +17 -0
- package/es/components/custom/vtable-react-attribute-plugin.js +86 -0
- package/es/components/custom/vtable-react-attribute-plugin.js.map +1 -0
- package/es/components/index.d.ts +3 -0
- package/es/components/index.js +6 -0
- package/es/components/index.js.map +1 -1
- package/es/containers/withContainer.js +2 -1
- package/es/eventsUtils.js +1 -2
- package/es/index.d.ts +2 -3
- package/es/index.js +3 -4
- package/es/index.js.map +1 -1
- package/es/tables/base-table.d.ts +2 -1
- package/es/tables/base-table.js +17 -4
- package/es/tables/base-table.js.map +1 -1
- package/es/vtable.d.ts +2 -0
- package/es/vtable.js +4 -0
- package/es/vtable.js.map +1 -0
- package/package.json +7 -5
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface BaseComponentProps {
|
|
3
3
|
id?: string | number;
|
|
4
|
+
children?: React.ReactNode;
|
|
4
5
|
}
|
|
5
6
|
type ComponentProps = BaseComponentProps & {
|
|
6
7
|
updateId?: number;
|
|
7
8
|
componentId?: number;
|
|
9
|
+
componentIndex?: number;
|
|
8
10
|
};
|
|
9
11
|
export declare const createComponent: <T extends ComponentProps>(componentName: string, optionName: string, supportedEvents?: Record<string, string> | null, isSingle?: boolean) => React.FC<T>;
|
|
10
12
|
export {};
|
|
@@ -33,8 +33,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
33
33
|
value: !0
|
|
34
34
|
}), exports.createComponent = void 0;
|
|
35
35
|
|
|
36
|
-
const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vutils"), table_1 = __importDefault(require("../context/table")), eventsUtils_1 = require("../eventsUtils"), createComponent = (componentName, optionName, supportedEvents, isSingle) => {
|
|
37
|
-
const ignoreKeys = [ "id", "updateId", "componentId" ], notOptionKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
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", "componentId", "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,14 +42,25 @@ 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
|
-
}), []),
|
|
45
|
+
}), []), props.children ? react_1.default.Children.map(props.children, (child => react_1.default.createElement(custom_layout_1.CustomLayout, {
|
|
46
|
+
componentIndex: props.componentIndex
|
|
47
|
+
}, child))) : null;
|
|
46
48
|
};
|
|
47
|
-
return Comp.displayName = componentName, Comp.parseOption = props =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
return Comp.displayName = componentName, Comp.parseOption = props => {
|
|
50
|
+
const newComponentOption = (0, vutils_1.pickWithout)(props, notOptionKeys);
|
|
51
|
+
if (props.children) {
|
|
52
|
+
const {children: children} = props;
|
|
53
|
+
react_1.default.Children.map(children, (child => {
|
|
54
|
+
"custom-layout" === child.props.role && (newComponentOption.customLayout = "react-custom-layout"),
|
|
55
|
+
"header-custom-layout" === child.props.role && (newComponentOption.headerCustomLayout = "react-custom-layout");
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
option: newComponentOption,
|
|
60
|
+
optionName: optionName,
|
|
61
|
+
isSingle: isSingle
|
|
62
|
+
};
|
|
63
|
+
}, Comp;
|
|
52
64
|
};
|
|
53
65
|
|
|
54
|
-
exports.createComponent = createComponent;
|
|
55
|
-
//# sourceMappingURL=base-component.js.map
|
|
66
|
+
exports.createComponent = createComponent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/base-component.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
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,aAAa,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;IACnF,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,I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AG,aAAa,CAAC;IAEhC,IAAY,CAAC,WAAW,GAAG,CAAC,KAAsD,EAAE,EAAE;QACrF,MAAM,kBAAkB,GAAe,IAAA,oBAAW,EAAI,KAAK,EAAE,aAAa,CAAC,CAAC;QAG5E,IAAI,KAAK,CAAC,QAAQ,EAAE;YAClB,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;YAC3B,eAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAwB,EAAE,CAAC,KAAmB,EAAE,EAAE;gBACnE,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE;oBACvC,kBAA0B,CAAC,YAAY,GAAG,qBAAqB,CAAC;iBAClE;gBACD,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE;oBAC9C,kBAA0B,CAAC,kBAAkB,GAAG,qBAAqB,CAAC;iBACxE;YACH,CAAC,CAAC,CAAC;SACJ;QAKD,OAAO;YACL,MAAM,EAAE,kBAAkB;YAC1B,UAAU;YACV,QAAQ;SACT,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAvFW,QAAA,eAAe,mBAuF1B","file":"base-component.js","sourcesContent":["import type { ReactElement } 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?: number; 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', 'componentId', '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 return React.createElement(CustomLayout, { componentIndex: props.componentIndex }, child);\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 // deal width customLayout\n if (props.children) {\n const { children } = props;\n React.Children.map(children as ReactElement, (child: ReactElement) => {\n if (child.props.role === 'custom-layout') {\n (newComponentOption as any).customLayout = 'react-custom-layout';\n }\n if (child.props.role === 'header-custom-layout') {\n (newComponentOption as any).headerCustomLayout = 'react-custom-layout';\n }\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\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"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 RadioAttributes = VRender.RadioAttributes;
|
|
6
|
+
type CheckboxAttributes = VRender.CheckboxAttributes;
|
|
7
|
+
type IEventParamsType = VRender.IEventParamsType;
|
|
8
|
+
type GraphicProps<IGraphicGraphicAttribute> = {
|
|
9
|
+
attribute: IGraphicGraphicAttribute;
|
|
10
|
+
ref?: Ref<IGraphic>;
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
} & IEventParamsType;
|
|
13
|
+
export declare const Tag: (props: GraphicProps<TagAttributes>) => ReactElement<GraphicProps<TagAttributes>, JSXElementConstructor<GraphicProps<TagAttributes>>>;
|
|
14
|
+
export declare const Radio: (props: GraphicProps<RadioAttributes>) => ReactElement<GraphicProps<RadioAttributes>, JSXElementConstructor<GraphicProps<RadioAttributes>>>;
|
|
15
|
+
export declare const Checkbox: (props: GraphicProps<CheckboxAttributes>) => ReactElement<GraphicProps<CheckboxAttributes>, JSXElementConstructor<GraphicProps<CheckboxAttributes>>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/custom/component.ts"],"names":[],"mappings":";;;AAca,QAAA,GAAG,GAEqF,KAAY,CAAC;AAErG,QAAA,KAAK,GAEuF,OAAc,CAAC;AAE3G,QAAA,QAAQ,GAGnB,UAAiB,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 RadioAttributes = VRender.RadioAttributes;\ntype CheckboxAttributes = VRender.CheckboxAttributes;\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\nexport const Radio: (\n props: GraphicProps<RadioAttributes>\n) => ReactElement<GraphicProps<RadioAttributes>, JSXElementConstructor<GraphicProps<RadioAttributes>>> = 'radio' as any;\n\nexport const Checkbox: (\n props: GraphicProps<CheckboxAttributes>\n) => ReactElement<GraphicProps<CheckboxAttributes>, JSXElementConstructor<GraphicProps<CheckboxAttributes>>> =\n 'checkbox' as any;\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,96 @@
|
|
|
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;
|
|
@@ -0,0 +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;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,GAAG,IAAA,cAAM,EAAyB,IAAI,GAAG,EAAE,CAAC,CAAC;IAG5D,MAAM,aAAa,GAAqB,IAAA,mBAAW,EACjD,IAAI,CAAC,EAAE;QACL,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QACtC,IAAI,KAAK,CAAC;QACV,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAC9B,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEpD,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,CAAC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I,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;AA7GW,QAAA,YAAY,gBA6GvB;AAEF,SAAS,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI;IACxE,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 } 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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __importDefault = this && this.__importDefault || function(mod) {
|
|
4
|
+
return mod && mod.__esModule ? mod : {
|
|
5
|
+
default: mod
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: !0
|
|
11
|
+
}), exports.reconcilor = void 0;
|
|
12
|
+
|
|
13
|
+
const vtable_1 = require("@visactor/vtable"), vutils_1 = require("@visactor/vutils"), react_1 = __importDefault(require("react")), react_reconciler_1 = __importDefault(require("react-reconciler")), constants_js_1 = require("react-reconciler/constants.js"), {application: application, createText: createText, REACT_TO_CANOPUS_EVENTS: REACT_TO_CANOPUS_EVENTS, Tag: Tag} = vtable_1.VRender;
|
|
14
|
+
|
|
15
|
+
function createGraphic(type, props) {
|
|
16
|
+
if ("tag" === type) {
|
|
17
|
+
return new Tag(props.attribute);
|
|
18
|
+
}
|
|
19
|
+
if (!application.graphicService.creator[type]) return;
|
|
20
|
+
return application.graphicService.creator[type](props.attribute);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isEventProp(key, props) {
|
|
24
|
+
return key.startsWith("on") && (0, vutils_1.isFunction)(props[key]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function bindEventsToGraphic(graphic, props) {
|
|
28
|
+
for (const key in props) isEventProp(key, props) && graphic.addEventListener(REACT_TO_CANOPUS_EVENTS[key], props[key]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function updateGraphicProps(graphic, newProps, oldProps) {
|
|
32
|
+
for (const propKey in oldProps) isEventProp(propKey, oldProps) && oldProps[propKey] !== newProps[propKey] && graphic.removeEventListener(REACT_TO_CANOPUS_EVENTS[propKey], oldProps[propKey]);
|
|
33
|
+
for (const propKey in newProps) isEventProp(propKey, newProps) && oldProps[propKey] !== newProps[propKey] && graphic.addEventListener(REACT_TO_CANOPUS_EVENTS[propKey], newProps[propKey]);
|
|
34
|
+
graphic.initAttributes(newProps.attribute), "image" === graphic.type && graphic.loadImage(newProps.attribute.image);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=reconciler.js.map
|
|
38
|
+
exports.reconcilor = (0, react_reconciler_1.default)({
|
|
39
|
+
supportsMutation: !0,
|
|
40
|
+
supportsPersistence: !1,
|
|
41
|
+
createInstance: (type, props, instance) => {
|
|
42
|
+
const graphic = createGraphic(type, props);
|
|
43
|
+
if (graphic) return bindEventsToGraphic(graphic, props), graphic;
|
|
44
|
+
},
|
|
45
|
+
createTextInstance: (text, instance) => {},
|
|
46
|
+
appendInitialChild: (parentInstance, childInstance) => {
|
|
47
|
+
parentInstance.add(childInstance);
|
|
48
|
+
},
|
|
49
|
+
finalizeInitialChildren: () => !1,
|
|
50
|
+
prepareUpdate: () => !0,
|
|
51
|
+
shouldSetTextContent: () => !1,
|
|
52
|
+
getRootHostContext: () => null,
|
|
53
|
+
getChildHostContext: () => null,
|
|
54
|
+
getPublicInstance: instance => instance,
|
|
55
|
+
prepareForCommit: () => null,
|
|
56
|
+
resetAfterCommit: () => {},
|
|
57
|
+
preparePortalMount: () => null,
|
|
58
|
+
scheduleTimeout: setTimeout,
|
|
59
|
+
cancelTimeout: clearTimeout,
|
|
60
|
+
noTimeout: -1,
|
|
61
|
+
isPrimaryRenderer: !1,
|
|
62
|
+
getCurrentEventPriority: () => constants_js_1.DefaultEventPriority,
|
|
63
|
+
getInstanceFromNode: node => null,
|
|
64
|
+
beforeActiveInstanceBlur: () => {},
|
|
65
|
+
afterActiveInstanceBlur: () => {},
|
|
66
|
+
prepareScopeUpdate: () => {},
|
|
67
|
+
getInstanceFromScope: () => {},
|
|
68
|
+
detachDeletedInstance: () => {},
|
|
69
|
+
supportsHydration: !1,
|
|
70
|
+
appendChild: (parentInstance, child) => {
|
|
71
|
+
parentInstance.add(child);
|
|
72
|
+
},
|
|
73
|
+
appendChildToContainer: (container, child) => {
|
|
74
|
+
container.add(child);
|
|
75
|
+
},
|
|
76
|
+
insertBefore: (parentInstance, child, beforeChild) => {
|
|
77
|
+
parentInstance.insertBefore(child, beforeChild);
|
|
78
|
+
},
|
|
79
|
+
insertInContainerBefore: (parentInstance, child, beforeChild) => {
|
|
80
|
+
parentInstance.insertBefore(child, beforeChild);
|
|
81
|
+
},
|
|
82
|
+
removeChild: (parentInstance, child) => {
|
|
83
|
+
child.delete();
|
|
84
|
+
},
|
|
85
|
+
removeChildFromContainer: (parentInstance, child) => {
|
|
86
|
+
child.delete();
|
|
87
|
+
},
|
|
88
|
+
commitUpdate: (instance, updatePayload, type, oldProps, newProps) => {
|
|
89
|
+
updateGraphicProps(instance, newProps, oldProps);
|
|
90
|
+
},
|
|
91
|
+
hideInstance: instance => {
|
|
92
|
+
instance.setAttribute("visible", !1);
|
|
93
|
+
},
|
|
94
|
+
unhideInstance: (instance, props) => {
|
|
95
|
+
instance.setAttribute("visible", !0);
|
|
96
|
+
},
|
|
97
|
+
clearContainer: container => {
|
|
98
|
+
container.removeAllChild();
|
|
99
|
+
},
|
|
100
|
+
commitTextUpdate: (textInstance, oldText, newText) => {}
|
|
101
|
+
}), exports.reconcilor.injectIntoDevTools({
|
|
102
|
+
bundleType: "production" !== process.env.NODE_ENV ? 1 : 0,
|
|
103
|
+
version: react_1.default.version,
|
|
104
|
+
rendererPackageName: "react-vtable"
|
|
105
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/custom/reconciler.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA2C;AAC3C,6CAA8C;AAC9C,kDAA0B;AAC1B,wEAA+C;AAC/C,gEAAqE;AAErE,MAAM,EAAE,WAAW,EAAE,UAAU,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AmB,CAAC,OAAgB,EAAE,KAAU;IACvD,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,IAAI,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;YAC3B,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;SACpE;KACF;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAgB,EAAE,QAAa,EAAE,QAAa;IAExE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,IAAI,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC7E,OAAO,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;SAClF;KACF;IACD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,IAAI,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC7E,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;SAC/E;KACF;IAGD,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE;QAC5B,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KAC7C;AACH,CAAC","file":"reconciler.js","sourcesContent":["import { VRender } from '@visactor/vtable';\nimport { isFunction } from '@visactor/vutils';\nimport React from 'react';\nimport ReactReconciler from 'react-reconciler';\nimport { DefaultEventPriority } from 'react-reconciler/constants.js';\n\nconst { application, createText, REACT_TO_CANOPUS_EVENTS, Tag } = VRender;\ntype Graphic = VRender.Graphic;\ntype Instance = Graphic;\n\nexport const reconcilor = ReactReconciler({\n supportsMutation: true,\n supportsPersistence: false,\n\n createInstance: (type: string, props: any, instance) => {\n const graphic = createGraphic(type, props);\n if (graphic) {\n bindEventsToGraphic(graphic, props);\n } else {\n return undefined;\n // createInstance\n // graphic = createGraphic('group', {});\n }\n return graphic;\n },\n\n createTextInstance: (text, instance) => {\n // const textGraphic = createText({ text });\n // return textGraphic;\n // debugger;\n // return document.createTextNode(text);\n return undefined;\n },\n\n appendInitialChild: (parentInstance: Instance, childInstance: Instance) => {\n parentInstance.add(childInstance);\n },\n\n finalizeInitialChildren: () => false,\n\n prepareUpdate: () => true,\n\n shouldSetTextContent: () => false,\n\n getRootHostContext: () => null,\n\n getChildHostContext: () => null,\n\n getPublicInstance: (instance: Instance) => {\n return instance;\n },\n\n prepareForCommit: () => null,\n\n resetAfterCommit: () => undefined,\n\n preparePortalMount: () => null,\n\n // eslint-disable-next-line no-undef\n scheduleTimeout: setTimeout,\n // eslint-disable-next-line no-undef\n cancelTimeout: clearTimeout,\n\n noTimeout: -1,\n isPrimaryRenderer: false,\n\n getCurrentEventPriority: () => DefaultEventPriority,\n\n getInstanceFromNode: node => null,\n\n beforeActiveInstanceBlur: () => undefined,\n\n afterActiveInstanceBlur: () => undefined,\n\n prepareScopeUpdate: () => undefined,\n\n getInstanceFromScope: () => undefined,\n\n detachDeletedInstance: () => undefined,\n\n supportsHydration: false,\n\n appendChild: (parentInstance: Instance, child: Instance) => {\n parentInstance.add(child);\n },\n appendChildToContainer: (container: Instance, child: Instance) => {\n container.add(child);\n },\n\n insertBefore: (parentInstance: Instance, child: Instance, beforeChild: Instance) => {\n parentInstance.insertBefore(child, beforeChild);\n },\n\n insertInContainerBefore: (parentInstance: Instance, child: Instance, beforeChild: Instance) => {\n parentInstance.insertBefore(child, beforeChild);\n },\n\n removeChild: (parentInstance: Instance, child: Instance) => {\n child.delete();\n },\n\n removeChildFromContainer: (parentInstance: Instance, child: Instance) => {\n child.delete();\n },\n\n commitUpdate: (instance, updatePayload, type, oldProps, newProps) => {\n updateGraphicProps(instance, newProps, oldProps);\n },\n\n hideInstance: (instance: Instance) => {\n instance.setAttribute('visible', false);\n },\n\n unhideInstance: (instance, props) => {\n instance.setAttribute('visible', true);\n },\n\n clearContainer: (container: Instance) => {\n container.removeAllChild();\n },\n\n commitTextUpdate: (textInstance: any, oldText: string, newText: string) => {\n // debugger;\n }\n});\n\nreconcilor.injectIntoDevTools({\n // findFiberByHostInstance: () => {},\n // @ts-ignore\n // eslint-disable-next-line no-undef\n bundleType: process.env.NODE_ENV !== 'production' ? 1 : 0,\n version: React.version,\n rendererPackageName: 'react-vtable'\n});\n\nfunction createGraphic(type: string, props: any) {\n // may have unwanted onxxx prop\n if (type === 'tag') {\n const tag = new Tag(props.attribute);\n return tag;\n } else if (!application.graphicService.creator[type]) {\n return;\n }\n const graphic = application.graphicService.creator[type]((props as any).attribute);\n return graphic;\n}\n\nfunction isEventProp(key: string, props: any) {\n return key.startsWith('on') && isFunction(props[key]);\n}\n\nfunction bindEventsToGraphic(graphic: Graphic, props: any) {\n for (const key in props) {\n if (isEventProp(key, props)) {\n graphic.addEventListener(REACT_TO_CANOPUS_EVENTS[key], props[key]);\n }\n }\n}\n\nfunction updateGraphicProps(graphic: Graphic, newProps: any, oldProps: any) {\n // deal width event update\n for (const propKey in oldProps) {\n if (isEventProp(propKey, oldProps) && oldProps[propKey] !== newProps[propKey]) {\n graphic.removeEventListener(REACT_TO_CANOPUS_EVENTS[propKey], oldProps[propKey]);\n }\n }\n for (const propKey in newProps) {\n if (isEventProp(propKey, newProps) && oldProps[propKey] !== newProps[propKey]) {\n graphic.addEventListener(REACT_TO_CANOPUS_EVENTS[propKey], newProps[propKey]);\n }\n }\n\n // update all attribute\n graphic.initAttributes(newProps.attribute);\n if (graphic.type === 'image') {\n graphic.loadImage(newProps.attribute.image);\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.reactEnvModule = void 0;
|
|
6
|
+
|
|
7
|
+
const vtable_1 = require("@visactor/vtable"), vutils_1 = require("@visactor/vutils"), {ContainerModule: ContainerModule, EnvContribution: EnvContribution, BrowserEnvContribution: BrowserEnvContribution} = vtable_1.VRender;
|
|
8
|
+
|
|
9
|
+
exports.reactEnvModule = new ContainerModule(((bind, unbind, isBound, rebind) => {
|
|
10
|
+
bind(VTableBrowserEnvContribution).toSelf().inSingletonScope(), isBound(EnvContribution) ? rebind(EnvContribution).toService(VTableBrowserEnvContribution) : bind(EnvContribution).toService(VTableBrowserEnvContribution);
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
class VTableBrowserEnvContribution extends BrowserEnvContribution {
|
|
14
|
+
updateDom(dom, params) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const tableDiv = dom.parentElement;
|
|
17
|
+
if (tableDiv) {
|
|
18
|
+
const top = parseInt(params.style.top, 10), left = parseInt(params.style.left, 10);
|
|
19
|
+
let domWidth, domHeight;
|
|
20
|
+
if (dom.style.display = "none") {
|
|
21
|
+
const cellGroup = (0, vtable_1.getTargetCell)(params.graphic);
|
|
22
|
+
domWidth = null !== (_a = cellGroup.attribute.width) && void 0 !== _a ? _a : 1,
|
|
23
|
+
domHeight = null !== (_b = cellGroup.attribute.height) && void 0 !== _b ? _b : 1;
|
|
24
|
+
} else domWidth = dom.offsetWidth, domHeight = dom.offsetHeight;
|
|
25
|
+
if (top + domHeight < 0 || left + domWidth < 0 || top > tableDiv.offsetHeight || left > tableDiv.offsetWidth) return dom.style.display = "none",
|
|
26
|
+
!1;
|
|
27
|
+
}
|
|
28
|
+
const {width: width, height: height, style: style} = params;
|
|
29
|
+
return style && ((0, vutils_1.isString)(style) ? dom.setAttribute("style", style) : Object.keys(style).forEach((k => {
|
|
30
|
+
dom.style[k] = style[k];
|
|
31
|
+
}))), null != width && (dom.style.width = `${width}px`), null != height && (dom.style.height = `${height}px`),
|
|
32
|
+
!0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=vtable-browser-env-contribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["components/custom/vtable-browser-env-contribution.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAC1D,6CAA4C;AAE5C,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,sBAAsB,EAAE,GAAG,gBAAO,CAAC;AAGhE,QAAA,cAAc,GAAG,IAAI,eAAe,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;IAClF,IAAI,CAAC,4BAA4B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC/D,IAAI,OAAO,CAAC,eAAe,CAAC,EAAE;QAC5B,MAAM,CAAC,eAAe,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;KACjE;SAAM;QACL,IAAI,CAAC,eAAe,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;KAC/D;AACH,CAAC,CAAC,CAAC;AAEH,MAAM,4BAA6B,SAAQ,sBAAsB;IAC/D,SAAS,CAAC,GAAgB,EAAE,MAA2B;;QACrD,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC;QACnC,IAAI,QAAQ,EAAE;YACZ,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC3C,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAE7C,IAAI,QAAQ,CAAC;YACb,IAAI,SAAS,CAAC;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,EAAE;g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CAAC;IACd,CAAC;CACF","file":"vtable-browser-env-contribution.js","sourcesContent":["import { getTargetCell, VRender } from '@visactor/vtable';\nimport { isString } from '@visactor/vutils';\n\nconst { ContainerModule, EnvContribution, BrowserEnvContribution } = VRender;\ntype CreateDOMParamsType = VRender.CreateDOMParamsType;\n\nexport const reactEnvModule = new ContainerModule((bind, unbind, isBound, rebind) => {\n bind(VTableBrowserEnvContribution).toSelf().inSingletonScope();\n if (isBound(EnvContribution)) {\n rebind(EnvContribution).toService(VTableBrowserEnvContribution);\n } else {\n bind(EnvContribution).toService(VTableBrowserEnvContribution);\n }\n});\n\nclass VTableBrowserEnvContribution extends BrowserEnvContribution {\n updateDom(dom: HTMLElement, params: CreateDOMParamsType): boolean {\n const tableDiv = dom.parentElement;\n if (tableDiv) {\n const top = parseInt(params.style.top, 10);\n const left = parseInt(params.style.left, 10);\n\n let domWidth;\n let domHeight;\n if ((dom.style.display = 'none')) {\n const cellGroup = getTargetCell(params.graphic);\n domWidth = cellGroup.attribute.width ?? 1;\n domHeight = cellGroup.attribute.height ?? 1;\n } else {\n domWidth = dom.offsetWidth;\n domHeight = dom.offsetHeight;\n }\n if (top + domHeight < 0 || left + domWidth < 0 || top > tableDiv.offsetHeight || left > tableDiv.offsetWidth) {\n dom.style.display = 'none';\n return false;\n }\n }\n\n const { width, height, style } = params;\n\n if (style) {\n if (isString(style)) {\n dom.setAttribute('style', style);\n } else {\n Object.keys(style).forEach(k => {\n dom.style[k] = style[k];\n });\n }\n }\n if (width != null) {\n dom.style.width = `${width}px`;\n }\n if (height != null) {\n dom.style.height = `${height}px`;\n }\n\n return true;\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VRender } from '@visactor/vtable';
|
|
2
|
+
declare const ReactAttributePlugin: typeof VRender.ReactAttributePlugin;
|
|
3
|
+
type CommonDomOptions = VRender.CommonDomOptions;
|
|
4
|
+
type CreateDOMParamsType = VRender.CreateDOMParamsType;
|
|
5
|
+
type IGraphic = VRender.CreateDOMParamsType;
|
|
6
|
+
type IStage = VRender.CreateDOMParamsType;
|
|
7
|
+
type SimpleDomStyleOptions = VRender.CreateDOMParamsType;
|
|
8
|
+
export declare class VTableReactAttributePlugin extends ReactAttributePlugin {
|
|
9
|
+
removeElement(id: string): void;
|
|
10
|
+
renderGraphicHTML(graphic: IGraphic): void;
|
|
11
|
+
getWrapContainer(stage: IStage, userContainer?: string | HTMLElement | null, domParams?: CreateDOMParamsType): {
|
|
12
|
+
wrapContainer: HTMLElement;
|
|
13
|
+
nativeContainer: any;
|
|
14
|
+
};
|
|
15
|
+
updateStyleOfWrapContainer(graphic: IGraphic, stage: IStage, wrapContainer: HTMLElement, nativeContainer: HTMLElement, options: SimpleDomStyleOptions & CommonDomOptions): void;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.VTableReactAttributePlugin = void 0;
|
|
6
|
+
|
|
7
|
+
const vtable_1 = require("@visactor/vtable"), vutils_1 = require("@visactor/vutils"), {ReactAttributePlugin: ReactAttributePlugin, application: application} = vtable_1.VRender;
|
|
8
|
+
|
|
9
|
+
class VTableReactAttributePlugin extends ReactAttributePlugin {
|
|
10
|
+
removeElement(id) {
|
|
11
|
+
super.removeElement(id), delete this.htmlMap[id];
|
|
12
|
+
}
|
|
13
|
+
renderGraphicHTML(graphic) {
|
|
14
|
+
var _a;
|
|
15
|
+
const {react: react} = graphic.attribute;
|
|
16
|
+
if (!react) return;
|
|
17
|
+
const stage = graphic.stage;
|
|
18
|
+
if (!stage) return;
|
|
19
|
+
const ReactDOM = stage.params.ReactDOM, {element: element, container: container} = react;
|
|
20
|
+
if (!(element && ReactDOM && ReactDOM.createRoot)) return;
|
|
21
|
+
const id = (0, vutils_1.isNil)(react.id) ? `${null !== (_a = graphic.id) && void 0 !== _a ? _a : graphic._uid}_react` : react.id;
|
|
22
|
+
if (this.htmlMap && this.htmlMap[id] && container && container !== this.htmlMap[id].container && this.removeElement(id),
|
|
23
|
+
this.htmlMap && this.htmlMap[id]) this.htmlMap[id].root.render(element); else {
|
|
24
|
+
const {wrapContainer: wrapContainer, nativeContainer: nativeContainer} = this.getWrapContainer(stage, container);
|
|
25
|
+
if (wrapContainer) {
|
|
26
|
+
const root = ReactDOM.createRoot(wrapContainer);
|
|
27
|
+
root.render(element), this.htmlMap || (this.htmlMap = {}), this.htmlMap[id] = {
|
|
28
|
+
root: root,
|
|
29
|
+
wrapContainer: wrapContainer,
|
|
30
|
+
nativeContainer: nativeContainer,
|
|
31
|
+
container: container,
|
|
32
|
+
renderId: this.renderId
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!this.htmlMap || !this.htmlMap[id]) return;
|
|
37
|
+
const {wrapContainer: wrapContainer, nativeContainer: nativeContainer} = this.htmlMap[id];
|
|
38
|
+
this.updateStyleOfWrapContainer(graphic, stage, wrapContainer, nativeContainer, react),
|
|
39
|
+
this.htmlMap[id].renderId = this.renderId;
|
|
40
|
+
}
|
|
41
|
+
getWrapContainer(stage, userContainer, domParams) {
|
|
42
|
+
let nativeContainer;
|
|
43
|
+
return nativeContainer = userContainer ? "string" == typeof userContainer ? application.global.getElementById(userContainer) : userContainer : stage.window.getContainer(),
|
|
44
|
+
{
|
|
45
|
+
wrapContainer: application.global.createDom(Object.assign({
|
|
46
|
+
tagName: "div",
|
|
47
|
+
parent: nativeContainer
|
|
48
|
+
}, domParams)),
|
|
49
|
+
nativeContainer: nativeContainer
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
updateStyleOfWrapContainer(graphic, stage, wrapContainer, nativeContainer, options) {
|
|
53
|
+
const {pointerEvents: pointerEvents} = options;
|
|
54
|
+
let calculateStyle = this.parseDefaultStyleFromGraphic(graphic);
|
|
55
|
+
calculateStyle.display = !1 !== graphic.attribute.visible ? "block" : "none", calculateStyle.pointerEvents = !0 === pointerEvents ? "all" : pointerEvents || "none",
|
|
56
|
+
wrapContainer.style.position || (wrapContainer.style.position = "absolute", nativeContainer.style.position = "relative");
|
|
57
|
+
let left = 0, top = 0;
|
|
58
|
+
const b = graphic.globalAABBBounds;
|
|
59
|
+
let anchorType = options.anchorType;
|
|
60
|
+
if ((0, vutils_1.isNil)(anchorType) && (anchorType = "text" === graphic.type ? "position" : "boundsLeftTop"),
|
|
61
|
+
"boundsLeftTop" === anchorType && (anchorType = "top-left"), "position" === anchorType || b.empty()) {
|
|
62
|
+
const matrix = graphic.globalTransMatrix;
|
|
63
|
+
left = matrix.e, top = matrix.f;
|
|
64
|
+
} else {
|
|
65
|
+
const anchor = (0, vutils_1.calculateAnchorOfBounds)(b, anchorType);
|
|
66
|
+
left = anchor.x, top = anchor.y;
|
|
67
|
+
}
|
|
68
|
+
const containerTL = application.global.getElementTopLeft(nativeContainer, !1), windowTL = stage.window.getTopLeft(!1), offsetX = left + windowTL.left - containerTL.left, offsetTop = top + windowTL.top - containerTL.top;
|
|
69
|
+
if (calculateStyle.left = `${offsetX}px`, calculateStyle.top = `${offsetTop}px`,
|
|
70
|
+
"text" === graphic.type && "position" === anchorType && (calculateStyle = Object.assign(Object.assign({}, calculateStyle), this.getTransformOfText(graphic))),
|
|
71
|
+
(0, vutils_1.isFunction)(options.style)) {
|
|
72
|
+
const userStyle = options.style({
|
|
73
|
+
top: offsetTop,
|
|
74
|
+
left: offsetX,
|
|
75
|
+
width: b.width(),
|
|
76
|
+
height: b.height()
|
|
77
|
+
}, graphic, wrapContainer);
|
|
78
|
+
userStyle && (calculateStyle = Object.assign(Object.assign({}, calculateStyle), userStyle));
|
|
79
|
+
} else (0, vutils_1.isObject)(options.style) ? calculateStyle = Object.assign(Object.assign({}, calculateStyle), options.style) : (0,
|
|
80
|
+
vutils_1.isString)(options.style) && options.style && (calculateStyle = Object.assign(Object.assign({}, calculateStyle), (0,
|
|
81
|
+
vutils_1.styleStringToObject)(options.style)));
|
|
82
|
+
application.global.updateDom(wrapContainer, {
|
|
83
|
+
width: options.width,
|
|
84
|
+
height: options.width,
|
|
85
|
+
style: calculateStyle,
|
|
86
|
+
graphic: graphic
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
exports.VTableReactAttributePlugin = VTableReactAttributePlugin;
|
|
92
|
+
//# sourceMappingURL=vtable-react-attribute-plugin.js.map
|