@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,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
|
-
!
|
|
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
|
-
!
|
|
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
|
package/es/jsmind.copy-paste.js
CHANGED
|
@@ -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
|
|
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
|