@dialpad/dialtone-vue
Version:
Vue component library for Dialpad's design system Dialtone
46 lines (45 loc) • 1.49 kB
JavaScript
function h(t, n) {
if (!t) return [];
const { from: o, to: f } = t.selection;
let r;
if (typeof n == "string")
r = Object.entries(t.schema.nodes).filter(([, e]) => e.groups.includes(n)).map(([, e]) => ({
type: e
}));
else {
r = n;
for (const e of r)
e.type = e.type ? y(e.type, t.schema) : null;
}
let i = null, s = null;
const l = /* @__PURE__ */ new Set(), d = new Set(r);
return t.doc.nodesBetween(o, f, (e, p, c) => {
if (d.size === 0) return !1;
if (!e.isText) {
const a = r.filter((u) => u.type ? typeof u.type == "string" ? !1 : e.type.name === u.type.name : !0).find((u) => u.attributes ? g(e.attrs, u.attributes) : !0);
a && (s && i && i !== c && (d.delete(s), l.add(s)), s = a), i = e;
}
}), s && l.add(s), [...l.values()].map((e) => {
var p;
return e.key ? e.key : typeof e.type == "string" ? e.type : (p = e.type) != null && p.name ? e.type.name : "";
});
}
function y(t, n) {
if (typeof t == "string") {
if (!n.nodes[t])
throw Error(
`There is no node type named '${t}'. Maybe you forgot to add the extension?`
);
return n.nodes[t];
}
return t;
}
function g(t, n, o) {
const f = Object.keys(n);
return f.length ? f.every((r) => o.strict ? n[r] === t[r] : Object.prototype.toString.call(n[r]) === "[object RegExp]" ? n[r].test(t[r]) : n[r] === t[r]) : !0;
}
export {
h as default,
g as objectIncludes
};
//# sourceMappingURL=last-active-nodes.js.map