@b10cks/nuxt 0.10.0 → 0.10.2
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 +73 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +7 -3
- package/dist/runtime/composables/useB10cksApi.d.ts +1 -2
- package/dist/runtime/composables/useB10cksApi.js +42 -56
- package/dist/runtime/plugin.js +14 -11
- package/package.json +19 -21
package/README.md
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @b10cks/nuxt
|
|
2
|
+
|
|
3
|
+
Nuxt 4 module for integrating b10cks into your Nuxt applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @b10cks/nuxt @b10cks/vue @b10cks/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Add the module to your `nuxt.config.ts`:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
export default defineNuxtConfig({
|
|
17
|
+
modules: ['@b10cks/nuxt'],
|
|
18
|
+
b10cks: {
|
|
19
|
+
accessToken: 'your-access-token',
|
|
20
|
+
apiUrl: 'https://api.b10cks.com/api',
|
|
21
|
+
componentsDir: '~/b10cks', // Optional: custom components directory
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Directives
|
|
29
|
+
|
|
30
|
+
#### `v-editable`
|
|
31
|
+
|
|
32
|
+
Mark content as editable within the b10cks editor.
|
|
33
|
+
|
|
34
|
+
```vue
|
|
35
|
+
<div v-editable="block">
|
|
36
|
+
Content here
|
|
37
|
+
</div>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### `v-editable-field`
|
|
41
|
+
|
|
42
|
+
Mark specific fields within editable blocks.
|
|
43
|
+
|
|
44
|
+
```vue
|
|
45
|
+
<div v-editable="block">
|
|
46
|
+
<h1 v-editable-field="{ id: block.id, field: 'title' }">Title</h1>
|
|
47
|
+
<p v-editable-field="{ id: block.id, field: 'description' }">Description</p>
|
|
48
|
+
</div>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Components
|
|
52
|
+
|
|
53
|
+
#### `B10cksComponent`
|
|
54
|
+
|
|
55
|
+
Render b10cks components directly in your Nuxt app.
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<B10cksComponent :component="componentData" />
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Custom Components
|
|
62
|
+
|
|
63
|
+
Place your custom b10cks components in the `~/b10cks` directory (or your configured `componentsDir`). They will be auto-imported as global components.
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
- `accessToken` - Your b10cks API access token (required)
|
|
68
|
+
- `apiUrl` - The b10cks API endpoint (default: `https://api.b10cks.com/api`)
|
|
69
|
+
- `componentsDir` - Directory for custom components (default: `~/b10cks`)
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addComponentsDir, addPlugin, addImports } from '@nuxt/kit';
|
|
2
2
|
|
|
3
|
-
const module = defineNuxtModule({
|
|
3
|
+
const module$1 = defineNuxtModule({
|
|
4
4
|
meta: {
|
|
5
5
|
name: "@b10cks/nuxt",
|
|
6
6
|
configKey: "b10cks"
|
|
@@ -23,9 +23,13 @@ const module = defineNuxtModule({
|
|
|
23
23
|
apiUrl: options.apiUrl
|
|
24
24
|
};
|
|
25
25
|
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
26
|
-
addImports({
|
|
26
|
+
addImports({
|
|
27
|
+
name: "useB10cksApi",
|
|
28
|
+
as: "useB10cksApi",
|
|
29
|
+
from: resolver.resolve("./runtime/composables/useB10cksApi")
|
|
30
|
+
});
|
|
27
31
|
nuxt.options.typescript.hoist.push("@b10cks/vue");
|
|
28
32
|
}
|
|
29
33
|
});
|
|
30
34
|
|
|
31
|
-
export { module as default };
|
|
35
|
+
export { module$1 as default };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { IBBaseQueryParams, IBBlock, IBContent, IBContentQueryParams, IBDataEntry, IBDataSource,
|
|
2
|
-
import type { Endpoint } from '@b10cks/client';
|
|
1
|
+
import type { Endpoint, IBBaseQueryParams, IBBlock, IBContent, IBContentQueryParams, IBDataEntry, IBDataSource, IBResponse, IBSpace } from '@b10cks/client';
|
|
3
2
|
export interface UseB10cksApiOptions<T> {
|
|
4
3
|
immediate?: boolean;
|
|
5
4
|
params?: Omit<IBBaseQueryParams, 'token'>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { computed, ref } from "vue";
|
|
2
1
|
import { useNuxtApp, useState } from "#app";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
3
|
export const useB10cksApi = () => {
|
|
4
4
|
const { $b10cksClient } = useNuxtApp();
|
|
5
5
|
function useApiResource(endpoint, options = {}) {
|
|
@@ -41,8 +41,7 @@ export const useB10cksApi = () => {
|
|
|
41
41
|
pending.value = true;
|
|
42
42
|
error.value = null;
|
|
43
43
|
try {
|
|
44
|
-
|
|
45
|
-
data.value = results;
|
|
44
|
+
data.value = await $b10cksClient.getAll(endpoint, params);
|
|
46
45
|
return data.value;
|
|
47
46
|
} catch (err) {
|
|
48
47
|
error.value = err instanceof Error ? err : new Error(String(err));
|
|
@@ -63,70 +62,52 @@ export const useB10cksApi = () => {
|
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
64
|
const useContent = (full_slug, params = {}, options = {}) => {
|
|
66
|
-
return useApiResource(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if ("data" in result) {
|
|
73
|
-
return result.data;
|
|
74
|
-
}
|
|
75
|
-
return result;
|
|
65
|
+
return useApiResource(`contents/${full_slug}`, {
|
|
66
|
+
...options,
|
|
67
|
+
params,
|
|
68
|
+
transform: (result) => {
|
|
69
|
+
if ("data" in result) {
|
|
70
|
+
return result.data;
|
|
76
71
|
}
|
|
72
|
+
return result;
|
|
77
73
|
}
|
|
78
|
-
);
|
|
74
|
+
});
|
|
79
75
|
};
|
|
80
76
|
const useContents = (params = {}, options = {}) => {
|
|
81
|
-
return useApiCollection(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
params
|
|
86
|
-
}
|
|
87
|
-
);
|
|
77
|
+
return useApiCollection("contents", {
|
|
78
|
+
...options,
|
|
79
|
+
params
|
|
80
|
+
});
|
|
88
81
|
};
|
|
89
82
|
const useBlocks = (params = {}, options = {}) => {
|
|
90
|
-
return useApiCollection(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
params
|
|
95
|
-
}
|
|
96
|
-
);
|
|
83
|
+
return useApiCollection("blocks", {
|
|
84
|
+
...options,
|
|
85
|
+
params
|
|
86
|
+
});
|
|
97
87
|
};
|
|
98
88
|
const useDataEntries = (source, params = {}, options = {}) => {
|
|
99
|
-
return useApiCollection(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
params
|
|
104
|
-
}
|
|
105
|
-
);
|
|
89
|
+
return useApiCollection(`datasources/${source}/entries`, {
|
|
90
|
+
...options,
|
|
91
|
+
params
|
|
92
|
+
});
|
|
106
93
|
};
|
|
107
94
|
const useDataSources = (options = {}) => {
|
|
108
|
-
return useApiCollection(
|
|
109
|
-
"datasources",
|
|
110
|
-
options
|
|
111
|
-
);
|
|
95
|
+
return useApiCollection("datasources", options);
|
|
112
96
|
};
|
|
113
97
|
const useSpace = (options = {}) => {
|
|
114
|
-
return useApiResource(
|
|
115
|
-
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if ("data" in result) {
|
|
120
|
-
return result.data;
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
98
|
+
return useApiResource("spaces/me", {
|
|
99
|
+
...options,
|
|
100
|
+
transform: (result) => {
|
|
101
|
+
if ("data" in result) {
|
|
102
|
+
return result.data;
|
|
123
103
|
}
|
|
104
|
+
return result;
|
|
124
105
|
}
|
|
125
|
-
);
|
|
106
|
+
});
|
|
126
107
|
};
|
|
127
108
|
const cache = useState("redirects");
|
|
128
109
|
const useRedirects = (options = {}) => {
|
|
129
|
-
const { immediate = true, params = {}
|
|
110
|
+
const { immediate = true, params = {} } = options;
|
|
130
111
|
const pending = ref(false);
|
|
131
112
|
const data = ref(cache.value || null);
|
|
132
113
|
const error = ref(null);
|
|
@@ -137,12 +118,12 @@ export const useB10cksApi = () => {
|
|
|
137
118
|
pending.value = true;
|
|
138
119
|
error.value = null;
|
|
139
120
|
try {
|
|
140
|
-
const results = await $b10cksClient.getAll(
|
|
121
|
+
const results = await $b10cksClient.getAll(
|
|
122
|
+
"redirects",
|
|
123
|
+
params
|
|
124
|
+
);
|
|
141
125
|
const transformed = Object.fromEntries(
|
|
142
|
-
results.map(({ source, target, status_code }) => [
|
|
143
|
-
source,
|
|
144
|
-
{ target, status_code }
|
|
145
|
-
])
|
|
126
|
+
results.map(({ source, target, status_code }) => [source, { target, status_code }])
|
|
146
127
|
);
|
|
147
128
|
data.value = transformed;
|
|
148
129
|
cache.value = transformed;
|
|
@@ -166,7 +147,12 @@ export const useB10cksApi = () => {
|
|
|
166
147
|
};
|
|
167
148
|
};
|
|
168
149
|
const configCache = useState("config");
|
|
169
|
-
const useB10cksConfig = async ({
|
|
150
|
+
const useB10cksConfig = async ({
|
|
151
|
+
slug = "_config",
|
|
152
|
+
version,
|
|
153
|
+
language,
|
|
154
|
+
...params
|
|
155
|
+
} = {}) => {
|
|
170
156
|
const options = {
|
|
171
157
|
params: {
|
|
172
158
|
...params,
|
package/dist/runtime/plugin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { useState } from "#app";
|
|
1
2
|
import { ApiClient } from "@b10cks/client";
|
|
2
|
-
import {
|
|
3
|
+
import { B10cksVue, previewBridge } from "@b10cks/vue";
|
|
3
4
|
import { defineNuxtPlugin, useRequestURL, useRuntimeConfig } from "nuxt/app";
|
|
4
|
-
import { useState } from "#app";
|
|
5
5
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
6
6
|
const config = useRuntimeConfig();
|
|
7
7
|
const url = useRequestURL();
|
|
@@ -12,15 +12,18 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
const rvState = useState("b10cks_rv", () => 0);
|
|
15
|
-
const b10cksClient = new ApiClient(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const b10cksClient = new ApiClient(
|
|
16
|
+
{
|
|
17
|
+
baseUrl: config.public.b10cks.apiUrl || "https://api.b10cks.com/api",
|
|
18
|
+
token: config.public.b10cks.accessToken,
|
|
19
|
+
fetchClient: $fetch,
|
|
20
|
+
getRv: () => rvState.value,
|
|
21
|
+
setRv: (value) => {
|
|
22
|
+
rvState.value = value;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
url
|
|
26
|
+
);
|
|
24
27
|
return {
|
|
25
28
|
provide: {
|
|
26
29
|
b10cksClient
|
package/package.json
CHANGED
|
@@ -1,49 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b10cks/nuxt",
|
|
3
|
+
"version": "0.10.2",
|
|
4
|
+
"description": "b10cks Nuxt module",
|
|
3
5
|
"license": "MIT",
|
|
4
|
-
"version": "0.10.0",
|
|
5
6
|
"author": "Michael Wallner @ Coder's Cantina",
|
|
6
|
-
"description": "b10cks Nuxt module",
|
|
7
|
-
"type": "module",
|
|
8
7
|
"repository": {
|
|
9
8
|
"type": "git",
|
|
10
9
|
"url": "https://github.com/b10cks/sdk.git",
|
|
11
10
|
"directory": "packages/nuxt"
|
|
12
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/module.mjs",
|
|
13
17
|
"exports": {
|
|
14
18
|
".": {
|
|
15
19
|
"types": "./dist/types.d.mts",
|
|
16
20
|
"import": "./dist/module.mjs"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@b10cks/client": "^0.10.1",
|
|
28
|
+
"@b10cks/vue": "^0.10.2"
|
|
29
|
+
},
|
|
23
30
|
"devDependencies": {
|
|
24
|
-
"@nuxt/
|
|
25
|
-
"@nuxt/eslint-config": "^1.9.0",
|
|
26
|
-
"@nuxt/kit": "^4.0.3",
|
|
31
|
+
"@nuxt/kit": "^4.2.1",
|
|
27
32
|
"@nuxt/module-builder": "^1.0.2",
|
|
28
|
-
"@nuxt/schema": "^4.
|
|
29
|
-
"nuxt": "^4.
|
|
33
|
+
"@nuxt/schema": "^4.2.1",
|
|
34
|
+
"nuxt": "^4.2.1"
|
|
30
35
|
},
|
|
31
36
|
"release": {
|
|
32
37
|
"branches": [
|
|
33
38
|
"main"
|
|
34
39
|
]
|
|
35
40
|
},
|
|
36
|
-
"publishConfig": {
|
|
37
|
-
"access": "public"
|
|
38
|
-
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@b10cks/client": "^0.10.0",
|
|
41
|
-
"@b10cks/vue": "^0.10.0"
|
|
42
|
-
},
|
|
43
41
|
"scripts": {
|
|
44
42
|
"build": "nuxt-module-build prepare && nuxt-module-build build",
|
|
45
|
-
"lint": "
|
|
46
|
-
"lint:fix": "
|
|
43
|
+
"lint": "biome check --apply .",
|
|
44
|
+
"lint:fix": "biome check --apply .",
|
|
47
45
|
"test": "vitest",
|
|
48
46
|
"clean": "rm -rf dist"
|
|
49
47
|
}
|