@vectoriox/iox-ui 5.133.0 → 5.135.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/commerce-core/index.d.ts +12 -1
- package/composite-core/index.d.ts +27 -22
- package/design-core/index.d.ts +436 -35
- package/domain-core/index.d.ts +353 -0
- package/domain-core/package.json +3 -0
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs +2 -0
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +6 -48
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +21 -0
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +68 -57
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +895 -416
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-domain-core.mjs +422 -0
- package/fesm2022/vectoriox-iox-ui-domain-core.mjs.map +1 -0
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +14039 -12067
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +9 -3
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-mail-core.mjs +210 -2
- package/fesm2022/vectoriox-iox-ui-mail-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +290 -16
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +1511 -432
- package/harness-core/index.d.ts +6 -1
- package/index.d.ts +139 -10
- package/mail-core/index.d.ts +190 -2
- package/package.json +5 -1
- package/src/actions-core/element-actions.ts +2 -0
- package/src/assist-core/page-sections.ts +7 -37
- package/src/commerce-core/shop-display.ts +21 -0
- package/src/composite-core/shop.ts +71 -57
- package/src/design-core/design-settings.ts +16 -0
- package/src/design-core/design-token.model.ts +7 -1
- package/src/design-core/flavor-spec.generated.ts +374 -35
- package/src/design-core/flavor-tokens.ts +12 -1
- package/src/design-core/header-behaviour.ts +32 -0
- package/src/design-core/motion-language.ts +115 -0
- package/src/design-core/public-api.ts +1 -0
- package/src/design-core/style-presets.ts +3 -0
- package/src/domain-core/domain-vocabulary.ts +125 -0
- package/src/domain-core/domain-wire.ts +95 -0
- package/src/domain-core/org-path-redirect.ts +105 -0
- package/src/domain-core/public-api.ts +12 -0
- package/src/domain-core/web-domain.ts +251 -0
- package/src/generation-core/carry-fill.ts +36 -0
- package/src/generation-core/carry.ts +398 -0
- package/src/generation-core/check-carry.ts +216 -0
- package/src/generation-core/check-layout.ts +71 -5
- package/src/generation-core/compose-layout.ts +187 -28
- package/src/generation-core/compose-site.ts +154 -31
- package/src/generation-core/entrances.ts +66 -10
- package/src/generation-core/header-edit.ts +299 -0
- package/src/generation-core/header-mix.ts +64 -5
- package/src/generation-core/layout-fingerprint.ts +5 -1
- package/src/generation-core/layout-language.ts +20 -1
- package/src/generation-core/layout-space.ts +4 -4
- package/src/generation-core/layout-wire.ts +36 -1
- package/src/generation-core/node-baselines.generated.ts +1 -0
- package/src/generation-core/public-api.ts +7 -0
- package/src/generation-core/redesign-additions.ts +273 -0
- package/src/generation-core/redesign-run.ts +364 -0
- package/src/generation-core/refit-page.ts +151 -0
- package/src/generation-core/section-stamp.ts +4 -4
- package/src/generation-core/shop-plan.ts +15 -0
- package/src/generation-core/site-build-run.ts +67 -3
- package/src/generation-core/site-spec.generated.ts +194 -94
- package/src/generation-core/site-tree.ts +19 -5
- package/src/generation-core/validate-site-plan.ts +37 -3
- package/src/harness-core/motion.ts +13 -3
- package/src/harness-core/starting-design.ts +1 -1
- package/src/mail-core/mail-domain.ts +305 -0
- package/src/mail-core/mail-wire.ts +8 -0
- package/src/mail-core/public-api.ts +3 -1
- package/styles/iox-design.css +30 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { jsonAnyOf, jsonInteger, jsonListOf, jsonOneOf, JsonSchema, jsonShapedObject, jsonText } from './json-schema';
|
|
2
|
+
import { expandWireContentType, expandWirePage, PLAN_WIRE_SHAPE, PlanWireEntry, wireContentTypeJsonSchema, wirePageJsonSchema } from './plan-wire';
|
|
3
|
+
import { isPlainObject, PlainObject } from './shape-check';
|
|
4
|
+
import { CmsDataSourcePlan, ContentTypePlan, PagePlan, PlanDataSourceMode, PlanDataSourceType, SitePlan } from './site-plan.model';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What a REDESIGN may add (site-redesign plan §3e — RD3-D2 as amended by Doron, 2026-11-21: "the system can suggest new
|
|
8
|
+
* pages if make sense and in case do use asked for redisign and new pages or content"). Additive only: a new page takes
|
|
9
|
+
* a NEW address, new content (a type, items) sits beside what exists, and nothing existing — a type, a field, an item,
|
|
10
|
+
* a data source, a relation, an address — is ever edited or removed. Facts are never invented (a missing one is a
|
|
11
|
+
* placeholder the gate blocks on).
|
|
12
|
+
*
|
|
13
|
+
* Two strict requests, built from the plan wire's OWN entries (the vocabulary, the expanders and the gate are the
|
|
14
|
+
* build's): **Pages** first — every redesign, the pages to add with who wanted them and why, the new types those pages
|
|
15
|
+
* need (by name) and the new items an existing type should get (by count) — then **Content**, only when Pages named a new
|
|
16
|
+
* type or new items: the new types in full and the new items' values. The sources a new type is read by are DERIVED
|
|
17
|
+
* (`additionSourcesOf`), never asked — so the Pages request can bind them before the type exists. Pure; no transport.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** Who wanted a page the redesign adds. */
|
|
21
|
+
export enum AdditionOrigin {
|
|
22
|
+
/** The owner's sentence asked for it — staged with its switch ON. */
|
|
23
|
+
Asked = 'asked',
|
|
24
|
+
/** The reading says the site lacks it — staged with its switch OFF, never added unless the owner turns it on. */
|
|
25
|
+
Suggested = 'suggested',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The two requests, in the order they are asked. */
|
|
29
|
+
export enum AdditionsPart {
|
|
30
|
+
Pages = 'pages',
|
|
31
|
+
Content = 'content',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Each request's format name. */
|
|
35
|
+
export const REDESIGN_ADDITIONS_SCHEMA_NAMES: Readonly<Record<AdditionsPart, string>> = {
|
|
36
|
+
[AdditionsPart.Pages]: 'site_redesign_pages',
|
|
37
|
+
[AdditionsPart.Content]: 'site_redesign_content',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** At most this many of each (the build's sample cap for items). */
|
|
41
|
+
export const ADDITION_CAPS = { suggested: 2, asked: 6, itemsPerType: 6 } as const;
|
|
42
|
+
|
|
43
|
+
/** The suffix of a new type's one-item source (its per-item page reads it by `:slug`). */
|
|
44
|
+
export const ADDITION_ITEM_SOURCE_SUFFIX = 'Item';
|
|
45
|
+
/** The field and route param a new type's item page is picked by. */
|
|
46
|
+
export const ADDITION_SLUG = 'slug';
|
|
47
|
+
|
|
48
|
+
const PAGE_KEYS: Readonly<Record<string, string>> = {
|
|
49
|
+
origin: `string — ${AdditionOrigin.Asked}: the owner's sentence asks for this page; ${AdditionOrigin.Suggested}: the site lacks it and the owner decides (at most ${ADDITION_CAPS.suggested})`,
|
|
50
|
+
reason: 'string — one plain sentence the owner reads beside the page: what they asked, or why a site like theirs has it',
|
|
51
|
+
};
|
|
52
|
+
const NEW_TYPE_SHAPE = { name: 'string — a NEW content type name (never one the studio has)', label: 'string — its name as the owner reads it' };
|
|
53
|
+
const NEW_ITEMS_SHAPE = { contentType: 'string — a content type the studio HAS, or one of newTypes', count: `number — how many new items (1–${ADDITION_CAPS.itemsPerType}); the owner's sentence must ask for them` };
|
|
54
|
+
const PAGES_SHAPE = {
|
|
55
|
+
pages: 'page[] — ONLY the pages to add, each at an address the studio does not have; [] = none',
|
|
56
|
+
newTypes: 'newType[] — the new kinds of content the new pages need; [] = none',
|
|
57
|
+
newItems: 'newItems[] — new items the sentence asks for; [] = none',
|
|
58
|
+
};
|
|
59
|
+
const ITEM_SHAPE = { contentType: 'string — the type the item goes into', values: 'seedValue[] — its field values; a fact the owner did not give stays empty' };
|
|
60
|
+
const CONTENT_SHAPE = {
|
|
61
|
+
contentTypes: 'contentType[] — exactly the new types named, in full (a per-item page needs a slug field)',
|
|
62
|
+
items: 'item[] — the new items, one entry each',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const withKeys = (schema: JsonSchema, extra: Record<string, JsonSchema>): JsonSchema => {
|
|
66
|
+
const s = schema as { properties: Record<string, JsonSchema>; required: string[] };
|
|
67
|
+
return { ...schema, properties: { ...s.properties, ...extra }, required: [...s.required, ...Object.keys(extra)] } as JsonSchema;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** The format a model writes one additions request in (≤ 40 properties each — `redesign-additions.spec`). */
|
|
71
|
+
export function redesignAdditionsJsonSchema(part: AdditionsPart): JsonSchema {
|
|
72
|
+
if (part === AdditionsPart.Pages) {
|
|
73
|
+
const page = withKeys(wirePageJsonSchema(), {
|
|
74
|
+
origin: { ...jsonOneOf(Object.values(AdditionOrigin)), description: PAGE_KEYS['origin'] },
|
|
75
|
+
reason: { ...jsonText(), description: PAGE_KEYS['reason'] },
|
|
76
|
+
});
|
|
77
|
+
return jsonShapedObject(PAGES_SHAPE, {
|
|
78
|
+
pages: jsonListOf(page),
|
|
79
|
+
newTypes: jsonListOf(jsonShapedObject(NEW_TYPE_SHAPE, { name: jsonText(), label: jsonText() }, 'additions newType')),
|
|
80
|
+
newItems: jsonListOf(jsonShapedObject(NEW_ITEMS_SHAPE, { contentType: jsonText(), count: jsonInteger() }, 'additions newItems')),
|
|
81
|
+
}, 'additions pages');
|
|
82
|
+
}
|
|
83
|
+
const value = jsonShapedObject(PLAN_WIRE_SHAPE[PlanWireEntry.SeedValue], { field: jsonText(), value: jsonAnyOf([jsonText(), jsonListOf(jsonText())]), each: jsonListOf(jsonText()) }, 'additions seedValue');
|
|
84
|
+
return jsonShapedObject(CONTENT_SHAPE, {
|
|
85
|
+
contentTypes: jsonListOf(wireContentTypeJsonSchema()),
|
|
86
|
+
items: jsonListOf(jsonShapedObject(ITEM_SHAPE, { contentType: jsonText(), values: jsonListOf(value) }, 'additions item')),
|
|
87
|
+
}, 'additions content');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A page the redesign adds. */
|
|
91
|
+
export interface AdditionPage {
|
|
92
|
+
page: PagePlan;
|
|
93
|
+
origin: AdditionOrigin;
|
|
94
|
+
reason: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** One new item into a type (existing or new): its field values. */
|
|
98
|
+
export interface AdditionItem {
|
|
99
|
+
contentType: string;
|
|
100
|
+
values: Readonly<Record<string, unknown>>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** What a redesign adds, expanded from its answers. */
|
|
104
|
+
export interface RedesignAdditions {
|
|
105
|
+
pages: AdditionPage[];
|
|
106
|
+
contentTypes: ContentTypePlan[];
|
|
107
|
+
/** Derived (`additionSourcesOf`) for every new type. */
|
|
108
|
+
dataSources: CmsDataSourcePlan[];
|
|
109
|
+
items: AdditionItem[];
|
|
110
|
+
/** The Pages answer's asks: new types by name, new items by count — what the Content request is asked for. */
|
|
111
|
+
asks: { newTypes: Array<{ name: string; label: string }>; newItems: Array<{ contentType: string; count: number }> };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The sources a new type is read by — derived, never asked: the list (`<type>`) and one item by `:slug`. */
|
|
115
|
+
export function additionSourcesOf(typeName: string): CmsDataSourcePlan[] {
|
|
116
|
+
return [
|
|
117
|
+
{ alias: typeName, type: PlanDataSourceType.Cms, mode: PlanDataSourceMode.Query, contentType: typeName },
|
|
118
|
+
{ alias: `${typeName}${ADDITION_ITEM_SOURCE_SUFFIX}`, type: PlanDataSourceType.Cms, mode: PlanDataSourceMode.Single, contentType: typeName, filterByRouteParam: { field: ADDITION_SLUG, routeParam: ADDITION_SLUG } },
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const list = (value: unknown): unknown[] => (Array.isArray(value) ? value : []);
|
|
123
|
+
const text = (value: unknown): string => (typeof value === 'string' ? value : '');
|
|
124
|
+
|
|
125
|
+
/** Does the Pages answer ask for content (so the Content request is asked). */
|
|
126
|
+
export function additionsNeedContent(pagesAnswer: unknown): boolean {
|
|
127
|
+
return isPlainObject(pagesAnswer) && (list(pagesAnswer['newTypes']).length > 0 || list(pagesAnswer['newItems']).length > 0);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The answers → what the redesign adds. Translates, never repairs (as `expandPlanWire`): a wrong value stays wrong, for
|
|
132
|
+
* `checkAdditions`. The Content answer is absent when it was not asked.
|
|
133
|
+
*/
|
|
134
|
+
export function expandAdditions(pagesAnswer: unknown, contentAnswer?: unknown): RedesignAdditions {
|
|
135
|
+
const pages = isPlainObject(pagesAnswer) ? pagesAnswer : {};
|
|
136
|
+
const content = isPlainObject(contentAnswer) ? contentAnswer : {};
|
|
137
|
+
const newTypes = list(pages['newTypes']).filter(isPlainObject).map(t => ({ name: text(t['name']), label: text(t['label']) }));
|
|
138
|
+
return {
|
|
139
|
+
pages: list(pages['pages']).filter(isPlainObject).map(wire => {
|
|
140
|
+
const { origin, reason, ...page } = wire as PlainObject;
|
|
141
|
+
return { page: expandWirePage(page) as PagePlan, origin: origin as AdditionOrigin, reason: text(reason) };
|
|
142
|
+
}),
|
|
143
|
+
contentTypes: list(content['contentTypes']).map(t => expandWireContentType(t) as ContentTypePlan),
|
|
144
|
+
dataSources: newTypes.filter(t => t.name).flatMap(t => additionSourcesOf(t.name)),
|
|
145
|
+
items: list(content['items']).filter(isPlainObject).map(item => ({
|
|
146
|
+
contentType: text(item['contentType']),
|
|
147
|
+
values: Object.fromEntries(list(item['values']).filter(isPlainObject).map(v => [text(v['field']), v['value']])),
|
|
148
|
+
})),
|
|
149
|
+
asks: {
|
|
150
|
+
newTypes,
|
|
151
|
+
newItems: list(pages['newItems']).filter(isPlainObject).map(n => ({ contentType: text(n['contentType']), count: Number(n['count']) || 0 })),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** What `checkAdditions` refuses. */
|
|
157
|
+
export enum AdditionIssueCode {
|
|
158
|
+
/** A new page at an address the studio (or another addition) already has. */
|
|
159
|
+
RouteTaken = 'addition-route-taken',
|
|
160
|
+
/** A new type whose name the studio already has — an existing type is never changed. */
|
|
161
|
+
TypeExists = 'addition-type-exists',
|
|
162
|
+
/** An item, or a page's binding, for a type that is neither the studio's nor a new one. */
|
|
163
|
+
TypeUnknown = 'addition-type-unknown',
|
|
164
|
+
/** A binding to a source that is neither the studio's nor a new type's derived one. */
|
|
165
|
+
SourceUnknown = 'addition-source-unknown',
|
|
166
|
+
/** An `asked` page or new items with no sentence to ask for them. */
|
|
167
|
+
NotAsked = 'addition-not-asked',
|
|
168
|
+
/** More than `ADDITION_CAPS` allows. */
|
|
169
|
+
TooMany = 'addition-too-many',
|
|
170
|
+
/** A new type named by Pages that Content did not write (or wrote twice), or one written that Pages did not name. */
|
|
171
|
+
TypeMismatch = 'addition-type-mismatch',
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface AdditionIssue {
|
|
175
|
+
code: AdditionIssueCode;
|
|
176
|
+
/** Into the answer that holds it (`pages[1].route`, `contentTypes[0].name`, `items[2].contentType`). */
|
|
177
|
+
path: string;
|
|
178
|
+
message: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** What the studio has — what an addition may never take or change. */
|
|
182
|
+
export interface AdditionsStudio {
|
|
183
|
+
routes: ReadonlyArray<string>;
|
|
184
|
+
contentTypes: ReadonlyArray<string>;
|
|
185
|
+
dataSources: ReadonlyArray<string>;
|
|
186
|
+
/** The owner's sentence ('' = none). */
|
|
187
|
+
prompt: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const routeKey = (route: string) => (route.replace(/\/+$/, '') || '/').toLowerCase();
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* THE additive check (§3e): every page at a new address, every new type a new name, every item into a known type, every
|
|
194
|
+
* binding to a known source, `asked` only with a sentence, the caps held, and the Content answer exactly the types Pages
|
|
195
|
+
* named. Refuses with a path; never repairs. An existing type's FIELDS cannot be expressed by the format at all.
|
|
196
|
+
*/
|
|
197
|
+
export function checkAdditions(additions: RedesignAdditions, studio: AdditionsStudio): AdditionIssue[] {
|
|
198
|
+
const issues: AdditionIssue[] = [];
|
|
199
|
+
const say = (code: AdditionIssueCode, path: string, message: string) => issues.push({ code, path, message });
|
|
200
|
+
const asked = !!studio.prompt.trim();
|
|
201
|
+
const taken = new Set(studio.routes.map(routeKey));
|
|
202
|
+
const types = new Set(studio.contentTypes);
|
|
203
|
+
const newTypes = new Set(additions.asks.newTypes.map(t => t.name));
|
|
204
|
+
const sources = new Set([...studio.dataSources, ...additions.dataSources.map(s => s.alias)]);
|
|
205
|
+
|
|
206
|
+
additions.pages.forEach(({ page, origin }, i) => {
|
|
207
|
+
const key = routeKey(String(page?.route ?? ''));
|
|
208
|
+
if (taken.has(key)) say(AdditionIssueCode.RouteTaken, `pages[${i}].route`, `${page.route} is already a page of this site — a new page takes a new address`);
|
|
209
|
+
taken.add(key);
|
|
210
|
+
if (origin === AdditionOrigin.Asked && !asked) say(AdditionIssueCode.NotAsked, `pages[${i}].origin`, 'nothing was asked: a page the site lacks is "suggested"');
|
|
211
|
+
if (page.template && !types.has(page.template) && !newTypes.has(page.template)) say(AdditionIssueCode.TypeUnknown, `pages[${i}].template`, `"${page.template}" is not a content type of this site or a new one`);
|
|
212
|
+
for (const [alias, path] of [[page.routeSource, `pages[${i}].routeSource`], ...(page.sections ?? []).map((s, j) => [s.binding, `pages[${i}].sections[${j}].binding`])] as Array<[string | undefined, string]>) {
|
|
213
|
+
if (alias && !sources.has(alias)) say(AdditionIssueCode.SourceUnknown, path, `"${alias}" is not a source of this site or of a new type`);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
const suggested = additions.pages.filter(p => p.origin === AdditionOrigin.Suggested).length;
|
|
217
|
+
const askedPages = additions.pages.filter(p => p.origin === AdditionOrigin.Asked).length;
|
|
218
|
+
if (suggested > ADDITION_CAPS.suggested) say(AdditionIssueCode.TooMany, 'pages', `${suggested} suggested pages — at most ${ADDITION_CAPS.suggested}`);
|
|
219
|
+
if (askedPages > ADDITION_CAPS.asked) say(AdditionIssueCode.TooMany, 'pages', `${askedPages} asked pages — at most ${ADDITION_CAPS.asked}`);
|
|
220
|
+
|
|
221
|
+
additions.asks.newTypes.forEach((t, i) => {
|
|
222
|
+
if (types.has(t.name)) say(AdditionIssueCode.TypeExists, `newTypes[${i}].name`, `"${t.name}" is already a content type — an existing type is never changed`);
|
|
223
|
+
});
|
|
224
|
+
const written = additions.contentTypes.map(t => t?.name);
|
|
225
|
+
additions.contentTypes.forEach((t, i) => {
|
|
226
|
+
if (types.has(t?.name)) say(AdditionIssueCode.TypeExists, `contentTypes[${i}].name`, `"${t.name}" is already a content type — an existing type is never changed`);
|
|
227
|
+
else if (!newTypes.has(t?.name) || written.indexOf(t.name) !== i) say(AdditionIssueCode.TypeMismatch, `contentTypes[${i}].name`, `"${t?.name}" is not one of the new types named, once each`);
|
|
228
|
+
});
|
|
229
|
+
for (const name of newTypes) if (additions.contentTypes.length && !written.includes(name)) say(AdditionIssueCode.TypeMismatch, 'contentTypes', `the new type "${name}" was named but not written`);
|
|
230
|
+
|
|
231
|
+
if (additions.items.length && !asked) say(AdditionIssueCode.NotAsked, 'items', 'nothing was asked: new items only when the sentence asks for them');
|
|
232
|
+
const perType = new Map<string, number>();
|
|
233
|
+
additions.items.forEach((item, i) => {
|
|
234
|
+
if (!types.has(item.contentType) && !newTypes.has(item.contentType)) say(AdditionIssueCode.TypeUnknown, `items[${i}].contentType`, `"${item.contentType}" is not a content type of this site or a new one`);
|
|
235
|
+
perType.set(item.contentType, (perType.get(item.contentType) ?? 0) + 1);
|
|
236
|
+
});
|
|
237
|
+
for (const [type, n] of perType) if (n > ADDITION_CAPS.itemsPerType) say(AdditionIssueCode.TooMany, 'items', `${n} new ${type} items — at most ${ADDITION_CAPS.itemsPerType}`);
|
|
238
|
+
return issues;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** A page the redesign adds is keyed `added:<n>` in the run's plan (its order in the Pages answer). */
|
|
242
|
+
export const ADDITION_KEY_PREFIX = 'added:';
|
|
243
|
+
export const additionKey = (n: number): string => `${ADDITION_KEY_PREFIX}${n}`;
|
|
244
|
+
export const isAdditionKey = (key: string | null | undefined): boolean => typeof key === 'string' && key.startsWith(ADDITION_KEY_PREFIX);
|
|
245
|
+
/** What a Switch's `additions` names to write the new items the sentence asked for into types the studio HAS. */
|
|
246
|
+
export const ADDITION_ITEMS_KEY = 'items';
|
|
247
|
+
|
|
248
|
+
/** The data source aliases a page reads (its route source and its sections' bindings). */
|
|
249
|
+
function aliasesOf(page: PagePlan): string[] {
|
|
250
|
+
return [page.routeSource, ...(page.sections ?? []).map(s => s.binding)].filter((a): a is string => typeof a === 'string' && !!a);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** The NEW content types an added page brings: its template, or a type whose derived source it reads. */
|
|
254
|
+
export function typesOfAddition(page: PagePlan, additions: Pick<RedesignAdditions, 'contentTypes'>): string[] {
|
|
255
|
+
const aliases = new Set(aliasesOf(page));
|
|
256
|
+
return additions.contentTypes.map(t => t.name).filter(name =>
|
|
257
|
+
page.template === name || additionSourcesOf(name).some(source => aliases.has(source.alias)));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The plan with what the redesign adds (§3e) — pure. Each added page keyed `added:<n>`; the new types and their derived
|
|
262
|
+
* sources appended (a source alias the plan already has is never replaced). `only`: just these additions' pages, and only
|
|
263
|
+
* the new types (and their sources) those pages bring — what a Switch with some additions turned off writes.
|
|
264
|
+
*/
|
|
265
|
+
export function withAdditions(plan: SitePlan, additions: RedesignAdditions, only?: ReadonlySet<string>): SitePlan {
|
|
266
|
+
const pages = additions.pages.map((a, i) => ({ ...a.page, key: additionKey(i) })).filter(p => !only || only.has(p.key));
|
|
267
|
+
const brought = new Set(pages.flatMap(p => typesOfAddition(p, additions)));
|
|
268
|
+
const types = additions.contentTypes.filter(t => !only || brought.has(t.name));
|
|
269
|
+
const typeNames = new Set(types.map(t => t.name));
|
|
270
|
+
const have = new Set(plan.dataSources.map(d => d.alias));
|
|
271
|
+
const sources = additions.dataSources.filter(d => d.type === PlanDataSourceType.Cms && typeNames.has((d as CmsDataSourcePlan).contentType) && !have.has(d.alias));
|
|
272
|
+
return { ...plan, pages: [...plan.pages, ...pages], contentTypes: [...plan.contentTypes, ...types], dataSources: [...plan.dataSources, ...sources] };
|
|
273
|
+
}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import type { ComposedPlaceholder } from './compose-site';
|
|
2
|
+
import type { LayoutIssue } from './layout-language';
|
|
3
|
+
import type { SerializedNode } from './serialized-node';
|
|
4
|
+
import type { AdditionIssue, AdditionOrigin } from './redesign-additions';
|
|
5
|
+
import { BuildStepError, BuildStepRecord, CreatedRecord, SiteBuildKind, SiteBuildStatus, UndoKept } from './site-build-run';
|
|
6
|
+
import type { PagePlan } from './site-plan.model';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A REDESIGN run's wire vocabulary (site-redesign plan §3c, RD2): a new design for a built site, with everything it holds
|
|
10
|
+
* kept. The same W2 runner and the same single-run slot as a build (`SiteBuildKind.Redesign` in the `siteBuilds`
|
|
11
|
+
* collection), its own steps: Snapshot → Harvest → Compose → Stage, then the owner's Switch, then Back for
|
|
12
|
+
* `REDESIGN_BACK_DAYS`. Structure is locked (RD-D4): a redesign writes pages' layouts and settings, the header and footer,
|
|
13
|
+
* and the look — never a content type, field, item, data source or route. ONE definition: iox-cms stores and answers it,
|
|
14
|
+
* the redesign screens (RD3) read it. Pure types, enums and helpers; no transport.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The steps a redesign takes before its Switch, in the order they run. */
|
|
18
|
+
export enum RedesignStep {
|
|
19
|
+
/** Every page in scope (its layout, settings, fingerprint) and the globals — the version Back restores. */
|
|
20
|
+
Snapshot = 'snapshot',
|
|
21
|
+
/** `harvestPage` per page in scope: what on it is the owner's. */
|
|
22
|
+
Harvest = 'harvest',
|
|
23
|
+
/** What the redesign may ADD (§3e, RD3-D2 as amended): new pages the owner asked for or the reading suggests, the new
|
|
24
|
+
* content they need — asked, checked (`checkAdditions`), drawn and staged; nothing existing is touched. */
|
|
25
|
+
Additions = 'additions',
|
|
26
|
+
/** Per page: the model's layout with its carry (a composed page), or the page re-fitted for the new look. */
|
|
27
|
+
Compose = 'compose',
|
|
28
|
+
/** The new layouts, header, footer and look written onto the RUN — the live site does not move. */
|
|
29
|
+
Stage = 'stage',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const REDESIGN_STEPS: ReadonlyArray<RedesignStep> = Object.values(RedesignStep);
|
|
33
|
+
|
|
34
|
+
/** How long Back stays open after a Switch (RD-D11). */
|
|
35
|
+
export const REDESIGN_BACK_DAYS = 30;
|
|
36
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
37
|
+
|
|
38
|
+
/** How a page in scope got its new design. */
|
|
39
|
+
export enum StagedPageWay {
|
|
40
|
+
/** The model laid it out (the M8 layout request with the page's carry). */
|
|
41
|
+
Composed = 'composed',
|
|
42
|
+
/** Re-stamped from its run's plan in the new look, the owner's content and edits carried (Re-fit — no model). */
|
|
43
|
+
Refit = 'refit',
|
|
44
|
+
/** Not redesigned: it stays as it is and wears the new look through its tokens and element styles. */
|
|
45
|
+
Kept = 'kept',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Why a page went the way it did, when the way alone does not say it. */
|
|
49
|
+
export enum StagedPageReason {
|
|
50
|
+
/** The page is laid out by patterns in its plan (not a composed page): re-fitted, no model asked (RD-D13). */
|
|
51
|
+
Patterns = 'patterns',
|
|
52
|
+
/** The model's layout did not hold (after its repair and the section fallback): re-fitted instead. */
|
|
53
|
+
ModelFellBack = 'model-fell-back',
|
|
54
|
+
/** There is no reading to ask the model with (a site built from a template): re-fitted. */
|
|
55
|
+
NoReading = 'no-reading',
|
|
56
|
+
/** The model was refused before the call (credits, plan): re-fitted. */
|
|
57
|
+
Refused = 'refused',
|
|
58
|
+
/** A legal page: its text is the owner's, never recomposed (RD-D17). */
|
|
59
|
+
Legal = 'legal',
|
|
60
|
+
/** A page the owner made by hand that stays as it is: there is no reading to lay it out with (a studio built from a
|
|
61
|
+
* template). With a reading it is laid out like a composed page (RD-D16, RD3-D1 — `handPageKey`). */
|
|
62
|
+
HandMade = 'hand-made',
|
|
63
|
+
/** The run that built it, or its page in that run's plan, is gone: nothing to re-stamp it from. */
|
|
64
|
+
NoSource = 'no-source',
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What the owner asked of the redesign. */
|
|
68
|
+
export interface RedesignRequest {
|
|
69
|
+
/** "What should change in your site's design?" — every layout request reads it. */
|
|
70
|
+
prompt: string;
|
|
71
|
+
/** The new look (design-core `DesignChoices`, completed against its pack) — the one the Switch applies. */
|
|
72
|
+
design: Record<string, unknown>;
|
|
73
|
+
/** The pages in scope by id; null = every page of the studio. */
|
|
74
|
+
pages: string[] | null;
|
|
75
|
+
/** RD-D8: keep the header and footer as they are. */
|
|
76
|
+
keepGlobals: boolean;
|
|
77
|
+
/** RD-D16: section (root) indexes per page id the owner ticked Keep. */
|
|
78
|
+
keep: Record<string, number[]>;
|
|
79
|
+
/** A model the owner chose for the layouts (M8 D4), or none: the studio's choice for the step. */
|
|
80
|
+
model?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A page as the Snapshot took it — what Back restores, and what Switch judges a page edited after the harvest by. */
|
|
84
|
+
export interface RedesignSnapshotPage {
|
|
85
|
+
pageId: string;
|
|
86
|
+
name: string;
|
|
87
|
+
route: string;
|
|
88
|
+
/** The whole page document's fingerprint at the snapshot (iox-cms `fingerprint`). */
|
|
89
|
+
fingerprint: string;
|
|
90
|
+
layout: SerializedNode[];
|
|
91
|
+
pageSettings: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface RedesignSnapshot {
|
|
95
|
+
pages: RedesignSnapshotPage[];
|
|
96
|
+
/** The studio's global elements as they were (the header and footer the Switch may replace). */
|
|
97
|
+
globals: SerializedNode[];
|
|
98
|
+
/** The global elements' data sources, as they were. */
|
|
99
|
+
globalSources: unknown[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** One page's new design, staged on the run. */
|
|
103
|
+
export interface StagedPage {
|
|
104
|
+
pageId: string;
|
|
105
|
+
name: string;
|
|
106
|
+
route: string;
|
|
107
|
+
/** The page's key in the plan it is composed from: the run that built it, or `handPageKey(pageId)` for a page the owner
|
|
108
|
+
* made by hand (RD2.1). Absent: kept with no plan page (a legal page). */
|
|
109
|
+
key?: string;
|
|
110
|
+
way: StagedPageWay;
|
|
111
|
+
reason?: StagedPageReason;
|
|
112
|
+
/** The new layout (absent when kept). */
|
|
113
|
+
layout?: SerializedNode[];
|
|
114
|
+
/** The page's settings after a switch (a composed page names this run as its `layoutSource`). */
|
|
115
|
+
pageSettings?: Record<string, unknown>;
|
|
116
|
+
/** Handles of the carry that the new layout does not place — Compare's "Not placed" (R-H3). */
|
|
117
|
+
notPlaced: string[];
|
|
118
|
+
/** Handles placed as they were arranged (a bound part, a block, a kept section — RD-D20). */
|
|
119
|
+
keptArrangement: string[];
|
|
120
|
+
/** What the composer settled alone (a carried link to a node that left, dropped — `mendCarry`). */
|
|
121
|
+
mended: LayoutIssue[];
|
|
122
|
+
/** The model that laid it out (a composed page). */
|
|
123
|
+
model?: string;
|
|
124
|
+
/** How many times the owner asked for this page again (Try another layout · Redo this page — RD3); absent: never. */
|
|
125
|
+
again?: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A page the redesign would ADD (§3e): who wanted it and why, where it goes, what new content it brings — staged, written
|
|
129
|
+
* only by the Switch when it is turned on. */
|
|
130
|
+
export interface StagedAddition {
|
|
131
|
+
/** Its key in the run's plan (`added:<n>`) — what Switch `additions` names. */
|
|
132
|
+
key: string;
|
|
133
|
+
origin: AdditionOrigin;
|
|
134
|
+
/** One plain sentence the owner reads beside it. */
|
|
135
|
+
reason: string;
|
|
136
|
+
name: string;
|
|
137
|
+
/** A NEW address — no page of the studio has it. */
|
|
138
|
+
route: string;
|
|
139
|
+
/** Switched by default: an asked page is on, a suggested one off until the owner turns it on. */
|
|
140
|
+
accepted: boolean;
|
|
141
|
+
/** The page as the Switch writes it (drawn from its sections; the run's plan holds it). */
|
|
142
|
+
layout: SerializedNode[];
|
|
143
|
+
pageSettings: Record<string, unknown>;
|
|
144
|
+
/** The new content types it brings (a type shared by several additions is written with the first one switched). */
|
|
145
|
+
types: string[];
|
|
146
|
+
/** New items it brings, per content type (the samples of a new type, or the items the sentence asked for). */
|
|
147
|
+
items: Record<string, number>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Why a redesign staged no additions without asking, or could not use the answer. */
|
|
151
|
+
export enum AdditionsSkipped {
|
|
152
|
+
/** No sentence, and the owner turned down the suggestions of their last redesign: nothing is asked. */
|
|
153
|
+
NothingToAsk = 'nothing-to-ask',
|
|
154
|
+
/** Asked, and the answer did not pass (after its one re-ask). */
|
|
155
|
+
NotUsable = 'not-usable',
|
|
156
|
+
/** Refused before the call (credits, plan) — the redesign goes on without additions. */
|
|
157
|
+
Refused = 'refused',
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Why the Switch held an addition back: something took its place since it was staged (never overwritten). */
|
|
161
|
+
export enum AdditionHeldBack {
|
|
162
|
+
RouteTaken = 'route-taken',
|
|
163
|
+
TypeExists = 'type-exists',
|
|
164
|
+
SourceTaken = 'source-taken',
|
|
165
|
+
/** It brings a new content type and the person who switched may not add one (an org owner or admin may). */
|
|
166
|
+
TypesNotAllowed = 'types-not-allowed',
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The additions as staged: the pages, and what was asked but could not be added — said on Compare ("Couldn't add …"). */
|
|
170
|
+
export interface RedesignAdditionsStaged {
|
|
171
|
+
pages: StagedAddition[];
|
|
172
|
+
/** New items the sentence asked for into a type the studio HAS, per type — written with the first page switched or,
|
|
173
|
+
* with no page, by the Switch itself when `items` is accepted. */
|
|
174
|
+
items: Record<string, number>;
|
|
175
|
+
/** Refused with a path and not added (the check, or the merged plan's validator). */
|
|
176
|
+
dropped: AdditionIssue[];
|
|
177
|
+
/** Why nothing was asked or the answer could not be used (none: it was asked and read). */
|
|
178
|
+
skipped?: AdditionsSkipped;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface RedesignStaged {
|
|
182
|
+
pages: StagedPage[];
|
|
183
|
+
/** What the redesign would add (§3e) — absent on a run staged before additions existed. */
|
|
184
|
+
additions?: RedesignAdditionsStaged;
|
|
185
|
+
/** The new header and footer (absent: kept — RD-D8). */
|
|
186
|
+
globals?: SerializedNode[];
|
|
187
|
+
/** The look the Switch applies (completed `DesignChoices`). */
|
|
188
|
+
design: Record<string, unknown>;
|
|
189
|
+
/** The placeholders of the staged pages and globals (owner = page key or global slot) — once switched, they are the
|
|
190
|
+
* live site's for those owners (what the gate counts, what a visitor's page leaves out when blank). */
|
|
191
|
+
placeholders: ComposedPlaceholder[];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** What the Switch (and Back) did to one page. */
|
|
195
|
+
export enum RedesignPageResult {
|
|
196
|
+
Switched = 'switched',
|
|
197
|
+
/** Edited after the harvest: not switched (RD-D12) — Compare offers "Redo this page". */
|
|
198
|
+
Stale = 'stale',
|
|
199
|
+
/** The owner kept the old design for it (per-page accept, RD-D9). */
|
|
200
|
+
Declined = 'declined',
|
|
201
|
+
/** Kept as it is by the redesign (`StagedPageWay.Kept`) — nothing to write. */
|
|
202
|
+
Unchanged = 'unchanged',
|
|
203
|
+
/** Back: the snapshot is on the page again. */
|
|
204
|
+
Restored = 'restored',
|
|
205
|
+
/** Back: edited since the switch and not asked to restore — left as it is (RD-D12). */
|
|
206
|
+
EditedSince = 'edited-since',
|
|
207
|
+
/** Back: the page was deleted since the switch. */
|
|
208
|
+
Gone = 'gone',
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The parts of a Switch or a Back, in the order they run — a resumed one carries on after the done ones. */
|
|
212
|
+
export enum RedesignPart {
|
|
213
|
+
/** What the redesign adds — new types, items, sources and pages (§3e) — before the pages, so a new page's links resolve. */
|
|
214
|
+
Additions = 'additions',
|
|
215
|
+
Pages = 'pages',
|
|
216
|
+
Globals = 'globals',
|
|
217
|
+
Look = 'look',
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export const REDESIGN_PARTS: ReadonlyArray<RedesignPart> = Object.values(RedesignPart);
|
|
221
|
+
|
|
222
|
+
export interface RedesignPageOutcome {
|
|
223
|
+
pageId: string;
|
|
224
|
+
result: RedesignPageResult;
|
|
225
|
+
/** The page's fingerprint as the switch (or Back) left it. */
|
|
226
|
+
fingerprint?: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface RedesignSwitch {
|
|
230
|
+
at: Date | string;
|
|
231
|
+
/** The pages the owner accepted (null = every staged page). */
|
|
232
|
+
accepted: string[] | null;
|
|
233
|
+
pages: RedesignPageOutcome[];
|
|
234
|
+
/** Global ids the switch wrote, with their fingerprints (Back puts the old ones back only over these, unchanged). */
|
|
235
|
+
globals: Array<{ id: string; fingerprint: string }>;
|
|
236
|
+
/** The additions the owner turned on (keys); absent = each as staged (`accepted`). */
|
|
237
|
+
additions?: string[] | null;
|
|
238
|
+
/** Exactly what the Switch ADDED (§3e) — the build's record shape, so Back removes these and nothing else, by the
|
|
239
|
+
* build's Undo rule (fingerprint, in use). */
|
|
240
|
+
added?: CreatedRecord[];
|
|
241
|
+
/** Additions held back at the Switch: their address or a type name was taken since — decided once, before the first
|
|
242
|
+
* write, so a resumed Switch writes exactly the same. */
|
|
243
|
+
heldBack?: Array<{ key: string; reason: AdditionHeldBack }>;
|
|
244
|
+
/** Whether the person who switched may add a content type (an org owner or admin). */
|
|
245
|
+
mayAddTypes?: boolean;
|
|
246
|
+
done: RedesignPart[];
|
|
247
|
+
finishedAt?: Date | string;
|
|
248
|
+
error?: BuildStepError;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface RedesignBack {
|
|
252
|
+
at: Date | string;
|
|
253
|
+
/** Pages edited since the switch the owner chose to restore anyway. */
|
|
254
|
+
restoreEdited: string[];
|
|
255
|
+
pages: RedesignPageOutcome[];
|
|
256
|
+
/** Globals edited since the switch, left as they are. */
|
|
257
|
+
keptGlobals: string[];
|
|
258
|
+
/** Look tokens the author edited since, kept (DS8.1). */
|
|
259
|
+
keptTokens: string[];
|
|
260
|
+
/** What the Switch added that Back left — edited since, or still shown by a page that stays (the build's Undo rule). */
|
|
261
|
+
keptAdded?: UndoKept[];
|
|
262
|
+
done: RedesignPart[];
|
|
263
|
+
finishedAt?: Date | string;
|
|
264
|
+
error?: BuildStepError;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The run as `GET …/site-builds/:id` answers a redesign. */
|
|
268
|
+
export interface RedesignRun {
|
|
269
|
+
_id: string;
|
|
270
|
+
organization: string;
|
|
271
|
+
kind: SiteBuildKind.Redesign;
|
|
272
|
+
status: SiteBuildStatus;
|
|
273
|
+
active?: boolean;
|
|
274
|
+
steps: BuildStepRecord<RedesignStep>[];
|
|
275
|
+
request: RedesignRequest;
|
|
276
|
+
/** The build runs whose plans the pages in scope were composed from. */
|
|
277
|
+
sourceRunIds: string[];
|
|
278
|
+
snapshot?: RedesignSnapshot;
|
|
279
|
+
staged?: RedesignStaged;
|
|
280
|
+
switch?: RedesignSwitch;
|
|
281
|
+
back?: RedesignBack;
|
|
282
|
+
requestedBy: string;
|
|
283
|
+
startedAt: Date | string;
|
|
284
|
+
finishedAt?: Date | string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** `GET …/site-builds/:id/back`: what a Back would restore and what it would ask about — never guessed in the browser. */
|
|
288
|
+
export interface RedesignBackPreview {
|
|
289
|
+
open: boolean;
|
|
290
|
+
until: string | null;
|
|
291
|
+
restores: string[];
|
|
292
|
+
/** Pages edited since the switch: Back leaves them unless the owner names them. */
|
|
293
|
+
editedSince: Array<{ pageId: string; name: string }>;
|
|
294
|
+
revertsLook: boolean;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** `GET …/redesign/:id/switch` — what a Switch would do NOW, before the owner clicks it (RD3): each staged page's result as
|
|
298
|
+
* the Switch would judge it (a page changed since the harvest is `stale` — Compare offers Redo this page), and the gate's
|
|
299
|
+
* refusal for the site as the switch would leave it (null: it would pass, or no live page is written). Writes nothing. */
|
|
300
|
+
export interface RedesignSwitchPreview {
|
|
301
|
+
pages: Array<{ pageId: string; name: string; result: RedesignPageResult }>;
|
|
302
|
+
/** The ONE Publish dialog's refusal (iox-cms's 409 body), as `POST …/switch` would answer it with no acknowledgement. */
|
|
303
|
+
gate: unknown | null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** The refusals of a redesign's start, switch and back. */
|
|
307
|
+
export enum RedesignRefusalCode {
|
|
308
|
+
/** No page in scope was built by a site build — there is nothing to redesign. */
|
|
309
|
+
NothingBuilt = 'nothing-built',
|
|
310
|
+
/** A page id in scope is not a page of this organization. */
|
|
311
|
+
UnknownPage = 'unknown-page',
|
|
312
|
+
/** The look asked for is not a look (design-core cannot complete it). */
|
|
313
|
+
InvalidDesign = 'invalid-design',
|
|
314
|
+
/** Switch on a run that is not staged, Back on one that is not switched. */
|
|
315
|
+
WrongStatus = 'wrong-status',
|
|
316
|
+
/** Back after `REDESIGN_BACK_DAYS`. */
|
|
317
|
+
BackClosed = 'back-closed',
|
|
318
|
+
/** One page again: the page is not one of the run's staged pages, or it stays as it is with nothing to lay out
|
|
319
|
+
* (a legal page, a page with no plan to compose it from). */
|
|
320
|
+
NotRedesignable = 'not-redesignable',
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** The day Back closes, or null (not switched). */
|
|
324
|
+
export function redesignBackUntil(run: Pick<RedesignRun, 'switch'>): Date | null {
|
|
325
|
+
const at = run.switch?.finishedAt ?? run.switch?.at;
|
|
326
|
+
return at ? new Date(new Date(at).getTime() + REDESIGN_BACK_DAYS * DAY_MS) : null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** May Back run now: switched, and within `REDESIGN_BACK_DAYS` of the switch. */
|
|
330
|
+
export function redesignBackOpen(run: Pick<RedesignRun, 'status' | 'switch'>, now: Date): boolean {
|
|
331
|
+
const until = redesignBackUntil(run);
|
|
332
|
+
return run.status === SiteBuildStatus.Switched && !!until && now.getTime() <= until.getTime();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** The plan-page key of a page the owner made by hand (RD2.1, RD3-D1 (a)): `hand:<pageId>`. */
|
|
336
|
+
export const HAND_PAGE_KEY_PREFIX = 'hand:';
|
|
337
|
+
|
|
338
|
+
export function handPageKey(pageId: string): string {
|
|
339
|
+
return `${HAND_PAGE_KEY_PREFIX}${pageId}`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Is `key` a hand-made page's plan-page key. */
|
|
343
|
+
export function isHandPageKey(key: string | null | undefined): boolean {
|
|
344
|
+
return typeof key === 'string' && key.startsWith(HAND_PAGE_KEY_PREFIX) && key.length > HAND_PAGE_KEY_PREFIX.length;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The plan page a redesign gives a page the owner made by hand (RD2.1): its address and name, laid out by the model in the
|
|
349
|
+
* layout language (`compose`), every section the owner's (`harvestPage(…, { built: false })`), no sections of its own to
|
|
350
|
+
* fall back on, never added to the navigation (the owner's header decides that, as before).
|
|
351
|
+
*/
|
|
352
|
+
export function handPlanPage(page: Pick<RedesignSnapshotPage, 'pageId' | 'name' | 'route'>): PagePlan {
|
|
353
|
+
return { key: handPageKey(page.pageId), name: page.name, route: page.route, inNav: false, sections: [], compose: true };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** May the owner let a redesign go (Discard): staged, or failed before any Switch wrote a page. */
|
|
357
|
+
export function redesignDiscardable(run: Pick<RedesignRun, 'status' | 'switch'>): boolean {
|
|
358
|
+
return run.status === SiteBuildStatus.Done || (run.status === SiteBuildStatus.Failed && !run.switch);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** Is a run a redesign (a stored run of either kind). */
|
|
362
|
+
export function isRedesignRun(run: { kind?: unknown } | null | undefined): boolean {
|
|
363
|
+
return run?.kind === SiteBuildKind.Redesign;
|
|
364
|
+
}
|