@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,445 +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
- import t from '@umbraci/jsmind';
9
- if (!t) throw new Error('jsMind is not defined');
10
- const e = t.$,
11
- i =
12
- 'getSelection' in e.w
13
- ? function () {
14
- e.w.getSelection().removeAllRanges();
15
- }
16
- : function () {
17
- e.d.selection.empty();
18
- },
19
- s = {
20
- line_width: 5,
21
- line_color: 'rgba(0,0,0,0.3)',
22
- line_color_invalid: 'rgba(255,51,51,0.6)',
23
- lookup_delay: 200,
24
- lookup_interval: 100,
25
- scrolling_trigger_width: 20,
26
- scrolling_step_length: 10,
27
- shadow_node_class_name: 'jsmind-draggable-shadow-node',
28
- };
29
- class o {
30
- constructor(e, i) {
31
- var o = {};
32
- t.util.json.merge(o, s),
33
- t.util.json.merge(o, i),
34
- (this.version = '0.4.0'),
35
- (this.jm = e),
36
- (this.options = o),
37
- (this.is_svg_engine = 'svg' === e.view.opts.engine),
38
- (this.e_canvas = null),
39
- (this.canvas_ctx = null),
40
- (this.helper_line = null),
41
- (this.shadow = null),
42
- (this.shadow_p_x = 0),
43
- (this.shadow_p_y = 0),
44
- (this.shadow_w = 0),
45
- (this.shadow_h = 0),
46
- (this.active_node = null),
47
- (this.target_node = null),
48
- (this.target_direct = null),
49
- (this.client_w = 0),
50
- (this.client_h = 0),
51
- (this.offset_x = 0),
52
- (this.offset_y = 0),
53
- (this.hlookup_delay = 0),
54
- (this.hlookup_timer = 0),
55
- (this.capture = !1),
56
- (this.moved = !1),
57
- (this.canvas_draggable = e.get_view_draggable()),
58
- (this.view_panel = e.view.e_panel),
59
- (this.view_panel_rect = null);
60
- }
61
- init() {
62
- this.create_canvas(), this.create_shadow(), this.event_bind();
63
- }
64
- resize() {
65
- this.jm.view.e_nodes.appendChild(this.shadow),
66
- this.is_svg_engine
67
- ? (this.e_canvas.setAttribute('width', this.jm.view.size.w),
68
- this.e_canvas.setAttribute('height', this.jm.view.size.h))
69
- : ((this.e_canvas.width = this.jm.view.size.w),
70
- (this.e_canvas.height = this.jm.view.size.h));
71
- }
72
- create_canvas() {
73
- if (this.is_svg_engine) {
74
- var t = this._create_svg_element('svg');
75
- t.setAttribute('class', 'jsmind-draggable-helper'),
76
- t.setAttribute(
77
- 'style',
78
- 'position: absolute; top: 0; left: 0; pointer-events: none;'
79
- ),
80
- this.jm.view.e_panel.appendChild(t),
81
- (this.e_canvas = t);
82
- } else {
83
- var i = e.c('canvas');
84
- this.jm.view.e_panel.appendChild(i);
85
- var s = i.getContext('2d');
86
- (this.e_canvas = i), (this.canvas_ctx = s);
87
- }
88
- }
89
- _create_svg_element(t) {
90
- return e.d.createElementNS('http://www.w3.org/2000/svg', t);
91
- }
92
- create_shadow() {
93
- var t = e.c('jmnode');
94
- (t.style.visibility = 'hidden'),
95
- (t.style.zIndex = '3'),
96
- (t.style.cursor = 'move'),
97
- (t.style.opacity = '0.7'),
98
- (t.className = this.options.shadow_node_class_name),
99
- (this.shadow = t);
100
- }
101
- reset_shadow(t) {
102
- var e = this.shadow.style;
103
- (this.shadow.innerHTML = t.innerHTML),
104
- (e.left = t.style.left),
105
- (e.top = t.style.top),
106
- (e.width = t.style.width),
107
- (e.height = t.style.height),
108
- (e.backgroundImage = t.style.backgroundImage),
109
- (e.backgroundSize = t.style.backgroundSize),
110
- (e.transform = t.style.transform),
111
- (this.shadow_w = this.shadow.clientWidth),
112
- (this.shadow_h = this.shadow.clientHeight);
113
- }
114
- show_shadow() {
115
- this.moved || (this.shadow.style.visibility = 'visible');
116
- }
117
- hide_shadow() {
118
- this.shadow.style.visibility = 'hidden';
119
- }
120
- magnet_shadow(t, e, i) {
121
- this.clear_lines();
122
- var s = i ? this.options.line_color_invalid : this.options.line_color;
123
- this.is_svg_engine
124
- ? this.svg_draw_line(t.x, t.y, e.x, e.y, s)
125
- : ((this.canvas_ctx.lineWidth = this.options.line_width),
126
- (this.canvas_ctx.strokeStyle = s),
127
- (this.canvas_ctx.lineCap = 'round'),
128
- this.canvas_lineto(t.x, t.y, e.x, e.y));
129
- }
130
- clear_lines() {
131
- this.is_svg_engine
132
- ? this.helper_line &&
133
- this.helper_line.parentNode &&
134
- (this.e_canvas.removeChild(this.helper_line), (this.helper_line = null))
135
- : this.canvas_ctx.clearRect(0, 0, this.jm.view.size.w, this.jm.view.size.h);
136
- }
137
- canvas_lineto(t, e, i, s) {
138
- this.canvas_ctx.beginPath(),
139
- this.canvas_ctx.moveTo(t, e),
140
- this.canvas_ctx.lineTo(i, s),
141
- this.canvas_ctx.stroke();
142
- }
143
- svg_draw_line(t, e, i, s, o) {
144
- (this.helper_line = this._create_svg_element('path')),
145
- this.helper_line.setAttribute('stroke', o),
146
- this.helper_line.setAttribute('stroke-width', this.options.line_width),
147
- this.helper_line.setAttribute('fill', 'transparent'),
148
- this.helper_line.setAttribute('stroke-linecap', 'round'),
149
- this._svg_bezier_to(this.helper_line, t, e, i, s),
150
- this.e_canvas.appendChild(this.helper_line);
151
- }
152
- _svg_bezier_to(t, e, i, s, o) {
153
- t.setAttribute(
154
- 'd',
155
- 'M ' +
156
- e +
157
- ' ' +
158
- i +
159
- ' C ' +
160
- (e + (2 * (s - e)) / 3) +
161
- ' ' +
162
- i +
163
- ', ' +
164
- e +
165
- ' ' +
166
- o +
167
- ', ' +
168
- s +
169
- ' ' +
170
- o
171
- );
172
- }
173
- event_bind() {
174
- var t = this,
175
- i = this.jm.view.container;
176
- e.on(i, 'mousedown', function (e) {
177
- 0 === e.button && t.dragstart.call(t, e);
178
- }),
179
- e.on(i, 'mousemove', function (e) {
180
- (0 === e.movementX && 0 === e.movementY) || t.drag.call(t, e);
181
- }),
182
- e.on(i, 'mouseup', function (e) {
183
- t.dragend.call(t, e);
184
- }),
185
- e.on(i, 'touchstart', function (e) {
186
- t.dragstart.call(t, e);
187
- }),
188
- e.on(i, 'touchmove', function (e) {
189
- t.drag.call(t, e);
190
- }),
191
- e.on(i, 'touchend', function (e) {
192
- t.dragend.call(t, e);
193
- });
194
- }
195
- dragstart(t) {
196
- if (this.jm.get_editable() && !this.capture) {
197
- var i = this.jm.view;
198
- if (!i.is_editing()) {
199
- (this.active_node = null), (this.view_draggable = this.jm.get_view_draggable());
200
- var s = this.find_node_element(t.target);
201
- if (s) {
202
- this.view_draggable && this.jm.disable_view_draggable();
203
- var o = i.get_binded_nodeid(s);
204
- if (o) {
205
- var n = this.jm.get_node(o);
206
- if (!n.isroot) {
207
- if (n.data && !1 === n.data.draggable) return;
208
- this.reset_shadow(s),
209
- (this.view_panel_rect = this.view_panel.getBoundingClientRect()),
210
- (this.active_node = n),
211
- (this.offset_x =
212
- (t.clientX || t.touches[0].clientX) / i.zoom_current -
213
- s.offsetLeft),
214
- (this.offset_y =
215
- (t.clientY || t.touches[0].clientY) / i.zoom_current -
216
- s.offsetTop),
217
- (this.client_hw = Math.floor(s.clientWidth / 2)),
218
- (this.client_hh = Math.floor(s.clientHeight / 2)),
219
- 0 != this.hlookup_delay && e.w.clearTimeout(this.hlookup_delay),
220
- 0 != this.hlookup_timer && e.w.clearInterval(this.hlookup_timer);
221
- var h = this;
222
- (this.hlookup_delay = e.w.setTimeout(function () {
223
- (h.hlookup_delay = 0),
224
- (h.hlookup_timer = e.w.setInterval(function () {
225
- h.lookup_target_node.call(h);
226
- }, h.options.lookup_interval));
227
- }, this.options.lookup_delay)),
228
- (h.capture = !0);
229
- }
230
- }
231
- }
232
- }
233
- }
234
- }
235
- drag(t) {
236
- if (this.jm.get_editable() && this.capture) {
237
- t.preventDefault(), this.show_shadow(), (this.moved = !0), i();
238
- var e = this.jm.view,
239
- s = (t.clientX || t.touches[0].clientX) / e.zoom_current - this.offset_x,
240
- o = (t.clientY || t.touches[0].clientY) / e.zoom_current - this.offset_y;
241
- t.clientY - this.view_panel_rect.top < this.options.scrolling_trigger_width &&
242
- this.view_panel.scrollTop > this.options.scrolling_step_length
243
- ? (this.view_panel.scrollBy(0, -this.options.scrolling_step_length),
244
- (this.offset_y += this.options.scrolling_step_length / e.zoom_current))
245
- : this.view_panel_rect.bottom - t.clientY < this.options.scrolling_trigger_width &&
246
- this.view_panel.scrollTop <
247
- this.view_panel.scrollHeight -
248
- this.view_panel_rect.height -
249
- this.options.scrolling_step_length &&
250
- (this.view_panel.scrollBy(0, this.options.scrolling_step_length),
251
- (this.offset_y -= this.options.scrolling_step_length / e.zoom_current)),
252
- t.clientX - this.view_panel_rect.left < this.options.scrolling_trigger_width &&
253
- this.view_panel.scrollLeft > this.options.scrolling_step_length
254
- ? (this.view_panel.scrollBy(-this.options.scrolling_step_length, 0),
255
- (this.offset_x += this.options.scrolling_step_length / e.zoom_current))
256
- : this.view_panel_rect.right - t.clientX <
257
- this.options.scrolling_trigger_width &&
258
- this.view_panel.scrollLeft <
259
- this.view_panel.scrollWidth -
260
- this.view_panel_rect.width -
261
- this.options.scrolling_step_length &&
262
- (this.view_panel.scrollBy(this.options.scrolling_step_length, 0),
263
- (this.offset_x -= this.options.scrolling_step_length / e.zoom_current)),
264
- (this.shadow.style.left = s + 'px'),
265
- (this.shadow.style.top = o + 'px'),
266
- i();
267
- }
268
- }
269
- dragend(t) {
270
- if (this.jm.get_editable()) {
271
- if ((this.view_draggable && this.jm.enable_view_draggable(), this.capture)) {
272
- if (
273
- (0 != this.hlookup_delay &&
274
- (e.w.clearTimeout(this.hlookup_delay),
275
- (this.hlookup_delay = 0),
276
- this.clear_lines()),
277
- 0 != this.hlookup_timer &&
278
- (e.w.clearInterval(this.hlookup_timer),
279
- (this.hlookup_timer = 0),
280
- this.clear_lines()),
281
- this.moved)
282
- ) {
283
- var i = this.active_node,
284
- s = this.target_node,
285
- o = this.target_direct;
286
- this.move_node(i, s, o);
287
- }
288
- this.hide_shadow();
289
- }
290
- (this.view_panel_rect = null), (this.moved = !1), (this.capture = !1);
291
- }
292
- }
293
- find_node_element(t) {
294
- return t === this.jm.view.e_nodes ||
295
- t === this.jm.view.e_panel ||
296
- t === this.jm.view.container
297
- ? null
298
- : 'jmnode' === t.tagName.toLowerCase()
299
- ? t
300
- : this.find_node_element(t.parentNode);
301
- }
302
- lookup_target_node() {
303
- let e = this.shadow.offsetLeft,
304
- i = this.shadow.offsetTop;
305
- if (e === this.shadow_p_x && i === this.shadow_p_y) return;
306
- (this.shadow_p_x = e), (this.shadow_p_y = i);
307
- let s =
308
- this.shadow_p_x + this.shadow_w / 2 >= this.get_root_x()
309
- ? t.direction.right
310
- : t.direction.left,
311
- o = this.lookup_overlapping_node_parent(s) || this.lookup_close_node(s);
312
- if (o) {
313
- let e = this.calc_point_of_node(o, s),
314
- i = t.node.inherited(this.active_node, o);
315
- this.magnet_shadow(e.sp, e.np, i), (this.target_node = o), (this.target_direct = s);
316
- }
317
- }
318
- get_root_x() {
319
- let t = this.jm.get_root(),
320
- e = t.get_location(),
321
- i = t.get_size();
322
- return e.x + i.w / 2;
323
- }
324
- lookup_overlapping_node_parent(t) {
325
- let e = this.shadow.getBoundingClientRect(),
326
- i = e.x + (e.width * (1 - t)) / 2,
327
- s = (this.jm.options.layout.hspace + this.jm.options.layout.pspace) * t,
328
- o = e.height,
329
- n = [
330
- [i, e.y],
331
- [i, e.y + o / 2],
332
- [i, e.y + o],
333
- [i + s / 2, e.y],
334
- [i + s / 2, e.y + o / 2],
335
- [i + s / 2, e.y + o],
336
- [i + s, e.y],
337
- [i + s, e.y + o / 2],
338
- [i + s, e.y + o],
339
- ];
340
- for (const t of n) {
341
- let e = this.lookup_node_parent_by_location(t[0], t[1]);
342
- if (e) return e;
343
- }
344
- }
345
- lookup_node_parent_by_location(t, i) {
346
- return e.d
347
- .elementsFromPoint(t, i)
348
- .filter(
349
- t => 'JMNODE' === t.tagName && t.className !== this.options.shadow_node_class_name
350
- )
351
- .map(t => this.jm.view.get_binded_nodeid(t))
352
- .map(t => t && this.jm.mind.nodes[t])
353
- .map(t => t && t.parent)
354
- .find(t => t);
355
- }
356
- lookup_close_node(t) {
357
- return Object.values(this.jm.mind.nodes)
358
- .filter(e => e.direction == t || e.isroot)
359
- .filter(t => this.jm.layout.is_visible(t))
360
- .filter(e => this.shadow_on_target_side(e, t))
361
- .map(e => ({ node: e, distance: this.shadow_to_node(e, t) }))
362
- .reduce((t, e) => (t.distance < e.distance ? t : e), {
363
- node: this.jm.get_root(),
364
- distance: Number.MAX_VALUE,
365
- }).node;
366
- }
367
- shadow_on_target_side(e, i) {
368
- return (
369
- (i == t.direction.right && this.shadow_to_right_of_node(e) > 0) ||
370
- (i == t.direction.left && this.shadow_to_left_of_node(e) > 0)
371
- );
372
- }
373
- shadow_to_right_of_node(t) {
374
- return this.shadow_p_x - t.get_location().x - t.get_size().w;
375
- }
376
- shadow_to_left_of_node(t) {
377
- return t.get_location().x - this.shadow_p_x - this.shadow_w;
378
- }
379
- shadow_to_base_line_of_node(t) {
380
- return this.shadow_p_y + this.shadow_h / 2 - t.get_location().y - t.get_size().h / 2;
381
- }
382
- shadow_to_node(e, i) {
383
- return (
384
- (i === t.direction.right
385
- ? Math.abs(this.shadow_to_right_of_node(e))
386
- : Math.abs(this.shadow_to_left_of_node(e))) +
387
- Math.abs(this.shadow_to_base_line_of_node(e))
388
- );
389
- }
390
- calc_point_of_node(t, e) {
391
- let i = t.get_size(),
392
- s = t.get_location(),
393
- o = t.isroot ? s.x + i.w / 2 : s.x + (i.w * (1 + e)) / 2 + this.options.line_width * e,
394
- n = s.y + i.h / 2;
395
- return {
396
- sp: {
397
- x: this.shadow_p_x + (this.shadow_w * (1 - e)) / 2 - this.options.line_width * e,
398
- y: this.shadow_p_y + this.shadow_h / 2,
399
- },
400
- np: { x: o, y: n },
401
- };
402
- }
403
- move_node(e, i, s) {
404
- var o = this.shadow.offsetTop;
405
- if (i && e && !t.node.inherited(e, i)) {
406
- if (this.options.validate_drag && 'function' == typeof this.options.validate_drag) {
407
- if (!this.options.validate_drag(e, i))
408
- return (
409
- (this.active_node = null),
410
- (this.target_node = null),
411
- void (this.target_direct = null)
412
- );
413
- }
414
- for (
415
- var n = i.children,
416
- h = n.length,
417
- l = null,
418
- _ = Number.MAX_VALUE,
419
- a = null,
420
- r = '_last_';
421
- h--;
422
-
423
- )
424
- if ((l = n[h]).direction == s && l.id != e.id) {
425
- var d = l.get_location().y - o;
426
- d > 0 && d < _ && ((_ = d), (a = l), (r = '_first_'));
427
- }
428
- a && (r = a.id), this.jm.move_node(e.id, r, i.id, s);
429
- }
430
- (this.active_node = null), (this.target_node = null), (this.target_direct = null);
431
- }
432
- jm_event_handle(e, i) {
433
- e === t.event_type.resize && this.resize();
434
- }
435
- }
436
- const n = new t.plugin('draggable_node', function (t, e) {
437
- var i = new o(t, e);
438
- i.init(),
439
- t.add_event_listener(function (t, e) {
440
- i.jm_event_handle.call(i, t, e);
441
- });
442
- });
443
- t.register_plugin(n);
444
- export { o as DraggableNode, o as default, n as draggable_plugin };
2
+ * @license BSD-3-Clause
3
+ * @copyright 2014-2025 hizzgdev@163.com
4
+ *
5
+ * Project Home:
6
+ * https://github.com/hizzgdev/jsmind/
7
+ */
8
+ import t from"@umbraci/jsmind";"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(t){return this.slice(0,t.length)===t});class e{static instanceName="";static preload=!1;constructor({jm:t,pluginOpt:e}){this.jm=t,this.options=e||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}if(!t)throw new Error("jsMind is not defined");const i=t.$,s="getSelection"in i.w?function(){i.w.getSelection().removeAllRanges()}:function(){i.d.selection.empty()},o={line_width:5,line_color:"rgba(0,0,0,0.3)",line_color_invalid:"rgba(255,51,51,0.6)",lookup_delay:200,lookup_interval:100,scrolling_trigger_width:20,scrolling_step_length:10,shadow_node_class_name:"jsmind-draggable-shadow-node"};class n{constructor(e,i){var s={};t.util.json.merge(s,o),t.util.json.merge(s,i),this.version="0.4.0",this.jm=e,this.options=s,this.is_svg_engine="svg"===e.view.opts.engine,this.e_canvas=null,this.canvas_ctx=null,this.helper_line=null,this.shadow=null,this.shadow_p_x=0,this.shadow_p_y=0,this.shadow_w=0,this.shadow_h=0,this.active_node=null,this.target_node=null,this.target_direct=null,this.client_w=0,this.client_h=0,this.offset_x=0,this.offset_y=0,this.hlookup_delay=0,this.hlookup_timer=0,this.capture=!1,this.moved=!1,this.canvas_draggable=e.get_view_draggable(),this.view_panel=e.view.e_panel,this.view_panel_rect=null}init(){this.create_canvas(),this.create_shadow(),this.event_bind()}resize(){this.jm.view.e_nodes.appendChild(this.shadow),this.is_svg_engine?(this.e_canvas.setAttribute("width",this.jm.view.size.w),this.e_canvas.setAttribute("height",this.jm.view.size.h)):(this.e_canvas.width=this.jm.view.size.w,this.e_canvas.height=this.jm.view.size.h)}create_canvas(){if(this.is_svg_engine){var t=this._create_svg_element("svg");t.setAttribute("class","jsmind-draggable-helper"),t.setAttribute("style","position: absolute; top: 0; left: 0; pointer-events: none;"),this.jm.view.e_panel.appendChild(t),this.e_canvas=t}else{var e=i.c("canvas");this.jm.view.e_panel.appendChild(e);var s=e.getContext("2d");this.e_canvas=e,this.canvas_ctx=s}}_create_svg_element(t){return i.d.createElementNS("http://www.w3.org/2000/svg",t)}create_shadow(){var t=i.c("jmnode");t.style.visibility="hidden",t.style.zIndex="3",t.style.cursor="move",t.style.opacity="0.7",t.className=this.options.shadow_node_class_name,this.shadow=t}reset_shadow(t){var e=this.shadow.style,s=t.style,o=i.w.getComputedStyle(t);this.shadow.innerHTML=t.innerHTML;["left","top","width","height","backgroundImage","backgroundSize","transform"].forEach(t=>{e[t]=s[t]});["whiteSpace","wordBreak","overflowWrap","maxWidth"].forEach(t=>{e[t]=s[t]||o[t]}),this.shadow_w=this.shadow.clientWidth,this.shadow_h=this.shadow.clientHeight}show_shadow(){this.moved||(this.shadow.style.visibility="visible")}hide_shadow(){this.shadow.style.visibility="hidden"}magnet_shadow(t,e,i){this.clear_lines();var s=i?this.options.line_color_invalid:this.options.line_color;this.is_svg_engine?this.svg_draw_line(t.x,t.y,e.x,e.y,s):(this.canvas_ctx.lineWidth=this.options.line_width,this.canvas_ctx.strokeStyle=s,this.canvas_ctx.lineCap="round",this.canvas_lineto(t.x,t.y,e.x,e.y))}clear_lines(){this.is_svg_engine?this.helper_line&&this.helper_line.parentNode&&(this.e_canvas.removeChild(this.helper_line),this.helper_line=null):this.canvas_ctx.clearRect(0,0,this.jm.view.size.w,this.jm.view.size.h)}canvas_lineto(t,e,i,s){this.canvas_ctx.beginPath(),this.canvas_ctx.moveTo(t,e),this.canvas_ctx.lineTo(i,s),this.canvas_ctx.stroke()}svg_draw_line(t,e,i,s,o){this.helper_line=this._create_svg_element("path"),this.helper_line.setAttribute("stroke",o),this.helper_line.setAttribute("stroke-width",this.options.line_width),this.helper_line.setAttribute("fill","transparent"),this.helper_line.setAttribute("stroke-linecap","round"),this._svg_bezier_to(this.helper_line,t,e,i,s),this.e_canvas.appendChild(this.helper_line)}_svg_bezier_to(t,e,i,s,o){t.setAttribute("d","M "+e+" "+i+" C "+(e+2*(s-e)/3)+" "+i+", "+e+" "+o+", "+s+" "+o)}event_bind(){var t=this,e=this.jm.view.container;i.on(e,"mousedown",function(e){0===e.button&&t.dragstart.call(t,e)}),i.on(e,"mousemove",function(e){0===e.movementX&&0===e.movementY||t.drag.call(t,e)}),i.on(e,"mouseup",function(e){t.dragend.call(t,e)}),i.on(e,"touchstart",function(e){t.dragstart.call(t,e)}),i.on(e,"touchmove",function(e){t.drag.call(t,e)}),i.on(e,"touchend",function(e){t.dragend.call(t,e)})}dragstart(t){if(this.jm.get_editable()&&!this.capture){var e=this.jm.view;if(!e.is_editing()){this.active_node=null,this.view_draggable=this.jm.get_view_draggable();var s=this.find_node_element(t.target);if(s){this.view_draggable&&this.jm.disable_view_draggable();var o=e.get_binded_nodeid(s);if(o){var n=this.jm.get_node(o);if(!n.isroot){if(n.data&&!1===n.data.draggable)return;this.reset_shadow(s),this.view_panel_rect=this.view_panel.getBoundingClientRect(),this.active_node=n,this.offset_x=(t.clientX||t.touches[0].clientX)/e.zoom_current-s.offsetLeft,this.offset_y=(t.clientY||t.touches[0].clientY)/e.zoom_current-s.offsetTop,this.client_hw=Math.floor(s.clientWidth/2),this.client_hh=Math.floor(s.clientHeight/2),0!=this.hlookup_delay&&i.w.clearTimeout(this.hlookup_delay),0!=this.hlookup_timer&&i.w.clearInterval(this.hlookup_timer);var h=this;this.hlookup_delay=i.w.setTimeout(function(){h.hlookup_delay=0,h.hlookup_timer=i.w.setInterval(function(){h.lookup_target_node.call(h)},h.options.lookup_interval)},this.options.lookup_delay),h.capture=!0}}}}}}drag(t){if(this.jm.get_editable()&&this.capture){t.preventDefault(),this.show_shadow(),this.moved=!0,s();var e=this.jm.view,i=(t.clientX||t.touches[0].clientX)/e.zoom_current-this.offset_x,o=(t.clientY||t.touches[0].clientY)/e.zoom_current-this.offset_y;t.clientY-this.view_panel_rect.top<this.options.scrolling_trigger_width&&this.view_panel.scrollTop>this.options.scrolling_step_length?(this.view_panel.scrollBy(0,-this.options.scrolling_step_length),this.offset_y+=this.options.scrolling_step_length/e.zoom_current):this.view_panel_rect.bottom-t.clientY<this.options.scrolling_trigger_width&&this.view_panel.scrollTop<this.view_panel.scrollHeight-this.view_panel_rect.height-this.options.scrolling_step_length&&(this.view_panel.scrollBy(0,this.options.scrolling_step_length),this.offset_y-=this.options.scrolling_step_length/e.zoom_current),t.clientX-this.view_panel_rect.left<this.options.scrolling_trigger_width&&this.view_panel.scrollLeft>this.options.scrolling_step_length?(this.view_panel.scrollBy(-this.options.scrolling_step_length,0),this.offset_x+=this.options.scrolling_step_length/e.zoom_current):this.view_panel_rect.right-t.clientX<this.options.scrolling_trigger_width&&this.view_panel.scrollLeft<this.view_panel.scrollWidth-this.view_panel_rect.width-this.options.scrolling_step_length&&(this.view_panel.scrollBy(this.options.scrolling_step_length,0),this.offset_x-=this.options.scrolling_step_length/e.zoom_current),this.shadow.style.left=i+"px",this.shadow.style.top=o+"px",s()}}dragend(t){if(this.jm.get_editable()){if(this.view_draggable&&this.jm.enable_view_draggable(),this.capture){if(0!=this.hlookup_delay&&(i.w.clearTimeout(this.hlookup_delay),this.hlookup_delay=0,this.clear_lines()),0!=this.hlookup_timer&&(i.w.clearInterval(this.hlookup_timer),this.hlookup_timer=0,this.clear_lines()),this.moved){var e=this.active_node,s=this.target_node,o=this.target_direct;this.move_node(e,s,o)}this.hide_shadow()}this.view_panel_rect=null,this.moved=!1,this.capture=!1}}find_node_element(t){return t===this.jm.view.e_nodes||t===this.jm.view.e_panel||t===this.jm.view.container?null:"jmnode"===t.tagName.toLowerCase()?t:this.find_node_element(t.parentNode)}lookup_target_node(){let e=this.shadow.offsetLeft,i=this.shadow.offsetTop;if(e===this.shadow_p_x&&i===this.shadow_p_y)return;this.shadow_p_x=e,this.shadow_p_y=i;let s=this.shadow_p_x+this.shadow_w/2>=this.get_root_x()?t.direction.right:t.direction.left,o=this.lookup_overlapping_node_parent(s)||this.lookup_close_node(s);if(o){let e=this.calc_point_of_node(o,s),i=t.node.inherited(this.active_node,o);this.magnet_shadow(e.sp,e.np,i),this.target_node=o,this.target_direct=s}}get_root_x(){let t=this.jm.get_root(),e=t.get_location(),i=t.get_size();return e.x+i.w/2}lookup_overlapping_node_parent(t){let e=this.shadow.getBoundingClientRect(),i=e.x+e.width*(1-t)/2,s=(this.jm.options.layout.hspace+this.jm.options.layout.pspace)*t,o=e.height,n=[[i,e.y],[i,e.y+o/2],[i,e.y+o],[i+s/2,e.y],[i+s/2,e.y+o/2],[i+s/2,e.y+o],[i+s,e.y],[i+s,e.y+o/2],[i+s,e.y+o]];for(const t of n){let e=this.lookup_node_parent_by_location(t[0],t[1]);if(e)return e}}lookup_node_parent_by_location(t,e){return i.d.elementsFromPoint(t,e).filter(t=>"JMNODE"===t.tagName&&t.className!==this.options.shadow_node_class_name).map(t=>this.jm.view.get_binded_nodeid(t)).map(t=>t&&this.jm.mind.nodes[t]).map(t=>t&&t.parent).find(t=>t)}lookup_close_node(t){return Object.values(this.jm.mind.nodes).filter(e=>e.direction==t||e.isroot).filter(t=>this.jm.layout.is_visible(t)).filter(e=>this.shadow_on_target_side(e,t)).map(e=>({node:e,distance:this.shadow_to_node(e,t)})).reduce((t,e)=>t.distance<e.distance?t:e,{node:this.jm.get_root(),distance:Number.MAX_VALUE}).node}shadow_on_target_side(e,i){return i==t.direction.right&&this.shadow_to_right_of_node(e)>0||i==t.direction.left&&this.shadow_to_left_of_node(e)>0}shadow_to_right_of_node(t){return this.shadow_p_x-t.get_location().x-t.get_size().w}shadow_to_left_of_node(t){return t.get_location().x-this.shadow_p_x-this.shadow_w}shadow_to_base_line_of_node(t){return this.shadow_p_y+this.shadow_h/2-t.get_location().y-t.get_size().h/2}shadow_to_node(e,i){return(i===t.direction.right?Math.abs(this.shadow_to_right_of_node(e)):Math.abs(this.shadow_to_left_of_node(e)))+Math.abs(this.shadow_to_base_line_of_node(e))}calc_point_of_node(t,e){let i=t.get_size(),s=t.get_location(),o=t.isroot?s.x+i.w/2:s.x+i.w*(1+e)/2+this.options.line_width*e,n=s.y+i.h/2;return{sp:{x:this.shadow_p_x+this.shadow_w*(1-e)/2-this.options.line_width*e,y:this.shadow_p_y+this.shadow_h/2},np:{x:o,y:n}}}move_node(e,i,s){var o=this.shadow.offsetTop;if(i&&e&&!t.node.inherited(e,i)){if(this.options.validate_drag&&"function"==typeof this.options.validate_drag){if(!this.options.validate_drag(e,i))return this.active_node=null,this.target_node=null,void(this.target_direct=null)}for(var n=i.children,h=n.length,l=null,a=Number.MAX_VALUE,_=null,r="_last_";h--;)if((l=n[h]).direction==s&&l.id!=e.id){var d=l.get_location().y-o;d>0&&d<a&&(a=d,_=l,r="_first_")}_&&(r=_.id),this.jm.move_node(e.id,r,i.id,s)}this.active_node=null,this.target_node=null,this.target_direct=null}jm_event_handle(e,i){e===t.event_type.resize&&this.resize()}}class h extends e{static instanceName="draggable";static preload=!1;constructor({jm:t,pluginOpt:e}){super({jm:t,pluginOpt:e}),this.draggable=new n(t,e),this.draggable.init(),this._eventHandle=(t,e)=>{this.draggable.jm_event_handle(t,e)},t.add_event_listener(this._eventHandle),t.draggable=this.draggable}beforePluginRemove(){delete this.jm.draggable}}t.usePlugin(h);export{n as DraggableNode,h as DraggableNodePlugin,n as default};
445
9
  //# sourceMappingURL=jsmind.draggable-node.js.map