@keboola/design 13.1.2 → 13.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @keboola/design
2
2
 
3
+ ## 13.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - `MarkdownEditor`'s link panel stays inside the viewport, and a nested list shows one marker per item.
8
+ - The link panel is a `Popover` anchored to the Insert Link button, in both `toolbarMode`s. It opens below the button at its left edge, shifts left to stay 8 px inside the viewport, and opens above the button when there is no room below. It used to hang off the button at a fixed 320 px, so in a narrow container (a reply box in a `Sheet`) it ran past the edge and the container clipped it.
9
+ - It renders in `document.body`, like the floating toolbar, so it wears the page theme and stacks over a surrounding `Modal` or `Sheet`. It takes the `Popover` surface: argo chrome gives it the larger radius.
10
+ - An outside click or focus closes it, and focus stays where the click or focus put it. It used to stay open.
11
+ - A second press of Insert Link closes it like Cancel. The button carries `aria-expanded` and `aria-controls`, and the panel is a dialog named `Insert Link`.
12
+ - The Label field takes focus, with its text selected, every time the panel opens, including a reopen while it is still animating out.
13
+ - Unchanged: both fields take clicks, Enter adds the link, Escape closes only the panel and returns focus to the editor (then the floating toolbar, then the dialog), and the editor's selection survives opening the panel and adding the link.
14
+ - With `saveOnBlur`, focus moving into anything the toolbar portals (the floating toolbar, the link panel, the Block type and Alignment menus) does not count as leaving the editor, in either mode. Opening either menu used to save. `onSave` still fires synchronously on a real blur.
15
+ - In a nested bullet, numbered or check list, the item that holds the nested list no longer draws a bullet, number or checkbox of its own beside the nested item's. The markdown it exports is unchanged.
16
+
3
17
  ## 13.1.2
4
18
 
5
19
  ### Patch Changes
@@ -14,7 +14,6 @@ import { Kbd } from "./Kbd-J4n1J6i4.js";
14
14
  import { toast } from "./toast-CyXEdaCZ.js";
15
15
  import { Suspense, createContext, lazy, use, useCallback, useEffect, useId, useRef, useState } from "react";
16
16
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
17
- import { DismissableLayer } from "@radix-ui/react-dismissable-layer";
18
17
  import { $createCodeNode, $isCodeNode, CodeNode } from "@lexical/code";
19
18
  import { AutoFocusPlugin } from "@lexical/react/LexicalAutoFocusPlugin";
20
19
  import { AutoLinkPlugin } from "@lexical/react/LexicalAutoLinkPlugin";
