@yahoo/uds-create-config 5.34.3 → 5.35.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/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/dist/spec/bake.d.ts +84 -0
- package/dist/spec/bake.js +405 -0
- package/dist/spec/cell.d.ts +32 -1
- package/dist/spec/cell.js +84 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/spec/cell.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ declare class Cell {
|
|
|
27
27
|
private memoDefaults;
|
|
28
28
|
private memoConditional;
|
|
29
29
|
private memoProps;
|
|
30
|
+
private memoContent;
|
|
30
31
|
private memoEntry;
|
|
31
32
|
private memoHolding;
|
|
32
33
|
private memoOwn;
|
|
@@ -40,6 +41,16 @@ declare class Cell {
|
|
|
40
41
|
get conditional(): Record<string, unknown>;
|
|
41
42
|
/** The values in force: the defaults, what holds for the cell, then the coordinate itself. */
|
|
42
43
|
get props(): Record<string, unknown>;
|
|
44
|
+
/** The preview content the cell shows: the `*` entry, then every entry that holds for it. What a
|
|
45
|
+
* drop seeds and a placed instance compares its own content against; no declared or code
|
|
46
|
+
* default is in it. */
|
|
47
|
+
get content(): Record<string, unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* Whether this is the component's default on the canvas: the cell "Set as default" chose, where a
|
|
50
|
+
* drop lands. Every axis the coordinate names matches the default cell's, the coordinate names at
|
|
51
|
+
* least one, and no modifier is forced. {@link isDefaults} asks about the defaults in code.
|
|
52
|
+
*/
|
|
53
|
+
isCanvasDefault(modifiers?: readonly string[]): boolean;
|
|
43
54
|
/** The `preview` entry whose condition is exactly this coordinate, or `undefined`. */
|
|
44
55
|
get entry(): IndexedPreviewCondition | undefined;
|
|
45
56
|
/** The conditional `preview` entries that hold for this cell, in stored order. */
|
|
@@ -167,5 +178,25 @@ declare function cellAt({
|
|
|
167
178
|
path: string;
|
|
168
179
|
cell: SlotCell;
|
|
169
180
|
}): Cell;
|
|
181
|
+
/** The props and states whose values pick a cell of a component's grid: its variants, its booleans
|
|
182
|
+
* and its states. */
|
|
183
|
+
declare function cellAxes(config: Config, path: string): readonly string[];
|
|
184
|
+
/**
|
|
185
|
+
* The coordinate of a component's default cell on the canvas: the preview's defaults, with each
|
|
186
|
+
* boolean prop and each state they leave unset at its rest value, the way the grid spells that cell
|
|
187
|
+
* (`busy: false`).
|
|
188
|
+
*/
|
|
189
|
+
declare function canvasDefaultCoordinate(config: Config, path: string): Readonly<SlotCell>;
|
|
190
|
+
/** The cell a placed instance's props pick: the default cell's coordinate with the instance's own
|
|
191
|
+
* axis values over it. With no props, the default cell itself. */
|
|
192
|
+
declare function canvasCellAt({
|
|
193
|
+
config,
|
|
194
|
+
path,
|
|
195
|
+
props
|
|
196
|
+
}: {
|
|
197
|
+
config: Config;
|
|
198
|
+
path: string;
|
|
199
|
+
props?: Readonly<Record<string, unknown>>;
|
|
200
|
+
}): Cell;
|
|
170
201
|
//#endregion
|
|
171
|
-
export { Cell, CellSlot, GoverningCondition, cellAt };
|
|
202
|
+
export { Cell, CellSlot, GoverningCondition, canvasCellAt, canvasDefaultCoordinate, cellAt, cellAxes };
|
package/dist/spec/cell.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { canonicalCondition, refLeaf } from "../framework/utils/refs.js";
|
|
2
|
+
import { createSliceMemo } from "../framework/memo.js";
|
|
3
|
+
import { componentStates } from "../framework/component-states.js";
|
|
4
|
+
import { unconditionalPreviewProps } from "../framework/preview-store.js";
|
|
2
5
|
import { holdingPreviewConditions, previewConditionalProps, previewDefaults } from "../framework/projections.js";
|
|
3
6
|
import { propApplies, surfaceProps } from "../framework/prop-surface.js";
|
|
4
7
|
import { ruleApplies } from "../framework/layer-styles.js";
|
|
@@ -32,6 +35,7 @@ var Cell = class {
|
|
|
32
35
|
memoDefaults = UNSET;
|
|
33
36
|
memoConditional = UNSET;
|
|
34
37
|
memoProps = UNSET;
|
|
38
|
+
memoContent = UNSET;
|
|
35
39
|
memoEntry = UNSET;
|
|
36
40
|
memoHolding = UNSET;
|
|
37
41
|
memoOwn = UNSET;
|
|
@@ -62,6 +66,31 @@ var Cell = class {
|
|
|
62
66
|
};
|
|
63
67
|
return this.memoProps;
|
|
64
68
|
}
|
|
69
|
+
/** The preview content the cell shows: the `*` entry, then every entry that holds for it. What a
|
|
70
|
+
* drop seeds and a placed instance compares its own content against; no declared or code
|
|
71
|
+
* default is in it. */
|
|
72
|
+
get content() {
|
|
73
|
+
if (this.memoContent === UNSET) this.memoContent = {
|
|
74
|
+
...unconditionalPreviewProps(this.config.resolve("component", this.component)?.body) ?? {},
|
|
75
|
+
...this.conditional
|
|
76
|
+
};
|
|
77
|
+
return this.memoContent;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether this is the component's default on the canvas: the cell "Set as default" chose, where a
|
|
81
|
+
* drop lands. Every axis the coordinate names matches the default cell's, the coordinate names at
|
|
82
|
+
* least one, and no modifier is forced. {@link isDefaults} asks about the defaults in code.
|
|
83
|
+
*/
|
|
84
|
+
isCanvasDefault(modifiers = []) {
|
|
85
|
+
if (modifiers.length > 0) return false;
|
|
86
|
+
const entries = Object.entries(this.coordinate);
|
|
87
|
+
if (entries.length === 0) return false;
|
|
88
|
+
const defaults = canvasDefaultCoordinate(this.config, this.component);
|
|
89
|
+
return entries.every(([prop, value]) => {
|
|
90
|
+
const held = defaults[prop];
|
|
91
|
+
return held !== void 0 && String(held) === String(value);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
65
94
|
/** The `preview` entry whose condition is exactly this coordinate, or `undefined`. */
|
|
66
95
|
get entry() {
|
|
67
96
|
if (this.memoEntry === UNSET) this.memoEntry = previewConditionAt({
|
|
@@ -357,5 +386,59 @@ function cellAt({ config, path, cell }) {
|
|
|
357
386
|
byKey.set(key, made);
|
|
358
387
|
return made;
|
|
359
388
|
}
|
|
389
|
+
/** The props and states whose values pick a cell of a component's grid: its variants, its booleans
|
|
390
|
+
* and its states. */
|
|
391
|
+
function cellAxes(config, path) {
|
|
392
|
+
const cache = canvasCache(config);
|
|
393
|
+
const hit = cache.axes.get(path);
|
|
394
|
+
if (hit) return hit;
|
|
395
|
+
const axes = [];
|
|
396
|
+
const props = (config.resolve("component", path)?.body)?.props;
|
|
397
|
+
for (const [prop, decl] of Object.entries(props ?? {})) {
|
|
398
|
+
const type = decl?.type;
|
|
399
|
+
if (type === "variant" || type === "boolean") axes.push(prop);
|
|
400
|
+
}
|
|
401
|
+
for (const state of componentStates(config, path)) axes.push(state.name);
|
|
402
|
+
cache.axes.set(path, axes);
|
|
403
|
+
return axes;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* The coordinate of a component's default cell on the canvas: the preview's defaults, with each
|
|
407
|
+
* boolean prop and each state they leave unset at its rest value, the way the grid spells that cell
|
|
408
|
+
* (`busy: false`).
|
|
409
|
+
*/
|
|
410
|
+
function canvasDefaultCoordinate(config, path) {
|
|
411
|
+
const cache = canvasCache(config);
|
|
412
|
+
const hit = cache.coordinates.get(path);
|
|
413
|
+
if (hit) return hit;
|
|
414
|
+
const coordinate = {};
|
|
415
|
+
const props = (config.resolve("component", path)?.body)?.props;
|
|
416
|
+
for (const [prop, decl] of Object.entries(props ?? {})) if (decl?.type === "boolean") coordinate[prop] = false;
|
|
417
|
+
for (const state of componentStates(config, path)) coordinate[state.name] = state.type === "boolean" ? false : state.default;
|
|
418
|
+
const defaults = previewDefaults(config, path);
|
|
419
|
+
for (const axis of cellAxes(config, path)) if (defaults[axis] !== void 0) coordinate[axis] = defaults[axis];
|
|
420
|
+
const made = coordinate;
|
|
421
|
+
cache.coordinates.set(path, made);
|
|
422
|
+
return made;
|
|
423
|
+
}
|
|
424
|
+
/** The cell a placed instance's props pick: the default cell's coordinate with the instance's own
|
|
425
|
+
* axis values over it. With no props, the default cell itself. */
|
|
426
|
+
function canvasCellAt({ config, path, props }) {
|
|
427
|
+
const coordinate = { ...canvasDefaultCoordinate(config, path) };
|
|
428
|
+
for (const axis of cellAxes(config, path)) if (props?.[axis] !== void 0) coordinate[axis] = props[axis];
|
|
429
|
+
return cellAt({
|
|
430
|
+
config,
|
|
431
|
+
path,
|
|
432
|
+
cell: coordinate
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/** Per component slice, each component's cell axes and default coordinate asked for so far. */
|
|
436
|
+
const canvasCache = createSliceMemo({
|
|
437
|
+
kinds: ["component"],
|
|
438
|
+
compute: (_config) => ({
|
|
439
|
+
axes: /* @__PURE__ */ new Map(),
|
|
440
|
+
coordinates: /* @__PURE__ */ new Map()
|
|
441
|
+
})
|
|
442
|
+
});
|
|
360
443
|
//#endregion
|
|
361
|
-
export { cellAt };
|
|
444
|
+
export { canvasCellAt, canvasDefaultCoordinate, cellAt, cellAxes };
|