canopycms 0.0.68-int.113 → 0.0.68-int.114

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 (170) hide show
  1. package/dist/ai/generate.d.ts +4 -4
  2. package/dist/ai/generate.js +75 -14
  3. package/dist/ai/types.d.ts +12 -0
  4. package/dist/api/branch.js +13 -13
  5. package/dist/auth/cache.d.ts +1 -1
  6. package/dist/auth/cache.js +1 -1
  7. package/dist/auth/file-based-auth-cache.d.ts +8 -0
  8. package/dist/auth/file-based-auth-cache.js +11 -0
  9. package/dist/authorization/branch.d.ts +1 -1
  10. package/dist/authorization/branch.js +2 -1
  11. package/dist/cli/cli.js +160 -28
  12. package/dist/cli/generate-ai-content.js +156 -24
  13. package/dist/content-reader.js +2 -1
  14. package/dist/context.js +2 -1
  15. package/dist/editor/BranchManager.js +13 -17
  16. package/dist/editor/CommentsPanel.js +7 -6
  17. package/dist/editor/Editor.js +152 -30
  18. package/dist/editor/EditorAuthGate.js +2 -2
  19. package/dist/editor/EditorPanes.d.ts +10 -0
  20. package/dist/editor/EditorPanes.js +32 -8
  21. package/dist/editor/FormRenderer.d.ts +10 -0
  22. package/dist/editor/FormRenderer.js +92 -73
  23. package/dist/editor/PreviewFrame.d.ts +3 -1
  24. package/dist/editor/PreviewFrame.js +72 -9
  25. package/dist/editor/admin/SystemHealthPanel.js +27 -24
  26. package/dist/editor/branch-status.d.ts +16 -0
  27. package/dist/editor/branch-status.js +28 -0
  28. package/dist/editor/comments/BranchComments.js +1 -1
  29. package/dist/editor/comments/EntryComments.d.ts +3 -0
  30. package/dist/editor/comments/EntryComments.js +3 -3
  31. package/dist/editor/comments/FieldWrapper.d.ts +3 -0
  32. package/dist/editor/comments/FieldWrapper.js +2 -2
  33. package/dist/editor/comments/InlineCommentThread.js +2 -1
  34. package/dist/editor/comments/ThreadCarousel.js +2 -2
  35. package/dist/editor/components/ConfirmDeleteModal.js +1 -1
  36. package/dist/editor/components/EditorCrashScreen.js +1 -1
  37. package/dist/editor/components/EditorHeader.d.ts +2 -0
  38. package/dist/editor/components/EditorHeader.js +15 -36
  39. package/dist/editor/components/EditorSidebar.d.ts +5 -6
  40. package/dist/editor/components/EditorSidebar.js +2 -2
  41. package/dist/editor/components/EntryCreateModal.js +1 -1
  42. package/dist/editor/components/NoEditPermissionNotice.d.ts +3 -2
  43. package/dist/editor/components/NoEditPermissionNotice.js +3 -2
  44. package/dist/editor/components/ReadOnlyDraftNotice.d.ts +11 -0
  45. package/dist/editor/components/ReadOnlyDraftNotice.js +12 -0
  46. package/dist/editor/components/RenameEntryModal.js +1 -1
  47. package/dist/editor/components/StagedChangesDrawer.js +3 -3
  48. package/dist/editor/components/UndoToastMessage.d.ts +14 -0
  49. package/dist/editor/components/UndoToastMessage.js +9 -0
  50. package/dist/editor/components/UserBadge.js +9 -5
  51. package/dist/editor/copy.d.ts +14 -0
  52. package/dist/editor/copy.js +14 -0
  53. package/dist/editor/fields/BlockField.d.ts +5 -0
  54. package/dist/editor/fields/BlockField.js +38 -32
  55. package/dist/editor/fields/CodeField.d.ts +2 -0
  56. package/dist/editor/fields/CodeField.js +5 -2
  57. package/dist/editor/fields/DateTimeField.d.ts +2 -0
  58. package/dist/editor/fields/DateTimeField.js +5 -2
  59. package/dist/editor/fields/FieldCrashFallback.d.ts +3 -3
  60. package/dist/editor/fields/FieldCrashFallback.js +4 -4
  61. package/dist/editor/fields/FieldLabel.d.ts +24 -0
  62. package/dist/editor/fields/FieldLabel.js +9 -0
  63. package/dist/editor/fields/ImageField.d.ts +4 -0
  64. package/dist/editor/fields/ImageField.js +17 -8
  65. package/dist/editor/fields/InlineGroupField.js +4 -3
  66. package/dist/editor/fields/MarkdownField.d.ts +6 -0
  67. package/dist/editor/fields/MarkdownField.js +41 -11
  68. package/dist/editor/fields/MdxImageDialog.js +1 -1
  69. package/dist/editor/fields/NumberField.d.ts +2 -0
  70. package/dist/editor/fields/NumberField.js +4 -2
  71. package/dist/editor/fields/NumberListField.d.ts +2 -0
  72. package/dist/editor/fields/NumberListField.js +4 -2
  73. package/dist/editor/fields/ObjectField.d.ts +1 -0
  74. package/dist/editor/fields/ObjectField.js +5 -4
  75. package/dist/editor/fields/ReferenceField.d.ts +2 -0
  76. package/dist/editor/fields/ReferenceField.js +9 -3
  77. package/dist/editor/fields/SelectField.d.ts +2 -0
  78. package/dist/editor/fields/SelectField.js +8 -2
  79. package/dist/editor/fields/StringListField.d.ts +2 -0
  80. package/dist/editor/fields/StringListField.js +5 -2
  81. package/dist/editor/fields/TextField.d.ts +2 -0
  82. package/dist/editor/fields/TextField.js +5 -2
  83. package/dist/editor/fields/ToggleField.d.ts +2 -0
  84. package/dist/editor/fields/ToggleField.js +6 -3
  85. package/dist/editor/fields/entry-link/InsertEntryLink.js +1 -1
  86. package/dist/editor/fields/list-item-keys.d.ts +8 -0
  87. package/dist/editor/fields/list-item-keys.js +50 -0
  88. package/dist/editor/group-manager/GroupCard.js +1 -1
  89. package/dist/editor/group-manager/GroupForm.js +1 -1
  90. package/dist/editor/group-manager/InternalGroupsTab.js +1 -1
  91. package/dist/editor/group-manager/MemberList.js +1 -1
  92. package/dist/editor/group-manager/hooks/useGroupState.d.ts +1 -0
  93. package/dist/editor/group-manager/hooks/useGroupState.js +1 -1
  94. package/dist/editor/group-manager/index.js +26 -2
  95. package/dist/editor/hooks/useBranchActions.js +2 -2
  96. package/dist/editor/hooks/useBranchManager.js +36 -22
  97. package/dist/editor/hooks/useDraftManager.d.ts +8 -0
  98. package/dist/editor/hooks/useDraftManager.js +27 -5
  99. package/dist/editor/hooks/useEditorLayout.d.ts +45 -3
  100. package/dist/editor/hooks/useEditorLayout.js +97 -7
  101. package/dist/editor/hooks/useUserMetadata.js +12 -1
  102. package/dist/editor/media/AssetCard.js +1 -1
  103. package/dist/editor/media/CropStep.js +6 -1
  104. package/dist/editor/media/MediaLibraryBody.js +3 -3
  105. package/dist/editor/permission-manager/PermissionEditor.js +3 -3
  106. package/dist/editor/permission-manager/index.js +1 -1
  107. package/dist/editor/preview-bridge.js +2 -2
  108. package/dist/editor/schema-editor/CollectionEditor.js +1 -1
  109. package/dist/editor/schema-editor/EntryTypeEditor.js +1 -1
  110. package/dist/editor/theme.d.ts +1 -1
  111. package/dist/editor/theme.js +11 -11
  112. package/dist/editor/undo-removal.d.ts +44 -0
  113. package/dist/editor/undo-removal.js +129 -0
  114. package/dist/editor/user-display.d.ts +4 -0
  115. package/dist/editor/user-display.js +5 -0
  116. package/dist/editor/utils/confirm-modal.d.ts +8 -0
  117. package/dist/editor/utils/confirm-modal.js +12 -0
  118. package/dist/entry-link-resolver.d.ts +11 -1
  119. package/dist/entry-link-resolver.js +65 -5
  120. package/dist/git-manager.d.ts +6 -6
  121. package/dist/git-manager.js +16 -15
  122. package/dist/github-service.d.ts +25 -1
  123. package/dist/github-service.js +65 -6
  124. package/dist/http/handler.js +2 -1
  125. package/dist/static/seo.d.ts +5 -5
  126. package/dist/static/seo.js +5 -5
  127. package/dist/system-users.d.ts +12 -0
  128. package/dist/system-users.js +12 -0
  129. package/dist/types.d.ts +9 -1
  130. package/dist/utils/error.js +4 -3
  131. package/dist/utils/escape-text.d.ts +7 -0
  132. package/dist/utils/escape-text.js +27 -0
  133. package/dist/version.d.ts +1 -1
  134. package/dist/version.js +1 -1
  135. package/dist/worker/branch-policy.d.ts +124 -0
  136. package/dist/worker/branch-policy.js +243 -0
  137. package/dist/worker/bundle-header.d.ts +117 -0
  138. package/dist/worker/bundle-header.js +253 -0
  139. package/dist/worker/cms-worker.d.ts +68 -17
  140. package/dist/worker/cms-worker.js +116 -33
  141. package/dist/worker/gateway-egress.d.ts +43 -0
  142. package/dist/worker/gateway-egress.js +209 -0
  143. package/dist/worker/gateway-instance.d.ts +42 -0
  144. package/dist/worker/gateway-instance.js +129 -0
  145. package/dist/worker/git-process.d.ts +81 -0
  146. package/dist/worker/git-process.js +234 -0
  147. package/dist/worker/git-sync.d.ts +8 -7
  148. package/dist/worker/git-sync.js +184 -74
  149. package/dist/worker/github-gateway-http.d.ts +62 -0
  150. package/dist/worker/github-gateway-http.js +977 -0
  151. package/dist/worker/github-gateway-wire.d.ts +589 -0
  152. package/dist/worker/github-gateway-wire.js +484 -0
  153. package/dist/worker/github-gateway.d.ts +152 -58
  154. package/dist/worker/github-gateway.js +485 -129
  155. package/dist/worker/github-mirror-upkeep.d.ts +75 -0
  156. package/dist/worker/github-mirror-upkeep.js +266 -0
  157. package/dist/worker/github-mirror.d.ts +271 -71
  158. package/dist/worker/github-mirror.js +755 -238
  159. package/dist/worker/github-transfer.d.ts +56 -0
  160. package/dist/worker/github-transfer.js +444 -0
  161. package/dist/worker/self-checks.d.ts +107 -0
  162. package/dist/worker/self-checks.js +358 -0
  163. package/dist/worker/shared-repo-git.d.ts +20 -7
  164. package/dist/worker/shared-repo-git.js +51 -22
  165. package/dist/worker/stale-mirror.d.ts +82 -0
  166. package/dist/worker/stale-mirror.js +130 -0
  167. package/dist/worker/task-runner.d.ts +2 -0
  168. package/dist/worker/task-runner.js +49 -20
  169. package/dist/worker/worker-context.d.ts +6 -0
  170. package/package.json +1 -1
