@yahoo/uds-create-config 5.102.0 → 5.103.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.
|
@@ -2,7 +2,10 @@ import { DefaultSource } from "../../framework/projections.js";
|
|
|
2
2
|
import { Config } from "../../framework/Config.js";
|
|
3
3
|
|
|
4
4
|
//#region src/entities/system/resolve-properties.d.ts
|
|
5
|
-
type PropertyState = /** Nothing in the config gives this element the property. */'not-declared'
|
|
5
|
+
type PropertyState = /** Nothing in the config gives this element the property. */'not-declared'
|
|
6
|
+
/** The component doesn't declare it, and the element it renders takes it as a DOM attribute
|
|
7
|
+
* (`style`, `id`, `data-*`, `aria-*`), so it reaches the DOM as stored. */
|
|
8
|
+
| 'attribute' /** The config gives it a value, but a design file can't write it. */ | 'read-only' /** This element states it. */ | 'set' /** Another source supplies it: a rule a prop drives, a composite, a forced modifier block. */ | 'inherited' /** The component definition supplies it, or nothing does. */ | 'default';
|
|
6
9
|
type PropertyValue = {
|
|
7
10
|
readonly kind: 'value';
|
|
8
11
|
readonly value: unknown;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { isRef, pathOf, refLeaf } from "../../framework/utils/refs.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isNativeConfig } from "../../configs/platform.js";
|
|
3
|
+
import { renderedTarget, rootLayerOf } from "./element.js";
|
|
3
4
|
import { createSliceMemo } from "../../framework/memo.js";
|
|
4
5
|
import { UDS_FORCE_STATES } from "../../framework/component-states.js";
|
|
5
6
|
import { authoredBag, defaultSources, propOwner } from "../../framework/projections.js";
|
|
6
7
|
import { forwardClaims, layerPropRoutes, propApplies, surfaceProps } from "../../framework/prop-surface.js";
|
|
7
8
|
import { layerDeclarationStacks } from "../../framework/layer-styles.js";
|
|
8
9
|
import { layerRoutedProps, splitStyleProps } from "../../framework/class-names.js";
|
|
10
|
+
import { isDomAttribute } from "../../framework/dom-attributes.js";
|
|
9
11
|
import { Component } from "./Component.js";
|
|
12
|
+
import { classGrammar } from "../../capture/class-grammar.js";
|
|
10
13
|
import { markerKind } from "../../framework/bindings.js";
|
|
11
14
|
//#region src/entities/system/resolve-properties.ts
|
|
12
15
|
/**
|
|
@@ -14,7 +17,8 @@ import { markerKind } from "../../framework/bindings.js";
|
|
|
14
17
|
* the value that paints, where that value comes from, and whether the config lets you write it.
|
|
15
18
|
*
|
|
16
19
|
* The states are Donna's (Properties Panel Refactor): Set, Inherited, Default, Read-only and Not
|
|
17
|
-
* declared
|
|
20
|
+
* declared, plus Attribute for a DOM attribute the component passes through to its element. The
|
|
21
|
+
* element's force-state pins are read the way the render reads them.
|
|
18
22
|
*
|
|
19
23
|
* A value is the highest-ranked source that sets the key, ranked the way the render settles it.
|
|
20
24
|
* Style values are CSS on the root element, so they rank as the stylesheet does: the element's own
|
|
@@ -39,6 +43,8 @@ import { markerKind } from "../../framework/bindings.js";
|
|
|
39
43
|
* whose own `width` is a number) has no row of its own.
|
|
40
44
|
* OPEN: an element's own modifier blocks (`_hover: { … }`) aren't read as sources under `forced`.
|
|
41
45
|
* OPEN: a value's token origin and a borrowed component's `system` aren't reported.
|
|
46
|
+
* OPEN: an element's inline `style` outranks every class, but its declarations aren't read as
|
|
47
|
+
* sources, so a row its `style` overrides still names the class's value as the winner.
|
|
42
48
|
*/
|
|
43
49
|
const componentModels = createSliceMemo({
|
|
44
50
|
kinds: [
|
|
@@ -144,18 +150,42 @@ function resolveProperties({ config, target, forced = [], previews = false, incl
|
|
|
144
150
|
seen: /* @__PURE__ */ new Set(),
|
|
145
151
|
depth: 0
|
|
146
152
|
});
|
|
147
|
-
if (!resolved)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return rows.map(({ key, styleProperty, surfaced, sources }) => {
|
|
153
|
-
if (!(surfaced || sources.some(({ source }) => source.kind !== "element"))) return notDeclared({
|
|
154
|
-
key,
|
|
153
|
+
if (!resolved) {
|
|
154
|
+
const tag = hostTagOf(target.type);
|
|
155
|
+
if (tag) return hostFacts({
|
|
156
|
+
config,
|
|
157
|
+
tag,
|
|
155
158
|
stored: target.props,
|
|
156
|
-
|
|
157
|
-
styleProperty
|
|
159
|
+
include
|
|
158
160
|
});
|
|
161
|
+
return orderedKeys([storedKeys(target.props), include]).map((key) => notDeclared({
|
|
162
|
+
key,
|
|
163
|
+
stored: target.props
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
const { path, rows } = resolved;
|
|
167
|
+
const tag = renderedTag({
|
|
168
|
+
config,
|
|
169
|
+
path,
|
|
170
|
+
stored: target.props
|
|
171
|
+
});
|
|
172
|
+
return rows.map(({ key, styleProperty, surfaced, sources }) => {
|
|
173
|
+
if (!(surfaced || sources.some(({ source }) => source.kind !== "element"))) {
|
|
174
|
+
if (!styleProperty && isStoredAttribute({
|
|
175
|
+
config,
|
|
176
|
+
key,
|
|
177
|
+
tag
|
|
178
|
+
})) return attribute({
|
|
179
|
+
key,
|
|
180
|
+
stored: target.props
|
|
181
|
+
});
|
|
182
|
+
return notDeclared({
|
|
183
|
+
key,
|
|
184
|
+
stored: target.props,
|
|
185
|
+
path,
|
|
186
|
+
styleProperty
|
|
187
|
+
});
|
|
188
|
+
}
|
|
159
189
|
const [winner, ...beneath] = sources.map(({ value, source }) => ({
|
|
160
190
|
value,
|
|
161
191
|
source
|
|
@@ -347,6 +377,123 @@ function isInherited(source) {
|
|
|
347
377
|
if (source.kind === "layer-component") return isInherited(source.source);
|
|
348
378
|
return source.kind === "modifier" || source.kind === "composite";
|
|
349
379
|
}
|
|
380
|
+
/** The tag a plain HTML element names, as a spec stores its type (`html:nav`) or bare (`nav`). */
|
|
381
|
+
function hostTagOf(type) {
|
|
382
|
+
const tag = type.startsWith("html:") ? type.slice(5) : type;
|
|
383
|
+
return /^[a-z][a-zA-Z0-9-]*$/.test(tag) ? tag : void 0;
|
|
384
|
+
}
|
|
385
|
+
/** The style prop a class names, as the class grammar reads it: off the style properties, the tokens
|
|
386
|
+
* their values name, and the class prefix the settings give. */
|
|
387
|
+
const classStyleProps = createSliceMemo({
|
|
388
|
+
kinds: [
|
|
389
|
+
"style-property",
|
|
390
|
+
"token",
|
|
391
|
+
"settings"
|
|
392
|
+
],
|
|
393
|
+
compute: (config) => {
|
|
394
|
+
const grammar = classGrammar(config);
|
|
395
|
+
return (cls) => grammar.styleProp(cls);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
/** React's own props, which it reads rather than writing to the element. */
|
|
399
|
+
const REACT_PROPS = new Set([
|
|
400
|
+
"children",
|
|
401
|
+
"key",
|
|
402
|
+
"ref",
|
|
403
|
+
"dangerouslySetInnerHTML",
|
|
404
|
+
"suppressContentEditableWarning",
|
|
405
|
+
"suppressHydrationWarning"
|
|
406
|
+
]);
|
|
407
|
+
/**
|
|
408
|
+
* Whether a key the element stores reaches its DOM element as an attribute: one the tag takes, other
|
|
409
|
+
* than React's own props and the `on*` handlers, which a stored value can't be. A native element
|
|
410
|
+
* renders no DOM, so none does.
|
|
411
|
+
*/
|
|
412
|
+
function isStoredAttribute({ config, key, tag }) {
|
|
413
|
+
if (isNativeConfig(config)) return false;
|
|
414
|
+
if (REACT_PROPS.has(key) || /^on[A-Z]/.test(key)) return false;
|
|
415
|
+
return isDomAttribute({
|
|
416
|
+
key,
|
|
417
|
+
tag
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* A plain HTML element's rows. It takes every style property, and its classes are its values: a class
|
|
422
|
+
* the system writes for a style property's value sets that property, the first such class winning, and
|
|
423
|
+
* a value stored under the property's own name wins over its class, as the design panel reads it.
|
|
424
|
+
* The classes no style property writes are its `className`, and every other DOM attribute its tag
|
|
425
|
+
* takes is an attribute.
|
|
426
|
+
*/
|
|
427
|
+
function hostFacts({ config, tag, stored, include }) {
|
|
428
|
+
const styleProp = classStyleProps(config);
|
|
429
|
+
const fromClasses = {};
|
|
430
|
+
const otherClasses = [];
|
|
431
|
+
const classes = typeof stored.className === "string" ? stored.className.split(/\s+/).filter(Boolean) : [];
|
|
432
|
+
for (const cls of classes) {
|
|
433
|
+
const match = styleProp(cls);
|
|
434
|
+
if (!match) otherClasses.push(cls);
|
|
435
|
+
else if (!Object.hasOwn(fromClasses, match.path)) fromClasses[match.path] = match.leaf === "" ? true : match.leaf;
|
|
436
|
+
}
|
|
437
|
+
const { className: _className, children: _children, ...own } = stored;
|
|
438
|
+
const values = {
|
|
439
|
+
...fromClasses,
|
|
440
|
+
...own
|
|
441
|
+
};
|
|
442
|
+
return orderedKeys([
|
|
443
|
+
storedKeys(values),
|
|
444
|
+
otherClasses.length > 0 ? ["className"] : [],
|
|
445
|
+
config.list("style-property").map((entity) => entity.path),
|
|
446
|
+
include
|
|
447
|
+
]).map((key) => {
|
|
448
|
+
if (key === "className") return attribute({
|
|
449
|
+
key,
|
|
450
|
+
stored: { className: otherClasses.join(" ") }
|
|
451
|
+
});
|
|
452
|
+
if (config.resolve("style-property", key)) {
|
|
453
|
+
const has = ownEntry(values, key) !== void 0;
|
|
454
|
+
return {
|
|
455
|
+
key,
|
|
456
|
+
styleProperty: key,
|
|
457
|
+
state: has ? "set" : "default",
|
|
458
|
+
value: has ? propertyValue(values[key]) : UNSET,
|
|
459
|
+
source: has ? ELEMENT : null,
|
|
460
|
+
editable: true,
|
|
461
|
+
beneath: []
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (isStoredAttribute({
|
|
465
|
+
config,
|
|
466
|
+
key,
|
|
467
|
+
tag
|
|
468
|
+
})) return attribute({
|
|
469
|
+
key,
|
|
470
|
+
stored
|
|
471
|
+
});
|
|
472
|
+
return notDeclared({
|
|
473
|
+
key,
|
|
474
|
+
stored
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
/** The tag the element renders: its own `as`, or what the component's root renders. A native root
|
|
479
|
+
* renders a package export, which has no tag. */
|
|
480
|
+
function renderedTag({ config, path, stored }) {
|
|
481
|
+
if (typeof stored.as === "string") return stored.as;
|
|
482
|
+
const target = renderedTarget(config, path);
|
|
483
|
+
return target.kind === "tag" ? target.tag : void 0;
|
|
484
|
+
}
|
|
485
|
+
/** A DOM attribute the element stores, which the design file writes like any other key. */
|
|
486
|
+
function attribute({ key, stored }) {
|
|
487
|
+
const has = Object.hasOwn(stored, key) && stored[key] !== void 0;
|
|
488
|
+
return {
|
|
489
|
+
key,
|
|
490
|
+
state: "attribute",
|
|
491
|
+
value: has ? propertyValue(stored[key]) : UNSET,
|
|
492
|
+
source: has ? ELEMENT : null,
|
|
493
|
+
editable: true,
|
|
494
|
+
beneath: []
|
|
495
|
+
};
|
|
496
|
+
}
|
|
350
497
|
function notDeclared({ key, stored, path, styleProperty }) {
|
|
351
498
|
const has = Object.hasOwn(stored, key) && stored[key] !== void 0;
|
|
352
499
|
return {
|