@bettercms-ai/kit 3.2.0 → 4.1.1

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.
Files changed (135) hide show
  1. package/dist/adapters/lossy.d.ts +4 -0
  2. package/dist/adapters/lossy.js +4 -0
  3. package/dist/adapters/lossy.js.map +1 -1
  4. package/dist/adapters/prod-types.d.ts +4 -0
  5. package/dist/adapters/prod-types.js +4 -1
  6. package/dist/adapters/prod-types.js.map +1 -1
  7. package/dist/adapters/schema.js +7 -0
  8. package/dist/adapters/schema.js.map +1 -1
  9. package/dist/context.d.ts +81 -4
  10. package/dist/context.js +58 -1
  11. package/dist/context.js.map +1 -1
  12. package/dist/controls/choice.d.ts +1 -1
  13. package/dist/controls/choice.js +21 -2
  14. package/dist/controls/choice.js.map +1 -1
  15. package/dist/controls/index.d.ts +1 -0
  16. package/dist/controls/index.js +3 -2
  17. package/dist/controls/index.js.map +1 -1
  18. package/dist/controls/link.d.ts +23 -2
  19. package/dist/controls/link.js +456 -4
  20. package/dist/controls/link.js.map +1 -1
  21. package/dist/controls/media-v16.d.ts +27 -0
  22. package/dist/controls/media-v16.js +261 -0
  23. package/dist/controls/media-v16.js.map +1 -0
  24. package/dist/controls/media.js +63 -1
  25. package/dist/controls/media.js.map +1 -1
  26. package/dist/controls/reference-services.d.ts +8 -0
  27. package/dist/controls/reference.js +78 -2
  28. package/dist/controls/reference.js.map +1 -1
  29. package/dist/controls/rich-text/ai-runs.d.ts +13 -0
  30. package/dist/controls/rich-text/ai-runs.js +71 -0
  31. package/dist/controls/rich-text/ai-runs.js.map +1 -0
  32. package/dist/controls/rich-text/block-tool.d.ts +31 -0
  33. package/dist/controls/rich-text/block-tool.js +62 -0
  34. package/dist/controls/rich-text/block-tool.js.map +1 -0
  35. package/dist/controls/rich-text/blocks.d.ts +6 -1
  36. package/dist/controls/rich-text/blocks.js +404 -24
  37. package/dist/controls/rich-text/blocks.js.map +1 -1
  38. package/dist/controls/rich-text/catalog.d.ts +21 -6
  39. package/dist/controls/rich-text/catalog.js +312 -23
  40. package/dist/controls/rich-text/catalog.js.map +1 -1
  41. package/dist/controls/rich-text/code-head.d.ts +30 -0
  42. package/dist/controls/rich-text/code-head.js +230 -0
  43. package/dist/controls/rich-text/code-head.js.map +1 -0
  44. package/dist/controls/rich-text/codec.d.ts +3 -3
  45. package/dist/controls/rich-text/codec.js +3 -1
  46. package/dist/controls/rich-text/codec.js.map +1 -1
  47. package/dist/controls/rich-text/control.d.ts +1 -1
  48. package/dist/controls/rich-text/control.js +11 -29
  49. package/dist/controls/rich-text/control.js.map +1 -1
  50. package/dist/controls/rich-text/dom.d.ts +27 -0
  51. package/dist/controls/rich-text/dom.js +69 -4
  52. package/dist/controls/rich-text/dom.js.map +1 -1
  53. package/dist/controls/rich-text/editor.js +212 -50
  54. package/dist/controls/rich-text/editor.js.map +1 -1
  55. package/dist/controls/rich-text/ops.js +1 -0
  56. package/dist/controls/rich-text/ops.js.map +1 -1
  57. package/dist/controls/rich-text/slash-preview.d.ts +8 -0
  58. package/dist/controls/rich-text/slash-preview.js +287 -0
  59. package/dist/controls/rich-text/slash-preview.js.map +1 -0
  60. package/dist/controls/rich-text/table-grid.d.ts +22 -0
  61. package/dist/controls/rich-text/table-grid.js +1052 -0
  62. package/dist/controls/rich-text/table-grid.js.map +1 -0
  63. package/dist/controls/rich-text/toolbar.js +60 -18
  64. package/dist/controls/rich-text/toolbar.js.map +1 -1
  65. package/dist/controls/text.d.ts +6 -0
  66. package/dist/controls/text.js +95 -5
  67. package/dist/controls/text.js.map +1 -1
  68. package/dist/core/facets.d.ts +1 -0
  69. package/dist/core/facets.js +1 -0
  70. package/dist/core/facets.js.map +1 -1
  71. package/dist/engine/array.d.ts +7 -0
  72. package/dist/engine/array.js +164 -45
  73. package/dist/engine/array.js.map +1 -1
  74. package/dist/engine/expand.d.ts +1 -1
  75. package/dist/engine/expand.js +1 -1
  76. package/dist/engine/expand.js.map +1 -1
  77. package/dist/engine/field-shell.d.ts +12 -0
  78. package/dist/engine/field-shell.js +217 -63
  79. package/dist/engine/field-shell.js.map +1 -1
  80. package/dist/engine/frame.js +39 -2
  81. package/dist/engine/frame.js.map +1 -1
  82. package/dist/engine/grouping.d.ts +71 -10
  83. package/dist/engine/grouping.js +223 -26
  84. package/dist/engine/grouping.js.map +1 -1
  85. package/dist/engine/held.d.ts +2 -2
  86. package/dist/engine/held.js +2 -2
  87. package/dist/engine/held.js.map +1 -1
  88. package/dist/engine/kit-field.d.ts +0 -10
  89. package/dist/engine/kit-field.js +40 -72
  90. package/dist/engine/kit-field.js.map +1 -1
  91. package/dist/engine/schema-form.js +7 -2
  92. package/dist/engine/schema-form.js.map +1 -1
  93. package/dist/index.d.ts +1 -1
  94. package/dist/index.js +14 -7
  95. package/dist/index.js.map +1 -1
  96. package/dist/kit.css +85 -0
  97. package/dist/schema/table.d.ts +2 -1
  98. package/dist/schema/table.js +5 -0
  99. package/dist/schema/table.js.map +1 -1
  100. package/dist/schema/types.d.ts +6 -0
  101. package/dist/schema/types.js.map +1 -1
  102. package/dist/styles.css +1 -1
  103. package/dist/theme.css +115 -0
  104. package/dist/tokens.css +268 -0
  105. package/dist/ui/block-icon-picker.d.ts +38 -0
  106. package/dist/ui/block-icon-picker.js +141 -0
  107. package/dist/ui/block-icon-picker.js.map +1 -0
  108. package/dist/ui/button.js +1 -0
  109. package/dist/ui/button.js.map +1 -1
  110. package/dist/ui/code-language-menu.d.ts +24 -0
  111. package/dist/ui/code-language-menu.js +123 -0
  112. package/dist/ui/code-language-menu.js.map +1 -0
  113. package/dist/ui/content-fields.d.ts +47 -0
  114. package/dist/ui/content-fields.js +278 -0
  115. package/dist/ui/content-fields.js.map +1 -0
  116. package/dist/ui/foundations.d.ts +118 -0
  117. package/dist/ui/foundations.js +564 -0
  118. package/dist/ui/foundations.js.map +1 -0
  119. package/dist/ui/index.d.ts +6 -0
  120. package/dist/ui/index.js +7 -1
  121. package/dist/ui/inspector.d.ts +394 -0
  122. package/dist/ui/inspector.js +1173 -0
  123. package/dist/ui/inspector.js.map +1 -0
  124. package/dist/ui/overlay.d.ts +7 -2
  125. package/dist/ui/overlay.js +55 -20
  126. package/dist/ui/overlay.js.map +1 -1
  127. package/dist/ui/shortcut-hint.js +1 -1
  128. package/dist/ui/shortcut-hint.js.map +1 -1
  129. package/dist/ui/toast.d.ts +5 -3
  130. package/dist/ui/toast.js +83 -11
  131. package/dist/ui/toast.js.map +1 -1
  132. package/dist/ui/tooltip-card.d.ts +45 -0
  133. package/dist/ui/tooltip-card.js +135 -0
  134. package/dist/ui/tooltip-card.js.map +1 -0
  135. package/package.json +1 -1