@@ -9,6 +9,8 @@ export interface MarkdownFieldProps {
9
9
  dataCanopyField?: string;
10
10
  /** The HTML tags the field accepts; the toolbar offers no action writing another. Omitted: any. */
11
11
  htmlTags?: ReadonlySet<string>;
12
+ /** Shows the content without accepting edits, in the rich-text editor or as source. */
13
+ readOnly?: boolean;
12
14
  }
13
15
  /** @internal Exported for the round-trip corpus test, which drives exactly this editor. */
14
16
  export declare const MDXEditorLazy: React.LazyExoticComponent<React.FC<{
@@ -23,6 +25,9 @@ export declare const MDXEditorLazy: React.LazyExoticComponent<React.FC<{
23
25
  imageUploadHandler: (file: File) => Promise<string>;
24
26
  imagePreviewHandler: (src: string) => Promise<string>;
25
27
  htmlTags?: ReadonlySet<string>;
28
+ readOnly?: boolean;
29
+ /** Names the content area for assistive tech; MDXEditor's default is "editable markdown". */
30
+ contentLabel?: string;
26
31
  }>>;
27
32
  /** The textarea over a markdown value; `failure` is why the rich-text editor could not open it. */
28
33
  export declare const MarkdownSourceEditor: React.FC<{
@@ -30,5 +35,6 @@ export declare const MarkdownSourceEditor: React.FC<{
30
35
  value: string;
31
36
  onChange: (value: string) => void;
32
37
  failure?: string;
38
+ readOnly?: boolean;
33
39
  }>;
34
40
  export declare const MarkdownField: React.FC<MarkdownFieldProps>;
@@ -86,9 +86,12 @@ export const MDXEditorLazy = React.lazy(async () => {
86
86
  }, [state, editor]);
87
87
  return _jsx(MdxImageDialog, { state: liveState, onSave: saveImage, onClose: closeImageDialog });
88
88
  };
89
- const WrappedEditor = ({ markdown, onChange, onError, onInsert, editorRef, imageUploadHandler, imagePreviewHandler, htmlTags, }) => {
89
+ const WrappedEditor = ({ markdown, onChange, onError, onInsert, editorRef, imageUploadHandler, imagePreviewHandler, htmlTags, readOnly, contentLabel, }) => {
90
90
  const underline = htmlTags?.has('u') ?? true;
91
- return (_jsx(MDXEditor, { ref: editorRef, markdown: markdown, onChange: onChange, onError: onError, toMarkdownOptions: MARKDOWN_EXPORT_OPTIONS, plugins: [
91
+ const translation = (key, defaultValue, interpolations = {}) => key === 'contentArea.editableMarkdown' && contentLabel
92
+ ? contentLabel
93
+ : Object.entries(interpolations).reduce((text, [name, v]) => text.replaceAll(`{{${name}}}`, String(v)), defaultValue);
94
+ return (_jsx(MDXEditor, { ref: editorRef, markdown: markdown, readOnly: readOnly, translation: translation, onChange: onChange, onError: onError, toMarkdownOptions: MARKDOWN_EXPORT_OPTIONS, plugins: [
92
95
  headingsPlugin(),
93
96
  listsPlugin(),
94
97
  quotePlugin(),
@@ -124,15 +127,22 @@ export const MDXEditorLazy = React.lazy(async () => {
124
127
  markdown: 'Markdown',
125
128
  },
126
129
  }),
127
- toolbarPlugin({
128
- toolbarContents: () => (_jsxs(_Fragment, { children: [_jsx(UndoRedo, {}), _jsx(Separator, {}), _jsx(BoldItalicUnderlineToggles, { options: underline ? undefined : ['Bold', 'Italic'] }), _jsx(CodeToggle, {}), _jsx(Separator, {}), _jsx(BlockTypeSelect, {}), _jsx(Separator, {}), _jsx(ListsToggle, {}), _jsx(Separator, {}), _jsx(CreateLink, {}), _jsx(EntryLinkToolbarButton, { onInsert: onInsert }), _jsx(InsertImage, {}), _jsx(InsertTable, {}), _jsx(InsertThematicBreak, {}), _jsx(InsertCodeBlock, {})] })),
129
- }),
130
+ // MDXEditor's readOnly blocks only the toolbar's pointer events; its buttons still take the
131
+ // keyboard, and their commands edit the document.
132
+ // It reads plugins once, so the editor's key remounts it when `readOnly` changes.
133
+ ...(readOnly
134
+ ? []
135
+ : [
136
+ toolbarPlugin({
137
+ toolbarContents: () => (_jsxs(_Fragment, { children: [_jsx(UndoRedo, {}), _jsx(Separator, {}), _jsx(BoldItalicUnderlineToggles, { options: underline ? undefined : ['Bold', 'Italic'] }), _jsx(CodeToggle, {}), _jsx(Separator, {}), _jsx(BlockTypeSelect, {}), _jsx(Separator, {}), _jsx(ListsToggle, {}), _jsx(Separator, {}), _jsx(CreateLink, {}), _jsx(EntryLinkToolbarButton, { onInsert: onInsert }), _jsx(InsertImage, {}), _jsx(InsertTable, {}), _jsx(InsertThematicBreak, {}), _jsx(InsertCodeBlock, {})] })),
138
+ }),
139
+ ]),
130
140
  ], contentEditableClassName: "canopy-mdx-content" }));
131
141
  };
132
142
  return { default: WrappedEditor };
133
143
  });
134
144
  const editorWrapperStyle = {
135
- background: '#fff',
145
+ background: 'var(--mantine-color-white)',
136
146
  border: '1px solid var(--mantine-color-gray-4, #ced4da)',
137
147
  borderRadius: 'var(--mantine-radius-sm, 4px)',
138
148
  overflow: 'hidden',
@@ -177,10 +187,15 @@ const EditorContentStyles = () => (_jsx("style", { children: `
177
187
  color: var(--mantine-color-gray-6, #868e96);
178
188
  }
179
189
  ` }));
180
- const FallbackTextarea = ({ value, onChange, }) => (_jsx(Textarea, { value: value, onChange: (e) => onChange(e.currentTarget.value), placeholder: "Loading markdown editor...", autosize: true, minRows: 6, size: "sm", readOnly: true }));
190
+ const FallbackTextarea = ({ value }) => (_jsx(Textarea, { value: value, placeholder: "Loading markdown editor...", autosize: true, minRows: 6, size: "sm", readOnly: true }));
181
191
  /** The textarea over a markdown value; `failure` is why the rich-text editor could not open it. */
182
- export const MarkdownSourceEditor = ({ label, value, onChange, failure }) => (_jsxs(_Fragment, { children: [failure !== undefined && (_jsxs(Alert, { color: "yellow", variant: "light", mb: "xs", "data-testid": "markdown-source-fallback", children: [_jsx(Text, { size: "sm", children: "This content couldn't be opened in the visual editor. You can still edit the text and save." }), _jsx(Text, { size: "xs", c: "dimmed", mt: 4, children: failure })] })), _jsx(Textarea, { value: value, onChange: (e) => onChange(e.currentTarget.value), "aria-label": label ? `${label} (source)` : 'Markdown source', "data-testid": "markdown-source-editor", autosize: true, minRows: 10, size: "sm", styles: { input: { fontFamily: 'var(--mantine-font-family-monospace)' } } })] }));
183
- export const MarkdownField = ({ id, label, description, value, onChange, dataCanopyField, htmlTags, }) => {
192
+ export const MarkdownSourceEditor = ({ label, value, onChange, failure, readOnly = false }) => (_jsxs(_Fragment, { children: [failure !== undefined && (_jsxs(Alert, { color: "yellow", variant: "light", mb: "xs", "data-testid": "markdown-source-fallback", children: [_jsx(Text, { size: "sm", children: readOnly
193
+ ? "This content couldn't be opened in the visual editor, so it is shown as text."
194
+ : "This content couldn't be opened in the visual editor. You can still edit the text and save." }), _jsx(Text, { size: "xs", c: "dimmed", mt: 4, children: failure })] })), _jsx(Textarea, { value: value, readOnly: readOnly, onChange: (e) => {
195
+ if (!readOnly)
196
+ onChange(e.currentTarget.value);
197
+ }, "aria-label": label ? `${label} (source)` : 'Markdown source', "data-testid": "markdown-source-editor", autosize: true, minRows: 10, size: "sm", styles: { input: { fontFamily: 'var(--mantine-font-family-monospace)' } } })] }));
198
+ export const MarkdownField = ({ id, label, description, value, onChange, dataCanopyField, htmlTags, readOnly = false, }) => {
184
199
  const generatedId = useId();
185
200
  const inputId = id ?? generatedId;
186
201
  const editorRef = useRef(null);
@@ -194,6 +209,19 @@ export const MarkdownField = ({ id, label, description, value, onChange, dataCan
194
209
  const [, rerender] = useReducer((n) => n + 1, 0);
195
210
  const [rejectedInsert, setRejectedInsert] = useState(null);
196
211
  const [editorGeneration, setEditorGeneration] = useState(0);
212
+ const rootRef = useRef(null);
213
+ // A read-only content area stays reachable by keyboard, like the read-only inputs beside it.
214
+ // Lexical drops it from the tab order once it is not editable, and mounts it after this runs.
215
+ useEffect(() => {
216
+ const root = rootRef.current;
217
+ if (!readOnly || !root)
218
+ return;
219
+ const focusable = () => root.querySelector('.canopy-mdx-content')?.setAttribute('tabindex', '0');
220
+ focusable();
221
+ const observer = new MutationObserver(focusable);
222
+ observer.observe(root, { childList: true, subtree: true });
223
+ return () => observer.disconnect();
224
+ }, [readOnly]);
197
225
  // Drives both MDXEditor's drag/drop/paste upload and the custom image
198
226
  // dialog's Upload tab via the same presign/finalize-or-proxied pipeline
199
227
  // (media/upload-asset.ts). Memoized on the API client (itself memoized by
@@ -214,10 +242,12 @@ export const MarkdownField = ({ id, label, description, value, onChange, dataCan
214
242
  editorRef.current?.setMarkdown(value);
215
243
  }, [value]);
216
244
  const emitChange = useCallback((newValue) => {
245
+ if (readOnly)
246
+ return;
217
247
  lastExternalValue.current = newValue;
218
248
  setRejectedInsert(null);
219
249
  onChange(newValue);
220
- }, [onChange]);
250
+ }, [onChange, readOnly]);
221
251
  // Dropped: MDXEditor's re-serialization of the document it was mounted with
222
252
  // (flagged `initialMarkdownNormalize`; it would mark an unedited entry
223
253
  // modified), and inserted markdown it rejected, which it emits as if that
@@ -286,5 +316,5 @@ export const MarkdownField = ({ id, label, description, value, onChange, dataCan
286
316
  setSourceChosen(false);
287
317
  rerender();
288
318
  };
289
- return (_jsxs("div", { id: inputId, "data-canopy-field": dataCanopyField, className: "canopy-markdown-field", ...groupDescriptionProps(inputId, description), children: [_jsxs(Group, { justify: "space-between", align: "flex-end", mb: 4, wrap: "nowrap", children: [label ? (_jsx(Text, { size: "sm", fw: 500, children: label })) : (_jsx("span", {})), _jsx(Button, { variant: "subtle", size: "compact-xs", "data-testid": "markdown-mode-toggle", onClick: toggleMode, children: showSource ? 'Rich text' : 'Edit source' })] }), _jsx(FieldDescription, { baseId: inputId, description: description }), _jsx(EditorContentStyles, {}), showSource ? (_jsx(MarkdownSourceEditor, { label: label, value: value, onChange: handleSourceChange, failure: failure })) : (_jsxs("div", { style: editorWrapperStyle, children: [rejectedInsert !== null && (_jsxs(Alert, { color: "yellow", variant: "light", mb: "xs", withCloseButton: true, onClose: () => setRejectedInsert(null), "data-testid": "markdown-insert-rejected", children: [_jsx(Text, { size: "sm", children: "The rich-text editor can't show what was inserted, so nothing was added." }), _jsx(Text, { size: "xs", c: "dimmed", mt: 4, children: rejectedInsert })] })), _jsx(EditorErrorBoundary, { context: { boundary: 'rich-text', fieldPath: dataCanopyField }, fallback: () => null, onCaught: handleEditorCrash, children: _jsx(Suspense, { fallback: _jsx(FallbackTextarea, { value: value, onChange: onChange }), children: _jsx(MDXEditorLazy, { markdown: value, onChange: handleEditorChange, onError: handleEditorError, onInsert: handleInsert, editorRef: editorRef, imageUploadHandler: imageUploadHandler, imagePreviewHandler: imagePreviewHandler, htmlTags: htmlTags }, editorGeneration) }) })] }))] }));
319
+ return (_jsxs("div", { ref: rootRef, id: inputId, "data-canopy-field": dataCanopyField, className: "canopy-markdown-field", ...groupDescriptionProps(inputId, description), children: [_jsxs(Group, { justify: "space-between", align: "flex-end", mb: 4, wrap: "nowrap", children: [label ? (_jsx(Text, { size: "sm", fw: 500, children: label })) : (_jsx("span", {})), !readOnly && (_jsx(Button, { variant: "subtle", size: "compact-xs", "data-testid": "markdown-mode-toggle", onClick: toggleMode, children: showSource ? 'Rich text' : 'Edit source' }))] }), _jsx(FieldDescription, { baseId: inputId, description: description }), _jsx(EditorContentStyles, {}), showSource ? (_jsx(MarkdownSourceEditor, { label: label, value: value, onChange: handleSourceChange, failure: failure, readOnly: readOnly })) : (_jsxs("div", { style: editorWrapperStyle, children: [rejectedInsert !== null && (_jsxs(Alert, { color: "yellow", variant: "light", mb: "xs", withCloseButton: true, onClose: () => setRejectedInsert(null), "data-testid": "markdown-insert-rejected", children: [_jsx(Text, { size: "sm", children: "The rich-text editor can't show what was inserted, so nothing was added." }), _jsx(Text, { size: "xs", c: "dimmed", mt: 4, children: rejectedInsert })] })), _jsx(EditorErrorBoundary, { context: { boundary: 'rich-text', fieldPath: dataCanopyField }, fallback: () => null, onCaught: handleEditorCrash, children: _jsx(Suspense, { fallback: _jsx(FallbackTextarea, { value: value }), children: _jsx(MDXEditorLazy, { markdown: value, onChange: handleEditorChange, onError: handleEditorError, onInsert: handleInsert, editorRef: editorRef, imageUploadHandler: imageUploadHandler, imagePreviewHandler: imagePreviewHandler, htmlTags: htmlTags, readOnly: readOnly, contentLabel: label }, `${editorGeneration}-${readOnly}`) }) })] }))] }));
290
320
  };
@@ -67,5 +67,5 @@ export const MdxImageDialog = ({ state, onSave, onClose }) => {
67
67
  if (next)
68
68
  setTab(next);
69
69
  }, children: [_jsxs(Tabs.List, { children: [_jsx(Tabs.Tab, { value: "upload", "data-testid": "mdx-image-dialog-tab-upload", children: "Upload" }), _jsx(Tabs.Tab, { value: "library", "data-testid": "mdx-image-dialog-tab-library", children: "From library" }), _jsx(Tabs.Tab, { value: "url", "data-testid": "mdx-image-dialog-tab-url", children: "By URL" })] }), _jsx(Tabs.Panel, { value: "upload", pt: "sm", children: _jsxs(Stack, { gap: "xs", children: [_jsx(Dropzone, { onDrop: (files) => void handleDrop(files), onReject: handleReject, maxSize: MAX_UPLOAD_BYTES, accept: ACCEPTED_IMAGE_MIME_TYPES, loading: upload.uploading, multiple: false, "data-testid": "mdx-image-dialog-dropzone", children: _jsxs(Group, { justify: "center", gap: "xs", py: "sm", style: { pointerEvents: 'none' }, children: [_jsx(IconUpload, { size: 20 }), _jsx(Text, { size: "sm", children: "Drop an image here, or click to browse" })] }) }), upload.uploading &&
70
- (upload.progress !== null ? (_jsx(Progress, { value: upload.progress * 100, size: "sm" })) : (_jsx(Progress, { value: 100, size: "sm", animated: true }))), (upload.error || dropError) && (_jsx(Alert, { icon: _jsx(IconAlertCircle, { size: 16 }), color: "red", children: upload.error || dropError }))] }) }), _jsx(Tabs.Panel, { value: "library", pt: "sm", children: _jsx("div", { style: { height: LIBRARY_PANEL_HEIGHT }, children: _jsx(MediaLibraryBody, { opened: tab === 'library', mode: "picker", onSelect: handlePickFromLibrary }) }) }), _jsx(Tabs.Panel, { value: "url", pt: "sm", children: _jsxs(Stack, { gap: "xs", children: [_jsx(TextInput, { label: "Image URL", placeholder: "https://example.com/image.png", value: urlValue, onChange: (event) => setUrlValue(event.currentTarget.value), "data-testid": "mdx-image-dialog-url" }), _jsx(Group, { justify: "flex-end", children: _jsx(Button, { onClick: handleUrlSubmit, disabled: !urlValue.trim(), "data-testid": "mdx-image-dialog-url-submit", children: "Insert" }) })] }) })] }), _jsx(Group, { justify: "flex-end", children: _jsx(Button, { variant: "default", onClick: onClose, children: "Cancel" }) })] }) }));
70
+ (upload.progress !== null ? (_jsx(Progress, { value: upload.progress * 100, size: "sm" })) : (_jsx(Progress, { value: 100, size: "sm", animated: true }))), (upload.error || dropError) && (_jsx(Alert, { icon: _jsx(IconAlertCircle, { size: 16 }), color: "red", children: upload.error || dropError }))] }) }), _jsx(Tabs.Panel, { value: "library", pt: "sm", children: _jsx("div", { style: { height: LIBRARY_PANEL_HEIGHT }, children: _jsx(MediaLibraryBody, { opened: tab === 'library', mode: "picker", onSelect: handlePickFromLibrary }) }) }), _jsx(Tabs.Panel, { value: "url", pt: "sm", children: _jsxs(Stack, { gap: "xs", children: [_jsx(TextInput, { label: "Image URL", placeholder: "https://example.com/image.png", value: urlValue, onChange: (event) => setUrlValue(event.currentTarget.value), "data-testid": "mdx-image-dialog-url" }), _jsx(Group, { justify: "flex-end", children: _jsx(Button, { size: "sm", onClick: handleUrlSubmit, disabled: !urlValue.trim(), "data-testid": "mdx-image-dialog-url-submit", children: "Insert" }) })] }) })] }), _jsx(Group, { justify: "flex-end", children: _jsx(Button, { size: "sm", variant: "default", onClick: onClose, children: "Cancel" }) })] }) }));
71
71
  };
