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