@contentstack/studio-registry 1.9.0 → 2.0.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 +297 -46
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/common/global-store.js +44 -8
- package/dist/esm/common/global-store.js.map +1 -1
- package/dist/esm/component-registry/registry-options-processor.js +116 -0
- package/dist/esm/component-registry/registry-options-processor.js.map +1 -1
- package/dist/esm/component-registry/registry.js +1 -1
- package/dist/esm/component-registry/registry.js.map +1 -1
- package/dist/esm/component-registry/singleton.js +40 -10
- package/dist/esm/component-registry/singleton.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.js +34 -13
- package/dist/esm/data-binder/retrieve-data.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.util.js +47 -2
- package/dist/esm/data-binder/retrieve-data.util.js.map +1 -1
- package/dist/esm/index.d.ts +114 -47
- package/dist/esm/index.js +3 -3
- package/dist/esm/state-store/function-registry.js +6 -6
- package/dist/esm/state-store/function-registry.js.map +1 -1
- package/dist/esm/state-store/public-api.js +1 -1
- package/dist/esm/state-store/public-api.js.map +1 -1
- package/dist/esm/state-store/state-store.js +8 -8
- package/dist/esm/state-store/state-store.js.map +1 -1
- package/package.json +16 -7
- package/LICENSE +0 -21
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var constants = require('@contentstack/studio-messenger/constants');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Keys for registry error message lookup. Use these constants instead of string literals.
|
|
@@ -3948,6 +3948,8 @@ function processRegistryOptions(userConfig, options) {
|
|
|
3948
3948
|
if (userConfig.thumbnailUrl) {
|
|
3949
3949
|
defaultOptions.thumbnailUrl = userConfig.thumbnailUrl;
|
|
3950
3950
|
}
|
|
3951
|
+
validateDesignProps(userConfig.type, defaultOptions.props, userConfig.styles);
|
|
3952
|
+
validateSlotDataFrom(userConfig.type, defaultOptions.props);
|
|
3951
3953
|
if (userConfig.styles) {
|
|
3952
3954
|
defaultOptions.styles = processRegistryOptionsStylesOptions(userConfig.styles);
|
|
3953
3955
|
}
|
|
@@ -4082,6 +4084,79 @@ function processRegistryOptionsProps(props) {
|
|
|
4082
4084
|
validateSlotCountPropLinkages(props, processedProps);
|
|
4083
4085
|
return { props: processedProps, validators: propValidators };
|
|
4084
4086
|
}
|
|
4087
|
+
/** Prop types that may carry the `design` flag. */
|
|
4088
|
+
const DESIGN_PROP_TYPES = new Set(["choice", "string"]);
|
|
4089
|
+
/**
|
|
4090
|
+
* Keys a design prop must never use: `default` is consumed as the component's
|
|
4091
|
+
* `className` by `handleNodeStyles`, and the rest would collide with React /
|
|
4092
|
+
* renderer-owned props when the generated class is spread onto the component.
|
|
4093
|
+
*/
|
|
4094
|
+
const DESIGN_PROP_RESERVED_KEYS = new Set([
|
|
4095
|
+
"default",
|
|
4096
|
+
"className",
|
|
4097
|
+
"children",
|
|
4098
|
+
"style",
|
|
4099
|
+
"key",
|
|
4100
|
+
"ref",
|
|
4101
|
+
]);
|
|
4102
|
+
/**
|
|
4103
|
+
* Design props are style groups in disguise: the renderer spreads
|
|
4104
|
+
* `node.styles[key]`'s generated class onto the component under the prop key.
|
|
4105
|
+
* A key that is not a CSS property, is reserved, collides with a registered
|
|
4106
|
+
* style group, or sits on an unsupported prop type would either style nothing
|
|
4107
|
+
* or clobber another prop — so the flag is stripped with a warning
|
|
4108
|
+
* (registry convention: warn, don't throw).
|
|
4109
|
+
*
|
|
4110
|
+
* CSS-property check: only the camelCase SHAPE is enforced (strip-worthy) —
|
|
4111
|
+
* DOM-based existence checks differ across browsers/test environments, and an
|
|
4112
|
+
* unknown-but-css-shaped key merely emits a no-op CSS declaration, which is
|
|
4113
|
+
* safe. When a DOM is available and doesn't know the property, an advisory
|
|
4114
|
+
* warning is logged without stripping the flag.
|
|
4115
|
+
*/
|
|
4116
|
+
function validateDesignProps(componentType, processedProps, stylesInput) {
|
|
4117
|
+
const styleGroupKeys = new Set(Object.keys(stylesInput ?? {}));
|
|
4118
|
+
for (const [field, prop] of Object.entries(processedProps)) {
|
|
4119
|
+
if (!("design" in prop) || !prop.design)
|
|
4120
|
+
continue;
|
|
4121
|
+
const strip = (reason) => {
|
|
4122
|
+
console.warn(`[studio] Ignoring \`design: true\` on prop "${field}" of component "${componentType}": ${reason}`);
|
|
4123
|
+
delete prop.design;
|
|
4124
|
+
};
|
|
4125
|
+
if (!DESIGN_PROP_TYPES.has(prop.type)) {
|
|
4126
|
+
strip(`type "${prop.type}" is not supported (allowed: ${[...DESIGN_PROP_TYPES].join(", ")}).`);
|
|
4127
|
+
}
|
|
4128
|
+
else if (DESIGN_PROP_RESERVED_KEYS.has(field)) {
|
|
4129
|
+
strip(`"${field}" is a reserved key.`);
|
|
4130
|
+
}
|
|
4131
|
+
else if (styleGroupKeys.has(field)) {
|
|
4132
|
+
strip(`"${field}" collides with a registered style group.`);
|
|
4133
|
+
}
|
|
4134
|
+
else if (!CAMEL_CASE_CSS_KEY.test(field)) {
|
|
4135
|
+
strip(`"${field}" is not a camelCase CSS property.`);
|
|
4136
|
+
}
|
|
4137
|
+
else if (!isKnownCssPropertyInDom(field)) {
|
|
4138
|
+
console.warn(`[studio] Design prop "${field}" of component "${componentType}" does not match a known CSS property in this browser — its values will emit a no-op declaration.`);
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
const CAMEL_CASE_CSS_KEY = /^[a-z][a-zA-Z]*$/;
|
|
4143
|
+
/** Best-effort DOM probe; returns true when no reliable DOM is available. */
|
|
4144
|
+
function isKnownCssPropertyInDom(key) {
|
|
4145
|
+
if (typeof document === "undefined" || !document.createElement)
|
|
4146
|
+
return true;
|
|
4147
|
+
try {
|
|
4148
|
+
const style = document.createElement("div").style;
|
|
4149
|
+
if (key in style)
|
|
4150
|
+
return true;
|
|
4151
|
+
// Some DOM implementations only accept kebab-case via setProperty.
|
|
4152
|
+
const kebab = key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
4153
|
+
style.setProperty(kebab, "unset");
|
|
4154
|
+
return style.getPropertyValue(kebab) !== "";
|
|
4155
|
+
}
|
|
4156
|
+
catch {
|
|
4157
|
+
return true;
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4085
4160
|
/**
|
|
4086
4161
|
* The editor stores a single-select choice value as a `string[]` (and the SDK unwraps
|
|
4087
4162
|
* it to a scalar on render). Authors may write a single-select `defaultValue` as a
|
|
@@ -4137,6 +4212,47 @@ function validateSlotCountPropLinkages(originalProps, processedProps) {
|
|
|
4137
4212
|
};
|
|
4138
4213
|
}
|
|
4139
4214
|
}
|
|
4215
|
+
/**
|
|
4216
|
+
* `dataFrom` on a slot names the prop whose bound data a `<Slot data>` key
|
|
4217
|
+
* forwards, so Studio can resolve that key's CMS schema. It is a schema hint
|
|
4218
|
+
* only — a bad entry must not break registration, so it is dropped with a
|
|
4219
|
+
* warning (registry convention: warn, don't throw). A target has to be a
|
|
4220
|
+
* registered, non-slot prop: a slot holds nodes, not data, and a missing name
|
|
4221
|
+
* would silently fall back to the plain-JSON schema Studio shows today.
|
|
4222
|
+
*/
|
|
4223
|
+
function validateSlotDataFrom(componentType, processedProps) {
|
|
4224
|
+
for (const [field, prop] of Object.entries(processedProps)) {
|
|
4225
|
+
if (prop.type !== "slot")
|
|
4226
|
+
continue;
|
|
4227
|
+
const slotProp = prop;
|
|
4228
|
+
const { dataFrom } = slotProp;
|
|
4229
|
+
if (dataFrom === undefined)
|
|
4230
|
+
continue;
|
|
4231
|
+
const warn = (reason) => console.warn(`[studio] Ignoring \`dataFrom\` ${reason} on slot "${field}" of component "${componentType}".`);
|
|
4232
|
+
if (!dataFrom || typeof dataFrom !== "object" || Array.isArray(dataFrom)) {
|
|
4233
|
+
warn("(expected an object mapping slot data keys to prop names)");
|
|
4234
|
+
delete slotProp.dataFrom;
|
|
4235
|
+
continue;
|
|
4236
|
+
}
|
|
4237
|
+
const valid = {};
|
|
4238
|
+
for (const [key, propName] of Object.entries(dataFrom)) {
|
|
4239
|
+
const target = typeof propName === "string" ? processedProps[propName] : undefined;
|
|
4240
|
+
if (!target) {
|
|
4241
|
+
warn(`entry "${key}": "${String(propName)}" is not a registered prop`);
|
|
4242
|
+
}
|
|
4243
|
+
else if (target.type === "slot") {
|
|
4244
|
+
warn(`entry "${key}": "${propName}" is a slot, not a data prop`);
|
|
4245
|
+
}
|
|
4246
|
+
else {
|
|
4247
|
+
valid[key] = propName;
|
|
4248
|
+
}
|
|
4249
|
+
}
|
|
4250
|
+
if (Object.keys(valid).length)
|
|
4251
|
+
slotProp.dataFrom = valid;
|
|
4252
|
+
else
|
|
4253
|
+
delete slotProp.dataFrom;
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4140
4256
|
function getBlockStyleSections() {
|
|
4141
4257
|
return STYLE_SECTION_CATEGORIES.block;
|
|
4142
4258
|
}
|
|
@@ -4636,8 +4752,34 @@ class ComponentRegistry {
|
|
|
4636
4752
|
*
|
|
4637
4753
|
* The key is versioned (`_v1`) so future shape changes can land under `_v2`
|
|
4638
4754
|
* without colliding with older SDK copies during a partial upgrade.
|
|
4755
|
+
*
|
|
4756
|
+
* ── Why there are TWO slots ─────────────────────────────────────────────────
|
|
4757
|
+
* Sharing works for everything whose value is identical in both graphs (design
|
|
4758
|
+
* tokens, breakpoints, state). It does NOT work for the component registry,
|
|
4759
|
+
* because the two renderers need DIFFERENT values for the same component type:
|
|
4760
|
+
*
|
|
4761
|
+
* - `StudioServerComponent` (`@contentstack/studio-react/rsc`) runs in the RSC
|
|
4762
|
+
* graph and needs the CLIENT REFERENCE for a `"use client"` component, so
|
|
4763
|
+
* React can serialize it as an island.
|
|
4764
|
+
* - `StudioComponent` (main entry) runs in the SSR/browser graph and needs the
|
|
4765
|
+
* REAL implementation, because a client reference cannot be called.
|
|
4766
|
+
*
|
|
4767
|
+
* With one shared slot and one entry per type, whichever graph registered
|
|
4768
|
+
* first decided what the other graph rendered. When the RSC renderer lost that
|
|
4769
|
+
* race it called a client component itself, outside any client React runtime,
|
|
4770
|
+
* and the first hook threw `Cannot read properties of null (reading
|
|
4771
|
+
* 'useState')`. Components without hooks rendered inline and silently lost
|
|
4772
|
+
* their island, so the breakage was invisible until an interactive component
|
|
4773
|
+
* hit it.
|
|
4774
|
+
*
|
|
4775
|
+
* So the component registry is keyed per graph: the RSC entry reads and writes
|
|
4776
|
+
* the `_rsc` slot, every other consumer keeps the original slot. Registration
|
|
4777
|
+
* order stops being load-bearing. The remaining registries stay shared — their
|
|
4778
|
+
* contents are plain data, correct in either graph.
|
|
4639
4779
|
*/
|
|
4640
4780
|
const GLOBAL_STORE_KEY = "__contentstack_studio_registry_v1";
|
|
4781
|
+
const GLOBAL_STORE_KEY_SERVER = "__contentstack_studio_registry_v1_rsc";
|
|
4782
|
+
const storeKeyFor = (graph) => graph === "server" ? GLOBAL_STORE_KEY_SERVER : GLOBAL_STORE_KEY;
|
|
4641
4783
|
/**
|
|
4642
4784
|
* Returns the SDK's versioned slot on globalThis, creating it on first call.
|
|
4643
4785
|
* Always returns the same object reference within a single JS runtime.
|
|
@@ -4646,11 +4788,15 @@ const GLOBAL_STORE_KEY = "__contentstack_studio_registry_v1";
|
|
|
4646
4788
|
* read/write so the public API of `studio-registry` stays free of cross-
|
|
4647
4789
|
* package import dependencies (e.g. `BreakpointManager` lives in
|
|
4648
4790
|
* `studio-client`).
|
|
4791
|
+
*
|
|
4792
|
+
* @param graph - which slot to read. Defaults to `"client"`; only the RSC
|
|
4793
|
+
* entry passes `"server"`.
|
|
4649
4794
|
*/
|
|
4650
|
-
function getGlobalStudioStore() {
|
|
4795
|
+
function getGlobalStudioStore(graph = "client") {
|
|
4651
4796
|
const g = globalThis;
|
|
4652
|
-
|
|
4653
|
-
|
|
4797
|
+
const key = storeKeyFor(graph);
|
|
4798
|
+
if (!g[key]) {
|
|
4799
|
+
g[key] = {
|
|
4654
4800
|
componentRegistry: null,
|
|
4655
4801
|
designRegistry: null,
|
|
4656
4802
|
breakpointManager: null,
|
|
@@ -4658,17 +4804,30 @@ function getGlobalStudioStore() {
|
|
|
4658
4804
|
functionRegistry: null,
|
|
4659
4805
|
};
|
|
4660
4806
|
}
|
|
4661
|
-
return g[
|
|
4807
|
+
return g[key];
|
|
4662
4808
|
}
|
|
4663
4809
|
/**
|
|
4664
|
-
* Clears the
|
|
4665
|
-
*
|
|
4810
|
+
* Clears the store. For tests only. Production code should never call this —
|
|
4811
|
+
* it would orphan every existing reference to the previous instances.
|
|
4812
|
+
*
|
|
4813
|
+
* @param graph - clears just that graph's slot. Omit to clear both.
|
|
4666
4814
|
*/
|
|
4667
|
-
function resetGlobalStudioStore() {
|
|
4815
|
+
function resetGlobalStudioStore(graph) {
|
|
4668
4816
|
const g = globalThis;
|
|
4669
|
-
|
|
4817
|
+
const keys = graph
|
|
4818
|
+
? [storeKeyFor(graph)]
|
|
4819
|
+
: [GLOBAL_STORE_KEY, GLOBAL_STORE_KEY_SERVER];
|
|
4820
|
+
for (const key of keys)
|
|
4821
|
+
delete g[key];
|
|
4670
4822
|
}
|
|
4671
4823
|
|
|
4824
|
+
const registryFor = (graph) => {
|
|
4825
|
+
const store = getGlobalStudioStore(graph);
|
|
4826
|
+
if (!store.componentRegistry) {
|
|
4827
|
+
store.componentRegistry = new ComponentRegistry();
|
|
4828
|
+
}
|
|
4829
|
+
return store.componentRegistry;
|
|
4830
|
+
};
|
|
4672
4831
|
/**
|
|
4673
4832
|
* Singleton ComponentRegistry, backed by a versioned slot on `globalThis`.
|
|
4674
4833
|
*
|
|
@@ -4682,13 +4841,33 @@ function resetGlobalStudioStore() {
|
|
|
4682
4841
|
* After this change, all callers of `getComponentRegistryInstance()` resolve
|
|
4683
4842
|
* to the same `ComponentRegistry` instance within a single JS runtime,
|
|
4684
4843
|
* regardless of which graph or worker they were evaluated in.
|
|
4844
|
+
*
|
|
4845
|
+
* One exception: the RSC renderer has its own instance — see
|
|
4846
|
+
* {@link getServerComponentRegistryInstance} and the "Why there are TWO slots"
|
|
4847
|
+
* note in `common/global-store.ts`.
|
|
4685
4848
|
*/
|
|
4686
4849
|
function getComponentRegistryInstance() {
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4850
|
+
return registryFor("client");
|
|
4851
|
+
}
|
|
4852
|
+
/**
|
|
4853
|
+
* Singleton ComponentRegistry for the RSC (server) module graph, used only by
|
|
4854
|
+
* `@contentstack/studio-react/rsc`.
|
|
4855
|
+
*
|
|
4856
|
+
* It is a SEPARATE instance from {@link getComponentRegistryInstance} on
|
|
4857
|
+
* purpose. The two renderers need different values for the same component
|
|
4858
|
+
* type — a client reference for the RSC renderer, the real implementation for
|
|
4859
|
+
* the client renderer — and both graphs run in one process, sharing
|
|
4860
|
+
* `globalThis`. One entry per type meant the first registration to arrive
|
|
4861
|
+
* decided what the other renderer got, making correctness depend on request
|
|
4862
|
+
* order (a Studio canvas request before the first visitor render was enough to
|
|
4863
|
+
* break every visitor render for the life of the process).
|
|
4864
|
+
*
|
|
4865
|
+
* Consequence for consumers: registering in the browser/SSR graph no longer
|
|
4866
|
+
* populates the RSC renderer. An app using `StudioServerComponent` must
|
|
4867
|
+
* register from a server module through `@contentstack/studio-react/rsc`.
|
|
4868
|
+
*/
|
|
4869
|
+
function getServerComponentRegistryInstance() {
|
|
4870
|
+
return registryFor("server");
|
|
4692
4871
|
}
|
|
4693
4872
|
/**
|
|
4694
4873
|
* Resets the singleton instance.
|
|
@@ -4703,16 +4882,19 @@ function getComponentRegistryInstance() {
|
|
|
4703
4882
|
* });
|
|
4704
4883
|
* ```
|
|
4705
4884
|
*/
|
|
4706
|
-
function resetComponentRegistryInstance() {
|
|
4707
|
-
|
|
4885
|
+
function resetComponentRegistryInstance(graph) {
|
|
4886
|
+
const graphs = graph ? [graph] : ["client", "server"];
|
|
4887
|
+
for (const g of graphs)
|
|
4888
|
+
getGlobalStudioStore(g).componentRegistry = null;
|
|
4708
4889
|
}
|
|
4709
4890
|
/**
|
|
4710
4891
|
* Checks if the singleton instance has been created.
|
|
4711
4892
|
*
|
|
4893
|
+
* @param graph - which graph's instance to check. Defaults to `"client"`.
|
|
4712
4894
|
* @returns true if the instance exists, false otherwise
|
|
4713
4895
|
*/
|
|
4714
|
-
function hasComponentRegistryInstance() {
|
|
4715
|
-
return getGlobalStudioStore().componentRegistry !== null;
|
|
4896
|
+
function hasComponentRegistryInstance(graph = "client") {
|
|
4897
|
+
return getGlobalStudioStore(graph).componentRegistry !== null;
|
|
4716
4898
|
}
|
|
4717
4899
|
|
|
4718
4900
|
const SIZE_TOKENS = {
|
|
@@ -5882,7 +6064,22 @@ function isKnownType(type) {
|
|
|
5882
6064
|
}
|
|
5883
6065
|
function getSlotData({ nodeProps, field, node, getSlots, }) {
|
|
5884
6066
|
const currentNodeProp = nodeProps[field];
|
|
5885
|
-
|
|
6067
|
+
// The slot key normally rides on the node's own prop (`props.children.slot`),
|
|
6068
|
+
// which Studio's editor writes when it authors a container. A composition
|
|
6069
|
+
// authored through the CMA routinely omits it — the children are already in
|
|
6070
|
+
// `node.slots[field]`, so the prop looks redundant.
|
|
6071
|
+
//
|
|
6072
|
+
// Without a fallback that omission renders NOTHING, silently: no throw, no
|
|
6073
|
+
// warning, and the parent still renders its own wrapper, so the page looks
|
|
6074
|
+
// "built but empty" and the cause is invisible. Measured end-to-end: a
|
|
6075
|
+
// page > section-composition > box > header/plain-text tree resolved
|
|
6076
|
+
// correctly at every layer — CDA, spec, registry, static_value — and emitted
|
|
6077
|
+
// a single empty <div>.
|
|
6078
|
+
//
|
|
6079
|
+
// `node.slots[field]` is the same key the component definition declares the
|
|
6080
|
+
// slot under, so falling back to `field` is the author's evident intent and
|
|
6081
|
+
// matches what the editor would have written.
|
|
6082
|
+
const slotUid = currentNodeProp?.slot ?? (node.slots?.[field] ? field : undefined);
|
|
5886
6083
|
if (!slotUid) {
|
|
5887
6084
|
return null;
|
|
5888
6085
|
}
|
|
@@ -5956,6 +6153,35 @@ function normalizeSingleSelectChoiceValue(resolvedData, prop) {
|
|
|
5956
6153
|
}
|
|
5957
6154
|
return resolvedData;
|
|
5958
6155
|
}
|
|
6156
|
+
/**
|
|
6157
|
+
* A design prop's bound value is written straight into a CSS declaration —
|
|
6158
|
+
* there is no token-to-CSS step left. So a CMS field holding `gradient-teal`
|
|
6159
|
+
* rather than `linear-gradient(...)` (or `var(--card-bg-gradient-teal)`)
|
|
6160
|
+
* produces an invalid declaration that the browser silently drops: no error,
|
|
6161
|
+
* no style, nothing to tell an author their field is the problem.
|
|
6162
|
+
*
|
|
6163
|
+
* Best-effort and browser-only: `CSS.supports` is absent server-side, where
|
|
6164
|
+
* this stays quiet rather than guessing.
|
|
6165
|
+
*/
|
|
6166
|
+
const STYLE_BINDING_PATH = /^styles\.[^.]+\.responsiveStyles\.[^.]+\.(.+)$/;
|
|
6167
|
+
const warnOnNonCssBoundValue = (key, value) => {
|
|
6168
|
+
const property = STYLE_BINDING_PATH.exec(key)?.[1];
|
|
6169
|
+
if (!property || typeof value !== "string" || !value.trim())
|
|
6170
|
+
return;
|
|
6171
|
+
if (typeof CSS === "undefined" || typeof CSS.supports !== "function")
|
|
6172
|
+
return;
|
|
6173
|
+
const kebab = property.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
6174
|
+
try {
|
|
6175
|
+
if (CSS.supports(kebab, value))
|
|
6176
|
+
return;
|
|
6177
|
+
}
|
|
6178
|
+
catch {
|
|
6179
|
+
return;
|
|
6180
|
+
}
|
|
6181
|
+
console.warn(`[studio] Bound design prop "${property}" resolved to "${value}", which is not a valid ` +
|
|
6182
|
+
`value for that CSS property — the declaration will be dropped and nothing will render. ` +
|
|
6183
|
+
`The field this is bound to has to hold a CSS value (e.g. a var(--token) or a literal).`);
|
|
6184
|
+
};
|
|
5959
6185
|
const resolveMetadataBindings = (node, data) => {
|
|
5960
6186
|
if (!node.metadata?.bindings)
|
|
5961
6187
|
return;
|
|
@@ -5964,6 +6190,7 @@ const resolveMetadataBindings = (node, data) => {
|
|
|
5964
6190
|
const binding = bindings[key];
|
|
5965
6191
|
const dataPath = binding && getBindingString(binding);
|
|
5966
6192
|
const getBinding = get(data, dataPath);
|
|
6193
|
+
warnOnNonCssBoundValue(key, getBinding);
|
|
5967
6194
|
set(node, key, getBinding);
|
|
5968
6195
|
}
|
|
5969
6196
|
};
|
|
@@ -6051,6 +6278,28 @@ const reportedBindingErrors = new Set();
|
|
|
6051
6278
|
* Keys are `${nodeUid}-${field}`; the trailing `-` (and fixed-length uids)
|
|
6052
6279
|
* makes the prefix match exact, so one node's uid can't match another's.
|
|
6053
6280
|
*/
|
|
6281
|
+
/**
|
|
6282
|
+
* Reports a binding error to the Visual Builder.
|
|
6283
|
+
*
|
|
6284
|
+
* The event manager is imported on demand rather than at module scope: it is
|
|
6285
|
+
* the postMessage bridge, and importing it statically pulls
|
|
6286
|
+
* @contentstack/advanced-post-message into every bundle that reaches this
|
|
6287
|
+
* module — including a published site, where `composableStudioEventManager` is
|
|
6288
|
+
* `undefined` and these calls do nothing. Both call sites are already
|
|
6289
|
+
* editor-only and best-effort, so sending a microtask later is not observable.
|
|
6290
|
+
*/
|
|
6291
|
+
function reportBindingError(propKey, errorMessage) {
|
|
6292
|
+
// The send is RETURNED from `then` so `catch` covers it as well as the
|
|
6293
|
+
// import. `send` rejects with NO_REQUEST_LISTENER_FOUND whenever nothing is
|
|
6294
|
+
// listening on the other side — which is every context except an open Studio
|
|
6295
|
+
// canvas — and an uncaught rejection there surfaces in the visitor's console
|
|
6296
|
+
// and fails the test run. Best-effort telemetry must never reject.
|
|
6297
|
+
void import('@contentstack/studio-messenger')
|
|
6298
|
+
.then(({ composableStudioEventManager }) => composableStudioEventManager?.send(constants.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, { propKey, errorMessage }))
|
|
6299
|
+
.catch((error) => {
|
|
6300
|
+
console.warn("[studio] could not send", constants.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, error);
|
|
6301
|
+
});
|
|
6302
|
+
}
|
|
6054
6303
|
function clearReportedBindingErrorsForNode(nodeUid) {
|
|
6055
6304
|
if (reportedBindingErrors.size === 0)
|
|
6056
6305
|
return;
|
|
@@ -6059,10 +6308,7 @@ function clearReportedBindingErrorsForNode(nodeUid) {
|
|
|
6059
6308
|
if (!propKey.startsWith(prefix))
|
|
6060
6309
|
continue;
|
|
6061
6310
|
reportedBindingErrors.delete(propKey);
|
|
6062
|
-
|
|
6063
|
-
propKey,
|
|
6064
|
-
errorMessage: "",
|
|
6065
|
-
});
|
|
6311
|
+
reportBindingError(propKey, "");
|
|
6066
6312
|
}
|
|
6067
6313
|
}
|
|
6068
6314
|
// Responsible for resolving props to values
|
|
@@ -6078,6 +6324,14 @@ function retrievePropValue(args) {
|
|
|
6078
6324
|
if (!isKnownType(type)) {
|
|
6079
6325
|
return;
|
|
6080
6326
|
}
|
|
6327
|
+
// Design props never resolve to a data value: their generated class is
|
|
6328
|
+
// spread onto the component from `node.styles[field]` BEFORE resolved
|
|
6329
|
+
// props, so emitting anything here (even the registration defaultValue)
|
|
6330
|
+
// would clobber that class. See studio-registry design-prop validation
|
|
6331
|
+
// and docs/adr/0003.
|
|
6332
|
+
if ("design" in prop && prop.design) {
|
|
6333
|
+
return;
|
|
6334
|
+
}
|
|
6081
6335
|
let resolvedData;
|
|
6082
6336
|
// When the value is resolved via the `dataSources.page.*` fallback below,
|
|
6083
6337
|
// the CSLP tag must come from the SAME page path (not the section-local
|
|
@@ -6320,10 +6574,7 @@ function retrievePropValue(args) {
|
|
|
6320
6574
|
if (isCompositionBeingEdited) {
|
|
6321
6575
|
// In editor mode: Send to Visual Builder
|
|
6322
6576
|
reportedBindingErrors.add(`${node.uid}-${field}`);
|
|
6323
|
-
|
|
6324
|
-
propKey: `${node.uid}-${field}`,
|
|
6325
|
-
errorMessage: getRegistryErrorMessage(RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH_EDITOR, { expectedType: type, receivedType }),
|
|
6326
|
-
});
|
|
6577
|
+
reportBindingError(`${node.uid}-${field}`, getRegistryErrorMessage(RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH_EDITOR, { expectedType: type, receivedType }));
|
|
6327
6578
|
}
|
|
6328
6579
|
else {
|
|
6329
6580
|
// In production mode: Console warning
|
|
@@ -6347,10 +6598,7 @@ function retrievePropValue(args) {
|
|
|
6347
6598
|
const propKey = `${node.uid}-${field}`;
|
|
6348
6599
|
if (reportedBindingErrors.has(propKey)) {
|
|
6349
6600
|
reportedBindingErrors.delete(propKey);
|
|
6350
|
-
|
|
6351
|
-
propKey,
|
|
6352
|
-
errorMessage: "",
|
|
6353
|
-
});
|
|
6601
|
+
reportBindingError(propKey, "");
|
|
6354
6602
|
}
|
|
6355
6603
|
}
|
|
6356
6604
|
mappedData[field] = resolvedData;
|
|
@@ -6536,7 +6784,7 @@ class StudioStateStore {
|
|
|
6536
6784
|
this.externalUnsubs.clear();
|
|
6537
6785
|
if (storage === "custom") {
|
|
6538
6786
|
if (!hasCustomFns) {
|
|
6539
|
-
throw new Error('[
|
|
6787
|
+
throw new Error('[Contentstack Studio] state storage "custom" requires getState and setState functions');
|
|
6540
6788
|
}
|
|
6541
6789
|
this.userConfig = {
|
|
6542
6790
|
getState: config.getState,
|
|
@@ -6546,7 +6794,7 @@ class StudioStateStore {
|
|
|
6546
6794
|
}
|
|
6547
6795
|
else {
|
|
6548
6796
|
if (hasCustomFns && isDev$1()) {
|
|
6549
|
-
console.warn(`[
|
|
6797
|
+
console.warn(`[Contentstack Studio] state storage "${storage}" uses the built-in store — the provided getState/setState are ignored (use storage: "custom" to keep them)`);
|
|
6550
6798
|
}
|
|
6551
6799
|
this.userConfig = createWebStorageBackend(storage, config.storageKey ?? DEFAULT_STORAGE_KEY);
|
|
6552
6800
|
}
|
|
@@ -6598,7 +6846,7 @@ class StudioStateStore {
|
|
|
6598
6846
|
this.externalUnsubs.set(key, typeof unsub === "function" ? unsub : () => { });
|
|
6599
6847
|
}
|
|
6600
6848
|
catch (err) {
|
|
6601
|
-
console.error(`[
|
|
6849
|
+
console.error(`[Contentstack Studio] state subscribe("${key}") threw:`, err);
|
|
6602
6850
|
}
|
|
6603
6851
|
}
|
|
6604
6852
|
isConfigured() {
|
|
@@ -6630,7 +6878,7 @@ class StudioStateStore {
|
|
|
6630
6878
|
return;
|
|
6631
6879
|
}
|
|
6632
6880
|
if (existing.type !== def.type && isDev$1()) {
|
|
6633
|
-
console.warn(`[
|
|
6881
|
+
console.warn(`[Contentstack Studio] state variable "${key}" already declared as "${existing.type}"; ignoring re-declaration as "${def.type}"`);
|
|
6634
6882
|
}
|
|
6635
6883
|
return;
|
|
6636
6884
|
}
|
|
@@ -6663,7 +6911,7 @@ class StudioStateStore {
|
|
|
6663
6911
|
listener();
|
|
6664
6912
|
}
|
|
6665
6913
|
catch (err) {
|
|
6666
|
-
console.error("[
|
|
6914
|
+
console.error("[Contentstack Studio] state variables-changed listener threw:", err);
|
|
6667
6915
|
}
|
|
6668
6916
|
}
|
|
6669
6917
|
}
|
|
@@ -6686,7 +6934,7 @@ class StudioStateStore {
|
|
|
6686
6934
|
return this.userConfig.getState(key);
|
|
6687
6935
|
}
|
|
6688
6936
|
catch (err) {
|
|
6689
|
-
console.error(`[
|
|
6937
|
+
console.error(`[Contentstack Studio] getState("${key}") threw:`, err);
|
|
6690
6938
|
return undefined;
|
|
6691
6939
|
}
|
|
6692
6940
|
}
|
|
@@ -6703,7 +6951,7 @@ class StudioStateStore {
|
|
|
6703
6951
|
if (isServer()) {
|
|
6704
6952
|
if (!this.warnedServerSet && isDev$1()) {
|
|
6705
6953
|
this.warnedServerSet = true;
|
|
6706
|
-
console.warn("[
|
|
6954
|
+
console.warn("[Contentstack Studio] setState is a no-op during server rendering — state writes are client-only");
|
|
6707
6955
|
}
|
|
6708
6956
|
return;
|
|
6709
6957
|
}
|
|
@@ -6764,7 +7012,7 @@ class StudioStateStore {
|
|
|
6764
7012
|
listener();
|
|
6765
7013
|
}
|
|
6766
7014
|
catch (err) {
|
|
6767
|
-
console.error(`[
|
|
7015
|
+
console.error(`[Contentstack Studio] state listener for "${key}" threw:`, err);
|
|
6768
7016
|
}
|
|
6769
7017
|
}
|
|
6770
7018
|
}
|
|
@@ -6849,7 +7097,7 @@ function notifyFunctionsChanged() {
|
|
|
6849
7097
|
listener();
|
|
6850
7098
|
}
|
|
6851
7099
|
catch (err) {
|
|
6852
|
-
console.error("[
|
|
7100
|
+
console.error("[Contentstack Studio] studio-functions change listener threw:", err);
|
|
6853
7101
|
}
|
|
6854
7102
|
}
|
|
6855
7103
|
}
|
|
@@ -6888,11 +7136,11 @@ function registerStudioFunctions(functions) {
|
|
|
6888
7136
|
const registry = getRegistry();
|
|
6889
7137
|
for (const [name, fn] of Object.entries(functions ?? {})) {
|
|
6890
7138
|
if (typeof fn !== "function") {
|
|
6891
|
-
console.warn(`[
|
|
7139
|
+
console.warn(`[Contentstack Studio] registerStudioFunctions: "${name}" is not a function — skipped`);
|
|
6892
7140
|
continue;
|
|
6893
7141
|
}
|
|
6894
7142
|
if (registry.functions.has(name) && isDev()) {
|
|
6895
|
-
console.warn(`[
|
|
7143
|
+
console.warn(`[Contentstack Studio] studio function "${name}" re-registered (overwriting previous)`);
|
|
6896
7144
|
}
|
|
6897
7145
|
registry.functions.set(name, fn);
|
|
6898
7146
|
}
|
|
@@ -6916,7 +7164,7 @@ function getStudioFunctionNames() {
|
|
|
6916
7164
|
function callStudioFunction(name, ...args) {
|
|
6917
7165
|
const fn = getRegistry().functions.get(name);
|
|
6918
7166
|
if (!fn) {
|
|
6919
|
-
console.warn(`[
|
|
7167
|
+
console.warn(`[Contentstack Studio] studio function "${name}" is not registered. Did you call registerStudioFunctions()?`);
|
|
6920
7168
|
return undefined;
|
|
6921
7169
|
}
|
|
6922
7170
|
const store = getStateStoreInstance();
|
|
@@ -6934,14 +7182,14 @@ function callStudioFunction(name, ...args) {
|
|
|
6934
7182
|
typeof result.then === "function" &&
|
|
6935
7183
|
typeof result.catch === "function") {
|
|
6936
7184
|
return result.catch((err) => {
|
|
6937
|
-
console.error(`[
|
|
7185
|
+
console.error(`[Contentstack Studio] studio function "${name}" rejected:`, err);
|
|
6938
7186
|
return undefined;
|
|
6939
7187
|
});
|
|
6940
7188
|
}
|
|
6941
7189
|
return result;
|
|
6942
7190
|
}
|
|
6943
7191
|
catch (err) {
|
|
6944
|
-
console.error(`[
|
|
7192
|
+
console.error(`[Contentstack Studio] studio function "${name}" threw:`, err);
|
|
6945
7193
|
return undefined;
|
|
6946
7194
|
}
|
|
6947
7195
|
}
|
|
@@ -7193,7 +7441,7 @@ class BreakpointRegistry {
|
|
|
7193
7441
|
*/
|
|
7194
7442
|
function registerComponentStateVariable(key, options) {
|
|
7195
7443
|
if (!key || typeof key !== "string") {
|
|
7196
|
-
throw new Error("[
|
|
7444
|
+
throw new Error("[Contentstack Studio] registerComponentStateVariable requires a non-empty string key");
|
|
7197
7445
|
}
|
|
7198
7446
|
getStateStoreInstance().declareVariable(key, options, "component");
|
|
7199
7447
|
}
|
|
@@ -7347,6 +7595,7 @@ exports.getPlaceHolderComponent = getPlaceHolderComponent;
|
|
|
7347
7595
|
exports.getRepeaterBinding = getRepeaterBinding;
|
|
7348
7596
|
exports.getRepeaterContextPath = getRepeaterContextPath;
|
|
7349
7597
|
exports.getSectionUIDFromNode = getSectionUIDFromNode;
|
|
7598
|
+
exports.getServerComponentRegistryInstance = getServerComponentRegistryInstance;
|
|
7350
7599
|
exports.getSlotData = getSlotData;
|
|
7351
7600
|
exports.getStateDefaultsFor = getStateDefaultsFor;
|
|
7352
7601
|
exports.getStateStoreInstance = getStateStoreInstance;
|
|
@@ -7355,6 +7604,7 @@ exports.getStudioFunctionNames = getStudioFunctionNames;
|
|
|
7355
7604
|
exports.getStudioStateSnapshot = getStudioStateSnapshot;
|
|
7356
7605
|
exports.hasComponentRegistryInstance = hasComponentRegistryInstance;
|
|
7357
7606
|
exports.hasDesignRegistryInstance = hasDesignRegistryInstance;
|
|
7607
|
+
exports.isClientReferenceComponent = isClientReferenceComponent;
|
|
7358
7608
|
exports.isDataMatchingPropType = isDataMatchingPropType;
|
|
7359
7609
|
exports.isKnownType = isKnownType;
|
|
7360
7610
|
exports.normalizeSingleSelectChoiceValue = normalizeSingleSelectChoiceValue;
|
|
@@ -7371,5 +7621,6 @@ exports.retrievePropValue = retrievePropValue;
|
|
|
7371
7621
|
exports.studioState = studioState;
|
|
7372
7622
|
exports.subscribeStudioFunctionsChanged = subscribeStudioFunctionsChanged;
|
|
7373
7623
|
exports.subscribeStudioStateVariablesChanged = subscribeStudioStateVariablesChanged;
|
|
7624
|
+
exports.warnOnNonCssBoundValue = warnOnNonCssBoundValue;
|
|
7374
7625
|
exports.wrapActionProps = wrapActionProps;
|
|
7375
7626
|
//# sourceMappingURL=index.cjs.map
|