@yurikilian/lex4 1.5.1 → 1.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1458,33 +1458,33 @@ const createLucideIcon = (iconName, iconNode) => {
1458
1458
  * This source code is licensed under the ISC license.
1459
1459
  * See the LICENSE file in the root directory of this source tree.
1460
1460
  */
1461
- const __iconNode$p = [
1461
+ const __iconNode$r = [
1462
1462
  ["path", { d: "m15 16 2.536-7.328a1.02 1.02 1 0 1 1.928 0L22 16", key: "xik6mr" }],
1463
1463
  ["path", { d: "M15.697 14h5.606", key: "1stdlc" }],
1464
1464
  ["path", { d: "m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16", key: "d5nyq2" }],
1465
1465
  ["path", { d: "M3.304 13h6.392", key: "1q3zxz" }]
1466
1466
  ];
1467
- const ALargeSmall = createLucideIcon("a-large-small", __iconNode$p);
1467
+ const ALargeSmall = createLucideIcon("a-large-small", __iconNode$r);
1468
1468
  /**
1469
1469
  * @license lucide-react v1.8.0 - ISC
1470
1470
  *
1471
1471
  * This source code is licensed under the ISC license.
1472
1472
  * See the LICENSE file in the root directory of this source tree.
1473
1473
  */
1474
- const __iconNode$o = [
1474
+ const __iconNode$q = [
1475
1475
  [
1476
1476
  "path",
1477
1477
  { d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8", key: "mg9rjx" }
1478
1478
  ]
1479
1479
  ];
1480
- const Bold = createLucideIcon("bold", __iconNode$o);
1480
+ const Bold = createLucideIcon("bold", __iconNode$q);
1481
1481
  /**
1482
1482
  * @license lucide-react v1.8.0 - ISC
1483
1483
  *
1484
1484
  * This source code is licensed under the ISC license.
1485
1485
  * See the LICENSE file in the root directory of this source tree.
1486
1486
  */
1487
- const __iconNode$n = [
1487
+ const __iconNode$p = [
1488
1488
  [
1489
1489
  "path",
1490
1490
  { d: "M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1", key: "ezmyqa" }
@@ -1497,7 +1497,23 @@ const __iconNode$n = [
1497
1497
  }
1498
1498
  ]
1499
1499
  ];
1500
- const Braces = createLucideIcon("braces", __iconNode$n);
1500
+ const Braces = createLucideIcon("braces", __iconNode$p);
1501
+ /**
1502
+ * @license lucide-react v1.8.0 - ISC
1503
+ *
1504
+ * This source code is licensed under the ISC license.
1505
+ * See the LICENSE file in the root directory of this source tree.
1506
+ */
1507
+ const __iconNode$o = [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]];
1508
+ const Check = createLucideIcon("check", __iconNode$o);
1509
+ /**
1510
+ * @license lucide-react v1.8.0 - ISC
1511
+ *
1512
+ * This source code is licensed under the ISC license.
1513
+ * See the LICENSE file in the root directory of this source tree.
1514
+ */
1515
+ const __iconNode$n = [["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]];
1516
+ const ChevronDown = createLucideIcon("chevron-down", __iconNode$n);
1501
1517
  /**
1502
1518
  * @license lucide-react v1.8.0 - ISC
1503
1519
  *
@@ -1989,7 +2005,9 @@ const EMPTY_RESOLVED = {
1989
2005
  handleFactories: []
1990
2006
  };
1991
2007
  const ExtensionResolvedContext = createContext(EMPTY_RESOLVED);
1992
- function arraysEqual(a, b) {
2008
+ function extensionArraysEqual(a, b) {
2009
+ if (a === b) return true;
2010
+ if (!a || !b) return !a && !b;
1993
2011
  if (a.length !== b.length) return false;
1994
2012
  for (let i = 0; i < a.length; i++) {
1995
2013
  if (a[i] !== b[i]) return false;
@@ -1997,12 +2015,11 @@ function arraysEqual(a, b) {
1997
2015
  return true;
1998
2016
  }
1999
2017
  const ExtensionProvider = ({ extensions, children }) => {
2000
- const prevNamesRef = useRef([]);
2018
+ const prevExtensionsRef = useRef(void 0);
2001
2019
  const resolvedRef = useRef(EMPTY_RESOLVED);
2002
- const currentNames = (extensions ?? []).map((e) => e.name);
2003
- if (!arraysEqual(currentNames, prevNamesRef.current)) {
2020
+ if (!extensionArraysEqual(extensions, prevExtensionsRef.current)) {
2004
2021
  resolvedRef.current = extensions && extensions.length > 0 ? resolveExtensions(extensions) : EMPTY_RESOLVED;
2005
- prevNamesRef.current = currentNames;
2022
+ prevExtensionsRef.current = extensions;
2006
2023
  }
2007
2024
  const resolved = resolvedRef.current;
2008
2025
  let wrapped = /* @__PURE__ */ jsx(Fragment, { children });
@@ -2484,6 +2501,136 @@ function readSelectedVariableFormatting(editor) {
2484
2501
  fontSize: extractFontSizePtFromStyle(style)
2485
2502
  };
2486
2503
  }
2504
+ const BLOCK_TYPE_OPTIONS = [
2505
+ { value: "paragraph", shortLabel: "P" },
2506
+ { value: "h1", shortLabel: "H1" },
2507
+ { value: "h2", shortLabel: "H2" },
2508
+ { value: "h3", shortLabel: "H3" },
2509
+ { value: "h4", shortLabel: "H4" },
2510
+ { value: "h5", shortLabel: "H5" },
2511
+ { value: "h6", shortLabel: "H6" }
2512
+ ];
2513
+ function getBlockTypeLabel(t, blockType) {
2514
+ switch (blockType) {
2515
+ case "h1":
2516
+ return t.toolbar.heading1;
2517
+ case "h2":
2518
+ return t.toolbar.heading2;
2519
+ case "h3":
2520
+ return t.toolbar.heading3;
2521
+ case "h4":
2522
+ return t.toolbar.heading4;
2523
+ case "h5":
2524
+ return t.toolbar.heading5;
2525
+ case "h6":
2526
+ return t.toolbar.heading6;
2527
+ default:
2528
+ return t.toolbar.paragraph;
2529
+ }
2530
+ }
2531
+ function getBlockTypeShortLabel(blockType) {
2532
+ var _a;
2533
+ return ((_a = BLOCK_TYPE_OPTIONS.find((option) => option.value === blockType)) == null ? void 0 : _a.shortLabel) ?? "P";
2534
+ }
2535
+ const BlockTypePicker = ({ value, onChange }) => {
2536
+ const t = useTranslations();
2537
+ const [open, setOpen] = useState(false);
2538
+ const containerRef = useRef(null);
2539
+ useEffect(() => {
2540
+ if (!open) {
2541
+ return;
2542
+ }
2543
+ const handleClickOutside = (event) => {
2544
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
2545
+ setOpen(false);
2546
+ }
2547
+ };
2548
+ const handleEscape = (event) => {
2549
+ if (event.key === "Escape") {
2550
+ setOpen(false);
2551
+ }
2552
+ };
2553
+ document.addEventListener("mousedown", handleClickOutside);
2554
+ document.addEventListener("keydown", handleEscape);
2555
+ return () => {
2556
+ document.removeEventListener("mousedown", handleClickOutside);
2557
+ document.removeEventListener("keydown", handleEscape);
2558
+ };
2559
+ }, [open]);
2560
+ return /* @__PURE__ */ jsxs(
2561
+ "div",
2562
+ {
2563
+ ref: containerRef,
2564
+ className: "lex4-block-type-picker",
2565
+ "data-testid": "block-type-picker",
2566
+ children: [
2567
+ /* @__PURE__ */ jsxs(
2568
+ "button",
2569
+ {
2570
+ type: "button",
2571
+ className: `lex4-block-type-trigger${open ? " open" : ""}`,
2572
+ "data-testid": "block-type-selector",
2573
+ "aria-label": t.toolbar.blockType,
2574
+ "aria-expanded": open,
2575
+ "aria-haspopup": "menu",
2576
+ title: getBlockTypeLabel(t, value),
2577
+ onMouseDown: (event) => event.preventDefault(),
2578
+ onClick: () => setOpen((current) => !current),
2579
+ children: [
2580
+ /* @__PURE__ */ jsx(
2581
+ "span",
2582
+ {
2583
+ className: `lex4-block-type-trigger-code${value === "paragraph" ? "" : " heading"}`,
2584
+ children: getBlockTypeShortLabel(value)
2585
+ }
2586
+ ),
2587
+ /* @__PURE__ */ jsx(ChevronDown, { size: 14, className: `lex4-block-type-trigger-chevron${open ? " open" : ""}` })
2588
+ ]
2589
+ }
2590
+ ),
2591
+ open && /* @__PURE__ */ jsx(
2592
+ "div",
2593
+ {
2594
+ className: "lex4-block-type-menu",
2595
+ role: "menu",
2596
+ "data-testid": "block-type-menu",
2597
+ children: BLOCK_TYPE_OPTIONS.map((option) => {
2598
+ const label = getBlockTypeLabel(t, option.value);
2599
+ const active = option.value === value;
2600
+ return /* @__PURE__ */ jsxs(
2601
+ "button",
2602
+ {
2603
+ type: "button",
2604
+ role: "menuitemradio",
2605
+ "aria-checked": active,
2606
+ className: `lex4-block-type-item${active ? " active" : ""}`,
2607
+ "data-testid": `block-type-option-${option.value}`,
2608
+ onMouseDown: (event) => event.preventDefault(),
2609
+ onClick: () => {
2610
+ onChange(option.value);
2611
+ setOpen(false);
2612
+ },
2613
+ children: [
2614
+ /* @__PURE__ */ jsx(
2615
+ "span",
2616
+ {
2617
+ className: `lex4-block-type-item-code${option.value === "paragraph" ? "" : " heading"}${active ? " active" : ""}`,
2618
+ children: option.shortLabel
2619
+ }
2620
+ ),
2621
+ /* @__PURE__ */ jsx("span", { className: "lex4-block-type-item-label", children: label }),
2622
+ /* @__PURE__ */ jsx("span", { className: "lex4-block-type-item-check", "aria-hidden": "true", children: active ? /* @__PURE__ */ jsx(Check, { size: 14 }) : null })
2623
+ ]
2624
+ },
2625
+ option.value
2626
+ );
2627
+ })
2628
+ }
2629
+ )
2630
+ ]
2631
+ }
2632
+ );
2633
+ };
2487
2634
  const HeaderFooterToggle = ({
2488
2635
  enabled,
2489
2636
  onToggle,
@@ -2982,19 +3129,9 @@ const Toolbar = () => {
2982
3129
  [activeEditor, applyToBodyEditors, runToolbarAction, t.history.actions.fontSizeChanged]
2983
3130
  );
2984
3131
  const handleBlockTypeChange = useCallback(
2985
- (e) => {
2986
- const blockType = e.target.value;
2987
- const labelMap = {
2988
- paragraph: t.toolbar.paragraph,
2989
- h1: t.toolbar.heading1,
2990
- h2: t.toolbar.heading2,
2991
- h3: t.toolbar.heading3,
2992
- h4: t.toolbar.heading4,
2993
- h5: t.toolbar.heading5,
2994
- h6: t.toolbar.heading6
2995
- };
3132
+ (blockType) => {
2996
3133
  runToolbarAction(
2997
- interpolate(t.history.actions.blockTypeChanged, { value: labelMap[blockType] }),
3134
+ interpolate(t.history.actions.blockTypeChanged, { value: getBlockTypeLabel(t, blockType) }),
2998
3135
  () => {
2999
3136
  applyToBodyEditors((editor) => setBlockType(editor, blockType));
3000
3137
  }
@@ -3004,13 +3141,7 @@ const Toolbar = () => {
3004
3141
  applyToBodyEditors,
3005
3142
  runToolbarAction,
3006
3143
  t.history.actions.blockTypeChanged,
3007
- t.toolbar.heading1,
3008
- t.toolbar.heading2,
3009
- t.toolbar.heading3,
3010
- t.toolbar.heading4,
3011
- t.toolbar.heading5,
3012
- t.toolbar.heading6,
3013
- t.toolbar.paragraph
3144
+ t
3014
3145
  ]
3015
3146
  );
3016
3147
  const handleToggleHistory = useCallback(() => {
@@ -3045,23 +3176,11 @@ const Toolbar = () => {
3045
3176
  )
3046
3177
  ] }),
3047
3178
  /* @__PURE__ */ jsx(Divider, {}),
3048
- /* @__PURE__ */ jsx("div", { className: "lex4-toolbar-group-gap lex4-toolbar-group-block", children: /* @__PURE__ */ jsxs(
3049
- "select",
3179
+ /* @__PURE__ */ jsx("div", { className: "lex4-toolbar-group", children: /* @__PURE__ */ jsx(
3180
+ BlockTypePicker,
3050
3181
  {
3051
- className: "lex4-toolbar-select lex4-toolbar-select-block",
3052
- "data-testid": "block-type-selector",
3053
- "aria-label": t.toolbar.blockType,
3054
3182
  value: activeBlockType,
3055
- onChange: handleBlockTypeChange,
3056
- children: [
3057
- /* @__PURE__ */ jsx("option", { value: "paragraph", children: t.toolbar.paragraph }),
3058
- /* @__PURE__ */ jsx("option", { value: "h1", children: t.toolbar.heading1 }),
3059
- /* @__PURE__ */ jsx("option", { value: "h2", children: t.toolbar.heading2 }),
3060
- /* @__PURE__ */ jsx("option", { value: "h3", children: t.toolbar.heading3 }),
3061
- /* @__PURE__ */ jsx("option", { value: "h4", children: t.toolbar.heading4 }),
3062
- /* @__PURE__ */ jsx("option", { value: "h5", children: t.toolbar.heading5 }),
3063
- /* @__PURE__ */ jsx("option", { value: "h6", children: t.toolbar.heading6 })
3064
- ]
3183
+ onChange: handleBlockTypeChange
3065
3184
  }
3066
3185
  ) }),
3067
3186
  /* @__PURE__ */ jsx(Divider, {}),