laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
57 lines (56 loc) • 2.03 kB
JavaScript
"use client";
import { jsxs as c, jsx as a } from "react/jsx-runtime";
import { $isListNode as d, ListNode as T } from "../../../../node_modules/@lexical/list/LexicalList.prod.js";
import { $isHeadingNode as u } from "../../../../node_modules/@lexical/rich-text/LexicalRichText.prod.js";
import { $findMatchingParent as y, $getNearestNodeOfType as h } from "../../../../node_modules/@lexical/utils/LexicalUtils.prod.js";
import { $isRangeSelection as N, $isRootOrShadowRoot as $ } from "../../../../node_modules/lexical/Lexical.prod.js";
import { useToolbarContext as b } from "../../context/toolbar-context.js";
import { useUpdateToolbarHandler as L } from "../../editor-hooks/use-update-toolbar.js";
import { blockTypeToBlockName as s } from "./block-format/block-format-data.js";
import { Select as S, SelectTrigger as k, SelectContent as w, SelectGroup as O } from "../../../ui/select.js";
function H({
children: m
}) {
const { activeEditor: p, blockType: i, setBlockType: l } = b();
function g(n) {
if (N(n)) {
const o = n.anchor.getNode();
let e = o.getKey() === "root" ? o : y(o, (t) => {
const r = t.getParent();
return r !== null && $(r);
});
e === null && (e = o.getTopLevelElementOrThrow());
const f = e.getKey();
if (p.getElementByKey(f) !== null)
if (d(e)) {
const t = h(
o,
T
), r = t ? t.getListType() : e.getListType();
l(r);
} else {
const t = u(e) ? e.getTag() : e.getType();
t in s && l(t);
}
}
}
return L(g), /* @__PURE__ */ c(
S,
{
value: i,
onValueChange: (n) => {
l(n);
},
children: [
/* @__PURE__ */ c(k, { className: "!h-8 w-min gap-1", children: [
s[i].icon,
/* @__PURE__ */ a("span", { children: s[i].label })
] }),
/* @__PURE__ */ a(w, { children: /* @__PURE__ */ a(O, { children: m }) })
]
}
);
}
export {
H as BlockFormatDropDown
};