@contentstack/studio-registry 2.0.1 → 2.1.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/cjs/index.cjs +670 -11
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/common/global-store.js.map +1 -1
- package/dist/esm/component-registry/built-in-components-loader.js +36 -0
- package/dist/esm/component-registry/built-in-components-loader.js.map +1 -0
- package/dist/esm/component-registry/registry.constant.js +3 -0
- package/dist/esm/component-registry/registry.constant.js.map +1 -1
- package/dist/esm/component-registry/registry.js +6 -0
- package/dist/esm/component-registry/registry.js.map +1 -1
- package/dist/esm/data-binder/first-of-type.js +86 -0
- package/dist/esm/data-binder/first-of-type.js.map +1 -0
- package/dist/esm/data-binder/handle-binding-map.util.js +3 -0
- package/dist/esm/data-binder/handle-binding-map.util.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.js +54 -8
- package/dist/esm/data-binder/retrieve-data.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.util.js +11 -2
- package/dist/esm/data-binder/retrieve-data.util.js.map +1 -1
- package/dist/esm/data-binder/section-exposed-bindings.js +98 -0
- package/dist/esm/data-binder/section-exposed-bindings.js.map +1 -0
- package/dist/esm/data-binder/section-exposed-design-props.js +243 -0
- package/dist/esm/data-binder/section-exposed-design-props.js.map +1 -0
- package/dist/esm/data-binder/state-binding.util.js +50 -1
- package/dist/esm/data-binder/state-binding.util.js.map +1 -1
- package/dist/esm/design-registry/design-registry.js +44 -1
- package/dist/esm/design-registry/design-registry.js.map +1 -1
- package/dist/esm/index.d.ts +313 -9
- package/dist/esm/index.js +6 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -2173,7 +2173,7 @@ var objectCtorString = funcToString.call(Object);
|
|
|
2173
2173
|
* _.isPlainObject(Object.create(null));
|
|
2174
2174
|
* // => true
|
|
2175
2175
|
*/
|
|
2176
|
-
function isPlainObject(value) {
|
|
2176
|
+
function isPlainObject$1(value) {
|
|
2177
2177
|
if (!isObjectLike(value) || baseGetTag(value) != objectTag$2) {
|
|
2178
2178
|
return false;
|
|
2179
2179
|
}
|
|
@@ -3481,7 +3481,7 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta
|
|
|
3481
3481
|
newValue = [];
|
|
3482
3482
|
}
|
|
3483
3483
|
}
|
|
3484
|
-
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
|
3484
|
+
else if (isPlainObject$1(srcValue) || isArguments(srcValue)) {
|
|
3485
3485
|
newValue = objValue;
|
|
3486
3486
|
if (isArguments(objValue)) {
|
|
3487
3487
|
newValue = toPlainObject(objValue);
|
|
@@ -3761,6 +3761,30 @@ var snakeCase = createCompounder(function(result, word, index) {
|
|
|
3761
3761
|
return result + (index ? '_' : '') + word.toLowerCase();
|
|
3762
3762
|
});
|
|
3763
3763
|
|
|
3764
|
+
/**
|
|
3765
|
+
* Converts `value` to a property path array.
|
|
3766
|
+
*
|
|
3767
|
+
* @static
|
|
3768
|
+
* @memberOf _
|
|
3769
|
+
* @since 4.0.0
|
|
3770
|
+
* @category Util
|
|
3771
|
+
* @param {*} value The value to convert.
|
|
3772
|
+
* @returns {Array} Returns the new property path array.
|
|
3773
|
+
* @example
|
|
3774
|
+
*
|
|
3775
|
+
* _.toPath('a.b.c');
|
|
3776
|
+
* // => ['a', 'b', 'c']
|
|
3777
|
+
*
|
|
3778
|
+
* _.toPath('a[0].b.c');
|
|
3779
|
+
* // => ['a', '0', 'b', 'c']
|
|
3780
|
+
*/
|
|
3781
|
+
function toPath(value) {
|
|
3782
|
+
if (isArray(value)) {
|
|
3783
|
+
return arrayMap(value, toKey);
|
|
3784
|
+
}
|
|
3785
|
+
return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
|
|
3786
|
+
}
|
|
3787
|
+
|
|
3764
3788
|
const DATA_SOURCES_PREFIX = "dataSources";
|
|
3765
3789
|
const DATA_SOURCES = {
|
|
3766
3790
|
COMPONENT_PROPS: "component_props",
|
|
@@ -3853,6 +3877,9 @@ const INTERNAL_COMPONENTS_NAMES = {
|
|
|
3853
3877
|
// * HTML Elements
|
|
3854
3878
|
HTML_ELEMENT: "html-element",
|
|
3855
3879
|
STYLE_SHEET: "style-sheet",
|
|
3880
|
+
// * Hidden, rendered by the SDK itself
|
|
3881
|
+
// What a fetch that failed inside Studio's canvas renders instead of a page.
|
|
3882
|
+
RESOLUTION_FAILURE: "studio-resolution-failure",
|
|
3856
3883
|
};
|
|
3857
3884
|
/**
|
|
3858
3885
|
* System components are protected components that are not intended to be modified or removed.
|
|
@@ -4649,6 +4676,12 @@ class ComponentRegistry {
|
|
|
4649
4676
|
// Not a lazy component or not registered
|
|
4650
4677
|
const loader = this.componentLoaders.get(componentType);
|
|
4651
4678
|
if (!loader) {
|
|
4679
|
+
// A registered component can still have code to fetch: a built-in that
|
|
4680
|
+
// loads on demand in the browser carries a `preload`, so a fetch can
|
|
4681
|
+
// start it as soon as it has read the layout. It never rejects.
|
|
4682
|
+
const preload = this.componentRegistry.get(componentType)?.component?.preload;
|
|
4683
|
+
if (typeof preload === "function")
|
|
4684
|
+
await preload();
|
|
4652
4685
|
return;
|
|
4653
4686
|
}
|
|
4654
4687
|
const loadPromise = (async () => {
|
|
@@ -4897,6 +4930,38 @@ function hasComponentRegistryInstance(graph = "client") {
|
|
|
4897
4930
|
return getGlobalStudioStore(graph).componentRegistry !== null;
|
|
4898
4931
|
}
|
|
4899
4932
|
|
|
4933
|
+
/**
|
|
4934
|
+
* How code that reads the registry before anything has rendered gets the
|
|
4935
|
+
* built-in components registered.
|
|
4936
|
+
*
|
|
4937
|
+
* `@contentstack/studio-react` used to register the built-ins when it was
|
|
4938
|
+
* imported. That made every import of it — one hook in a component file — carry
|
|
4939
|
+
* the registry, every built-in and the client SDK. It now registers them when
|
|
4940
|
+
* they are first needed: the renderer and `registerComponents` do it directly,
|
|
4941
|
+
* and for everything else the package root leaves a loader here.
|
|
4942
|
+
*
|
|
4943
|
+
* The one caller that needs the loader is the composition fetch in the browser,
|
|
4944
|
+
* which checks the registry for every component a composition uses and can run
|
|
4945
|
+
* before the renderer has loaded. It lives in `studio-client`, which cannot
|
|
4946
|
+
* import `studio-react`; this slot is how the two meet.
|
|
4947
|
+
*/
|
|
4948
|
+
function setBuiltInComponentsLoader(loader) {
|
|
4949
|
+
getGlobalStudioStore("client").builtInComponentsLoader = loader;
|
|
4950
|
+
}
|
|
4951
|
+
/**
|
|
4952
|
+
* Runs the loader the renderer package left, if any.
|
|
4953
|
+
*
|
|
4954
|
+
* @returns whether a loader ran. `false` means no renderer package is present
|
|
4955
|
+
* to provide built-ins, which is worth reporting as such.
|
|
4956
|
+
*/
|
|
4957
|
+
async function loadBuiltInComponents() {
|
|
4958
|
+
const loader = getGlobalStudioStore("client").builtInComponentsLoader;
|
|
4959
|
+
if (!loader)
|
|
4960
|
+
return false;
|
|
4961
|
+
await loader();
|
|
4962
|
+
return true;
|
|
4963
|
+
}
|
|
4964
|
+
|
|
4900
4965
|
const SIZE_TOKENS = {
|
|
4901
4966
|
XS: "4px",
|
|
4902
4967
|
S: "8px",
|
|
@@ -5649,6 +5714,7 @@ class DesignRegistry {
|
|
|
5649
5714
|
classes = {};
|
|
5650
5715
|
tokens;
|
|
5651
5716
|
cssVariables;
|
|
5717
|
+
tokenOrigins;
|
|
5652
5718
|
options = {
|
|
5653
5719
|
tokenOptions: getDefaultDesignTokensOptions(),
|
|
5654
5720
|
};
|
|
@@ -5660,18 +5726,25 @@ class DesignRegistry {
|
|
|
5660
5726
|
this.tokens = processedDesignTokens;
|
|
5661
5727
|
this.cssVariables = cssVariablesValues;
|
|
5662
5728
|
this.cssVariablesToDesignTokens = cssVariablesToDesignTokens;
|
|
5729
|
+
this.tokenOrigins = Object.fromEntries(Object.keys(cssVariablesValues).map((cssVariable) => [
|
|
5730
|
+
cssVariable,
|
|
5731
|
+
"default",
|
|
5732
|
+
]));
|
|
5663
5733
|
}
|
|
5664
5734
|
registerDesignTokens(tokens, options = {}) {
|
|
5665
5735
|
const csDesignTokens = processDesignToken(DEFAULT_DESIGN_TOKENS);
|
|
5666
5736
|
const userDesignTokens = processDesignToken(tokens);
|
|
5667
5737
|
const config = processDesignTokensOptions(options);
|
|
5668
5738
|
this.options.tokenOptions = config;
|
|
5739
|
+
// Read before the merge below, which writes into csDesignTokens.
|
|
5740
|
+
const origins = tokenOriginSources(config.allowDefaultDesignTokens ? csDesignTokens : undefined, userDesignTokens);
|
|
5669
5741
|
const { processedDesignTokens, cssVariablesValues, cssVariablesToDesignTokens, } = designTokensToCssVariables(this.options.tokenOptions.allowDefaultDesignTokens // Explicitly check for true
|
|
5670
5742
|
? merge(csDesignTokens, userDesignTokens)
|
|
5671
5743
|
: userDesignTokens);
|
|
5672
5744
|
this.tokens = processedDesignTokens;
|
|
5673
5745
|
this.cssVariables = cssVariablesValues;
|
|
5674
5746
|
this.cssVariablesToDesignTokens = cssVariablesToDesignTokens;
|
|
5747
|
+
this.tokenOrigins = getTokenOrigins(cssVariablesValues, origins);
|
|
5675
5748
|
}
|
|
5676
5749
|
getDesignTokens() {
|
|
5677
5750
|
return this.tokens;
|
|
@@ -5685,15 +5758,26 @@ class DesignRegistry {
|
|
|
5685
5758
|
getCssVariablesToDesignTokens() {
|
|
5686
5759
|
return this.cssVariablesToDesignTokens;
|
|
5687
5760
|
}
|
|
5761
|
+
/** Where each registered token comes from; see {@link CssVariablesToOrigin}. */
|
|
5762
|
+
getDesignTokenOrigins() {
|
|
5763
|
+
return this.tokenOrigins;
|
|
5764
|
+
}
|
|
5688
5765
|
/**
|
|
5689
5766
|
* If the design tokens are already processed, we can use this method to update the design tokens
|
|
5690
5767
|
* without processing them again.
|
|
5691
5768
|
* @param tokens The processed design tokens
|
|
5769
|
+
* @param cssVariables The token values. Without them the registry keeps
|
|
5770
|
+
* answering {@link getDesignTokenCssVariables} with the defaults' values.
|
|
5771
|
+
* @param tokenOrigins Where each token comes from, when the sender knows.
|
|
5692
5772
|
*/
|
|
5693
|
-
updateDesignTokens(tokens, cssVariablesToDesignTokens, options) {
|
|
5773
|
+
updateDesignTokens(tokens, cssVariablesToDesignTokens, options, cssVariables, tokenOrigins) {
|
|
5694
5774
|
this.tokens = tokens;
|
|
5695
5775
|
this.options.tokenOptions = options;
|
|
5696
5776
|
this.cssVariablesToDesignTokens = cssVariablesToDesignTokens;
|
|
5777
|
+
if (cssVariables)
|
|
5778
|
+
this.cssVariables = cssVariables;
|
|
5779
|
+
if (tokenOrigins)
|
|
5780
|
+
this.tokenOrigins = tokenOrigins;
|
|
5697
5781
|
}
|
|
5698
5782
|
clearDesignTokens() {
|
|
5699
5783
|
this.tokens = getDefaultDesignTokens();
|
|
@@ -5732,6 +5816,30 @@ class DesignRegistry {
|
|
|
5732
5816
|
}, {});
|
|
5733
5817
|
}
|
|
5734
5818
|
}
|
|
5819
|
+
/**
|
|
5820
|
+
* The CSS variables the defaults and the app each define. A variable is
|
|
5821
|
+
* derived from the token's path, so a token the app redefines has the same
|
|
5822
|
+
* variable as the default it replaces.
|
|
5823
|
+
*/
|
|
5824
|
+
function tokenOriginSources(defaultTokens, userTokens) {
|
|
5825
|
+
return {
|
|
5826
|
+
defaults: new Set(defaultTokens
|
|
5827
|
+
? Object.keys(designTokensToCssVariables(defaultTokens).cssVariablesValues)
|
|
5828
|
+
: []),
|
|
5829
|
+
own: new Set(Object.keys(designTokensToCssVariables(userTokens).cssVariablesValues)),
|
|
5830
|
+
};
|
|
5831
|
+
}
|
|
5832
|
+
/** Marks each registered token by where it comes from. */
|
|
5833
|
+
function getTokenOrigins(registered, { defaults, own }) {
|
|
5834
|
+
return Object.fromEntries(Object.keys(registered).map((cssVariable) => [
|
|
5835
|
+
cssVariable,
|
|
5836
|
+
own.has(cssVariable)
|
|
5837
|
+
? defaults.has(cssVariable)
|
|
5838
|
+
? "overridden"
|
|
5839
|
+
: "app"
|
|
5840
|
+
: "default",
|
|
5841
|
+
]));
|
|
5842
|
+
}
|
|
5735
5843
|
|
|
5736
5844
|
/**
|
|
5737
5845
|
* Singleton DesignRegistry, backed by a versioned slot on `globalThis`.
|
|
@@ -5818,6 +5926,88 @@ const getCslpTag = ({ bindedField, data, }) => {
|
|
|
5818
5926
|
return cslpValue || {};
|
|
5819
5927
|
};
|
|
5820
5928
|
|
|
5929
|
+
/**
|
|
5930
|
+
* First-of-type binding (COMS-2484).
|
|
5931
|
+
*
|
|
5932
|
+
* A binding path segment `$first:<type>` stands where a list index would: it
|
|
5933
|
+
* means "the first element of this list whose type is <type>". Studio writes
|
|
5934
|
+
* it for a pick under a block type or content type the preview data has no
|
|
5935
|
+
* element of, so the binding reads that type's first element once one exists.
|
|
5936
|
+
*
|
|
5937
|
+
* - Modular blocks: `modular_blocks.$first:block2.block2.caption` — the type
|
|
5938
|
+
* is the block's key. The block key stays after the segment, as it does
|
|
5939
|
+
* after an index.
|
|
5940
|
+
* - References: `reference.$first:blog.title` — the type is the entry's
|
|
5941
|
+
* `_content_type_uid`.
|
|
5942
|
+
*
|
|
5943
|
+
* Before a path is read, `resolveFirstOfTypePath` swaps every such segment for
|
|
5944
|
+
* the index of the first matching element in `data`. Everything downstream
|
|
5945
|
+
* (lodash `get`, edit tags, type checks) then sees an ordinary path. With no
|
|
5946
|
+
* matching element the path is returned as it is: it reads as missing.
|
|
5947
|
+
*/
|
|
5948
|
+
const FIRST_OF_TYPE_PREFIX = "$first:";
|
|
5949
|
+
/** The type uid a `$first:<type>` segment names, or undefined for any other segment. */
|
|
5950
|
+
const parseFirstOfTypeSegment = (segment) => segment.startsWith(FIRST_OF_TYPE_PREFIX) &&
|
|
5951
|
+
segment.length > FIRST_OF_TYPE_PREFIX.length
|
|
5952
|
+
? segment.slice(FIRST_OF_TYPE_PREFIX.length)
|
|
5953
|
+
: undefined;
|
|
5954
|
+
/** Whether `path` holds a `$first:<type>` segment. */
|
|
5955
|
+
const hasFirstOfTypeSegment = (path) => typeof path === "string" && path.includes(FIRST_OF_TYPE_PREFIX);
|
|
5956
|
+
const IGNORED_ELEMENT_KEYS = new Set(["$", "_metadata"]);
|
|
5957
|
+
/**
|
|
5958
|
+
* A list element's type: a reference entry's `_content_type_uid`, or a
|
|
5959
|
+
* modular block element's single block key (edit tags and metadata aside).
|
|
5960
|
+
*/
|
|
5961
|
+
const getListElementType = (element) => {
|
|
5962
|
+
if (!element || typeof element !== "object" || Array.isArray(element)) {
|
|
5963
|
+
return undefined;
|
|
5964
|
+
}
|
|
5965
|
+
const record = element;
|
|
5966
|
+
if (typeof record._content_type_uid === "string") {
|
|
5967
|
+
return record._content_type_uid;
|
|
5968
|
+
}
|
|
5969
|
+
const keys = Object.keys(record).filter((key) => !IGNORED_ELEMENT_KEYS.has(key));
|
|
5970
|
+
return keys.length === 1 ? keys[0] : undefined;
|
|
5971
|
+
};
|
|
5972
|
+
/**
|
|
5973
|
+
* `path` with every `$first:<type>` segment swapped for the index of the first
|
|
5974
|
+
* element of that type in `data`, or `path` unchanged when it has none or no
|
|
5975
|
+
* element matches.
|
|
5976
|
+
*/
|
|
5977
|
+
function resolveFirstOfTypePath(data, path) {
|
|
5978
|
+
if (!hasFirstOfTypeSegment(path))
|
|
5979
|
+
return path;
|
|
5980
|
+
const segments = toPath(path);
|
|
5981
|
+
const resolved = [];
|
|
5982
|
+
let current = data;
|
|
5983
|
+
for (const segment of segments) {
|
|
5984
|
+
const type = parseFirstOfTypeSegment(segment);
|
|
5985
|
+
if (type === undefined) {
|
|
5986
|
+
resolved.push(segment);
|
|
5987
|
+
current =
|
|
5988
|
+
current && typeof current === "object"
|
|
5989
|
+
? current[segment]
|
|
5990
|
+
: undefined;
|
|
5991
|
+
continue;
|
|
5992
|
+
}
|
|
5993
|
+
if (!Array.isArray(current))
|
|
5994
|
+
return path;
|
|
5995
|
+
const index = current.findIndex((element) => getListElementType(element) === type);
|
|
5996
|
+
if (index < 0)
|
|
5997
|
+
return path;
|
|
5998
|
+
resolved.push(String(index));
|
|
5999
|
+
current = current[index];
|
|
6000
|
+
}
|
|
6001
|
+
return resolved.join(".");
|
|
6002
|
+
}
|
|
6003
|
+
/** A path for reading schemas or fetch fields: `$first:<type>` segments dropped, as indexes are. */
|
|
6004
|
+
const withoutFirstOfTypeSegments = (path) => hasFirstOfTypeSegment(path)
|
|
6005
|
+
? path
|
|
6006
|
+
.split(".")
|
|
6007
|
+
.filter((segment) => parseFirstOfTypeSegment(segment) === undefined)
|
|
6008
|
+
.join(".")
|
|
6009
|
+
: path;
|
|
6010
|
+
|
|
5821
6011
|
/**
|
|
5822
6012
|
* This transforms the provided data into the format defined by the schema.
|
|
5823
6013
|
*
|
|
@@ -5847,6 +6037,9 @@ function getDataInSchemaFormat(schema, data, bindingMap = {}, propPath = "") {
|
|
|
5847
6037
|
function getArrayData(schema, data, bindingMap, propPath) {
|
|
5848
6038
|
if (Object.keys(bindingMap).length === 0)
|
|
5849
6039
|
return data;
|
|
6040
|
+
// Mapped items come from a list; bound data that is not one maps to none.
|
|
6041
|
+
if (!Array.isArray(data))
|
|
6042
|
+
return [];
|
|
5850
6043
|
const arrayItemSchema = schema.items;
|
|
5851
6044
|
return data.map((item) => getDataInSchemaFormat(arrayItemSchema, item, bindingMap, propPath));
|
|
5852
6045
|
}
|
|
@@ -5917,6 +6110,102 @@ function removeCurrentBindingKey(entry, bindingMap, currentBindingKey) {
|
|
|
5917
6110
|
return [key, newValue];
|
|
5918
6111
|
}
|
|
5919
6112
|
|
|
6113
|
+
/**
|
|
6114
|
+
* Returns true when a section exposed prop's expose-time binding can only be
|
|
6115
|
+
* resolved INSIDE the section's own render scope — i.e. the per-iteration
|
|
6116
|
+
* Repeater item context (`dataSources.repeater.<uid>.context...`).
|
|
6117
|
+
*
|
|
6118
|
+
* Such bindings cannot be resolved at the page level, where the exposed-prop
|
|
6119
|
+
* OVERRIDE value is computed (the page data context has no `dataSources.repeater`
|
|
6120
|
+
* — that slice is injected at render time by the Repeater component, one entry
|
|
6121
|
+
* per iteration). An exposed prop bound this way is therefore NOT page-
|
|
6122
|
+
* overridable: it represents a different value for every repeater item, which a
|
|
6123
|
+
* single page-level override could never express.
|
|
6124
|
+
*
|
|
6125
|
+
* The exposed-prop override mechanism makes the page node's binding the SOLE
|
|
6126
|
+
* source of truth and applies it by KEY PRESENCE (so a cleared prop renders
|
|
6127
|
+
* empty instead of falling back to the section's authored binding). For a
|
|
6128
|
+
* repeater-context prop that rule backfires: the page-level override resolves to
|
|
6129
|
+
* `undefined`, and applying it blanks the field instead of letting the internal
|
|
6130
|
+
* Repeater binding resolve. Callers use this guard to SKIP such props from the
|
|
6131
|
+
* overrides map so retrievePropValue falls through to the node's own binding.
|
|
6132
|
+
*/
|
|
6133
|
+
function isSectionInternalExposedBinding(bindingAtExposeTime) {
|
|
6134
|
+
const type = bindingAtExposeTime?.type;
|
|
6135
|
+
return type === "repeater";
|
|
6136
|
+
}
|
|
6137
|
+
/**
|
|
6138
|
+
* The `repeaterUID` a `repeater` binding reads (`binding.value.repeaterUID`), or
|
|
6139
|
+
* undefined for any other binding / malformed input. Never throws.
|
|
6140
|
+
*/
|
|
6141
|
+
function getRepeaterBindingUID(binding) {
|
|
6142
|
+
const b = binding;
|
|
6143
|
+
if (b?.type !== "repeater")
|
|
6144
|
+
return undefined;
|
|
6145
|
+
const uid = b.value?.repeaterUID;
|
|
6146
|
+
return typeof uid === "string" && uid ? uid : undefined;
|
|
6147
|
+
}
|
|
6148
|
+
/**
|
|
6149
|
+
* Decides whether an exposed prop's page-level override should be SKIPPED (so
|
|
6150
|
+
* retrievePropValue falls through to the internal node's own binding) given its
|
|
6151
|
+
* expose-time binding and the page composer's LIVE binding for it (its type and,
|
|
6152
|
+
* for a `repeater` binding, the Repeater it reads).
|
|
6153
|
+
*
|
|
6154
|
+
* Shared by every renderer (client SectionComposition / SectionCompositionProvider
|
|
6155
|
+
* and the RSC entry) so server and client make the same call.
|
|
6156
|
+
*
|
|
6157
|
+
* The override VALUE can't drive this decision for repeater-context props: at
|
|
6158
|
+
* page level a repeater binding resolves to a placeholder (not undefined), so an
|
|
6159
|
+
* untouched seed looks identical to a real value. The live binding can:
|
|
6160
|
+
*
|
|
6161
|
+
* - auto-seeded → untouched; SKIP so the section's own binding wins.
|
|
6162
|
+
* - no live binding → nothing to override with; SKIP.
|
|
6163
|
+
* - expose-time NOT repeater → never skip (apply-by-key-presence preserved, so a
|
|
6164
|
+
* cleared template/contentstack/static prop still renders empty).
|
|
6165
|
+
* - expose-time repeater + live type page-resolvable (template/contentstack/…) →
|
|
6166
|
+
* the composer rebound it; APPLY the override.
|
|
6167
|
+
* - expose-time repeater + live `repeater` binding → decided by WHICH Repeater it
|
|
6168
|
+
* reads. An untouched pre-`autoSeeded` copy of the expose-time binding reads
|
|
6169
|
+
* the Repeater INSIDE the section (same `repeaterUID`) → SKIP. A real override
|
|
6170
|
+
* bound to a Repeater on the page/Template around the placed section reads a
|
|
6171
|
+
* different `repeaterUID` → APPLY. When either `repeaterUID` is unknown the
|
|
6172
|
+
* data can't tell them apart, so keep the old type-only behaviour (SKIP).
|
|
6173
|
+
*/
|
|
6174
|
+
function shouldSkipExposedOverride(bindingAtExposeTime, liveBindingType, autoSeeded, liveRepeaterUID) {
|
|
6175
|
+
// Untouched, auto-seeded prop → defer to the section's INTERNAL binding (which
|
|
6176
|
+
// the provider re-scopes via selectedField / repeater item context) so the
|
|
6177
|
+
// exposed prop follows schema switches and per-iteration data exactly like an
|
|
6178
|
+
// unexposed prop. Any manual edit/clear rewrites the binding without the flag,
|
|
6179
|
+
// making the page override the sole source of truth (apply-by-key-presence).
|
|
6180
|
+
if (autoSeeded)
|
|
6181
|
+
return true;
|
|
6182
|
+
// The page composition has NO binding for this exposed prop at all — its key is
|
|
6183
|
+
// absent from the page node's props (e.g. the section exposed the prop AFTER this
|
|
6184
|
+
// placement was authored, so the page node was never seeded with it). With no
|
|
6185
|
+
// page-level binding there is nothing to override WITH: retrievePropValue resolves
|
|
6186
|
+
// an unbound prop to its type's empty default ("" for strings), and applying that
|
|
6187
|
+
// by key-presence would BLANK the section's own authored binding (e.g. a template
|
|
6188
|
+
// binding to the connected entry). Defer to the section's internal binding,
|
|
6189
|
+
// exactly like an untouched auto-seeded prop. (A cleared prop differs — clearing
|
|
6190
|
+
// rewrites the binding, so it keeps a live type and still applies empty.)
|
|
6191
|
+
if (!liveBindingType)
|
|
6192
|
+
return true;
|
|
6193
|
+
// Backward-compat for placements seeded before the autoSeeded marker existed:
|
|
6194
|
+
// a repeater expose-time binding left as the (page-unresolvable) repeater seed
|
|
6195
|
+
// must still skip — applying its placeholder value would blank the per-iteration
|
|
6196
|
+
// field. Template/etc. legacy seeds keep their prior apply behavior.
|
|
6197
|
+
if (!isSectionInternalExposedBinding(bindingAtExposeTime))
|
|
6198
|
+
return false;
|
|
6199
|
+
if (liveBindingType !== "repeater")
|
|
6200
|
+
return false;
|
|
6201
|
+
// Both are repeater bindings: an untouched copy reads the SAME Repeater as the
|
|
6202
|
+
// expose-time binding; an override bound to a page/Template Repeater does not.
|
|
6203
|
+
const exposeRepeaterUID = getRepeaterBindingUID(bindingAtExposeTime);
|
|
6204
|
+
if (!liveRepeaterUID || !exposeRepeaterUID)
|
|
6205
|
+
return true;
|
|
6206
|
+
return liveRepeaterUID === exposeRepeaterUID;
|
|
6207
|
+
}
|
|
6208
|
+
|
|
5920
6209
|
/**
|
|
5921
6210
|
* Extracts the binding path string from a Contentstack-like binding object.
|
|
5922
6211
|
* Flattens nested path objects into a dot-notation string.
|
|
@@ -6123,6 +6412,14 @@ const getBindingString = (binding) => {
|
|
|
6123
6412
|
// Fallback for simple string bindings
|
|
6124
6413
|
return binding.value;
|
|
6125
6414
|
};
|
|
6415
|
+
/**
|
|
6416
|
+
* The binding's data path with any first-of-type segment resolved against
|
|
6417
|
+
* `data` (see `first-of-type.ts`): the path every value read and edit tag uses.
|
|
6418
|
+
*/
|
|
6419
|
+
const getResolvedBindingString = (binding, data) => {
|
|
6420
|
+
const path = getBindingString(binding);
|
|
6421
|
+
return typeof path === "string" ? resolveFirstOfTypePath(data, path) : path;
|
|
6422
|
+
};
|
|
6126
6423
|
const convertBindingPath = (bindingType, path) => {
|
|
6127
6424
|
const strategy = DataSourceStrategyRegistry.getInstance().get(bindingType);
|
|
6128
6425
|
if (strategy && strategy.convertPath) {
|
|
@@ -6188,7 +6485,7 @@ const resolveMetadataBindings = (node, data) => {
|
|
|
6188
6485
|
const { bindings } = node.metadata;
|
|
6189
6486
|
for (const key in bindings) {
|
|
6190
6487
|
const binding = bindings[key];
|
|
6191
|
-
const dataPath = binding &&
|
|
6488
|
+
const dataPath = binding && getResolvedBindingString(binding, data);
|
|
6192
6489
|
const getBinding = get(data, dataPath);
|
|
6193
6490
|
warnOnNonCssBoundValue(key, getBinding);
|
|
6194
6491
|
set(node, key, getBinding);
|
|
@@ -6333,6 +6630,9 @@ function retrievePropValue(args) {
|
|
|
6333
6630
|
return;
|
|
6334
6631
|
}
|
|
6335
6632
|
let resolvedData;
|
|
6633
|
+
// The bound field has no value (yet): it shows the fallback, which is not a
|
|
6634
|
+
// type mismatch.
|
|
6635
|
+
let isMissingValue = false;
|
|
6336
6636
|
// When the value is resolved via the `dataSources.page.*` fallback below,
|
|
6337
6637
|
// the CSLP tag must come from the SAME page path (not the section-local
|
|
6338
6638
|
// binding, which missed). Holds that page path so the cslp block points the
|
|
@@ -6381,7 +6681,12 @@ function retrievePropValue(args) {
|
|
|
6381
6681
|
const fallbackValue = staticValue !== undefined
|
|
6382
6682
|
? staticValue
|
|
6383
6683
|
: (defaultValue ?? placeholderComponent);
|
|
6384
|
-
|
|
6684
|
+
// A first-of-type segment resolves to its element's index here, so every
|
|
6685
|
+
// read and edit tag below sees an ordinary path (COMS-2484).
|
|
6686
|
+
const rawDataPath = bindedField && getBindingString(bindedField);
|
|
6687
|
+
const dataPath = typeof rawDataPath === "string"
|
|
6688
|
+
? resolveFirstOfTypePath(data, rawDataPath)
|
|
6689
|
+
: rawDataPath;
|
|
6385
6690
|
if ((type === "array" || type === "object") && dataPath) {
|
|
6386
6691
|
let pathForGet = dataPath;
|
|
6387
6692
|
// Use strategy-based path conversion (Agnostic)
|
|
@@ -6417,8 +6722,13 @@ function retrievePropValue(args) {
|
|
|
6417
6722
|
Array.isArray(transformedData)) {
|
|
6418
6723
|
const cslpObj = getCslpTag({ bindedField: dataPath, data });
|
|
6419
6724
|
if (cslpObj["data-cslp"]) {
|
|
6725
|
+
// One edit tag per item: the list's tag plus the item index
|
|
6726
|
+
// (`<ct>.<entry>.<locale>.gallery.0`). Live Preview / Visual
|
|
6727
|
+
// Editor read a numeric segment as a list index; a `$` before it
|
|
6728
|
+
// (`gallery.$0`) is looked up as a field path, so every item showed
|
|
6729
|
+
// "Invalid CSLP tag" with no add/move controls.
|
|
6420
6730
|
mappedData[`$${field}Items`] = transformedData.map((_, idx) => {
|
|
6421
|
-
return { "data-cslp": `${cslpObj["data-cslp"]}
|
|
6731
|
+
return { "data-cslp": `${cslpObj["data-cslp"]}.${idx}` };
|
|
6422
6732
|
});
|
|
6423
6733
|
}
|
|
6424
6734
|
}
|
|
@@ -6460,7 +6770,7 @@ function retrievePropValue(args) {
|
|
|
6460
6770
|
dataPath.startsWith("dataSources.") &&
|
|
6461
6771
|
!dataPath.startsWith("dataSources.page.") &&
|
|
6462
6772
|
data?.dataSources?.page) {
|
|
6463
|
-
const pagePath = dataPath.replace(/^dataSources\./, "dataSources.page.");
|
|
6773
|
+
const pagePath = resolveFirstOfTypePath(data, (typeof rawDataPath === "string" ? rawDataPath : dataPath).replace(/^dataSources\./, "dataSources.page."));
|
|
6464
6774
|
const pageResolved = get(data, pagePath, undefined);
|
|
6465
6775
|
if (pageResolved !== undefined && pageResolved !== null) {
|
|
6466
6776
|
resolvedData = pageResolved;
|
|
@@ -6474,7 +6784,8 @@ function retrievePropValue(args) {
|
|
|
6474
6784
|
// But context IS the primitive value, so accessing context.fieldName returns undefined.
|
|
6475
6785
|
// In this case, we should return the context itself.
|
|
6476
6786
|
let handledRepeaterContext = false;
|
|
6477
|
-
if (dataPath
|
|
6787
|
+
if (typeof dataPath === "string" &&
|
|
6788
|
+
dataPath.includes("dataSources.repeater")) {
|
|
6478
6789
|
const pathParts = dataPath.split(".");
|
|
6479
6790
|
// Check if path is: dataSources.repeater.{uid}.context.{fieldName}
|
|
6480
6791
|
if (pathParts.length >= 5 && pathParts[3] === "context") {
|
|
@@ -6491,10 +6802,31 @@ function retrievePropValue(args) {
|
|
|
6491
6802
|
}
|
|
6492
6803
|
}
|
|
6493
6804
|
}
|
|
6805
|
+
// A bound field with no value — empty for now, such as position 0 of a
|
|
6806
|
+
// list with no elements (COMS-2484): the editor shows the prop's
|
|
6807
|
+
// placeholder and the live site shows nothing. A text prop's fallback is
|
|
6808
|
+
// a placeholder element, which the type check below would otherwise
|
|
6809
|
+
// replace with the "may not display correctly" text meant for real
|
|
6810
|
+
// type mismatches.
|
|
6811
|
+
isMissingValue =
|
|
6812
|
+
type !== "object" &&
|
|
6813
|
+
type !== "array" &&
|
|
6814
|
+
!handledRepeaterContext &&
|
|
6815
|
+
(resolvedData === undefined ||
|
|
6816
|
+
resolvedData === null ||
|
|
6817
|
+
resolvedData === fallbackValue);
|
|
6818
|
+
if (isMissingValue) {
|
|
6819
|
+
resolvedData = isCompositionBeingEdited
|
|
6820
|
+
? fallbackValue
|
|
6821
|
+
: (staticValue ?? defaultValue ?? getDefaultPropStaticValue(type));
|
|
6822
|
+
}
|
|
6494
6823
|
// Unwrap single-key objects (common in Contentstack Modular Blocks)
|
|
6495
6824
|
// We only do this if we are not explicitly expecting an object or array.
|
|
6496
6825
|
// Skip if we already handled the repeater context case above.
|
|
6497
|
-
if (type !== "object" &&
|
|
6826
|
+
if (type !== "object" &&
|
|
6827
|
+
type !== "array" &&
|
|
6828
|
+
!handledRepeaterContext &&
|
|
6829
|
+
!isMissingValue) {
|
|
6498
6830
|
resolvedData = getFlattenedData(resolvedData);
|
|
6499
6831
|
resolvedData = normalizeSingleSelectChoiceValue(resolvedData, prop);
|
|
6500
6832
|
// Fallback to static value if the resolved data is still not matching the expected primitive type
|
|
@@ -6562,7 +6894,7 @@ function retrievePropValue(args) {
|
|
|
6562
6894
|
// TODO: @ravencolevol: In case of the missing string value, we are providing a placeholder component, failing this check. We have to revisit the placeholder component logic.
|
|
6563
6895
|
//NOTE: This is the error message that is sent to the parent on the render is it a good idea to send the error message here?
|
|
6564
6896
|
//or it should happen in the data tab section. might require a revisit.
|
|
6565
|
-
if (!isDataMatchingPropType(resolvedData, type)) {
|
|
6897
|
+
if (!isMissingValue && !isDataMatchingPropType(resolvedData, type)) {
|
|
6566
6898
|
const receivedType = getDataType(resolvedData);
|
|
6567
6899
|
const errorMessage = getRegistryErrorMessage(RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH, {
|
|
6568
6900
|
component: node.type,
|
|
@@ -6648,13 +6980,21 @@ function retrievePropValue(args) {
|
|
|
6648
6980
|
// so the resolved VALUE can't distinguish "untouched" from "overridden". The
|
|
6649
6981
|
// live binding type can: still `repeater` (or absent) ⇒ untouched, fall
|
|
6650
6982
|
// through to the internal per-iteration binding; any page-resolvable type ⇒
|
|
6651
|
-
// the composer rebound it and the override must win.
|
|
6983
|
+
// the composer rebound it and the override must win. For a live `repeater`
|
|
6984
|
+
// binding the TYPE alone can't tell an untouched legacy copy (reads the
|
|
6985
|
+
// Repeater inside the section) from a real override bound to a Repeater
|
|
6986
|
+
// around the placed section, so also surface WHICH Repeater it reads.
|
|
6987
|
+
// shouldSkipExposedOverride consumes all three maps.
|
|
6652
6988
|
const bindingTypes = {};
|
|
6989
|
+
const bindingRepeaters = {};
|
|
6653
6990
|
const autoSeeded = {};
|
|
6654
6991
|
for (const field of Object.keys(nodeProps)) {
|
|
6655
6992
|
const binding = nodeProps[field]?.binding;
|
|
6656
6993
|
if (binding?.type)
|
|
6657
6994
|
bindingTypes[field] = binding.type;
|
|
6995
|
+
const repeaterUID = getRepeaterBindingUID(binding);
|
|
6996
|
+
if (repeaterUID)
|
|
6997
|
+
bindingRepeaters[field] = repeaterUID;
|
|
6658
6998
|
// An auto-seeded binding means the page composer hasn't touched this exposed
|
|
6659
6999
|
// prop — the renderer skips its override so the section's internal binding
|
|
6660
7000
|
// resolves (re-scoped on schema switch / per repeater iteration).
|
|
@@ -6662,6 +7002,7 @@ function retrievePropValue(args) {
|
|
|
6662
7002
|
autoSeeded[field] = true;
|
|
6663
7003
|
}
|
|
6664
7004
|
mappedData["section_exposed_binding_types"] = bindingTypes;
|
|
7005
|
+
mappedData["section_exposed_binding_repeaters"] = bindingRepeaters;
|
|
6665
7006
|
mappedData["section_exposed_auto_seeded"] = autoSeeded;
|
|
6666
7007
|
// Per-placement design/preview mode. The editor's SectionComposition uses
|
|
6667
7008
|
// this to derive/override the render mode of every repeater, condition-block,
|
|
@@ -7259,6 +7600,55 @@ function collectStateBindingKeys(node) {
|
|
|
7259
7600
|
}
|
|
7260
7601
|
return [...keys];
|
|
7261
7602
|
}
|
|
7603
|
+
/**
|
|
7604
|
+
* The keys a node binds as Studio state (`source: "state"`, written when the
|
|
7605
|
+
* author picks a State Variable) that are not declared in this process yet.
|
|
7606
|
+
* Only tagged bindings count: an untagged `component_props` key may as well be
|
|
7607
|
+
* a function the app registers later, or plain data.
|
|
7608
|
+
*/
|
|
7609
|
+
function getUndeclaredStateBindingKeys(node) {
|
|
7610
|
+
if (!node)
|
|
7611
|
+
return [];
|
|
7612
|
+
const store = getStateStoreInstance();
|
|
7613
|
+
const keys = new Set();
|
|
7614
|
+
const consider = (binding) => {
|
|
7615
|
+
if (binding?.source !== "state")
|
|
7616
|
+
return;
|
|
7617
|
+
const key = getComponentPropsBindingKey(binding);
|
|
7618
|
+
if (key && !declaredKeyForPath(store, key))
|
|
7619
|
+
keys.add(key);
|
|
7620
|
+
};
|
|
7621
|
+
for (const binding of Object.values(node.metadata?.bindings ?? {})) {
|
|
7622
|
+
consider(binding);
|
|
7623
|
+
}
|
|
7624
|
+
for (const prop of Object.values(node.props ?? {})) {
|
|
7625
|
+
consider(prop?.binding);
|
|
7626
|
+
}
|
|
7627
|
+
return [...keys];
|
|
7628
|
+
}
|
|
7629
|
+
/** Keys already reported by {@link warnUndeclaredStateBindings}. */
|
|
7630
|
+
const reportedUndeclaredStateKeys = new Set();
|
|
7631
|
+
/**
|
|
7632
|
+
* Development aid, for server renders: warns once per key when a node bound to
|
|
7633
|
+
* a Studio state variable renders before the app declared that variable. The
|
|
7634
|
+
* server then renders the binding's fallback, and when the browser declares
|
|
7635
|
+
* the variable before hydrating, hydration finds the declared default instead
|
|
7636
|
+
* and reports a mismatch. Fix: declare state where every render sees it first
|
|
7637
|
+
* — `registerGlobalStateVariables` in a module the layout imports.
|
|
7638
|
+
*/
|
|
7639
|
+
function warnUndeclaredStateBindings(node) {
|
|
7640
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production")
|
|
7641
|
+
return;
|
|
7642
|
+
for (const key of getUndeclaredStateBindingKeys(node)) {
|
|
7643
|
+
if (reportedUndeclaredStateKeys.has(key))
|
|
7644
|
+
continue;
|
|
7645
|
+
reportedUndeclaredStateKeys.add(key);
|
|
7646
|
+
console.warn(`[Contentstack Studio] "${key}" is bound as a Studio state variable but ` +
|
|
7647
|
+
`was not declared when this page rendered on the server, so it rendered ` +
|
|
7648
|
+
`its fallback and hydration may not match. Declare it before rendering, ` +
|
|
7649
|
+
`e.g. registerGlobalStateVariables() in a module your layout imports.`);
|
|
7650
|
+
}
|
|
7651
|
+
}
|
|
7262
7652
|
/**
|
|
7263
7653
|
* Snapshot of the given declared state keys — `{ key: currentValue }` —
|
|
7264
7654
|
* merged by the renderer into `data.component_props` before prop resolution
|
|
@@ -7351,6 +7741,247 @@ function getNodeBoundFunctionName(node) {
|
|
|
7351
7741
|
return undefined;
|
|
7352
7742
|
}
|
|
7353
7743
|
|
|
7744
|
+
/**
|
|
7745
|
+
* Exposed design props (docs/adr/0004). A Section can expose a Design prop
|
|
7746
|
+
* (ADR 0003) of one of its inner nodes so each Template placement sets its own
|
|
7747
|
+
* per-breakpoint values. The placement stores them in the PLACED node's
|
|
7748
|
+
* `styles`, under a group keyed by the exposed prop's uid, with the real CSS
|
|
7749
|
+
* property as the declaration key:
|
|
7750
|
+
*
|
|
7751
|
+
* placed.styles[ep.uid].responsiveStyles[bp][ep.propKey] = <css value>
|
|
7752
|
+
*
|
|
7753
|
+
* The renderers turn that into a per-inner-node override map carried on
|
|
7754
|
+
* `dataSources[SECTION_EXPOSED_STYLE_OVERRIDES_KEY]` (next to
|
|
7755
|
+
* `section_exposed_overrides`), and merge it per breakpoint into a CLONE of the
|
|
7756
|
+
* inner node's styles right before `handleNodeStyles`. Every helper here is
|
|
7757
|
+
* shared by the client renderer, the RSC entry, the editor canvas and SSR style
|
|
7758
|
+
* extraction, so they all make the same call.
|
|
7759
|
+
*/
|
|
7760
|
+
/** dataSources key carrying {@link SectionExposedStyleOverrides} into a section subtree. */
|
|
7761
|
+
const SECTION_EXPOSED_STYLE_OVERRIDES_KEY = "section_exposed_style_overrides";
|
|
7762
|
+
/**
|
|
7763
|
+
* Internal prop a renderer hands a placed section's wrapper component: the
|
|
7764
|
+
* placed node's resolved style groups other than `default` (the raw material
|
|
7765
|
+
* the wrapper builds {@link SectionExposedStyleOverrides} from). Never a DOM
|
|
7766
|
+
* attribute.
|
|
7767
|
+
*/
|
|
7768
|
+
const SECTION_EXPOSED_STYLES_PROP = "section_exposed_styles";
|
|
7769
|
+
const DEFAULT_STYLE_GROUP = "default";
|
|
7770
|
+
const isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
7771
|
+
/** Reads `sectionExposedProps` from a section's ui (tolerates a missing/encoded ui). */
|
|
7772
|
+
function getSectionExposedPropDefinitions(sectionUi) {
|
|
7773
|
+
if (!isPlainObject(sectionUi))
|
|
7774
|
+
return [];
|
|
7775
|
+
const defs = sectionUi.metadata
|
|
7776
|
+
?.sectionExposedProps;
|
|
7777
|
+
return Array.isArray(defs) ? defs : [];
|
|
7778
|
+
}
|
|
7779
|
+
/** Indexes every node of a section's ui tree (through all slots) by uid. */
|
|
7780
|
+
function indexSectionNodes(sectionUi) {
|
|
7781
|
+
const byUid = new Map();
|
|
7782
|
+
const walk = (node) => {
|
|
7783
|
+
if (!isPlainObject(node))
|
|
7784
|
+
return;
|
|
7785
|
+
if (typeof node.uid === "string")
|
|
7786
|
+
byUid.set(node.uid, node);
|
|
7787
|
+
const slots = node.slots;
|
|
7788
|
+
if (!isPlainObject(slots))
|
|
7789
|
+
return;
|
|
7790
|
+
for (const children of Object.values(slots)) {
|
|
7791
|
+
if (Array.isArray(children))
|
|
7792
|
+
children.forEach(walk);
|
|
7793
|
+
}
|
|
7794
|
+
};
|
|
7795
|
+
walk(sectionUi);
|
|
7796
|
+
return byUid;
|
|
7797
|
+
}
|
|
7798
|
+
/**
|
|
7799
|
+
* Is this exposed prop a Design prop? The inner component's registration is
|
|
7800
|
+
* the truth: `propKey` registered with `design: true` on the component at
|
|
7801
|
+
* `nodeUid`. Only when that registration can't be found (no node, no
|
|
7802
|
+
* registry, component or prop not registered) does the entry's `design` flag
|
|
7803
|
+
* decide — so a legacy entry written without the flag still counts as design.
|
|
7804
|
+
*/
|
|
7805
|
+
function isExposedDesignProp(ep, innerNode, registry) {
|
|
7806
|
+
let registered;
|
|
7807
|
+
if (innerNode && registry) {
|
|
7808
|
+
try {
|
|
7809
|
+
registered = registry.getComponentByNode(innerNode, true)?.props?.[ep.propKey];
|
|
7810
|
+
}
|
|
7811
|
+
catch {
|
|
7812
|
+
registered = undefined;
|
|
7813
|
+
}
|
|
7814
|
+
}
|
|
7815
|
+
if (isPlainObject(registered))
|
|
7816
|
+
return registered.design === true;
|
|
7817
|
+
return ep.design === true;
|
|
7818
|
+
}
|
|
7819
|
+
/**
|
|
7820
|
+
* Splits a section's exposed props into ordinary props (`propDefs`, which ride
|
|
7821
|
+
* `section_exposed_overrides`) and design props (`designDefs`, which ride
|
|
7822
|
+
* {@link SECTION_EXPOSED_STYLE_OVERRIDES_KEY}). One walk of the section ui.
|
|
7823
|
+
*/
|
|
7824
|
+
function partitionSectionExposedProps(defs, sectionUi, registry) {
|
|
7825
|
+
if (!defs.length)
|
|
7826
|
+
return { propDefs: defs, designDefs: [] };
|
|
7827
|
+
const nodes = indexSectionNodes(sectionUi);
|
|
7828
|
+
const propDefs = [];
|
|
7829
|
+
const designDefs = [];
|
|
7830
|
+
for (const ep of defs) {
|
|
7831
|
+
if (isExposedDesignProp(ep, nodes.get(ep.nodeUid), registry)) {
|
|
7832
|
+
designDefs.push(ep);
|
|
7833
|
+
}
|
|
7834
|
+
else {
|
|
7835
|
+
propDefs.push(ep);
|
|
7836
|
+
}
|
|
7837
|
+
}
|
|
7838
|
+
return { propDefs, designDefs };
|
|
7839
|
+
}
|
|
7840
|
+
/** A placed section node (by node type, or by its registration's metadata). */
|
|
7841
|
+
function isSectionCompositionNode(node, componentOptions) {
|
|
7842
|
+
if (node?.type === "section-composition")
|
|
7843
|
+
return true;
|
|
7844
|
+
return (componentOptions?.metadata?.type ===
|
|
7845
|
+
"section-composition");
|
|
7846
|
+
}
|
|
7847
|
+
/**
|
|
7848
|
+
* A placed section's own styles as they may become classes: the `default`
|
|
7849
|
+
* group only. Its other groups are exposed-design-prop values for the inner
|
|
7850
|
+
* nodes and must never reach the wrapper as class props or DOM attributes.
|
|
7851
|
+
*/
|
|
7852
|
+
function getSectionCompositionOwnStyles(styles) {
|
|
7853
|
+
const own = styles?.[DEFAULT_STYLE_GROUP];
|
|
7854
|
+
return own ? { [DEFAULT_STYLE_GROUP]: own } : {};
|
|
7855
|
+
}
|
|
7856
|
+
/**
|
|
7857
|
+
* Snapshot of a placed section's non-`default` style groups' responsive
|
|
7858
|
+
* styles (copied per breakpoint, so a later in-place binding resolution on the
|
|
7859
|
+
* node can't change a value a memo already compared). `undefined` when none.
|
|
7860
|
+
*/
|
|
7861
|
+
function getSectionExposedStyleGroups(styles) {
|
|
7862
|
+
if (!isPlainObject(styles))
|
|
7863
|
+
return undefined;
|
|
7864
|
+
let out;
|
|
7865
|
+
for (const [group, style] of Object.entries(styles)) {
|
|
7866
|
+
if (group === DEFAULT_STYLE_GROUP)
|
|
7867
|
+
continue;
|
|
7868
|
+
const responsive = style
|
|
7869
|
+
?.responsiveStyles;
|
|
7870
|
+
if (!isPlainObject(responsive))
|
|
7871
|
+
continue;
|
|
7872
|
+
const copy = {};
|
|
7873
|
+
for (const [bp, decls] of Object.entries(responsive)) {
|
|
7874
|
+
if (isPlainObject(decls))
|
|
7875
|
+
copy[bp] = { ...decls };
|
|
7876
|
+
}
|
|
7877
|
+
out = out ?? {};
|
|
7878
|
+
out[group] = copy;
|
|
7879
|
+
}
|
|
7880
|
+
return out;
|
|
7881
|
+
}
|
|
7882
|
+
const isEmptyCssValue = (v) => v === undefined || v === null || v === "";
|
|
7883
|
+
/**
|
|
7884
|
+
* Builds `{ [nodeUid]: { [propKey]: { [bp]: { [propKey]: value } } } }` from a
|
|
7885
|
+
* placed section's style groups (keyed by exposed uid, as returned by
|
|
7886
|
+
* {@link getSectionExposedStyleGroups}). Only design
|
|
7887
|
+
* exposures count, and only the declaration under the exposure's real CSS key
|
|
7888
|
+
* (`ep.propKey`) — anything else in the group (e.g. the legacy uid-keyed
|
|
7889
|
+
* declaration) is ignored. A breakpoint whose value is empty/unresolved is
|
|
7890
|
+
* left out, so it keeps the Section's own value.
|
|
7891
|
+
*/
|
|
7892
|
+
function buildSectionExposedStyleOverrides(designDefs, placedGroups) {
|
|
7893
|
+
if (!designDefs.length || !isPlainObject(placedGroups))
|
|
7894
|
+
return null;
|
|
7895
|
+
let overrides = null;
|
|
7896
|
+
for (const ep of designDefs) {
|
|
7897
|
+
const responsive = placedGroups[ep.uid];
|
|
7898
|
+
if (!isPlainObject(responsive))
|
|
7899
|
+
continue;
|
|
7900
|
+
const perBreakpoint = {};
|
|
7901
|
+
for (const [bp, decls] of Object.entries(responsive)) {
|
|
7902
|
+
if (!isPlainObject(decls) || !(ep.propKey in decls))
|
|
7903
|
+
continue;
|
|
7904
|
+
const value = decls[ep.propKey];
|
|
7905
|
+
if (isEmptyCssValue(value))
|
|
7906
|
+
continue;
|
|
7907
|
+
perBreakpoint[bp] = { [ep.propKey]: value };
|
|
7908
|
+
}
|
|
7909
|
+
if (!Object.keys(perBreakpoint).length)
|
|
7910
|
+
continue;
|
|
7911
|
+
overrides = overrides ?? {};
|
|
7912
|
+
overrides[ep.nodeUid] = overrides[ep.nodeUid] ?? {};
|
|
7913
|
+
overrides[ep.nodeUid][ep.propKey] = perBreakpoint;
|
|
7914
|
+
}
|
|
7915
|
+
return overrides;
|
|
7916
|
+
}
|
|
7917
|
+
/**
|
|
7918
|
+
* Merges one inner node's exposed-design-prop overrides into a CLONE of its
|
|
7919
|
+
* styles: per breakpoint, the placement's declarations replace the Section's
|
|
7920
|
+
* at that breakpoint id; every other breakpoint keeps the Section's value. A
|
|
7921
|
+
* group the Section never set is created. The input is never mutated (inner
|
|
7922
|
+
* nodes are shared by every placement of the Section).
|
|
7923
|
+
*/
|
|
7924
|
+
function applyExposedStyleOverrides(styles, overridesForNode) {
|
|
7925
|
+
const base = (styles ?? {});
|
|
7926
|
+
if (!overridesForNode || !Object.keys(overridesForNode).length)
|
|
7927
|
+
return base;
|
|
7928
|
+
const merged = { ...base };
|
|
7929
|
+
for (const [propKey, perBreakpoint] of Object.entries(overridesForNode)) {
|
|
7930
|
+
if (!isPlainObject(perBreakpoint))
|
|
7931
|
+
continue;
|
|
7932
|
+
const group = base[propKey];
|
|
7933
|
+
merged[propKey] = {
|
|
7934
|
+
...(group ?? {}),
|
|
7935
|
+
classes: group?.classes ?? [],
|
|
7936
|
+
responsiveStyles: {
|
|
7937
|
+
...(group?.responsiveStyles ?? {}),
|
|
7938
|
+
...perBreakpoint,
|
|
7939
|
+
},
|
|
7940
|
+
};
|
|
7941
|
+
}
|
|
7942
|
+
return merged;
|
|
7943
|
+
}
|
|
7944
|
+
/** The style override map in scope, read from a data context's dataSources. */
|
|
7945
|
+
function getSectionExposedStyleOverrides(dataSources) {
|
|
7946
|
+
if (!isPlainObject(dataSources))
|
|
7947
|
+
return undefined;
|
|
7948
|
+
const map = dataSources[SECTION_EXPOSED_STYLE_OVERRIDES_KEY];
|
|
7949
|
+
return isPlainObject(map) ? map : undefined;
|
|
7950
|
+
}
|
|
7951
|
+
/**
|
|
7952
|
+
* The styles a renderer hands `handleNodeStyles` for a node:
|
|
7953
|
+
* - a placed section → its `default` group only;
|
|
7954
|
+
* - an inner node with exposed-design-prop overrides in scope → a merged clone;
|
|
7955
|
+
* - anything else → its own styles, untouched.
|
|
7956
|
+
*/
|
|
7957
|
+
function getNodeRenderStyles(node, dataSources, isSectionComposition = node.type === "section-composition") {
|
|
7958
|
+
if (isSectionComposition)
|
|
7959
|
+
return getSectionCompositionOwnStyles(node.styles);
|
|
7960
|
+
const forNode = getSectionExposedStyleOverrides(dataSources)?.[node.uid];
|
|
7961
|
+
return applyExposedStyleOverrides(node.styles, forNode);
|
|
7962
|
+
}
|
|
7963
|
+
/**
|
|
7964
|
+
* Returns `dataSources` scoped to ONE placement's style overrides: `overrides`
|
|
7965
|
+
* replaces whatever map was inherited (an enclosing section's map is never
|
|
7966
|
+
* meant for this section's nodes), and `null` removes it. Returns the input
|
|
7967
|
+
* unchanged when there is nothing to add or remove.
|
|
7968
|
+
*/
|
|
7969
|
+
function withSectionExposedStyleOverrides(dataSources, overrides) {
|
|
7970
|
+
const hasInherited = isPlainObject(dataSources) &&
|
|
7971
|
+
SECTION_EXPOSED_STYLE_OVERRIDES_KEY in dataSources;
|
|
7972
|
+
if (overrides && Object.keys(overrides).length) {
|
|
7973
|
+
if (hasInherited &&
|
|
7974
|
+
dataSources[SECTION_EXPOSED_STYLE_OVERRIDES_KEY] === overrides) {
|
|
7975
|
+
return dataSources;
|
|
7976
|
+
}
|
|
7977
|
+
return { ...dataSources, [SECTION_EXPOSED_STYLE_OVERRIDES_KEY]: overrides };
|
|
7978
|
+
}
|
|
7979
|
+
if (!hasInherited)
|
|
7980
|
+
return dataSources;
|
|
7981
|
+
const { [SECTION_EXPOSED_STYLE_OVERRIDES_KEY]: _dropped, ...rest } = dataSources;
|
|
7982
|
+
return rest;
|
|
7983
|
+
}
|
|
7984
|
+
|
|
7354
7985
|
class BreakpointRegistry {
|
|
7355
7986
|
breakpoints = [];
|
|
7356
7987
|
requiredFields = ["id", "query", "previewSize"];
|
|
@@ -7568,14 +8199,19 @@ exports.DATA_SOURCES = DATA_SOURCES;
|
|
|
7568
8199
|
exports.DATA_SOURCES_PREFIX = DATA_SOURCES_PREFIX;
|
|
7569
8200
|
exports.DEFAULT_DESIGN_TOKENS = DEFAULT_DESIGN_TOKENS;
|
|
7570
8201
|
exports.DesignRegistry = DesignRegistry;
|
|
8202
|
+
exports.FIRST_OF_TYPE_PREFIX = FIRST_OF_TYPE_PREFIX;
|
|
7571
8203
|
exports.INTERNAL_COMPONENTS_NAMES = INTERNAL_COMPONENTS_NAMES;
|
|
7572
8204
|
exports.INTERNAL_COMPONENT_SECTIONS = INTERNAL_COMPONENT_SECTIONS;
|
|
7573
8205
|
exports.INTERNAL_SECTIONS = INTERNAL_SECTIONS;
|
|
7574
8206
|
exports.JSONRTERegistry = JSONRTERegistry;
|
|
8207
|
+
exports.SECTION_EXPOSED_STYLES_PROP = SECTION_EXPOSED_STYLES_PROP;
|
|
8208
|
+
exports.SECTION_EXPOSED_STYLE_OVERRIDES_KEY = SECTION_EXPOSED_STYLE_OVERRIDES_KEY;
|
|
7575
8209
|
exports.STYLE_SECTIONS_OPTIONS = STYLE_SECTIONS_OPTIONS;
|
|
7576
8210
|
exports.STYLE_SECTION_CATEGORIES = STYLE_SECTION_CATEGORIES;
|
|
7577
8211
|
exports.SYSTEM_COMPONENTS = SYSTEM_COMPONENTS;
|
|
7578
8212
|
exports.StudioStateStore = StudioStateStore;
|
|
8213
|
+
exports.applyExposedStyleOverrides = applyExposedStyleOverrides;
|
|
8214
|
+
exports.buildSectionExposedStyleOverrides = buildSectionExposedStyleOverrides;
|
|
7579
8215
|
exports.callStudioFunction = callStudioFunction;
|
|
7580
8216
|
exports.clearReportedBindingErrorsForNode = clearReportedBindingErrorsForNode;
|
|
7581
8217
|
exports.collectStateBindingKeys = collectStateBindingKeys;
|
|
@@ -7590,10 +8226,18 @@ exports.getDesignClassesNames = getDesignClassesNames;
|
|
|
7590
8226
|
exports.getDesignRegistryInstance = getDesignRegistryInstance;
|
|
7591
8227
|
exports.getFlattenedData = getFlattenedData;
|
|
7592
8228
|
exports.getGlobalStudioStore = getGlobalStudioStore;
|
|
8229
|
+
exports.getListElementType = getListElementType;
|
|
7593
8230
|
exports.getNodeBoundFunctionName = getNodeBoundFunctionName;
|
|
8231
|
+
exports.getNodeRenderStyles = getNodeRenderStyles;
|
|
7594
8232
|
exports.getPlaceHolderComponent = getPlaceHolderComponent;
|
|
7595
8233
|
exports.getRepeaterBinding = getRepeaterBinding;
|
|
8234
|
+
exports.getRepeaterBindingUID = getRepeaterBindingUID;
|
|
7596
8235
|
exports.getRepeaterContextPath = getRepeaterContextPath;
|
|
8236
|
+
exports.getResolvedBindingString = getResolvedBindingString;
|
|
8237
|
+
exports.getSectionCompositionOwnStyles = getSectionCompositionOwnStyles;
|
|
8238
|
+
exports.getSectionExposedPropDefinitions = getSectionExposedPropDefinitions;
|
|
8239
|
+
exports.getSectionExposedStyleGroups = getSectionExposedStyleGroups;
|
|
8240
|
+
exports.getSectionExposedStyleOverrides = getSectionExposedStyleOverrides;
|
|
7597
8241
|
exports.getSectionUIDFromNode = getSectionUIDFromNode;
|
|
7598
8242
|
exports.getServerComponentRegistryInstance = getServerComponentRegistryInstance;
|
|
7599
8243
|
exports.getSlotData = getSlotData;
|
|
@@ -7602,12 +8246,21 @@ exports.getStateStoreInstance = getStateStoreInstance;
|
|
|
7602
8246
|
exports.getStateValuesFor = getStateValuesFor;
|
|
7603
8247
|
exports.getStudioFunctionNames = getStudioFunctionNames;
|
|
7604
8248
|
exports.getStudioStateSnapshot = getStudioStateSnapshot;
|
|
8249
|
+
exports.getUndeclaredStateBindingKeys = getUndeclaredStateBindingKeys;
|
|
7605
8250
|
exports.hasComponentRegistryInstance = hasComponentRegistryInstance;
|
|
7606
8251
|
exports.hasDesignRegistryInstance = hasDesignRegistryInstance;
|
|
8252
|
+
exports.hasFirstOfTypeSegment = hasFirstOfTypeSegment;
|
|
8253
|
+
exports.indexSectionNodes = indexSectionNodes;
|
|
7607
8254
|
exports.isClientReferenceComponent = isClientReferenceComponent;
|
|
7608
8255
|
exports.isDataMatchingPropType = isDataMatchingPropType;
|
|
8256
|
+
exports.isExposedDesignProp = isExposedDesignProp;
|
|
7609
8257
|
exports.isKnownType = isKnownType;
|
|
8258
|
+
exports.isSectionCompositionNode = isSectionCompositionNode;
|
|
8259
|
+
exports.isSectionInternalExposedBinding = isSectionInternalExposedBinding;
|
|
8260
|
+
exports.loadBuiltInComponents = loadBuiltInComponents;
|
|
7610
8261
|
exports.normalizeSingleSelectChoiceValue = normalizeSingleSelectChoiceValue;
|
|
8262
|
+
exports.parseFirstOfTypeSegment = parseFirstOfTypeSegment;
|
|
8263
|
+
exports.partitionSectionExposedProps = partitionSectionExposedProps;
|
|
7611
8264
|
exports.registerComponentStateVariable = registerComponentStateVariable;
|
|
7612
8265
|
exports.registerGlobalStateVariables = registerGlobalStateVariables;
|
|
7613
8266
|
exports.registerStudioFunctions = registerStudioFunctions;
|
|
@@ -7616,11 +8269,17 @@ exports.resetDesignRegistryInstance = resetDesignRegistryInstance;
|
|
|
7616
8269
|
exports.resetGlobalStudioStore = resetGlobalStudioStore;
|
|
7617
8270
|
exports.resetStateStoreInstance = resetStateStoreInstance;
|
|
7618
8271
|
exports.resetStudioFunctions = resetStudioFunctions;
|
|
8272
|
+
exports.resolveFirstOfTypePath = resolveFirstOfTypePath;
|
|
7619
8273
|
exports.resolveMetadataBindings = resolveMetadataBindings;
|
|
7620
8274
|
exports.retrievePropValue = retrievePropValue;
|
|
8275
|
+
exports.setBuiltInComponentsLoader = setBuiltInComponentsLoader;
|
|
8276
|
+
exports.shouldSkipExposedOverride = shouldSkipExposedOverride;
|
|
7621
8277
|
exports.studioState = studioState;
|
|
7622
8278
|
exports.subscribeStudioFunctionsChanged = subscribeStudioFunctionsChanged;
|
|
7623
8279
|
exports.subscribeStudioStateVariablesChanged = subscribeStudioStateVariablesChanged;
|
|
7624
8280
|
exports.warnOnNonCssBoundValue = warnOnNonCssBoundValue;
|
|
8281
|
+
exports.warnUndeclaredStateBindings = warnUndeclaredStateBindings;
|
|
8282
|
+
exports.withSectionExposedStyleOverrides = withSectionExposedStyleOverrides;
|
|
8283
|
+
exports.withoutFirstOfTypeSegments = withoutFirstOfTypeSegments;
|
|
7625
8284
|
exports.wrapActionProps = wrapActionProps;
|
|
7626
8285
|
//# sourceMappingURL=index.cjs.map
|