@uniformdev/uniform-nuxt 17.5.0 → 17.5.1-alpha.130
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
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
- [Features](#features)
|
|
6
6
|
- [API reference](#api-reference)
|
|
7
7
|
- [Options](#options)
|
|
8
|
-
- [
|
|
8
|
+
- [Auto-imported composables](#auto-imported-composables)
|
|
9
|
+
- [`useUniformComposition`](#useuniformcomposition)
|
|
9
10
|
- [Components](#components)
|
|
10
|
-
- [
|
|
11
|
-
- [
|
|
11
|
+
- [`<Composition />`](#composition-)
|
|
12
|
+
- [`<SlotContent />`](#slotcontent-)
|
|
13
|
+
- [Injected in the Nuxt instance](#injected-in-the-nuxt-instance)
|
|
12
14
|
- [Examples](#examples)
|
|
13
15
|
|
|
14
16
|
## Getting started
|
|
@@ -64,31 +66,40 @@ These are the option you pass to the module in `nuxt.config.ts`.
|
|
|
64
66
|
|
|
65
67
|
\* Required
|
|
66
68
|
|
|
67
|
-
###
|
|
68
|
-
These are the
|
|
69
|
+
### Auto-imported composables
|
|
70
|
+
These are the composables that the module auto registers for you, so you can use them without import.
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
#### `useUniformComposition`
|
|
73
|
+
A Vue composable which takes care of fetching a composition and optionally enhancing it. The composable also takes care of enabling Contextual editing capability.
|
|
74
|
+
It takes the following named arguments:
|
|
75
|
+
|
|
76
|
+
| Named argument | Type | Description |
|
|
71
77
|
|---|---|---|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
| `$preview` | object \| undefined | This object is only defined in preview mode, so you can use it to adjust your app if it's in preview mode. It contains the slug of the current composition. |
|
|
75
|
-
| `$uniformCanvasClient` | CanvasClient | Returns the Canvas client which you can use to fetch or update compositions. For composition fetching, it's recommended to use `$useComposition` instead. |
|
|
78
|
+
| `enhance` | function | A function to enhance the composition after fetching it. It passes the fetched composition as an argument and should return the enhanced composition. |
|
|
79
|
+
| Parameters to get a composition | - | The compasable allows passing any of the parameters allowed by [CanvasClient](https://docs.uniform.app/reference/packages/uniformdev-canvas#canvasclient)'s `getCompositionBy...` methods (e.g. `getCompositionById`, `getCompositionBySlug`, etc.) |
|
|
76
80
|
|
|
81
|
+
Example:
|
|
82
|
+
```js
|
|
83
|
+
const { composition } = useUniformComposable({
|
|
84
|
+
slug: '/my-slug',
|
|
85
|
+
enhance: (c) => doSomething(c),
|
|
86
|
+
});
|
|
87
|
+
```
|
|
77
88
|
|
|
78
89
|
### Components
|
|
79
90
|
These are the components that the module auto registers for you, so you can use them without import.
|
|
80
91
|
|
|
81
|
-
####
|
|
82
|
-
This component wraps the whole composition, it
|
|
92
|
+
#### `<Composition />`
|
|
93
|
+
This component wraps the whole composition, it accepts the following props:
|
|
83
94
|
|
|
84
95
|
| Prop | Type | Description |
|
|
85
96
|
|---|---|---|
|
|
86
97
|
| `data`* | string | The data of the composition to be rendered, this is usually the `composition` object that you get from `$useComposition` |
|
|
87
|
-
| `resolveRenderer` | function | This function is responsible
|
|
98
|
+
| `resolveRenderer` | function | This function is responsible for mapping Canvas components to Vue components. It takes a `ComponentInstance` object and should return a Vue component (usually based on the component `type`). If no resolver is provided, it will try to resolve the component on the global context of the app, so if you have globally defined components, it will try to map them based on the `name` of the Vue component and the `type` of the Canvas component.|
|
|
88
99
|
|
|
89
100
|
\* Required
|
|
90
101
|
|
|
91
|
-
####
|
|
102
|
+
#### `<SlotContent />`
|
|
92
103
|
This component is used to render the slots of a composition, and it can be only used inside a `<Composition />`.
|
|
93
104
|
You can nest `<SlotContent />` inside each other if you have nested slots.
|
|
94
105
|
|
|
@@ -96,6 +107,15 @@ You can nest `<SlotContent />` inside each other if you have nested slots.
|
|
|
96
107
|
|---|---|---|
|
|
97
108
|
| `name` | string | The name of the Canvas slot to render.<br>If no value is provided, all the slots will be rendered (this is not recommended as the order of the rendered slots is not guaranteed). |
|
|
98
109
|
|
|
110
|
+
### Injected in the Nuxt instance
|
|
111
|
+
These are the properties that the module injects in the Nuxt app instance, so you can use them anywhere in your app via `useNuxtApp()`.
|
|
112
|
+
|
|
113
|
+
| Property | Type | Description |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `$useUniformContext` | function | A Vue composable that returns the current Uniform Context instance which allows you to interact with the context such updating the scores and so on. It also returns other provided properties such as `outputType` |
|
|
116
|
+
| `$preview` | object \| undefined | This object is only defined in preview mode, so you can use it to adjust your app if it's in preview mode. It contains the slug of the current composition. |
|
|
117
|
+
| `$uniformCanvasClient` | CanvasClient | Returns the Canvas client which you can use to fetch or update compositions. For composition fetching, it's recommended to use `$useComposition` instead. |
|
|
118
|
+
|
|
99
119
|
## Examples
|
|
100
120
|
|
|
101
121
|
Here are some example where the module is used:
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { defineNuxtModule, addTemplate, addPlugin, addImportsDir, resolveAlias, extendViteConfig } from '@nuxt/kit';
|
|
1
2
|
import { resolve } from 'path';
|
|
2
3
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import { defineNuxtModule, addTemplate, addPlugin, resolveAlias, extendViteConfig } from '@nuxt/kit';
|
|
4
4
|
|
|
5
5
|
const uniformContextProxyPath = "uniform/context/instance.ts";
|
|
6
6
|
const module = defineNuxtModule({
|
|
@@ -40,6 +40,7 @@ const module = defineNuxtModule({
|
|
|
40
40
|
const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
|
|
41
41
|
nuxt.options.build.transpile.push(runtimeDir);
|
|
42
42
|
addPlugin(resolve(runtimeDir, "plugin"));
|
|
43
|
+
addImportsDir(resolve(runtimeDir, `./composables`));
|
|
43
44
|
}
|
|
44
45
|
});
|
|
45
46
|
function resolveConfigFilePath(nuxt, filePath) {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type RootComponentInstance, type CompositionGetByNodePathParameters, type CompositionGetBySlugParameters, type CompositionGetByNodeIdParameters, type CompositionGetByIdParameters, type DataResolutionOption } from '@uniformdev/canvas';
|
|
2
|
+
export declare const useUniformComposition: (options: (CompositionGetBySlugParameters | CompositionGetByIdParameters | CompositionGetByNodePathParameters | CompositionGetByNodeIdParameters) & DataResolutionOption & {
|
|
3
|
+
enhance?: ((composition: RootComponentInstance) => RootComponentInstance | Promise<RootComponentInstance>) | undefined;
|
|
4
|
+
}) => Promise<{
|
|
5
|
+
composition: import("vue-demi").Ref<{
|
|
6
|
+
type: string;
|
|
7
|
+
parameters?: {
|
|
8
|
+
[key: string]: {
|
|
9
|
+
value: unknown;
|
|
10
|
+
type: string;
|
|
11
|
+
connectedData?: {
|
|
12
|
+
pointer: string;
|
|
13
|
+
syntax: "jptr";
|
|
14
|
+
required?: boolean | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
};
|
|
17
|
+
} | undefined;
|
|
18
|
+
variant?: string | undefined;
|
|
19
|
+
slots?: {
|
|
20
|
+
[key: string]: {
|
|
21
|
+
type: string;
|
|
22
|
+
parameters?: {
|
|
23
|
+
[key: string]: {
|
|
24
|
+
value: unknown;
|
|
25
|
+
type: string;
|
|
26
|
+
connectedData?: {
|
|
27
|
+
pointer: string;
|
|
28
|
+
syntax: "jptr";
|
|
29
|
+
required?: boolean | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
};
|
|
32
|
+
} | undefined;
|
|
33
|
+
variant?: string | undefined;
|
|
34
|
+
slots?: {
|
|
35
|
+
[key: string]: any[];
|
|
36
|
+
} | undefined;
|
|
37
|
+
_id?: string | undefined;
|
|
38
|
+
_pattern?: string | undefined;
|
|
39
|
+
_dataResources?: {
|
|
40
|
+
[key: string]: {
|
|
41
|
+
type: string;
|
|
42
|
+
isPatternParameter?: boolean | undefined;
|
|
43
|
+
variables?: {
|
|
44
|
+
[key: string]: string;
|
|
45
|
+
} | undefined;
|
|
46
|
+
};
|
|
47
|
+
} | undefined;
|
|
48
|
+
_patternDataResources?: {
|
|
49
|
+
[key: string]: {
|
|
50
|
+
type: string;
|
|
51
|
+
isPatternParameter?: boolean | undefined;
|
|
52
|
+
variables?: {
|
|
53
|
+
[key: string]: string;
|
|
54
|
+
} | undefined;
|
|
55
|
+
};
|
|
56
|
+
} | undefined;
|
|
57
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
58
|
+
}[];
|
|
59
|
+
} | undefined;
|
|
60
|
+
_id: string;
|
|
61
|
+
_slug?: string | null | undefined;
|
|
62
|
+
_name: string;
|
|
63
|
+
_dataResources?: {
|
|
64
|
+
[key: string]: {
|
|
65
|
+
type: string;
|
|
66
|
+
isPatternParameter?: boolean | undefined;
|
|
67
|
+
variables?: {
|
|
68
|
+
[key: string]: string;
|
|
69
|
+
} | undefined;
|
|
70
|
+
};
|
|
71
|
+
} | undefined;
|
|
72
|
+
} | undefined>;
|
|
73
|
+
fullResponse: any;
|
|
74
|
+
pending: any;
|
|
75
|
+
error: any;
|
|
76
|
+
}>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useAsyncData, useNuxtApp } from "#app";
|
|
2
|
+
import { watch, ref, toRaw } from "vue-demi";
|
|
3
|
+
import {
|
|
4
|
+
CANVAS_DRAFT_STATE,
|
|
5
|
+
CANVAS_PUBLISHED_STATE
|
|
6
|
+
} from "@uniformdev/canvas";
|
|
7
|
+
import { useContextualEditing } from "@uniformdev/canvas-vue";
|
|
8
|
+
export const useUniformComposition = async (options) => {
|
|
9
|
+
const { enhance = (c) => c, ...parameters } = options;
|
|
10
|
+
const { $uniformCanvasClient, $preview: preview } = useNuxtApp();
|
|
11
|
+
const canvasClient = $uniformCanvasClient;
|
|
12
|
+
const activeComposition = ref(void 0);
|
|
13
|
+
const { composition: contextualEditingComposition } = useContextualEditing({
|
|
14
|
+
initialCompositionValue: void 0
|
|
15
|
+
});
|
|
16
|
+
watch(
|
|
17
|
+
[contextualEditingComposition],
|
|
18
|
+
async () => {
|
|
19
|
+
if (!contextualEditingComposition.value) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const composition = toRaw(contextualEditingComposition.value);
|
|
23
|
+
activeComposition.value = await enhance(composition);
|
|
24
|
+
},
|
|
25
|
+
{ deep: true }
|
|
26
|
+
);
|
|
27
|
+
const { data, pending, error } = await useAsyncData(
|
|
28
|
+
`composition-${JSON.stringify(parameters)}`,
|
|
29
|
+
async () => {
|
|
30
|
+
const state = preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE;
|
|
31
|
+
if ("slug" in parameters) {
|
|
32
|
+
const slug = parameters.slug;
|
|
33
|
+
return await canvasClient.getCompositionBySlug({
|
|
34
|
+
...parameters,
|
|
35
|
+
slug,
|
|
36
|
+
state
|
|
37
|
+
});
|
|
38
|
+
} else if ("compositionId" in parameters) {
|
|
39
|
+
const compositionId = parameters.compositionId;
|
|
40
|
+
return await canvasClient.getCompositionById({
|
|
41
|
+
...parameters,
|
|
42
|
+
compositionId,
|
|
43
|
+
state
|
|
44
|
+
});
|
|
45
|
+
} else if ("projectMapNodeId" in parameters) {
|
|
46
|
+
return await canvasClient.unstable_getCompositionByNodeId({
|
|
47
|
+
...parameters,
|
|
48
|
+
state
|
|
49
|
+
});
|
|
50
|
+
} else if ("projectMapNodePath" in parameters) {
|
|
51
|
+
return await canvasClient.unstable_getCompositionByNodePath({
|
|
52
|
+
...parameters,
|
|
53
|
+
state
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
activeComposition.value = data.value?.composition ? await enhance(data.value.composition) : void 0;
|
|
59
|
+
return {
|
|
60
|
+
composition: activeComposition,
|
|
61
|
+
fullResponse: data.value,
|
|
62
|
+
pending,
|
|
63
|
+
error
|
|
64
|
+
};
|
|
65
|
+
};
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
defineNuxtPlugin,
|
|
3
|
-
useRoute,
|
|
4
|
-
useRouter,
|
|
5
|
-
useRuntimeConfig,
|
|
6
|
-
useHead,
|
|
7
|
-
refreshNuxtData,
|
|
8
|
-
useAsyncData,
|
|
9
|
-
useState,
|
|
10
|
-
useCookie
|
|
11
|
-
} from "#app";
|
|
12
|
-
import userProvidedContextInstance from "#build/uniform/context/instance";
|
|
13
|
-
import { watch, toRaw } from "vue-demi";
|
|
14
|
-
import {
|
|
15
|
-
CanvasClient,
|
|
16
2
|
CANVAS_DRAFT_STATE,
|
|
17
|
-
CANVAS_PUBLISHED_STATE
|
|
3
|
+
CANVAS_PUBLISHED_STATE,
|
|
4
|
+
CanvasClient
|
|
18
5
|
} from "@uniformdev/canvas";
|
|
6
|
+
import { Composition, SlotContent, useCompositionEventEffect } from "@uniformdev/canvas-vue";
|
|
19
7
|
import {
|
|
20
8
|
Context,
|
|
21
|
-
SERVER_STATE_ID,
|
|
22
9
|
CookieTransitionDataStore,
|
|
23
10
|
enableContextDevTools,
|
|
11
|
+
SERVER_STATE_ID,
|
|
24
12
|
UNIFORM_DEFAULT_COOKIE_NAME
|
|
25
13
|
} from "@uniformdev/context";
|
|
26
|
-
import { Composition, SlotContent, useCompositionEventEffect } from "@uniformdev/canvas-vue";
|
|
27
14
|
import {
|
|
28
|
-
provideUniformContext,
|
|
29
15
|
onRouteChange,
|
|
16
|
+
provideUniformContext,
|
|
30
17
|
useUniformContext
|
|
31
18
|
} from "@uniformdev/context-vue";
|
|
19
|
+
import { toRaw, watch } from "vue-demi";
|
|
20
|
+
import {
|
|
21
|
+
defineNuxtPlugin,
|
|
22
|
+
navigateTo,
|
|
23
|
+
refreshNuxtData,
|
|
24
|
+
useAsyncData,
|
|
25
|
+
useCookie,
|
|
26
|
+
useHead,
|
|
27
|
+
useRoute,
|
|
28
|
+
useRouter,
|
|
29
|
+
useRuntimeConfig,
|
|
30
|
+
useState
|
|
31
|
+
} from "#app";
|
|
32
|
+
import userProvidedContextInstance from "#build/uniform/context/instance";
|
|
33
|
+
const log = process.env.NODE_ENV === "development" ? (...args) => console.log(...args) : () => {
|
|
34
|
+
};
|
|
32
35
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
33
36
|
if (nuxtApp.$uniformIsSetup) {
|
|
34
37
|
return;
|
|
@@ -64,7 +67,7 @@ function setupContext(nuxtApp) {
|
|
|
64
67
|
);
|
|
65
68
|
}
|
|
66
69
|
if (!uniformContext && options.manifest) {
|
|
67
|
-
|
|
70
|
+
log("uniform-nuxt: \u{1F4DC} found a manifest, will initialize Context");
|
|
68
71
|
const manifestAsSimpleObject = toRaw(options.manifest);
|
|
69
72
|
uniformContext = new Context({
|
|
70
73
|
defaultConsent: Boolean(options.defaultConsent),
|
|
@@ -116,12 +119,22 @@ function setupPreview() {
|
|
|
116
119
|
const route = useRoute();
|
|
117
120
|
let preview;
|
|
118
121
|
if (route.query.preview === "true") {
|
|
119
|
-
|
|
122
|
+
log("uniform-nuxt: \u{1F575}\uFE0F Entering preview mode");
|
|
120
123
|
preview = {
|
|
121
124
|
slug: route.query.slug,
|
|
122
125
|
compositionId: route.query.id
|
|
123
126
|
};
|
|
124
127
|
}
|
|
128
|
+
if (preview && route.query.redirectedForPreview !== "true") {
|
|
129
|
+
navigateTo({
|
|
130
|
+
path: preview.slug,
|
|
131
|
+
query: {
|
|
132
|
+
...route.query,
|
|
133
|
+
redirectedForPreview: "true"
|
|
134
|
+
},
|
|
135
|
+
replace: true
|
|
136
|
+
});
|
|
137
|
+
}
|
|
125
138
|
router.beforeEach((to, from, next) => {
|
|
126
139
|
if (!next) {
|
|
127
140
|
return;
|
|
@@ -161,8 +174,12 @@ function setupUseComposition(uniformCanvasClient, currentCompositionId, preview)
|
|
|
161
174
|
const { data, pending, error } = await useAsyncData(`composition-${slug || compositionId}`, async () => {
|
|
162
175
|
if (slug) {
|
|
163
176
|
return await uniformCanvasClient.getCompositionBySlug({ slug, state });
|
|
177
|
+
} else if (compositionId) {
|
|
178
|
+
return await uniformCanvasClient.getCompositionById({ compositionId, state });
|
|
164
179
|
}
|
|
165
|
-
|
|
180
|
+
log(
|
|
181
|
+
"uniform-nuxt: `useComposition` requires either a `slug` or a `compositionId`, but none were provided."
|
|
182
|
+
);
|
|
166
183
|
});
|
|
167
184
|
currentCompositionId.value = data.value?.composition._id ?? "";
|
|
168
185
|
return { data, pending, error };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/uniform-nuxt",
|
|
3
|
-
"version": "17.5.
|
|
3
|
+
"version": "17.5.1-alpha.130+3fac779b1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@nuxt/kit": "
|
|
25
|
+
"@nuxt/kit": "3.0.0",
|
|
26
26
|
"vue-demi": "^0.13.11"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -32,21 +32,21 @@
|
|
|
32
32
|
"@uniformdev/context-vue": ">15"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@nuxt/module-builder": "0.2.
|
|
36
|
-
"@nuxt/schema": "3.0.0
|
|
35
|
+
"@nuxt/module-builder": "0.2.1",
|
|
36
|
+
"@nuxt/schema": "3.0.0",
|
|
37
37
|
"@nuxtjs/eslint-config-typescript": "11.0.0",
|
|
38
|
-
"@uniformdev/canvas": "^17.5.
|
|
39
|
-
"@uniformdev/canvas-vue": "^17.5.
|
|
40
|
-
"@uniformdev/context": "^17.5.
|
|
41
|
-
"@uniformdev/context-vue": "^17.5.
|
|
42
|
-
"esbuild": "0.15.
|
|
38
|
+
"@uniformdev/canvas": "^17.5.1-alpha.130+3fac779b1",
|
|
39
|
+
"@uniformdev/canvas-vue": "^17.5.1-alpha.130+3fac779b1",
|
|
40
|
+
"@uniformdev/context": "^17.5.1-alpha.130+3fac779b1",
|
|
41
|
+
"@uniformdev/context-vue": "^17.5.1-alpha.130+3fac779b1",
|
|
42
|
+
"esbuild": "0.15.15",
|
|
43
43
|
"eslint": "latest",
|
|
44
|
-
"nuxt": "3.0.0
|
|
45
|
-
"vue": "3.2.
|
|
44
|
+
"nuxt": "3.0.0",
|
|
45
|
+
"vue": "3.2.45",
|
|
46
46
|
"vue-router": "4.1.5"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "3fac779b1b42a1afeb05156cb51768a98573438f"
|
|
52
52
|
}
|