@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,158 @@
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,require("@umbraci/jsmind")):"function"==typeof define&&define.amd?define(["exports","@umbraci/jsmind"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jsMindMultilineText={},e.jsMind)}(this,function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=n(t);if(!i.default)throw new Error("jsMind is not defined");const o=i.default.$,d={text_width:200,line_height:"1.5"};function l(e={}){const t=Object.assign({},d,e);return function(e,n,i){return!(!i.topic||!i.topic.includes("\n"))&&(n.style.whiteSpace="pre-wrap",n.style.wordBreak="break-word",n.style.maxWidth=t.text_width+"px",n.textContent=i.topic,!0)}}function r(e,t){console.log("[Multiline Plugin] Initializing...",t);const n=Object.assign({},d,t),l=e.view;let r=null,a=null;function s(){if(!r||!a)return;const e=r._data.view.element;a.parentNode&&a.parentNode.removeChild(a),e.style.zIndex="auto",r=null,l.editing_node=null,a=null}l.opts.custom_node_render&&(l.render_node=l._custom_node_render.bind(l),console.log("[Multiline Plugin] Re-bound view.render_node")),e.mind&&e.mind.root&&(!function(e){const t=e.view,n=e.mind;if(!n||!n.root)return;const i=[];for(const e in n.nodes){const t=n.nodes[e];t._data&&t._data.view&&t._data.view.element&&i.push(t)}for(const e of i){const n=e._data.view.element;t.render_node(n,e)}for(const t of i)if(e.layout.is_visible(t)){const e=t._data.view.element;t._data.view.width=e.clientWidth,t._data.view.height=e.clientHeight}e.layout.layout(),e.view.show(!1)}(e),console.log("[Multiline Plugin] Re-rendered all nodes")),l.edit_node_begin=function(e){if(console.log("[Multiline Plugin] edit_node_begin called",e),!e.topic)return;r&&l.edit_node_end(),r=e,l.editing_node=e;const t=o.c("div");t.contentEditable="plaintext-only",t.className="jsmind-multiline-editor",t.textContent=e.topic,a=t;const i=e._data.view.element;Object.assign(t.style,{width:"auto",minHeight:i.clientHeight+"px",lineHeight:n.line_height,border:"none",outline:"none",whiteSpace:"pre-wrap",wordBreak:"break-word",boxSizing:"border-box",overflow:"hidden"});const d=()=>{t.style.height="auto",t.style.height=t.scrollHeight+"px"};o.on(t,"input",d),setTimeout(d,0),o.on(t,"keydown",e=>{"Enter"!==e.key||e.shiftKey?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),function(){if(!r||!a)return;const e=r;s(),l.render_node(e._data.view.element,e),l.e_panel.focus()}()):"Tab"===e.key&&(e.preventDefault(),e.stopPropagation(),l.edit_node_end()):(e.preventDefault(),e.stopPropagation(),l.edit_node_end())}),o.on(t,"blur",()=>{setTimeout(()=>{r&&l.edit_node_end()},100)}),i.innerHTML="",i.appendChild(t),i.style.zIndex=5,t.focus();const u=o.d.createRange();u.selectNodeContents(t);const c=o.w.getSelection();c.removeAllRanges(),c.addRange(u)},l.edit_node_end=function(){if(!r||!a)return;const t=r,n=(a.textContent||"").trim().replace(/\r\n/g,"\n").replace(/\r/g,"\n").replace(/\n{3,}/g,"\n\n");s(),i.default.util.text.is_empty(n)||t.topic===n?l.render_node(t._data.view.element,t):e.update_node(t.id,n),l.e_panel.focus()}}i.default.register_plugin(new i.default.plugin("multiline_text",r));var a={name:"multiline_text",init:r,createMultilineRender:l};e.createMultilineRender=l,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, require('@umbraci/jsmind'))
11
+ : 'function' == typeof define && define.amd
12
+ ? define(['exports', '@umbraci/jsmind'], t)
13
+ : t(
14
+ ((e = 'undefined' != typeof globalThis ? globalThis : e || self).jsMindMultilineText =
15
+ {}),
16
+ e.jsMind
17
+ );
18
+ })(this, function (e, t) {
19
+ 'use strict';
20
+ function n(e) {
21
+ return e && 'object' == typeof e && 'default' in e ? e : { default: e };
22
+ }
23
+ var i = n(t);
24
+ if (!i.default) throw new Error('jsMind is not defined');
25
+ const o = i.default.$,
26
+ d = { text_width: 200, line_height: '1.5' };
27
+ function l(e = {}) {
28
+ const t = Object.assign({}, d, e);
29
+ return function (e, n, i) {
30
+ return (
31
+ !(!i.topic || !i.topic.includes('\n')) &&
32
+ ((n.style.whiteSpace = 'pre-wrap'),
33
+ (n.style.wordBreak = 'break-word'),
34
+ (n.style.maxWidth = t.text_width + 'px'),
35
+ (n.textContent = i.topic),
36
+ !0)
37
+ );
38
+ };
39
+ }
40
+ function r(e, t) {
41
+ console.log('[Multiline Plugin] Initializing...', t);
42
+ const n = Object.assign({}, d, t),
43
+ l = e.view;
44
+ let r = null,
45
+ a = null;
46
+ function s() {
47
+ if (!r || !a) return;
48
+ const e = r._data.view.element;
49
+ a.parentNode && a.parentNode.removeChild(a),
50
+ (e.style.zIndex = 'auto'),
51
+ (r = null),
52
+ (l.editing_node = null),
53
+ (a = null);
54
+ }
55
+ l.opts.custom_node_render &&
56
+ ((l.render_node = l._custom_node_render.bind(l)),
57
+ console.log('[Multiline Plugin] Re-bound view.render_node')),
58
+ e.mind &&
59
+ e.mind.root &&
60
+ (!(function (e) {
61
+ const t = e.view,
62
+ n = e.mind;
63
+ if (!n || !n.root) return;
64
+ const i = [];
65
+ for (const e in n.nodes) {
66
+ const t = n.nodes[e];
67
+ t._data && t._data.view && t._data.view.element && i.push(t);
68
+ }
69
+ for (const e of i) {
70
+ const n = e._data.view.element;
71
+ t.render_node(n, e);
72
+ }
73
+ for (const t of i)
74
+ if (e.layout.is_visible(t)) {
75
+ const e = t._data.view.element;
76
+ (t._data.view.width = e.clientWidth),
77
+ (t._data.view.height = e.clientHeight);
78
+ }
79
+ e.layout.layout(), e.view.show(!1);
80
+ })(e),
81
+ console.log('[Multiline Plugin] Re-rendered all nodes')),
82
+ (l.edit_node_begin = function (e) {
83
+ if ((console.log('[Multiline Plugin] edit_node_begin called', e), !e.topic)) return;
84
+ r && l.edit_node_end(), (r = e), (l.editing_node = e);
85
+ const t = o.c('div');
86
+ (t.contentEditable = 'plaintext-only'),
87
+ (t.className = 'jsmind-multiline-editor'),
88
+ (t.textContent = e.topic),
89
+ (a = t);
90
+ const i = e._data.view.element;
91
+ Object.assign(t.style, {
92
+ width: 'auto',
93
+ minHeight: i.clientHeight + 'px',
94
+ lineHeight: n.line_height,
95
+ border: 'none',
96
+ outline: 'none',
97
+ whiteSpace: 'pre-wrap',
98
+ wordBreak: 'break-word',
99
+ boxSizing: 'border-box',
100
+ overflow: 'hidden',
101
+ });
102
+ const d = () => {
103
+ (t.style.height = 'auto'), (t.style.height = t.scrollHeight + 'px');
104
+ };
105
+ o.on(t, 'input', d),
106
+ setTimeout(d, 0),
107
+ o.on(t, 'keydown', e => {
108
+ 'Enter' !== e.key || e.shiftKey
109
+ ? 'Escape' === e.key
110
+ ? (e.preventDefault(),
111
+ e.stopPropagation(),
112
+ (function () {
113
+ if (!r || !a) return;
114
+ const e = r;
115
+ s(),
116
+ l.render_node(e._data.view.element, e),
117
+ l.e_panel.focus();
118
+ })())
119
+ : 'Tab' === e.key &&
120
+ (e.preventDefault(), e.stopPropagation(), l.edit_node_end())
121
+ : (e.preventDefault(), e.stopPropagation(), l.edit_node_end());
122
+ }),
123
+ o.on(t, 'blur', () => {
124
+ setTimeout(() => {
125
+ r && l.edit_node_end();
126
+ }, 100);
127
+ }),
128
+ (i.innerHTML = ''),
129
+ i.appendChild(t),
130
+ (i.style.zIndex = 5),
131
+ t.focus();
132
+ const u = o.d.createRange();
133
+ u.selectNodeContents(t);
134
+ const c = o.w.getSelection();
135
+ c.removeAllRanges(), c.addRange(u);
136
+ }),
137
+ (l.edit_node_end = function () {
138
+ if (!r || !a) return;
139
+ const t = r,
140
+ n = (a.textContent || '')
141
+ .trim()
142
+ .replace(/\r\n/g, '\n')
143
+ .replace(/\r/g, '\n')
144
+ .replace(/\n{3,}/g, '\n\n');
145
+ s(),
146
+ i.default.util.text.is_empty(n) || t.topic === n
147
+ ? l.render_node(t._data.view.element, t)
148
+ : e.update_node(t.id, n),
149
+ l.e_panel.focus();
150
+ });
151
+ }
152
+ i.default.register_plugin(new i.default.plugin('multiline_text', r));
153
+ var a = { name: 'multiline_text', init: r, createMultilineRender: l };
154
+ (e.createMultilineRender = l),
155
+ (e.default = a),
156
+ Object.defineProperty(e, '__esModule', { value: !0 });
157
+ });
9
158
  //# sourceMappingURL=jsmind.multiline-text.js.map
