UNPKG

@visactor/react-vtable

Version:

The react version of VTable

110 lines (99 loc) 4.38 kB
import { application, REACT_TO_CANOPUS_EVENTS } from "@visactor/vtable/es/vrender"; import { isFunction, isNumber, merge } from "@visactor/vutils"; import React from "react"; import ReactReconciler from "react-reconciler"; import { DefaultEventPriority } from "react-reconciler/constants.js"; import { createVRenderComponent } from "../../components/vrender-components/component-creater"; export const reconcilor = ReactReconciler({ supportsMutation: !0, supportsPersistence: !1, createInstance: (type, props, instance) => { const graphic = createGraphic(type, props); if (graphic) return bindEventsToGraphic(graphic, props), graphic; }, createTextInstance: (text, instance) => {}, appendInitialChild: (parentInstance, childInstance) => { parentInstance.add(childInstance); }, finalizeInitialChildren: () => !1, prepareUpdate: () => !0, shouldSetTextContent: () => !1, getRootHostContext: () => null, getChildHostContext: () => null, getPublicInstance: instance => instance, prepareForCommit: () => null, resetAfterCommit: () => {}, preparePortalMount: () => null, scheduleTimeout: setTimeout, cancelTimeout: clearTimeout, noTimeout: -1, isPrimaryRenderer: !1, getCurrentEventPriority: () => DefaultEventPriority, getInstanceFromNode: node => null, beforeActiveInstanceBlur: () => {}, afterActiveInstanceBlur: () => {}, prepareScopeUpdate: () => {}, getInstanceFromScope: () => {}, detachDeletedInstance: () => {}, supportsHydration: !1, appendChild: (parentInstance, child) => { parentInstance.add(child); }, appendChildToContainer: (container, child) => { container.add(child); }, insertBefore: (parentInstance, child, beforeChild) => { parentInstance.insertBefore(child, beforeChild); }, insertInContainerBefore: (parentInstance, child, beforeChild) => { parentInstance.insertBefore(child, beforeChild); }, removeChild: (parentInstance, child) => { child.delete(); }, removeChildFromContainer: (parentInstance, child) => { child.delete(); }, commitUpdate: (instance, updatePayload, type, oldProps, newProps) => { updateGraphicProps(instance, newProps, oldProps); }, hideInstance: instance => { instance.setAttribute("visible", !1); }, unhideInstance: (instance, props) => { instance.setAttribute("visible", !0); }, clearContainer: container => { container.removeAllChild(); }, commitTextUpdate: (textInstance, oldText, newText) => {} }); function createGraphic(type, props) { const component = createVRenderComponent(type, props); if (component) return component; if (!application.graphicService.creator[type]) return; return application.graphicService.creator[type](props.attribute); } function isEventProp(key, props) { return key.startsWith("on") && isFunction(props[key]); } function bindEventsToGraphic(graphic, props) { for (const key in props) isEventProp(key, props) && REACT_TO_CANOPUS_EVENTS[key] && graphic.addEventListener(REACT_TO_CANOPUS_EVENTS[key], props[key]); } function updateGraphicProps(graphic, newProps, oldProps) { var _a; for (const propKey in oldProps) isEventProp(propKey, oldProps) && oldProps[propKey] !== newProps[propKey] && graphic.removeEventListener(REACT_TO_CANOPUS_EVENTS[propKey], oldProps[propKey]); for (const propKey in newProps) isEventProp(propKey, newProps) && oldProps[propKey] !== newProps[propKey] && graphic.addEventListener(REACT_TO_CANOPUS_EVENTS[propKey], newProps[propKey]); const attribute = null !== (_a = newProps.attribute) && void 0 !== _a ? _a : merge({}, newProps); if (graphic.initAttributes(attribute), "image" === graphic.type && graphic.loadImage(attribute.image), "flex" === attribute.display && void 0 === attribute.width && void 0 === attribute.height && isNumber(oldProps.attribute.width) && isNumber(oldProps.attribute.height)) { const plugin = graphic.stage.pluginService.findPluginsByName("FlexLayoutPlugin")[0]; plugin && plugin.tryLayoutChildren(graphic); } } //# sourceMappingURL=reconciler.js.map reconcilor.injectIntoDevTools({ bundleType: 0, version: React.version, rendererPackageName: "react-vtable" });