laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
108 lines (107 loc) • 3.66 kB
JavaScript
"use client";
import { $createRangeSelection as k, $isElementNode as g, INTERNAL_$isBlock as $, $getSelection as P, $setSelection as v, $caretFromPoint as w, $isExtendableTextPointCaret as K, $extendCaretToRange as E, $isChildCaret as I, $isDecoratorNode as O, $isRootNode as h, $getEditor as _, $isTokenOrSegmented as B, $getCharacterOffsets as F } from "../../lexical/Lexical.prod.js";
import { $cloneWithProperties as J, $selectAll as Q } from "../../lexical/Lexical.prod.js";
const p = /* @__PURE__ */ new Map();
function S(t) {
const e = {};
if (!t) return e;
const n = t.split(";");
for (const o of n) if (o !== "") {
const [r, s] = o.split(/:([^]+)/);
r && s && (e[r.trim()] = s.trim());
}
return e;
}
function A(t) {
let e = p.get(t);
return e === void 0 && (e = S(t), p.set(t, e)), e;
}
function L(t, e) {
const n = t.getStartEndPoints();
if (e.isSelected(t) && !B(e) && n !== null) {
const [o, r] = n, s = t.isBackward(), i = o.getNode(), c = r.getNode(), l = e.is(i), u = e.is(c);
if (l || u) {
const [a, f] = F(t), C = i.is(c), T = e.is(s ? c : i), x = e.is(s ? i : c);
let d, y = 0;
C ? (y = a > f ? f : a, d = a > f ? a : f) : T ? (y = s ? f : a, d = void 0) : x && (y = 0, d = s ? a : f), e.__text = e.__text.slice(y, d);
}
}
return e;
}
function W(t) {
const e = t.getStyle(), n = S(e);
p.set(e, n);
}
function D(t, e) {
const n = t.getFormatType(), o = t.getIndent();
n !== e.getFormatType() && e.setFormat(n), o !== e.getIndent() && e.setIndent(o);
}
function Z(t, e, n = D) {
if (t === null) return;
const o = t.getStartEndPoints(), r = /* @__PURE__ */ new Map();
let s = null;
if (o) {
const [i, c] = o;
s = k(), s.anchor.set(i.key, i.offset, i.type), s.focus.set(c.key, c.offset, c.type);
const l = m(i.getNode(), $), u = m(c.getNode(), $);
g(l) && r.set(l.getKey(), l), g(u) && r.set(u.getKey(), u);
}
for (const i of t.getNodes()) if (g(i) && $(i)) r.set(i.getKey(), i);
else if (o === null) {
const c = m(i, $);
g(c) && r.set(c.getKey(), c);
}
for (const [i, c] of r) {
const l = e();
n(c, l), c.replace(l, !0), s && (i === s.anchor.key && s.anchor.set(l.getKey(), s.anchor.offset, s.anchor.type), i === s.focus.key && s.focus.set(l.getKey(), s.focus.offset, s.focus.type));
}
s && t.is(P()) && v(s);
}
function N(t) {
const e = t.anchor.getNode(), n = h(e) ? e : e.getParentOrThrow(), o = _().getElementByKey(n.getKey());
if (o === null) return !1;
const r = o.ownerDocument.defaultView;
return r === null ? !1 : r.getComputedStyle(o).writingMode === "vertical-rl";
}
function j(t, e) {
const n = N(t) ? !e : e, o = w(t.focus, n ? "previous" : "next");
if (K(o)) return !1;
for (const r of E(o)) {
if (I(r)) return !r.origin.isInline();
if (!g(r.origin)) {
if (O(r.origin)) return !0;
break;
}
}
return !1;
}
function R(t, e, n, o) {
t.modify(e ? "extend" : "move", n, o);
}
function b(t) {
const e = t.anchor.getNode();
return (h(e) ? e : e.getParentOrThrow()).getDirection() === "rtl";
}
function q(t, e, n) {
const o = b(t);
let r;
r = N(t) || o ? !n : n, R(t, e, r, "character");
}
function m(t, e) {
let n = t;
for (; n !== null && n.getParent() !== null && !e(n); ) n = n.getParentOrThrow();
return e(n) ? n : null;
}
export {
W as $addNodeStyle,
J as $cloneWithProperties,
D as $copyBlockFormatIndent,
b as $isParentElementRTL,
R as $moveCaretSelection,
q as $moveCharacter,
Q as $selectAll,
Z as $setBlocksType,
j as $shouldOverrideDefaultCharacterSelection,
L as $sliceSelectedTextNodeContent,
A as getStyleObjectFromCSS
};