@dotcms/uve 1.2.1 → 1.2.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/public.cjs.js CHANGED
@@ -237,24 +237,10 @@ function getDotContentletAttributes(contentlet, container) {
237
237
  'data-dot-inode': contentlet?.inode,
238
238
  'data-dot-type': contentlet?.contentType,
239
239
  'data-dot-container': container,
240
- 'data-dot-on-number-of-pages': contentlet?.['onNumberOfPages'] || '1'
241
- };
242
- }
243
- /**
244
- * Helper function that returns an object containing analytics-specific data attributes.
245
- * These attributes are used by the DotCMS Analytics SDK to track content interactions.
246
- *
247
- * @param {DotCMSBasicContentlet} contentlet - The contentlet to get the analytics attributes for
248
- * @returns {DotAnalyticsAttributes} The analytics data attributes
249
- * @internal
250
- */
251
- function getDotAnalyticsAttributes(contentlet) {
252
- return {
253
- 'data-dot-analytics-identifier': contentlet?.identifier,
254
- 'data-dot-analytics-inode': contentlet?.inode,
255
- 'data-dot-analytics-basetype': contentlet?.baseType,
256
- 'data-dot-analytics-contenttype': contentlet?.contentType,
257
- 'data-dot-analytics-title': contentlet?.['widgetTitle'] || contentlet?.title
240
+ 'data-dot-on-number-of-pages': contentlet?.['onNumberOfPages'] || '1',
241
+ ...(contentlet?.dotStyleProperties && {
242
+ 'data-dot-style-properties': JSON.stringify(contentlet.dotStyleProperties)
243
+ })
258
244
  };
259
245
  }
260
246
  /**
@@ -287,6 +273,8 @@ const getContainersData = (dotCMSPageAsset, columContainer) => {
287
273
  container
288
274
  } = dotContainer;
289
275
  const acceptTypes = containerStructures?.map(structure => structure.contentTypeVar).join(',') ?? '';
276
+ // TODO: Check if the variantId is needed and we need to find another way to get it.
277
+ // Since the parentPermissionable is not available after: https://github.com/dotCMS/core/pull/32890
290
278
  const variantId = container?.parentPermissionable?.variantId;
291
279
  const maxContentlets = container?.maxContentlets ?? 0;
292
280
  const path = container?.path;
@@ -490,7 +478,10 @@ function onContentletHovered(callback) {
490
478
  contentType: foundElement.dataset?.['dotType'],
491
479
  baseType: foundElement.dataset?.['dotBasetype'],
492
480
  widgetTitle: foundElement.dataset?.['dotWidgetTitle'],
493
- onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages']
481
+ onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages'],
482
+ ...(foundElement.dataset?.['dotStyleProperties'] && {
483
+ dotStyleProperties: JSON.parse(foundElement.dataset['dotStyleProperties'])
484
+ })
494
485
  };
495
486
  const vtlFiles = findDotCMSVTLData(foundElement);
496
487
  const contentletPayload = {
@@ -614,10 +605,6 @@ const EMPTY_CONTAINER_STYLE_ANGULAR = {
614
605
  * @internal
615
606
  */
616
607
  const CUSTOM_NO_COMPONENT = 'CustomNoComponent';
617
- // Analytics active flag key
618
- const ANALYTICS_WINDOWS_ACTIVE_KEY = '__dotAnalyticsActive__';
619
- // Analytics cleanup function key
620
- const ANALYTICS_WINDOWS_CLEANUP_KEY = '__dotAnalyticsCleanup';
621
608
 
622
609
  /**
623
610
  * Gets the current state of the Universal Visual Editor (UVE).
@@ -703,57 +690,6 @@ function createUVESubscription(eventType, callback) {
703
690
  }
704
691
  return eventCallback(callback);
705
692
  }
706
- /**
707
- * Checks if DotCMS Analytics is active by verifying the global window flag.
708
- *
709
- * This function checks for the presence of the `__dotAnalyticsActive__` flag on the window object,
710
- * which is set by the `@dotcms/analytics` SDK when Analytics is successfully initialized.
711
- *
712
- * This utility can be used in any JavaScript framework (React, Angular, Vue, etc.) to conditionally
713
- * enable analytics-related features or data attributes.
714
- *
715
- * @export
716
- * @returns {boolean} true if Analytics is initialized and active, false otherwise
717
- *
718
- * @example
719
- * ```ts
720
- * // React example
721
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
722
- *
723
- * function MyComponent() {
724
- * const shouldTrack = isAnalyticsActive();
725
- *
726
- * if (shouldTrack) {
727
- * // Add analytics tracking
728
- * }
729
- * }
730
- * ```
731
- *
732
- * @example
733
- * ```ts
734
- * // Angular example
735
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
736
- *
737
- * if (isAnalyticsActive()) {
738
- * // Apply analytics attributes to elements
739
- * element.setAttribute('data-dot-object', 'contentlet');
740
- * }
741
- * ```
742
- *
743
- * @example
744
- * ```ts
745
- * // Vanilla JavaScript / Any framework
746
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
747
- *
748
- * if (isAnalyticsActive()) {
749
- * console.log('DotCMS Analytics is active');
750
- * }
751
- * ```
752
- */
753
- function isAnalyticsActive() {
754
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
755
- return typeof window !== 'undefined' && window[ANALYTICS_WINDOWS_ACTIVE_KEY] === true;
756
- }
757
693
 
