druxt-menu 0.22.0-dev.20261006094246 → 0.22.0-dev.20261011015353
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 +1 -1
- package/dist/druxt-menu.esm.js +57 -12
- package/dist/druxt-menu.ssr.js +57 -12
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/druxt-menu/v/dev)
|
|
7
7
|
[](https://github.com/druxt/druxt.js/actions/workflows/ci.yml)
|
|
8
8
|
[](https://snyk.io/test/github/druxt/druxt.js?targetFile=package.json)
|
|
9
|
-
[](https://codecov.io/gh/druxt/druxt.js)
|
|
10
10
|
|
|
11
11
|
> Drupal Menu and Menu item Druxt components, with support for the JSON:API Menu Items module.
|
|
12
12
|
|
package/dist/druxt-menu.esm.js
CHANGED
|
@@ -197,11 +197,12 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
197
197
|
throw new TypeError("Vuex store not found.");
|
|
198
198
|
}
|
|
199
199
|
const namespace = "druxtMenu";
|
|
200
|
-
const
|
|
200
|
+
const inFlight = new Map();
|
|
201
201
|
const module = {
|
|
202
202
|
namespaced: true,
|
|
203
203
|
state: () => ({
|
|
204
|
-
entities: {}
|
|
204
|
+
entities: {},
|
|
205
|
+
loaded: {}
|
|
205
206
|
}),
|
|
206
207
|
mutations: {
|
|
207
208
|
addEntities(state, { entities, prefix }) {
|
|
@@ -209,28 +210,66 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
209
210
|
Vue.set(state.entities, prefix, {});
|
|
210
211
|
for (const index in entities) {
|
|
211
212
|
const entity = entities[index];
|
|
212
|
-
|
|
213
|
+
const stored = state.entities[prefix][entity.id];
|
|
214
|
+
Vue.set(state.entities[prefix], entity.id, stored ? {
|
|
215
|
+
...stored,
|
|
216
|
+
...entity,
|
|
217
|
+
attributes: { ...stored.attributes, ...entity.attributes },
|
|
218
|
+
relationships: { ...stored.relationships, ...entity.relationships }
|
|
219
|
+
} : entity);
|
|
213
220
|
}
|
|
214
221
|
},
|
|
222
|
+
addLoaded(state, { key, ids, prefix }) {
|
|
223
|
+
if (!state.loaded)
|
|
224
|
+
Vue.set(state, "loaded", {});
|
|
225
|
+
if (!state.loaded[prefix])
|
|
226
|
+
Vue.set(state.loaded, prefix, {});
|
|
227
|
+
Vue.set(state.loaded[prefix], key, ids);
|
|
228
|
+
},
|
|
215
229
|
flushEntities(state, { prefix }) {
|
|
216
|
-
|
|
230
|
+
for (const request of inFlight.values()) {
|
|
231
|
+
if (!prefix || request.prefix === String(prefix))
|
|
232
|
+
request.stale = true;
|
|
233
|
+
}
|
|
217
234
|
if (!prefix || typeof state.entities !== "object")
|
|
218
235
|
Vue.set(state, "entities", {});
|
|
219
236
|
if (prefix)
|
|
220
237
|
Vue.set(state.entities, prefix, {});
|
|
238
|
+
if (!prefix || typeof state.loaded !== "object")
|
|
239
|
+
Vue.set(state, "loaded", {});
|
|
240
|
+
if (prefix)
|
|
241
|
+
Vue.set(state.loaded, prefix, {});
|
|
221
242
|
}
|
|
222
243
|
},
|
|
223
244
|
actions: {
|
|
224
|
-
async get({ commit }, context) {
|
|
245
|
+
async get({ commit, state }, context) {
|
|
225
246
|
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
247
|
+
const key = JSON.stringify([name, settings || {}]);
|
|
248
|
+
const loaded = ((state.loaded || {})[prefix] || {})[key];
|
|
249
|
+
if (loaded)
|
|
250
|
+
return loaded.map((id) => ((state.entities || {})[prefix] || {})[id]);
|
|
251
|
+
const requestKey = JSON.stringify([String(prefix), key]);
|
|
252
|
+
if (!inFlight.has(requestKey)) {
|
|
253
|
+
const request = { prefix: String(prefix), stale: false };
|
|
254
|
+
inFlight.set(requestKey, request);
|
|
255
|
+
request.promise = (async () => {
|
|
256
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
257
|
+
request.stale = false;
|
|
258
|
+
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
259
|
+
if (!request.stale) {
|
|
260
|
+
commit("addEntities", { entities, prefix });
|
|
261
|
+
commit("addLoaded", { key, prefix, ids: (entities || []).map((entity) => entity.id) });
|
|
262
|
+
return entities;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
})();
|
|
266
|
+
const clear = () => {
|
|
267
|
+
if (inFlight.get(requestKey) === request)
|
|
268
|
+
inFlight.delete(requestKey);
|
|
269
|
+
};
|
|
270
|
+
request.promise.then(clear, clear);
|
|
233
271
|
}
|
|
272
|
+
return inFlight.get(requestKey).promise;
|
|
234
273
|
}
|
|
235
274
|
},
|
|
236
275
|
getters: {
|
|
@@ -245,6 +284,12 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
245
284
|
store.registerModule(namespace, module, {
|
|
246
285
|
preserveState: Boolean(store.state[namespace])
|
|
247
286
|
});
|
|
287
|
+
if (!runtime.isServer()) {
|
|
288
|
+
store.watch((state) => (state.auth || {}).loggedIn, (loggedIn, before) => {
|
|
289
|
+
if (typeof before === "boolean")
|
|
290
|
+
store.commit(`${namespace}/flushEntities`, {});
|
|
291
|
+
}, { sync: true });
|
|
292
|
+
}
|
|
248
293
|
};
|
|
249
294
|
|
|
250
295
|
const DruxtMenuMixin = {
|
package/dist/druxt-menu.ssr.js
CHANGED
|
@@ -205,11 +205,12 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
205
205
|
throw new TypeError("Vuex store not found.");
|
|
206
206
|
}
|
|
207
207
|
const namespace = "druxtMenu";
|
|
208
|
-
const
|
|
208
|
+
const inFlight = new Map();
|
|
209
209
|
const module = {
|
|
210
210
|
namespaced: true,
|
|
211
211
|
state: () => ({
|
|
212
|
-
entities: {}
|
|
212
|
+
entities: {},
|
|
213
|
+
loaded: {}
|
|
213
214
|
}),
|
|
214
215
|
mutations: {
|
|
215
216
|
addEntities(state, { entities, prefix }) {
|
|
@@ -217,28 +218,66 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
217
218
|
Vue__default["default"].set(state.entities, prefix, {});
|
|
218
219
|
for (const index in entities) {
|
|
219
220
|
const entity = entities[index];
|
|
220
|
-
|
|
221
|
+
const stored = state.entities[prefix][entity.id];
|
|
222
|
+
Vue__default["default"].set(state.entities[prefix], entity.id, stored ? {
|
|
223
|
+
...stored,
|
|
224
|
+
...entity,
|
|
225
|
+
attributes: { ...stored.attributes, ...entity.attributes },
|
|
226
|
+
relationships: { ...stored.relationships, ...entity.relationships }
|
|
227
|
+
} : entity);
|
|
221
228
|
}
|
|
222
229
|
},
|
|
230
|
+
addLoaded(state, { key, ids, prefix }) {
|
|
231
|
+
if (!state.loaded)
|
|
232
|
+
Vue__default["default"].set(state, "loaded", {});
|
|
233
|
+
if (!state.loaded[prefix])
|
|
234
|
+
Vue__default["default"].set(state.loaded, prefix, {});
|
|
235
|
+
Vue__default["default"].set(state.loaded[prefix], key, ids);
|
|
236
|
+
},
|
|
223
237
|
flushEntities(state, { prefix }) {
|
|
224
|
-
|
|
238
|
+
for (const request of inFlight.values()) {
|
|
239
|
+
if (!prefix || request.prefix === String(prefix))
|
|
240
|
+
request.stale = true;
|
|
241
|
+
}
|
|
225
242
|
if (!prefix || typeof state.entities !== "object")
|
|
226
243
|
Vue__default["default"].set(state, "entities", {});
|
|
227
244
|
if (prefix)
|
|
228
245
|
Vue__default["default"].set(state.entities, prefix, {});
|
|
246
|
+
if (!prefix || typeof state.loaded !== "object")
|
|
247
|
+
Vue__default["default"].set(state, "loaded", {});
|
|
248
|
+
if (prefix)
|
|
249
|
+
Vue__default["default"].set(state.loaded, prefix, {});
|
|
229
250
|
}
|
|
230
251
|
},
|
|
231
252
|
actions: {
|
|
232
|
-
async get({ commit }, context) {
|
|
253
|
+
async get({ commit, state }, context) {
|
|
233
254
|
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
255
|
+
const key = JSON.stringify([name, settings || {}]);
|
|
256
|
+
const loaded = ((state.loaded || {})[prefix] || {})[key];
|
|
257
|
+
if (loaded)
|
|
258
|
+
return loaded.map((id) => ((state.entities || {})[prefix] || {})[id]);
|
|
259
|
+
const requestKey = JSON.stringify([String(prefix), key]);
|
|
260
|
+
if (!inFlight.has(requestKey)) {
|
|
261
|
+
const request = { prefix: String(prefix), stale: false };
|
|
262
|
+
inFlight.set(requestKey, request);
|
|
263
|
+
request.promise = (async () => {
|
|
264
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
265
|
+
request.stale = false;
|
|
266
|
+
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
267
|
+
if (!request.stale) {
|
|
268
|
+
commit("addEntities", { entities, prefix });
|
|
269
|
+
commit("addLoaded", { key, prefix, ids: (entities || []).map((entity) => entity.id) });
|
|
270
|
+
return entities;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
})();
|
|
274
|
+
const clear = () => {
|
|
275
|
+
if (inFlight.get(requestKey) === request)
|
|
276
|
+
inFlight.delete(requestKey);
|
|
277
|
+
};
|
|
278
|
+
request.promise.then(clear, clear);
|
|
241
279
|
}
|
|
280
|
+
return inFlight.get(requestKey).promise;
|
|
242
281
|
}
|
|
243
282
|
},
|
|
244
283
|
getters: {
|
|
@@ -253,6 +292,12 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
253
292
|
store.registerModule(namespace, module, {
|
|
254
293
|
preserveState: Boolean(store.state[namespace])
|
|
255
294
|
});
|
|
295
|
+
if (!runtime.isServer()) {
|
|
296
|
+
store.watch((state) => (state.auth || {}).loggedIn, (loggedIn, before) => {
|
|
297
|
+
if (typeof before === "boolean")
|
|
298
|
+
store.commit(`${namespace}/flushEntities`, {});
|
|
299
|
+
}, { sync: true });
|
|
300
|
+
}
|
|
256
301
|
};
|
|
257
302
|
|
|
258
303
|
const DruxtMenuMixin = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "druxt-menu",
|
|
3
|
-
"version": "0.22.0-dev.
|
|
3
|
+
"version": "0.22.0-dev.20261011015353",
|
|
4
4
|
"description": "Drupal Menu and Menu item Druxt components, with support for the JSON:API Menu Items module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"deepmerge": "^4.3.1",
|
|
51
51
|
"drupal-jsonapi-params": "^2.3.2",
|
|
52
|
-
"druxt": "0.25.0-dev.
|
|
53
|
-
"druxt-blocks": "0.18.0-dev.
|
|
52
|
+
"druxt": "0.25.0-dev.20261011015353",
|
|
53
|
+
"druxt-blocks": "0.18.0-dev.20261011015353"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"axios": "0.
|
|
57
|
-
"lodash": "^4.
|
|
56
|
+
"axios": "0.34.0",
|
|
57
|
+
"lodash": "^4.18.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"vue": "^2.7.14",
|