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