@umbraci/jsmind 0.10.15 → 0.10.18

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