@contentstack/studio-client 3.1.0 → 4.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/README.md +21 -0
- package/dist/breakpoints/BreakpointManager.js +7 -5
- package/dist/breakpoints/BreakpointManager.js.map +1 -1
- package/dist/breakpoints/breakpoint.js +3 -2
- package/dist/breakpoints/breakpoint.js.map +1 -1
- package/dist/canvas/canvas.utils.js +13 -1
- package/dist/canvas/canvas.utils.js.map +1 -1
- package/dist/composable-studio/build-scoped-data.js +53 -31
- package/dist/composable-studio/build-scoped-data.js.map +1 -1
- package/dist/composable-studio/collect-data-needs.js +22 -4
- package/dist/composable-studio/collect-data-needs.js.map +1 -1
- package/dist/composable-studio/sdk.js +1288 -453
- package/dist/composable-studio/sdk.js.map +1 -1
- package/dist/composable-studio/section-data.js +316 -0
- package/dist/composable-studio/section-data.js.map +1 -0
- package/dist/composable-studio/studio-intelligence.manager.js +5 -2
- package/dist/composable-studio/studio-intelligence.manager.js.map +1 -1
- package/dist/config/config.schema.js +45 -8
- package/dist/config/config.schema.js.map +1 -1
- package/dist/config/default-config.js +10 -3
- package/dist/config/default-config.js.map +1 -1
- package/dist/config/process-user-config.js +37 -1
- package/dist/config/process-user-config.js.map +1 -1
- package/dist/config/stack-sdk-wrapper.js +71 -2
- package/dist/config/stack-sdk-wrapper.js.map +1 -1
- package/dist/context-menu/context-menu.js +5 -2
- package/dist/context-menu/context-menu.js.map +1 -1
- package/dist/design/handle-active-style-change.js +3 -2
- package/dist/design/handle-active-style-change.js.map +1 -1
- package/dist/dnd/dnd-event.js +2 -1
- package/dist/dnd/dnd-event.js.map +1 -1
- package/dist/dnd/dnd-manager.js +3 -1
- package/dist/dnd/dnd-manager.js.map +1 -1
- package/dist/editor.d.ts +250 -0
- package/dist/editor.js +11 -0
- package/dist/editor.js.map +1 -0
- package/dist/get-active-node-screenshot/get-node-screenshot-event.js +2 -1
- package/dist/get-active-node-screenshot/get-node-screenshot-event.js.map +1 -1
- package/dist/hidden-element-notification/hidden-element-notification-event.js +2 -1
- package/dist/hidden-element-notification/hidden-element-notification-event.js.map +1 -1
- package/dist/highlight-node/highlight-node-manager.js +225 -15
- package/dist/highlight-node/highlight-node-manager.js.map +1 -1
- package/dist/highlight-node/highlight-node.js +42 -6
- package/dist/highlight-node/highlight-node.js.map +1 -1
- package/dist/highlight-spacing/highlight-spacing-events.js +2 -1
- package/dist/highlight-spacing/highlight-spacing-events.js.map +1 -1
- package/dist/index.d.ts +1334 -467
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/dist/url-change/url-change.js +4 -3
- package/dist/url-change/url-change.js.map +1 -1
- package/dist/url-metadata/build-template-query.js +27 -6
- package/dist/url-metadata/build-template-query.js.map +1 -1
- package/dist/utils/canvas.js +2 -1
- package/dist/utils/canvas.js.map +1 -1
- package/dist/utils/check-bindings.js +233 -0
- package/dist/utils/check-bindings.js.map +1 -0
- package/dist/utils/classify-response-error.js +288 -0
- package/dist/utils/classify-response-error.js.map +1 -0
- package/dist/utils/composable-studio-error.js +36 -20
- package/dist/utils/composable-studio-error.js.map +1 -1
- package/dist/utils/composition-not-found.js +52 -0
- package/dist/utils/composition-not-found.js.map +1 -0
- package/dist/utils/conditionBlock.js +80 -3
- package/dist/utils/conditionBlock.js.map +1 -1
- package/dist/utils/constants.js +21 -2
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/degraded-finding.js +166 -0
- package/dist/utils/degraded-finding.js.map +1 -0
- package/dist/utils/editor-mode.js +1 -1
- package/dist/utils/http-error.constants.js +12 -46
- package/dist/utils/http-error.constants.js.map +1 -1
- package/dist/utils/include-path-rules.js +141 -0
- package/dist/utils/include-path-rules.js.map +1 -0
- package/dist/utils/is-composition-being-edited.js +1 -1
- package/dist/utils/is-inside-iframe.js +1 -1
- package/dist/utils/is-inside-visual-builder-frame.js +1 -1
- package/dist/utils/parse-ui.js +60 -0
- package/dist/utils/parse-ui.js.map +1 -0
- package/dist/utils/query-param.js +1 -1
- package/dist/utils/query-param.js.map +1 -1
- package/dist/utils/query-url-budget.js +79 -0
- package/dist/utils/query-url-budget.js.map +1 -0
- package/dist/utils/reference-stub.js +75 -0
- package/dist/utils/reference-stub.js.map +1 -0
- package/dist/utils/reference_fetcher.js +59 -4
- package/dist/utils/reference_fetcher.js.map +1 -1
- package/dist/utils/require-stack.js +141 -0
- package/dist/utils/require-stack.js.map +1 -0
- package/dist/utils/served-by.js +33 -0
- package/dist/utils/served-by.js.map +1 -0
- package/dist/utils/spec-analyzer.js +2 -2
- package/dist/utils/spec-analyzer.js.map +1 -1
- package/dist/utils/studio-error-codes.js +253 -0
- package/dist/utils/studio-error-codes.js.map +1 -0
- package/dist/utils/studio-error.js +122 -0
- package/dist/utils/studio-error.js.map +1 -0
- package/dist/utils/studio-messaging.js +25 -0
- package/dist/utils/studio-messaging.js.map +1 -0
- package/dist/visual-builder/composition-save-event.js +2 -1
- package/dist/visual-builder/composition-save-event.js.map +1 -1
- package/package.json +19 -7
- package/LICENSE +0 -21
- package/dist/utils/error-messages.default.js +0 -141
- package/dist/utils/error-messages.default.js.map +0 -1
- package/dist/utils/error-messages.js +0 -47
- package/dist/utils/error-messages.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import { studioSdk } from './composable-studio/initializer-sdk.js';
|
|
2
2
|
export { ELEMENT_TO_NODE, NODE_TO_ELEMENT, NODE_TO_PARENT, NODE_TO_PATH_NODE } from './composable-studio/weak-maps.js';
|
|
3
|
-
export { buildSectionScopedData, getSeoMetadataPure } from './composable-studio/sdk.js';
|
|
3
|
+
export { buildSectionScopedData, derivePlacementIncludePaths, getSeoMetadataPure } from './composable-studio/sdk.js';
|
|
4
4
|
export { getCompositionMetadata, renderMetadataToHtml } from './composable-studio/composition-metadata.js';
|
|
5
|
+
export { TEMPLATE_BINDING_TYPE, TEMPLATE_FETCH_ROOT_KEY, fetchRootFromBinding, flattenPath, getRootBindingPath, getRootScopePath, isDataRootCleared, isPageAbsoluteField, isTemplateFetchRoot, isTemplateRootBinding, nestPath, parseEntryFetchRootKey, resolveInstanceRootBinding, resolveLegacySelectedField, resolveLegacySelectedFieldWithProvenance, resolveMatchedSchema, sectionDataEqual, splitFieldPath, synthesizeTemplateRootBinding, templateFetchRoot } from './composable-studio/section-data.js';
|
|
5
6
|
export { parseStringValue, preProcessStaticValues } from './composable-studio/data/pre-process-static-values.js';
|
|
6
7
|
export { COMPOSITION_PLACEMENT_OPTIONS } from './composable-studio/composition-placement.types.js';
|
|
7
8
|
export { addContextMenuEventListeners } from './context-menu/context-menu.js';
|
|
8
|
-
export { EDGE_PADDING, MAX_SCROLL_SPEED, SCROLL_INTERVAL, dndManager } from './dnd/dnd-manager.js';
|
|
9
|
-
export { dndEventListener } from './dnd/dnd-event.js';
|
|
10
|
-
export { calculateDynamicSpeed, getScrollableParent } from './dnd/scroll-utils.js';
|
|
11
|
-
export { addHighlightNodeEventListeners, handleOnScroll, handleResize, isModKey } from './highlight-node/highlight-node.js';
|
|
12
|
-
export { highlightNodeManager } from './highlight-node/highlight-node-manager.js';
|
|
13
|
-
export { TARGET_NODE } from '@contentstack/studio-message-types/latest';
|
|
14
9
|
export { addUrlChangeListeners } from './url-change/url-change.js';
|
|
15
|
-
export { addHighlightSpacingEventListeners } from './highlight-spacing/highlight-spacing-events.js';
|
|
16
10
|
export { getDefaultConfig } from './config/default-config.js';
|
|
17
11
|
export { addBreakpointEventListeners } from './breakpoints/breakpoint.js';
|
|
18
12
|
export { DEFAULT_BREAKPOINTS } from './breakpoints/breakpoint.constant.js';
|
|
19
13
|
export { BreakpointManager } from './breakpoints/BreakpointManager.js';
|
|
20
14
|
export { RendererMode } from './canvas/canvas.type.js';
|
|
21
|
-
export { findNearestBuilderNode, findNearestSlotNode, getComposableElement, getComputedStyles, getHitboxDetails, getHitboxDirection, hasSlotDropzone, serializeEvent, toggleNodeVisible } from './canvas/canvas.utils.js';
|
|
15
|
+
export { findNearestBuilderNode, findNearestSlotNode, getComposableElement, getComposableElements, getComputedStyles, getHitboxDetails, getHitboxDirection, hasSlotDropzone, serializeEvent, toggleNodeVisible } from './canvas/canvas.utils.js';
|
|
22
16
|
export { COMPOSABLE_DATA_ATTRIBUTES, INCLUDE_DEPTH_COUNT, SCHEMA_VERSION, SDK_VERSION, isBrowser } from './utils/constants.js';
|
|
23
17
|
export { applyOperation, findPath, findPathForElement } from './utils/editor-utils.js';
|
|
24
18
|
export { isCompositionBeingEdited } from './utils/is-composition-being-edited.js';
|
|
@@ -27,10 +21,14 @@ export { SECTION_COMPOSITIONS_KEY, TEMPLATE_FULL_ENTRY_KEY, batchFetchEntries, e
|
|
|
27
21
|
export { isInsideVisualBuilderFrame } from './utils/is-inside-visual-builder-frame.js';
|
|
28
22
|
export { isInsideIframe } from './utils/is-inside-iframe.js';
|
|
29
23
|
export { STUDIO_CANVAS_QUERY_PARAM, STUDIO_MODE_HTML_CLASS, detectStudioMode, isStudioCanvas, isStudioEditorMode, markStudioMode } from './utils/editor-mode.js';
|
|
30
|
-
export { ComposableStudioError
|
|
31
|
-
export {
|
|
24
|
+
export { ComposableStudioError } from './utils/composable-studio-error.js';
|
|
25
|
+
export { CompositionNotFoundError, isCompositionNotFound } from './utils/composition-not-found.js';
|
|
26
|
+
export { buildStudioErrorContext, createStudioError, isSetupFault } from './utils/studio-error.js';
|
|
27
|
+
export { StudioErrorClass, StudioErrorCode } from './utils/studio-error-codes.js';
|
|
28
|
+
export { evaluateCondition, resolveConditionScope } from './utils/conditionBlock.js';
|
|
32
29
|
export { RendererModeUtil, clientRendererModeUtil, serializeComputedStyles } from './utils/canvas.js';
|
|
33
30
|
export { analyzeMultipleSpecs, analyzeUsedComponents, getComponentUsageStats, specUsesComponent } from './utils/spec-analyzer.js';
|
|
31
|
+
export { sendStudioEvent } from './utils/studio-messaging.js';
|
|
34
32
|
export { loadGoogleFont } from './design/fonts/index.js';
|
|
35
33
|
export { GOOGLE_FONT_API } from './design/fonts/fonts.constant.js';
|
|
36
34
|
export { createClassNameUid } from './design/create-class-name-uid.js';
|
|
@@ -38,9 +36,6 @@ export { updateStyleOnStyleNodeChange } from './design/handle-active-style-chang
|
|
|
38
36
|
export { composableStudioEventEmitter } from './emitted-events/event-emitter.js';
|
|
39
37
|
export { COMPOSABLE_STUDIO_EMITTED_EVENTS } from './emitted-events/events.constant.js';
|
|
40
38
|
export { getEmbeddedAssetRenderer, getEmbeddedEntryRenderer, getJSONRTE, registerEmbeddedEntryRenderer, registerJSONRTE, registerRTERenderer } from './json-rte-registry/index.js';
|
|
41
|
-
export { compositionSaveEventListener } from './visual-builder/composition-save-event.js';
|
|
42
|
-
export { closeHiddenElementNotification, hiddenElementNotificationEventEmitter, openHiddenElementNotification } from './hidden-element-notification/hidden-element-notification-event.js';
|
|
43
|
-
export { getNodeScreenshotEvent } from './get-active-node-screenshot/get-node-screenshot-event.js';
|
|
44
39
|
export { ExpressionResolver } from './query/expression-resolver.js';
|
|
45
40
|
export { QueryExecutor } from './query/query-executor.js';
|
|
46
41
|
export { buildTemplateQuery, buildUrlMetadataQueryObject, resolveByUrlSource } from './url-metadata/build-template-query.js';
|
|
@@ -49,9 +44,14 @@ export { rankUrlMatches } from './url-metadata/rank-url-matches.js';
|
|
|
49
44
|
export { shouldUseUrlMetadataPath } from './url-metadata/shouldUseUrlMetadataPath.js';
|
|
50
45
|
export { COMPOSITION_PREVIEW_URL_SOURCES, COMPOSITION_PREVIEW_URL_SOURCES_VALUES, DEFAULT_COMPOSITION_PREVIEW_URL_SOURCE, URL_PATTERN_DATE_VARIABLES, URL_PATTERN_METADATA_FIELDS, URL_PATTERN_METADATA_FIELDS_VALUES, URL_PATTERN_VARIABLE_TYPES } from './url-metadata/types.js';
|
|
51
46
|
export { compileUrlPattern, computePatternSpecificity, matchCompositionUrl, matchUrlPattern } from './url-metadata/url-pattern-matcher.js';
|
|
47
|
+
export { TARGET_NODE } from '@contentstack/studio-message-types/latest';
|
|
52
48
|
export { IS_BROWSER } from '@contentstack/studio-messenger';
|
|
53
49
|
export { createEmbeddedEntryConversion, defaultAssetRender, extractHtmlRteRefs, extractJsonRteRefs, fetchEmbeddedEntries } from './json-rte-registry/embedded-entry-conversion.js';
|
|
54
50
|
|
|
51
|
+
// Editor-only listeners (dnd, highlight, hidden-element, screenshot,
|
|
52
|
+
// composition-save) live in `./editor`. They hold a static import of the
|
|
53
|
+
// postMessage bridge, which every consumer of this barrel would otherwise
|
|
54
|
+
// inherit. See src/editor.ts.
|
|
55
55
|
// STUDIO SDK
|
|
56
56
|
|
|
57
57
|
export { studioSdk as default, studioSdk };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;;;;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { IS_BROWSER,
|
|
1
|
+
import { IS_BROWSER, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
|
|
2
|
+
import { sendStudioEvent } from '../utils/studio-messaging.js';
|
|
2
3
|
|
|
3
4
|
function sendUrlToParent() {
|
|
4
5
|
if (!IS_BROWSER)
|
|
5
6
|
return;
|
|
6
7
|
const url = window.location.href;
|
|
7
|
-
|
|
8
|
+
sendStudioEvent(POST_MESSAGE_EVENTS.URL_CHANGE, { url });
|
|
8
9
|
}
|
|
9
10
|
function setupNavigationApi() {
|
|
10
11
|
if (!IS_BROWSER)
|
|
@@ -14,7 +15,7 @@ function setupNavigationApi() {
|
|
|
14
15
|
return null;
|
|
15
16
|
const handler = (event) => {
|
|
16
17
|
const url = event.destination.url;
|
|
17
|
-
|
|
18
|
+
sendStudioEvent(POST_MESSAGE_EVENTS.URL_CHANGE, { url });
|
|
18
19
|
};
|
|
19
20
|
nav.addEventListener("navigate", handler);
|
|
20
21
|
return () => nav.removeEventListener("navigate", handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-change.js","sources":["../../src/url-change/url-change.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"url-change.js","sources":["../../src/url-change/url-change.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAkBA,SAAS,eAAe,GAAA;AACtB,IAAA,IAAI,CAAC,UAAU;QAAE;AACjB,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI;IAChC,eAAe,CAAC,mBAAmB,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC;AAC1D;AAEA,SAAS,kBAAkB,GAAA;AACzB,IAAA,IAAI,CAAC,UAAU;AAAE,QAAA,OAAO,IAAI;AAC5B,IAAA,MAAM,GAAG,GAAI,MAA6C,CAAC,UAE9C;AACb,IAAA,IAAI,CAAC,GAAG;AAAE,QAAA,OAAO,IAAI;AACrB,IAAA,MAAM,OAAO,GAAG,CAAC,KAAwB,KAAI;AAC3C,QAAA,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG;QACjC,eAAe,CAAC,mBAAmB,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC;AAC1D,IAAA,CAAC;AACD,IAAA,GAAG,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC;IACzC,OAAO,MAAM,GAAG,CAAC,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC;AAC3D;AAEA,SAAS,4BAA4B,GAAA;AACnC,IAAA,IAAI,CAAC,UAAU;AAAE,QAAA,OAAO,MAAK,EAAE,CAAC;AAEhC,IAAA,MAAM,eAAe,GAAG,MAAM,eAAe,EAAE;IAE/C,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;IACrD,MAAM,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;AAE3D,IAAA,OAAO,CAAC,SAAS,GAAG,UAAU,GAAG,IAAI,EAAA;AACnC,QAAA,aAAa,CAAC,GAAG,IAAI,CAAC;AACtB,QAAA,eAAe,EAAE;AACnB,IAAA,CAAC;AACD,IAAA,OAAO,CAAC,YAAY,GAAG,UAAU,GAAG,IAAI,EAAA;AACtC,QAAA,gBAAgB,CAAC,GAAG,IAAI,CAAC;AACzB,QAAA,eAAe,EAAE;AACnB,IAAA,CAAC;AAED,IAAA,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,eAAe,CAAC;AAEpD,IAAA,OAAO,MAAK;AACV,QAAA,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,eAAe,CAAC;AACvD,QAAA,OAAO,CAAC,SAAS,GAAG,aAAa;AACjC,QAAA,OAAO,CAAC,YAAY,GAAG,gBAAgB;AACzC,IAAA,CAAC;AACH;AAEA;;;;AAIG;SACa,qBAAqB,GAAA;AAGnC,IAAA,IAAI,CAAC,UAAU;AAAE,QAAA,OAAO,SAAS;AAEjC,IAAA,eAAe,EAAE;AAEjB,IAAA,MAAM,mBAAmB,GAAG,kBAAkB,EAAE;IAChD,IAAI,mBAAmB,EAAE;QACvB,OAAO;AACL,YAAA,oBAAoB,EAAE,mBAAmB;SAC1C;IACH;AAEA,IAAA,MAAM,cAAc,GAAG,4BAA4B,EAAE;IACrD,OAAO;AACL,QAAA,oBAAoB,EAAE,cAAc;KACrC;AACH;;;;"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { COMPOSITION_PREVIEW_URL_SOURCES } from './types.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Non-empty predicate for scalar entry fields: not the empty string, not null.
|
|
5
|
+
*
|
|
6
|
+
* `null` is expressed as a scalar `$ne` rather than as an element of `$nin`.
|
|
7
|
+
* The preview service rejects a `null` inside an `$in`/`$nin` array outright —
|
|
8
|
+
* HTTP 400, `error_code` 141, `{"query":["is not valid."]}` — while the CMA
|
|
9
|
+
* accepts it. The array form therefore failed every preview-transport read of
|
|
10
|
+
* this query and fell back to the CMA, spending a whole extra round trip on the
|
|
11
|
+
* path that gates the canvas iframe. Both services accept the scalar form and
|
|
12
|
+
* select the same entries.
|
|
13
|
+
*/
|
|
4
14
|
const NON_EMPTY = {
|
|
5
|
-
$nin: [""
|
|
15
|
+
$nin: [""],
|
|
16
|
+
$ne: null,
|
|
6
17
|
};
|
|
7
18
|
/** Existence predicate for taxonomy variables (entry has at least one term). */
|
|
8
19
|
const TAXONOMY_EXISTS = { $exists: true };
|
|
@@ -15,7 +26,7 @@ const TAXONOMY_EXISTS = { $exists: true };
|
|
|
15
26
|
* stringifies it and passes it to `api.cma.entry.getAll` via the `query` param.
|
|
16
27
|
*
|
|
17
28
|
* In `existence` mode for `legacy_url` and `content_type_url_pattern` the
|
|
18
|
-
* object is `{ url: { $nin: ["", null
|
|
29
|
+
* object is `{ url: { $nin: [""], $ne: null } }` regardless of `extractedVariables`.
|
|
19
30
|
*/
|
|
20
31
|
function buildUrlMetadataQueryObject(context, mode = "match") {
|
|
21
32
|
const { url_source, compositionQuery, extractedVariables } = context;
|
|
@@ -75,7 +86,7 @@ function buildReferencePredicate(ref, mode) {
|
|
|
75
86
|
* pass the per-field object unchanged.
|
|
76
87
|
*/
|
|
77
88
|
function buildTemplateQuery(stackSdk, context, queryOptions, mode = "match") {
|
|
78
|
-
const { parsedUrlQueries, connectedContentType, extractedVariables, url_source, } = context;
|
|
89
|
+
const { compositionQuery, parsedUrlQueries, connectedContentType, extractedVariables, url_source, } = context;
|
|
79
90
|
const queryObject = buildUrlMetadataQueryObject(context, mode);
|
|
80
91
|
// Full-path `$or` branch for `{{entry.url}}` (entry.url-only for now). The
|
|
81
92
|
// `url` field holds the full path, so we match it against the whole request
|
|
@@ -85,12 +96,22 @@ function buildTemplateQuery(stackSdk, context, queryOptions, mode = "match") {
|
|
|
85
96
|
url_source !== COMPOSITION_PREVIEW_URL_SOURCES.LEGACY_URL;
|
|
86
97
|
const hasEntryUrl = typeof extractedVariables.fields.url === "string" ||
|
|
87
98
|
typeof extractedVariables.fields.url === "number";
|
|
99
|
+
// A literal pattern extracts no variables, so the decomposition is `{}` —
|
|
100
|
+
// which with `.limit(1)` means "any one entry of this content type", not
|
|
101
|
+
// "no filter". Match the request path against `url` instead, as
|
|
102
|
+
// content_type_url_pattern and the legacy path both do. Existence mode is
|
|
103
|
+
// exempt: it deliberately wants any entry fitting the pattern.
|
|
104
|
+
const literalUrl = extractedVariables.requestPath ?? compositionQuery.url;
|
|
105
|
+
const isVariableless = Object.keys(queryObject).length === 0;
|
|
106
|
+
const decomposedQuery = mode === "match" && isPatternSource && isVariableless && literalUrl
|
|
107
|
+
? { url: literalUrl }
|
|
108
|
+
: queryObject;
|
|
88
109
|
const finalQuery = mode === "match" &&
|
|
89
110
|
isPatternSource &&
|
|
90
111
|
hasEntryUrl &&
|
|
91
112
|
extractedVariables.requestPath
|
|
92
|
-
? { $or: [
|
|
93
|
-
:
|
|
113
|
+
? { $or: [decomposedQuery, { url: extractedVariables.requestPath }] }
|
|
114
|
+
: decomposedQuery;
|
|
94
115
|
return stackSdk
|
|
95
116
|
.ctQuery(connectedContentType, {
|
|
96
117
|
references: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-template-query.js","sources":["../../src/url-metadata/build-template-query.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAoBA;
|
|
1
|
+
{"version":3,"file":"build-template-query.js","sources":["../../src/url-metadata/build-template-query.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAoBA;;;;;;;;;;AAUG;AACH,MAAM,SAAS,GAA+C;IAC5D,IAAI,EAAE,CAAC,EAAE,CAAC;AACV,IAAA,GAAG,EAAE,IAAI;CACV;AAED;AACA,MAAM,eAAe,GAAsB,EAAE,OAAO,EAAE,IAAI,EAAE;AAE5D;;;;;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+
import { IS_BROWSER, COMPOSABLE_STUDIO_QUERY_PARAM } from '@contentstack/studio-messenger/constants';
|
|
2
2
|
import { RendererMode } from '../canvas/canvas.type.js';
|
|
3
|
+
import '@contentstack/studio-messenger';
|
|
3
4
|
import { camelCase } from 'lodash-es';
|
|
4
5
|
|
|
5
6
|
class RendererModeUtil {
|
package/dist/utils/canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","sources":["../../src/utils/canvas.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"canvas.js","sources":["../../src/utils/canvas.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;MAOa,gBAAgB,CAAA;IACnB,YAAY,GAA2B,IAAI;IAC3C,qBAAqB,GAAY,KAAK;AAC9C,IAAA,WAAA,CAAY,YAA8B,EAAA;AACxC,QAAA,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE;AAChC,YAAA,IAAI,CAAC,qBAAqB,GAAG,IAAI;YACjC;QACF;AACA,QAAA,IAAI,CAAC,YAAY;YACf,YAAY,IAAI,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC/D;AAEA;;;;AAIG;IACH,mBAAmB,GAAA;AACjB,QAAA,IAAI,IAAI,CAAC,qBAAqB,EAAE;AAC9B,YAAA,OAAO,KAAK;QACd;QACA,OAAO,IAAI,CAAC,YAAa,CAAC,GAAG,CAAC,6BAA6B,CAAC,OAAO,CAAC;IACtE;AAEA;;;;AAIG;IACH,cAAc,GAAA;AACZ,QAAA,IAAI,IAAI,CAAC,qBAAqB,EAAE;AAC9B,YAAA,OAAO,KAAK;QACd;QACA,IAAI,CAAC,UAAU,EAAE;AACf,YAAA,OAAO,KAAK;QACd;AACA,QAAA,OAAO,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG;IACnC;AAEA;;;;;;AAMG;IACH,0BAA0B,GAAA;AACxB,QAAA,IAAI,IAA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AQ,GAAG,SAAS,CAAC,QAAQ,CAAC;AAC9B,YAAA,MAAM,KAAK,GAAG,aAAa,CAAC,QAAqC,CAAC;YAClE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;gBACzC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE;YAC/C;QACF;QAAE,OAAO,KAAK,EAAE;;YAEd,OAAO,CAAC,IAAI,CAAC,CAAA,kCAAA,EAAqC,QAAQ,CAAA,CAAE,EAAE,KAAK,CAAC;QACtE;IACF;AACA,IAAA,OAAO,gBAAgB;AACzB;;;;"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { get } from 'lodash-es';
|
|
2
|
+
import { DATA_SOURCES, getBindingString, convertBindingPath, DATA_SOURCES_PREFIX } from '@contentstack/studio-registry';
|
|
3
|
+
import { DegradedCode } from './degraded-finding.js';
|
|
4
|
+
import { getBindingStringForCS } from './sdk.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Finds the bindings that will render blank, before anybody has to ask why.
|
|
8
|
+
*
|
|
9
|
+
* This is the most common silent failure in the product: the page loads, the
|
|
10
|
+
* composition renders, one element is empty, and nothing anywhere says so. The
|
|
11
|
+
* author reports it as "Studio is broken" because from where they sit that is
|
|
12
|
+
* exactly what it looks like.
|
|
13
|
+
*
|
|
14
|
+
* **The check resolves a binding the same way the renderer does** — the same
|
|
15
|
+
* path builder, the same `get`, the same page-namespace fallback — rather than
|
|
16
|
+
* re-deriving the lookup here. Anything else would produce a second opinion, and
|
|
17
|
+
* a second opinion that disagrees with the screen is worse than silence: it
|
|
18
|
+
* sends somebody to fix a binding that works.
|
|
19
|
+
*
|
|
20
|
+
* Everything it cannot resolve the renderer's way is skipped rather than
|
|
21
|
+
* guessed. A binding inside a repeater is read against one iteration's item, and
|
|
22
|
+
* a binding inside a section is read against that section's own scoped data, so
|
|
23
|
+
* neither can be answered from the page's data and neither is reported. That
|
|
24
|
+
* makes this deliberately incomplete — and incomplete is the correct trade,
|
|
25
|
+
* because every case it does report is one the reader can act on.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Prop types that hold exactly one value.
|
|
29
|
+
*
|
|
30
|
+
* `object`, `array` and `json_rte` are left out because a container is what they
|
|
31
|
+
* are for. `any` is left out because it accepts whatever arrives, so there is
|
|
32
|
+
* nothing to mismatch against. `action` holds a function name and is resolved
|
|
33
|
+
* through a different path entirely.
|
|
34
|
+
*/
|
|
35
|
+
const SINGLE_VALUE_PROP_TYPES = new Set([
|
|
36
|
+
"string",
|
|
37
|
+
"boolean",
|
|
38
|
+
"number",
|
|
39
|
+
"datestring",
|
|
40
|
+
"href",
|
|
41
|
+
"imageurl",
|
|
42
|
+
"choice",
|
|
43
|
+
"plaintext",
|
|
44
|
+
]);
|
|
45
|
+
/** The binding kinds whose paths are absolute against the page's own data. */
|
|
46
|
+
const PAGE_ROOTED_BINDINGS = new Set([
|
|
47
|
+
DATA_SOURCES.CONTENTSTACK,
|
|
48
|
+
DATA_SOURCES.TEMPLATE,
|
|
49
|
+
]);
|
|
50
|
+
/**
|
|
51
|
+
* Subfields an asset carries, used to tell an asset binding from any other
|
|
52
|
+
* dotted path.
|
|
53
|
+
*
|
|
54
|
+
* Matching on the subfield rather than on the field's own name is what keeps
|
|
55
|
+
* this working on every stack: an asset field can be called anything, but what
|
|
56
|
+
* a binding reads out of one is fixed by Contentstack.
|
|
57
|
+
*/
|
|
58
|
+
const ASSET_SUBFIELDS = new Set([
|
|
59
|
+
"url",
|
|
60
|
+
"filename",
|
|
61
|
+
"title",
|
|
62
|
+
"content_type",
|
|
63
|
+
"file_size",
|
|
64
|
+
"dimension",
|
|
65
|
+
]);
|
|
66
|
+
/**
|
|
67
|
+
* Whether a null value here is better explained by a known Preview API defect
|
|
68
|
+
* than by the author's binding.
|
|
69
|
+
*
|
|
70
|
+
* The defect: asked for an asset subfield as a dotted projection —
|
|
71
|
+
* `only[BASE][]=image.url` — on a request that also projects a bare field, the
|
|
72
|
+
* preview service returns null where the delivery CDN returns the asset. It is
|
|
73
|
+
* verified, it is ours, and it is invisible: the author sees a missing image and
|
|
74
|
+
* the only available reading is that they bound the wrong field.
|
|
75
|
+
*
|
|
76
|
+
* **It ranks rather than asserts, and the reason is precise.** The defect needs
|
|
77
|
+
* the other projected field to be a modular block, and telling a modular-blocks
|
|
78
|
+
* field from any other bare field needs the content type's schema, which is not
|
|
79
|
+
* fetched. So the conditions here are the ones that are provable — preview, a
|
|
80
|
+
* dotted asset projection, a bare field beside it — and the remaining
|
|
81
|
+
* uncertainty is carried in the causes instead of being papered over.
|
|
82
|
+
*/
|
|
83
|
+
function looksLikeThePreviewAssetDefect(path, { servedBy, projection }) {
|
|
84
|
+
if (servedBy !== "preview")
|
|
85
|
+
return false;
|
|
86
|
+
const segments = path.split(".");
|
|
87
|
+
if (segments.length < 2)
|
|
88
|
+
return false;
|
|
89
|
+
if (!ASSET_SUBFIELDS.has(segments[segments.length - 1]))
|
|
90
|
+
return false;
|
|
91
|
+
const projectedAsDottedPath = projection.some(([parent, field]) => parent === "BASE" && field === path);
|
|
92
|
+
if (!projectedAsDottedPath)
|
|
93
|
+
return false;
|
|
94
|
+
return projection.some(([parent, field]) => parent === "BASE" && !field.includes("."));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Which entry a binding reads from, when the binding names one.
|
|
98
|
+
*
|
|
99
|
+
* A template binding does not: it reads whichever entry the composition is
|
|
100
|
+
* connected to on this request, and that is not knowable from the binding. Both
|
|
101
|
+
* fields are therefore absent rather than filled with a stand-in phrase — a
|
|
102
|
+
* stand-in reads as a value in the structured findings, and drops straight into
|
|
103
|
+
* the middle of a sentence as "on entry the connected entry of "the connected
|
|
104
|
+
* content type"".
|
|
105
|
+
*/
|
|
106
|
+
function subjectOf(binding) {
|
|
107
|
+
const value = (binding.value ?? {});
|
|
108
|
+
return { entryUid: value.uid, contentTypeUid: value._content_type_uid };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Resolves a binding exactly as the renderer will.
|
|
112
|
+
*
|
|
113
|
+
* The page-namespace retry mirrors the renderer's own: a binding authored on a
|
|
114
|
+
* slot child against a page-level field produces a section-local path that
|
|
115
|
+
* resolves to nothing, and the renderer looks again under `dataSources.page`
|
|
116
|
+
* before giving up. Skipping that retry here would report every one of those
|
|
117
|
+
* bindings as broken while the screen shows them working.
|
|
118
|
+
*/
|
|
119
|
+
function resolveAsRendererWould(binding, data) {
|
|
120
|
+
const dataPath = getBindingString(binding);
|
|
121
|
+
if (!dataPath)
|
|
122
|
+
return undefined;
|
|
123
|
+
const resolved = get(data, convertBindingPath(binding.type, dataPath));
|
|
124
|
+
if (resolved !== undefined && resolved !== null)
|
|
125
|
+
return resolved;
|
|
126
|
+
if (typeof dataPath === "string" &&
|
|
127
|
+
dataPath.startsWith(`${DATA_SOURCES_PREFIX}.`) &&
|
|
128
|
+
!dataPath.startsWith(`${DATA_SOURCES_PREFIX}.page.`) &&
|
|
129
|
+
get(data, `${DATA_SOURCES_PREFIX}.page`)) {
|
|
130
|
+
return get(data, dataPath.replace(new RegExp(`^${DATA_SOURCES_PREFIX}\\.`), `${DATA_SOURCES_PREFIX}.page.`));
|
|
131
|
+
}
|
|
132
|
+
return resolved;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Whether the document this binding reads from arrived at all.
|
|
136
|
+
*
|
|
137
|
+
* A binding against an entry that was never fetched is not a broken binding —
|
|
138
|
+
* the entry not arriving is its own finding, already reported with the uid that
|
|
139
|
+
* went missing. Reporting it twice under two names would have a reader chasing
|
|
140
|
+
* the binding instead of the entry.
|
|
141
|
+
*/
|
|
142
|
+
function documentIsPresent(binding, dataSources) {
|
|
143
|
+
if (binding.type === DATA_SOURCES.TEMPLATE) {
|
|
144
|
+
return dataSources?.[DATA_SOURCES.TEMPLATE] != null;
|
|
145
|
+
}
|
|
146
|
+
const { entryUid, contentTypeUid } = subjectOf(binding);
|
|
147
|
+
if (!entryUid || !contentTypeUid)
|
|
148
|
+
return false;
|
|
149
|
+
return (dataSources?.[DATA_SOURCES.CONTENTSTACK]?.[`${contentTypeUid}:${entryUid}`] != null);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Every binding on the page that resolves to nothing, or to the wrong kind of
|
|
153
|
+
* thing.
|
|
154
|
+
*
|
|
155
|
+
* Deduplicated on the binding rather than on the element, because one field
|
|
156
|
+
* read by six elements is one thing to go and fix.
|
|
157
|
+
*/
|
|
158
|
+
function findBindingDefects(spec, dataSources, request = { servedBy: "unknown", projection: [] }) {
|
|
159
|
+
const defects = new Map();
|
|
160
|
+
const data = { dataSources };
|
|
161
|
+
function inspectProp(prop) {
|
|
162
|
+
const binding = prop?.binding;
|
|
163
|
+
if (!binding?.type || !PAGE_ROOTED_BINDINGS.has(binding.type))
|
|
164
|
+
return;
|
|
165
|
+
if (!documentIsPresent(binding, dataSources))
|
|
166
|
+
return;
|
|
167
|
+
// A binding with no path reads the whole document. There is no field to be
|
|
168
|
+
// missing, so there is nothing here to report.
|
|
169
|
+
const dataPath = getBindingString(binding);
|
|
170
|
+
if (!dataPath || typeof dataPath !== "string")
|
|
171
|
+
return;
|
|
172
|
+
const { entryUid, contentTypeUid } = subjectOf(binding);
|
|
173
|
+
// The path as an author would recognise it. Read off the binding rather
|
|
174
|
+
// than sliced off the front of the lookup string, because the two kinds do
|
|
175
|
+
// not have the same number of segments in front of the field — a
|
|
176
|
+
// contentstack binding carries an entry key there and a template binding
|
|
177
|
+
// does not, so a fixed slice puts `product:prodA` into the sentence.
|
|
178
|
+
const path = getBindingStringForCS(binding);
|
|
179
|
+
const resolved = resolveAsRendererWould(binding, data);
|
|
180
|
+
if (resolved === undefined || resolved === null) {
|
|
181
|
+
// Our own defect gets named ahead of the author's binding when the
|
|
182
|
+
// conditions for it hold. Both produce the identical absence, and only
|
|
183
|
+
// one of them is worth an author's afternoon: told the field is missing,
|
|
184
|
+
// they will re-point a binding that is already correct and watch it stay
|
|
185
|
+
// blank, because the fix is not theirs to make.
|
|
186
|
+
const code = looksLikeThePreviewAssetDefect(path, request)
|
|
187
|
+
? DegradedCode.PREVIEW_ASSET_PROJECTION_NULL
|
|
188
|
+
: DegradedCode.BINDING_PATH_MISSING;
|
|
189
|
+
defects.set(`${code}|${dataPath}`, {
|
|
190
|
+
code,
|
|
191
|
+
path,
|
|
192
|
+
entryUid,
|
|
193
|
+
contentTypeUid,
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// Presence-gated: a prop that never declared its type cannot be said to
|
|
198
|
+
// have got the wrong one, so an absent `type` reports nothing rather than
|
|
199
|
+
// guessing.
|
|
200
|
+
if (!prop.type || !SINGLE_VALUE_PROP_TYPES.has(prop.type))
|
|
201
|
+
return;
|
|
202
|
+
if (typeof resolved !== "object")
|
|
203
|
+
return;
|
|
204
|
+
defects.set(`${DegradedCode.BINDING_SHAPE_MISMATCH}|${dataPath}`, {
|
|
205
|
+
code: DegradedCode.BINDING_SHAPE_MISMATCH,
|
|
206
|
+
path,
|
|
207
|
+
entryUid,
|
|
208
|
+
contentTypeUid,
|
|
209
|
+
resolvedTo: Array.isArray(resolved) ? "modular block" : "group",
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function traverse(node) {
|
|
213
|
+
if (!node)
|
|
214
|
+
return;
|
|
215
|
+
// A repeater's item bindings are read against one iteration, and a
|
|
216
|
+
// section's against its own scoped data. Neither can be answered from here,
|
|
217
|
+
// so neither subtree is walked.
|
|
218
|
+
if (node.type === "repeater" || node.type === "section-composition")
|
|
219
|
+
return;
|
|
220
|
+
Object.values(node.props ?? {}).forEach(inspectProp);
|
|
221
|
+
Object.values(node.slots ?? {}).forEach((slotContent) => {
|
|
222
|
+
if (Array.isArray(slotContent))
|
|
223
|
+
slotContent.forEach(traverse);
|
|
224
|
+
else if (slotContent && typeof slotContent === "object")
|
|
225
|
+
traverse(slotContent);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
traverse(spec);
|
|
229
|
+
return [...defects.values()];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { findBindingDefects };
|
|
233
|
+
//# sourceMappingURL=check-bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-bindings.js","sources":["../../src/utils/check-bindings.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;;;AAoBG;AAcH;;;;;;;AAOG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC;IACtC,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,UAAU;IACV,QAAQ;IACR,WAAW;AACZ,CAAA,CAAC;AAEF;AACA,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAS;AAC3C,IAAA,YAAY,CAAC,YAAY;AACzB,IAAA,YAAY,CAAC,QAAQ;AACtB,CAAA,CAAC;AAEF;;;;;;;AAOG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,KAAK;IACL,UAAU;IACV,OAAO;IACP,cAAc;IACd,WAAW;IACX,WAAW;AACZ,CAAA,CAAC;AAuCF;;;;;;;;;;;;;;;;AAgBG;AACH,SAAS,8BAA8B,CACrC,IAAY,EACZ,EAAE,QAAQ,EAAE,UAAU,EAAgB,EAAA;IAEtC,IAAI,QAAQ,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;IAExC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;AAChC,IAAA,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;AAAE,QAAA,OAAO,KAAK;AACrC,IAAA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAAE,QAAA,OAAO,KAAK;IAErE,MAAM,qBAAqB,GAAG,UAAU,CAAC,IAAI,CAC3C,CAAC,CAAC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