@dotcms/uve 0.0.1-beta.12 → 0.0.1-beta.13

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 CHANGED
@@ -1,7 +1,149 @@
1
- # sdk-uve
1
+ # DotCMS UVE SDK
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ A JavaScript library to connect your dotCMS pages with the Universal Visual Editor (UVE) and enable content authors to edit pages in real time.
4
4
 
5
- ## Running unit tests
5
+ ## Installation
6
6
 
7
- Run `nx test sdk-uve` to execute the unit tests via [Jest](https://jestjs.io).
7
+ The UVE SDK is automatically included in DotCMS installations. For external usage:
8
+
9
+ ```bash
10
+ yarn add @dotcms/uve-sdk
11
+ ```
12
+
13
+
14
+ ## Entry Points
15
+
16
+ The library exposes three main entry points:
17
+
18
+ - **`@dotcms/uve`**: Provides everything developers need to communicate with UVE.
19
+
20
+ - **`@dotcms/uve/types`**: Offers TypeScript types, interfaces, and other structures to help users organize their code properly.
21
+
22
+ ---
23
+
24
+ ## Functions
25
+
26
+ ### `createUVESubscription`
27
+
28
+ Subscribe to the pages changes. Receive a callback that will be called with the updated content of the page.
29
+
30
+ **Parameters:**
31
+ - `eventType` - The type of event to subscribe to.
32
+ - `callback` - The callback function that will be called when the event occurs.
33
+
34
+ **Returns:**
35
+ - An event subscription that can be used to unsubscribe.
36
+
37
+ **Example:**
38
+ ***typescript
39
+ // Subscribe to page changes
40
+ const subscription = createUVESubscription(UVEEventType.CONTENT_CHANGES, (changes) => {
41
+ console.log('Content changes:', changes);
42
+ });
43
+
44
+ // Unsubscribe
45
+
46
+ subscription.unsubscribe()
47
+ ```
48
+
49
+ ---
50
+
51
+ ### `getUVEState`
52
+
53
+ Retrieves the current UVE state.
54
+
55
+ **Returns:**
56
+ - A `UVEState` object if running inside the editor, or `undefined` otherwise.
57
+
58
+ The state includes:
59
+ - `mode`: The current editor mode (preview, edit, live).
60
+ - `languageId`: The language ID of the current page set in the UVE.
61
+ - `persona`: The persona of the current page set in the UVE.
62
+ - `variantName`: The name of the current variant.
63
+ - `experimentId`: The ID of the current experiment.
64
+ - `publishDate`: The publish date of the current page set in the UVE.
65
+
66
+ > **Note:** If any of these properties are absent, it means the value is the default one.
67
+
68
+ **Example:**
69
+ ```typescript
70
+ const editorState = getUVEState();
71
+ if (editorState?.mode === 'edit') {
72
+ // Enable editing features
73
+ }
74
+ ```
75
+
76
+ ---
77
+
78
+ ### `editContentlet`
79
+
80
+ Allows you to edit a contentlet in the editor.
81
+
82
+ Calling this function within the editor prompts the UVE to open a dialog to edit the specified contentlet.
83
+
84
+ **Parameters:**
85
+ - `contentlet<T>` - The contentlet to edit.
86
+
87
+ **Example:**
88
+ ```typescript
89
+ editContentlet(myContentlet);
90
+ ```
91
+
92
+ ---
93
+
94
+ ### `reorderMenu`
95
+
96
+ Reorders the menu based on the provided configuration.
97
+
98
+ **Parameters:**
99
+ - `config` (optional): Configuration for reordering the menu.
100
+ - `startLevel` (default: `1`): The starting level of the menu to reorder.
101
+ - `depth` (default: `2`): The depth of the menu to reorder.
102
+
103
+ This function constructs a URL for the reorder menu page with the specified `startLevel` and `depth`, then sends a message to the editor to perform the reorder action.
104
+
105
+ **Example:**
106
+ ```typescript
107
+ reorderMenu({ startLevel: 2, depth: 3 });
108
+ ```
109
+
110
+ ---
111
+
112
+ ### `initInlineEditing`
113
+
114
+ Initializes inline editing in the editor.
115
+
116
+ **Example:**
117
+ ```typescript
118
+ initInlineEditing();
119
+ ```
120
+
121
+ ---
122
+
123
+ ### `sendMessageToUVE`
124
+
125
+ The `sendMessageToUVE` function allows you to send messages to the dotCMS page editor. This is useful for triggering specific actions or updating the editor's state.
126
+
127
+ This function is primarily used within other libraries but can be helpful if you need to trigger specific behavior by sending a message to the UVE.
128
+
129
+ **Example:**
130
+ ```typescript
131
+ sendMessageToEditor({ type: 'CUSTOM_MESSAGE': DotCMSUVEAction, payload: { key: 'value' } });
132
+ ```
133
+
134
+ ### Available Message Types (DotCMSUVEAction)
135
+
136
+ | **Type** | **Description** |
137
+ |--------------------------------------|---------------------------------------------------------------------------------------------------|
138
+ | `set-url` | Notifies the dotCMS editor that the page has changed. |
139
+ | `set-bounds` | Sends the position of rows, columns, containers, and contentlets to the editor. |
140
+ | `set-contentlet` | Sends information about the currently hovered contentlet. |
141
+ | `scroll` | Informs the editor that the page is being scrolled. |
142
+ | `scroll-end` | Notifies the editor that scrolling has stopped.
143
+ | `init-inline-editing` | Initializes the inline editing mode in the editor. |
144
+ | `copy-contentlet-inline-editing` | Opens the "Copy Contentlet" dialog to duplicate and edit a contentlet inline. |
145
+ | `update-contentlet-inline-editing` | Triggers the save action for inline-edited contentlets. |
146
+ | `reorder-menu` | Triggers the menu reorder action with a specified configuration. |
147
+ | `get-page-data` | Requests the current page information from the editor. |
148
+ | `client-ready` | Indicates that the client has sent a GraphQL query to the editor. |
149
+ | `edit-contentlet` | Opens the contentlet editing dialog in the editor. |
package/index.cjs.js CHANGED
@@ -93,7 +93,7 @@ function createUVESubscription(eventType, callback) {
93
93
  * @template T
94
94
  * @param {DotCMSUVEMessage<T>} message
95
95
  */
96
- function sendMessageToEditor(message) {
96
+ function sendMessageToUVE(message) {
97
97
  window.parent.postMessage(message, '*');
98
98
  }
99
99
  /**
@@ -106,7 +106,7 @@ function sendMessageToEditor(message) {
106
106
  * @param {Contentlet<T>} contentlet - The contentlet to edit.
107
107
  */
108
108
  function editContentlet(contentlet) {
109
- sendMessageToEditor({
109
+ sendMessageToUVE({
110
110
  action: types.DotCMSUVEAction.EDIT_CONTENTLET,
111
111
  payload: contentlet
112
112
  });
@@ -126,7 +126,7 @@ function reorderMenu(config) {
126
126
  startLevel = 1,
127
127
  depth = 2
128
128
  } = config || {};
129
- sendMessageToEditor({
129
+ sendMessageToUVE({
130
130
  action: types.DotCMSUVEAction.REORDER_MENU,
131
131
  payload: {
132
132
  startLevel,
@@ -150,7 +150,7 @@ function reorderMenu(config) {
150
150
  * ```
151
151
  */
152
152
  function initInlineEditing(type, data) {
153
- sendMessageToEditor({
153
+ sendMessageToUVE({
154
154
  action: types.DotCMSUVEAction.INIT_INLINE_EDITING,
155
155
  payload: {
156
156
  type,
@@ -164,4 +164,4 @@ exports.editContentlet = editContentlet;
164
164
  exports.getUVEState = getUVEState;
165
165
  exports.initInlineEditing = initInlineEditing;
166
166
  exports.reorderMenu = reorderMenu;
167
- exports.sendMessageToEditor = sendMessageToEditor;
167
+ exports.sendMessageToUVE = sendMessageToUVE;
package/index.esm.js CHANGED
@@ -91,7 +91,7 @@ function createUVESubscription(eventType, callback) {
91
91
  * @template T
92
92
  * @param {DotCMSUVEMessage<T>} message
93
93
  */
94
- function sendMessageToEditor(message) {
94
+ function sendMessageToUVE(message) {
95
95
  window.parent.postMessage(message, '*');
96
96
  }
97
97
  /**
@@ -104,7 +104,7 @@ function sendMessageToEditor(message) {
104
104
  * @param {Contentlet<T>} contentlet - The contentlet to edit.
105
105
  */
106
106
  function editContentlet(contentlet) {
107
- sendMessageToEditor({
107
+ sendMessageToUVE({
108
108
  action: DotCMSUVEAction.EDIT_CONTENTLET,
109
109
  payload: contentlet
110
110
  });
@@ -124,7 +124,7 @@ function reorderMenu(config) {
124
124
  startLevel = 1,
125
125
  depth = 2
126
126
  } = config || {};
127
- sendMessageToEditor({
127
+ sendMessageToUVE({
128
128
  action: DotCMSUVEAction.REORDER_MENU,
129
129
  payload: {
130
130
  startLevel,
@@ -148,7 +148,7 @@ function reorderMenu(config) {
148
148
  * ```
149
149
  */
150
150
  function initInlineEditing(type, data) {
151
- sendMessageToEditor({
151
+ sendMessageToUVE({
152
152
  action: DotCMSUVEAction.INIT_INLINE_EDITING,
153
153
  payload: {
154
154
  type,
@@ -157,4 +157,4 @@ function initInlineEditing(type, data) {
157
157
  });
158
158
  }
159
159
 
160
- export { createUVESubscription, editContentlet, getUVEState, initInlineEditing, reorderMenu, sendMessageToEditor };
160
+ export { createUVESubscription, editContentlet, getUVEState, initInlineEditing, reorderMenu, sendMessageToUVE };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/uve",
3
- "version": "0.0.1-beta.12",
3
+ "version": "0.0.1-beta.13",
4
4
  "description": "Official JavaScript library for interacting with Universal Visual Editor (UVE)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,7 +8,7 @@ import { DotCMSInlineEditingPayload, DotCMSInlineEditingType } from '../types/ev
8
8
  * @template T
9
9
  * @param {DotCMSUVEMessage<T>} message
10
10
  */
11
- export declare function sendMessageToEditor<T = unknown>(message: DotCMSUVEMessage<T>): void;
11
+ export declare function sendMessageToUVE<T = unknown>(message: DotCMSUVEMessage<T>): void;
12
12
  /**
13
13
  * You can use this function to edit a contentlet in the editor.
14
14
  *
@@ -1,4 +1,46 @@
1
+ /**
2
+ * Sets up scroll event handlers for the window to notify the editor about scroll events.
3
+ * Adds listeners for both 'scroll' and 'scrollend' events, sending appropriate messages
4
+ * to the editor when these events occur.
5
+ */
1
6
  export declare function scrollHandler(): void;
7
+ /**
8
+ * Adds 'empty-contentlet' class to contentlet elements that have no height.
9
+ * This helps identify and style empty contentlets in the editor view.
10
+ *
11
+ * @remarks
12
+ * The function queries all elements with data-dot-object="contentlet" attribute
13
+ * and checks their clientHeight. If an element has no height (clientHeight = 0),
14
+ * it adds the 'empty-contentlet' class to that element.
15
+ */
2
16
  export declare function addClassToEmptyContentlets(): void;
17
+ /**
18
+ * Registers event handlers for various UVE (Universal Visual Editor) events.
19
+ *
20
+ * This function sets up subscriptions for:
21
+ * - Page reload events that refresh the window
22
+ * - Bounds request events to update editor boundaries
23
+ * - Iframe scroll events to handle smooth scrolling within bounds
24
+ * - Contentlet hover events to notify the editor
25
+ *
26
+ * @remarks
27
+ * For scroll events, the function includes logic to prevent scrolling beyond
28
+ * the top or bottom boundaries of the iframe, which helps maintain proper
29
+ * scroll event handling.
30
+ */
3
31
  export declare function registerUVEEvents(): void;
32
+ /**
33
+ * Notifies the editor that the UVE client is ready to receive messages.
34
+ *
35
+ * This function sends a message to the editor indicating that the client-side
36
+ * initialization is complete and it's ready to handle editor interactions.
37
+ *
38
+ * @remarks
39
+ * This is typically called after all UVE event handlers and DOM listeners
40
+ * have been set up successfully.
41
+ */
4
42
  export declare function setClientIsReady(): void;
43
+ /**
44
+ * Listen for block editor inline event.
45
+ */
46
+ export declare const listenBlockEditorInlineEvent: () => void;