markmap-toolbar 0.15.0-alpha.1 → 0.15.3-alpha.1

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 CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-toolbar v0.15.0-alpha.1+1308d8e | MIT License */
1
+ /*! markmap-toolbar v0.15.3-alpha.1+fb5e189 | 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.1.1 | ISC License */
24
- var VTYPE_ELEMENT = 1;
25
- var VTYPE_FUNCTION = 2;
26
- var MOUNT_SINGLE = 1;
27
- var MOUNT_ARRAY = 4;
28
- var SVG_NS = 'http://www.w3.org/2000/svg';
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
- var isLeaf = function isLeaf(c) {
36
- return typeof c === 'string' || typeof c === 'number';
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
- var vtype;
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: vtype,
49
- type: type,
50
- props: props
40
+ vtype,
41
+ type,
42
+ props
51
43
  };
52
44
  }
53
- var jsxs = jsx;
45
+ const jsxs = jsx;
54
46
  function Fragment(props) {
55
47
  return props.children;
56
48
  }
57
- var DEFAULT_ENV = {
49
+ const DEFAULT_ENV = {
58
50
  isSvg: false
59
51
  };
60
- function insertDom(parent, ref) {
61
- if (ref.type === MOUNT_SINGLE) {
62
- if (ref.node != null) parent.append(ref.node);
63
- } else if (ref.type === MOUNT_ARRAY) {
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 (var key in props) {
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
- domElement[key] = props[key];
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
- var attrMap = {
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
- var namespace = isSVG ? NS_ATTRS[attr] : undefined;
83
+ const namespace = isSVG ? NS_ATTRS[attr] : undefined;
97
84
  if (namespace !== undefined) {
98
85
  el.setAttributeNS(namespace, attr, value);
99
86
  } else {
@@ -101,116 +88,83 @@ function setDOMAttribute(el, attr, value, isSVG) {
101
88
  }
102
89
  }
103
90
  }
104
- function mount(vnode, env) {
105
- if (env === void 0) {
106
- env = DEFAULT_ENV;
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
- var _ref = vnode,
122
- type = _ref.type,
123
- props = _ref.props;
105
+ const {
106
+ type,
107
+ props
108
+ } = vnode;
124
109
  if (type === Fragment) {
125
- var node = document.createDocumentFragment();
110
+ const node = document.createDocumentFragment();
126
111
  if (props.children) {
127
- var childrenRef = mount(props.children, env);
128
- insertDom(node, childrenRef);
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
- var childVNode = type(props);
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
- var _node;
146
- var _ref2 = vnode,
147
- _type = _ref2.type,
148
- _props = _ref2.props;
149
- if (!env.isSvg && _type === 'svg') {
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
- _node = document.createElement(_type);
135
+ node = document.createElement(type);
156
136
  } else {
157
- _node = document.createElementNS(SVG_NS, _type);
137
+ node = document.createElementNS(SVG_NS, type);
158
138
  }
159
- mountAttributes(_node, _props, env);
160
- var _childrenRef;
161
- if (_props.children) {
162
- var childEnv = env;
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
- _childrenRef = mount(_props.children, childEnv);
147
+ const children = mountChildren(props.children, childEnv);
148
+ if (children != null) insertDom(node, children);
169
149
  }
170
- if (_childrenRef != null) insertDom(_node, _childrenRef);
171
- var ref = _props.ref;
172
- if (typeof ref === 'function') ref(_node);
173
- return {
174
- type: MOUNT_SINGLE,
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
- function flattenWithoutNull(array) {
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
- if (Array.isArray(vnode)) {
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';
167
+ const clsActive = 'active';
214
168
  function renderBrand() {
215
169
  return jsxs("a", {
216
170
  className: "mm-toolbar-brand",
@@ -243,7 +197,7 @@ function safeCaller(fn) {
243
197
  try {
244
198
  await promise;
245
199
  } finally {
246
- promise = null;
200
+ promise = undefined;
247
201
  }
248
202
  };
249
203
  }
@@ -251,7 +205,6 @@ class Toolbar {
251
205
  static create(mm) {
252
206
  const toolbar = new Toolbar();
253
207
  toolbar.attach(mm);
254
- toolbar.render();
255
208
  return toolbar;
256
209
  }
257
210
  static icon(path, attrs = {}) {
@@ -272,10 +225,10 @@ class Toolbar {
272
225
  constructor() {
273
226
  this.showBrand = true;
274
227
  this.registry = {};
275
- this.markmap = null;
276
228
  this.el = mountDom(jsx("div", {
277
229
  className: "mm-toolbar"
278
230
  }));
231
+ this.items = [...Toolbar.defaultItems];
279
232
  this.register({
280
233
  id: 'zoomIn',
281
234
  title: 'Zoom in',
@@ -294,7 +247,20 @@ class Toolbar {
294
247
  content: Toolbar.icon('M4 7h2v-2h2v4h-4zM4 13h2v2h2v-4h-4zM16 7h-2v-2h-2v4h4zM16 13h-2v2h-2v-4h4z'),
295
248
  onClick: this.getHandler(mm => mm.fit())
296
249
  });
297
- this.items = Toolbar.defaultItems;
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 ? void 0 : _this$markmap.setOptions({
259
+ toggleRecursively: active
260
+ });
261
+ }
262
+ });
263
+ this.render();
298
264
  }
299
265
  setBrand(show) {
300
266
  this.showBrand = show;
@@ -334,7 +300,7 @@ class Toolbar {
334
300
  return this.el;
335
301
  }
336
302
  }
337
- Toolbar.defaultItems = ['zoomIn', 'zoomOut', 'fit'];
303
+ Toolbar.defaultItems = ['zoomIn', 'zoomOut', 'fit', 'recurse'];
338
304
 
339
305
  exports.Toolbar = Toolbar;
340
306
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-toolbar v0.15.0-alpha.1+1308d8e | MIT License */
1
+ /*! markmap-toolbar v0.15.3-alpha.1+fb5e189 | MIT License */
2
2
  import { mountDom } from '@gera2ld/jsx-dom';
3
3
  import { jsx, jsxs, Fragment } from '@gera2ld/jsx-dom/jsx-runtime';
4
4
 
@@ -18,6 +18,7 @@ function _extends() {
18
18
  }
19
19
 
20
20
  const clsToolbarItem = 'mm-toolbar-item';
21
+ const clsActive = 'active';
21
22
  function renderBrand() {
22
23
  return jsxs("a", {
23
24
  className: "mm-toolbar-brand",
@@ -50,7 +51,7 @@ function safeCaller(fn) {
50
51
  try {
51
52
  await promise;
52
53
  } finally {
53
- promise = null;
54
+ promise = undefined;
54
55
  }
55
56
  };
56
57
  }
@@ -58,7 +59,6 @@ class Toolbar {
58
59
  static create(mm) {
59
60
  const toolbar = new Toolbar();
60
61
  toolbar.attach(mm);
61
- toolbar.render();
62
62
  return toolbar;
63
63
  }
64
64
  static icon(path, attrs = {}) {
@@ -79,10 +79,10 @@ class Toolbar {
79
79
  constructor() {
80
80
  this.showBrand = true;
81
81
  this.registry = {};
82
- this.markmap = null;
83
82
  this.el = mountDom(jsx("div", {
84
83
  className: "mm-toolbar"
85
84
  }));
85
+ this.items = [...Toolbar.defaultItems];
86
86
  this.register({
87
87
  id: 'zoomIn',
88
88
  title: 'Zoom in',
@@ -101,7 +101,20 @@ class Toolbar {
101
101
  content: Toolbar.icon('M4 7h2v-2h2v4h-4zM4 13h2v2h2v-4h-4zM16 7h-2v-2h-2v4h4zM16 13h-2v2h-2v-4h4z'),
102
102
  onClick: this.getHandler(mm => mm.fit())
103
103
  });
104
- this.items = Toolbar.defaultItems;
104
+ this.register({
105
+ id: 'recurse',
106
+ title: 'Toggle recursively',
107
+ content: Toolbar.icon('M16 4h-12v12h12v-8h-8v4h2v-2h4v4h-8v-8h10z'),
108
+ onClick: e => {
109
+ var _this$markmap;
110
+ const button = e.target.closest(`.${clsToolbarItem}`);
111
+ const active = button == null ? void 0 : button.classList.toggle(clsActive);
112
+ (_this$markmap = this.markmap) == null ? void 0 : _this$markmap.setOptions({
113
+ toggleRecursively: active
114
+ });
115
+ }
116
+ });
117
+ this.render();
105
118
  }
106
119
  setBrand(show) {
107
120
  this.showBrand = show;
@@ -141,6 +154,6 @@ class Toolbar {
141
154
  return this.el;
142
155
  }
143
156
  }
144
- Toolbar.defaultItems = ['zoomIn', 'zoomOut', 'fit'];
157
+ Toolbar.defaultItems = ['zoomIn', 'zoomOut', 'fit', 'recurse'];
145
158
 
146
159
  export { Toolbar };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-toolbar",
3
- "version": "0.15.0-alpha.1+1308d8e",
3
+ "version": "0.15.3-alpha.1+fb5e189",
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.15.0-alpha.0",
39
- "markmap-view": "0.15.0-alpha.0"
38
+ "markmap-common": "0.15.3-alpha.1+fb5e189",
39
+ "markmap-view": "0.15.3-alpha.1+fb5e189"
40
40
  },
41
41
  "dependencies": {
42
- "@babel/runtime": "^7.16.3",
43
- "@gera2ld/jsx-dom": "^2.1.1"
42
+ "@babel/runtime": "^7.22.6",
43
+ "@gera2ld/jsx-dom": "^2.2.2"
44
44
  },
45
- "gitHead": "1308d8ea5a6e6b24b6c5f053a50cc319df4ad93d"
45
+ "gitHead": "fb5e1891c9cfda0426feb8f43555f32c56648f10"
46
46
  }