@dotcms/uve 0.0.1-beta.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ # sdk-uve
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test sdk-uve` to execute the unit tests via [Jest](https://jestjs.io).
package/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/public/index";
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/index.cjs.js ADDED
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var types = require('./types.cjs.js');
4
+
5
+ /**
6
+ * Gets the current state of the Universal Visual Editor (UVE).
7
+ *
8
+ * This function checks if the code is running inside the DotCMS Universal Visual Editor
9
+ * and returns information about its current state, including the editor mode.
10
+ *
11
+ * @export
12
+ * @return {UVEState | undefined} Returns the UVE state object if running inside the editor,
13
+ * undefined otherwise.
14
+ *
15
+ * The state includes:
16
+ * - mode: The current editor mode (preview, edit, live)
17
+ * - languageId: The language ID of the current page setted on the UVE
18
+ * - persona: The persona of the current page setted on the UVE
19
+ * - variantName: The name of the current variant
20
+ * - experimentId: The ID of the current experiment
21
+ * - publishDate: The publish date of the current page setted on the UVE
22
+ *
23
+ * @note The absence of any of these properties means that the value is the default one.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const editorState = getUVEState();
28
+ * if (editorState?.mode === 'edit') {
29
+ * // Enable editing features
30
+ * }
31
+ * ```
32
+ */
33
+ function getUVEState() {
34
+ if (typeof window === 'undefined' || window.parent === window || !window.location) {
35
+ return;
36
+ }
37
+ const url = new URL(window.location.href);
38
+ const possibleModes = Object.values(types.UVE_MODE);
39
+ let mode = url.searchParams.get('mode') ?? types.UVE_MODE.EDIT;
40
+ const languageId = url.searchParams.get('language_id');
41
+ const persona = url.searchParams.get('personaId');
42
+ const variantName = url.searchParams.get('variantName');
43
+ const experimentId = url.searchParams.get('experimentId');
44
+ const publishDate = url.searchParams.get('publishDate');
45
+ if (!possibleModes.includes(mode)) {
46
+ mode = types.UVE_MODE.EDIT;
47
+ }
48
+ return {
49
+ mode,
50
+ languageId,
51
+ persona,
52
+ variantName,
53
+ experimentId,
54
+ publishDate
55
+ };
56
+ }
57
+
58
+ exports.getUVEState = getUVEState;
package/index.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/index.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/public/index";
package/index.esm.js ADDED
@@ -0,0 +1,56 @@
1
+ import { UVE_MODE } from './types.esm.js';
2
+
3
+ /**
4
+ * Gets the current state of the Universal Visual Editor (UVE).
5
+ *
6
+ * This function checks if the code is running inside the DotCMS Universal Visual Editor
7
+ * and returns information about its current state, including the editor mode.
8
+ *
9
+ * @export
10
+ * @return {UVEState | undefined} Returns the UVE state object if running inside the editor,
11
+ * undefined otherwise.
12
+ *
13
+ * The state includes:
14
+ * - mode: The current editor mode (preview, edit, live)
15
+ * - languageId: The language ID of the current page setted on the UVE
16
+ * - persona: The persona of the current page setted on the UVE
17
+ * - variantName: The name of the current variant
18
+ * - experimentId: The ID of the current experiment
19
+ * - publishDate: The publish date of the current page setted on the UVE
20
+ *
21
+ * @note The absence of any of these properties means that the value is the default one.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const editorState = getUVEState();
26
+ * if (editorState?.mode === 'edit') {
27
+ * // Enable editing features
28
+ * }
29
+ * ```
30
+ */
31
+ function getUVEState() {
32
+ if (typeof window === 'undefined' || window.parent === window || !window.location) {
33
+ return;
34
+ }
35
+ const url = new URL(window.location.href);
36
+ const possibleModes = Object.values(UVE_MODE);
37
+ let mode = url.searchParams.get('mode') ?? UVE_MODE.EDIT;
38
+ const languageId = url.searchParams.get('language_id');
39
+ const persona = url.searchParams.get('personaId');
40
+ const variantName = url.searchParams.get('variantName');
41
+ const experimentId = url.searchParams.get('experimentId');
42
+ const publishDate = url.searchParams.get('publishDate');
43
+ if (!possibleModes.includes(mode)) {
44
+ mode = UVE_MODE.EDIT;
45
+ }
46
+ return {
47
+ mode,
48
+ languageId,
49
+ persona,
50
+ variantName,
51
+ experimentId,
52
+ publishDate
53
+ };
54
+ }
55
+
56
+ export { getUVEState };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@dotcms/uve",
3
+ "version": "0.0.1-beta.0",
4
+ "description": "Official JavaScript library for interacting with Universal Visual Editor (UVE)",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/dotCMS/core.git#main"
8
+ },
9
+ "keywords": [
10
+ "dotCMS",
11
+ "CMS",
12
+ "Content Management",
13
+ "UVE",
14
+ "Universal Visual Editor"
15
+ ],
16
+ "author": "dotcms <dev@dotcms.com>",
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/dotCMS/core/issues"
20
+ },
21
+ "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/client/README.md",
22
+ "exports": {
23
+ "./package.json": "./package.json",
24
+ ".": {
25
+ "module": "./index.esm.js",
26
+ "types": "./index.esm.d.ts",
27
+ "import": "./index.cjs.mjs",
28
+ "default": "./index.cjs.js"
29
+ },
30
+ "./types": {
31
+ "module": "./types.esm.js",
32
+ "types": "./types.esm.d.ts",
33
+ "import": "./types.cjs.mjs",
34
+ "default": "./types.cjs.js"
35
+ }
36
+ },
37
+ "module": "./index.esm.js",
38
+ "main": "./index.cjs.js",
39
+ "types": "./index.esm.d.ts"
40
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Represents the state of the Universal Visual Editor (UVE)
3
+ * @interface
4
+ * @property {UVE_MODE} mode - The current mode of operation for UVE (EDIT, PREVIEW, LIVE, or UNKNOWN)
5
+ * @property {string | null} persona - The selected persona for content personalization
6
+ * @property {string | null} variantName - The name of the current content variant
7
+ * @property {string | null} experimentId - The identifier for the current A/B testing experiment
8
+ * @property {string | null} publishDate - The scheduled publish date for content
9
+ * @property {string | null} languageId - The identifier for the current language selection
10
+ */
11
+ export interface UVEState {
12
+ mode: UVE_MODE;
13
+ persona: string | null;
14
+ variantName: string | null;
15
+ experimentId: string | null;
16
+ publishDate: string | null;
17
+ languageId: string | null;
18
+ }
19
+ /**
20
+ * Possible modes of UVE (Universal Visual Editor)
21
+ * @enum {string}
22
+ *
23
+ * @property {string} LIVE - Shows published and future content
24
+ * @property {string} PREVIEW - Shows published and working content
25
+ * @property {string} EDIT - Enables content editing functionality in UVE
26
+ * @property {string} UNKNOWN - Error state, UVE should not remain in this mode
27
+ */
28
+ export declare enum UVE_MODE {
29
+ EDIT = "EDIT_MODE",
30
+ PREVIEW = "PREVIEW_MODE",
31
+ LIVE = "LIVE",
32
+ UNKNOWN = "UNKNOWN"
33
+ }
@@ -0,0 +1,30 @@
1
+ import { UVEState } from './types';
2
+ /**
3
+ * Gets the current state of the Universal Visual Editor (UVE).
4
+ *
5
+ * This function checks if the code is running inside the DotCMS Universal Visual Editor
6
+ * and returns information about its current state, including the editor mode.
7
+ *
8
+ * @export
9
+ * @return {UVEState | undefined} Returns the UVE state object if running inside the editor,
10
+ * undefined otherwise.
11
+ *
12
+ * The state includes:
13
+ * - mode: The current editor mode (preview, edit, live)
14
+ * - languageId: The language ID of the current page setted on the UVE
15
+ * - persona: The persona of the current page setted on the UVE
16
+ * - variantName: The name of the current variant
17
+ * - experimentId: The ID of the current experiment
18
+ * - publishDate: The publish date of the current page setted on the UVE
19
+ *
20
+ * @note The absence of any of these properties means that the value is the default one.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const editorState = getUVEState();
25
+ * if (editorState?.mode === 'edit') {
26
+ * // Enable editing features
27
+ * }
28
+ * ```
29
+ */
30
+ export declare function getUVEState(): UVEState | undefined;
@@ -0,0 +1,2 @@
1
+ import { getUVEState } from '../lib/utils';
2
+ export { getUVEState };
@@ -0,0 +1,2 @@
1
+ import { UVE_MODE, UVEState } from '../lib/types';
2
+ export { UVE_MODE, UVEState };
package/types.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/public/types";
@@ -0,0 +1 @@
1
+ exports._default = require('./types.cjs.js').default;
package/types.cjs.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Possible modes of UVE (Universal Visual Editor)
5
+ * @enum {string}
6
+ *
7
+ * @property {string} LIVE - Shows published and future content
8
+ * @property {string} PREVIEW - Shows published and working content
9
+ * @property {string} EDIT - Enables content editing functionality in UVE
10
+ * @property {string} UNKNOWN - Error state, UVE should not remain in this mode
11
+ */
12
+ exports.UVE_MODE = void 0;
13
+ (function (UVE_MODE) {
14
+ UVE_MODE["EDIT"] = "EDIT_MODE";
15
+ UVE_MODE["PREVIEW"] = "PREVIEW_MODE";
16
+ UVE_MODE["LIVE"] = "LIVE";
17
+ UVE_MODE["UNKNOWN"] = "UNKNOWN";
18
+ })(exports.UVE_MODE || (exports.UVE_MODE = {}));
package/types.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './types.cjs.js';
2
+ export { _default as default } from './types.cjs.default.js';
package/types.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/public/types";
package/types.esm.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Possible modes of UVE (Universal Visual Editor)
3
+ * @enum {string}
4
+ *
5
+ * @property {string} LIVE - Shows published and future content
6
+ * @property {string} PREVIEW - Shows published and working content
7
+ * @property {string} EDIT - Enables content editing functionality in UVE
8
+ * @property {string} UNKNOWN - Error state, UVE should not remain in this mode
9
+ */
10
+ var UVE_MODE;
11
+ (function (UVE_MODE) {
12
+ UVE_MODE["EDIT"] = "EDIT_MODE";
13
+ UVE_MODE["PREVIEW"] = "PREVIEW_MODE";
14
+ UVE_MODE["LIVE"] = "LIVE";
15
+ UVE_MODE["UNKNOWN"] = "UNKNOWN";
16
+ })(UVE_MODE || (UVE_MODE = {}));
17
+
18
+ export { UVE_MODE };