druxt 0.18.3 → 0.19.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/dist/components/DruxtModule.vue +48 -9
- package/dist/druxt.esm.js +222 -207
- package/dist/druxt.ssr.js +227 -211
- package/package.json +5 -5
|
@@ -38,6 +38,14 @@ export default {
|
|
|
38
38
|
|
|
39
39
|
/** */
|
|
40
40
|
props: {
|
|
41
|
+
/**
|
|
42
|
+
* The resource langcode.
|
|
43
|
+
*/
|
|
44
|
+
langcode: {
|
|
45
|
+
type: String,
|
|
46
|
+
default: undefined
|
|
47
|
+
},
|
|
48
|
+
|
|
41
49
|
/**
|
|
42
50
|
* The module value.
|
|
43
51
|
*
|
|
@@ -170,7 +178,17 @@ export default {
|
|
|
170
178
|
this.component = component
|
|
171
179
|
},
|
|
172
180
|
|
|
181
|
+
computed: {
|
|
182
|
+
lang: ({ langcode, $route }) => langcode || ($route.meta || {}).langcode
|
|
183
|
+
},
|
|
184
|
+
|
|
173
185
|
watch: {
|
|
186
|
+
lang(to, from) {
|
|
187
|
+
if (to !== from) {
|
|
188
|
+
this.$fetch()
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
|
|
174
192
|
model() {
|
|
175
193
|
if (this.component.props && this.component.props.value !== this.model) {
|
|
176
194
|
this.component.props.value = this.model
|
|
@@ -237,7 +255,12 @@ export default {
|
|
|
237
255
|
let components = []
|
|
238
256
|
for (const set of options.filter(set => Array.isArray(set))) {
|
|
239
257
|
const variants = []
|
|
240
|
-
|
|
258
|
+
|
|
259
|
+
// Add langcode suffix to all sets.
|
|
260
|
+
// console.log('SET', set)
|
|
261
|
+
// set.push(this.lang)
|
|
262
|
+
|
|
263
|
+
for (const item of set.filter((o) => o)) {
|
|
241
264
|
// Build array of name parts.
|
|
242
265
|
const parts = variants.length ? [...variants[0].parts] : []
|
|
243
266
|
parts.push(pascalCase(splitByCase(item)))
|
|
@@ -245,14 +268,26 @@ export default {
|
|
|
245
268
|
// Convert parts into a pascalCase component name.
|
|
246
269
|
const name = pascalCase([this.$options.name, ...parts])
|
|
247
270
|
|
|
248
|
-
// Check if component is globally registered.
|
|
249
|
-
const global = !!this.$options.components[name]
|
|
250
|
-
|
|
251
271
|
// Store set variant data to be used in next set item.
|
|
252
272
|
variants.unshift({ global, name, parts })
|
|
253
273
|
|
|
254
|
-
|
|
255
|
-
|
|
274
|
+
// Add langcode suffixed component option.
|
|
275
|
+
if (this.lang) {
|
|
276
|
+
const langcodeName = pascalCase([this.$options.name, ...parts, this.lang])
|
|
277
|
+
components.push({
|
|
278
|
+
global: !!this.$options.components[langcodeName],
|
|
279
|
+
name: langcodeName,
|
|
280
|
+
parts: [...parts, this.lang]
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// And component option.
|
|
285
|
+
components.push({
|
|
286
|
+
global: !!this.$options.components[name],
|
|
287
|
+
name,
|
|
288
|
+
parts
|
|
289
|
+
})
|
|
290
|
+
}
|
|
256
291
|
}
|
|
257
292
|
|
|
258
293
|
// Filter unique components.
|
|
@@ -280,7 +315,10 @@ export default {
|
|
|
280
315
|
return {}
|
|
281
316
|
}
|
|
282
317
|
|
|
283
|
-
const propsData =
|
|
318
|
+
const propsData = {
|
|
319
|
+
langcode: this.lang,
|
|
320
|
+
...this.$options.druxt.propsData.call(this, this)
|
|
321
|
+
}
|
|
284
322
|
|
|
285
323
|
// Props.
|
|
286
324
|
const props = {}
|
|
@@ -391,8 +429,9 @@ export default {
|
|
|
391
429
|
props: (this.wrapper || {}).propsData || undefined,
|
|
392
430
|
}
|
|
393
431
|
|
|
394
|
-
// Return only wrapper if fetch state is still pending
|
|
395
|
-
|
|
432
|
+
// Return only wrapper if fetch state is still pending and Druxt hasn't set
|
|
433
|
+
// the available component options.
|
|
434
|
+
if (this.$fetchState.pending && !this.component.options.length) {
|
|
396
435
|
return h((this.wrapper || {}).component || 'div', wrapperData)
|
|
397
436
|
}
|
|
398
437
|
|
package/dist/druxt.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
+
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
2
3
|
import { join, resolve } from 'path';
|
|
3
4
|
import axios from 'axios';
|
|
4
5
|
import { stringify } from 'querystring';
|
|
@@ -6,168 +7,6 @@ import consola from 'consola';
|
|
|
6
7
|
import merge from 'deepmerge';
|
|
7
8
|
import md5 from 'md5';
|
|
8
9
|
import Vue from 'vue';
|
|
9
|
-
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
10
|
-
|
|
11
|
-
var name = "druxt";
|
|
12
|
-
var version = "0.18.3";
|
|
13
|
-
var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
|
|
14
|
-
var keywords = [
|
|
15
|
-
"cms",
|
|
16
|
-
"decoupled",
|
|
17
|
-
"drupal",
|
|
18
|
-
"druxt",
|
|
19
|
-
"headless",
|
|
20
|
-
"jsonapi",
|
|
21
|
-
"json:api",
|
|
22
|
-
"nuxt",
|
|
23
|
-
"module",
|
|
24
|
-
"vue"
|
|
25
|
-
];
|
|
26
|
-
var homepage = "https://druxtjs.org";
|
|
27
|
-
var bugs = {
|
|
28
|
-
url: "https://github.com/druxt/druxt.js/issues"
|
|
29
|
-
};
|
|
30
|
-
var repository = {
|
|
31
|
-
type: "git",
|
|
32
|
-
url: "git+https://github.com/druxt/druxt.js"
|
|
33
|
-
};
|
|
34
|
-
var license = "MIT";
|
|
35
|
-
var exports = {
|
|
36
|
-
".": {
|
|
37
|
-
require: "./dist/druxt.ssr.js",
|
|
38
|
-
"import": "./dist/druxt.esm.js"
|
|
39
|
-
},
|
|
40
|
-
"./components/*": "./dist/components/*"
|
|
41
|
-
};
|
|
42
|
-
var main = "dist/druxt.ssr.js";
|
|
43
|
-
var module = "dist/druxt.esm.js";
|
|
44
|
-
var files = [
|
|
45
|
-
"dist",
|
|
46
|
-
"stories",
|
|
47
|
-
"templates"
|
|
48
|
-
];
|
|
49
|
-
var dependencies = {
|
|
50
|
-
"@nuxtjs/axios": "^5.13.6",
|
|
51
|
-
"@nuxtjs/proxy": "^2.1.0",
|
|
52
|
-
chalk: "^4.1.2",
|
|
53
|
-
deepmerge: "^4.2.2",
|
|
54
|
-
"drupal-jsonapi-params": "^2.0.0",
|
|
55
|
-
md5: "^2.3.0",
|
|
56
|
-
querystring: "^0.2.0",
|
|
57
|
-
scule: "^0.2.0"
|
|
58
|
-
};
|
|
59
|
-
var devDependencies = {
|
|
60
|
-
"@storybook/addon-docs": "^6.4.13"
|
|
61
|
-
};
|
|
62
|
-
var peerDependencies = {
|
|
63
|
-
axios: "*",
|
|
64
|
-
consola: "*"
|
|
65
|
-
};
|
|
66
|
-
var optionalDependencies = {
|
|
67
|
-
"core-js": "^3.16.1",
|
|
68
|
-
vue: "^2.6.14",
|
|
69
|
-
vuex: "^3.6.2"
|
|
70
|
-
};
|
|
71
|
-
var publishConfig = {
|
|
72
|
-
access: "public"
|
|
73
|
-
};
|
|
74
|
-
var meta = {
|
|
75
|
-
name: name,
|
|
76
|
-
version: version,
|
|
77
|
-
description: description,
|
|
78
|
-
keywords: keywords,
|
|
79
|
-
homepage: homepage,
|
|
80
|
-
bugs: bugs,
|
|
81
|
-
repository: repository,
|
|
82
|
-
license: license,
|
|
83
|
-
exports: exports,
|
|
84
|
-
main: main,
|
|
85
|
-
module: module,
|
|
86
|
-
files: files,
|
|
87
|
-
dependencies: dependencies,
|
|
88
|
-
devDependencies: devDependencies,
|
|
89
|
-
peerDependencies: peerDependencies,
|
|
90
|
-
optionalDependencies: optionalDependencies,
|
|
91
|
-
publishConfig: publishConfig
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const DruxtNuxtModule = function(moduleOptions = {}) {
|
|
95
|
-
var _a;
|
|
96
|
-
const options = {
|
|
97
|
-
endpoint: "/jsonapi",
|
|
98
|
-
...moduleOptions,
|
|
99
|
-
...(this.options || {}).druxt
|
|
100
|
-
};
|
|
101
|
-
if (options.proxy) {
|
|
102
|
-
const proxies = {};
|
|
103
|
-
if ((options.proxy || {}).api) {
|
|
104
|
-
proxies[options.endpoint] = options.baseUrl;
|
|
105
|
-
proxies["/router/translate-path"] = options.baseUrl;
|
|
106
|
-
}
|
|
107
|
-
if ((options.proxy || {}).files) {
|
|
108
|
-
const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
|
|
109
|
-
proxies[`/sites/${filesPath}/files`] = options.baseUrl;
|
|
110
|
-
}
|
|
111
|
-
if (this.options.proxy) {
|
|
112
|
-
if (Array.isArray(this.options.proxy)) {
|
|
113
|
-
this.options.proxy = [
|
|
114
|
-
...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
|
|
115
|
-
...this.options.proxy
|
|
116
|
-
];
|
|
117
|
-
} else {
|
|
118
|
-
this.options.proxy = {
|
|
119
|
-
...proxies,
|
|
120
|
-
...this.options.proxy
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
this.options.proxy = proxies;
|
|
125
|
-
}
|
|
126
|
-
this.addModule("@nuxtjs/proxy");
|
|
127
|
-
}
|
|
128
|
-
if (!options.axios) {
|
|
129
|
-
this.options.axios = {
|
|
130
|
-
baseURL: options.baseUrl,
|
|
131
|
-
proxy: !!(options.proxy || {}).api,
|
|
132
|
-
...this.options.axios
|
|
133
|
-
};
|
|
134
|
-
this.addModule("@nuxtjs/axios");
|
|
135
|
-
}
|
|
136
|
-
this.nuxt.hook("components:dirs", (dirs) => {
|
|
137
|
-
dirs.push({ path: join(__dirname, "components") });
|
|
138
|
-
});
|
|
139
|
-
this.addPlugin({
|
|
140
|
-
src: resolve(__dirname, "../templates/plugin.js"),
|
|
141
|
-
fileName: "druxt.js",
|
|
142
|
-
options
|
|
143
|
-
});
|
|
144
|
-
const extendPlugins = this.options.extendPlugins;
|
|
145
|
-
this.options.extendPlugins = (plugins) => {
|
|
146
|
-
plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
|
|
147
|
-
const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
|
|
148
|
-
const axiosPlugin = plugins[axiosIndex];
|
|
149
|
-
plugins.splice(axiosIndex, 1);
|
|
150
|
-
const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
|
|
151
|
-
const druxtPlugin = plugins[druxtIndex];
|
|
152
|
-
plugins.splice(druxtIndex, 1);
|
|
153
|
-
plugins = [axiosPlugin, druxtPlugin, ...plugins];
|
|
154
|
-
return plugins;
|
|
155
|
-
};
|
|
156
|
-
this.addPlugin({
|
|
157
|
-
src: resolve(__dirname, "../templates/store.js"),
|
|
158
|
-
fileName: "store/druxt.js",
|
|
159
|
-
options
|
|
160
|
-
});
|
|
161
|
-
this.options.store = true;
|
|
162
|
-
this.options.components = (_a = this.options.components) != null ? _a : true;
|
|
163
|
-
this.options.cli.badgeMessages.push(`${chalk.blue.bold("Druxt")} @ v${meta.version}`);
|
|
164
|
-
this.options.cli.badgeMessages.push(`${chalk.bold("API:")} ${chalk.blue.underline(options.baseUrl + options.endpoint)}`);
|
|
165
|
-
this.nuxt.hook("storybook:config", async ({ stories }) => {
|
|
166
|
-
stories.push("druxt/stories/*.stories.mdx");
|
|
167
|
-
stories.push("druxt/dist/components/*.stories.mdx");
|
|
168
|
-
stories.push("druxt/dist/components/*.stories.mjs");
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
10
|
|
|
172
11
|
class DruxtClient {
|
|
173
12
|
constructor(baseUrl, options = {}) {
|
|
@@ -201,6 +40,7 @@ class DruxtClient {
|
|
|
201
40
|
jsonapiResourceConfig: "jsonapi_resource_config--jsonapi_resource_config",
|
|
202
41
|
...options
|
|
203
42
|
};
|
|
43
|
+
this.index = {};
|
|
204
44
|
}
|
|
205
45
|
addHeaders(headers) {
|
|
206
46
|
if (typeof headers === "undefined") {
|
|
@@ -250,11 +90,11 @@ class DruxtClient {
|
|
|
250
90
|
}
|
|
251
91
|
}
|
|
252
92
|
}
|
|
253
|
-
async createResource(resource) {
|
|
93
|
+
async createResource(resource, prefix = "") {
|
|
254
94
|
if (resource.id) {
|
|
255
|
-
return this.updateResource(resource);
|
|
95
|
+
return this.updateResource(resource, prefix);
|
|
256
96
|
}
|
|
257
|
-
const { href } = await this.getIndex(resource.type);
|
|
97
|
+
const { href } = await this.getIndex(resource.type, prefix);
|
|
258
98
|
if (!href) {
|
|
259
99
|
return false;
|
|
260
100
|
}
|
|
@@ -301,8 +141,8 @@ class DruxtClient {
|
|
|
301
141
|
this.error(err, { url });
|
|
302
142
|
}
|
|
303
143
|
}
|
|
304
|
-
async getCollection(type, query) {
|
|
305
|
-
const { href } = await this.getIndex(type);
|
|
144
|
+
async getCollection(type, query, prefix) {
|
|
145
|
+
const { href } = await this.getIndex(type, prefix);
|
|
306
146
|
if (!href) {
|
|
307
147
|
return false;
|
|
308
148
|
}
|
|
@@ -310,25 +150,25 @@ class DruxtClient {
|
|
|
310
150
|
const { data } = await this.get(url);
|
|
311
151
|
return data;
|
|
312
152
|
}
|
|
313
|
-
async getCollectionAll(type, query) {
|
|
153
|
+
async getCollectionAll(type, query, prefix) {
|
|
314
154
|
const collections = [];
|
|
315
|
-
let res = await this.getCollection(type, query);
|
|
155
|
+
let res = await this.getCollection(type, query, prefix);
|
|
316
156
|
collections.push(res);
|
|
317
157
|
while (((res.links || {}).next || {}).href) {
|
|
318
158
|
query = res.links.next.href.split("?")[1];
|
|
319
|
-
res = await this.getCollection(type, query);
|
|
159
|
+
res = await this.getCollection(type, query, prefix);
|
|
320
160
|
collections.push(res);
|
|
321
161
|
}
|
|
322
162
|
return collections;
|
|
323
163
|
}
|
|
324
|
-
async getIndex(resource) {
|
|
325
|
-
if (this.index && !resource) {
|
|
326
|
-
return this.index;
|
|
164
|
+
async getIndex(resource, prefix) {
|
|
165
|
+
if ((this.index || {})[prefix] && !resource) {
|
|
166
|
+
return this.index[prefix];
|
|
327
167
|
}
|
|
328
|
-
if (this.index && resource) {
|
|
329
|
-
return this.index[resource] ? this.index[resource] : false;
|
|
168
|
+
if ((this.index || {})[prefix] && resource) {
|
|
169
|
+
return this.index[prefix][resource] ? this.index[prefix][resource] : false;
|
|
330
170
|
}
|
|
331
|
-
const url = this.options.endpoint;
|
|
171
|
+
const url = [prefix, this.options.endpoint].join("");
|
|
332
172
|
const { data } = await this.get(url);
|
|
333
173
|
let index = data.links;
|
|
334
174
|
if (typeof index !== "object") {
|
|
@@ -363,14 +203,14 @@ class DruxtClient {
|
|
|
363
203
|
};
|
|
364
204
|
}
|
|
365
205
|
}
|
|
366
|
-
this.index = index;
|
|
367
|
-
return resource ? this.index[resource] || false : this.index;
|
|
206
|
+
this.index[prefix] = index;
|
|
207
|
+
return resource ? this.index[prefix][resource] || false : this.index[prefix];
|
|
368
208
|
}
|
|
369
|
-
async getRelated(type, id, related, query) {
|
|
209
|
+
async getRelated(type, id, related, query, prefix = "") {
|
|
370
210
|
if (!id || !type || !related) {
|
|
371
211
|
return false;
|
|
372
212
|
}
|
|
373
|
-
let { href } = await this.getIndex(type);
|
|
213
|
+
let { href } = await this.getIndex(type, prefix);
|
|
374
214
|
if (!href) {
|
|
375
215
|
href = this.options.endpoint + "/" + type.replace("--", "/");
|
|
376
216
|
}
|
|
@@ -378,11 +218,11 @@ class DruxtClient {
|
|
|
378
218
|
const { data } = await this.get(url);
|
|
379
219
|
return data;
|
|
380
220
|
}
|
|
381
|
-
async getResource(type, id, query) {
|
|
221
|
+
async getResource(type, id, query, prefix) {
|
|
382
222
|
if (!id || !type) {
|
|
383
223
|
return false;
|
|
384
224
|
}
|
|
385
|
-
let { href } = await this.getIndex(type);
|
|
225
|
+
let { href } = await this.getIndex(type, prefix);
|
|
386
226
|
if (!href) {
|
|
387
227
|
href = this.options.endpoint + "/" + type.replace("--", "/");
|
|
388
228
|
}
|
|
@@ -390,8 +230,8 @@ class DruxtClient {
|
|
|
390
230
|
const { data } = await this.get(url);
|
|
391
231
|
return data;
|
|
392
232
|
}
|
|
393
|
-
async updateResource(resource) {
|
|
394
|
-
const { href } = await this.getIndex(resource.type);
|
|
233
|
+
async updateResource(resource, prefix) {
|
|
234
|
+
const { href } = await this.getIndex(resource.type, prefix);
|
|
395
235
|
if (!href) {
|
|
396
236
|
return false;
|
|
397
237
|
}
|
|
@@ -410,15 +250,187 @@ class DruxtClient {
|
|
|
410
250
|
}
|
|
411
251
|
}
|
|
412
252
|
|
|
253
|
+
var name = "druxt";
|
|
254
|
+
var version = "0.19.0";
|
|
255
|
+
var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
|
|
256
|
+
var keywords = [
|
|
257
|
+
"cms",
|
|
258
|
+
"decoupled",
|
|
259
|
+
"drupal",
|
|
260
|
+
"druxt",
|
|
261
|
+
"headless",
|
|
262
|
+
"jsonapi",
|
|
263
|
+
"json:api",
|
|
264
|
+
"nuxt",
|
|
265
|
+
"module",
|
|
266
|
+
"vue"
|
|
267
|
+
];
|
|
268
|
+
var homepage = "https://druxtjs.org";
|
|
269
|
+
var bugs = {
|
|
270
|
+
url: "https://github.com/druxt/druxt.js/issues"
|
|
271
|
+
};
|
|
272
|
+
var repository = {
|
|
273
|
+
type: "git",
|
|
274
|
+
url: "git+https://github.com/druxt/druxt.js"
|
|
275
|
+
};
|
|
276
|
+
var license = "MIT";
|
|
277
|
+
var exports = {
|
|
278
|
+
".": {
|
|
279
|
+
require: "./dist/druxt.ssr.js",
|
|
280
|
+
"import": "./dist/druxt.esm.js"
|
|
281
|
+
},
|
|
282
|
+
"./components/*": "./dist/components/*"
|
|
283
|
+
};
|
|
284
|
+
var main = "dist/druxt.ssr.js";
|
|
285
|
+
var module = "dist/druxt.esm.js";
|
|
286
|
+
var files = [
|
|
287
|
+
"dist",
|
|
288
|
+
"stories",
|
|
289
|
+
"templates"
|
|
290
|
+
];
|
|
291
|
+
var dependencies = {
|
|
292
|
+
"@nuxtjs/axios": "^5.13.6",
|
|
293
|
+
"@nuxtjs/proxy": "^2.1.0",
|
|
294
|
+
chalk: "^4.1.2",
|
|
295
|
+
deepmerge: "^4.2.2",
|
|
296
|
+
"drupal-jsonapi-params": "^2.0.0",
|
|
297
|
+
md5: "^2.3.0",
|
|
298
|
+
querystring: "^0.2.1",
|
|
299
|
+
scule: "^0.2.1"
|
|
300
|
+
};
|
|
301
|
+
var devDependencies = {
|
|
302
|
+
"@storybook/addon-docs": "^6.4.22"
|
|
303
|
+
};
|
|
304
|
+
var peerDependencies = {
|
|
305
|
+
axios: "*",
|
|
306
|
+
consola: "*"
|
|
307
|
+
};
|
|
308
|
+
var optionalDependencies = {
|
|
309
|
+
"core-js": "^3.22.5",
|
|
310
|
+
vue: "^2.6.14",
|
|
311
|
+
vuex: "^3.6.2"
|
|
312
|
+
};
|
|
313
|
+
var publishConfig = {
|
|
314
|
+
access: "public"
|
|
315
|
+
};
|
|
316
|
+
var meta = {
|
|
317
|
+
name: name,
|
|
318
|
+
version: version,
|
|
319
|
+
description: description,
|
|
320
|
+
keywords: keywords,
|
|
321
|
+
homepage: homepage,
|
|
322
|
+
bugs: bugs,
|
|
323
|
+
repository: repository,
|
|
324
|
+
license: license,
|
|
325
|
+
exports: exports,
|
|
326
|
+
main: main,
|
|
327
|
+
module: module,
|
|
328
|
+
files: files,
|
|
329
|
+
dependencies: dependencies,
|
|
330
|
+
devDependencies: devDependencies,
|
|
331
|
+
peerDependencies: peerDependencies,
|
|
332
|
+
optionalDependencies: optionalDependencies,
|
|
333
|
+
publishConfig: publishConfig
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const DruxtNuxtModule = async function(moduleOptions = {}) {
|
|
337
|
+
var _a;
|
|
338
|
+
const options = {
|
|
339
|
+
endpoint: "/jsonapi",
|
|
340
|
+
...moduleOptions,
|
|
341
|
+
...(this.options || {}).druxt
|
|
342
|
+
};
|
|
343
|
+
const druxt = new DruxtClient(options.baseUrl, {
|
|
344
|
+
...options,
|
|
345
|
+
proxy: { ...options.proxy || {}, api: false }
|
|
346
|
+
});
|
|
347
|
+
if (options.proxy) {
|
|
348
|
+
const proxies = {};
|
|
349
|
+
if ((options.proxy || {}).api) {
|
|
350
|
+
proxies[options.endpoint] = options.baseUrl;
|
|
351
|
+
const resourceType = "configurable_language--configurable_language";
|
|
352
|
+
const query = new DrupalJsonApiParams().addFields(resourceType, ["drupal_internal__id"]);
|
|
353
|
+
const languages = (await druxt.getCollectionAll(resourceType, query) || []).map((o) => o.data).flat().filter((o) => !["und", "zxx"].includes(o.attributes.drupal_internal__id)).map((o) => o.attributes.drupal_internal__id);
|
|
354
|
+
for (const langcode of languages) {
|
|
355
|
+
proxies[`/${langcode}${options.endpoint}`] = options.baseUrl;
|
|
356
|
+
}
|
|
357
|
+
proxies["/router/translate-path"] = options.baseUrl;
|
|
358
|
+
}
|
|
359
|
+
if ((options.proxy || {}).files) {
|
|
360
|
+
const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
|
|
361
|
+
proxies[`/sites/${filesPath}/files`] = options.baseUrl;
|
|
362
|
+
}
|
|
363
|
+
if (this.options.proxy) {
|
|
364
|
+
if (Array.isArray(this.options.proxy)) {
|
|
365
|
+
this.options.proxy = [
|
|
366
|
+
...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
|
|
367
|
+
...this.options.proxy
|
|
368
|
+
];
|
|
369
|
+
} else {
|
|
370
|
+
this.options.proxy = {
|
|
371
|
+
...proxies,
|
|
372
|
+
...this.options.proxy
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
this.options.proxy = proxies;
|
|
377
|
+
}
|
|
378
|
+
this.addModule("@nuxtjs/proxy");
|
|
379
|
+
}
|
|
380
|
+
if (!options.axios) {
|
|
381
|
+
this.options.axios = {
|
|
382
|
+
baseURL: options.baseUrl,
|
|
383
|
+
proxy: !!(options.proxy || {}).api,
|
|
384
|
+
...this.options.axios
|
|
385
|
+
};
|
|
386
|
+
this.addModule("@nuxtjs/axios");
|
|
387
|
+
}
|
|
388
|
+
this.nuxt.hook("components:dirs", (dirs) => {
|
|
389
|
+
dirs.push({ path: join(__dirname, "components") });
|
|
390
|
+
});
|
|
391
|
+
this.addPlugin({
|
|
392
|
+
src: resolve(__dirname, "../templates/plugin.js"),
|
|
393
|
+
fileName: "druxt.js",
|
|
394
|
+
options
|
|
395
|
+
});
|
|
396
|
+
const extendPlugins = this.options.extendPlugins;
|
|
397
|
+
this.options.extendPlugins = (plugins) => {
|
|
398
|
+
plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
|
|
399
|
+
const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
|
|
400
|
+
const axiosPlugin = plugins[axiosIndex];
|
|
401
|
+
plugins.splice(axiosIndex, 1);
|
|
402
|
+
const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
|
|
403
|
+
const druxtPlugin = plugins[druxtIndex];
|
|
404
|
+
plugins.splice(druxtIndex, 1);
|
|
405
|
+
plugins = [axiosPlugin, druxtPlugin, ...plugins];
|
|
406
|
+
return plugins;
|
|
407
|
+
};
|
|
408
|
+
this.addPlugin({
|
|
409
|
+
src: resolve(__dirname, "../templates/store.js"),
|
|
410
|
+
fileName: "store/druxt.js",
|
|
411
|
+
options
|
|
412
|
+
});
|
|
413
|
+
this.options.store = true;
|
|
414
|
+
this.options.components = (_a = this.options.components) != null ? _a : true;
|
|
415
|
+
this.options.cli.badgeMessages.push(`${chalk.blue.bold("Druxt")} @ v${meta.version}`);
|
|
416
|
+
this.options.cli.badgeMessages.push(`${chalk.bold("API:")} ${chalk.blue.underline(options.baseUrl + options.endpoint)}`);
|
|
417
|
+
this.nuxt.hook("storybook:config", async ({ stories }) => {
|
|
418
|
+
stories.push("druxt/stories/*.stories.mdx");
|
|
419
|
+
stories.push("druxt/dist/components/*.stories.mdx");
|
|
420
|
+
stories.push("druxt/dist/components/*.stories.mjs");
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
|
|
413
424
|
const getDrupalJsonApiParams = (query) => {
|
|
414
425
|
return new DrupalJsonApiParams().initialize(query);
|
|
415
426
|
};
|
|
416
427
|
|
|
417
|
-
const dehydrateResources = ({ commit, queryObject, resources }) => {
|
|
428
|
+
const dehydrateResources = ({ commit, queryObject, resources, prefix }) => {
|
|
418
429
|
return (resources || []).map((data) => {
|
|
419
430
|
const link = decodeURI(((data.links || {}).self || {}).href || "");
|
|
420
431
|
const href = typeof (queryObject.fields || {})[data.type] === "string" ? [link.split("?")[0], `fields[${data.type}]=${queryObject.fields[data.type]}`].join("?") : link;
|
|
421
432
|
commit("druxt/addResource", {
|
|
433
|
+
prefix,
|
|
422
434
|
resource: {
|
|
423
435
|
data,
|
|
424
436
|
links: { self: { href } }
|
|
@@ -439,21 +451,23 @@ const DruxtStore = ({ store }) => {
|
|
|
439
451
|
resources: {}
|
|
440
452
|
}),
|
|
441
453
|
mutations: {
|
|
442
|
-
addCollection(state, { collection, type, hash }) {
|
|
454
|
+
addCollection(state, { collection, type, hash, prefix }) {
|
|
443
455
|
if (!state.collections[type])
|
|
444
456
|
Vue.set(state.collections, type, {});
|
|
457
|
+
if (!state.collections[type][hash])
|
|
458
|
+
Vue.set(state.collections[type], hash, {});
|
|
445
459
|
const link = decodeURI((((collection || {}).links || {}).self || {}).href || "");
|
|
446
460
|
const query = link.split("?")[1] || "";
|
|
447
461
|
const queryObject = getDrupalJsonApiParams(query).getQueryObject();
|
|
448
|
-
collection.data = dehydrateResources({ commit: this.commit, queryObject, resources: collection.data });
|
|
462
|
+
collection.data = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.data });
|
|
449
463
|
if (collection.included) {
|
|
450
|
-
collection.included = dehydrateResources({ commit: this.commit, queryObject, resources: collection.included });
|
|
464
|
+
collection.included = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.included });
|
|
451
465
|
delete collection.included;
|
|
452
466
|
}
|
|
453
|
-
collection = merge(state.collections[type][hash] || {}, collection, { arrayMerge: (dst, src) => src });
|
|
454
|
-
Vue.set(state.collections[type],
|
|
467
|
+
collection = merge(state.collections[type][hash][prefix] || {}, collection, { arrayMerge: (dst, src) => src });
|
|
468
|
+
Vue.set(state.collections[type][hash], prefix, collection);
|
|
455
469
|
},
|
|
456
|
-
addResource(state, { resource, hash }) {
|
|
470
|
+
addResource(state, { prefix, resource, hash }) {
|
|
457
471
|
if (hash) {
|
|
458
472
|
console.warn("[druxt] The `hash` argument for `druxt/addResource` has been deprecated, see https://druxtjs.org/guide/deprecations.html#druxtstore-addresource-hash");
|
|
459
473
|
}
|
|
@@ -468,30 +482,32 @@ const DruxtStore = ({ store }) => {
|
|
|
468
482
|
resource[flag] = Date.now();
|
|
469
483
|
if (!state.resources[type])
|
|
470
484
|
Vue.set(state.resources, type, {});
|
|
485
|
+
if (!state.resources[type][id])
|
|
486
|
+
Vue.set(state.resources[type], id, {});
|
|
471
487
|
if (resource.included) {
|
|
472
|
-
dehydrateResources({ commit: this.commit, queryObject, resources: resource.included });
|
|
488
|
+
dehydrateResources({ commit: this.commit, prefix, queryObject, resources: resource.included });
|
|
473
489
|
delete resource.included;
|
|
474
490
|
}
|
|
475
|
-
resource = merge(state.resources[type][id] || {}, resource, { arrayMerge: (dst, src) => src });
|
|
476
|
-
Vue.set(state.resources[type],
|
|
491
|
+
resource = merge(state.resources[type][id][prefix] || {}, resource, { arrayMerge: (dst, src) => src });
|
|
492
|
+
Vue.set(state.resources[type][id], prefix, resource);
|
|
477
493
|
}
|
|
478
494
|
},
|
|
479
495
|
actions: {
|
|
480
|
-
async getCollection({ commit, state }, { type, query }) {
|
|
496
|
+
async getCollection({ commit, state }, { type, query, prefix }) {
|
|
481
497
|
const queryObject = getDrupalJsonApiParams(query).getQueryObject();
|
|
482
498
|
const hash = query ? md5(JSON.stringify({ ...queryObject, fields: {}, include: [] })) : "_default";
|
|
483
|
-
if ((state.collections[type] || {})[hash]) {
|
|
499
|
+
if (((state.collections[type] || {})[hash] || {})[prefix]) {
|
|
484
500
|
return {
|
|
485
|
-
...state.collections[type][hash],
|
|
486
|
-
data: state.collections[type][hash].data.map((o) => (state.resources[o.type][o.id] || {}).data)
|
|
501
|
+
...state.collections[type][hash][prefix],
|
|
502
|
+
data: state.collections[type][hash][prefix].data.map((o) => ((state.resources[o.type][o.id] || {})[prefix] || {}).data)
|
|
487
503
|
};
|
|
488
504
|
}
|
|
489
|
-
const collection = await this.$druxt.getCollection(type, query);
|
|
490
|
-
commit("addCollection", { collection: { ...collection }, type, hash });
|
|
505
|
+
const collection = await this.$druxt.getCollection(type, query, prefix);
|
|
506
|
+
commit("addCollection", { collection: { ...collection }, type, hash, prefix });
|
|
491
507
|
return collection;
|
|
492
508
|
},
|
|
493
|
-
async getResource({ commit, dispatch, state }, { type, id, query }) {
|
|
494
|
-
const storedResource = (state.resources[type] || {})[id] ? { ...state.resources[type][id] } : null;
|
|
509
|
+
async getResource({ commit, dispatch, state }, { type, id, query, prefix }) {
|
|
510
|
+
const storedResource = ((state.resources[type] || {})[id] || {})[prefix] ? { ...state.resources[type][id][prefix] } : null;
|
|
495
511
|
const queryObject = getDrupalJsonApiParams(query).getQueryObject();
|
|
496
512
|
queryObject.include = Array.isArray(queryObject.include) ? queryObject.include.join(",") : queryObject.include;
|
|
497
513
|
if (queryObject.include && typeof (queryObject.fields || {})[type] === "string") {
|
|
@@ -535,10 +551,10 @@ const DruxtStore = ({ store }) => {
|
|
|
535
551
|
}
|
|
536
552
|
let resource;
|
|
537
553
|
if (!storedResource || fields) {
|
|
538
|
-
resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject));
|
|
539
|
-
commit("addResource", { resource: { ...resource } });
|
|
554
|
+
resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject), prefix);
|
|
555
|
+
commit("addResource", { prefix, resource: { ...resource } });
|
|
540
556
|
}
|
|
541
|
-
const result = { ...(state.resources[type] || {})[id] };
|
|
557
|
+
const result = { ...((state.resources[type] || {})[id] || {})[prefix] };
|
|
542
558
|
if (queryObject.include && ((resource || {}).included || (storedResource || {}).included)) {
|
|
543
559
|
included = [
|
|
544
560
|
...(resource || {}).included || [],
|
|
@@ -608,5 +624,4 @@ class DruxtClass {
|
|
|
608
624
|
|
|
609
625
|
DruxtNuxtModule.meta = require("../package.json");
|
|
610
626
|
|
|
611
|
-
export default
|
|
612
|
-
export { DruxtClass, DruxtClient, DruxtStore };
|
|
627
|
+
export { DruxtClass, DruxtClient, DruxtStore, DruxtNuxtModule as default };
|
package/dist/druxt.ssr.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const chalk = require('chalk');
|
|
6
|
+
const drupalJsonapiParams = require('drupal-jsonapi-params');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
const axios = require('axios');
|
|
8
9
|
const querystring = require('querystring');
|
|
@@ -10,7 +11,6 @@ const consola = require('consola');
|
|
|
10
11
|
const merge = require('deepmerge');
|
|
11
12
|
const md5 = require('md5');
|
|
12
13
|
const Vue = require('vue');
|
|
13
|
-
const drupalJsonapiParams = require('drupal-jsonapi-params');
|
|
14
14
|
|
|
15
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
16
|
|
|
@@ -21,170 +21,9 @@ const merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
|
|
|
21
21
|
const md5__default = /*#__PURE__*/_interopDefaultLegacy(md5);
|
|
22
22
|
const Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
|
|
23
23
|
|
|
24
|
-
var name = "druxt";
|
|
25
|
-
var version = "0.18.3";
|
|
26
|
-
var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
|
|
27
|
-
var keywords = [
|
|
28
|
-
"cms",
|
|
29
|
-
"decoupled",
|
|
30
|
-
"drupal",
|
|
31
|
-
"druxt",
|
|
32
|
-
"headless",
|
|
33
|
-
"jsonapi",
|
|
34
|
-
"json:api",
|
|
35
|
-
"nuxt",
|
|
36
|
-
"module",
|
|
37
|
-
"vue"
|
|
38
|
-
];
|
|
39
|
-
var homepage = "https://druxtjs.org";
|
|
40
|
-
var bugs = {
|
|
41
|
-
url: "https://github.com/druxt/druxt.js/issues"
|
|
42
|
-
};
|
|
43
|
-
var repository = {
|
|
44
|
-
type: "git",
|
|
45
|
-
url: "git+https://github.com/druxt/druxt.js"
|
|
46
|
-
};
|
|
47
|
-
var license = "MIT";
|
|
48
|
-
var exports$1 = {
|
|
49
|
-
".": {
|
|
50
|
-
require: "./dist/druxt.ssr.js",
|
|
51
|
-
"import": "./dist/druxt.esm.js"
|
|
52
|
-
},
|
|
53
|
-
"./components/*": "./dist/components/*"
|
|
54
|
-
};
|
|
55
|
-
var main = "dist/druxt.ssr.js";
|
|
56
|
-
var module$1 = "dist/druxt.esm.js";
|
|
57
|
-
var files = [
|
|
58
|
-
"dist",
|
|
59
|
-
"stories",
|
|
60
|
-
"templates"
|
|
61
|
-
];
|
|
62
|
-
var dependencies = {
|
|
63
|
-
"@nuxtjs/axios": "^5.13.6",
|
|
64
|
-
"@nuxtjs/proxy": "^2.1.0",
|
|
65
|
-
chalk: "^4.1.2",
|
|
66
|
-
deepmerge: "^4.2.2",
|
|
67
|
-
"drupal-jsonapi-params": "^2.0.0",
|
|
68
|
-
md5: "^2.3.0",
|
|
69
|
-
querystring: "^0.2.0",
|
|
70
|
-
scule: "^0.2.0"
|
|
71
|
-
};
|
|
72
|
-
var devDependencies = {
|
|
73
|
-
"@storybook/addon-docs": "^6.4.13"
|
|
74
|
-
};
|
|
75
|
-
var peerDependencies = {
|
|
76
|
-
axios: "*",
|
|
77
|
-
consola: "*"
|
|
78
|
-
};
|
|
79
|
-
var optionalDependencies = {
|
|
80
|
-
"core-js": "^3.16.1",
|
|
81
|
-
vue: "^2.6.14",
|
|
82
|
-
vuex: "^3.6.2"
|
|
83
|
-
};
|
|
84
|
-
var publishConfig = {
|
|
85
|
-
access: "public"
|
|
86
|
-
};
|
|
87
|
-
const meta = {
|
|
88
|
-
name: name,
|
|
89
|
-
version: version,
|
|
90
|
-
description: description,
|
|
91
|
-
keywords: keywords,
|
|
92
|
-
homepage: homepage,
|
|
93
|
-
bugs: bugs,
|
|
94
|
-
repository: repository,
|
|
95
|
-
license: license,
|
|
96
|
-
exports: exports$1,
|
|
97
|
-
main: main,
|
|
98
|
-
module: module$1,
|
|
99
|
-
files: files,
|
|
100
|
-
dependencies: dependencies,
|
|
101
|
-
devDependencies: devDependencies,
|
|
102
|
-
peerDependencies: peerDependencies,
|
|
103
|
-
optionalDependencies: optionalDependencies,
|
|
104
|
-
publishConfig: publishConfig
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const DruxtNuxtModule = function(moduleOptions = {}) {
|
|
108
|
-
var _a;
|
|
109
|
-
const options = {
|
|
110
|
-
endpoint: "/jsonapi",
|
|
111
|
-
...moduleOptions,
|
|
112
|
-
...(this.options || {}).druxt
|
|
113
|
-
};
|
|
114
|
-
if (options.proxy) {
|
|
115
|
-
const proxies = {};
|
|
116
|
-
if ((options.proxy || {}).api) {
|
|
117
|
-
proxies[options.endpoint] = options.baseUrl;
|
|
118
|
-
proxies["/router/translate-path"] = options.baseUrl;
|
|
119
|
-
}
|
|
120
|
-
if ((options.proxy || {}).files) {
|
|
121
|
-
const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
|
|
122
|
-
proxies[`/sites/${filesPath}/files`] = options.baseUrl;
|
|
123
|
-
}
|
|
124
|
-
if (this.options.proxy) {
|
|
125
|
-
if (Array.isArray(this.options.proxy)) {
|
|
126
|
-
this.options.proxy = [
|
|
127
|
-
...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
|
|
128
|
-
...this.options.proxy
|
|
129
|
-
];
|
|
130
|
-
} else {
|
|
131
|
-
this.options.proxy = {
|
|
132
|
-
...proxies,
|
|
133
|
-
...this.options.proxy
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
this.options.proxy = proxies;
|
|
138
|
-
}
|
|
139
|
-
this.addModule("@nuxtjs/proxy");
|
|
140
|
-
}
|
|
141
|
-
if (!options.axios) {
|
|
142
|
-
this.options.axios = {
|
|
143
|
-
baseURL: options.baseUrl,
|
|
144
|
-
proxy: !!(options.proxy || {}).api,
|
|
145
|
-
...this.options.axios
|
|
146
|
-
};
|
|
147
|
-
this.addModule("@nuxtjs/axios");
|
|
148
|
-
}
|
|
149
|
-
this.nuxt.hook("components:dirs", (dirs) => {
|
|
150
|
-
dirs.push({ path: path.join(__dirname, "components") });
|
|
151
|
-
});
|
|
152
|
-
this.addPlugin({
|
|
153
|
-
src: path.resolve(__dirname, "../templates/plugin.js"),
|
|
154
|
-
fileName: "druxt.js",
|
|
155
|
-
options
|
|
156
|
-
});
|
|
157
|
-
const extendPlugins = this.options.extendPlugins;
|
|
158
|
-
this.options.extendPlugins = (plugins) => {
|
|
159
|
-
plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
|
|
160
|
-
const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
|
|
161
|
-
const axiosPlugin = plugins[axiosIndex];
|
|
162
|
-
plugins.splice(axiosIndex, 1);
|
|
163
|
-
const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
|
|
164
|
-
const druxtPlugin = plugins[druxtIndex];
|
|
165
|
-
plugins.splice(druxtIndex, 1);
|
|
166
|
-
plugins = [axiosPlugin, druxtPlugin, ...plugins];
|
|
167
|
-
return plugins;
|
|
168
|
-
};
|
|
169
|
-
this.addPlugin({
|
|
170
|
-
src: path.resolve(__dirname, "../templates/store.js"),
|
|
171
|
-
fileName: "store/druxt.js",
|
|
172
|
-
options
|
|
173
|
-
});
|
|
174
|
-
this.options.store = true;
|
|
175
|
-
this.options.components = (_a = this.options.components) != null ? _a : true;
|
|
176
|
-
this.options.cli.badgeMessages.push(`${chalk__default['default'].blue.bold("Druxt")} @ v${meta.version}`);
|
|
177
|
-
this.options.cli.badgeMessages.push(`${chalk__default['default'].bold("API:")} ${chalk__default['default'].blue.underline(options.baseUrl + options.endpoint)}`);
|
|
178
|
-
this.nuxt.hook("storybook:config", async ({ stories }) => {
|
|
179
|
-
stories.push("druxt/stories/*.stories.mdx");
|
|
180
|
-
stories.push("druxt/dist/components/*.stories.mdx");
|
|
181
|
-
stories.push("druxt/dist/components/*.stories.mjs");
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
|
|
185
24
|
class DruxtClient {
|
|
186
25
|
constructor(baseUrl, options = {}) {
|
|
187
|
-
this.log = consola__default[
|
|
26
|
+
this.log = consola__default["default"].create({ defaults: {
|
|
188
27
|
tag: "DruxtClient"
|
|
189
28
|
} });
|
|
190
29
|
if (!baseUrl) {
|
|
@@ -194,7 +33,7 @@ class DruxtClient {
|
|
|
194
33
|
if (typeof options.axios === "function") {
|
|
195
34
|
this.axios = options.axios;
|
|
196
35
|
} else {
|
|
197
|
-
this.axios = axios__default[
|
|
36
|
+
this.axios = axios__default["default"].create({
|
|
198
37
|
...options.axios || {},
|
|
199
38
|
baseURL: baseUrl && !(options.proxy || {}).api ? baseUrl : void 0
|
|
200
39
|
});
|
|
@@ -214,6 +53,7 @@ class DruxtClient {
|
|
|
214
53
|
jsonapiResourceConfig: "jsonapi_resource_config--jsonapi_resource_config",
|
|
215
54
|
...options
|
|
216
55
|
};
|
|
56
|
+
this.index = {};
|
|
217
57
|
}
|
|
218
58
|
addHeaders(headers) {
|
|
219
59
|
if (typeof headers === "undefined") {
|
|
@@ -263,11 +103,11 @@ class DruxtClient {
|
|
|
263
103
|
}
|
|
264
104
|
}
|
|
265
105
|
}
|
|
266
|
-
async createResource(resource) {
|
|
106
|
+
async createResource(resource, prefix = "") {
|
|
267
107
|
if (resource.id) {
|
|
268
|
-
return this.updateResource(resource);
|
|
108
|
+
return this.updateResource(resource, prefix);
|
|
269
109
|
}
|
|
270
|
-
const { href } = await this.getIndex(resource.type);
|
|
110
|
+
const { href } = await this.getIndex(resource.type, prefix);
|
|
271
111
|
if (!href) {
|
|
272
112
|
return false;
|
|
273
113
|
}
|
|
@@ -314,8 +154,8 @@ class DruxtClient {
|
|
|
314
154
|
this.error(err, { url });
|
|
315
155
|
}
|
|
316
156
|
}
|
|
317
|
-
async getCollection(type, query) {
|
|
318
|
-
const { href } = await this.getIndex(type);
|
|
157
|
+
async getCollection(type, query, prefix) {
|
|
158
|
+
const { href } = await this.getIndex(type, prefix);
|
|
319
159
|
if (!href) {
|
|
320
160
|
return false;
|
|
321
161
|
}
|
|
@@ -323,25 +163,25 @@ class DruxtClient {
|
|
|
323
163
|
const { data } = await this.get(url);
|
|
324
164
|
return data;
|
|
325
165
|
}
|
|
326
|
-
async getCollectionAll(type, query) {
|
|
166
|
+
async getCollectionAll(type, query, prefix) {
|
|
327
167
|
const collections = [];
|
|
328
|
-
let res = await this.getCollection(type, query);
|
|
168
|
+
let res = await this.getCollection(type, query, prefix);
|
|
329
169
|
collections.push(res);
|
|
330
170
|
while (((res.links || {}).next || {}).href) {
|
|
331
171
|
query = res.links.next.href.split("?")[1];
|
|
332
|
-
res = await this.getCollection(type, query);
|
|
172
|
+
res = await this.getCollection(type, query, prefix);
|
|
333
173
|
collections.push(res);
|
|
334
174
|
}
|
|
335
175
|
return collections;
|
|
336
176
|
}
|
|
337
|
-
async getIndex(resource) {
|
|
338
|
-
if (this.index && !resource) {
|
|
339
|
-
return this.index;
|
|
177
|
+
async getIndex(resource, prefix) {
|
|
178
|
+
if ((this.index || {})[prefix] && !resource) {
|
|
179
|
+
return this.index[prefix];
|
|
340
180
|
}
|
|
341
|
-
if (this.index && resource) {
|
|
342
|
-
return this.index[resource] ? this.index[resource] : false;
|
|
181
|
+
if ((this.index || {})[prefix] && resource) {
|
|
182
|
+
return this.index[prefix][resource] ? this.index[prefix][resource] : false;
|
|
343
183
|
}
|
|
344
|
-
const url = this.options.endpoint;
|
|
184
|
+
const url = [prefix, this.options.endpoint].join("");
|
|
345
185
|
const { data } = await this.get(url);
|
|
346
186
|
let index = data.links;
|
|
347
187
|
if (typeof index !== "object") {
|
|
@@ -376,14 +216,14 @@ class DruxtClient {
|
|
|
376
216
|
};
|
|
377
217
|
}
|
|
378
218
|
}
|
|
379
|
-
this.index = index;
|
|
380
|
-
return resource ? this.index[resource] || false : this.index;
|
|
219
|
+
this.index[prefix] = index;
|
|
220
|
+
return resource ? this.index[prefix][resource] || false : this.index[prefix];
|
|
381
221
|
}
|
|
382
|
-
async getRelated(type, id, related, query) {
|
|
222
|
+
async getRelated(type, id, related, query, prefix = "") {
|
|
383
223
|
if (!id || !type || !related) {
|
|
384
224
|
return false;
|
|
385
225
|
}
|
|
386
|
-
let { href } = await this.getIndex(type);
|
|
226
|
+
let { href } = await this.getIndex(type, prefix);
|
|
387
227
|
if (!href) {
|
|
388
228
|
href = this.options.endpoint + "/" + type.replace("--", "/");
|
|
389
229
|
}
|
|
@@ -391,11 +231,11 @@ class DruxtClient {
|
|
|
391
231
|
const { data } = await this.get(url);
|
|
392
232
|
return data;
|
|
393
233
|
}
|
|
394
|
-
async getResource(type, id, query) {
|
|
234
|
+
async getResource(type, id, query, prefix) {
|
|
395
235
|
if (!id || !type) {
|
|
396
236
|
return false;
|
|
397
237
|
}
|
|
398
|
-
let { href } = await this.getIndex(type);
|
|
238
|
+
let { href } = await this.getIndex(type, prefix);
|
|
399
239
|
if (!href) {
|
|
400
240
|
href = this.options.endpoint + "/" + type.replace("--", "/");
|
|
401
241
|
}
|
|
@@ -403,8 +243,8 @@ class DruxtClient {
|
|
|
403
243
|
const { data } = await this.get(url);
|
|
404
244
|
return data;
|
|
405
245
|
}
|
|
406
|
-
async updateResource(resource) {
|
|
407
|
-
const { href } = await this.getIndex(resource.type);
|
|
246
|
+
async updateResource(resource, prefix) {
|
|
247
|
+
const { href } = await this.getIndex(resource.type, prefix);
|
|
408
248
|
if (!href) {
|
|
409
249
|
return false;
|
|
410
250
|
}
|
|
@@ -423,15 +263,187 @@ class DruxtClient {
|
|
|
423
263
|
}
|
|
424
264
|
}
|
|
425
265
|
|
|
266
|
+
var name = "druxt";
|
|
267
|
+
var version = "0.19.0";
|
|
268
|
+
var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";
|
|
269
|
+
var keywords = [
|
|
270
|
+
"cms",
|
|
271
|
+
"decoupled",
|
|
272
|
+
"drupal",
|
|
273
|
+
"druxt",
|
|
274
|
+
"headless",
|
|
275
|
+
"jsonapi",
|
|
276
|
+
"json:api",
|
|
277
|
+
"nuxt",
|
|
278
|
+
"module",
|
|
279
|
+
"vue"
|
|
280
|
+
];
|
|
281
|
+
var homepage = "https://druxtjs.org";
|
|
282
|
+
var bugs = {
|
|
283
|
+
url: "https://github.com/druxt/druxt.js/issues"
|
|
284
|
+
};
|
|
285
|
+
var repository = {
|
|
286
|
+
type: "git",
|
|
287
|
+
url: "git+https://github.com/druxt/druxt.js"
|
|
288
|
+
};
|
|
289
|
+
var license = "MIT";
|
|
290
|
+
var exports$1 = {
|
|
291
|
+
".": {
|
|
292
|
+
require: "./dist/druxt.ssr.js",
|
|
293
|
+
"import": "./dist/druxt.esm.js"
|
|
294
|
+
},
|
|
295
|
+
"./components/*": "./dist/components/*"
|
|
296
|
+
};
|
|
297
|
+
var main = "dist/druxt.ssr.js";
|
|
298
|
+
var module$1 = "dist/druxt.esm.js";
|
|
299
|
+
var files = [
|
|
300
|
+
"dist",
|
|
301
|
+
"stories",
|
|
302
|
+
"templates"
|
|
303
|
+
];
|
|
304
|
+
var dependencies = {
|
|
305
|
+
"@nuxtjs/axios": "^5.13.6",
|
|
306
|
+
"@nuxtjs/proxy": "^2.1.0",
|
|
307
|
+
chalk: "^4.1.2",
|
|
308
|
+
deepmerge: "^4.2.2",
|
|
309
|
+
"drupal-jsonapi-params": "^2.0.0",
|
|
310
|
+
md5: "^2.3.0",
|
|
311
|
+
querystring: "^0.2.1",
|
|
312
|
+
scule: "^0.2.1"
|
|
313
|
+
};
|
|
314
|
+
var devDependencies = {
|
|
315
|
+
"@storybook/addon-docs": "^6.4.22"
|
|
316
|
+
};
|
|
317
|
+
var peerDependencies = {
|
|
318
|
+
axios: "*",
|
|
319
|
+
consola: "*"
|
|
320
|
+
};
|
|
321
|
+
var optionalDependencies = {
|
|
322
|
+
"core-js": "^3.22.5",
|
|
323
|
+
vue: "^2.6.14",
|
|
324
|
+
vuex: "^3.6.2"
|
|
325
|
+
};
|
|
326
|
+
var publishConfig = {
|
|
327
|
+
access: "public"
|
|
328
|
+
};
|
|
329
|
+
const meta = {
|
|
330
|
+
name: name,
|
|
331
|
+
version: version,
|
|
332
|
+
description: description,
|
|
333
|
+
keywords: keywords,
|
|
334
|
+
homepage: homepage,
|
|
335
|
+
bugs: bugs,
|
|
336
|
+
repository: repository,
|
|
337
|
+
license: license,
|
|
338
|
+
exports: exports$1,
|
|
339
|
+
main: main,
|
|
340
|
+
module: module$1,
|
|
341
|
+
files: files,
|
|
342
|
+
dependencies: dependencies,
|
|
343
|
+
devDependencies: devDependencies,
|
|
344
|
+
peerDependencies: peerDependencies,
|
|
345
|
+
optionalDependencies: optionalDependencies,
|
|
346
|
+
publishConfig: publishConfig
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const DruxtNuxtModule = async function(moduleOptions = {}) {
|
|
350
|
+
var _a;
|
|
351
|
+
const options = {
|
|
352
|
+
endpoint: "/jsonapi",
|
|
353
|
+
...moduleOptions,
|
|
354
|
+
...(this.options || {}).druxt
|
|
355
|
+
};
|
|
356
|
+
const druxt = new DruxtClient(options.baseUrl, {
|
|
357
|
+
...options,
|
|
358
|
+
proxy: { ...options.proxy || {}, api: false }
|
|
359
|
+
});
|
|
360
|
+
if (options.proxy) {
|
|
361
|
+
const proxies = {};
|
|
362
|
+
if ((options.proxy || {}).api) {
|
|
363
|
+
proxies[options.endpoint] = options.baseUrl;
|
|
364
|
+
const resourceType = "configurable_language--configurable_language";
|
|
365
|
+
const query = new drupalJsonapiParams.DrupalJsonApiParams().addFields(resourceType, ["drupal_internal__id"]);
|
|
366
|
+
const languages = (await druxt.getCollectionAll(resourceType, query) || []).map((o) => o.data).flat().filter((o) => !["und", "zxx"].includes(o.attributes.drupal_internal__id)).map((o) => o.attributes.drupal_internal__id);
|
|
367
|
+
for (const langcode of languages) {
|
|
368
|
+
proxies[`/${langcode}${options.endpoint}`] = options.baseUrl;
|
|
369
|
+
}
|
|
370
|
+
proxies["/router/translate-path"] = options.baseUrl;
|
|
371
|
+
}
|
|
372
|
+
if ((options.proxy || {}).files) {
|
|
373
|
+
const filesPath = typeof options.proxy.files === "string" ? options.proxy.files : "default";
|
|
374
|
+
proxies[`/sites/${filesPath}/files`] = options.baseUrl;
|
|
375
|
+
}
|
|
376
|
+
if (this.options.proxy) {
|
|
377
|
+
if (Array.isArray(this.options.proxy)) {
|
|
378
|
+
this.options.proxy = [
|
|
379
|
+
...Object.keys(proxies).map((path) => `${options.baseUrl}${path}`),
|
|
380
|
+
...this.options.proxy
|
|
381
|
+
];
|
|
382
|
+
} else {
|
|
383
|
+
this.options.proxy = {
|
|
384
|
+
...proxies,
|
|
385
|
+
...this.options.proxy
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
this.options.proxy = proxies;
|
|
390
|
+
}
|
|
391
|
+
this.addModule("@nuxtjs/proxy");
|
|
392
|
+
}
|
|
393
|
+
if (!options.axios) {
|
|
394
|
+
this.options.axios = {
|
|
395
|
+
baseURL: options.baseUrl,
|
|
396
|
+
proxy: !!(options.proxy || {}).api,
|
|
397
|
+
...this.options.axios
|
|
398
|
+
};
|
|
399
|
+
this.addModule("@nuxtjs/axios");
|
|
400
|
+
}
|
|
401
|
+
this.nuxt.hook("components:dirs", (dirs) => {
|
|
402
|
+
dirs.push({ path: path.join(__dirname, "components") });
|
|
403
|
+
});
|
|
404
|
+
this.addPlugin({
|
|
405
|
+
src: path.resolve(__dirname, "../templates/plugin.js"),
|
|
406
|
+
fileName: "druxt.js",
|
|
407
|
+
options
|
|
408
|
+
});
|
|
409
|
+
const extendPlugins = this.options.extendPlugins;
|
|
410
|
+
this.options.extendPlugins = (plugins) => {
|
|
411
|
+
plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
|
|
412
|
+
const axiosIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/axios.js`);
|
|
413
|
+
const axiosPlugin = plugins[axiosIndex];
|
|
414
|
+
plugins.splice(axiosIndex, 1);
|
|
415
|
+
const druxtIndex = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
|
|
416
|
+
const druxtPlugin = plugins[druxtIndex];
|
|
417
|
+
plugins.splice(druxtIndex, 1);
|
|
418
|
+
plugins = [axiosPlugin, druxtPlugin, ...plugins];
|
|
419
|
+
return plugins;
|
|
420
|
+
};
|
|
421
|
+
this.addPlugin({
|
|
422
|
+
src: path.resolve(__dirname, "../templates/store.js"),
|
|
423
|
+
fileName: "store/druxt.js",
|
|
424
|
+
options
|
|
425
|
+
});
|
|
426
|
+
this.options.store = true;
|
|
427
|
+
this.options.components = (_a = this.options.components) != null ? _a : true;
|
|
428
|
+
this.options.cli.badgeMessages.push(`${chalk__default["default"].blue.bold("Druxt")} @ v${meta.version}`);
|
|
429
|
+
this.options.cli.badgeMessages.push(`${chalk__default["default"].bold("API:")} ${chalk__default["default"].blue.underline(options.baseUrl + options.endpoint)}`);
|
|
430
|
+
this.nuxt.hook("storybook:config", async ({ stories }) => {
|
|
431
|
+
stories.push("druxt/stories/*.stories.mdx");
|
|
432
|
+
stories.push("druxt/dist/components/*.stories.mdx");
|
|
433
|
+
stories.push("druxt/dist/components/*.stories.mjs");
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
|
|
426
437
|
const getDrupalJsonApiParams = (query) => {
|
|
427
438
|
return new drupalJsonapiParams.DrupalJsonApiParams().initialize(query);
|
|
428
439
|
};
|
|
429
440
|
|
|
430
|
-
const dehydrateResources = ({ commit, queryObject, resources }) => {
|
|
441
|
+
const dehydrateResources = ({ commit, queryObject, resources, prefix }) => {
|
|
431
442
|
return (resources || []).map((data) => {
|
|
432
443
|
const link = decodeURI(((data.links || {}).self || {}).href || "");
|
|
433
444
|
const href = typeof (queryObject.fields || {})[data.type] === "string" ? [link.split("?")[0], `fields[${data.type}]=${queryObject.fields[data.type]}`].join("?") : link;
|
|
434
445
|
commit("druxt/addResource", {
|
|
446
|
+
prefix,
|
|
435
447
|
resource: {
|
|
436
448
|
data,
|
|
437
449
|
links: { self: { href } }
|
|
@@ -452,21 +464,23 @@ const DruxtStore = ({ store }) => {
|
|
|
452
464
|
resources: {}
|
|
453
465
|
}),
|
|
454
466
|
mutations: {
|
|
455
|
-
addCollection(state, { collection, type, hash }) {
|
|
467
|
+
addCollection(state, { collection, type, hash, prefix }) {
|
|
456
468
|
if (!state.collections[type])
|
|
457
|
-
Vue__default[
|
|
469
|
+
Vue__default["default"].set(state.collections, type, {});
|
|
470
|
+
if (!state.collections[type][hash])
|
|
471
|
+
Vue__default["default"].set(state.collections[type], hash, {});
|
|
458
472
|
const link = decodeURI((((collection || {}).links || {}).self || {}).href || "");
|
|
459
473
|
const query = link.split("?")[1] || "";
|
|
460
474
|
const queryObject = getDrupalJsonApiParams(query).getQueryObject();
|
|
461
|
-
collection.data = dehydrateResources({ commit: this.commit, queryObject, resources: collection.data });
|
|
475
|
+
collection.data = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.data });
|
|
462
476
|
if (collection.included) {
|
|
463
|
-
collection.included = dehydrateResources({ commit: this.commit, queryObject, resources: collection.included });
|
|
477
|
+
collection.included = dehydrateResources({ commit: this.commit, prefix, queryObject, resources: collection.included });
|
|
464
478
|
delete collection.included;
|
|
465
479
|
}
|
|
466
|
-
collection = merge__default[
|
|
467
|
-
Vue__default[
|
|
480
|
+
collection = merge__default["default"](state.collections[type][hash][prefix] || {}, collection, { arrayMerge: (dst, src) => src });
|
|
481
|
+
Vue__default["default"].set(state.collections[type][hash], prefix, collection);
|
|
468
482
|
},
|
|
469
|
-
addResource(state, { resource, hash }) {
|
|
483
|
+
addResource(state, { prefix, resource, hash }) {
|
|
470
484
|
if (hash) {
|
|
471
485
|
console.warn("[druxt] The `hash` argument for `druxt/addResource` has been deprecated, see https://druxtjs.org/guide/deprecations.html#druxtstore-addresource-hash");
|
|
472
486
|
}
|
|
@@ -480,31 +494,33 @@ const DruxtStore = ({ store }) => {
|
|
|
480
494
|
const flag = typeof (queryObject.fields || {})[((resource || {}).data || {}).type] === "string" ? "_druxt_partial" : "_druxt_full";
|
|
481
495
|
resource[flag] = Date.now();
|
|
482
496
|
if (!state.resources[type])
|
|
483
|
-
Vue__default[
|
|
497
|
+
Vue__default["default"].set(state.resources, type, {});
|
|
498
|
+
if (!state.resources[type][id])
|
|
499
|
+
Vue__default["default"].set(state.resources[type], id, {});
|
|
484
500
|
if (resource.included) {
|
|
485
|
-
dehydrateResources({ commit: this.commit, queryObject, resources: resource.included });
|
|
501
|
+
dehydrateResources({ commit: this.commit, prefix, queryObject, resources: resource.included });
|
|
486
502
|
delete resource.included;
|
|
487
503
|
}
|
|
488
|
-
resource = merge__default[
|
|
489
|
-
Vue__default[
|
|
504
|
+
resource = merge__default["default"](state.resources[type][id][prefix] || {}, resource, { arrayMerge: (dst, src) => src });
|
|
505
|
+
Vue__default["default"].set(state.resources[type][id], prefix, resource);
|
|
490
506
|
}
|
|
491
507
|
},
|
|
492
508
|
actions: {
|
|
493
|
-
async getCollection({ commit, state }, { type, query }) {
|
|
509
|
+
async getCollection({ commit, state }, { type, query, prefix }) {
|
|
494
510
|
const queryObject = getDrupalJsonApiParams(query).getQueryObject();
|
|
495
|
-
const hash = query ? md5__default[
|
|
496
|
-
if ((state.collections[type] || {})[hash]) {
|
|
511
|
+
const hash = query ? md5__default["default"](JSON.stringify({ ...queryObject, fields: {}, include: [] })) : "_default";
|
|
512
|
+
if (((state.collections[type] || {})[hash] || {})[prefix]) {
|
|
497
513
|
return {
|
|
498
|
-
...state.collections[type][hash],
|
|
499
|
-
data: state.collections[type][hash].data.map((o) => (state.resources[o.type][o.id] || {}).data)
|
|
514
|
+
...state.collections[type][hash][prefix],
|
|
515
|
+
data: state.collections[type][hash][prefix].data.map((o) => ((state.resources[o.type][o.id] || {})[prefix] || {}).data)
|
|
500
516
|
};
|
|
501
517
|
}
|
|
502
|
-
const collection = await this.$druxt.getCollection(type, query);
|
|
503
|
-
commit("addCollection", { collection: { ...collection }, type, hash });
|
|
518
|
+
const collection = await this.$druxt.getCollection(type, query, prefix);
|
|
519
|
+
commit("addCollection", { collection: { ...collection }, type, hash, prefix });
|
|
504
520
|
return collection;
|
|
505
521
|
},
|
|
506
|
-
async getResource({ commit, dispatch, state }, { type, id, query }) {
|
|
507
|
-
const storedResource = (state.resources[type] || {})[id] ? { ...state.resources[type][id] } : null;
|
|
522
|
+
async getResource({ commit, dispatch, state }, { type, id, query, prefix }) {
|
|
523
|
+
const storedResource = ((state.resources[type] || {})[id] || {})[prefix] ? { ...state.resources[type][id][prefix] } : null;
|
|
508
524
|
const queryObject = getDrupalJsonApiParams(query).getQueryObject();
|
|
509
525
|
queryObject.include = Array.isArray(queryObject.include) ? queryObject.include.join(",") : queryObject.include;
|
|
510
526
|
if (queryObject.include && typeof (queryObject.fields || {})[type] === "string") {
|
|
@@ -548,10 +564,10 @@ const DruxtStore = ({ store }) => {
|
|
|
548
564
|
}
|
|
549
565
|
let resource;
|
|
550
566
|
if (!storedResource || fields) {
|
|
551
|
-
resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject));
|
|
552
|
-
commit("addResource", { resource: { ...resource } });
|
|
567
|
+
resource = await this.$druxt.getResource(type, id, getDrupalJsonApiParams(queryObject), prefix);
|
|
568
|
+
commit("addResource", { prefix, resource: { ...resource } });
|
|
553
569
|
}
|
|
554
|
-
const result = { ...(state.resources[type] || {})[id] };
|
|
570
|
+
const result = { ...((state.resources[type] || {})[id] || {})[prefix] };
|
|
555
571
|
if (queryObject.include && ((resource || {}).included || (storedResource || {}).included)) {
|
|
556
572
|
included = [
|
|
557
573
|
...(resource || {}).included || [],
|
|
@@ -624,4 +640,4 @@ DruxtNuxtModule.meta = require("../package.json");
|
|
|
624
640
|
exports.DruxtClass = DruxtClass;
|
|
625
641
|
exports.DruxtClient = DruxtClient;
|
|
626
642
|
exports.DruxtStore = DruxtStore;
|
|
627
|
-
exports
|
|
643
|
+
exports["default"] = DruxtNuxtModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "The Fully Decoupled Drupal Framework for Nuxt.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"deepmerge": "^4.2.2",
|
|
45
45
|
"drupal-jsonapi-params": "^2.0.0",
|
|
46
46
|
"md5": "^2.3.0",
|
|
47
|
-
"querystring": "^0.2.
|
|
48
|
-
"scule": "^0.2.
|
|
47
|
+
"querystring": "^0.2.1",
|
|
48
|
+
"scule": "^0.2.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@storybook/addon-docs": "^6.4.
|
|
51
|
+
"@storybook/addon-docs": "^6.4.22"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"axios": "*",
|
|
55
55
|
"consola": "*"
|
|
56
56
|
},
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"core-js": "^3.
|
|
58
|
+
"core-js": "^3.22.5",
|
|
59
59
|
"vue": "^2.6.14",
|
|
60
60
|
"vuex": "^3.6.2"
|
|
61
61
|
},
|