758
694
  /**
759
695
  * Sets the bounds of the containers in the editor.
@@ -1176,8 +1112,6 @@ function initUVE(config = {}) {
1176
1112
  };
1177
1113
  }
1178
1114
 
1179
- exports.ANALYTICS_WINDOWS_ACTIVE_KEY = ANALYTICS_WINDOWS_ACTIVE_KEY;
1180
- exports.ANALYTICS_WINDOWS_CLEANUP_KEY = ANALYTICS_WINDOWS_CLEANUP_KEY;
1181
1115
  exports.CUSTOM_NO_COMPONENT = CUSTOM_NO_COMPONENT;
1182
1116
  exports.DEVELOPMENT_MODE = DEVELOPMENT_MODE;
1183
1117
  exports.EMPTY_CONTAINER_STYLE_ANGULAR = EMPTY_CONTAINER_STYLE_ANGULAR;
@@ -1198,7 +1132,6 @@ exports.getClosestDotCMSContainerData = getClosestDotCMSContainerData;
1198
1132
  exports.getColumnPositionClasses = getColumnPositionClasses;
1199
1133
  exports.getContainersData = getContainersData;
1200
1134
  exports.getContentletsInContainer = getContentletsInContainer;
1201
- exports.getDotAnalyticsAttributes = getDotAnalyticsAttributes;
1202
1135
  exports.getDotCMSContainerData = getDotCMSContainerData;
1203
1136
  exports.getDotCMSContentletsBound = getDotCMSContentletsBound;
1204
1137
  exports.getDotCMSPageBounds = getDotCMSPageBounds;
@@ -1207,7 +1140,6 @@ exports.getDotContentletAttributes = getDotContentletAttributes;
1207
1140
  exports.getUVEState = getUVEState;
1208
1141
  exports.initInlineEditing = initInlineEditing;
1209
1142
  exports.initUVE = initUVE;
1210
- exports.isAnalyticsActive = isAnalyticsActive;
1211
1143
  exports.isValidBlocks = isValidBlocks;
1212
1144
  exports.reorderMenu = reorderMenu;
1213
1145
  exports.sendMessageToUVE = sendMessageToUVE;
package/public.esm.js CHANGED
@@ -235,24 +235,10 @@ function getDotContentletAttributes(contentlet, container) {
235
235
  'data-dot-inode': contentlet?.inode,
236
236
  'data-dot-type': contentlet?.contentType,
237
237
  'data-dot-container': container,
238
- 'data-dot-on-number-of-pages': contentlet?.['onNumberOfPages'] || '1'
239
- };
240
- }
241
- /**
242
- * Helper function that returns an object containing analytics-specific data attributes.
243
- * These attributes are used by the DotCMS Analytics SDK to track content interactions.
244
- *
245
- * @param {DotCMSBasicContentlet} contentlet - The contentlet to get the analytics attributes for
246
- * @returns {DotAnalyticsAttributes} The analytics data attributes
247
- * @internal
248
- */
249
- function getDotAnalyticsAttributes(contentlet) {
250
- return {
251
- 'data-dot-analytics-identifier': contentlet?.identifier,
252
- 'data-dot-analytics-inode': contentlet?.inode,
253
- 'data-dot-analytics-basetype': contentlet?.baseType,
254
- 'data-dot-analytics-contenttype': contentlet?.contentType,
255
- 'data-dot-analytics-title': contentlet?.['widgetTitle'] || contentlet?.title
238
+ 'data-dot-on-number-of-pages': contentlet?.['onNumberOfPages'] || '1',
239
+ ...(contentlet?.dotStyleProperties && {
240
+ 'data-dot-style-properties': JSON.stringify(contentlet.dotStyleProperties)
241
+ })
256
242
  };
257
243
  }
