@uniformdev/uniform-nuxt 17.5.1-alpha.7 → 17.6.1-alpha.60
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 } = useUniformComposition({
|
|
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 CompositionGetByIdParameters, type CompositionGetByNodeIdParameters, type CompositionGetByNodePathParameters, type CompositionGetBySlugParameters, type DataResolutionOption, type RootComponentInstance } 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,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CANVAS_DRAFT_STATE,
|
|
3
|
+
CANVAS_PUBLISHED_STATE
|
|
4
|
+
} from "@uniformdev/canvas";
|
|
5
|
+
import { useContextualEditing } from "@uniformdev/canvas-vue";
|
|
6
|
+
import { ref, toRaw, watch } from "vue-demi";
|
|
7
|
+
import { useAsyncData, useNuxtApp } from "#app";
|
|
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
|
+
let response = void 0;
|
|
32
|
+
if ("slug" in parameters) {
|
|
33
|
+
response = await canvasClient.getCompositionBySlug({
|
|
34
|
+
...parameters,
|
|
35
|
+
state
|
|
36
|
+
});
|
|
37
|
+
} else if ("compositionId" in parameters) {
|
|
38
|
+
response = await canvasClient.getCompositionById({
|
|
39
|
+
...parameters,
|
|
40
|
+
state
|
|
41
|
+
});
|
|
42
|
+
} else if ("projectMapNodeId" in parameters) {
|
|
43
|
+
response = await canvasClient.unstable_getCompositionByNodeId({
|
|
44
|
+
...parameters,
|
|
45
|
+
state
|
|
46
|
+
});
|
|
47
|
+
} else if ("projectMapNodePath" in parameters) {
|
|
48
|
+
response = await canvasClient.unstable_getCompositionByNodePath({
|
|
49
|
+
...parameters,
|
|
50
|
+
state
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (!response) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Failed to fetch the composition with the given parameters: ${JSON.stringify(parameters)}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const composition = await enhance(response.composition);
|
|
59
|
+
return { composition, response };
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
activeComposition.value = data.value?.composition;
|
|
63
|
+
return {
|
|
64
|
+
composition: activeComposition,
|
|
65
|
+
fullResponse: data.value?.response,
|
|
66
|
+
pending,
|
|
67
|
+
error
|
|
68
|
+
};
|
|
69
|
+
};
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
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
|
+
refreshNuxtData,
|
|
23
|
+
useAsyncData,
|
|
24
|
+
useCookie,
|
|
25
|
+
useHead,
|
|
26
|
+
useRoute,
|
|
27
|
+
useRouter,
|
|
28
|
+
useRuntimeConfig,
|
|
29
|
+
useState
|
|
30
|
+
} from "#app";
|
|
31
|
+
import userProvidedContextInstance from "#build/uniform/context/instance";
|
|
32
32
|
const log = process.env.NODE_ENV === "development" ? (...args) => console.log(...args) : () => {
|
|
33
33
|
};
|
|
34
34
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -37,7 +37,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
37
37
|
}
|
|
38
38
|
try {
|
|
39
39
|
const currentCompositionId = useState("currentCompositionId", () => "");
|
|
40
|
-
const preview = setupPreview();
|
|
40
|
+
const preview = setupPreview(nuxtApp);
|
|
41
41
|
const uniformContextData = setupContext(nuxtApp);
|
|
42
42
|
const uniformCanvasClient = setupCanvas(nuxtApp);
|
|
43
43
|
setupLivePreview(currentCompositionId, Boolean(preview));
|
|
@@ -113,7 +113,7 @@ function setupCanvas(nuxtApp) {
|
|
|
113
113
|
});
|
|
114
114
|
return uniformCanvasClient;
|
|
115
115
|
}
|
|
116
|
-
function setupPreview() {
|
|
116
|
+
function setupPreview(nuxtApp) {
|
|
117
117
|
const router = useRouter();
|
|
118
118
|
const route = useRoute();
|
|
119
119
|
let preview;
|
|
@@ -124,6 +124,18 @@ function setupPreview() {
|
|
|
124
124
|
compositionId: route.query.id
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
+
nuxtApp.hook("app:beforeMount", () => {
|
|
128
|
+
if (preview && route.query.slug) {
|
|
129
|
+
router.push({
|
|
130
|
+
path: preview?.slug,
|
|
131
|
+
query: {
|
|
132
|
+
...route.query,
|
|
133
|
+
slug: void 0,
|
|
134
|
+
id: void 0
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
127
139
|
router.beforeEach((to, from, next) => {
|
|
128
140
|
if (!next) {
|
|
129
141
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/uniform-nuxt",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.6.1-alpha.60+dce2049a1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"@uniformdev/context-vue": ">15"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@nuxt/module-builder": "0.2.
|
|
35
|
+
"@nuxt/module-builder": "0.2.1",
|
|
36
36
|
"@nuxt/schema": "3.0.0",
|
|
37
37
|
"@nuxtjs/eslint-config-typescript": "11.0.0",
|
|
38
|
-
"@uniformdev/canvas": "^17.
|
|
39
|
-
"@uniformdev/canvas-vue": "^17.
|
|
40
|
-
"@uniformdev/context": "^17.
|
|
41
|
-
"@uniformdev/context-vue": "^17.
|
|
42
|
-
"esbuild": "0.15.
|
|
38
|
+
"@uniformdev/canvas": "^17.6.1-alpha.60+dce2049a1",
|
|
39
|
+
"@uniformdev/canvas-vue": "^17.6.1-alpha.60+dce2049a1",
|
|
40
|
+
"@uniformdev/context": "^17.6.1-alpha.60+dce2049a1",
|
|
41
|
+
"@uniformdev/context-vue": "^17.6.1-alpha.60+dce2049a1",
|
|
42
|
+
"esbuild": "0.15.16",
|
|
43
43
|
"eslint": "latest",
|
|
44
44
|
"nuxt": "3.0.0",
|
|
45
45
|
"vue": "3.2.45",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "dce2049a142bec6e78cda9d976eacf13a96aa483"
|
|
52
52
|
}
|