@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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// packages/studio/src/sign-in-link.ts
|
|
2
|
+
// A magic-link email opens `/sign-in/link` in the Studio, not the API's
|
|
3
|
+
// verify endpoint. Mail scanners open every link in a message, and the token
|
|
4
|
+
// works once, so only a click on that page spends it.
|
|
5
|
+
|
|
6
|
+
export function isSignInLinkPath(pathname: string): boolean {
|
|
7
|
+
return pathname.replace(/\/$/, "") === "/sign-in/link";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The API URL that spends the token, or null when the link has none. */
|
|
11
|
+
export function signInLinkVerifyUrl(
|
|
12
|
+
apiBase: string,
|
|
13
|
+
search: string,
|
|
14
|
+
studioOrigin: string,
|
|
15
|
+
): string | null {
|
|
16
|
+
const params = new URLSearchParams(search);
|
|
17
|
+
const token = params.get("token");
|
|
18
|
+
if (!token) return null;
|
|
19
|
+
const verify = new URL(`${apiBase}/api/auth/magic-link/verify`);
|
|
20
|
+
verify.searchParams.set("token", token);
|
|
21
|
+
// Without a callback better-auth answers JSON instead of redirecting.
|
|
22
|
+
verify.searchParams.set("callbackURL", params.get("callbackURL") || `${studioOrigin}/`);
|
|
23
|
+
for (const key of ["newUserCallbackURL", "errorCallbackURL"]) {
|
|
24
|
+
const value = params.get(key);
|
|
25
|
+
if (value) verify.searchParams.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
return verify.toString();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What to tell someone better-auth sent back with `?error=`. */
|
|
31
|
+
export function signInLinkError(code: string | null): string | null {
|
|
32
|
+
if (!code) return null;
|
|
33
|
+
if (code === "INVALID_TOKEN") {
|
|
34
|
+
return "This sign-in link has expired or was already used. Send yourself a new one.";
|
|
35
|
+
}
|
|
36
|
+
return "That sign-in link did not work. Send yourself a new one.";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The address without the error better-auth appended. */
|
|
40
|
+
export function withoutSignInLinkError(href: string): string {
|
|
41
|
+
const url = new URL(href);
|
|
42
|
+
url.searchParams.delete("error");
|
|
43
|
+
url.searchParams.delete("error_description");
|
|
44
|
+
return url.toString();
|
|
45
|
+
}
|
package/src/site-pointer.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type PointerGrab = {
|
|
|
10
10
|
blockType: string | null;
|
|
11
11
|
blockIndex: number | null;
|
|
12
12
|
quote: string;
|
|
13
|
+
/** Block prop the clicked text came from, when the page marks it with `data-backmatter-field`. */
|
|
14
|
+
field: string | null;
|
|
13
15
|
} & ElementOrigin;
|
|
14
16
|
|
|
15
17
|
const EMPTY_ORIGIN: ElementOrigin = {
|
|
@@ -29,6 +31,16 @@ function presentAttr(el: Element, name: string): string | null {
|
|
|
29
31
|
return value ? value : null;
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
const FIELD_NAME = /^[\w.$-]{1,80}$/;
|
|
35
|
+
|
|
36
|
+
/** The prop named by the nearest `data-backmatter-field`, inside the block when there is one. */
|
|
37
|
+
function fieldOf(target: Element, marker: Element | null): string | null {
|
|
38
|
+
const holder = target.closest("[data-backmatter-field]");
|
|
39
|
+
if (!holder || (marker && holder !== marker && !marker.contains(holder))) return null;
|
|
40
|
+
const name = holder.getAttribute("data-backmatter-field");
|
|
41
|
+
return name && FIELD_NAME.test(name) ? name : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
32
44
|
/** Resolve the block marker and visible text under a click. Clicks on the bar are ignored. */
|
|
33
45
|
export function grabAt(target: Element | null, bar: Element | null): PointerGrab | null {
|
|
34
46
|
if (!target) return null;
|
|
@@ -42,7 +54,7 @@ export function grabAt(target: Element | null, bar: Element | null): PointerGrab
|
|
|
42
54
|
const origin = readElementOrigin(target) ?? EMPTY_ORIGIN;
|
|
43
55
|
if (!marker) {
|
|
44
56
|
if (!quote && !origin.component && !origin.file) return null;
|
|
45
|
-
return { blockId: null, blockType: null, blockIndex: null, quote, ...origin };
|
|
57
|
+
return { blockId: null, blockType: null, blockIndex: null, quote, field: fieldOf(target, null), ...origin };
|
|
46
58
|
}
|
|
47
59
|
const indexRaw = marker.getAttribute("data-backmatter-index");
|
|
48
60
|
const blockIndex = indexRaw !== null && /^\d+$/.test(indexRaw) ? Number(indexRaw) : null;
|
|
@@ -51,6 +63,7 @@ export function grabAt(target: Element | null, bar: Element | null): PointerGrab
|
|
|
51
63
|
blockType: presentAttr(marker, "data-backmatter-type"),
|
|
52
64
|
blockIndex,
|
|
53
65
|
quote,
|
|
66
|
+
field: fieldOf(target, marker),
|
|
54
67
|
...origin,
|
|
55
68
|
};
|
|
56
69
|
}
|
package/src/site-widget.tsx
CHANGED
|
@@ -178,7 +178,12 @@ export function SiteWidget({
|
|
|
178
178
|
</TooltipProvider>
|
|
179
179
|
) : null}
|
|
180
180
|
{doc && publishOpen ? (
|
|
181
|
-
<div
|
|
181
|
+
<div
|
|
182
|
+
role="dialog"
|
|
183
|
+
aria-label="Publish"
|
|
184
|
+
data-backmatter-panel=""
|
|
185
|
+
style={publishPanelStyle(publishAnchor)}
|
|
186
|
+
>
|
|
182
187
|
<EmbedPublishPage
|
|
183
188
|
workspaceId={doc.workspaceId}
|
|
184
189
|
onStatus={({ changeCount: count }) => setChangeCount(count)}
|
|
@@ -325,6 +330,9 @@ function SitePointer({ doc }: { doc: SiteWidgetDoc }) {
|
|
|
325
330
|
return null;
|
|
326
331
|
}
|
|
327
332
|
|
|
333
|
+
// Inline so the panel keeps its look on any host, even if the widget stylesheet
|
|
334
|
+
// is missing or stale. The text color is set here so panel text never inherits
|
|
335
|
+
// the host page's color (white text on a dark site would vanish on this white panel).
|
|
328
336
|
function publishPanelStyle(anchor: DOMRect | null): CSSProperties {
|
|
329
337
|
const insetRight = anchor
|
|
330
338
|
? Math.max(16, window.innerWidth - anchor.right)
|
|
@@ -343,6 +351,9 @@ function publishPanelStyle(anchor: DOMRect | null): CSSProperties {
|
|
|
343
351
|
border: "1px solid #e4e4e7",
|
|
344
352
|
borderRadius: 12,
|
|
345
353
|
background: "#ffffff",
|
|
354
|
+
color: "#18181b",
|
|
355
|
+
colorScheme: "light",
|
|
356
|
+
fontFamily: '"Geist Sans", Geist, ui-sans-serif, system-ui, sans-serif',
|
|
346
357
|
boxShadow: "0 16px 40px rgba(24, 24, 27, 0.14), 0 2px 8px rgba(24, 24, 27, 0.06)",
|
|
347
358
|
};
|
|
348
359
|
}
|
package/src/ui/Field.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// packages/studio/src/ui/Field.tsx
|
|
2
|
+
import { useId } from "react";
|
|
2
3
|
import * as stylex from "@stylexjs/stylex";
|
|
3
4
|
import { colors, space, type } from "../styles/tokens.stylex";
|
|
4
5
|
|
|
@@ -21,6 +22,31 @@ export function Field({
|
|
|
21
22
|
);
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* `Field` for a composite control (an object or a list) that holds its own
|
|
27
|
+
* labeled inputs. A group, not a `<label>`, so its children keep their labels.
|
|
28
|
+
*/
|
|
29
|
+
export function FieldGroup({
|
|
30
|
+
label,
|
|
31
|
+
hint,
|
|
32
|
+
children,
|
|
33
|
+
}: {
|
|
34
|
+
label: string;
|
|
35
|
+
hint?: React.ReactNode;
|
|
36
|
+
children: React.ReactNode;
|
|
37
|
+
}) {
|
|
38
|
+
const labelId = useId();
|
|
39
|
+
return (
|
|
40
|
+
<div role="group" aria-labelledby={labelId} {...stylex.props(styles.field)}>
|
|
41
|
+
<span id={labelId} {...stylex.props(styles.label)}>
|
|
42
|
+
{label}
|
|
43
|
+
</span>
|
|
44
|
+
{children}
|
|
45
|
+
{hint ? <span {...stylex.props(styles.hint)}>{hint}</span> : null}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
24
50
|
/**
|
|
25
51
|
* A label forwards a click on its plain content to its first labelable descendant.
|
|
26
52
|
* In a composite control that is an arbitrary button, such as a gallery's first remove button.
|
package/src/ui/Input.tsx
CHANGED
|
@@ -13,7 +13,47 @@ export function Input(props: Props) {
|
|
|
13
13
|
return <BaseInput {...stylex.props(styles.input, styles.inputFocus)} {...props} />;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export type SelectOption = {
|
|
16
|
+
export type SelectOption = {
|
|
17
|
+
value: string;
|
|
18
|
+
label: string;
|
|
19
|
+
/** A muted second line under the label, such as a route. Searched too. */
|
|
20
|
+
description?: string;
|
|
21
|
+
/** Options sharing a group sit under its heading. Options with none come first. */
|
|
22
|
+
group?: string;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type OptionGroup = { value: string; items: SelectOption[] };
|
|
27
|
+
|
|
28
|
+
/** Groups in order of first appearance, with ungrouped options first. */
|
|
29
|
+
function groupOptions(options: SelectOption[]): OptionGroup[] {
|
|
30
|
+
const groups = new Map<string, SelectOption[]>();
|
|
31
|
+
for (const option of options) {
|
|
32
|
+
const key = option.group ?? "";
|
|
33
|
+
const list = groups.get(key);
|
|
34
|
+
if (list) list.push(option);
|
|
35
|
+
else groups.set(key, [option]);
|
|
36
|
+
}
|
|
37
|
+
const ungrouped = groups.get("");
|
|
38
|
+
groups.delete("");
|
|
39
|
+
const ordered = [...groups.entries()].map(([value, items]) => ({ value, items }));
|
|
40
|
+
return ungrouped ? [{ value: "", items: ungrouped }, ...ordered] : ordered;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function OptionText({ option }: { option: SelectOption }) {
|
|
44
|
+
return (
|
|
45
|
+
<span {...stylex.props(styles.optionText)}>
|
|
46
|
+
<span data-select-option-label="" {...stylex.props(styles.optionLabel)}>
|
|
47
|
+
{option.label}
|
|
48
|
+
</span>
|
|
49
|
+
{option.description ? (
|
|
50
|
+
<span data-select-option-description="" {...stylex.props(styles.optionDescription)}>
|
|
51
|
+
{option.description}
|
|
52
|
+
</span>
|
|
53
|
+
) : null}
|
|
54
|
+
</span>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
17
57
|
|
|
18
58
|
type SelectProps = {
|
|
19
59
|
options: SelectOption[];
|
|
@@ -41,7 +81,11 @@ export function Select(props: SelectProps) {
|
|
|
41
81
|
function matchesQuery(option: SelectOption, query: string) {
|
|
42
82
|
const q = query.trim().toLowerCase();
|
|
43
83
|
if (!q) return true;
|
|
44
|
-
return
|
|
84
|
+
return (
|
|
85
|
+
option.label.toLowerCase().includes(q) ||
|
|
86
|
+
option.value.toLowerCase().includes(q) ||
|
|
87
|
+
(option.description?.toLowerCase().includes(q) ?? false)
|
|
88
|
+
);
|
|
45
89
|
}
|
|
46
90
|
|
|
47
91
|
function FilterSelect({
|
|
@@ -58,6 +102,30 @@ function FilterSelect({
|
|
|
58
102
|
}: SelectProps) {
|
|
59
103
|
const selected = options.find((opt) => opt.value === value) ?? null;
|
|
60
104
|
const [open, setOpen] = useState(false);
|
|
105
|
+
const grouped = options.some((opt) => opt.group !== undefined);
|
|
106
|
+
const renderItem = (opt: SelectOption) => (
|
|
107
|
+
<Combobox.Item
|
|
108
|
+
key={opt.value}
|
|
109
|
+
value={opt}
|
|
110
|
+
disabled={opt.disabled}
|
|
111
|
+
data-no-ring=""
|
|
112
|
+
className={(state) =>
|
|
113
|
+
cx(
|
|
114
|
+
popup.item,
|
|
115
|
+
state.highlighted && popup.itemHighlighted,
|
|
116
|
+
state.selected && popup.itemSelected,
|
|
117
|
+
state.disabled && popup.itemDisabled,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
>
|
|
121
|
+
<span {...stylex.props(popup.itemIndicator)}>
|
|
122
|
+
<Combobox.ItemIndicator>
|
|
123
|
+
<CheckIcon />
|
|
124
|
+
</Combobox.ItemIndicator>
|
|
125
|
+
</span>
|
|
126
|
+
<OptionText option={opt} />
|
|
127
|
+
</Combobox.Item>
|
|
128
|
+
);
|
|
61
129
|
const clear = (event: { preventDefault: () => void; stopPropagation: () => void }) => {
|
|
62
130
|
event.preventDefault();
|
|
63
131
|
event.stopPropagation();
|
|
@@ -65,7 +133,7 @@ function FilterSelect({
|
|
|
65
133
|
};
|
|
66
134
|
return (
|
|
67
135
|
<Combobox.Root
|
|
68
|
-
items={options}
|
|
136
|
+
items={grouped ? groupOptions(options) : options}
|
|
69
137
|
value={selected}
|
|
70
138
|
name={name}
|
|
71
139
|
disabled={disabled}
|
|
@@ -79,6 +147,9 @@ function FilterSelect({
|
|
|
79
147
|
{chip && selected ? (
|
|
80
148
|
<span {...stylex.props(styles.chip)}>
|
|
81
149
|
<span {...stylex.props(styles.chipLabel)}>{selected.label}</span>
|
|
150
|
+
{selected.description ? (
|
|
151
|
+
<span {...stylex.props(styles.chipDescription)}>{selected.description}</span>
|
|
152
|
+
) : null}
|
|
82
153
|
</span>
|
|
83
154
|
) : (
|
|
84
155
|
<Combobox.Value>
|
|
@@ -149,37 +220,18 @@ function FilterSelect({
|
|
|
149
220
|
/>
|
|
150
221
|
<Combobox.Empty className={cx(popup.empty)}>No matches</Combobox.Empty>
|
|
151
222
|
<Combobox.List>
|
|
152
|
-
{
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
>
|
|
167
|
-
<span {...stylex.props(popup.itemIndicator)}>
|
|
168
|
-
<Combobox.ItemIndicator>
|
|
169
|
-
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden>
|
|
170
|
-
<path
|
|
171
|
-
d="M3.5 8.5 6.5 11.5 12.5 4.5"
|
|
172
|
-
stroke="currentColor"
|
|
173
|
-
strokeWidth="1.5"
|
|
174
|
-
strokeLinecap="round"
|
|
175
|
-
strokeLinejoin="round"
|
|
176
|
-
/>
|
|
177
|
-
</svg>
|
|
178
|
-
</Combobox.ItemIndicator>
|
|
179
|
-
</span>
|
|
180
|
-
{opt.label}
|
|
181
|
-
</Combobox.Item>
|
|
182
|
-
)}
|
|
223
|
+
{grouped
|
|
224
|
+
? (group: OptionGroup) => (
|
|
225
|
+
<Combobox.Group key={group.value} items={group.items}>
|
|
226
|
+
{group.value ? (
|
|
227
|
+
<Combobox.GroupLabel data-select-group-label="" className={cx(popup.groupLabel)}>
|
|
228
|
+
{group.value}
|
|
229
|
+
</Combobox.GroupLabel>
|
|
230
|
+
) : null}
|
|
231
|
+
<Combobox.Collection>{renderItem}</Combobox.Collection>
|
|
232
|
+
</Combobox.Group>
|
|
233
|
+
)
|
|
234
|
+
: renderItem}
|
|
183
235
|
</Combobox.List>
|
|
184
236
|
</Combobox.Popup>
|
|
185
237
|
</Combobox.Positioner>
|
|
@@ -300,7 +352,9 @@ function ListSelect({
|
|
|
300
352
|
</svg>
|
|
301
353
|
</BaseSelect.ItemIndicator>
|
|
302
354
|
</span>
|
|
303
|
-
<BaseSelect.ItemText>
|
|
355
|
+
<BaseSelect.ItemText>
|
|
356
|
+
<OptionText option={opt} />
|
|
357
|
+
</BaseSelect.ItemText>
|
|
304
358
|
</BaseSelect.Item>
|
|
305
359
|
))}
|
|
306
360
|
</BaseSelect.List>
|
|
@@ -311,6 +365,20 @@ function ListSelect({
|
|
|
311
365
|
);
|
|
312
366
|
}
|
|
313
367
|
|
|
368
|
+
function CheckIcon() {
|
|
369
|
+
return (
|
|
370
|
+
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden>
|
|
371
|
+
<path
|
|
372
|
+
d="M3.5 8.5 6.5 11.5 12.5 4.5"
|
|
373
|
+
stroke="currentColor"
|
|
374
|
+
strokeWidth="1.5"
|
|
375
|
+
strokeLinecap="round"
|
|
376
|
+
strokeLinejoin="round"
|
|
377
|
+
/>
|
|
378
|
+
</svg>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
314
382
|
export function Textarea({
|
|
315
383
|
mono,
|
|
316
384
|
...props
|
|
@@ -392,6 +460,15 @@ const styles = stylex.create({
|
|
|
392
460
|
textOverflow: "ellipsis",
|
|
393
461
|
whiteSpace: "nowrap",
|
|
394
462
|
},
|
|
463
|
+
chipDescription: {
|
|
464
|
+
minWidth: 0,
|
|
465
|
+
// The route gives up its room before the title does.
|
|
466
|
+
flexShrink: 3,
|
|
467
|
+
overflow: "hidden",
|
|
468
|
+
textOverflow: "ellipsis",
|
|
469
|
+
whiteSpace: "nowrap",
|
|
470
|
+
color: colors.textMuted,
|
|
471
|
+
},
|
|
395
472
|
selectActions: {
|
|
396
473
|
display: "inline-flex",
|
|
397
474
|
alignItems: "center",
|
|
@@ -422,6 +499,28 @@ const styles = stylex.create({
|
|
|
422
499
|
},
|
|
423
500
|
selectPopup: {
|
|
424
501
|
minWidth: "var(--anchor-width)",
|
|
502
|
+
// Long labels truncate instead of stretching the menu across the window.
|
|
503
|
+
maxWidth: "min(max(var(--anchor-width), 24rem), var(--available-width))",
|
|
504
|
+
maxHeight: "min(var(--available-height), 24rem)",
|
|
505
|
+
},
|
|
506
|
+
optionText: {
|
|
507
|
+
flex: 1,
|
|
508
|
+
display: "flex",
|
|
509
|
+
flexDirection: "column",
|
|
510
|
+
minWidth: 0,
|
|
511
|
+
gap: 1,
|
|
512
|
+
},
|
|
513
|
+
optionLabel: {
|
|
514
|
+
overflow: "hidden",
|
|
515
|
+
textOverflow: "ellipsis",
|
|
516
|
+
whiteSpace: "nowrap",
|
|
517
|
+
},
|
|
518
|
+
optionDescription: {
|
|
519
|
+
overflow: "hidden",
|
|
520
|
+
textOverflow: "ellipsis",
|
|
521
|
+
whiteSpace: "nowrap",
|
|
522
|
+
fontSize: type.xs,
|
|
523
|
+
color: colors.textMuted,
|
|
425
524
|
},
|
|
426
525
|
textarea: {
|
|
427
526
|
minHeight: "8rem",
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// packages/studio/src/workspace/schema-source.tsx
|
|
2
|
+
//
|
|
3
|
+
// Where the schema snapshot behind the current branch came from: the branch it
|
|
4
|
+
// was imported from, when, and which source files failed to evaluate. A block
|
|
5
|
+
// whose file fails is missing or stale in the picker; this says why.
|
|
6
|
+
import { createContext, useContext } from "react";
|
|
7
|
+
import * as stylex from "@stylexjs/stylex";
|
|
8
|
+
import type { SchemaFailure } from "../api";
|
|
9
|
+
import { commitAge } from "../pages/home-rows";
|
|
10
|
+
import { colors, radius, space, type } from "../styles/tokens.stylex";
|
|
11
|
+
|
|
12
|
+
export type SchemaSource = {
|
|
13
|
+
branch?: string;
|
|
14
|
+
/** ISO time the snapshot was written. */
|
|
15
|
+
createdAt?: string;
|
|
16
|
+
failures: SchemaFailure[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const SchemaSourceContext = createContext<SchemaSource | null>(null);
|
|
20
|
+
|
|
21
|
+
export const SchemaSourceProvider = SchemaSourceContext.Provider;
|
|
22
|
+
|
|
23
|
+
export function useSchemaSource(): SchemaSource | null {
|
|
24
|
+
return useContext(SchemaSourceContext);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Failures of `blocks/` and `richtext/` definition files. */
|
|
28
|
+
export function blockFailures(source: SchemaSource | null): SchemaFailure[] {
|
|
29
|
+
return (source?.failures ?? []).filter((failure) =>
|
|
30
|
+
/(^|\/)(blocks|richtext)\//.test(failure.path),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** "main · 2h ago". Empty when the snapshot names neither. */
|
|
35
|
+
export function schemaSourceLabel(source: SchemaSource | null, now = Date.now()): string {
|
|
36
|
+
if (!source) return "";
|
|
37
|
+
const age = source.createdAt ? commitAge(source.createdAt, now) : "";
|
|
38
|
+
return [source.branch, age].filter(Boolean).join(" · ");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function SchemaSourceNote({ source }: { source: SchemaSource | null }) {
|
|
42
|
+
const label = schemaSourceLabel(source);
|
|
43
|
+
if (!label) return null;
|
|
44
|
+
const title = source?.createdAt
|
|
45
|
+
? `Schema snapshot imported from ${source.branch ?? "the repository"} at ${new Date(source.createdAt).toLocaleString()}`
|
|
46
|
+
: undefined;
|
|
47
|
+
return (
|
|
48
|
+
<span data-schema-source="" title={title} {...stylex.props(styles.note)}>
|
|
49
|
+
{label}
|
|
50
|
+
</span>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function SchemaFailureList({
|
|
55
|
+
failures,
|
|
56
|
+
title,
|
|
57
|
+
}: {
|
|
58
|
+
failures: SchemaFailure[];
|
|
59
|
+
title: string;
|
|
60
|
+
}) {
|
|
61
|
+
if (failures.length === 0) return null;
|
|
62
|
+
return (
|
|
63
|
+
<div role="status" data-schema-failures="" {...stylex.props(styles.failures)}>
|
|
64
|
+
<span {...stylex.props(styles.failuresTitle)}>{title}</span>
|
|
65
|
+
<ul {...stylex.props(styles.list)}>
|
|
66
|
+
{failures.map((failure) => (
|
|
67
|
+
<li key={failure.path} {...stylex.props(styles.item)}>
|
|
68
|
+
<code {...stylex.props(styles.path)}>{failure.path}</code>
|
|
69
|
+
<span {...stylex.props(styles.message)}>{failure.message}</span>
|
|
70
|
+
</li>
|
|
71
|
+
))}
|
|
72
|
+
</ul>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const styles = stylex.create({
|
|
78
|
+
note: {
|
|
79
|
+
color: colors.textMuted,
|
|
80
|
+
fontFamily: type.mono,
|
|
81
|
+
fontSize: type.xs,
|
|
82
|
+
whiteSpace: "nowrap",
|
|
83
|
+
},
|
|
84
|
+
failures: {
|
|
85
|
+
display: "flex",
|
|
86
|
+
flexDirection: "column",
|
|
87
|
+
gap: space.xs,
|
|
88
|
+
paddingBlock: space.sm,
|
|
89
|
+
paddingInline: space.md,
|
|
90
|
+
borderWidth: 1,
|
|
91
|
+
borderStyle: "solid",
|
|
92
|
+
borderColor: colors.border,
|
|
93
|
+
borderInlineStartWidth: 2,
|
|
94
|
+
borderInlineStartColor: colors.danger,
|
|
95
|
+
borderRadius: radius.md,
|
|
96
|
+
fontSize: type.sm,
|
|
97
|
+
},
|
|
98
|
+
failuresTitle: {
|
|
99
|
+
color: colors.danger,
|
|
100
|
+
fontWeight: 500,
|
|
101
|
+
},
|
|
102
|
+
list: {
|
|
103
|
+
display: "flex",
|
|
104
|
+
flexDirection: "column",
|
|
105
|
+
gap: space.xs,
|
|
106
|
+
margin: 0,
|
|
107
|
+
padding: 0,
|
|
108
|
+
listStyle: "none",
|
|
109
|
+
},
|
|
110
|
+
item: {
|
|
111
|
+
display: "flex",
|
|
112
|
+
flexDirection: "column",
|
|
113
|
+
gap: "2px",
|
|
114
|
+
minWidth: 0,
|
|
115
|
+
},
|
|
116
|
+
path: {
|
|
117
|
+
fontFamily: type.mono,
|
|
118
|
+
fontSize: type.xs,
|
|
119
|
+
color: colors.text,
|
|
120
|
+
},
|
|
121
|
+
message: {
|
|
122
|
+
color: colors.textMuted,
|
|
123
|
+
fontSize: type.xs,
|
|
124
|
+
overflowWrap: "anywhere",
|
|
125
|
+
},
|
|
126
|
+
});
|