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