@dotcms/vue 1.5.5 → 1.7.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.
@@ -0,0 +1,79 @@
1
+ import { App, InjectionKey } from 'vue';
2
+ import { createDotCMSClient } from '@dotcms/client';
3
+ import { DotCMSClientConfig } from '@dotcms/types';
4
+ /**
5
+ * The dotCMS client instance created by {@link createDotCMSClient}. Use this
6
+ * type to annotate variables that hold the injected client.
7
+ */
8
+ export type DotCMSClient = ReturnType<typeof createDotCMSClient>;
9
+ /**
10
+ * Injection key for the dotCMS client.
11
+ *
12
+ * Advanced: exported so a consumer can `inject(DOTCMS_CLIENT)` directly (e.g.
13
+ * outside a `setup()` where {@link useDotCMSClient} would throw), but prefer
14
+ * {@link useDotCMSClient}.
15
+ */
16
+ export declare const DOTCMS_CLIENT: InjectionKey<DotCMSClient>;
17
+ /**
18
+ * A Vue plugin returned by {@link createDotCMSVue}. Install it with `app.use`.
19
+ */
20
+ export interface DotCMSVuePlugin {
21
+ install(app: App): void;
22
+ /** The client instance the plugin provides. Handy for use outside components. */
23
+ client: DotCMSClient;
24
+ }
25
+ /**
26
+ * Creates the dotCMS Vue plugin.
27
+ *
28
+ * Builds a single dotCMS client from `config` and provides it to the whole app
29
+ * so components can retrieve it with {@link useDotCMSClient} — no module-level
30
+ * singleton to import. This is the Vue analog of Angular's `provideDotCMSClient`.
31
+ *
32
+ * The created client is also exposed on the returned object as `.client`, so
33
+ * non-component code (route loaders, plain modules) can share the same instance.
34
+ *
35
+ * @param config - the same configuration accepted by `createDotCMSClient`
36
+ * @returns a Vue plugin to pass to `app.use()`
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { createApp } from 'vue';
41
+ * import { createDotCMSVue } from '@dotcms/vue';
42
+ * import App from './App.vue';
43
+ *
44
+ * const app = createApp(App);
45
+ *
46
+ * app.use(
47
+ * createDotCMSVue({
48
+ * dotcmsUrl: 'https://demo.dotcms.com',
49
+ * authToken: 'your-auth-token',
50
+ * siteId: 'your-site-id',
51
+ * requestOptions: {
52
+ * // UVE needs fresh data so in-context edits are reflected immediately.
53
+ * cache: 'no-cache'
54
+ * }
55
+ * })
56
+ * );
57
+ *
58
+ * app.mount('#app');
59
+ * ```
60
+ */
61
+ export declare function createDotCMSVue(config: DotCMSClientConfig): DotCMSVuePlugin;
62
+ /**
63
+ * Retrieves the dotCMS client provided by {@link createDotCMSVue}.
64
+ *
65
+ * Must be called from a component `setup` (or another composable). Throws if the
66
+ * plugin was not installed with `app.use(createDotCMSVue(...))`, so a missing
67
+ * provider fails loudly instead of returning `undefined`.
68
+ *
69
+ * @returns the dotCMS client instance
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { useDotCMSClient } from '@dotcms/vue';
74
+ *
75
+ * const client = useDotCMSClient();
76
+ * const { pageAsset } = await client.page.get({ path: '/' });
77
+ * ```
78
+ */
79
+ export declare function useDotCMSClient(): DotCMSClient;
@@ -1,5 +1,13 @@
1
1
  import { DotCMSPageAsset, DotCMSPageRendererMode } from '@dotcms/types';
2
2
  import { Component } from 'vue';
3
+ /**
4
+ * Prefix for the per-contentlet named slots of {@link DotCMSLayoutBody}. A slot
5
+ * named `contentlet-<identifier>` overrides the mapped component for the
6
+ * contentlet with that identifier.
7
+ *
8
+ * @example `<template #contentlet-abc123>…</template>` targets identifier `abc123`.
9
+ */
10
+ export declare const CONTENTLET_SLOT_PREFIX = "contentlet-";
3
11
  /**
4
12
  * Props for {@link DotCMSLayoutBody}.
5
13
  */