@@ -6,6 +6,8 @@ export interface NumberFieldProps {
6
6
  value: number | undefined;
7
7
  onChange: (value: number | undefined) => void;
8
8
  dataCanopyField?: string;
9
+ /** Shows the value without accepting edits. */
10
+ readOnly?: boolean;
9
11
  }
10
12
  /**
11
13
  * Editor for `type: 'number'` fields.
@@ -27,14 +27,16 @@ const toNumericValue = (raw) => {
27
27
  * would silently store `0.5` after the second keystroke. See
28
28
  * NumberField.test.tsx's keystroke matrix.
29
29
  */
30
- export const NumberField = ({ id, label, description, value, onChange, dataCanopyField, }) => {
30
+ export const NumberField = ({ id, label, description, value, onChange, dataCanopyField, readOnly = false, }) => {
31
31
  const generatedId = useId();
32
32
  const inputId = id ?? generatedId;
33
33
  const [inputValue, setInputValue] = useState(value ?? '');
34
34
  // Shows the in-progress text only while it still matches the parent's
35
35
  // value; once the parent's value diverges (load, discard, reload), that value wins.
36
36
  const displayValue = toNumericValue(inputValue) === value ? inputValue : (value ?? '');
37
- return (_jsx(NumberInput, { id: inputId, label: label, description: description, value: displayValue, size: "sm", onChange: (next) => {
37
+ return (_jsx(NumberInput, { id: inputId, label: label, description: description, value: displayValue, size: "sm", readOnly: readOnly, onChange: (next) => {
38
+ if (readOnly)
39
+ return;
38
40
  setInputValue(next);
39
41
  onChange(toNumericValue(next));
40
42
  }, "data-canopy-field": dataCanopyField }));
@@ -6,6 +6,8 @@ export interface NumberListFieldProps {
6
6
  value: number[];
7
7
  onChange: (value: number[]) => void;
8
8
  dataCanopyField?: string;
9
+ /** Shows the value without accepting edits. */
10
+ readOnly?: boolean;
9
11
  }
10
12
  /**
11
13
  * Editor for `type: 'number', list: true` fields.
@@ -27,13 +27,15 @@ const parseTag = (tag) => {
27
27
  * on Enter indistinguishably from being accepted, with nothing to tell a
28
28
  * typo from a broken field — so rejected text is named in the error slot.
29
29
  */
30
- export const NumberListField = ({ id, label, description, value, onChange, dataCanopyField, }) => {
30
+ export const NumberListField = ({ id, label, description, value, onChange, dataCanopyField, readOnly = false, }) => {
31
31
  const generatedId = useId();
32
32
  const inputId = id ?? generatedId;
33
33
  const [rejected, setRejected] = useState([]);
34
34
  return (_jsx(TagsInput, { id: inputId, label: label, description: description, value: value.map(String), size: "sm", error: rejected.length > 0
35
35
  ? `Not ${rejected.length === 1 ? 'a number' : 'numbers'}: ${rejected.join(', ')}`
36
- : undefined, onChange: (next) => {
36
+ : undefined, readOnly: readOnly, onChange: (next) => {
37
+ if (readOnly)
38
+ return;
37
39
  const parsed = [];
38
40
  const dropped = [];
39
41
  for (const tag of next) {
@@ -3,6 +3,7 @@ import type { FieldConfig } from '../../config/index.js';
3
3
  export type RenderField = (field: FieldConfig, value: unknown, onChange: (v: unknown) => void, path: Array<string | number>) => React.ReactNode;
4
4
  export interface ObjectFieldProps {
5
5
  label?: string;
6
+ required?: boolean;
6
7
  description?: string;
7
8
  fields: FieldConfig[];
8
9
  value: Record<string, unknown> | undefined;
@@ -1,13 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId } from 'react';
3
- import { Button, Group, Paper, Stack, Text } from '@mantine/core';
3
+ import { Button, Paper, Stack } from '@mantine/core';
4
4
  import { isPlainRecord } from '../../validation/field-traversal.js';
5
5
  import { formatCanopyPath } from '../canopy-path.js';
6
- import { FieldDescription, groupDescriptionProps } from './FieldDescription.js';
7
- export const ObjectField = ({ label, description, fields, value, onChange, renderField, path, dataCanopyField, onRemove, }) => {
6
+ import { groupDescriptionProps } from './FieldDescription.js';
7
+ import { FieldLabel } from './FieldLabel.js';
8
+ export const ObjectField = ({ label, required, description, fields, value, onChange, renderField, path, dataCanopyField, onRemove, }) => {
8
9
  const current = isPlainRecord(value) ? value : {};
9
10
  const descriptionBaseId = useId();
10
- return (_jsx(Paper, { withBorder: true, radius: "md", p: "md", bg: "gray.0", "data-canopy-field": dataCanopyField ?? formatCanopyPath(path), shadow: "xs", ...groupDescriptionProps(descriptionBaseId, description), children: _jsxs(Stack, { gap: "sm", children: [(label || onRemove) && (_jsxs(Group, { justify: "space-between", children: [label && (_jsx(Text, { size: "xs", fw: 700, c: "neutral.8", children: label })), onRemove && (_jsx(Button, { size: "xs", variant: "subtle", color: "red", onClick: onRemove, children: "Clear" }))] })), _jsx(FieldDescription, { baseId: descriptionBaseId, description: description }), _jsx(Stack, { gap: "sm", children: fields.map((field) => {
11
+ return (_jsx(Paper, { withBorder: true, p: "md", bg: "gray.0", "data-canopy-field": dataCanopyField ?? formatCanopyPath(path), shadow: "xs", ...groupDescriptionProps(descriptionBaseId, description), children: _jsxs(Stack, { gap: "sm", children: [_jsx(FieldLabel, { label: label, required: required, description: description, descriptionBaseId: descriptionBaseId, actions: onRemove && (_jsx(Button, { variant: "subtle", color: "red", onClick: onRemove, children: "Clear" })) }), _jsx(Stack, { gap: "sm", children: fields.map((field) => {
11
12
  const fieldPath = [...path, field.name];
12
13
  return (_jsx("div", { children: renderField(field, current[field.name], (next) => onChange({ ...current, [field.name]: next }), fieldPath) }, formatCanopyPath(fieldPath)));
13
14
  }) })] }) }));
@@ -17,5 +17,7 @@ export interface ReferenceFieldProps {
17
17
  onChange: (value: string | string[]) => void;
18
18
  multiple?: boolean;
19
19
  dataCanopyField?: string;
20
+ /** Shows the value without accepting edits. */
21
+ readOnly?: boolean;
20
22
  }
21
23
  export declare const ReferenceField: React.FC<ReferenceFieldProps>;
@@ -17,7 +17,7 @@ function unlistedReferenceLabel(value, id) {
17
17
  }
18
18
  return `Unavailable entry (${id})`;
19
19
  }
20
- export const ReferenceField = ({ id, label, description, options: staticOptions, collections, entryTypes, displayField = 'title', branch = 'main', value, onChange, multiple, dataCanopyField, }) => {
20
+ export const ReferenceField = ({ id, label, description, options: staticOptions, collections, entryTypes, displayField = 'title', branch = 'main', value, onChange, multiple, dataCanopyField, readOnly = false, }) => {
21
21
  // Configured with the deployment's basePath when rendered inside an
22
22
  // ApiClientProvider (always true in the real Editor tree); `null` outside one
23
23
  // (e.g. FormRenderer.stories.tsx), so the fetch effect falls back to a
@@ -125,7 +125,13 @@ export const ReferenceField = ({ id, label, description, options: staticOptions,
125
125
  return (_jsxs(Stack, { gap: 4, "data-canopy-field": dataCanopyField, "data-testid": `reference-field-${dataCanopyField}`, ...groupDescriptionProps(inputId, description), children: [_jsx(Text, { size: "sm", fw: 500, children: label }), _jsx(FieldDescription, { baseId: inputId, description: description }), _jsx(Loader, { size: "sm", "data-testid": `reference-loading-${dataCanopyField}` })] }));
126
126
  }
127
127
  if (error) {
128
- return (_jsxs(Stack, { gap: 4, "data-canopy-field": dataCanopyField, "data-testid": `reference-field-${dataCanopyField}`, ...groupDescriptionProps(inputId, description), children: [_jsx(Text, { size: "sm", fw: 500, children: label }), _jsx(FieldDescription, { baseId: inputId, description: description }), _jsx(Alert, { icon: _jsx(IconAlertCircle, { size: 16 }), color: "red", title: "Error", "data-testid": `reference-error-${dataCanopyField}`, children: _jsxs(Stack, { gap: 4, children: [_jsx(Text, { size: "sm", children: error }), _jsx(Button, { size: "xs", variant: "light", onClick: handleRetry, "data-testid": `reference-retry-${dataCanopyField}`, children: "Retry" })] }) })] }));
128
+ return (_jsxs(Stack, { gap: 4, "data-canopy-field": dataCanopyField, "data-testid": `reference-field-${dataCanopyField}`, ...groupDescriptionProps(inputId, description), children: [_jsx(Text, { size: "sm", fw: 500, children: label }), _jsx(FieldDescription, { baseId: inputId, description: description }), _jsx(Alert, { icon: _jsx(IconAlertCircle, { size: 16 }), color: "red", title: "Error", "data-testid": `reference-error-${dataCanopyField}`, children: _jsxs(Stack, { gap: 4, children: [_jsx(Text, { size: "sm", children: error }), _jsx(Button, { variant: "light", onClick: handleRetry, "data-testid": `reference-retry-${dataCanopyField}`, children: "Retry" })] }) })] }));
129
129
  }
130
- return (_jsx(Stack, { gap: 4, "data-canopy-field": dataCanopyField, "data-testid": `reference-field-${dataCanopyField}`, children: multiple ? (_jsx(MultiSelect, { id: inputId, label: label, description: description, data: data, value: normalizedValue, onChange: (next) => onChange(next), searchable: true, placeholder: "Select reference\u2026", size: "sm" })) : (_jsx(Select, { id: inputId, label: label, description: description, data: data, value: normalizedValue, onChange: (next) => onChange(next ?? ''), searchable: true, clearable: true, placeholder: "Select reference\u2026", size: "sm" })) }));
130
+ return (_jsx(Stack, { gap: 4, "data-canopy-field": dataCanopyField, "data-testid": `reference-field-${dataCanopyField}`, children: multiple ? (_jsx(MultiSelect, { id: inputId, label: label, description: description, data: data, value: normalizedValue, readOnly: readOnly, rightSection: readOnly ? _jsx("span", {}) : undefined, onChange: (next) => {
131
+ if (!readOnly)
132
+ onChange(next);
133
+ }, searchable: true, placeholder: readOnly ? undefined : 'Select reference…', size: "sm" })) : (_jsx(Select, { id: inputId, label: label, description: description, data: data, value: normalizedValue, readOnly: readOnly, rightSection: readOnly ? _jsx("span", {}) : undefined, onChange: (next) => {
134
+ if (!readOnly)
135
+ onChange(next ?? '');
136
+ }, searchable: true, clearable: true, placeholder: readOnly ? undefined : 'Select reference…', size: "sm" })) }));
131
137
  };
@@ -13,6 +13,8 @@ export interface SelectFieldProps {
13
13
  multiple?: boolean;
14
14
  placeholder?: string;
15
15
  dataCanopyField?: string;
16
+ /** Shows the value without accepting edits. */
17
+ readOnly?: boolean;
16
18
  }
17
19
  export declare const SelectField: React.FC<SelectFieldProps>;
18
20
  export {};
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId } from 'react';
3
3
  import { MultiSelect, Select, Stack, Text } from '@mantine/core';
4
- export const SelectField = ({ id, label, description, options, value, onChange, multiple, placeholder = 'Select…', dataCanopyField, }) => {
4
+ export const SelectField = ({ id, label, description, options, value, onChange, multiple, placeholder = 'Select…', dataCanopyField, readOnly = false, }) => {
5
5
  const normalizedValue = multiple
6
6
  ? Array.isArray(value)
7
7
  ? value
@@ -11,5 +11,11 @@ export const SelectField = ({ id, label, description, options, value, onChange,
11
11
  : '';
12
12
  const generatedId = useId();
13
13
  const inputId = id ?? generatedId;
14
- return (_jsxs(Stack, { gap: 4, "data-canopy-field": dataCanopyField, children: [multiple ? (_jsx(MultiSelect, { id: inputId, label: label, description: description, data: options, value: normalizedValue, onChange: (next) => onChange(next), searchable: true, placeholder: placeholder, size: "sm" })) : (_jsx(Select, { id: inputId, label: label, description: description, data: options, value: normalizedValue, onChange: (next) => onChange(next ?? ''), searchable: true, clearable: true, placeholder: placeholder, size: "sm" })), multiple && (_jsx(Text, { size: "xs", c: "dimmed", children: "Searchable multi-select; start typing to filter." }))] }));
14
+ return (_jsxs(Stack, { gap: 4, "data-canopy-field": dataCanopyField, children: [multiple ? (_jsx(MultiSelect, { id: inputId, label: label, description: description, data: options, value: normalizedValue, readOnly: readOnly, rightSection: readOnly ? _jsx("span", {}) : undefined, onChange: (next) => {
15
+ if (!readOnly)
16
+ onChange(next);
17
+ }, searchable: true, placeholder: readOnly ? undefined : placeholder, size: "sm" })) : (_jsx(Select, { id: inputId, label: label, description: description, data: options, value: normalizedValue, readOnly: readOnly, rightSection: readOnly ? _jsx("span", {}) : undefined, onChange: (next) => {
18
+ if (!readOnly)
19
+ onChange(next ?? '');
20
+ }, searchable: true, clearable: true, placeholder: readOnly ? undefined : placeholder, size: "sm" })), multiple && !readOnly && (_jsx(Text, { size: "xs", c: "dimmed", children: "Searchable multi-select; start typing to filter." }))] }));
15
21
  };
@@ -6,6 +6,8 @@ export interface StringListFieldProps {
6
6
  value: string[];
7
7
  onChange: (value: string[]) => void;
8
8
  dataCanopyField?: string;
9
+ /** Shows the value without accepting edits. */
10
+ readOnly?: boolean;
9
11
  }
10
12
  /**
11
13
  * Editor for `type: 'string', list: true` fields.
@@ -7,10 +7,13 @@ import { TagsInput } from '@mantine/core';
7
7
  * Uses Mantine's TagsInput: type + Enter adds an item, each item renders as a
8
8
  * removable pill, and Backspace on an empty input removes the last item.
9
9
  */
10
- export const StringListField = ({ id, label, description, value, onChange, dataCanopyField, }) => {
10
+ export const StringListField = ({ id, label, description, value, onChange, dataCanopyField, readOnly = false, }) => {
11
11
  const generatedId = useId();
12
12
  const inputId = id ?? generatedId;
13
- return (_jsx(TagsInput, { id: inputId, label: label, description: description, value: value, size: "sm", onChange: onChange,
13
+ return (_jsx(TagsInput, { id: inputId, label: label, description: description, value: value, size: "sm", readOnly: readOnly, onChange: (next) => {
14
+ if (!readOnly)
15
+ onChange(next);
16
+ },
14
17
  // Faithful generic-list semantics, not tag ergonomics: no comma-splitting
15
18
  // ("New York, NY" stays one item) and duplicates are legitimate list
16
19
  // data — TagsInput's defaults would break both, so existing file data
@@ -6,5 +6,7 @@ export interface TextFieldProps {
6
6
  value: string;
7
7
  onChange: (value: string) => void;
8
8
  dataCanopyField?: string;
9
+ /** Shows the value without accepting edits. */
10
+ readOnly?: boolean;
9
11
  }
10
12
  export declare const TextField: React.FC<TextFieldProps>;
@@ -1,8 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useId } from 'react';
3
3
  import { TextInput } from '@mantine/core';
4
- export const TextField = ({ id, label, description, value, onChange, dataCanopyField, }) => {
4
+ export const TextField = ({ id, label, description, value, onChange, dataCanopyField, readOnly = false, }) => {
5
5
  const generatedId = useId();
6
6
  const inputId = id ?? generatedId;
7
- return (_jsx(TextInput, { id: inputId, label: label, description: description, value: value, size: "sm", onChange: (e) => onChange(e.currentTarget.value), "data-canopy-field": dataCanopyField }));
7
+ return (_jsx(TextInput, { id: inputId, label: label, description: description, value: value, size: "sm", readOnly: readOnly, onChange: (e) => {
8
+ if (!readOnly)
9
+ onChange(e.currentTarget.value);
10
+ }, "data-canopy-field": dataCanopyField }));
8
11
  };
@@ -7,5 +7,7 @@ export interface ToggleFieldProps {
7
7
  onChange: (value: boolean) => void;
8
8
  dataCanopyField?: string;
9
9
  testId?: string;
10
+ /** Shows the value without accepting edits. */
11
+ readOnly?: boolean;
10
12
  }
11
13
  export declare const ToggleField: React.FC<ToggleFieldProps>;
@@ -1,11 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId } from 'react';
3
- import { Stack, Switch } from '@mantine/core';
3
+ import { Group, Stack, Switch, Text } from '@mantine/core';
4
4
  import { FieldDescription, fieldDescriptionId } from './FieldDescription.js';
5
- export const ToggleField = ({ id, label, description, value, onChange, dataCanopyField, testId, }) => {
5
+ export const ToggleField = ({ id, label, description, value, onChange, dataCanopyField, testId, readOnly = false, }) => {
6
6
  const generatedId = useId();
7
7
  const inputId = id ?? generatedId;
8
8
  // A Switch's `description` sits inside its <label> and so joins the accessible name;
9
9
  // rendering it as a sibling keeps the name to the label alone.
10
- return (_jsxs(Stack, { gap: 4, children: [_jsx(Switch, { id: inputId, label: label, "aria-describedby": description ? fieldDescriptionId(inputId) : undefined, checked: value, onChange: (e) => onChange(e.currentTarget.checked), size: "md", "data-canopy-field": dataCanopyField, wrapperProps: testId ? { 'data-testid': testId } : undefined }), _jsx(FieldDescription, { baseId: inputId, description: description })] }));
10
+ return (_jsxs(Stack, { gap: 4, children: [_jsxs(Group, { gap: "sm", wrap: "nowrap", children: [_jsx(Switch, { id: inputId, label: label, "aria-describedby": description ? fieldDescriptionId(inputId) : undefined, checked: value, disabled: readOnly, onChange: (e) => {
11
+ if (!readOnly)
12
+ onChange(e.currentTarget.checked);
13
+ }, size: "md", "data-canopy-field": dataCanopyField, wrapperProps: testId ? { 'data-testid': testId } : undefined }), readOnly && (_jsx(Text, { size: "sm", c: "gray.7", "data-testid": testId ? `${testId}-value` : undefined, children: value ? 'On' : 'Off' }))] }), _jsx(FieldDescription, { baseId: inputId, description: description })] }));
11
14
  };
@@ -44,7 +44,7 @@ export const InsertEntryLink = ({ onInsert }) => {
44
44
  setOpened(false);
45
45
  setSearch('');
46
46
  };
47
- return (_jsxs(_Fragment, { children: [_jsx(ActionIcon, { variant: "subtle", size: "sm", color: "gray", title: "Insert entry link", "data-testid": "insert-entry-link-button", onClick: () => setOpened(true), children: _jsx(IconFileSymlink, { size: 16 }) }), _jsx(Modal, { opened: opened, onClose: () => {
47
+ return (_jsxs(_Fragment, { children: [_jsx(ActionIcon, { variant: "subtle", color: "gray", title: "Insert entry link", "data-testid": "insert-entry-link-button", onClick: () => setOpened(true), children: _jsx(IconFileSymlink, { size: 16 }) }), _jsx(Modal, { opened: opened, onClose: () => {
48
48
  setOpened(false);
49
49
  setSearch('');
50
50
  }, title: "Link to Entry", size: "md", children: _jsx(Stack, { gap: "sm", children: _jsxs(Combobox, { store: combobox, onOptionSubmit: (val) => {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Keys for the items of object lists and block lists. An object listed once keeps the key it
3
+ * was first shown with, so an append remounts no item, a removal never hands a crashed item's
4
+ * boundary to the next one, and an item put back by Undo (the same object) gets its key back. A
5
+ * list whose length is unchanged (an edited item, the saved copy of the same items) keeps keys by
6
+ * position. One instance serves every list a component renders, told apart by `listPath`.
7
+ */
8
+ export declare function useListItemKeys(): (items: readonly unknown[], listPath: string) => string[];
@@ -0,0 +1,50 @@
1
+ import { useRef } from 'react';
2
+ /**
3
+ * Keys for the items of object lists and block lists. An object listed once keeps the key it
4
+ * was first shown with, so an append remounts no item, a removal never hands a crashed item's
5
+ * boundary to the next one, and an item put back by Undo (the same object) gets its key back. A
6
+ * list whose length is unchanged (an edited item, the saved copy of the same items) keeps keys by
7
+ * position. One instance serves every list a component renders, told apart by `listPath`.
8
+ */
9
+ export function useListItemKeys() {
10
+ const listItemKeys = useRef(new WeakMap());
11
+ const lastListKeys = useRef(new Map());
12
+ const nextListItemKey = useRef(0);
13
+ return (items, listPath) => {
14
+ const previous = lastListKeys.current.get(listPath);
15
+ const occurrences = new Map();
16
+ for (const item of items) {
17
+ if (typeof item === 'object' && item !== null) {
18
+ occurrences.set(item, (occurrences.get(item) ?? 0) + 1);
19
+ }
20
+ }
21
+ // Only an object listed once has an identity; a repeated one is keyed by position.
22
+ const single = (item) => typeof item === 'object' && item !== null && occurrences.get(item) === 1;
23
+ const claimed = new Set();
24
+ const keys = items.map((item) => {
25
+ const own = single(item) ? listItemKeys.current.get(item) : undefined;
26
+ // Two objects can hold one key, an edited copy having inherited its original's.
27
+ if (own === undefined || claimed.has(own))
28
+ return undefined;
29
+ claimed.add(own);
30
+ return own;
31
+ });
32
+ // The rest inherit their position's key, never one an object present here holds.
33
+ const resolved = keys.map((key, idx) => {
34
+ if (key !== undefined)
35
+ return key;
36
+ let next = previous?.length === items.length ? previous[idx] : undefined;
37
+ if (next === undefined || claimed.has(next)) {
38
+ nextListItemKey.current += 1;
39
+ next = `item-${nextListItemKey.current}`;
40
+ }
41
+ claimed.add(next);
42
+ const item = items[idx];
43
+ if (single(item))
44
+ listItemKeys.current.set(item, next);
45
+ return next;
46
+ });
47
+ lastListKeys.current.set(listPath, resolved);
48
+ return resolved;
49
+ };
50
+ }
@@ -4,5 +4,5 @@ import { ActionIcon, Badge, Group, Paper, Text, Tooltip } from '@mantine/core';
4
4
  import { IconEdit, IconTrash } from '@tabler/icons-react';
5
5
  import { MemberList } from './MemberList.js';
6
6
  export const GroupCard = ({ group, isUnsaved, onEdit, onDelete, onAddMember, onRemoveMember, onGetUserMetadata, showUserSearch, searchQuery, searchResults, isSearching, searchError, onSearchQueryChange, onShowSearch, onHideSearch, canSearch, }) => {
7
- return (_jsxs(Paper, { withBorder: true, p: "sm", mb: "xs", children: [_jsxs(Group, { justify: "space-between", mb: "sm", children: [_jsxs("div", { style: { flex: 1 }, children: [_jsxs(Group, { gap: "xs", children: [_jsx(Text, { size: "sm", fw: 500, children: group.name }), _jsxs(Badge, { size: "sm", variant: "light", children: [group.members?.length || 0, " members"] }), isUnsaved && (_jsx(Badge, { size: "sm", variant: "light", color: "orange", children: "Unsaved" }))] }), _jsxs(Text, { size: "xs", c: "dimmed", mt: 4, children: ["ID: ", group.id] }), group.description && (_jsx(Text, { size: "xs", c: "dimmed", mt: 4, children: group.description }))] }), _jsxs(Group, { gap: "xs", children: [_jsx(Tooltip, { label: "Edit group", children: _jsx(ActionIcon, { size: "sm", variant: "subtle", onClick: () => onEdit(group), children: _jsx(IconEdit, { size: 16 }) }) }), _jsx(Tooltip, { label: "Delete group", children: _jsx(ActionIcon, { size: "sm", variant: "subtle", color: "red", onClick: () => onDelete(group.id), children: _jsx(IconTrash, { size: 16 }) }) })] })] }), _jsx(MemberList, { groupId: group.id, members: group.members || [], onRemoveMember: onRemoveMember, onAddMember: onAddMember, onGetUserMetadata: onGetUserMetadata, showUserSearch: showUserSearch, searchQuery: searchQuery, searchResults: searchResults, isSearching: isSearching, searchError: searchError, onSearchQueryChange: onSearchQueryChange, onShowSearch: onShowSearch, onHideSearch: onHideSearch, canSearch: canSearch })] }));
7
+ return (_jsxs(Paper, { withBorder: true, p: "sm", mb: "xs", children: [_jsxs(Group, { justify: "space-between", mb: "sm", children: [_jsxs("div", { style: { flex: 1 }, children: [_jsxs(Group, { gap: "xs", children: [_jsx(Text, { size: "sm", fw: 500, children: group.name }), _jsxs(Badge, { size: "sm", variant: "light", children: [group.members?.length || 0, " members"] }), isUnsaved && (_jsx(Badge, { size: "sm", variant: "light", color: "orange", children: "Unsaved" }))] }), _jsxs(Text, { size: "xs", c: "dimmed", mt: 4, children: ["ID: ", group.id] }), group.description && (_jsx(Text, { size: "xs", c: "dimmed", mt: 4, children: group.description }))] }), _jsxs(Group, { gap: "xs", children: [_jsx(Tooltip, { label: "Edit group", children: _jsx(ActionIcon, { variant: "subtle", "aria-label": "Edit group", onClick: () => onEdit(group), children: _jsx(IconEdit, { size: 16 }) }) }), _jsx(Tooltip, { label: "Delete group", children: _jsx(ActionIcon, { variant: "subtle", color: "red", "aria-label": "Delete group", onClick: () => onDelete(group.id), children: _jsx(IconTrash, { size: 16 }) }) })] })] }), _jsx(MemberList, { groupId: group.id, members: group.members || [], onRemoveMember: onRemoveMember, onAddMember: onAddMember, onGetUserMetadata: onGetUserMetadata, showUserSearch: showUserSearch, searchQuery: searchQuery, searchResults: searchResults, isSearching: isSearching, searchError: searchError, onSearchQueryChange: onSearchQueryChange, onShowSearch: onShowSearch, onHideSearch: onHideSearch, canSearch: canSearch })] }));
8
8
  };
@@ -2,5 +2,5 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Button, Group, Modal, Paper, Stack, Text, TextInput, Textarea } from '@mantine/core';
4
4
  export const GroupForm = ({ isOpen, editingGroup, formData, onFormChange, onSave, onClose, }) => {
5
- return (_jsx(Modal, { opened: isOpen, onClose: onClose, title: editingGroup ? 'Edit Group' : 'Create Group', children: _jsxs(Stack, { gap: "md", children: [editingGroup && (_jsxs("div", { children: [_jsx(Text, { size: "sm", fw: 500, mb: 4, children: "ID (system-generated)" }), _jsx(Paper, { p: "xs", withBorder: true, bg: "gray.0", children: _jsx(Text, { size: "sm", ff: "monospace", c: "dimmed", children: editingGroup.id }) })] })), _jsx(TextInput, { label: "Group Name", placeholder: "e.g., Content Editors", value: formData.name, onChange: (e) => onFormChange({ name: e.target.value }), required: true }), _jsx(Textarea, { label: "Description", placeholder: "Optional description", value: formData.description, onChange: (e) => onFormChange({ description: e.target.value }), rows: 3 }), _jsxs(Group, { justify: "flex-end", gap: "sm", children: [_jsx(Button, { variant: "subtle", onClick: onClose, children: "Cancel" }), _jsx(Button, { onClick: onSave, children: editingGroup ? 'Apply' : 'Add' })] })] }) }));
5
+ return (_jsx(Modal, { opened: isOpen, onClose: onClose, title: editingGroup ? 'Edit Group' : 'Create Group', children: _jsxs(Stack, { gap: "md", children: [editingGroup && (_jsxs("div", { children: [_jsx(Text, { size: "sm", fw: 500, mb: 4, children: "ID (system-generated)" }), _jsx(Paper, { p: "xs", withBorder: true, bg: "gray.0", children: _jsx(Text, { size: "sm", ff: "monospace", c: "dimmed", children: editingGroup.id }) })] })), _jsx(TextInput, { label: "Group Name", placeholder: "e.g., Content Editors", value: formData.name, onChange: (e) => onFormChange({ name: e.target.value }), required: true }), _jsx(Textarea, { label: "Description", placeholder: "Optional description", value: formData.description, onChange: (e) => onFormChange({ description: e.target.value }), rows: 3 }), _jsxs(Group, { justify: "flex-end", gap: "sm", children: [_jsx(Button, { size: "sm", variant: "subtle", onClick: onClose, children: "Cancel" }), _jsx(Button, { size: "sm", onClick: onSave, children: editingGroup ? 'Apply' : 'Add' })] })] }) }));
6
6
  };
@@ -11,5 +11,5 @@ export const InternalGroupsTab = ({ groups, unsavedGroupIds, canEdit, onCreateGr
11
11
  paddingTop: 'var(--mantine-spacing-md)',
12
12
  }, children: groups.length === 0 ? (_jsxs(Paper, { withBorder: true, p: "md", style: { textAlign: 'center' }, children: [_jsx(IconUsers, { size: 32, color: "gray", style: { margin: '0 auto', marginBottom: 8 } }), _jsx(Text, { size: "sm", c: "dimmed", children: "No internal groups" })] })) : (_jsx(Stack, { gap: "xs", pb: "md", children: groups.map((group) => (_jsx(Paper, { withBorder: true, p: "sm", children: _jsxs(Group, { justify: "space-between", children: [_jsxs("div", { children: [_jsx(Text, { size: "sm", fw: 500, children: group.name }), group.description && (_jsx(Text, { size: "xs", c: "dimmed", children: group.description }))] }), _jsxs(Text, { size: "sm", variant: "light", children: [group.members?.length || 0, " members"] })] }) }, group.id))) })) }));
13
13
  }
14
- return (_jsx(ScrollArea, { style: { height: '100%' }, pt: "md", children: _jsxs(Stack, { gap: "sm", pb: "md", children: [_jsxs(Group, { justify: "space-between", mb: "xs", children: [_jsx(Text, { size: "sm", fw: 500, c: "dimmed", children: "Manage your internal groups" }), _jsx(Button, { size: "xs", variant: "light", leftSection: _jsx(IconPlus, { size: 14 }), onClick: onCreateGroup, children: "Create Group" })] }), groups.length === 0 ? (_jsxs(Paper, { withBorder: true, p: "md", style: { textAlign: 'center' }, children: [_jsx(IconUsers, { size: 32, color: "gray", style: { margin: '0 auto', marginBottom: 8 } }), _jsx(Text, { size: "sm", c: "dimmed", children: "No internal groups yet. Create one to get started." })] })) : (groups.map((group) => (_jsx(GroupCard, { group: group, isUnsaved: unsavedGroupIds.has(group.id), onEdit: onEditGroup, onDelete: onDeleteGroup, onAddMember: onAddMember, onRemoveMember: onRemoveMember, onGetUserMetadata: onGetUserMetadata, showUserSearch: activeSearchGroupId === group.id, searchQuery: searchQuery, searchResults: searchResults, isSearching: isSearching, searchError: searchError, onSearchQueryChange: onSearchQueryChange, onShowSearch: () => onShowSearch(group.id), onHideSearch: onHideSearch, canSearch: canSearch }, group.id))))] }) }));
14
+ return (_jsx(ScrollArea, { style: { height: '100%' }, pt: "md", children: _jsxs(Stack, { gap: "sm", pb: "md", children: [_jsxs(Group, { justify: "space-between", mb: "xs", children: [_jsx(Text, { size: "sm", fw: 500, c: "dimmed", children: "Manage your internal groups" }), _jsx(Button, { variant: "light", leftSection: _jsx(IconPlus, { size: 14 }), onClick: onCreateGroup, children: "Create Group" })] }), groups.length === 0 ? (_jsxs(Paper, { withBorder: true, p: "md", style: { textAlign: 'center' }, children: [_jsx(IconUsers, { size: 32, color: "gray", style: { margin: '0 auto', marginBottom: 8 } }), _jsx(Text, { size: "sm", c: "dimmed", children: "No internal groups yet. Create one to get started." })] })) : (groups.map((group) => (_jsx(GroupCard, { group: group, isUnsaved: unsavedGroupIds.has(group.id), onEdit: onEditGroup, onDelete: onDeleteGroup, onAddMember: onAddMember, onRemoveMember: onRemoveMember, onGetUserMetadata: onGetUserMetadata, showUserSearch: activeSearchGroupId === group.id, searchQuery: searchQuery, searchResults: searchResults, isSearching: isSearching, searchError: searchError, onSearchQueryChange: onSearchQueryChange, onShowSearch: () => onShowSearch(group.id), onHideSearch: onHideSearch, canSearch: canSearch }, group.id))))] }) }));
15
15
  };
@@ -8,5 +8,5 @@ export const MemberList = ({ groupId, members, onRemoveMember, onAddMember, onGe
8
8
  onAddMember(groupId, userId);
9
9
  onHideSearch();
10
10
  };
11
- return (_jsxs("div", { children: [_jsx(Text, { size: "xs", fw: 500, mb: 4, children: "Members" }), _jsx(Group, { gap: "xs", mb: "xs", children: members.length > 0 ? (members.map((userId) => onGetUserMetadata ? (_jsx(UserBadge, { userId: userId, getUserMetadata: onGetUserMetadata, variant: "avatar-name", size: "xs", badgeVariant: "filled", color: "blue", onRemove: () => onRemoveMember(groupId, userId), showEmailTooltip: true }, userId)) : (_jsx(Badge, { variant: "filled", color: "blue", pr: 3, rightSection: _jsx(ActionIcon, { size: "xs", color: "blue", radius: "xl", variant: "transparent", onClick: () => onRemoveMember(groupId, userId), children: _jsx(IconX, { size: 10, style: { color: 'white' } }) }), children: userId }, userId)))) : (_jsx(Text, { size: "xs", c: "dimmed", children: "No members" })) }), showUserSearch ? (_jsx(Paper, { withBorder: true, p: "sm", mt: "xs", children: _jsxs(Stack, { gap: "xs", children: [_jsx(TextInput, { placeholder: "Search users by name or email...", value: searchQuery, onChange: (e) => onSearchQueryChange(e.target.value), "aria-label": "Search users by name or email", size: "xs" }), isSearching && _jsx(Loader, { size: "xs" }), searchError && (_jsx(Text, { size: "xs", c: "red", children: searchError })), searchResults.length > 0 && (_jsx(Stack, { gap: 4, children: searchResults.map((user) => (_jsx(Paper, { p: "xs", withBorder: true, style: { cursor: 'pointer' }, onClick: () => handleAddMember(user.id), children: onGetUserMetadata ? (_jsx(UserBadge, { userId: user.id, getUserMetadata: onGetUserMetadata, variant: "full", size: "sm", cachedUser: user, showEmailTooltip: false })) : (_jsxs(_Fragment, { children: [_jsx(Text, { size: "sm", fw: 500, children: user.name }), _jsx(Text, { size: "xs", c: "dimmed", children: user.email })] })) }, user.id))) })), searchQuery.trim() && !isSearching && searchResults.length === 0 && (_jsx(Text, { size: "xs", c: "dimmed", children: "No users found" })), _jsx(Button, { size: "xs", variant: "subtle", onClick: onHideSearch, children: "Cancel" })] }) })) : (_jsx(Button, { size: "xs", variant: "subtle", leftSection: _jsx(IconSearch, { size: 14 }), onClick: onShowSearch, disabled: !canSearch, children: "Add Member" }))] }));
11
+ return (_jsxs("div", { children: [_jsx(Text, { size: "xs", fw: 500, mb: 4, children: "Members" }), _jsx(Group, { gap: "xs", mb: "xs", children: members.length > 0 ? (members.map((userId) => onGetUserMetadata ? (_jsx(UserBadge, { userId: userId, getUserMetadata: onGetUserMetadata, variant: "avatar-name", size: "xs", badgeVariant: "filled", color: "blue", onRemove: () => onRemoveMember(groupId, userId), showEmailTooltip: true }, userId)) : (_jsx(Badge, { variant: "filled", color: "blue", pr: 3, rightSection: _jsx(ActionIcon, { size: "xs", color: "blue", radius: "xl", variant: "transparent", onClick: () => onRemoveMember(groupId, userId), children: _jsx(IconX, { size: 10, style: { color: 'var(--mantine-color-white)' } }) }), children: userId }, userId)))) : (_jsx(Text, { size: "xs", c: "dimmed", children: "No members" })) }), showUserSearch ? (_jsx(Paper, { withBorder: true, p: "sm", mt: "xs", children: _jsxs(Stack, { gap: "xs", children: [_jsx(TextInput, { placeholder: "Search users by name or email...", value: searchQuery, onChange: (e) => onSearchQueryChange(e.target.value), "aria-label": "Search users by name or email", size: "xs" }), isSearching && _jsx(Loader, { size: "xs" }), searchError && (_jsx(Text, { size: "xs", c: "red", children: searchError })), searchResults.length > 0 && (_jsx(Stack, { gap: 4, children: searchResults.map((user) => (_jsx(Paper, { p: "xs", withBorder: true, style: { cursor: 'pointer' }, onClick: () => handleAddMember(user.id), children: onGetUserMetadata ? (_jsx(UserBadge, { userId: user.id, getUserMetadata: onGetUserMetadata, variant: "full", size: "sm", cachedUser: user, showEmailTooltip: false })) : (_jsxs(_Fragment, { children: [_jsx(Text, { size: "sm", fw: 500, children: user.name }), _jsx(Text, { size: "xs", c: "dimmed", children: user.email })] })) }, user.id))) })), searchQuery.trim() && !isSearching && searchResults.length === 0 && (_jsx(Text, { size: "xs", c: "dimmed", children: "No users found" })), _jsx(Button, { variant: "subtle", onClick: onHideSearch, children: "Cancel" })] }) })) : (_jsx(Button, { variant: "subtle", leftSection: _jsx(IconSearch, { size: 14 }), onClick: onShowSearch, disabled: !canSearch, children: "Add Member" }))] }));
12
12
  };
@@ -1,4 +1,5 @@
1
1
  import type { InternalGroup, CanopyGroupId, CanopyUserId } from '../types.js';
2
+ export declare const isTempGroupId: (id: CanopyGroupId) => boolean;
2
3
  export interface UseGroupStateOptions {
3
4
  initialGroups: InternalGroup[];
4
5
  onSave?: (groups: InternalGroup[]) => Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { useState, useEffect, useCallback, useMemo } from 'react';
2
2
  const TEMP_GROUP_ID_PREFIX = 'temp-';
3
- const isTempGroupId = (id) => id.startsWith(TEMP_GROUP_ID_PREFIX);
3
+ export const isTempGroupId = (id) => id.startsWith(TEMP_GROUP_ID_PREFIX);
4
4
  const sameMembers = (a = [], b = []) => a.length === b.length && [...a].sort().join('\n') === [...b].sort().join('\n');
5
5
  const sameGroup = (a, b) => a.name === b.name &&
6
6
  (a.description ?? '') === (b.description ?? '') &&