@byline/richtext-lexical 2.5.2 → 2.6.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.
@@ -8,7 +8,9 @@ const EditorComponent = /*#__PURE__*/ lazy(()=>import("./editor-component.js").t
8
8
  function EditorField(props) {
9
9
  return /*#__PURE__*/ jsx(Suspense, {
10
10
  fallback: /*#__PURE__*/ jsx(Shimmer, {
11
- height: "35vh"
11
+ variant: "text",
12
+ lines: 20,
13
+ lineHeight: "1.15rem"
12
14
  }),
13
15
  children: /*#__PURE__*/ jsx(EditorComponent, {
14
16
  ...props
@@ -1,25 +1,51 @@
1
- .inline-image-plugin--modal-image {
2
- margin-bottom: 2rem;
1
+ .inline-image-modal-picker {
2
+ align-items: center;
3
+ gap: .75rem;
4
+ display: flex;
5
+ }
6
+
7
+ .inline-image-modal-thumb, .inline-image-modal-thumb-placeholder {
8
+ border: 1px solid var(--border-color);
9
+ border-radius: .25rem;
10
+ flex-shrink: 0;
11
+ width: 8rem;
12
+ height: 8rem;
3
13
  }
4
14
 
5
- .inline-image-plugin--modal-media-display {
6
- margin-bottom: 2em;
15
+ .inline-image-modal-thumb {
16
+ object-fit: cover;
7
17
  }
8
18
 
9
- .inline-image-plugin--modal-alt-text {
10
- margin-bottom: 1em;
19
+ .inline-image-modal-thumb-placeholder {
20
+ background-color: var(--surface-subtle);
21
+ color: var(--text-subtle);
22
+ justify-content: center;
23
+ align-items: center;
24
+ font-size: .75rem;
25
+ display: flex;
11
26
  }
12
27
 
13
- .inline-image-plugin--modal-position {
14
- margin-bottom: 2em;
28
+ .inline-image-modal-picker-details {
29
+ flex-direction: column;
30
+ flex: 1;
31
+ align-items: flex-start;
32
+ gap: .5rem;
33
+ min-width: 0;
34
+ display: flex;
15
35
  }
16
36
 
17
- .inline-image-plugin--modal-show-caption {
18
- margin-bottom: 1em;
37
+ .inline-image-modal-change-btn {
38
+ flex-shrink: 0;
39
+ min-width: 70px;
19
40
  }
20
41
 
21
- .inline-image-plugin--modal-actions {
22
- gap: 12px;
23
- display: flex;
42
+ .inline-image-modal-title {
43
+ white-space: nowrap;
44
+ text-overflow: ellipsis;
45
+ min-width: 0;
46
+ color: var(--text-subtle);
47
+ align-self: stretch;
48
+ font-size: .875rem;
49
+ overflow: hidden;
24
50
  }
25
51
 
@@ -7,4 +7,5 @@
7
7
  */
8
8
  import type * as React from 'react';
9
9
  import type { InlineImageModalProps } from './types';
10
+ import './inline-image-modal.css';
10
11
  export declare const InlineImageModal: React.FC<InlineImageModalProps>;
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useMemo, useState } from "react";
4
+ import { RelationPicker } from "@byline/admin/react";
4
5
  import { getCollectionDefinition } from "@byline/core";
5
- import { Button, Checkbox, CloseIcon, ErrorText, IconButton, Input, Label, Modal, RadioGroup, RadioGroupItem, RelationPicker } from "@byline/ui/react";
6
+ import { Button, Checkbox, CloseIcon, ErrorText, IconButton, Input, Label, Modal, RadioGroup, RadioGroupItem } from "@byline/ui/react";
6
7
  import { useModalFormState } from "../../shared/useModalFormState.js";
7
8
  import { isAltTextValid, positionOptions } from "./fields.js";
8
9
  import { deriveImageSizes, getPreferredSize } from "./utils.js";
10
+ import "./inline-image-modal.css";
9
11
  function emptyState() {
10
12
  return {
11
13
  documentRelation: null,
@@ -23,6 +25,22 @@ function fromInlineImageData(data) {
23
25
  showCaption: data.showCaption ?? false
24
26
  };
25
27
  }
28
+ const LABEL_FIELD_KEYS = [
29
+ 'title',
30
+ 'name',
31
+ 'subject',
32
+ 'label'
33
+ ];
34
+ function deriveLabel(fields) {
35
+ for (const key of LABEL_FIELD_KEYS){
36
+ const value = fields[key];
37
+ if ('string' == typeof value && value.trim().length > 0) return value;
38
+ }
39
+ }
40
+ const PICKER_EXTRA_FIELDS = [
41
+ 'altText',
42
+ ...LABEL_FIELD_KEYS
43
+ ];
26
44
  const InlineImageModal = ({ isOpen, collection, data: dataFromProps, onSubmit, onClose })=>{
27
45
  const [pickerOpen, setPickerOpen] = useState(false);
28
46
  const [altError, setAltError] = useState(null);
@@ -57,7 +75,8 @@ const InlineImageModal = ({ isOpen, collection, data: dataFromProps, onSubmit, o
57
75
  const fields = selection.record?.fields ?? {};
58
76
  const image = fields.image;
59
77
  const title = 'string' == typeof fields.title ? fields.title : void 0;
60
- const altTextFromMedia = 'string' == typeof fields.altText ? fields.altText : void 0;
78
+ const altTextFromMedia = 'string' == typeof fields.altText && fields.altText.trim().length > 0 ? fields.altText : void 0;
79
+ const derivedLabel = deriveLabel(fields);
61
80
  const sizes = image ? deriveImageSizes(image) : [];
62
81
  setState((s)=>{
63
82
  const document = {};
@@ -73,7 +92,7 @@ const InlineImageModal = ({ isOpen, collection, data: dataFromProps, onSubmit, o
73
92
  targetCollectionPath: collection,
74
93
  document: Object.keys(document).length > 0 ? document : void 0
75
94
  },
76
- altText: s.altText.length > 0 ? s.altText : altTextFromMedia ?? ''
95
+ altText: s.altText.length > 0 ? s.altText : altTextFromMedia ?? derivedLabel ?? ''
77
96
  };
78
97
  });
79
98
  setImageError(null);
@@ -138,28 +157,33 @@ const InlineImageModal = ({ isOpen, collection, data: dataFromProps, onSubmit, o
138
157
  children: "Image"
139
158
  }),
140
159
  /*#__PURE__*/ jsxs("div", {
141
- className: "flex items-center gap-3",
160
+ className: "inline-image-modal-picker",
142
161
  children: [
143
162
  pickedThumbUrl ? /*#__PURE__*/ jsx("img", {
144
163
  src: pickedThumbUrl,
145
164
  alt: pickedTitle ?? '',
146
- className: "w-18 h-18 object-cover rounded border border-gray-700"
165
+ className: "inline-image-modal-thumb"
147
166
  }) : /*#__PURE__*/ jsx("div", {
148
- className: "w-18 h-18 flex items-center justify-center bg-gray-800 rounded border border-gray-700 text-xs text-gray-500",
167
+ className: "inline-image-modal-thumb-placeholder",
149
168
  children: "—"
150
169
  }),
151
- /*#__PURE__*/ jsx(Button, {
152
- size: "sm",
153
- className: "min-w-[70px]",
154
- variant: "outlined",
155
- intent: "noeffect",
156
- type: "button",
157
- onClick: ()=>setPickerOpen(true),
158
- children: state.documentRelation ? 'Change image…' : `Pick ${targetDef?.labels.singular ?? 'image'}…`
159
- }),
160
- pickedTitle && /*#__PURE__*/ jsx("span", {
161
- className: "text-sm text-gray-200 truncate",
162
- children: pickedTitle
170
+ /*#__PURE__*/ jsxs("div", {
171
+ className: "inline-image-modal-picker-details",
172
+ children: [
173
+ pickedTitle && /*#__PURE__*/ jsx("span", {
174
+ className: "inline-image-modal-title",
175
+ children: pickedTitle
176
+ }),
177
+ /*#__PURE__*/ jsx(Button, {
178
+ size: "sm",
179
+ className: "inline-image-modal-change-btn",
180
+ variant: "outlined",
181
+ intent: "noeffect",
182
+ type: "button",
183
+ onClick: ()=>setPickerOpen(true),
184
+ children: state.documentRelation ? 'Change image…' : `Pick ${targetDef?.labels.singular ?? 'image'}…`
185
+ })
186
+ ]
163
187
  })
164
188
  ]
165
189
  }),
@@ -253,6 +277,7 @@ const InlineImageModal = ({ isOpen, collection, data: dataFromProps, onSubmit, o
253
277
  /*#__PURE__*/ jsx(RelationPicker, {
254
278
  targetCollectionPath: collection,
255
279
  targetDefinition: targetDef,
280
+ extraSelectFields: PICKER_EXTRA_FIELDS,
256
281
  isOpen: pickerOpen,
257
282
  onSelect: handlePickerSelect,
258
283
  onDismiss: ()=>setPickerOpen(false)
@@ -1,8 +1,9 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useMemo, useState } from "react";
4
+ import { RelationPicker } from "@byline/admin/react";
4
5
  import { getClientConfig, getCollectionDefinition } from "@byline/core";
5
- import { Button, Checkbox, CloseIcon, IconButton, Input, Label, Modal, RadioGroup, RadioGroupItem, RelationPicker, Select } from "@byline/ui/react";
6
+ import { Button, Checkbox, CloseIcon, IconButton, Input, Label, Modal, RadioGroup, RadioGroupItem, Select } from "@byline/ui/react";
6
7
  import { useModalFormState } from "../../shared/useModalFormState.js";
7
8
  import { validateUrl } from "../../utils/url.js";
8
9
  function emptyState(linkable) {
@@ -52,7 +52,9 @@ function EditorPlaceholder() {
52
52
  children: /*#__PURE__*/ jsx("div", {
53
53
  className: "byline-field-richtext-body",
54
54
  children: /*#__PURE__*/ jsx(Shimmer, {
55
- height: "35vh"
55
+ variant: "text",
56
+ lines: 20,
57
+ lineHeight: "1.15rem"
56
58
  })
57
59
  })
58
60
  });
@@ -1,5 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { ErrorText, Label, LocaleBadge, useFieldError, useFieldValue } from "@byline/ui/react";
2
+ import { LocaleBadge, useFieldError, useFieldValue } from "@byline/admin/react";
3
+ import { ErrorText, Label } from "@byline/ui/react";
3
4
  import classnames from "classnames";
4
5
  import { defaultEditorConfig } from "./field/config/default.js";
5
6
  import { defaultExtensionsList } from "./field/config/default-extensions.js";
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "type": "module",
5
5
  "license": "MPL-2.0",
6
- "version": "2.5.2",
6
+ "version": "2.6.1",
7
7
  "engines": {
8
8
  "node": ">=20.9.0"
9
9
  },
@@ -72,9 +72,10 @@
72
72
  "npm-run-all": "^4.1.5",
73
73
  "prism-react-renderer": "^2.4.1",
74
74
  "react-error-boundary": "^6.1.1",
75
- "@byline/client": "2.5.2",
76
- "@byline/core": "2.5.2",
77
- "@byline/ui": "2.5.2"
75
+ "@byline/admin": "2.6.1",
76
+ "@byline/core": "2.6.1",
77
+ "@byline/client": "2.6.1",
78
+ "@byline/ui": "2.6.1"
78
79
  },
79
80
  "peerDependencies": {
80
81
  "react": "^19.0.0",
@@ -115,6 +116,7 @@
115
116
  "typecheck": "tsc --noEmit",
116
117
  "clean": "node scripts/clean.js node_modules dist build types .turbo",
117
118
  "lint": "biome check --write --unsafe --diagnostic-level=error",
118
- "skip:test": "vitest"
119
+ "test": "vitest run --mode=node",
120
+ "test:watch": "vitest --mode=node"
119
121
  }
120
122
  }
@@ -44,7 +44,7 @@ const EditorComponent = lazy(() =>
44
44
 
45
45
  export function EditorField(props: EditorFieldProps): React.JSX.Element {
46
46
  return (
47
- <Suspense fallback={<Shimmer height="35vh" />}>
47
+ <Suspense fallback={<Shimmer variant="text" lines={20} lineHeight="1.15rem" />}>
48
48
  <EditorComponent {...props} />
49
49
  </Suspense>
50
50
  )
@@ -1,29 +1,59 @@
1
- .inline-image-plugin--modal-image {
2
- margin-bottom: 2rem;
3
- }
1
+ /**
2
+ * Inline image modal — image picker row.
3
+ *
4
+ * Only the picker row (thumbnail + change button + title) needs bespoke
5
+ * layout; the rest of the modal is composed from shared @byline/ui
6
+ * components. Colours use the design tokens so the row is theme-aware.
7
+ */
4
8
 
5
- .inline-image-plugin--modal-actions {
9
+ .inline-image-modal-picker {
6
10
  display: flex;
7
- gap: 12px;
11
+ align-items: center;
12
+ gap: 0.75rem;
13
+ }
14
+
15
+ .inline-image-modal-thumb,
16
+ .inline-image-modal-thumb-placeholder {
17
+ flex-shrink: 0;
18
+ width: 8rem;
19
+ height: 8rem;
20
+ border-radius: 0.25rem;
21
+ border: 1px solid var(--border-color);
8
22
  }
9
23
 
10
- .inline-image-plugin--modal-media-display {
11
- margin-bottom: 2em;
24
+ .inline-image-modal-thumb {
25
+ object-fit: cover;
12
26
  }
13
27
 
14
- .inline-image-plugin--modal-alt-text {
15
- margin-bottom: 1em;
28
+ .inline-image-modal-thumb-placeholder {
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: center;
32
+ background-color: var(--surface-subtle);
33
+ color: var(--text-subtle);
34
+ font-size: 0.75rem;
16
35
  }
17
36
 
18
- .inline-image-plugin--modal-position {
19
- margin-bottom: 2em;
37
+ .inline-image-modal-picker-details {
38
+ display: flex;
39
+ flex: 1;
40
+ min-width: 0;
41
+ flex-direction: column;
42
+ align-items: flex-start;
43
+ gap: 0.5rem;
20
44
  }
21
45
 
22
- .inline-image-plugin--modal-show-caption {
23
- margin-bottom: 1em;
46
+ .inline-image-modal-change-btn {
47
+ flex-shrink: 0;
48
+ min-width: 70px;
24
49
  }
25
50
 
26
- .inline-image-plugin--modal-actions {
27
- display: flex;
28
- gap: 12px;
51
+ .inline-image-modal-title {
52
+ align-self: stretch;
53
+ min-width: 0;
54
+ overflow: hidden;
55
+ white-space: nowrap;
56
+ text-overflow: ellipsis;
57
+ font-size: 0.875rem;
58
+ color: var(--text-subtle);
29
59
  }
@@ -11,6 +11,7 @@
11
11
  import type * as React from 'react'
12
12
  import { useMemo, useState } from 'react'
13
13
 
14
+ import { RelationPicker } from '@byline/admin/react'
14
15
  import type { CollectionDefinition, StoredFileValue } from '@byline/core'
15
16
  import { getCollectionDefinition } from '@byline/core'
16
17
  import {
@@ -24,7 +25,6 @@ import {
24
25
  Modal,
25
26
  RadioGroup,
26
27
  RadioGroupItem,
27
- RelationPicker,
28
28
  } from '@byline/ui/react'
29
29
 
30
30
  import { useModalFormState } from '../../shared/useModalFormState'
@@ -34,6 +34,8 @@ import type { DocumentRelation } from '../../nodes/document-relation'
34
34
  import type { Position } from './node-types'
35
35
  import type { InlineImageData, InlineImageModalProps } from './types'
36
36
 
37
+ import './inline-image-modal.css'
38
+
37
39
  interface FormState {
38
40
  documentRelation: DocumentRelation | null
39
41
  altText: string
@@ -60,6 +62,30 @@ function fromInlineImageData(data: InlineImageData | undefined): FormState {
60
62
  }
61
63
  }
62
64
 
65
+ /**
66
+ * Human-readable label fields a media/document collection might use, in
67
+ * priority order. Used only to *seed* the alt-text field when the picked
68
+ * record has no explicit `altText`. Intentionally excludes filenames — a
69
+ * label like `IMG_2024.jpg` makes poor alt text. The user can always edit.
70
+ */
71
+ const LABEL_FIELD_KEYS = ['title', 'name', 'subject', 'label'] as const
72
+
73
+ function deriveLabel(fields: Record<string, any>): string | undefined {
74
+ for (const key of LABEL_FIELD_KEYS) {
75
+ const value = fields[key]
76
+ if (typeof value === 'string' && value.trim().length > 0) return value
77
+ }
78
+ return undefined
79
+ }
80
+
81
+ /**
82
+ * Extra fields the relation picker must load (beyond its display columns)
83
+ * so `handlePickerSelect` can seed the alt-text field: the media's own
84
+ * `altText`, then the human-readable label fallbacks. Module-level so the
85
+ * reference is stable across renders (it feeds the picker's fetch effect).
86
+ */
87
+ const PICKER_EXTRA_FIELDS: string[] = ['altText', ...LABEL_FIELD_KEYS]
88
+
63
89
  export const InlineImageModal: React.FC<InlineImageModalProps> = ({
64
90
  isOpen,
65
91
  collection,
@@ -110,7 +136,13 @@ export const InlineImageModal: React.FC<InlineImageModalProps> = ({
110
136
  const fields = selection.record?.fields ?? {}
111
137
  const image = fields.image as StoredFileValue | undefined
112
138
  const title = typeof fields.title === 'string' ? fields.title : undefined
113
- const altTextFromMedia = typeof fields.altText === 'string' ? fields.altText : undefined
139
+ // Treat a present-but-blank `altText` as absent so the title fallback
140
+ // below still applies.
141
+ const altTextFromMedia =
142
+ typeof fields.altText === 'string' && fields.altText.trim().length > 0
143
+ ? fields.altText
144
+ : undefined
145
+ const derivedLabel = deriveLabel(fields)
114
146
  const sizes = image ? deriveImageSizes(image) : []
115
147
 
116
148
  setState((s) => {
@@ -128,10 +160,11 @@ export const InlineImageModal: React.FC<InlineImageModalProps> = ({
128
160
  targetCollectionPath: collection,
129
161
  document: Object.keys(document).length > 0 ? document : undefined,
130
162
  },
131
- // Pre-fill alt-text from the media's `altText` field on first pick if
132
- // the form's alt-text is still empty. Editorial wins over the source
133
- // record once the user starts typing.
134
- altText: s.altText.length > 0 ? s.altText : (altTextFromMedia ?? ''),
163
+ // Pre-fill alt-text on first pick when the form's alt-text is still
164
+ // empty: prefer the media's own `altText`, then fall back to a
165
+ // human-readable label (title / name / subject / label). Editorial
166
+ // wins over the source record once the user starts typing.
167
+ altText: s.altText.length > 0 ? s.altText : (altTextFromMedia ?? derivedLabel ?? ''),
135
168
  }
136
169
  })
137
170
  setImageError(null)
@@ -182,33 +215,31 @@ export const InlineImageModal: React.FC<InlineImageModalProps> = ({
182
215
  <div className="flex flex-col gap-4">
183
216
  <div className="flex flex-col gap-2">
184
217
  <span className="text-sm font-medium">Image</span>
185
- <div className="flex items-center gap-3">
218
+ <div className="inline-image-modal-picker">
186
219
  {pickedThumbUrl ? (
187
220
  <img
188
221
  src={pickedThumbUrl}
189
222
  alt={pickedTitle ?? ''}
190
- className="w-18 h-18 object-cover rounded border border-gray-700"
223
+ className="inline-image-modal-thumb"
191
224
  />
192
225
  ) : (
193
- <div className="w-18 h-18 flex items-center justify-center bg-gray-800 rounded border border-gray-700 text-xs text-gray-500">
194
-
195
- </div>
196
- )}
197
- <Button
198
- size="sm"
199
- className="min-w-[70px]"
200
- variant="outlined"
201
- intent="noeffect"
202
- type="button"
203
- onClick={() => setPickerOpen(true)}
204
- >
205
- {state.documentRelation
206
- ? 'Change image…'
207
- : `Pick ${targetDef?.labels.singular ?? 'image'}…`}
208
- </Button>
209
- {pickedTitle && (
210
- <span className="text-sm text-gray-200 truncate">{pickedTitle}</span>
226
+ <div className="inline-image-modal-thumb-placeholder">—</div>
211
227
  )}
228
+ <div className="inline-image-modal-picker-details">
229
+ {pickedTitle && <span className="inline-image-modal-title">{pickedTitle}</span>}
230
+ <Button
231
+ size="sm"
232
+ className="inline-image-modal-change-btn"
233
+ variant="outlined"
234
+ intent="noeffect"
235
+ type="button"
236
+ onClick={() => setPickerOpen(true)}
237
+ >
238
+ {state.documentRelation
239
+ ? 'Change image…'
240
+ : `Pick ${targetDef?.labels.singular ?? 'image'}…`}
241
+ </Button>
242
+ </div>
212
243
  </div>
213
244
  {imageError && <ErrorText id="image-error" text={imageError} />}
214
245
  </div>
@@ -293,6 +324,7 @@ export const InlineImageModal: React.FC<InlineImageModalProps> = ({
293
324
  <RelationPicker
294
325
  targetCollectionPath={collection}
295
326
  targetDefinition={targetDef}
327
+ extraSelectFields={PICKER_EXTRA_FIELDS}
296
328
  isOpen={pickerOpen}
297
329
  onSelect={handlePickerSelect}
298
330
  onDismiss={() => setPickerOpen(false)}
@@ -11,6 +11,7 @@
11
11
  import type * as React from 'react'
12
12
  import { useMemo, useState } from 'react'
13
13
 
14
+ import { RelationPicker } from '@byline/admin/react'
14
15
  import type { CollectionDefinition } from '@byline/core'
15
16
  import { getClientConfig, getCollectionDefinition } from '@byline/core'
16
17
  import {
@@ -23,7 +24,6 @@ import {
23
24
  Modal,
24
25
  RadioGroup,
25
26
  RadioGroupItem,
26
- RelationPicker,
27
27
  Select,
28
28
  type SelectValue,
29
29
  } from '@byline/ui/react'
@@ -0,0 +1,351 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+
9
+ /**
10
+ * Fixture-driven tests for the link visitor's three resolution branches:
11
+ *
12
+ * - Found — target resolved, `buildDocumentPath` returned a string
13
+ * - Found (fallback) — target resolved, generic `/${collectionPath}/${path}` compose
14
+ * - Branch A (threw) — `buildDocumentPath` raised
15
+ * - Branch B (missing) — target deleted between picker and walker
16
+ *
17
+ * The visitor itself is framework-agnostic and exercised directly: build
18
+ * a `LexicalNodeLike`, call `linkVisitor.match(node)`, then invoke the
19
+ * returned `apply` / `applyMissing` and assert on the mutated `node`.
20
+ *
21
+ * Branch C (hard transport failures) is owned by the framework caller
22
+ * (`embedRichTextFields`) and tested in `packages/core` against that
23
+ * service — see `richtext-embed.test.node.ts`.
24
+ */
25
+
26
+ import { type BylineLogger, type CollectionDefinition, defineServerConfig } from '@byline/core'
27
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
28
+
29
+ import { linkVisitor } from './populate'
30
+ import type { LexicalNodeLike } from '../../lexical-populate-shared'
31
+
32
+ // ---------------------------------------------------------------------------
33
+ // Test harness — logger + config registration
34
+ // ---------------------------------------------------------------------------
35
+
36
+ function makeLogger(): BylineLogger {
37
+ return {
38
+ log: vi.fn(),
39
+ fatal: vi.fn(),
40
+ error: vi.fn(),
41
+ warn: vi.fn(),
42
+ info: vi.fn(),
43
+ debug: vi.fn(),
44
+ trace: vi.fn(),
45
+ silent: vi.fn(),
46
+ }
47
+ }
48
+
49
+ function registerCollection(definition: Partial<CollectionDefinition> & { path: string }): void {
50
+ defineServerConfig({
51
+ collections: [
52
+ {
53
+ labels: { singular: 'Page', plural: 'Pages' },
54
+ fields: [{ name: 'title', type: 'text', label: 'Title' }],
55
+ useAsTitle: 'title',
56
+ ...definition,
57
+ } as CollectionDefinition,
58
+ ],
59
+ } as Parameters<typeof defineServerConfig>[0])
60
+ }
61
+
62
+ function clearConfig(): void {
63
+ // Mirror the config module's globalThis-symbol storage so tests can
64
+ // register a fresh collection set per case without bleed-over.
65
+ ;(globalThis as any)[Symbol.for('__byline_server_config__')] = null
66
+ ;(globalThis as any)[Symbol.for('__byline_client_config__')] = null
67
+ }
68
+
69
+ function installLogger(logger: BylineLogger): void {
70
+ // `defineLogger` is not re-exported from `@byline/core`'s root barrel —
71
+ // setting the symbol directly mirrors what `initBylineCore()` does at
72
+ // boot and avoids growing the public surface for test wiring.
73
+ ;(globalThis as any)[Symbol.for('__byline_logger__')] = logger
74
+ }
75
+
76
+ // ---------------------------------------------------------------------------
77
+ // Node fixtures
78
+ // ---------------------------------------------------------------------------
79
+
80
+ function makeInternalLinkNode(opts: {
81
+ documentId?: string
82
+ collectionPath?: string
83
+ document?: Record<string, any>
84
+ }): LexicalNodeLike {
85
+ return {
86
+ type: 'link',
87
+ attributes: {
88
+ linkType: 'internal',
89
+ targetDocumentId: opts.documentId ?? 'doc-1',
90
+ targetCollectionPath: opts.collectionPath ?? 'pages',
91
+ document: opts.document,
92
+ },
93
+ }
94
+ }
95
+
96
+ const targetFixture = {
97
+ id: 'doc-1',
98
+ path: 'about',
99
+ status: 'published',
100
+ fields: { title: 'About Us', area: 'root' },
101
+ }
102
+
103
+ // ---------------------------------------------------------------------------
104
+ // Suite
105
+ // ---------------------------------------------------------------------------
106
+
107
+ describe('linkVisitor', () => {
108
+ let logger: BylineLogger
109
+
110
+ beforeEach(() => {
111
+ logger = makeLogger()
112
+ installLogger(logger)
113
+ clearConfig()
114
+ })
115
+
116
+ afterEach(() => {
117
+ clearConfig()
118
+ })
119
+
120
+ // -------------------------------------------------------------------------
121
+ // match() — skip-conditions
122
+ // -------------------------------------------------------------------------
123
+
124
+ describe('match', () => {
125
+ it('returns null for non-link nodes', () => {
126
+ const node: LexicalNodeLike = { type: 'paragraph' }
127
+ expect(linkVisitor.match(node)).toBeNull()
128
+ })
129
+
130
+ it('returns null for custom-URL links', () => {
131
+ const node: LexicalNodeLike = {
132
+ type: 'link',
133
+ attributes: { linkType: 'custom', url: 'https://example.com' },
134
+ }
135
+ expect(linkVisitor.match(node)).toBeNull()
136
+ })
137
+
138
+ it('returns null when targetDocumentId is missing', () => {
139
+ const node: LexicalNodeLike = {
140
+ type: 'link',
141
+ attributes: { linkType: 'internal', targetCollectionPath: 'pages' },
142
+ }
143
+ expect(linkVisitor.match(node)).toBeNull()
144
+ })
145
+
146
+ it('returns null when targetCollectionPath is missing', () => {
147
+ const node: LexicalNodeLike = {
148
+ type: 'link',
149
+ attributes: { linkType: 'internal', targetDocumentId: 'doc-1' },
150
+ }
151
+ expect(linkVisitor.match(node)).toBeNull()
152
+ })
153
+
154
+ it('returns a PendingHydration for a well-formed internal link', () => {
155
+ registerCollection({ path: 'pages' })
156
+ const node = makeInternalLinkNode({})
157
+ const pending = linkVisitor.match(node)
158
+ expect(pending).not.toBeNull()
159
+ expect(pending?.collectionPath).toBe('pages')
160
+ expect(pending?.documentId).toBe('doc-1')
161
+ })
162
+ })
163
+
164
+ // -------------------------------------------------------------------------
165
+ // apply() — Found branches
166
+ // -------------------------------------------------------------------------
167
+
168
+ describe('apply (found)', () => {
169
+ it('uses buildDocumentPath when defined and returning a string', () => {
170
+ registerCollection({
171
+ path: 'pages',
172
+ useAsTitle: 'title',
173
+ buildDocumentPath: (doc) => `/custom/${doc.path}`,
174
+ })
175
+ const node = makeInternalLinkNode({})
176
+ const pending = linkVisitor.match(node)
177
+ pending?.apply(targetFixture)
178
+
179
+ expect(node.attributes?.document).toEqual({
180
+ title: 'About Us',
181
+ path: '/custom/about',
182
+ })
183
+ })
184
+
185
+ it('falls back to generic compose when buildDocumentPath returns null', () => {
186
+ registerCollection({
187
+ path: 'pages',
188
+ useAsTitle: 'title',
189
+ buildDocumentPath: () => null,
190
+ })
191
+ const node = makeInternalLinkNode({})
192
+ const pending = linkVisitor.match(node)
193
+ pending?.apply(targetFixture)
194
+
195
+ expect(node.attributes?.document?.path).toBe('/pages/about')
196
+ })
197
+
198
+ it('falls back to generic compose when buildDocumentPath is not defined', () => {
199
+ registerCollection({ path: 'pages', useAsTitle: 'title' })
200
+ const node = makeInternalLinkNode({})
201
+ const pending = linkVisitor.match(node)
202
+ pending?.apply(targetFixture)
203
+
204
+ expect(node.attributes?.document?.path).toBe('/pages/about')
205
+ })
206
+
207
+ it('refreshes title from useAsTitle (defaults to "title" when not set)', () => {
208
+ registerCollection({ path: 'pages' })
209
+ const node = makeInternalLinkNode({
210
+ document: { title: 'Stale Title', path: '/stale' },
211
+ })
212
+ const pending = linkVisitor.match(node)
213
+ pending?.apply(targetFixture)
214
+
215
+ expect(node.attributes?.document?.title).toBe('About Us')
216
+ })
217
+
218
+ it('honours a custom useAsTitle field', () => {
219
+ registerCollection({
220
+ path: 'pages',
221
+ useAsTitle: 'headline',
222
+ fields: [
223
+ { name: 'title', type: 'text', label: 'Title' },
224
+ { name: 'headline', type: 'text', label: 'Headline' },
225
+ ],
226
+ })
227
+ const node = makeInternalLinkNode({})
228
+ const pending = linkVisitor.match(node)
229
+ pending?.apply({
230
+ ...targetFixture,
231
+ fields: { title: 'fallback', headline: 'Real Headline' },
232
+ })
233
+
234
+ expect(node.attributes?.document?.title).toBe('Real Headline')
235
+ })
236
+
237
+ it('clears a stale _resolved: false flag when the target is now found', () => {
238
+ registerCollection({ path: 'pages' })
239
+ const node = makeInternalLinkNode({
240
+ document: { _resolved: false },
241
+ })
242
+ const pending = linkVisitor.match(node)
243
+ pending?.apply(targetFixture)
244
+
245
+ expect(node.attributes?.document?._resolved).toBeUndefined()
246
+ expect(node.attributes?.document?.path).toBe('/pages/about')
247
+ })
248
+
249
+ it('leaves path untouched when target.path is empty and no hook is defined', () => {
250
+ // Generic fallback bails when target.path is empty rather than
251
+ // emitting `/pages/undefined`.
252
+ registerCollection({ path: 'pages' })
253
+ const node = makeInternalLinkNode({
254
+ document: { title: 'Old', path: '/previous' },
255
+ })
256
+ const pending = linkVisitor.match(node)
257
+ pending?.apply({ ...targetFixture, path: '' })
258
+
259
+ expect(node.attributes?.document?.path).toBe('/previous')
260
+ })
261
+ })
262
+
263
+ // -------------------------------------------------------------------------
264
+ // apply() — Branch A: buildDocumentPath threw
265
+ // -------------------------------------------------------------------------
266
+
267
+ describe('apply (branch A — hook threw)', () => {
268
+ it('logs at info and leaves document.path untouched', () => {
269
+ registerCollection({
270
+ path: 'pages',
271
+ useAsTitle: 'title',
272
+ buildDocumentPath: () => {
273
+ throw new Error('boom')
274
+ },
275
+ })
276
+ const node = makeInternalLinkNode({
277
+ document: { title: 'Previous', path: '/previous' },
278
+ })
279
+ const pending = linkVisitor.match(node)
280
+ pending?.apply(targetFixture)
281
+
282
+ // Path preserved (branch A's whole point).
283
+ expect(node.attributes?.document?.path).toBe('/previous')
284
+ // Title still refreshes — only the path resolution failed.
285
+ expect(node.attributes?.document?.title).toBe('About Us')
286
+ expect(logger.info).toHaveBeenCalledWith(
287
+ expect.objectContaining({
288
+ collectionPath: 'pages',
289
+ documentId: 'doc-1',
290
+ err: expect.any(Error),
291
+ }),
292
+ 'buildDocumentPath threw'
293
+ )
294
+ })
295
+
296
+ it('does not fall back to generic compose when the hook threw', () => {
297
+ registerCollection({
298
+ path: 'pages',
299
+ buildDocumentPath: () => {
300
+ throw new Error('boom')
301
+ },
302
+ })
303
+ const node = makeInternalLinkNode({ document: {} })
304
+ const pending = linkVisitor.match(node)
305
+ pending?.apply(targetFixture)
306
+
307
+ // No path written — neither hook output nor generic fallback fired.
308
+ expect(node.attributes?.document?.path).toBeUndefined()
309
+ })
310
+ })
311
+
312
+ // -------------------------------------------------------------------------
313
+ // applyMissing() — Branch B: target deleted
314
+ // -------------------------------------------------------------------------
315
+
316
+ describe('applyMissing (branch B — target deleted)', () => {
317
+ it('deletes title and path and sets _resolved: false', () => {
318
+ registerCollection({ path: 'pages' })
319
+ const node = makeInternalLinkNode({
320
+ document: { title: 'Stale', path: '/stale-path' },
321
+ })
322
+ const pending = linkVisitor.match(node)
323
+ pending?.applyMissing?.()
324
+
325
+ expect(node.attributes?.document?.title).toBeUndefined()
326
+ expect(node.attributes?.document?.path).toBeUndefined()
327
+ expect(node.attributes?.document?._resolved).toBe(false)
328
+ })
329
+
330
+ it('logs at warn level', () => {
331
+ registerCollection({ path: 'pages' })
332
+ const node = makeInternalLinkNode({ document: { title: 'Stale' } })
333
+ const pending = linkVisitor.match(node)
334
+ pending?.applyMissing?.()
335
+
336
+ expect(logger.warn).toHaveBeenCalledWith(
337
+ { collectionPath: 'pages', documentId: 'doc-1' },
338
+ 'internal link target not found'
339
+ )
340
+ })
341
+
342
+ it('still produces a usable envelope when no prior document was present', () => {
343
+ registerCollection({ path: 'pages' })
344
+ const node = makeInternalLinkNode({})
345
+ const pending = linkVisitor.match(node)
346
+ pending?.applyMissing?.()
347
+
348
+ expect(node.attributes?.document).toEqual({ _resolved: false })
349
+ })
350
+ })
351
+ })
@@ -142,7 +142,7 @@ function EditorPlaceholder() {
142
142
  return (
143
143
  <div className="byline-field-richtext">
144
144
  <div className="byline-field-richtext-body">
145
- <Shimmer height="35vh" />
145
+ <Shimmer variant="text" lines={20} lineHeight="1.15rem" />
146
146
  </div>
147
147
  </div>
148
148
  )
@@ -8,8 +8,9 @@
8
8
 
9
9
  import type React from 'react'
10
10
 
11
+ import { LocaleBadge, useFieldError, useFieldValue } from '@byline/admin/react'
11
12
  import type { RichTextField as FieldType } from '@byline/core'
12
- import { ErrorText, Label, LocaleBadge, useFieldError, useFieldValue } from '@byline/ui/react'
13
+ import { ErrorText, Label } from '@byline/ui/react'
13
14
  import cx from 'classnames'
14
15
 
15
16
  import { defaultEditorConfig } from './field/config/default'