@@ -1,11 +1,13 @@
1
- import { Ref } from 'vue';
1
+ import { ComputedRef, MaybeRefOrGetter } from 'vue';
2
2
  import { UVE_MODE } from '@dotcms/types';
3
3
  /**
4
4
  * Composable that reports whether the current UVE mode matches the given mode.
5
5
  *
6
6
  * Useful for conditionally rendering content based on the editor mode (EDIT,
7
7
  * PREVIEW, LIVE). It resolves after mount (returns `false` during SSR), matching
8
- * the React SDK's `useDotCMSShowWhen` behavior.
8
+ * the React SDK's `useDotCMSShowWhen` behavior. The `when` argument may be a
9
+ * plain value, a `ref`, or a getter — a reactive value is re-evaluated when it
10
+ * changes.
9
11
  *
10
12
  * @example
11
13
  * ```ts
@@ -13,6 +15,6 @@ import { UVE_MODE } from '@dotcms/types';
13
15
  * ```
14
16
  *
15
17
  * @param when the UVE mode to check against
16
- * @returns a readonly ref that is `true` when the current UVE mode matches
18
+ * @returns a readonly computed that is `true` when the current UVE mode matches
17
19
  */
18
- export declare function useDotCMSShowWhen(when: UVE_MODE): Readonly<Ref<boolean>>;
20
+ export declare function useDotCMSShowWhen(when: MaybeRefOrGetter<UVE_MODE>): Readonly<ComputedRef<boolean>>;
@@ -1,4 +1,4 @@
1
- import { Ref } from 'vue';
1
+ import { MaybeRefOrGetter, Ref } from 'vue';
2
2
  import { DotCMSComposedPageResponse, DotCMSExtendedPageResponse } from '@dotcms/types';
3
3
  /**
4
4
  * Composable to manage the editable state of a dotCMS page inside the Universal
@@ -28,7 +28,10 @@ import { DotCMSComposedPageResponse, DotCMSExtendedPageResponse } from '@dotcms/
28
28
  * // page.value.pageAsset — reactive; re-renders on UVE content changes.
29
29
  * ```
30
30
  *
31
- * @param pageResponse the initial page response from `client.page.get()`
31
+ * @param pageResponse the page response from `client.page.get()`. May be a plain
32
+ * value, a `ref`, or a getter — when it's reactive, the composable re-initializes
33
+ * the UVE for the new page (e.g. on client-side route changes) so no manual
34
+ * component remount is needed.
32
35
  * @returns a reactive ref holding the (possibly live-updating) page response
33
36
  */
34
- export declare function useEditableDotCMSPage<T extends DotCMSExtendedPageResponse>(pageResponse: DotCMSComposedPageResponse<T>): Ref<DotCMSComposedPageResponse<T>>;
37
+ export declare function useEditableDotCMSPage<T extends DotCMSExtendedPageResponse>(pageResponse: MaybeRefOrGetter<DotCMSComposedPageResponse<T>>): Ref<DotCMSComposedPageResponse<T>>;
@@ -1,13 +1,13 @@
1
- import { Component, ComputedRef, InjectionKey } from 'vue';
1
+ import { Component, ComputedRef, InjectionKey, Slot } from 'vue';
2
2
  import { DotCMSPageAsset, DotCMSPageRendererMode } from '@dotcms/types';
3
3
  /**
4
4
  * The value carried by the dotCMS page context.
5
5
  *
6
6
  * This is the Vue analog of the React SDK's `DotCMSPageContext`. It is provided
7
- * once by {@link DotCMSLayoutBody} and consumed by the internal layout tree
8
- * (Container, Contentlet) as well as the dev-mode composable.
9
- *
10
- * @internal
7
+ * once by {@link DotCMSLayoutBody} and consumed by the layout tree (Container,
8
+ * Contentlet). It is also part of the public API: a custom content-type
9
+ * component rendered deep in the tree can read it via {@link useDotCMSPageContext}
10
+ * to access the page asset without prop drilling. This shape is stable.
11
11
  */
