markmap-toolbar 0.15.5-alpha.1 → 0.15.6-alpha.4
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/index.js +270 -284
- package/dist/index.mjs +118 -126
- package/dist/style.css +1 -1
- package/package.json +8 -10
- /package/{types → dist}/index.d.ts +0 -0
- /package/{types → dist}/toolbar.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,307 +1,293 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for (var key in source) {
|
|
13
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
14
|
-
target[key] = source[key];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
return _extends.apply(this, arguments);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
|
|
24
|
-
const VTYPE_ELEMENT = 1;
|
|
25
|
-
const VTYPE_FUNCTION = 2;
|
|
26
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
27
|
-
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
28
|
-
const NS_ATTRS = {
|
|
29
|
-
show: XLINK_NS,
|
|
30
|
-
actuate: XLINK_NS,
|
|
31
|
-
href: XLINK_NS
|
|
32
|
-
};
|
|
33
|
-
const isLeaf = c => typeof c === 'string' || typeof c === 'number';
|
|
34
|
-
const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
35
|
-
const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
36
|
-
function jsx(type, props) {
|
|
37
|
-
let vtype;
|
|
38
|
-
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
|
|
39
|
-
return {
|
|
40
|
-
vtype,
|
|
41
|
-
type,
|
|
42
|
-
props
|
|
1
|
+
(function(exports) {
|
|
2
|
+
"use strict";
|
|
3
|
+
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
|
|
4
|
+
const VTYPE_ELEMENT = 1;
|
|
5
|
+
const VTYPE_FUNCTION = 2;
|
|
6
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
7
|
+
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
8
|
+
const NS_ATTRS = {
|
|
9
|
+
show: XLINK_NS,
|
|
10
|
+
actuate: XLINK_NS,
|
|
11
|
+
href: XLINK_NS
|
|
43
12
|
};
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (key === 'dangerouslySetInnerHTML') {
|
|
61
|
-
domElement.innerHTML = props[key].__html;
|
|
62
|
-
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) {
|
|
63
|
-
const value = props[key];
|
|
64
|
-
if (value != null) domElement[key] = value;
|
|
65
|
-
} else if (key.startsWith('on')) {
|
|
66
|
-
domElement[key.toLowerCase()] = props[key];
|
|
67
|
-
} else {
|
|
68
|
-
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
69
|
-
}
|
|
13
|
+
const isLeaf = (c) => typeof c === "string" || typeof c === "number";
|
|
14
|
+
const isElement = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
15
|
+
const isRenderFunction = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
16
|
+
function jsx(type, props) {
|
|
17
|
+
let vtype;
|
|
18
|
+
if (typeof type === "string")
|
|
19
|
+
vtype = VTYPE_ELEMENT;
|
|
20
|
+
else if (typeof type === "function")
|
|
21
|
+
vtype = VTYPE_FUNCTION;
|
|
22
|
+
else
|
|
23
|
+
throw new Error("Invalid VNode type");
|
|
24
|
+
return {
|
|
25
|
+
vtype,
|
|
26
|
+
type,
|
|
27
|
+
props
|
|
28
|
+
};
|
|
70
29
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
labelFor: 'for'
|
|
75
|
-
};
|
|
76
|
-
function setDOMAttribute(el, attr, value, isSVG) {
|
|
77
|
-
attr = attrMap[attr] || attr;
|
|
78
|
-
if (value === true) {
|
|
79
|
-
el.setAttribute(attr, '');
|
|
80
|
-
} else if (value === false) {
|
|
81
|
-
el.removeAttribute(attr);
|
|
82
|
-
} else {
|
|
83
|
-
const namespace = isSVG ? NS_ATTRS[attr] : undefined;
|
|
84
|
-
if (namespace !== undefined) {
|
|
85
|
-
el.setAttributeNS(namespace, attr, value);
|
|
86
|
-
} else {
|
|
87
|
-
el.setAttribute(attr, value);
|
|
88
|
-
}
|
|
30
|
+
const jsxs = jsx;
|
|
31
|
+
function Fragment(props) {
|
|
32
|
+
return props.children;
|
|
89
33
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return null;
|
|
34
|
+
const DEFAULT_ENV = {
|
|
35
|
+
isSvg: false
|
|
36
|
+
};
|
|
37
|
+
function insertDom(parent, nodes) {
|
|
38
|
+
if (!Array.isArray(nodes))
|
|
39
|
+
nodes = [nodes];
|
|
40
|
+
nodes = nodes.filter(Boolean);
|
|
41
|
+
if (nodes.length)
|
|
42
|
+
parent.append(...nodes);
|
|
100
43
|
}
|
|
101
|
-
|
|
102
|
-
|
|
44
|
+
function mountAttributes(domElement, props, env) {
|
|
45
|
+
for (const key in props) {
|
|
46
|
+
if (key === "key" || key === "children" || key === "ref")
|
|
47
|
+
continue;
|
|
48
|
+
if (key === "dangerouslySetInnerHTML") {
|
|
49
|
+
domElement.innerHTML = props[key].__html;
|
|
50
|
+
} else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
|
|
51
|
+
const value = props[key];
|
|
52
|
+
if (value != null)
|
|
53
|
+
domElement[key] = value;
|
|
54
|
+
} else if (key.startsWith("on")) {
|
|
55
|
+
domElement[key.toLowerCase()] = props[key];
|
|
56
|
+
} else {
|
|
57
|
+
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
103
60
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
61
|
+
const attrMap = {
|
|
62
|
+
className: "class",
|
|
63
|
+
labelFor: "for"
|
|
64
|
+
};
|
|
65
|
+
function setDOMAttribute(el, attr, value, isSVG) {
|
|
66
|
+
attr = attrMap[attr] || attr;
|
|
67
|
+
if (value === true) {
|
|
68
|
+
el.setAttribute(attr, "");
|
|
69
|
+
} else if (value === false) {
|
|
70
|
+
el.removeAttribute(attr);
|
|
71
|
+
} else {
|
|
72
|
+
const namespace = isSVG ? NS_ATTRS[attr] : void 0;
|
|
73
|
+
if (namespace !== void 0) {
|
|
74
|
+
el.setAttributeNS(namespace, attr, value);
|
|
75
|
+
} else {
|
|
76
|
+
el.setAttribute(attr, value);
|
|
114
77
|
}
|
|
115
|
-
return node;
|
|
116
78
|
}
|
|
117
|
-
const childVNode = type(props);
|
|
118
|
-
return mount(childVNode, env);
|
|
119
79
|
}
|
|
120
|
-
|
|
121
|
-
return
|
|
80
|
+
function flatten(arr) {
|
|
81
|
+
return arr.reduce((prev, item) => prev.concat(item), []);
|
|
122
82
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (!env.isSvg && type === 'svg') {
|
|
130
|
-
env = Object.assign({}, env, {
|
|
131
|
-
isSvg: true
|
|
132
|
-
});
|
|
83
|
+
function mountChildren(children, env) {
|
|
84
|
+
return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
|
|
85
|
+
}
|
|
86
|
+
function mount(vnode, env = DEFAULT_ENV) {
|
|
87
|
+
if (vnode == null || typeof vnode === "boolean") {
|
|
88
|
+
return null;
|
|
133
89
|
}
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
} else {
|
|
137
|
-
node = document.createElementNS(SVG_NS, type);
|
|
90
|
+
if (vnode instanceof Node) {
|
|
91
|
+
return vnode;
|
|
138
92
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
93
|
+
if (isRenderFunction(vnode)) {
|
|
94
|
+
const {
|
|
95
|
+
type,
|
|
96
|
+
props
|
|
97
|
+
} = vnode;
|
|
98
|
+
if (type === Fragment) {
|
|
99
|
+
const node = document.createDocumentFragment();
|
|
100
|
+
if (props.children) {
|
|
101
|
+
const children = mountChildren(props.children, env);
|
|
102
|
+
insertDom(node, children);
|
|
103
|
+
}
|
|
104
|
+
return node;
|
|
146
105
|
}
|
|
147
|
-
const
|
|
148
|
-
|
|
106
|
+
const childVNode = type(props);
|
|
107
|
+
return mount(childVNode, env);
|
|
149
108
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} = props;
|
|
153
|
-
if (typeof ref === 'function') ref(node);
|
|
154
|
-
return node;
|
|
155
|
-
}
|
|
156
|
-
throw new Error('mount: Invalid Vnode!');
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Mount vdom as real DOM nodes.
|
|
161
|
-
*/
|
|
162
|
-
function mountDom(vnode) {
|
|
163
|
-
return mount(vnode);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const clsToolbarItem = 'mm-toolbar-item';
|
|
167
|
-
const clsActive = 'active';
|
|
168
|
-
function renderBrand() {
|
|
169
|
-
return jsxs("a", {
|
|
170
|
-
className: "mm-toolbar-brand",
|
|
171
|
-
href: "https://markmap.js.org/",
|
|
172
|
-
children: [jsx("img", {
|
|
173
|
-
alt: "markmap",
|
|
174
|
-
src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACoFBMVEUAAAAAAAD//wAAAACAgAD//wAAAABVVQCqqgBAQACAQACAgABmZgBtbQAAAABgQABgYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaFQAAAAAAAAAAAAAAAAAHAAARBQIdGAIYEwI/OgJYUQUfHQI+OgJDPgJJRARBPQRJQgRRSwRRTQRIQQRUTgRUUARZUgRSTQRPSQRjWgZORQRfWQZsZAhTTQRNRwRWUAZkXAZOSARUTgZPRwRRSQRoYwZWUQZWTgRbUwZmXQZoXghmXwdqYwdsYwdfVwVmXQdqYgdiWgVpYAl3bgl6cgl4cAqLggw8OAOWjA2Uig1OSAR2bQihlg55cAh5cAh6cQmMgwyOhAyUjA2QhQ2Uiw2Viw2soBCflA+voxGwpRGhlg+hlg+snxGroBGjmBCpnBC0pxKyphKxpRG2qhK0qBK5rBK5rBP/7h3/8B7/8R3/8h3/8R7/8h786x397B3+7R3EtxT66Rz66hz76hz86xz96xz97Bz+7Rz45xz56Bz76hz97Bz97B3MvRX15Rv25Rv45xz66Rz76hz97B3+7R3IuxX05Bv15Bv25Rz56Bz66Ry/sxPAsxPCtRTCthTNvxbZyxfczxfi0xjl1Rnn2Bnr2xrr3Brs3Rru3Rru3xrv3hrw3xrx4B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Uq+AK+uJqOlZBiSEKGLNnMA0iDfzwrI/NKgBOivk9piPdtUAAAAASUVORK5CYII="
|
|
175
|
-
}), jsx("span", {
|
|
176
|
-
children: "markmap"
|
|
177
|
-
})]
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
function renderItem({
|
|
181
|
-
title,
|
|
182
|
-
content,
|
|
183
|
-
onClick
|
|
184
|
-
}) {
|
|
185
|
-
return jsx("div", {
|
|
186
|
-
className: clsToolbarItem,
|
|
187
|
-
title: title,
|
|
188
|
-
onClick: onClick,
|
|
189
|
-
children: content
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
let promise;
|
|
193
|
-
function safeCaller(fn) {
|
|
194
|
-
return async (...args) => {
|
|
195
|
-
if (promise) return;
|
|
196
|
-
promise = fn(...args);
|
|
197
|
-
try {
|
|
198
|
-
await promise;
|
|
199
|
-
} finally {
|
|
200
|
-
promise = undefined;
|
|
109
|
+
if (isLeaf(vnode)) {
|
|
110
|
+
return document.createTextNode(`${vnode}`);
|
|
201
111
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
attrs = _extends({
|
|
212
|
-
stroke: 'none',
|
|
213
|
-
fill: 'currentColor',
|
|
214
|
-
'fill-rule': 'evenodd'
|
|
215
|
-
}, attrs);
|
|
216
|
-
return jsx("svg", {
|
|
217
|
-
width: "20",
|
|
218
|
-
height: "20",
|
|
219
|
-
viewBox: "0 0 20 20",
|
|
220
|
-
children: jsx("path", _extends({}, attrs, {
|
|
221
|
-
d: path
|
|
222
|
-
}))
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
constructor() {
|
|
226
|
-
this.showBrand = true;
|
|
227
|
-
this.registry = {};
|
|
228
|
-
this.el = mountDom(jsx("div", {
|
|
229
|
-
className: "mm-toolbar"
|
|
230
|
-
}));
|
|
231
|
-
this.items = [...Toolbar.defaultItems];
|
|
232
|
-
this.register({
|
|
233
|
-
id: 'zoomIn',
|
|
234
|
-
title: 'Zoom in',
|
|
235
|
-
content: Toolbar.icon('M9 5v4h-4v2h4v4h2v-4h4v-2h-4v-4z'),
|
|
236
|
-
onClick: this.getHandler(mm => mm.rescale(1.25))
|
|
237
|
-
});
|
|
238
|
-
this.register({
|
|
239
|
-
id: 'zoomOut',
|
|
240
|
-
title: 'Zoom out',
|
|
241
|
-
content: Toolbar.icon('M5 9h10v2h-10z'),
|
|
242
|
-
onClick: this.getHandler(mm => mm.rescale(0.8))
|
|
243
|
-
});
|
|
244
|
-
this.register({
|
|
245
|
-
id: 'fit',
|
|
246
|
-
title: 'Fit window size',
|
|
247
|
-
content: Toolbar.icon('M4 7h2v-2h2v4h-4zM4 13h2v2h2v-4h-4zM16 7h-2v-2h-2v4h4zM16 13h-2v2h-2v-4h4z'),
|
|
248
|
-
onClick: this.getHandler(mm => mm.fit())
|
|
249
|
-
});
|
|
250
|
-
this.register({
|
|
251
|
-
id: 'recurse',
|
|
252
|
-
title: 'Toggle recursively',
|
|
253
|
-
content: Toolbar.icon('M16 4h-12v12h12v-8h-8v4h2v-2h4v4h-8v-8h10z'),
|
|
254
|
-
onClick: e => {
|
|
255
|
-
var _this$markmap;
|
|
256
|
-
const button = e.target.closest(`.${clsToolbarItem}`);
|
|
257
|
-
const active = button == null ? void 0 : button.classList.toggle(clsActive);
|
|
258
|
-
(_this$markmap = this.markmap) == null || _this$markmap.setOptions({
|
|
259
|
-
toggleRecursively: active
|
|
112
|
+
if (isElement(vnode)) {
|
|
113
|
+
let node;
|
|
114
|
+
const {
|
|
115
|
+
type,
|
|
116
|
+
props
|
|
117
|
+
} = vnode;
|
|
118
|
+
if (!env.isSvg && type === "svg") {
|
|
119
|
+
env = Object.assign({}, env, {
|
|
120
|
+
isSvg: true
|
|
260
121
|
});
|
|
261
122
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
123
|
+
if (!env.isSvg) {
|
|
124
|
+
node = document.createElement(type);
|
|
125
|
+
} else {
|
|
126
|
+
node = document.createElementNS(SVG_NS, type);
|
|
127
|
+
}
|
|
128
|
+
mountAttributes(node, props, env);
|
|
129
|
+
if (props.children) {
|
|
130
|
+
let childEnv = env;
|
|
131
|
+
if (env.isSvg && type === "foreignObject") {
|
|
132
|
+
childEnv = Object.assign({}, childEnv, {
|
|
133
|
+
isSvg: false
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const children = mountChildren(props.children, childEnv);
|
|
137
|
+
if (children != null)
|
|
138
|
+
insertDom(node, children);
|
|
139
|
+
}
|
|
140
|
+
const {
|
|
141
|
+
ref
|
|
142
|
+
} = props;
|
|
143
|
+
if (typeof ref === "function")
|
|
144
|
+
ref(node);
|
|
145
|
+
return node;
|
|
146
|
+
}
|
|
147
|
+
throw new Error("mount: Invalid Vnode!");
|
|
268
148
|
}
|
|
269
|
-
|
|
270
|
-
|
|
149
|
+
function mountDom(vnode) {
|
|
150
|
+
return mount(vnode);
|
|
271
151
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
152
|
+
const clsToolbarItem = "mm-toolbar-item";
|
|
153
|
+
const clsActive = "active";
|
|
154
|
+
function renderBrand() {
|
|
155
|
+
return /* @__PURE__ */ jsxs("a", { className: "mm-toolbar-brand", href: "https://markmap.js.org/", children: [
|
|
156
|
+
/* @__PURE__ */ jsx(
|
|
157
|
+
"img",
|
|
158
|
+
{
|
|
159
|
+
alt: "markmap",
|
|
160
|
+
src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACoFBMVEUAAAAAAAD//wAAAACAgAD//wAAAABVVQCqqgBAQACAQACAgABmZgBtbQAAAABgQABgYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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sDAwSxmmVEzZu2XvqSLkchjw3g0h445Ybd24vmTN1Usd5X3R5DgaNqgN35sycP2/GxMkTMRVwMOivvtO3YsWUm3duX790EcMKdgbNNXdnnJh1+9T6ipzU+FB0RzIyiFYB5WdfaElUF8TmTQ6GwH39J2bvypMHcpg4MAKKkUGo5s6KWRfyGRh4WJClGEGBCgS8DLobliy/3abMwM8NBYwQjXDgf3ryxOspyKYyg+RFTFwdnYDAzbrw+oLFm9Ot3J3AwNHFTBykQrhg++GDh48cOXzk4P6VZy8s230MyAGCwwcP7iyRBJpiur1n8hQIWHX27NkLi6bAwOSuow5ABeY7OydOhoCFIAULe6E8YFCf8QAqEC86evniZTA4tfLsuRXHr0E4ly9ePF0uC3KnpH1MZBQQxPoVgxyZ5RMdBQaRMc6yIEcihWbQGaA3k9G8CfQoN0pAtSoxCMACihk9qGtBQZ2LHtRIkRUMiqwd2TJADiswsrjQlAGju/o+MLrPNkWo8mFN1ewMWmvBCebQ0rKMJG87QzF0FRwMRuvugpLcrXu3rp7Zs61UCtMZ2nVHbk+fMX/+jMmTp3Sf9MLiULG45q237txaPG3yxPYrYQzYMo60RWbD3E27Ll68Uq+AK+uJqOlZBiSEKGLNnMA0iDfzwrI/NKgBOivk9piPdtUAAAAASUVORK5CYII="
|
|
161
|
+
}
|
|
162
|
+
),
|
|
163
|
+
/* @__PURE__ */ jsx("span", { children: "markmap" })
|
|
164
|
+
] });
|
|
277
165
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return this.render();
|
|
166
|
+
function renderItem({ title, content, onClick }) {
|
|
167
|
+
return /* @__PURE__ */ jsx("div", { className: clsToolbarItem, title, onClick, children: content });
|
|
281
168
|
}
|
|
282
|
-
|
|
283
|
-
|
|
169
|
+
let promise;
|
|
170
|
+
function safeCaller(fn) {
|
|
171
|
+
return async (...args) => {
|
|
172
|
+
if (promise)
|
|
173
|
+
return;
|
|
174
|
+
promise = fn(...args);
|
|
175
|
+
try {
|
|
176
|
+
await promise;
|
|
177
|
+
} finally {
|
|
178
|
+
promise = void 0;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
284
181
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
182
|
+
const _Toolbar = class _Toolbar {
|
|
183
|
+
constructor() {
|
|
184
|
+
this.showBrand = true;
|
|
185
|
+
this.registry = {};
|
|
186
|
+
this.el = mountDom(/* @__PURE__ */ jsx("div", { className: "mm-toolbar" }));
|
|
187
|
+
this.items = [..._Toolbar.defaultItems];
|
|
188
|
+
this.register({
|
|
189
|
+
id: "zoomIn",
|
|
190
|
+
title: "Zoom in",
|
|
191
|
+
content: _Toolbar.icon("M9 5v4h-4v2h4v4h2v-4h4v-2h-4v-4z"),
|
|
192
|
+
onClick: this.getHandler((mm) => mm.rescale(1.25))
|
|
193
|
+
});
|
|
194
|
+
this.register({
|
|
195
|
+
id: "zoomOut",
|
|
196
|
+
title: "Zoom out",
|
|
197
|
+
content: _Toolbar.icon("M5 9h10v2h-10z"),
|
|
198
|
+
onClick: this.getHandler((mm) => mm.rescale(0.8))
|
|
199
|
+
});
|
|
200
|
+
this.register({
|
|
201
|
+
id: "fit",
|
|
202
|
+
title: "Fit window size",
|
|
203
|
+
content: _Toolbar.icon(
|
|
204
|
+
"M4 7h2v-2h2v4h-4zM4 13h2v2h2v-4h-4zM16 7h-2v-2h-2v4h4zM16 13h-2v2h-2v-4h4z"
|
|
205
|
+
),
|
|
206
|
+
onClick: this.getHandler((mm) => mm.fit())
|
|
207
|
+
});
|
|
208
|
+
this.register({
|
|
209
|
+
id: "recurse",
|
|
210
|
+
title: "Toggle recursively",
|
|
211
|
+
content: _Toolbar.icon("M16 4h-12v12h12v-8h-8v4h2v-2h4v4h-8v-8h10z"),
|
|
212
|
+
onClick: (e) => {
|
|
213
|
+
var _a;
|
|
214
|
+
const button = e.target.closest(
|
|
215
|
+
`.${clsToolbarItem}`
|
|
216
|
+
);
|
|
217
|
+
const active = button == null ? void 0 : button.classList.toggle(clsActive);
|
|
218
|
+
(_a = this.markmap) == null ? void 0 : _a.setOptions({
|
|
219
|
+
toggleRecursively: active
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
this.render();
|
|
224
|
+
}
|
|
225
|
+
static create(mm) {
|
|
226
|
+
const toolbar = new _Toolbar();
|
|
227
|
+
toolbar.attach(mm);
|
|
228
|
+
return toolbar;
|
|
229
|
+
}
|
|
230
|
+
static icon(path, attrs = {}) {
|
|
231
|
+
attrs = {
|
|
232
|
+
stroke: "none",
|
|
233
|
+
fill: "currentColor",
|
|
234
|
+
"fill-rule": "evenodd",
|
|
235
|
+
...attrs
|
|
236
|
+
};
|
|
237
|
+
return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 20 20", children: /* @__PURE__ */ jsx("path", { ...attrs, d: path }) });
|
|
238
|
+
}
|
|
239
|
+
setBrand(show) {
|
|
240
|
+
this.showBrand = show;
|
|
241
|
+
return this.render();
|
|
242
|
+
}
|
|
243
|
+
register(data) {
|
|
244
|
+
this.registry[data.id] = data;
|
|
245
|
+
}
|
|
246
|
+
getHandler(handle) {
|
|
247
|
+
handle = safeCaller(handle);
|
|
248
|
+
return () => {
|
|
249
|
+
if (this.markmap)
|
|
250
|
+
handle(this.markmap);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
setItems(items) {
|
|
254
|
+
this.items = [...items];
|
|
255
|
+
return this.render();
|
|
256
|
+
}
|
|
257
|
+
attach(mm) {
|
|
258
|
+
this.markmap = mm;
|
|
259
|
+
}
|
|
260
|
+
render() {
|
|
261
|
+
const items = this.items.map((item) => {
|
|
262
|
+
if (typeof item === "string") {
|
|
263
|
+
const data = this.registry[item];
|
|
264
|
+
if (!data)
|
|
265
|
+
console.warn(`[markmap-toolbar] ${item} not found`);
|
|
266
|
+
return data;
|
|
267
|
+
}
|
|
268
|
+
return item;
|
|
269
|
+
}).filter(Boolean);
|
|
270
|
+
while (this.el.firstChild) {
|
|
271
|
+
this.el.firstChild.remove();
|
|
291
272
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
273
|
+
this.el.append(
|
|
274
|
+
mountDom(
|
|
275
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
276
|
+
this.showBrand && renderBrand(),
|
|
277
|
+
items.map(renderItem)
|
|
278
|
+
] })
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
return this.el;
|
|
296
282
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
exports.Toolbar = Toolbar;
|
|
306
|
-
|
|
307
|
-
}));
|
|
283
|
+
};
|
|
284
|
+
_Toolbar.defaultItems = [
|
|
285
|
+
"zoomIn",
|
|
286
|
+
"zoomOut",
|
|
287
|
+
"fit",
|
|
288
|
+
"recurse"
|
|
289
|
+
];
|
|
290
|
+
let Toolbar = _Toolbar;
|
|
291
|
+
exports.Toolbar = Toolbar;
|
|
292
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
293
|
+
})(this.markmap = this.markmap || {});
|
package/dist/index.mjs
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
|
-
/*! markmap-toolbar v0.15.5-alpha.1+013bf59 | MIT License */
|
|
2
|
-
function _extends() {
|
|
3
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
4
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
5
|
-
var source = arguments[i];
|
|
6
|
-
for (var key in source) {
|
|
7
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
|
-
target[key] = source[key];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return target;
|
|
13
|
-
};
|
|
14
|
-
return _extends.apply(this, arguments);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
1
|
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */
|
|
18
2
|
const VTYPE_ELEMENT = 1;
|
|
19
3
|
const VTYPE_FUNCTION = 2;
|
|
20
|
-
const SVG_NS =
|
|
21
|
-
const XLINK_NS =
|
|
4
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
5
|
+
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
22
6
|
const NS_ATTRS = {
|
|
23
7
|
show: XLINK_NS,
|
|
24
8
|
actuate: XLINK_NS,
|
|
25
9
|
href: XLINK_NS
|
|
26
10
|
};
|
|
27
|
-
const isLeaf = c => typeof c ===
|
|
28
|
-
const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
29
|
-
const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
11
|
+
const isLeaf = (c) => typeof c === "string" || typeof c === "number";
|
|
12
|
+
const isElement = (c) => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
13
|
+
const isRenderFunction = (c) => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
30
14
|
function jsx(type, props) {
|
|
31
15
|
let vtype;
|
|
32
|
-
if (typeof type ===
|
|
16
|
+
if (typeof type === "string")
|
|
17
|
+
vtype = VTYPE_ELEMENT;
|
|
18
|
+
else if (typeof type === "function")
|
|
19
|
+
vtype = VTYPE_FUNCTION;
|
|
20
|
+
else
|
|
21
|
+
throw new Error("Invalid VNode type");
|
|
33
22
|
return {
|
|
34
23
|
vtype,
|
|
35
24
|
type,
|
|
@@ -44,19 +33,23 @@ const DEFAULT_ENV = {
|
|
|
44
33
|
isSvg: false
|
|
45
34
|
};
|
|
46
35
|
function insertDom(parent, nodes) {
|
|
47
|
-
if (!Array.isArray(nodes))
|
|
36
|
+
if (!Array.isArray(nodes))
|
|
37
|
+
nodes = [nodes];
|
|
48
38
|
nodes = nodes.filter(Boolean);
|
|
49
|
-
if (nodes.length)
|
|
39
|
+
if (nodes.length)
|
|
40
|
+
parent.append(...nodes);
|
|
50
41
|
}
|
|
51
42
|
function mountAttributes(domElement, props, env) {
|
|
52
43
|
for (const key in props) {
|
|
53
|
-
if (key ===
|
|
54
|
-
|
|
44
|
+
if (key === "key" || key === "children" || key === "ref")
|
|
45
|
+
continue;
|
|
46
|
+
if (key === "dangerouslySetInnerHTML") {
|
|
55
47
|
domElement.innerHTML = props[key].__html;
|
|
56
|
-
} else if (key ===
|
|
48
|
+
} else if (key === "innerHTML" || key === "textContent" || key === "innerText" || key === "value" && ["textarea", "select"].includes(domElement.tagName)) {
|
|
57
49
|
const value = props[key];
|
|
58
|
-
if (value != null)
|
|
59
|
-
|
|
50
|
+
if (value != null)
|
|
51
|
+
domElement[key] = value;
|
|
52
|
+
} else if (key.startsWith("on")) {
|
|
60
53
|
domElement[key.toLowerCase()] = props[key];
|
|
61
54
|
} else {
|
|
62
55
|
setDOMAttribute(domElement, key, props[key], env.isSvg);
|
|
@@ -64,18 +57,18 @@ function mountAttributes(domElement, props, env) {
|
|
|
64
57
|
}
|
|
65
58
|
}
|
|
66
59
|
const attrMap = {
|
|
67
|
-
className:
|
|
68
|
-
labelFor:
|
|
60
|
+
className: "class",
|
|
61
|
+
labelFor: "for"
|
|
69
62
|
};
|
|
70
63
|
function setDOMAttribute(el, attr, value, isSVG) {
|
|
71
64
|
attr = attrMap[attr] || attr;
|
|
72
65
|
if (value === true) {
|
|
73
|
-
el.setAttribute(attr,
|
|
66
|
+
el.setAttribute(attr, "");
|
|
74
67
|
} else if (value === false) {
|
|
75
68
|
el.removeAttribute(attr);
|
|
76
69
|
} else {
|
|
77
|
-
const namespace = isSVG ? NS_ATTRS[attr] :
|
|
78
|
-
if (namespace !==
|
|
70
|
+
const namespace = isSVG ? NS_ATTRS[attr] : void 0;
|
|
71
|
+
if (namespace !== void 0) {
|
|
79
72
|
el.setAttributeNS(namespace, attr, value);
|
|
80
73
|
} else {
|
|
81
74
|
el.setAttribute(attr, value);
|
|
@@ -86,10 +79,10 @@ function flatten(arr) {
|
|
|
86
79
|
return arr.reduce((prev, item) => prev.concat(item), []);
|
|
87
80
|
}
|
|
88
81
|
function mountChildren(children, env) {
|
|
89
|
-
return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
|
|
82
|
+
return Array.isArray(children) ? flatten(children.map((child) => mountChildren(child, env))) : mount(children, env);
|
|
90
83
|
}
|
|
91
84
|
function mount(vnode, env = DEFAULT_ENV) {
|
|
92
|
-
if (vnode == null || typeof vnode ===
|
|
85
|
+
if (vnode == null || typeof vnode === "boolean") {
|
|
93
86
|
return null;
|
|
94
87
|
}
|
|
95
88
|
if (vnode instanceof Node) {
|
|
@@ -120,7 +113,7 @@ function mount(vnode, env = DEFAULT_ENV) {
|
|
|
120
113
|
type,
|
|
121
114
|
props
|
|
122
115
|
} = vnode;
|
|
123
|
-
if (!env.isSvg && type ===
|
|
116
|
+
if (!env.isSvg && type === "svg") {
|
|
124
117
|
env = Object.assign({}, env, {
|
|
125
118
|
isSvg: true
|
|
126
119
|
});
|
|
@@ -133,129 +126,114 @@ function mount(vnode, env = DEFAULT_ENV) {
|
|
|
133
126
|
mountAttributes(node, props, env);
|
|
134
127
|
if (props.children) {
|
|
135
128
|
let childEnv = env;
|
|
136
|
-
if (env.isSvg && type ===
|
|
129
|
+
if (env.isSvg && type === "foreignObject") {
|
|
137
130
|
childEnv = Object.assign({}, childEnv, {
|
|
138
131
|
isSvg: false
|
|
139
132
|
});
|
|
140
133
|
}
|
|
141
134
|
const children = mountChildren(props.children, childEnv);
|
|
142
|
-
if (children != null)
|
|
135
|
+
if (children != null)
|
|
136
|
+
insertDom(node, children);
|
|
143
137
|
}
|
|
144
138
|
const {
|
|
145
139
|
ref
|
|
146
140
|
} = props;
|
|
147
|
-
if (typeof ref ===
|
|
141
|
+
if (typeof ref === "function")
|
|
142
|
+
ref(node);
|
|
148
143
|
return node;
|
|
149
144
|
}
|
|
150
|
-
throw new Error(
|
|
145
|
+
throw new Error("mount: Invalid Vnode!");
|
|
151
146
|
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Mount vdom as real DOM nodes.
|
|
155
|
-
*/
|
|
156
147
|
function mountDom(vnode) {
|
|
157
148
|
return mount(vnode);
|
|
158
149
|
}
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
const clsActive = 'active';
|
|
150
|
+
const clsToolbarItem = "mm-toolbar-item";
|
|
151
|
+
const clsActive = "active";
|
|
162
152
|
function renderBrand() {
|
|
163
|
-
return jsxs("a", {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
})
|
|
172
|
-
});
|
|
153
|
+
return /* @__PURE__ */ jsxs("a", { className: "mm-toolbar-brand", href: "https://markmap.js.org/", children: [
|
|
154
|
+
/* @__PURE__ */ jsx(
|
|
155
|
+
"img",
|
|
156
|
+
{
|
|
157
|
+
alt: "markmap",
|
|
158
|
+
src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACoFBMVEUAAAAAAAD//wAAAACAgAD//wAAAABVVQCqqgBAQACAQACAgABmZgBtbQAAAABgQABgYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaFQAAAAAAAAAAAAAAAAAHAAARBQIdGAIYEwI/OgJYUQUfHQI+OgJDPgJJRARBPQRJQgRRSwRRTQRIQQRUTgRUUARZUgRSTQRPSQRjWgZORQRfWQZsZAhTTQRNRwRWUAZkXAZOSARUTgZPRwRRSQRoYwZWUQZWTgRbUwZmXQZoXghmXwdqYwdsYwdfVwVmXQdqYgdiWgVpYAl3bgl6cgl4cAqLggw8OAOWjA2Uig1OSAR2bQihlg55cAh5cAh6cQmMgwyOhAyUjA2QhQ2Uiw2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IAULe6E8YFCf8QAqEC86evniZTA4tfLsuRXHr0E4ly9ePF0uC3KnpH1MZBQQxPoVgxyZ5RMdBQaRMc6yIEcihWbQGaA3k9G8CfQoN0pAtSoxCMACihk9qGtBQZ2LHtRIkRUMiqwd2TJADiswsrjQlAGju/o+MLrPNkWo8mFN1ewMWmvBCebQ0rKMJG87QzF0FRwMRuvugpLcrXu3rp7Zs61UCtMZ2nVHbk+fMX/+jMmTp3Sf9MLiULG45q237txaPG3yxPYrYQzYMo60RWbD3E27Ll68Uq+AK+uJqOlZBiSEKGLNnMA0iDfzwrI/NKgBOivk9piPdtUAAAAASUVORK5CYII="
|
|
159
|
+
}
|
|
160
|
+
),
|
|
161
|
+
/* @__PURE__ */ jsx("span", { children: "markmap" })
|
|
162
|
+
] });
|
|
173
163
|
}
|
|
174
|
-
function renderItem({
|
|
175
|
-
title,
|
|
176
|
-
content,
|
|
177
|
-
onClick
|
|
178
|
-
}) {
|
|
179
|
-
return jsx("div", {
|
|
180
|
-
className: clsToolbarItem,
|
|
181
|
-
title: title,
|
|
182
|
-
onClick: onClick,
|
|
183
|
-
children: content
|
|
184
|
-
});
|
|
164
|
+
function renderItem({ title, content, onClick }) {
|
|
165
|
+
return /* @__PURE__ */ jsx("div", { className: clsToolbarItem, title, onClick, children: content });
|
|
185
166
|
}
|
|
186
167
|
let promise;
|
|
187
168
|
function safeCaller(fn) {
|
|
188
169
|
return async (...args) => {
|
|
189
|
-
if (promise)
|
|
170
|
+
if (promise)
|
|
171
|
+
return;
|
|
190
172
|
promise = fn(...args);
|
|
191
173
|
try {
|
|
192
174
|
await promise;
|
|
193
175
|
} finally {
|
|
194
|
-
promise =
|
|
176
|
+
promise = void 0;
|
|
195
177
|
}
|
|
196
178
|
};
|
|
197
179
|
}
|
|
198
|
-
class
|
|
199
|
-
static create(mm) {
|
|
200
|
-
const toolbar = new Toolbar();
|
|
201
|
-
toolbar.attach(mm);
|
|
202
|
-
return toolbar;
|
|
203
|
-
}
|
|
204
|
-
static icon(path, attrs = {}) {
|
|
205
|
-
attrs = _extends({
|
|
206
|
-
stroke: 'none',
|
|
207
|
-
fill: 'currentColor',
|
|
208
|
-
'fill-rule': 'evenodd'
|
|
209
|
-
}, attrs);
|
|
210
|
-
return jsx("svg", {
|
|
211
|
-
width: "20",
|
|
212
|
-
height: "20",
|
|
213
|
-
viewBox: "0 0 20 20",
|
|
214
|
-
children: jsx("path", _extends({}, attrs, {
|
|
215
|
-
d: path
|
|
216
|
-
}))
|
|
217
|
-
});
|
|
218
|
-
}
|
|
180
|
+
const _Toolbar = class _Toolbar {
|
|
219
181
|
constructor() {
|
|
220
182
|
this.showBrand = true;
|
|
221
183
|
this.registry = {};
|
|
222
|
-
this.el = mountDom(jsx("div", {
|
|
223
|
-
|
|
224
|
-
}));
|
|
225
|
-
this.items = [...Toolbar.defaultItems];
|
|
184
|
+
this.el = mountDom(/* @__PURE__ */ jsx("div", { className: "mm-toolbar" }));
|
|
185
|
+
this.items = [..._Toolbar.defaultItems];
|
|
226
186
|
this.register({
|
|
227
|
-
id:
|
|
228
|
-
title:
|
|
229
|
-
content:
|
|
230
|
-
onClick: this.getHandler(mm => mm.rescale(1.25))
|
|
187
|
+
id: "zoomIn",
|
|
188
|
+
title: "Zoom in",
|
|
189
|
+
content: _Toolbar.icon("M9 5v4h-4v2h4v4h2v-4h4v-2h-4v-4z"),
|
|
190
|
+
onClick: this.getHandler((mm) => mm.rescale(1.25))
|
|
231
191
|
});
|
|
232
192
|
this.register({
|
|
233
|
-
id:
|
|
234
|
-
title:
|
|
235
|
-
content:
|
|
236
|
-
onClick: this.getHandler(mm => mm.rescale(0.8))
|
|
193
|
+
id: "zoomOut",
|
|
194
|
+
title: "Zoom out",
|
|
195
|
+
content: _Toolbar.icon("M5 9h10v2h-10z"),
|
|
196
|
+
onClick: this.getHandler((mm) => mm.rescale(0.8))
|
|
237
197
|
});
|
|
238
198
|
this.register({
|
|
239
|
-
id:
|
|
240
|
-
title:
|
|
241
|
-
content:
|
|
242
|
-
|
|
199
|
+
id: "fit",
|
|
200
|
+
title: "Fit window size",
|
|
201
|
+
content: _Toolbar.icon(
|
|
202
|
+
"M4 7h2v-2h2v4h-4zM4 13h2v2h2v-4h-4zM16 7h-2v-2h-2v4h4zM16 13h-2v2h-2v-4h4z"
|
|
203
|
+
),
|
|
204
|
+
onClick: this.getHandler((mm) => mm.fit())
|
|
243
205
|
});
|
|
244
206
|
this.register({
|
|
245
|
-
id:
|
|
246
|
-
title:
|
|
247
|
-
content:
|
|
248
|
-
onClick: e => {
|
|
249
|
-
var
|
|
250
|
-
const button = e.target.closest(
|
|
207
|
+
id: "recurse",
|
|
208
|
+
title: "Toggle recursively",
|
|
209
|
+
content: _Toolbar.icon("M16 4h-12v12h12v-8h-8v4h2v-2h4v4h-8v-8h10z"),
|
|
210
|
+
onClick: (e) => {
|
|
211
|
+
var _a;
|
|
212
|
+
const button = e.target.closest(
|
|
213
|
+
`.${clsToolbarItem}`
|
|
214
|
+
);
|
|
251
215
|
const active = button == null ? void 0 : button.classList.toggle(clsActive);
|
|
252
|
-
(
|
|
216
|
+
(_a = this.markmap) == null ? void 0 : _a.setOptions({
|
|
253
217
|
toggleRecursively: active
|
|
254
218
|
});
|
|
255
219
|
}
|
|
256
220
|
});
|
|
257
221
|
this.render();
|
|
258
222
|
}
|
|
223
|
+
static create(mm) {
|
|
224
|
+
const toolbar = new _Toolbar();
|
|
225
|
+
toolbar.attach(mm);
|
|
226
|
+
return toolbar;
|
|
227
|
+
}
|
|
228
|
+
static icon(path, attrs = {}) {
|
|
229
|
+
attrs = {
|
|
230
|
+
stroke: "none",
|
|
231
|
+
fill: "currentColor",
|
|
232
|
+
"fill-rule": "evenodd",
|
|
233
|
+
...attrs
|
|
234
|
+
};
|
|
235
|
+
return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 20 20", children: /* @__PURE__ */ jsx("path", { ...attrs, d: path }) });
|
|
236
|
+
}
|
|
259
237
|
setBrand(show) {
|
|
260
238
|
this.showBrand = show;
|
|
261
239
|
return this.render();
|
|
@@ -266,7 +244,8 @@ class Toolbar {
|
|
|
266
244
|
getHandler(handle) {
|
|
267
245
|
handle = safeCaller(handle);
|
|
268
246
|
return () => {
|
|
269
|
-
if (this.markmap)
|
|
247
|
+
if (this.markmap)
|
|
248
|
+
handle(this.markmap);
|
|
270
249
|
};
|
|
271
250
|
}
|
|
272
251
|
setItems(items) {
|
|
@@ -277,10 +256,11 @@ class Toolbar {
|
|
|
277
256
|
this.markmap = mm;
|
|
278
257
|
}
|
|
279
258
|
render() {
|
|
280
|
-
const items = this.items.map(item => {
|
|
281
|
-
if (typeof item ===
|
|
259
|
+
const items = this.items.map((item) => {
|
|
260
|
+
if (typeof item === "string") {
|
|
282
261
|
const data = this.registry[item];
|
|
283
|
-
if (!data)
|
|
262
|
+
if (!data)
|
|
263
|
+
console.warn(`[markmap-toolbar] ${item} not found`);
|
|
284
264
|
return data;
|
|
285
265
|
}
|
|
286
266
|
return item;
|
|
@@ -288,12 +268,24 @@ class Toolbar {
|
|
|
288
268
|
while (this.el.firstChild) {
|
|
289
269
|
this.el.firstChild.remove();
|
|
290
270
|
}
|
|
291
|
-
this.el.append(
|
|
292
|
-
|
|
293
|
-
|
|
271
|
+
this.el.append(
|
|
272
|
+
mountDom(
|
|
273
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
274
|
+
this.showBrand && renderBrand(),
|
|
275
|
+
items.map(renderItem)
|
|
276
|
+
] })
|
|
277
|
+
)
|
|
278
|
+
);
|
|
294
279
|
return this.el;
|
|
295
280
|
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
281
|
+
};
|
|
282
|
+
_Toolbar.defaultItems = [
|
|
283
|
+
"zoomIn",
|
|
284
|
+
"zoomOut",
|
|
285
|
+
"fit",
|
|
286
|
+
"recurse"
|
|
287
|
+
];
|
|
288
|
+
let Toolbar = _Toolbar;
|
|
289
|
+
export {
|
|
290
|
+
Toolbar
|
|
291
|
+
};
|
package/dist/style.css
CHANGED
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
}
|
|
25
25
|
.mm-toolbar-brand.active, .mm-toolbar-item.active {--un-bg-opacity:1;background-color:rgba(209,213,219,var(--un-bg-opacity));
|
|
26
26
|
}
|
|
27
|
-
.mm-toolbar {display:flex;-moz-user-select:none;user-select:none;align-items:center;border-width:1px;--un-border-opacity:1;border-color:rgba(209,213,219,var(--un-border-opacity));border-radius:0.25rem;border-style:solid;--un-bg-opacity:1;background-color:rgba(255,255,255,var(--un-bg-opacity));padding:0.25rem;line-height:1;
|
|
27
|
+
.mm-toolbar {display:flex;-webkit-user-select:none;-moz-user-select:none;user-select:none;align-items:center;border-width:1px;--un-border-opacity:1;border-color:rgba(209,213,219,var(--un-border-opacity));border-radius:0.25rem;border-style:solid;--un-bg-opacity:1;background-color:rgba(255,255,255,var(--un-bg-opacity));padding:0.25rem;line-height:1;
|
|
28
28
|
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-toolbar",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.6-alpha.4+4734119",
|
|
4
4
|
"description": "Extensible toolbar for markmap",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
-
"clean": "del-cli dist types",
|
|
8
|
+
"clean": "del-cli dist",
|
|
10
9
|
"build:types": "tsc",
|
|
11
|
-
"build:js": "
|
|
10
|
+
"build:js": "vite build && TARGET=es vite build --emptyOutDir=false"
|
|
12
11
|
},
|
|
13
12
|
"main": "dist/index.js",
|
|
14
13
|
"module": "dist/index.mjs",
|
|
15
14
|
"unpkg": "dist/index.js",
|
|
16
15
|
"jsdelivr": "dist/index.js",
|
|
17
16
|
"files": [
|
|
18
|
-
"dist"
|
|
19
|
-
"types"
|
|
17
|
+
"dist"
|
|
20
18
|
],
|
|
21
19
|
"publishConfig": {
|
|
22
20
|
"access": "public",
|
|
@@ -30,17 +28,17 @@
|
|
|
30
28
|
"bugs": {
|
|
31
29
|
"url": "https://github.com/markmap/markmap/issues"
|
|
32
30
|
},
|
|
33
|
-
"typings": "
|
|
31
|
+
"typings": "dist/index.d.ts",
|
|
34
32
|
"peerDependencies": {
|
|
35
33
|
"markmap-common": "*"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
|
-
"markmap-common": "0.15.5
|
|
39
|
-
"markmap-view": "0.15.
|
|
36
|
+
"markmap-common": "0.15.5",
|
|
37
|
+
"markmap-view": "0.15.6-alpha.4+4734119"
|
|
40
38
|
},
|
|
41
39
|
"dependencies": {
|
|
42
40
|
"@babel/runtime": "^7.22.6",
|
|
43
41
|
"@gera2ld/jsx-dom": "^2.2.2"
|
|
44
42
|
},
|
|
45
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "473411985496abcc20a546978438614c48ec56cf"
|
|
46
44
|
}
|
|
File without changes
|
|
File without changes
|