markmap-toolbar 0.14.5-alpha.15 → 0.14.5-alpha.17
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 +70 -118
- package/dist/index.mjs +5 -6
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! markmap-toolbar v0.14.5-alpha.
|
|
1
|
+
/*! markmap-toolbar v0.14.5-alpha.17+0d6a717 | MIT License */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -20,61 +20,48 @@ function _extends() {
|
|
|
20
20
|
return _extends.apply(this, arguments);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/*! @gera2ld/jsx-dom v2.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
30
|
-
var NS_ATTRS = {
|
|
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 = {
|
|
31
29
|
show: XLINK_NS,
|
|
32
30
|
actuate: XLINK_NS,
|
|
33
31
|
href: XLINK_NS
|
|
34
32
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var isElement = function isElement(c) {
|
|
39
|
-
return (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT;
|
|
40
|
-
};
|
|
41
|
-
var isRenderFunction = function isRenderFunction(c) {
|
|
42
|
-
return (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION;
|
|
43
|
-
};
|
|
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;
|
|
44
36
|
function jsx(type, props) {
|
|
45
|
-
|
|
37
|
+
let vtype;
|
|
46
38
|
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type');
|
|
47
39
|
return {
|
|
48
|
-
vtype
|
|
49
|
-
type
|
|
50
|
-
props
|
|
40
|
+
vtype,
|
|
41
|
+
type,
|
|
42
|
+
props
|
|
51
43
|
};
|
|
52
44
|
}
|
|
53
|
-
|
|
45
|
+
const jsxs = jsx;
|
|
54
46
|
function Fragment(props) {
|
|
55
47
|
return props.children;
|
|
56
48
|
}
|
|
57
|
-
|
|
49
|
+
const DEFAULT_ENV = {
|
|
58
50
|
isSvg: false
|
|
59
51
|
};
|
|
60
|
-
function insertDom(parent,
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ref.children.forEach(function (ch) {
|
|
65
|
-
insertDom(parent, ch);
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
throw new Error("Unkown ref type " + JSON.stringify(ref));
|
|
69
|
-
}
|
|
52
|
+
function insertDom(parent, nodes) {
|
|
53
|
+
if (!Array.isArray(nodes)) nodes = [nodes];
|
|
54
|
+
nodes = nodes.filter(Boolean);
|
|
55
|
+
if (nodes.length) parent.append(...nodes);
|
|
70
56
|
}
|
|
71
57
|
function mountAttributes(domElement, props, env) {
|
|
72
|
-
for (
|
|
58
|
+
for (const key in props) {
|
|
73
59
|
if (key === 'key' || key === 'children' || key === 'ref') continue;
|
|
74
60
|
if (key === 'dangerouslySetInnerHTML') {
|
|
75
61
|
domElement.innerHTML = props[key].__html;
|
|
76
|
-
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') {
|
|
77
|
-
|
|
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;
|
|
78
65
|
} else if (key.startsWith('on')) {
|
|
79
66
|
domElement[key.toLowerCase()] = props[key];
|
|
80
67
|
} else {
|
|
@@ -82,7 +69,7 @@ function mountAttributes(domElement, props, env) {
|
|
|
82
69
|
}
|
|
83
70
|
}
|
|
84
71
|
}
|
|
85
|
-
|
|
72
|
+
const attrMap = {
|
|
86
73
|
className: 'class',
|
|
87
74
|
labelFor: 'for'
|
|
88
75
|
};
|
|
@@ -93,7 +80,7 @@ function setDOMAttribute(el, attr, value, isSVG) {
|
|
|
93
80
|
} else if (value === false) {
|
|
94
81
|
el.removeAttribute(attr);
|
|
95
82
|
} else {
|
|
96
|
-
|
|
83
|
+
const namespace = isSVG ? NS_ATTRS[attr] : undefined;
|
|
97
84
|
if (namespace !== undefined) {
|
|
98
85
|
el.setAttributeNS(namespace, attr, value);
|
|
99
86
|
} else {
|
|
@@ -101,113 +88,79 @@ function setDOMAttribute(el, attr, value, isSVG) {
|
|
|
101
88
|
}
|
|
102
89
|
}
|
|
103
90
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
function flatten(arr) {
|
|
92
|
+
return arr.reduce((prev, item) => prev.concat(item), []);
|
|
93
|
+
}
|
|
94
|
+
function mountChildren(children, env) {
|
|
95
|
+
return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env);
|
|
96
|
+
}
|
|
97
|
+
function mount(vnode, env = DEFAULT_ENV) {
|
|
108
98
|
if (vnode == null || typeof vnode === 'boolean') {
|
|
109
|
-
return
|
|
110
|
-
type: MOUNT_SINGLE,
|
|
111
|
-
node: null
|
|
112
|
-
};
|
|
99
|
+
return null;
|
|
113
100
|
}
|
|
114
101
|
if (vnode instanceof Node) {
|
|
115
|
-
return
|
|
116
|
-
type: MOUNT_SINGLE,
|
|
117
|
-
node: vnode
|
|
118
|
-
};
|
|
102
|
+
return vnode;
|
|
119
103
|
}
|
|
120
104
|
if (isRenderFunction(vnode)) {
|
|
121
|
-
|
|
122
|
-
type
|
|
123
|
-
props
|
|
105
|
+
const {
|
|
106
|
+
type,
|
|
107
|
+
props
|
|
108
|
+
} = vnode;
|
|
124
109
|
if (type === Fragment) {
|
|
125
|
-
|
|
110
|
+
const node = document.createDocumentFragment();
|
|
126
111
|
if (props.children) {
|
|
127
|
-
|
|
128
|
-
insertDom(node,
|
|
112
|
+
const children = mountChildren(props.children, env);
|
|
113
|
+
insertDom(node, children);
|
|
129
114
|
}
|
|
130
|
-
return
|
|
131
|
-
type: MOUNT_SINGLE,
|
|
132
|
-
node: node
|
|
133
|
-
};
|
|
115
|
+
return node;
|
|
134
116
|
}
|
|
135
|
-
|
|
117
|
+
const childVNode = type(props);
|
|
136
118
|
return mount(childVNode, env);
|
|
137
119
|
}
|
|
138
120
|
if (isLeaf(vnode)) {
|
|
139
|
-
return {
|
|
140
|
-
type: MOUNT_SINGLE,
|
|
141
|
-
node: document.createTextNode("" + vnode)
|
|
142
|
-
};
|
|
121
|
+
return document.createTextNode(`${vnode}`);
|
|
143
122
|
}
|
|
144
123
|
if (isElement(vnode)) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
124
|
+
let node;
|
|
125
|
+
const {
|
|
126
|
+
type,
|
|
127
|
+
props
|
|
128
|
+
} = vnode;
|
|
129
|
+
if (!env.isSvg && type === 'svg') {
|
|
150
130
|
env = Object.assign({}, env, {
|
|
151
131
|
isSvg: true
|
|
152
132
|
});
|
|
153
133
|
}
|
|
154
134
|
if (!env.isSvg) {
|
|
155
|
-
|
|
135
|
+
node = document.createElement(type);
|
|
156
136
|
} else {
|
|
157
|
-
|
|
137
|
+
node = document.createElementNS(SVG_NS, type);
|
|
158
138
|
}
|
|
159
|
-
mountAttributes(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (env.isSvg && _type === 'foreignObject') {
|
|
139
|
+
mountAttributes(node, props, env);
|
|
140
|
+
if (props.children) {
|
|
141
|
+
let childEnv = env;
|
|
142
|
+
if (env.isSvg && type === 'foreignObject') {
|
|
164
143
|
childEnv = Object.assign({}, childEnv, {
|
|
165
144
|
isSvg: false
|
|
166
145
|
});
|
|
167
146
|
}
|
|
168
|
-
|
|
147
|
+
const children = mountChildren(props.children, childEnv);
|
|
148
|
+
if (children != null) insertDom(node, children);
|
|
169
149
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
node: _node
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
if (Array.isArray(vnode)) {
|
|
179
|
-
return {
|
|
180
|
-
type: MOUNT_ARRAY,
|
|
181
|
-
children: vnode.map(function (child) {
|
|
182
|
-
return mount(child, env);
|
|
183
|
-
})
|
|
184
|
-
};
|
|
150
|
+
const {
|
|
151
|
+
ref
|
|
152
|
+
} = props;
|
|
153
|
+
if (typeof ref === 'function') ref(node);
|
|
154
|
+
return node;
|
|
185
155
|
}
|
|
186
156
|
throw new Error('mount: Invalid Vnode!');
|
|
187
157
|
}
|
|
188
|
-
|
|
189
|
-
var result = [];
|
|
190
|
-
for (var i = 0; i < array.length; i += 1) {
|
|
191
|
-
var item = array[i];
|
|
192
|
-
if (Array.isArray(item)) result = result.concat(flattenWithoutNull(item));else if (item != null) result.push(item);
|
|
193
|
-
}
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
function asDom(result) {
|
|
197
|
-
if (result.type === MOUNT_SINGLE) {
|
|
198
|
-
return result.node;
|
|
199
|
-
}
|
|
200
|
-
return result.children.map(asDom);
|
|
201
|
-
}
|
|
158
|
+
|
|
202
159
|
/**
|
|
203
160
|
* Mount vdom as real DOM nodes.
|
|
204
161
|
*/
|
|
205
|
-
|
|
206
162
|
function mountDom(vnode) {
|
|
207
|
-
|
|
208
|
-
return flattenWithoutNull(vnode.map(mountDom));
|
|
209
|
-
}
|
|
210
|
-
return asDom(mount(vnode));
|
|
163
|
+
return mount(vnode);
|
|
211
164
|
}
|
|
212
165
|
|
|
213
166
|
const clsToolbarItem = 'mm-toolbar-item';
|
|
@@ -244,7 +197,7 @@ function safeCaller(fn) {
|
|
|
244
197
|
try {
|
|
245
198
|
await promise;
|
|
246
199
|
} finally {
|
|
247
|
-
promise =
|
|
200
|
+
promise = undefined;
|
|
248
201
|
}
|
|
249
202
|
};
|
|
250
203
|
}
|
|
@@ -273,7 +226,6 @@ class Toolbar {
|
|
|
273
226
|
constructor() {
|
|
274
227
|
this.showBrand = true;
|
|
275
228
|
this.registry = {};
|
|
276
|
-
this.markmap = null;
|
|
277
229
|
this.el = mountDom(jsx("div", {
|
|
278
230
|
className: "mm-toolbar"
|
|
279
231
|
}));
|
|
@@ -300,10 +252,10 @@ class Toolbar {
|
|
|
300
252
|
title: 'Toggle recursively',
|
|
301
253
|
content: Toolbar.icon('M16 4h-12v12h12v-8h-8v4h2v-2h4v4h-8v-8h10z'),
|
|
302
254
|
onClick: e => {
|
|
255
|
+
var _this$markmap;
|
|
303
256
|
const button = e.target.closest(`.${clsToolbarItem}`);
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
this.markmap.setOptions({
|
|
257
|
+
const active = button == null ? void 0 : button.classList.toggle(clsActive);
|
|
258
|
+
(_this$markmap = this.markmap) == null ? void 0 : _this$markmap.setOptions({
|
|
307
259
|
toggleRecursively: active
|
|
308
260
|
});
|
|
309
261
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! markmap-toolbar v0.14.5-alpha.
|
|
1
|
+
/*! markmap-toolbar v0.14.5-alpha.17+0d6a717 | MIT License */
|
|
2
2
|
import { mountDom } from '@gera2ld/jsx-dom';
|
|
3
3
|
import { jsx, jsxs, Fragment } from '@gera2ld/jsx-dom/jsx-runtime';
|
|
4
4
|
|
|
@@ -51,7 +51,7 @@ function safeCaller(fn) {
|
|
|
51
51
|
try {
|
|
52
52
|
await promise;
|
|
53
53
|
} finally {
|
|
54
|
-
promise =
|
|
54
|
+
promise = undefined;
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
}
|
|
@@ -80,7 +80,6 @@ class Toolbar {
|
|
|
80
80
|
constructor() {
|
|
81
81
|
this.showBrand = true;
|
|
82
82
|
this.registry = {};
|
|
83
|
-
this.markmap = null;
|
|
84
83
|
this.el = mountDom(jsx("div", {
|
|
85
84
|
className: "mm-toolbar"
|
|
86
85
|
}));
|
|
@@ -107,10 +106,10 @@ class Toolbar {
|
|
|
107
106
|
title: 'Toggle recursively',
|
|
108
107
|
content: Toolbar.icon('M16 4h-12v12h12v-8h-8v4h2v-2h4v4h-8v-8h10z'),
|
|
109
108
|
onClick: e => {
|
|
109
|
+
var _this$markmap;
|
|
110
110
|
const button = e.target.closest(`.${clsToolbarItem}`);
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
this.markmap.setOptions({
|
|
111
|
+
const active = button == null ? void 0 : button.classList.toggle(clsActive);
|
|
112
|
+
(_this$markmap = this.markmap) == null ? void 0 : _this$markmap.setOptions({
|
|
114
113
|
toggleRecursively: active
|
|
115
114
|
});
|
|
116
115
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-toolbar",
|
|
3
|
-
"version": "0.14.5-alpha.
|
|
3
|
+
"version": "0.14.5-alpha.17+0d6a717",
|
|
4
4
|
"description": "Extensible toolbar for markmap",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"markmap-common": "*"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"markmap-common": "0.14.
|
|
39
|
-
"markmap-view": "0.14.5-alpha.
|
|
38
|
+
"markmap-common": "0.14.2",
|
|
39
|
+
"markmap-view": "0.14.5-alpha.17+0d6a717"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/runtime": "^7.16.3",
|
|
43
|
-
"@gera2ld/jsx-dom": "^2.
|
|
43
|
+
"@gera2ld/jsx-dom": "^2.2.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "0d6a717b05c622a23faa501e79a7da7cda3ea0b6"
|
|
46
46
|
}
|