UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

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