@uniformdev/uniform-nuxt 16.0.1-alpha.143
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 +6 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.ts +12 -0
- package/dist/module.json +5 -0
- package/dist/module.mjs +24 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.mjs +100 -0
- package/dist/types.d.ts +10 -0
- package/package.json +38 -0
package/README.md
ADDED
package/dist/module.cjs
ADDED
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { ManifestV2 } from '@uniformdev/context';
|
|
3
|
+
|
|
4
|
+
interface ModuleOptions {
|
|
5
|
+
projectId?: string;
|
|
6
|
+
readOnlyApiKey?: string;
|
|
7
|
+
apiHost?: string;
|
|
8
|
+
manifest?: ManifestV2;
|
|
9
|
+
}
|
|
10
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
11
|
+
|
|
12
|
+
export { ModuleOptions, _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { defineNuxtModule, addPlugin } from '@nuxt/kit';
|
|
4
|
+
|
|
5
|
+
const module = defineNuxtModule({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "nuxt-uniform",
|
|
8
|
+
configKey: "uniform"
|
|
9
|
+
},
|
|
10
|
+
defaults: {
|
|
11
|
+
projectId: void 0,
|
|
12
|
+
readOnlyApiKey: void 0,
|
|
13
|
+
apiHost: "https://uniform.app",
|
|
14
|
+
manifest: void 0
|
|
15
|
+
},
|
|
16
|
+
setup(options, nuxt) {
|
|
17
|
+
nuxt.options.runtimeConfig.public["$uniform"] = { ...options };
|
|
18
|
+
const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
|
|
19
|
+
nuxt.options.build.transpile.push(runtimeDir);
|
|
20
|
+
addPlugin(resolve(runtimeDir, "plugin"));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export { module as default };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRoute, useRuntimeConfig, useHead } from "#app";
|
|
2
|
+
import { watch, ref } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
CanvasClient,
|
|
5
|
+
CANVAS_DRAFT_STATE,
|
|
6
|
+
CANVAS_PUBLISHED_STATE
|
|
7
|
+
} from "@uniformdev/canvas";
|
|
8
|
+
import { Context } from "@uniformdev/context";
|
|
9
|
+
import { Composition, SlotContent, useCompositionEventEffect } from "@uniformdev/canvas-vue";
|
|
10
|
+
import { provideUniformContext, onRouteChange } from "@uniformdev/context-vue";
|
|
11
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
12
|
+
if (nuxtApp.$uniformIsSetup) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const currentCompositionId = ref();
|
|
16
|
+
const preview = setupPreview();
|
|
17
|
+
const uniformContext = setupContext(nuxtApp);
|
|
18
|
+
const uniformCanvasClient = setupCanvas(nuxtApp);
|
|
19
|
+
setupLivePreview(currentCompositionId, Boolean(preview));
|
|
20
|
+
const useComposition = setupUseComposition(uniformCanvasClient, currentCompositionId, preview);
|
|
21
|
+
return {
|
|
22
|
+
provide: {
|
|
23
|
+
uniformIsSetup: true,
|
|
24
|
+
preview,
|
|
25
|
+
uniformCanvasClient,
|
|
26
|
+
uniformContext,
|
|
27
|
+
useComposition
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
function setupContext(nuxtApp) {
|
|
32
|
+
const options = useRuntimeConfig().public.$uniform;
|
|
33
|
+
let uniformContext;
|
|
34
|
+
if (options.manifest) {
|
|
35
|
+
console.log("\u{1F4DC} found a manifest, will initialize Context");
|
|
36
|
+
uniformContext = new Context({
|
|
37
|
+
defaultConsent: true,
|
|
38
|
+
manifest: options.manifest
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
provideUniformContext({
|
|
42
|
+
context: uniformContext,
|
|
43
|
+
outputType: options.outputType,
|
|
44
|
+
vueAppProvide: nuxtApp.vueApp.provide
|
|
45
|
+
});
|
|
46
|
+
const route = useRoute();
|
|
47
|
+
watch(() => JSON.stringify(route.query), () => {
|
|
48
|
+
onRouteChange(uniformContext);
|
|
49
|
+
});
|
|
50
|
+
return uniformContext;
|
|
51
|
+
}
|
|
52
|
+
function setupCanvas(nuxtApp) {
|
|
53
|
+
const options = useRuntimeConfig().public.$uniform;
|
|
54
|
+
nuxtApp.vueApp.component("Composition", Composition);
|
|
55
|
+
nuxtApp.vueApp.component("SlotContent", SlotContent);
|
|
56
|
+
const uniformCanvasClient = new CanvasClient({
|
|
57
|
+
projectId: options.projectId,
|
|
58
|
+
apiKey: options.readOnlyApiKey,
|
|
59
|
+
apiHost: options.apiHost
|
|
60
|
+
});
|
|
61
|
+
return uniformCanvasClient;
|
|
62
|
+
}
|
|
63
|
+
function setupPreview() {
|
|
64
|
+
const route = useRoute();
|
|
65
|
+
let preview;
|
|
66
|
+
if (route.query.preview === "true") {
|
|
67
|
+
console.log("\u{1F575}\uFE0F Entering preview mode");
|
|
68
|
+
preview = {
|
|
69
|
+
slug: route.query.slug
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return preview;
|
|
73
|
+
}
|
|
74
|
+
function setupLivePreview(currentCompositionId, isPreview = false) {
|
|
75
|
+
const { projectId } = useRuntimeConfig().public.$uniform;
|
|
76
|
+
const enabled = isPreview;
|
|
77
|
+
const onCompositionChange = async () => {
|
|
78
|
+
await refreshNuxtData();
|
|
79
|
+
};
|
|
80
|
+
useHead({
|
|
81
|
+
titleTemplate: (title) => enabled ? `\u26A1\uFE0F ${title}` : title
|
|
82
|
+
});
|
|
83
|
+
useCompositionEventEffect({
|
|
84
|
+
compositionIdRef: currentCompositionId,
|
|
85
|
+
projectId,
|
|
86
|
+
enabled,
|
|
87
|
+
effect: onCompositionChange
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function setupUseComposition(uniformCanvasClient, currentCompositionId, preview) {
|
|
91
|
+
const useComposition = async (options) => {
|
|
92
|
+
const { data, pending, error } = await useAsyncData(`composition-${options.slug || options.compositionId}`, async () => await uniformCanvasClient[options.slug ? "getCompositionBySlug" : "getCompositionById"]({
|
|
93
|
+
state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE,
|
|
94
|
+
...options
|
|
95
|
+
}));
|
|
96
|
+
currentCompositionId.value = data.value?.composition._id;
|
|
97
|
+
return { data, pending, error };
|
|
98
|
+
};
|
|
99
|
+
return useComposition;
|
|
100
|
+
}
|
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uniformdev/uniform-nuxt",
|
|
3
|
+
"version": "16.0.1-alpha.143+8bf270fcc",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/module.mjs",
|
|
9
|
+
"require": "./dist/module.cjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/module.cjs",
|
|
13
|
+
"types": "./dist/types.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prepack": "nuxt-module-build",
|
|
19
|
+
"build": "nuxt-module-build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@nuxt/kit": "^3.0.0-rc.4",
|
|
23
|
+
"@uniformdev/canvas": "^16.0.1-alpha.143+8bf270fcc",
|
|
24
|
+
"@uniformdev/canvas-vue": "^16.0.1-alpha.143+8bf270fcc",
|
|
25
|
+
"@uniformdev/context": "^16.0.1-alpha.143+8bf270fcc",
|
|
26
|
+
"@uniformdev/context-vue": "^16.0.1-alpha.143+8bf270fcc"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@nuxt/module-builder": "latest",
|
|
30
|
+
"@nuxtjs/eslint-config-typescript": "latest",
|
|
31
|
+
"eslint": "latest",
|
|
32
|
+
"nuxt": "^3.0.0-rc.4"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "8bf270fcc0cc82383d1f30311fe11dafd5fe3782"
|
|
38
|
+
}
|