@vectoriox/iox-ui 5.117.0 → 5.118.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 +169 -5
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +309 -14
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assist-core/assist-turn.ts +7 -4
- package/src/assist-core/page-edits.ts +39 -0
- package/src/assist-core/page-style.ts +346 -0
- package/src/assist-core/page-words.ts +37 -9
- package/src/assist-core/public-api.ts +5 -2
- package/src/assist-core/surfaces.ts +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, walkSerialized } from '@vectoriox/iox-ui/generation-core';
|
|
1
|
+
import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, NODE_BASELINES, walkSerialized } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
import { elementStylesFor, colorSchemeOf, ColorScheme, COLOR_SCHEME_TYPES, elementStyleById, COLOR_SCHEMES, NEW_NODE_STYLE_DEFAULTS, setColorScheme, switchElementStyle } from '@vectoriox/iox-ui/design-core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The surfaces AI Assist runs on (ai-assist-plan §2, §4): each screen that offers a prompt registers ONE spec — what it
|
|
@@ -96,7 +97,7 @@ const SURFACES = {
|
|
|
96
97
|
// Style, Sections and Look & motion join as each slice ships (ai-assist-plan §6, AI2).
|
|
97
98
|
[AssistSurface.BuilderPage]: spec({
|
|
98
99
|
surface: AssistSurface.BuilderPage,
|
|
99
|
-
families: [EditFamily.Words],
|
|
100
|
+
families: [EditFamily.Words, EditFamily.Style],
|
|
100
101
|
commit: CommitKind.BuilderStep,
|
|
101
102
|
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
102
103
|
permissions: [AssistPermission.PageUpdate],
|
|
@@ -1012,6 +1013,266 @@ function turnLocale(sentence, fields, values, uiLang) {
|
|
|
1012
1013
|
/** The language's own name in the admin's language (`en` → "English" / "אנגלית"). */
|
|
1013
1014
|
const languageName = (locale, uiLang) => displayName(locale, uiLang) ?? locale;
|
|
1014
1015
|
|
|
1016
|
+
/**
|
|
1017
|
+
* Surface S1 (the builder, this page), family `style` (ai-assist-plan §4, AI2b; ai-session-panel-plan `setStyle` /
|
|
1018
|
+
* `setScheme`): an element takes ANOTHER of the look's element styles, a section (or a box) another colour scheme — never
|
|
1019
|
+
* a CSS value, a colour or a size. What a node may take is a closed list: the other members of the swap set its current
|
|
1020
|
+
* style is in that its type may wear ({@link ASK_STYLE_SETS}). The SAME pure functions run on the server (the check on a
|
|
1021
|
+
* copy) and in the builder (the trial): `pageLooks` (the targets and their handles), `styleJsonSchema`,
|
|
1022
|
+
* `decodeStyleAnswers`, `applyStyleEdits` — design-core's `switchElementStyle` (the author's own changes are kept) and
|
|
1023
|
+
* `setColorScheme` (the ONE scheme writer), all or none.
|
|
1024
|
+
*/
|
|
1025
|
+
/**
|
|
1026
|
+
* The styles an owner may swap between by asking — each set is ONE kind of thing (a button, a heading, words, a box, a
|
|
1027
|
+
* badge). Every other element style (a tab, an accordion part, a cart button, the navigation bar) belongs to the recipe
|
|
1028
|
+
* that stamped it and is never offered. A node wearing a style is offered the union of the sets that style is in, kept
|
|
1029
|
+
* to the styles its type may wear (design-core `elementStylesFor`).
|
|
1030
|
+
*/
|
|
1031
|
+
const ASK_STYLE_SETS = [
|
|
1032
|
+
['button-primary', 'button-secondary', 'button-ghost'],
|
|
1033
|
+
['display', 'h1', 'h2', 'h3', 'eyebrow'],
|
|
1034
|
+
['lead', 'body', 'small', 'eyebrow'],
|
|
1035
|
+
['section', 'box', 'card', 'panel'],
|
|
1036
|
+
['badge-neutral', 'badge-success', 'badge-warning', 'badge-accent'],
|
|
1037
|
+
];
|
|
1038
|
+
/** A box that only holds things — offered a style only when it is the selection ("make this a card"). */
|
|
1039
|
+
const PLAIN_BOX_STYLE = 'box';
|
|
1040
|
+
/** A box wearing one of these paints its own ground — a colour scheme shows on it. */
|
|
1041
|
+
const SURFACE_STYLES = new Set(['section', 'card', 'panel']);
|
|
1042
|
+
const paintsGround = (style) => SURFACE_STYLES.has(style ?? '');
|
|
1043
|
+
/** A Text wearing this is a ButtonBlock's words: the button is the style target. */
|
|
1044
|
+
const BUTTON_LABEL_STYLE$1 = 'button-label';
|
|
1045
|
+
/** The styles a node may take by asking — its own among them — or [] when it is not a target. */
|
|
1046
|
+
function askableStyles(node) {
|
|
1047
|
+
const current = node.elementStyle;
|
|
1048
|
+
if (!current)
|
|
1049
|
+
return [];
|
|
1050
|
+
const wears = new Set(elementStylesFor(node.type).map(s => s.id));
|
|
1051
|
+
const offered = new Set(ASK_STYLE_SETS.filter(set => set.includes(current)).flat().filter(id => wears.has(id)));
|
|
1052
|
+
return offered.size > 1 ? [...offered] : [];
|
|
1053
|
+
}
|
|
1054
|
+
const isRecipePart = (node) => !!node.role && node.role.includes('.');
|
|
1055
|
+
/**
|
|
1056
|
+
* Every style / scheme target of the page in reading order. A node that carries words keeps its words handle
|
|
1057
|
+
* (`wordHandles`: node id → `s0.heading1`); a ButtonBlock is named by its words' handle (`s0.button1`); a section root is
|
|
1058
|
+
* `s{i}`; any other box is `s{i}.box{n}`. `selectedId` lets a plain box that is the selection be a target.
|
|
1059
|
+
*/
|
|
1060
|
+
function pageLooks(layout, wordHandles, selectedId) {
|
|
1061
|
+
const out = [];
|
|
1062
|
+
layout.forEach((root, index) => {
|
|
1063
|
+
let boxes = 0;
|
|
1064
|
+
const visit = (node, lineage) => {
|
|
1065
|
+
const here = [...lineage, node.id];
|
|
1066
|
+
const styles = askableStyles(node);
|
|
1067
|
+
const isRoot = node === root;
|
|
1068
|
+
const plain = node.elementStyle === PLAIN_BOX_STYLE && !isRoot && node.id !== selectedId;
|
|
1069
|
+
const takesStyle = styles.length > 0 && !plain && !(isRecipePart(node) && !wordHandles.has(node.id) && node.type !== 'ButtonBlock');
|
|
1070
|
+
const scheme = colorSchemeOf(node) ?? ColorScheme.Default;
|
|
1071
|
+
// A scheme re-declares tokens: only a node that paints a ground of its own (a section, card or panel style) shows
|
|
1072
|
+
// it — on any other the words take the scheme's ink over the page's ground (white on white). A node that may
|
|
1073
|
+
// TAKE such a style is offered one too; the check refuses the scheme unless the turn gives it that style.
|
|
1074
|
+
const takesScheme = COLOR_SCHEME_TYPES.includes(node.type) && !isRecipePart(node)
|
|
1075
|
+
&& (paintsGround(node.elementStyle) || scheme !== ColorScheme.Default || (takesStyle && styles.some(paintsGround)));
|
|
1076
|
+
if (takesStyle || takesScheme) {
|
|
1077
|
+
const handle = lookHandle(node, index, isRoot, wordHandles, () => ++boxes);
|
|
1078
|
+
if (handle) {
|
|
1079
|
+
out.push({
|
|
1080
|
+
look: {
|
|
1081
|
+
handle,
|
|
1082
|
+
label: lookLabel(handle, root, index),
|
|
1083
|
+
...(takesStyle ? { style: node.elementStyle, styles } : {}),
|
|
1084
|
+
...(takesScheme ? { scheme } : {}),
|
|
1085
|
+
},
|
|
1086
|
+
section: index, nodeId: node.id, type: node.type, lineage: here,
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
for (const child of node.children ?? [])
|
|
1091
|
+
visit(child, here);
|
|
1092
|
+
};
|
|
1093
|
+
visit(root, []);
|
|
1094
|
+
});
|
|
1095
|
+
return out;
|
|
1096
|
+
}
|
|
1097
|
+
function lookHandle(node, section, isRoot, wordHandles, nextBox) {
|
|
1098
|
+
if (isRoot)
|
|
1099
|
+
return `s${section}`;
|
|
1100
|
+
const own = wordHandles.get(node.id);
|
|
1101
|
+
if (own)
|
|
1102
|
+
return own;
|
|
1103
|
+
if (node.type === 'ButtonBlock') {
|
|
1104
|
+
const label = (node.children ?? []).find(c => c.type === 'Text' && c.elementStyle === BUTTON_LABEL_STYLE$1);
|
|
1105
|
+
return label ? wordHandles.get(label.id) ?? null : null;
|
|
1106
|
+
}
|
|
1107
|
+
return `s${section}.box${nextBox()}`;
|
|
1108
|
+
}
|
|
1109
|
+
const capitalise$1 = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
1110
|
+
/** "Hero · ground" → "Hero"; a composed section's id label ("hero-1") reads as words; else "Section 3". */
|
|
1111
|
+
function sectionLabel(node, index) {
|
|
1112
|
+
const own = (node.label ?? '').split(' · ')[0].trim();
|
|
1113
|
+
return own ? capitalise$1(own.replace(/[-_]+/g, ' ')) : `Section ${index + 1}`;
|
|
1114
|
+
}
|
|
1115
|
+
/** `s0` → the section's own name; `s0.box2` → "Box 2"; `s1.heading1` → "Heading 1". */
|
|
1116
|
+
function lookLabel(handle, root, index) {
|
|
1117
|
+
const tail = handle.split('.').slice(1).join(' ');
|
|
1118
|
+
if (!tail)
|
|
1119
|
+
return sectionLabel(root, index);
|
|
1120
|
+
return tail.replace(/^([a-z]+)(\d+)/, (_, k, n) => `${capitalise$1(k)} ${n}`);
|
|
1121
|
+
}
|
|
1122
|
+
/** The labels of the styles and schemes a brief mentions — the model reads ids, the owner reads these. */
|
|
1123
|
+
function lookNames(looks) {
|
|
1124
|
+
const styles = {};
|
|
1125
|
+
for (const look of looks)
|
|
1126
|
+
for (const id of look.styles ?? [])
|
|
1127
|
+
styles[id] = elementStyleById(id)?.label ?? id;
|
|
1128
|
+
const schemes = looks.some(l => l.scheme) ? Object.fromEntries(COLOR_SCHEMES.map(s => [s.id, s.label])) : {};
|
|
1129
|
+
return { styles, schemes };
|
|
1130
|
+
}
|
|
1131
|
+
var StyleAnswerKey;
|
|
1132
|
+
(function (StyleAnswerKey) {
|
|
1133
|
+
StyleAnswerKey["Styles"] = "styles";
|
|
1134
|
+
StyleAnswerKey["Schemes"] = "schemes";
|
|
1135
|
+
StyleAnswerKey["Note"] = "note";
|
|
1136
|
+
})(StyleAnswerKey || (StyleAnswerKey = {}));
|
|
1137
|
+
/**
|
|
1138
|
+
* The strict format of family `style` for the focus — ONE request: a list of `{ handle, style }` and a list of
|
|
1139
|
+
* `{ handle, scheme }`, each handle an enum of the focus's targets ([] leaves everything as it is). A list whose enum
|
|
1140
|
+
* would be empty is left out. The pairing (does THIS handle take THAT style) is the check's, so the format stays small
|
|
1141
|
+
* whatever the page holds.
|
|
1142
|
+
*/
|
|
1143
|
+
function styleJsonSchema(looks) {
|
|
1144
|
+
const styled = Object.entries(looks).filter(([, t]) => t.styles.length);
|
|
1145
|
+
const schemed = Object.entries(looks).filter(([, t]) => t.scheme);
|
|
1146
|
+
if (!styled.length && !schemed.length)
|
|
1147
|
+
return { parts: [], handles: [] };
|
|
1148
|
+
const properties = {};
|
|
1149
|
+
if (styled.length) {
|
|
1150
|
+
const ids = [...new Set(styled.flatMap(([, t]) => t.styles))];
|
|
1151
|
+
properties[StyleAnswerKey.Styles] = {
|
|
1152
|
+
...jsonListOf(jsonClosedObject({
|
|
1153
|
+
handle: jsonOneOf(styled.map(([h]) => h)),
|
|
1154
|
+
style: jsonOneOf(ids),
|
|
1155
|
+
}, ['handle', 'style'])),
|
|
1156
|
+
description: 'An element taking another of the styles the focus lists for it; [] changes no style.',
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
if (schemed.length) {
|
|
1160
|
+
properties[StyleAnswerKey.Schemes] = {
|
|
1161
|
+
...jsonListOf(jsonClosedObject({
|
|
1162
|
+
handle: jsonOneOf(schemed.map(([h]) => h)),
|
|
1163
|
+
scheme: jsonOneOf(COLOR_SCHEMES.map(s => s.id)),
|
|
1164
|
+
}, ['handle', 'scheme'])),
|
|
1165
|
+
description: 'A section or box taking another colour scheme; [] changes no colours.',
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
properties[StyleAnswerKey.Note] = { ...jsonText(), description: 'One short line for the owner on what changed, or what needs them.' };
|
|
1169
|
+
const part = jsonClosedObject(properties, Object.keys(properties));
|
|
1170
|
+
assertAssistBudget('style', [part]);
|
|
1171
|
+
return { parts: [part], handles: [[...new Set([...styled, ...schemed].map(([h]) => h))]] };
|
|
1172
|
+
}
|
|
1173
|
+
const listOf = (answer, key) => {
|
|
1174
|
+
const list = answer && typeof answer === 'object' ? answer[key] : undefined;
|
|
1175
|
+
return Array.isArray(list) ? list.filter((x) => !!x && typeof x === 'object') : [];
|
|
1176
|
+
};
|
|
1177
|
+
/** The answer → the edits it makes. */
|
|
1178
|
+
function decodeStyleAnswers(answers) {
|
|
1179
|
+
return answers.flatMap(answer => [
|
|
1180
|
+
...listOf(answer, StyleAnswerKey.Styles).map(x => ({ handle: String(x['handle'] ?? ''), style: String(x['style'] ?? '') })),
|
|
1181
|
+
...listOf(answer, StyleAnswerKey.Schemes).map(x => ({ handle: String(x['handle'] ?? ''), scheme: String(x['scheme'] ?? '') })),
|
|
1182
|
+
]);
|
|
1183
|
+
}
|
|
1184
|
+
const isStyleEdit = (e) => typeof e.style === 'string';
|
|
1185
|
+
const isSchemeEdit = (e) => typeof e.scheme === 'string';
|
|
1186
|
+
/** Which kind of change a change card shows. */
|
|
1187
|
+
var PageChangeOp;
|
|
1188
|
+
(function (PageChangeOp) {
|
|
1189
|
+
PageChangeOp["Words"] = "words";
|
|
1190
|
+
PageChangeOp["Style"] = "style";
|
|
1191
|
+
PageChangeOp["Scheme"] = "scheme";
|
|
1192
|
+
})(PageChangeOp || (PageChangeOp = {}));
|
|
1193
|
+
/** The serialized baseline: the type's constructor values, its text colour released as a new node's is (generation-core `createSerializedNode`). */
|
|
1194
|
+
const serializedBaselineStyles = type => {
|
|
1195
|
+
const own = { ...(NODE_BASELINES[type]?.styleProps ?? {}) };
|
|
1196
|
+
for (const [name, value] of Object.entries(NEW_NODE_STYLE_DEFAULTS))
|
|
1197
|
+
if (name in own)
|
|
1198
|
+
own[name] = value;
|
|
1199
|
+
return own;
|
|
1200
|
+
};
|
|
1201
|
+
const schemeLabel = (id) => COLOR_SCHEMES.find(s => s.id === id)?.label ?? id;
|
|
1202
|
+
const styleLabel = (id) => elementStyleById(id)?.label ?? id;
|
|
1203
|
+
/**
|
|
1204
|
+
* Family `style`, applied — the SAME check on the server and in the builder. All or none; never mutates its input. A
|
|
1205
|
+
* handle not in the focus, a style the target may not take, a scheme on a target that takes none are refused (re-asked
|
|
1206
|
+
* once by the server, never repaired here); an edit that changes nothing is dropped.
|
|
1207
|
+
*/
|
|
1208
|
+
function applyStyleEdits(layout, edits, ctx) {
|
|
1209
|
+
const result = JSON.parse(JSON.stringify(layout));
|
|
1210
|
+
const byId = new Map();
|
|
1211
|
+
walkSerialized(result, n => byId.set(n.id, n));
|
|
1212
|
+
const baseline = ctx.baseline ?? serializedBaselineStyles;
|
|
1213
|
+
const issues = [];
|
|
1214
|
+
const changes = [];
|
|
1215
|
+
const seen = new Set();
|
|
1216
|
+
// Styles first: a scheme may need the style the same turn gives its node (a plain box made a panel, then darkened).
|
|
1217
|
+
const ordered = [...edits.filter(e => !isSchemeEdit(e)), ...edits.filter(isSchemeEdit)];
|
|
1218
|
+
for (const edit of ordered) {
|
|
1219
|
+
const scheme = isSchemeEdit(edit);
|
|
1220
|
+
const key = `${scheme ? 'scheme' : 'style'}:${edit.handle}`;
|
|
1221
|
+
const refuse = (code, message) => issues.push({ code, handle: edit.handle, message });
|
|
1222
|
+
if (seen.has(key)) {
|
|
1223
|
+
refuse(AssistIssueCode.Duplicate, `"${edit.handle}" is given two ${scheme ? 'schemes' : 'styles'}`);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
seen.add(key);
|
|
1227
|
+
const target = Object.prototype.hasOwnProperty.call(ctx.looks, edit.handle) ? ctx.looks[edit.handle] : undefined;
|
|
1228
|
+
const node = target ? byId.get(target.id) : undefined;
|
|
1229
|
+
if (!target || !node) {
|
|
1230
|
+
refuse(AssistIssueCode.UnknownHandle, `"${edit.handle}" is not an element of the focus`);
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
if (scheme) {
|
|
1234
|
+
const to = edit.scheme;
|
|
1235
|
+
if (!target.scheme) {
|
|
1236
|
+
refuse(AssistIssueCode.NotAnOption, `${target.label} takes no colour scheme`);
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
if (!COLOR_SCHEMES.some(s => s.id === to)) {
|
|
1240
|
+
refuse(AssistIssueCode.NotAnOption, `"${to}" is not a colour scheme`);
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1243
|
+
const from = colorSchemeOf(node) ?? ColorScheme.Default;
|
|
1244
|
+
if (to !== ColorScheme.Default && !paintsGround(node.elementStyle)) {
|
|
1245
|
+
refuse(AssistIssueCode.NotAnOption, `${target.label} paints no ground of its own — give it the section, card or panel style in the same answer, or leave its colours`);
|
|
1246
|
+
continue;
|
|
1247
|
+
}
|
|
1248
|
+
if (!setColorScheme(node, to))
|
|
1249
|
+
continue;
|
|
1250
|
+
changes.push({ op: PageChangeOp.Scheme, handle: edit.handle, nodeId: node.id, label: target.label, from, to, before: schemeLabel(from), after: schemeLabel(to) });
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
const to = edit.style;
|
|
1254
|
+
if (!target.styles.includes(to)) {
|
|
1255
|
+
refuse(AssistIssueCode.NotAnOption, `${target.label} may take ${target.styles.map(s => `"${s}"`).join(', ')} — not "${to}"`);
|
|
1256
|
+
continue;
|
|
1257
|
+
}
|
|
1258
|
+
const from = node.elementStyle ?? '';
|
|
1259
|
+
if (from === to)
|
|
1260
|
+
continue;
|
|
1261
|
+
const switched = switchElementStyle(node, from, to, baseline(node.type));
|
|
1262
|
+
if (!switched.applied) {
|
|
1263
|
+
refuse(AssistIssueCode.NotAnOption, `"${to}" is not an element style`);
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
changes.push({
|
|
1267
|
+
op: PageChangeOp.Style, handle: edit.handle, nodeId: node.id, label: target.label, from, to,
|
|
1268
|
+
before: styleLabel(from), after: styleLabel(to), ...(switched.kept.length ? { keptOwn: switched.kept.length } : {}),
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
if (issues.length)
|
|
1272
|
+
return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
|
|
1273
|
+
return { ok: true, result, changes, issues: [] };
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1015
1276
|
/**
|
|
1016
1277
|
* Surface S1 (the builder, this page), family `words` (ai-assist-plan §4, ai-session-panel-plan §3b–§3d): the page as
|
|
1017
1278
|
* the model sees it — sections in order, each a handle (`s0`), the parts that carry words as handles (`s0.heading1`,
|
|
@@ -1062,11 +1323,6 @@ function readableWords(value) {
|
|
|
1062
1323
|
}
|
|
1063
1324
|
const sectionHandle = (index) => `s${index}`;
|
|
1064
1325
|
const capitalise = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
1065
|
-
/** "Hero · ground" → "Hero"; a composed section's id label ("hero-1") reads as words. */
|
|
1066
|
-
function sectionLabel(node, index) {
|
|
1067
|
-
const own = (node.label ?? '').split(' · ')[0].trim();
|
|
1068
|
-
return own ? capitalise(own.replace(/[-_]+/g, ' ')) : `Section ${index + 1}`;
|
|
1069
|
-
}
|
|
1070
1326
|
function boundLabel(node, prop) {
|
|
1071
1327
|
const b = (node.bindings ?? []).find(x => x.prop === prop);
|
|
1072
1328
|
return b ? [b.source, b.path].filter(Boolean).join(' ▸ ') : undefined;
|
|
@@ -1133,6 +1389,11 @@ function summarizePage(layout, ctx) {
|
|
|
1133
1389
|
const scope = selectedSection < 0 ? AssistScope.Page : asked;
|
|
1134
1390
|
const inFocus = (w) => scope === AssistScope.Page || w.section === selectedSection;
|
|
1135
1391
|
const selectedParts = scope === AssistScope.Node ? walked.filter(w => w.lineage.includes(ctx.selectedId)) : [];
|
|
1392
|
+
const wordHandles = new Map(walked.filter(w => !w.part.handle.split('.')[2]).map(w => [w.nodeId, w.part.handle]));
|
|
1393
|
+
const walkedLooks = pageLooks(layout, wordHandles, ctx.selectedId);
|
|
1394
|
+
const selectedWords = new Set(selectedParts.map(w => w.part.handle));
|
|
1395
|
+
const lookInFocus = (l) => scope === AssistScope.Page || (l.section === selectedSection
|
|
1396
|
+
&& (scope === AssistScope.Section || l.lineage.includes(ctx.selectedId) || selectedWords.has(l.look.handle)));
|
|
1136
1397
|
const sections = layout
|
|
1137
1398
|
.map((root, index) => ({ root, index }))
|
|
1138
1399
|
.filter(({ index }) => scope === AssistScope.Page || index === selectedSection)
|
|
@@ -1140,6 +1401,10 @@ function summarizePage(layout, ctx) {
|
|
|
1140
1401
|
handle: sectionHandle(index),
|
|
1141
1402
|
label: sectionLabel(root, index),
|
|
1142
1403
|
parts: walked.filter(w => w.section === index).map(w => ({ ...w.part, words: clipText(w.part.words, FOCUS_TEXT_CHARS) })),
|
|
1404
|
+
...(() => {
|
|
1405
|
+
const looks = walkedLooks.filter(l => l.section === index).map(l => l.look);
|
|
1406
|
+
return looks.length ? { looks } : {};
|
|
1407
|
+
})(),
|
|
1143
1408
|
}));
|
|
1144
1409
|
const around = layout
|
|
1145
1410
|
.map((root, index) => ({ root, index }))
|
|
@@ -1156,6 +1421,13 @@ function summarizePage(layout, ctx) {
|
|
|
1156
1421
|
handles[w.part.handle] = { key: w.prop, path: [], id: w.nodeId };
|
|
1157
1422
|
}
|
|
1158
1423
|
layout.forEach((root, index) => { nodes[sectionHandle(index)] = root.id; });
|
|
1424
|
+
const focusLooks = walkedLooks.filter(lookInFocus);
|
|
1425
|
+
const looks = Object.fromEntries(focusLooks.map(l => [l.look.handle, {
|
|
1426
|
+
id: l.nodeId, type: l.type, label: l.look.label, styles: [...(l.look.styles ?? [])], scheme: l.look.scheme !== undefined,
|
|
1427
|
+
}]));
|
|
1428
|
+
for (const l of walkedLooks)
|
|
1429
|
+
nodes[l.look.handle] ??= l.nodeId;
|
|
1430
|
+
const names = lookNames(focusLooks.map(l => l.look));
|
|
1159
1431
|
const focusWalked = scope === AssistScope.Node && selectedParts.length ? selectedParts : walked.filter(inFocus);
|
|
1160
1432
|
const never = focusWalked.filter(w => w.part.bound)
|
|
1161
1433
|
.map(w => ({ handle: w.part.handle, label: w.part.label, reason: `its words come from ${w.part.bound} — change them in that item` }));
|
|
@@ -1167,12 +1439,19 @@ function summarizePage(layout, ctx) {
|
|
|
1167
1439
|
widensTo: WIDENS[scope] ?? [],
|
|
1168
1440
|
};
|
|
1169
1441
|
const selectedNode = selectedParts[0];
|
|
1442
|
+
const selectedLook = scope === AssistScope.Node ? focusLooks.find(l => l.nodeId === ctx.selectedId) : undefined;
|
|
1170
1443
|
const focus = {
|
|
1171
1444
|
scope,
|
|
1172
1445
|
page: ctx.page,
|
|
1173
1446
|
sections,
|
|
1174
|
-
selected:
|
|
1175
|
-
|
|
1447
|
+
selected: [...new Set([
|
|
1448
|
+
...selectedParts.map(w => w.part.handle),
|
|
1449
|
+
...(scope === AssistScope.Node ? focusLooks.map(l => l.look.handle) : []),
|
|
1450
|
+
])],
|
|
1451
|
+
...(selectedLook ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedLook.look.label}` }
|
|
1452
|
+
: selectedNode ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedNode.part.label}` } : {}),
|
|
1453
|
+
...(Object.keys(names.styles).length ? { styleNames: names.styles } : {}),
|
|
1454
|
+
...(Object.keys(names.schemes).length ? { schemeNames: names.schemes } : {}),
|
|
1176
1455
|
};
|
|
1177
1456
|
return {
|
|
1178
1457
|
brief: {
|
|
@@ -1186,6 +1465,7 @@ function summarizePage(layout, ctx) {
|
|
|
1186
1465
|
handles,
|
|
1187
1466
|
focusHandles: focusWalked.filter(w => !w.part.bound).map(w => w.part.handle),
|
|
1188
1467
|
nodes,
|
|
1468
|
+
looks,
|
|
1189
1469
|
};
|
|
1190
1470
|
}
|
|
1191
1471
|
var WordsAnswerKey;
|
|
@@ -1316,7 +1596,7 @@ function applyWordEdits(layout, edits, ctx) {
|
|
|
1316
1596
|
continue;
|
|
1317
1597
|
written.push({ handle: edit.handle, text: readable });
|
|
1318
1598
|
node.props = { ...(node.props ?? {}), [prop]: stored };
|
|
1319
|
-
changes.push({ handle: edit.handle, nodeId: node.id, ...partLabel(node, prop, edit.handle), before: readableWords(before), after: readable });
|
|
1599
|
+
changes.push({ op: PageChangeOp.Words, handle: edit.handle, nodeId: node.id, ...partLabel(node, prop, edit.handle), before: readableWords(before), after: readable });
|
|
1320
1600
|
}
|
|
1321
1601
|
issues.push(...assistFactIssues(written, { words: ctx.words, sentence: ctx.sentence, existing: pageTexts(layout) }));
|
|
1322
1602
|
if (issues.length)
|
|
@@ -1379,6 +1659,19 @@ function pageWriteLocale(layout, ctx) {
|
|
|
1379
1659
|
return ctx.uiLang;
|
|
1380
1660
|
}
|
|
1381
1661
|
|
|
1662
|
+
const isWordEdit = (e) => 'value' in e;
|
|
1663
|
+
function applyPageEdits(layout, edits, ctx) {
|
|
1664
|
+
const words = applyWordEdits(layout, edits.filter(isWordEdit), {
|
|
1665
|
+
handles: ctx.summary.handles, never: ctx.summary.brief.rules.never, sentence: ctx.sentence, words: ctx.words,
|
|
1666
|
+
});
|
|
1667
|
+
const looks = edits.filter((e) => !isWordEdit(e) && (isStyleEdit(e) || isSchemeEdit(e)));
|
|
1668
|
+
const style = applyStyleEdits(words.result, looks, { looks: ctx.summary.looks, baseline: ctx.baseline });
|
|
1669
|
+
const issues = [...words.issues, ...style.issues];
|
|
1670
|
+
if (issues.length)
|
|
1671
|
+
return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
|
|
1672
|
+
return { ok: true, result: style.result, changes: [...words.changes, ...style.changes], issues: [] };
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1382
1675
|
/**
|
|
1383
1676
|
* The turn wire (plan §3d) — what cms-client posts and polls and iox-cms stores and answers, ONE definition both sides
|
|
1384
1677
|
* import (generation-core `ai-run.ts` is the precedent for generations). A turn is a document on the jobs runner:
|
|
@@ -1399,6 +1692,7 @@ const isTerminalTurn = (status) => TERMINAL.has(status);
|
|
|
1399
1692
|
const ASSIST_MODEL_AUTO = 'auto';
|
|
1400
1693
|
const ASSIST_POLL_MS = 750;
|
|
1401
1694
|
const MAX_SENTENCE_CHARS = 2000;
|
|
1695
|
+
const isLookChange = (c) => 'op' in c && (c.op === PageChangeOp.Style || c.op === PageChangeOp.Scheme);
|
|
1402
1696
|
/** A turn's own refusals and failures, beside generation-core's `AiRefusalCode`s (credits, plan, key), which a turn returns as they are. */
|
|
1403
1697
|
var AssistRefusalCode;
|
|
1404
1698
|
(function (AssistRefusalCode) {
|
|
@@ -1463,7 +1757,7 @@ function assistSessionKey(surface, target = {}) {
|
|
|
1463
1757
|
}
|
|
1464
1758
|
const SENTENCE_IN_MEMORY_CHARS = 80;
|
|
1465
1759
|
function outcome(turn) {
|
|
1466
|
-
const named = (list) => (list ?? []).map(c => ('locale' in c && c.locale ? `${c.label} (${c.locale})` : c.label)).join(', ');
|
|
1760
|
+
const named = (list) => (list ?? []).map(c => (isLookChange(c) ? `${c.label} → ${c.after}` : 'locale' in c && c.locale ? `${c.label} (${c.locale})` : c.label)).join(', ');
|
|
1467
1761
|
switch (turn.status) {
|
|
1468
1762
|
case AssistTurnStatus.Refused: return `refused: ${turn.refusal?.message ?? ''}`.trim();
|
|
1469
1763
|
case AssistTurnStatus.Failed: return 'failed';
|
|
@@ -1534,16 +1828,17 @@ function validateTurnRequest(req) {
|
|
|
1534
1828
|
* request, and family `fields` for surface S2 (one content item) — its brief (`summarizeItem`), its strict output format
|
|
1535
1829
|
* (`fieldsJsonSchema`) and the ONE check that applies an answer (`applyFieldEdits`), run by iox-cms on a copy and by
|
|
1536
1830
|
* cms-client as the trial — and family `words` for surface S1 (the builder, this page): `summarizePage`, `wordsJsonSchema`,
|
|
1537
|
-
* `applyWordEdits`, `pageSuggestions
|
|
1831
|
+
* `applyWordEdits`, `pageSuggestions` — and family `style` (`pageLooks`, `styleJsonSchema`, `applyStyleEdits`; both applied as
|
|
1832
|
+
* one turn by `applyPageEdits`). Every family's words pass ONE fact gate (`assistFactIssues` over generation-core's
|
|
1538
1833
|
* `factIssues`, R-H2). Pure: no transport, no clock, no randomness.
|
|
1539
1834
|
* ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets, jest
|
|
1540
1835
|
* moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM. It imports generation-core (the strict
|
|
1541
|
-
* schema builders and budget), so a consumer maps
|
|
1836
|
+
* schema builders and budget) and design-core (element styles, schemes), so a consumer maps all three.
|
|
1542
1837
|
*/
|
|
1543
1838
|
|
|
1544
1839
|
/**
|
|
1545
1840
|
* Generated bundle index. Do not edit.
|
|
1546
1841
|
*/
|
|
1547
1842
|
|
|
1548
|
-
export { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistIssueCode, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, NEW_TARGET, NONE_TEXT, NeverWriteReason, PAGE_WORD_SLOTS, PagePartKind, PageSuggestionKind, RouteAnswerKey, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, SurfaceStatus, WORDS_PER_PART, WordsAnswerKey, applyFieldEdits, applyWordEdits, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeWordsAnswers, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, isEmptyFieldValue, isPlainRecord, isSessionOf, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, memoryLine, namedLocale, pageSuggestions, pageWriteLocale, paragraphsToRichText, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sessionMemory, summarizeItem, summarizePage, surfacePermissions, surfaceSpec, titleField, turnLocale, unknownHandles, validateTurnRequest, wordsJsonSchema };
|
|
1843
|
+
export { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASK_STYLE_SETS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistIssueCode, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, NEW_TARGET, NONE_TEXT, NeverWriteReason, PAGE_WORD_SLOTS, PageChangeOp, PagePartKind, PageSuggestionKind, RouteAnswerKey, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, StyleAnswerKey, SurfaceStatus, WORDS_PER_PART, WordsAnswerKey, applyFieldEdits, applyPageEdits, applyStyleEdits, applyWordEdits, askableStyles, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeStyleAnswers, decodeWordsAnswers, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, isEmptyFieldValue, isPlainRecord, isSchemeEdit, isSessionOf, isStyleEdit, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, lookNames, memoryLine, namedLocale, pageLooks, pageSuggestions, pageWriteLocale, paragraphsToRichText, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sectionLabel, serializedBaselineStyles, sessionMemory, styleJsonSchema, summarizeItem, summarizePage, surfacePermissions, surfaceSpec, titleField, turnLocale, unknownHandles, validateTurnRequest, wordsJsonSchema };
|
|
1549
1844
|
//# sourceMappingURL=vectoriox-iox-ui-assist-core.mjs.map
|