@contentful/experience-design-system-types 2.36.1-dev-build-49ac29ec.0 → 2.36.1-dev-build-b8f3827a.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/package.json +1 -1
- package/dist/src/cdf/build.js +24 -1
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/cdf/build.js
CHANGED
|
@@ -11,6 +11,29 @@ export function stripUnsupportedSlotFields(entry) {
|
|
|
11
11
|
}
|
|
12
12
|
return { ...entry, $slots: cleaned };
|
|
13
13
|
}
|
|
14
|
+
const COLLISION_LEAF_KEY = 'default';
|
|
15
|
+
/** A token path that is also the parent of other token paths cannot be both
|
|
16
|
+
* in a nested tree, so the leaf moves to a `default` child (suffixed with `_`
|
|
17
|
+
* until it is unique). */
|
|
18
|
+
function resolveTokenPathCollisions(tokens) {
|
|
19
|
+
const taken = new Set(tokens.map((token) => token.path));
|
|
20
|
+
const parents = new Set();
|
|
21
|
+
for (const path of taken) {
|
|
22
|
+
const segments = path.split('.');
|
|
23
|
+
for (let i = 1; i < segments.length; i += 1)
|
|
24
|
+
parents.add(segments.slice(0, i).join('.'));
|
|
25
|
+
}
|
|
26
|
+
return tokens.map((token) => {
|
|
27
|
+
if (!parents.has(token.path))
|
|
28
|
+
return token;
|
|
29
|
+
let key = COLLISION_LEAF_KEY;
|
|
30
|
+
while (taken.has(`${token.path}.${key}`))
|
|
31
|
+
key += '_';
|
|
32
|
+
const path = `${token.path}.${key}`;
|
|
33
|
+
taken.add(path);
|
|
34
|
+
return { path, entry: token.entry };
|
|
35
|
+
});
|
|
36
|
+
}
|
|
14
37
|
export function buildCDF(components, tokens, opts = {}) {
|
|
15
38
|
if (components.length === 0 && tokens.length === 0 && !opts.deleteAll)
|
|
16
39
|
return undefined;
|
|
@@ -18,7 +41,7 @@ export function buildCDF(components, tokens, opts = {}) {
|
|
|
18
41
|
for (const { key, entry } of components) {
|
|
19
42
|
setAtPath(doc, key, stripUnsupportedSlotFields(entry));
|
|
20
43
|
}
|
|
21
|
-
for (const { path, entry } of tokens) {
|
|
44
|
+
for (const { path, entry } of resolveTokenPathCollisions(tokens)) {
|
|
22
45
|
setAtPath(doc, path, entry);
|
|
23
46
|
}
|
|
24
47
|
return doc;
|