UNPKG

@visactor/react-vtable

Version:
154 lines (141 loc) 7.19 kB
"use strict"; var __importDefault = this && this.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.createReconcilerContainer = exports.reconcilor = void 0; const vrender_1 = require("@visactor/vtable/es/vrender"), 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"), component_creater_1 = require("../../components/vrender-components/component-creater"), rendererPackageName = "react-vtable", rendererVersion = "string" == typeof react_1.default.version && react_1.default.version.length > 0 ? react_1.default.version : "0.0.0"; let currentUpdatePriority = constants_js_1.DefaultEventPriority; exports.reconcilor = react_reconciler_1.default({ supportsMutation: !0, supportsPersistence: !1, rendererVersion: rendererVersion, rendererPackageName: "react-vtable", 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: () => ({}), getChildHostContext: () => ({}), getPublicInstance: instance => instance, prepareForCommit: () => null, resetAfterCommit: () => {}, preparePortalMount: () => null, scheduleTimeout: setTimeout, cancelTimeout: clearTimeout, supportsMicrotasks: !0, scheduleMicrotask: callback => { Promise.resolve().then(callback); }, noTimeout: -1, isPrimaryRenderer: !1, setCurrentUpdatePriority: newPriority => { currentUpdatePriority = newPriority; }, getCurrentUpdatePriority: () => currentUpdatePriority, resolveUpdatePriority: () => currentUpdatePriority, trackSchedulerEvent: () => {}, resolveEventType: () => null, resolveEventTimeStamp: () => Date.now(), shouldAttemptEagerTransition: () => !1, getCurrentEventPriority: () => constants_js_1.DefaultEventPriority, getInstanceFromNode: node => null, beforeActiveInstanceBlur: () => {}, afterActiveInstanceBlur: () => {}, prepareScopeUpdate: () => {}, getInstanceFromScope: () => {}, detachDeletedInstance: () => {}, supportsHydration: !1, maySuspendCommit: () => !1, preloadInstance: () => null, startSuspendingCommit: () => null, suspendInstance: () => {}, waitForCommitToBeReady: () => null, 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: (...args) => { const instance = args[0]; if ("string" == typeof args[1]) { const oldProps = args[2]; return void updateGraphicProps(instance, args[3], oldProps); } const oldProps = args[3]; updateGraphicProps(instance, args[4], oldProps); }, hideInstance: instance => { instance.setAttribute("visible", !1); }, unhideInstance: (instance, props) => { instance.setAttribute("visible", !0); }, clearContainer: container => { container.removeAllChild(); }, commitTextUpdate: (textInstance, oldText, newText) => {} }); const injectIntoDevTools = exports.reconcilor.injectIntoDevTools; "function" == typeof injectIntoDevTools && (0 === injectIntoDevTools.length ? injectIntoDevTools() : injectIntoDevTools({ bundleType: 0, version: rendererVersion, rendererPackageName: "react-vtable" })); const createReconcilerContainer = (container, identifierPrefix = "custom", reportError) => { var _a; const createContainer = exports.reconcilor.createContainer, noop = () => {}, onUncaughtError = reportError ? error => reportError("uncaught", error) : noop, onCaughtError = reportError ? error => reportError("caught", error) : noop, onRecoverableError = reportError ? error => reportError("recoverable", error) : noop, majorVersion = Number.parseInt(String(null !== (_a = react_1.default.version) && void 0 !== _a ? _a : "0").split(".")[0], 10); return createContainer(container, Number.isFinite(majorVersion) && majorVersion >= 19 ? constants_js_1.ConcurrentRoot : constants_js_1.LegacyRoot, null, !1, !1, identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, null); }; function createGraphic(type, props) { const component = (0, component_creater_1.createVRenderComponent)(type, props); if (component) return component; if ("group" === type) return new vrender_1.Group(props.attribute ? props.attribute : props); if ("text" === type) return new vrender_1.Text(props.attribute ? props.attribute : props); if (!vrender_1.application.graphicService.creator[type]) return; return vrender_1.application.graphicService.creator[type](props.attribute); } function isEventProp(key, props) { return key.startsWith("on") && (0, vutils_1.isFunction)(props[key]); } function bindEventsToGraphic(graphic, props) { for (const key in props) isEventProp(key, props) && vrender_1.REACT_TO_CANOPUS_EVENTS[key] && graphic.addEventListener(vrender_1.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(vrender_1.REACT_TO_CANOPUS_EVENTS[propKey], oldProps[propKey]); for (const propKey in newProps) isEventProp(propKey, newProps) && oldProps[propKey] !== newProps[propKey] && graphic.addEventListener(vrender_1.REACT_TO_CANOPUS_EVENTS[propKey], newProps[propKey]); const attribute = null !== (_a = newProps.attribute) && void 0 !== _a ? _a : (0, vutils_1.merge)({}, newProps); if (graphic.initAttributes(attribute), "image" === graphic.type && graphic.loadImage(attribute.image), "flex" === attribute.display && void 0 === attribute.width && void 0 === attribute.height && (0, vutils_1.isNumber)(oldProps.attribute.width) && (0, vutils_1.isNumber)(oldProps.attribute.height)) { const plugin = graphic.stage.pluginService.findPluginsByName("FlexLayoutPlugin")[0]; plugin && plugin.tryLayoutChildren(graphic); } } //# sourceMappingURL=reconciler.js.map exports.createReconcilerContainer = createReconcilerContainer;