@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.
@@ -0,0 +1,220 @@
1
+ import React from 'react';
2
+ import Konva from 'konva/lib/Core.js';
3
+ import { applyNodeProps, updatePicture, EVENTS_NAMESPACE, } from './makeUpdates.js';
4
+ export { unstable_now as now, unstable_IdlePriority as idlePriority, unstable_runWithPriority as run, } from 'scheduler';
5
+ import {
6
+ // NoEventPriority,
7
+ DefaultEventPriority, DiscreteEventPriority, } from 'react-reconciler/constants.js';
8
+ const NO_CONTEXT = {};
9
+ const UPDATE_SIGNAL = {};
10
+ // for react-spring capability
11
+ Konva.Node.prototype._applyProps = applyNodeProps;
12
+ // let currentUpdatePriority: number = NoEventPriority;
13
+ let currentUpdatePriority = DefaultEventPriority;
14
+ export function appendInitialChild(parentInstance, child) {
15
+ if (typeof child === 'string') {
16
+ // Noop for string children of Text (eg <Text>foo</Text>)
17
+ console.error(`Do not use plain text as child of Konva.Node. You are using text: ${child}`);
18
+ return;
19
+ }
20
+ parentInstance.add(child);
21
+ updatePicture(parentInstance);
22
+ }
23
+ export function createInstance(type, props, internalInstanceHandle) {
24
+ let NodeClass = Konva[type];
25
+ if (!NodeClass) {
26
+ 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`);
27
+ NodeClass = Konva.Group;
28
+ }
29
+ // we need to split props into events and non events
30
+ // we we can pass non events into constructor directly
31
+ // that way the performance should be better
32
+ // we we apply change "applyNodeProps"
33
+ // then it will trigger change events on first run
34
+ // but we don't need them!
35
+ const propsWithoutEvents = {};
36
+ const propsWithOnlyEvents = {};
37
+ for (var key in props) {
38
+ // ignore ref
39
+ if (key === 'ref') {
40
+ continue;
41
+ }
42
+ var isEvent = key.slice(0, 2) === 'on';
43
+ if (isEvent) {
44
+ propsWithOnlyEvents[key] = props[key];
45
+ }
46
+ else {
47
+ propsWithoutEvents[key] = props[key];
48
+ }
49
+ }
50
+ const instance = new NodeClass(propsWithoutEvents);
51
+ applyNodeProps(instance, propsWithOnlyEvents);
52
+ return instance;
53
+ }
54
+ export function createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
55
+ console.error(`Text components are not supported for now in ReactKonva. Your text is: "${text}"`);
56
+ }
57
+ export function finalizeInitialChildren(domElement, type, props) {
58
+ return false;
59
+ }
60
+ export function getPublicInstance(instance) {
61
+ return instance;
62
+ }
63
+ export function prepareForCommit() {
64
+ return null;
65
+ }
66
+ export function preparePortalMount() {
67
+ return null;
68
+ }
69
+ export function prepareUpdate(domElement, type, oldProps, newProps) {
70
+ return UPDATE_SIGNAL;
71
+ }
72
+ export function resetAfterCommit() {
73
+ // Noop
74
+ }
75
+ export function resetTextContent(domElement) {
76
+ // Noop
77
+ }
78
+ export function shouldDeprioritizeSubtree(type, props) {
79
+ return false;
80
+ }
81
+ export function getRootHostContext() {
82
+ return NO_CONTEXT;
83
+ }
84
+ export function getChildHostContext() {
85
+ return NO_CONTEXT;
86
+ }
87
+ export const scheduleTimeout = setTimeout;
88
+ export const cancelTimeout = clearTimeout;
89
+ export const supportsMicrotasks = true;
90
+ // Run microtasks synchronously for immediate updates
91
+ export const scheduleMicrotask = (fn) => {
92
+ fn();
93
+ };
94
+ export const noTimeout = -1;
95
+ // export const schedulePassiveEffects = scheduleDeferredCallback;
96
+ // export const cancelPassiveEffects = cancelDeferredCallback;
97
+ export function shouldSetTextContent(type, props) {
98
+ return false;
99
+ }
100
+ // The Konva renderer is secondary to the React DOM renderer.
101
+ export const isPrimaryRenderer = false;
102
+ export const warnsIfNotActing = false;
103
+ export const supportsMutation = true;
104
+ export const supportsPersistence = false;
105
+ export const supportsHydration = false;
106
+ export function appendChild(parentInstance, child) {
107
+ if (child.parent === parentInstance) {
108
+ child.moveToTop();
109
+ }
110
+ else {
111
+ parentInstance.add(child);
112
+ }
113
+ updatePicture(parentInstance);
114
+ }
115
+ export function appendChildToContainer(parentInstance, child) {
116
+ if (child.parent === parentInstance) {
117
+ child.moveToTop();
118
+ }
119
+ else {
120
+ parentInstance.add(child);
121
+ }
122
+ updatePicture(parentInstance);
123
+ }
124
+ export function insertBefore(parentInstance, child, beforeChild) {
125
+ // child._remove() will not stop dragging
126
+ // but child.remove() will stop it, but we don't need it
127
+ // removing will reset zIndexes
128
+ child._remove();
129
+ parentInstance.add(child);
130
+ child.setZIndex(beforeChild.getZIndex());
131
+ updatePicture(parentInstance);
132
+ }
133
+ export function insertInContainerBefore(parentInstance, child, beforeChild) {
134
+ insertBefore(parentInstance, child, beforeChild);
135
+ }
136
+ export function removeChild(parentInstance, child) {
137
+ child.destroy();
138
+ child.off(EVENTS_NAMESPACE);
139
+ updatePicture(parentInstance);
140
+ }
141
+ export function removeChildFromContainer(parentInstance, child) {
142
+ child.destroy();
143
+ child.off(EVENTS_NAMESPACE);
144
+ updatePicture(parentInstance);
145
+ }
146
+ export function commitTextUpdate(textInstance, oldText, newText) {
147
+ console.error(`Text components are not yet supported in ReactKonva. You text is: "${newText}"`);
148
+ }
149
+ export function commitMount(instance, type, newProps) {
150
+ // Noop
151
+ }
152
+ export function commitUpdate(instance, type, oldProps, newProps) {
153
+ applyNodeProps(instance, newProps, oldProps);
154
+ }
155
+ export function hideInstance(instance) {
156
+ instance.hide();
157
+ updatePicture(instance);
158
+ }
159
+ export function hideTextInstance(textInstance) {
160
+ // Noop
161
+ }
162
+ export function unhideInstance(instance, props) {
163
+ if (props.visible == null || props.visible) {
164
+ instance.show();
165
+ }
166
+ }
167
+ export function unhideTextInstance(textInstance, text) {
168
+ // Noop
169
+ }
170
+ export function clearContainer(container) {
171
+ // Noop
172
+ }
173
+ export function detachDeletedInstance() { }
174
+ export function getInstanceFromNode() {
175
+ return null;
176
+ }
177
+ export function beforeActiveInstanceBlur() { }
178
+ export function afterActiveInstanceBlur() { }
179
+ export function getCurrentEventPriority() {
180
+ return DefaultEventPriority;
181
+ }
182
+ export function prepareScopeUpdate() { }
183
+ export function getInstanceFromScope() {
184
+ return null;
185
+ }
186
+ export function setCurrentUpdatePriority(newPriority) {
187
+ currentUpdatePriority = newPriority;
188
+ }
189
+ export function getCurrentUpdatePriority() {
190
+ return currentUpdatePriority;
191
+ }
192
+ export function resolveUpdatePriority() {
193
+ return DiscreteEventPriority;
194
+ }
195
+ export function shouldAttemptEagerTransition() {
196
+ return false;
197
+ }
198
+ export function trackSchedulerEvent() { }
199
+ export function resolveEventType() {
200
+ return null;
201
+ }
202
+ export function resolveEventTimeStamp() {
203
+ return -1.1;
204
+ }
205
+ export function requestPostPaintCallback() { }
206
+ export function maySuspendCommit() {
207
+ return false;
208
+ }
209
+ export function preloadInstance() {
210
+ return true;
211
+ }
212
+ export function startSuspendingCommit() { }
213
+ export function suspendInstance() { }
214
+ export function waitForCommitToBeReady() {
215
+ return null;
216
+ }
217
+ export const NotPendingTransition = null;
218
+ // React 19 transition context - create as React context that can be cast by reconciler
219
+ export const HostTransitionContext = /* @__PURE__ */ React.createContext(null);
220
+ export function resetFormInstance() { }
@@ -0,0 +1,117 @@
1
+ import { Konva } from 'konva/lib/Global.js';
2
+ const propsToSkip = {
3
+ children: true,
4
+ ref: true,
5
+ key: true,
6
+ style: true,
7
+ forwardedRef: true,
8
+ unstable_applyCache: true,
9
+ unstable_applyDrawHitFromCache: true,
10
+ };
11
+ let zIndexWarningShowed = false;
12
+ let dragWarningShowed = false;
13
+ export const EVENTS_NAMESPACE = '.react-konva-event';
14
+ let useStrictMode = false;
15
+ export function toggleStrictMode(value) {
16
+ useStrictMode = value;
17
+ }
18
+ const DRAGGABLE_WARNING = `ReactKonva: You have a Konva node with draggable = true and position defined but no onDragMove or onDragEnd events are handled.
19
+ Position of a node will be changed during drag&drop, so you should update state of the react app as well.
20
+ Consider to add onDragMove or onDragEnd events.
21
+ For more info see: https://github.com/konvajs/react-konva/issues/256
22
+ `;
23
+ const Z_INDEX_WARNING = `ReactKonva: You are using "zIndex" attribute for a Konva node.
24
+ react-konva may get confused with ordering. Just define correct order of elements in your render function of a component.
25
+ For more info see: https://github.com/konvajs/react-konva/issues/194
26
+ `;
27
+ const EMPTY_PROPS = {};
28
+ export function applyNodeProps(instance, props, oldProps = EMPTY_PROPS) {
29
+ // don't use zIndex in react-konva
30
+ if (!zIndexWarningShowed && 'zIndex' in props) {
31
+ console.warn(Z_INDEX_WARNING);
32
+ zIndexWarningShowed = true;
33
+ }
34
+ // check correct draggable usage
35
+ if (!dragWarningShowed && props.draggable) {
36
+ var hasPosition = props.x !== undefined || props.y !== undefined;
37
+ var hasEvents = props.onDragEnd || props.onDragMove;
38
+ if (hasPosition && !hasEvents) {
39
+ console.warn(DRAGGABLE_WARNING);
40
+ dragWarningShowed = true;
41
+ }
42
+ }
43
+ // check old props
44
+ // we need to unset properties that are not in new props
45
+ // and remove all events
46
+ for (var key in oldProps) {
47
+ if (propsToSkip[key]) {
48
+ continue;
49
+ }
50
+ var isEvent = key.slice(0, 2) === 'on';
51
+ var propChanged = oldProps[key] !== props[key];
52
+ // if that is a changed event, we need to remove it
53
+ if (isEvent && propChanged) {
54
+ var eventName = key.substr(2).toLowerCase();
55
+ if (eventName.substr(0, 7) === 'content') {
56
+ eventName =
57
+ 'content' +
58
+ eventName.substr(7, 1).toUpperCase() +
59
+ eventName.substr(8);
60
+ }
61
+ instance.off(eventName, oldProps[key]);
62
+ }
63
+ var toRemove = !props.hasOwnProperty(key);
64
+ if (toRemove) {
65
+ instance.setAttr(key, undefined);
66
+ }
67
+ }
68
+ var strictUpdate = useStrictMode || props._useStrictMode;
69
+ var updatedProps = {};
70
+ var hasUpdates = false;
71
+ const newEvents = {};
72
+ for (var key in props) {
73
+ if (propsToSkip[key]) {
74
+ continue;
75
+ }
76
+ var isEvent = key.slice(0, 2) === 'on';
77
+ var toAdd = oldProps[key] !== props[key];
78
+ if (isEvent && toAdd) {
79
+ var eventName = key.substr(2).toLowerCase();
80
+ if (eventName.substr(0, 7) === 'content') {
81
+ eventName =
82
+ 'content' +
83
+ eventName.substr(7, 1).toUpperCase() +
84
+ eventName.substr(8);
85
+ }
86
+ // check that event is not undefined
87
+ if (props[key]) {
88
+ newEvents[eventName] = props[key];
89
+ }
90
+ }
91
+ if (!isEvent &&
92
+ (props[key] !== oldProps[key] ||
93
+ (strictUpdate && props[key] !== instance.getAttr(key)))) {
94
+ hasUpdates = true;
95
+ updatedProps[key] = props[key];
96
+ }
97
+ }
98
+ if (hasUpdates) {
99
+ instance.setAttrs(updatedProps);
100
+ updatePicture(instance);
101
+ }
102
+ // subscribe to events AFTER we set attrs
103
+ // we need it to fix https://github.com/konvajs/react-konva/issues/471
104
+ // settings attrs may add events. Like "draggable: true" will add "mousedown" listener
105
+ for (var eventName in newEvents) {
106
+ // first clear any existing listeners, it is required for strict mode
107
+ instance.off(eventName + EVENTS_NAMESPACE);
108
+ // then attach new one
109
+ instance.on(eventName + EVENTS_NAMESPACE, newEvents[eventName]);
110
+ }
111
+ }
112
+ export function updatePicture(node) {
113
+ if (!Konva.autoDrawEnabled) {
114
+ var drawingNode = node.getLayer() || node.getStage();
115
+ drawingNode && drawingNode.batchDraw();
116
+ }
117
+ }
@@ -0,0 +1,25 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ require("konva");
25
+ __exportStar(require("./ReactKonvaCore.js"), exports);
@@ -0,0 +1,117 @@
1
+ // special file for minimal import
2
+ import * as React from 'react';
3
+ import * as ReactReconciler from 'react-reconciler';
4
+ import Konva from 'konva';
5
+ import { useContextBridge } from 'its-fine';
6
+
7
+ export interface KonvaNodeEvents {
8
+ onMouseOver?(evt: Konva.KonvaEventObject<MouseEvent>): void;
9
+ onMouseMove?(evt: Konva.KonvaEventObject<MouseEvent>): void;
10
+ onMouseOut?(evt: Konva.KonvaEventObject<MouseEvent>): void;
11
+ onMouseEnter?(evt: Konva.KonvaEventObject<MouseEvent>): void;
12
+ onMouseLeave?(evt: Konva.KonvaEventObject<MouseEvent>): void;
13
+ onMouseDown?(evt: Konva.KonvaEventObject<MouseEvent>): void;
14
+ onMouseUp?(evt: Konva.KonvaEventObject<MouseEvent>): void;
15
+ onWheel?(evt: Konva.KonvaEventObject<WheelEvent>): void;
16
+ onClick?(evt: Konva.KonvaEventObject<MouseEvent>): void;
17
+ onDblClick?(evt: Konva.KonvaEventObject<MouseEvent>): void;
18
+ onTouchStart?(evt: Konva.KonvaEventObject<TouchEvent>): void;
19
+ onTouchMove?(evt: Konva.KonvaEventObject<TouchEvent>): void;
20
+ onTouchEnd?(evt: Konva.KonvaEventObject<TouchEvent>): void;
21
+ onTap?(evt: Konva.KonvaEventObject<TouchEvent>): void;
22
+ onDblTap?(evt: Konva.KonvaEventObject<TouchEvent>): void;
23
+ onDragStart?(evt: Konva.KonvaEventObject<DragEvent>): void;
24
+ onDragMove?(evt: Konva.KonvaEventObject<DragEvent>): void;
25
+ onDragEnd?(evt: Konva.KonvaEventObject<DragEvent>): void;
26
+ onTransform?(evt: Konva.KonvaEventObject<Event>): void;
27
+ onTransformStart?(evt: Konva.KonvaEventObject<Event>): void;
28
+ onTransformEnd?(evt: Konva.KonvaEventObject<Event>): void;
29
+ onContextMenu?(evt: Konva.KonvaEventObject<PointerEvent>): void;
30
+ onPointerDown?(evt: Konva.KonvaEventObject<PointerEvent>): void;
31
+ onPointerMove?(evt: Konva.KonvaEventObject<PointerEvent>): void;
32
+ onPointerUp?(evt: Konva.KonvaEventObject<PointerEvent>): void;
33
+ onPointerCancel?(evt: Konva.KonvaEventObject<PointerEvent>): void;
34
+ onPointerEnter?(evt: Konva.KonvaEventObject<PointerEvent>): void;
35
+ onPointerLeave?(evt: Konva.KonvaEventObject<PointerEvent>): void;
36
+ onPointerOver?(evt: Konva.KonvaEventObject<PointerEvent>): void;
37
+ onPointerOut?(evt: Konva.KonvaEventObject<PointerEvent>): void;
38
+ onPointerClick?(evt: Konva.KonvaEventObject<PointerEvent>): void;
39
+ onPointerDblClick?(evt: Konva.KonvaEventObject<PointerEvent>): void;
40
+ onGotPointerCapture?(evt: Konva.KonvaEventObject<PointerEvent>): void;
41
+ onLostPointerCapture?(evt: Konva.KonvaEventObject<PointerEvent>): void;
42
+ }
43
+
44
+ export interface KonvaNodeComponent<
45
+ Node extends Konva.Node,
46
+ Props = Konva.NodeConfig
47
+ // We use React.ClassAttributes to fake the 'ref' attribute. This will ensure
48
+ // consumers get the proper 'Node' type in 'ref' instead of the wrapper
49
+ // component type.
50
+ > extends React.FC<Props & KonvaNodeEvents & React.ClassAttributes<Node>> {
51
+ getPublicInstance(): Node;
52
+ getNativeNode(): Node;
53
+ // putEventListener(type: string, listener: Function): void;
54
+ // handleEvent(event: Event): void;
55
+ }
56
+
57
+ export interface StageProps
58
+ extends Konva.NodeConfig,
59
+ KonvaNodeEvents,
60
+ Pick<
61
+ React.HTMLAttributes<HTMLDivElement>,
62
+ 'className' | 'role' | 'style' | 'tabIndex' | 'title'
63
+ > {}
64
+
65
+ // Stage is the only real class because the others are stubs that only know how
66
+ // to be rendered when they are under stage. Since there is no real backing
67
+ // class and are in reality are a string literal we don't want users to actually
68
+ // try and use them as a type. By defining them as a variable with an interface
69
+ // consumers will not be able to use the values as a type or constructor.
70
+ // The down side to this approach, is that typescript thinks the type is a
71
+ // function, but if the user tries to call it a runtime exception will occur.
72
+
73
+ export var Stage: KonvaNodeComponent<Konva.Stage, StageProps>;
74
+ export var Layer: KonvaNodeComponent<Konva.Layer, Konva.LayerConfig>;
75
+ export var FastLayer: KonvaNodeComponent<Konva.FastLayer, Konva.LayerConfig>;
76
+ export var Group: KonvaNodeComponent<Konva.Group, Konva.GroupConfig>;
77
+ export var Label: KonvaNodeComponent<Konva.Label, Konva.LabelConfig>;
78
+
79
+ /** Shapes */
80
+ export var Rect: KonvaNodeComponent<Konva.Rect, Konva.RectConfig>;
81
+ export var Circle: KonvaNodeComponent<Konva.Circle, Konva.CircleConfig>;
82
+ export var Ellipse: KonvaNodeComponent<Konva.Ellipse, Konva.EllipseConfig>;
83
+ export var Wedge: KonvaNodeComponent<Konva.Wedge, Konva.WedgeConfig>;
84
+ export var Transformer: KonvaNodeComponent<
85
+ Konva.Transformer,
86
+ Konva.TransformerConfig
87
+ >;
88
+ export var Line: KonvaNodeComponent<Konva.Line, Konva.LineConfig>;
89
+ export var Sprite: KonvaNodeComponent<Konva.Sprite, Konva.SpriteConfig>;
90
+ export var Image: KonvaNodeComponent<Konva.Image, Konva.ImageConfig>;
91
+ export var Text: KonvaNodeComponent<Konva.Text, Konva.TextConfig>;
92
+ export var TextPath: KonvaNodeComponent<Konva.TextPath, Konva.TextPathConfig>;
93
+ export var Star: KonvaNodeComponent<Konva.Star, Konva.StarConfig>;
94
+ export var Ring: KonvaNodeComponent<Konva.Ring, Konva.RingConfig>;
95
+ export var Arc: KonvaNodeComponent<Konva.Arc, Konva.ArcConfig>;
96
+ export var Tag: KonvaNodeComponent<Konva.Tag, Konva.TagConfig>;
97
+ export var Path: KonvaNodeComponent<Konva.Path, Konva.PathConfig>;
98
+ export var RegularPolygon: KonvaNodeComponent<
99
+ Konva.RegularPolygon,
100
+ Konva.RegularPolygonConfig
101
+ >;
102
+ export var Arrow: KonvaNodeComponent<Konva.Arrow, Konva.ArrowConfig>;
103
+ export var Shape: KonvaNodeComponent<Konva.Shape, Konva.ShapeConfig>;
104
+
105
+ export var useStrictMode: (useStrictMode: boolean) => void;
106
+ export var KonvaRenderer: ReactReconciler.Reconciler<
107
+ any,
108
+ any,
109
+ any,
110
+ any,
111
+ any,
112
+ any
113
+ >;
114
+
115
+ export var version: string;
116
+
117
+ export { useContextBridge };