@uniformdev/uniform-nuxt 16.0.1-nuxt.181 → 16.2.1-nuxt.249
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 +36 -25
- package/dist/module.d.ts +20 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -0
- package/dist/runtime/plugin.mjs +44 -10
- package/package.json +15 -11
package/README.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Uniform Nuxt module
|
|
2
2
|
|
|
3
|
+
- [Uniform Nuxt module](#uniform-nuxt-module)
|
|
4
|
+
- [Getting started](#getting-started)
|
|
5
|
+
- [Features](#features)
|
|
6
|
+
- [API reference](#api-reference)
|
|
7
|
+
- [Options](#options)
|
|
8
|
+
- [Injected in the Nuxt instance](#injected-in-the-nuxt-instance)
|
|
9
|
+
- [Components](#components)
|
|
10
|
+
- [\<Composition />](#composition-)
|
|
11
|
+
- [\<SlotContent />](#slotcontent-)
|
|
12
|
+
- [Examples](#examples)
|
|
13
|
+
|
|
3
14
|
## Getting started
|
|
4
15
|
|
|
5
16
|
Install the peer dependencies of the module (if you haven't already):
|
|
@@ -11,22 +22,17 @@ Install the module
|
|
|
11
22
|
npm i @uniformdev/uniform-nuxt
|
|
12
23
|
```
|
|
13
24
|
|
|
14
|
-
Add the module to
|
|
25
|
+
Add the module to your Nuxt config:
|
|
15
26
|
|
|
16
|
-
```
|
|
27
|
+
```js
|
|
17
28
|
import { defineNuxtConfig } from 'nuxt';
|
|
18
29
|
|
|
19
30
|
export default defineNuxtConfig({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
26
|
-
readOnlyApiKey: process.env.UNIFORM_API_KEY,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
],
|
|
31
|
+
modules: ['@uniformdev/uniform-nuxt'],
|
|
32
|
+
uniform: {
|
|
33
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
34
|
+
readOnlyApiKey: process.env.UNIFORM_API_KEY,
|
|
35
|
+
}
|
|
30
36
|
});
|
|
31
37
|
```
|
|
32
38
|
|
|
@@ -35,8 +41,8 @@ export default defineNuxtConfig({
|
|
|
35
41
|
- Auto-registers the needed Uniform components.
|
|
36
42
|
- Creates a Canvas client automatically.
|
|
37
43
|
- Creates a Uniform Context instance and provides it through the whole app, without the need of a wrapping component.
|
|
38
|
-
- Provides a handy `$useComposition` composable,
|
|
39
|
-
-
|
|
44
|
+
- Provides a handy `$useComposition` composable, built on top of Nuxt's [useAsyncData](https://v3.nuxtjs.org/api/composables/use-async-data).
|
|
45
|
+
- Handles Live Preview.
|
|
40
46
|
- Watches query string change, which Nuxt doesn't do by default.
|
|
41
47
|
|
|
42
48
|
## API reference
|
|
@@ -50,7 +56,12 @@ These are the option you pass to the module in `nuxt.config.ts`.
|
|
|
50
56
|
| `readOnlyApiKey`* | string | An API key that has read permissions to your Uniform project. ⚠️ Make sure the API key has only read access, because it's used in Nuxt's public runtime config |
|
|
51
57
|
| `manifest` | ManifestV2 | The Uniform Context manifest. This one is usually fetched right before the app is started using Uniform's CLI. Uniform Context won't be enabled if a manifest is missing. |
|
|
52
58
|
| `outputType` | 'standard' \| 'edge' | Set it to 'edge' when building the app for the edge using [NESI technology](https://docs.uniform.app/context/reference/netlify). Defaults to 'standard' |
|
|
53
|
-
| `apiHost` | string | The host to be used when calling the API. Defaults to
|
|
59
|
+
| `apiHost` | string | The host to be used when calling the API. Defaults to `https://uniform.app` |
|
|
60
|
+
| `defaultConsent` | boolean | Sets the default value of the user consent. Defaults to `false` |
|
|
61
|
+
| `enableContextDevTools` | boolean | Enables the [Context DevTools](https://docs.uniform.app/context/getting-started/browser-extension) plugin. Defaults to `true` |
|
|
62
|
+
| `uniformContextPath` | string | The path to a file that exports a Unifrom Context instance as default.<br>This will override the values of `manifest`, `defaultConsent` and `enableContextDevTools`. Useful for advanced use cases (such us using plugins other than the Context DevTools one). |
|
|
63
|
+
|
|
64
|
+
|
|
54
65
|
\* Required
|
|
55
66
|
|
|
56
67
|
### Injected in the Nuxt instance
|
|
@@ -58,38 +69,38 @@ These are the properties that the module injects in the Nuxt app instance, so yo
|
|
|
58
69
|
|
|
59
70
|
| Property | Type | Description |
|
|
60
71
|
|---|---|---|
|
|
61
|
-
| `$useComposition` | function | A
|
|
62
|
-
| `$useUniformContext` | function | A
|
|
72
|
+
| `$useComposition` | function | A Vue composable that you can use to fetch a Canvas composition. It's preview-aware, it will automatically fetch the draft composition if the app is in preview mode, otherwise it will return the published one. It uses Suspense under the hood, so you can have access to the error and pending states of the request |
|
|
73
|
+
| `$useUniformContext` | function | A Vue composable that returns the current Uniform Context instance which allows you interact with the context such updating the scores and so on. It also returns other provided properties such as `outputType` |
|
|
63
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. |
|
|
64
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. |
|
|
65
|
-
|
|
76
|
+
|
|
66
77
|
|
|
67
78
|
### Components
|
|
68
79
|
These are the components that the module auto registers for you, so you can use them without import.
|
|
69
80
|
|
|
70
|
-
####
|
|
81
|
+
#### \<Composition />
|
|
71
82
|
This component wraps the whole composition, it
|
|
72
83
|
|
|
73
84
|
| Prop | Type | Description |
|
|
74
85
|
|---|---|---|
|
|
75
86
|
| `data`* | string | The data of the composition to be rendered, this is usually the `composition` object that you get from `$useComposition` |
|
|
76
|
-
| `resolveRenderer` | function | This function is responsible of 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
|
|
87
|
+
| `resolveRenderer` | function | This function is responsible of 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.|
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
\* Required
|
|
79
90
|
|
|
80
|
-
####
|
|
91
|
+
#### \<SlotContent />
|
|
81
92
|
This component is used to render the slots of a composition, and it can be only used inside a `<Composition />`.
|
|
82
93
|
You can nest `<SlotContent />` inside each other if you have nested slots.
|
|
83
94
|
|
|
84
95
|
| Prop | Type | Description |
|
|
85
96
|
|---|---|---|
|
|
86
|
-
| `name` | string | The name of the Canvas slot to render
|
|
97
|
+
| `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). |
|
|
87
98
|
|
|
88
|
-
##
|
|
99
|
+
## Examples
|
|
89
100
|
|
|
90
101
|
Here are some example where the module is used:
|
|
91
102
|
- https://github.com/uniformdev/uniformconf-nuxt
|
|
92
|
-
- https://github.com/uniformdev/nuxt-canvas-
|
|
103
|
+
- https://github.com/uniformdev/nuxt-canvas-context-helloworld
|
|
93
104
|
|
|
94
105
|
|
|
95
106
|
|
package/dist/module.d.ts
CHANGED
|
@@ -2,13 +2,33 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
2
2
|
import { ManifestV2 } from '@uniformdev/context';
|
|
3
3
|
|
|
4
4
|
interface UniformModuleOptions {
|
|
5
|
+
/** The ID of the Uniform project you want to use in your app. */
|
|
5
6
|
projectId: string;
|
|
7
|
+
/** An API key that has read permissions to your Uniform project. ⚠️ Make sure the API key has only read access, because it's used in Nuxt's public runtime config */
|
|
6
8
|
readOnlyApiKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* The host to be used when calling the API.
|
|
11
|
+
* @default 'https://uniform.app'
|
|
12
|
+
*/
|
|
7
13
|
apiHost?: string;
|
|
14
|
+
/** The Uniform Context manifest. This one is usually fetched right before the app is started using Uniform's CLI. Uniform Context won't be enabled if a manifest is missing. */
|
|
8
15
|
manifest?: ManifestV2;
|
|
16
|
+
/**
|
|
17
|
+
* Set it to 'edge' when building the app for the edge using [NESI technology](https://docs.uniform.app/context/reference/netlify)
|
|
18
|
+
* @default 'standard'
|
|
19
|
+
*/
|
|
9
20
|
outputType?: string;
|
|
21
|
+
/** The path to a file that exports a Unifrom Context instance as default.<br>This will override the values of `manifest`, `defaultConsent` and `enableContextDevTools`. Useful for advanced use cases (such us using plugins other than the Context DevTools one). */
|
|
10
22
|
uniformContextPath?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the default value of the user consent.
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
11
27
|
defaultConsent?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Enables the [Context DevTools](https://docs.uniform.app/context/getting-started/browser-extension) plugin.
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
12
32
|
enableContextDevTools?: boolean;
|
|
13
33
|
}
|
|
14
34
|
declare const _default: _nuxt_schema.NuxtModule<UniformModuleOptions>;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -19,6 +19,7 @@ const module = defineNuxtModule({
|
|
|
19
19
|
enableContextDevTools: true
|
|
20
20
|
},
|
|
21
21
|
setup(options, nuxt) {
|
|
22
|
+
options.apiHost;
|
|
22
23
|
if (!options.projectId || !options.readOnlyApiKey) {
|
|
23
24
|
throw new Error("uniform-nuxt: The module options 'projectId' and 'readOnlyApiKey' are required");
|
|
24
25
|
}
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineNuxtPlugin,
|
|
3
3
|
useRoute,
|
|
4
|
+
useRouter,
|
|
4
5
|
useRuntimeConfig,
|
|
5
6
|
useHead,
|
|
6
7
|
refreshNuxtData,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
} from "@uniformdev/canvas";
|
|
18
19
|
import {
|
|
19
20
|
Context,
|
|
21
|
+
SERVER_STATE_ID,
|
|
20
22
|
CookieTransitionDataStore,
|
|
21
23
|
enableContextDevTools,
|
|
22
24
|
UNIFORM_DEFAULT_COOKIE_NAME
|
|
@@ -24,7 +26,8 @@ import {
|
|
|
24
26
|
import { Composition, SlotContent, useCompositionEventEffect } from "@uniformdev/canvas-vue";
|
|
25
27
|
import {
|
|
26
28
|
provideUniformContext,
|
|
27
|
-
onRouteChange
|
|
29
|
+
onRouteChange,
|
|
30
|
+
useUniformContext
|
|
28
31
|
} from "@uniformdev/context-vue";
|
|
29
32
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
30
33
|
if (nuxtApp.$uniformIsSetup) {
|
|
@@ -40,6 +43,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
40
43
|
return {
|
|
41
44
|
provide: {
|
|
42
45
|
uniformIsSetup: true,
|
|
46
|
+
useUniformContext,
|
|
43
47
|
preview,
|
|
44
48
|
uniformCanvasClient,
|
|
45
49
|
uniformContext: uniformContextData.context,
|
|
@@ -47,7 +51,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
47
51
|
}
|
|
48
52
|
};
|
|
49
53
|
} catch (e) {
|
|
50
|
-
console.
|
|
54
|
+
console.error("uniform-nuxt: An error occurred while initializing the Uniform plugin", e);
|
|
51
55
|
}
|
|
52
56
|
});
|
|
53
57
|
function setupContext(nuxtApp) {
|
|
@@ -74,10 +78,23 @@ function setupContext(nuxtApp) {
|
|
|
74
78
|
outputType: options.outputType,
|
|
75
79
|
vueAppInstance: nuxtApp.vueApp
|
|
76
80
|
});
|
|
81
|
+
if (uniformContext && typeof window === "undefined") {
|
|
82
|
+
const transferState = uniformContext.getServerToClientTransitionState();
|
|
83
|
+
useHead({
|
|
84
|
+
script: [
|
|
85
|
+
{
|
|
86
|
+
children: JSON.stringify(transferState),
|
|
87
|
+
id: SERVER_STATE_ID,
|
|
88
|
+
type: "application/json"
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
77
93
|
const route = useRoute();
|
|
78
|
-
watch(
|
|
79
|
-
if (uniformContext)
|
|
94
|
+
watch(route, () => {
|
|
95
|
+
if (uniformContext) {
|
|
80
96
|
onRouteChange(uniformContext);
|
|
97
|
+
}
|
|
81
98
|
});
|
|
82
99
|
return { context: uniformContext, outputType: options.outputType };
|
|
83
100
|
}
|
|
@@ -93,14 +110,26 @@ function setupCanvas(nuxtApp) {
|
|
|
93
110
|
return uniformCanvasClient;
|
|
94
111
|
}
|
|
95
112
|
function setupPreview() {
|
|
113
|
+
const router = useRouter();
|
|
96
114
|
const route = useRoute();
|
|
97
115
|
let preview;
|
|
98
116
|
if (route.query.preview === "true") {
|
|
99
117
|
console.log("uniform-nuxt: \u{1F575}\uFE0F Entering preview mode");
|
|
100
118
|
preview = {
|
|
101
|
-
slug: route.query.slug
|
|
119
|
+
slug: route.query.slug,
|
|
120
|
+
compositionId: route.query.id
|
|
102
121
|
};
|
|
103
122
|
}
|
|
123
|
+
router.beforeEach((to, from, next) => {
|
|
124
|
+
if (from.query.preview === "true" && to.query.preview !== "true") {
|
|
125
|
+
return next({
|
|
126
|
+
path: to.path,
|
|
127
|
+
hash: to.hash,
|
|
128
|
+
query: { ...to.query, preview: "true" }
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return next();
|
|
132
|
+
});
|
|
104
133
|
return preview;
|
|
105
134
|
}
|
|
106
135
|
function setupLivePreview(currentCompositionId, isPreview = false) {
|
|
@@ -121,11 +150,16 @@ function setupLivePreview(currentCompositionId, isPreview = false) {
|
|
|
121
150
|
}
|
|
122
151
|
function setupUseComposition(uniformCanvasClient, currentCompositionId, preview) {
|
|
123
152
|
const useComposition = async (options) => {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
})
|
|
128
|
-
|
|
153
|
+
const slug = preview?.slug ?? options.slug;
|
|
154
|
+
const compositionId = preview?.compositionId ?? options.compositionId;
|
|
155
|
+
const state = preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE;
|
|
156
|
+
const { data, pending, error } = await useAsyncData(`composition-${slug || compositionId}`, async () => {
|
|
157
|
+
if (slug) {
|
|
158
|
+
return await uniformCanvasClient.getCompositionBySlug({ slug, state });
|
|
159
|
+
}
|
|
160
|
+
return await uniformCanvasClient.getCompositionById({ compositionId, state });
|
|
161
|
+
});
|
|
162
|
+
currentCompositionId.value = data.value?.composition._id ?? "";
|
|
129
163
|
return { data, pending, error };
|
|
130
164
|
};
|
|
131
165
|
return useComposition;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/uniform-nuxt",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.2.1-nuxt.249+6d2287689",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -16,11 +16,14 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"prepack": "nuxt-module-build",
|
|
19
|
-
"build": "nuxt-module-build"
|
|
19
|
+
"build": "nuxt-module-build",
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
|
+
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",
|
|
22
|
+
"format": "prettier --write \"src/**/*.{js,ts,tsx}\""
|
|
20
23
|
},
|
|
21
24
|
"dependencies": {
|
|
22
25
|
"@nuxt/kit": "^3.0.0-rc.4",
|
|
23
|
-
"vue-demi": "^0.
|
|
26
|
+
"vue-demi": "^0.13.0"
|
|
24
27
|
},
|
|
25
28
|
"peerDependencies": {
|
|
26
29
|
"@uniformdev/canvas": ">15",
|
|
@@ -30,19 +33,20 @@
|
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
35
|
"@nuxt/module-builder": "0.1.7",
|
|
33
|
-
"@nuxt/schema": "3.0.0-rc.
|
|
36
|
+
"@nuxt/schema": "3.0.0-rc.5",
|
|
34
37
|
"@nuxtjs/eslint-config-typescript": "10.0.0",
|
|
35
|
-
"@uniformdev/canvas": "^16.
|
|
36
|
-
"@uniformdev/canvas-vue": "^16.
|
|
37
|
-
"@uniformdev/context": "^16.
|
|
38
|
-
"@uniformdev/context-vue": "^16.
|
|
38
|
+
"@uniformdev/canvas": "^16.2.1-nuxt.249+6d2287689",
|
|
39
|
+
"@uniformdev/canvas-vue": "^16.2.1-nuxt.249+6d2287689",
|
|
40
|
+
"@uniformdev/context": "^16.2.1-nuxt.249+6d2287689",
|
|
41
|
+
"@uniformdev/context-vue": "^16.2.1-nuxt.249+6d2287689",
|
|
39
42
|
"esbuild": "0.13.15",
|
|
40
43
|
"eslint": "latest",
|
|
41
|
-
"nuxt": "
|
|
42
|
-
"vue": "3.2.37"
|
|
44
|
+
"nuxt": "3.0.0-rc.5",
|
|
45
|
+
"vue": "3.2.37",
|
|
46
|
+
"vue-router": "3.5.4"
|
|
43
47
|
},
|
|
44
48
|
"publishConfig": {
|
|
45
49
|
"access": "public"
|
|
46
50
|
},
|
|
47
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "6d2287689097cb256d17483ea3726d4bb87b2fa6"
|
|
48
52
|
}
|