@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.
- package/dist/components/BlockTypePicker.d.ts +11 -0
- package/dist/components/BlockTypePicker.d.ts.map +1 -0
- package/dist/components/Toolbar.d.ts.map +1 -1
- package/dist/lex4-editor.cjs +149 -40
- package/dist/lex4-editor.cjs.map +1 -1
- package/dist/lex4-editor.js +149 -40
- package/dist/lex4-editor.js.map +1 -1
- package/dist/style.css +105 -2
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Lex4Translations } from '../i18n';
|
|
3
|
+
import { BlockType } from '../lexical/commands/block-commands';
|
|
4
|
+
export declare function getBlockTypeLabel(t: Lex4Translations, blockType: BlockType): string;
|
|
5
|
+
interface BlockTypePickerProps {
|
|
6
|
+
value: BlockType;
|
|
7
|
+
onChange: (blockType: BlockType) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const BlockTypePicker: React.FC<BlockTypePickerProps>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=BlockTypePicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTypePicker.d.ts","sourceRoot":"","sources":["../../src/components/BlockTypePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAYpE,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAiBnF;AAMD,UAAU,oBAAoB;IAC5B,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CAC1C;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA6F1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../src/components/Toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../src/components/Toolbar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAqEhE,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAoa3B,CAAC"}
|
package/dist/lex4-editor.cjs
CHANGED
|
@@ -1460,33 +1460,33 @@ const createLucideIcon = (iconName, iconNode) => {
|
|
|
1460
1460
|
* This source code is licensed under the ISC license.
|
|
1461
1461
|
* See the LICENSE file in the root directory of this source tree.
|
|
1462
1462
|
*/
|
|
1463
|
-
const __iconNode$
|
|
1463
|
+
const __iconNode$q = [
|
|
1464
1464
|
["path", { d: "m15 16 2.536-7.328a1.02 1.02 1 0 1 1.928 0L22 16", key: "xik6mr" }],
|
|
1465
1465
|
["path", { d: "M15.697 14h5.606", key: "1stdlc" }],
|
|
1466
1466
|
["path", { d: "m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16", key: "d5nyq2" }],
|
|
1467
1467
|
["path", { d: "M3.304 13h6.392", key: "1q3zxz" }]
|
|
1468
1468
|
];
|
|
1469
|
-
const ALargeSmall = createLucideIcon("a-large-small", __iconNode$
|
|
1469
|
+
const ALargeSmall = createLucideIcon("a-large-small", __iconNode$q);
|
|
1470
1470
|
/**
|
|
1471
1471
|
* @license lucide-react v1.8.0 - ISC
|
|
1472
1472
|
*
|
|
1473
1473
|
* This source code is licensed under the ISC license.
|
|
1474
1474
|
* See the LICENSE file in the root directory of this source tree.
|
|
1475
1475
|
*/
|
|
1476
|
-
const __iconNode$
|
|
1476
|
+
const __iconNode$p = [
|
|
1477
1477
|
[
|
|
1478
1478
|
"path",
|
|
1479
1479
|
{ 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" }
|
|
1480
1480
|
]
|
|
1481
1481
|
];
|
|
1482
|
-
const Bold = createLucideIcon("bold", __iconNode$
|
|
1482
|
+
const Bold = createLucideIcon("bold", __iconNode$p);
|
|
1483
1483
|
/**
|
|
1484
1484
|
* @license lucide-react v1.8.0 - ISC
|
|
1485
1485
|
*
|
|
1486
1486
|
* This source code is licensed under the ISC license.
|
|
1487
1487
|
* See the LICENSE file in the root directory of this source tree.
|
|
1488
1488
|
*/
|
|
1489
|
-
const __iconNode$
|
|
1489
|
+
const __iconNode$o = [
|
|
1490
1490
|
[
|
|
1491
1491
|
"path",
|
|
1492
1492
|
{ 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" }
|
|
@@ -1499,7 +1499,15 @@ const __iconNode$n = [
|
|
|
1499
1499
|
}
|
|
1500
1500
|
]
|
|
1501
1501
|
];
|
|
1502
|
-
const Braces = createLucideIcon("braces", __iconNode$
|
|
1502
|
+
const Braces = createLucideIcon("braces", __iconNode$o);
|
|
1503
|
+
/**
|
|
1504
|
+
* @license lucide-react v1.8.0 - ISC
|
|
1505
|
+
*
|
|
1506
|
+
* This source code is licensed under the ISC license.
|
|
1507
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
1508
|
+
*/
|
|
1509
|
+
const __iconNode$n = [["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]];
|
|
1510
|
+
const ChevronDown = createLucideIcon("chevron-down", __iconNode$n);
|
|
1503
1511
|
/**
|
|
1504
1512
|
* @license lucide-react v1.8.0 - ISC
|
|
1505
1513
|
*
|
|
@@ -2486,6 +2494,135 @@ function readSelectedVariableFormatting(editor) {
|
|
|
2486
2494
|
fontSize: extractFontSizePtFromStyle(style)
|
|
2487
2495
|
};
|
|
2488
2496
|
}
|
|
2497
|
+
const BLOCK_TYPE_OPTIONS = [
|
|
2498
|
+
{ value: "paragraph", shortLabel: "P" },
|
|
2499
|
+
{ value: "h1", shortLabel: "H1" },
|
|
2500
|
+
{ value: "h2", shortLabel: "H2" },
|
|
2501
|
+
{ value: "h3", shortLabel: "H3" },
|
|
2502
|
+
{ value: "h4", shortLabel: "H4" },
|
|
2503
|
+
{ value: "h5", shortLabel: "H5" },
|
|
2504
|
+
{ value: "h6", shortLabel: "H6" }
|
|
2505
|
+
];
|
|
2506
|
+
function getBlockTypeLabel(t, blockType) {
|
|
2507
|
+
switch (blockType) {
|
|
2508
|
+
case "h1":
|
|
2509
|
+
return t.toolbar.heading1;
|
|
2510
|
+
case "h2":
|
|
2511
|
+
return t.toolbar.heading2;
|
|
2512
|
+
case "h3":
|
|
2513
|
+
return t.toolbar.heading3;
|
|
2514
|
+
case "h4":
|
|
2515
|
+
return t.toolbar.heading4;
|
|
2516
|
+
case "h5":
|
|
2517
|
+
return t.toolbar.heading5;
|
|
2518
|
+
case "h6":
|
|
2519
|
+
return t.toolbar.heading6;
|
|
2520
|
+
default:
|
|
2521
|
+
return t.toolbar.paragraph;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
function getBlockTypeShortLabel(blockType) {
|
|
2525
|
+
var _a;
|
|
2526
|
+
return ((_a = BLOCK_TYPE_OPTIONS.find((option) => option.value === blockType)) == null ? void 0 : _a.shortLabel) ?? "P";
|
|
2527
|
+
}
|
|
2528
|
+
const BlockTypePicker = ({ value, onChange }) => {
|
|
2529
|
+
const t = useTranslations();
|
|
2530
|
+
const [open, setOpen] = React.useState(false);
|
|
2531
|
+
const containerRef = React.useRef(null);
|
|
2532
|
+
React.useEffect(() => {
|
|
2533
|
+
if (!open) {
|
|
2534
|
+
return;
|
|
2535
|
+
}
|
|
2536
|
+
const handleClickOutside = (event) => {
|
|
2537
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
2538
|
+
setOpen(false);
|
|
2539
|
+
}
|
|
2540
|
+
};
|
|
2541
|
+
const handleEscape = (event) => {
|
|
2542
|
+
if (event.key === "Escape") {
|
|
2543
|
+
setOpen(false);
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
2547
|
+
document.addEventListener("keydown", handleEscape);
|
|
2548
|
+
return () => {
|
|
2549
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
2550
|
+
document.removeEventListener("keydown", handleEscape);
|
|
2551
|
+
};
|
|
2552
|
+
}, [open]);
|
|
2553
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2554
|
+
"div",
|
|
2555
|
+
{
|
|
2556
|
+
ref: containerRef,
|
|
2557
|
+
className: "lex4-block-type-picker",
|
|
2558
|
+
"data-testid": "block-type-picker",
|
|
2559
|
+
children: [
|
|
2560
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2561
|
+
"button",
|
|
2562
|
+
{
|
|
2563
|
+
type: "button",
|
|
2564
|
+
className: `lex4-block-type-trigger${open ? " open" : ""}`,
|
|
2565
|
+
"data-testid": "block-type-selector",
|
|
2566
|
+
"aria-label": t.toolbar.blockType,
|
|
2567
|
+
"aria-expanded": open,
|
|
2568
|
+
"aria-haspopup": "menu",
|
|
2569
|
+
title: getBlockTypeLabel(t, value),
|
|
2570
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
2571
|
+
onClick: () => setOpen((current) => !current),
|
|
2572
|
+
children: [
|
|
2573
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2574
|
+
"span",
|
|
2575
|
+
{
|
|
2576
|
+
className: `lex4-block-type-trigger-code${value === "paragraph" ? "" : " heading"}`,
|
|
2577
|
+
children: getBlockTypeShortLabel(value)
|
|
2578
|
+
}
|
|
2579
|
+
),
|
|
2580
|
+
/* @__PURE__ */ jsxRuntime.jsx(ChevronDown, { size: 14, className: `lex4-block-type-trigger-chevron${open ? " open" : ""}` })
|
|
2581
|
+
]
|
|
2582
|
+
}
|
|
2583
|
+
),
|
|
2584
|
+
open && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2585
|
+
"div",
|
|
2586
|
+
{
|
|
2587
|
+
className: "lex4-block-type-menu",
|
|
2588
|
+
role: "menu",
|
|
2589
|
+
"data-testid": "block-type-menu",
|
|
2590
|
+
children: BLOCK_TYPE_OPTIONS.map((option) => {
|
|
2591
|
+
const label = getBlockTypeLabel(t, option.value);
|
|
2592
|
+
const active = option.value === value;
|
|
2593
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2594
|
+
"button",
|
|
2595
|
+
{
|
|
2596
|
+
type: "button",
|
|
2597
|
+
role: "menuitemradio",
|
|
2598
|
+
"aria-checked": active,
|
|
2599
|
+
className: `lex4-block-type-item${active ? " active" : ""}`,
|
|
2600
|
+
"data-testid": `block-type-option-${option.value}`,
|
|
2601
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
2602
|
+
onClick: () => {
|
|
2603
|
+
onChange(option.value);
|
|
2604
|
+
setOpen(false);
|
|
2605
|
+
},
|
|
2606
|
+
children: [
|
|
2607
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2608
|
+
"span",
|
|
2609
|
+
{
|
|
2610
|
+
className: `lex4-block-type-item-code${option.value === "paragraph" ? "" : " heading"}${active ? " active" : ""}`,
|
|
2611
|
+
children: option.shortLabel
|
|
2612
|
+
}
|
|
2613
|
+
),
|
|
2614
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "lex4-block-type-item-label", children: label })
|
|
2615
|
+
]
|
|
2616
|
+
},
|
|
2617
|
+
option.value
|
|
2618
|
+
);
|
|
2619
|
+
})
|
|
2620
|
+
}
|
|
2621
|
+
)
|
|
2622
|
+
]
|
|
2623
|
+
}
|
|
2624
|
+
);
|
|
2625
|
+
};
|
|
2489
2626
|
const HeaderFooterToggle = ({
|
|
2490
2627
|
enabled,
|
|
2491
2628
|
onToggle,
|
|
@@ -2984,19 +3121,9 @@ const Toolbar = () => {
|
|
|
2984
3121
|
[activeEditor, applyToBodyEditors, runToolbarAction, t.history.actions.fontSizeChanged]
|
|
2985
3122
|
);
|
|
2986
3123
|
const handleBlockTypeChange = React.useCallback(
|
|
2987
|
-
(
|
|
2988
|
-
const blockType = e.target.value;
|
|
2989
|
-
const labelMap = {
|
|
2990
|
-
paragraph: t.toolbar.paragraph,
|
|
2991
|
-
h1: t.toolbar.heading1,
|
|
2992
|
-
h2: t.toolbar.heading2,
|
|
2993
|
-
h3: t.toolbar.heading3,
|
|
2994
|
-
h4: t.toolbar.heading4,
|
|
2995
|
-
h5: t.toolbar.heading5,
|
|
2996
|
-
h6: t.toolbar.heading6
|
|
2997
|
-
};
|
|
3124
|
+
(blockType) => {
|
|
2998
3125
|
runToolbarAction(
|
|
2999
|
-
interpolate(t.history.actions.blockTypeChanged, { value:
|
|
3126
|
+
interpolate(t.history.actions.blockTypeChanged, { value: getBlockTypeLabel(t, blockType) }),
|
|
3000
3127
|
() => {
|
|
3001
3128
|
applyToBodyEditors((editor) => setBlockType(editor, blockType));
|
|
3002
3129
|
}
|
|
@@ -3006,13 +3133,7 @@ const Toolbar = () => {
|
|
|
3006
3133
|
applyToBodyEditors,
|
|
3007
3134
|
runToolbarAction,
|
|
3008
3135
|
t.history.actions.blockTypeChanged,
|
|
3009
|
-
t
|
|
3010
|
-
t.toolbar.heading2,
|
|
3011
|
-
t.toolbar.heading3,
|
|
3012
|
-
t.toolbar.heading4,
|
|
3013
|
-
t.toolbar.heading5,
|
|
3014
|
-
t.toolbar.heading6,
|
|
3015
|
-
t.toolbar.paragraph
|
|
3136
|
+
t
|
|
3016
3137
|
]
|
|
3017
3138
|
);
|
|
3018
3139
|
const handleToggleHistory = React.useCallback(() => {
|
|
@@ -3047,23 +3168,11 @@ const Toolbar = () => {
|
|
|
3047
3168
|
)
|
|
3048
3169
|
] }),
|
|
3049
3170
|
/* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
|
|
3050
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "lex4-toolbar-group
|
|
3051
|
-
|
|
3171
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "lex4-toolbar-group", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3172
|
+
BlockTypePicker,
|
|
3052
3173
|
{
|
|
3053
|
-
className: "lex4-toolbar-select lex4-toolbar-select-block",
|
|
3054
|
-
"data-testid": "block-type-selector",
|
|
3055
|
-
"aria-label": t.toolbar.blockType,
|
|
3056
3174
|
value: activeBlockType,
|
|
3057
|
-
onChange: handleBlockTypeChange
|
|
3058
|
-
children: [
|
|
3059
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "paragraph", children: t.toolbar.paragraph }),
|
|
3060
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "h1", children: t.toolbar.heading1 }),
|
|
3061
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "h2", children: t.toolbar.heading2 }),
|
|
3062
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "h3", children: t.toolbar.heading3 }),
|
|
3063
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "h4", children: t.toolbar.heading4 }),
|
|
3064
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "h5", children: t.toolbar.heading5 }),
|
|
3065
|
-
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "h6", children: t.toolbar.heading6 })
|
|
3066
|
-
]
|
|
3175
|
+
onChange: handleBlockTypeChange
|
|
3067
3176
|
}
|
|
3068
3177
|
) }),
|
|
3069
3178
|
/* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
|