258
244
  /**
@@ -285,6 +271,8 @@ const getContainersData = (dotCMSPageAsset, columContainer) => {
285
271
  container
286
272
  } = dotContainer;
287
273
  const acceptTypes = containerStructures?.map(structure => structure.contentTypeVar).join(',') ?? '';
274
+ // TODO: Check if the variantId is needed and we need to find another way to get it.
275
+ // Since the parentPermissionable is not available after: https://github.com/dotCMS/core/pull/32890
288
276
  const variantId = container?.parentPermissionable?.variantId;
289
277
  const maxContentlets = container?.maxContentlets ?? 0;
290
278
  const path = container?.path;
@@ -488,7 +476,10 @@ function onContentletHovered(callback) {
488
476
  contentType: foundElement.dataset?.['dotType'],
489
477
  baseType: foundElement.dataset?.['dotBasetype'],
490
478
  widgetTitle: foundElement.dataset?.['dotWidgetTitle'],
491
- onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages']
479
+ onNumberOfPages: foundElement.dataset?.['dotOnNumberOfPages'],
480
+ ...(foundElement.dataset?.['dotStyleProperties'] && {
481
+ dotStyleProperties: JSON.parse(foundElement.dataset['dotStyleProperties'])
482
+ })
492
483
  };
493
484
  const vtlFiles = findDotCMSVTLData(foundElement);
494
485
  const contentletPayload = {
@@ -612,10 +603,6 @@ const EMPTY_CONTAINER_STYLE_ANGULAR = {
612
603
  * @internal
613
604
  */
614
605
  const CUSTOM_NO_COMPONENT = 'CustomNoComponent';
615
- // Analytics active flag key
616
- const ANALYTICS_WINDOWS_ACTIVE_KEY = '__dotAnalyticsActive__';
617
- // Analytics cleanup function key
618
- const ANALYTICS_WINDOWS_CLEANUP_KEY = '__dotAnalyticsCleanup';
619
606
 
620
607
  /**
621
608
  * Gets the current state of the Universal Visual Editor (UVE).
@@ -701,57 +688,6 @@ function createUVESubscription(eventType, callback) {
701
688
  }
702
689
  return eventCallback(callback);
703
690
  }
704
- /**
705
- * Checks if DotCMS Analytics is active by verifying the global window flag.
706
- *
707
- * This function checks for the presence of the `__dotAnalyticsActive__` flag on the window object,
708
- * which is set by the `@dotcms/analytics` SDK when Analytics is successfully initialized.
709
- *
710
- * This utility can be used in any JavaScript framework (React, Angular, Vue, etc.) to conditionally
711
- * enable analytics-related features or data attributes.
712
- *
713
- * @export
714
- * @returns {boolean} true if Analytics is initialized and active, false otherwise
715
- *
716
- * @example
717
- * ```ts
718
- * // React example
719
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
720
- *
721
- * function MyComponent() {
722
- * const shouldTrack = isAnalyticsActive();
723
- *
724
- * if (shouldTrack) {
725
- * // Add analytics tracking
726
- * }
727
- * }
728
- * ```
729
- *
730
- * @example
731
- * ```ts
732
- * // Angular example
733
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
734
- *
735
- * if (isAnalyticsActive()) {
736
- * // Apply analytics attributes to elements
737
- * element.setAttribute('data-dot-object', 'contentlet');
738
- * }
739
- * ```
740
- *
741
- * @example
742
- * ```ts
743
- * // Vanilla JavaScript / Any framework
744
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
745
- *
746
- * if (isAnalyticsActive()) {
747
- * console.log('DotCMS Analytics is active');
748
- * }
749
- * ```
750
- */
751
- function isAnalyticsActive() {
752
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
753
- return typeof window !== 'undefined' && window[ANALYTICS_WINDOWS_ACTIVE_KEY] === true;
754
- }
755
691
 
