@visactor/react-vrender
Version:
## Description
153 lines (145 loc) • 9.29 kB
JavaScript
var __importDefault = this && this.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : {
default: mod
};
};
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.render = exports.reconcilor = exports.createInstance = void 0;
const vrender_1 = require("@visactor/vrender"), react_1 = __importDefault(require("react")), react_reconciler_1 = __importDefault(require("react-reconciler")), constants_1 = require("react-reconciler/constants"), processProps_1 = require("./processProps"), debug_1 = require("./util/debug"), isStage = instance => instance.stage === instance, isLayer = instance => instance.layer === instance, isGlyph = instance => "glyph" === instance.type, isShadowRoot = instance => "shadowroot" === instance.type, createInstance = (type, props, rootContainerInstance) => {
const graphicType = type.toLowerCase(), {graphicProps: graphicProps, eventProps: eventProps} = (0,
processProps_1.splitProps)(props);
let instance;
return instance = "glyph" === graphicType ? (0, vrender_1.createGlyph)(graphicProps) : "layer" === graphicType && rootContainerInstance ? isStage(rootContainerInstance) ? rootContainerInstance.createLayer() : rootContainerInstance.stage ? rootContainerInstance.stage.createLayer() : null : "shadowroot" === graphicType ? (0,
vrender_1.createShadowRoot)() : vrender_1.graphicCreator[graphicType](graphicProps),
(0, processProps_1.bindGraphicEvent)(eventProps, instance), (0, debug_1.log)("createInstance ", graphicType, instance),
instance;
};
exports.createInstance = createInstance;
const appendChild = (parentInstance, child) => {
var _a;
const isParentStage = isStage(parentInstance), isChildLayer = isLayer(child);
isParentStage && !isChildLayer && parentInstance.defaultLayer ? parentInstance.defaultLayer.appendChild(child) : isGlyph(parentInstance) ? parentInstance.setSubGraphic((null !== (_a = parentInstance.getSubGraphic()) && void 0 !== _a ? _a : []).concat(child)) : isShadowRoot(child) ? isParentStage ? (0,
debug_1.error)("stage can not attach shadow root") : parentInstance.attachShadow(child) : parentInstance.appendChild(child);
}, insertBeforeChild = (parentInstance, child, beforeChild) => {
const isParentStage = isStage(parentInstance), isChildLayer = isLayer(child), isBeforeChildLayer = isLayer(beforeChild);
if (isParentStage) isChildLayer || isBeforeChildLayer ? isChildLayer && isBeforeChildLayer && parentInstance.insertBefore(child, beforeChild) : parentInstance.defaultLayer ? parentInstance.defaultLayer.insertBefore(child, beforeChild) : (0,
debug_1.error)("default layer has been removed "); else if (!isParentStage && isChildLayer) (0,
debug_1.error)(`layer can not be inserted into other graphic: ${parentInstance.type}`); else if (isGlyph(parentInstance)) {
const prevSubGraphics = parentInstance.getSubGraphic(), index = prevSubGraphics.indexOf(child), beforeIndex = prevSubGraphics.indexOf(beforeChild);
if (index >= 0 && beforeIndex >= 0 && index !== beforeIndex) {
const newSubGraphics = prevSubGraphics.slice();
newSubGraphics[beforeIndex] = child, newSubGraphics[index] = beforeChild, parentInstance.setSubGraphic(newSubGraphics);
}
} else parentInstance.insertBefore(child, beforeChild);
}, removeChild = (parentInstance, child) => {
const isParentStage = isStage(parentInstance), isChildLayer = isLayer(child);
if (isParentStage && !isChildLayer && parentInstance.defaultLayer) parentInstance.defaultLayer.removeChild(child); else if (isGlyph(parentInstance)) {
const prevSubGraphics = parentInstance.getSubGraphic(), index = prevSubGraphics.indexOf(child);
index >= 0 && parentInstance.setSubGraphic([ ...prevSubGraphics.slice(0, index - 1), ...prevSubGraphics.slice(index + 1) ]);
} else isShadowRoot(child) ? isParentStage ? (0, debug_1.error)("stage can not attach shadow root") : parentInstance.detachShadow(child) : parentInstance.removeChild(child);
}, clearContainer = container => {
if (isStage(container)) for (container.defaultLayer && container.defaultLayer.removeAllChild(); container.childrenCount > 1; ) container.removeChild(container.getChildAt(1)); else container.removeAllChild();
};
exports.reconcilor = (0, react_reconciler_1.default)({
getPublicInstance: instance => instance,
getRootHostContext(rootContainerInstance) {},
getChildHostContext(parentHostContext, type, rootContainerInstance) {},
prepareForCommit: containerInfo => null,
resetAfterCommit(containerInfo) {},
preparePortalMount(containerInfo) {},
createInstance: (type, props, rootContainerInstance, hostContext, internalInstanceHandle) => (0,
exports.createInstance)(type, props, rootContainerInstance),
appendInitialChild(parentInstance, child) {
(0, debug_1.log)("appendInitialChild", parentInstance, child), appendChild(parentInstance, child);
},
finalizeInitialChildren: (parentInstance, type, props, rootContainerInstance, hostContext) => !1,
prepareUpdate: (instance, type, oldProps, newProps, rootContainerInstance, hostContext) => !0,
shouldSetTextContent: (type, props) => !1,
createTextInstance: (text, rootContainerInstance, hostContext, internalInstanceHandle) => (0,
vrender_1.createText)({
text: text
}),
scheduleTimeout(handler, timeout) {},
cancelTimeout(handle) {},
noTimeout: void 0,
getCurrentEventPriority: () => constants_1.DefaultEventPriority,
getInstanceFromNode(node) {
throw new Error("Not implemented.");
},
beforeActiveInstanceBlur() {},
isPrimaryRenderer: !1,
supportsMutation: !0,
supportsPersistence: !1,
supportsHydration: !1,
appendChild(parentInstance, child) {
(0, debug_1.log)("appendChild"), appendChild(parentInstance, child);
},
appendChildToContainer(container, child) {
(0, debug_1.log)("appendChildToContainer", container, child), appendChild(container, child);
},
commitTextUpdate(textInstance, oldText, newText) {},
commitMount(instance, type, newProps, internalInstanceHandle) {},
commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
(0, debug_1.log)("commitUpdate", instance, newProps), (0, processProps_1.updateProps)(instance, newProps, oldProps);
},
insertBefore(parentInstance, child, beforeChild) {
insertBeforeChild(parentInstance, child, beforeChild);
},
insertInContainerBefore(container, child, beforeChild) {
insertBeforeChild(container, child, beforeChild);
},
removeChild(parentInstance, child) {
(0, debug_1.log)("removeChild", parentInstance, child), removeChild(parentInstance, child);
},
removeChildFromContainer(container, child) {
removeChild(container, child);
},
resetTextContent(instance) {},
hideInstance(instance) {},
hideTextInstance(textInstance) {},
unhideInstance(instance, props) {},
unhideTextInstance(textInstance, text) {},
clearContainer(container) {
clearContainer(container);
},
cloneInstance: (instance, updatePayload, type, oldProps, newProps, internalInstanceHandle, keepChildren, recyclableInstance) => instance,
createContainerChildSet(container) {},
appendChildToContainerChildSet(childSet, child) {},
finalizeContainerChildren(container, newChildren) {},
replaceContainerChildren(container, newChildren) {},
canHydrateInstance: (instance, type, props) => instance,
canHydrateTextInstance: (instance, text) => null,
getNextHydratableSibling(instance) {},
getFirstHydratableChild(parentInstance) {},
hydrateInstance(instance, type, props, rootContainerInstance, hostContext, internalInstanceHandle) {},
hydrateTextInstance: (textInstance, text, internalInstanceHandle) => !1,
didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, text) {},
didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, text) {},
didNotHydrateContainerInstance(parentContainer, instance) {},
didNotHydrateInstance(parentType, parentProps, parentInstance, instance) {},
didNotFindHydratableContainerInstance(parentContainer, type, props) {},
didNotFindHydratableContainerTextInstance(parentContainer, text) {},
didNotFindHydratableInstance(parentType, parentProps, parentInstance, type, props) {},
didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, text) {},
afterActiveInstanceBlur() {},
prepareScopeUpdate() {},
getInstanceFromScope: () => null,
detachDeletedInstance() {}
}), exports.reconcilor.injectIntoDevTools({
bundleType: "production" !== process.env.NODE_ENV ? 1 : 0,
version: react_1.default.version,
rendererPackageName: "react-g",
rendererConfig: {
getInspectorDataForViewTag: tag => {
console.log(tag);
}
}
});
const render = (component, target, callback) => {
const container = exports.reconcilor.createContainer(target, 1, !1, null);
exports.reconcilor.updateContainer(component, container, null, callback);
};
exports.render = render;
//# sourceMappingURL=hostConfig.js.map
;