@backmatter/studio 0.0.20 → 0.0.22
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-C269OA8v.js → UiKitApp-CgGyJiC4.js} +2 -2
- package/dist/chunks/{WorkspaceRoutes-B4B5jjje.js → WorkspaceRoutes-CzCBnhNt.js} +26364 -25362
- package/dist/chunks/dashboard-w-mlsGky.js +1879 -0
- package/dist/chunks/{index-7-TtXaMq.js → index-_XfFuFSU.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 +304 -32
- package/package.json +2 -2
- package/src/App.tsx +7 -1
- package/src/api.ts +106 -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 +185 -29
- 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 +39 -67
- 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/MediaFieldInput.tsx +1 -1
- package/src/pages/MediaGalleryPage.tsx +36 -3
- 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/ui/Input.tsx +134 -35
- package/src/workspace/schema-source.tsx +126 -0
- package/dist/chunks/dashboard-DeNgythd.js +0 -1779
- package/src/site-devbar-overlay-inject.ts +0 -15
- package/src/site-publish-menu.tsx +0 -33
|
@@ -4,6 +4,7 @@ import * as stylex from "@stylexjs/stylex";
|
|
|
4
4
|
import {
|
|
5
5
|
documentLabel,
|
|
6
6
|
internalSuffixError,
|
|
7
|
+
isBareAnchor,
|
|
7
8
|
joinInternalLink,
|
|
8
9
|
linkSide,
|
|
9
10
|
matchesWhere,
|
|
@@ -12,7 +13,10 @@ import {
|
|
|
12
13
|
} from "@backmatter/core";
|
|
13
14
|
import type { SchemaField } from "../api";
|
|
14
15
|
import { colors, radius, space, type } from "../styles/tokens.stylex";
|
|
15
|
-
import { Input, Select } from "../ui/Input";
|
|
16
|
+
import { Input, Select, type SelectOption } from "../ui/Input";
|
|
17
|
+
|
|
18
|
+
/** Select value for "This page": a bare `#anchor` on whichever page shows the link. */
|
|
19
|
+
const THIS_PAGE = "#";
|
|
16
20
|
|
|
17
21
|
type ModelRef = {
|
|
18
22
|
type: string;
|
|
@@ -60,15 +64,22 @@ function internalSuffixState(value: string): {
|
|
|
60
64
|
return { parts, showSuffix: true, selectValue: parts.path };
|
|
61
65
|
}
|
|
62
66
|
|
|
67
|
+
function modelGroupLabel(type: string): string {
|
|
68
|
+
return type.charAt(0).toUpperCase() + type.slice(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Routes grouped by model in schema order, each titled with its route beneath. */
|
|
63
72
|
function buildRouteOptions(
|
|
64
73
|
field: SchemaField,
|
|
65
74
|
models: ModelRef[],
|
|
66
75
|
documentLists: RelationDocumentLists | undefined,
|
|
67
|
-
):
|
|
76
|
+
): SelectOption[] {
|
|
68
77
|
if (!documentLists) return [];
|
|
69
|
-
const options:
|
|
78
|
+
const options: SelectOption[] = [];
|
|
70
79
|
for (const model of routableTypes(field, models)) {
|
|
80
|
+
const group = modelGroupLabel(model.type);
|
|
71
81
|
const docs = documentLists[model.type] ?? [];
|
|
82
|
+
const modelOptions: SelectOption[] = [];
|
|
72
83
|
for (const doc of docs) {
|
|
73
84
|
if (!matchesWhere({ slug: doc.slug, frontmatter: doc.frontmatter }, field.where)) {
|
|
74
85
|
continue;
|
|
@@ -76,13 +87,19 @@ function buildRouteOptions(
|
|
|
76
87
|
const route = routeFor(model, doc.slug);
|
|
77
88
|
if (route === "") continue;
|
|
78
89
|
const label = documentLabel(doc.frontmatter, model);
|
|
79
|
-
|
|
90
|
+
modelOptions.push({
|
|
80
91
|
value: route,
|
|
81
|
-
label: label
|
|
92
|
+
label: label || route,
|
|
93
|
+
description: label ? route : undefined,
|
|
94
|
+
group,
|
|
82
95
|
});
|
|
83
96
|
}
|
|
97
|
+
// Titles that open with a quote mark sort by their first letter.
|
|
98
|
+
modelOptions.sort((a, b) =>
|
|
99
|
+
a.label.localeCompare(b.label, undefined, { ignorePunctuation: true, sensitivity: "base" }),
|
|
100
|
+
);
|
|
101
|
+
options.push(...modelOptions);
|
|
84
102
|
}
|
|
85
|
-
options.sort((a, b) => a.label.localeCompare(b.label));
|
|
86
103
|
return options;
|
|
87
104
|
}
|
|
88
105
|
|
|
@@ -153,11 +170,15 @@ export function LinkFieldInput({
|
|
|
153
170
|
linkSide(raw) === "external" ? "external" : "internal",
|
|
154
171
|
);
|
|
155
172
|
const [pendingClearOf, setPendingClearOf] = useState<string | null>(null);
|
|
173
|
+
const [thisPagePicked, setThisPagePicked] = useState(false);
|
|
174
|
+
const [openParts, setOpenParts] = useState({ query: false, anchor: false });
|
|
156
175
|
const [lastSyncedRaw, setLastSyncedRaw] = useState(raw);
|
|
157
176
|
if (raw !== lastSyncedRaw) {
|
|
158
177
|
setLastSyncedRaw(raw);
|
|
159
178
|
if (raw !== lastEmittedRawRef.current) {
|
|
160
179
|
lastEmittedRawRef.current = null;
|
|
180
|
+
setThisPagePicked(false);
|
|
181
|
+
setOpenParts({ query: false, anchor: false });
|
|
161
182
|
if (raw !== "") {
|
|
162
183
|
setEditorSide(linkSide(raw) === "external" ? "external" : "internal");
|
|
163
184
|
}
|
|
@@ -217,16 +238,32 @@ export function LinkFieldInput({
|
|
|
217
238
|
);
|
|
218
239
|
}
|
|
219
240
|
|
|
220
|
-
const
|
|
241
|
+
const internal = raw === "" ? {
|
|
221
242
|
parts: { path: "", query: "", anchor: "" },
|
|
222
|
-
showSuffix:
|
|
243
|
+
showSuffix: true,
|
|
223
244
|
selectValue: "",
|
|
224
245
|
} : internalSuffixState(raw);
|
|
246
|
+
const { parts, showSuffix } = internal;
|
|
247
|
+
// A bare anchor has no page to hold to a field's models or filter.
|
|
248
|
+
const bareAnchorAllowed = !(field.models && field.models.length > 0) && !field.where;
|
|
249
|
+
const bare = raw !== "" && isBareAnchor(raw);
|
|
250
|
+
const thisPage = bare || (raw === "" && thisPagePicked && bareAnchorAllowed);
|
|
251
|
+
const hasRoute = parts.path !== "";
|
|
252
|
+
const selectValue = thisPage ? THIS_PAGE : internal.selectValue;
|
|
225
253
|
|
|
226
|
-
const options = buildRouteOptions(field, models, documentLists);
|
|
227
|
-
if (selectValue && !options.some((option) => option.value === selectValue)) {
|
|
254
|
+
const options: SelectOption[] = buildRouteOptions(field, models, documentLists);
|
|
255
|
+
if (selectValue && selectValue !== THIS_PAGE && !options.some((option) => option.value === selectValue)) {
|
|
228
256
|
options.unshift({ value: selectValue, label: selectValue });
|
|
229
257
|
}
|
|
258
|
+
if (bareAnchorAllowed || bare) {
|
|
259
|
+
options.unshift({ value: THIS_PAGE, label: "This page" });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const showAnchor =
|
|
263
|
+
showSuffix && (thisPage || (hasRoute && (openParts.anchor || parts.anchor !== "")));
|
|
264
|
+
const showQuery = showSuffix && hasRoute && (openParts.query || parts.query !== "");
|
|
265
|
+
const canAddAnchor = !readOnly && showSuffix && hasRoute && !showAnchor;
|
|
266
|
+
const canAddQuery = !readOnly && showSuffix && hasRoute && !showQuery;
|
|
230
267
|
|
|
231
268
|
const internalPressed = editorSide !== "external";
|
|
232
269
|
|
|
@@ -251,41 +288,121 @@ export function LinkFieldInput({
|
|
|
251
288
|
chip
|
|
252
289
|
searchable
|
|
253
290
|
clearable={!field.required}
|
|
254
|
-
placeholder="
|
|
291
|
+
placeholder="Choose a page"
|
|
255
292
|
options={options}
|
|
256
293
|
value={selectValue || null}
|
|
257
294
|
disabled={readOnly}
|
|
258
295
|
onValueChange={(next) => {
|
|
259
296
|
if (readOnly) return;
|
|
260
297
|
if (next == null) {
|
|
298
|
+
setThisPagePicked(false);
|
|
299
|
+
setOpenParts({ query: false, anchor: false });
|
|
261
300
|
emitChange(undefined);
|
|
262
301
|
return;
|
|
263
302
|
}
|
|
303
|
+
if (next === THIS_PAGE) {
|
|
304
|
+
setThisPagePicked(true);
|
|
305
|
+
const anchor = showSuffix ? parts.anchor : "";
|
|
306
|
+
if (anchor !== "") {
|
|
307
|
+
emitChange(`#${anchor}`);
|
|
308
|
+
} else if (raw !== "") {
|
|
309
|
+
emitChange(undefined);
|
|
310
|
+
}
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
setThisPagePicked(false);
|
|
264
314
|
emitChange(joinInternalLink(next, showSuffix ? parts.query : "", showSuffix ? parts.anchor : ""));
|
|
265
315
|
}}
|
|
266
316
|
/>
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
317
|
+
{showQuery ? (
|
|
318
|
+
<LinkPart
|
|
319
|
+
label="Query"
|
|
320
|
+
prefix="?"
|
|
321
|
+
placeholder="key=value"
|
|
322
|
+
value={parts.query}
|
|
323
|
+
readOnly={readOnly}
|
|
324
|
+
onChange={(query) => {
|
|
325
|
+
if (readOnly) return;
|
|
326
|
+
emitChange(joinInternalLink(parts.path, query, parts.anchor));
|
|
327
|
+
}}
|
|
328
|
+
/>
|
|
329
|
+
) : null}
|
|
330
|
+
{showAnchor ? (
|
|
331
|
+
<LinkPart
|
|
332
|
+
label="Anchor"
|
|
333
|
+
prefix="#"
|
|
334
|
+
placeholder="section-id"
|
|
335
|
+
value={parts.anchor}
|
|
336
|
+
readOnly={readOnly}
|
|
337
|
+
onChange={(anchor) => {
|
|
338
|
+
if (readOnly) return;
|
|
339
|
+
const next = thisPage
|
|
340
|
+
? joinInternalLink("", "", anchor)
|
|
341
|
+
: joinInternalLink(parts.path, parts.query, anchor);
|
|
342
|
+
emitChange(next === "" ? undefined : next);
|
|
343
|
+
}}
|
|
344
|
+
/>
|
|
345
|
+
) : null}
|
|
346
|
+
{canAddAnchor || canAddQuery ? (
|
|
347
|
+
<div {...stylex.props(styles.addRow)}>
|
|
348
|
+
{canAddAnchor ? (
|
|
349
|
+
<button
|
|
350
|
+
type="button"
|
|
351
|
+
{...stylex.props(styles.addButton)}
|
|
352
|
+
onClick={() => setOpenParts((open) => ({ ...open, anchor: true }))}
|
|
353
|
+
>
|
|
354
|
+
Add anchor
|
|
355
|
+
</button>
|
|
356
|
+
) : null}
|
|
357
|
+
{canAddQuery ? (
|
|
358
|
+
<button
|
|
359
|
+
type="button"
|
|
360
|
+
{...stylex.props(styles.addButton)}
|
|
361
|
+
onClick={() => setOpenParts((open) => ({ ...open, query: true }))}
|
|
362
|
+
>
|
|
363
|
+
Add query
|
|
364
|
+
</button>
|
|
365
|
+
) : null}
|
|
366
|
+
</div>
|
|
367
|
+
) : null}
|
|
285
368
|
</div>
|
|
286
369
|
);
|
|
287
370
|
}
|
|
288
371
|
|
|
372
|
+
function LinkPart({
|
|
373
|
+
label,
|
|
374
|
+
prefix,
|
|
375
|
+
placeholder,
|
|
376
|
+
value,
|
|
377
|
+
readOnly,
|
|
378
|
+
onChange,
|
|
379
|
+
}: {
|
|
380
|
+
label: "Query" | "Anchor";
|
|
381
|
+
prefix: string;
|
|
382
|
+
placeholder: string;
|
|
383
|
+
value: string;
|
|
384
|
+
readOnly?: boolean;
|
|
385
|
+
onChange: (value: string) => void;
|
|
386
|
+
}) {
|
|
387
|
+
return (
|
|
388
|
+
<label {...stylex.props(styles.partRow)}>
|
|
389
|
+
<span {...stylex.props(styles.partLabel)}>{label}</span>
|
|
390
|
+
<span {...stylex.props(styles.partInput)}>
|
|
391
|
+
<span aria-hidden {...stylex.props(styles.partPrefix)}>
|
|
392
|
+
{prefix}
|
|
393
|
+
</span>
|
|
394
|
+
<Input
|
|
395
|
+
aria-label={label}
|
|
396
|
+
placeholder={placeholder}
|
|
397
|
+
value={value}
|
|
398
|
+
readOnly={readOnly}
|
|
399
|
+
onChange={(event) => onChange(event.target.value)}
|
|
400
|
+
/>
|
|
401
|
+
</span>
|
|
402
|
+
</label>
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
289
406
|
const styles = stylex.create({
|
|
290
407
|
stack: {
|
|
291
408
|
display: "flex",
|
|
@@ -308,6 +425,45 @@ const styles = stylex.create({
|
|
|
308
425
|
fontSize: type.sm,
|
|
309
426
|
cursor: "pointer",
|
|
310
427
|
},
|
|
428
|
+
partRow: {
|
|
429
|
+
display: "flex",
|
|
430
|
+
alignItems: "center",
|
|
431
|
+
gap: space.sm,
|
|
432
|
+
},
|
|
433
|
+
partLabel: {
|
|
434
|
+
flexShrink: 0,
|
|
435
|
+
width: "4rem",
|
|
436
|
+
fontFamily: type.sans,
|
|
437
|
+
fontSize: type.xs,
|
|
438
|
+
color: colors.textMuted,
|
|
439
|
+
},
|
|
440
|
+
partInput: {
|
|
441
|
+
display: "flex",
|
|
442
|
+
alignItems: "center",
|
|
443
|
+
gap: space.xs,
|
|
444
|
+
flex: 1,
|
|
445
|
+
minWidth: 0,
|
|
446
|
+
},
|
|
447
|
+
partPrefix: {
|
|
448
|
+
flexShrink: 0,
|
|
449
|
+
fontFamily: type.sans,
|
|
450
|
+
fontSize: type.sm,
|
|
451
|
+
color: colors.textMuted,
|
|
452
|
+
},
|
|
453
|
+
addRow: {
|
|
454
|
+
display: "flex",
|
|
455
|
+
gap: space.md,
|
|
456
|
+
},
|
|
457
|
+
addButton: {
|
|
458
|
+
padding: 0,
|
|
459
|
+
borderWidth: 0,
|
|
460
|
+
backgroundColor: "transparent",
|
|
461
|
+
color: colors.textMuted,
|
|
462
|
+
fontFamily: type.sans,
|
|
463
|
+
fontSize: type.xs,
|
|
464
|
+
cursor: "pointer",
|
|
465
|
+
textDecoration: { default: "none", ":hover": "underline" },
|
|
466
|
+
},
|
|
311
467
|
sideButtonPressed: {
|
|
312
468
|
borderColor: colors.text,
|
|
313
469
|
fontWeight: 600,
|
|
@@ -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, {
|