@bizapps/design-system-testing 1.7.2 → 1.8.0

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/editor.cjs CHANGED
@@ -981,6 +981,78 @@ function createResizableImage(options) {
981
981
  }
982
982
  });
983
983
  }
984
+ function LinkActions({ editor, labels, onEdit, onOpen }) {
985
+ const href = react$1.useEditorState({
986
+ editor,
987
+ selector: ({ editor: current }) => current.getAttributes("link").href ?? ""
988
+ });
989
+ return /* @__PURE__ */ jsxRuntime.jsxs(
990
+ "div",
991
+ {
992
+ "data-slot": "link-bubble-menu",
993
+ className: "bg-popover text-popover-foreground flex items-center gap-1 rounded-md border p-1 shadow-md",
994
+ children: [
995
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground max-w-[16rem] truncate px-2 text-xs", children: href }),
996
+ /* @__PURE__ */ jsxRuntime.jsx(
997
+ Button,
998
+ {
999
+ type: "button",
1000
+ size: "sm",
1001
+ variant: "ghost",
1002
+ title: labels.open,
1003
+ "aria-label": labels.open,
1004
+ disabled: !href,
1005
+ onClick: () => {
1006
+ if (!href) return;
1007
+ if (onOpen) {
1008
+ onOpen(href);
1009
+ return;
1010
+ }
1011
+ window.open(href, "_blank", "noopener,noreferrer");
1012
+ },
1013
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { className: "h-4 w-4" })
1014
+ }
1015
+ ),
1016
+ /* @__PURE__ */ jsxRuntime.jsx(
1017
+ Button,
1018
+ {
1019
+ type: "button",
1020
+ size: "sm",
1021
+ variant: "ghost",
1022
+ title: labels.edit,
1023
+ "aria-label": labels.edit,
1024
+ onClick: onEdit,
1025
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-4 w-4" })
1026
+ }
1027
+ ),
1028
+ /* @__PURE__ */ jsxRuntime.jsx(
1029
+ Button,
1030
+ {
1031
+ type: "button",
1032
+ size: "sm",
1033
+ variant: "ghost",
1034
+ className: "text-destructive",
1035
+ title: labels.remove,
1036
+ "aria-label": labels.remove,
1037
+ onClick: () => editor.chain().focus().extendMarkRange("link").unsetLink().run(),
1038
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Unlink, { className: "h-4 w-4" })
1039
+ }
1040
+ )
1041
+ ]
1042
+ }
1043
+ );
1044
+ }
1045
+ function LinkBubbleMenu({ editor, labels, onEdit, onOpen }) {
1046
+ const shouldShow = react.useCallback(
1047
+ // Only while the caret is actually in a link — otherwise this bar would
1048
+ // compete with any other bubble menu the consumer adds.
1049
+ ({ editor: current }) => current.isActive("link"),
1050
+ []
1051
+ );
1052
+ const options = react.useMemo(() => ({ placement: "bottom", offset: 8 }), []);
1053
+ if (!editor) return null;
1054
+ return /* @__PURE__ */ jsxRuntime.jsx(menus.BubbleMenu, { editor, shouldShow, options, children: /* @__PURE__ */ jsxRuntime.jsx(LinkActions, { editor, labels, onEdit, onOpen }) });
1055
+ }
984
1056
  function ListMenu({ editor, triggerLabel, icon, options }) {
985
1057
  const active = options.find((option) => editor?.isActive(option.node));
986
1058
  return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
@@ -1033,6 +1105,7 @@ function useRichTextEditor({
1033
1105
  onInsertImage,
1034
1106
  extraExtensions = [],
1035
1107
  extraToolbar = [],
1108
+ replaceToolbar,
1036
1109
  contentClassName,
1037
1110
  allowBase64Images = false,
1038
1111
  editorProps
@@ -1228,7 +1301,9 @@ function useRichTextEditor({
1228
1301
  )
1229
1302
  }
1230
1303
  ];
1231
- let items = builtIn;
1304
+ let items = replaceToolbar ? builtIn.map(
1305
+ (item) => item.kind !== "separator" && replaceToolbar[item.id] ? replaceToolbar[item.id] : item
1306
+ ) : builtIn;
1232
1307
  const appended = [];
1233
1308
  for (const group of extraToolbar) {
1234
1309
  if (!group.after) {
@@ -1245,8 +1320,9 @@ function useRichTextEditor({
1245
1320
  items = [...items.slice(0, at + 1), ...group.items, ...items.slice(at + 1)];
1246
1321
  }
1247
1322
  return [...items, ...appended];
1248
- }, [labels, extraToolbar, onInsertImage, openLink]);
1249
- return { editor, toolbar, linkNeedsText, currentLinkHref, applyLink };
1323
+ }, [labels, extraToolbar, replaceToolbar, onInsertImage, openLink]);
1324
+ const linkMenu = /* @__PURE__ */ jsxRuntime.jsx(LinkBubbleMenu, { editor, labels: labels.link, onEdit: openLink });
1325
+ return { editor, toolbar, linkMenu, linkNeedsText, currentLinkHref, applyLink };
1250
1326
  }
