@yurikilian/lex4 1.5.1 → 1.5.2

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$q = [
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$q);
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$p = [
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$p);
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$o = [
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,15 @@ const __iconNode$n = [
1497
1497
  }
1498
1498
  ]
1499
1499
  ];
1500
- const Braces = createLucideIcon("braces", __iconNode$n);
1500
+ const Braces = createLucideIcon("braces", __iconNode$o);
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$n = [["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]];
1508
+ const ChevronDown = createLucideIcon("chevron-down", __iconNode$n);
1501
1509
  /**
1502
1510
  * @license lucide-react v1.8.0 - ISC
1503
1511
  *
@@ -2484,6 +2492,135 @@ function readSelectedVariableFormatting(editor) {
2484
2492
  fontSize: extractFontSizePtFromStyle(style)
2485
2493
  };
2486
2494
  }
2495
+ const BLOCK_TYPE_OPTIONS = [
2496
+ { value: "paragraph", shortLabel: "P" },
2497
+ { value: "h1", shortLabel: "H1" },
2498
+ { value: "h2", shortLabel: "H2" },
2499
+ { value: "h3", shortLabel: "H3" },
2500
+ { value: "h4", shortLabel: "H4" },
2501
+ { value: "h5", shortLabel: "H5" },
2502
+ { value: "h6", shortLabel: "H6" }
2503
+ ];
2504
+ function getBlockTypeLabel(t, blockType) {
2505
+ switch (blockType) {
2506
+ case "h1":
2507
+ return t.toolbar.heading1;
2508
+ case "h2":
2509
+ return t.toolbar.heading2;
2510
+ case "h3":
2511
+ return t.toolbar.heading3;
2512
+ case "h4":
2513
+ return t.toolbar.heading4;
2514
+ case "h5":
2515
+ return t.toolbar.heading5;
2516
+ case "h6":
2517
+ return t.toolbar.heading6;
2518
+ default:
2519
+ return t.toolbar.paragraph;
2520
+ }
2521
+ }
2522
+ function getBlockTypeShortLabel(blockType) {
2523
+ var _a;
2524
+ return ((_a = BLOCK_TYPE_OPTIONS.find((option) => option.value === blockType)) == null ? void 0 : _a.shortLabel) ?? "P";
2525
+ }
2526
+ const BlockTypePicker = ({ value, onChange }) => {
2527
+ const t = useTranslations();
2528
+ const [open, setOpen] = useState(false);
2529
+ const containerRef = useRef(null);
2530
+ useEffect(() => {
2531
+ if (!open) {
2532
+ return;
2533
+ }
2534
+ const handleClickOutside = (event) => {
2535
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
2536
+ setOpen(false);
2537
+ }
2538
+ };
2539
+ const handleEscape = (event) => {
2540
+ if (event.key === "Escape") {
2541
+ setOpen(false);
2542
+ }
2543
+ };
2544
+ document.addEventListener("mousedown", handleClickOutside);
2545
+ document.addEventListener("keydown", handleEscape);
2546
+ return () => {
2547
+ document.removeEventListener("mousedown", handleClickOutside);
2548
+ document.removeEventListener("keydown", handleEscape);
2549
+ };
2550
+ }, [open]);
2551
+ return /* @__PURE__ */ jsxs(
2552
+ "div",
2553
+ {
2554
+ ref: containerRef,
2555
+ className: "lex4-block-type-picker",
2556
+ "data-testid": "block-type-picker",
2557
+ children: [
2558
+ /* @__PURE__ */ jsxs(
2559
+ "button",
2560
+ {
2561
+ type: "button",
2562
+ className: `lex4-block-type-trigger${open ? " open" : ""}`,
2563
+ "data-testid": "block-type-selector",
2564
+ "aria-label": t.toolbar.blockType,
2565
+ "aria-expanded": open,
2566
+ "aria-haspopup": "menu",
2567
+ title: getBlockTypeLabel(t, value),
2568
+ onMouseDown: (event) => event.preventDefault(),
2569
+ onClick: () => setOpen((current) => !current),
2570
+ children: [
2571
+ /* @__PURE__ */ jsx(
2572
+ "span",
2573
+ {
2574
+ className: `lex4-block-type-trigger-code${value === "paragraph" ? "" : " heading"}`,
2575
+ children: getBlockTypeShortLabel(value)
2576
+ }
2577
+ ),
2578
+ /* @__PURE__ */ jsx(ChevronDown, { size: 14, className: `lex4-block-type-trigger-chevron${open ? " open" : ""}` })
2579
+ ]
2580
+ }
2581
+ ),
2582
+ open && /* @__PURE__ */ jsx(
2583
+ "div",
2584
+ {
2585
+ className: "lex4-block-type-menu",
2586
+ role: "menu",
2587
+ "data-testid": "block-type-menu",
2588
+ children: BLOCK_TYPE_OPTIONS.map((option) => {
2589
+ const label = getBlockTypeLabel(t, option.value);
2590
+ const active = option.value === value;
2591
+ return /* @__PURE__ */ jsxs(
2592
+ "button",
2593
+ {
2594
+ type: "button",
2595
+ role: "menuitemradio",
2596
+ "aria-checked": active,
2597
+ className: `lex4-block-type-item${active ? " active" : ""}`,
2598
+ "data-testid": `block-type-option-${option.value}`,
2599
+ onMouseDown: (event) => event.preventDefault(),
2600
+ onClick: () => {
2601
+ onChange(option.value);
2602
+ setOpen(false);
2603
+ },
2604
+ children: [
2605
+ /* @__PURE__ */ jsx(
2606
+ "span",
2607
+ {
2608
+ className: `lex4-block-type-item-code${option.value === "paragraph" ? "" : " heading"}${active ? " active" : ""}`,
2609
+ children: option.shortLabel
2610
+ }
2611
+ ),
2612
+ /* @__PURE__ */ jsx("span", { className: "lex4-block-type-item-label", children: label })
2613
+ ]
2614
+ },
2615
+ option.value
2616
+ );
2617
+ })
2618
+ }
2619
+ )
2620
+ ]
2621
+ }
2622
+ );
2623
+ };
2487
2624
  const HeaderFooterToggle = ({
2488
2625
  enabled,
2489
2626
  onToggle,
@@ -2982,19 +3119,9 @@ const Toolbar = () => {
2982
3119
  [activeEditor, applyToBodyEditors, runToolbarAction, t.history.actions.fontSizeChanged]
2983
3120
  );
2984
3121
  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
- };
3122
+ (blockType) => {
2996
3123
  runToolbarAction(
2997
- interpolate(t.history.actions.blockTypeChanged, { value: labelMap[blockType] }),
3124
+ interpolate(t.history.actions.blockTypeChanged, { value: getBlockTypeLabel(t, blockType) }),
2998
3125
  () => {
2999
3126
  applyToBodyEditors((editor) => setBlockType(editor, blockType));
3000
3127
  }
@@ -3004,13 +3131,7 @@ const Toolbar = () => {
3004
3131
  applyToBodyEditors,
3005
3132
  runToolbarAction,
3006
3133
  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
3134
+ t
3014
3135
  ]
3015
3136
  );
3016
3137
  const handleToggleHistory = useCallback(() => {
@@ -3045,23 +3166,11 @@ const Toolbar = () => {
3045
3166
  )
3046
3167
  ] }),
3047
3168
  /* @__PURE__ */ jsx(Divider, {}),
3048
- /* @__PURE__ */ jsx("div", { className: "lex4-toolbar-group-gap lex4-toolbar-group-block", children: /* @__PURE__ */ jsxs(
3049
- "select",
3169
+ /* @__PURE__ */ jsx("div", { className: "lex4-toolbar-group", children: /* @__PURE__ */ jsx(
3170
+ BlockTypePicker,
3050
3171
  {
3051
- className: "lex4-toolbar-select lex4-toolbar-select-block",
3052
- "data-testid": "block-type-selector",
3053
- "aria-label": t.toolbar.blockType,
3054
3172
  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
- ]
3173
+ onChange: handleBlockTypeChange
3065
3174
  }
3066
3175
  ) }),
3067
3176
  /* @__PURE__ */ jsx(Divider, {}),