@uniformdev/uniform-nuxt 16.0.1-nuxt.158 → 16.2.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 +91 -4
- package/dist/module.json +1 -1
- package/dist/runtime/plugin.mjs +6 -3
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -1,9 +1,96 @@
|
|
|
1
|
-
# Uniform Nuxt
|
|
1
|
+
# Uniform Nuxt module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
Install the peer dependencies of the module (if you haven't already):
|
|
6
|
+
```
|
|
7
|
+
npm i @uniformdev/canvas @uniformdev/canvas-vue @uniformdev/context @uniformdev/context-vue
|
|
8
|
+
```
|
|
9
|
+
Install the module
|
|
10
|
+
```
|
|
11
|
+
npm i @uniformdev/uniform-nuxt
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Add the module to you Nuxt config:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { defineNuxtConfig } from 'nuxt';
|
|
18
|
+
|
|
19
|
+
export default defineNuxtConfig({
|
|
20
|
+
transpile: ['@uniformdev/canvas-vue', '@uniformdev/context-vue'],
|
|
21
|
+
modules: [
|
|
22
|
+
[
|
|
23
|
+
'@uniformdev/uniform-nuxt',
|
|
24
|
+
{
|
|
25
|
+
projectId: process.env.UNIFORM_PROJECT_ID,
|
|
26
|
+
readOnlyApiKey: process.env.UNIFORM_API_KEY,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- Auto-registers the needed Uniform components.
|
|
36
|
+
- Creates a Canvas client automatically.
|
|
37
|
+
- 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, build on top of Nuxt's [useAsyncData](https://v3.nuxtjs.org/api/composables/use-async-data).
|
|
39
|
+
- Handle Live Preview.
|
|
40
|
+
- Watches query string change, which Nuxt doesn't do by default.
|
|
41
|
+
|
|
42
|
+
## API reference
|
|
43
|
+
|
|
44
|
+
### Options
|
|
45
|
+
These are the option you pass to the module in `nuxt.config.ts`.
|
|
46
|
+
|
|
47
|
+
| Option | Type | Description |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `projectId`* | string | The ID of the Uniform project you want to use in your app. |
|
|
50
|
+
| `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
|
+
| `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
|
+
| `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 'https://uniform.app' |
|
|
54
|
+
\* Required
|
|
55
|
+
|
|
56
|
+
### Injected in the Nuxt instance
|
|
57
|
+
These are the properties that the module injects in the Nuxt app instance, so you can use them anywhere in your app.
|
|
58
|
+
|
|
59
|
+
| Property | Type | Description |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| `$useComposition` | function | A compasable 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 |
|
|
62
|
+
| `$useUniformContext` | function | A compasable 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
|
+
| `$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
|
+
| `$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
|
+
| `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. |
|
|
66
|
+
|
|
67
|
+
### Components
|
|
68
|
+
These are the components that the module auto registers for you, so you can use them without import.
|
|
69
|
+
|
|
70
|
+
#### <Composition />
|
|
71
|
+
This component wraps the whole composition, it
|
|
72
|
+
|
|
73
|
+
| Prop | Type | Description |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `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 componnet in 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 Canvas component|
|
|
77
|
+
|
|
78
|
+
* Required
|
|
79
|
+
|
|
80
|
+
#### <SlotContent />
|
|
81
|
+
This component is used to render the slots of a composition, and it can be only used inside a `<Composition />`.
|
|
82
|
+
You can nest `<SlotContent />` inside each other if you have nested slots.
|
|
83
|
+
|
|
84
|
+
| Prop | Type | Description |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `name` | string | The name of the Canvas slot to render. If no name is provided, all the slots will be rendered. This is not recommended as the order is not guaranteed |
|
|
87
|
+
|
|
88
|
+
## Example
|
|
89
|
+
|
|
90
|
+
Here are some example where the module is used:
|
|
91
|
+
- https://github.com/uniformdev/uniformconf-nuxt
|
|
92
|
+
- https://github.com/uniformdev/nuxt-canvas-nuxt
|
|
4
93
|
|
|
5
|
-
In the meantime, here is a working example on how to use the module:
|
|
6
|
-
https://github.com/uniformdev/uniformconf-nuxt/blob/main/nuxt.config.ts
|
|
7
94
|
|
|
8
95
|
|
|
9
96
|
-----
|
package/dist/module.json
CHANGED
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useState,
|
|
9
9
|
useCookie
|
|
10
10
|
} from "#app";
|
|
11
|
-
import { watch } from "vue-demi";
|
|
11
|
+
import { watch, toRaw } from "vue-demi";
|
|
12
12
|
import {
|
|
13
13
|
CanvasClient,
|
|
14
14
|
CANVAS_DRAFT_STATE,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
Context,
|
|
19
19
|
CookieTransitionDataStore,
|
|
20
|
+
enableContextDevTools,
|
|
20
21
|
UNIFORM_DEFAULT_COOKIE_NAME
|
|
21
22
|
} from "@uniformdev/context";
|
|
22
23
|
import { Composition, SlotContent, useCompositionEventEffect } from "@uniformdev/canvas-vue";
|
|
@@ -52,12 +53,14 @@ function setupContext(nuxtApp) {
|
|
|
52
53
|
let uniformContext;
|
|
53
54
|
if (options.manifest) {
|
|
54
55
|
console.log("uniform-nuxt: \u{1F4DC} found a manifest, will initialize Context");
|
|
56
|
+
const manifestAsSimpleObject = toRaw(options.manifest);
|
|
55
57
|
uniformContext = new Context({
|
|
56
58
|
defaultConsent: true,
|
|
57
|
-
manifest:
|
|
59
|
+
manifest: manifestAsSimpleObject,
|
|
58
60
|
transitionStore: new CookieTransitionDataStore({
|
|
59
61
|
serverCookieValue: uniformCookie
|
|
60
|
-
})
|
|
62
|
+
}),
|
|
63
|
+
plugins: [enableContextDevTools()]
|
|
61
64
|
});
|
|
62
65
|
}
|
|
63
66
|
provideUniformContext({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/uniform-nuxt",
|
|
3
|
-
"version": "16.0
|
|
3
|
+
"version": "16.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -30,16 +30,15 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@nuxt/module-builder": "0.1.7",
|
|
32
32
|
"@nuxtjs/eslint-config-typescript": "10.0.0",
|
|
33
|
-
"@uniformdev/canvas": "^16.0
|
|
34
|
-
"@uniformdev/canvas-vue": "^16.0
|
|
35
|
-
"@uniformdev/context": "^16.0
|
|
36
|
-
"@uniformdev/context-vue": "^16.0
|
|
33
|
+
"@uniformdev/canvas": "^16.2.0",
|
|
34
|
+
"@uniformdev/canvas-vue": "^16.2.0",
|
|
35
|
+
"@uniformdev/context": "^16.2.0",
|
|
36
|
+
"@uniformdev/context-vue": "^16.2.0",
|
|
37
37
|
"esbuild": "0.13.15",
|
|
38
38
|
"eslint": "latest",
|
|
39
39
|
"nuxt": "^3.0.0-rc.4"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
|
-
}
|
|
44
|
-
"gitHead": "fac0325bab53217a4c5a3c63d549812678f484f3"
|
|
43
|
+
}
|
|
45
44
|
}
|