@frontify/fondue
Version:
Design system of Frontify
53 lines (52 loc) • 1.29 kB
JavaScript
import { visit as s } from "unist-util-visit";
import { MENTION_SERIALIZE_REGEX as h } from "../../../utils.es.js";
function a() {
return u;
}
const u = (t) => {
s(t, "paragraph", i);
function i(e) {
const { children: r } = e;
e.children = [];
for (const n of r) {
if (!o(n, "text") || !n.value) {
e.children.push(n);
continue;
}
const l = [...n.value.matchAll(h)];
if (l === null || l.length === 0) {
e.children.push(n);
continue;
}
p(l, e, n.value);
}
}
}, o = (t, i) => t[i] !== "" && !!t.value, p = (t, i, e) => {
t[0].index > 0 && i.children.push({
type: "text",
value: e.slice(0, t[0].index)
});
for (const [n, l] of t.entries())
if (i.children.push({
type: "mention",
children: [{ type: "text", value: l[0] }]
}), t.length > n + 1 && e) {
const c = l.index + l[0].length;
i.children.push({
type: "text",
value: e.slice(c, t[n + 1].index)
});
}
const r = t[t.length - 1];
r.index + r[0].length < e.length ? i.children.push({
type: "text",
value: e.slice(r.index + r[0].length)
}) : i.children.push({
type: "text",
value: ""
});
};
export {
a as default
};
//# sourceMappingURL=index.es.js.map