@umbraci/jsmind 0.10.18 → 1.0.0-beta

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.
Files changed (55) hide show
  1. package/README.md +7 -7
  2. package/dist/jsmind.draggable-node.js +7 -472
  3. package/dist/jsmind.draggable-node.js.map +1 -1
  4. package/dist/jsmind.history.js +7 -980
  5. package/dist/jsmind.history.js.map +1 -1
  6. package/dist/jsmind.js +7 -2624
  7. package/dist/jsmind.js.map +1 -1
  8. package/dist/jsmind.multi-select.js +7 -671
  9. package/dist/jsmind.multi-select.js.map +1 -1
  10. package/dist/jsmind.multiline-text.js +7 -156
  11. package/dist/jsmind.multiline-text.js.map +1 -1
  12. package/dist/jsmind.screenshot.js +7 -156
  13. package/dist/jsmind.screenshot.js.map +1 -1
  14. package/es/jsmind.draggable-node.js +7 -443
  15. package/es/jsmind.draggable-node.js.map +1 -1
  16. package/es/jsmind.history.js +7 -944
  17. package/es/jsmind.history.js.map +1 -1
  18. package/es/jsmind.js +7 -2570
  19. package/es/jsmind.js.map +1 -1
  20. package/es/jsmind.multi-select.js +7 -621
  21. package/es/jsmind.multi-select.js.map +1 -1
  22. package/es/jsmind.multiline-text.js +7 -136
  23. package/es/jsmind.multiline-text.js.map +1 -1
  24. package/es/jsmind.screenshot.js +7 -136
  25. package/es/jsmind.screenshot.js.map +1 -1
  26. package/lib/jsmind.draggable-node.js +7 -450
  27. package/lib/jsmind.draggable-node.js.map +1 -1
  28. package/lib/jsmind.history.js +7 -946
  29. package/lib/jsmind.history.js.map +1 -1
  30. package/lib/jsmind.js +7 -2571
  31. package/lib/jsmind.js.map +1 -1
  32. package/lib/jsmind.multi-select.js +7 -623
  33. package/lib/jsmind.multi-select.js.map +1 -1
  34. package/lib/jsmind.multiline-text.js +7 -141
  35. package/lib/jsmind.multiline-text.js.map +1 -1
  36. package/lib/jsmind.screenshot.js +7 -145
  37. package/lib/jsmind.screenshot.js.map +1 -1
  38. package/package.json +26 -25
  39. package/types/generated/jsmind.d.ts +21 -24
  40. package/types/generated/jsmind.mind.d.ts +7 -0
  41. package/types/generated/{jsmind.enhanced-plugin.d.ts → jsmind.plugin-system.d.ts} +10 -10
  42. package/types/generated/jsmind.plugin.d.ts +93 -13
  43. package/types/generated/jsmind.view_provider.d.ts +1 -1
  44. package/types/generated/plugins/history/history-diff.d.ts +10 -0
  45. package/types/generated/plugins/history/jsmind.history.d.ts +2 -2
  46. package/types/generated/plugins/jsmind.draggable-node.d.ts +13 -3
  47. package/types/generated/plugins/jsmind.multi-select.d.ts +3 -3
  48. package/types/generated/plugins/jsmind.multiline-text.d.ts +67 -21
  49. package/types/generated/plugins/jsmind.screenshot.d.ts +12 -3
  50. package/types/tsconfig.declaration.json +6 -1
  51. package/dist/jsmind.copy-paste.js +0 -283
  52. package/dist/jsmind.copy-paste.js.map +0 -1
  53. package/es/jsmind.copy-paste.js +0 -260
  54. package/es/jsmind.copy-paste.js.map +0 -1
  55. package/types/generated/plugins/jsmind.multiline-text-v2.d.ts +0 -58
