UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

56 lines (55 loc) 2.99 kB
"use client"; import { useLexicalComposerContext as N } from "./LexicalComposerContext.prod.js"; import { forwardRef as C, useState as p, useLayoutEffect as h, useEffect as F, useCallback as O, useMemo as P } from "react"; import { jsxs as U, Fragment as V, jsx as m } from "react/jsx-runtime"; import { $canShowPlaceholderCurry as $ } from "../text/LexicalText.prod.js"; import { mergeRegister as G } from "../utils/LexicalUtils.prod.js"; const L = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? h : F; function H({ editor: e, ariaActiveDescendant: t, ariaAutoComplete: l, ariaControls: d, ariaDescribedBy: n, ariaErrorMessage: o, ariaExpanded: a, ariaInvalid: u, ariaLabel: f, ariaLabelledBy: s, ariaMultiline: b, ariaOwns: k, ariaRequired: D, autoCapitalize: R, className: j, id: q, role: E = "textbox", spellCheck: z = !0, style: A, tabIndex: I, "data-testid": M, ...S }, v) { const [r, w] = p(e.isEditable()), x = O(((i) => { i && i.ownerDocument && i.ownerDocument.defaultView ? e.setRootElement(i) : e.setRootElement(null); }), [e]), B = P((() => /* @__PURE__ */ (function(...i) { return (g) => { i.forEach(((c) => { typeof c == "function" ? c(g) : c != null && (c.current = g); })); }; })(v, x)), [x, v]); return L((() => (w(e.isEditable()), e.registerEditableListener(((i) => { w(i); })))), [e]), m("div", { "aria-activedescendant": r ? t : void 0, "aria-autocomplete": r ? l : "none", "aria-controls": r ? d : void 0, "aria-describedby": n, ...o != null ? { "aria-errormessage": o } : {}, "aria-expanded": r && E === "combobox" ? !!a : void 0, ...u != null ? { "aria-invalid": u } : {}, "aria-label": f, "aria-labelledby": s, "aria-multiline": b, "aria-owns": r ? k : void 0, "aria-readonly": !r || void 0, "aria-required": D, autoCapitalize: R, className: j, contentEditable: r, "data-testid": M, id: q, ref: B, role: r ? E : void 0, spellCheck: z, style: A, tabIndex: I, ...S }); } const J = C(H); function y(e) { return e.getEditorState().read($(e.isComposing())); } const _ = C(K); function K(e, t) { const { placeholder: l, ...d } = e, [n] = N(); return U(V, { children: [m(J, { editor: n, ...d, ref: t }), l != null && m(Q, { editor: n, content: l })] }); } function Q({ content: e, editor: t }) { const l = (function(a) { const [u, f] = p((() => y(a))); return L((() => { function s() { const b = y(a); f(b); } return s(), G(a.registerUpdateListener((() => { s(); })), a.registerEditableListener((() => { s(); }))); }), [a]), u; })(t), [d, n] = p(t.isEditable()); if (h((() => (n(t.isEditable()), t.registerEditableListener(((a) => { n(a); })))), [t]), !l) return null; let o = null; return typeof e == "function" ? o = e(d) : e !== null && (o = e), o === null ? null : m("div", { "aria-hidden": !0, children: o }); } export { _ as ContentEditable, J as ContentEditableElement };