@inditextech/weave-react 0.1.1 → 0.2.1

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/dist/react.js CHANGED
@@ -1,866 +1,310 @@
1
- import w from "react";
2
- import { WeaveStageGridPlugin as cr, WeaveStagePanningPlugin as lr, WeaveStageResizePlugin as fr, WeaveStageZoomPlugin as dr, WeaveNodesSelectionPlugin as vr, WeaveStageDropAreaPlugin as gr, WeaveConnectedUsersPlugin as pr, WeaveUsersPointersPlugin as hr, WeaveCopyPasteNodesPlugin as br, Weave as mr } from "@inditextech/weave-sdk";
3
- var Ue = { exports: {} }, ae = {};
4
- /**
5
- * @license React
6
- * react-jsx-runtime.development.js
7
- *
8
- * Copyright (c) Facebook, Inc. and its affiliates.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- */
13
- (function() {
14
- var c = w, o = Symbol.for("react.element"), n = Symbol.for("react.portal"), m = Symbol.for("react.fragment"), O = Symbol.for("react.strict_mode"), U = Symbol.for("react.profiler"), M = Symbol.for("react.provider"), I = Symbol.for("react.context"), x = Symbol.for("react.forward_ref"), E = Symbol.for("react.suspense"), _ = Symbol.for("react.suspense_list"), R = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), N = Symbol.for("react.offscreen"), H = Symbol.iterator, oe = "@@iterator";
15
- function ie(e) {
16
- if (e === null || typeof e != "object")
17
- return null;
18
- var r = H && e[H] || e[oe];
19
- return typeof r == "function" ? r : null;
20
- }
21
- var A = c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
22
- function g(e) {
23
- {
24
- for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), i = 1; i < r; i++)
25
- t[i - 1] = arguments[i];
26
- se("error", e, t);
27
- }
28
- }
29
- function se(e, r, t) {
30
- {
31
- var i = A.ReactDebugCurrentFrame, l = i.getStackAddendum();
32
- l !== "" && (r += "%s", t = t.concat([l]));
33
- var f = t.map(function(u) {
34
- return String(u);
35
- });
36
- f.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, f);
37
- }
38
- }
39
- var ue = !1, ce = !1, le = !1, K = !1, fe = !1, Y;
40
- Y = Symbol.for("react.module.reference");
41
- function V(e) {
42
- return !!(typeof e == "string" || typeof e == "function" || e === m || e === U || fe || e === O || e === E || e === _ || K || e === N || ue || ce || le || typeof e == "object" && e !== null && (e.$$typeof === D || e.$$typeof === R || e.$$typeof === M || e.$$typeof === I || e.$$typeof === x || // This needs to include all possible module reference object
43
- // types supported by any Flight configuration anywhere since
44
- // we don't know which Flight build this will end up being used
45
- // with.
46
- e.$$typeof === Y || e.getModuleId !== void 0));
47
- }
48
- function z(e, r, t) {
49
- var i = e.displayName;
50
- if (i)
51
- return i;
52
- var l = r.displayName || r.name || "";
53
- return l !== "" ? t + "(" + l + ")" : t;
54
- }
55
- function $(e) {
56
- return e.displayName || "Context";
57
- }
58
- function S(e) {
59
- if (e == null)
60
- return null;
61
- if (typeof e.tag == "number" && g("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
62
- return e.displayName || e.name || null;
63
- if (typeof e == "string")
64
- return e;
65
- switch (e) {
66
- case m:
67
- return "Fragment";
68
- case n:
69
- return "Portal";
70
- case U:
71
- return "Profiler";
72
- case O:
73
- return "StrictMode";
74
- case E:
75
- return "Suspense";
76
- case _:
77
- return "SuspenseList";
78
- }
79
- if (typeof e == "object")
80
- switch (e.$$typeof) {
81
- case I:
82
- var r = e;
83
- return $(r) + ".Consumer";
84
- case M:
85
- var t = e;
86
- return $(t._context) + ".Provider";
87
- case x:
88
- return z(e, e.render, "ForwardRef");
89
- case R:
90
- var i = e.displayName || null;
91
- return i !== null ? i : S(e.type) || "Memo";
92
- case D: {
93
- var l = e, f = l._payload, u = l._init;
94
- try {
95
- return S(u(f));
96
- } catch {
97
- return null;
98
- }
99
- }
100
- }
101
- return null;
102
- }
103
- var j = Object.assign, F = 0, G, X, J, q, Q, a, k;
104
- function P() {
105
- }
106
- P.__reactDisabledLog = !0;
107
- function y() {
108
- {
109
- if (F === 0) {
110
- G = console.log, X = console.info, J = console.warn, q = console.error, Q = console.group, a = console.groupCollapsed, k = console.groupEnd;
111
- var e = {
112
- configurable: !0,
113
- enumerable: !0,
114
- value: P,
115
- writable: !0
116
- };
117
- Object.defineProperties(console, {
118
- info: e,
119
- log: e,
120
- warn: e,
121
- error: e,
122
- group: e,
123
- groupCollapsed: e,
124
- groupEnd: e
125
- });
126
- }
127
- F++;
128
- }
129
- }
130
- function T() {
131
- {
132
- if (F--, F === 0) {
133
- var e = {
134
- configurable: !0,
135
- enumerable: !0,
136
- writable: !0
137
- };
138
- Object.defineProperties(console, {
139
- log: j({}, e, {
140
- value: G
141
- }),
142
- info: j({}, e, {
143
- value: X
144
- }),
145
- warn: j({}, e, {
146
- value: J
147
- }),
148
- error: j({}, e, {
149
- value: q
150
- }),
151
- group: j({}, e, {
152
- value: Q
153
- }),
154
- groupCollapsed: j({}, e, {
155
- value: a
156
- }),
157
- groupEnd: j({}, e, {
158
- value: k
159
- })
160
- });
161
- }
162
- F < 0 && g("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
163
- }
164
- }
165
- var de = A.ReactCurrentDispatcher, ve;
166
- function ee(e, r, t) {
167
- {
168
- if (ve === void 0)
169
- try {
170
- throw Error();
171
- } catch (l) {
172
- var i = l.stack.trim().match(/\n( *(at )?)/);
173
- ve = i && i[1] || "";
174
- }
175
- return `
176
- ` + ve + e;
177
- }
178
- }
179
- var ge = !1, re;
180
- {
181
- var Ye = typeof WeakMap == "function" ? WeakMap : Map;
182
- re = new Ye();
183
- }
184
- function ye(e, r) {
185
- if (!e || ge)
186
- return "";
187
- {
188
- var t = re.get(e);
189
- if (t !== void 0)
190
- return t;
191
- }
192
- var i;
193
- ge = !0;
194
- var l = Error.prepareStackTrace;
195
- Error.prepareStackTrace = void 0;
196
- var f;
197
- f = de.current, de.current = null, y();
198
- try {
199
- if (r) {
200
- var u = function() {
201
- throw Error();
202
- };
203
- if (Object.defineProperty(u.prototype, "props", {
204
- set: function() {
205
- throw Error();
206
- }
207
- }), typeof Reflect == "object" && Reflect.construct) {
208
- try {
209
- Reflect.construct(u, []);
210
- } catch (h) {
211
- i = h;
212
- }
213
- Reflect.construct(e, [], u);
214
- } else {
215
- try {
216
- u.call();
217
- } catch (h) {
218
- i = h;
219
- }
220
- e.call(u.prototype);
221
- }
222
- } else {
223
- try {
224
- throw Error();
225
- } catch (h) {
226
- i = h;
227
- }
228
- e();
229
- }
230
- } catch (h) {
231
- if (h && i && typeof h.stack == "string") {
232
- for (var s = h.stack.split(`
233
- `), p = i.stack.split(`
234
- `), d = s.length - 1, v = p.length - 1; d >= 1 && v >= 0 && s[d] !== p[v]; )
235
- v--;
236
- for (; d >= 1 && v >= 0; d--, v--)
237
- if (s[d] !== p[v]) {
238
- if (d !== 1 || v !== 1)
239
- do
240
- if (d--, v--, v < 0 || s[d] !== p[v]) {
241
- var C = `
242
- ` + s[d].replace(" at new ", " at ");
243
- return e.displayName && C.includes("<anonymous>") && (C = C.replace("<anonymous>", e.displayName)), typeof e == "function" && re.set(e, C), C;
244
- }
245
- while (d >= 1 && v >= 0);
246
- break;
247
- }
248
- }
249
- } finally {
250
- ge = !1, de.current = f, T(), Error.prepareStackTrace = l;
251
- }
252
- var Z = e ? e.displayName || e.name : "", W = Z ? ee(Z) : "";
253
- return typeof e == "function" && re.set(e, W), W;
254
- }
255
- function $e(e, r, t) {
256
- return ye(e, !1);
257
- }
258
- function Le(e) {
259
- var r = e.prototype;
260
- return !!(r && r.isReactComponent);
261
- }
262
- function te(e, r, t) {
263
- if (e == null)
264
- return "";
265
- if (typeof e == "function")
266
- return ye(e, Le(e));
267
- if (typeof e == "string")
268
- return ee(e);
269
- switch (e) {
270
- case E:
271
- return ee("Suspense");
272
- case _:
273
- return ee("SuspenseList");
274
- }
275
- if (typeof e == "object")
276
- switch (e.$$typeof) {
277
- case x:
278
- return $e(e.render);
279
- case R:
280
- return te(e.type, r, t);
281
- case D: {
282
- var i = e, l = i._payload, f = i._init;
283
- try {
284
- return te(f(l), r, t);
285
- } catch {
286
- }
287
- }
288
- }
289
- return "";
290
- }
291
- var B = Object.prototype.hasOwnProperty, Ee = {}, Se = A.ReactDebugCurrentFrame;
292
- function ne(e) {
293
- if (e) {
294
- var r = e._owner, t = te(e.type, e._source, r ? r.type : null);
295
- Se.setExtraStackFrame(t);
296
- } else
297
- Se.setExtraStackFrame(null);
298
- }
299
- function Ze(e, r, t, i, l) {
300
- {
301
- var f = Function.call.bind(B);
302
- for (var u in e)
303
- if (f(e, u)) {
304
- var s = void 0;
305
- try {
306
- if (typeof e[u] != "function") {
307
- var p = Error((i || "React class") + ": " + t + " type `" + u + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[u] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
308
- throw p.name = "Invariant Violation", p;
309
- }
310
- s = e[u](r, u, i, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
311
- } catch (d) {
312
- s = d;
313
- }
314
- s && !(s instanceof Error) && (ne(l), g("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", i || "React class", t, u, typeof s), ne(null)), s instanceof Error && !(s.message in Ee) && (Ee[s.message] = !0, ne(l), g("Failed %s type: %s", t, s.message), ne(null));
315
- }
316
- }
317
- }
318
- var Me = Array.isArray;
319
- function pe(e) {
320
- return Me(e);
321
- }
322
- function Ne(e) {
323
- {
324
- var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
325
- return t;
326
- }
327
- }
328
- function Ve(e) {
329
- try {
330
- return Ce(e), !1;
331
- } catch {
332
- return !0;
333
- }
334
- }
335
- function Ce(e) {
336
- return "" + e;
337
- }
338
- function _e(e) {
339
- if (Ve(e))
340
- return g("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ne(e)), Ce(e);
341
- }
342
- var Pe = A.ReactCurrentOwner, ze = {
343
- key: !0,
344
- ref: !0,
345
- __self: !0,
346
- __source: !0
347
- }, Te, we;
348
- function Be(e) {
349
- if (B.call(e, "ref")) {
350
- var r = Object.getOwnPropertyDescriptor(e, "ref").get;
351
- if (r && r.isReactWarning)
352
- return !1;
353
- }
354
- return e.ref !== void 0;
355
- }
356
- function He(e) {
357
- if (B.call(e, "key")) {
358
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
359
- if (r && r.isReactWarning)
360
- return !1;
361
- }
362
- return e.key !== void 0;
363
- }
364
- function Ke(e, r) {
365
- typeof e.ref == "string" && Pe.current;
366
- }
367
- function Ge(e, r) {
368
- {
369
- var t = function() {
370
- Te || (Te = !0, g("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
371
- };
372
- t.isReactWarning = !0, Object.defineProperty(e, "key", {
373
- get: t,
374
- configurable: !0
375
- });
376
- }
377
- }
378
- function Xe(e, r) {
379
- {
380
- var t = function() {
381
- we || (we = !0, g("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
382
- };
383
- t.isReactWarning = !0, Object.defineProperty(e, "ref", {
384
- get: t,
385
- configurable: !0
386
- });
387
- }
388
- }
389
- var Je = function(e, r, t, i, l, f, u) {
390
- var s = {
391
- // This tag allows us to uniquely identify this as a React Element
392
- $$typeof: o,
393
- // Built-in properties that belong on the element
394
- type: e,
395
- key: r,
396
- ref: t,
397
- props: u,
398
- // Record the component responsible for creating this element.
399
- _owner: f
400
- };
401
- return s._store = {}, Object.defineProperty(s._store, "validated", {
402
- configurable: !1,
403
- enumerable: !1,
404
- writable: !0,
405
- value: !1
406
- }), Object.defineProperty(s, "_self", {
407
- configurable: !1,
408
- enumerable: !1,
409
- writable: !1,
410
- value: i
411
- }), Object.defineProperty(s, "_source", {
412
- configurable: !1,
413
- enumerable: !1,
414
- writable: !1,
415
- value: l
416
- }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
417
- };
418
- function qe(e, r, t, i, l) {
419
- {
420
- var f, u = {}, s = null, p = null;
421
- t !== void 0 && (_e(t), s = "" + t), He(r) && (_e(r.key), s = "" + r.key), Be(r) && (p = r.ref, Ke(r, l));
422
- for (f in r)
423
- B.call(r, f) && !ze.hasOwnProperty(f) && (u[f] = r[f]);
424
- if (e && e.defaultProps) {
425
- var d = e.defaultProps;
426
- for (f in d)
427
- u[f] === void 0 && (u[f] = d[f]);
428
- }
429
- if (s || p) {
430
- var v = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
431
- s && Ge(u, v), p && Xe(u, v);
432
- }
433
- return Je(e, s, p, l, i, Pe.current, u);
434
- }
435
- }
436
- var he = A.ReactCurrentOwner, Oe = A.ReactDebugCurrentFrame;
437
- function L(e) {
438
- if (e) {
439
- var r = e._owner, t = te(e.type, e._source, r ? r.type : null);
440
- Oe.setExtraStackFrame(t);
441
- } else
442
- Oe.setExtraStackFrame(null);
443
- }
444
- var be;
445
- be = !1;
446
- function me(e) {
447
- return typeof e == "object" && e !== null && e.$$typeof === o;
448
- }
449
- function je() {
450
- {
451
- if (he.current) {
452
- var e = S(he.current.type);
453
- if (e)
454
- return `
1
+ import React from "react";
2
+ import { Weave, WeaveConnectedUsersPlugin, WeaveCopyPasteNodesPlugin, WeaveNodesSelectionPlugin, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveUsersPointersPlugin } from "@inditextech/weave-sdk";
3
+ import Konva from "konva";
4
+ import "yjs";
455
5
 
456
- Check the render method of \`` + e + "`.";
457
- }
458
- return "";
459
- }
460
- }
461
- function Qe(e) {
462
- return "";
463
- }
464
- var ke = {};
465
- function er(e) {
466
- {
467
- var r = je();
468
- if (!r) {
469
- var t = typeof e == "string" ? e : e.displayName || e.name;
470
- t && (r = `
6
+ //#region ../types/dist/types.js
7
+ const WEAVE_INSTANCE_STATUS = {
8
+ ["IDLE"]: "idle",
9
+ ["STARTING"]: "starting",
10
+ ["LOADING_FONTS"]: "loadingFonts",
11
+ ["RUNNING"]: "running"
12
+ };
13
+
14
+ //#endregion
15
+ //#region ../../node_modules/zustand/esm/vanilla.mjs
16
+ const createStoreImpl = (createState) => {
17
+ let state;
18
+ const listeners = /* @__PURE__ */ new Set();
19
+ const setState = (partial, replace) => {
20
+ const nextState = typeof partial === "function" ? partial(state) : partial;
21
+ if (!Object.is(nextState, state)) {
22
+ const previousState = state;
23
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
24
+ listeners.forEach((listener) => listener(state, previousState));
25
+ }
26
+ };
27
+ const getState = () => state;
28
+ const getInitialState = () => initialState;
29
+ const subscribe = (listener) => {
30
+ listeners.add(listener);
31
+ return () => listeners.delete(listener);
32
+ };
33
+ const api = {
34
+ setState,
35
+ getState,
36
+ getInitialState,
37
+ subscribe
38
+ };
39
+ const initialState = state = createState(setState, getState, api);
40
+ return api;
41
+ };
42
+ const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
471
43
 
472
- Check the top-level render call using <` + t + ">.");
473
- }
474
- return r;
475
- }
476
- }
477
- function xe(e, r) {
478
- {
479
- if (!e._store || e._store.validated || e.key != null)
480
- return;
481
- e._store.validated = !0;
482
- var t = er(r);
483
- if (ke[t])
484
- return;
485
- ke[t] = !0;
486
- var i = "";
487
- e && e._owner && e._owner !== he.current && (i = " It was passed a child from " + S(e._owner.type) + "."), L(e), g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, i), L(null);
488
- }
489
- }
490
- function Ae(e, r) {
491
- {
492
- if (typeof e != "object")
493
- return;
494
- if (pe(e))
495
- for (var t = 0; t < e.length; t++) {
496
- var i = e[t];
497
- me(i) && xe(i, r);
498
- }
499
- else if (me(e))
500
- e._store && (e._store.validated = !0);
501
- else if (e) {
502
- var l = ie(e);
503
- if (typeof l == "function" && l !== e.entries)
504
- for (var f = l.call(e), u; !(u = f.next()).done; )
505
- me(u.value) && xe(u.value, r);
506
- }
507
- }
508
- }
509
- function rr(e) {
510
- {
511
- var r = e.type;
512
- if (r == null || typeof r == "string")
513
- return;
514
- var t;
515
- if (typeof r == "function")
516
- t = r.propTypes;
517
- else if (typeof r == "object" && (r.$$typeof === x || // Note: Memo only checks outer props here.
518
- // Inner props are checked in the reconciler.
519
- r.$$typeof === R))
520
- t = r.propTypes;
521
- else
522
- return;
523
- if (t) {
524
- var i = S(r);
525
- Ze(t, e.props, "prop", i, e);
526
- } else if (r.PropTypes !== void 0 && !be) {
527
- be = !0;
528
- var l = S(r);
529
- g("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", l || "Unknown");
530
- }
531
- typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && g("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
532
- }
533
- }
534
- function tr(e) {
535
- {
536
- for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
537
- var i = r[t];
538
- if (i !== "children" && i !== "key") {
539
- L(e), g("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", i), L(null);
540
- break;
541
- }
542
- }
543
- e.ref !== null && (L(e), g("Invalid attribute `ref` supplied to `React.Fragment`."), L(null));
544
- }
545
- }
546
- var Ie = {};
547
- function De(e, r, t, i, l, f) {
548
- {
549
- var u = V(e);
550
- if (!u) {
551
- var s = "";
552
- (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (s += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
553
- var p = Qe();
554
- p ? s += p : s += je();
555
- var d;
556
- e === null ? d = "null" : pe(e) ? d = "array" : e !== void 0 && e.$$typeof === o ? (d = "<" + (S(e.type) || "Unknown") + " />", s = " Did you accidentally export a JSX literal instead of a component?") : d = typeof e, g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", d, s);
557
- }
558
- var v = qe(e, r, t, l, f);
559
- if (v == null)
560
- return v;
561
- if (u) {
562
- var C = r.children;
563
- if (C !== void 0)
564
- if (i)
565
- if (pe(C)) {
566
- for (var Z = 0; Z < C.length; Z++)
567
- Ae(C[Z], e);
568
- Object.freeze && Object.freeze(C);
569
- } else
570
- g("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
571
- else
572
- Ae(C, e);
573
- }
574
- if (B.call(r, "key")) {
575
- var W = S(e), h = Object.keys(r).filter(function(ur) {
576
- return ur !== "key";
577
- }), Re = h.length > 0 ? "{key: someKey, " + h.join(": ..., ") + ": ...}" : "{key: someKey}";
578
- if (!Ie[W + Re]) {
579
- var sr = h.length > 0 ? "{" + h.join(": ..., ") + ": ...}" : "{}";
580
- g(`A props object containing a "key" prop is being spread into JSX:
581
- let props = %s;
582
- <%s {...props} />
583
- React keys must be passed directly to JSX without using spread:
584
- let props = %s;
585
- <%s key={someKey} {...props} />`, Re, W, sr, W), Ie[W + Re] = !0;
586
- }
587
- }
588
- return e === m ? tr(v) : rr(v), v;
589
- }
590
- }
591
- function nr(e, r, t) {
592
- return De(e, r, t, !0);
593
- }
594
- function ar(e, r, t) {
595
- return De(e, r, t, !1);
596
- }
597
- var or = ar, ir = nr;
598
- ae.Fragment = m, ae.jsx = or, ae.jsxs = ir;
599
- })();
600
- Ue.exports = ae;
601
- var Fe = Ue.exports;
602
- const Rr = {
603
- IDLE: "idle"
604
- }, We = (c) => {
605
- let o;
606
- const n = /* @__PURE__ */ new Set(), m = (E, _) => {
607
- const R = typeof E == "function" ? E(o) : E;
608
- if (!Object.is(R, o)) {
609
- const D = o;
610
- o = _ ?? (typeof R != "object" || R === null) ? R : Object.assign({}, o, R), n.forEach((N) => N(o, D));
611
- }
612
- }, O = () => o, I = { setState: m, getState: O, getInitialState: () => x, subscribe: (E) => (n.add(E), () => n.delete(E)) }, x = o = c(m, O, I);
613
- return I;
614
- }, yr = (c) => c ? We(c) : We, Er = (c) => c;
615
- function Sr(c, o = Er) {
616
- const n = w.useSyncExternalStore(
617
- c.subscribe,
618
- () => o(c.getState()),
619
- () => o(c.getInitialState())
620
- );
621
- return w.useDebugValue(n), n;
44
+ //#endregion
45
+ //#region ../../node_modules/zustand/esm/react.mjs
46
+ const identity = (arg) => arg;
47
+ function useStore(api, selector = identity) {
48
+ const slice = React.useSyncExternalStore(api.subscribe, () => selector(api.getState()), () => selector(api.getInitialState()));
49
+ React.useDebugValue(slice);
50
+ return slice;
622
51
  }
623
- const Cr = (c) => {
624
- const o = yr(c), n = (m) => Sr(o, m);
625
- return Object.assign(n, o), n;
626
- }, _r = (c) => Cr, b = _r()((c) => ({
627
- instance: null,
628
- appState: {
629
- weave: {}
630
- },
631
- status: Rr.IDLE,
632
- room: {
633
- loaded: !1
634
- },
635
- connection: {
636
- status: "disconnected"
637
- },
638
- users: {},
639
- undoRedo: {
640
- canUndo: !1,
641
- canRedo: !1
642
- },
643
- zoom: {
644
- value: 1,
645
- canZoomIn: !1,
646
- canZoomOut: !1
647
- },
648
- contextMenu: {
649
- show: !1,
650
- position: {
651
- x: 0,
652
- y: 0
653
- },
654
- options: []
655
- },
656
- selection: {
657
- nodes: [],
658
- node: void 0
659
- },
660
- actions: {
661
- active: !1,
662
- actual: void 0
663
- },
664
- setInstance: (o) => c((n) => ({
665
- ...n,
666
- instance: o
667
- })),
668
- setStatus: (o) => c((n) => ({
669
- ...n,
670
- status: o
671
- })),
672
- setAppState: (o) => c((n) => ({
673
- ...n,
674
- appState: o
675
- })),
676
- setConnectionStatus: (o) => c((n) => ({
677
- ...n,
678
- connection: {
679
- ...n.connection,
680
- status: o
681
- }
682
- })),
683
- setRoomLoaded: (o) => c((n) => ({
684
- ...n,
685
- room: {
686
- ...n.room,
687
- loaded: o
688
- }
689
- })),
690
- setUsers: (o) => c((n) => ({
691
- ...n,
692
- users: o
693
- })),
694
- setCanUndo: (o) => c((n) => ({
695
- ...n,
696
- undoRedo: {
697
- ...n.undoRedo,
698
- canUndo: o
699
- }
700
- })),
701
- setCanRedo: (o) => c((n) => ({
702
- ...n,
703
- undoRedo: {
704
- ...n.undoRedo,
705
- canRedo: o
706
- }
707
- })),
708
- setZoom: (o) => c((n) => ({
709
- ...n,
710
- zoom: {
711
- ...n.zoom,
712
- value: o
713
- }
714
- })),
715
- setCanZoomIn: (o) => c((n) => ({
716
- ...n,
717
- zoom: {
718
- ...n.zoom,
719
- canZoomIn: o
720
- }
721
- })),
722
- setCanZoomOut: (o) => c((n) => ({
723
- ...n,
724
- zoom: {
725
- ...n.zoom,
726
- canZoomOut: o
727
- }
728
- })),
729
- setSelectedNodes: (o) => c((n) => ({
730
- ...n,
731
- selection: {
732
- ...n.selection,
733
- nodes: o
734
- }
735
- })),
736
- setNode: (o) => c((n) => ({
737
- ...n,
738
- selection: {
739
- ...n.selection,
740
- node: o
741
- }
742
- })),
743
- setActualAction: (o) => c((n) => ({
744
- ...n,
745
- actions: {
746
- ...n.actions,
747
- active: typeof o < "u",
748
- actual: o
749
- }
750
- }))
751
- })), wr = ({
752
- containerId: c,
753
- getUser: o,
754
- store: n,
755
- nodes: m = [],
756
- actions: O = [],
757
- plugins: U = [],
758
- customPlugins: M = [],
759
- fonts: I = [],
760
- callbacks: x = {},
761
- children: E
762
- }) => {
763
- const _ = w.useRef(null), R = b((a) => a.selection.nodes), D = b((a) => a.setInstance), N = b((a) => a.setAppState), H = b((a) => a.setStatus), oe = b((a) => a.setRoomLoaded), ie = b((a) => a.setUsers), A = b((a) => a.setCanUndo), g = b((a) => a.setCanRedo), se = b((a) => a.setZoom), ue = b((a) => a.setCanZoomIn), ce = b((a) => a.setCanZoomOut), le = b((a) => a.setSelectedNodes), K = b((a) => a.setNode), fe = b((a) => a.setActualAction), {
764
- onInstanceStatus: Y,
765
- onRoomLoaded: V,
766
- onStateChange: z,
767
- onUndoManagerStatusChange: $,
768
- onActiveActionChange: S,
769
- ...j
770
- } = x, F = w.useCallback(
771
- (a) => {
772
- H(a), Y == null || Y(a);
773
- },
774
- // eslint-disable-next-line react-hooks/exhaustive-deps
775
- []
776
- ), G = w.useCallback(
777
- (a) => {
778
- oe(a), V == null || V(a);
779
- },
780
- // eslint-disable-next-line react-hooks/exhaustive-deps
781
- []
782
- ), X = w.useCallback(
783
- (a) => {
784
- N(a), z == null || z(a);
785
- },
786
- // eslint-disable-next-line react-hooks/exhaustive-deps
787
- [R]
788
- ), J = w.useCallback(
789
- (a) => {
790
- const {
791
- canUndo: k,
792
- canRedo: P
793
- } = a;
794
- A(k), g(P), $ == null || $(a);
795
- },
796
- // eslint-disable-next-line react-hooks/exhaustive-deps
797
- []
798
- ), q = w.useCallback(
799
- (a) => {
800
- fe(a), S == null || S(status);
801
- },
802
- // eslint-disable-next-line react-hooks/exhaustive-deps
803
- [R]
804
- ), Q = w.useCallback((a) => {
805
- a.length === 1 && K(a[0].node), a.length !== 1 && K(void 0), le(a);
806
- }, []);
807
- return w.useEffect(() => {
808
- async function a() {
809
- const k = document.getElementById(c), P = k == null ? void 0 : k.getBoundingClientRect();
810
- if (k && !_.current) {
811
- if (m.length > 0)
812
- for (const T of m)
813
- ;
814
- if (O.length > 0)
815
- for (const T of O)
816
- ;
817
- const y = [];
818
- if (U.length > 0)
819
- for (const T of U)
820
- y.push(T);
821
- else
822
- y.push(new cr({})), y.push(new lr()), y.push(new fr()), y.push(new dr({
823
- onZoomChange: (T) => {
824
- se(T.scale), ue(T.canZoomIn), ce(T.canZoomOut);
825
- }
826
- })), y.push(new vr({
827
- onNodesChange: Q
828
- })), y.push(new gr({})), y.push(new pr({
829
- onConnectedUsersChanged: (T) => {
830
- ie(T);
831
- },
832
- getUser: o
833
- })), y.push(new hr({
834
- getUser: o
835
- })), y.push(new br({}));
836
- _.current = new mr({
837
- store: n,
838
- nodes: m,
839
- actions: O,
840
- plugins: [...y, ...M],
841
- fonts: I,
842
- callbacks: {
843
- ...j,
844
- onInstanceStatus: F,
845
- onRoomLoaded: G,
846
- onStateChange: X,
847
- onUndoManagerStatusChange: J,
848
- onActiveActionChange: q
849
- },
850
- logger: {
851
- level: "info"
852
- }
853
- }, {
854
- container: c,
855
- width: (P == null ? void 0 : P.width) ?? 1920,
856
- height: (P == null ? void 0 : P.height) ?? 1080
857
- }), D(_.current), _.current.start();
858
- }
859
- }
860
- a();
861
- }, []), /* @__PURE__ */ Fe.jsx(Fe.Fragment, { children: E });
52
+ const createImpl = (createState) => {
53
+ const api = createStore(createState);
54
+ const useBoundStore = (selector) => useStore(api, selector);
55
+ Object.assign(useBoundStore, api);
56
+ return useBoundStore;
862
57
  };
863
- export {
864
- wr as WeaveProvider,
865
- b as useWeave
58
+ const create = (createState) => createState ? createImpl(createState) : createImpl;
59
+
60
+ //#endregion
61
+ //#region src/components/store.tsx
62
+ const useWeave = create()((set) => ({
63
+ instance: null,
64
+ appState: { weave: {} },
65
+ status: WEAVE_INSTANCE_STATUS.IDLE,
66
+ room: { loaded: false },
67
+ connection: { status: "disconnected" },
68
+ users: {},
69
+ undoRedo: {
70
+ canUndo: false,
71
+ canRedo: false
72
+ },
73
+ zoom: {
74
+ value: 1,
75
+ canZoomIn: false,
76
+ canZoomOut: false
77
+ },
78
+ contextMenu: {
79
+ show: false,
80
+ position: {
81
+ x: 0,
82
+ y: 0
83
+ },
84
+ options: []
85
+ },
86
+ selection: {
87
+ nodes: [],
88
+ node: void 0
89
+ },
90
+ actions: {
91
+ active: false,
92
+ actual: void 0
93
+ },
94
+ setInstance: (newInstance) => set((state) => ({
95
+ ...state,
96
+ instance: newInstance
97
+ })),
98
+ setStatus: (newStatus) => set((state) => ({
99
+ ...state,
100
+ status: newStatus
101
+ })),
102
+ setAppState: (newAppState) => set((state) => ({
103
+ ...state,
104
+ appState: newAppState
105
+ })),
106
+ setConnectionStatus: (newConnectionStatus) => set((state) => ({
107
+ ...state,
108
+ connection: {
109
+ ...state.connection,
110
+ status: newConnectionStatus
111
+ }
112
+ })),
113
+ setRoomLoaded: (newStatus) => set((state) => ({
114
+ ...state,
115
+ room: {
116
+ ...state.room,
117
+ loaded: newStatus
118
+ }
119
+ })),
120
+ setUsers: (newUsers) => set((state) => ({
121
+ ...state,
122
+ users: newUsers
123
+ })),
124
+ setCanUndo: (newCanUndo) => set((state) => ({
125
+ ...state,
126
+ undoRedo: {
127
+ ...state.undoRedo,
128
+ canUndo: newCanUndo
129
+ }
130
+ })),
131
+ setCanRedo: (newCanRedo) => set((state) => ({
132
+ ...state,
133
+ undoRedo: {
134
+ ...state.undoRedo,
135
+ canRedo: newCanRedo
136
+ }
137
+ })),
138
+ setZoom: (newZoom) => set((state) => ({
139
+ ...state,
140
+ zoom: {
141
+ ...state.zoom,
142
+ value: newZoom
143
+ }
144
+ })),
145
+ setCanZoomIn: (newCanZoomIn) => set((state) => ({
146
+ ...state,
147
+ zoom: {
148
+ ...state.zoom,
149
+ canZoomIn: newCanZoomIn
150
+ }
151
+ })),
152
+ setCanZoomOut: (newCanZoomOut) => set((state) => ({
153
+ ...state,
154
+ zoom: {
155
+ ...state.zoom,
156
+ canZoomOut: newCanZoomOut
157
+ }
158
+ })),
159
+ setSelectedNodes: (newSelectedNodes) => set((state) => ({
160
+ ...state,
161
+ selection: {
162
+ ...state.selection,
163
+ nodes: newSelectedNodes
164
+ }
165
+ })),
166
+ setNode: (newNode) => set((state) => ({
167
+ ...state,
168
+ selection: {
169
+ ...state.selection,
170
+ node: newNode
171
+ }
172
+ })),
173
+ setActualAction: (newActualAction) => set((state) => ({
174
+ ...state,
175
+ actions: {
176
+ ...state.actions,
177
+ active: typeof newActualAction !== "undefined",
178
+ actual: newActualAction
179
+ }
180
+ }))
181
+ }));
182
+
183
+ //#endregion
184
+ //#region src/components/provider.tsx
185
+ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [], plugins = [], customPlugins = [], fonts = [], callbacks = {}, children }) => {
186
+ const weaveInstanceRef = React.useRef(null);
187
+ const selectedNodes = useWeave((state) => state.selection.nodes);
188
+ const setInstance = useWeave((state) => state.setInstance);
189
+ const setAppState = useWeave((state) => state.setAppState);
190
+ const setStatus = useWeave((state) => state.setStatus);
191
+ const setRoomLoaded = useWeave((state) => state.setRoomLoaded);
192
+ const setUsers = useWeave((state) => state.setUsers);
193
+ const setCanUndo = useWeave((state) => state.setCanUndo);
194
+ const setCanRedo = useWeave((state) => state.setCanRedo);
195
+ const setZoom = useWeave((state) => state.setZoom);
196
+ const setCanZoomIn = useWeave((state) => state.setCanZoomIn);
197
+ const setCanZoomOut = useWeave((state) => state.setCanZoomOut);
198
+ const setSelectedNodes = useWeave((state) => state.setSelectedNodes);
199
+ const setNode = useWeave((state) => state.setNode);
200
+ const setActualAction = useWeave((state) => state.setActualAction);
201
+ const { onInstanceStatus, onRoomLoaded, onStateChange, onUndoManagerStatusChange, onActiveActionChange,...restCallbacks } = callbacks;
202
+ const onInstanceStatusHandler = React.useCallback(
203
+ (status$1) => {
204
+ setStatus(status$1);
205
+ onInstanceStatus?.(status$1);
206
+ },
207
+ // eslint-disable-next-line react-hooks/exhaustive-deps
208
+ []
209
+ );
210
+ const onRoomLoadedHandler = React.useCallback(
211
+ (status$1) => {
212
+ setRoomLoaded(status$1);
213
+ onRoomLoaded?.(status$1);
214
+ },
215
+ // eslint-disable-next-line react-hooks/exhaustive-deps
216
+ []
217
+ );
218
+ const onStateChangeHandler = React.useCallback(
219
+ (state) => {
220
+ setAppState(state);
221
+ onStateChange?.(state);
222
+ },
223
+ // eslint-disable-next-line react-hooks/exhaustive-deps
224
+ [selectedNodes]
225
+ );
226
+ const onUndoManagerStatusChangeHandler = React.useCallback(
227
+ (undoManagerStatus) => {
228
+ const { canUndo, canRedo } = undoManagerStatus;
229
+ setCanUndo(canUndo);
230
+ setCanRedo(canRedo);
231
+ onUndoManagerStatusChange?.(undoManagerStatus);
232
+ },
233
+ // eslint-disable-next-line react-hooks/exhaustive-deps
234
+ []
235
+ );
236
+ const onActiveActionChangeHandler = React.useCallback(
237
+ (actionName) => {
238
+ setActualAction(actionName);
239
+ onActiveActionChange?.(status);
240
+ },
241
+ // eslint-disable-next-line react-hooks/exhaustive-deps
242
+ [selectedNodes]
243
+ );
244
+ const onNodesChange = React.useCallback((nodes$1) => {
245
+ if (nodes$1.length === 1) setNode(nodes$1[0].node);
246
+ if (nodes$1.length !== 1) setNode(void 0);
247
+ setSelectedNodes(nodes$1);
248
+ }, []);
249
+ React.useEffect(() => {
250
+ async function initWeave() {
251
+ const weaveEle = document.getElementById(containerId);
252
+ const weaveEleClientRect = weaveEle?.getBoundingClientRect();
253
+ if (weaveEle && !weaveInstanceRef.current) {
254
+ const instanceNodes = [];
255
+ if (nodes.length > 0) for (const node of nodes) instanceNodes.push(node);
256
+ const instanceActions = [];
257
+ if (actions.length > 0) for (const action of actions) instanceActions.push(action);
258
+ const instancePlugins = [];
259
+ if (plugins.length > 0) for (const plugin of plugins) instancePlugins.push(plugin);
260
+ else {
261
+ instancePlugins.push(new WeaveStageGridPlugin({}));
262
+ instancePlugins.push(new WeaveStagePanningPlugin());
263
+ instancePlugins.push(new WeaveStageResizePlugin());
264
+ instancePlugins.push(new WeaveStageZoomPlugin({ onZoomChange: (zoomInfo) => {
265
+ setZoom(zoomInfo.scale);
266
+ setCanZoomIn(zoomInfo.canZoomIn);
267
+ setCanZoomOut(zoomInfo.canZoomOut);
268
+ } }));
269
+ instancePlugins.push(new WeaveNodesSelectionPlugin({ onNodesChange }));
270
+ instancePlugins.push(new WeaveStageDropAreaPlugin({}));
271
+ instancePlugins.push(new WeaveConnectedUsersPlugin({
272
+ onConnectedUsersChanged: (users) => {
273
+ setUsers(users);
274
+ },
275
+ getUser
276
+ }));
277
+ instancePlugins.push(new WeaveUsersPointersPlugin({ getUser }));
278
+ instancePlugins.push(new WeaveCopyPasteNodesPlugin({}));
279
+ }
280
+ weaveInstanceRef.current = new Weave({
281
+ store,
282
+ nodes,
283
+ actions,
284
+ plugins: [...instancePlugins, ...customPlugins],
285
+ fonts,
286
+ callbacks: {
287
+ ...restCallbacks,
288
+ onInstanceStatus: onInstanceStatusHandler,
289
+ onRoomLoaded: onRoomLoadedHandler,
290
+ onStateChange: onStateChangeHandler,
291
+ onUndoManagerStatusChange: onUndoManagerStatusChangeHandler,
292
+ onActiveActionChange: onActiveActionChangeHandler
293
+ },
294
+ logger: { level: "info" }
295
+ }, {
296
+ container: containerId,
297
+ width: weaveEleClientRect?.width ?? 1920,
298
+ height: weaveEleClientRect?.height ?? 1080
299
+ });
300
+ setInstance(weaveInstanceRef.current);
301
+ weaveInstanceRef.current.start();
302
+ }
303
+ }
304
+ initWeave();
305
+ }, []);
306
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
866
307
  };
308
+
309
+ //#endregion
310
+ export { WeaveProvider, useWeave };