@contentful/experiences-design 0.7.0 → 0.7.1
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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +2 -2
- package/dist/viewport.d.ts +3 -36
- package/dist/viewport.js +6 -64
- package/dist/viewport.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 0.7.1 (2026-08-07)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- server-side design pre-resolution against a fallback viewport [AIS-386] ([#119](https://github.com/contentful/experiences/pull/119))
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated core to 0.7.1
|
|
10
|
+
|
|
1
11
|
## 0.7.0 (2026-08-07)
|
|
2
12
|
|
|
3
13
|
### 🧱 Updated Dependencies
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { toCssMediaQuery } from './viewport.js';
|
|
2
2
|
export { CSS_PROPERTIES, isCssProperty, toCssKey } from './css-properties.js';
|
|
3
|
-
|
|
3
|
+
export { applyTokenResolver, getValueForViewport, getViewportIndex, resolveDesignProperties } from '@contentful/experiences-sdk-core';
|
package/dist/viewport.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ViewportDef } from '@contentful/experiences-sdk-core';
|
|
2
|
+
export { applyTokenResolver, getValueForViewport, getViewportIndex, resolveDesignProperties } from '@contentful/experiences-sdk-core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Convert a Contentful viewport `query` string into a CSS media query.
|
|
@@ -6,39 +7,5 @@ import { DesignToken, ResolveToken, DesignPropValue, ViewportDef } from '@conten
|
|
|
6
7
|
* or for any unrecognized format.
|
|
7
8
|
*/
|
|
8
9
|
declare function toCssMediaQuery(viewport: ViewportDef): string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Resolve a viewport ID to its index in the ordered viewports list. Returns 0
|
|
11
|
-
* (the wildcard viewport) when the id is unknown or undefined.
|
|
12
|
-
*/
|
|
13
|
-
declare function getViewportIndex(viewports: ViewportDef[], viewportId?: string): number;
|
|
14
|
-
/**
|
|
15
|
-
* Resolve a single design-property envelope to its render-time value:
|
|
16
|
-
* - ManualDesignValue → its scalar
|
|
17
|
-
* - DesignToken → the envelope passes through (customer-owned resolution)
|
|
18
|
-
* - ValuesByViewport → cascade-lookup against the active viewport, then
|
|
19
|
-
* unwrap the inner Manual/Token as above
|
|
20
|
-
* - undefined → returns undefined
|
|
21
|
-
*/
|
|
22
|
-
declare function getValueForViewport(prop: DesignPropValue | undefined, viewports: ViewportDef[], activeViewportIndex: number): string | number | boolean | DesignToken | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Resolve every design-property envelope on a node into a flat record keyed
|
|
25
|
-
* by property name. Customer components receive these values as plain props.
|
|
26
|
-
*/
|
|
27
|
-
declare function resolveDesignProperties(designProperties: Record<string, DesignPropValue> | undefined, viewports: ViewportDef[], activeViewportIndex: number): Record<string, string | number | boolean | DesignToken>;
|
|
28
|
-
/**
|
|
29
|
-
* Resolves `DesignToken` envelopes in a viewport-resolved design record via
|
|
30
|
-
* `resolveToken`; scalars pass through, and with no resolver the record is
|
|
31
|
-
* returned unchanged. Keys that resolve to `undefined` are dropped and their
|
|
32
|
-
* token ids collected in `unresolved` for a single grouped warning.
|
|
33
|
-
*
|
|
34
|
-
* When no `resolveToken` is configured but the record contains `DesignToken`
|
|
35
|
-
* envelopes, warns once — those keys reach components as raw envelope objects
|
|
36
|
-
* (e.g. rendering as `[object Object]`), which is almost always a missing-
|
|
37
|
-
* config mistake rather than intent.
|
|
38
|
-
*/
|
|
39
|
-
declare function applyTokenResolver(props: Record<string, string | number | boolean | DesignToken>, resolveToken?: ResolveToken): {
|
|
40
|
-
props: Record<string, unknown>;
|
|
41
|
-
unresolved: string[];
|
|
42
|
-
};
|
|
43
10
|
|
|
44
|
-
export {
|
|
11
|
+
export { toCssMediaQuery };
|
package/dist/viewport.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyTokenResolver,
|
|
3
|
+
getValueForViewport,
|
|
4
|
+
getViewportIndex,
|
|
5
|
+
resolveDesignProperties
|
|
6
|
+
} from "@contentful/experiences-sdk-core";
|
|
1
7
|
const MEDIA_QUERY_REGEXP = /^(<|>)(\d+)(px|cm|mm|in|pt|pc)$/;
|
|
2
8
|
function toCssMediaQuery(viewport) {
|
|
3
9
|
const { query } = viewport;
|
|
@@ -14,70 +20,6 @@ function toCssMediaQuery(viewport) {
|
|
|
14
20
|
}
|
|
15
21
|
return void 0;
|
|
16
22
|
}
|
|
17
|
-
function getViewportIndex(viewports, viewportId) {
|
|
18
|
-
if (!viewportId) return 0;
|
|
19
|
-
const index = viewports.findIndex((v) => v.id === viewportId);
|
|
20
|
-
return index === -1 ? 0 : index;
|
|
21
|
-
}
|
|
22
|
-
function unwrapInner(inner) {
|
|
23
|
-
if (!inner) return void 0;
|
|
24
|
-
if (inner.type === "ManualDesignValue") return inner.value;
|
|
25
|
-
return inner;
|
|
26
|
-
}
|
|
27
|
-
function resolveValuesByViewport(bag, viewports, activeViewportIndex) {
|
|
28
|
-
for (let i = activeViewportIndex; i >= 0; i--) {
|
|
29
|
-
const viewport = viewports[i];
|
|
30
|
-
if (!viewport) continue;
|
|
31
|
-
const candidate = bag.values[viewport.id];
|
|
32
|
-
if (candidate !== void 0 && candidate !== null) return candidate;
|
|
33
|
-
}
|
|
34
|
-
return void 0;
|
|
35
|
-
}
|
|
36
|
-
function getValueForViewport(prop, viewports, activeViewportIndex) {
|
|
37
|
-
if (!prop) return void 0;
|
|
38
|
-
if (prop.type === "ManualDesignValue") return prop.value;
|
|
39
|
-
if (prop.type === "DesignToken") return prop;
|
|
40
|
-
return unwrapInner(resolveValuesByViewport(prop, viewports, activeViewportIndex));
|
|
41
|
-
}
|
|
42
|
-
function resolveDesignProperties(designProperties, viewports, activeViewportIndex) {
|
|
43
|
-
const out = {};
|
|
44
|
-
if (!designProperties) return out;
|
|
45
|
-
for (const [key, prop] of Object.entries(designProperties)) {
|
|
46
|
-
const value = getValueForViewport(prop, viewports, activeViewportIndex);
|
|
47
|
-
if (value !== void 0) out[key] = value;
|
|
48
|
-
}
|
|
49
|
-
return out;
|
|
50
|
-
}
|
|
51
|
-
let warnedMissingResolver = false;
|
|
52
|
-
function applyTokenResolver(props, resolveToken) {
|
|
53
|
-
if (!resolveToken) {
|
|
54
|
-
if (!warnedMissingResolver && typeof console !== "undefined") {
|
|
55
|
-
const tokenKeys = Object.entries(props).filter(([, v]) => typeof v === "object" && v !== null && v.type === "DesignToken").map(([k]) => k);
|
|
56
|
-
if (tokenKeys.length) {
|
|
57
|
-
warnedMissingResolver = true;
|
|
58
|
-
console.warn(
|
|
59
|
-
`[@contentful/experiences] Design tokens are present but no \`resolveToken\` is configured on the Config; token-valued design props (${tokenKeys.join(", ")}) reach components unresolved. Add \`resolveToken\` to your Config to map token ids to values.`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return { props, unresolved: [] };
|
|
64
|
-
}
|
|
65
|
-
const out = {};
|
|
66
|
-
const unresolved = [];
|
|
67
|
-
for (const [key, value] of Object.entries(props)) {
|
|
68
|
-
if (typeof value === "object" && value !== null && value.type === "DesignToken") {
|
|
69
|
-
const resolved = resolveToken(value);
|
|
70
|
-
if (resolved === void 0) {
|
|
71
|
-
unresolved.push(value.value);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
out[key] = resolved;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
out[key] = value;
|
|
78
|
-
}
|
|
79
|
-
return { props: out, unresolved };
|
|
80
|
-
}
|
|
81
23
|
export {
|
|
82
24
|
applyTokenResolver,
|
|
83
25
|
getValueForViewport,
|
package/dist/viewport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viewport.ts"],"sourcesContent":["/*\n * Viewport
|
|
1
|
+
{"version":3,"sources":["../src/viewport.ts"],"sourcesContent":["/*\n * Viewport → CSS media-query translation. The cascade + token-resolution\n * helpers now live in core (so the resolve pipeline can pre-resolve design\n * server-side) and are re-exported here to keep this package's API unchanged.\n */\n\nimport type { ViewportDef } from '@contentful/experiences-sdk-core';\n\nexport {\n applyTokenResolver,\n getValueForViewport,\n getViewportIndex,\n resolveDesignProperties,\n} from '@contentful/experiences-sdk-core';\n\nconst MEDIA_QUERY_REGEXP = /^(<|>)(\\d+)(px|cm|mm|in|pt|pc)$/;\n\n/**\n * Convert a Contentful viewport `query` string into a CSS media query.\n * Returns `undefined` for the wildcard \"*\" (always matches; no media query needed)\n * or for any unrecognized format.\n */\nexport function toCssMediaQuery(viewport: ViewportDef): string | undefined {\n const { query } = viewport;\n if (query === '*') return undefined;\n const match = query.match(MEDIA_QUERY_REGEXP);\n if (!match) return undefined;\n const [, operator, value, unit] = match;\n if (!operator || !value || !unit) return undefined;\n if (operator === '<') {\n return `(max-width: ${Number(value) - 1}${unit})`;\n }\n if (operator === '>') {\n return `(min-width: ${Number(value) + 1}${unit})`;\n }\n return undefined;\n}\n"],"mappings":"AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,qBAAqB;AAOpB,SAAS,gBAAgB,UAA2C;AACzE,QAAM,EAAE,MAAM,IAAI;AAClB,MAAI,UAAU,IAAK,QAAO;AAC1B,QAAM,QAAQ,MAAM,MAAM,kBAAkB;AAC5C,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,CAAC,EAAE,UAAU,OAAO,IAAI,IAAI;AAClC,MAAI,CAAC,YAAY,CAAC,SAAS,CAAC,KAAM,QAAO;AACzC,MAAI,aAAa,KAAK;AACpB,WAAO,eAAe,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI;AAAA,EAChD;AACA,MAAI,aAAa,KAAK;AACpB,WAAO,eAAe,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI;AAAA,EAChD;AACA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-design",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Viewport math and design-property resolution utilities for Contentful Experiences",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"directory": "packages/design"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@contentful/experiences-sdk-core": "0.7.
|
|
33
|
+
"@contentful/experiences-sdk-core": "0.7.1"
|
|
34
34
|
}
|
|
35
35
|
}
|