@backmatter/studio 0.0.17 → 0.0.19
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-D7vllRQE.js → UiKitApp-B1ANqCac.js} +528 -481
- package/dist/chunks/{WorkspaceRoutes-DH1LD-2Q.js → WorkspaceRoutes-BHNGrf-j.js} +24955 -24119
- package/dist/chunks/{dashboard-Dsaeud2x.js → dashboard-b-W6dGm5.js} +586 -565
- package/dist/chunks/{index-CGMqw2NH.js → index-HYioDjux.js} +104 -104
- package/dist/dashboard.js +2 -2
- package/dist/index.js +166 -159
- package/dist/site-widget.css +25 -6
- package/dist/site-widget.js +6925 -6840
- package/dist/studio.css +171 -42
- package/package.json +2 -2
- package/src/api.ts +44 -1
- package/src/chat/ChatMessage.tsx +4 -4
- package/src/chat/ChatProvider.tsx +6 -0
- package/src/chat/chat-helpers.ts +54 -2
- package/src/chrome/CommandPalette.tsx +3 -3
- package/src/chrome/ContentExplorerSidebar.tsx +421 -74
- package/src/chrome/WorkspaceStatusBar.tsx +24 -24
- package/src/chrome/commit-error.ts +48 -60
- package/src/chrome/commit-failure.tsx +2 -2
- package/src/chrome/content-path-tree.ts +4 -0
- package/src/chrome/explorer-row-menu.ts +28 -0
- package/src/chrome/folder-create-context.ts +14 -0
- package/src/chrome/use-publish-check.ts +75 -0
- package/src/{pages/code-session-routes.ts → content-routes.ts} +6 -6
- package/src/fields/FieldControl.tsx +198 -64
- package/src/fields/LinkFieldInput.tsx +315 -0
- package/src/fields/choose-field-input.ts +5 -0
- package/src/fields/link-targets.ts +60 -0
- package/src/host-path.ts +13 -0
- package/src/pages/CodeSessionPage.tsx +6 -241
- package/src/pages/DocEditorPage.tsx +121 -178
- package/src/pages/EmbedPublishPage.tsx +13 -5
- package/src/pages/GithubConnectPage.tsx +1 -1
- package/src/pages/LoginPage.tsx +67 -5
- package/src/pages/MediaFieldInput.tsx +712 -37
- package/src/pages/MediaGalleryPage.tsx +69 -5
- package/src/pages/PreviewAddress.tsx +293 -0
- package/src/pages/WorkspaceHomePage.tsx +1 -1
- package/src/pages/code-session-boot.ts +0 -12
- package/src/pages/media-selection.ts +79 -0
- package/src/pages/ui-kit/colors.tsx +2 -0
- package/src/pages/ui-kit/fields.tsx +60 -0
- package/src/styles/themes.ts +2 -0
- package/src/styles/tokens.stylex.ts +1 -0
- package/src/ui/Button.tsx +14 -0
- package/src/ui/Field.tsx +12 -1
- package/src/ui/Input.tsx +191 -97
- package/src/ui/popup.ts +13 -6
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// packages/studio/src/fields/link-targets.ts
|
|
2
|
+
import type { SchemaField } from "../api";
|
|
3
|
+
import { resolveObjectFields } from "./resolve-object-fields";
|
|
4
|
+
|
|
5
|
+
type ModelRef = { type: string; external?: boolean; route?: string | false };
|
|
6
|
+
type ObjectDef = { name: string; fields: Record<string, SchemaField> };
|
|
7
|
+
|
|
8
|
+
function modelTypeLoadable(type: string, models: ModelRef[]): boolean {
|
|
9
|
+
const model = models.find((item) => item.type === type);
|
|
10
|
+
return Boolean(model && !model.external && model.route !== false);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function collectFromFields(
|
|
14
|
+
fields: Record<string, SchemaField>,
|
|
15
|
+
models: ModelRef[],
|
|
16
|
+
objects: ObjectDef[],
|
|
17
|
+
visiting: Set<string>,
|
|
18
|
+
targets: Set<string>,
|
|
19
|
+
): void {
|
|
20
|
+
for (const field of Object.values(fields)) {
|
|
21
|
+
if (field.kind === "link") {
|
|
22
|
+
if (field.to === "external") {
|
|
23
|
+
// external-only links do not load documents
|
|
24
|
+
} else if (field.models && field.models.length > 0) {
|
|
25
|
+
for (const type of field.models) {
|
|
26
|
+
if (modelTypeLoadable(type, models)) {
|
|
27
|
+
targets.add(type);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
for (const model of models) {
|
|
32
|
+
if (!model.external && model.route !== false) {
|
|
33
|
+
targets.add(model.type);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const nested = resolveObjectFields(field, objects);
|
|
40
|
+
if (!nested) continue;
|
|
41
|
+
|
|
42
|
+
let nextVisiting = visiting;
|
|
43
|
+
if (field.object && (field.kind === "object" || field.kind === "array")) {
|
|
44
|
+
if (visiting.has(field.object)) continue;
|
|
45
|
+
nextVisiting = new Set(visiting).add(field.object);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
collectFromFields(nested, models, objects, nextVisiting, targets);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function linkDocumentTypes(
|
|
53
|
+
fields: Record<string, SchemaField>,
|
|
54
|
+
models: ModelRef[],
|
|
55
|
+
objects: ObjectDef[],
|
|
56
|
+
): string[] {
|
|
57
|
+
const targets = new Set<string>();
|
|
58
|
+
collectFromFields(fields, models, objects, new Set<string>(), targets);
|
|
59
|
+
return [...targets].sort();
|
|
60
|
+
}
|
package/src/host-path.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// packages/studio/src/host-path.ts
|
|
2
|
+
|
|
3
|
+
/** A typed or pasted address, as a path on the host. */
|
|
4
|
+
export function hostPath(input: string): string {
|
|
5
|
+
const trimmed = input.trim();
|
|
6
|
+
if (!trimmed) return "/";
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(trimmed);
|
|
9
|
+
return `${url.pathname}${url.search}${url.hash}` || "/";
|
|
10
|
+
} catch {
|
|
11
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
// packages/studio/src/pages/CodeSessionPage.tsx
|
|
2
|
-
import { useCallback, useEffect, useRef, useState
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import type { RouteModel } from "@backmatter/core";
|
|
4
4
|
import { useOutletContext } from "react-router";
|
|
5
5
|
import * as stylex from "@stylexjs/stylex";
|
|
6
|
-
import { Combobox } from "@base-ui/react/combobox";
|
|
7
6
|
import {
|
|
8
|
-
IconArrowRotateClockwise,
|
|
9
|
-
IconArrowUpRight,
|
|
10
7
|
IconCheckmark1Small,
|
|
11
8
|
IconCrossSmall,
|
|
12
9
|
IconEyeOpen,
|
|
13
10
|
IconFiles,
|
|
14
|
-
IconGlobe,
|
|
15
11
|
} from "@central-icons-react/round-outlined-radius-2-stroke-1.5";
|
|
16
12
|
import { ChatPanel } from "../chat/ChatPanel";
|
|
17
13
|
import { ChatProvider, ChatSessionScope, useChatBusy } from "../chat/ChatProvider";
|
|
18
14
|
import { useReplicaState } from "../replica/useReplica";
|
|
15
|
+
import { routesForContentFiles } from "../content-routes";
|
|
19
16
|
import { colors, radius, space, type } from "../styles/tokens.stylex";
|
|
20
17
|
import { apiCredentials, apiHeaders, apiUrl } from "../studio-config";
|
|
21
18
|
import { Text } from "../ui/Text";
|
|
22
|
-
import { cx, popup, popupClassName } from "../ui/popup";
|
|
23
19
|
import type { WorkspaceOutletContext } from "../workspace/types";
|
|
24
|
-
import { bootSteps,
|
|
20
|
+
import { bootSteps, type BootStep, type HostPhase } from "./code-session-boot";
|
|
25
21
|
import {
|
|
26
22
|
frameAddress,
|
|
27
23
|
framedLocation,
|
|
@@ -30,7 +26,7 @@ import {
|
|
|
30
26
|
previewUrl,
|
|
31
27
|
type HostPreview,
|
|
32
28
|
} from "./code-session-frame";
|
|
33
|
-
import {
|
|
29
|
+
import { PreviewAddress } from "./PreviewAddress";
|
|
34
30
|
import { CodeSessionFiles, type FilesView } from "./CodeSessionFiles";
|
|
35
31
|
import { PreviewSizeSwitch, PreviewViewport } from "./PreviewSize";
|
|
36
32
|
import { persistPreviewSize, readPreviewSize, type PreviewSize } from "./preview-size";
|
|
@@ -194,7 +190,7 @@ export function CodeSessionScreen({
|
|
|
194
190
|
</TabButton>
|
|
195
191
|
</div>
|
|
196
192
|
|
|
197
|
-
<
|
|
193
|
+
<PreviewAddress
|
|
198
194
|
path={location}
|
|
199
195
|
enabled={frameSrc !== null && tab === "preview"}
|
|
200
196
|
routes={routes}
|
|
@@ -324,170 +320,6 @@ function TabButton({
|
|
|
324
320
|
);
|
|
325
321
|
}
|
|
326
322
|
|
|
327
|
-
function AddressBar({
|
|
328
|
-
path,
|
|
329
|
-
enabled,
|
|
330
|
-
routes,
|
|
331
|
-
routesPending,
|
|
332
|
-
onOpenRoutes,
|
|
333
|
-
onPath,
|
|
334
|
-
onReload,
|
|
335
|
-
onOpen,
|
|
336
|
-
}: {
|
|
337
|
-
path: string;
|
|
338
|
-
enabled: boolean;
|
|
339
|
-
routes: readonly string[];
|
|
340
|
-
routesPending: boolean;
|
|
341
|
-
onOpenRoutes?: () => void;
|
|
342
|
-
onPath: (path: string) => void;
|
|
343
|
-
onReload: () => void;
|
|
344
|
-
onOpen: () => void;
|
|
345
|
-
}) {
|
|
346
|
-
const [query, setQuery] = useState<string | null>(null);
|
|
347
|
-
const [open, setOpen] = useState(false);
|
|
348
|
-
const picked = useRef(false);
|
|
349
|
-
const fieldRef = useRef<HTMLButtonElement>(null);
|
|
350
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
351
|
-
const shown = query ? matchingRoutes(routes, query) : [...routes];
|
|
352
|
-
|
|
353
|
-
useEffect(() => {
|
|
354
|
-
if (!open) return;
|
|
355
|
-
const input = inputRef.current;
|
|
356
|
-
input?.focus();
|
|
357
|
-
input?.select();
|
|
358
|
-
}, [open]);
|
|
359
|
-
|
|
360
|
-
return (
|
|
361
|
-
<div {...stylex.props(styles.address)}>
|
|
362
|
-
<button
|
|
363
|
-
type="button"
|
|
364
|
-
aria-label="Reload preview"
|
|
365
|
-
disabled={!enabled}
|
|
366
|
-
onClick={onReload}
|
|
367
|
-
{...stylex.props(styles.iconButton)}
|
|
368
|
-
>
|
|
369
|
-
<IconArrowRotateClockwise size={14} ariaHidden />
|
|
370
|
-
</button>
|
|
371
|
-
<Combobox.Root
|
|
372
|
-
items={shown}
|
|
373
|
-
filteredItems={shown}
|
|
374
|
-
inputValue={query ?? ""}
|
|
375
|
-
disabled={!enabled}
|
|
376
|
-
open={open}
|
|
377
|
-
value={routes.includes(path) ? path : null}
|
|
378
|
-
onOpenChange={(next) => {
|
|
379
|
-
if (!enabled && next) return;
|
|
380
|
-
setOpen(next);
|
|
381
|
-
if (next) onOpenRoutes?.();
|
|
382
|
-
else setQuery(null);
|
|
383
|
-
}}
|
|
384
|
-
onInputValueChange={(value, details) => {
|
|
385
|
-
if (details.reason === "input-change" || details.reason === "input-clear") {
|
|
386
|
-
setQuery(value);
|
|
387
|
-
}
|
|
388
|
-
}}
|
|
389
|
-
onValueChange={(value) => {
|
|
390
|
-
if (typeof value !== "string") return;
|
|
391
|
-
picked.current = true;
|
|
392
|
-
setQuery(null);
|
|
393
|
-
onPath(hostPath(value));
|
|
394
|
-
queueMicrotask(() => {
|
|
395
|
-
picked.current = false;
|
|
396
|
-
});
|
|
397
|
-
}}
|
|
398
|
-
>
|
|
399
|
-
<Combobox.Trigger
|
|
400
|
-
ref={fieldRef}
|
|
401
|
-
aria-label="Preview path"
|
|
402
|
-
disabled={!enabled}
|
|
403
|
-
data-no-ring
|
|
404
|
-
className={cx(styles.addressTrigger)}
|
|
405
|
-
>
|
|
406
|
-
<IconGlobe size={13} ariaHidden />
|
|
407
|
-
<span {...stylex.props(styles.addressPath)}>{path}</span>
|
|
408
|
-
</Combobox.Trigger>
|
|
409
|
-
<Combobox.Portal>
|
|
410
|
-
<Combobox.Positioner
|
|
411
|
-
anchor={fieldRef}
|
|
412
|
-
side="bottom"
|
|
413
|
-
align="start"
|
|
414
|
-
sideOffset={6}
|
|
415
|
-
className={cx(popup.positioner)}
|
|
416
|
-
>
|
|
417
|
-
<Combobox.Popup
|
|
418
|
-
aria-label="Pages"
|
|
419
|
-
className={(state) => popupClassName(state, styles.routePopup)}
|
|
420
|
-
>
|
|
421
|
-
<form
|
|
422
|
-
onSubmit={(event: FormEvent<HTMLFormElement>) => {
|
|
423
|
-
event.preventDefault();
|
|
424
|
-
const fromList = picked.current;
|
|
425
|
-
picked.current = false;
|
|
426
|
-
if (fromList) return;
|
|
427
|
-
const typed = event.currentTarget.querySelector("input")?.value;
|
|
428
|
-
if (typed?.trim()) onPath(hostPath(typed));
|
|
429
|
-
setOpen(false);
|
|
430
|
-
setQuery(null);
|
|
431
|
-
}}
|
|
432
|
-
>
|
|
433
|
-
<Combobox.Input
|
|
434
|
-
ref={inputRef}
|
|
435
|
-
placeholder="Find a page"
|
|
436
|
-
aria-label="Find a page"
|
|
437
|
-
spellCheck={false}
|
|
438
|
-
autoComplete="off"
|
|
439
|
-
data-no-ring
|
|
440
|
-
className={cx(popup.quietInput, styles.routeSearch)}
|
|
441
|
-
onKeyDown={(event) => {
|
|
442
|
-
if (event.key !== "Enter") return;
|
|
443
|
-
// A highlighted row is chosen by the combobox. A bare Enter goes to the typed path.
|
|
444
|
-
if (event.currentTarget.getAttribute("aria-activedescendant")) return;
|
|
445
|
-
const typed = event.currentTarget.value.trim();
|
|
446
|
-
if (!typed) return;
|
|
447
|
-
picked.current = true;
|
|
448
|
-
onPath(hostPath(typed));
|
|
449
|
-
}}
|
|
450
|
-
/>
|
|
451
|
-
</form>
|
|
452
|
-
<div {...stylex.props(popup.separator)} />
|
|
453
|
-
<Combobox.Empty className={cx(popup.empty)}>
|
|
454
|
-
{routesPending ? "Loading pages" : "No pages"}
|
|
455
|
-
</Combobox.Empty>
|
|
456
|
-
<Combobox.List className={cx(styles.routeList)}>
|
|
457
|
-
{(route: string) => (
|
|
458
|
-
<Combobox.Item
|
|
459
|
-
key={route}
|
|
460
|
-
value={route}
|
|
461
|
-
className={(state) =>
|
|
462
|
-
cx(
|
|
463
|
-
popup.item,
|
|
464
|
-
styles.routeItem,
|
|
465
|
-
state.highlighted && popup.itemHighlighted,
|
|
466
|
-
state.selected && popup.itemSelected,
|
|
467
|
-
)
|
|
468
|
-
}
|
|
469
|
-
>
|
|
470
|
-
{route}
|
|
471
|
-
</Combobox.Item>
|
|
472
|
-
)}
|
|
473
|
-
</Combobox.List>
|
|
474
|
-
</Combobox.Popup>
|
|
475
|
-
</Combobox.Positioner>
|
|
476
|
-
</Combobox.Portal>
|
|
477
|
-
</Combobox.Root>
|
|
478
|
-
<button
|
|
479
|
-
type="button"
|
|
480
|
-
aria-label="Open preview in a new tab"
|
|
481
|
-
disabled={!enabled}
|
|
482
|
-
onClick={onOpen}
|
|
483
|
-
{...stylex.props(styles.iconButton)}
|
|
484
|
-
>
|
|
485
|
-
<IconArrowUpRight size={14} ariaHidden />
|
|
486
|
-
</button>
|
|
487
|
-
</div>
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
323
|
function BootCard({
|
|
492
324
|
title,
|
|
493
325
|
steps,
|
|
@@ -920,7 +752,7 @@ export default function CodeSessionPage() {
|
|
|
920
752
|
live={live}
|
|
921
753
|
onReload={() => navigate(location)}
|
|
922
754
|
onOpen={() => void openInNewTab()}
|
|
923
|
-
routes={
|
|
755
|
+
routes={routesForContentFiles(models, fileList ?? [])}
|
|
924
756
|
routesPending={routesPending}
|
|
925
757
|
onOpenRoutes={openRoutes}
|
|
926
758
|
files={{
|
|
@@ -1161,76 +993,9 @@ const styles = stylex.create({
|
|
|
1161
993
|
backgroundColor: colors.bgSurface,
|
|
1162
994
|
boxShadow: "0 1px 2px rgba(0, 0, 0, 0.08)",
|
|
1163
995
|
},
|
|
1164
|
-
address: {
|
|
1165
|
-
display: "flex",
|
|
1166
|
-
alignItems: "center",
|
|
1167
|
-
gap: space.xs,
|
|
1168
|
-
minWidth: 0,
|
|
1169
|
-
},
|
|
1170
996
|
sizeSwitch: {
|
|
1171
997
|
justifySelf: "end",
|
|
1172
998
|
},
|
|
1173
|
-
addressTrigger: {
|
|
1174
|
-
display: "flex",
|
|
1175
|
-
flex: 1,
|
|
1176
|
-
alignItems: "center",
|
|
1177
|
-
gap: space.xs,
|
|
1178
|
-
minWidth: 0,
|
|
1179
|
-
height: "28px",
|
|
1180
|
-
paddingInline: space.sm,
|
|
1181
|
-
borderWidth: 0,
|
|
1182
|
-
borderRadius: "999px",
|
|
1183
|
-
font: "inherit",
|
|
1184
|
-
textAlign: "left",
|
|
1185
|
-
cursor: { default: "pointer", ":disabled": "default" },
|
|
1186
|
-
color: { default: colors.textMuted, ":disabled": colors.textMuted },
|
|
1187
|
-
backgroundColor: colors.bgPanelInset,
|
|
1188
|
-
},
|
|
1189
|
-
addressPath: {
|
|
1190
|
-
flex: 1,
|
|
1191
|
-
minWidth: 0,
|
|
1192
|
-
overflow: "hidden",
|
|
1193
|
-
textOverflow: "ellipsis",
|
|
1194
|
-
whiteSpace: "nowrap",
|
|
1195
|
-
fontFamily: type.mono,
|
|
1196
|
-
fontSize: type.xs,
|
|
1197
|
-
color: colors.text,
|
|
1198
|
-
},
|
|
1199
|
-
routeSearch: {
|
|
1200
|
-
fontFamily: type.mono,
|
|
1201
|
-
fontSize: type.xs,
|
|
1202
|
-
},
|
|
1203
|
-
routePopup: {
|
|
1204
|
-
width: "var(--anchor-width)",
|
|
1205
|
-
minWidth: "220px",
|
|
1206
|
-
maxHeight: "min(320px, var(--available-height))",
|
|
1207
|
-
display: "flex",
|
|
1208
|
-
flexDirection: "column",
|
|
1209
|
-
overflowY: "hidden",
|
|
1210
|
-
},
|
|
1211
|
-
routeList: {
|
|
1212
|
-
minHeight: 0,
|
|
1213
|
-
overflowY: "auto",
|
|
1214
|
-
},
|
|
1215
|
-
routeItem: {
|
|
1216
|
-
fontFamily: type.mono,
|
|
1217
|
-
},
|
|
1218
|
-
iconButton: {
|
|
1219
|
-
display: "inline-flex",
|
|
1220
|
-
alignItems: "center",
|
|
1221
|
-
justifyContent: "center",
|
|
1222
|
-
flexShrink: 0,
|
|
1223
|
-
width: "28px",
|
|
1224
|
-
height: "28px",
|
|
1225
|
-
borderWidth: 0,
|
|
1226
|
-
borderRadius: radius.sm,
|
|
1227
|
-
cursor: { default: "pointer", ":disabled": "default" },
|
|
1228
|
-
color: { default: colors.textMuted, ":disabled": colors.border },
|
|
1229
|
-
backgroundColor: {
|
|
1230
|
-
default: "transparent",
|
|
1231
|
-
[hover]: { default: null, ":hover:not(:disabled)": colors.bgHover },
|
|
1232
|
-
},
|
|
1233
|
-
},
|
|
1234
999
|
canvas: {
|
|
1235
1000
|
position: "relative",
|
|
1236
1001
|
display: "flex",
|