markmap-toolbar
Advanced tools
Comparing version 0.14.5-alpha.15 to 0.14.5-alpha.16
@@ -1,2 +0,2 @@ | ||
/*! markmap-toolbar v0.14.5-alpha.15+1fe26c8 | MIT License */ | ||
/*! markmap-toolbar v0.14.5-alpha.16+33e8294 | MIT License */ | ||
(function (global, factory) { | ||
@@ -23,10 +23,8 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
/*! @gera2ld/jsx-dom v2.1.1 | ISC License */ | ||
var VTYPE_ELEMENT = 1; | ||
var VTYPE_FUNCTION = 2; | ||
var MOUNT_SINGLE = 1; | ||
var MOUNT_ARRAY = 4; | ||
var SVG_NS = 'http://www.w3.org/2000/svg'; | ||
var XLINK_NS = 'http://www.w3.org/1999/xlink'; | ||
var NS_ATTRS = { | ||
/*! @gera2ld/jsx-dom v2.2.2 | ISC License */ | ||
const VTYPE_ELEMENT = 1; | ||
const VTYPE_FUNCTION = 2; | ||
const SVG_NS = 'http://www.w3.org/2000/svg'; | ||
const XLINK_NS = 'http://www.w3.org/1999/xlink'; | ||
const NS_ATTRS = { | ||
show: XLINK_NS, | ||
@@ -36,45 +34,34 @@ actuate: XLINK_NS, | ||
}; | ||
var isLeaf = function isLeaf(c) { | ||
return typeof c === 'string' || typeof c === 'number'; | ||
}; | ||
var isElement = function isElement(c) { | ||
return (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT; | ||
}; | ||
var isRenderFunction = function isRenderFunction(c) { | ||
return (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION; | ||
}; | ||
const isLeaf = c => typeof c === 'string' || typeof c === 'number'; | ||
const isElement = c => (c == null ? void 0 : c.vtype) === VTYPE_ELEMENT; | ||
const isRenderFunction = c => (c == null ? void 0 : c.vtype) === VTYPE_FUNCTION; | ||
function jsx(type, props) { | ||
var vtype; | ||
let vtype; | ||
if (typeof type === 'string') vtype = VTYPE_ELEMENT;else if (typeof type === 'function') vtype = VTYPE_FUNCTION;else throw new Error('Invalid VNode type'); | ||
return { | ||
vtype: vtype, | ||
type: type, | ||
props: props | ||
vtype, | ||
type, | ||
props | ||
}; | ||
} | ||
var jsxs = jsx; | ||
const jsxs = jsx; | ||
function Fragment(props) { | ||
return props.children; | ||
} | ||
var DEFAULT_ENV = { | ||
const DEFAULT_ENV = { | ||
isSvg: false | ||
}; | ||
function insertDom(parent, ref) { | ||
if (ref.type === MOUNT_SINGLE) { | ||
if (ref.node != null) parent.append(ref.node); | ||
} else if (ref.type === MOUNT_ARRAY) { | ||
ref.children.forEach(function (ch) { | ||
insertDom(parent, ch); | ||
}); | ||
} else { | ||
throw new Error("Unkown ref type " + JSON.stringify(ref)); | ||
} | ||
function insertDom(parent, nodes) { | ||
if (!Array.isArray(nodes)) nodes = [nodes]; | ||
nodes = nodes.filter(Boolean); | ||
if (nodes.length) parent.append(...nodes); | ||
} | ||
function mountAttributes(domElement, props, env) { | ||
for (var key in props) { | ||
for (const key in props) { | ||
if (key === 'key' || key === 'children' || key === 'ref') continue; | ||
if (key === 'dangerouslySetInnerHTML') { | ||
domElement.innerHTML = props[key].__html; | ||
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText') { | ||
domElement[key] = props[key]; | ||
} else if (key === 'innerHTML' || key === 'textContent' || key === 'innerText' || key === 'value' && ['textarea', 'select'].includes(domElement.tagName)) { | ||
const value = props[key]; | ||
if (value != null) domElement[key] = value; | ||
} else if (key.startsWith('on')) { | ||
@@ -87,3 +74,3 @@ domElement[key.toLowerCase()] = props[key]; | ||
} | ||
var attrMap = { | ||
const attrMap = { | ||
className: 'class', | ||
@@ -99,3 +86,3 @@ labelFor: 'for' | ||
} else { | ||
var namespace = isSVG ? NS_ATTRS[attr] : undefined; | ||
const namespace = isSVG ? NS_ATTRS[attr] : undefined; | ||
if (namespace !== undefined) { | ||
@@ -108,48 +95,41 @@ el.setAttributeNS(namespace, attr, value); | ||
} | ||
function mount(vnode, env) { | ||
if (env === void 0) { | ||
env = DEFAULT_ENV; | ||
} | ||
function flatten(arr) { | ||
return arr.reduce((prev, item) => prev.concat(item), []); | ||
} | ||
function mountChildren(children, env) { | ||
return Array.isArray(children) ? flatten(children.map(child => mountChildren(child, env))) : mount(children, env); | ||
} | ||
function mount(vnode, env = DEFAULT_ENV) { | ||
if (vnode == null || typeof vnode === 'boolean') { | ||
return { | ||
type: MOUNT_SINGLE, | ||
node: null | ||
}; | ||
return null; | ||
} | ||
if (vnode instanceof Node) { | ||
return { | ||
type: MOUNT_SINGLE, | ||
node: vnode | ||
}; | ||
return vnode; | ||
} | ||
if (isRenderFunction(vnode)) { | ||
var _ref = vnode, | ||
type = _ref.type, | ||
props = _ref.props; | ||
const { | ||
type, | ||
props | ||
} = vnode; | ||
if (type === Fragment) { | ||
var node = document.createDocumentFragment(); | ||
const node = document.createDocumentFragment(); | ||
if (props.children) { | ||
var childrenRef = mount(props.children, env); | ||
insertDom(node, childrenRef); | ||
const children = mountChildren(props.children, env); | ||
insertDom(node, children); | ||
} | ||
return { | ||
type: MOUNT_SINGLE, | ||
node: node | ||
}; | ||
return node; | ||
} | ||
var childVNode = type(props); | ||
const childVNode = type(props); | ||
return mount(childVNode, env); | ||
} | ||
if (isLeaf(vnode)) { | ||
return { | ||
type: MOUNT_SINGLE, | ||
node: document.createTextNode("" + vnode) | ||
}; | ||
return document.createTextNode(`${vnode}`); | ||
} | ||
if (isElement(vnode)) { | ||
var _node; | ||
var _ref2 = vnode, | ||
_type = _ref2.type, | ||
_props = _ref2.props; | ||
if (!env.isSvg && _type === 'svg') { | ||
let node; | ||
const { | ||
type, | ||
props | ||
} = vnode; | ||
if (!env.isSvg && type === 'svg') { | ||
env = Object.assign({}, env, { | ||
@@ -160,11 +140,10 @@ isSvg: true | ||
if (!env.isSvg) { | ||
_node = document.createElement(_type); | ||
node = document.createElement(type); | ||
} else { | ||
_node = document.createElementNS(SVG_NS, _type); | ||
node = document.createElementNS(SVG_NS, type); | ||
} | ||
mountAttributes(_node, _props, env); | ||
var _childrenRef; | ||
if (_props.children) { | ||
var childEnv = env; | ||
if (env.isSvg && _type === 'foreignObject') { | ||
mountAttributes(node, props, env); | ||
if (props.children) { | ||
let childEnv = env; | ||
if (env.isSvg && type === 'foreignObject') { | ||
childEnv = Object.assign({}, childEnv, { | ||
@@ -174,45 +153,19 @@ isSvg: false | ||
} | ||
_childrenRef = mount(_props.children, childEnv); | ||
const children = mountChildren(props.children, childEnv); | ||
if (children != null) insertDom(node, children); | ||
} | ||
if (_childrenRef != null) insertDom(_node, _childrenRef); | ||
var ref = _props.ref; | ||
if (typeof ref === 'function') ref(_node); | ||
return { | ||
type: MOUNT_SINGLE, | ||
node: _node | ||
}; | ||
const { | ||
ref | ||
} = props; | ||
if (typeof ref === 'function') ref(node); | ||
return node; | ||
} | ||
if (Array.isArray(vnode)) { | ||
return { | ||
type: MOUNT_ARRAY, | ||
children: vnode.map(function (child) { | ||
return mount(child, env); | ||
}) | ||
}; | ||
} | ||
throw new Error('mount: Invalid Vnode!'); | ||
} | ||
function flattenWithoutNull(array) { | ||
var result = []; | ||
for (var i = 0; i < array.length; i += 1) { | ||
var item = array[i]; | ||
if (Array.isArray(item)) result = result.concat(flattenWithoutNull(item));else if (item != null) result.push(item); | ||
} | ||
return result; | ||
} | ||
function asDom(result) { | ||
if (result.type === MOUNT_SINGLE) { | ||
return result.node; | ||
} | ||
return result.children.map(asDom); | ||
} | ||
/** | ||
* Mount vdom as real DOM nodes. | ||
*/ | ||
function mountDom(vnode) { | ||
if (Array.isArray(vnode)) { | ||
return flattenWithoutNull(vnode.map(mountDom)); | ||
} | ||
return asDom(mount(vnode)); | ||
return mount(vnode); | ||
} | ||
@@ -254,3 +207,3 @@ | ||
} finally { | ||
promise = null; | ||
promise = undefined; | ||
} | ||
@@ -284,3 +237,2 @@ }; | ||
this.registry = {}; | ||
this.markmap = null; | ||
this.el = mountDom(jsx("div", { | ||
@@ -312,6 +264,6 @@ className: "mm-toolbar" | ||
onClick: e => { | ||
var _this$markmap; | ||
const button = e.target.closest(`.${clsToolbarItem}`); | ||
const toggle = () => button.classList.toggle(clsActive); | ||
const active = toggle(); | ||
this.markmap.setOptions({ | ||
const active = button == null ? void 0 : button.classList.toggle(clsActive); | ||
(_this$markmap = this.markmap) == null ? void 0 : _this$markmap.setOptions({ | ||
toggleRecursively: active | ||
@@ -318,0 +270,0 @@ }); |
{ | ||
"name": "markmap-toolbar", | ||
"version": "0.14.5-alpha.15+1fe26c8", | ||
"version": "0.14.5-alpha.16+33e8294", | ||
"description": "Extensible toolbar for markmap", | ||
@@ -38,10 +38,10 @@ "author": "Gerald <gera2ld@live.com>", | ||
"devDependencies": { | ||
"markmap-common": "0.14.5-alpha.15+1fe26c8", | ||
"markmap-view": "0.14.5-alpha.15+1fe26c8" | ||
"markmap-common": "0.14.5-alpha.16+33e8294", | ||
"markmap-view": "0.14.5-alpha.16+33e8294" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.16.3", | ||
"@gera2ld/jsx-dom": "^2.1.1" | ||
"@gera2ld/jsx-dom": "^2.2.2" | ||
}, | ||
"gitHead": "1fe26c8234296e2188e466c7b9dbf3b7e171857d" | ||
"gitHead": "33e8294050d7438f6cdadd5bf06a665560585195" | ||
} |
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
21680
565
Updated@gera2ld/jsx-dom@^2.2.2