12
12
  export interface DotCMSPageContextValue {
13
13
  /** The dotCMS page asset containing the layout and containers. */
@@ -31,6 +31,15 @@ export interface DotCMSPageContextValue {
31
31
  * single `dotcms:analytics:ready` listener) and shared with the tree.
32
32
  */
33
33
  isAnalyticsActive: boolean;
34
+ /**
35
+ * Named slots passed to {@link DotCMSLayoutBody}, keyed by contentlet
36
+ * identifier (the `contentlet-<identifier>` slot name, with the prefix
37
+ * stripped). When a contentlet has a matching slot, that slot content is
38
+ * rendered instead of the mapped component — the Vue analog of the React
39
+ * SDK's `slots` prop. Empty (or omitted) when no per-contentlet slots were
40
+ * provided; {@link DotCMSLayoutBody} always sets it.
41
+ */
42
+ slots?: Record<string, Slot>;
34
43
  }
35
44
  /**
36
45
  * Injection key for the dotCMS page context.
@@ -39,23 +48,27 @@ export interface DotCMSPageContextValue {
39
48
  * asset arriving via `uve-set-page-data`) propagate to every consumer that reads
40
49
  * `ctx.value` — the whole layout tree re-renders reactively.
41
50
  *
42
- * @internal
51
+ * Advanced: exported so consumers can `inject` directly, but prefer
52
+ * {@link useDotCMSPageContext}.
43
53
  */
44
54
  export declare const DOTCMS_PAGE_CONTEXT: InjectionKey<ComputedRef<DotCMSPageContextValue>>;
45
55
  /**
46
56
  * Provides the dotCMS page context to descendant components.
47
57
  *
48
- * @internal
58
+ * Advanced: {@link DotCMSLayoutBody} already provides this for the rendered tree,
59
+ * so most applications never call it. Exposed for consumers that render the
60
+ * layout tree themselves.
61
+ *
49
62
  * @param value a computed producing the current context value
50
63
  */
51
64
  export declare function provideDotCMSPageContext(value: ComputedRef<DotCMSPageContextValue>): void;
52
65
  /**
53
66
  * Injects the dotCMS page context as a reactive `ComputedRef`.
54
67
  *
55
- * Falls back to an empty context when used outside of a {@link DotCMSLayoutBody},
56
- * mirroring the default value the React context is created with.
68
+ * Public: use this from a custom content-type component to read the current
69
+ * `pageAsset`, renderer `mode`, or editor state without prop drilling. Falls back
70
+ * to an empty context when used outside of a {@link DotCMSLayoutBody}.
57
71
  *
58
- * @internal
59
72
  * @returns the current page context value as a computed ref
60
73
  */
61
74
  export declare function useDotCMSPageContext(): ComputedRef<DotCMSPageContextValue>;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Options for a single {@link DotCMSImageLoader} call.
