@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,625 +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
- 'use strict';
9
- Object.defineProperty(exports, '__esModule', { value: !0 }),
10
- 'function' != typeof String.prototype.startsWith &&
11
- (String.prototype.startsWith = function (e) {
12
- return this.slice(0, e.length) === e;
13
- });
14
- const e = 1,
15
- t = 4,
16
- s = 1,
17
- i = 2,
18
- n = 3,
19
- l = 4;
20
- var o = function () {};
21
- let _ =
22
- 'undefined' == typeof console
23
- ? { level: o, log: o, debug: o, info: o, warn: o, error: o }
24
- : {
25
- level: function (e) {
26
- _.debug = e > s ? o : console.debug;
27
- _.info = e > i ? o : console.info;
28
- _.warn = e > n ? o : console.warn;
29
- _.error = e > l ? o : console.error;
30
- },
31
- log: console.log,
32
- debug: console.debug,
33
- info: console.info,
34
- warn: console.warn,
35
- error: console.error,
36
- };
37
- class d {
38
- static instanceName = '';
39
- static preload = !1;
40
- constructor({ jm: e, pluginOpt: t }) {
41
- (this.jm = e), (this.options = t || {});
42
- }
43
- beforePluginRemove() {}
44
- beforePluginDestroy() {
45
- this.beforePluginRemove();
46
- }
47
- }
48
- const c = {
49
- enable_multi_select: !1,
50
- include_descendants: !0,
51
- shift_simple_mode: !1,
52
- allow_ctrl: !0,
53
- allow_shift: !0,
54
- filter: null,
55
- };
56
- class r {
57
- constructor(e, t) {
58
- (this.jm = e),
59
- (this.options = t),
60
- this._ensure_selection_state(),
61
- (this._selection_mode = null),
62
- (this._last_selected_node = null);
63
- }
64
- _ensure_selection_state() {
65
- this.jm.mind || (this.jm.mind = {}),
66
- this.jm.mind.selected_nodes || (this.jm.mind.selected_nodes = new Set()),
67
- this.jm.view || (this.jm.view = {}),
68
- this.jm.view.multi_selected_nodes || (this.jm.view.multi_selected_nodes = new Map());
69
- }
70
- get_selected_nodes() {
71
- return (
72
- this._ensure_selection_state(),
73
- this.jm.mind && this.jm.mind.selected_nodes
74
- ? Array.from(this.jm.mind.selected_nodes).map(e => e.id)
75
- : []
76
- );
77
- }
78
- is_node_selected(e) {
79
- const t = this._resolve_node(e);
80
- return (
81
- !(!t || !this.jm.mind) &&
82
- (this._ensure_selection_state(), this.jm.mind.selected_nodes.has(t))
83
- );
84
- }
85
- select_node(e) {
86
- const t = this._resolve_node(e);
87
- if (!t) return void _.error('[multiSelect] node not found: ' + e);
88
- if (
89
- (this._ensure_selection_state(),
90
- this._clear_selection_state(),
91
- this._ensure_selection_state(),
92
- !this.jm.mind || !this.jm.mind.selected_nodes)
93
- )
94
- return void _.error('[multiSelect] jm.mind or selected_nodes is not available');
95
- (this.jm.mind.selected = t),
96
- (this._last_selected_node = t),
97
- this.jm.mind.selected_nodes.has(t) || this.jm.mind.selected_nodes.add(t),
98
- this._mark_node_selected(t),
99
- (this._selection_mode = 'single');
100
- const s = [t.id];
101
- this._invoke_select_event({ evt: 'select_node', data: s, node: t.id, nodes: s });
102
- }
103
- select_clear() {
104
- this._ensure_selection_state(),
105
- this.jm.mind &&
106
- ((this.jm.mind.selected = null),
107
- (this._last_selected_node = null),
108
- this._clear_selection_state());
109
- }
110
- toggle_node_selection(e) {
111
- const t = this._resolve_node(e);
112
- if (t && this.jm.layout.is_visible(t))
113
- if ((this._ensure_selection_state(), this.jm.mind.selected_nodes.has(t)))
114
- this._deselect_subtree(t);
115
- else {
116
- this._selection_mode = 'multi';
117
- this._append_selection([t]).length &&
118
- ((this.jm.mind.selected = t),
119
- (this._last_selected_node = t),
120
- this._invoke_select_event({
121
- evt: 'multi_select',
122
- data: [t.id],
123
- node: t.id,
124
- nodes: [t.id],
125
- }));
126
- }
127
- }
128
- toggle_subtree_selection(e, t) {
129
- const s = this._resolve_node(e);
130
- if (!s) return void _.error('[multiSelect] node not found: ' + e);
131
- if (!this.jm.layout.is_visible(s)) return;
132
- const i =
133
- t && void 0 !== t.include_descendants
134
- ? !!t.include_descendants
135
- : !1 !== this.options.include_descendants;
136
- if (
137
- (this._ensure_selection_state(),
138
- this.jm.mind.selected_nodes.has(s) && 'multi' === this._selection_mode)
139
- ) {
140
- let e = this._collect_subtree_nodes(s, {
141
- includeChildren: !0,
142
- respectFilter: !1,
143
- skipRootFilter: !1,
144
- });
145
- e.length || (e = [s]);
146
- const t = this._remove_selection(e);
147
- if (t.length) {
148
- this.jm.mind.selected &&
149
- this.jm.mind.selected.id === s.id &&
150
- (this.jm.mind.selected = null),
151
- (this._selection_mode = this._derive_selection_mode());
152
- const e = t.map(e => e.id);
153
- this._invoke_select_event({ evt: 'multi_deselect', data: e, node: s.id, nodes: e });
154
- }
155
- } else {
156
- this._selection_mode = 'multi';
157
- let e = this._collect_subtree_nodes(s, {
158
- includeChildren: i,
159
- respectFilter: !0,
160
- skipRootFilter: !0,
161
- });
162
- e.length || (e = [s]);
163
- const t = this._append_selection(e, { focusNode: s });
164
- this._ensure_selection_state();
165
- const n =
166
- s.parent && !this.jm.mind.selected_nodes.has(s.parent)
167
- ? this._ensure_ancestor_selection([s], s, {
168
- requireAncestorChainSelected: !0,
169
- })
170
- : [],
171
- l = t.concat(n);
172
- if (l.length) {
173
- this.jm.mind.selected = s;
174
- const e = l.map(e => e.id);
175
- this._invoke_select_event({ evt: 'multi_select', data: e, node: s.id, nodes: e });
176
- }
177
- }
178
- }
179
- get_selection_mode() {
180
- return this._selection_mode;
181
- }
182
- _handle_node_click(e) {
183
- const { e: t, node: s, element: i } = e;
184
- if (!s || !i) return;
185
- this._ensure_selection_state();
186
- const n = this._get_multi_select_mode(t);
187
- if ('ctrl' === n) this.toggle_node_selection(s);
188
- else if ('shift' === n) {
189
- const e = this.jm.get_node(s);
190
- if (!e) return void _.warn('[multiSelect] Node not found for shift selection: ' + s);
191
- if (this.options.shift_simple_mode)
192
- this.is_node_selected(s) ? this._deselect_subtree(e) : this._range_select_nodes(s);
193
- else if (this.is_node_selected(s)) this._deselect_subtree(e);
194
- else {
195
- const t = !1 !== this.options.include_descendants;
196
- let s = this._collect_subtree_nodes(e, {
197
- includeChildren: t,
198
- respectFilter: !0,
199
- skipRootFilter: !0,
200
- });
201
- s.length || (s = [e]);
202
- const i = this._append_selection(s, { focusNode: e });
203
- if (i.length) {
204
- (this.jm.mind.selected = e),
205
- (this._last_selected_node = e),
206
- (this._selection_mode = this._derive_selection_mode());
207
- const t = i.map(e => e.id);
208
- this._invoke_select_event({
209
- evt: 'multi_select',
210
- data: t,
211
- node: e.id,
212
- nodes: t,
213
- });
214
- } else
215
- this._ensure_selection_state(),
216
- this.jm.mind.selected_nodes.has(e) ||
217
- (this.jm.mind.selected_nodes.add(e), this._mark_node_selected(e)),
218
- (this.jm.mind.selected = e),
219
- (this._last_selected_node = e),
220
- (this._selection_mode = this._derive_selection_mode()),
221
- this._invoke_select_event({
222
- evt: 'multi_select',
223
- data: [e.id],
224
- node: e.id,
225
- nodes: [e.id],
226
- });
227
- }
228
- } else this.select_node(s);
229
- }
230
- _handle_node_removed(e) {
231
- this._ensure_selection_state(),
232
- this.jm.mind.selected_nodes.has(e) && this.jm.mind.selected_nodes.delete(e),
233
- this._last_selected_node &&
234
- this._last_selected_node.id === e.id &&
235
- (this._last_selected_node = null),
236
- this.jm.view.multi_selected_nodes &&
237
- this.jm.view.multi_selected_nodes.has(e.id) &&
238
- this._unmark_node_selected(e);
239
- }
240
- _get_multi_select_mode(e) {
241
- return e
242
- ? !1 !== this.options.allow_shift && !0 === e.shiftKey
243
- ? 'shift'
244
- : !1 === this.options.allow_ctrl || (!0 !== e.ctrlKey && !0 !== e.metaKey)
245
- ? null
246
- : 'ctrl'
247
- : null;
248
- }
249
- _append_selection(e, t) {
250
- if (!e || !e.length) return [];
251
- if ((this._ensure_selection_state(), !this.jm.mind || !this.jm.mind.selected_nodes))
252
- return (
253
- _.warn('[multiSelect] Cannot append selection: selected_nodes not available'), []
254
- );
255
- const s = [];
256
- for (let t = 0; t < e.length; t++) {
257
- const i = e[t];
258
- this.jm.mind.selected_nodes.has(i) || (this.jm.mind.selected_nodes.add(i), s.push(i));
259
- }
260
- if (s.length) {
261
- const e = t && t.focusNode ? t.focusNode : null;
262
- this._mark_nodes_selected(s, e || s[s.length - 1]);
263
- }
264
- return s;
265
- }
266
- _remove_selection(e) {
267
- if (!e || !e.length) return [];
268
- this._ensure_selection_state();
269
- const t = [];
270
- for (let s = 0; s < e.length; s++) {
271
- const i = e[s];
272
- this.jm.mind.selected_nodes.has(i) &&
273
- (this.jm.mind.selected_nodes.delete(i), t.push(i));
274
- }
275
- return t.length && this._unmark_nodes_selected(t), t;
276
- }
277
- _deselect_subtree(e) {
278
- let t = this._collect_subtree_nodes(e, {
279
- includeChildren: !0,
280
- respectFilter: !1,
281
- skipRootFilter: !1,
282
- });
283
- t.length || (t = [e]);
284
- const s = this._remove_selection(t);
285
- if (s.length) {
286
- this.jm.mind.selected &&
287
- this.jm.mind.selected.id === e.id &&
288
- (this.jm.mind.selected = null),
289
- (this._selection_mode = this._derive_selection_mode());
290
- const t = s.map(e => e.id);
291
- this._invoke_select_event({ evt: 'multi_deselect', data: t, node: e.id, nodes: t });
292
- }
293
- }
294
- _clear_selection_state() {
295
- if (
296
- (this._ensure_selection_state(),
297
- (this._selection_mode = null),
298
- (this.jm.mind && this.jm.mind.selected_nodes) || this._ensure_selection_state(),
299
- !this.jm.mind || !this.jm.mind.selected_nodes || 0 === this.jm.mind.selected_nodes.size)
300
- )
301
- return this._clear_all_selected_nodes_view(), [];
302
- const e = Array.from(this.jm.mind.selected_nodes);
303
- return this.jm.mind.selected_nodes.clear(), this._unmark_nodes_selected(e), e;
304
- }
305
- _collect_subtree_nodes(e, t) {
306
- const s = t || {},
307
- i = !1 !== s.includeChildren,
308
- n = !!s.respectFilter,
309
- l = !!s.skipRootFilter,
310
- o = n ? this._get_selection_filter() : null,
311
- _ = [],
312
- d = (e, t) => {
313
- let s = !0;
314
- if ((!o || (l && t) || (s = !1 !== o(e)), s && _.push(e), i && e.children))
315
- for (let t = 0; t < e.children.length; t++) d(e.children[t], !1);
316
- };
317
- return d(e, !0), _;
318
- }
319
- _ensure_ancestor_selection(e, t, s) {
320
- if (!e || !e.length) return [];
321
- this._ensure_selection_state();
322
- const i = !(!s || !s.requireAncestorChainSelected),
323
- n = [],
324
- l = Object.create(null);
325
- for (let t = 0; t < e.length; t++) {
326
- let s = e[t].parent;
327
- if (!s) continue;
328
- const o = [];
329
- let _ = !i;
330
- for (; s; ) {
331
- if (this.jm.mind.selected_nodes.has(s)) {
332
- _ = !0;
333
- break;
334
- }
335
- o.push(s), (s = s.parent);
336
- }
337
- if (_)
338
- for (let e = 0; e < o.length; e++) {
339
- const t = o[e];
340
- this.jm.mind.selected_nodes.has(t) || l[t.id] || (n.push(t), (l[t.id] = !0));
341
- }
342
- }
343
- if (!n.length) return [];
344
- const o = t || e[e.length - 1];
345
- return this._append_selection(n, { focusNode: o });
346
- }
347
- _get_selection_filter() {
348
- return this.options && 'function' == typeof this.options.filter
349
- ? this.options.filter
350
- : null;
351
- }
352
- _range_select_nodes(e) {
353
- const t = this._resolve_node(e);
354
- if (!t || !this.jm.layout.is_visible(t)) return;
355
- if ((this._ensure_selection_state(), 0 === this.jm.mind.selected_nodes.size)) {
356
- let e = this._collect_subtree_nodes(t, {
357
- includeChildren: !0,
358
- respectFilter: !0,
359
- skipRootFilter: !0,
360
- });
361
- e.length || (e = [t]);
362
- const s = this._append_selection(e);
363
- if (s.length) {
364
- (this.jm.mind.selected = t),
365
- (this._last_selected_node = t),
366
- (this._selection_mode = this._derive_selection_mode());
367
- const e = s.map(e => e.id);
368
- this._invoke_select_event({ evt: 'multi_select', data: e, node: t.id, nodes: e });
369
- }
370
- return;
371
- }
372
- this._ensure_selection_state();
373
- const s = Array.from(this.jm.mind.selected_nodes),
374
- i =
375
- this._last_selected_node &&
376
- this.jm.mind.selected_nodes.has(this._last_selected_node)
377
- ? this._last_selected_node
378
- : s[0],
379
- n = this._find_nodes_between(i, t);
380
- if (!n.length) {
381
- const e = [t],
382
- s = this._append_selection(e);
383
- if (s.length) {
384
- (this.jm.mind.selected = t),
385
- (this._last_selected_node = t),
386
- (this._selection_mode = this._derive_selection_mode());
387
- const e = s.map(e => e.id);
388
- this._invoke_select_event({ evt: 'multi_select', data: e, node: t.id, nodes: e });
389
- }
390
- return;
391
- }
392
- this._ensure_selection_state();
393
- const l = n.filter(e => !this.jm.mind.selected_nodes.has(e)),
394
- o = this._append_selection(l);
395
- if (o.length) {
396
- (this.jm.mind.selected = t),
397
- (this._last_selected_node = t),
398
- (this._selection_mode = this._derive_selection_mode());
399
- const e = o.map(e => e.id);
400
- this._invoke_select_event({ evt: 'multi_select', data: e, node: t.id, nodes: e });
401
- }
402
- }
403
- _find_nodes_between(e, t) {
404
- if (!e || !t) return [];
405
- const s = [],
406
- i = e => {
407
- if ((this.jm.layout.is_visible(e) && s.push(e), e.children))
408
- for (let t = 0; t < e.children.length; t++) i(e.children[t]);
409
- };
410
- this.jm.mind && this.jm.mind.root && i(this.jm.mind.root);
411
- let n = -1,
412
- l = -1;
413
- for (let i = 0; i < s.length; i++) s[i].id === e.id && (n = i), s[i].id === t.id && (l = i);
414
- if (-1 === n || -1 === l) return [];
415
- const o = Math.min(n, l),
416
- _ = Math.max(n, l);
417
- return s.slice(o, _ + 1);
418
- }
419
- _derive_selection_mode() {
420
- this._ensure_selection_state();
421
- const e = this.jm.mind.selected_nodes.size;
422
- return 0 === e ? null : e > 1 ? 'multi' : 'single';
423
- }
424
- _mark_nodes_selected(e, t) {
425
- if (e && e.length) {
426
- for (let t = 0; t < e.length; t++) this._mark_node_selected(e[t]);
427
- this.jm.view.selected_node = t || e[e.length - 1];
428
- }
429
- }
430
- _mark_node_selected(e) {
431
- if (!e || this.jm.view.multi_selected_nodes.has(e.id)) return;
432
- const t = e._data && e._data.view && e._data.view.element;
433
- t &&
434
- (t.classList
435
- ? t.classList.add('selected')
436
- : /(\s|^)selected(\s|$)/.test(t.className) || (t.className += ' selected'),
437
- this.jm.view.multi_selected_nodes.set(e.id, e));
438
- }
439
- _unmark_nodes_selected(e) {
440
- if (e && e.length) for (let t = 0; t < e.length; t++) this._unmark_node_selected(e[t]);
441
- }
442
- _unmark_node_selected(e) {
443
- if (e) {
444
- if (this.jm.view.multi_selected_nodes.has(e.id)) {
445
- const t = e._data && e._data.view && e._data.view.element;
446
- t &&
447
- (t.classList
448
- ? t.classList.remove('selected')
449
- : (t.className = t.className.replace(/\s*selected\b/i, ''))),
450
- this.jm.view.multi_selected_nodes.delete(e.id);
451
- }
452
- this.jm.view.selected_node &&
453
- this.jm.view.selected_node.id === e.id &&
454
- (this.jm.view.selected_node = null);
455
- }
456
- }
457
- _clear_all_selected_nodes_view() {
458
- if (
459
- (this._ensure_selection_state(),
460
- !this.jm.view.multi_selected_nodes || !this.jm.view.multi_selected_nodes.size)
461
- )
462
- return void (this.jm.view && (this.jm.view.selected_node = null));
463
- const e = Array.from(this.jm.view.multi_selected_nodes.values());
464
- for (let t = 0; t < e.length; t++) this._unmark_node_selected(e[t]);
465
- this.jm.view && (this.jm.view.selected_node = null);
466
- }
467
- _invoke_select_event(e) {
468
- try {
469
- e.nodes || (e.nodes = e.data || []),
470
- e.data || (e.data = e.nodes || []),
471
- this.jm.invoke_event_handle(t, e);
472
- } catch (e) {
473
- _.warn('[multiSelect] failed to invoke select event', e);
474
- }
475
- }
476
- _resolve_node(e) {
477
- return e ? ('string' == typeof e ? this.jm.get_node(e) : e) : null;
478
- }
479
- }
480
- class h extends d {
481
- static instanceName = 'multiSelectPlugin';
482
- static preload = !1;
483
- constructor({ jm: e, pluginOpt: t }) {
484
- super({ jm: e, pluginOpt: t });
485
- const s = Object.assign({}, c, t || {});
486
- (this.options = s),
487
- (this._mounted = !1),
488
- (this._core = null),
489
- (this._listener = null),
490
- (this._enabled = !!s.enable_multi_select),
491
- this._initCore();
492
- }
493
- _initCore() {
494
- const t = this.jm,
495
- s = this.options,
496
- i = this;
497
- (this._core = new r(t, s)),
498
- this._mountAPI(),
499
- (this._listener = (t, s) => {
500
- try {
501
- t === e && i._core.select_clear();
502
- } catch (e) {
503
- _.warn('[multiSelect] listener error', e);
504
- }
505
- }),
506
- t.add_event_listener(this._listener),
507
- (this._original_select_node = t.select_node.bind(t)),
508
- (this._original_select_clear = t.select_clear.bind(t)),
509
- (t.select_node = e =>
510
- i._enabled ? i._core.select_node(e) : i._original_select_node(e)),
511
- (t.select_clear = () =>
512
- i._enabled ? i._core.select_clear() : i._original_select_clear());
513
- const n = t.constructor.$;
514
- (this._domClickHandler = function (e) {
515
- if (!i._enabled) return;
516
- const s = e.target || e.currentTarget,
517
- n = t.view.get_binded_nodeid(s);
518
- n && t.view.is_node(s)
519
- ? (e.preventDefault(),
520
- e.stopPropagation(),
521
- e.stopImmediatePropagation && e.stopImmediatePropagation(),
522
- i._core._handle_node_click({ e: e, node: n, element: s, evt: 'click' }))
523
- : n || e.ctrlKey || e.metaKey || e.shiftKey || i._core.select_clear();
524
- }),
525
- t.view && t.view.e_nodes
526
- ? (n.on(t.view.e_nodes, 'click', this._domClickHandler),
527
- _.info('[multiSelect] plugin click handler attached'))
528
- : _.warn('[multiSelect] nodes container not ready; DOM handler not attached'),
529
- this._enabled &&
530
- 'function' == typeof t.disable_event_handle &&
531
- t.disable_event_handle('mousedown'),
532
- _.info('[multiSelect] API mounted and event listener attached.');
533
- }
534
- _mountAPI() {
535
- if (this._mounted) return;
536
- const e = this.jm,
537
- t = this,
538
- s = {
539
- get_selected_nodes: () =>
540
- t._core
541
- ? t._core.get_selected_nodes()
542
- : (_.warn('[multiSelect] Core not initialized'), []),
543
- is_node_selected: e => !!t._core && t._core.is_node_selected(e),
544
- select_node: e => {
545
- t._core ? t._core.select_node(e) : _.warn('[multiSelect] Core not initialized');
546
- },
547
- select_clear: () => {
548
- t._core && t._core.select_clear();
549
- },
550
- toggle_node_selection: e => {
551
- t._core
552
- ? t._core.toggle_node_selection(e)
553
- : _.warn('[multiSelect] Core not initialized');
554
- },
555
- toggle_subtree_selection: e => {
556
- t._core
557
- ? t._core.toggle_subtree_selection(e)
558
- : _.warn('[multiSelect] Core not initialized');
559
- },
560
- get_selection_mode: () => (t._core ? t._core.get_selection_mode() : null),
561
- getOptions: () => {
562
- const e = t._core ? t._core.options : t.options;
563
- return Object.assign({}, e, { enable_multi_select: t._enabled });
564
- },
565
- enable: () => t.setEnabled(!0),
566
- disable: () => t.setEnabled(!1),
567
- setEnabled: e => t.setEnabled(e),
568
- setOptions: e => t.setOptions(e),
569
- };
570
- Object.defineProperty(e, 'multiSelect', {
571
- value: s,
572
- configurable: !0,
573
- enumerable: !1,
574
- writable: !1,
575
- }),
576
- (this._mounted = !0),
577
- _.info('[multiSelect] API mounted.');
578
- }
579
- beforePluginRemove() {
580
- try {
581
- if (this._listener && this.jm && Array.isArray(this.jm.event_handles)) {
582
- const e = this.jm.event_handles.indexOf(this._listener);
583
- e >= 0 && this.jm.event_handles.splice(e, 1);
584
- }
585
- 'function' == typeof this.jm.enable_event_handle &&
586
- this.jm.enable_event_handle('mousedown'),
587
- this._domClickHandler &&
588
- this.jm &&
589
- this.jm.view &&
590
- this.jm.view.e_nodes &&
591
- (this._domClickHandler = null),
592
- this._original_select_node && (this.jm.select_node = this._original_select_node),
593
- this._original_select_clear && (this.jm.select_clear = this._original_select_clear),
594
- this.jm &&
595
- Object.prototype.hasOwnProperty.call(this.jm, 'multiSelect') &&
596
- delete this.jm.multiSelect,
597
- (this._mounted = !1);
598
- } catch (e) {
599
- _.error('[multiSelect] remove failed:', e);
600
- }
601
- }
602
- setEnabled(e) {
603
- const t = !!e;
604
- this._enabled !== t &&
605
- ((this._enabled = t),
606
- (this.options.enable_multi_select = this._enabled),
607
- this._enabled
608
- ? 'function' == typeof this.jm.disable_event_handle &&
609
- this.jm.disable_event_handle('mousedown')
610
- : 'function' == typeof this.jm.enable_event_handle &&
611
- this.jm.enable_event_handle('mousedown'));
612
- }
613
- setOptions(e) {
614
- const t = Object.assign({}, e || {});
615
- (this.options = Object.assign({}, this.options, t)),
616
- this._core &&
617
- this._core.options &&
618
- (this._core.options = Object.assign({}, this._core.options, t));
619
- }
620
- beforePluginDestroy() {
621
- _.debug('[multiSelect] beforePluginDestroy'), this.beforePluginRemove();
622
- }
623
- }
624
- (exports.MultiSelectCore = r), (exports.MultiSelectPlugin = h), (exports.default = h);
2
+ * @license BSD-3-Clause
3
+ * @copyright 2014-2025 hizzgdev@163.com
4
+ *
5
+ * Project Home:
6
+ * https://github.com/hizzgdev/jsmind/
7
+ */
8
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(e){return this.slice(0,e.length)===e});const e=1,t=4,s=1,i=2,n=3,l=4;var o=function(){};let _="undefined"==typeof console?{level:o,log:o,debug:o,info:o,warn:o,error:o}:{level:function(e){_.debug=e>s?o:console.debug;_.info=e>i?o:console.info;_.warn=e>n?o:console.warn;_.error=e>l?o:console.error},log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};class d{static instanceName="";static preload=!1;constructor({jm:e,pluginOpt:t}){this.jm=e,this.options=t||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}const c={enable_multi_select:!1,include_descendants:!0,shift_simple_mode:!1,allow_ctrl:!0,allow_shift:!0,filter:null};class r{constructor(e,t){this.jm=e,this.options=t,this._ensure_selection_state(),this._selection_mode=null,this._last_selected_node=null}_ensure_selection_state(){this.jm.mind||(this.jm.mind={}),this.jm.mind.selected_nodes||(this.jm.mind.selected_nodes=new Set),this.jm.view||(this.jm.view={}),this.jm.view.multi_selected_nodes||(this.jm.view.multi_selected_nodes=new Map)}get_selected_nodes(){return this._ensure_selection_state(),this.jm.mind&&this.jm.mind.selected_nodes?Array.from(this.jm.mind.selected_nodes).map(e=>e.id):[]}is_node_selected(e){const t=this._resolve_node(e);return!(!t||!this.jm.mind)&&(this._ensure_selection_state(),this.jm.mind.selected_nodes.has(t))}select_node(e){const t=this._resolve_node(e);if(!t)return void _.error("[multiSelect] node not found: "+e);if(this._ensure_selection_state(),this._clear_selection_state(),this._ensure_selection_state(),!this.jm.mind||!this.jm.mind.selected_nodes)return void _.error("[multiSelect] jm.mind or selected_nodes is not available");this.jm.mind.selected=t,this._last_selected_node=t,this.jm.mind.selected_nodes.has(t)||this.jm.mind.selected_nodes.add(t),this._mark_node_selected(t),this._selection_mode="single";const s=[t.id];this._invoke_select_event({evt:"select_node",data:s,node:t.id,nodes:s})}select_clear(){this._ensure_selection_state(),this.jm.mind&&(this.jm.mind.selected=null,this._last_selected_node=null,this._clear_selection_state())}toggle_node_selection(e){const t=this._resolve_node(e);if(t&&this.jm.layout.is_visible(t))if(this._ensure_selection_state(),this.jm.mind.selected_nodes.has(t))this._deselect_subtree(t);else{this._selection_mode="multi";this._append_selection([t]).length&&(this.jm.mind.selected=t,this._last_selected_node=t,this._invoke_select_event({evt:"multi_select",data:[t.id],node:t.id,nodes:[t.id]}))}}toggle_subtree_selection(e,t){const s=this._resolve_node(e);if(!s)return void _.error("[multiSelect] node not found: "+e);if(!this.jm.layout.is_visible(s))return;const i=t&&void 0!==t.include_descendants?!!t.include_descendants:!1!==this.options.include_descendants;if(this._ensure_selection_state(),this.jm.mind.selected_nodes.has(s)&&"multi"===this._selection_mode){let e=this._collect_subtree_nodes(s,{includeChildren:!0,respectFilter:!1,skipRootFilter:!1});e.length||(e=[s]);const t=this._remove_selection(e);if(t.length){this.jm.mind.selected&&this.jm.mind.selected.id===s.id&&(this.jm.mind.selected=null),this._selection_mode=this._derive_selection_mode();const e=t.map(e=>e.id);this._invoke_select_event({evt:"multi_deselect",data:e,node:s.id,nodes:e})}}else{this._selection_mode="multi";let e=this._collect_subtree_nodes(s,{includeChildren:i,respectFilter:!0,skipRootFilter:!0});e.length||(e=[s]);const t=this._append_selection(e,{focusNode:s});this._ensure_selection_state();const n=s.parent&&!this.jm.mind.selected_nodes.has(s.parent)?this._ensure_ancestor_selection([s],s,{requireAncestorChainSelected:!0}):[],l=t.concat(n);if(l.length){this.jm.mind.selected=s;const e=l.map(e=>e.id);this._invoke_select_event({evt:"multi_select",data:e,node:s.id,nodes:e})}}}get_selection_mode(){return this._selection_mode}_handle_node_click(e){const{e:t,node:s,element:i}=e;if(!s||!i)return;this._ensure_selection_state();const n=this._get_multi_select_mode(t);if("ctrl"===n)this.toggle_node_selection(s);else if("shift"===n){const e=this.jm.get_node(s);if(!e)return void _.warn("[multiSelect] Node not found for shift selection: "+s);if(this.options.shift_simple_mode)this.is_node_selected(s)?this._deselect_subtree(e):this._range_select_nodes(s);else if(this.is_node_selected(s))this._deselect_subtree(e);else{const t=!1!==this.options.include_descendants;let s=this._collect_subtree_nodes(e,{includeChildren:t,respectFilter:!0,skipRootFilter:!0});s.length||(s=[e]);const i=this._append_selection(s,{focusNode:e});if(i.length){this.jm.mind.selected=e,this._last_selected_node=e,this._selection_mode=this._derive_selection_mode();const t=i.map(e=>e.id);this._invoke_select_event({evt:"multi_select",data:t,node:e.id,nodes:t})}else this._ensure_selection_state(),this.jm.mind.selected_nodes.has(e)||(this.jm.mind.selected_nodes.add(e),this._mark_node_selected(e)),this.jm.mind.selected=e,this._last_selected_node=e,this._selection_mode=this._derive_selection_mode(),this._invoke_select_event({evt:"multi_select",data:[e.id],node:e.id,nodes:[e.id]})}}else this.select_node(s)}_handle_node_removed(e){this._ensure_selection_state(),this.jm.mind.selected_nodes.has(e)&&this.jm.mind.selected_nodes.delete(e),this._last_selected_node&&this._last_selected_node.id===e.id&&(this._last_selected_node=null),this.jm.view.multi_selected_nodes&&this.jm.view.multi_selected_nodes.has(e.id)&&this._unmark_node_selected(e)}_get_multi_select_mode(e){return e?!1!==this.options.allow_shift&&!0===e.shiftKey?"shift":!1===this.options.allow_ctrl||!0!==e.ctrlKey&&!0!==e.metaKey?null:"ctrl":null}_append_selection(e,t){if(!e||!e.length)return[];if(this._ensure_selection_state(),!this.jm.mind||!this.jm.mind.selected_nodes)return _.warn("[multiSelect] Cannot append selection: selected_nodes not available"),[];const s=[];for(let t=0;t<e.length;t++){const i=e[t];this.jm.mind.selected_nodes.has(i)||(this.jm.mind.selected_nodes.add(i),s.push(i))}if(s.length){const e=t&&t.focusNode?t.focusNode:null;this._mark_nodes_selected(s,e||s[s.length-1])}return s}_remove_selection(e){if(!e||!e.length)return[];this._ensure_selection_state();const t=[];for(let s=0;s<e.length;s++){const i=e[s];this.jm.mind.selected_nodes.has(i)&&(this.jm.mind.selected_nodes.delete(i),t.push(i))}return t.length&&this._unmark_nodes_selected(t),t}_deselect_subtree(e){let t=this._collect_subtree_nodes(e,{includeChildren:!0,respectFilter:!1,skipRootFilter:!1});t.length||(t=[e]);const s=this._remove_selection(t);if(s.length){this.jm.mind.selected&&this.jm.mind.selected.id===e.id&&(this.jm.mind.selected=null),this._selection_mode=this._derive_selection_mode();const t=s.map(e=>e.id);this._invoke_select_event({evt:"multi_deselect",data:t,node:e.id,nodes:t})}}_clear_selection_state(){if(this._ensure_selection_state(),this._selection_mode=null,this.jm.mind&&this.jm.mind.selected_nodes||this._ensure_selection_state(),!this.jm.mind||!this.jm.mind.selected_nodes||0===this.jm.mind.selected_nodes.size)return this._clear_all_selected_nodes_view(),[];const e=Array.from(this.jm.mind.selected_nodes);return this.jm.mind.selected_nodes.clear(),this._unmark_nodes_selected(e),e}_collect_subtree_nodes(e,t){const s=t||{},i=!1!==s.includeChildren,n=!!s.respectFilter,l=!!s.skipRootFilter,o=n?this._get_selection_filter():null,_=[],d=(e,t)=>{let s=!0;if(!o||l&&t||(s=!1!==o(e)),s&&_.push(e),i&&e.children)for(let t=0;t<e.children.length;t++)d(e.children[t],!1)};return d(e,!0),_}_ensure_ancestor_selection(e,t,s){if(!e||!e.length)return[];this._ensure_selection_state();const i=!(!s||!s.requireAncestorChainSelected),n=[],l=Object.create(null);for(let t=0;t<e.length;t++){let s=e[t].parent;if(!s)continue;const o=[];let _=!i;for(;s;){if(this.jm.mind.selected_nodes.has(s)){_=!0;break}o.push(s),s=s.parent}if(_)for(let e=0;e<o.length;e++){const t=o[e];this.jm.mind.selected_nodes.has(t)||l[t.id]||(n.push(t),l[t.id]=!0)}}if(!n.length)return[];const o=t||e[e.length-1];return this._append_selection(n,{focusNode:o})}_get_selection_filter(){return this.options&&"function"==typeof this.options.filter?this.options.filter:null}_range_select_nodes(e){const t=this._resolve_node(e);if(!t||!this.jm.layout.is_visible(t))return;if(this._ensure_selection_state(),0===this.jm.mind.selected_nodes.size){let e=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!0,skipRootFilter:!0});e.length||(e=[t]);const s=this._append_selection(e);if(s.length){this.jm.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();const e=s.map(e=>e.id);this._invoke_select_event({evt:"multi_select",data:e,node:t.id,nodes:e})}return}this._ensure_selection_state();const s=Array.from(this.jm.mind.selected_nodes),i=this._last_selected_node&&this.jm.mind.selected_nodes.has(this._last_selected_node)?this._last_selected_node:s[0],n=this._find_nodes_between(i,t);if(!n.length){const e=[t],s=this._append_selection(e);if(s.length){this.jm.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();const e=s.map(e=>e.id);this._invoke_select_event({evt:"multi_select",data:e,node:t.id,nodes:e})}return}this._ensure_selection_state();const l=n.filter(e=>!this.jm.mind.selected_nodes.has(e)),o=this._append_selection(l);if(o.length){this.jm.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();const e=o.map(e=>e.id);this._invoke_select_event({evt:"multi_select",data:e,node:t.id,nodes:e})}}_find_nodes_between(e,t){if(!e||!t)return[];const s=[],i=e=>{if(this.jm.layout.is_visible(e)&&s.push(e),e.children)for(let t=0;t<e.children.length;t++)i(e.children[t])};this.jm.mind&&this.jm.mind.root&&i(this.jm.mind.root);let n=-1,l=-1;for(let i=0;i<s.length;i++)s[i].id===e.id&&(n=i),s[i].id===t.id&&(l=i);if(-1===n||-1===l)return[];const o=Math.min(n,l),_=Math.max(n,l);return s.slice(o,_+1)}_derive_selection_mode(){this._ensure_selection_state();const e=this.jm.mind.selected_nodes.size;return 0===e?null:e>1?"multi":"single"}_mark_nodes_selected(e,t){if(e&&e.length){for(let t=0;t<e.length;t++)this._mark_node_selected(e[t]);this.jm.view.selected_node=t||e[e.length-1]}}_mark_node_selected(e){if(!e||this.jm.view.multi_selected_nodes.has(e.id))return;const t=e._data&&e._data.view&&e._data.view.element;t&&(t.classList?t.classList.add("selected"):/(\s|^)selected(\s|$)/.test(t.className)||(t.className+=" selected"),this.jm.view.multi_selected_nodes.set(e.id,e))}_unmark_nodes_selected(e){if(e&&e.length)for(let t=0;t<e.length;t++)this._unmark_node_selected(e[t])}_unmark_node_selected(e){if(e){if(this.jm.view.multi_selected_nodes.has(e.id)){const t=e._data&&e._data.view&&e._data.view.element;t&&(t.classList?t.classList.remove("selected"):t.className=t.className.replace(/\s*selected\b/i,"")),this.jm.view.multi_selected_nodes.delete(e.id)}this.jm.view.selected_node&&this.jm.view.selected_node.id===e.id&&(this.jm.view.selected_node=null)}}_clear_all_selected_nodes_view(){if(this._ensure_selection_state(),!this.jm.view.multi_selected_nodes||!this.jm.view.multi_selected_nodes.size)return void(this.jm.view&&(this.jm.view.selected_node=null));const e=Array.from(this.jm.view.multi_selected_nodes.values());for(let t=0;t<e.length;t++)this._unmark_node_selected(e[t]);this.jm.view&&(this.jm.view.selected_node=null)}_invoke_select_event(e){try{e.nodes||(e.nodes=e.data||[]),e.data||(e.data=e.nodes||[]),this.jm.invoke_event_handle(t,e)}catch(e){_.warn("[multiSelect] failed to invoke select event",e)}}_resolve_node(e){return e?"string"==typeof e?this.jm.get_node(e):e:null}}class h extends d{static instanceName="multiSelectPlugin";static preload=!1;constructor({jm:e,pluginOpt:t}){super({jm:e,pluginOpt:t});const s=Object.assign({},c,t||{});this.options=s,this._mounted=!1,this._core=null,this._listener=null,this._enabled=!!s.enable_multi_select,this._initCore()}_initCore(){const t=this.jm,s=this.options,i=this;this._core=new r(t,s),this._mountAPI(),this._listener=(t,s)=>{try{t===e&&i._core.select_clear()}catch(e){_.warn("[multiSelect] listener error",e)}},t.add_event_listener(this._listener),this._original_select_node=t.select_node.bind(t),this._original_select_clear=t.select_clear.bind(t),t.select_node=e=>i._enabled?i._core.select_node(e):i._original_select_node(e),t.select_clear=()=>i._enabled?i._core.select_clear():i._original_select_clear();const n=t.constructor.$;this._domClickHandler=function(e){if(!i._enabled)return;const s=e.target||e.currentTarget,n=t.view.get_binded_nodeid(s);n&&t.view.is_node(s)?(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),i._core._handle_node_click({e:e,node:n,element:s,evt:"click"})):n||e.ctrlKey||e.metaKey||e.shiftKey||i._core.select_clear()},t.view&&t.view.e_nodes?(n.on(t.view.e_nodes,"click",this._domClickHandler),_.info("[multiSelect] plugin click handler attached")):_.warn("[multiSelect] nodes container not ready; DOM handler not attached"),this._enabled&&"function"==typeof t.disable_event_handle&&t.disable_event_handle("mousedown"),_.info("[multiSelect] API mounted and event listener attached.")}_mountAPI(){if(this._mounted)return;const e=this.jm,t=this,s={get_selected_nodes:()=>t._core?t._core.get_selected_nodes():(_.warn("[multiSelect] Core not initialized"),[]),is_node_selected:e=>!!t._core&&t._core.is_node_selected(e),select_node:e=>{t._core?t._core.select_node(e):_.warn("[multiSelect] Core not initialized")},select_clear:()=>{t._core&&t._core.select_clear()},toggle_node_selection:e=>{t._core?t._core.toggle_node_selection(e):_.warn("[multiSelect] Core not initialized")},toggle_subtree_selection:e=>{t._core?t._core.toggle_subtree_selection(e):_.warn("[multiSelect] Core not initialized")},get_selection_mode:()=>t._core?t._core.get_selection_mode():null,getOptions:()=>{const e=t._core?t._core.options:t.options;return Object.assign({},e,{enable_multi_select:t._enabled})},enable:()=>t.setEnabled(!0),disable:()=>t.setEnabled(!1),setEnabled:e=>t.setEnabled(e),setOptions:e=>t.setOptions(e)};Object.defineProperty(e,"multiSelect",{value:s,configurable:!0,enumerable:!1,writable:!1}),this._mounted=!0,_.info("[multiSelect] API mounted.")}beforePluginRemove(){try{if(this._listener&&this.jm&&Array.isArray(this.jm.event_handles)){const e=this.jm.event_handles.indexOf(this._listener);e>=0&&this.jm.event_handles.splice(e,1)}"function"==typeof this.jm.enable_event_handle&&this.jm.enable_event_handle("mousedown"),this._domClickHandler&&this.jm&&this.jm.view&&this.jm.view.e_nodes&&(this._domClickHandler=null),this._original_select_node&&(this.jm.select_node=this._original_select_node),this._original_select_clear&&(this.jm.select_clear=this._original_select_clear),this.jm&&Object.prototype.hasOwnProperty.call(this.jm,"multiSelect")&&delete this.jm.multiSelect,this._mounted=!1}catch(e){_.error("[multiSelect] remove failed:",e)}}setEnabled(e){const t=!!e;this._enabled!==t&&(this._enabled=t,this.options.enable_multi_select=this._enabled,this._enabled?"function"==typeof this.jm.disable_event_handle&&this.jm.disable_event_handle("mousedown"):"function"==typeof this.jm.enable_event_handle&&this.jm.enable_event_handle("mousedown"))}setOptions(e){const t=Object.assign({},e||{});this.options=Object.assign({},this.options,t),this._core&&this._core.options&&(this._core.options=Object.assign({},this._core.options,t))}beforePluginDestroy(){_.debug("[multiSelect] beforePluginDestroy"),this.beforePluginRemove()}}exports.MultiSelectCore=r,exports.MultiSelectPlugin=h,exports.default=h;
625
9
  //# sourceMappingURL=jsmind.multi-select.js.map