@skirtle/vue-vnode-utils
Version:
Utilities for manipulating Vue 3 VNodes
197 lines (196 loc) • 6.71 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
let _skirtle_vue_vnode_utils = require("@skirtle/vue-vnode-utils");
let vue = require("vue");
//#region src/iterators.ts
const warn = (method, msg) => {
console.warn(`[${method}] ${msg}`);
};
const checkArguments = (method, passed, expected) => {
for (let index = 0; index < passed.length; ++index) {
const t = typeOf(passed[index]);
const expect = expected[index];
if (expect !== t) warn(method, `Argument ${index + 1} was ${t}, should be ${expect}`);
}
};
const typeOf = (value) => {
let t = typeof value;
if (t === "object") {
if (value === null) t = "null";
else if (Array.isArray(value)) t = "array";
else if ((0, vue.isVNode)(value)) t = "vnode";
else if (value instanceof Date) t = "date";
else if (value instanceof RegExp) t = "regexp";
}
return t;
};
//#endregion
//#region src/with-meta/iterators.ts
function checkFunction(method, callback) {
checkArguments(method, [callback], ["function"]);
}
function setPropertyValue(obj, key, value) {
return Object.defineProperty(obj, key, {
value,
enumerable: true
});
}
function createMetaFactory(children, options) {
let index = -1;
const baseMeta = { get length() {
const length = (0, _skirtle_vue_vnode_utils.countChildren)(children, options);
setPropertyValue(baseMeta, "length", length);
return length;
} };
return () => {
return setPropertyValue(Object.create(baseMeta), "index", ++index);
};
}
function withMeta(iterator, children, callback, options) {
const metaFactory = createMetaFactory(children, options);
return iterator(children, (vnode) => {
return callback(vnode, metaFactory());
}, options);
}
const addProps = (children, callback, options = _skirtle_vue_vnode_utils.COMPONENTS_AND_ELEMENTS) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("addProps", callback);
return withMeta(_skirtle_vue_vnode_utils.addProps, children, callback, options);
};
const replaceChildren = (children, callback, options = _skirtle_vue_vnode_utils.SKIP_COMMENTS) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("replaceChildren", callback);
return withMeta(_skirtle_vue_vnode_utils.replaceChildren, children, callback, options);
};
const betweenChildren = (children, callback, options = _skirtle_vue_vnode_utils.SKIP_COMMENTS) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("betweenChildren", callback);
const metaFactory = createMetaFactory(children, options);
return (0, _skirtle_vue_vnode_utils.betweenChildren)(children, (previousVNode, nextVNode) => {
return callback(previousVNode, nextVNode, metaFactory());
}, options);
};
const someChild = (children, callback, options = _skirtle_vue_vnode_utils.ALL_VNODES) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("someChild", callback);
return withMeta(_skirtle_vue_vnode_utils.someChild, children, callback, options);
};
const everyChild = (children, callback, options = _skirtle_vue_vnode_utils.ALL_VNODES) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("everyChild", callback);
return withMeta(_skirtle_vue_vnode_utils.everyChild, children, callback, options);
};
const eachChild = (children, callback, options = _skirtle_vue_vnode_utils.ALL_VNODES) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("eachChild", callback);
return withMeta(_skirtle_vue_vnode_utils.eachChild, children, callback, options);
};
const findChild = (children, callback, options = _skirtle_vue_vnode_utils.ALL_VNODES) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("findChild", callback);
return withMeta(_skirtle_vue_vnode_utils.findChild, children, callback, options);
};
const reduceChildren = (children, callback, initialValue, options = _skirtle_vue_vnode_utils.ALL_VNODES) => {
if (!(process.env.NODE_ENV === "production")) checkFunction("reduceChildren", callback);
const metaFactory = createMetaFactory(children, options);
return (0, _skirtle_vue_vnode_utils.reduceChildren)(children, (previousValue, vnode) => {
return callback(previousValue, vnode, metaFactory());
}, initialValue, options);
};
//#endregion
Object.defineProperty(exports, "ALL_VNODES", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.ALL_VNODES;
}
});
Object.defineProperty(exports, "COMPONENTS_AND_ELEMENTS", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.COMPONENTS_AND_ELEMENTS;
}
});
Object.defineProperty(exports, "SKIP_COMMENTS", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.SKIP_COMMENTS;
}
});
exports.addProps = addProps;
exports.betweenChildren = betweenChildren;
Object.defineProperty(exports, "countChildren", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.countChildren;
}
});
exports.eachChild = eachChild;
exports.everyChild = everyChild;
Object.defineProperty(exports, "extractSingleChild", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.extractSingleChild;
}
});
exports.findChild = findChild;
Object.defineProperty(exports, "getText", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.getText;
}
});
Object.defineProperty(exports, "getType", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.getType;
}
});
Object.defineProperty(exports, "isComment", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isComment;
}
});
Object.defineProperty(exports, "isComponent", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isComponent;
}
});
Object.defineProperty(exports, "isElement", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isElement;
}
});
Object.defineProperty(exports, "isEmpty", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isEmpty;
}
});
Object.defineProperty(exports, "isFragment", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isFragment;
}
});
Object.defineProperty(exports, "isFunctionalComponent", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isFunctionalComponent;
}
});
Object.defineProperty(exports, "isStatefulComponent", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isStatefulComponent;
}
});
Object.defineProperty(exports, "isStatic", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isStatic;
}
});
Object.defineProperty(exports, "isText", {
enumerable: true,
get: function() {
return _skirtle_vue_vnode_utils.isText;
}
});
exports.reduceChildren = reduceChildren;
exports.replaceChildren = replaceChildren;
exports.someChild = someChild;