@@ -1,9 +1,11 @@
1
1
  import { pathKey, same } from "../lib/path.js";
2
- import { isTextual, plainText } from "../lib/schema.js";
2
+ import { emptyFor, initialFor, isEmptyValue, isTextual, plainText } from "../lib/schema.js";
3
3
  import { cn } from "../lib/cn.js";
4
- import { AI_PRESETS, FieldHeaderSlot, KitSectionTitle, seesDevSurfaces, useForm, useKitEnv, useKitServices } from "../context.js";
4
+ import { AI_PRESETS, FieldHeaderSlot, KitSectionTitle, seesDevSurfaces, useForm, useKitEnv, useKitFocusField, useKitLook, useKitServices } from "../context.js";
5
5
  import { Button, Sparkle } from "../ui/button.js";
6
+ import { InfoTooltip } from "../ui/tooltip-card.js";
6
7
  import { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Popover, PopoverAnchor, PopoverContent, Tooltip } from "../ui/overlay.js";
8
+ import { FieldCounter, FieldSweep, FocusDot, counterState, overLimitText } from "../ui/inspector.js";
7
9
  import { RowChrome } from "./bits.js";
8
10
  import { Avatar, avatarRingSpread } from "../ui/display.js";
9
11
  import { presenceColor } from "../ui/presence.js";
