@dotcms/client 0.0.1-alpha.11 → 0.0.1-alpha.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.
Files changed (38) hide show
  1. package/package.json +26 -24
  2. package/src/index.js +5 -0
  3. package/src/index.js.map +1 -0
  4. package/src/lib/client/{sdk-js-client.ts → sdk-js-client.d.ts} +13 -121
  5. package/src/lib/client/sdk-js-client.js +148 -0
  6. package/src/lib/client/sdk-js-client.js.map +1 -0
  7. package/src/lib/editor/listeners/listeners.d.ts +46 -0
  8. package/src/lib/editor/listeners/{listeners.ts → listeners.js} +38 -61
  9. package/src/lib/editor/listeners/listeners.js.map +1 -0
  10. package/src/lib/editor/models/{client.model.ts → client.model.d.ts} +13 -13
  11. package/src/lib/editor/models/client.model.js +45 -0
  12. package/src/lib/editor/models/client.model.js.map +1 -0
  13. package/src/lib/editor/models/{editor.model.ts → editor.model.d.ts} +0 -1
  14. package/src/lib/editor/models/editor.model.js +2 -0
  15. package/src/lib/editor/models/editor.model.js.map +1 -0
  16. package/src/lib/editor/models/{listeners.model.ts → listeners.model.d.ts} +5 -8
  17. package/src/lib/editor/models/listeners.model.js +22 -0
  18. package/src/lib/editor/models/listeners.model.js.map +1 -0
  19. package/src/lib/editor/sdk-editor-vtl.d.ts +6 -0
  20. package/src/lib/editor/{sdk-editor-vtl.ts → sdk-editor-vtl.js} +2 -14
  21. package/src/lib/editor/sdk-editor-vtl.js.map +1 -0
  22. package/src/lib/editor/sdk-editor.d.ts +23 -0
  23. package/src/lib/editor/{sdk-editor.ts → sdk-editor.js} +7 -21
  24. package/src/lib/editor/sdk-editor.js.map +1 -0
  25. package/src/lib/editor/utils/editor.utils.d.ts +82 -0
  26. package/src/lib/editor/utils/{editor.utils.ts → editor.utils.js} +25 -75
  27. package/src/lib/editor/utils/editor.utils.js.map +1 -0
  28. package/.eslintrc.json +0 -18
  29. package/jest.config.ts +0 -15
  30. package/project.json +0 -63
  31. package/src/lib/client/sdk-js-client.spec.ts +0 -258
  32. package/src/lib/editor/listeners/listeners.spec.ts +0 -58
  33. package/src/lib/editor/sdk-editor.spec.ts +0 -92
  34. package/src/lib/editor/utils/editor.utils.spec.ts +0 -164
  35. package/tsconfig.json +0 -22
  36. package/tsconfig.lib.json +0 -10
  37. package/tsconfig.spec.json +0 -9
  38. /package/src/{index.ts → index.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listeners.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/editor/listeners/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,OAAO,EAAgC,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EACH,WAAW,EACX,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACtB,MAAM,uBAAuB,CAAC;AAQ/B;;GAEG;AACH,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;AAEvD;;GAEG;AACH,IAAI,gBAAgB,GAA2B;IAC3C,QAAQ,EAAE,eAAe;CAC5B,CAAC;AAEF,MAAM,UAAU,mBAAmB,CAAC,MAA8B;IAC9D,gBAAgB,GAAG,MAAM,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAmC,EAAE,CAAC;AAEhE;;;;;GAKG;AACH,SAAS,SAAS;IACd,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CACzB,QAAQ,CAAC,gBAAgB,CAAC,+BAA+B,CAAC,CACzC,CAAC;IACtB,MAAM,YAAY,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAErD,mBAAmB,CAAC;QAChB,MAAM,EAAE,gBAAgB,CAAC,UAAU;QACnC,OAAO,EAAE,YAAY;KACxB,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,SAAS,UAAU;IAC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AE;QACxB,mBAAmB,CAAC;YAChB,MAAM,EAAE,gBAAgB,CAAC,aAAa;SACzC,CAAC,CAAC;QACH,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC;IAChD,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAElD,aAAa,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,cAAc;KAC3B,CAAC,CAAC;AACP,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB;IAClC,MAAM,sBAAsB,GAAG,GAAG,EAAE;QAChC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACnD,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACxD,aAAa,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,sBAAsB;KACnC,CAAC,CAAC;AACP,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU;IACtB,mBAAmB,CAAC;QAChB,MAAM,EAAE,gBAAgB,CAAC,WAAW;KACvC,CAAC,CAAC;AACP,CAAC"}
@@ -4,31 +4,33 @@
4
4
  * @export
5
5
  * @enum {number}
6
6
  */
7
- export enum CUSTOMER_ACTIONS {
7
+ export declare enum CUSTOMER_ACTIONS {
8
8
  /**
9
9
  * Tell the dotcms editor that page change
10
10
  */
11
- NAVIGATION_UPDATE = 'set-url',
11
+ NAVIGATION_UPDATE = "set-url",
12
12
  /**
13
13
  * Send the element position of the rows, columnsm containers and contentlets
14
14
  */
15
- SET_BOUNDS = 'set-bounds',
15
+ SET_BOUNDS = "set-bounds",
16
16
  /**
17
17
  * Send the information of the hovered contentlet
18
18
  */
19
- SET_CONTENTLET = 'set-contentlet',
19
+ SET_CONTENTLET = "set-contentlet",
20
20
  /**
21
21
  * Tell the editor that the page is being scrolled
22
22
  */
23
- IFRAME_SCROLL = 'scroll',
23
+ IFRAME_SCROLL = "scroll",
24
24
  /**
25
25
  * Ping the editor to see if the page is inside the editor
26
26
  */
27
- PING_EDITOR = 'ping-editor',
28
-
29
- NOOP = 'noop'
27
+ PING_EDITOR = "ping-editor",
28
+ /**
29
+ * Tell the editor to trigger a menu reorder
30
+ */
31
+ REORDER_MENU = "reorder-menu",
32
+ NOOP = "noop"
30
33
  }
31
-
32
34
  /**
33
35
  * Post message props
34
36
  *
@@ -40,7 +42,6 @@ type PostMessageProps<T> = {
40
42
  action: CUSTOMER_ACTIONS;
41
43
  payload?: T;
42
44
  };
43
-
44
45
  /**
45
46
  * Post message to dotcms page editor
46
47
  *
@@ -48,6 +49,5 @@ type PostMessageProps<T> = {
48
49
  * @template T
49
50
  * @param {PostMessageProps<T>} message
50
51
  */
51
- export function postMessageToEditor<T = unknown>(message: PostMessageProps<T>) {
52
- window.parent.postMessage(message, '*');
53
- }
52
+ export declare function postMessageToEditor<T = unknown>(message: PostMessageProps<T>): void;
53
+ export {};
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Actions send to the dotcms editor
3
+ *
4
+ * @export
5
+ * @enum {number}
6
+ */
7
+ export var CUSTOMER_ACTIONS;
8
+ (function (CUSTOMER_ACTIONS) {
9
+ /**
10
+ * Tell the dotcms editor that page change
11
+ */
12
+ CUSTOMER_ACTIONS["NAVIGATION_UPDATE"] = "set-url";
13
+ /**
14
+ * Send the element position of the rows, columnsm containers and contentlets
15
+ */
16
+ CUSTOMER_ACTIONS["SET_BOUNDS"] = "set-bounds";
17
+ /**
18
+ * Send the information of the hovered contentlet
19
+ */
20
+ CUSTOMER_ACTIONS["SET_CONTENTLET"] = "set-contentlet";
21
+ /**
22
+ * Tell the editor that the page is being scrolled
23
+ */
24
+ CUSTOMER_ACTIONS["IFRAME_SCROLL"] = "scroll";
25
+ /**
26
+ * Ping the editor to see if the page is inside the editor
27
+ */
28
+ CUSTOMER_ACTIONS["PING_EDITOR"] = "ping-editor";
29
+ /**
30
+ * Tell the editor to trigger a menu reorder
31
+ */
32
+ CUSTOMER_ACTIONS["REORDER_MENU"] = "reorder-menu";
33
+ CUSTOMER_ACTIONS["NOOP"] = "noop";
34
+ })(CUSTOMER_ACTIONS || (CUSTOMER_ACTIONS = {}));
35
+ /**
36
+ * Post message to dotcms page editor
37
+ *
38
+ * @export
39
+ * @template T
40
+ * @param {PostMessageProps<T>} message
41
+ */
42
+ export function postMessageToEditor(message) {
43
+ window.parent.postMessage(message, '*');
44
+ }
45
+ //# sourceMappingURL=client.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.model.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/editor/models/client.model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAN,IAAY,gBA4BX;AA5BD,WAAY,gBAAgB;IACxB;;OAEG;IACH,iDAA6B,CAAA;IAC7B;;OAEG;IACH,6CAAyB,CAAA;IACzB;;OAEG;IACH,qDAAiC,CAAA;IACjC;;OAEG;IACH,4CAAwB,CAAA;IACxB;;OAEG;IACH,+CAA2B,CAAA;IAE3B;;OAEG;IACH,iDAA6B,CAAA;IAE7B,iCAAa,CAAA;AACjB,CAAC,EA5BW,gBAAgB,KAAhB,gBAAgB,QA4B3B;AAcD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAc,OAA4B;IACzE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC"}
@@ -9,7 +9,6 @@ export interface DotCMSPageEditorConfig {
9
9
  * A callback function that will be called when the page editor needs to be reloaded.
10
10
  */
11
11
  onReload: () => void;
12
-
13
12
  /**
14
13
  * The pathname of the page being edited. Optional.
15
14
  */
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=editor.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor.model.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/editor/models/editor.model.ts"],"names":[],"mappings":""}
@@ -4,24 +4,22 @@
4
4
  * @export
5
5
  * @enum {number}
6
6
  */
7
- export enum NOTIFY_CUSTOMER {
7
+ export declare enum NOTIFY_CUSTOMER {
8
8
  /**
9
9
  * Request to page to reload
10
10
  */
11
- EMA_RELOAD_PAGE = 'ema-reload-page',
11
+ EMA_RELOAD_PAGE = "ema-reload-page",
12
12
  /**
13
13
  * Request the bounds for the elements
14
14
  */
15
- EMA_REQUEST_BOUNDS = 'ema-request-bounds',
15
+ EMA_REQUEST_BOUNDS = "ema-request-bounds",
16
16
  /**
17
17
  * Received pong from the editor
18
18
  */
19
- EMA_EDITOR_PONG = 'ema-editor-pong'
19
+ EMA_EDITOR_PONG = "ema-editor-pong"
20
20
  }
21
-
22
21
  type ListenerCallbackMessage = (event: MessageEvent) => void;
23
22
  type ListenerCallbackPointer = (event: PointerEvent) => void;
24
-
25
23
  /**
26
24
  * Listener for the dotcms editor
27
25
  *
@@ -32,7 +30,6 @@ interface DotCMSPageEditorListener {
32
30
  event: string;
33
31
  callback: ListenerCallbackMessage | ListenerCallbackPointer;
34
32
  }
35
-
36
33
  /**
37
34
  * Observer for the dotcms editor
38
35
  *
@@ -42,5 +39,5 @@ interface DotCMSPageEditorObserver {
42
39
  type: 'observer';
43
40
  observer: MutationObserver;
44
41
  }
45
-
46
42
  export type DotCMSPageEditorSubscription = DotCMSPageEditorListener | DotCMSPageEditorObserver;
43
+ export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Actions received from the dotcms editor
3
+ *
4
+ * @export
5
+ * @enum {number}
6
+ */
7
+ export var NOTIFY_CUSTOMER;
8
+ (function (NOTIFY_CUSTOMER) {
9
+ /**
10
+ * Request to page to reload
11
+ */
12
+ NOTIFY_CUSTOMER["EMA_RELOAD_PAGE"] = "ema-reload-page";
13
+ /**
14
+ * Request the bounds for the elements
15
+ */
16
+ NOTIFY_CUSTOMER["EMA_REQUEST_BOUNDS"] = "ema-request-bounds";
17
+ /**
18
+ * Received pong from the editor
19
+ */
20
+ NOTIFY_CUSTOMER["EMA_EDITOR_PONG"] = "ema-editor-pong";
21
+ })(NOTIFY_CUSTOMER || (NOTIFY_CUSTOMER = {}));
22
+ //# sourceMappingURL=listeners.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listeners.model.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/editor/models/listeners.model.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAN,IAAY,eAaX;AAbD,WAAY,eAAe;IACvB;;OAEG;IACH,sDAAmC,CAAA;IACnC;;OAEG;IACH,4DAAyC,CAAA;IACzC;;OAEG;IACH,sDAAmC,CAAA;AACvC,CAAC,EAbW,eAAe,KAAf,eAAe,QAa1B"}
@@ -0,0 +1,6 @@
1
+ declare global {
2
+ interface Window {
3
+ lastScrollYPosition: number;
4
+ }
5
+ }
6
+ export {};
@@ -1,18 +1,5 @@
1
- import {
2
- listenEditorMessages,
3
- listenHoveredContentlet,
4
- pingEditor,
5
- preserveScrollOnIframe,
6
- scrollHandler
7
- } from './listeners/listeners';
1
+ import { listenEditorMessages, listenHoveredContentlet, pingEditor, preserveScrollOnIframe, scrollHandler } from './listeners/listeners';
8
2
  import { isInsideEditor } from './sdk-editor';
9
-
10
- declare global {
11
- interface Window {
12
- lastScrollYPosition: number;
13
- }
14
- }
15
-
16
3
  /**
17
4
  * This is the main entry point for the SDK VTL.
18
5
  * This is added to VTL Script in the EditPage
@@ -30,3 +17,4 @@ if (isInsideEditor()) {
30
17
  preserveScrollOnIframe();
31
18
  listenHoveredContentlet();
32
19
  }
20
+ //# sourceMappingURL=sdk-editor-vtl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-editor-vtl.js","sourceRoot":"","sources":["../../../../../../../libs/sdk/client/src/lib/editor/sdk-editor-vtl.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EACV,sBAAsB,EACtB,aAAa,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAQ9C;;;;;;;;;GASG;AACH,IAAI,cAAc,EAAE,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC;IACb,oBAAoB,EAAE,CAAC;IACvB,aAAa,EAAE,CAAC;IAChB,sBAAsB,EAAE,CAAC;IACzB,uBAAuB,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { DotCMSPageEditorConfig } from './models/editor.model';
2
+ /**
3
+ *
4
+ * Updates the navigation in the editor.
5
+ * @param {string} pathname - The pathname to update the navigation with.
6
+ * @memberof DotCMSPageEditor
7
+ */
8
+ export declare function updateNavigation(pathname: string): void;
9
+ /**
10
+ * Checks if the code is running inside an editor.
11
+ * @returns {boolean} Returns true if the code is running inside an editor, otherwise false.
12
+ */
13
+ export declare function isInsideEditor(): boolean;
14
+ /**
15
+ * Initializes the DotCMS page editor.
16
+ *
17
+ * @param conf - Optional configuration for the editor.
18
+ */
19
+ export declare function initEditor(config?: DotCMSPageEditorConfig): void;
20
+ /**
21
+ * Destroys the editor by removing event listeners and disconnecting observers.
22
+ */
23
+ export declare function destroyEditor(): void;
@@ -1,21 +1,12 @@
1
- import {
2
- listenEditorMessages,
3
- listenHoveredContentlet,
4
- pingEditor,
5
- scrollHandler,
6
- subscriptions,
7
- setPageEditorConfig
8
- } from './listeners/listeners';
1
+ import { listenEditorMessages, listenHoveredContentlet, pingEditor, scrollHandler, setPageEditorConfig, subscriptions } from './listeners/listeners';
9
2
  import { CUSTOMER_ACTIONS, postMessageToEditor } from './models/client.model';
10
- import { DotCMSPageEditorConfig } from './models/editor.model';
11
-
12
3
  /**
13
4
  *
14
5
  * Updates the navigation in the editor.
15
6
  * @param {string} pathname - The pathname to update the navigation with.
16
7
  * @memberof DotCMSPageEditor
17
8
  */
18
- export function updateNavigation(pathname: string) {
9
+ export function updateNavigation(pathname) {
19
10
  postMessageToEditor({
20
11
  action: CUSTOMER_ACTIONS.NAVIGATION_UPDATE,
21
12
  payload: {
@@ -23,46 +14,41 @@ export function updateNavigation(pathname: string) {
23
14
  }
24
15
  });
25
16
  }
26
-
27
17
  /**
28
18
  * Checks if the code is running inside an editor.
29
19
  * @returns {boolean} Returns true if the code is running inside an editor, otherwise false.
30
20
  */
31
21
  export function isInsideEditor() {
32
- if (window.parent === window) {
22
+ if (typeof window === 'undefined') {
33
23
  return false;
34
24
  }
35
-
36
- return true;
25
+ return window.parent !== window;
37
26
  }
38
-
39
27
  /**
40
28
  * Initializes the DotCMS page editor.
41
29
  *
42
30
  * @param conf - Optional configuration for the editor.
43
31
  */
44
- export function initEditor(config?: DotCMSPageEditorConfig) {
32
+ export function initEditor(config) {
45
33
  if (config) {
46
34
  setPageEditorConfig(config);
47
35
  }
48
-
49
36
  pingEditor();
50
37
  listenEditorMessages();
51
38
  listenHoveredContentlet();
52
39
  scrollHandler();
53
40
  }
54
-
55
41
  /**
56
42
  * Destroys the editor by removing event listeners and disconnecting observers.
57
43
  */
58
44
  export function destroyEditor() {
59
45
  subscriptions.forEach((subscription) => {
60
46
  if (subscription.type === 'listener') {
61
- window.removeEventListener(subscription.event, subscription.callback as EventListener);
47
+ window.removeEventListener(subscription.event, subscription.callback);
62
48
  }
63
-
64
49
  if (subscription.type === 'observer') {
65
50
  subscription.observer.disconnect();
66
51
  }
67
52
  });
68
53
  }
54
+ //# sourceMappingURL=sdk-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-editor.js","sourceRoot":"","sources":["../../../../../../../libs/sdk/client/src/lib/editor/sdk-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,oBAAoB,EACpB,uBAAuB,EACvB,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,aAAa,EAChB,MAAM,uBAAuB,CAAC;A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.
3
+ *
4
+ * @interface ContentletBound
5
+ */
6
+ interface ContentletBound {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ payload: string;
12
+ }
13
+ /**
14
+ * Bound information for a container.
15
+ *
16
+ * @interface ContainerBound
17
+ */
18
+ interface ContainerBound {
19
+ x: number;
20
+ y: number;
21
+ width: number;
22
+ height: number;
23
+ payload: string;
24
+ contentlets: ContentletBound[];
25
+ }
26
+ /**
27
+ * Calculates the bounding information for each page element within the given containers.
28
+ *
29
+ * @export
30
+ * @param {HTMLDivElement[]} containers
31
+ * @return {*} An array of objects containing the bounding information for each page element.
32
+ */
33
+ export declare function getPageElementBound(containers: HTMLDivElement[]): ContainerBound[];
34
+ /**
35
+ * An array of objects containing the bounding information for each contentlet inside a container.
36
+ *
37
+ * @export
38
+ * @param {DOMRect} containerRect
39
+ * @param {HTMLDivElement[]} contentlets
40
+ * @return {*}
41
+ */
42
+ export declare function getContentletsBound(containerRect: DOMRect, contentlets: HTMLDivElement[]): ContentletBound[];
43
+ /**
44
+ * Get container data from VTLS.
45
+ *
46
+ * @export
47
+ * @param {HTMLElement} container
48
+ * @return {*}
49
+ */
50
+ export declare function getContainerData(container: HTMLElement): {
51
+ acceptTypes: string;
52
+ identifier: string;
53
+ maxContentlets: string;
54
+ uuid: string;
55
+ };
56
+ /**
57
+ * Get the closest container data from the contentlet.
58
+ *
59
+ * @export
60
+ * @param {Element} element
61
+ * @return {*}
62
+ */
63
+ export declare function getClosestContainerData(element: Element): {
64
+ acceptTypes: string;
65
+ identifier: string;
66
+ maxContentlets: string;
67
+ uuid: string;
68
+ } | null;
69
+ /**
70
+ * Find the closest contentlet element based on HTMLElement.
71
+ *
72
+ * @export
73
+ * @param {(HTMLElement | null)} element
74
+ * @return {*}
75
+ */
76
+ export declare function findDotElement(element: HTMLElement | null): HTMLElement | null;
77
+ export declare function findDotVTLElement(element: HTMLElement | null): HTMLElement | null;
78
+ export declare function findVTLData(target: HTMLElement): {
79
+ inode: string | undefined;
80
+ name: string | undefined;
81
+ }[] | null;
82
+ export {};
@@ -1,37 +1,3 @@
1
- /**
2
- * Bound information for a contentlet.
3
- *
4
- * @interface ContentletBound
5
- */
6
- interface ContentletBound {
7
- x: number;
8
- y: number;
9
- width: number;
10
- height: number;
11
- payload: string;
12
- }
13
-
14
- /**
15
- * Bound information for a container.
16
- *
17
- * @interface ContenainerBound
18
- */
19
- interface ContenainerBound {
20
- x: number;
21
- y: number;
22
- width: number;
23
- height: number;
24
- payload: {
25
- container: {
26
- acceptTypes: string;
27
- identifier: string;
28
- maxContentlets: string;
29
- uuid: string;
30
- };
31
- };
32
- contentlets: ContentletBound[];
33
- }
34
-
35
1
  /**
36
2
  * Calculates the bounding information for each page element within the given containers.
37
3
  *
@@ -39,26 +5,22 @@ interface ContenainerBound {
39
5
  * @param {HTMLDivElement[]} containers
40
6
  * @return {*} An array of objects containing the bounding information for each page element.
41
7
  */
42
- export function getPageElementBound(containers: HTMLDivElement[]): ContenainerBound[] {
8
+ export function getPageElementBound(containers) {
43
9
  return containers.map((container) => {
44
10
  const containerRect = container.getBoundingClientRect();
45
- const contentlets = Array.from(
46
- container.querySelectorAll('[data-dot-object="contentlet"]')
47
- ) as HTMLDivElement[];
48
-
11
+ const contentlets = Array.from(container.querySelectorAll('[data-dot-object="contentlet"]'));
49
12
  return {
50
13
  x: containerRect.x,
51
14
  y: containerRect.y,
52
15
  width: containerRect.width,
53
16
  height: containerRect.height,
54
- payload: {
17
+ payload: JSON.stringify({
55
18
  container: getContainerData(container)
56
- },
19
+ }),
57
20
  contentlets: getContentletsBound(containerRect, contentlets)
58
21
  };
59
22
  });
60
23
  }
61
-
62
24
  /**
63
25
  * An array of objects containing the bounding information for each contentlet inside a container.
64
26
  *
@@ -67,13 +29,9 @@ export function getPageElementBound(containers: HTMLDivElement[]): ContenainerBo
67
29
  * @param {HTMLDivElement[]} contentlets
68
30
  * @return {*}
69
31
  */
70
- export function getContentletsBound(
71
- containerRect: DOMRect,
72
- contentlets: HTMLDivElement[]
73
- ): ContentletBound[] {
32
+ export function getContentletsBound(containerRect, contentlets) {
74
33
  return contentlets.map((contentlet) => {
75
34
  const contentletRect = contentlet.getBoundingClientRect();
76
-
77
35
  return {
78
36
  x: 0,
79
37
  y: contentletRect.y - containerRect.y,
@@ -93,7 +51,6 @@ export function getContentletsBound(
93
51
  };
94
52
  });
95
53
  }
96
-
97
54
  /**
98
55
  * Get container data from VTLS.
99
56
  *
@@ -101,7 +58,7 @@ export function getContentletsBound(
101
58
  * @param {HTMLElement} container
102
59
  * @return {*}
103
60
  */
104
- export function getContainerData(container: HTMLElement) {
61
+ export function getContainerData(container) {
105
62
  return {
106
63
  acceptTypes: container.dataset?.['dotAcceptTypes'] || '',
107
64
  identifier: container.dataset?.['dotIdentifier'] || '',
@@ -109,7 +66,6 @@ export function getContainerData(container: HTMLElement) {
109
66
  uuid: container.dataset?.['dotUuid'] || ''
110
67
  };
111
68
  }
112
-
113
69
  /**
114
70
  * Get the closest container data from the contentlet.
115
71
  *
@@ -117,22 +73,20 @@ export function getContainerData(container: HTMLElement) {
117
73
  * @param {Element} element
118
74
  * @return {*}
119
75
  */
120
- export function getClosestContainerData(element: Element) {
76
+ export function getClosestContainerData(element) {
121
77
  // Find the closest ancestor element with data-dot-object="container" attribute
122
- const container = element.closest('[data-dot-object="container"]') as HTMLElement;
123
-
78
+ const container = element.closest('[data-dot-object="container"]');
124
79
  // If a container element is found
125
80
  if (container) {
126
81
  // Return the dataset of the container element
127
82
  return getContainerData(container);
128
- } else {
83
+ }
84
+ else {
129
85
  // If no container element is found, return null
130
86
  console.warn('No container found for the contentlet');
131
-
132
87
  return null;
133
88
  }
134
89
  }
135
-
136
90
  /**
137
91
  * Find the closest contentlet element based on HTMLElement.
138
92
  *
@@ -140,35 +94,30 @@ export function getClosestContainerData(element: Element) {
140
94
  * @param {(HTMLElement | null)} element
141
95
  * @return {*}
142
96
  */
143
- export function findContentletElement(element: HTMLElement | null): HTMLElement | null {
144
- if (!element) return null;
145
-
146
- if (element.dataset && element.dataset?.['dotObject'] === 'contentlet') {
97
+ export function findDotElement(element) {
98
+ if (!element)
99
+ return null;
100
+ if (element?.dataset?.['dotObject'] === 'contentlet' ||
101
+ (element?.dataset?.['dotObject'] === 'container' && element.children.length === 0)) {
147
102
  return element;
148
- } else {
149
- return findContentletElement(element?.['parentElement']);
150
103
  }
104
+ return findDotElement(element?.['parentElement']);
151
105
  }
152
-
153
- export function findVTLElement(element: HTMLElement | null): HTMLElement | null {
154
- if (!element) return null;
155
-
106
+ export function findDotVTLElement(element) {
107
+ if (!element)
108
+ return null;
156
109
  if (element.dataset && element.dataset?.['dotObject'] === 'vtl-file') {
157
110
  return element;
158
- } else {
159
- return findContentletElement(element?.['parentElement']);
111
+ }
112
+ else {
113
+ return findDotElement(element?.['parentElement']);
160
114
  }
161
115
  }
162
-
163
- export function findVTLData(target: HTMLElement) {
164
- const vltElements = target.querySelectorAll(
165
- '[data-dot-object="vtl-file"]'
166
- ) as NodeListOf<HTMLElement>;
167
-
116
+ export function findVTLData(target) {
117
+ const vltElements = target.querySelectorAll('[data-dot-object="vtl-file"]');
168
118
  if (!vltElements.length) {
169
119
  return null;
170
120
  }
171
-
172
121
  return Array.from(vltElements).map((vltElement) => {
173
122
  return {
174
123
  inode: vltElement.dataset?.['dotInode'],
@@ -176,3 +125,4 @@ export function findVTLData(target: HTMLElement) {
176
125
  };
177
126
  });
178
127
  }
128
+ //# sourceMappingURL=editor.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor.utils.js","sourceRoot":"","sources":["../../../../../../../../libs/sdk/client/src/lib/editor/utils/editor.utils.ts"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA4B;IAC5D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QAChC,MAAM,aAAa,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACxD,MAAM,WAAW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AAC;IACnB,CAAC;IAED,OAAO,cAAc,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAA2B;IACzD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE1B,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,KAAK,UAAU,EAAE,CAAC;QACnE,OAAO,OAAO,CAAC;IACnB,CAAC;SAAM,CAAC;QACJ,OAAO,cAAc,CAAC,OAAO,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IACtD,CAAC;AACL,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC3C,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,CACvC,8BAA8B,CACN,CAAC;IAE7B,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAC9C,OAAO;YACH,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC;YACvC,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC;SACvC,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC"}
package/.eslintrc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": ["../../../.eslintrc.base.json"],
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
- "rules": {}
8
- },
9
- {
10
- "files": ["*.ts", "*.tsx"],
11
- "rules": {}
12
- },
13
- {
14
- "files": ["*.js", "*.jsx"],
15
- "rules": {}
16
- }
17
- ]
18
- }
package/jest.config.ts DELETED
@@ -1,15 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: 'sdk-client',
4
- preset: '../../../jest.preset.js',
5
- globals: {
6
- 'ts-jest': {
7
- tsconfig: '<rootDir>/tsconfig.spec.json'
8
- }
9
- },
10
- transform: {
11
- '^.+\\.[tj]s$': 'ts-jest'
12
- },
13
- moduleFileExtensions: ['ts', 'js', 'html'],
14
- coverageDirectory: '../../../coverage/libs/sdk/client'
15
- };