@contentstack/studio-client 0.0.2
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 +37 -0
- package/dist/breakpoints/BreakpointManager.js +65 -0
- package/dist/breakpoints/BreakpointManager.js.map +1 -0
- package/dist/breakpoints/breakpoint.constant.js +31 -0
- package/dist/breakpoints/breakpoint.constant.js.map +1 -0
- package/dist/breakpoints/breakpoint.js +41 -0
- package/dist/breakpoints/breakpoint.js.map +1 -0
- package/dist/canvas/canvas.type.js +10 -0
- package/dist/canvas/canvas.type.js.map +1 -0
- package/dist/canvas/canvas.utils.js +127 -0
- package/dist/canvas/canvas.utils.js.map +1 -0
- package/dist/composable-studio/data/pre-process-static-values.js +158 -0
- package/dist/composable-studio/data/pre-process-static-values.js.map +1 -0
- package/dist/composable-studio/initializer-sdk.js +33 -0
- package/dist/composable-studio/initializer-sdk.js.map +1 -0
- package/dist/composable-studio/sdk.js +527 -0
- package/dist/composable-studio/sdk.js.map +1 -0
- package/dist/composable-studio/weak-maps.js +7 -0
- package/dist/composable-studio/weak-maps.js.map +1 -0
- package/dist/config/config.constant.js +4 -0
- package/dist/config/config.constant.js.map +1 -0
- package/dist/config/config.schema.js +40 -0
- package/dist/config/config.schema.js.map +1 -0
- package/dist/config/default-config.js +20 -0
- package/dist/config/default-config.js.map +1 -0
- package/dist/config/process-user-config.js +43 -0
- package/dist/config/process-user-config.js.map +1 -0
- package/dist/config/stack-sdk-wrapper.js +128 -0
- package/dist/config/stack-sdk-wrapper.js.map +1 -0
- package/dist/context-menu/context-menu.js +43 -0
- package/dist/context-menu/context-menu.js.map +1 -0
- package/dist/design/create-class-name-uid.js +13 -0
- package/dist/design/create-class-name-uid.js.map +1 -0
- package/dist/design/fonts/fonts.constant.js +16 -0
- package/dist/design/fonts/fonts.constant.js.map +1 -0
- package/dist/design/fonts/index.js +62 -0
- package/dist/design/fonts/index.js.map +1 -0
- package/dist/design/handle-active-style-change.js +50 -0
- package/dist/design/handle-active-style-change.js.map +1 -0
- package/dist/dnd/dnd-event.js +29 -0
- package/dist/dnd/dnd-event.js.map +1 -0
- package/dist/dnd/dnd-manager.js +144 -0
- package/dist/dnd/dnd-manager.js.map +1 -0
- package/dist/dnd/utils.js +50 -0
- package/dist/dnd/utils.js.map +1 -0
- package/dist/emitted-events/event-emitter.js +7 -0
- package/dist/emitted-events/event-emitter.js.map +1 -0
- package/dist/emitted-events/events.constant.js +7 -0
- package/dist/emitted-events/events.constant.js.map +1 -0
- package/dist/get-active-node-screenshot/get-node-screenshot-event.js +30 -0
- package/dist/get-active-node-screenshot/get-node-screenshot-event.js.map +1 -0
- package/dist/get-composition-from-slug/get-composition-from-slug.js +59 -0
- package/dist/get-composition-from-slug/get-composition-from-slug.js.map +1 -0
- package/dist/hidden-element-notification/hidden-element-notification-event.js +26 -0
- package/dist/hidden-element-notification/hidden-element-notification-event.js.map +1 -0
- package/dist/highlight-node/highlight-node-manager.js +307 -0
- package/dist/highlight-node/highlight-node-manager.js.map +1 -0
- package/dist/highlight-node/highlight-node.js +213 -0
- package/dist/highlight-node/highlight-node.js.map +1 -0
- package/dist/highlight-spacing/highlight-spacing-events.js +31 -0
- package/dist/highlight-spacing/highlight-spacing-events.js.map +1 -0
- package/dist/index.d.ts +719 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/json-rte-registry/index.js +47 -0
- package/dist/json-rte-registry/index.js.map +1 -0
- package/dist/utils/canvas.js +128 -0
- package/dist/utils/canvas.js.map +1 -0
- package/dist/utils/composable-studio-error.js +27 -0
- package/dist/utils/composable-studio-error.js.map +1 -0
- package/dist/utils/condition-block.utils.js +23 -0
- package/dist/utils/condition-block.utils.js.map +1 -0
- package/dist/utils/conditionBlock.js +127 -0
- package/dist/utils/conditionBlock.js.map +1 -0
- package/dist/utils/constants.js +19 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/convertCompositionQueryInputToCompositionQuery.js +19 -0
- package/dist/utils/convertCompositionQueryInputToCompositionQuery.js.map +1 -0
- package/dist/utils/editor-utils.js +86 -0
- package/dist/utils/editor-utils.js.map +1 -0
- package/dist/utils/is-composition-being-edited.js +12 -0
- package/dist/utils/is-composition-being-edited.js.map +1 -0
- package/dist/utils/is-inside-visual-builder-frame.js +12 -0
- package/dist/utils/is-inside-visual-builder-frame.js.map +1 -0
- package/dist/utils/query-param.js +33 -0
- package/dist/utils/query-param.js.map +1 -0
- package/dist/utils/reference_fetcher.js +214 -0
- package/dist/utils/reference_fetcher.js.map +1 -0
- package/dist/utils/sdk.js +66 -0
- package/dist/utils/sdk.js.map +1 -0
- package/dist/visual-builder/composition-save-event.js +13 -0
- package/dist/visual-builder/composition-save-event.js.map +1 -0
- package/package.json +57 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { studioSdk } from './composable-studio/initializer-sdk.js';
|
|
2
|
+
export { sendInitMessage } from './composable-studio/initializer-sdk.js';
|
|
3
|
+
export { ELEMENT_TO_NODE, NODE_TO_ELEMENT, NODE_TO_PARENT, NODE_TO_PATH_NODE } from './composable-studio/weak-maps.js';
|
|
4
|
+
export { parseStringValue, preProcessStaticValues } from './composable-studio/data/pre-process-static-values.js';
|
|
5
|
+
export { addContextMenuEventListeners } from './context-menu/context-menu.js';
|
|
6
|
+
export { EDGE_PADDING, MAX_SCROLL_SPEED, SCROLL_INTERVAL, dndManager } from './dnd/dnd-manager.js';
|
|
7
|
+
export { dndEventListener } from './dnd/dnd-event.js';
|
|
8
|
+
export { calculateDynamicSpeed, getScrollContainer, getScrollContainerRect, getScrollableParent } from './dnd/utils.js';
|
|
9
|
+
export { addHighlightNodeEventListeners, handleOnScroll, handleResize } from './highlight-node/highlight-node.js';
|
|
10
|
+
export { highlightNodeManager } from './highlight-node/highlight-node-manager.js';
|
|
11
|
+
export { TARGET_NODE } from '@contentstack/studio-message-types/latest';
|
|
12
|
+
export { addHighlightSpacingEventListeners } from './highlight-spacing/highlight-spacing-events.js';
|
|
13
|
+
export { getDefaultConfig } from './config/default-config.js';
|
|
14
|
+
export { addBreakpointEventListeners } from './breakpoints/breakpoint.js';
|
|
15
|
+
export { DEFAULT_BREAKPOINTS } from './breakpoints/breakpoint.constant.js';
|
|
16
|
+
export { BreakpointManager } from './breakpoints/BreakpointManager.js';
|
|
17
|
+
export { RendererMode } from './canvas/canvas.type.js';
|
|
18
|
+
export { findNearestBuilderNode, findNearestSlotNode, getComposableElement, getComputedStyles, getHitboxDetails, getHitboxDirection, hasSlotDropzone, serializeEvent, toggleNodeVisible } from './canvas/canvas.utils.js';
|
|
19
|
+
export { COMPOSABLE_DATA_ATTRIBUTES, INCLUDE_DEPTH_COUNT, isBrowser } from './utils/constants.js';
|
|
20
|
+
export { applyOperation, findPath, findPathForElement } from './utils/editor-utils.js';
|
|
21
|
+
export { isCompositionBeingEdited } from './utils/is-composition-being-edited.js';
|
|
22
|
+
export { onlyParmasGenerator, queryParam } from './utils/query-param.js';
|
|
23
|
+
export { batchFetchEntries, entriesFromResponse, getBindingStringForCS, setStaticEntryInDS, setTemplateEntryInDS } from './utils/sdk.js';
|
|
24
|
+
export { isInsideVisualBuilderFrame } from './utils/is-inside-visual-builder-frame.js';
|
|
25
|
+
export { ComposableStudioError, ComposableStudioErrors, FALLBACK_POSSIBLE_ERRORS } from './utils/composable-studio-error.js';
|
|
26
|
+
export { evaluateCondition } from './utils/conditionBlock.js';
|
|
27
|
+
export { RendererModeUtil, clientRendererModeUtil, serializeComputedStyles } from './utils/canvas.js';
|
|
28
|
+
export { loadGoogleFont } from './design/fonts/index.js';
|
|
29
|
+
export { FONTS, FONT_VARIANTS, GOOGLE_FONT_API } from './design/fonts/fonts.constant.js';
|
|
30
|
+
export { createClassNameUid } from './design/create-class-name-uid.js';
|
|
31
|
+
export { updateStyleOnStyleNodeChange } from './design/handle-active-style-change.js';
|
|
32
|
+
export { composableStudioEventEmitter } from './emitted-events/event-emitter.js';
|
|
33
|
+
export { COMPOSABLE_STUDIO_EMITTED_EVENTS } from './emitted-events/events.constant.js';
|
|
34
|
+
export { getJSONRTE, registerJSONRTE } from './json-rte-registry/index.js';
|
|
35
|
+
export { compositionSaveEventListener } from './visual-builder/composition-save-event.js';
|
|
36
|
+
export { closeHiddenElementNotification, hiddenElementNotificationEventEmitter, openHiddenElementNotification } from './hidden-element-notification/hidden-element-notification-event.js';
|
|
37
|
+
export { getNodeScreenshotEvent } from './get-active-node-screenshot/get-node-screenshot-event.js';
|
|
38
|
+
export { IS_BROWSER } from '@contentstack/studio-messenger';
|
|
39
|
+
|
|
40
|
+
// STUDIO SDK
|
|
41
|
+
|
|
42
|
+
export { studioSdk as default, studioSdk };
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { JSONRTERegistry } from '@contentstack/studio-registry';
|
|
2
|
+
|
|
3
|
+
const jsonRTERegistryInstance = /* #__PURE__ */ new JSONRTERegistry();
|
|
4
|
+
/**
|
|
5
|
+
* Registers a config for JSON RTE
|
|
6
|
+
* @param config - The config to register. This should have the following format:
|
|
7
|
+
* {
|
|
8
|
+
* customElementTypes: {
|
|
9
|
+
* [elementName]: {
|
|
10
|
+
* parse: (node: any) => any,
|
|
11
|
+
* render: (node: any) => any,
|
|
12
|
+
* },
|
|
13
|
+
* },
|
|
14
|
+
* }
|
|
15
|
+
* For more details, check the docs here: https://github.com/contentstack/json-rte-serializer/blob/main/README.md#custom-element-types
|
|
16
|
+
* @throws If the config is not provided
|
|
17
|
+
* @example
|
|
18
|
+
* registerJSONRTE({
|
|
19
|
+
* customElementTypes: {
|
|
20
|
+
* myComponent: {
|
|
21
|
+
* parse: (node) => node,
|
|
22
|
+
* render: (node) => (
|
|
23
|
+
* <div>
|
|
24
|
+
* <h3>My Component</h3>
|
|
25
|
+
* <p>{node.children[0].text}</p>
|
|
26
|
+
* </div>
|
|
27
|
+
* ),
|
|
28
|
+
* },
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
*/
|
|
32
|
+
function registerJSONRTE(config) {
|
|
33
|
+
if (!config) {
|
|
34
|
+
throw new Error("Please provide a config to configure JSON RTE");
|
|
35
|
+
}
|
|
36
|
+
jsonRTERegistryInstance.registerJSONRTE(config);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the current config for JSON RTE
|
|
40
|
+
* @returns The current config for JSON RTE
|
|
41
|
+
*/
|
|
42
|
+
function getJSONRTE() {
|
|
43
|
+
return jsonRTERegistryInstance.getJSONRTE();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { getJSONRTE, registerJSONRTE };
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/json-rte-registry/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA,MAAM,uBAAuB,mBAAmB,IAAI,eAAe,EAAE;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACG,SAAU,eAAe,CAAC,MAA0B,EAAA;IACxD,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC;IAClE;AACA,IAAA,uBAAuB,CAAC,eAAe,CAAC,MAAM,CAAC;AACjD;AAEA;;;AAGG;SACa,UAAU,GAAA;AACxB,IAAA,OAAO,uBAAuB,CAAC,UAAU,EAAE;AAC7C;;;;"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { IS_BROWSER, COMPOSABLE_STUDIO_QUERY_PARAM } from '@contentstack/studio-messenger';
|
|
2
|
+
import { RendererMode } from '../canvas/canvas.type.js';
|
|
3
|
+
import { camelCase } from 'lodash-es';
|
|
4
|
+
import '@contentstack/studio-registry';
|
|
5
|
+
import './composable-studio-error.js';
|
|
6
|
+
import '@contentstack/studio-message-types/latest';
|
|
7
|
+
|
|
8
|
+
class RendererModeUtil {
|
|
9
|
+
searchParams = null;
|
|
10
|
+
isServerWithoutParams = false;
|
|
11
|
+
constructor(searchParams) {
|
|
12
|
+
if (!IS_BROWSER && !searchParams) {
|
|
13
|
+
this.isServerWithoutParams = true;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.searchParams =
|
|
17
|
+
searchParams ?? new URLSearchParams(window.location.search);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the current context is inside a Studio.
|
|
21
|
+
*
|
|
22
|
+
* @returns {boolean} True if inside a Studio, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
isInsideStudioFrame() {
|
|
25
|
+
if (this.isServerWithoutParams) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return this.searchParams.has(COMPOSABLE_STUDIO_QUERY_PARAM.ENABLED);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the current context is inside an iframe.
|
|
32
|
+
*
|
|
33
|
+
* @returns {boolean} True if inside an iframe, false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
isInsideIframe() {
|
|
36
|
+
if (this.isServerWithoutParams) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (!IS_BROWSER) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return window.self !== window.top;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks if the current context is inside a Visual Builder frame.
|
|
46
|
+
*
|
|
47
|
+
* Learn more about Visual Builder: {@link https://www.contentstack.com/docs/content-managers/visual-builder}
|
|
48
|
+
*
|
|
49
|
+
* @returns {boolean} True if inside a Visual Builder frame, false otherwise.
|
|
50
|
+
*/
|
|
51
|
+
isInsideVisualBuilderFrame() {
|
|
52
|
+
if (this.isServerWithoutParams) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return (this.searchParams.get(COMPOSABLE_STUDIO_QUERY_PARAM.VISUAL_BUILDER) ===
|
|
56
|
+
"true");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the current context is editing a specific composition.
|
|
60
|
+
*
|
|
61
|
+
* It is useful when you have multiple compositions in a single page
|
|
62
|
+
* and you want to know if the current context is editing a specific
|
|
63
|
+
* composition.
|
|
64
|
+
*
|
|
65
|
+
* @param compositionUid - The UID of the composition to check.
|
|
66
|
+
* @returns {boolean} True if editing the specified composition, false otherwise.
|
|
67
|
+
*/
|
|
68
|
+
isEditingCurrentComposition(compositionUid) {
|
|
69
|
+
if (this.isServerWithoutParams) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return (this.searchParams.get(COMPOSABLE_STUDIO_QUERY_PARAM.COMPOSABLE_UID) ===
|
|
73
|
+
compositionUid);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Determines the current renderer mode for a given composition UID.
|
|
77
|
+
*
|
|
78
|
+
* - Returns "edit" if the current composition is being edited.
|
|
79
|
+
* - Returns "show_edit_button" if inside the visual builder frame
|
|
80
|
+
* or if the composition is not currently being edited but should show the edit button.
|
|
81
|
+
* - Returns "preview" otherwise.
|
|
82
|
+
*
|
|
83
|
+
* This method is useful when you want to change the functionality of the
|
|
84
|
+
* component based on where it is being rendered.
|
|
85
|
+
*
|
|
86
|
+
* @param compositionUid - The UID of the composition to check.
|
|
87
|
+
* @returns RendererMode - The current mode (EDIT, SHOW_EDIT_BUTTON, or PREVIEW).
|
|
88
|
+
*/
|
|
89
|
+
getMode(compositionUid) {
|
|
90
|
+
if (this.isServerWithoutParams) {
|
|
91
|
+
return RendererMode.PREVIEW;
|
|
92
|
+
}
|
|
93
|
+
if (this.isEditingCurrentComposition(compositionUid)) {
|
|
94
|
+
return RendererMode.EDIT;
|
|
95
|
+
}
|
|
96
|
+
const shouldShowEditButtonForAllCompositionInVB = this.isInsideVisualBuilderFrame();
|
|
97
|
+
const shouldShowEditForNonActiveCompositionInsideComposable = !this.isEditingCurrentComposition(compositionUid) &&
|
|
98
|
+
this.isInsideStudioFrame();
|
|
99
|
+
const shouldShowEditButton = shouldShowEditButtonForAllCompositionInVB ||
|
|
100
|
+
shouldShowEditForNonActiveCompositionInsideComposable;
|
|
101
|
+
if (shouldShowEditButton) {
|
|
102
|
+
return RendererMode.SHOW_EDIT_BUTTON;
|
|
103
|
+
}
|
|
104
|
+
return RendererMode.PREVIEW;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const clientRendererModeUtil = /* #__PURE__ */ new RendererModeUtil();
|
|
108
|
+
const serializeComputedStyles = (computedStyle) => {
|
|
109
|
+
const serializedStyles = {};
|
|
110
|
+
const styleProperties = Array.from(computedStyle);
|
|
111
|
+
for (let property of styleProperties) {
|
|
112
|
+
try {
|
|
113
|
+
property = camelCase(property);
|
|
114
|
+
const value = computedStyle[property];
|
|
115
|
+
if (value !== undefined && value !== null) {
|
|
116
|
+
serializedStyles[property] = value.toString();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
// Skip properties that can't be accessed
|
|
121
|
+
console.warn(`Could not serialize CSS property: ${property}`, error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return serializedStyles;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export { RendererModeUtil, clientRendererModeUtil, serializeComputedStyles };
|
|
128
|
+
//# sourceMappingURL=canvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,E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RESOLVING_DATA_SOURCES_FAILED",
|
|
5
|
+
STACK_SDK_NOT_AVAILABLE: "STACK_SDK_NOT_AVAILABLE",
|
|
6
|
+
INVALID_FETCH_SPEC_OPTIONS: "INVALID_FETCH_SPEC_OPTIONS",
|
|
7
|
+
};
|
|
8
|
+
class ComposableStudioError extends Error {
|
|
9
|
+
id;
|
|
10
|
+
details;
|
|
11
|
+
constructor(id, message, details) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.details = details;
|
|
15
|
+
}
|
|
16
|
+
canFallback() {
|
|
17
|
+
return FALLBACK_POSSIBLE_ERRORS.includes(this.id);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// This fails for agadoo
|
|
21
|
+
// ComposableStudioError.prototype.name = "ComposableStudioError";
|
|
22
|
+
const FALLBACK_POSSIBLE_ERRORS = [
|
|
23
|
+
ComposableStudioErrors.COMPOSITION_NOT_FOUND,
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export { ComposableStudioError, ComposableStudioErrors, FALLBACK_POSSIBLE_ERRORS };
|
|
27
|
+
//# sourceMappingURL=composable-studio-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composable-studio-error.js","sources":["../../src/utils/composable-studio-error.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,sBAAsB,GAAG;AACpC,IAAA,qBAAqB,EAAE,uBAAuB;AAC9C,IAAA,8BAA8B,EAAE,gCAAgC;AAChE,IAAA,6BAA6B,EAAE,+BAA+B;AAC9D,IAAA,uBAAuB,EAAE,yBAAyB;AAClD,IAAA,0BAA0B,EAAE,4BAA4B;;AAGpD,MAAO,qBAAsB,SAAQ,KAAK,CAAA;AAC9C,IAAA,EAAE;AACF,IAAA,OAAO;AAEP,IAAA,WAAA,CACE,EAAuC,EACvC,OAAe,EACf,OAAa,EAAA;QAEb,KAAK,CAAC,OAAO,CAAC;AACd,QAAA,IAAI,CAAC,EAAE,GAAG,EAAE;AACZ,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;IACxB;IAEA,WAAW,GAAA;QACT,OAAO,wBAAwB,CAAC,QAAQ,CACtC,IAAI,CAAC,EAA+C,CACrD;IACH;AACD;AACD;AACA;AAEO,MAAM,wBAAwB,GAAG;AACtC,IAAA,sBAAsB,CAAC,qBAAqB;;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
|
|
3
|
+
function isGreaterThan(value1, value2) {
|
|
4
|
+
return value1 > value2;
|
|
5
|
+
}
|
|
6
|
+
function isLessThan(value1, value2) {
|
|
7
|
+
return value1 < value2;
|
|
8
|
+
}
|
|
9
|
+
function isGreaterThanOrEqual(value1, value2) {
|
|
10
|
+
return value1 >= value2;
|
|
11
|
+
}
|
|
12
|
+
function isLessThanOrEqual(value1, value2) {
|
|
13
|
+
return value1 <= value2;
|
|
14
|
+
}
|
|
15
|
+
function doesArrayInclude(arr, value) {
|
|
16
|
+
return Array.isArray(arr) && arr.includes(value);
|
|
17
|
+
}
|
|
18
|
+
function isNotEqual(value1, value2) {
|
|
19
|
+
return !isEqual(value1, value2);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { doesArrayInclude, isGreaterThan, isGreaterThanOrEqual, isLessThan, isLessThanOrEqual, isNotEqual };
|
|
23
|
+
//# sourceMappingURL=condition-block.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-block.utils.js","sources":["../../src/utils/condition-block.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEM,SAAU,aAAa,CAAC,MAAc,EAAE,MAAc,EAAA;IAC1D,OAAO,MAAM,GAAG,MAAM;AACxB;AAEM,SAAU,UAAU,CAAC,MAAc,EAAE,MAAc,EAAA;IACvD,OAAO,MAAM,GAAG,MAAM;AACxB;AAEM,SAAU,oBAAoB,CAAC,MAAc,EAAE,MAAc,EAAA;IACjE,OAAO,MAAM,IAAI,MAAM;AACzB;AAEM,SAAU,iBAAiB,CAAC,MAAc,EAAE,MAAc,EAAA;IAC9D,OAAO,MAAM,IAAI,MAAM;AACzB;AAEM,SAAU,gBAAgB,CAAC,GAAQ,EAAE,KAAU,EAAA;AACnD,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;AAClD;AAOM,SAAU,UAAU,CAAC,MAAW,EAAE,MAAW,EAAA;AACjD,IAAA,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;AACjC;;;;"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { get, isEqual } from 'lodash-es';
|
|
2
|
+
import { isNotEqual, doesArrayInclude, isLessThanOrEqual, isLessThan, isGreaterThanOrEqual, isGreaterThan } from './condition-block.utils.js';
|
|
3
|
+
import { getBindingString } from '@contentstack/studio-registry';
|
|
4
|
+
|
|
5
|
+
// Helper function to evaluate conditions
|
|
6
|
+
const evaluateCondition = (condition, data) => {
|
|
7
|
+
if (!condition?.conditionBinding) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const conditionValue = get(data, getBindingString(condition?.conditionBinding));
|
|
11
|
+
switch (condition?.type) {
|
|
12
|
+
case "number": {
|
|
13
|
+
const numValue = Number(conditionValue);
|
|
14
|
+
return handleNumberComparison(condition.operator, numValue, condition.value);
|
|
15
|
+
}
|
|
16
|
+
case "string": {
|
|
17
|
+
const strValue = String(conditionValue);
|
|
18
|
+
const compareValue = condition.caseSensitive
|
|
19
|
+
? strValue
|
|
20
|
+
: strValue.toLowerCase();
|
|
21
|
+
const conditionValueString = condition.caseSensitive
|
|
22
|
+
? condition.value
|
|
23
|
+
: condition.value.toLowerCase();
|
|
24
|
+
switch (condition.operator) {
|
|
25
|
+
case "contains":
|
|
26
|
+
return compareValue.includes(conditionValueString);
|
|
27
|
+
case "startsWith":
|
|
28
|
+
return compareValue.startsWith(conditionValueString);
|
|
29
|
+
case "endsWith":
|
|
30
|
+
return compareValue.endsWith(conditionValueString);
|
|
31
|
+
case "matches":
|
|
32
|
+
return new RegExp(condition.value).test(strValue);
|
|
33
|
+
case "eq":
|
|
34
|
+
return isEqual(compareValue, conditionValueString);
|
|
35
|
+
case "neq":
|
|
36
|
+
return isNotEqual(compareValue, conditionValueString);
|
|
37
|
+
default:
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
case "boolean":
|
|
42
|
+
switch (condition.operator) {
|
|
43
|
+
case "is":
|
|
44
|
+
return isEqual(conditionValue, condition.value);
|
|
45
|
+
default:
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
case "array": {
|
|
49
|
+
return handleArrayCondition(condition, conditionValue);
|
|
50
|
+
}
|
|
51
|
+
case "modular_block":
|
|
52
|
+
switch (condition.operator) {
|
|
53
|
+
case "is":
|
|
54
|
+
return !!conditionValue;
|
|
55
|
+
default:
|
|
56
|
+
return handleArrayCondition(condition, conditionValue);
|
|
57
|
+
}
|
|
58
|
+
case "date": {
|
|
59
|
+
const dateValue = new Date(conditionValue).getTime();
|
|
60
|
+
const compareDate = new Date(condition.value).getTime();
|
|
61
|
+
return handleNumberComparison(condition.operator, dateValue, compareDate);
|
|
62
|
+
}
|
|
63
|
+
case "select":
|
|
64
|
+
switch (condition.operator) {
|
|
65
|
+
case "is":
|
|
66
|
+
return isEqual(conditionValue, condition.value);
|
|
67
|
+
case "isNot":
|
|
68
|
+
return isNotEqual(conditionValue, condition.value);
|
|
69
|
+
case "includes":
|
|
70
|
+
return doesArrayInclude(conditionValue, condition.value);
|
|
71
|
+
case "excludes":
|
|
72
|
+
return !doesArrayInclude(conditionValue, condition.value);
|
|
73
|
+
default:
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
case "image_extension": {
|
|
77
|
+
const extension = conditionValue.split(".").pop();
|
|
78
|
+
switch (condition.operator) {
|
|
79
|
+
case "is":
|
|
80
|
+
return isEqual(extension, condition.value);
|
|
81
|
+
case "isNot":
|
|
82
|
+
return isNotEqual(extension, condition.value);
|
|
83
|
+
default:
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
case "image_size": {
|
|
88
|
+
const imageSize = parseInt(conditionValue.file_size || "0");
|
|
89
|
+
return handleNumberComparison(condition.operator, imageSize, condition.value);
|
|
90
|
+
}
|
|
91
|
+
case "reference": {
|
|
92
|
+
switch (condition.operator) {
|
|
93
|
+
case "contentTypeIs":
|
|
94
|
+
return isEqual(conditionValue, condition.value);
|
|
95
|
+
default:
|
|
96
|
+
return handleArrayCondition(condition, conditionValue);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
function handleArrayCondition(condition, conditionValue) {
|
|
104
|
+
const arrayValue = Array.isArray(conditionValue) ? conditionValue : [];
|
|
105
|
+
return handleNumberComparison(condition.operator, arrayValue.length, condition.value);
|
|
106
|
+
}
|
|
107
|
+
function handleNumberComparison(operator, value1, value2) {
|
|
108
|
+
switch (operator) {
|
|
109
|
+
case "eq":
|
|
110
|
+
return isEqual(value1, value2);
|
|
111
|
+
case "neq":
|
|
112
|
+
return isNotEqual(value1, value2);
|
|
113
|
+
case "gt":
|
|
114
|
+
return isGreaterThan(value1, value2);
|
|
115
|
+
case "gte":
|
|
116
|
+
return isGreaterThanOrEqual(value1, value2);
|
|
117
|
+
case "lt":
|
|
118
|
+
return isLessThan(value1, value2);
|
|
119
|
+
case "lte":
|
|
120
|
+
return isLessThanOrEqual(value1, value2);
|
|
121
|
+
default:
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { evaluateCondition };
|
|
127
|
+
//# sourceMappingURL=conditionBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionBlock.js","sources":["../../src/utils/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AAgB,EAChB,MAAc,EACd,MAAc,EAAA;IAEd,QAAQ,QAAQ;AACd,QAAA,KAAK,IAAI;AACP,YAAA,OAAO,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;AAChC,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC;AACnC,QAAA,KAAK,IAAI;AACP,YAAA,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC;AACtC,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC;AAC7C,QAAA,KAAK,IAAI;AACP,YAAA,OAAO,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC;AACnC,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC;AAC1C,QAAA;AACE,YAAA,OAAO,KAAK;;AAElB;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { IS_BROWSER } from '@contentstack/studio-messenger';
|
|
2
|
+
|
|
3
|
+
const isBrowser = () => {
|
|
4
|
+
return typeof window !== "undefined" && typeof global === "undefined";
|
|
5
|
+
};
|
|
6
|
+
const INCLUDE_DEPTH_COUNT = 5;
|
|
7
|
+
const COMPOSABLE_DATA_ATTRIBUTES = {
|
|
8
|
+
BUILDER: "data-composable-studio-builder",
|
|
9
|
+
PLACEHOLDER: "data-composable-studio-placeholder",
|
|
10
|
+
LEAF: "data-composable-studio-leaf",
|
|
11
|
+
NODE: "data-composable-studio-node",
|
|
12
|
+
SLOT: "data-composable-studio-slot",
|
|
13
|
+
ID: "data-composable-studio-id",
|
|
14
|
+
SLOT_UID: "data-composable-studio-slot-uid",
|
|
15
|
+
CSLP: "data-cslp",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { COMPOSABLE_DATA_ATTRIBUTES, INCLUDE_DEPTH_COUNT, isBrowser };
|
|
19
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/utils/constants.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEO,MAAM,SAAS,GAAG,MAAK;IAC5B,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW;AACvE;AAEO,MAAM,mBAAmB,GAAG;AAE5B,MAAM,0BAA0B,GAAG;AACxC,IAAA,OAAO,EAAE,gCAAgC;AACzC,IAAA,WAAW,EAAE,oCAAoC;AACjD,IAAA,IAAI,EAAE,6BAA6B;AACnC,IAAA,IAAI,EAAE,6BAA6B;AACnC,IAAA,IAAI,EAAE,6BAA6B;AACnC,IAAA,EAAE,EAAE,2BAA2B;AAC/B,IAAA,QAAQ,EAAE,iCAAiC;AAC3C,IAAA,IAAI,EAAE,WAAW;;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function convertCompositionQueryInputToCompositionQuery(compositionQueryInput) {
|
|
2
|
+
const compositionUid = "compositionUid" in compositionQueryInput
|
|
3
|
+
? compositionQueryInput.compositionUid
|
|
4
|
+
: null;
|
|
5
|
+
const url = "url" in compositionQueryInput ? compositionQueryInput.url : null;
|
|
6
|
+
if (compositionUid && url) {
|
|
7
|
+
return { composableUid: compositionUid, url: url };
|
|
8
|
+
}
|
|
9
|
+
else if (compositionUid) {
|
|
10
|
+
return { composableUid: compositionUid };
|
|
11
|
+
}
|
|
12
|
+
else if (url) {
|
|
13
|
+
return { url: url };
|
|
14
|
+
}
|
|
15
|
+
throw new Error("Neither compositionUid nor url is provided. We should never reach this condition");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { convertCompositionQueryInputToCompositionQuery };
|
|
19
|
+
//# sourceMappingURL=convertCompositionQueryInputToCompositionQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertCompositionQueryInputToCompositionQuery.js","sources":["../../src/utils/convertCompositionQueryInputToCompositionQuery.ts"],"sourcesContent":[null],"names":[],"mappings":"AAKM,SAAU,8CAA8C,CAC5D,qBAA4C,EAAA;AAE5C,IAAA,MAAM,cAAc,GAClB,gBAAgB,IAAI;UAChB,qBAAqB,CAAC;UACtB,IAAI;AACV,IAAA,MAAM,GAAG,GAAG,KAAK,IAAI,qBAAqB,GAAG,qBAAqB,CAAC,GAAG,GAAG,IAAI;AAE7E,IAAA,IAAI,cAAc,IAAI,GAAG,EAAE;QACzB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,EAAE;IACpD;SAAO,IAAI,cAAc,EAAE;AACzB,QAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE;IAC1C;SAAO,IAAI,GAAG,EAAE;AACd,QAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE;IACrB;AAEA,IAAA,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF;AACH;;;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { set } from 'lodash-es';
|
|
2
|
+
import { NODE_TO_PARENT, NODE_TO_PATH_NODE, ELEMENT_TO_NODE } from '../composable-studio/weak-maps.js';
|
|
3
|
+
|
|
4
|
+
// **** BIG NOTE: THIS FILE IMPLEMENTS THE LIGHTER VERSION OF THE NODE OPERATIONS. THE REPEATED CODE IS INTENTIONAL TO KEEP THE FILE LIGHTER. WE ARE ONLY USING THE STUDIO INTERNAL PACKAGE FOR THE TYPES. ****
|
|
5
|
+
const findPath = (node) => {
|
|
6
|
+
const path = [];
|
|
7
|
+
let child = node;
|
|
8
|
+
const condition = true;
|
|
9
|
+
while (condition) {
|
|
10
|
+
const parent = NODE_TO_PARENT.get(child);
|
|
11
|
+
if (parent === undefined) {
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
14
|
+
const pn = NODE_TO_PATH_NODE.get(child);
|
|
15
|
+
if (pn === undefined)
|
|
16
|
+
break;
|
|
17
|
+
path.unshift(pn);
|
|
18
|
+
child = parent;
|
|
19
|
+
}
|
|
20
|
+
throw Error("Could not find path for node");
|
|
21
|
+
};
|
|
22
|
+
const findPathForElement = (el) => {
|
|
23
|
+
const node = ELEMENT_TO_NODE.get(el);
|
|
24
|
+
if (!node) {
|
|
25
|
+
throw new Error("Node not found");
|
|
26
|
+
}
|
|
27
|
+
return findPath(node);
|
|
28
|
+
};
|
|
29
|
+
const applyOperation = (editor, operations) => {
|
|
30
|
+
operations.forEach((operation) => applyOperationOnNode(editor, operation));
|
|
31
|
+
return editor;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Ligher version of the getNode function
|
|
35
|
+
* @param node The node from which to start searching
|
|
36
|
+
* @param path The path to the node to be found
|
|
37
|
+
* @returns The node at the given path
|
|
38
|
+
*/
|
|
39
|
+
const getNode = (node, path) => {
|
|
40
|
+
let currentNode = node;
|
|
41
|
+
for (const [slot, index] of path) {
|
|
42
|
+
currentNode = currentNode.slots[slot][index];
|
|
43
|
+
}
|
|
44
|
+
return currentNode;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* It is a lighter version of the applyOperation function that modifies the JSON object.
|
|
48
|
+
* @param editor The root node
|
|
49
|
+
* @param operation The action to be performed on the node
|
|
50
|
+
*/
|
|
51
|
+
const applyOperationOnNode = (editor, operation) => {
|
|
52
|
+
const { type } = operation;
|
|
53
|
+
switch (type) {
|
|
54
|
+
case "insert_node": {
|
|
55
|
+
const { path, node } = operation;
|
|
56
|
+
const parent = getNode(editor, path.slice(0, path.length - 1));
|
|
57
|
+
const [slot, index] = path[path.length - 1];
|
|
58
|
+
parent.slots[slot].splice(index, 0, node);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "remove_node": {
|
|
62
|
+
const { path } = operation;
|
|
63
|
+
const parent = getNode(editor, path.slice(0, path.length - 1));
|
|
64
|
+
const [slot, index] = path[path.length - 1];
|
|
65
|
+
parent.slots[slot].splice(index, 1);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case "set_node": {
|
|
69
|
+
const { path, newProperties } = operation;
|
|
70
|
+
const node = getNode(editor, path);
|
|
71
|
+
for (const key in newProperties) {
|
|
72
|
+
if (["type"].includes(key)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
set(node, key, newProperties[key]);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
default: {
|
|
80
|
+
console.error(`Unknown operation type: ${type}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { applyOperation, findPath, findPathForElement };
|
|
86
|
+
//# sourceMappingURL=editor-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-utils.js","sources":["../../src/utils/editor-utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;AAeO,MAAM,QAAQ,GAAG,CAAC,IAAgB,KAAU;IACjD,MAAM,IAAI,GAAS,EAAE;IACrB,IAAI,KAAK,GAAG,IAAI;IAChB,MAAM,SAAS,GAAG,IAAI;IACtB,OAAO,SAAS,EAAE;QAChB,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC;AACxC,QAAA,IAAI,MAAM,KAAK,SAAS,EAAE;AACxB,YAAA,OAAO,IAAI;QACb;QACA,MAAM,EAAE,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC;QACvC,IAAI,EAAE,KAAK,SAAS;YAAE;AACtB,QAAA,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAChB,KAAK,GAAG,MAAM;IAChB;AACA,IAAA,MAAM,KAAK,CAAC,8BAA8B,CAAC;AAC7C;AAEO,MAAM,kBAAkB,GAAG,CAAC,EAAe,KAAI;IACpD,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;IACpC,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC;IACnC;AACA,IAAA,OAAO,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AAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9D,YAAA,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,YAAA,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YACnC;QACF;QACA,KAAK,UAAU,EAAE;AACf,YAAA,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,SAAS;YACzC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;AAClC,YAAA,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;gBAC/B,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;oBAC1B;gBACF;gBACA,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;YACpC;YACA;QACF;QACA,SAAS;AACP,YAAA,OAAO,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAA,CAAE,CAAC;QAClD;;AAEJ,CAAC;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { COMPOSABLE_STUDIO_QUERY_PARAM } from '@contentstack/studio-messenger';
|
|
2
|
+
import { queryParam } from './query-param.js';
|
|
3
|
+
|
|
4
|
+
function isCompositionBeingEdited(compositionUid) {
|
|
5
|
+
const editedComposableUid = queryParam.get(COMPOSABLE_STUDIO_QUERY_PARAM.COMPOSABLE_UID);
|
|
6
|
+
return Boolean(editedComposableUid &&
|
|
7
|
+
compositionUid &&
|
|
8
|
+
editedComposableUid === compositionUid);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { isCompositionBeingEdited };
|
|
12
|
+
//# sourceMappingURL=is-composition-being-edited.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-composition-being-edited.js","sources":["../../src/utils/is-composition-being-edited.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAGM,SAAU,wBAAwB,CAAC,cAAsB,EAAA;IAC7D,MAAM,mBAAmB,GAAG,UAAU,CAAC,GAAG,CACxC,6BAA6B,CAAC,cAAc,CAC7C;IACD,OAAO,OAAO,CACZ,mBAAmB;QACjB,cAAc;QACd,mBAAmB,KAAK,cAAc,CACzC;AACH;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IS_BROWSER, COMPOSABLE_STUDIO_QUERY_PARAM } from '@contentstack/studio-messenger';
|
|
2
|
+
|
|
3
|
+
const isInsideVisualBuilderFrame = () => {
|
|
4
|
+
if (!IS_BROWSER) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
8
|
+
return (searchParams.get(COMPOSABLE_STUDIO_QUERY_PARAM.VISUAL_BUILDER) === "true");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { isInsideVisualBuilderFrame };
|
|
12
|
+
//# sourceMappingURL=is-inside-visual-builder-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-inside-visual-builder-frame.js","sources":["../../src/utils/is-inside-visual-builder-frame.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKO,MAAM,0BAA0B,GAAG,MAAK;IAC7C,IAAI,CAAC,UAAU,EAAE;AACf,QAAA,OAAO,KAAK;IACd;IACA,MAAM,YAAY,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;AAChE,IAAA,QACE,YAAY,CAAC,GAAG,CAAC,6BAA6B,CAAC,cAAc,CAAC,KAAK,MAAM;AAE7E;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IS_BROWSER } from '@contentstack/studio-messenger';
|
|
2
|
+
|
|
3
|
+
const queryParam = {
|
|
4
|
+
get(key) {
|
|
5
|
+
if (IS_BROWSER) {
|
|
6
|
+
return new URLSearchParams(window.location.search).get(key);
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
},
|
|
10
|
+
has(key) {
|
|
11
|
+
if (IS_BROWSER) {
|
|
12
|
+
return new URLSearchParams(window.location.search).has(key);
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const onlyParmasGenerator = (only) => {
|
|
18
|
+
const referenceFields = new Map();
|
|
19
|
+
only.forEach(([reference, field]) => {
|
|
20
|
+
if (!referenceFields.has(reference)) {
|
|
21
|
+
referenceFields.set(reference, []);
|
|
22
|
+
}
|
|
23
|
+
referenceFields.get(reference).push(field);
|
|
24
|
+
});
|
|
25
|
+
const onlyParams = {};
|
|
26
|
+
referenceFields.forEach((fields, reference) => {
|
|
27
|
+
onlyParams[`only[${reference}][]`] = fields;
|
|
28
|
+
});
|
|
29
|
+
return onlyParams;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { onlyParmasGenerator, queryParam };
|
|
33
|
+
//# sourceMappingURL=query-param.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-param.js","sources":["../../src/utils/query-param.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKO,MAAM,UAAU,GAAG;AACxB,IAAA,GAAG,CAAC,GAAoC,EAAA;QACtC,IAAI,UAAU,EAAE;AACd,YAAA,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;QAC7D;AAEA,QAAA,OAAO,IAAI;IACb,CAAC;AACD,IAAA,GAAG,CAAC,GAAoC,EAAA;QACtC,IAAI,UAAU,EAAE;AACd,YAAA,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;QAC7D;AAEA,QAAA,OAAO,KAAK;IACd,CAAC;;AAGI,MAAM,mBAAmB,GAAG,CAAC,IAAwB,KAAI;AAC9D,IAAA,MAAM,eAAe,GAAG,IAAI,GAAG,EAAE;IACjC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,KAAI;QAClC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;AACnC,YAAA,eAAe,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC;QACpC;QACA,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;AAC5C,IAAA,CAAC,CAAC;IACF,MAAM,UAAU,GAA2B,EAAE;IAC7C,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,SAAS,KAAI;AAC5C,QAAA,UAAU,CAAC,CAAA,KAAA,EAAQ,SAAS,KAAK,CAAC,GAAG,MAAM;AAC7C,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,UAAU;AACnB;;;;"}
|