@@ -12,7 +14,7 @@ import { resolveHelp } from "../schema/help.js";
12
14
  import { textLength } from "../lib/validate.js";
13
15
  import * as React from "react";
14
16
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
- import { IconAlertCircle, IconAlertTriangle, IconArrowBackUp, IconBraces, IconClipboard, IconCopy, IconDots, IconHistory, IconInfoCircle, IconLock, IconMessage, IconMessagePlus, IconRefresh, IconRotate, IconWorld } from "@tabler/icons-react";
17
+ import { IconAlertCircle, IconAlertTriangle, IconArrowBackUp, IconBraces, IconClipboard, IconCopy, IconDots, IconEraser, IconHistory, IconInfoCircle, IconLink, IconLock, IconMessage, IconMessagePlus, IconRefresh, IconRestore, IconRotate, IconWorld } from "@tabler/icons-react";
16
18
  import { AnimatePresence, motion } from "framer-motion";
17
19
  import { createPortal } from "react-dom";
18
20
  //#region src/engine/field-shell.tsx
@@ -121,6 +123,25 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
121
123
  setCommentsOpen(false);
122
124
  setCommentSel(null);
123
125
  };
126
+ const openRef = React.useRef(() => {});
127
+ openRef.current = (sel) => {
128
+ if (!canComment) return;
129
+ if (env.onComment) return env.onComment(path, field);
130
+ setCommentSel(sel ?? null);
131
+ setCommentArea(fieldPopoverCollision(document.getElementById(id)?.closest("[data-field-key]") ?? null));
132
+ setCommentsOpen(true);
133
+ };
134
+ React.useEffect(() => {
135
+ const box = document.getElementById(id)?.closest("[data-field-key]");
136
+ if (!box) return;
137
+ const on = (e) => {
138
+ e.stopPropagation();
139
+ openRef.current(e.detail);
140
+ };
141
+ box.addEventListener(KIT_OPEN_FIELD_COMMENTS, on);
142
+ return () => box.removeEventListener(KIT_OPEN_FIELD_COMMENTS, on);
143
+ }, [id]);
144
+ const v16 = useKitLook() === "v16";
124
145
  const openCount = env.comments[key] ?? 0;
125
146
  const useStoreCount = env.onComment ? void 0 : services.useFieldCommentCount;
126
147
  const changed = !!form?.hasPublished && !same(value, form.publishedAt(path));
@@ -135,7 +156,10 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
135
156
  const limit = field.validation?.max ?? field.validation?.recommendedMax;
136
157
  const len = textLength(value);
137
158
  const near = !!limit && len >= limit * .8;
138
- const counter = limit && (field.type === "string" || field.type === "text" || field.type === "richtext") ? /* @__PURE__ */ jsxs("span", {
159
+ const counter = limit && (field.type === "string" || field.type === "text" || field.type === "richtext") ? v16 ? counterState(len, limit) === "ok" ? null : /* @__PURE__ */ jsx(FieldCounter, {
160
+ value: len,
161
+ max: limit
162
+ }) : /* @__PURE__ */ jsxs("span", {
139
163
  "data-slot": "field-counter",
140
164
  className: cn("tabular-nums text-kit-xs", !near && "hidden group-focus-within/field:inline", field.validation?.max && len > field.validation.max ? "text-kit-danger-fg" : field.validation?.recommendedMax && len > field.validation.recommendedMax ? "text-kit-warning-fg" : "text-kit-fg-3"),
141
165
  children: [
@@ -178,7 +202,14 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
178
202
  if (next) el.setAttribute("aria-describedby", next);
179
203
  else el.removeAttribute("aria-describedby");
180
204
  }, [id, describedBy]);
181
- const info = tip ? /* @__PURE__ */ jsx(Tooltip, {
205
+ const info = tip ? v16 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(InfoTooltip, {
206
+ title: field.title,
207
+ children: tip
208
+ }), /* @__PURE__ */ jsx("span", {
209
+ id: moreId,
210
+ className: "sr-only",
211
+ children: tip
212
+ })] }) : /* @__PURE__ */ jsx(Tooltip, {
182
213
  content: /* @__PURE__ */ jsx("span", {
183
214
  className: "block max-w-[260px] whitespace-normal font-normal leading-4",
184
215
  children: tip
@@ -204,8 +235,8 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
204
235
  children: field.title
205
236
  }), field.validation?.required ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
206
237
  "aria-hidden": true,
207
- className: "text-kit-fg-2",
208
- children: "*"
238
+ className: v16 ? "whitespace-pre" : "text-kit-fg-2",
239
+ children: v16 ? " *" : "*"
209
240
  }), /* @__PURE__ */ jsx("span", {
210
241
  className: "sr-only",
211
242
  children: "(required)"
@@ -288,11 +319,31 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
288
319
  })
289
320
  })