1251
1327
  function ColorMenu({ editor, labels, icon, swatches }) {
1252
1328
  const active = swatches.find((swatch) => editor?.isActive(swatch.mark));
@@ -1386,78 +1462,6 @@ function InsertLinkDialog({
1386
1462
  ] })
1387
1463
  ] }) });
1388
1464
  }
1389
- function LinkActions({ editor, labels, onEdit, onOpen }) {
1390
- const href = react$1.useEditorState({
1391
- editor,
1392
- selector: ({ editor: current }) => current.getAttributes("link").href ?? ""
1393
- });
1394
- return /* @__PURE__ */ jsxRuntime.jsxs(
1395
- "div",
1396
- {
1397
- "data-slot": "link-bubble-menu",
1398
- className: "bg-popover text-popover-foreground flex items-center gap-1 rounded-md border p-1 shadow-md",
1399
- children: [
1400
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground max-w-[16rem] truncate px-2 text-xs", children: href }),
1401
- /* @__PURE__ */ jsxRuntime.jsx(
1402
- Button,
1403
- {
1404
- type: "button",
1405
- size: "sm",
1406
- variant: "ghost",
1407
- title: labels.open,
1408
- "aria-label": labels.open,
1409
- disabled: !href,
1410
- onClick: () => {
1411
- if (!href) return;
1412
- if (onOpen) {
1413
- onOpen(href);
1414
- return;
1415
- }
1416
- window.open(href, "_blank", "noopener,noreferrer");
1417
- },
1418
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { className: "h-4 w-4" })
1419
- }
1420
- ),
1421
- /* @__PURE__ */ jsxRuntime.jsx(
1422
- Button,
1423
- {
1424
- type: "button",
1425
- size: "sm",
1426
- variant: "ghost",
1427
- title: labels.edit,
1428
- "aria-label": labels.edit,
1429
- onClick: onEdit,
1430
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-4 w-4" })
1431
- }
1432
- ),
1433
- /* @__PURE__ */ jsxRuntime.jsx(
1434
- Button,
1435
- {
1436
- type: "button",
1437
- size: "sm",
1438
- variant: "ghost",
1439
- className: "text-destructive",
1440
- title: labels.remove,
1441
- "aria-label": labels.remove,
1442
- onClick: () => editor.chain().focus().extendMarkRange("link").unsetLink().run(),
1443
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Unlink, { className: "h-4 w-4" })
1444
- }
1445
- )
1446
- ]
1447
- }
1448
- );
1449
- }
1450
- function LinkBubbleMenu({ editor, labels, onEdit, onOpen }) {
1451
- const shouldShow = react.useCallback(
1452
- // Only while the caret is actually in a link — otherwise this bar would
1453
- // compete with any other bubble menu the consumer adds.
1454
- ({ editor: current }) => current.isActive("link"),
1455
- []
1456
- );
1457
- const options = react.useMemo(() => ({ placement: "bottom", offset: 8 }), []);
1458
- if (!editor) return null;
1459
- return /* @__PURE__ */ jsxRuntime.jsx(menus.BubbleMenu, { editor, shouldShow, options, children: /* @__PURE__ */ jsxRuntime.jsx(LinkActions, { editor, labels, onEdit, onOpen }) });
1460
- }
1461
1465
 
1462
1466
  exports.ColorMenu = ColorMenu;
1463
1467
  exports.EDITOR_CONTENT_STYLE = EDITOR_CONTENT_STYLE;