@visactor/react-vtable
Version:
The react version of VTable
112 lines (104 loc) • 4.79 kB
JavaScript
;
var __importDefault = this && this.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : {
default: mod
};
};
Object.defineProperty(exports, "__esModule", {
value: !0
}), 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");
function createGraphic(type, props) {
const component = (0, component_creater_1.createVRenderComponent)(type, props);
if (component) return component;
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.reconcilor = (0, react_reconciler_1.default)({
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: () => constants_js_1.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) => {}
}), exports.reconcilor.injectIntoDevTools({
bundleType: 0,
version: react_1.default.version,
rendererPackageName: "react-vtable"
});