@depup/react-konva 19.2.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/ReactKonvaCore.d.ts +117 -0
- package/changes.json +5 -0
- package/es/ReactKonva.js +10 -0
- package/es/ReactKonvaCore.d.ts +117 -0
- package/es/ReactKonvaCore.js +185 -0
- package/es/ReactKonvaHostConfig.js +220 -0
- package/es/makeUpdates.js +117 -0
- package/lib/ReactKonva.js +25 -0
- package/lib/ReactKonvaCore.d.ts +117 -0
- package/lib/ReactKonvaCore.js +221 -0
- package/lib/ReactKonvaHostConfig.js +277 -0
- package/lib/makeUpdates.js +123 -0
- package/package.json +93 -0
- package/react-konva.d.ts +1 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on ReactArt.js
|
|
3
|
+
* Copyright (c) 2017-present Lavrenov Anton.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* MIT
|
|
7
|
+
*/
|
|
8
|
+
'use strict';
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.useContextBridge = exports.useStrictMode = exports.Stage = exports.KonvaRenderer = exports.version = exports.Transformer = exports.Shape = exports.Arrow = exports.RegularPolygon = exports.Path = exports.Tag = exports.Arc = exports.Ring = exports.Star = exports.TextPath = exports.Text = exports.Image = exports.Sprite = exports.Line = exports.Wedge = exports.Ellipse = exports.Circle = exports.Rect = exports.Label = exports.Group = exports.FastLayer = exports.Layer = void 0;
|
|
47
|
+
const react_1 = __importDefault(require("react"));
|
|
48
|
+
if (react_1.default.version.indexOf('19') === -1) {
|
|
49
|
+
throw new Error('react-konva version 19 is only compatible with React 19. Make sure to have the last version of react-konva and react or downgrade react-konva to version 18.');
|
|
50
|
+
}
|
|
51
|
+
const Core_js_1 = __importDefault(require("konva/lib/Core.js"));
|
|
52
|
+
const react_reconciler_1 = __importDefault(require("react-reconciler"));
|
|
53
|
+
const constants_js_1 = require("react-reconciler/constants.js");
|
|
54
|
+
const HostConfig = __importStar(require("./ReactKonvaHostConfig.js"));
|
|
55
|
+
const makeUpdates_js_1 = require("./makeUpdates.js");
|
|
56
|
+
const its_fine_1 = require("its-fine");
|
|
57
|
+
Object.defineProperty(exports, "useContextBridge", { enumerable: true, get: function () { return its_fine_1.useContextBridge; } });
|
|
58
|
+
function usePrevious(value) {
|
|
59
|
+
const ref = react_1.default.useRef({});
|
|
60
|
+
react_1.default.useLayoutEffect(() => {
|
|
61
|
+
ref.current = value;
|
|
62
|
+
});
|
|
63
|
+
react_1.default.useLayoutEffect(() => {
|
|
64
|
+
return () => {
|
|
65
|
+
// when using suspense it is possible that stage is unmounted
|
|
66
|
+
// but React still keep component ref
|
|
67
|
+
// in that case we need to manually flush props
|
|
68
|
+
// we have a special test for that
|
|
69
|
+
ref.current = {};
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
return ref.current;
|
|
73
|
+
}
|
|
74
|
+
const useIsReactStrictMode = () => {
|
|
75
|
+
const memoCount = react_1.default.useRef(0);
|
|
76
|
+
// in strict mode, memo will be called twice
|
|
77
|
+
react_1.default.useMemo(() => {
|
|
78
|
+
memoCount.current++;
|
|
79
|
+
}, []);
|
|
80
|
+
return memoCount.current > 1;
|
|
81
|
+
};
|
|
82
|
+
const StageWrap = (props) => {
|
|
83
|
+
const container = react_1.default.useRef(null);
|
|
84
|
+
const stage = react_1.default.useRef(null);
|
|
85
|
+
const fiberRef = react_1.default.useRef(null);
|
|
86
|
+
const oldProps = usePrevious(props);
|
|
87
|
+
const Bridge = (0, its_fine_1.useContextBridge)();
|
|
88
|
+
const pendingDestroy = react_1.default.useRef(null);
|
|
89
|
+
const _setRef = (stage) => {
|
|
90
|
+
const { forwardedRef } = props;
|
|
91
|
+
if (!forwardedRef) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (typeof forwardedRef === 'function') {
|
|
95
|
+
forwardedRef(stage);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
forwardedRef.current = stage;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const isStrictMode = useIsReactStrictMode();
|
|
102
|
+
const destroyStage = () => {
|
|
103
|
+
_setRef(null);
|
|
104
|
+
// CRITICAL: flushSyncFromReconciler is required here to ensure pending work
|
|
105
|
+
// (e.g. stale MobX updates on child components) is flushed synchronously
|
|
106
|
+
// before the tree is torn down. Without it, unmounting a Stage can leave
|
|
107
|
+
// pending Konva work that runs after the stage is already destroyed.
|
|
108
|
+
exports.KonvaRenderer.flushSyncFromReconciler(() => {
|
|
109
|
+
exports.KonvaRenderer.updateContainer(null, fiberRef.current, null);
|
|
110
|
+
});
|
|
111
|
+
stage.current?.destroy();
|
|
112
|
+
stage.current = null;
|
|
113
|
+
};
|
|
114
|
+
react_1.default.useLayoutEffect(() => {
|
|
115
|
+
// Cancel any pending destruction (happens during re-ordering in strict mode)
|
|
116
|
+
if (pendingDestroy.current) {
|
|
117
|
+
clearTimeout(pendingDestroy.current);
|
|
118
|
+
pendingDestroy.current = null;
|
|
119
|
+
}
|
|
120
|
+
// If stage already exists (re-ordering scenario), reuse it
|
|
121
|
+
if (stage.current) {
|
|
122
|
+
_setRef(stage.current);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
stage.current = new Core_js_1.default.Stage({
|
|
126
|
+
width: props.width,
|
|
127
|
+
height: props.height,
|
|
128
|
+
container: container.current,
|
|
129
|
+
});
|
|
130
|
+
_setRef(stage.current);
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
fiberRef.current = exports.KonvaRenderer.createContainer(stage.current, constants_js_1.ConcurrentRoot, null, false, null, '', console.error, console.error, console.error, null);
|
|
133
|
+
exports.KonvaRenderer.updateContainer(react_1.default.createElement(Bridge, {}, props.children), fiberRef.current, null, () => { });
|
|
134
|
+
}
|
|
135
|
+
return () => {
|
|
136
|
+
if (isStrictMode) {
|
|
137
|
+
// Delay destruction to allow cancellation on remount
|
|
138
|
+
pendingDestroy.current = setTimeout(destroyStage, 0);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
destroyStage();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}, []);
|
|
145
|
+
react_1.default.useLayoutEffect(() => {
|
|
146
|
+
_setRef(stage.current);
|
|
147
|
+
(0, makeUpdates_js_1.applyNodeProps)(stage.current, props, oldProps);
|
|
148
|
+
// =============================================================================
|
|
149
|
+
// CRITICAL FIX - DO NOT REMOVE
|
|
150
|
+
// =============================================================================
|
|
151
|
+
// This flushSyncFromReconciler wrapper is CRITICAL for React 19 compatibility.
|
|
152
|
+
//
|
|
153
|
+
// THE BUG:
|
|
154
|
+
// When using useSyncExternalStore (MobX, Zustand, etc.) with react-konva,
|
|
155
|
+
// parent component's useLayoutEffect couldn't find newly added Konva nodes.
|
|
156
|
+
// The nodes were added to the store, but not yet rendered to the canvas.
|
|
157
|
+
//
|
|
158
|
+
// ROOT CAUSE:
|
|
159
|
+
// React 19's updateContainer can defer Konva reconciler work to a later
|
|
160
|
+
// microtask. Combined with Bridge component (from its-fine) and Html components
|
|
161
|
+
// that create secondary React roots, this caused child components to render
|
|
162
|
+
// AFTER parent's useLayoutEffect completed.
|
|
163
|
+
//
|
|
164
|
+
// THE FIX:
|
|
165
|
+
// flushSyncFromReconciler forces ALL scheduled Konva reconciler work to
|
|
166
|
+
// complete synchronously within this useLayoutEffect, ensuring child
|
|
167
|
+
// components render before any parent effects run.
|
|
168
|
+
//
|
|
169
|
+
// WARNING - NOT COVERED BY TESTS:
|
|
170
|
+
// This bug CANNOT be reproduced in local test environments (Vitest/Playwright).
|
|
171
|
+
// It only manifests in production builds with specific conditions:
|
|
172
|
+
// - MobX/useSyncExternalStore for state management
|
|
173
|
+
// - Html components with secondary React roots using Bridge
|
|
174
|
+
// - Complex component hierarchies (multiple pages/stages)
|
|
175
|
+
// The fix was verified in Polotno production app.
|
|
176
|
+
// =============================================================================
|
|
177
|
+
exports.KonvaRenderer.flushSyncFromReconciler(() => {
|
|
178
|
+
exports.KonvaRenderer.updateContainer(react_1.default.createElement(Bridge, {}, props.children), fiberRef.current, null);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
return react_1.default.createElement('div', {
|
|
182
|
+
ref: container,
|
|
183
|
+
id: props.id,
|
|
184
|
+
accessKey: props.accessKey,
|
|
185
|
+
className: props.className,
|
|
186
|
+
role: props.role,
|
|
187
|
+
style: props.style,
|
|
188
|
+
tabIndex: props.tabIndex,
|
|
189
|
+
title: props.title,
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
exports.Layer = 'Layer';
|
|
193
|
+
exports.FastLayer = 'FastLayer';
|
|
194
|
+
exports.Group = 'Group';
|
|
195
|
+
exports.Label = 'Label';
|
|
196
|
+
exports.Rect = 'Rect';
|
|
197
|
+
exports.Circle = 'Circle';
|
|
198
|
+
exports.Ellipse = 'Ellipse';
|
|
199
|
+
exports.Wedge = 'Wedge';
|
|
200
|
+
exports.Line = 'Line';
|
|
201
|
+
exports.Sprite = 'Sprite';
|
|
202
|
+
exports.Image = 'Image';
|
|
203
|
+
exports.Text = 'Text';
|
|
204
|
+
exports.TextPath = 'TextPath';
|
|
205
|
+
exports.Star = 'Star';
|
|
206
|
+
exports.Ring = 'Ring';
|
|
207
|
+
exports.Arc = 'Arc';
|
|
208
|
+
exports.Tag = 'Tag';
|
|
209
|
+
exports.Path = 'Path';
|
|
210
|
+
exports.RegularPolygon = 'RegularPolygon';
|
|
211
|
+
exports.Arrow = 'Arrow';
|
|
212
|
+
exports.Shape = 'Shape';
|
|
213
|
+
exports.Transformer = 'Transformer';
|
|
214
|
+
exports.version = '19.2.3';
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
exports.KonvaRenderer = (0, react_reconciler_1.default)(HostConfig);
|
|
217
|
+
// Update Stage component declaration
|
|
218
|
+
exports.Stage = react_1.default.forwardRef((props, ref) => {
|
|
219
|
+
return react_1.default.createElement(its_fine_1.FiberProvider, {}, react_1.default.createElement(StageWrap, { ...props, forwardedRef: ref }));
|
|
220
|
+
});
|
|
221
|
+
exports.useStrictMode = makeUpdates_js_1.toggleStrictMode;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HostTransitionContext = exports.NotPendingTransition = 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;
|
|
7
|
+
exports.appendInitialChild = appendInitialChild;
|
|
8
|
+
exports.createInstance = createInstance;
|
|
9
|
+
exports.createTextInstance = createTextInstance;
|
|
10
|
+
exports.finalizeInitialChildren = finalizeInitialChildren;
|
|
11
|
+
exports.getPublicInstance = getPublicInstance;
|
|
12
|
+
exports.prepareForCommit = prepareForCommit;
|
|
13
|
+
exports.preparePortalMount = preparePortalMount;
|
|
14
|
+
exports.prepareUpdate = prepareUpdate;
|
|
15
|
+
exports.resetAfterCommit = resetAfterCommit;
|
|
16
|
+
exports.resetTextContent = resetTextContent;
|
|
17
|
+
exports.shouldDeprioritizeSubtree = shouldDeprioritizeSubtree;
|
|
18
|
+
exports.getRootHostContext = getRootHostContext;
|
|
19
|
+
exports.getChildHostContext = getChildHostContext;
|
|
20
|
+
exports.shouldSetTextContent = shouldSetTextContent;
|
|
21
|
+
exports.appendChild = appendChild;
|
|
22
|
+
exports.appendChildToContainer = appendChildToContainer;
|
|
23
|
+
exports.insertBefore = insertBefore;
|
|
24
|
+
exports.insertInContainerBefore = insertInContainerBefore;
|
|
25
|
+
exports.removeChild = removeChild;
|
|
26
|
+
exports.removeChildFromContainer = removeChildFromContainer;
|
|
27
|
+
exports.commitTextUpdate = commitTextUpdate;
|
|
28
|
+
exports.commitMount = commitMount;
|
|
29
|
+
exports.commitUpdate = commitUpdate;
|
|
30
|
+
exports.hideInstance = hideInstance;
|
|
31
|
+
exports.hideTextInstance = hideTextInstance;
|
|
32
|
+
exports.unhideInstance = unhideInstance;
|
|
33
|
+
exports.unhideTextInstance = unhideTextInstance;
|
|
34
|
+
exports.clearContainer = clearContainer;
|
|
35
|
+
exports.detachDeletedInstance = detachDeletedInstance;
|
|
36
|
+
exports.getInstanceFromNode = getInstanceFromNode;
|
|
37
|
+
exports.beforeActiveInstanceBlur = beforeActiveInstanceBlur;
|
|
38
|
+
exports.afterActiveInstanceBlur = afterActiveInstanceBlur;
|
|
39
|
+
exports.getCurrentEventPriority = getCurrentEventPriority;
|
|
40
|
+
exports.prepareScopeUpdate = prepareScopeUpdate;
|
|
41
|
+
exports.getInstanceFromScope = getInstanceFromScope;
|
|
42
|
+
exports.setCurrentUpdatePriority = setCurrentUpdatePriority;
|
|
43
|
+
exports.getCurrentUpdatePriority = getCurrentUpdatePriority;
|
|
44
|
+
exports.resolveUpdatePriority = resolveUpdatePriority;
|
|
45
|
+
exports.shouldAttemptEagerTransition = shouldAttemptEagerTransition;
|
|
46
|
+
exports.trackSchedulerEvent = trackSchedulerEvent;
|
|
47
|
+
exports.resolveEventType = resolveEventType;
|
|
48
|
+
exports.resolveEventTimeStamp = resolveEventTimeStamp;
|
|
49
|
+
exports.requestPostPaintCallback = requestPostPaintCallback;
|
|
50
|
+
exports.maySuspendCommit = maySuspendCommit;
|
|
51
|
+
exports.preloadInstance = preloadInstance;
|
|
52
|
+
exports.startSuspendingCommit = startSuspendingCommit;
|
|
53
|
+
exports.suspendInstance = suspendInstance;
|
|
54
|
+
exports.waitForCommitToBeReady = waitForCommitToBeReady;
|
|
55
|
+
exports.resetFormInstance = resetFormInstance;
|
|
56
|
+
const react_1 = __importDefault(require("react"));
|
|
57
|
+
const Core_js_1 = __importDefault(require("konva/lib/Core.js"));
|
|
58
|
+
const makeUpdates_js_1 = require("./makeUpdates.js");
|
|
59
|
+
var scheduler_1 = require("scheduler");
|
|
60
|
+
Object.defineProperty(exports, "now", { enumerable: true, get: function () { return scheduler_1.unstable_now; } });
|
|
61
|
+
Object.defineProperty(exports, "idlePriority", { enumerable: true, get: function () { return scheduler_1.unstable_IdlePriority; } });
|
|
62
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return scheduler_1.unstable_runWithPriority; } });
|
|
63
|
+
const constants_js_1 = require("react-reconciler/constants.js");
|
|
64
|
+
const NO_CONTEXT = {};
|
|
65
|
+
const UPDATE_SIGNAL = {};
|
|
66
|
+
// for react-spring capability
|
|
67
|
+
Core_js_1.default.Node.prototype._applyProps = makeUpdates_js_1.applyNodeProps;
|
|
68
|
+
// let currentUpdatePriority: number = NoEventPriority;
|
|
69
|
+
let currentUpdatePriority = constants_js_1.DefaultEventPriority;
|
|
70
|
+
function appendInitialChild(parentInstance, child) {
|
|
71
|
+
if (typeof child === 'string') {
|
|
72
|
+
// Noop for string children of Text (eg <Text>foo</Text>)
|
|
73
|
+
console.error(`Do not use plain text as child of Konva.Node. You are using text: ${child}`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
parentInstance.add(child);
|
|
77
|
+
(0, makeUpdates_js_1.updatePicture)(parentInstance);
|
|
78
|
+
}
|
|
79
|
+
function createInstance(type, props, internalInstanceHandle) {
|
|
80
|
+
let NodeClass = Core_js_1.default[type];
|
|
81
|
+
if (!NodeClass) {
|
|
82
|
+
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`);
|
|
83
|
+
NodeClass = Core_js_1.default.Group;
|
|
84
|
+
}
|
|
85
|
+
// we need to split props into events and non events
|
|
86
|
+
// we we can pass non events into constructor directly
|
|
87
|
+
// that way the performance should be better
|
|
88
|
+
// we we apply change "applyNodeProps"
|
|
89
|
+
// then it will trigger change events on first run
|
|
90
|
+
// but we don't need them!
|
|
91
|
+
const propsWithoutEvents = {};
|
|
92
|
+
const propsWithOnlyEvents = {};
|
|
93
|
+
for (var key in props) {
|
|
94
|
+
// ignore ref
|
|
95
|
+
if (key === 'ref') {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
var isEvent = key.slice(0, 2) === 'on';
|
|
99
|
+
if (isEvent) {
|
|
100
|
+
propsWithOnlyEvents[key] = props[key];
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
propsWithoutEvents[key] = props[key];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const instance = new NodeClass(propsWithoutEvents);
|
|
107
|
+
(0, makeUpdates_js_1.applyNodeProps)(instance, propsWithOnlyEvents);
|
|
108
|
+
return instance;
|
|
109
|
+
}
|
|
110
|
+
function createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
|
|
111
|
+
console.error(`Text components are not supported for now in ReactKonva. Your text is: "${text}"`);
|
|
112
|
+
}
|
|
113
|
+
function finalizeInitialChildren(domElement, type, props) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function getPublicInstance(instance) {
|
|
117
|
+
return instance;
|
|
118
|
+
}
|
|
119
|
+
function prepareForCommit() {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
function preparePortalMount() {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
function prepareUpdate(domElement, type, oldProps, newProps) {
|
|
126
|
+
return UPDATE_SIGNAL;
|
|
127
|
+
}
|
|
128
|
+
function resetAfterCommit() {
|
|
129
|
+
// Noop
|
|
130
|
+
}
|
|
131
|
+
function resetTextContent(domElement) {
|
|
132
|
+
// Noop
|
|
133
|
+
}
|
|
134
|
+
function shouldDeprioritizeSubtree(type, props) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
function getRootHostContext() {
|
|
138
|
+
return NO_CONTEXT;
|
|
139
|
+
}
|
|
140
|
+
function getChildHostContext() {
|
|
141
|
+
return NO_CONTEXT;
|
|
142
|
+
}
|
|
143
|
+
exports.scheduleTimeout = setTimeout;
|
|
144
|
+
exports.cancelTimeout = clearTimeout;
|
|
145
|
+
exports.supportsMicrotasks = true;
|
|
146
|
+
// Run microtasks synchronously for immediate updates
|
|
147
|
+
const scheduleMicrotask = (fn) => {
|
|
148
|
+
fn();
|
|
149
|
+
};
|
|
150
|
+
exports.scheduleMicrotask = scheduleMicrotask;
|
|
151
|
+
exports.noTimeout = -1;
|
|
152
|
+
// export const schedulePassiveEffects = scheduleDeferredCallback;
|
|
153
|
+
// export const cancelPassiveEffects = cancelDeferredCallback;
|
|
154
|
+
function shouldSetTextContent(type, props) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
// The Konva renderer is secondary to the React DOM renderer.
|
|
158
|
+
exports.isPrimaryRenderer = false;
|
|
159
|
+
exports.warnsIfNotActing = false;
|
|
160
|
+
exports.supportsMutation = true;
|
|
161
|
+
exports.supportsPersistence = false;
|
|
162
|
+
exports.supportsHydration = false;
|
|
163
|
+
function appendChild(parentInstance, child) {
|
|
164
|
+
if (child.parent === parentInstance) {
|
|
165
|
+
child.moveToTop();
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
parentInstance.add(child);
|
|
169
|
+
}
|
|
170
|
+
(0, makeUpdates_js_1.updatePicture)(parentInstance);
|
|
171
|
+
}
|
|
172
|
+
function appendChildToContainer(parentInstance, child) {
|
|
173
|
+
if (child.parent === parentInstance) {
|
|
174
|
+
child.moveToTop();
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
parentInstance.add(child);
|
|
178
|
+
}
|
|
179
|
+
(0, makeUpdates_js_1.updatePicture)(parentInstance);
|
|
180
|
+
}
|
|
181
|
+
function insertBefore(parentInstance, child, beforeChild) {
|
|
182
|
+
// child._remove() will not stop dragging
|
|
183
|
+
// but child.remove() will stop it, but we don't need it
|
|
184
|
+
// removing will reset zIndexes
|
|
185
|
+
child._remove();
|
|
186
|
+
parentInstance.add(child);
|
|
187
|
+
child.setZIndex(beforeChild.getZIndex());
|
|
188
|
+
(0, makeUpdates_js_1.updatePicture)(parentInstance);
|
|
189
|
+
}
|
|
190
|
+
function insertInContainerBefore(parentInstance, child, beforeChild) {
|
|
191
|
+
insertBefore(parentInstance, child, beforeChild);
|
|
192
|
+
}
|
|
193
|
+
function removeChild(parentInstance, child) {
|
|
194
|
+
child.destroy();
|
|
195
|
+
child.off(makeUpdates_js_1.EVENTS_NAMESPACE);
|
|
196
|
+
(0, makeUpdates_js_1.updatePicture)(parentInstance);
|
|
197
|
+
}
|
|
198
|
+
function removeChildFromContainer(parentInstance, child) {
|
|
199
|
+
child.destroy();
|
|
200
|
+
child.off(makeUpdates_js_1.EVENTS_NAMESPACE);
|
|
201
|
+
(0, makeUpdates_js_1.updatePicture)(parentInstance);
|
|
202
|
+
}
|
|
203
|
+
function commitTextUpdate(textInstance, oldText, newText) {
|
|
204
|
+
console.error(`Text components are not yet supported in ReactKonva. You text is: "${newText}"`);
|
|
205
|
+
}
|
|
206
|
+
function commitMount(instance, type, newProps) {
|
|
207
|
+
// Noop
|
|
208
|
+
}
|
|
209
|
+
function commitUpdate(instance, type, oldProps, newProps) {
|
|
210
|
+
(0, makeUpdates_js_1.applyNodeProps)(instance, newProps, oldProps);
|
|
211
|
+
}
|
|
212
|
+
function hideInstance(instance) {
|
|
213
|
+
instance.hide();
|
|
214
|
+
(0, makeUpdates_js_1.updatePicture)(instance);
|
|
215
|
+
}
|
|
216
|
+
function hideTextInstance(textInstance) {
|
|
217
|
+
// Noop
|
|
218
|
+
}
|
|
219
|
+
function unhideInstance(instance, props) {
|
|
220
|
+
if (props.visible == null || props.visible) {
|
|
221
|
+
instance.show();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function unhideTextInstance(textInstance, text) {
|
|
225
|
+
// Noop
|
|
226
|
+
}
|
|
227
|
+
function clearContainer(container) {
|
|
228
|
+
// Noop
|
|
229
|
+
}
|
|
230
|
+
function detachDeletedInstance() { }
|
|
231
|
+
function getInstanceFromNode() {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
function beforeActiveInstanceBlur() { }
|
|
235
|
+
function afterActiveInstanceBlur() { }
|
|
236
|
+
function getCurrentEventPriority() {
|
|
237
|
+
return constants_js_1.DefaultEventPriority;
|
|
238
|
+
}
|
|
239
|
+
function prepareScopeUpdate() { }
|
|
240
|
+
function getInstanceFromScope() {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
function setCurrentUpdatePriority(newPriority) {
|
|
244
|
+
currentUpdatePriority = newPriority;
|
|
245
|
+
}
|
|
246
|
+
function getCurrentUpdatePriority() {
|
|
247
|
+
return currentUpdatePriority;
|
|
248
|
+
}
|
|
249
|
+
function resolveUpdatePriority() {
|
|
250
|
+
return constants_js_1.DiscreteEventPriority;
|
|
251
|
+
}
|
|
252
|
+
function shouldAttemptEagerTransition() {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
function trackSchedulerEvent() { }
|
|
256
|
+
function resolveEventType() {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
function resolveEventTimeStamp() {
|
|
260
|
+
return -1.1;
|
|
261
|
+
}
|
|
262
|
+
function requestPostPaintCallback() { }
|
|
263
|
+
function maySuspendCommit() {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
function preloadInstance() {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
function startSuspendingCommit() { }
|
|
270
|
+
function suspendInstance() { }
|
|
271
|
+
function waitForCommitToBeReady() {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
exports.NotPendingTransition = null;
|
|
275
|
+
// React 19 transition context - create as React context that can be cast by reconciler
|
|
276
|
+
exports.HostTransitionContext = react_1.default.createContext(null);
|
|
277
|
+
function resetFormInstance() { }
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVENTS_NAMESPACE = void 0;
|
|
4
|
+
exports.toggleStrictMode = toggleStrictMode;
|
|
5
|
+
exports.applyNodeProps = applyNodeProps;
|
|
6
|
+
exports.updatePicture = updatePicture;
|
|
7
|
+
const Global_js_1 = require("konva/lib/Global.js");
|
|
8
|
+
const propsToSkip = {
|
|
9
|
+
children: true,
|
|
10
|
+
ref: true,
|
|
11
|
+
key: true,
|
|
12
|
+
style: true,
|
|
13
|
+
forwardedRef: true,
|
|
14
|
+
unstable_applyCache: true,
|
|
15
|
+
unstable_applyDrawHitFromCache: true,
|
|
16
|
+
};
|
|
17
|
+
let zIndexWarningShowed = false;
|
|
18
|
+
let dragWarningShowed = false;
|
|
19
|
+
exports.EVENTS_NAMESPACE = '.react-konva-event';
|
|
20
|
+
let useStrictMode = false;
|
|
21
|
+
function toggleStrictMode(value) {
|
|
22
|
+
useStrictMode = value;
|
|
23
|
+
}
|
|
24
|
+
const DRAGGABLE_WARNING = `ReactKonva: You have a Konva node with draggable = true and position defined but no onDragMove or onDragEnd events are handled.
|
|
25
|
+
Position of a node will be changed during drag&drop, so you should update state of the react app as well.
|
|
26
|
+
Consider to add onDragMove or onDragEnd events.
|
|
27
|
+
For more info see: https://github.com/konvajs/react-konva/issues/256
|
|
28
|
+
`;
|
|
29
|
+
const Z_INDEX_WARNING = `ReactKonva: You are using "zIndex" attribute for a Konva node.
|
|
30
|
+
react-konva may get confused with ordering. Just define correct order of elements in your render function of a component.
|
|
31
|
+
For more info see: https://github.com/konvajs/react-konva/issues/194
|
|
32
|
+
`;
|
|
33
|
+
const EMPTY_PROPS = {};
|
|
34
|
+
function applyNodeProps(instance, props, oldProps = EMPTY_PROPS) {
|
|
35
|
+
// don't use zIndex in react-konva
|
|
36
|
+
if (!zIndexWarningShowed && 'zIndex' in props) {
|
|
37
|
+
console.warn(Z_INDEX_WARNING);
|
|
38
|
+
zIndexWarningShowed = true;
|
|
39
|
+
}
|
|
40
|
+
// check correct draggable usage
|
|
41
|
+
if (!dragWarningShowed && props.draggable) {
|
|
42
|
+
var hasPosition = props.x !== undefined || props.y !== undefined;
|
|
43
|
+
var hasEvents = props.onDragEnd || props.onDragMove;
|
|
44
|
+
if (hasPosition && !hasEvents) {
|
|
45
|
+
console.warn(DRAGGABLE_WARNING);
|
|
46
|
+
dragWarningShowed = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// check old props
|
|
50
|
+
// we need to unset properties that are not in new props
|
|
51
|
+
// and remove all events
|
|
52
|
+
for (var key in oldProps) {
|
|
53
|
+
if (propsToSkip[key]) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
var isEvent = key.slice(0, 2) === 'on';
|
|
57
|
+
var propChanged = oldProps[key] !== props[key];
|
|
58
|
+
// if that is a changed event, we need to remove it
|
|
59
|
+
if (isEvent && propChanged) {
|
|
60
|
+
var eventName = key.substr(2).toLowerCase();
|
|
61
|
+
if (eventName.substr(0, 7) === 'content') {
|
|
62
|
+
eventName =
|
|
63
|
+
'content' +
|
|
64
|
+
eventName.substr(7, 1).toUpperCase() +
|
|
65
|
+
eventName.substr(8);
|
|
66
|
+
}
|
|
67
|
+
instance.off(eventName, oldProps[key]);
|
|
68
|
+
}
|
|
69
|
+
var toRemove = !props.hasOwnProperty(key);
|
|
70
|
+
if (toRemove) {
|
|
71
|
+
instance.setAttr(key, undefined);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
var strictUpdate = useStrictMode || props._useStrictMode;
|
|
75
|
+
var updatedProps = {};
|
|
76
|
+
var hasUpdates = false;
|
|
77
|
+
const newEvents = {};
|
|
78
|
+
for (var key in props) {
|
|
79
|
+
if (propsToSkip[key]) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
var isEvent = key.slice(0, 2) === 'on';
|
|
83
|
+
var toAdd = oldProps[key] !== props[key];
|
|
84
|
+
if (isEvent && toAdd) {
|
|
85
|
+
var eventName = key.substr(2).toLowerCase();
|
|
86
|
+
if (eventName.substr(0, 7) === 'content') {
|
|
87
|
+
eventName =
|
|
88
|
+
'content' +
|
|
89
|
+
eventName.substr(7, 1).toUpperCase() +
|
|
90
|
+
eventName.substr(8);
|
|
91
|
+
}
|
|
92
|
+
// check that event is not undefined
|
|
93
|
+
if (props[key]) {
|
|
94
|
+
newEvents[eventName] = props[key];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!isEvent &&
|
|
98
|
+
(props[key] !== oldProps[key] ||
|
|
99
|
+
(strictUpdate && props[key] !== instance.getAttr(key)))) {
|
|
100
|
+
hasUpdates = true;
|
|
101
|
+
updatedProps[key] = props[key];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (hasUpdates) {
|
|
105
|
+
instance.setAttrs(updatedProps);
|
|
106
|
+
updatePicture(instance);
|
|
107
|
+
}
|
|
108
|
+
// subscribe to events AFTER we set attrs
|
|
109
|
+
// we need it to fix https://github.com/konvajs/react-konva/issues/471
|
|
110
|
+
// settings attrs may add events. Like "draggable: true" will add "mousedown" listener
|
|
111
|
+
for (var eventName in newEvents) {
|
|
112
|
+
// first clear any existing listeners, it is required for strict mode
|
|
113
|
+
instance.off(eventName + exports.EVENTS_NAMESPACE);
|
|
114
|
+
// then attach new one
|
|
115
|
+
instance.on(eventName + exports.EVENTS_NAMESPACE, newEvents[eventName]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function updatePicture(node) {
|
|
119
|
+
if (!Global_js_1.Konva.autoDrawEnabled) {
|
|
120
|
+
var drawingNode = node.getLayer() || node.getStage();
|
|
121
|
+
drawingNode && drawingNode.batchDraw();
|
|
122
|
+
}
|
|
123
|
+
}
|