@backmatter/studio 0.0.19 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{UiKitApp-B1ANqCac.js → UiKitApp-CMMcsaX4.js} +2 -2
- package/dist/chunks/{WorkspaceRoutes-BHNGrf-j.js → WorkspaceRoutes-DW0sLdpJ.js} +27141 -26236
- package/dist/chunks/dashboard-By0P4Yny.js +1879 -0
- package/dist/chunks/{index-HYioDjux.js → index-DTPUqaHE.js} +1 -1
- package/dist/dashboard.js +2 -2
- package/dist/index.js +205 -194
- package/dist/site-widget.css +208 -0
- package/dist/site-widget.js +10495 -9947
- package/dist/studio.css +280 -24
- package/package.json +2 -2
- package/src/App.tsx +7 -1
- package/src/api.ts +113 -13
- package/src/chat/ChatFiles.tsx +261 -0
- package/src/chat/ChatMessage.tsx +5 -0
- package/src/chat/ChatPanel.tsx +218 -14
- package/src/chat/ChatProvider.tsx +72 -22
- package/src/chat/Composer.tsx +83 -6
- package/src/chat/PendingFileRow.tsx +188 -0
- package/src/chat/chat-context.ts +7 -1
- package/src/chat/chat-helpers.ts +49 -0
- package/src/chat/chat-state.ts +17 -6
- package/src/chat/icons.tsx +28 -0
- package/src/chat/model-copy.ts +41 -0
- package/src/chat/pending-files.ts +236 -0
- package/src/chat/side-width.ts +48 -0
- package/src/chrome/AppShell.tsx +9 -1
- package/src/chrome/CommandPalette.tsx +7 -0
- package/src/chrome/ContentExplorerSidebar.tsx +43 -74
- package/src/chrome/folder-create-context.ts +56 -11
- package/src/chrome/hotkeys.ts +8 -0
- package/src/fields/FieldControl.tsx +331 -115
- package/src/fields/LinkFieldInput.tsx +13 -6
- package/src/fields/array-item-title.ts +28 -0
- package/src/fields/field-label.ts +8 -0
- package/src/host-pointer.ts +2 -0
- package/src/install-preview-pointer.ts +1 -0
- package/src/pages/BlockPicker.tsx +362 -0
- package/src/pages/BlocksList.tsx +57 -50
- package/src/pages/CliAuthorizePage.tsx +138 -25
- package/src/pages/DocEditorPage.tsx +95 -18
- package/src/pages/EmbedPublishPage.tsx +40 -2
- package/src/pages/LoginPage.tsx +118 -31
- package/src/pages/SettingsSchemaPage.tsx +19 -3
- package/src/pages/WorkspaceLayout.tsx +16 -1
- package/src/pages/block-picker.ts +116 -0
- package/src/pages/editor-grab.ts +61 -13
- package/src/pages/preview-split.ts +24 -0
- package/src/pages/session-preview.ts +1 -0
- package/src/replica/types.ts +2 -0
- package/src/sign-in-link.ts +45 -0
- package/src/site-pointer.ts +14 -1
- package/src/site-widget.tsx +12 -1
- package/src/ui/Field.tsx +26 -0
- package/src/workspace/schema-source.tsx +126 -0
- package/dist/chunks/dashboard-b-W6dGm5.js +0 -1779
- package/src/site-devbar-overlay-inject.ts +0 -15
- package/src/site-publish-menu.tsx +0 -33
package/src/chrome/hotkeys.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// packages/studio/src/chrome/hotkeys.ts
|
|
2
2
|
export type HotkeyAction = "save" | "palette" | "chat";
|
|
3
3
|
|
|
4
|
+
/** Opens the command palette from a control, the same as its hotkey. */
|
|
5
|
+
export const OPEN_PALETTE_EVENT = "backmatter:open-palette";
|
|
6
|
+
|
|
7
|
+
export function openCommandPalette(): void {
|
|
8
|
+
if (typeof window === "undefined") return;
|
|
9
|
+
window.dispatchEvent(new CustomEvent(OPEN_PALETTE_EVENT));
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
export type HotkeyLike = {
|
|
5
13
|
key: string;
|
|
6
14
|
metaKey: boolean;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// packages/studio/src/fields/FieldControl.tsx
|
|
2
|
-
import { useEffect, useState, type ReactNode } from "react";
|
|
2
|
+
import { useEffect, useRef, useState, type ReactNode } from "react";
|
|
3
3
|
import * as stylex from "@stylexjs/stylex";
|
|
4
4
|
import { documentLabel, matchesWhere } from "@backmatter/core";
|
|
5
5
|
import type { SchemaField } from "../api";
|
|
6
6
|
import { resolveFieldInput, useStudioDefinition } from "../define-studio";
|
|
7
|
-
import { colors, space } from "../styles/tokens.stylex";
|
|
7
|
+
import { colors, radius, space, type } from "../styles/tokens.stylex";
|
|
8
|
+
import { Button } from "../ui/Button";
|
|
9
|
+
import { Field, FieldGroup } from "../ui/Field";
|
|
8
10
|
import { Input, Select, Textarea } from "../ui/Input";
|
|
9
11
|
import { MediaFieldInput } from "../pages/MediaFieldInput";
|
|
12
|
+
import { arrayItemTitle } from "./array-item-title";
|
|
10
13
|
import { chooseFieldInput } from "./choose-field-input";
|
|
14
|
+
import { fieldLabel } from "./field-label";
|
|
11
15
|
import { LinkFieldInput } from "./LinkFieldInput";
|
|
12
16
|
import { nestedStartsCollapsed, resolveObjectFields } from "./resolve-object-fields";
|
|
13
17
|
|
|
@@ -198,14 +202,19 @@ function CollapsibleNest({
|
|
|
198
202
|
}
|
|
199
203
|
return (
|
|
200
204
|
<div {...stylex.props(styles.nest)}>
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
<div {...stylex.props(styles.nestToggle)}>
|
|
206
|
+
<Button
|
|
207
|
+
variant="ghost"
|
|
208
|
+
size="sm"
|
|
209
|
+
muted
|
|
210
|
+
data-nest-toggle={fieldName}
|
|
211
|
+
aria-expanded={expanded}
|
|
212
|
+
onClick={() => setExpanded((open) => !open)}
|
|
213
|
+
>
|
|
214
|
+
<ChevronIcon open={expanded} />
|
|
215
|
+
{expanded ? "Collapse" : "Expand"} {fieldName}
|
|
216
|
+
</Button>
|
|
217
|
+
</div>
|
|
209
218
|
{expanded ? (
|
|
210
219
|
<div data-nest={fieldName} {...stylex.props(styles.nestBody)}>
|
|
211
220
|
{children}
|
|
@@ -246,21 +255,22 @@ function ObjectFieldEditor({
|
|
|
246
255
|
const body = (
|
|
247
256
|
<div {...stylex.props(styles.objectFields)}>
|
|
248
257
|
{Object.entries(resolved).map(([fieldName, nestedField]) => (
|
|
249
|
-
<
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
258
|
+
<NestedField key={fieldName} name={fieldName} field={nestedField}>
|
|
259
|
+
<FieldControl
|
|
260
|
+
name={`${name}.${fieldName}`}
|
|
261
|
+
field={nestedField}
|
|
262
|
+
value={record[fieldName]}
|
|
263
|
+
models={models}
|
|
264
|
+
objects={objects}
|
|
265
|
+
documentLists={documentLists}
|
|
266
|
+
readOnly={readOnly}
|
|
267
|
+
ancestorObjectNames={nextAncestors}
|
|
268
|
+
blocksEditor={blocksEditor}
|
|
269
|
+
onChange={(next) => {
|
|
270
|
+
onChange({ ...record, [fieldName]: next });
|
|
271
|
+
}}
|
|
272
|
+
/>
|
|
273
|
+
</NestedField>
|
|
264
274
|
))}
|
|
265
275
|
</div>
|
|
266
276
|
);
|
|
@@ -285,6 +295,94 @@ function ObjectFieldEditor({
|
|
|
285
295
|
);
|
|
286
296
|
}
|
|
287
297
|
|
|
298
|
+
/** Composite fields hold their own labeled inputs, so they get a group, not a `<label>`. */
|
|
299
|
+
function NestedField({
|
|
300
|
+
name,
|
|
301
|
+
field,
|
|
302
|
+
children,
|
|
303
|
+
}: {
|
|
304
|
+
name: string;
|
|
305
|
+
field: SchemaField;
|
|
306
|
+
children: ReactNode;
|
|
307
|
+
}) {
|
|
308
|
+
const label = fieldLabel(name, field);
|
|
309
|
+
const hint = field.description ? (
|
|
310
|
+
<span {...stylex.props(styles.fieldGuidance)}>{field.description}</span>
|
|
311
|
+
) : undefined;
|
|
312
|
+
if (field.kind === "object" || field.kind === "array" || field.kind === "blocks") {
|
|
313
|
+
return (
|
|
314
|
+
<FieldGroup label={label} hint={hint}>
|
|
315
|
+
{children}
|
|
316
|
+
</FieldGroup>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
return (
|
|
320
|
+
<Field label={label} hint={hint}>
|
|
321
|
+
{children}
|
|
322
|
+
</Field>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
let arrayItemKeySeq = 0;
|
|
327
|
+
function nextArrayItemKey(): string {
|
|
328
|
+
arrayItemKeySeq += 1;
|
|
329
|
+
return `item-${arrayItemKeySeq}`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function ChevronIcon({ open }: { open: boolean }) {
|
|
333
|
+
return (
|
|
334
|
+
<svg
|
|
335
|
+
width="12"
|
|
336
|
+
height="12"
|
|
337
|
+
viewBox="0 0 12 12"
|
|
338
|
+
fill="none"
|
|
339
|
+
stroke="currentColor"
|
|
340
|
+
strokeWidth="1.5"
|
|
341
|
+
strokeLinecap="round"
|
|
342
|
+
strokeLinejoin="round"
|
|
343
|
+
aria-hidden
|
|
344
|
+
{...stylex.props(styles.chevron, open && styles.chevronOpen)}
|
|
345
|
+
>
|
|
346
|
+
<path d="M4.5 2.5 8 6l-3.5 3.5" />
|
|
347
|
+
</svg>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function ArrowIcon({ direction }: { direction: "up" | "down" }) {
|
|
352
|
+
return (
|
|
353
|
+
<svg
|
|
354
|
+
width="12"
|
|
355
|
+
height="12"
|
|
356
|
+
viewBox="0 0 12 12"
|
|
357
|
+
fill="none"
|
|
358
|
+
stroke="currentColor"
|
|
359
|
+
strokeWidth="1.5"
|
|
360
|
+
strokeLinecap="round"
|
|
361
|
+
strokeLinejoin="round"
|
|
362
|
+
aria-hidden
|
|
363
|
+
>
|
|
364
|
+
{direction === "up" ? <path d="M6 9.5v-7M3 5.5l3-3 3 3" /> : <path d="M6 2.5v7M3 6.5l3 3 3-3" />}
|
|
365
|
+
</svg>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function RemoveIcon() {
|
|
370
|
+
return (
|
|
371
|
+
<svg
|
|
372
|
+
width="12"
|
|
373
|
+
height="12"
|
|
374
|
+
viewBox="0 0 12 12"
|
|
375
|
+
fill="none"
|
|
376
|
+
stroke="currentColor"
|
|
377
|
+
strokeWidth="1.5"
|
|
378
|
+
strokeLinecap="round"
|
|
379
|
+
aria-hidden
|
|
380
|
+
>
|
|
381
|
+
<path d="M3 3l6 6M9 3l-6 6" />
|
|
382
|
+
</svg>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
288
386
|
function ArrayFieldEditor({
|
|
289
387
|
name,
|
|
290
388
|
field,
|
|
@@ -298,6 +396,8 @@ function ArrayFieldEditor({
|
|
|
298
396
|
onChange,
|
|
299
397
|
}: SharedFieldProps) {
|
|
300
398
|
const resolved = resolveObjectFields(field, objects);
|
|
399
|
+
const keysRef = useRef<string[]>([]);
|
|
400
|
+
const [openKeys, setOpenKeys] = useState<ReadonlySet<string>>(() => new Set());
|
|
301
401
|
if (!resolved) {
|
|
302
402
|
return (
|
|
303
403
|
<JsonField
|
|
@@ -310,98 +410,138 @@ function ArrayFieldEditor({
|
|
|
310
410
|
}
|
|
311
411
|
|
|
312
412
|
const items = arrayValue(value);
|
|
413
|
+
// Stable keys keep an item's open state and inputs with it when the list reorders.
|
|
414
|
+
const keys = keysRef.current;
|
|
415
|
+
while (keys.length < items.length) keys.push(nextArrayItemKey());
|
|
416
|
+
keys.length = items.length;
|
|
417
|
+
|
|
313
418
|
const itemField: SchemaField = { kind: "object", object: field.object, fields: resolved };
|
|
314
419
|
const objectName = field.object;
|
|
315
420
|
const nextAncestors = objectName ? [...ancestorObjectNames, objectName] : ancestorObjectNames;
|
|
316
421
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
nextItems[index] = next;
|
|
334
|
-
onChange(nextItems);
|
|
335
|
-
}}
|
|
336
|
-
/>
|
|
337
|
-
<div {...stylex.props(styles.arrayActions)}>
|
|
338
|
-
<button
|
|
339
|
-
type="button"
|
|
340
|
-
data-action="array-up"
|
|
341
|
-
disabled={readOnly || index === 0}
|
|
342
|
-
onClick={() => {
|
|
343
|
-
if (index === 0) return;
|
|
344
|
-
const nextItems = [...items];
|
|
345
|
-
const prev = nextItems[index - 1];
|
|
346
|
-
nextItems[index - 1] = nextItems[index]!;
|
|
347
|
-
nextItems[index] = prev!;
|
|
348
|
-
onChange(nextItems);
|
|
349
|
-
}}
|
|
350
|
-
>
|
|
351
|
-
Up
|
|
352
|
-
</button>
|
|
353
|
-
<button
|
|
354
|
-
type="button"
|
|
355
|
-
data-action="array-down"
|
|
356
|
-
disabled={readOnly || index === items.length - 1}
|
|
357
|
-
onClick={() => {
|
|
358
|
-
if (index >= items.length - 1) return;
|
|
359
|
-
const nextItems = [...items];
|
|
360
|
-
const next = nextItems[index + 1];
|
|
361
|
-
nextItems[index + 1] = nextItems[index]!;
|
|
362
|
-
nextItems[index] = next!;
|
|
363
|
-
onChange(nextItems);
|
|
364
|
-
}}
|
|
365
|
-
>
|
|
366
|
-
Down
|
|
367
|
-
</button>
|
|
368
|
-
<button
|
|
369
|
-
type="button"
|
|
370
|
-
data-action="array-remove"
|
|
371
|
-
disabled={readOnly}
|
|
372
|
-
onClick={() => {
|
|
373
|
-
onChange(items.filter((_, i) => i !== index));
|
|
374
|
-
}}
|
|
375
|
-
>
|
|
376
|
-
Remove
|
|
377
|
-
</button>
|
|
378
|
-
</div>
|
|
379
|
-
</div>
|
|
380
|
-
))}
|
|
381
|
-
<button
|
|
382
|
-
type="button"
|
|
383
|
-
data-action="array-add"
|
|
384
|
-
disabled={readOnly}
|
|
385
|
-
onClick={() => onChange([...items, {}])}
|
|
386
|
-
>
|
|
387
|
-
Add
|
|
388
|
-
</button>
|
|
389
|
-
</div>
|
|
390
|
-
);
|
|
422
|
+
function toggle(key: string) {
|
|
423
|
+
setOpenKeys((prev) => {
|
|
424
|
+
const next = new Set(prev);
|
|
425
|
+
if (next.has(key)) next.delete(key);
|
|
426
|
+
else next.add(key);
|
|
427
|
+
return next;
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function swap(index: number, other: number) {
|
|
432
|
+
if (other < 0 || other >= items.length) return;
|
|
433
|
+
const nextItems = [...items];
|
|
434
|
+
[nextItems[index], nextItems[other]] = [nextItems[other], nextItems[index]];
|
|
435
|
+
[keys[index], keys[other]] = [keys[other]!, keys[index]!];
|
|
436
|
+
onChange(nextItems);
|
|
437
|
+
}
|
|
391
438
|
|
|
392
|
-
|
|
393
|
-
|
|
439
|
+
function remove(index: number) {
|
|
440
|
+
keys.splice(index, 1);
|
|
441
|
+
onChange(items.filter((_, i) => i !== index));
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function add() {
|
|
445
|
+
const key = nextArrayItemKey();
|
|
446
|
+
keys.push(key);
|
|
447
|
+
setOpenKeys((prev) => new Set(prev).add(key));
|
|
448
|
+
onChange([...items, {}]);
|
|
394
449
|
}
|
|
395
450
|
|
|
396
451
|
return (
|
|
397
|
-
<
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
452
|
+
<div {...stylex.props(styles.array)}>
|
|
453
|
+
{items.length > 0 ? (
|
|
454
|
+
<div data-array-list="" {...stylex.props(styles.arrayList)}>
|
|
455
|
+
{items.map((item, index) => {
|
|
456
|
+
const key = keys[index]!;
|
|
457
|
+
const open = openKeys.has(key);
|
|
458
|
+
const title = arrayItemTitle(item, resolved, index);
|
|
459
|
+
return (
|
|
460
|
+
<div key={key} data-array-item="" {...stylex.props(styles.arrayItem)}>
|
|
461
|
+
<div {...stylex.props(styles.itemBar)}>
|
|
462
|
+
<button
|
|
463
|
+
type="button"
|
|
464
|
+
data-item-toggle=""
|
|
465
|
+
aria-expanded={open}
|
|
466
|
+
{...stylex.props(styles.itemToggle)}
|
|
467
|
+
onClick={() => toggle(key)}
|
|
468
|
+
>
|
|
469
|
+
<ChevronIcon open={open} />
|
|
470
|
+
<span {...stylex.props(styles.itemTitle)}>{title}</span>
|
|
471
|
+
</button>
|
|
472
|
+
<div {...stylex.props(styles.itemActions)}>
|
|
473
|
+
<Button
|
|
474
|
+
variant="ghost"
|
|
475
|
+
size="sm"
|
|
476
|
+
muted
|
|
477
|
+
data-action="array-up"
|
|
478
|
+
aria-label={`Move ${title} up`}
|
|
479
|
+
disabled={readOnly || index === 0}
|
|
480
|
+
onClick={() => swap(index, index - 1)}
|
|
481
|
+
>
|
|
482
|
+
<ArrowIcon direction="up" />
|
|
483
|
+
</Button>
|
|
484
|
+
<Button
|
|
485
|
+
variant="ghost"
|
|
486
|
+
size="sm"
|
|
487
|
+
muted
|
|
488
|
+
data-action="array-down"
|
|
489
|
+
aria-label={`Move ${title} down`}
|
|
490
|
+
disabled={readOnly || index === items.length - 1}
|
|
491
|
+
onClick={() => swap(index, index + 1)}
|
|
492
|
+
>
|
|
493
|
+
<ArrowIcon direction="down" />
|
|
494
|
+
</Button>
|
|
495
|
+
<Button
|
|
496
|
+
variant="ghost"
|
|
497
|
+
size="sm"
|
|
498
|
+
muted
|
|
499
|
+
data-action="array-remove"
|
|
500
|
+
aria-label={`Remove ${title}`}
|
|
501
|
+
disabled={readOnly}
|
|
502
|
+
onClick={() => remove(index)}
|
|
503
|
+
>
|
|
504
|
+
<RemoveIcon />
|
|
505
|
+
</Button>
|
|
506
|
+
</div>
|
|
507
|
+
</div>
|
|
508
|
+
{open ? (
|
|
509
|
+
<div {...stylex.props(styles.itemBody)}>
|
|
510
|
+
<FieldControl
|
|
511
|
+
name={`${name}[${index}]`}
|
|
512
|
+
field={itemField}
|
|
513
|
+
value={item}
|
|
514
|
+
models={models}
|
|
515
|
+
objects={objects}
|
|
516
|
+
documentLists={documentLists}
|
|
517
|
+
readOnly={readOnly}
|
|
518
|
+
ancestorObjectNames={nextAncestors}
|
|
519
|
+
blocksEditor={blocksEditor}
|
|
520
|
+
onChange={(next) => {
|
|
521
|
+
const nextItems = [...items];
|
|
522
|
+
nextItems[index] = next;
|
|
523
|
+
onChange(nextItems);
|
|
524
|
+
}}
|
|
525
|
+
/>
|
|
526
|
+
</div>
|
|
527
|
+
) : null}
|
|
528
|
+
</div>
|
|
529
|
+
);
|
|
530
|
+
})}
|
|
531
|
+
</div>
|
|
532
|
+
) : null}
|
|
533
|
+
<div>
|
|
534
|
+
<Button
|
|
535
|
+
variant="secondary"
|
|
536
|
+
size="sm"
|
|
537
|
+
data-action="array-add"
|
|
538
|
+
disabled={readOnly}
|
|
539
|
+
onClick={add}
|
|
540
|
+
>
|
|
541
|
+
Add item
|
|
542
|
+
</Button>
|
|
543
|
+
</div>
|
|
544
|
+
</div>
|
|
405
545
|
);
|
|
406
546
|
}
|
|
407
547
|
|
|
@@ -849,7 +989,7 @@ const styles = stylex.create({
|
|
|
849
989
|
objectFields: {
|
|
850
990
|
display: "flex",
|
|
851
991
|
flexDirection: "column",
|
|
852
|
-
gap: space.
|
|
992
|
+
gap: space.md,
|
|
853
993
|
},
|
|
854
994
|
nest: {
|
|
855
995
|
display: "flex",
|
|
@@ -864,19 +1004,95 @@ const styles = stylex.create({
|
|
|
864
1004
|
flexDirection: "column",
|
|
865
1005
|
gap: space.sm,
|
|
866
1006
|
},
|
|
1007
|
+
fieldGuidance: {
|
|
1008
|
+
fontFamily: type.sans,
|
|
1009
|
+
fontSize: type.sm,
|
|
1010
|
+
},
|
|
1011
|
+
array: {
|
|
1012
|
+
display: "flex",
|
|
1013
|
+
flexDirection: "column",
|
|
1014
|
+
gap: space.sm,
|
|
1015
|
+
},
|
|
867
1016
|
arrayList: {
|
|
868
1017
|
display: "flex",
|
|
869
1018
|
flexDirection: "column",
|
|
870
|
-
|
|
1019
|
+
borderWidth: 1,
|
|
1020
|
+
borderStyle: "solid",
|
|
1021
|
+
borderColor: colors.border,
|
|
1022
|
+
borderRadius: radius.md,
|
|
1023
|
+
backgroundColor: colors.bgSurface,
|
|
871
1024
|
},
|
|
872
1025
|
arrayItem: {
|
|
1026
|
+
borderBottomWidth: 1,
|
|
1027
|
+
borderBottomStyle: "solid",
|
|
1028
|
+
borderBottomColor: colors.border,
|
|
1029
|
+
":last-child": {
|
|
1030
|
+
borderBottomWidth: 0,
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
itemBar: {
|
|
873
1034
|
display: "flex",
|
|
874
|
-
|
|
1035
|
+
alignItems: "center",
|
|
1036
|
+
gap: space.xs,
|
|
1037
|
+
minHeight: "32px",
|
|
1038
|
+
paddingInlineStart: space.sm,
|
|
1039
|
+
paddingInlineEnd: space.xs,
|
|
1040
|
+
paddingBlock: space.xs,
|
|
1041
|
+
},
|
|
1042
|
+
itemToggle: {
|
|
1043
|
+
display: "flex",
|
|
1044
|
+
alignItems: "center",
|
|
875
1045
|
gap: space.sm,
|
|
1046
|
+
minWidth: 0,
|
|
1047
|
+
flex: 1,
|
|
1048
|
+
margin: 0,
|
|
1049
|
+
paddingBlock: space.xs,
|
|
1050
|
+
paddingInline: 0,
|
|
1051
|
+
borderWidth: 0,
|
|
1052
|
+
backgroundColor: "transparent",
|
|
1053
|
+
color: colors.text,
|
|
1054
|
+
font: "inherit",
|
|
1055
|
+
fontSize: type.sm,
|
|
1056
|
+
fontWeight: 500,
|
|
1057
|
+
textAlign: "start",
|
|
1058
|
+
cursor: "pointer",
|
|
1059
|
+
":focus-visible": {
|
|
1060
|
+
outlineWidth: 2,
|
|
1061
|
+
outlineStyle: "solid",
|
|
1062
|
+
outlineColor: colors.focus,
|
|
1063
|
+
outlineOffset: 1,
|
|
1064
|
+
borderRadius: radius.sm,
|
|
1065
|
+
},
|
|
1066
|
+
},
|
|
1067
|
+
itemTitle: {
|
|
1068
|
+
minWidth: 0,
|
|
1069
|
+
overflow: "hidden",
|
|
1070
|
+
textOverflow: "ellipsis",
|
|
1071
|
+
whiteSpace: "nowrap",
|
|
1072
|
+
},
|
|
1073
|
+
chevron: {
|
|
1074
|
+
flexShrink: 0,
|
|
1075
|
+
color: colors.textMuted,
|
|
1076
|
+
transitionProperty: "transform",
|
|
1077
|
+
transitionDuration: "120ms",
|
|
1078
|
+
"@media (prefers-reduced-motion: reduce)": {
|
|
1079
|
+
transitionDuration: "0ms",
|
|
1080
|
+
},
|
|
876
1081
|
},
|
|
877
|
-
|
|
1082
|
+
chevronOpen: {
|
|
1083
|
+
transform: "rotate(90deg)",
|
|
1084
|
+
},
|
|
1085
|
+
itemActions: {
|
|
878
1086
|
display: "flex",
|
|
879
|
-
|
|
880
|
-
gap:
|
|
1087
|
+
flexShrink: 0,
|
|
1088
|
+
gap: "2px",
|
|
1089
|
+
},
|
|
1090
|
+
itemBody: {
|
|
1091
|
+
display: "flex",
|
|
1092
|
+
flexDirection: "column",
|
|
1093
|
+
gap: space.md,
|
|
1094
|
+
paddingInlineStart: space.xl,
|
|
1095
|
+
paddingInlineEnd: space.md,
|
|
1096
|
+
paddingBottom: space.md,
|
|
881
1097
|
},
|
|
882
1098
|
});
|
|
@@ -219,9 +219,15 @@ export function LinkFieldInput({
|
|
|
219
219
|
|
|
220
220
|
const { parts, showSuffix, selectValue } = raw === "" ? {
|
|
221
221
|
parts: { path: "", query: "", anchor: "" },
|
|
222
|
-
showSuffix:
|
|
222
|
+
showSuffix: true,
|
|
223
223
|
selectValue: "",
|
|
224
224
|
} : internalSuffixState(raw);
|
|
225
|
+
// With no route picked, the anchor is a bare `#anchor` on the page that
|
|
226
|
+
// renders the link. A field limited to models or a filter can't take one.
|
|
227
|
+
const bareAnchorAllowed = !(field.models && field.models.length > 0) && !field.where;
|
|
228
|
+
const hasRoute = parts.path !== "";
|
|
229
|
+
const queryEditable = showSuffix && hasRoute;
|
|
230
|
+
const anchorEditable = showSuffix && (hasRoute || bareAnchorAllowed);
|
|
225
231
|
|
|
226
232
|
const options = buildRouteOptions(field, models, documentLists);
|
|
227
233
|
if (selectValue && !options.some((option) => option.value === selectValue)) {
|
|
@@ -267,19 +273,20 @@ export function LinkFieldInput({
|
|
|
267
273
|
<Input
|
|
268
274
|
aria-label="Query"
|
|
269
275
|
value={showSuffix ? parts.query : ""}
|
|
270
|
-
readOnly={readOnly || !
|
|
276
|
+
readOnly={readOnly || !queryEditable}
|
|
271
277
|
onChange={(event) => {
|
|
272
|
-
if (readOnly || !
|
|
278
|
+
if (readOnly || !queryEditable) return;
|
|
273
279
|
emitChange(joinInternalLink(parts.path, event.target.value, parts.anchor));
|
|
274
280
|
}}
|
|
275
281
|
/>
|
|
276
282
|
<Input
|
|
277
283
|
aria-label="Anchor"
|
|
278
284
|
value={showSuffix ? parts.anchor : ""}
|
|
279
|
-
readOnly={readOnly || !
|
|
285
|
+
readOnly={readOnly || !anchorEditable}
|
|
280
286
|
onChange={(event) => {
|
|
281
|
-
if (readOnly || !
|
|
282
|
-
|
|
287
|
+
if (readOnly || !anchorEditable) return;
|
|
288
|
+
const next = joinInternalLink(parts.path, parts.query, event.target.value);
|
|
289
|
+
emitChange(next === "" ? undefined : next);
|
|
283
290
|
}}
|
|
284
291
|
/>
|
|
285
292
|
</div>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// packages/studio/src/fields/array-item-title.ts
|
|
2
|
+
import type { SchemaField } from "../api";
|
|
3
|
+
|
|
4
|
+
const TITLE_KEYS = ["label", "title", "name", "heading"];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What an array item's card header says: its label-like value, else its first
|
|
8
|
+
* non-empty text value in field order, else "Item n".
|
|
9
|
+
*/
|
|
10
|
+
export function arrayItemTitle(
|
|
11
|
+
item: unknown,
|
|
12
|
+
fields: Record<string, SchemaField>,
|
|
13
|
+
index: number,
|
|
14
|
+
): string {
|
|
15
|
+
const record =
|
|
16
|
+
item && typeof item === "object" && !Array.isArray(item) ? (item as Record<string, unknown>) : {};
|
|
17
|
+
const text = (key: string) => {
|
|
18
|
+
const value = record[key];
|
|
19
|
+
return typeof value === "string" ? value.trim() : "";
|
|
20
|
+
};
|
|
21
|
+
for (const key of TITLE_KEYS) {
|
|
22
|
+
if (key in fields && text(key)) return text(key);
|
|
23
|
+
}
|
|
24
|
+
for (const key of Object.keys(fields)) {
|
|
25
|
+
if (text(key)) return text(key);
|
|
26
|
+
}
|
|
27
|
+
return `Item ${index + 1}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// packages/studio/src/fields/field-label.ts
|
|
2
|
+
import type { SchemaField } from "../api";
|
|
3
|
+
|
|
4
|
+
/** The label Studio shows for a field: its own `label`, else the capitalized name. */
|
|
5
|
+
export function fieldLabel(name: string, field: SchemaField): string {
|
|
6
|
+
if ("label" in field && typeof field.label === "string" && field.label) return field.label;
|
|
7
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
8
|
+
}
|
package/src/host-pointer.ts
CHANGED
|
@@ -76,6 +76,7 @@ export function bindHostPointer(doc: Document): () => void {
|
|
|
76
76
|
line?: number | null;
|
|
77
77
|
column?: number | null;
|
|
78
78
|
stack?: string[];
|
|
79
|
+
field?: string | null;
|
|
79
80
|
}) {
|
|
80
81
|
transport.send({
|
|
81
82
|
type: "backmatter:grab",
|
|
@@ -91,6 +92,7 @@ export function bindHostPointer(doc: Document): () => void {
|
|
|
91
92
|
...(grab.line ? { line: grab.line } : {}),
|
|
92
93
|
...(grab.column ? { column: grab.column } : {}),
|
|
93
94
|
...(grab.stack && grab.stack.length > 0 ? { stack: grab.stack } : {}),
|
|
95
|
+
...(grab.field ? { field: grab.field } : {}),
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
98
|
const pointer = installPreviewPointer(doc, {
|