@@ -1,946 +1,9 @@
1
1
  /**
2
- * @license BSD-3-Clause
3
- * @copyright 2014-2025 hizzgdev@163.com
4
- *
5
- * Project Home:
6
- * https://github.com/hizzgdev/jsmind/
7
- */
8
- 'function' != typeof String.prototype.startsWith &&
9
- (String.prototype.startsWith = function (t) {
10
- return this.slice(0, t.length) === t;
11
- });
12
- const t = 1,
13
- e = 3,
14
- r = 6,
15
- n = 1,
16
- i = 2,
17
- o = 3,
18
- s = 4;
19
- var a = function () {};
20
- let h =
21
- 'undefined' == typeof console
22
- ? { level: a, log: a, debug: a, info: a, warn: a, error: a }
23
- : {
24
- level: function (t) {
25
- h.debug = t > n ? a : console.debug;
26
- h.info = t > i ? a : console.info;
27
- h.warn = t > o ? a : console.warn;
28
- h.error = t > s ? a : console.error;
29
- },
30
- log: console.log,
31
- debug: console.debug,
32
- info: console.info,
33
- warn: console.warn,
34
- error: console.error,
35
- };
36
- class c {
37
- static instanceName = '';
38
- static preload = !1;
39
- constructor({ jm: t, pluginOpt: e }) {
40
- (this.jm = t), (this.options = e || {});
41
- }
42
- beforePluginRemove() {}
43
- beforePluginDestroy() {
44
- this.beforePluginRemove();
45
- }
46
- }
47
- var u = Object.getOwnPropertyNames,
48
- d = Object.getOwnPropertySymbols,
49
- l = Object.prototype.hasOwnProperty;
50
- function f(t, e) {
51
- return function (r, n, i) {
52
- return t(r, n, i) && e(r, n, i);
53
- };
54
- }
55
- function p(t) {
56
- return function (e, r, n) {
57
- if (!e || !r || 'object' != typeof e || 'object' != typeof r) return t(e, r, n);
58
- var i = n.cache,
59
- o = i.get(e),
60
- s = i.get(r);
61
- if (o && s) return o === r && s === e;
62
- i.set(e, r), i.set(r, e);
63
- var a = t(e, r, n);
64
- return i.delete(e), i.delete(r), a;
65
- };
66
- }
67
- function y(t) {
68
- return u(t).concat(d(t));
69
- }
70
- var g =
71
- Object.hasOwn ||
72
- function (t, e) {
73
- return l.call(t, e);
74
- };
75
- function m(t, e) {
76
- return t === e || (!t && !e && t != t && e != e);
77
- }
78
- var _ = Object.getOwnPropertyDescriptor,
79
- b = Object.keys;
80
- function v(t, e, r) {
81
- var n = t.length;
82
- if (e.length !== n) return !1;
83
- for (; n-- > 0; ) if (!r.equals(t[n], e[n], n, n, t, e, r)) return !1;
84
- return !0;
85
- }
86
- function x(t, e) {
87
- return m(t.getTime(), e.getTime());
88
- }
89
- function S(t, e) {
90
- return (
91
- t.name === e.name && t.message === e.message && t.cause === e.cause && t.stack === e.stack
92
- );
93
- }
94
- function j(t, e) {
95
- return t === e;
96
- }
97
- function w(t, e, r) {
98
- var n = t.size;
99
- if (n !== e.size) return !1;
100
- if (!n) return !0;
101
- for (var i, o, s = new Array(n), a = t.entries(), h = 0; (i = a.next()) && !i.done; ) {
102
- for (var c = e.entries(), u = !1, d = 0; (o = c.next()) && !o.done; )
103
- if (s[d]) d++;
104
- else {
105
- var l = i.value,
106
- f = o.value;
107
- if (
108
- r.equals(l[0], f[0], h, d, t, e, r) &&
109
- r.equals(l[1], f[1], l[0], f[0], t, e, r)
110
- ) {
111
- u = s[d] = !0;
112
- break;
113
- }
114
- d++;
115
- }
116
- if (!u) return !1;
117
- h++;
118
- }
119
- return !0;
120
- }
121
- var k = m;
122
- function M(t, e, r) {
123
- var n = b(t),
124
- i = n.length;
125
- if (b(e).length !== i) return !1;
126
- for (; i-- > 0; ) if (!N(t, e, r, n[i])) return !1;
127
- return !0;
128
- }
129
- function O(t, e, r) {
130
- var n,
131
- i,
132
- o,
133
- s = y(t),
134
- a = s.length;
135
- if (y(e).length !== a) return !1;
136
- for (; a-- > 0; ) {
137
- if (!N(t, e, r, (n = s[a]))) return !1;
138
- if (
139
- ((i = _(t, n)),
140
- (o = _(e, n)),
141
- (i || o) &&
142
- (!i ||
143
- !o ||
144
- i.configurable !== o.configurable ||
145
- i.enumerable !== o.enumerable ||
146
- i.writable !== o.writable))
147
- )
148
- return !1;
149
- }
150
- return !0;
151
- }
152
- function A(t, e) {
153
- return m(t.valueOf(), e.valueOf());
154
- }
155
- function q(t, e) {
156
- return t.source === e.source && t.flags === e.flags;
157
- }
158
- function E(t, e, r) {
159
- var n = t.size;
160
- if (n !== e.size) return !1;
161
- if (!n) return !0;
162
- for (var i, o, s = new Array(n), a = t.values(); (i = a.next()) && !i.done; ) {
163
- for (var h = e.values(), c = !1, u = 0; (o = h.next()) && !o.done; ) {
164
- if (!s[u] && r.equals(i.value, o.value, i.value, o.value, t, e, r)) {
165
- c = s[u] = !0;
166
- break;
167
- }
168
- u++;
169
- }
170
- if (!c) return !1;
171
- }
172
- return !0;
173
- }
174
- function C(t, e) {
175
- var r = t.length;
176
- if (e.length !== r) return !1;
177
- for (; r-- > 0; ) if (t[r] !== e[r]) return !1;
178
- return !0;
179
- }
180
- function P(t, e) {
181
- return (
182
- t.hostname === e.hostname &&
183
- t.pathname === e.pathname &&
184
- t.protocol === e.protocol &&
185
- t.port === e.port &&
186
- t.hash === e.hash &&
187
- t.username === e.username &&
188
- t.password === e.password
189
- );
190
- }
191
- function N(t, e, r, n) {
192
- return (
193
- !(('_owner' !== n && '__o' !== n && '__v' !== n) || (!t.$$typeof && !e.$$typeof)) ||
194
- (g(e, n) && r.equals(t[n], e[n], n, n, t, e, r))
195
- );
196
- }
197
- var T = Array.isArray,
198
- F = 'function' == typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView : null,
199
- D = Object.assign,
200
- I = Object.prototype.toString.call.bind(Object.prototype.toString);
201
- function K(t) {
202
- var e = t.areArraysEqual,
203
- r = t.areDatesEqual,
204
- n = t.areErrorsEqual,
205
- i = t.areFunctionsEqual,
206
- o = t.areMapsEqual,
207
- s = t.areNumbersEqual,
208
- a = t.areObjectsEqual,
209
- h = t.arePrimitiveWrappersEqual,
210
- c = t.areRegExpsEqual,
211
- u = t.areSetsEqual,
212
- d = t.areTypedArraysEqual,
213
- l = t.areUrlsEqual,
214
- f = t.unknownTagComparators;
215
- return function (t, p, y) {
216
- if (t === p) return !0;
217
- if (null == t || null == p) return !1;
218
- var g = typeof t;
219
- if (g !== typeof p) return !1;
220
- if ('object' !== g) return 'number' === g ? s(t, p, y) : 'function' === g && i(t, p, y);
221
- var m = t.constructor;
222
- if (m !== p.constructor) return !1;
223
- if (m === Object) return a(t, p, y);
224
- if (T(t)) return e(t, p, y);
225
- if (null != F && F(t)) return d(t, p, y);
226
- if (m === Date) return r(t, p, y);
227
- if (m === RegExp) return c(t, p, y);
228
- if (m === Map) return o(t, p, y);
229
- if (m === Set) return u(t, p, y);
230
- var _,
231
- b = I(t);
232
- if ('[object Date]' === b) return r(t, p, y);
233
- if ('[object RegExp]' === b) return c(t, p, y);
234
- if ('[object Map]' === b) return o(t, p, y);
235
- if ('[object Set]' === b) return u(t, p, y);
236
- if ('[object Object]' === b)
237
- return 'function' != typeof t.then && 'function' != typeof p.then && a(t, p, y);
238
- if ('[object URL]' === b) return l(t, p, y);
239
- if ('[object Error]' === b) return n(t, p, y);
240
- if ('[object Arguments]' === b) return a(t, p, y);
241
- if ('[object Boolean]' === b || '[object Number]' === b || '[object String]' === b)
242
- return h(t, p, y);
243
- if (f) {
244
- var v = f[b];
245
- if (!v) {
246
- var x = null != (_ = t) ? _[Symbol.toStringTag] : void 0;
247
- x && (v = f[x]);
248
- }
249
- if (v) return v(t, p, y);
250
- }
251
- return !1;
252
- };
253
- }
254
- var z = R();
255
- function R(t) {
256
- void 0 === t && (t = {});
257
- var e,
258
- r = t.circular,
259
- n = void 0 !== r && r,
260
- i = t.createInternalComparator,
261
- o = t.createState,
262
- s = t.strict,
263
- a = void 0 !== s && s,
264
- h = (function (t) {
265
- var e = t.circular,
266
- r = t.createCustomConfig,
267
- n = t.strict,
268
- i = {
269
- areArraysEqual: n ? O : v,
270
- areDatesEqual: x,
271
- areErrorsEqual: S,
272
- areFunctionsEqual: j,
273
- areMapsEqual: n ? f(w, O) : w,
274
- areNumbersEqual: k,
275
- areObjectsEqual: n ? O : M,
276
- arePrimitiveWrappersEqual: A,
277
- areRegExpsEqual: q,
278
- areSetsEqual: n ? f(E, O) : E,
279
- areTypedArraysEqual: n ? O : C,
280
- areUrlsEqual: P,
281
- unknownTagComparators: void 0,
282
- };
283
- if ((r && (i = D({}, i, r(i))), e)) {
284
- var o = p(i.areArraysEqual),
285
- s = p(i.areMapsEqual),
286
- a = p(i.areObjectsEqual),
287
- h = p(i.areSetsEqual);
288
- i = D({}, i, {
289
- areArraysEqual: o,
290
- areMapsEqual: s,
291
- areObjectsEqual: a,
292
- areSetsEqual: h,
293
- });
294
- }
295
- return i;
296
- })(t),
297
- c = K(h);
298
- return (function (t) {
299
- var e = t.circular,
300
- r = t.comparator,
301
- n = t.createState,
302
- i = t.equals,
303
- o = t.strict;
304
- if (n)
305
- return function (t, s) {
306
- var a = n(),
307
- h = a.cache,
308
- c = void 0 === h ? (e ? new WeakMap() : void 0) : h,
309
- u = a.meta;
310
- return r(t, s, { cache: c, equals: i, meta: u, strict: o });
311
- };
312
- if (e)
313
- return function (t, e) {
314
- return r(t, e, { cache: new WeakMap(), equals: i, meta: void 0, strict: o });
315
- };
316
- var s = { cache: void 0, equals: i, meta: void 0, strict: o };
317
- return function (t, e) {
318
- return r(t, e, s);
319
- };
320
- })({
321
- circular: n,
322
- comparator: c,
323
- createState: o,
324
- equals: i
325
- ? i(c)
326
- : ((e = c),
327
- function (t, r, n, i, o, s, a) {
328
- return e(t, r, a);
329
- }),
330
- strict: a,
331
- });
332
- }
333
- function B(t, e) {
334
- const r = (function (t) {
335
- return (e = t) && 'object' == typeof e && 'data' in e ? t.data : t;
336
- var e;
337
- })(t),
338
- n = e && Array.isArray(e.fields) ? e.fields : ['topic', 'data', 'id'],
339
- i = e && Array.isArray(e.excludeFields) ? e.excludeFields : [],
340
- o = e && e.idKey ? e.idKey : 'id',
341
- s = e && e.childrenKey ? e.childrenKey : 'children',
342
- a = !e || !1 !== e.includeStructure,
343
- h = new Map();
344
- return (
345
- r &&
346
- r[o] &&
347
- (function t(e, r, c) {
348
- const u = (function (t) {
349
- const e = {};
350
- o in t && (e[o] = t[o]);
351
- const r = new Set([
352
- o,
353
- s,
354
- 'direction',
355
- 'expanded',
356
- 'parentid',
357
- 'index',
358
- 'isroot',
359
- ]),
360
- a = new Set(i);
361
- n.includes('data');
362
- for (const i of n)
363
- if ('data' === i) {
364
- const i = {};
365
- let o = !1;
366
- for (const e in t)
367
- r.has(e) ||
368
- n.includes(e) ||
369
- a.has(e) ||
370
- ((i[e] = t[e]), (o = !0));
371
- o && (e.data = i);
372
- } else i in t && i !== o && !a.has(i) && (e[i] = t[i]);
373
- return e;
374
- })(e),
375
- d = e[o];
376
- a && ((u.parentid = r || null), (u.index = 'number' == typeof c ? c : 0)),
377
- h.set(d, u);
378
- const l = e[s];
379
- l && Array.isArray(l) && l.forEach((e, r) => t(e, d, r));
380
- })(r, null, 0),
381
- h
382
- );
383
- }
384
- function U(t, e) {
385
- if (t === e) return !0;
386
- if (!t || !e) return !1;
387
- const r = Object.keys(t),
388
- n = Object.keys(e);
389
- if (r.length !== n.length) return !1;
390
- for (const n of r) {
391
- const r = t[n],
392
- i = e[n];
393
- if (r === i) continue;
394
- if (r && i && 'object' == typeof r && 'object' == typeof i) {
395
- if (!z(r, i)) return !1;
396
- } else if (r !== i) return !1;
397
- }
398
- return !0;
399
- }
400
- function W(t, e) {
401
- const r = [];
402
- if (!t || !e) return r;
403
- const n = new Set([...Object.keys(t), ...Object.keys(e)]);
404
- n.delete('id');
405
- for (const i of n) {
406
- const n = t[i],
407
- o = e[i];
408
- if (n === o) continue;
409
- (n && o && 'object' == typeof n && 'object' == typeof o ? !z(n, o) : n !== o) &&
410
- r.push({ key: i, before: n, after: o });
411
- }
412
- return r;
413
- }
414
- function $(t) {
415
- let e = !1,
416
- r = !1;
417
- for (const n of t) 'parentid' === n.key && (e = !0), 'index' === n.key && (r = !0);
418
- return { moved: e || r, parentChanged: e, orderChanged: r };
419
- }
420
- function H(t) {
421
- const e = new Map();
422
- for (const [r, n] of t) {
423
- const t = n.parentid;
424
- e.has(t) || e.set(t, []), e.get(t).push({ id: r, index: n.index });
425
- }
426
- for (const t of e.values()) t.sort((t, e) => t.index - e.index);
427
- return e;
428
- }
429
- function J(t, e, r) {
430
- const n = new Set(),
431
- i = new Map();
432
- e.forEach((t, e) => i.set(t.id, e));
433
- const o = [],
434
- s = [];
435
- for (const e of t) i.has(e.id) && (o.push(e.id), s.push(i.get(e.id)));
436
- if (o.length <= 1) return n;
437
- const a = (function (t) {
438
- const e = t.slice(),
439
- r = [0];
440
- let n, i, o, s, a;
441
- const h = t.length;
442
- for (n = 0; n < h; n++) {
443
- const h = t[n];
444
- if (0 !== h || 0 === n) {
445
- if (((i = r[r.length - 1]), t[i] < h)) {
446
- (e[n] = i), r.push(n);
447
- continue;
448
- }
449
- for (o = 0, s = r.length - 1; o < s; )
450
- (a = (o + s) >> 1), t[r[a]] < h ? (o = a + 1) : (s = a);
451
- h < t[r[o]] && (o > 0 && (e[n] = r[o - 1]), (r[o] = n));
452
- }
453
- }
454
- for (o = r.length, s = r[o - 1]; o-- > 0; ) (r[o] = s), (s = e[s]);
455
- return r;
456
- })(s),
457
- h = new Set(a);
458
- return (
459
- o.forEach((t, e) => {
460
- h.has(e) || n.add(t);
461
- }),
462
- n
463
- );
464
- }
465
- function Y(t, e, r = {}) {
466
- const {
467
- fields: n,
468
- excludeFields: i,
469
- idKey: o,
470
- childrenKey: s,
471
- includeStructure: a = !0,
472
- maxSize: h = 5e3,
473
- } = r,
474
- c = B(t, { fields: n, excludeFields: i, idKey: o, childrenKey: s, includeStructure: a }),
475
- u = B(e, { fields: n, excludeFields: i, idKey: o, childrenKey: s, includeStructure: a }),
476
- d = [],
477
- l = [],
478
- f = [];
479
- for (const [t, e] of u) {
480
- if (!c.has(t)) {
481
- d.push(e);
482
- continue;
483
- }
484
- const r = c.get(t);
485
- if (!U(r, e)) {
486
- const n = W(r, e);
487
- l.push({ id: t, before: r, after: e, changes: n });
488
- }
489
- }
490
- for (const [t, e] of c) u.has(t) || f.push(e);
491
- let p = !1;
492
- const y = d.length + l.length + f.length;
493
- if (y > h) {
494
- p = !0;
495
- const t = Math.max(0, h),
496
- e = Math.min(d.length, Math.floor(t * (d.length / y))),
497
- r = Math.min(l.length, Math.floor(t * (l.length / y))),
498
- n = Math.min(f.length, Math.max(0, t - e - r));
499
- (d.length = e), (l.length = r), (f.length = n);
500
- }
501
- if (a) {
502
- const t = (function (t, e, r) {
503
- const n = [],
504
- i = [],
505
- o = [],
506
- s = new Set(),
507
- a = H(e),
508
- h = H(r);
509
- for (const [t, e] of h) {
510
- const r = J(a.get(t) || [], e);
511
- for (const t of r) s.add(t);
512
- }
513
- for (const e of t) {
514
- const { id: t, before: r, after: a, changes: h } = e,
515
- c = $(h),
516
- u = c.parentChanged,
517
- d = !u && c.orderChanged && s.has(t);
518
- if (u || d) {
519
- const e = {
520
- moveType: u ? 'cross-parent' : 'reorder',
521
- parentChanged: c.parentChanged,
522
- orderChanged: c.orderChanged,
523
- fromParent: r.parentid,
524
- toParent: a.parentid,
525
- fromOrder: r.index,
526
- toOrder: a.index,
527
- },
528
- i = h.filter(t => 'parentid' !== t.key && 'index' !== t.key);
529
- i.length > 0
530
- ? o.push({ id: t, before: r, after: a, changes: i, moveInfo: e })
531
- : n.push({ id: t, before: r, after: a, moveInfo: e });
532
- } else if (c.orderChanged) {
533
- const e = h.filter(t => 'parentid' !== t.key && 'index' !== t.key);
534
- e.length > 0 && i.push({ id: t, before: r, after: a, changes: e });
535
- } else i.push({ id: t, before: r, after: a, changes: h });
536
- }
537
- return { moved: n, modified: i, movedAndModified: o };
538
- })(l, c, u);
539
- return {
540
- created: d,
541
- deleted: f,
542
- truncated: p,
543
- moved: t.moved,
544
- modified: t.modified,
545
- movedAndModified: t.movedAndModified,
546
- };
547
- }
548
- return { created: d, deleted: f, moved: [], modified: l, movedAndModified: [], truncated: p };
549
- }
550
- R({ strict: !0 }),
551
- R({ circular: !0 }),
552
- R({ circular: !0, strict: !0 }),
553
- R({
554
- createInternalComparator: function () {
555
- return m;
556
- },
557
- }),
558
- R({
559
- strict: !0,
560
- createInternalComparator: function () {
561
- return m;
562
- },
563
- }),
564
- R({
565
- circular: !0,
566
- createInternalComparator: function () {
567
- return m;
568
- },
569
- }),
570
- R({
571
- circular: !0,
572
- createInternalComparator: function () {
573
- return m;
574
- },
575
- strict: !0,
576
- });
577
- const V = {
578
- enabled: !0,
579
- throttleMs: 100,
580
- maxHistory: 500,
581
- storageMode: 'object',
582
- autoSwitchThreshold: 0,
583
- keymap: { enabled: !1, redoUsesY: !1 },
584
- detail: { enabled: !1 },
585
- diff: { flat: !0, fields: void 0, maxSize: 5e3 },
586
- };
587
- class L extends c {
588
- static instanceName = 'historyPlugin';
589
- static preload = !0;
590
- constructor({ jm: t, pluginOpt: e }) {
591
- super({ jm: t, pluginOpt: e }),
592
- (this.options = (function (t) {
593
- const e = Object.assign({}, V, t || {});
594
- return (
595
- e.keymap || (e.keymap = { enabled: !1, redoUsesY: !1 }),
596
- e.detail || (e.detail = { enabled: !1 }),
597
- e.diff || (e.diff = { flat: !0, fields: void 0, maxSize: 5e3 }),
598
- e
599
- );
600
- })(e)),
601
- (this._mounted = !1),
602
- (this._core = null),
603
- this._mountAPI(),
604
- this._initCore();
605
- }
606
- beforePluginDestroy() {
607
- h.debug('[history] beforePluginDestroy: clearing history stack'),
608
- this._core && this._core.clear();
609
- }
610
- _initCore() {
611
- const r = this.jm,
612
- n = this.options;
613
- n.keymap &&
614
- n.keymap.enabled &&
615
- r.options &&
616
- r.options.shortcut &&
617
- this._injectShortcuts(r.options.shortcut, !!n.keymap.redoUsesY);
618
- const i = new G(r, n);
619
- (this._core = i),
620
- r.history &&
621
- ((r.history.add = (t, e) => i.add(t, e)),
622
- (r.history.pause = () => i.pause()),
623
- (r.history.resume = t => i.resume(!!t)),
624
- (r.history.clear = () => i.clear()),
625
- (r.history.canBack = () => i.canBack()),
626
- (r.history.canForward = () => i.canForward()),
627
- (r.history.back = t => i.back('number' == typeof t ? t : 1)),
628
- (r.history.forward = t => i.forward('number' == typeof t ? t : 1)),
629
- (r.history.length = () => i.length()),
630
- (r.history.index = () => i.index()),
631
- (r.history.setMax = t => i.setMax(t)),
632
- (r.history.setThrottle = t => i.setThrottle(t)),
633
- (r.history.exportSnapshot = () => i.exportSnapshot()),
634
- (r.history.importSnapshot = (t, e) => i.importSnapshot(t, e)),
635
- (r.history.getStack = () => i.getStackMeta()),
636
- (r.history.diff = (t, e, r) => {
637
- const n = this.jm.options.fieldNames,
638
- i = n?.id || 'id';
639
- return Y(t, e, {
640
- fields: [n?.topic || 'topic', 'data', i],
641
- idKey: i,
642
- childrenKey: n?.children || 'children',
643
- ...r,
644
- });
645
- }),
646
- (this._listener = (r, n) => {
647
- try {
648
- if (r === t && n && 'data' in n) {
649
- let t = null;
650
- const e = n.data && n.data[0];
651
- if (e)
652
- if (e.data)
653
- if (Array.isArray(e.data)) {
654
- const r = e.data.find(t => t.isroot);
655
- t = r && r.id;
656
- } else t = e.data.id;
657
- else e.id && (t = e.id);
658
- return void (
659
- t &&
660
- t !== i._lastRootId &&
661
- (h.debug('[history] root id changed, clearing stack and pausing'),
662
- i.clear(),
663
- (i._lastRootId = t),
664
- setTimeout(() => {
665
- try {
666
- h.debug('[history] adding bootstrap snapshot after show'),
667
- i._addNow && i._addNow('bootstrap'),
668
- h.debug('[history] resuming history recording');
669
- } catch (t) {
670
- h.warn('[history] failed to add bootstrap snapshot', t);
671
- }
672
- }, 100))
673
- );
674
- }
675
- r === e && n && n.evt && i.add(n.evt, n);
676
- } catch (t) {
677
- h.warn('[history] listener error', t);
678
- }
679
- }),
680
- r.add_event_listener(this._listener));
681
- }
682
- _injectShortcuts(t, e) {
683
- const r = [4186, 8282],
684
- n = e ? [4185, 8281] : [5210, 9306];
685
- (t.handles.history_back = (t, e) => {
686
- t.history &&
687
- t.history.back() &&
688
- (e.preventDefault(), e.stopPropagation && e.stopPropagation());
689
- }),
690
- (t.handles.history_forward = (t, e) => {
691
- t.history &&
692
- t.history.forward() &&
693
- (e.preventDefault(), e.stopPropagation && e.stopPropagation());
694
- }),
695
- (t.mapping.history_back = r),
696
- (t.mapping.history_forward = n);
697
- }
698
- _mountAPI() {
699
- if (this._mounted) return;
700
- const t = this.jm,
701
- e = {
702
- add: () => {},
703
- pause: () => {},
704
- resume: t => {},
705
- clear: () => {},
706
- canBack: () => !1,
707
- canForward: () => !1,
708
- back: t => !1,
709
- forward: t => !1,
710
- length: () => 0,
711
- index: () => -1,
712
- setMax: t => {},
713
- setThrottle: t => {},
714
- exportSnapshot: () => null,
715
- importSnapshot: (t, e) => {},
716
- getStack: () => ({ items: [], index: -1 }),
717
- diff: (t, e, r) => {
718
- const n = this.jm.options.fieldNames,
719
- i = n?.id || 'id';
720
- return Y(t, e, {
721
- fields: [n?.topic || 'topic', 'data', i],
722
- idKey: i,
723
- childrenKey: n?.children || 'children',
724
- ...r,
725
- });
726
- },
727
- getOptions: () => Object.assign({}, this.options),
728
- };
729
- Object.defineProperty(t, 'history', {
730
- value: e,
731
- configurable: !0,
732
- enumerable: !1,
733
- writable: !1,
734
- }),
735
- (this._mounted = !0),
736
- h.info('[history] API mounted (preload).');
737
- }
738
- beforePluginRemove() {
739
- try {
740
- if (this._listener && this.jm && Array.isArray(this.jm.event_handles)) {
741
- const t = this.jm.event_handles.indexOf(this._listener);
742
- t >= 0 && this.jm.event_handles.splice(t, 1);
743
- }
744
- this.jm &&
745
- Object.prototype.hasOwnProperty.call(this.jm, 'history') &&
746
- delete this.jm.history,
747
- (this._mounted = !1);
748
- } catch (t) {
749
- h.error('[history] remove failed:', t);
750
- }
751
- }
752
- beforePluginDestroy() {
753
- h.error('beforePluginDestroy'), this.beforePluginRemove();
754
- }
755
- }
756
- class G {
757
- constructor(t, e) {
758
- (this.jm = t),
759
- (this.options = e),
760
- (this.enabled = !!e.enabled),
761
- (this.maxHistory = Math.max(1, 0 | e.maxHistory)),
762
- (this.throttleMs = Math.max(0, 0 | e.throttleMs)),
763
- (this.storageMode = e.storageMode || 'object'),
764
- (this.autoSwitchThreshold = Math.max(0, 0 | e.autoSwitchThreshold)),
765
- (this._history = []),
766
- (this._idx = -1),
767
- (this._paused = !1),
768
- (this._lastAddAt = 0),
769
- (this._timer = 0),
770
- (this._pending = !1),
771
- (this._pendingMeta = void 0),
772
- (this._lastSig = null),
773
- (this._lastRootId = null);
774
- }
775
- add(t = 'manual', e) {
776
- if (!this.enabled || this._paused) return;
777
- const r = Date.now() - this._lastAddAt;
778
- if (r >= this.throttleMs) return this._addNow(t, e), void (this._lastAddAt = Date.now());
779
- if (((this._pending = !0), (this._pendingMeta = e), this._timer)) return;
780
- const n = Math.max(0, this.throttleMs - r);
781
- this._timer = setTimeout(() => {
782
- (this._timer = 0),
783
- !this._paused &&
784
- this.enabled &&
785
- (this._addNow(t, this._pendingMeta), (this._lastAddAt = Date.now())),
786
- (this._pending = !1),
787
- (this._pendingMeta = void 0);
788
- }, n);
789
- }
790
- pause() {
791
- this._paused = !0;
792
- }
793
- resume(t = !1) {
794
- (this._paused = !1),
795
- t &&
796
- this._pending &&
797
- (clearTimeout(this._timer),
798
- (this._timer = 0),
799
- this._addNow('resume-flush', this._pendingMeta),
800
- (this._lastAddAt = Date.now()),
801
- (this._pending = !1),
802
- (this._pendingMeta = void 0));
803
- }
804
- clear() {
805
- (this._history = []), (this._idx = -1), (this._lastSig = null), this._notifyChange();
806
- }
807
- canBack() {
808
- return this._idx > 0;
809
- }
810
- canForward() {
811
- return this._idx >= 0 && this._idx < this._history.length - 1;
812
- }
813
- back(t = 1) {
814
- if (((!Number.isFinite(t) || t <= 0) && (t = 1), this._idx - t < 0)) return !1;
815
- this._idx -= t;
816
- const e = this._applyIndex();
817
- return e && this._notifyChange(), e;
818
- }
819
- forward(t = 1) {
820
- if (((!Number.isFinite(t) || t <= 0) && (t = 1), this._idx + t >= this._history.length))
821
- return !1;
822
- this._idx += t;
823
- const e = this._applyIndex();
824
- return e && this._notifyChange(), e;
825
- }
826
- length() {
827
- return this._history.length;
828
- }
829
- index() {
830
- return this._idx;
831
- }
832
- setMax(t) {
833
- this.maxHistory = Math.max(1, 0 | t);
834
- }
835
- setThrottle(t) {
836
- this.throttleMs = Math.max(0, 0 | t);
837
- }
838
- exportSnapshot() {
839
- return this._takeSnapshot();
840
- }
841
- importSnapshot(t, e) {
842
- return this._applySnapshot(t, e);
843
- }
844
- getStackMeta() {
845
- return { items: this._history.slice(), index: this._idx };
846
- }
847
- _notifyChange() {
848
- try {
849
- this.jm.invoke_event_handle(r, {
850
- index: this._idx,
851
- length: this._history.length,
852
- canBack: this.canBack(),
853
- canForward: this.canForward(),
854
- });
855
- } catch (t) {
856
- h.warn('[history] failed to notify change', t);
857
- }
858
- }
859
- _addNow(t, e) {
860
- const r = this._takeSnapshot();
861
- let n = this.storageMode;
862
- if (this.autoSwitchThreshold > 0 && 'object' === n) {
863
- const t = this._countNodes(r);
864
- t > this.autoSwitchThreshold &&
865
- ((n = 'string'),
866
- h.debug(
867
- `[history] auto-switched to string mode (${t} nodes > ${this.autoSwitchThreshold})`
868
- ));
869
- }
870
- let i = null;
871
- try {
872
- i = JSON.stringify(r);
873
- } catch {}
874
- if (!i || !this._lastSig || i !== this._lastSig) {
875
- if (
876
- (this._idx < this._history.length - 1 &&
877
- (this._history = this._history.slice(0, this._idx + 1)),
878
- this._history.length >= this.maxHistory &&
879
- (this._history.shift(), (this._idx = Math.max(-1, this._idx - 1))),
880
- 'string' === n)
881
- )
882
- this._history.push(i);
883
- else {
884
- const t = this._deepFreeze(r);
885
- this._history.push(t);
886
- }
887
- (this._idx = this._history.length - 1), (this._lastSig = i), this._notifyChange();
888
- }
889
- }
890
- _applyIndex() {
891
- const t = this._history[this._idx];
892
- if (!t) return !1;
893
- try {
894
- let e;
895
- if ('string' == typeof t) (e = JSON.parse(t)), (this._lastSig = t);
896
- else {
897
- e = this._cloneSnapshot(t);
898
- try {
899
- this._lastSig = JSON.stringify(t);
900
- } catch {
901
- this._lastSig = null;
902
- }
903
- }
904
- return this._applySnapshot(e, { skipCentering: !0 }), !0;
905
- } catch (t) {
906
- return h.error('[history] apply snapshot failed', t), !1;
907
- }
908
- }
909
- _takeSnapshot() {
910
- return this.jm.get_data('node_tree');
911
- }
912
- _applySnapshot(t, e) {
913
- const r = !(!e || !e.skipCentering);
914
- return this.jm.show(t, r), !0;
915
- }
916
- _countNodes(t) {
917
- let e = 0;
918
- return (
919
- (function t(r) {
920
- if (r && (e++, r.children && Array.isArray(r.children)))
921
- for (const e of r.children) t(e);
922
- })(t && t.data ? t.data : t),
923
- e
924
- );
925
- }
926
- _deepFreeze(t) {
927
- if (!t || 'object' != typeof t) return t;
928
- if (Object.isFrozen(t)) return t;
929
- if ((Object.freeze(t), Array.isArray(t))) for (const e of t) this._deepFreeze(e);
930
- else for (const e of Object.keys(t)) this._deepFreeze(t[e]);
931
- return t;
932
- }
933
- _cloneSnapshot(t) {
934
- if ('function' == typeof structuredClone)
935
- try {
936
- return structuredClone(t);
937
- } catch {}
938
- try {
939
- return JSON.parse(JSON.stringify(t));
940
- } catch {
941
- return t;
942
- }
943
- }
944
- }
945
- export { L as HistoryPlugin, L as default };
2
+ * @license BSD-3-Clause
3
+ * @copyright 2014-2025 hizzgdev@163.com
4
+ *
5
+ * Project Home:
6
+ * https://github.com/hizzgdev/jsmind/
7
+ */
8
+ "function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(t){return this.slice(0,t.length)===t});const t=1,e=3,r=6,n=1,i=2,o=3,s=4;var a=function(){};let h="undefined"==typeof console?{level:a,log:a,debug:a,info:a,warn:a,error:a}:{level:function(t){h.debug=t>n?a:console.debug;h.info=t>i?a:console.info;h.warn=t>o?a:console.warn;h.error=t>s?a:console.error},log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};class c{static instanceName="";static preload=!1;constructor({jm:t,pluginOpt:e}){this.jm=t,this.options=e||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}var u=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty;function f(t,e){return function(r,n,i){return t(r,n,i)&&e(r,n,i)}}function p(t){return function(e,r,n){if(!e||!r||"object"!=typeof e||"object"!=typeof r)return t(e,r,n);var i=n.cache,o=i.get(e),s=i.get(r);if(o&&s)return o===r&&s===e;i.set(e,r),i.set(r,e);var a=t(e,r,n);return i.delete(e),i.delete(r),a}}function y(t){return u(t).concat(d(t))}var g=Object.hasOwn||function(t,e){return l.call(t,e)};function m(t,e){return t===e||!t&&!e&&t!=t&&e!=e}var _=Object.getOwnPropertyDescriptor,b=Object.keys;function v(t,e,r){var n=t.length;if(e.length!==n)return!1;for(;n-- >0;)if(!r.equals(t[n],e[n],n,n,t,e,r))return!1;return!0}function x(t,e){return m(t.getTime(),e.getTime())}function S(t,e){return t.name===e.name&&t.message===e.message&&t.cause===e.cause&&t.stack===e.stack}function j(t,e){return t===e}function w(t,e,r){var n=t.size;if(n!==e.size)return!1;if(!n)return!0;for(var i,o,s=new Array(n),a=t.entries(),h=0;(i=a.next())&&!i.done;){for(var c=e.entries(),u=!1,d=0;(o=c.next())&&!o.done;)if(s[d])d++;else{var l=i.value,f=o.value;if(r.equals(l[0],f[0],h,d,t,e,r)&&r.equals(l[1],f[1],l[0],f[0],t,e,r)){u=s[d]=!0;break}d++}if(!u)return!1;h++}return!0}var k=m;function M(t,e,r){var n=b(t),i=n.length;if(b(e).length!==i)return!1;for(;i-- >0;)if(!N(t,e,r,n[i]))return!1;return!0}function O(t,e,r){var n,i,o,s=y(t),a=s.length;if(y(e).length!==a)return!1;for(;a-- >0;){if(!N(t,e,r,n=s[a]))return!1;if(i=_(t,n),o=_(e,n),(i||o)&&(!i||!o||i.configurable!==o.configurable||i.enumerable!==o.enumerable||i.writable!==o.writable))return!1}return!0}function A(t,e){return m(t.valueOf(),e.valueOf())}function q(t,e){return t.source===e.source&&t.flags===e.flags}function E(t,e,r){var n=t.size;if(n!==e.size)return!1;if(!n)return!0;for(var i,o,s=new Array(n),a=t.values();(i=a.next())&&!i.done;){for(var h=e.values(),c=!1,u=0;(o=h.next())&&!o.done;){if(!s[u]&&r.equals(i.value,o.value,i.value,o.value,t,e,r)){c=s[u]=!0;break}u++}if(!c)return!1}return!0}function C(t,e){var r=t.length;if(e.length!==r)return!1;for(;r-- >0;)if(t[r]!==e[r])return!1;return!0}function P(t,e){return t.hostname===e.hostname&&t.pathname===e.pathname&&t.protocol===e.protocol&&t.port===e.port&&t.hash===e.hash&&t.username===e.username&&t.password===e.password}function N(t,e,r,n){return!("_owner"!==n&&"__o"!==n&&"__v"!==n||!t.$$typeof&&!e.$$typeof)||g(e,n)&&r.equals(t[n],e[n],n,n,t,e,r)}var T=Array.isArray,F="function"==typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView:null,D=Object.assign,I=Object.prototype.toString.call.bind(Object.prototype.toString);function K(t){var e=t.areArraysEqual,r=t.areDatesEqual,n=t.areErrorsEqual,i=t.areFunctionsEqual,o=t.areMapsEqual,s=t.areNumbersEqual,a=t.areObjectsEqual,h=t.arePrimitiveWrappersEqual,c=t.areRegExpsEqual,u=t.areSetsEqual,d=t.areTypedArraysEqual,l=t.areUrlsEqual,f=t.unknownTagComparators;return function(t,p,y){if(t===p)return!0;if(null==t||null==p)return!1;var g=typeof t;if(g!==typeof p)return!1;if("object"!==g)return"number"===g?s(t,p,y):"function"===g&&i(t,p,y);var m=t.constructor;if(m!==p.constructor)return!1;if(m===Object)return a(t,p,y);if(T(t))return e(t,p,y);if(null!=F&&F(t))return d(t,p,y);if(m===Date)return r(t,p,y);if(m===RegExp)return c(t,p,y);if(m===Map)return o(t,p,y);if(m===Set)return u(t,p,y);var _,b=I(t);if("[object Date]"===b)return r(t,p,y);if("[object RegExp]"===b)return c(t,p,y);if("[object Map]"===b)return o(t,p,y);if("[object Set]"===b)return u(t,p,y);if("[object Object]"===b)return"function"!=typeof t.then&&"function"!=typeof p.then&&a(t,p,y);if("[object URL]"===b)return l(t,p,y);if("[object Error]"===b)return n(t,p,y);if("[object Arguments]"===b)return a(t,p,y);if("[object Boolean]"===b||"[object Number]"===b||"[object String]"===b)return h(t,p,y);if(f){var v=f[b];if(!v){var x=null!=(_=t)?_[Symbol.toStringTag]:void 0;x&&(v=f[x])}if(v)return v(t,p,y)}return!1}}var z=R();function R(t){void 0===t&&(t={});var e,r=t.circular,n=void 0!==r&&r,i=t.createInternalComparator,o=t.createState,s=t.strict,a=void 0!==s&&s,h=function(t){var e=t.circular,r=t.createCustomConfig,n=t.strict,i={areArraysEqual:n?O:v,areDatesEqual:x,areErrorsEqual:S,areFunctionsEqual:j,areMapsEqual:n?f(w,O):w,areNumbersEqual:k,areObjectsEqual:n?O:M,arePrimitiveWrappersEqual:A,areRegExpsEqual:q,areSetsEqual:n?f(E,O):E,areTypedArraysEqual:n?O:C,areUrlsEqual:P,unknownTagComparators:void 0};if(r&&(i=D({},i,r(i))),e){var o=p(i.areArraysEqual),s=p(i.areMapsEqual),a=p(i.areObjectsEqual),h=p(i.areSetsEqual);i=D({},i,{areArraysEqual:o,areMapsEqual:s,areObjectsEqual:a,areSetsEqual:h})}return i}(t),c=K(h);return function(t){var e=t.circular,r=t.comparator,n=t.createState,i=t.equals,o=t.strict;if(n)return function(t,s){var a=n(),h=a.cache,c=void 0===h?e?new WeakMap:void 0:h,u=a.meta;return r(t,s,{cache:c,equals:i,meta:u,strict:o})};if(e)return function(t,e){return r(t,e,{cache:new WeakMap,equals:i,meta:void 0,strict:o})};var s={cache:void 0,equals:i,meta:void 0,strict:o};return function(t,e){return r(t,e,s)}}({circular:n,comparator:c,createState:o,equals:i?i(c):(e=c,function(t,r,n,i,o,s,a){return e(t,r,a)}),strict:a})}function B(t,e){const r=function(t){return(e=t)&&"object"==typeof e&&"data"in e?t.data:t;var e}(t),n=e&&Array.isArray(e.fields)?e.fields:["topic","data","id"],i=e&&Array.isArray(e.excludeFields)?e.excludeFields:[],o=e&&e.idKey?e.idKey:"id",s=e&&e.childrenKey?e.childrenKey:"children",a=!e||!1!==e.includeStructure,h=new Map;return r&&r[o]&&function t(e,r,c){const u=function(t){const e={};o in t&&(e[o]=t[o]);const r=new Set([o,s,"direction","expanded","parentid","index","isroot"]),a=new Set(i);n.includes("data");for(const i of n)if("data"===i){const i={};let o=!1;for(const e in t)r.has(e)||n.includes(e)||a.has(e)||(i[e]=t[e],o=!0);o&&(e.data=i)}else i in t&&i!==o&&!a.has(i)&&(e[i]=t[i]);return e}(e),d=e[o];a&&(u.parentid=r||null,u.index="number"==typeof c?c:0),h.set(d,u);const l=e[s];l&&Array.isArray(l)&&l.forEach((e,r)=>t(e,d,r))}(r,null,0),h}function U(t,e){if(t===e)return!0;if(!t||!e)return!1;const r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(const n of r){const r=t[n],i=e[n];if(r===i)continue;if(r&&i&&"object"==typeof r&&"object"==typeof i){if(!z(r,i))return!1}else if(r!==i)return!1}return!0}function W(t,e){const r=[];if(!t||!e)return r;const n=new Set([...Object.keys(t),...Object.keys(e)]);n.delete("id");for(const i of n){const n=t[i],o=e[i];if(n===o)continue;(n&&o&&"object"==typeof n&&"object"==typeof o?!z(n,o):n!==o)&&r.push({key:i,before:n,after:o})}return r}function $(t){let e=!1,r=!1;for(const n of t)"parentid"===n.key&&(e=!0),"index"===n.key&&(r=!0);return{moved:e||r,parentChanged:e,orderChanged:r}}function H(t){const e=new Map;for(const[r,n]of t){const t=n.parentid;e.has(t)||e.set(t,[]),e.get(t).push({id:r,index:n.index})}for(const t of e.values())t.sort((t,e)=>t.index-e.index);return e}function J(t,e,r){const n=new Set,i=new Map;e.forEach((t,e)=>i.set(t.id,e));const o=[],s=[];for(const e of t)i.has(e.id)&&(o.push(e.id),s.push(i.get(e.id)));if(o.length<=1)return n;const a=function(t){const e=t.slice(),r=[0];let n,i,o,s,a;const h=t.length;for(n=0;n<h;n++){const h=t[n];if(0!==h||0===n){if(i=r[r.length-1],t[i]<h){e[n]=i,r.push(n);continue}for(o=0,s=r.length-1;o<s;)a=o+s>>1,t[r[a]]<h?o=a+1:s=a;h<t[r[o]]&&(o>0&&(e[n]=r[o-1]),r[o]=n)}}for(o=r.length,s=r[o-1];o-- >0;)r[o]=s,s=e[s];return r}(s),h=new Set(a);return o.forEach((t,e)=>{h.has(e)||n.add(t)}),n}function Y(t,e,r={}){const{fields:n,excludeFields:i,idKey:o,childrenKey:s,includeStructure:a=!0,maxSize:h=5e3}=r,c=B(t,{fields:n,excludeFields:i,idKey:o,childrenKey:s,includeStructure:a}),u=B(e,{fields:n,excludeFields:i,idKey:o,childrenKey:s,includeStructure:a}),d=[],l=[],f=[];for(const[t,e]of u){if(!c.has(t)){d.push(e);continue}const r=c.get(t);if(!U(r,e)){const n=W(r,e);l.push({id:t,before:r,after:e,changes:n})}}for(const[t,e]of c)u.has(t)||f.push(e);let p=!1;const y=d.length+l.length+f.length;if(y>h){p=!0;const t=Math.max(0,h),e=Math.min(d.length,Math.floor(t*(d.length/y))),r=Math.min(l.length,Math.floor(t*(l.length/y))),n=Math.min(f.length,Math.max(0,t-e-r));d.length=e,l.length=r,f.length=n}if(a){const t=function(t,e,r){const n=[],i=[],o=[],s=new Set,a=H(e),h=H(r);for(const[t,e]of h){const r=J(a.get(t)||[],e);for(const t of r)s.add(t)}for(const e of t){const{id:t,before:r,after:a,changes:h}=e,c=$(h),u=c.parentChanged,d=!u&&c.orderChanged&&s.has(t);if(u||d){const e={moveType:u?"cross-parent":"reorder",parentChanged:c.parentChanged,orderChanged:c.orderChanged,fromParent:r.parentid,toParent:a.parentid,fromOrder:r.index,toOrder:a.index},i=h.filter(t=>"parentid"!==t.key&&"index"!==t.key);i.length>0?o.push({id:t,before:r,after:a,changes:i,moveInfo:e}):n.push({id:t,before:r,after:a,moveInfo:e})}else if(c.orderChanged){const e=h.filter(t=>"parentid"!==t.key&&"index"!==t.key);e.length>0&&i.push({id:t,before:r,after:a,changes:e})}else i.push({id:t,before:r,after:a,changes:h})}return{moved:n,modified:i,movedAndModified:o}}(l,c,u);return{created:d,deleted:f,truncated:p,moved:t.moved,modified:t.modified,movedAndModified:t.movedAndModified}}return{created:d,deleted:f,moved:[],modified:l,movedAndModified:[],truncated:p}}R({strict:!0}),R({circular:!0}),R({circular:!0,strict:!0}),R({createInternalComparator:function(){return m}}),R({strict:!0,createInternalComparator:function(){return m}}),R({circular:!0,createInternalComparator:function(){return m}}),R({circular:!0,createInternalComparator:function(){return m},strict:!0});const V={enabled:!0,throttleMs:100,maxHistory:500,storageMode:"object",autoSwitchThreshold:0,keymap:{enabled:!1,redoUsesY:!1},detail:{enabled:!1},diff:{flat:!0,fields:void 0,maxSize:5e3}};class L extends c{static instanceName="historyPlugin";static preload=!0;constructor({jm:t,pluginOpt:e}){super({jm:t,pluginOpt:e}),this.options=function(t){const e=Object.assign({},V,t||{});return e.keymap||(e.keymap={enabled:!1,redoUsesY:!1}),e.detail||(e.detail={enabled:!1}),e.diff||(e.diff={flat:!0,fields:void 0,maxSize:5e3}),e}(e),this._mounted=!1,this._core=null,this._mountAPI(),this._initCore()}beforePluginDestroy(){h.debug("[history] beforePluginDestroy: clearing history stack"),this._core&&this._core.clear()}_initCore(){const r=this.jm,n=this.options;n.keymap&&n.keymap.enabled&&r.options&&r.options.shortcut&&this._injectShortcuts(r.options.shortcut,!!n.keymap.redoUsesY);const i=new G(r,n);this._core=i,r.history&&(r.history.add=(t,e)=>i.add(t,e),r.history.pause=()=>i.pause(),r.history.resume=t=>i.resume(!!t),r.history.clear=()=>i.clear(),r.history.canBack=()=>i.canBack(),r.history.canForward=()=>i.canForward(),r.history.back=t=>i.back("number"==typeof t?t:1),r.history.forward=t=>i.forward("number"==typeof t?t:1),r.history.length=()=>i.length(),r.history.index=()=>i.index(),r.history.setMax=t=>i.setMax(t),r.history.setThrottle=t=>i.setThrottle(t),r.history.exportSnapshot=()=>i.exportSnapshot(),r.history.importSnapshot=(t,e)=>i.importSnapshot(t,e),r.history.getStack=()=>i.getStackMeta(),r.history.diff=(t,e,r)=>{const n=this.jm.options.fieldNames,i=n?.id||"id";return Y(t,e,{fields:[n?.topic||"topic","data",i],idKey:i,childrenKey:n?.children||"children",...r})},this._listener=(r,n)=>{try{if(r===t&&n&&"data"in n){let t=null;const e=n.data&&n.data[0];if(e)if(e.data)if(Array.isArray(e.data)){const r=e.data.find(t=>t.isroot);t=r&&r.id}else t=e.data.id;else e.id&&(t=e.id);return void(t&&t!==i._lastRootId&&(h.debug("[history] root id changed, clearing stack and pausing"),i.clear(),i._lastRootId=t,setTimeout(()=>{try{h.debug("[history] adding bootstrap snapshot after show"),i._addNow&&i._addNow("bootstrap"),h.debug("[history] resuming history recording")}catch(t){h.warn("[history] failed to add bootstrap snapshot",t)}},100)))}r===e&&n&&n.evt&&i.add(n.evt,n)}catch(t){h.warn("[history] listener error",t)}},r.add_event_listener(this._listener))}_injectShortcuts(t,e){const r=[4186,8282],n=e?[4185,8281]:[5210,9306];t.handles.history_back=(t,e)=>{t.history&&t.history.back()&&(e.preventDefault(),e.stopPropagation&&e.stopPropagation())},t.handles.history_forward=(t,e)=>{t.history&&t.history.forward()&&(e.preventDefault(),e.stopPropagation&&e.stopPropagation())},t.mapping.history_back=r,t.mapping.history_forward=n}_mountAPI(){if(this._mounted)return;const t=this.jm,e={add:()=>{},pause:()=>{},resume:t=>{},clear:()=>{},canBack:()=>!1,canForward:()=>!1,back:t=>!1,forward:t=>!1,length:()=>0,index:()=>-1,setMax:t=>{},setThrottle:t=>{},exportSnapshot:()=>null,importSnapshot:(t,e)=>{},getStack:()=>({items:[],index:-1}),diff:(t,e,r)=>{const n=this.jm.options.fieldNames,i=n?.id||"id";return Y(t,e,{fields:[n?.topic||"topic","data",i],idKey:i,childrenKey:n?.children||"children",...r})},getOptions:()=>Object.assign({},this.options)};Object.defineProperty(t,"history",{value:e,configurable:!0,enumerable:!1,writable:!1}),this._mounted=!0,h.info("[history] API mounted (preload).")}beforePluginRemove(){try{if(this._listener&&this.jm&&Array.isArray(this.jm.event_handles)){const t=this.jm.event_handles.indexOf(this._listener);t>=0&&this.jm.event_handles.splice(t,1)}this.jm&&Object.prototype.hasOwnProperty.call(this.jm,"history")&&delete this.jm.history,this._mounted=!1}catch(t){h.error("[history] remove failed:",t)}}beforePluginDestroy(){h.error("beforePluginDestroy"),this.beforePluginRemove()}}class G{constructor(t,e){this.jm=t,this.options=e,this.enabled=!!e.enabled,this.maxHistory=Math.max(1,0|e.maxHistory),this.throttleMs=Math.max(0,0|e.throttleMs),this.storageMode=e.storageMode||"object",this.autoSwitchThreshold=Math.max(0,0|e.autoSwitchThreshold),this._history=[],this._idx=-1,this._paused=!1,this._lastAddAt=0,this._timer=0,this._pending=!1,this._pendingMeta=void 0,this._lastSig=null,this._lastRootId=null}add(t="manual",e){if(!this.enabled||this._paused)return;const r=Date.now()-this._lastAddAt;if(r>=this.throttleMs)return this._addNow(t,e),void(this._lastAddAt=Date.now());if(this._pending=!0,this._pendingMeta=e,this._timer)return;const n=Math.max(0,this.throttleMs-r);this._timer=setTimeout(()=>{this._timer=0,!this._paused&&this.enabled&&(this._addNow(t,this._pendingMeta),this._lastAddAt=Date.now()),this._pending=!1,this._pendingMeta=void 0},n)}pause(){this._paused=!0}resume(t=!1){this._paused=!1,t&&this._pending&&(clearTimeout(this._timer),this._timer=0,this._addNow("resume-flush",this._pendingMeta),this._lastAddAt=Date.now(),this._pending=!1,this._pendingMeta=void 0)}clear(){this._history=[],this._idx=-1,this._lastSig=null,this._notifyChange()}canBack(){return this._idx>0}canForward(){return this._idx>=0&&this._idx<this._history.length-1}back(t=1){if((!Number.isFinite(t)||t<=0)&&(t=1),this._idx-t<0)return!1;this._idx-=t;const e=this._applyIndex();return e&&this._notifyChange(),e}forward(t=1){if((!Number.isFinite(t)||t<=0)&&(t=1),this._idx+t>=this._history.length)return!1;this._idx+=t;const e=this._applyIndex();return e&&this._notifyChange(),e}length(){return this._history.length}index(){return this._idx}setMax(t){this.maxHistory=Math.max(1,0|t)}setThrottle(t){this.throttleMs=Math.max(0,0|t)}exportSnapshot(){return this._takeSnapshot()}importSnapshot(t,e){return this._applySnapshot(t,e)}getStackMeta(){return{items:this._history.slice(),index:this._idx}}_notifyChange(){try{this.jm.invoke_event_handle(r,{index:this._idx,length:this._history.length,canBack:this.canBack(),canForward:this.canForward()})}catch(t){h.warn("[history] failed to notify change",t)}}_addNow(t,e){const r=this._takeSnapshot();let n=this.storageMode;if(this.autoSwitchThreshold>0&&"object"===n){const t=this._countNodes(r);t>this.autoSwitchThreshold&&(n="string",h.debug(`[history] auto-switched to string mode (${t} nodes > ${this.autoSwitchThreshold})`))}let i=null;try{i=JSON.stringify(r)}catch{}if(!i||!this._lastSig||i!==this._lastSig){if(this._idx<this._history.length-1&&(this._history=this._history.slice(0,this._idx+1)),this._history.length>=this.maxHistory&&(this._history.shift(),this._idx=Math.max(-1,this._idx-1)),"string"===n)this._history.push(i);else{const t=this._deepFreeze(r);this._history.push(t)}this._idx=this._history.length-1,this._lastSig=i,this._notifyChange()}}_applyIndex(){const t=this._history[this._idx];if(!t)return!1;try{let e;if("string"==typeof t)e=JSON.parse(t),this._lastSig=t;else{e=this._cloneSnapshot(t);try{this._lastSig=JSON.stringify(t)}catch{this._lastSig=null}}return this._applySnapshot(e,{skipCentering:!0}),!0}catch(t){return h.error("[history] apply snapshot failed",t),!1}}_takeSnapshot(){return this.jm.get_data("node_tree")}_applySnapshot(t,e){const r=!(!e||!e.skipCentering);return this.jm.show(t,r),!0}_countNodes(t){let e=0;return function t(r){if(r&&(e++,r.children&&Array.isArray(r.children)))for(const e of r.children)t(e)}(t&&t.data?t.data:t),e}_deepFreeze(t){if(!t||"object"!=typeof t)return t;if(Object.isFrozen(t))return t;if(Object.freeze(t),Array.isArray(t))for(const e of t)this._deepFreeze(e);else for(const e of Object.keys(t))this._deepFreeze(t[e]);return t}_cloneSnapshot(t){if("function"==typeof structuredClone)try{return structuredClone(t)}catch{}try{return JSON.parse(JSON.stringify(t))}catch{return t}}}export{L as HistoryPlugin,L as default};
946
9
  //# sourceMappingURL=jsmind.history.js.map