@yahoo/uds-create-config 5.90.2 → 5.91.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.
@@ -1,7 +1,7 @@
1
1
  import { isRef, pathOf, splitRef } from "../framework/utils/refs.js";
2
2
  import { isPlainObject } from "../framework/utils/field-path.js";
3
3
  import { createSliceMemo } from "../framework/memo.js";
4
- import { resolveComponentProps } from "../framework/projections.js";
4
+ import { propOwner, resolveComponentProps } from "../framework/projections.js";
5
5
  //#region src/spec/id-props.ts
6
6
  const NONE = [];
7
7
  const idPropsCache = createSliceMemo({
@@ -15,6 +15,32 @@ function referencedPropName(target) {
15
15
  const name = member.slice(6);
16
16
  return name && !name.includes("/") ? name : void 0;
17
17
  }
18
+ /**
19
+ * Where `component`'s `prop` is declared: the component that owns it, which a `'*'` forward merges it
20
+ * from, and past any `forward` into another component's prop, the prop it fills.
21
+ */
22
+ function endOf({ config, component, prop }) {
23
+ const ownedAt = (path, name) => {
24
+ const owner = propOwner(config, path, name) ?? path;
25
+ return {
26
+ component: owner,
27
+ prop: name,
28
+ decl: resolveComponentProps(config, owner)[name]
29
+ };
30
+ };
31
+ let at = ownedAt(component, prop);
32
+ const seen = /* @__PURE__ */ new Set();
33
+ while (isPlainObject(at.decl) && at.decl.type === "forward") {
34
+ const { into } = at.decl;
35
+ if (!isRef(into) || splitRef(into).kind !== "component") break;
36
+ const next = referencedPropName(into);
37
+ const here = spaceOf(at.component, at.prop);
38
+ if (!next || seen.has(here)) break;
39
+ seen.add(here);
40
+ at = ownedAt(pathOf(into), next);
41
+ }
42
+ return at;
43
+ }
18
44
  function spaceOf(component, prop) {
19
45
  return `${component}#props/${prop}`;
20
46
  }
@@ -27,20 +53,32 @@ function idProps({ config, path }) {
27
53
  const hit = cache.get(component);
28
54
  if (hit) return hit;
29
55
  const found = [];
30
- for (const [prop, decl] of Object.entries(resolveComponentProps(config, component))) {
56
+ for (const prop of Object.keys(resolveComponentProps(config, component))) {
57
+ const end = endOf({
58
+ config,
59
+ component,
60
+ prop
61
+ });
62
+ const { decl } = end;
31
63
  if (!isPlainObject(decl) || decl.type !== "string") continue;
32
64
  const unique = decl.uniqueId === true;
33
65
  const target = isRef(decl.uniqueIdRef) ? decl.uniqueIdRef : void 0;
34
66
  const referenced = target ? referencedPropName(target) : void 0;
35
- if (target && referenced) found.push({
36
- prop,
37
- space: spaceOf(pathOf(target), referenced),
38
- unique,
39
- ref: true
40
- });
41
- else if (unique) found.push({
67
+ if (target && referenced) {
68
+ const named = endOf({
69
+ config,
70
+ component: pathOf(target),
71
+ prop: referenced
72
+ });
73
+ found.push({
74
+ prop,
75
+ space: spaceOf(named.component, named.prop),
76
+ unique,
77
+ ref: true
78
+ });
79
+ } else if (unique) found.push({
42
80
  prop,
43
- space: spaceOf(component, prop),
81
+ space: spaceOf(end.component, end.prop),
44
82
  unique,
45
83
  ref: false
46
84
  });