@@ -1,9 +1,158 @@
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,require("@umbraci/jsmind"),require("dom-to-image")):"function"==typeof define&&define.amd?define(["exports","@umbraci/jsmind","dom-to-image"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jsMindScreenshot={},e.jsMind,e.domtoimage)}(this,function(e,t,i){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(t),r=n(i);if(!o.default)throw new Error("jsMind is not defined");if(!r.default)throw new Error("dom-to-image is required");const s=o.default.$,a={filename:null,watermark:{left:s.w.location,right:"https://github.com/UmbraCi/jsmind"},background:"transparent"};class d{constructor(e,t){var i={};o.default.util.json.merge(i,a),o.default.util.json.merge(i,t),this.version="0.2.0",this.jm=e,this.options=i,this.dpr=e.view.device_pixel_ratio}shoot(){let e=this.create_canvas(),t=e.getContext("2d");t.scale(this.dpr,this.dpr),Promise.resolve(t).then(()=>this.draw_background(t)).then(()=>this.draw_lines(t)).then(()=>this.draw_nodes(t)).then(()=>this.draw_watermark(e,t)).then(()=>this.download(e)).then(()=>this.clear(e))}create_canvas(){let e=s.c("canvas");const t=this.jm.view.size.w,i=this.jm.view.size.h;return e.width=t*this.dpr,e.height=i*this.dpr,e.style.width=t+"px",e.style.height=i+"px",e.style.visibility="hidden",this.jm.view.e_panel.appendChild(e),e}clear(e){e.parentNode.removeChild(e)}draw_background(e){return new Promise(function(t,i){const n=this.options.background;n&&"transparent"!==n&&(e.fillStyle=this.options.background,e.fillRect(0,0,this.jm.view.size.w,this.jm.view.size.h)),t(e)}.bind(this))}draw_lines(e){return new Promise(function(t,i){this.jm.view.graph.copy_to(e,function(){t(e)})}.bind(this))}draw_nodes(e){return r.default.toSvg(this.jm.view.e_nodes,{style:{zoom:1}}).then(this.load_image).then(function(t){return e.drawImage(t,0,0),e})}draw_watermark(e,t){return t.textBaseline="bottom",t.fillStyle="#000",t.font="11px Verdana,Arial,Helvetica,sans-serif",this.options.watermark.left&&(t.textAlign="left",t.fillText(this.options.watermark.left,5.5,e.height-2.5)),this.options.watermark.right&&(t.textAlign="right",t.fillText(this.options.watermark.right,e.width-5.5,e.height-2.5)),t}load_image(e){return new Promise(function(t,i){let n=new Image;n.onload=function(){t(n)},n.onerror=i,n.src=e})}download(e){var t=(this.options.filename||this.jm.mind.name)+".png";if(navigator.msSaveBlob&&e.msToBlob){var i=e.msToBlob();navigator.msSaveBlob(i,t)}else{var n=e.toDataURL(),o=s.c("a");if("download"in o){o.style.visibility="hidden",o.href=n,o.download=t,s.d.body.appendChild(o);var r=s.d.createEvent("MouseEvents");r.initEvent("click",!0,!0),o.dispatchEvent(r),s.d.body.removeChild(o)}else location.href=n}}}const l=new o.default.plugin("screenshot",function(e,t){var i=new d(e,t);e.screenshot=i,e.shoot=function(){i.shoot()}});o.default.register_plugin(l),e.JmScreenshot=d,e.default=d,e.screenshot_plugin=l,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, require('@umbraci/jsmind'), require('dom-to-image'))
11
+ : 'function' == typeof define && define.amd
12
+ ? define(['exports', '@umbraci/jsmind', 'dom-to-image'], t)
13
+ : t(
14
+ ((e = 'undefined' != typeof globalThis ? globalThis : e || self).jsMindScreenshot =
15
+ {}),
16
+ e.jsMind,
17
+ e.domtoimage
18
+ );
19
+ })(this, function (e, t, i) {
20
+ 'use strict';
21
+ function n(e) {
22
+ return e && 'object' == typeof e && 'default' in e ? e : { default: e };
23
+ }
24
+ var o = n(t),
25
+ r = n(i);
26
+ if (!o.default) throw new Error('jsMind is not defined');
27
+ if (!r.default) throw new Error('dom-to-image is required');
28
+ const s = o.default.$,
29
+ a = {
30
+ filename: null,
31
+ watermark: { left: s.w.location, right: 'https://github.com/UmbraCi/jsmind' },
32
+ background: 'transparent',
33
+ };
34
+ class d {
35
+ constructor(e, t) {
36
+ var i = {};
37
+ o.default.util.json.merge(i, a),
38
+ o.default.util.json.merge(i, t),
39
+ (this.version = '0.2.0'),
40
+ (this.jm = e),
41
+ (this.options = i),
42
+ (this.dpr = e.view.device_pixel_ratio);
43
+ }
44
+ shoot() {
45
+ let e = this.create_canvas(),
46
+ t = e.getContext('2d');
47
+ t.scale(this.dpr, this.dpr),
48
+ Promise.resolve(t)
49
+ .then(() => this.draw_background(t))
50
+ .then(() => this.draw_lines(t))
51
+ .then(() => this.draw_nodes(t))
52
+ .then(() => this.draw_watermark(e, t))
53
+ .then(() => this.download(e))
54
+ .then(() => this.clear(e));
55
+ }
56
+ create_canvas() {
57
+ let e = s.c('canvas');
58
+ const t = this.jm.view.size.w,
59
+ i = this.jm.view.size.h;
60
+ return (
61
+ (e.width = t * this.dpr),
62
+ (e.height = i * this.dpr),
63
+ (e.style.width = t + 'px'),
64
+ (e.style.height = i + 'px'),
65
+ (e.style.visibility = 'hidden'),
66
+ this.jm.view.e_panel.appendChild(e),
67
+ e
68
+ );
69
+ }
70
+ clear(e) {
71
+ e.parentNode.removeChild(e);
72
+ }
73
+ draw_background(e) {
74
+ return new Promise(
75
+ function (t, i) {
76
+ const n = this.options.background;
77
+ n &&
78
+ 'transparent' !== n &&
79
+ ((e.fillStyle = this.options.background),
80
+ e.fillRect(0, 0, this.jm.view.size.w, this.jm.view.size.h)),
81
+ t(e);
82
+ }.bind(this)
83
+ );
84
+ }
85
+ draw_lines(e) {
86
+ return new Promise(
87
+ function (t, i) {
88
+ this.jm.view.graph.copy_to(e, function () {
89
+ t(e);
90
+ });
91
+ }.bind(this)
92
+ );
93
+ }
94
+ draw_nodes(e) {
95
+ return r.default
96
+ .toSvg(this.jm.view.e_nodes, { style: { zoom: 1 } })
97
+ .then(this.load_image)
98
+ .then(function (t) {
99
+ return e.drawImage(t, 0, 0), e;
100
+ });
101
+ }
102
+ draw_watermark(e, t) {
103
+ return (
104
+ (t.textBaseline = 'bottom'),
105
+ (t.fillStyle = '#000'),
106
+ (t.font = '11px Verdana,Arial,Helvetica,sans-serif'),
107
+ this.options.watermark.left &&
108
+ ((t.textAlign = 'left'),
109
+ t.fillText(this.options.watermark.left, 5.5, e.height - 2.5)),
110
+ this.options.watermark.right &&
111
+ ((t.textAlign = 'right'),
112
+ t.fillText(this.options.watermark.right, e.width - 5.5, e.height - 2.5)),
113
+ t
114
+ );
115
+ }
116
+ load_image(e) {
117
+ return new Promise(function (t, i) {
118
+ let n = new Image();
119
+ (n.onload = function () {
120
+ t(n);
121
+ }),
122
+ (n.onerror = i),
123
+ (n.src = e);
124
+ });
125
+ }
126
+ download(e) {
127
+ var t = (this.options.filename || this.jm.mind.name) + '.png';
128
+ if (navigator.msSaveBlob && e.msToBlob) {
129
+ var i = e.msToBlob();
130
+ navigator.msSaveBlob(i, t);
131
+ } else {
132
+ var n = e.toDataURL(),
133
+ o = s.c('a');
134
+ if ('download' in o) {
135
+ (o.style.visibility = 'hidden'),
136
+ (o.href = n),
137
+ (o.download = t),
138
+ s.d.body.appendChild(o);
139
+ var r = s.d.createEvent('MouseEvents');
140
+ r.initEvent('click', !0, !0), o.dispatchEvent(r), s.d.body.removeChild(o);
141
+ } else location.href = n;
142
+ }
143
+ }
144
+ }
145
+ const l = new o.default.plugin('screenshot', function (e, t) {
146
+ var i = new d(e, t);
147
+ (e.screenshot = i),
148
+ (e.shoot = function () {
149
+ i.shoot();
150
+ });
151
+ });
152
+ o.default.register_plugin(l),
153
+ (e.JmScreenshot = d),
154
+ (e.default = d),
155
+ (e.screenshot_plugin = l),
156
+ Object.defineProperty(e, '__esModule', { value: !0 });
157
+ });
9
158
  //# sourceMappingURL=jsmind.screenshot.js.map