@@ -42,6 +41,11 @@ import { $convertFromMarkdownString, $convertToMarkdownString, CHECK_LIST, TRANS
42
41
  const ImageRendererContext = createContext(null);
43
42
  const ImageRendererProvider = ImageRendererContext;
44
43
  const useImageRenderer = () => use(ImageRendererContext);
44
+ const EditorLayerContext = createContext(void 0);
45
+ /** Takes the id `MarkdownEditor`'s blur guard matches on its toolbar's portalled layers. */
46
+ const EditorLayerProvider = EditorLayerContext;
47
+ /** Props for a layer the toolbar portals out of the editor, so its blur guard counts focus there. */
48
+ const useEditorLayer = () => ({ "data-editor-layer": use(EditorLayerContext) });
45
49
  //#endregion
46
50
  //#region src/blocks/MarkdownEditor/nodes/ImageNodeComponent.tsx
47
51
  const isPlaceholder = (src) => src.startsWith("upload-placeholder-");
@@ -760,6 +764,7 @@ const TRIGGER_LABEL = "Text alignment";
760
764
  const ALIGNMENT_ICONS = Object.fromEntries(ALIGNMENT_OPTIONS.map(({ value, icon }) => [value, icon]));
761
765
  const AlignmentDropdown = ({ editor, alignment }) => {
762
766
  const savedSelectionRef = useRef(null);
767
+ const editorLayer = useEditorLayer();
763
768
  const handleOpenChange = (open) => {
764
769
  if (open) editor.getEditorState().read(() => {
765
770
  const selection = $getSelection();
@@ -789,6 +794,7 @@ const AlignmentDropdown = ({ editor, alignment }) => {
789
794
  })
790
795
  })
791
796
  }), /* @__PURE__ */ jsx(DropdownMenu.Content, {
797
+ ...editorLayer,
792
798
  align: "start",
793
799
  className: "tw:min-w-32",
794
800
  children: ALIGNMENT_OPTIONS.map(({ value, label, icon: IconComp }) => /* @__PURE__ */ jsxs(DropdownMenu.Item, {
@@ -851,6 +857,7 @@ const BLOCK_TYPE_OPTIONS = Object.entries(BLOCK_TYPE_META).filter(([, meta]) =>
851
857
  const isBlockType = (value) => Object.prototype.hasOwnProperty.call(BLOCK_TYPE_META, value);
852
858
  const BlockTypeDropdown = ({ editor, blockType }) => {
853
859
  const savedSelectionRef = useRef(null);
860
+ const editorLayer = useEditorLayer();
854
861
  const currentMeta = isBlockType(blockType) ? BLOCK_TYPE_META[blockType] : null;
855
862
  const CurrentBlockIcon = currentMeta?.icon ?? Type;
856
863
  const handleOpenChange = (open) => {
@@ -898,6 +905,7 @@ const BlockTypeDropdown = ({ editor, blockType }) => {
898
905
  })
899
906
  })
900
907
  }), /* @__PURE__ */ jsx(DropdownMenu.Content, {
908
+ ...editorLayer,
901
909
  align: "start",
902
910
  className: "tw:min-w-40",
903
911
  children: BLOCK_TYPE_OPTIONS.map(({ value, label, icon: IconComp }) => /* @__PURE__ */ jsxs(DropdownMenu.Item, {
@@ -922,7 +930,12 @@ const MOD_KEY = IS_APPLE ? {
922
930
  aria: "Control",
923
931
  symbol: "Ctrl"
924
932
  };
925
- const ToolbarButton = ({ active, disabled, onClick, tooltip, shortcutKey, children, className: extraClassName }) => /* @__PURE__ */ jsx(Tooltip, {
933
+ /**
934
+ * An icon button named by its tooltip.
935
+ *
936
+ * - Other props reach the `<button>`, so it can be a trigger; they cannot rename it.
937
+ */
938
+ const ToolbarButton = ({ active, tooltip, shortcutKey, children, className: extraClassName, ...props }) => /* @__PURE__ */ jsx(Tooltip, {
926
939
  tooltip: shortcutKey ? /* @__PURE__ */ jsxs("span", {
927
940
  className: "tw:inline-flex tw:items-center tw:gap-2",
928
941
  children: [tooltip, /* @__PURE__ */ jsxs(Kbd.Group, {
@@ -941,16 +954,16 @@ const ToolbarButton = ({ active, disabled, onClick, tooltip, shortcutKey, childr
941
954
  triggerAsChild: true,
942
955
  children: /* @__PURE__ */ jsx("button", {
943
956
  type: "button",
957
+ ...props,
944
958
  "aria-label": tooltip,
945
959
  "aria-keyshortcuts": shortcutKey ? `${MOD_KEY.aria}+${shortcutKey}` : void 0,
946
- disabled,
947
- onClick,
948
960
  className: cn("tw:flex tw:h-7 tw:min-w-7 tw:cursor-pointer tw:items-center tw:justify-center tw:rounded tw:border-0 tw:bg-transparent tw:px-1 tw:text-xs tw:text-muted-foreground", "tw:hover:bg-accent tw:disabled:cursor-not-allowed tw:disabled:opacity-30", active && "tw:bg-secondary-100 tw:text-secondary-500", extraClassName),
949
961
  children
950
962
  })
951
963
  });
952
964
  //#endregion
953
965
  //#region src/blocks/MarkdownEditor/plugins/toolbar/LinkPanel.tsx
966
+ const PANEL_NAME = "Insert Link";
954
967
  const insertLink = (editor, url, label, savedSelection) => {
955
968
  editor.update(() => {
956
969
  $setSelection(savedSelection);
@@ -969,13 +982,25 @@ const insertLink = (editor, url, label, savedSelection) => {
969
982
  });
970
983
  };
971
984
  const LinkPanel = ({ editor, isLink }) => {
985
+ const editorLayer = useEditorLayer();
972
986
  const [open, setOpen] = useState(false);
973
987
  const [url, setUrl] = useState("");
974
988
  const [label, setLabel] = useState("");
975
989
  const savedSelectionRef = useRef(null);
976
990
  const panelRef = useRef(null);
991
+ const labelRef = useRef(null);
977
992
  const labelId = useId();
978
993
  const urlId = useId();
994
+ /**
995
+ * Focuses and selects the Label field on every open.
996
+ *
997
+ * - `FocusScope` does it only on mount, and a reopen during the exit animation reuses the panel.
998
+ */
999
+ useEffect(() => {
1000
+ if (!open) return;
1001
+ labelRef.current?.focus({ preventScroll: true });
1002
+ labelRef.current?.select();
1003
+ }, [open]);
979
1004
  const handleOpen = () => {
980
1005
  editor.getEditorState().read(() => {
981
1006
  const selection = $getSelection();
@@ -998,14 +1023,14 @@ const LinkPanel = ({ editor, isLink }) => {
998
1023
  editor.focus();
999
1024
  };
1000
1025
  /**
1001
- * Closes the panel on Escape pressed anywhere while it is open.
1026
+ * Opens the panel, or closes it however Radix asks: Escape, its button again, an outside click.
1002
1027
  *
1003
- * - `preventDefault` claims the key from a surface outside Radix's stack (`FullScreenModal`).
1004
- * - Focus goes back to the editor only from inside the panel; anywhere else it stays put.
1028
+ * - Focus still in the panel (Escape, or the button, which leaves focus put): the editor takes it.
1029
+ * - Focus already elsewhere (an outside click or focus): it stays there.
1005
1030
  */
1006
- const handleEscape = (event) => {
1007
- event.preventDefault();
1008
- if (panelRef.current?.contains(document.activeElement)) handleClose();
1031
+ const handleOpenChange = (next) => {
1032
+ if (next) handleOpen();
1033
+ else if (panelRef.current?.contains(document.activeElement)) handleClose();
1009
1034
  else resetPanel();
1010
1035
  };
1011
1036
  const handleSubmit = () => {
@@ -1026,58 +1051,62 @@ const LinkPanel = ({ editor, isLink }) => {
1026
1051
  tooltip: "Remove Link",
1027
1052
  children: /* @__PURE__ */ jsx(Link, { className: "tw:size-4" })
1028
1053
  });
1029
- return /* @__PURE__ */ jsxs("div", {
1030
- className: "tw:relative",
1031
- children: [/* @__PURE__ */ jsx(ToolbarButton, {
1032
- active: open,
1033
- onClick: handleOpen,
1034
- tooltip: "Insert Link",
1035
- children: /* @__PURE__ */ jsx(Link, { className: "tw:size-4" })
1036
- }), open && /* @__PURE__ */ jsx(DismissableLayer, {
1037
- ref: panelRef,
1038
- onEscapeKeyDown: handleEscape,
1039
- className: "tw:absolute tw:left-0 tw:top-full tw:z-50 tw:mt-1 tw:w-80 tw:rounded-md tw:border tw:border-border tw:bg-popover tw:p-3 tw:text-popover-foreground tw:shadow-lg",
1040
- children: /* @__PURE__ */ jsxs("div", {
1041
- className: "tw:flex tw:flex-col tw:gap-2",
1042
- children: [
1043
- /* @__PURE__ */ jsxs(FormGroup, { children: [/* @__PURE__ */ jsx(Label, {
1044
- htmlFor: labelId,
1045
- className: "tw:mb-1 tw:text-xs",
1046
- children: "Label"
1047
- }), /* @__PURE__ */ jsx(TextInput, {
1048
- id: labelId,
1049
- autoFocus: true,
1050
- placeholder: "Link text",
1051
- value: label,
1052
- onValueChange: setLabel,
1053
- onKeyDown: handleKeyDown,
1054
- variant: "secondary"
1055
- })] }),
1056
- /* @__PURE__ */ jsxs(FormGroup, { children: [/* @__PURE__ */ jsx(Label, {
1057
- htmlFor: urlId,
1058
- className: "tw:mb-1 tw:text-xs",
1059
- children: "URL"
1060
- }), /* @__PURE__ */ jsx(TextInput, {
1061
- id: urlId,
1062
- placeholder: "https://…",
1063
- value: url,
1064
- onValueChange: setUrl,
1065
- onKeyDown: handleKeyDown,
1066
- variant: "secondary"
1067
- })] }),
1068
- /* @__PURE__ */ jsxs(ButtonGroup, { children: [/* @__PURE__ */ jsx(Button, {
1069
- size: "small",
1070
- variant: "outline",
1071
- onClick: handleClose,
1072
- children: "Cancel"
1073
- }), /* @__PURE__ */ jsx(Button, {
1074
- size: "small",
1075
- onClick: handleSubmit,
1076
- disabled: !url.trim(),
1077
- children: "Add link"
1078
- })] })
1079
- ]
1054
+ return /* @__PURE__ */ jsxs(Popover, {
1055
+ open,
1056
+ onOpenChange: handleOpenChange,
1057
+ children: [/* @__PURE__ */ jsx(Popover.Trigger, {
1058
+ asChild: true,
1059
+ children: /* @__PURE__ */ jsx(ToolbarButton, {
1060
+ active: open,
1061
+ tooltip: PANEL_NAME,
1062
+ children: /* @__PURE__ */ jsx(Link, { className: "tw:size-4" })
1080
1063
  })
1064
+ }), /* @__PURE__ */ jsxs(Popover.Content, {
1065
+ ref: panelRef,
1066
+ "aria-label": PANEL_NAME,
1067
+ ...editorLayer,
1068
+ align: "start",
1069
+ collisionPadding: 8,
1070
+ onCloseAutoFocus: (event) => event.preventDefault(),
1071
+ className: "tw:w-80 tw:max-w-[calc(100vw-1rem)] tw:gap-2 tw:p-3",
1072
+ children: [
1073
+ /* @__PURE__ */ jsxs(FormGroup, { children: [/* @__PURE__ */ jsx(Label, {
1074
+ htmlFor: labelId,
1075
+ className: "tw:mb-1 tw:text-xs",
1076
+ children: "Label"
1077
+ }), /* @__PURE__ */ jsx(TextInput, {
1078
+ ref: labelRef,
1079
+ id: labelId,
1080
+ placeholder: "Link text",
1081
+ value: label,
1082
+ onValueChange: setLabel,
1083
+ onKeyDown: handleKeyDown,
1084
+ variant: "secondary"
1085
+ })] }),
1086
+ /* @__PURE__ */ jsxs(FormGroup, { children: [/* @__PURE__ */ jsx(Label, {
1087
+ htmlFor: urlId,
1088
+ className: "tw:mb-1 tw:text-xs",
1089
+ children: "URL"
1090
+ }), /* @__PURE__ */ jsx(TextInput, {
1091
+ id: urlId,
1092
+ placeholder: "https://…",
1093
+ value: url,
1094
+ onValueChange: setUrl,
1095
+ onKeyDown: handleKeyDown,
1096
+ variant: "secondary"
1097
+ })] }),
1098
+ /* @__PURE__ */ jsxs(ButtonGroup, { children: [/* @__PURE__ */ jsx(Button, {
1099
+ size: "small",
1100
+ variant: "outline",
1101
+ onClick: handleClose,
1102
+ children: "Cancel"
1103
+ }), /* @__PURE__ */ jsx(Button, {
1104
+ size: "small",
1105
+ onClick: handleSubmit,
1106
+ disabled: !url.trim(),
1107
+ children: "Add link"
1108
+ })] })
1109
+ ]
1081
1110
  })]
1082
1111
  });
1083
1112
  };
@@ -1103,6 +1132,7 @@ const hasFocus = (element) => !!element?.contains(document.activeElement);
1103
1132
  * Keeps focus, and the editor selection with it, where it was when a toolbar control is pressed.
1104
1133
  *
1105
1134
  * - A link panel field takes focus as usual, so a click there lands the caret in it.
1135
+ * - The link panel is portalled, but React bubbles its events up here all the same.
1106
1136
  */
1107
1137
  const keepEditorFocus = (event) => {
1108
1138
  if (event.target instanceof HTMLInputElement) return;
@@ -1110,6 +1140,7 @@ const keepEditorFocus = (event) => {
1110
1140
  };
1111
1141
  const ToolbarPlugin = ({ mode = "floating" }) => {
1112
1142
  const [editor] = useLexicalComposerContext();
1143
+ const editorLayer = useEditorLayer();
1113
1144
  const [isBold, setIsBold] = useState(false);
1114
1145
  const [isItalic, setIsItalic] = useState(false);
1115
1146
  const [isUnderline, setIsUnderline] = useState(false);
@@ -1364,6 +1395,7 @@ const ToolbarPlugin = ({ mode = "floating" }) => {
1364
1395
  return /* @__PURE__ */ jsxs(Popover, {
1365
1396
  open: true,
1366
1397
  children: [/* @__PURE__ */ jsx(Popover.Anchor, { virtualRef: { current: anchor } }), /* @__PURE__ */ jsx(Popover.Content, {
1398
+ ...editorLayer,
1367
1399
  ref: toolbarRef,
1368
1400
  role: "toolbar",
1369
1401
  "aria-label": "Formatting options",
@@ -1375,7 +1407,7 @@ const ToolbarPlugin = ({ mode = "floating" }) => {
1375
1407
  onEscapeKeyDown: handleEscape,
1376
1408
  onInteractOutside: handleInteractOutside,
1377
1409
  onMouseDown: keepEditorFocus,
1378
- className: cn(TOOLBAR_BASE_CLASS, "tw:flex-row tw:overflow-visible"),
1410
+ className: cn(TOOLBAR_BASE_CLASS, "tw:flex-row"),
1379
1411
  children: buttons
1380
1412
  })]
1381
1413
  });
@@ -1401,6 +1433,7 @@ const editorTheme = {
1401
1433
  ol: "tw:!list-decimal",
1402
1434
  ul: "tw:!list-disc",
1403
1435
  checklist: "tw:!list-none tw:!pl-0",
1436
+ nested: { listitem: "tw:list-none tw:before:hidden tw:after:hidden" },
1404
1437
  listitemChecked: [
1405
1438
  "tw:relative tw:!pl-6 tw:list-none tw:outline-hidden tw:line-through tw:text-muted-foreground",
1406
1439
  "tw:before:content-[\"\"] tw:before:absolute tw:before:left-0 tw:before:top-[3px]",
@@ -1444,12 +1477,14 @@ const MarkdownEditor = ({ value, onChange, readOnly = false, placeholder, autoFo
1444
1477
  }
1445
1478
  }));
1446
1479
  const skipBlurSaveRef = useRef(false);
1480
+ const layerId = useId();
1447
1481
  const handleBlur = saveOnBlur && onSave ? (event) => {
1448
1482
  if (skipBlurSaveRef.current) {
1449
1483
  skipBlurSaveRef.current = false;
1450
1484
  return;
1451
1485
  }
1452
- if (!event.currentTarget.contains(event.relatedTarget)) onSave();
1486
+ const next = event.relatedTarget;
1487
+ if (!event.currentTarget.contains(next) && !next?.closest(`[data-editor-layer="${layerId}"]`)) onSave();
1453
1488
  } : void 0;
1454
1489
  return /* @__PURE__ */ jsx(LexicalComposer, {
1455
1490
  initialConfig,
@@ -1459,7 +1494,10 @@ const MarkdownEditor = ({ value, onChange, readOnly = false, placeholder, autoFo
1459
1494
  className: cn(!compact && "tw:prose", compact && "tw:[&_p]:m-0 tw:[&_p+p]:mt-2", clampDisplay && "tw:[&:not(:focus-within)]:line-clamp-2", className),
1460
1495
  onBlur: handleBlur,
1461
1496
  children: [
1462
- showToolbar && editable && /* @__PURE__ */ jsx(ToolbarPlugin, { mode: toolbarMode }),
1497
+ showToolbar && editable && /* @__PURE__ */ jsx(EditorLayerProvider, {
1498
+ value: layerId,
1499
+ children: /* @__PURE__ */ jsx(ToolbarPlugin, { mode: toolbarMode })
1500
+ }),
1463
1501
  /* @__PURE__ */ jsx("div", {
1464
1502
  className: cn("tw:relative tw:rounded-md tw:transition-colors", contentPadding, compact && "tw:-mx-1.5 tw:-my-0.5", editable && "tw:cursor-text tw:hover:bg-muted tw:focus-within:ring-2 tw:focus-within:ring-ring/40"),
1465
1503
  children: /* @__PURE__ */ jsx(RichTextPlugin, {