@vectoriox/iox-ui 5.111.0 → 5.113.0
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/assist-core/index.d.ts +650 -0
- package/assist-core/package.json +3 -0
- package/design-core/index.d.ts +80 -0
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +1144 -0
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -0
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +94 -0
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +103 -43
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/generation-core/index.d.ts +20 -47
- package/package.json +5 -1
- package/src/assist-core/assist-locale.ts +73 -0
- package/src/assist-core/assist-turn.ts +240 -0
- package/src/assist-core/brief.ts +98 -0
- package/src/assist-core/budget.ts +34 -0
- package/src/assist-core/content-fields.ts +256 -0
- package/src/assist-core/field-edits.ts +178 -0
- package/src/assist-core/field-values.ts +42 -0
- package/src/assist-core/fields-schema.ts +117 -0
- package/src/assist-core/public-api.ts +24 -0
- package/src/assist-core/rich-text.ts +32 -0
- package/src/assist-core/route-schema.ts +49 -0
- package/src/assist-core/summarize-item.ts +219 -0
- package/src/assist-core/surfaces.ts +235 -0
- package/src/design-core/flavor-spec.generated.ts +94 -0
- package/src/generation-core/ai-run.ts +34 -0
- package/src/generation-core/compose-layout.ts +57 -18
- package/src/generation-core/plan-words.ts +12 -3
- package/src/generation-core/site-spec.generated.ts +1 -22
- package/styles/iox-design.css +39 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsonAnyOf, jsonClosedObject, jsonListOf, jsonOneOf, JsonSchema, jsonText } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
|
|
3
|
+
import { assertAssistBudget, MAX_ROUTE_PROPERTIES } from './budget';
|
|
4
|
+
import { AssistIssue, AssistIssueCode } from './brief';
|
|
5
|
+
import { AssistSurface, EditFamily, SURFACES } from './surfaces';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The route request (plan §3c rule 5): the first, small, fast question of every turn — which of THIS surface's
|
|
9
|
+
* families the sentence needs, or `cannot` with one line for the owner. Its family enum is the surface's, so the model
|
|
10
|
+
* cannot route a content-item sentence to the builder's Style.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export enum RouteAnswerKey {
|
|
14
|
+
Families = 'families',
|
|
15
|
+
Cannot = 'cannot',
|
|
16
|
+
Reply = 'reply',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function routeJsonSchema(surface: AssistSurface): JsonSchema {
|
|
20
|
+
const schema = jsonClosedObject({
|
|
21
|
+
[RouteAnswerKey.Families]: { ...jsonListOf(jsonOneOf(SURFACES[surface].families)), description: 'The kinds of change the sentence asks for, in the order to make them. [] when it cannot be done here.' },
|
|
22
|
+
[RouteAnswerKey.Cannot]: { ...jsonAnyOf([jsonText(), { type: 'null' }]), description: 'Why it cannot be done here, in one line in the sentence\'s language — or null.' },
|
|
23
|
+
[RouteAnswerKey.Reply]: { ...jsonText(), description: 'One short line to the owner, in the sentence\'s language.' },
|
|
24
|
+
}, Object.values(RouteAnswerKey));
|
|
25
|
+
assertAssistBudget(`route ${surface}`, [schema], MAX_ROUTE_PROPERTIES);
|
|
26
|
+
return schema;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AssistRoute {
|
|
30
|
+
readonly ok: boolean;
|
|
31
|
+
readonly families: ReadonlyArray<EditFamily>;
|
|
32
|
+
readonly cannot: string | null;
|
|
33
|
+
readonly reply: string;
|
|
34
|
+
readonly issues: ReadonlyArray<AssistIssue>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const text = (v: unknown): string => (typeof v === 'string' ? v.trim() : '');
|
|
38
|
+
|
|
39
|
+
/** A route answer, checked against its surface: a family the surface does not have is refused, repeats dropped. */
|
|
40
|
+
export function readRoute(surface: AssistSurface, answer: unknown): AssistRoute {
|
|
41
|
+
const a = (answer && typeof answer === 'object' ? answer : {}) as Record<string, unknown>;
|
|
42
|
+
const allowed = new Set<string>(SURFACES[surface].families);
|
|
43
|
+
const named = Array.isArray(a[RouteAnswerKey.Families]) ? (a[RouteAnswerKey.Families] as unknown[]).map(String) : [];
|
|
44
|
+
const issues: AssistIssue[] = named.filter(f => !allowed.has(f))
|
|
45
|
+
.map(f => ({ code: AssistIssueCode.UnknownFamily, message: `"${f}" is not a family of ${surface}` }));
|
|
46
|
+
const families = [...new Set(named.filter(f => allowed.has(f)))] as EditFamily[];
|
|
47
|
+
const cannot = text(a[RouteAnswerKey.Cannot]) || null;
|
|
48
|
+
return { ok: !issues.length, families: cannot ? [] : families, cannot, reply: text(a[RouteAnswerKey.Reply]), issues };
|
|
49
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, MEMORY_TURNS } from './budget';
|
|
2
|
+
import { AssistBriefError, AssistIssueCode, Brief, FIELD_HANDLE_PREFIX, HandleMap, HandleTarget, NeverWrite, SIBLING_HANDLE_PREFIX } from './brief';
|
|
3
|
+
import { AssistField, AssistFieldKind, assistFields, ContentTypeSchema, isWritable, NeverWriteReason, titleField } from './content-fields';
|
|
4
|
+
import { BriefValue, isEmptyFieldValue, readFieldValue, readLocaleValues } from './field-values';
|
|
5
|
+
import { AssistScope, AssistSurface, SURFACES } from './surfaces';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The brief of surface S2 — one content item (plan §3c, §4 S2). Focus = the item (every field as a handle `f.<key>`,
|
|
9
|
+
* its kind, label, full value, which locales a multiLang field has filled) or ONE field when the owner opened the
|
|
10
|
+
* field's sparkle; around = the rest of the item (when the focus is a field) and up to five sibling items of the type,
|
|
11
|
+
* each value clipped to 160 characters — examples of the studio's voice, never something to copy.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type ContentRecord = Readonly<Record<string, unknown>>;
|
|
15
|
+
|
|
16
|
+
export interface ItemBriefField {
|
|
17
|
+
readonly handle: string;
|
|
18
|
+
readonly label: string;
|
|
19
|
+
readonly kind: AssistFieldKind;
|
|
20
|
+
readonly required: boolean;
|
|
21
|
+
/** In the write locale for a multiLang field. */
|
|
22
|
+
readonly empty: boolean;
|
|
23
|
+
/** Absent on a never-written field: the model only learns whether it is filled. */
|
|
24
|
+
readonly value?: BriefValue;
|
|
25
|
+
readonly options?: ReadonlyArray<string>;
|
|
26
|
+
readonly locales?: { readonly filled: ReadonlyArray<string>; readonly empty: ReadonlyArray<string> };
|
|
27
|
+
readonly never?: NeverWriteReason;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ItemFocus {
|
|
31
|
+
readonly scope: AssistScope;
|
|
32
|
+
readonly type: { readonly name: string; readonly label: string };
|
|
33
|
+
/** The item's name as the list shows it ('' for a new item). */
|
|
34
|
+
readonly title: string;
|
|
35
|
+
/** The `@title` field's handle, when the type has one. */
|
|
36
|
+
readonly titleHandle: string | null;
|
|
37
|
+
readonly fields: ReadonlyArray<ItemBriefField>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ItemSummary {
|
|
41
|
+
readonly handle: string;
|
|
42
|
+
readonly title: string;
|
|
43
|
+
/** handle → value, ≤ 160 characters. */
|
|
44
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ItemAround {
|
|
48
|
+
/** The item's other fields, summarised — only when the focus is one field. */
|
|
49
|
+
readonly item: Readonly<Record<string, string>> | null;
|
|
50
|
+
readonly siblings: ReadonlyArray<ItemSummary>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type ItemBrief = Brief<ItemFocus, ItemAround>;
|
|
54
|
+
|
|
55
|
+
export interface ItemBriefContext {
|
|
56
|
+
/** The locale the turn writes in. */
|
|
57
|
+
readonly locale: string;
|
|
58
|
+
/** One field's key or handle: the per-field sparkle. */
|
|
59
|
+
readonly focusField?: string;
|
|
60
|
+
/** Other items of the type (the item itself is skipped); the first five are sent. */
|
|
61
|
+
readonly siblings?: ReadonlyArray<ContentRecord>;
|
|
62
|
+
readonly owner?: string | null;
|
|
63
|
+
readonly memory?: ReadonlyArray<string>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface SummarizedItem {
|
|
67
|
+
readonly brief: ItemBrief;
|
|
68
|
+
readonly handles: HandleMap;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const ID_KEY = '_id';
|
|
72
|
+
const ELLIPSIS = '…';
|
|
73
|
+
const LIST_JOIN = ', ';
|
|
74
|
+
const PARAGRAPH_JOIN = '\n\n';
|
|
75
|
+
|
|
76
|
+
const TEXT_KINDS: ReadonlySet<AssistFieldKind> = new Set([AssistFieldKind.Text, AssistFieldKind.Textarea, AssistFieldKind.RichText]);
|
|
77
|
+
|
|
78
|
+
export const clipText = (text: string, max: number = AROUND_TEXT_CHARS): string =>
|
|
79
|
+
text.length <= max ? text : `${text.slice(0, max - ELLIPSIS.length).trimEnd()}${ELLIPSIS}`;
|
|
80
|
+
|
|
81
|
+
function briefField(field: AssistField, raw: unknown, locale: string): ItemBriefField {
|
|
82
|
+
const base = { handle: field.handle, label: field.label, kind: field.kind, required: field.required };
|
|
83
|
+
if (field.never) return { ...base, empty: isEmptyFieldValue(raw), never: field.never };
|
|
84
|
+
const options = field.options ? { options: field.options } : {};
|
|
85
|
+
if (field.locales) {
|
|
86
|
+
const values = readLocaleValues(field.kind, field.locales, raw);
|
|
87
|
+
const filled = field.locales.filter(l => !isEmptyFieldValue(values[l]));
|
|
88
|
+
return {
|
|
89
|
+
...base, ...options,
|
|
90
|
+
empty: isEmptyFieldValue(values[locale]),
|
|
91
|
+
value: values as Record<string, string | ReadonlyArray<string>>,
|
|
92
|
+
locales: { filled, empty: field.locales.filter(l => !filled.includes(l)) },
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const value = readFieldValue(field.kind, raw);
|
|
96
|
+
return { ...base, ...options, empty: isEmptyFieldValue(value), value };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const localeOrFirst = (values: Record<string, BriefValue>, locale: string): BriefValue =>
|
|
100
|
+
!isEmptyFieldValue(values[locale]) ? values[locale] : Object.values(values).find(v => !isEmptyFieldValue(v)) ?? null;
|
|
101
|
+
|
|
102
|
+
/** A value as one clipped line: the write locale first (else the first filled one), paragraphs and lists joined. */
|
|
103
|
+
function summaryText(field: AssistField, raw: unknown, locale: string): string {
|
|
104
|
+
const value = field.locales ? localeOrFirst(readLocaleValues(field.kind, field.locales, raw), locale) : readFieldValue(field.kind, raw);
|
|
105
|
+
if (value === null) return '';
|
|
106
|
+
const text = Array.isArray(value) ? value.join(field.kind === AssistFieldKind.RichText ? PARAGRAPH_JOIN : LIST_JOIN) : String(value);
|
|
107
|
+
return clipText(text.replace(/\s+/g, ' ').trim());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function summaries(fields: ReadonlyArray<AssistField>, record: ContentRecord, locale: string): Record<string, string> {
|
|
111
|
+
return Object.fromEntries(fields
|
|
112
|
+
.map(f => [f.handle, summaryText(f, record[f.key], locale)] as const)
|
|
113
|
+
.filter(([, text]) => text !== ''));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function findFocusField(fields: ReadonlyArray<AssistField>, focus: string): AssistField {
|
|
117
|
+
const found = fields.find(f => f.key === focus || f.handle === focus || f.handle === `${FIELD_HANDLE_PREFIX}${focus}`);
|
|
118
|
+
if (!found) throw new AssistBriefError(AssistIssueCode.UnknownHandle, `"${focus}" is not a field of this type`);
|
|
119
|
+
return found;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const neverList = (fields: ReadonlyArray<AssistField>): NeverWrite[] =>
|
|
123
|
+
fields.filter(f => f.never).map(f => ({ handle: f.handle, label: f.label, reason: f.never as string }));
|
|
124
|
+
|
|
125
|
+
function siblingsOf(record: ContentRecord, siblings: ReadonlyArray<ContentRecord>): ContentRecord[] {
|
|
126
|
+
const own = record[ID_KEY];
|
|
127
|
+
return siblings.filter(s => own === undefined || s[ID_KEY] !== own).slice(0, AROUND_ITEMS_MAX);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** S2's brief and its handle map: `f.<key>` per field, `s<n>` per sibling (its id stays in the map, never sent). */
|
|
131
|
+
export function summarizeItem(schema: ContentTypeSchema, item: ContentRecord, ctx: ItemBriefContext): SummarizedItem {
|
|
132
|
+
const fields = assistFields(schema);
|
|
133
|
+
const focused = ctx.focusField ? findFocusField(fields, ctx.focusField) : null;
|
|
134
|
+
const title = titleField(schema, fields);
|
|
135
|
+
const voiceFields = fields.filter(f => isWritable(f) && TEXT_KINDS.has(f.kind));
|
|
136
|
+
const siblings = siblingsOf(item, ctx.siblings ?? []);
|
|
137
|
+
const siblingHandle = (i: number) => `${SIBLING_HANDLE_PREFIX}${i + 1}`;
|
|
138
|
+
const surface = SURFACES[AssistSurface.ContentItem];
|
|
139
|
+
const scope = focused ? AssistScope.Field : AssistScope.Item;
|
|
140
|
+
|
|
141
|
+
const handles: Record<string, HandleTarget> = Object.fromEntries([
|
|
142
|
+
...fields.map(f => [f.handle, { key: f.key, path: [f.key] }] as const),
|
|
143
|
+
...siblings.map((s, i) => [siblingHandle(i), { key: siblingHandle(i), path: [], ...(s[ID_KEY] !== undefined ? { id: String(s[ID_KEY]) } : {}) }] as const),
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
const brief: ItemBrief = {
|
|
147
|
+
surface: AssistSurface.ContentItem,
|
|
148
|
+
focus: {
|
|
149
|
+
scope,
|
|
150
|
+
type: { name: schema.name, label: schema.metaData?.label || schema.name },
|
|
151
|
+
title: title ? summaryText(title, item[title.key], ctx.locale) : '',
|
|
152
|
+
titleHandle: title?.handle ?? null,
|
|
153
|
+
fields: (focused ? [focused] : fields).map(f => briefField(f, item[f.key], ctx.locale)),
|
|
154
|
+
},
|
|
155
|
+
around: {
|
|
156
|
+
item: focused ? summaries(fields.filter(f => f !== focused && isWritable(f)), item, ctx.locale) : null,
|
|
157
|
+
siblings: siblings.map((s, i) => ({
|
|
158
|
+
handle: siblingHandle(i),
|
|
159
|
+
title: title ? summaryText(title, s[title.key], ctx.locale) : '',
|
|
160
|
+
fields: summaries(voiceFields, s, ctx.locale),
|
|
161
|
+
})),
|
|
162
|
+
},
|
|
163
|
+
owner: ctx.owner ?? null,
|
|
164
|
+
rules: {
|
|
165
|
+
families: surface.families,
|
|
166
|
+
locale: ctx.locale,
|
|
167
|
+
never: neverList(fields),
|
|
168
|
+
scope,
|
|
169
|
+
widensTo: surface.scopes.slice(surface.scopes.indexOf(scope) + 1),
|
|
170
|
+
},
|
|
171
|
+
memory: (ctx.memory ?? []).slice(-MEMORY_TURNS),
|
|
172
|
+
};
|
|
173
|
+
return { brief, handles };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export enum ItemSuggestionKind {
|
|
177
|
+
FillEmpty = 'fillEmpty',
|
|
178
|
+
Translate = 'translate',
|
|
179
|
+
Shorten = 'shorten',
|
|
180
|
+
WriteSeo = 'writeSeo',
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** A quick action the box offers, built from the brief (never canned text — the client words it). */
|
|
184
|
+
export interface ItemSuggestion {
|
|
185
|
+
readonly kind: ItemSuggestionKind;
|
|
186
|
+
readonly handles: ReadonlyArray<string>;
|
|
187
|
+
/** Translate: the locale to fill. */
|
|
188
|
+
readonly locale?: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A text this long is worth a "Shorten". */
|
|
192
|
+
export const SHORTEN_FROM_CHARS = 280;
|
|
193
|
+
const SEO_WORDS: ReadonlyArray<string> = ['seo', 'meta'];
|
|
194
|
+
|
|
195
|
+
const textLength = (v: BriefValue | undefined): number =>
|
|
196
|
+
typeof v === 'string' ? v.length : Array.isArray(v) ? v.join(' ').length : 0;
|
|
197
|
+
|
|
198
|
+
function translations(writable: ReadonlyArray<ItemBriefField>): ItemSuggestion[] {
|
|
199
|
+
const byLocale = new Map<string, string[]>();
|
|
200
|
+
for (const f of writable) {
|
|
201
|
+
if (!f.locales || !f.locales.filled.length) continue;
|
|
202
|
+
for (const l of f.locales.empty) byLocale.set(l, [...(byLocale.get(l) ?? []), f.handle]);
|
|
203
|
+
}
|
|
204
|
+
return [...byLocale].map(([locale, handles]) => ({ kind: ItemSuggestionKind.Translate, locale, handles }));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** S2's quick actions: Fill empty fields, Translate to <locale>, Shorten, Write SEO — each only when it applies. */
|
|
208
|
+
export function itemSuggestions(brief: ItemBrief): ItemSuggestion[] {
|
|
209
|
+
const writable = brief.focus.fields.filter(f => !f.never);
|
|
210
|
+
const empty = writable.filter(f => f.empty).map(f => f.handle);
|
|
211
|
+
const long = writable.filter(f => TEXT_KINDS.has(f.kind) && !f.locales && textLength(f.value) >= SHORTEN_FROM_CHARS).map(f => f.handle);
|
|
212
|
+
const seo = writable.filter(f => SEO_WORDS.some(w => f.handle.slice(FIELD_HANDLE_PREFIX.length).toLowerCase().startsWith(w))).map(f => f.handle);
|
|
213
|
+
return [
|
|
214
|
+
...(empty.length ? [{ kind: ItemSuggestionKind.FillEmpty, handles: empty }] : []),
|
|
215
|
+
...translations(writable),
|
|
216
|
+
...(long.length ? [{ kind: ItemSuggestionKind.Shorten, handles: long }] : []),
|
|
217
|
+
...(seo.length ? [{ kind: ItemSuggestionKind.WriteSeo, handles: seo }] : []),
|
|
218
|
+
];
|
|
219
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { AiStep } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The surfaces AI Assist runs on (ai-assist-plan §2, §4): each screen that offers a prompt registers ONE spec — what it
|
|
5
|
+
* may change (families), how an accepted change is committed, which model steps a turn uses, the role actions the
|
|
6
|
+
* server re-checks, whether it reads photos and the focus ladder its chip widens along.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export enum AssistSurface {
|
|
10
|
+
BuilderPage = 'builderPage',
|
|
11
|
+
ContentItem = 'contentItem',
|
|
12
|
+
ContentFromPhotos = 'contentFromPhotos',
|
|
13
|
+
ContentList = 'contentList',
|
|
14
|
+
SchemaType = 'schemaType',
|
|
15
|
+
ShopProduct = 'shopProduct',
|
|
16
|
+
Media = 'media',
|
|
17
|
+
BuilderSite = 'builderSite',
|
|
18
|
+
FormInbox = 'formInbox',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** How an accepted turn reaches the studio (plan §3e). */
|
|
22
|
+
export enum CommitKind {
|
|
23
|
+
/** One builder history step. */
|
|
24
|
+
BuilderStep = 'builderStep',
|
|
25
|
+
/** Written into the screen's form; Save stays the owner's. */
|
|
26
|
+
FormFill = 'formFill',
|
|
27
|
+
/** A server run that writes drafts, with its own Undo. */
|
|
28
|
+
Run = 'run',
|
|
29
|
+
/** Nothing is written: filters, a copied reply. */
|
|
30
|
+
View = 'view',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The closed edit families a sentence may be answered in — one strict request each. */
|
|
34
|
+
export enum EditFamily {
|
|
35
|
+
Words = 'words',
|
|
36
|
+
Sections = 'sections',
|
|
37
|
+
Style = 'style',
|
|
38
|
+
Look = 'look',
|
|
39
|
+
Fields = 'fields',
|
|
40
|
+
Items = 'items',
|
|
41
|
+
View = 'view',
|
|
42
|
+
Schema = 'schema',
|
|
43
|
+
Media = 'media',
|
|
44
|
+
Plan = 'plan',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The model steps of a turn — generation-core's `AiStep` rows (Settings ▸ AI ▸ Models), never a second spelling. */
|
|
48
|
+
export const AssistStep = {
|
|
49
|
+
AssistRoute: AiStep.AssistRoute,
|
|
50
|
+
AssistEdit: AiStep.AssistEdit,
|
|
51
|
+
AssistRead: AiStep.AssistRead,
|
|
52
|
+
} as const;
|
|
53
|
+
export type AssistStep = typeof AssistStep[keyof typeof AssistStep];
|
|
54
|
+
|
|
55
|
+
/** One rung of a surface's focus ladder — the chip's ✕ widens to the next rung. */
|
|
56
|
+
export enum AssistScope {
|
|
57
|
+
Field = 'field',
|
|
58
|
+
Item = 'item',
|
|
59
|
+
Type = 'type',
|
|
60
|
+
Types = 'types',
|
|
61
|
+
Node = 'node',
|
|
62
|
+
Section = 'section',
|
|
63
|
+
Page = 'page',
|
|
64
|
+
Site = 'site',
|
|
65
|
+
Photo = 'photo',
|
|
66
|
+
Photos = 'photos',
|
|
67
|
+
Rows = 'rows',
|
|
68
|
+
Slot = 'slot',
|
|
69
|
+
Library = 'library',
|
|
70
|
+
Submission = 'submission',
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** iox-cms role actions (`roles/enums.ts` `Permissions`) a surface needs — the server re-checks them, never only the client. */
|
|
74
|
+
export enum AssistPermission {
|
|
75
|
+
SchemaAll = 'schema_all',
|
|
76
|
+
ContentRead = 'content_read',
|
|
77
|
+
ContentCreate = 'content_create',
|
|
78
|
+
ContentUpdate = 'content_update',
|
|
79
|
+
PageRead = 'page_read',
|
|
80
|
+
PageCreate = 'page_create',
|
|
81
|
+
PageUpdate = 'page_update',
|
|
82
|
+
PageDelete = 'page_delete',
|
|
83
|
+
StorageAll = 'storage_all',
|
|
84
|
+
ProductsAll = 'products_all',
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export enum SurfaceStatus {
|
|
88
|
+
Built = 'built',
|
|
89
|
+
Planned = 'planned',
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface SurfaceSpec {
|
|
93
|
+
readonly surface: AssistSurface;
|
|
94
|
+
readonly families: ReadonlyArray<EditFamily>;
|
|
95
|
+
readonly commit: CommitKind;
|
|
96
|
+
/** A family committed differently from the surface (the list's items are a Run; its filters a View). */
|
|
97
|
+
readonly familyCommits?: Readonly<Partial<Record<EditFamily, CommitKind>>>;
|
|
98
|
+
/** Model steps a turn may use. Media (S7) uses the picture steps of generation-core, none of these. */
|
|
99
|
+
readonly steps: ReadonlyArray<AssistStep>;
|
|
100
|
+
/** Every one is required. `content_<action>` is specialised per content type when `perContentType`. */
|
|
101
|
+
readonly permissions: ReadonlyArray<AssistPermission>;
|
|
102
|
+
/** A family that needs more than the surface does. */
|
|
103
|
+
readonly familyPermissions?: Readonly<Partial<Record<EditFamily, ReadonlyArray<AssistPermission>>>>;
|
|
104
|
+
/** The content permissions name a type (`content_<type>_<action>`), as the iox-cms guard specialises them. */
|
|
105
|
+
readonly perContentType: boolean;
|
|
106
|
+
readonly readsPhotos: boolean;
|
|
107
|
+
/** The focus ladder, narrowest first. */
|
|
108
|
+
readonly scopes: ReadonlyArray<AssistScope>;
|
|
109
|
+
readonly status: SurfaceStatus;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const spec = (s: Omit<SurfaceSpec, 'perContentType' | 'readsPhotos'> & Partial<Pick<SurfaceSpec, 'perContentType' | 'readsPhotos'>>): SurfaceSpec => ({
|
|
113
|
+
perContentType: false,
|
|
114
|
+
readsPhotos: false,
|
|
115
|
+
...s,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const SURFACES: Readonly<Record<AssistSurface, SurfaceSpec>> = {
|
|
119
|
+
[AssistSurface.BuilderPage]: spec({
|
|
120
|
+
surface: AssistSurface.BuilderPage,
|
|
121
|
+
families: [EditFamily.Words, EditFamily.Sections, EditFamily.Style, EditFamily.Look],
|
|
122
|
+
commit: CommitKind.BuilderStep,
|
|
123
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
124
|
+
permissions: [AssistPermission.PageUpdate],
|
|
125
|
+
scopes: [AssistScope.Node, AssistScope.Section, AssistScope.Page],
|
|
126
|
+
status: SurfaceStatus.Planned,
|
|
127
|
+
}),
|
|
128
|
+
[AssistSurface.ContentItem]: spec({
|
|
129
|
+
surface: AssistSurface.ContentItem,
|
|
130
|
+
families: [EditFamily.Fields],
|
|
131
|
+
commit: CommitKind.FormFill,
|
|
132
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
133
|
+
permissions: [AssistPermission.ContentUpdate],
|
|
134
|
+
perContentType: true,
|
|
135
|
+
scopes: [AssistScope.Field, AssistScope.Item, AssistScope.Type],
|
|
136
|
+
status: SurfaceStatus.Built,
|
|
137
|
+
}),
|
|
138
|
+
[AssistSurface.ContentFromPhotos]: spec({
|
|
139
|
+
surface: AssistSurface.ContentFromPhotos,
|
|
140
|
+
families: [EditFamily.Fields, EditFamily.Media],
|
|
141
|
+
commit: CommitKind.Run,
|
|
142
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistRead, AssistStep.AssistEdit],
|
|
143
|
+
permissions: [AssistPermission.ContentCreate, AssistPermission.StorageAll],
|
|
144
|
+
perContentType: true,
|
|
145
|
+
readsPhotos: true,
|
|
146
|
+
scopes: [AssistScope.Photo, AssistScope.Photos, AssistScope.Type],
|
|
147
|
+
status: SurfaceStatus.Planned,
|
|
148
|
+
}),
|
|
149
|
+
[AssistSurface.ContentList]: spec({
|
|
150
|
+
surface: AssistSurface.ContentList,
|
|
151
|
+
families: [EditFamily.View, EditFamily.Items],
|
|
152
|
+
commit: CommitKind.View,
|
|
153
|
+
familyCommits: { [EditFamily.Items]: CommitKind.Run },
|
|
154
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
155
|
+
permissions: [AssistPermission.ContentRead],
|
|
156
|
+
familyPermissions: { [EditFamily.Items]: [AssistPermission.ContentCreate, AssistPermission.ContentUpdate] },
|
|
157
|
+
perContentType: true,
|
|
158
|
+
scopes: [AssistScope.Rows, AssistScope.Type],
|
|
159
|
+
status: SurfaceStatus.Planned,
|
|
160
|
+
}),
|
|
161
|
+
[AssistSurface.SchemaType]: spec({
|
|
162
|
+
surface: AssistSurface.SchemaType,
|
|
163
|
+
families: [EditFamily.Schema],
|
|
164
|
+
commit: CommitKind.FormFill,
|
|
165
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
166
|
+
permissions: [AssistPermission.SchemaAll],
|
|
167
|
+
scopes: [AssistScope.Field, AssistScope.Type, AssistScope.Types],
|
|
168
|
+
status: SurfaceStatus.Planned,
|
|
169
|
+
}),
|
|
170
|
+
[AssistSurface.ShopProduct]: spec({
|
|
171
|
+
surface: AssistSurface.ShopProduct,
|
|
172
|
+
families: [EditFamily.Fields],
|
|
173
|
+
commit: CommitKind.FormFill,
|
|
174
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistRead, AssistStep.AssistEdit],
|
|
175
|
+
permissions: [AssistPermission.ProductsAll],
|
|
176
|
+
readsPhotos: true,
|
|
177
|
+
scopes: [AssistScope.Field, AssistScope.Item],
|
|
178
|
+
status: SurfaceStatus.Planned,
|
|
179
|
+
}),
|
|
180
|
+
[AssistSurface.Media]: spec({
|
|
181
|
+
surface: AssistSurface.Media,
|
|
182
|
+
families: [EditFamily.Media],
|
|
183
|
+
commit: CommitKind.Run,
|
|
184
|
+
steps: [],
|
|
185
|
+
permissions: [AssistPermission.StorageAll],
|
|
186
|
+
readsPhotos: true,
|
|
187
|
+
scopes: [AssistScope.Slot, AssistScope.Library],
|
|
188
|
+
status: SurfaceStatus.Planned,
|
|
189
|
+
}),
|
|
190
|
+
[AssistSurface.BuilderSite]: spec({
|
|
191
|
+
surface: AssistSurface.BuilderSite,
|
|
192
|
+
families: [EditFamily.Plan, EditFamily.Sections],
|
|
193
|
+
commit: CommitKind.Run,
|
|
194
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
195
|
+
permissions: [AssistPermission.PageCreate, AssistPermission.PageUpdate, AssistPermission.PageDelete],
|
|
196
|
+
familyPermissions: { [EditFamily.Plan]: [AssistPermission.SchemaAll] },
|
|
197
|
+
scopes: [AssistScope.Page, AssistScope.Site],
|
|
198
|
+
status: SurfaceStatus.Planned,
|
|
199
|
+
}),
|
|
200
|
+
[AssistSurface.FormInbox]: spec({
|
|
201
|
+
surface: AssistSurface.FormInbox,
|
|
202
|
+
families: [EditFamily.Words],
|
|
203
|
+
commit: CommitKind.View,
|
|
204
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
205
|
+
permissions: [AssistPermission.PageRead],
|
|
206
|
+
scopes: [AssistScope.Submission],
|
|
207
|
+
status: SurfaceStatus.Planned,
|
|
208
|
+
}),
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export const surfaceSpec = (surface: AssistSurface): SurfaceSpec => SURFACES[surface];
|
|
212
|
+
|
|
213
|
+
export const builtSurfaces = (): AssistSurface[] =>
|
|
214
|
+
Object.values(SURFACES).filter(s => s.status === SurfaceStatus.Built).map(s => s.surface);
|
|
215
|
+
|
|
216
|
+
export const commitOf = (surface: AssistSurface, family: EditFamily): CommitKind =>
|
|
217
|
+
SURFACES[surface].familyCommits?.[family] ?? SURFACES[surface].commit;
|
|
218
|
+
|
|
219
|
+
const CONTENT_PERMISSION_PREFIX = 'content_';
|
|
220
|
+
const ALL_SUFFIX = '_all';
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The permission strings the server checks for a turn on this surface (and these families): `content_<action>` becomes
|
|
224
|
+
* `content_<type>_<action>` on a per-type surface — the same specialisation iox-cms's AuthorizationGuard applies to a
|
|
225
|
+
* `:resource` route, so a user granted only `content_posts_update` may assist on posts and nowhere else.
|
|
226
|
+
*/
|
|
227
|
+
export function surfacePermissions(surface: AssistSurface, contentType?: string, families: ReadonlyArray<EditFamily> = []): string[] {
|
|
228
|
+
const s = SURFACES[surface];
|
|
229
|
+
const all = [...s.permissions, ...families.flatMap(f => s.familyPermissions?.[f] ?? [])];
|
|
230
|
+
const named = all.map(p => {
|
|
231
|
+
if (!s.perContentType || !contentType || !p.startsWith(CONTENT_PERMISSION_PREFIX) || p.endsWith(ALL_SUFFIX)) return p as string;
|
|
232
|
+
return `${CONTENT_PERMISSION_PREFIX}${contentType}_${p.slice(CONTENT_PERMISSION_PREFIX.length)}`;
|
|
233
|
+
});
|
|
234
|
+
return [...new Set(named)];
|
|
235
|
+
}
|
|
@@ -788,6 +788,16 @@ export const SPEC_TIERS = {
|
|
|
788
788
|
"type": "number",
|
|
789
789
|
"default": "0.5"
|
|
790
790
|
},
|
|
791
|
+
{
|
|
792
|
+
"name": "list-focus-scale",
|
|
793
|
+
"type": "number",
|
|
794
|
+
"default": "1.05"
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
"name": "list-rise",
|
|
798
|
+
"type": "size",
|
|
799
|
+
"default": "-10px"
|
|
800
|
+
},
|
|
791
801
|
{
|
|
792
802
|
"name": "panel-bg",
|
|
793
803
|
"type": "color",
|
|
@@ -6737,6 +6747,20 @@ export const SPEC_FLAVOR_PACKS = [
|
|
|
6737
6747
|
"group": "components",
|
|
6738
6748
|
"value": "0.5"
|
|
6739
6749
|
},
|
|
6750
|
+
{
|
|
6751
|
+
"name": "list-focus-scale",
|
|
6752
|
+
"tier": "component",
|
|
6753
|
+
"type": "number",
|
|
6754
|
+
"group": "components",
|
|
6755
|
+
"value": "1.05"
|
|
6756
|
+
},
|
|
6757
|
+
{
|
|
6758
|
+
"name": "list-rise",
|
|
6759
|
+
"tier": "component",
|
|
6760
|
+
"type": "size",
|
|
6761
|
+
"group": "components",
|
|
6762
|
+
"value": "-10px"
|
|
6763
|
+
},
|
|
6740
6764
|
{
|
|
6741
6765
|
"name": "panel-bg",
|
|
6742
6766
|
"tier": "component",
|
|
@@ -9071,6 +9095,20 @@ export const SPEC_FLAVOR_PACKS = [
|
|
|
9071
9095
|
"group": "components",
|
|
9072
9096
|
"value": "0.5"
|
|
9073
9097
|
},
|
|
9098
|
+
{
|
|
9099
|
+
"name": "list-focus-scale",
|
|
9100
|
+
"tier": "component",
|
|
9101
|
+
"type": "number",
|
|
9102
|
+
"group": "components",
|
|
9103
|
+
"value": "1.05"
|
|
9104
|
+
},
|
|
9105
|
+
{
|
|
9106
|
+
"name": "list-rise",
|
|
9107
|
+
"tier": "component",
|
|
9108
|
+
"type": "size",
|
|
9109
|
+
"group": "components",
|
|
9110
|
+
"value": "-10px"
|
|
9111
|
+
},
|
|
9074
9112
|
{
|
|
9075
9113
|
"name": "panel-bg",
|
|
9076
9114
|
"tier": "component",
|
|
@@ -11413,6 +11451,20 @@ export const SPEC_FLAVOR_PACKS = [
|
|
|
11413
11451
|
"group": "components",
|
|
11414
11452
|
"value": "0.5"
|
|
11415
11453
|
},
|
|
11454
|
+
{
|
|
11455
|
+
"name": "list-focus-scale",
|
|
11456
|
+
"tier": "component",
|
|
11457
|
+
"type": "number",
|
|
11458
|
+
"group": "components",
|
|
11459
|
+
"value": "1.05"
|
|
11460
|
+
},
|
|
11461
|
+
{
|
|
11462
|
+
"name": "list-rise",
|
|
11463
|
+
"tier": "component",
|
|
11464
|
+
"type": "size",
|
|
11465
|
+
"group": "components",
|
|
11466
|
+
"value": "-10px"
|
|
11467
|
+
},
|
|
11416
11468
|
{
|
|
11417
11469
|
"name": "panel-bg",
|
|
11418
11470
|
"tier": "component",
|
|
@@ -13767,6 +13819,20 @@ export const SPEC_FLAVOR_PACKS = [
|
|
|
13767
13819
|
"group": "components",
|
|
13768
13820
|
"value": "0.5"
|
|
13769
13821
|
},
|
|
13822
|
+
{
|
|
13823
|
+
"name": "list-focus-scale",
|
|
13824
|
+
"tier": "component",
|
|
13825
|
+
"type": "number",
|
|
13826
|
+
"group": "components",
|
|
13827
|
+
"value": "1.05"
|
|
13828
|
+
},
|
|
13829
|
+
{
|
|
13830
|
+
"name": "list-rise",
|
|
13831
|
+
"tier": "component",
|
|
13832
|
+
"type": "size",
|
|
13833
|
+
"group": "components",
|
|
13834
|
+
"value": "-10px"
|
|
13835
|
+
},
|
|
13770
13836
|
{
|
|
13771
13837
|
"name": "panel-bg",
|
|
13772
13838
|
"tier": "component",
|
|
@@ -16124,6 +16190,20 @@ export const SPEC_FLAVOR_PACKS = [
|
|
|
16124
16190
|
"group": "components",
|
|
16125
16191
|
"value": "0.5"
|
|
16126
16192
|
},
|
|
16193
|
+
{
|
|
16194
|
+
"name": "list-focus-scale",
|
|
16195
|
+
"tier": "component",
|
|
16196
|
+
"type": "number",
|
|
16197
|
+
"group": "components",
|
|
16198
|
+
"value": "1.05"
|
|
16199
|
+
},
|
|
16200
|
+
{
|
|
16201
|
+
"name": "list-rise",
|
|
16202
|
+
"tier": "component",
|
|
16203
|
+
"type": "size",
|
|
16204
|
+
"group": "components",
|
|
16205
|
+
"value": "-10px"
|
|
16206
|
+
},
|
|
16127
16207
|
{
|
|
16128
16208
|
"name": "panel-bg",
|
|
16129
16209
|
"tier": "component",
|
|
@@ -18462,6 +18542,20 @@ export const SPEC_FLAVOR_PACKS = [
|
|
|
18462
18542
|
"group": "components",
|
|
18463
18543
|
"value": "0.5"
|
|
18464
18544
|
},
|
|
18545
|
+
{
|
|
18546
|
+
"name": "list-focus-scale",
|
|
18547
|
+
"tier": "component",
|
|
18548
|
+
"type": "number",
|
|
18549
|
+
"group": "components",
|
|
18550
|
+
"value": "1.05"
|
|
18551
|
+
},
|
|
18552
|
+
{
|
|
18553
|
+
"name": "list-rise",
|
|
18554
|
+
"tier": "component",
|
|
18555
|
+
"type": "size",
|
|
18556
|
+
"group": "components",
|
|
18557
|
+
"value": "-10px"
|
|
18558
|
+
},
|
|
18465
18559
|
{
|
|
18466
18560
|
"name": "panel-bg",
|
|
18467
18561
|
"tier": "component",
|