@dotcms/uve 0.0.1-beta.2 → 0.0.1-beta.21

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.
Files changed (40) hide show
  1. package/README.md +321 -4
  2. package/index.cjs.d.ts +1 -1
  3. package/index.cjs.js +10 -54
  4. package/index.cjs2.js +1151 -0
  5. package/index.esm.d.ts +1 -1
  6. package/index.esm.js +2 -56
  7. package/index.esm2.js +1119 -0
  8. package/internal.cjs.d.ts +1 -0
  9. package/internal.cjs.default.js +1 -0
  10. package/internal.cjs.js +39 -0
  11. package/internal.cjs.mjs +2 -0
  12. package/internal.esm.d.ts +1 -0
  13. package/internal.esm.js +2 -0
  14. package/package.json +26 -7
  15. package/src/index.d.ts +2 -0
  16. package/src/internal/constants.d.ts +76 -0
  17. package/src/internal/events.d.ts +66 -0
  18. package/src/internal/index.d.ts +1 -0
  19. package/src/internal.d.ts +6 -0
  20. package/src/lib/{utils.d.ts → core/core.utils.d.ts} +20 -1
  21. package/src/lib/dom/dom.utils.d.ts +206 -0
  22. package/src/lib/editor/internal.d.ts +23 -0
  23. package/src/lib/editor/public.d.ts +62 -0
  24. package/src/lib/types/block-editor-renderer/internal.d.ts +46 -0
  25. package/src/lib/types/block-editor-renderer/public.d.ts +38 -0
  26. package/src/lib/types/editor/internal.d.ts +119 -0
  27. package/src/lib/types/editor/public.d.ts +271 -0
  28. package/src/lib/types/events/internal.d.ts +34 -0
  29. package/src/lib/types/events/public.d.ts +18 -0
  30. package/src/lib/types/page/public.d.ts +485 -0
  31. package/src/script/sdk-editor.d.ts +6 -0
  32. package/src/script/utils.d.ts +53 -0
  33. package/src/types.d.ts +4 -0
  34. package/types.cjs.d.ts +1 -1
  35. package/types.cjs.js +97 -4
  36. package/types.esm.d.ts +1 -1
  37. package/types.esm.js +98 -5
  38. package/src/lib/types.d.ts +0 -33
  39. package/src/public/index.d.ts +0 -2
  40. package/src/public/types.d.ts +0 -2
