@bizapps/design-system-testing 1.7.1 → 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,8 +1105,10 @@ function useRichTextEditor({
1033
1105
  onInsertImage,
1034
1106
  extraExtensions = [],
1035
1107
  extraToolbar = [],
1108
+ replaceToolbar,
1036
1109
  contentClassName,
1037
- allowBase64Images = false
1110
+ allowBase64Images = false,
1111
+ editorProps
1038
1112
  }) {
1039
1113
  const [linkNeedsText, setLinkNeedsText] = react.useState(false);
1040
1114
  const editor = react$1.useEditor({
@@ -1057,6 +1131,7 @@ function useRichTextEditor({
1057
1131
  // repaint as the selection and attributes change.
1058
1132
  shouldRerenderOnTransaction: true,
1059
1133
  editorProps: {
1134
+ ...editorProps,
1060
1135
  attributes: {
1061
1136
  // ProseMirror's editable div needs its own accessible name: a
1062
1137
  // visible <Label> beside it is decoration, and a screen reader
@@ -1226,7 +1301,9 @@ function useRichTextEditor({
1226
1301
  )
1227
1302
  }
1228
1303
  ];
1229
- let items = builtIn;
1304
+ let items = replaceToolbar ? builtIn.map(
1305
+ (item) => item.kind !== "separator" && replaceToolbar[item.id] ? replaceToolbar[item.id] : item
1306
+ ) : builtIn;
1230
1307
  const appended = [];
1231
1308
  for (const group of extraToolbar) {
1232
1309
  if (!group.after) {
@@ -1243,8 +1320,9 @@ function useRichTextEditor({
1243
1320
  items = [...items.slice(0, at + 1), ...group.items, ...items.slice(at + 1)];
1244
1321
  }
1245
1322
  return [...items, ...appended];
1246
- }, [labels, extraToolbar, onInsertImage, openLink]);
1247
- 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 };
1248
1326
  }
1249
1327
  function ColorMenu({ editor, labels, icon, swatches }) {
1250
1328
  const active = swatches.find((swatch) => editor?.isActive(swatch.mark));
@@ -1384,78 +1462,6 @@ function InsertLinkDialog({
1384
1462
  ] })
1385
1463
  ] }) });
1386
1464
  }
1387
- function LinkActions({ editor, labels, onEdit, onOpen }) {
1388
- const href = react$1.useEditorState({
1389
- editor,
1390
- selector: ({ editor: current }) => current.getAttributes("link").href ?? ""
1391
- });
1392
- return /* @__PURE__ */ jsxRuntime.jsxs(
1393
- "div",
1394
- {
1395
- "data-slot": "link-bubble-menu",
1396
- className: "bg-popover text-popover-foreground flex items-center gap-1 rounded-md border p-1 shadow-md",
1397
- children: [
1398
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground max-w-[16rem] truncate px-2 text-xs", children: href }),
1399
- /* @__PURE__ */ jsxRuntime.jsx(
1400
- Button,
1401
- {
1402
- type: "button",
1403
- size: "sm",
1404
- variant: "ghost",
1405
- title: labels.open,
1406
- "aria-label": labels.open,
1407
- disabled: !href,
1408
- onClick: () => {
1409
- if (!href) return;
1410
- if (onOpen) {
1411
- onOpen(href);
1412
- return;
1413
- }
1414
- window.open(href, "_blank", "noopener,noreferrer");
1415
- },
1416
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { className: "h-4 w-4" })
1417
- }
1418
- ),
1419
- /* @__PURE__ */ jsxRuntime.jsx(
1420
- Button,
1421
- {
1422
- type: "button",
1423
- size: "sm",
1424
- variant: "ghost",
1425
- title: labels.edit,
1426
- "aria-label": labels.edit,
1427
- onClick: onEdit,
1428
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-4 w-4" })
1429
- }
1430
- ),
1431
- /* @__PURE__ */ jsxRuntime.jsx(
1432
- Button,
1433
- {
1434
- type: "button",
1435
- size: "sm",
1436
- variant: "ghost",
1437
- className: "text-destructive",
1438
- title: labels.remove,
1439
- "aria-label": labels.remove,
1440
- onClick: () => editor.chain().focus().extendMarkRange("link").unsetLink().run(),
1441
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Unlink, { className: "h-4 w-4" })
1442
- }
1443
- )
1444
- ]
1445
- }
1446
- );
1447
- }
1448
- function LinkBubbleMenu({ editor, labels, onEdit, onOpen }) {
1449
- const shouldShow = react.useCallback(
1450
- // Only while the caret is actually in a link — otherwise this bar would
1451
- // compete with any other bubble menu the consumer adds.
1452
- ({ editor: current }) => current.isActive("link"),
1453
- []
1454
- );
1455
- const options = react.useMemo(() => ({ placement: "bottom", offset: 8 }), []);
1456
- if (!editor) return null;
1457
- return /* @__PURE__ */ jsxRuntime.jsx(menus.BubbleMenu, { editor, shouldShow, options, children: /* @__PURE__ */ jsxRuntime.jsx(LinkActions, { editor, labels, onEdit, onOpen }) });
1458
- }
1459
1465
 
1460
1466
  exports.ColorMenu = ColorMenu;
1461
1467
  exports.EDITOR_CONTENT_STYLE = EDITOR_CONTENT_STYLE;