@contentstack/studio-registry 1.4.1 → 1.6.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 +159 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/component-registry/registry-options-processor.js +36 -0
- package/dist/esm/component-registry/registry-options-processor.js.map +1 -1
- package/dist/esm/component-registry/registry.constant.js +1 -0
- package/dist/esm/component-registry/registry.constant.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.js +115 -2
- package/dist/esm/data-binder/retrieve-data.js.map +1 -1
- package/dist/esm/data-binder/retrieve-data.util.js +7 -1
- package/dist/esm/data-binder/retrieve-data.util.js.map +1 -1
- package/dist/esm/index.d.ts +94 -4
- package/dist/esm/index.js +1 -1
- package/package.json +7 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -131,6 +131,7 @@ const INTERNAL_COMPONENTS_NAMES = {
|
|
|
131
131
|
JSON_RTE: "json-rte",
|
|
132
132
|
COLLAPSIBLE_TEXT: "collapsible-text",
|
|
133
133
|
PLAIN_TEXT: "plain-text",
|
|
134
|
+
RICH_TEXT: "rich-text",
|
|
134
135
|
// * Media
|
|
135
136
|
VIDEO: "video",
|
|
136
137
|
EMBED: "embed",
|
|
@@ -3907,6 +3908,7 @@ function getDefaultComponentSchemaInput(options) {
|
|
|
3907
3908
|
hideFromComponentList: false,
|
|
3908
3909
|
registry: "user-defined",
|
|
3909
3910
|
icon: "",
|
|
3911
|
+
layerIcon: "",
|
|
3910
3912
|
metadata: {},
|
|
3911
3913
|
styles: {
|
|
3912
3914
|
default: {
|
|
@@ -3969,6 +3971,16 @@ function processRegistryOptions(userConfig, options) {
|
|
|
3969
3971
|
if ("icon" in userConfig && userConfig.icon) {
|
|
3970
3972
|
defaultOptions.icon = userConfig.icon;
|
|
3971
3973
|
}
|
|
3974
|
+
if (userConfig.layerIcon) {
|
|
3975
|
+
if (isValidLayerIcon(userConfig.layerIcon)) {
|
|
3976
|
+
defaultOptions.layerIcon = userConfig.layerIcon;
|
|
3977
|
+
}
|
|
3978
|
+
else {
|
|
3979
|
+
// Don't break registration over a bad icon — drop it and fall back to the default glyph.
|
|
3980
|
+
console.warn(`[studio] Ignoring invalid \`layerIcon\` for component "${userConfig.type}". ` +
|
|
3981
|
+
`Expected an inline SVG string, an absolute http(s)/data:image URL, or a servable relative path.`);
|
|
3982
|
+
}
|
|
3983
|
+
}
|
|
3972
3984
|
if (userConfig.metadata) {
|
|
3973
3985
|
defaultOptions.metadata = userConfig.metadata;
|
|
3974
3986
|
}
|
|
@@ -3977,6 +3989,31 @@ function processRegistryOptions(userConfig, options) {
|
|
|
3977
3989
|
propValidators,
|
|
3978
3990
|
};
|
|
3979
3991
|
}
|
|
3992
|
+
/**
|
|
3993
|
+
* Light, render-agnostic check that a `layerIcon` value is plausibly an inline SVG,
|
|
3994
|
+
* an image URL, or a servable path. This is developer feedback only — the Studio
|
|
3995
|
+
* builder still sanitizes/validates authoritatively at render time, since the value
|
|
3996
|
+
* crosses the postMessage boundary untrusted.
|
|
3997
|
+
*/
|
|
3998
|
+
function isValidLayerIcon(value) {
|
|
3999
|
+
if (typeof value !== "string")
|
|
4000
|
+
return false;
|
|
4001
|
+
const v = value.trim();
|
|
4002
|
+
if (!v)
|
|
4003
|
+
return false;
|
|
4004
|
+
// Inline SVG markup (with or without an xml prolog).
|
|
4005
|
+
if (v.startsWith("<"))
|
|
4006
|
+
return v.includes("<svg");
|
|
4007
|
+
// Absolute http(s) URL.
|
|
4008
|
+
if (/^https?:\/\//i.test(v))
|
|
4009
|
+
return true;
|
|
4010
|
+
// A data URI must be an image.
|
|
4011
|
+
if (/^data:/i.test(v))
|
|
4012
|
+
return /^data:image\//i.test(v);
|
|
4013
|
+
// A relative/root-relative asset path. Must be explicitly path-shaped — a bare token
|
|
4014
|
+
// (e.g. a built-in icon NAME like "ComponentBox") is NOT a valid layerIcon.
|
|
4015
|
+
return v.startsWith("/") || v.startsWith("./") || v.startsWith("../");
|
|
4016
|
+
}
|
|
3980
4017
|
function processStylesOptionsStyleSections(styleSections, defaultStyleSections) {
|
|
3981
4018
|
if (typeof styleSections === "undefined" || styleSections === "all") {
|
|
3982
4019
|
return defaultStyleSections;
|
|
@@ -5799,6 +5836,7 @@ function getDefaultPropStaticValue(args) {
|
|
|
5799
5836
|
datestring: "",
|
|
5800
5837
|
any: "",
|
|
5801
5838
|
json_rte: {},
|
|
5839
|
+
plaintext: "",
|
|
5802
5840
|
};
|
|
5803
5841
|
if (args) {
|
|
5804
5842
|
return defaultValues[args];
|
|
@@ -5819,6 +5857,7 @@ function isKnownType(type) {
|
|
|
5819
5857
|
datestring: true,
|
|
5820
5858
|
any: true,
|
|
5821
5859
|
json_rte: true,
|
|
5860
|
+
plaintext: true,
|
|
5822
5861
|
};
|
|
5823
5862
|
return Object.keys(knownTypes).includes(type);
|
|
5824
5863
|
}
|
|
@@ -5939,8 +5978,12 @@ function isDataMatchingPropType(data, type) {
|
|
|
5939
5978
|
imageurl: dataType === "string",
|
|
5940
5979
|
datestring: dataType === "string",
|
|
5941
5980
|
json_rte: dataType === "object",
|
|
5981
|
+
// "any" accepts all data types — no validation
|
|
5982
|
+
any: true,
|
|
5983
|
+
// "plaintext" accepts singleline/multiline text, number, and boolean fields
|
|
5984
|
+
plaintext: dataType === "string" || dataType === "number" || dataType === "boolean",
|
|
5942
5985
|
};
|
|
5943
|
-
return map[type];
|
|
5986
|
+
return map[type] ?? false;
|
|
5944
5987
|
}
|
|
5945
5988
|
function getDataType(data) {
|
|
5946
5989
|
if (typeof data === "object" && data !== null && !Array.isArray(data)) {
|
|
@@ -5960,6 +6003,48 @@ const dataSourceCapabilities = {
|
|
|
5960
6003
|
[DATA_SOURCES.QUERY]: { supportsCslp: true }, // Verified: Query supports CSLP now
|
|
5961
6004
|
};
|
|
5962
6005
|
|
|
6006
|
+
/**
|
|
6007
|
+
* Prop keys (`<nodeUid>-<field>`) for which a binding-type-mismatch error has
|
|
6008
|
+
* been reported to the editor and not yet retracted.
|
|
6009
|
+
*
|
|
6010
|
+
* The editor's "Data Mismatch Found" badge is driven entirely by the
|
|
6011
|
+
* UPDATE_BINDING_ERRORS messages we send from here — it has no other source of
|
|
6012
|
+
* truth. Previously we only ever SENT errors and never retracted them, so a
|
|
6013
|
+
* transient mismatch (e.g. a section repeater bound to scope-root that briefly
|
|
6014
|
+
* sees the whole entry OBJECT while a freshly-swapped schema re-scopes) left a
|
|
6015
|
+
* sticky error that survived even after the data resolved correctly. Tracking
|
|
6016
|
+
* what we've reported lets us emit a one-shot retraction the moment the data
|
|
6017
|
+
* matches again, so the badge reflects the live render instead of latching.
|
|
6018
|
+
*/
|
|
6019
|
+
const reportedBindingErrors = new Set();
|
|
6020
|
+
/**
|
|
6021
|
+
* Retract every binding-mismatch error previously reported for `nodeUid`'s
|
|
6022
|
+
* props and forget them.
|
|
6023
|
+
*
|
|
6024
|
+
* The in-render retraction in `retrievePropValue` only clears the editor badge
|
|
6025
|
+
* when the SAME node re-renders with matching data — which never happens once
|
|
6026
|
+
* the node disappears (e.g. a repeater item removed, or a section swapped for a
|
|
6027
|
+
* different schema). Without this, such a node's badge would latch and its
|
|
6028
|
+
* entry would leak in `reportedBindingErrors` forever. Call this from the
|
|
6029
|
+
* node's unmount path so the badge reflects the live tree.
|
|
6030
|
+
*
|
|
6031
|
+
* Keys are `${nodeUid}-${field}`; the trailing `-` (and fixed-length uids)
|
|
6032
|
+
* makes the prefix match exact, so one node's uid can't match another's.
|
|
6033
|
+
*/
|
|
6034
|
+
function clearReportedBindingErrorsForNode(nodeUid) {
|
|
6035
|
+
if (reportedBindingErrors.size === 0)
|
|
6036
|
+
return;
|
|
6037
|
+
const prefix = `${nodeUid}-`;
|
|
6038
|
+
for (const propKey of reportedBindingErrors) {
|
|
6039
|
+
if (!propKey.startsWith(prefix))
|
|
6040
|
+
continue;
|
|
6041
|
+
reportedBindingErrors.delete(propKey);
|
|
6042
|
+
studioMessenger.composableStudioEventManager?.send(studioMessenger.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, {
|
|
6043
|
+
propKey,
|
|
6044
|
+
errorMessage: "",
|
|
6045
|
+
});
|
|
6046
|
+
}
|
|
6047
|
+
}
|
|
5963
6048
|
// Responsible for resolving props to values
|
|
5964
6049
|
function retrievePropValue(args) {
|
|
5965
6050
|
const { data, componentOptions, node, cslp, placeholders = {}, getSlots, jsonRTE, isCompositionBeingEdited, } = args;
|
|
@@ -5988,6 +6073,11 @@ function retrievePropValue(args) {
|
|
|
5988
6073
|
return;
|
|
5989
6074
|
}
|
|
5990
6075
|
let resolvedData;
|
|
6076
|
+
// When the value is resolved via the `dataSources.page.*` fallback below,
|
|
6077
|
+
// the CSLP tag must come from the SAME page path (not the section-local
|
|
6078
|
+
// binding, which missed). Holds that page path so the cslp block points the
|
|
6079
|
+
// edit tag at the field the value actually came from.
|
|
6080
|
+
let cslpPathOverride;
|
|
5991
6081
|
if (type === "slot") {
|
|
5992
6082
|
resolvedData = getSlotData({
|
|
5993
6083
|
nodeProps: nodeProps,
|
|
@@ -6008,6 +6098,20 @@ function retrievePropValue(args) {
|
|
|
6008
6098
|
const overridesForNode = data.dataSources?.section_exposed_overrides?.[node.uid];
|
|
6009
6099
|
if (overridesForNode && field in overridesForNode) {
|
|
6010
6100
|
mappedData[field] = overridesForNode[field];
|
|
6101
|
+
// Carry the page-resolved CSLP tag for this exposed prop. This branch
|
|
6102
|
+
// short-circuits BEFORE the cslp block (~L430), so without re-emitting
|
|
6103
|
+
// here a page-overridden field (e.g. a section's root component bound via
|
|
6104
|
+
// a non-repeater binding) renders with no `data-cslp` and loses its
|
|
6105
|
+
// live-preview edit overlay — even though its value resolves fine. The
|
|
6106
|
+
// SectionComposition wrappers stash the page node's resolved cslp object
|
|
6107
|
+
// alongside the value under `$<propKey>`, so it points at the PAGE entry
|
|
6108
|
+
// field (the override's source of truth). Repeater-context exposed props
|
|
6109
|
+
// are never in this map (they fall through to their own binding + cslp).
|
|
6110
|
+
if (cslp.appendTags) {
|
|
6111
|
+
const overrideCslp = overridesForNode[`$${field}`];
|
|
6112
|
+
if (overrideCslp)
|
|
6113
|
+
mappedData[`$${field}`] = overrideCslp;
|
|
6114
|
+
}
|
|
6011
6115
|
return;
|
|
6012
6116
|
}
|
|
6013
6117
|
const nodePropConfig = nodeProps[field];
|
|
@@ -6099,6 +6203,8 @@ function retrievePropValue(args) {
|
|
|
6099
6203
|
const pageResolved = get(data, pagePath, undefined);
|
|
6100
6204
|
if (pageResolved !== undefined && pageResolved !== null) {
|
|
6101
6205
|
resolvedData = pageResolved;
|
|
6206
|
+
// Mirror the value's source so the cslp block tags the page field.
|
|
6207
|
+
cslpPathOverride = pagePath;
|
|
6102
6208
|
}
|
|
6103
6209
|
}
|
|
6104
6210
|
// Handle primitive values in repeater context
|
|
@@ -6205,6 +6311,7 @@ function retrievePropValue(args) {
|
|
|
6205
6311
|
});
|
|
6206
6312
|
if (isCompositionBeingEdited) {
|
|
6207
6313
|
// In editor mode: Send to Visual Builder
|
|
6314
|
+
reportedBindingErrors.add(`${node.uid}-${field}`);
|
|
6208
6315
|
studioMessenger.composableStudioEventManager?.send(studioMessenger.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, {
|
|
6209
6316
|
propKey: `${node.uid}-${field}`,
|
|
6210
6317
|
errorMessage: getRegistryErrorMessage(RegistryErrorMessageKey.DATA_BINDING_TYPE_MISMATCH_EDITOR, { expectedType: type, receivedType }),
|
|
@@ -6223,6 +6330,21 @@ function retrievePropValue(args) {
|
|
|
6223
6330
|
});
|
|
6224
6331
|
}
|
|
6225
6332
|
}
|
|
6333
|
+
else if (isCompositionBeingEdited) {
|
|
6334
|
+
// Data now matches the prop type. If we previously reported a mismatch for
|
|
6335
|
+
// this prop, retract it (empty errorMessage → the editor calls
|
|
6336
|
+
// removeBindingError) so a stale "Data Mismatch Found" badge doesn't
|
|
6337
|
+
// persist after the binding re-resolves — e.g. once a swapped section
|
|
6338
|
+
// schema finishes re-scoping a repeater's items to its array field.
|
|
6339
|
+
const propKey = `${node.uid}-${field}`;
|
|
6340
|
+
if (reportedBindingErrors.has(propKey)) {
|
|
6341
|
+
reportedBindingErrors.delete(propKey);
|
|
6342
|
+
studioMessenger.composableStudioEventManager?.send(studioMessenger.POST_MESSAGE_EVENTS.UPDATE_BINDING_ERRORS, {
|
|
6343
|
+
propKey,
|
|
6344
|
+
errorMessage: "",
|
|
6345
|
+
});
|
|
6346
|
+
}
|
|
6347
|
+
}
|
|
6226
6348
|
mappedData[field] = resolvedData;
|
|
6227
6349
|
if (type === "json_rte") {
|
|
6228
6350
|
mappedData["jsonConfig"] = jsonRTE;
|
|
@@ -6230,7 +6352,13 @@ function retrievePropValue(args) {
|
|
|
6230
6352
|
const isCSLPAbleType = bindedField?.type &&
|
|
6231
6353
|
dataSourceCapabilities[bindedField.type]?.supportsCslp;
|
|
6232
6354
|
if (cslp.appendTags && dataPath && isCSLPAbleType) {
|
|
6233
|
-
|
|
6355
|
+
// Use the page-fallback path when the value came from there (cross-section
|
|
6356
|
+
// / slot-child page binding), so the edit tag points at the field that
|
|
6357
|
+
// actually supplied the value; otherwise the section-local binding path.
|
|
6358
|
+
const cslpValue = getCslpTag({
|
|
6359
|
+
bindedField: cslpPathOverride ?? dataPath,
|
|
6360
|
+
data,
|
|
6361
|
+
});
|
|
6234
6362
|
if (cslpValue) {
|
|
6235
6363
|
mappedData[`$${field}`] = cslpValue;
|
|
6236
6364
|
}
|
|
@@ -6262,6 +6390,34 @@ function retrievePropValue(args) {
|
|
|
6262
6390
|
mappedData["symbol_props"][uid] = mappedData[field];
|
|
6263
6391
|
});
|
|
6264
6392
|
}
|
|
6393
|
+
if (node.type === "section-composition") {
|
|
6394
|
+
// Surface the page composer's LIVE binding type for each exposed prop so the
|
|
6395
|
+
// SectionComposition renderer can tell an untouched seed from a real override.
|
|
6396
|
+
// A repeater expose-time binding is only resolvable inside the section's own
|
|
6397
|
+
// Repeater scope; at page level it resolves to a placeholder, not undefined —
|
|
6398
|
+
// so the resolved VALUE can't distinguish "untouched" from "overridden". The
|
|
6399
|
+
// live binding type can: still `repeater` (or absent) ⇒ untouched, fall
|
|
6400
|
+
// through to the internal per-iteration binding; any page-resolvable type ⇒
|
|
6401
|
+
// the composer rebound it and the override must win.
|
|
6402
|
+
const bindingTypes = {};
|
|
6403
|
+
const autoSeeded = {};
|
|
6404
|
+
for (const field of Object.keys(nodeProps)) {
|
|
6405
|
+
const binding = nodeProps[field]?.binding;
|
|
6406
|
+
if (binding?.type)
|
|
6407
|
+
bindingTypes[field] = binding.type;
|
|
6408
|
+
// An auto-seeded binding means the page composer hasn't touched this exposed
|
|
6409
|
+
// prop — the renderer skips its override so the section's internal binding
|
|
6410
|
+
// resolves (re-scoped on schema switch / per repeater iteration).
|
|
6411
|
+
if (binding?.autoSeeded)
|
|
6412
|
+
autoSeeded[field] = true;
|
|
6413
|
+
}
|
|
6414
|
+
mappedData["section_exposed_binding_types"] = bindingTypes;
|
|
6415
|
+
mappedData["section_exposed_auto_seeded"] = autoSeeded;
|
|
6416
|
+
// Per-placement design/preview mode. The editor's SectionComposition uses
|
|
6417
|
+
// this to derive/override the render mode of every repeater, condition-block,
|
|
6418
|
+
// and section-slot inside the section. Ignored in production (renders live).
|
|
6419
|
+
mappedData["mode"] = node?.metadata?.mode;
|
|
6420
|
+
}
|
|
6265
6421
|
// TODO: Add support for useData Hook for studio
|
|
6266
6422
|
return mappedData;
|
|
6267
6423
|
}
|
|
@@ -6347,6 +6503,7 @@ exports.JSONRTERegistry = JSONRTERegistry;
|
|
|
6347
6503
|
exports.STYLE_SECTIONS_OPTIONS = STYLE_SECTIONS_OPTIONS;
|
|
6348
6504
|
exports.STYLE_SECTION_CATEGORIES = STYLE_SECTION_CATEGORIES;
|
|
6349
6505
|
exports.SYSTEM_COMPONENTS = SYSTEM_COMPONENTS;
|
|
6506
|
+
exports.clearReportedBindingErrorsForNode = clearReportedBindingErrorsForNode;
|
|
6350
6507
|
exports.convertBindingPath = convertBindingPath;
|
|
6351
6508
|
exports.getBindingString = getBindingString;
|
|
6352
6509
|
exports.getComponentRegistryInstance = getComponentRegistryInstance;
|