Files
furniture/node_modules/react-konva/lib/ReactKonvaHostConfig.js
T
2026-10-17 12:09:36 -04:00

307 lines
13 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HostTransitionContext = exports.NotPendingTransition = exports.maySuspendCommitInSyncRender = exports.maySuspendCommitOnUpdate = exports.createViewTransitionInstance = exports.removeChildFromContainer = exports.insertInContainerBefore = exports.appendChildToContainer = exports.supportsHydration = exports.supportsPersistence = exports.supportsMutation = exports.warnsIfNotActing = exports.isPrimaryRenderer = exports.noTimeout = exports.scheduleMicrotask = exports.supportsMicrotasks = exports.cancelTimeout = exports.scheduleTimeout = exports.run = exports.idlePriority = exports.now = void 0;
exports.appendInitialChild = appendInitialChild;
exports.createInstance = createInstance;
exports.createTextInstance = createTextInstance;
exports.finalizeInitialChildren = finalizeInitialChildren;
exports.getPublicInstance = getPublicInstance;
exports.createFragmentInstance = createFragmentInstance;
exports.updateFragmentInstanceFiber = updateFragmentInstanceFiber;
exports.commitNewChildToFragmentInstance = commitNewChildToFragmentInstance;
exports.deleteChildFromFragmentInstance = deleteChildFromFragmentInstance;
exports.prepareForCommit = prepareForCommit;
exports.preparePortalMount = preparePortalMount;
exports.resetAfterCommit = resetAfterCommit;
exports.resetTextContent = resetTextContent;
exports.getRootHostContext = getRootHostContext;
exports.getChildHostContext = getChildHostContext;
exports.shouldSetTextContent = shouldSetTextContent;
exports.appendChild = appendChild;
exports.insertBefore = insertBefore;
exports.removeChild = removeChild;
exports.commitTextUpdate = commitTextUpdate;
exports.commitMount = commitMount;
exports.commitUpdate = commitUpdate;
exports.hideInstance = hideInstance;
exports.hideTextInstance = hideTextInstance;
exports.unhideInstance = unhideInstance;
exports.unhideTextInstance = unhideTextInstance;
exports.clearContainer = clearContainer;
exports.detachDeletedInstance = detachDeletedInstance;
exports.getInstanceFromNode = getInstanceFromNode;
exports.bindToConsole = bindToConsole;
exports.beforeActiveInstanceBlur = beforeActiveInstanceBlur;
exports.afterActiveInstanceBlur = afterActiveInstanceBlur;
exports.prepareScopeUpdate = prepareScopeUpdate;
exports.getInstanceFromScope = getInstanceFromScope;
exports.setCurrentUpdatePriority = setCurrentUpdatePriority;
exports.getCurrentUpdatePriority = getCurrentUpdatePriority;
exports.resolveUpdatePriority = resolveUpdatePriority;
exports.shouldAttemptEagerTransition = shouldAttemptEagerTransition;
exports.trackSchedulerEvent = trackSchedulerEvent;
exports.resolveEventType = resolveEventType;
exports.resolveEventTimeStamp = resolveEventTimeStamp;
exports.requestPostPaintCallback = requestPostPaintCallback;
exports.maySuspendCommit = maySuspendCommit;
exports.startViewTransition = startViewTransition;
exports.preloadInstance = preloadInstance;
exports.startSuspendingCommit = startSuspendingCommit;
exports.suspendInstance = suspendInstance;
exports.suspendOnActiveViewTransition = suspendOnActiveViewTransition;
exports.waitForCommitToBeReady = waitForCommitToBeReady;
exports.getSuspendedCommitReason = getSuspendedCommitReason;
exports.resetFormInstance = resetFormInstance;
const react_1 = __importDefault(require("react"));
const Core_js_1 = __importDefault(require("konva/lib/Core.js"));
const makeUpdates_js_1 = require("./makeUpdates.js");
var scheduler_1 = require("scheduler");
Object.defineProperty(exports, "now", { enumerable: true, get: function () { return scheduler_1.unstable_now; } });
Object.defineProperty(exports, "idlePriority", { enumerable: true, get: function () { return scheduler_1.unstable_IdlePriority; } });
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return scheduler_1.unstable_runWithPriority; } });
const constants_js_1 = require("react-reconciler/constants.js");
const NO_CONTEXT = {};
// for react-spring capability
Core_js_1.default.Node.prototype._applyProps = makeUpdates_js_1.applyNodeProps;
// let currentUpdatePriority: number = NoEventPriority;
let currentUpdatePriority = constants_js_1.DefaultEventPriority;
function appendInitialChild(parentInstance, child) {
if (typeof child === 'string') {
// Noop for string children of Text (eg <Text>foo</Text>)
console.error(`Do not use plain text as child of Konva.Node. You are using text: ${child}`);
return;
}
parentInstance.add(child);
(0, makeUpdates_js_1.updatePicture)(parentInstance);
}
function createInstance(type, props, internalInstanceHandle) {
let NodeClass = Core_js_1.default[type];
if (!NodeClass) {
console.error(`Konva has no node with the type ${type}. Group will be used instead. If you use minimal version of react-konva, just import required nodes into Konva: "import "konva/lib/shapes/${type}" If you want to render DOM elements as part of canvas tree take a look into this demo: https://konvajs.github.io/docs/react/DOM_Portal.html`);
NodeClass = Core_js_1.default.Group;
}
// we need to split props into events and non events
// we we can pass non events into constructor directly
// that way the performance should be better
// we we apply change "applyNodeProps"
// then it will trigger change events on first run
// but we don't need them!
const propsWithoutEvents = {};
const propsWithOnlyEvents = {};
for (var key in props) {
// ignore ref
if (key === 'ref') {
continue;
}
var isEvent = key.slice(0, 2) === 'on';
if (isEvent) {
propsWithOnlyEvents[key] = props[key];
}
else {
propsWithoutEvents[key] = props[key];
}
}
const instance = new NodeClass(propsWithoutEvents);
(0, makeUpdates_js_1.applyNodeProps)(instance, propsWithOnlyEvents);
return instance;
}
function createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
console.error(`Text components are not supported for now in ReactKonva. Your text is: "${text}"`);
}
function finalizeInitialChildren(domElement, type, props) {
return false;
}
function getPublicInstance(instance) {
return instance;
}
// Fragments group Konva children but have no DOM instance or Fragment methods.
// This matches React's noop renderer.
function createFragmentInstance() {
return null;
}
function updateFragmentInstanceFiber() { }
function commitNewChildToFragmentInstance() { }
function deleteChildFromFragmentInstance() { }
let finishUpdateBatch;
function prepareForCommit() {
// Older supported Konva versions do not expose commit batching.
finishUpdateBatch = Core_js_1.default.beginUpdateBatch?.();
return null;
}
function preparePortalMount() {
return null;
}
function resetAfterCommit() {
const finish = finishUpdateBatch;
finishUpdateBatch = undefined;
// React layout effects must see the final Transformer geometry.
finish?.();
}
function resetTextContent(domElement) {
// Noop
}
function getRootHostContext() {
return NO_CONTEXT;
}
function getChildHostContext() {
return NO_CONTEXT;
}
exports.scheduleTimeout = setTimeout;
exports.cancelTimeout = clearTimeout;
exports.supportsMicrotasks = true;
// Async — fixes the mobx-react-lite snapshot race. Stage's useLayoutEffect
// then explicitly calls `flushSyncWork()` to keep parent useLayoutEffect able
// to read Konva nodes added by subscribing children (see ReactKonvaCore.tsx).
var EventBatch_js_1 = require("./EventBatch.js");
Object.defineProperty(exports, "scheduleMicrotask", { enumerable: true, get: function () { return EventBatch_js_1.scheduleMicrotask; } });
exports.noTimeout = -1;
// export const schedulePassiveEffects = scheduleDeferredCallback;
// export const cancelPassiveEffects = cancelDeferredCallback;
function shouldSetTextContent(type, props) {
return false;
}
// The Konva renderer is secondary to the React DOM renderer.
exports.isPrimaryRenderer = false;
exports.warnsIfNotActing = false;
exports.supportsMutation = true;
exports.supportsPersistence = false;
exports.supportsHydration = false;
function appendChild(parentInstance, child) {
if (child.parent === parentInstance) {
child.moveToTop();
}
else {
parentInstance.add(child);
}
(0, makeUpdates_js_1.updatePicture)(parentInstance);
}
exports.appendChildToContainer = appendChild;
function insertBefore(parentInstance, child, beforeChild) {
// child._remove() will not stop dragging
// but child.remove() will stop it, but we don't need it
// removing will reset zIndexes
child._remove();
parentInstance.add(child);
child.setZIndex(beforeChild.getZIndex());
(0, makeUpdates_js_1.updatePicture)(parentInstance);
}
exports.insertInContainerBefore = insertBefore;
function removeChild(parentInstance, child) {
child.destroy();
child.off(makeUpdates_js_1.EVENTS_NAMESPACE);
(0, makeUpdates_js_1.updatePicture)(parentInstance);
}
exports.removeChildFromContainer = removeChild;
function commitTextUpdate(textInstance, oldText, newText) {
console.error(`Text components are not yet supported in ReactKonva. You text is: "${newText}"`);
}
function commitMount(instance, type, newProps) {
// Noop
}
function commitUpdate(instance, type, oldProps, newProps) {
(0, makeUpdates_js_1.applyNodeProps)(instance, newProps, oldProps);
}
function hideInstance(instance) {
instance.hide();
(0, makeUpdates_js_1.updatePicture)(instance);
}
function hideTextInstance(textInstance) {
// Noop
}
function unhideInstance(instance, props) {
if (props.visible == null || props.visible) {
instance.show();
(0, makeUpdates_js_1.updatePicture)(instance);
}
}
function unhideTextInstance(textInstance, text) {
// Noop
}
function clearContainer(container) {
// Noop
}
function detachDeletedInstance(instance) {
// React visits every deleted host node here, including descendants of a
// removed container. Konva.destroy() alone does not release their listeners.
instance.off(makeUpdates_js_1.EVENTS_NAMESPACE);
}
function getInstanceFromNode() {
return null;
}
function bindToConsole(methodName, args) {
return console[methodName].bind(console, ...args);
}
function beforeActiveInstanceBlur() { }
function afterActiveInstanceBlur() { }
function prepareScopeUpdate() { }
function getInstanceFromScope() {
return null;
}
function setCurrentUpdatePriority(newPriority) {
currentUpdatePriority = newPriority;
}
function getCurrentUpdatePriority() {
return currentUpdatePriority;
}
// Load-bearing: pins secondary commits to React's sync lane so they land
// before the scheduler yields. Required for parent useLayoutEffect to read
// Konva nodes added by subscribing children. Changing to Default/Continuous/
// Idle breaks ~18 tests in test/01-mounting and test/16-scheduling-invariants.
function resolveUpdatePriority() {
return constants_js_1.DiscreteEventPriority;
}
function shouldAttemptEagerTransition() {
return false;
}
function trackSchedulerEvent() { }
function resolveEventType() {
return null;
}
function resolveEventTimeStamp() {
return -1.1;
}
function requestPostPaintCallback() { }
function maySuspendCommit() {
// React 19.3 calls this during render only for nodes inside ViewTransition.
// Reject before commit, where a view-transition error can escape boundaries.
throw new Error('ViewTransition is not supported inside a Stage. ' +
'Place ViewTransition around Stage to animate its DOM container.');
}
exports.createViewTransitionInstance = maySuspendCommit;
exports.maySuspendCommitOnUpdate = maySuspendCommit;
exports.maySuspendCommitInSyncRender = maySuspendCommit;
// Empty ViewTransition boundaries can reach commit without any Konva nodes.
// Finish those commits without animation so ref errors can reach a boundary.
function startViewTransition(suspendedState, rootContainer, transitionTypes, mutationCallback, layoutCallback, afterMutationCallback, spawnedWorkCallback, passiveCallback, errorCallback, blockedCallback, finishedAnimation) {
mutationCallback();
layoutCallback();
finishedAnimation?.();
spawnedWorkCallback();
return null;
}
function preloadInstance() {
return true;
}
function startSuspendingCommit() { }
function suspendInstance() { }
// React also calls this for Suspense retries without a ViewTransition component.
function suspendOnActiveViewTransition() { }
function waitForCommitToBeReady() {
return null;
}
function getSuspendedCommitReason() {
return null;
}
// Stage provides the surrounding DOM form status. Standalone roots stay idle.
exports.NotPendingTransition = Object.freeze({
pending: false,
data: null,
method: null,
action: null,
});
exports.HostTransitionContext = react_1.default.createContext(exports.NotPendingTransition);
function resetFormInstance() { }