756
692
  /**
757
693
  * Sets the bounds of the containers in the editor.
@@ -1174,4 +1110,4 @@ function initUVE(config = {}) {
1174
1110
  };
1175
1111
  }
1176
1112
 
1177
- export { ANALYTICS_WINDOWS_ACTIVE_KEY as A, getContentletsInContainer as B, CUSTOM_NO_COMPONENT as C, DEVELOPMENT_MODE as D, END_CLASS as E, getDotContainerAttributes as F, setBounds as G, isValidBlocks as H, PRODUCTION_MODE as P, START_CLASS as S, __UVE_EVENTS__ as _, initInlineEditing as a, enableBlockEditorInline as b, createUVESubscription as c, initUVE as d, editContentlet as e, __UVE_EVENT_ERROR_FALLBACK__ as f, getUVEState as g, EMPTY_CONTAINER_STYLE_REACT as h, isAnalyticsActive as i, EMPTY_CONTAINER_STYLE_ANGULAR as j, ANALYTICS_WINDOWS_CLEANUP_KEY as k, getDotCMSPageBounds as l, getDotCMSContentletsBound as m, getDotCMSContainerData as n, getClosestDotCMSContainerData as o, findDotCMSElement as p, findDotCMSVTLData as q, reorderMenu as r, sendMessageToUVE as s, computeScrollIsInBottom as t, updateNavigation as u, combineClasses as v, getColumnPositionClasses as w, getDotContentletAttributes as x, getDotAnalyticsAttributes as y, getContainersData as z };
1113
+ export { isValidBlocks as A, CUSTOM_NO_COMPONENT as C, DEVELOPMENT_MODE as D, END_CLASS as E, PRODUCTION_MODE as P, START_CLASS as S, __UVE_EVENTS__ as _, enableBlockEditorInline as a, initUVE as b, createUVESubscription as c, __UVE_EVENT_ERROR_FALLBACK__ as d, editContentlet as e, EMPTY_CONTAINER_STYLE_REACT as f, getUVEState as g, EMPTY_CONTAINER_STYLE_ANGULAR as h, initInlineEditing as i, getDotCMSPageBounds as j, getDotCMSContentletsBound as k, getDotCMSContainerData as l, getClosestDotCMSContainerData as m, findDotCMSElement as n, findDotCMSVTLData as o, computeScrollIsInBottom as p, combineClasses as q, reorderMenu as r, sendMessageToUVE as s, getColumnPositionClasses as t, updateNavigation as u, getDotContentletAttributes as v, getContainersData as w, getContentletsInContainer as x, getDotContainerAttributes as y, setBounds as z };
package/src/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './lib/core/core.utils';
2
2
  export * from './lib/editor/public';
3
+ export * from './lib/style-editor/types';
4
+ export * from './lib/style-editor/public';
@@ -74,5 +74,3 @@ export declare const EMPTY_CONTAINER_STYLE_ANGULAR: {
74
74
  * @internal
75
75
  */
76
76
  export declare const CUSTOM_NO_COMPONENT = "CustomNoComponent";