290
321
  }) : null,
322
+ v16 && !bare ? /* @__PURE__ */ jsx(Tooltip, {
323
+ content: "Copy link to field",
324
+ children: /* @__PURE__ */ jsx("button", {
325
+ type: "button",
326
+ "data-field-reveal": "",
327
+ "aria-label": `Copy link to ${field.title}`,
328
+ className: "-my-0.5 size-5 items-center justify-center rounded-[4px] text-kit-fg-3 hover:bg-kit-insp-track hover:text-kit-fg focus-visible:outline-2 focus-visible:outline-offset-1 [&_svg]:size-4",
329
+ onClick: () => {
330
+ const href = `${window.location.href.split("#")[0]}#${encodeURIComponent(key)}`;
331
+ const w = navigator.clipboard?.writeText(href);
332
+ if (!w) return services.toast?.("Copy is not available in this browser");
333
+ w.then(() => services.toast?.("Link to field copied"), () => services.toast?.("The browser refused to copy the link"));
334
+ },
335
+ children: /* @__PURE__ */ jsx(IconLink, {
336
+ stroke: 1.5,
337
+ "aria-hidden": true
338
+ })
339
+ })
340
+ }) : null,
291
341
  canComment ? /* @__PURE__ */ jsx(CommentButton, {
292
342
  count: openCount,
293
343
  useCount: useStoreCount ? () => useStoreCount(env.docId, key) : void 0,
294
344
  label: field.title,
295
345
  open: commentsOpen,
346
+ onThreads: !env.onComment && services.onOpenFieldThreads ? () => services.onOpenFieldThreads(env.docId, key) : void 0,
296
347
  onOpen: (el) => {
297
348
  if (env.onComment) return env.onComment(path, field);
298
349
  setCommentSel(null);
@@ -342,7 +393,7 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
342
393
  "aria-hidden": true
343
394
  }), /* @__PURE__ */ jsxs("span", {
344
395
  className: "min-w-0",
345
- children: [issue.message, issue.fix && !readOnly ? /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("button", {
396
+ children: [v16 && issue.kind === "rule" && limit && len > limit && /^Keep it under \d+ characters/.test(issue.message) ? overLimitText(limit) : issue.message, issue.fix && !readOnly ? /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("button", {
346
397
  type: "button",
347
398
  onClick: issue.fix.apply,
348
399
  className: "font-medium text-kit-fg underline-offset-2 hover:underline",
@@ -355,12 +406,14 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
355
406
  children: meta
356
407
  }) : null]
357
408
  }) : null;
358
- const labelEl = /* @__PURE__ */ jsx("label", {
409
+ const focus = useKitFocusField();
410
+ const focused = !!focus && focus.key === key;
411
+ const labelEl = /* @__PURE__ */ jsxs("label", {
359
412
  htmlFor: id,
360
413
  id: `${id}-label`,
361
414
  className: "flex min-w-0 items-center gap-1 text-kit-sm font-medium text-kit-fg-2 transition-colors group-focus-within/field:text-kit-fg",
362
415
  title: longTitle,
363
- children: label
416
+ children: [label, focused ? /* @__PURE__ */ jsx(FocusDot, {}) : null]
364
417
  });
365
418
  const body = layout === "row" ? /* @__PURE__ */ jsxs("div", {
366
419
  className: cn("group/field relative flex min-w-0 flex-col gap-1.5", className),
@@ -468,13 +521,15 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
468
521
  message
469
522
  ]
470
523
  }) : /* @__PURE__ */ jsxs("div", {
471
- className: cn("group/field relative flex min-w-0 flex-col gap-1.5", className),
524
+ className: cn("group/field relative flex min-w-0 flex-col gap-1.5", focused && "isolate", className),
472
525
  "data-field-key": key,
473
526
  "data-field": path.length === 1 ? key : void 0,
474
527
  "data-slot": "kit-field",
475
528
  "data-inherited": inh && !overridden ? "" : void 0,
476
529
  "data-overridden": overridden ? "" : void 0,
530
+ "data-cur": focused ? "" : void 0,
477
531
  children: [
532
+ focused && focus?.flash != null ? /* @__PURE__ */ jsx(FieldSweep, {}, String(focus.flash)) : null,
478
533
  bar,
479
534
  repeatsSection ? /* @__PURE__ */ jsx("label", {
480
535
  htmlFor: id,
@@ -520,6 +575,7 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
520
575
  message
521
576
  ]
522
577
  });
578
+ const commentPop = commentsOpen && services.fieldCommentsPopover ? services.fieldCommentsPopover({ selection: !!commentSel }) : null;
523
579
  return /* @__PURE__ */ jsx(FieldCommentRequest.Provider, {
524
580
  value: requestComment,
525
581
  children: /* @__PURE__ */ jsxs(Popover, {
@@ -539,10 +595,11 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
539
595
  children: body
540
596
  }), commentsOpen && InPlaceComments ? /* @__PURE__ */ jsx(PopoverContent, {
541
597
  align: "start",
542
- sideOffset: 8,
598
+ sideOffset: commentPop?.sideOffset ?? 8,
599
+ alignOffset: commentPop?.alignOffset,
543
600
  ...commentArea,
544
601
  initialFocus: false,
545
- className: "w-[clamp(280px,var(--anchor-width),420px)] p-0",
602
+ className: cn("p-0", commentPop?.className ?? "w-[clamp(280px,var(--anchor-width),420px)]"),
546
603
  children: /* @__PURE__ */ jsx(InPlaceComments, {
547
604
  docId: env.docId,
548
605
  fieldKey: key,
@@ -572,6 +629,12 @@ function FieldShell({ field, path, id, value, onChange, readOnly, issue, action,
572
629
  })
573
630
  });
574
631
  }
632
+ /** REQ-2-6: the event a field's box answers by opening its comments (`detail`: the quoted selection, or none). */
633
+ var KIT_OPEN_FIELD_COMMENTS = "kit:open-field-comments";
634
+ /** Opens the comments of the field whose `[data-field-key]` box is `box` (a plain field's selected words as `selection`). */
635
+ function openFieldComments(box, selection) {
636
+ box.dispatchEvent(new CustomEvent(KIT_OPEN_FIELD_COMMENTS, { detail: selection }));
637
+ }
575
638
  /** V2 features/comments fieldPopoverCollision: inside a scrolling panel, collide with that panel below its sticky header. */
576
639
  function fieldPopoverCollision(anchor) {
577
640
  let area = anchor?.parentElement ?? null;
@@ -602,14 +665,16 @@ function StoreCommentButton({ useCount, ...props }) {
602
665
  count: useCount()
603
666
  });
604
667
  }
605
- function CountedCommentButton({ count, label, open, onOpen }) {
668
+ function CountedCommentButton({ count, label, open, onOpen, onThreads }) {
669
+ const v16 = useKitLook() === "v16";
670
+ const n = `${count} comment${count === 1 ? "" : "s"}`;
606
671
  if (count > 0) return /* @__PURE__ */ jsx(Tooltip, {
607
- content: `${count} open comment${count === 1 ? "" : "s"} on ${label}`,
672
+ content: v16 ? `${n} · open thread` : `${count} open comment${count === 1 ? "" : "s"} on ${label}`,
608
673
  children: /* @__PURE__ */ jsxs("button", {
609
674
  type: "button",
610
- onClick: (e) => onOpen(e.currentTarget),
675
+ onClick: (e) => onThreads ? onThreads() : onOpen(e.currentTarget),
611
676
  "data-state": open ? "open" : "closed",
612
- "aria-label": `${count} open comments on ${label}`,
677
+ "aria-label": v16 ? `${n} on ${label} · open thread` : `${count} open comments on ${label}`,
613
678
  className: "-my-0.5 inline-flex h-5 items-center gap-0.5 rounded-kit-md px-1 text-kit-2xs font-medium text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg data-[state=open]:bg-kit-hover data-[state=open]:text-kit-fg",
614
679
  children: [/* @__PURE__ */ jsx(IconMessage, {
615
680
  className: "size-3.5",
@@ -622,12 +687,12 @@ function CountedCommentButton({ count, label, open, onOpen }) {
622
687
  })
623
688
  });
624
689
  return /* @__PURE__ */ jsx(Tooltip, {
625
- content: "Add comment",
690
+ content: v16 ? "Comment" : "Add comment",
626
691
  children: /* @__PURE__ */ jsx("button", {
627
692
  type: "button",
628
693
  onClick: (e) => onOpen(e.currentTarget),
629
694
  "data-state": open ? "open" : "closed",
630
- "aria-label": `Add comment to ${label}`,
695
+ "aria-label": v16 ? `Comment on ${label}` : `Add comment to ${label}`,
631
696
  "data-field-reveal": "",
632
697
  className: cn("-my-0.5 size-6 items-center justify-center rounded-kit-md text-kit-fg-3 hover:bg-kit-hover hover:text-kit-fg"),
633
698
  children: /* @__PURE__ */ jsx(IconMessagePlus, {
@@ -704,6 +769,20 @@ function PeerStack({ peers, size = 16 }) {
704
769
  }, "peers") : null
705
770
  });
706
771
  }
772
+ /** The field ⋯ menu alone, for a field drawn without its shell (a top-level Object group's header, look v16). */
773
+ function FieldActionsMenu({ field, path, value, onChange, readOnly }) {
774
+ const form = useForm();
775
+ const changed = !!form?.hasPublished && !same(value, form.publishedAt(path));
776
+ return /* @__PURE__ */ jsx(FieldMenu, {
777
+ field,
778
+ path,
779
+ value,
780
+ onChange,
781
+ readOnly: !!readOnly,
782
+ changed,
783
+ onAi: () => {}
784
+ });
785
+ }
707
786
  function FieldMenu({ field, path, value, onChange, readOnly, changed, onAi }) {
708
787
  const form = useForm();
709
788
  const env = useKitEnv();
@@ -714,6 +793,54 @@ function FieldMenu({ field, path, value, onChange, readOnly, changed, onAi }) {
714
793
  const prose = field.type === "string" || field.type === "text" || field.type === "richtext" && !!richText;
715
794
  const editable = !readOnly;
716
795
  const dev = seesDevSurfaces(env);
796
+ const v16 = useKitLook() === "v16";
797
+ const copyField = () => {
798
+ const html = richTextHtml(richText, field, path, value);
799
+ clip = {
800
+ type: field.type,
801
+ value: structuredCloneish(value),
802
+ label: field.title,
803
+ ...html !== void 0 ? { html } : {}
804
+ };
805
+ const text = textual ? plainText(value) || "" : typeof value === "string" ? value : JSON.stringify(value ?? null, null, 2);
806
+ navigator.clipboard?.writeText(text).catch(() => {});
807
+ toast?.success(`${field.title} copied`);
808
+ };
809
+ const copyApi = () => {
810
+ navigator.clipboard?.writeText(api).catch(() => {});
811
+ toast?.success(`Copied ${api}`);
812
+ };
813
+ const resetPublished = editable && form?.hasPublished && changed ? /* @__PURE__ */ jsx(MenuItem, {
814
+ icon: /* @__PURE__ */ jsx(IconRotate, { stroke: 1.5 }),
815
+ onClick: () => {
816
+ const prev = value;
817
+ onChange(form.publishedAt(path));
818
+ toast?.(`${field.title} reset to published`, {
819
+ action: {
820
+ label: "Undo",
821
+ onClick: () => onChange(prev)
822
+ },
823
+ duration: 1e4
824
+ });
825
+ },
826
+ children: "Reset to published"
827
+ }) : null;
828
+ const aiRows = editable && prose && aiRewrite ? /* @__PURE__ */ jsxs(Fragment, { children: [
829
+ /* @__PURE__ */ jsx(MenuSeparator, {}),
830
+ form?.aiKeys.has(key) ? /* @__PURE__ */ jsx(MenuItem, {
831
+ icon: /* @__PURE__ */ jsx(IconArrowBackUp, { stroke: 1.5 }),
832
+ onClick: () => {
833
+ form.undo(key);
834
+ form.markAi(key, false);
835
+ },
836
+ children: "Undo AI change"
837
+ }) : null,
838
+ /* @__PURE__ */ jsx(MenuItem, {
839
+ icon: /* @__PURE__ */ jsx(Sparkle, { size: 16 }),
840
+ onClick: () => window.setTimeout(onAi, 0),
841
+ children: "Rewrite with AI"
842
+ })
843
+ ] }) : null;
717
844
  return /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(Tooltip, {
718
845
  content: "Field actions",
719
846
  children: /* @__PURE__ */ jsx(MenuTrigger, {
@@ -726,25 +853,26 @@ function FieldMenu({ field, path, value, onChange, readOnly, changed, onAi }) {
726
853
  "aria-hidden": true
727
854
  })
728
855
  })
729
- }), /* @__PURE__ */ jsxs(MenuContent, {
856
+ }), /* @__PURE__ */ jsx(MenuContent, {
730
857
  align: "end",
731
858
  className: "w-60",
732
- children: [
859
+ children: v16 ? /* @__PURE__ */ jsxs(Fragment, { children: [
733
860
  /* @__PURE__ */ jsx(MenuItem, {
734
861
  icon: /* @__PURE__ */ jsx(IconCopy, { stroke: 1.5 }),
735
- onClick: () => {
736
- const html = richTextHtml(richText, field, path, value);
737
- clip = {
738
- type: field.type,
739
- value: structuredCloneish(value),
740
- label: field.title,
741
- ...html !== void 0 ? { html } : {}
742
- };
743
- const text = textual ? plainText(value) || "" : typeof value === "string" ? value : JSON.stringify(value ?? null, null, 2);
744
- navigator.clipboard?.writeText(text).catch(() => {});
745
- toast?.success(`${field.title} copied`);
746
- },
747
- children: "Copy value"
862
+ shortcut: "⌘C",
863
+ onClick: copyField,
864
+ children: "Copy field"
865
+ }),
866
+ /* @__PURE__ */ jsx(MenuItem, {
867
+ icon: /* @__PURE__ */ jsx(IconBraces, { stroke: 1.5 }),
868
+ onClick: copyApi,
869
+ children: /* @__PURE__ */ jsxs("span", {
870
+ className: "flex w-full items-center justify-between gap-3",
871
+ children: ["Copy API name", /* @__PURE__ */ jsx("span", {
872
+ className: "truncate text-[12px] leading-4 text-kit-insp-faint",
873
+ children: api.length > 22 ? `…${api.slice(-20)}` : api
874
+ })]
875
+ })
748
876
  }),
749
877
  editable ? /* @__PURE__ */ jsx(PasteItem, {
750
878
  field,
@@ -752,12 +880,36 @@ function FieldMenu({ field, path, value, onChange, readOnly, changed, onAi }) {
752
880
  value,
753
881
  onChange
754
882
  }) : null,
755
- editable && form?.hasPublished && changed ? /* @__PURE__ */ jsx(MenuItem, {
756
- icon: /* @__PURE__ */ jsx(IconRotate, { stroke: 1.5 }),
883
+ editable || env.onFieldHistory ? /* @__PURE__ */ jsx(MenuSeparator, {}) : null,
884
+ editable ? /* @__PURE__ */ jsx(MenuItem, {
885
+ icon: /* @__PURE__ */ jsx(IconRestore, { stroke: 1.5 }),
886
+ onClick: () => {
887
+ const prev = value;
888
+ onChange(initialFor(field));
889
+ toast?.(`${field.title} reset to default`, {
890
+ action: {
891
+ label: "Undo",
892
+ onClick: () => onChange(prev)
893
+ },
894
+ duration: 1e4
895
+ });
896
+ },
897
+ children: "Reset to default"
898
+ }) : null,
899
+ resetPublished,
900
+ env.onFieldHistory ? /* @__PURE__ */ jsx(MenuItem, {
901
+ icon: /* @__PURE__ */ jsx(IconHistory, { stroke: 1.5 }),
902
+ onClick: () => env.onFieldHistory(path, field),
903
+ children: "View field history"
904
+ }) : null,
905
+ editable ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MenuSeparator, {}), /* @__PURE__ */ jsx(MenuItem, {
906
+ danger: true,
907
+ icon: /* @__PURE__ */ jsx(IconEraser, { stroke: 1.5 }),
908
+ disabled: isEmptyValue(value),
757
909
  onClick: () => {
758
910
  const prev = value;
759
- onChange(form.publishedAt(path));
760
- toast?.(`${field.title} reset to published`, {
911
+ onChange(emptyFor(field));
912
+ toast?.(`${field.title} cleared`, {
761
913
  action: {
762
914
  label: "Undo",
763
915
  onClick: () => onChange(prev)
@@ -765,8 +917,27 @@ function FieldMenu({ field, path, value, onChange, readOnly, changed, onAi }) {
765
917
  duration: 1e4
766
918
  });
767
919
  },
768
- children: "Reset to published"
920
+ children: "Clear field"
921
+ })] }) : null,
922
+ FieldMenuExtras ? /* @__PURE__ */ jsx(FieldMenuExtras, {
923
+ field,
924
+ path,
925
+ readOnly
769
926
  }) : null,
927
+ aiRows
928
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
929
+ /* @__PURE__ */ jsx(MenuItem, {
930
+ icon: /* @__PURE__ */ jsx(IconCopy, { stroke: 1.5 }),
931
+ onClick: copyField,
932
+ children: "Copy value"
933
+ }),
934
+ editable ? /* @__PURE__ */ jsx(PasteItem, {
935
+ field,
936
+ path,
937
+ value,
938
+ onChange
939
+ }) : null,
940
+ resetPublished,
770
941
  env.onFieldHistory ? /* @__PURE__ */ jsx(MenuItem, {
771
942
  icon: /* @__PURE__ */ jsx(IconHistory, { stroke: 1.5 }),
772
943
  onClick: () => env.onFieldHistory(path, field),
@@ -777,29 +948,11 @@ function FieldMenu({ field, path, value, onChange, readOnly, changed, onAi }) {
777
948
  path,
778
949
  readOnly
779
950
  }) : null,
780
- editable && prose && aiRewrite ? /* @__PURE__ */ jsxs(Fragment, { children: [
781
- /* @__PURE__ */ jsx(MenuSeparator, {}),
782
- form?.aiKeys.has(key) ? /* @__PURE__ */ jsx(MenuItem, {
783
- icon: /* @__PURE__ */ jsx(IconArrowBackUp, { stroke: 1.5 }),
784
- onClick: () => {
785
- form.undo(key);
786
- form.markAi(key, false);
787
- },
788
- children: "Undo AI change"
789
- }) : null,
790
- /* @__PURE__ */ jsx(MenuItem, {
791
- icon: /* @__PURE__ */ jsx(Sparkle, { size: 16 }),
792
- onClick: () => window.setTimeout(onAi, 0),
793
- children: "Rewrite with AI"
794
- })
795
- ] }) : null,
951
+ aiRows,
796
952
  dev ? /* @__PURE__ */ jsx(MenuSeparator, {}) : null,
797
953
  dev ? /* @__PURE__ */ jsx(MenuItem, {
798
954
  icon: /* @__PURE__ */ jsx(IconBraces, { stroke: 1.5 }),
799
- onClick: () => {
800
- navigator.clipboard?.writeText(api).catch(() => {});
801
- toast?.success(`Copied ${api}`);
802
- },
955
+ onClick: copyApi,
803
956
  children: /* @__PURE__ */ jsxs("span", {
804
957
  className: "flex w-full items-center justify-between gap-3",
805
958
  children: ["Copy API name", /* @__PURE__ */ jsx("span", {
@@ -808,16 +961,17 @@ function FieldMenu({ field, path, value, onChange, readOnly, changed, onAi }) {
808
961
  })]
809
962
  })
810
963
  }) : null
811
- ]
964
+ ] })
812
965
  })] });
813
966
  }
814
967
  /** Reads the shared clipboard when the menu opens (it mounts with the popup), so a copy in another field is seen. */
815
968
  function PasteItem({ field, path, value, onChange }) {
816
969
  const { toast, richText } = useKitServices();
970
+ const v16 = useKitLook() === "v16";
817
971
  const textual = isTextual(field.type);
818
972
  const needsCodec = !!clip && field.type === "richtext" && clip.type !== "richtext" && !richText;
819
973
  const pasteOk = clip && !needsCodec && (clip.type === field.type || textual && isTextual(clip.type));
820
- const pasteReason = !clip ? "Copy a value from a field first." : needsCodec ? "This rich text field takes a copied rich text value only." : pasteOk ? null : `Clipboard holds ${kindOf(clip.type)}. This field takes ${kindOf(field.type)}.`;
974
+ const pasteReason = !clip ? v16 ? "Copy a field first" : "Copy a value from a field first." : needsCodec ? "This rich text field takes a copied rich text value only." : pasteOk ? null : `Clipboard holds ${kindOf(clip.type)}. This field takes ${kindOf(field.type)}.`;
821
975
  return /* @__PURE__ */ jsx(MenuItem, {
822
976
  icon: /* @__PURE__ */ jsx(IconClipboard, { stroke: 1.5 }),
823
977
  disabled: !pasteOk,
@@ -845,7 +999,7 @@ function PasteItem({ field, path, value, onChange }) {
845
999
  },
846
1000
  children: /* @__PURE__ */ jsxs("span", {
847
1001
  className: "flex flex-col",
848
- children: ["Paste value", pasteReason ? /* @__PURE__ */ jsx("span", {
1002
+ children: [v16 ? "Paste field" : "Paste value", pasteReason ? /* @__PURE__ */ jsx("span", {
849
1003
  className: "whitespace-normal text-kit-xs text-kit-fg-3",
850
1004
  children: pasteReason
851
1005
  }) : null]
@@ -1022,6 +1176,6 @@ function TypeOut({ text, speed = 14 }) {
1022
1176
  }) : null] });
1023
1177
  }
1024
1178
  //#endregion
1025
- export { FieldCommentRequest, FieldShell, LABEL_HINT_AT, PeerStack, apiName, resetFieldClipboard };
1179
+ export { FieldActionsMenu, FieldCommentRequest, FieldShell, KIT_OPEN_FIELD_COMMENTS, LABEL_HINT_AT, PeerStack, apiName, openFieldComments, resetFieldClipboard };
1026
1180
 
1027
1181
  //# sourceMappingURL=field-shell.js.map