@umbraci/jsmind 0.10.18 → 1.0.1-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.
- package/README.md +7 -7
- package/dist/jsmind.draggable-node.js +7 -472
- package/dist/jsmind.draggable-node.js.map +1 -1
- package/dist/jsmind.history.js +7 -980
- package/dist/jsmind.history.js.map +1 -1
- package/dist/jsmind.js +7 -2624
- package/dist/jsmind.js.map +1 -1
- package/dist/jsmind.multi-select.js +7 -671
- package/dist/jsmind.multi-select.js.map +1 -1
- package/dist/jsmind.multiline-text.js +7 -156
- package/dist/jsmind.multiline-text.js.map +1 -1
- package/dist/jsmind.screenshot.js +7 -156
- package/dist/jsmind.screenshot.js.map +1 -1
- package/es/jsmind.draggable-node.js +7 -443
- package/es/jsmind.draggable-node.js.map +1 -1
- package/es/jsmind.history.js +7 -944
- package/es/jsmind.history.js.map +1 -1
- package/es/jsmind.js +7 -2570
- package/es/jsmind.js.map +1 -1
- package/es/jsmind.multi-select.js +7 -621
- package/es/jsmind.multi-select.js.map +1 -1
- package/es/jsmind.multiline-text.js +7 -136
- package/es/jsmind.multiline-text.js.map +1 -1
- package/es/jsmind.screenshot.js +7 -136
- package/es/jsmind.screenshot.js.map +1 -1
- package/lib/jsmind.draggable-node.js +7 -450
- package/lib/jsmind.draggable-node.js.map +1 -1
- package/lib/jsmind.history.js +7 -946
- package/lib/jsmind.history.js.map +1 -1
- package/lib/jsmind.js +7 -2571
- package/lib/jsmind.js.map +1 -1
- package/lib/jsmind.multi-select.js +7 -623
- package/lib/jsmind.multi-select.js.map +1 -1
- package/lib/jsmind.multiline-text.js +7 -141
- package/lib/jsmind.multiline-text.js.map +1 -1
- package/lib/jsmind.screenshot.js +7 -145
- package/lib/jsmind.screenshot.js.map +1 -1
- package/package.json +26 -25
- package/types/generated/jsmind.d.ts +21 -24
- package/types/generated/jsmind.mind.d.ts +7 -0
- package/types/generated/{jsmind.enhanced-plugin.d.ts → jsmind.plugin-system.d.ts} +10 -10
- package/types/generated/jsmind.plugin.d.ts +93 -13
- package/types/generated/jsmind.view_provider.d.ts +1 -1
- package/types/generated/plugins/history/history-diff.d.ts +10 -0
- package/types/generated/plugins/history/jsmind.history.d.ts +2 -2
- package/types/generated/plugins/jsmind.draggable-node.d.ts +13 -3
- package/types/generated/plugins/jsmind.multi-select.d.ts +3 -3
- package/types/generated/plugins/jsmind.multiline-text.d.ts +67 -21
- package/types/generated/plugins/jsmind.screenshot.d.ts +12 -3
- package/types/generated/plugins/multi-select/jsmind.multi-select.d.ts +109 -0
- package/types/tsconfig.declaration.json +6 -1
- package/dist/jsmind.copy-paste.js +0 -283
- package/dist/jsmind.copy-paste.js.map +0 -1
- package/es/jsmind.copy-paste.js +0 -260
- package/es/jsmind.copy-paste.js.map +0 -1
- package/types/generated/plugins/jsmind.multiline-text-v2.d.ts +0 -58
|
@@ -1,623 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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=3,s=4,i=1,n=2,_=3,o=4;var l=function(){};let d="undefined"==typeof console?{level:l,log:l,debug:l,info:l,warn:l,error:l}:{level:function(e){d.debug=e>i?l:console.debug;d.info=e>n?l:console.info;d.warn=e>_?l:console.warn;d.error=e>o?l:console.error},log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};class a{static instanceName="";static preload=!1;constructor({jm:e,pluginOpt:t}){this.jm=e,this.options=t||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}const h={enable_multi_select:!1,enable_ctrl_key_node_selection:!0,enable_box_selection:!0,use_left_key_selection_right_key_drag:!1};class r{constructor(e){this.jm=e,this._mode=null,this._last_selected_node=null,this._marked_ids=new Set,this._ensure_state()}_ensure_state(){this.jm.mind||(this.jm.mind={}),this.jm.mind.selected_nodes||(this.jm.mind.selected_nodes=new Set)}_resolve_node(e){return e?"string"==typeof e?this.jm.get_node(e):e:null}_is_visible(e){return!!(e&&this.jm.layout&&this.jm.layout.is_visible(e))}_derive_mode(){this._ensure_state();const e=this.jm.mind.selected_nodes.size;return 0===e?null:1===e?"single":"multi"}_set_focus(e){this.jm.mind.selected=e||null,this.jm.view&&(this.jm.view.selected_node=e||null),this._last_selected_node=e||null}_mark_node(e){if(!e)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._marked_ids.add(e.id))}_unmark_node(e){if(!e)return;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._marked_ids.delete(e.id)}_sync_view_from_state(){this._ensure_state();const e=new Set,t=Array.from(this.jm.mind.selected_nodes);for(let s=0;s<t.length;s++)e.add(t[s].id);const s=[];this._marked_ids.forEach(t=>{e.has(t)||s.push(t)});for(let e=0;e<s.length;e++){const t=this.jm.get_node(s[e]);t?this._unmark_node(t):this._marked_ids.delete(s[e])}for(let e=0;e<t.length;e++)this._mark_node(t[e])}_emit(e,t,i){const n=(t||[]).map(e=>e.id);this.jm.invoke_event_handle(s,{evt:e,data:n,node:i?i.id:null,nodes:n})}get_selected_nodes(){return this._ensure_state(),Array.from(this.jm.mind.selected_nodes).map(e=>e.id)}get_selected_node_set(){return this._ensure_state(),new Set(this.jm.mind.selected_nodes)}is_node_selected(e){const t=this._resolve_node(e);return!!t&&(this._ensure_state(),this.jm.mind.selected_nodes.has(t))}get_selection_mode(){return this._mode}select_node(e){const t=this._resolve_node(e);if(!this._is_visible(t))return;this._ensure_state();const s=Array.from(this.jm.mind.selected_nodes);this.jm.mind.selected_nodes.clear(),this.jm.mind.selected_nodes.add(t),this._set_focus(t),this._mode="single",this._sync_view_from_state();const i=s.filter(e=>e.id!==t.id);i.length&&this._emit("multi_deselect",i,t),this._emit("select_node",[t],t)}select_clear(){if(this._ensure_state(),0===this.jm.mind.selected_nodes.size)return this._set_focus(null),void(this._mode=null);const e=Array.from(this.jm.mind.selected_nodes);this.jm.mind.selected_nodes.clear(),this._set_focus(null),this._mode=null,this._sync_view_from_state(),this._emit("clear_selection",e,null)}toggle_node_selection(e){const t=this._resolve_node(e);if(this._is_visible(t)){if(this._ensure_state(),this.jm.mind.selected_nodes.has(t)){if(this.jm.mind.selected_nodes.delete(t),this.jm.mind.selected===t){const e=Array.from(this.jm.mind.selected_nodes);this._set_focus(e.length?e[e.length-1]:null)}return this._mode=this._derive_mode(),this._sync_view_from_state(),void this._emit("multi_deselect",[t],this.jm.mind.selected||null)}this.jm.mind.selected_nodes.add(t),this._set_focus(t),this._mode=this._derive_mode(),this._sync_view_from_state(),this._emit("multi_select",[t],t)}}set_selection(e,t){this._ensure_state();const s=t||{},i=[],n=new Set;for(let t=0;t<e.length;t++){const s=e[t];s&&this._is_visible(s)&&!n.has(s.id)&&(n.add(s.id),i.push(s))}const _=Array.from(this.jm.mind.selected_nodes);this.jm.mind.selected_nodes.clear();for(let e=0;e<i.length;e++)this.jm.mind.selected_nodes.add(i[e]);const o=s.focusNode||(i.length?i[i.length-1]:null);if(this._set_focus(o),this._mode=this._derive_mode(),this._sync_view_from_state(),!1===s.emit)return;const l=new Set(_.map(e=>e.id)),d=new Set(i.map(e=>e.id)),a=i.filter(e=>!l.has(e.id)),h=_.filter(e=>!d.has(e.id));h.length&&this._emit("multi_deselect",h,o),a.length&&this._emit("multi_select",a,o),!a.length&&!h.length&&o&&s.forceSelectEvent&&this._emit("select_node",[o],o)}prune_removed(e){if(this._ensure_state(),!e||!e.length||0===this.jm.mind.selected_nodes.size)return;const t=new Set(e),s=[];if(this.jm.mind.selected_nodes.forEach(e=>{t.has(e.id)&&s.push(e)}),s.length){for(let e=0;e<s.length;e++)this.jm.mind.selected_nodes.delete(s[e]);if(this.jm.mind.selected&&t.has(this.jm.mind.selected.id)){const e=Array.from(this.jm.mind.selected_nodes);this._set_focus(e.length?e[e.length-1]:null)}this._mode=this._derive_mode(),this._sync_view_from_state(),this._emit("multi_deselect",s,this.jm.mind.selected||null)}}}class c{constructor(e,t,s,i){this.jm=e,this.state=t,this.getOptions=s,this.isEnabled=i,this._dragging=!1,this._active=!1,this._append_mode=!1,this._base_selected=[],this._start_client={x:0,y:0},this._current_client={x:0,y:0},this._overlay=null,this._on_mouse_move=this._on_mouse_move.bind(this),this._on_mouse_up=this._on_mouse_up.bind(this)}is_selecting(){return this._dragging}should_start(e){if(!this.isEnabled())return!1;const t=this.getOptions();return!!t.enable_box_selection&&(t.use_left_key_selection_right_key_drag?1===e.which:(e.ctrlKey||e.metaKey)&&3===e.which)}start(e){this._dragging||(this._dragging=!0,this._active=!1,this._append_mode=!(!e.ctrlKey&&!e.metaKey),this._base_selected=Array.from(this.state.get_selected_node_set()),this._start_client={x:e.clientX,y:e.clientY},this._current_client={x:e.clientX,y:e.clientY},this._append_mode||this.state.set_selection([],{emit:!1}),this._ensure_overlay(),this._update_overlay(),document.addEventListener("mousemove",this._on_mouse_move,!0),document.addEventListener("mouseup",this._on_mouse_up,!0))}_ensure_overlay(){if(this._overlay)return;const e=document.createElement("div");e.style.position="fixed",e.style.pointerEvents="none",e.style.border="1px solid #0984e3",e.style.background="rgba(9,132,227,0.2)",e.style.zIndex="2147483000",e.style.display="none",document.body.appendChild(e),this._overlay=e}_update_overlay(){if(!this._overlay)return;const e=Math.min(this._start_client.x,this._current_client.x),t=Math.min(this._start_client.y,this._current_client.y),s=Math.abs(this._start_client.x-this._current_client.x),i=Math.abs(this._start_client.y-this._current_client.y);this._overlay.style.left=e+"px",this._overlay.style.top=t+"px",this._overlay.style.width=s+"px",this._overlay.style.height=i+"px",this._overlay.style.display=this._active?"block":"none"}_collect_nodes_in_rect(){if(!this.jm.mind||!this.jm.mind.nodes)return[];const e=Math.min(this._start_client.x,this._current_client.x),t=Math.min(this._start_client.y,this._current_client.y),s=Math.max(this._start_client.x,this._current_client.x),i=Math.max(this._start_client.y,this._current_client.y),n=Object.values(this.jm.mind.nodes),_=[];for(let o=0;o<n.length;o++){const l=n[o];if(!this.jm.layout.is_visible(l))continue;const d=l._data&&l._data.view&&l._data.view.element;if(!d)continue;const a=d.getBoundingClientRect();!(a.right<e||a.left>s||a.bottom<t||a.top>i)&&_.push(l)}return _}_on_mouse_move(e){if(!this._dragging)return;this._current_client={x:e.clientX,y:e.clientY};const t=Math.abs(this._start_client.x-this._current_client.x),s=Math.abs(this._start_client.y-this._current_client.y);if(this._active=t>4||s>4,!this._active)return void this._update_overlay();const i=this._collect_nodes_in_rect(),n=this._append_mode?this._base_selected.concat(i.filter(e=>!this._base_selected.find(t=>t.id===e.id))):i;this.state.set_selection(n,{focusNode:n.length?n[n.length-1]:null,emit:!1}),this._update_overlay(),e.preventDefault(),e.stopPropagation()}_on_mouse_up(e){if(!this._dragging)return;const t=this._active;if(this._dragging=!1,this._active=!1,this._base_selected=[],this._overlay&&(this._overlay.style.display="none"),document.removeEventListener("mousemove",this._on_mouse_move,!0),document.removeEventListener("mouseup",this._on_mouse_up,!0),t){const t=Array.from(this.state.get_selected_node_set());this.state.set_selection(t,{focusNode:t.length?t[t.length-1]:null,emit:!0}),e.preventDefault(),e.stopPropagation()}}destroy(){this._dragging=!1,document.removeEventListener("mousemove",this._on_mouse_move,!0),document.removeEventListener("mouseup",this._on_mouse_up,!0),this._overlay&&this._overlay.parentNode&&this._overlay.parentNode.removeChild(this._overlay),this._overlay=null}}class m{constructor(e,t,s,i){this.jm=e,this.state=t,this.getOptions=s,this.isEnabled=i,this.selectBox=new c(e,t,s,i),this._on_nodes_mousedown=this._on_nodes_mousedown.bind(this),this._on_panel_contextmenu=this._on_panel_contextmenu.bind(this)}bind(){this.jm.view&&this.jm.view.e_nodes&&this.jm.view.e_panel?(this.jm.view.e_nodes.addEventListener("mousedown",this._on_nodes_mousedown,!0),this.jm.view.e_panel.addEventListener("contextmenu",this._on_panel_contextmenu,!0)):d.warn("[multiSelect] view is not ready, interaction skipped")}_on_panel_contextmenu(e){this.isEnabled()&&this.selectBox.is_selecting()&&(e.preventDefault(),e.stopPropagation())}_on_nodes_mousedown(e){if(!this.isEnabled())return;const t=this.getOptions(),s=e.target||e.currentTarget,i=this.jm.view.get_binded_nodeid(s);return i&&this.jm.view.is_node(s)?(t.enable_ctrl_key_node_selection&&(e.ctrlKey||e.metaKey)?this.state.toggle_node_selection(i):this.state.select_node(i),e.preventDefault(),e.stopPropagation(),void(e.stopImmediatePropagation&&e.stopImmediatePropagation())):!i&&this.selectBox.should_start(e)?(this.selectBox.start(e),e.preventDefault(),e.stopPropagation(),void(e.stopImmediatePropagation&&e.stopImmediatePropagation())):void(i||e.ctrlKey||e.metaKey||e.shiftKey||(this.state.select_clear(),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation()))}destroy(){this.jm.view&&this.jm.view.e_nodes&&this.jm.view.e_nodes.removeEventListener("mousedown",this._on_nodes_mousedown,!0),this.jm.view&&this.jm.view.e_panel&&this.jm.view.e_panel.removeEventListener("contextmenu",this._on_panel_contextmenu,!0),this.selectBox.destroy()}}class u extends a{static instanceName="multiSelectPlugin";static preload=!1;constructor({jm:s,pluginOpt:i}){super({jm:s,pluginOpt:i}),this.options=Object.assign({},h,i||{}),this._enabled=!!this.options.enable_multi_select,this._state=new r(s),this._interaction=new m(s,this._state,()=>this.options,()=>this._enabled),this._listener=(s,i)=>{this._enabled&&(s!==e?s===t&&i&&"remove_node"===i.evt&&this._state.prune_removed(i.data||[]):this._state.select_clear())},this._mountAPI(),this.jm.add_event_listener(this._listener),this._interaction.bind(),this._enabled&&"function"==typeof this.jm.disable_event_handle&&this.jm.disable_event_handle("mousedown")}_mountAPI(){const e=this,t={get_selected_nodes:()=>e._state.get_selected_nodes(),is_node_selected:t=>e._state.is_node_selected(t),select_node:t=>e._state.select_node(t),select_clear:()=>e._state.select_clear(),toggle_node_selection:t=>e._state.toggle_node_selection(t),get_selection_mode:()=>e._state.get_selection_mode(),getOptions:()=>Object.assign({},e.options,{enable_multi_select:e._enabled}),enable:()=>e.setEnabled(!0),disable:()=>e.setEnabled(!1),setEnabled:t=>e.setEnabled(t),setOptions:t=>e.setOptions(t)};Object.defineProperty(this.jm,"multiSelect",{value:t,configurable:!0,enumerable:!1,writable:!1})}setEnabled(e){this._enabled=!!e,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){this.options=Object.assign({},this.options,e||{})}beforePluginRemove(){if("function"==typeof this.jm.enable_event_handle&&this.jm.enable_event_handle("mousedown"),this._enabled=!1,this._interaction&&this._interaction.destroy(),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)}this.jm&&Object.prototype.hasOwnProperty.call(this.jm,"multiSelect")&&delete this.jm.multiSelect}beforePluginDestroy(){this.beforePluginRemove()}}const v=r;export{v as MultiSelectCore,m as MultiSelectInteraction,u as MultiSelectPlugin,r as MultiSelectState,c as SelectBox,u as default};
|
|
623
9
|
//# sourceMappingURL=jsmind.multi-select.js.map
|