77
- export declare const ANALYTICS_WINDOWS_ACTIVE_KEY = "__dotAnalyticsActive__";
78
- export declare const ANALYTICS_WINDOWS_CLEANUP_KEY = "__dotAnalyticsCleanup";
@@ -47,51 +47,3 @@ export declare function getUVEState(): UVEState | undefined;
47
47
  * ```
48
48
  */
49
49
  export declare function createUVESubscription<T extends UVEEventType>(eventType: T, callback: (payload: UVEEventPayloadMap[T] extends undefined ? void : UVEEventPayloadMap[T]) => void): UVEEventSubscription;
50
- /**
51
- * Checks if DotCMS Analytics is active by verifying the global window flag.
52
- *
53
- * This function checks for the presence of the `__dotAnalyticsActive__` flag on the window object,
54
- * which is set by the `@dotcms/analytics` SDK when Analytics is successfully initialized.
55
- *
56
- * This utility can be used in any JavaScript framework (React, Angular, Vue, etc.) to conditionally
57
- * enable analytics-related features or data attributes.
58
- *
59
- * @export
60
- * @returns {boolean} true if Analytics is initialized and active, false otherwise
61
- *
62
- * @example
63
- * ```ts
64
- * // React example
65
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
66
- *
67
- * function MyComponent() {
68
- * const shouldTrack = isAnalyticsActive();
69
- *
70
- * if (shouldTrack) {
71
- * // Add analytics tracking
72
- * }
73
- * }
74
- * ```
75
- *
76
- * @example
77
- * ```ts
78
- * // Angular example
79
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
80
- *
81
- * if (isAnalyticsActive()) {
82
- * // Apply analytics attributes to elements
83
- * element.setAttribute('data-dot-object', 'contentlet');
84
- * }
85
- * ```
86
- *
87
- * @example
88
- * ```ts
89
- * // Vanilla JavaScript / Any framework
90
- * import { isAnalyticsActive } from '@dotcms/uve/internal';
91
- *
92
- * if (isAnalyticsActive()) {
93
- * console.log('DotCMS Analytics is active');
94
- * }
95
- * ```
96
- */
97
- export declare function isAnalyticsActive(): boolean;
@@ -1,5 +1,5 @@
1
1
  import { DotCMSBasicContentlet, DotCMSColumnContainer, DotCMSPageAsset, DotPageAssetLayoutColumn, EditableContainerData } from '@dotcms/types';
2
- import { DotAnalyticsAttributes, DotCMSContainerBound, DotCMSContentletBound, DotContainerAttributes, DotContentletAttributes } from '@dotcms/types/internal';
2
+ import { DotCMSContainerBound, DotCMSContentletBound, DotContainerAttributes, DotContentletAttributes } from '@dotcms/types/internal';
3
3
  /**
4
4
  * Calculates the bounding information for each page element within the given containers.
5
5
  *
@@ -152,15 +152,6 @@ export declare const getColumnPositionClasses: (column: DotPageAssetLayoutColumn
152
152
  * @returns {DotContentletAttributes} The dotCMS data attributes
153
153
  */
154
154
  export declare function getDotContentletAttributes(contentlet: DotCMSBasicContentlet, container: string): DotContentletAttributes;
155
- /**
156
- * Helper function that returns an object containing analytics-specific data attributes.
157
- * These attributes are used by the DotCMS Analytics SDK to track content interactions.
158
- *
159
- * @param {DotCMSBasicContentlet} contentlet - The contentlet to get the analytics attributes for
160
- * @returns {DotAnalyticsAttributes} The analytics data attributes
161
- * @internal
162
- */
163
- export declare function getDotAnalyticsAttributes(contentlet: DotCMSBasicContentlet): DotAnalyticsAttributes;
164
155
  /**
165
156
  *
166
157
  *
@@ -0,0 +1,71 @@
1
+ import { StyleEditorForm, StyleEditorFormSchema } from './types';
2
+ /**
3
+ * Normalizes a complete form definition into the schema format expected by UVE.
4
+ *
5
+ * This is the main entry point for converting a developer-friendly form definition
6
+ * into the normalized schema structure that UVE (Universal Visual Editor) can consume.
7
+ * The normalization process transforms the entire form hierarchy:
8
+ *
9
+ * **Normalization Process:**
10
+ * 1. Preserves the `contentType` identifier
11
+ * 2. Processes each section using `normalizeSection`, which:
12
+ * - Normalizes all fields in the section using `normalizeField`
13
+ * - Organizes fields into the required multi-dimensional array structure
14
+ * 3. Returns a fully normalized schema with consistent structure across all sections
15
+ *
16
+ * The resulting schema has all field-specific properties moved into `config` objects
17
+ * and all sections using the consistent single-column array structure, regardless
18
+ * of the input format.
19
+ *
20
+ * @experimental This method is experimental and may be subject to change.
21
+ *
22
+ * @param form - The complete form definition to normalize
23
+ * @param form.contentType - The content type identifier this form is associated with
24
+ * @param form.sections - Array of section definitions, each containing a title and fields
25
+ * @returns The normalized form schema ready to be sent to UVE, with all fields and sections normalized
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const schema = normalizeForm({
30
+ * contentType: 'my-content-type',
31
+ * sections: [
32
+ * {
33
+ * title: 'Typography',
34
+ * fields: [
35
+ * { type: 'input', id: 'font-size', label: 'Font Size', inputType: 'number' },
36
+ * { type: 'dropdown', id: 'font-family', label: 'Font Family', options: ['Arial', 'Helvetica'] }
37
+ * ]
38
+ * },
39
+ * {
40
+ * title: 'Colors',
41
+ * fields: [
42
+ * { type: 'input', id: 'primary-color', label: 'Primary Color', inputType: 'text' }
43
+ * ]
44
+ * }
45
+ * ]
46
+ * });
47
+ * // Returns: {
48
+ * // contentType: 'my-content-type',
49
+ * // sections: [
50
+ * // {
51
+ * // title: 'Typography',
52
+ * // fields: [
53
+ * // [
54
+ * // { type: 'input', id: 'font-size', label: 'Font Size', config: { inputType: 'number' } },
55
+ * // { type: 'dropdown', id: 'font-family', label: 'Font Family', config: { options: [...] } }
56
+ * // ]
57
+ * // ]
58
+ * // },
59
+ * // {
60
+ * // title: 'Colors',
61
+ * // fields: [
62
+ * // [
63
+ * // { type: 'input', id: 'primary-color', label: 'Primary Color', config: { inputType: 'text' } }
64
+ * // ]
65
+ * // ]
66
+ * // }
67
+ * // ]
68
+ * // }
69
+ * ```
70
+ */
71
+ export declare function normalizeForm(form: StyleEditorForm): StyleEditorFormSchema;