@@ -1,9 +1,260 @@
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 e from"@umbraci/jsmind";const t=new class{constructor(e){this.w=e,this.d=e.document,this.g=function(e){return this.d.getElementById(e)},this.c=function(e){return this.d.createElement(e)},this.t=function(e,t){e.hasChildNodes()?e.firstChild.nodeValue=t:e.appendChild(this.d.createTextNode(t))},this.h=function(e,t){t instanceof HTMLElement?(e.innerHTML="",e.appendChild(t)):e.innerHTML=t},this.i=function(e){return!!e&&"object"==typeof e&&1===e.nodeType&&"object"==typeof e.style&&"object"==typeof e.ownerDocument},this.on=function(e,t,i){e.addEventListener?e.addEventListener(t,i,!1):e.attachEvent("on"+t,i)}}}(window),i={file:{read:function(e,t){var i=new FileReader;i.onload=function(){"function"==typeof t&&t(this.result,e.name)},i.readAsText(e)},save:function(e,i,n){var o;if("function"==typeof t.w.Blob)o=new Blob([e],{type:i});else{var a=new(t.w.BlobBuilder||t.w.MozBlobBuilder||t.w.WebKitBlobBuilder||t.w.MSBlobBuilder);a.append(e),o=a.getBlob(i)}if(navigator.msSaveBlob)navigator.msSaveBlob(o,n);else{var r=(t.w.URL||t.w.webkitURL).createObjectURL(o),s=t.c("a");if("download"in s){s.style.visibility="hidden",s.href=r,s.download=n,t.d.body.appendChild(s);var d=t.d.createEvent("MouseEvents");d.initEvent("click",!0,!0),s.dispatchEvent(d),t.d.body.removeChild(s)}else location.href=r}}},json:{json2string:function(e){return JSON.stringify(e)},string2json:function(e){return JSON.parse(e)},merge:function(e,t){for(var n in t)n in e?"object"!=typeof e[n]||"[object object]"!=Object.prototype.toString.call(e[n]).toLowerCase()||e[n].length?e[n]=t[n]:i.json.merge(e[n],t[n]):e[n]=t[n];return e}},uuid:{newid:function(){return((new Date).getTime().toString(16)+Math.random().toString(16).substring(2)).substring(2,18)}},text:{is_empty:function(e){return!e||0==e.replace(/\s*/,"").length}}};class n{constructor(e,t={}){this.jsMind=e,this.options={enabled:!0,shortcuts:{copy:"meta+c",paste:"meta+v",cut:"meta+x"},...t},this.clipboardData=null,this.logger={info:e=>console.info("[CopyPaste]",e),warn:e=>console.warn("[CopyPaste]",e),error:e=>console.error("[CopyPaste]",e),debug:e=>console.debug("[CopyPaste]",e)},this.init()}init(){return this.logger.info("CopyPaste plugin initialized"),!0}handleCopy(e){if(!this.options.enabled)return;const t=this.jsMind.get_selected_node();if(t)try{e.preventDefault(),this.clipboardData={id:t.id,topic:t.topic,data:t.data||{},direction:t.direction,expanded:t.expanded,children:this.copyChildren(t)},this.logger.info("Node copied:",t.topic),this.showMessage("节点已复制")}catch(e){this.logger.error("Copy failed:",e),this.showMessage("复制失败","error")}else this.logger.warn("No node selected for copying")}handlePaste(e){if(!this.options.enabled)return;if(!this.clipboardData)return this.logger.warn("No data in clipboard"),void this.showMessage("剪贴板为空,请先复制节点","warning");const t=this.jsMind.get_selected_node();if(!t)return this.logger.warn("No target node selected for pasting"),void this.showMessage("请选择目标节点","warning");try{e.preventDefault();const i=this.prepareBatchData(this.clipboardData),n=this.jsMind.add_nodes(t,[i]);n&&n.length>0&&(this.logger.info("Nodes pasted successfully:",this.clipboardData.topic),this.showMessage("粘贴成功"))}catch(e){this.logger.error("Paste failed:",e),this.showMessage("粘贴失败","error")}}handleCut(e){if(!this.options.enabled)return;const t=this.jsMind.get_selected_node();if(t){if(t.isroot)return this.logger.warn("Cannot cut root node"),void this.showMessage("不能剪切根节点","warning");try{e.preventDefault(),this.clipboardData={id:t.id,topic:t.topic,data:t.data||{},direction:t.direction,expanded:t.expanded,children:this.copyChildren(t)};this.jsMind.remove_node(t)&&(this.logger.info("Node cut:",t.topic),this.showMessage("节点已剪切"))}catch(e){this.logger.error("Cut failed:",e),this.showMessage("剪切失败","error")}}else this.logger.warn("No node selected for cutting")}copyChildren(e){return e.children&&0!==e.children.length?e.children.map(e=>({id:e.id,topic:e.topic,data:e.data||{},direction:e.direction,expanded:e.expanded,children:this.copyChildren(e)})):[]}prepareBatchData(e){return{id:i.uuid.newid(),topic:e.topic,data:e.data||{},children:e.children&&e.children.length>0?e.children.map(e=>this.prepareBatchData(e)):void 0}}pasteChildren(e,t){if(!t||0===t.length)return[];const i=t.map(e=>this.prepareBatchData(e));return this.jsMind.add_nodes(e,i)}showMessage(e,t="info"){console.log(`[CopyPaste ${t.toUpperCase()}]: ${e}`)}clear(){this.clipboardData=null,this.logger.info("Clipboard cleared")}getStatus(){return{hasData:!!this.clipboardData,data:this.clipboardData}}}const o=new e.plugin("copy-paste",function(e,t){var i=t||{};i.shortcuts=i.shortcuts||{copy:"meta+c",paste:"meta+v",cut:"meta+x"};var o=new n(e,i);e.view&&e.view.e_panel&&e.view.e_panel.addEventListener("keydown",function(e){!e.metaKey&&!e.ctrlKey||"c"!==e.key||e.shiftKey||e.altKey?!e.metaKey&&!e.ctrlKey||"v"!==e.key||e.shiftKey||e.altKey?!e.metaKey&&!e.ctrlKey||"x"!==e.key||e.shiftKey||e.altKey||o.handleCut(e):o.handlePaste(e):o.handleCopy(e)}),e.copy_paste_handler=o});e.register_plugin(o);export{o as copy_paste_plugin,n as default};
2
+ * @license BSD-3-Clause
3
+ * @copyright 2014-2025 hizzgdev@163.com
4
+ *
5
+ * Project Home:
6
+ * https://github.com/hizzgdev/jsmind/
7
+ */
8
+ import e from '@umbraci/jsmind';
9
+ const t = new (class {
10
+ constructor(e) {
11
+ (this.w = e),
12
+ (this.d = e.document),
13
+ (this.g = function (e) {
14
+ return this.d.getElementById(e);
15
+ }),
16
+ (this.c = function (e) {
17
+ return this.d.createElement(e);
18
+ }),
19
+ (this.t = function (e, t) {
20
+ e.hasChildNodes()
21
+ ? (e.firstChild.nodeValue = t)
22
+ : e.appendChild(this.d.createTextNode(t));
23
+ }),
24
+ (this.h = function (e, t) {
25
+ t instanceof HTMLElement
26
+ ? ((e.innerHTML = ''), e.appendChild(t))
27
+ : (e.innerHTML = t);
28
+ }),
29
+ (this.i = function (e) {
30
+ return (
31
+ !!e &&
32
+ 'object' == typeof e &&
33
+ 1 === e.nodeType &&
34
+ 'object' == typeof e.style &&
35
+ 'object' == typeof e.ownerDocument
36
+ );
37
+ }),
38
+ (this.on = function (e, t, i) {
39
+ e.addEventListener ? e.addEventListener(t, i, !1) : e.attachEvent('on' + t, i);
40
+ });
41
+ }
42
+ })(window),
43
+ i = {
44
+ file: {
45
+ read: function (e, t) {
46
+ var i = new FileReader();
47
+ (i.onload = function () {
48
+ 'function' == typeof t && t(this.result, e.name);
49
+ }),
50
+ i.readAsText(e);
51
+ },
52
+ save: function (e, i, n) {
53
+ var o;
54
+ if ('function' == typeof t.w.Blob) o = new Blob([e], { type: i });
55
+ else {
56
+ var a = new (t.w.BlobBuilder ||
57
+ t.w.MozBlobBuilder ||
58
+ t.w.WebKitBlobBuilder ||
59
+ t.w.MSBlobBuilder)();
60
+ a.append(e), (o = a.getBlob(i));
61
+ }
62
+ if (navigator.msSaveBlob) navigator.msSaveBlob(o, n);
63
+ else {
64
+ var r = (t.w.URL || t.w.webkitURL).createObjectURL(o),
65
+ s = t.c('a');
66
+ if ('download' in s) {
67
+ (s.style.visibility = 'hidden'),
68
+ (s.href = r),
69
+ (s.download = n),
70
+ t.d.body.appendChild(s);
71
+ var d = t.d.createEvent('MouseEvents');
72
+ d.initEvent('click', !0, !0), s.dispatchEvent(d), t.d.body.removeChild(s);
73
+ } else location.href = r;
74
+ }
75
+ },
76
+ },
77
+ json: {
78
+ json2string: function (e) {
79
+ return JSON.stringify(e);
80
+ },
81
+ string2json: function (e) {
82
+ return JSON.parse(e);
83
+ },
84
+ merge: function (e, t) {
85
+ for (var n in t)
86
+ n in e
87
+ ? 'object' != typeof e[n] ||
88
+ '[object object]' != Object.prototype.toString.call(e[n]).toLowerCase() ||
89
+ e[n].length
90
+ ? (e[n] = t[n])
91
+ : i.json.merge(e[n], t[n])
92
+ : (e[n] = t[n]);
93
+ return e;
94
+ },
95
+ },
96
+ uuid: {
97
+ newid: function () {
98
+ return (
99
+ new Date().getTime().toString(16) + Math.random().toString(16).substring(2)
100
+ ).substring(2, 18);
101
+ },
102
+ },
103
+ text: {
104
+ is_empty: function (e) {
105
+ return !e || 0 == e.replace(/\s*/, '').length;
106
+ },
107
+ },
108
+ };
109
+ class n {
110
+ constructor(e, t = {}) {
111
+ (this.jsMind = e),
112
+ (this.options = {
113
+ enabled: !0,
114
+ shortcuts: { copy: 'meta+c', paste: 'meta+v', cut: 'meta+x' },
115
+ ...t,
116
+ }),
117
+ (this.clipboardData = null),
118
+ (this.logger = {
119
+ info: e => console.info('[CopyPaste]', e),
120
+ warn: e => console.warn('[CopyPaste]', e),
121
+ error: e => console.error('[CopyPaste]', e),
122
+ debug: e => console.debug('[CopyPaste]', e),
123
+ }),
124
+ this.init();
125
+ }
126
+ init() {
127
+ return this.logger.info('CopyPaste plugin initialized'), !0;
128
+ }
129
+ handleCopy(e) {
130
+ if (!this.options.enabled) return;
131
+ const t = this.jsMind.get_selected_node();
132
+ if (t)
133
+ try {
134
+ e.preventDefault(),
135
+ (this.clipboardData = {
136
+ id: t.id,
137
+ topic: t.topic,
138
+ data: t.data || {},
139
+ direction: t.direction,
140
+ expanded: t.expanded,
141
+ children: this.copyChildren(t),
142
+ }),
143
+ this.logger.info('Node copied:', t.topic),
144
+ this.showMessage('节点已复制');
145
+ } catch (e) {
146
+ this.logger.error('Copy failed:', e), this.showMessage('复制失败', 'error');
147
+ }
148
+ else this.logger.warn('No node selected for copying');
149
+ }
150
+ handlePaste(e) {
151
+ if (!this.options.enabled) return;
152
+ if (!this.clipboardData)
153
+ return (
154
+ this.logger.warn('No data in clipboard'),
155
+ void this.showMessage('剪贴板为空,请先复制节点', 'warning')
156
+ );
157
+ const t = this.jsMind.get_selected_node();
158
+ if (!t)
159
+ return (
160
+ this.logger.warn('No target node selected for pasting'),
161
+ void this.showMessage('请选择目标节点', 'warning')
162
+ );
163
+ try {
164
+ e.preventDefault();
165
+ const i = this.prepareBatchData(this.clipboardData),
166
+ n = this.jsMind.add_nodes(t, [i]);
167
+ n &&
168
+ n.length > 0 &&
169
+ (this.logger.info('Nodes pasted successfully:', this.clipboardData.topic),
170
+ this.showMessage('粘贴成功'));
171
+ } catch (e) {
172
+ this.logger.error('Paste failed:', e), this.showMessage('粘贴失败', 'error');
173
+ }
174
+ }
175
+ handleCut(e) {
176
+ if (!this.options.enabled) return;
177
+ const t = this.jsMind.get_selected_node();
178
+ if (t) {
179
+ if (t.isroot)
180
+ return (
181
+ this.logger.warn('Cannot cut root node'),
182
+ void this.showMessage('不能剪切根节点', 'warning')
183
+ );
184
+ try {
185
+ e.preventDefault(),
186
+ (this.clipboardData = {
187
+ id: t.id,
188
+ topic: t.topic,
189
+ data: t.data || {},
190
+ direction: t.direction,
191
+ expanded: t.expanded,
192
+ children: this.copyChildren(t),
193
+ });
194
+ this.jsMind.remove_node(t) &&
195
+ (this.logger.info('Node cut:', t.topic), this.showMessage('节点已剪切'));
196
+ } catch (e) {
197
+ this.logger.error('Cut failed:', e), this.showMessage('剪切失败', 'error');
198
+ }
199
+ } else this.logger.warn('No node selected for cutting');
200
+ }
201
+ copyChildren(e) {
202
+ return e.children && 0 !== e.children.length
203
+ ? e.children.map(e => ({
204
+ id: e.id,
205
+ topic: e.topic,
206
+ data: e.data || {},
207
+ direction: e.direction,
208
+ expanded: e.expanded,
209
+ children: this.copyChildren(e),
210
+ }))
211
+ : [];
212
+ }
213
+ prepareBatchData(e) {
214
+ return {
215
+ id: i.uuid.newid(),
216
+ topic: e.topic,
217
+ data: e.data || {},
218
+ children:
219
+ e.children && e.children.length > 0
220
+ ? e.children.map(e => this.prepareBatchData(e))
221
+ : void 0,
222
+ };
223
+ }
224
+ pasteChildren(e, t) {
225
+ if (!t || 0 === t.length) return [];
226
+ const i = t.map(e => this.prepareBatchData(e));
227
+ return this.jsMind.add_nodes(e, i);
228
+ }
229
+ showMessage(e, t = 'info') {
230
+ console.log(`[CopyPaste ${t.toUpperCase()}]: ${e}`);
231
+ }
232
+ clear() {
233
+ (this.clipboardData = null), this.logger.info('Clipboard cleared');
234
+ }
235
+ getStatus() {
236
+ return { hasData: !!this.clipboardData, data: this.clipboardData };
237
+ }
238
+ }
239
+ const o = new e.plugin('copy-paste', function (e, t) {
240
+ var i = t || {};
241
+ i.shortcuts = i.shortcuts || { copy: 'meta+c', paste: 'meta+v', cut: 'meta+x' };
242
+ var o = new n(e, i);
243
+ e.view &&
244
+ e.view.e_panel &&
245
+ e.view.e_panel.addEventListener('keydown', function (e) {
246
+ (!e.metaKey && !e.ctrlKey) || 'c' !== e.key || e.shiftKey || e.altKey
247
+ ? (!e.metaKey && !e.ctrlKey) || 'v' !== e.key || e.shiftKey || e.altKey
248
+ ? (!e.metaKey && !e.ctrlKey) ||
249
+ 'x' !== e.key ||
250
+ e.shiftKey ||
251
+ e.altKey ||
252
+ o.handleCut(e)
253
+ : o.handlePaste(e)
254
+ : o.handleCopy(e);
255
+ }),
256
+ (e.copy_paste_handler = o);
257
+ });
258
+ e.register_plugin(o);
259
+ export { o as copy_paste_plugin, n as default };
9
260
  //# sourceMappingURL=jsmind.copy-paste.js.map