3
+ */
4
+ export interface DotCMSImageLoaderOptions {
5
+ /** Target width in pixels. Requests a resized image from the dotCMS image API. */
6
+ width?: number;
7
+ /**
8
+ * JPEG quality (1-100).
9
+ * @default 50
10
+ */
11
+ quality?: number;
12
+ /**
13
+ * Language id for the asset.
14
+ * @default '1'
15
+ */
16
+ languageId?: string;
17
+ }
18
+ /**
19
+ * A function that turns a dotCMS asset identifier (or path) into an image URL.
20
+ * Returned by {@link createDotCMSImageLoader}.
21
+ */
22
+ export type DotCMSImageLoader = (src: string, options?: DotCMSImageLoaderOptions) => string;
23
+ /**
24
+ * Creates a dotCMS image URL builder.
25
+ *
26
+ * dotCMS serves images through its image API (the `/dA/` route), which handles
27
+ * on-the-fly resizing and optimization. This is the Vue analog of Angular's
28
+ * `provideDotCMSImageLoader`: Angular wires the same URL math into its
29
+ * `IMAGE_LOADER` token, while Vue has no such token, so this returns a plain
30
+ * function you call from a template.
31
+ *
32
+ * Absolute URLs (already `http(s)://…`) are returned unchanged, so mixing dotCMS
33
+ * assets with external/stock imagery just works.
34
+ *
35
+ * @param dotcmsUrl - Base URL of the dotCMS instance. When omitted (empty), URLs
36
+ * are site-relative (`/dA/…`), which is what you want behind a dev proxy.
37
+ * @returns a loader function `(src, options?) => url`
38
+ * @throws if `dotcmsUrl` is a non-empty, invalid URL
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { createDotCMSImageLoader } from '@dotcms/vue';
43
+ *
44
+ * // Absolute (production): points at the dotCMS host.
45
+ * const image = createDotCMSImageLoader(import.meta.env.VITE_DOTCMS_HOST);
46
+ * image(contentlet.inode, { width: 800 });
47
+ * // → https://demo.dotcms.com/dA/<inode>/800w/50q?language_id=1
48
+ *
49
+ * // Relative (dev proxy): omit the host so the Vite proxy handles /dA.
50
+ * const proxied = createDotCMSImageLoader();
51
+ * proxied(contentlet.inode, { width: 800 }); // → /dA/<inode>/800w/50q?language_id=1
52
+ * ```
53
+ */
54
+ export declare function createDotCMSImageLoader(dotcmsUrl?: string): DotCMSImageLoader;
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
1
  {
2
- "name": "@dotcms/vue",
3
- "version": "1.5.5",
4
- "peerDependencies": {
5
- "vue": ">=3.4"
6
- },
7
- "dependencies": {
8
- "@dotcms/uve": "latest",
9
- "@dotcms/client": "latest",
10
- "@tinymce/tinymce-vue": "^6.1.0"
11
- },
12
- "devDependencies": {
13
- "@dotcms/types": "latest"
14
- },
15
- "description": "Official Vue components library to render a dotCMS page.",
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/dotCMS/core.git#main"
19
- },
20
- "keywords": [
21
- "dotCMS",
22
- "CMS",
23
- "Content Management",
24
- "API Client",
25
- "REST API",
26
- "Vue",
27
- "Vue 3",
28
- "Components"
29
- ],
30
- "type": "module",
31
- "main": "./index.js",
32
- "module": "./index.js",
33
- "types": "./index.d.ts",
34
- "exports": {
35
- "./package.json": "./package.json",
36
- ".": {
37
- "types": "./index.d.ts",
38
- "import": "./index.js"
39
- }
40
- },
41
- "author": "dotcms <dev@dotcms.com>",
42
- "license": "MIT",
43
- "bugs": {
44
- "url": "https://github.com/dotCMS/core/issues"
45
- },
46
- "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/vue/README.md"
2
+ "name": "@dotcms/vue",
3
+ "version": "1.7.0",
4
+ "peerDependencies": {
5
+ "vue": ">=3.4"
6
+ },
7
+ "dependencies": {
8
+ "@dotcms/uve": "latest",
9
+ "@dotcms/client": "latest",
10
+ "@tinymce/tinymce-vue": "^6.1.0"
11
+ },
12
+ "devDependencies": {
13
+ "@dotcms/types": "latest"
14
+ },
15
+ "description": "Official Vue components library to render a dotCMS page.",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/dotCMS/core.git#main"
19
+ },
20
+ "keywords": [
21
+ "dotCMS",
22
+ "CMS",
23
+ "Content Management",
24
+ "API Client",
25
+ "REST API",
26
+ "Vue",
27
+ "Vue 3",
28
+ "Components"
29
+ ],
30
+ "type": "module",
31
+ "main": "./index.js",
32
+ "module": "./index.js",
33
+ "types": "./index.d.ts",
34
+ "exports": {
35
+ "./package.json": "./package.json",
36
+ ".": {
37
+ "types": "./index.d.ts",
38
+ "import": "./index.js"
39
+ }
40
+ },
41
+ "author": "dotcms <dev@dotcms.com>",
42
+ "license": "MIT",
43
+ "bugs": {
44
+ "url": "https://github.com/dotCMS/core/issues"
45
+ },
46
+ "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/vue/README.md"
47
47
  }