@@ -0,0 +1,119 @@
1
+ import { DotCMSUVEAction } from './public';
2
+ /**
3
+ * @description Custom client parameters for fetching data.
4
+ */
5
+ export type DotCMSCustomerParams = {
6
+ depth: string;
7
+ };
8
+ /**
9
+ * Configuration for reordering a menu.
10
+ */
11
+ export interface DotCMSReorderMenuConfig {
12
+ /**
13
+ * The starting level of the menu to be reordered.
14
+ */
15
+ startLevel: number;
16
+ /**
17
+ * The depth of the menu levels to be reordered.
18
+ */
19
+ depth: number;
20
+ }
21
+ declare global {
22
+ interface Window {
23
+ dotCMSUVE: DotCMSUVE;
24
+ }
25
+ }
26
+ /**
27
+ * Post message props
28
+ *
29
+ * @export
30
+ * @template T
31
+ * @interface DotCMSUVEMessage
32
+ */
33
+ export type DotCMSUVEMessage<T> = {
34
+ action: DotCMSUVEAction;
35
+ payload?: T;
36
+ };
37
+ type DotCMSUVEFunction = (...args: any[]) => void;
38
+ export interface DotCMSUVE {
39
+ editContentlet: DotCMSUVEFunction;
40
+ initInlineEditing: DotCMSUVEFunction;
41
+ reorderMenu: DotCMSUVEFunction;
42
+ lastScrollYPosition: number;
43
+ }
44
+ /**
45
+ * Main fields of a Contentlet (Inherited from the Content Type).
46
+ */
47
+ export interface ContentTypeMainFields {
48
+ hostName: string;
49
+ modDate: string;
50
+ publishDate: string;
51
+ title: string;
52
+ baseType: string;
53
+ inode: string;
54
+ archived: boolean;
55
+ ownerName: string;
56
+ host: string;
57
+ working: boolean;
58
+ locked: boolean;
59
+ stInode: string;
60
+ contentType: string;
61
+ live: boolean;
62
+ owner: string;
63
+ identifier: string;
64
+ publishUserName: string;
65
+ publishUser: string;
66
+ languageId: number;
67
+ creationDate: string;
68
+ url: string;
69
+ titleImage: string;
70
+ modUserName: string;
71
+ hasLiveVersion: boolean;
72
+ folder: string;
73
+ hasTitleImage: boolean;
74
+ sortOrder: number;
75
+ modUser: string;
76
+ __icon__: string;
77
+ contentTypeIcon: string;
78
+ variant: string;
79
+ }
80
+ /**
81
+ * Bound information for a contentlet.
82
+ *
83
+ * @interface ContentletBound
84
+ * Bound information for a contentlet.
85
+ *
86
+ * @interface DotCMSContentletBound
87
+ * @property {number} x - The x-coordinate of the contentlet.
88
+ * @property {number} y - The y-coordinate of the contentlet.
89
+ * @property {number} width - The width of the contentlet.
90
+ * @property {number} height - The height of the contentlet.
91
+ * @property {string} payload - The payload data of the contentlet in JSON format.
92
+ */
93
+ export interface DotCMSContentletBound {
94
+ x: number;
95
+ y: number;
96
+ width: number;
97
+ height: number;
98
+ payload: string;
99
+ }
100
+ /**
101
+ * Bound information for a container.
102
+ *
103
+ * @interface DotCMSContainerBound
104
+ * @property {number} x - The x-coordinate of the container.
105
+ * @property {number} y - The y-coordinate of the container.
106
+ * @property {number} width - The width of the container.
107
+ * @property {number} height - The height of the container.
108
+ * @property {string} payload - The payload data of the container in JSON format.
109
+ * @property {DotCMSContentletBound[]} contentlets - An array of contentlets within the container.
110
+ */
111
+ export interface DotCMSContainerBound {
112
+ x: number;
113
+ y: number;
114
+ width: number;
115
+ height: number;
116
+ payload: string;
117
+ contentlets: DotCMSContentletBound[];
118
+ }
119
+ export {};
@@ -0,0 +1,271 @@
1
+ import { ContentTypeMainFields, DotCMSContainerBound } from './internal';
2
+ import { DEVELOPMENT_MODE, PRODUCTION_MODE } from '../../../internal';
3
+ import { DotCMSBasicGraphQLPage, DotCMSPageAsset } from '../page/public';
4
+ /**
5
+ * Represents the state of the Universal Visual Editor (UVE)
6
+ * @interface
7
+ * @property {UVE_MODE} mode - The current mode of operation for UVE (EDIT, PREVIEW, LIVE, or UNKNOWN)
8
+ * @property {string | null} persona - The selected persona for content personalization
9
+ * @property {string | null} variantName - The name of the current content variant
10
+ * @property {string | null} experimentId - The identifier for the current A/B testing experiment
11
+ * @property {string | null} publishDate - The scheduled publish date for content
12
+ * @property {string | null} languageId - The identifier for the current language selection
13
+ */
14
+ export interface UVEState {
15
+ mode: UVE_MODE;
16
+ persona: string | null;
17
+ variantName: string | null;
18
+ experimentId: string | null;
19
+ publishDate: string | null;
20
+ languageId: string | null;
21
+ }
22
+ /**
23
+ * The mode of the page renderer component
24
+ * @enum {string}
25
+ */
26
+ export type DotCMSPageRendererMode = typeof PRODUCTION_MODE | typeof DEVELOPMENT_MODE;
27
+ /**
28
+ * Possible modes of UVE (Universal Visual Editor)
29
+ * @enum {string}
30
+ *
31
+ * @property {string} LIVE - Shows published and future content
32
+ * @property {string} PREVIEW - Shows published and working content
33
+ * @property {string} EDIT - Enables content editing functionality in UVE
34
+ * @property {string} UNKNOWN - Error state, UVE should not remain in this mode
35
+ */
36
+ export declare enum UVE_MODE {
37
+ EDIT = "EDIT_MODE",
38
+ PREVIEW = "PREVIEW_MODE",
39
+ LIVE = "LIVE",
40
+ UNKNOWN = "UNKNOWN"
41
+ }
42
+ /**
43
+ * Callback function for UVE events
44
+ * @callback UVEEventHandler
45
+ * @param {unknown} eventData - The event data
46
+ */
47
+ export type UVEEventHandler = (eventData?: unknown) => void;
48
+ /**
49
+ * Unsubscribe function for UVE events
50
+ * @callback UVEUnsubscribeFunction
51
+ */
52
+ export type UVEUnsubscribeFunction = () => void;
53
+ /**
54
+ * UVE event subscription type
55
+ * @typedef {Object} UVEEventSubscription
56
+ * @property {UVEUnsubscribeFunction} unsubscribe - The unsubscribe function for the UVE event
57
+ * @property {string} event - The event name
58
+ */
59
+ export type UVEEventSubscription = {
60
+ unsubscribe: UVEUnsubscribeFunction;
61
+ event: string;
62
+ };
63
+ /**
64
+ * UVE event type
65
+ * @typedef {function} UVEEventSubscriber
66
+ */
67
+ export type UVEEventSubscriber = (callback: UVEEventHandler) => UVEEventSubscription;
68
+ /**
69
+ * Configuration type for DotCMS Editor
70
+ * @typedef {Object} DotCMSEditoConfig
71
+ * @property {Object} [params] - Parameters for Page API configuration
72
+ * @property {number} [params.depth] - The depth level for fetching page data
73
+ * @property {string} [query] - GraphQL query string for data fetching
74
+ */
75
+ export type DotCMSEditorConfig = {
76
+ params: {
77
+ depth: number;
78
+ };
79
+ } | {
80
+ query: string;
81
+ };
82
+ /**
83
+ * Actions send to the dotcms editor
84
+ *
85
+ * @export
86
+ * @enum {number}
87
+ */
88
+ export declare enum DotCMSUVEAction {
89
+ /**
90
+ * Tell the dotcms editor that page change
91
+ */
92
+ NAVIGATION_UPDATE = "set-url",
93
+ /**
94
+ * Send the element position of the rows, columnsm containers and contentlets
95
+ */
96
+ SET_BOUNDS = "set-bounds",
97
+ /**
98
+ * Send the information of the hovered contentlet
99
+ */
100
+ SET_CONTENTLET = "set-contentlet",
101
+ /**
102
+ * Tell the editor that the page is being scrolled
103
+ */
104
+ IFRAME_SCROLL = "scroll",
105
+ /**
106
+ * Tell the editor that the page has stopped scrolling
107
+ */
108
+ IFRAME_SCROLL_END = "scroll-end",
109
+ /**
110
+ * Ping the editor to see if the page is inside the editor
111
+ */
112
+ PING_EDITOR = "ping-editor",
113
+ /**
114
+ * Tell the editor to init the inline editing editor.
115
+ */
116
+ INIT_INLINE_EDITING = "init-inline-editing",
117
+ /**
118
+ * Tell the editor to open the Copy-contentlet dialog
119
+ * To copy a content and then edit it inline.
120
+ */
121
+ COPY_CONTENTLET_INLINE_EDITING = "copy-contentlet-inline-editing",
122
+ /**
123
+ * Tell the editor to save inline edited contentlet
124
+ */
125
+ UPDATE_CONTENTLET_INLINE_EDITING = "update-contentlet-inline-editing",
126
+ /**
127
+ * Tell the editor to trigger a menu reorder
128
+ */
129
+ REORDER_MENU = "reorder-menu",
130
+ /**
131
+ * Tell the editor to send the page info to iframe
132
+ */
133
+ GET_PAGE_DATA = "get-page-data",
134
+ /**
135
+ * Tell the editor an user send a graphql query
136
+ */
137
+ CLIENT_READY = "client-ready",
138
+ /**
139
+ * Tell the editor to edit a contentlet
140
+ */
141
+ EDIT_CONTENTLET = "edit-contentlet",
142
+ /**
143
+ * Tell the editor to do nothing
144
+ */
145
+ NOOP = "noop"
146
+ }
147
+ /**
148
+ * The contentlet has the main fields and the custom fields of the content type.
149
+ *
150
+ * @template T - The custom fields of the content type.
151
+ */
152
+ export type Contentlet<T> = T & ContentTypeMainFields;
153
+ /**
154
+ * Available events in the Universal Visual Editor
155
+ * @enum {string}
156
+ */
157
+ export declare enum UVEEventType {
158
+ /**
159
+ * Triggered when page data changes from the editor
160
+ */
161
+ CONTENT_CHANGES = "changes",
162
+ /**
163
+ * Triggered when the page needs to be reloaded
164
+ */
165
+ PAGE_RELOAD = "page-reload",
166
+ /**
167
+ * Triggered when the editor requests container bounds
168
+ */
169
+ REQUEST_BOUNDS = "request-bounds",
170
+ /**
171
+ * Triggered when scroll action is needed inside the iframe
172
+ */
173
+ IFRAME_SCROLL = "iframe-scroll",
174
+ /**
175
+ * Triggered when a contentlet is hovered
176
+ */
177
+ CONTENTLET_HOVERED = "contentlet-hovered"
178
+ }
179
+ /**
180
+ * Type definitions for each event's payload
181
+ */
182
+ export type UVEEventPayloadMap = {
183
+ [UVEEventType.CONTENT_CHANGES]: DotCMSEditablePage;
184
+ [UVEEventType.PAGE_RELOAD]: undefined;
185
+ [UVEEventType.REQUEST_BOUNDS]: DotCMSContainerBound[];
186
+ [UVEEventType.IFRAME_SCROLL]: 'up' | 'down';
187
+ [UVEEventType.CONTENTLET_HOVERED]: unknown;
188
+ };
189
+ /**
190
+ *
191
+ * Interface representing the data needed for container editing
192
+ * @interface EditableContainerData
193
+ */
194
+ export interface EditableContainerData {
195
+ uuid: string;
196
+ identifier: string;
197
+ acceptTypes: string;
198
+ maxContentlets: number;
199
+ variantId?: string;
200
+ }
201
+ /**
202
+ *
203
+ * Interface representing the data attributes of a DotCMS container.
204
+ * @interface DotContainerAttributes
205
+ */
206
+ export interface DotContainerAttributes {
207
+ 'data-dot-object': string;
208
+ 'data-dot-accept-types': string;
209
+ 'data-dot-identifier': string;
210
+ 'data-max-contentlets': string;
211
+ 'data-dot-uuid': string;
212
+ }
213
+ /**
214
+ *
215
+ * Interface representing the data attributes of a DotCMS contentlet.
216
+ * @interface DotContentletAttributes
217
+ */
218
+ export interface DotContentletAttributes {
219
+ 'data-dot-identifier': string;
220
+ 'data-dot-basetype': string;
221
+ 'data-dot-title': string;
222
+ 'data-dot-inode': string;
223
+ 'data-dot-type': string;
224
+ 'data-dot-container': string;
225
+ 'data-dot-on-number-of-pages': string;
226
+ }
227
+ /**
228
+ * Represents a GraphQL error
229
+ * @interface DotCMSGraphQLError
230
+ */
231
+ export interface DotCMSGraphQLError {
232
+ message: string;
233
+ locations: {
234
+ line: number;
235
+ column: number;
236
+ }[];
237
+ extensions: {
238
+ classification: string;
239
+ };
240
+ }
241
+ /**
242
+ * Represents the complete response from a GraphQL page query
243
+ *
244
+ * @template TContent - The type of the content data
245
+ * @template TNav - The type of the navigation data
246
+ */
247
+ export interface DotCMSGraphQLPageResponse<TContent = Record<string, any>> {
248
+ page: DotCMSBasicGraphQLPage;
249
+ content?: TContent;
250
+ errors?: DotCMSGraphQLError;
251
+ graphql: {
252
+ query: string;
253
+ variables: Record<string, unknown>;
254
+ };
255
+ }
256
+ /**
257
+ * Payload for initializing the UVE
258
+ * @interface DotCMSEditablePage
259
+ */
260
+ export type DotCMSEditablePage = DotCMSGraphQLPageResponse | DotCMSPageAsset;
261
+ /**
262
+ * Configuration for the UVE
263
+ * @interface DotCMSUVEConfig
264
+ */
265
+ export interface DotCMSUVEConfig {
266
+ graphql?: {
267
+ query: string;
268
+ variables: Record<string, unknown>;
269
+ };
270
+ params?: Record<string, unknown>;
271
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Actions received from the dotcms editor
3
+ *
4
+ * @export
5
+ * @enum {number}
6
+ */
7
+ export declare enum __DOTCMS_UVE_EVENT__ {
8
+ /**
9
+ * Request to page to reload
10
+ */
11
+ UVE_RELOAD_PAGE = "uve-reload-page",
12
+ /**
13
+ * Request the bounds for the elements
14
+ */
15
+ UVE_REQUEST_BOUNDS = "uve-request-bounds",
16
+ /**
17
+ * Received pong from the editor
18
+ */
19
+ UVE_EDITOR_PONG = "uve-editor-pong",
20
+ /**
21
+ * Received scroll event trigger from the editor
22
+ */
23
+ UVE_SCROLL_INSIDE_IFRAME = "uve-scroll-inside-iframe",
24
+ /**
25
+ * TODO:
26
+ * Set the page data - This is used to catch the "changes" event.
27
+ * We must to re-check the name late.
28
+ */
29
+ UVE_SET_PAGE_DATA = "uve-set-page-data",
30
+ /**
31
+ * Copy contentlet inline editing success
32
+ */
33
+ UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS = "uve-copy-contentlet-inline-editing-success"
34
+ }
@@ -0,0 +1,18 @@
1
+ export type DotCMSInlineEditingType = 'BLOCK_EDITOR' | 'WYSIWYG';
2
+ /**
3
+ * Interface representing the data needed for inline editing in DotCMS
4
+ *
5
+ * @interface DotCMSInlineEditorData
6
+ * @property {string} inode - The inode identifier of the content being edited
7
+ * @property {number} language - The language ID of the content
8
+ * @property {string} contentType - The content type identifier
9
+ * @property {string} fieldName - The name of the field being edited
10
+ * @property {Record<string, unknown>} content - The content data as key-value pairs
11
+ */
12
+ export interface DotCMSInlineEditingPayload {
13
+ inode: string;
14
+ language: number;
15
+ contentType: string;
16
+ fieldName: string;
17
+ content: Record<string, unknown>;
18
+ }