@umbraci/jsmind 0.10.17 → 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,283 @@
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).jsMindCopyPaste={},e.jsMind)}(this,function(e,t){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=i(t);const o=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),a={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,t,i){var n;if("function"==typeof o.w.Blob)n=new Blob([e],{type:t});else{var a=new(o.w.BlobBuilder||o.w.MozBlobBuilder||o.w.WebKitBlobBuilder||o.w.MSBlobBuilder);a.append(e),n=a.getBlob(t)}if(navigator.msSaveBlob)navigator.msSaveBlob(n,i);else{var r=(o.w.URL||o.w.webkitURL).createObjectURL(n),s=o.c("a");if("download"in s){s.style.visibility="hidden",s.href=r,s.download=i,o.d.body.appendChild(s);var d=o.d.createEvent("MouseEvents");d.initEvent("click",!0,!0),s.dispatchEvent(d),o.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 i in t)i in e?"object"!=typeof e[i]||"[object object]"!=Object.prototype.toString.call(e[i]).toLowerCase()||e[i].length?e[i]=t[i]:a.json.merge(e[i],t[i]):e[i]=t[i];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 r{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:a.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 s=new n.default.plugin("copy-paste",function(e,t){var i=t||{};i.shortcuts=i.shortcuts||{copy:"meta+c",paste:"meta+v",cut:"meta+x"};var n=new r(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||n.handleCut(e):n.handlePaste(e):n.handleCopy(e)}),e.copy_paste_handler=n});n.default.register_plugin(s),e.copy_paste_plugin=s,e.default=r,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).jsMindCopyPaste =
15
+ {}),
16
+ e.jsMind
17
+ );
18
+ })(this, function (e, t) {
19
+ 'use strict';
20
+ function i(e) {
21
+ return e && 'object' == typeof e && 'default' in e ? e : { default: e };
22
+ }
23
+ var n = i(t);
24
+ const o = new (class {
25
+ constructor(e) {
26
+ (this.w = e),
27
+ (this.d = e.document),
28
+ (this.g = function (e) {
29
+ return this.d.getElementById(e);
30
+ }),
31
+ (this.c = function (e) {
32
+ return this.d.createElement(e);
33
+ }),
34
+ (this.t = function (e, t) {
35
+ e.hasChildNodes()
36
+ ? (e.firstChild.nodeValue = t)
37
+ : e.appendChild(this.d.createTextNode(t));
38
+ }),
39
+ (this.h = function (e, t) {
40
+ t instanceof HTMLElement
41
+ ? ((e.innerHTML = ''), e.appendChild(t))
42
+ : (e.innerHTML = t);
43
+ }),
44
+ (this.i = function (e) {
45
+ return (
46
+ !!e &&
47
+ 'object' == typeof e &&
48
+ 1 === e.nodeType &&
49
+ 'object' == typeof e.style &&
50
+ 'object' == typeof e.ownerDocument
51
+ );
52
+ }),
53
+ (this.on = function (e, t, i) {
54
+ e.addEventListener
55
+ ? e.addEventListener(t, i, !1)
56
+ : e.attachEvent('on' + t, i);
57
+ });
58
+ }
59
+ })(window),
60
+ a = {
61
+ file: {
62
+ read: function (e, t) {
63
+ var i = new FileReader();
64
+ (i.onload = function () {
65
+ 'function' == typeof t && t(this.result, e.name);
66
+ }),
67
+ i.readAsText(e);
68
+ },
69
+ save: function (e, t, i) {
70
+ var n;
71
+ if ('function' == typeof o.w.Blob) n = new Blob([e], { type: t });
72
+ else {
73
+ var a = new (o.w.BlobBuilder ||
74
+ o.w.MozBlobBuilder ||
75
+ o.w.WebKitBlobBuilder ||
76
+ o.w.MSBlobBuilder)();
77
+ a.append(e), (n = a.getBlob(t));
78
+ }
79
+ if (navigator.msSaveBlob) navigator.msSaveBlob(n, i);
80
+ else {
81
+ var r = (o.w.URL || o.w.webkitURL).createObjectURL(n),
82
+ s = o.c('a');
83
+ if ('download' in s) {
84
+ (s.style.visibility = 'hidden'),
85
+ (s.href = r),
86
+ (s.download = i),
87
+ o.d.body.appendChild(s);
88
+ var d = o.d.createEvent('MouseEvents');
89
+ d.initEvent('click', !0, !0),
90
+ s.dispatchEvent(d),
91
+ o.d.body.removeChild(s);
92
+ } else location.href = r;
93
+ }
94
+ },
95
+ },
96
+ json: {
97
+ json2string: function (e) {
98
+ return JSON.stringify(e);
99
+ },
100
+ string2json: function (e) {
101
+ return JSON.parse(e);
102
+ },
103
+ merge: function (e, t) {
104
+ for (var i in t)
105
+ i in e
106
+ ? 'object' != typeof e[i] ||
107
+ '[object object]' !=
108
+ Object.prototype.toString.call(e[i]).toLowerCase() ||
109
+ e[i].length
110
+ ? (e[i] = t[i])
111
+ : a.json.merge(e[i], t[i])
112
+ : (e[i] = t[i]);
113
+ return e;
114
+ },
115
+ },
116
+ uuid: {
117
+ newid: function () {
118
+ return (
119
+ new Date().getTime().toString(16) + Math.random().toString(16).substring(2)
120
+ ).substring(2, 18);
121
+ },
122
+ },
123
+ text: {
124
+ is_empty: function (e) {
125
+ return !e || 0 == e.replace(/\s*/, '').length;
126
+ },
127
+ },
128
+ };
129
+ class r {
130
+ constructor(e, t = {}) {
131
+ (this.jsMind = e),
132
+ (this.options = {
133
+ enabled: !0,
134
+ shortcuts: { copy: 'meta+c', paste: 'meta+v', cut: 'meta+x' },
135
+ ...t,
136
+ }),
137
+ (this.clipboardData = null),
138
+ (this.logger = {
139
+ info: e => console.info('[CopyPaste]', e),
140
+ warn: e => console.warn('[CopyPaste]', e),
141
+ error: e => console.error('[CopyPaste]', e),
142
+ debug: e => console.debug('[CopyPaste]', e),
143
+ }),
144
+ this.init();
145
+ }
146
+ init() {
147
+ return this.logger.info('CopyPaste plugin initialized'), !0;
148
+ }
149
+ handleCopy(e) {
150
+ if (!this.options.enabled) return;
151
+ const t = this.jsMind.get_selected_node();
152
+ if (t)
153
+ try {
154
+ e.preventDefault(),
155
+ (this.clipboardData = {
156
+ id: t.id,
157
+ topic: t.topic,
158
+ data: t.data || {},
159
+ direction: t.direction,
160
+ expanded: t.expanded,
161
+ children: this.copyChildren(t),
162
+ }),
163
+ this.logger.info('Node copied:', t.topic),
164
+ this.showMessage('节点已复制');
165
+ } catch (e) {
166
+ this.logger.error('Copy failed:', e), this.showMessage('复制失败', 'error');
167
+ }
168
+ else this.logger.warn('No node selected for copying');
169
+ }
170
+ handlePaste(e) {
171
+ if (!this.options.enabled) return;
172
+ if (!this.clipboardData)
173
+ return (
174
+ this.logger.warn('No data in clipboard'),
175
+ void this.showMessage('剪贴板为空,请先复制节点', 'warning')
176
+ );
177
+ const t = this.jsMind.get_selected_node();
178
+ if (!t)
179
+ return (
180
+ this.logger.warn('No target node selected for pasting'),
181
+ void this.showMessage('请选择目标节点', 'warning')
182
+ );
183
+ try {
184
+ e.preventDefault();
185
+ const i = this.prepareBatchData(this.clipboardData),
186
+ n = this.jsMind.add_nodes(t, [i]);
187
+ n &&
188
+ n.length > 0 &&
189
+ (this.logger.info('Nodes pasted successfully:', this.clipboardData.topic),
190
+ this.showMessage('粘贴成功'));
191
+ } catch (e) {
192
+ this.logger.error('Paste failed:', e), this.showMessage('粘贴失败', 'error');
193
+ }
194
+ }
195
+ handleCut(e) {
196
+ if (!this.options.enabled) return;
197
+ const t = this.jsMind.get_selected_node();
198
+ if (t) {
199
+ if (t.isroot)
200
+ return (
201
+ this.logger.warn('Cannot cut root node'),
202
+ void this.showMessage('不能剪切根节点', 'warning')
203
+ );
204
+ try {
205
+ e.preventDefault(),
206
+ (this.clipboardData = {
207
+ id: t.id,
208
+ topic: t.topic,
209
+ data: t.data || {},
210
+ direction: t.direction,
211
+ expanded: t.expanded,
212
+ children: this.copyChildren(t),
213
+ });
214
+ this.jsMind.remove_node(t) &&
215
+ (this.logger.info('Node cut:', t.topic), this.showMessage('节点已剪切'));
216
+ } catch (e) {
217
+ this.logger.error('Cut failed:', e), this.showMessage('剪切失败', 'error');
218
+ }
219
+ } else this.logger.warn('No node selected for cutting');
220
+ }
221
+ copyChildren(e) {
222
+ return e.children && 0 !== e.children.length
223
+ ? e.children.map(e => ({
224
+ id: e.id,
225
+ topic: e.topic,
226
+ data: e.data || {},
227
+ direction: e.direction,
228
+ expanded: e.expanded,
229
+ children: this.copyChildren(e),
230
+ }))
231
+ : [];
232
+ }
233
+ prepareBatchData(e) {
234
+ return {
235
+ id: a.uuid.newid(),
236
+ topic: e.topic,
237
+ data: e.data || {},
238
+ children:
239
+ e.children && e.children.length > 0
240
+ ? e.children.map(e => this.prepareBatchData(e))
241
+ : void 0,
242
+ };
243
+ }
244
+ pasteChildren(e, t) {
245
+ if (!t || 0 === t.length) return [];
246
+ const i = t.map(e => this.prepareBatchData(e));
247
+ return this.jsMind.add_nodes(e, i);
248
+ }
249
+ showMessage(e, t = 'info') {
250
+ console.log(`[CopyPaste ${t.toUpperCase()}]: ${e}`);
251
+ }
252
+ clear() {
253
+ (this.clipboardData = null), this.logger.info('Clipboard cleared');
254
+ }
255
+ getStatus() {
256
+ return { hasData: !!this.clipboardData, data: this.clipboardData };
257
+ }
258
+ }
259
+ const s = new n.default.plugin('copy-paste', function (e, t) {
260
+ var i = t || {};
261
+ i.shortcuts = i.shortcuts || { copy: 'meta+c', paste: 'meta+v', cut: 'meta+x' };
262
+ var n = new r(e, i);
263
+ e.view &&
264
+ e.view.e_panel &&
265
+ e.view.e_panel.addEventListener('keydown', function (e) {
266
+ (!e.metaKey && !e.ctrlKey) || 'c' !== e.key || e.shiftKey || e.altKey
267
+ ? (!e.metaKey && !e.ctrlKey) || 'v' !== e.key || e.shiftKey || e.altKey
268
+ ? (!e.metaKey && !e.ctrlKey) ||
269
+ 'x' !== e.key ||
270
+ e.shiftKey ||
271
+ e.altKey ||
272
+ n.handleCut(e)
273
+ : n.handlePaste(e)
274
+ : n.handleCopy(e);
275
+ }),
276
+ (e.copy_paste_handler = n);
277
+ });
278
+ n.default.register_plugin(s),
279
+ (e.copy_paste_plugin = s),
280
+ (e.default = r),
281
+ Object.defineProperty(e, '__esModule', { value: !0 });
282
+ });
9
283
  //# sourceMappingURL=jsmind.copy-paste.js.map