druxt-menu 0.22.0-dev.20261002073505 → 0.22.0-dev.20261002115337
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/druxt-menu.esm.js +28 -19
- package/dist/druxt-menu.ssr.js +28 -19
- package/package.json +3 -3
package/dist/druxt-menu.esm.js
CHANGED
|
@@ -91,6 +91,24 @@ class DruxtMenu {
|
|
|
91
91
|
}
|
|
92
92
|
return query;
|
|
93
93
|
}
|
|
94
|
+
buildMenuLinkContentQuery(menuName, settings) {
|
|
95
|
+
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
96
|
+
return this.buildQuery("menu_link_content--menu_link_content", menuName, requiredFields, settings);
|
|
97
|
+
}
|
|
98
|
+
buildJsonApiMenuItemsQuery(menuName, settings) {
|
|
99
|
+
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
100
|
+
const query = this.buildQuery("menu_link_content--menu_link_content", menuName, requiredFields, settings);
|
|
101
|
+
if ((settings || {}).max_depth) {
|
|
102
|
+
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
103
|
+
}
|
|
104
|
+
if ((settings || {}).min_depth) {
|
|
105
|
+
query.addFilter("min_depth", parseInt(settings.min_depth));
|
|
106
|
+
}
|
|
107
|
+
if ((settings || {}).parent) {
|
|
108
|
+
query.addFilter("parent", settings.parent);
|
|
109
|
+
}
|
|
110
|
+
return query;
|
|
111
|
+
}
|
|
94
112
|
async get(menuName, settings, prefix) {
|
|
95
113
|
if (!menuCache.has(this.druxt))
|
|
96
114
|
menuCache.set(this.druxt, new Map());
|
|
@@ -101,14 +119,15 @@ class DruxtMenu {
|
|
|
101
119
|
cache.generation = generation;
|
|
102
120
|
}
|
|
103
121
|
const jsonApiMenuItems = !!this.options.menu.jsonApiMenuItems;
|
|
104
|
-
const
|
|
122
|
+
const query = jsonApiMenuItems ? this.buildJsonApiMenuItemsQuery(menuName, settings) : this.buildMenuLinkContentQuery(menuName, settings);
|
|
123
|
+
const cacheKey = JSON.stringify([prefix || "", menuName, jsonApiMenuItems, query.getQueryString()]);
|
|
105
124
|
if (!cache.has(cacheKey)) {
|
|
106
125
|
const processCache = (scope) => typeof this.druxt.processCache === "function" ? this.druxt.processCache(scope) : null;
|
|
107
126
|
const sharedKey = JSON.stringify([this.druxt.indexKey, cacheKey]);
|
|
108
127
|
const shared = processCache("menu");
|
|
109
128
|
const stored = shared && shared.get(sharedKey);
|
|
110
129
|
const since = shared ? shared.generation : void 0;
|
|
111
|
-
const request = stored ? Promise.resolve(stored) : (jsonApiMenuItems ? this.getJsonApiMenuItems(menuName, settings, prefix) : this.getMenuLinkContent(menuName, settings, prefix)).then((result) => {
|
|
130
|
+
const request = stored ? Promise.resolve(stored) : (jsonApiMenuItems ? this.getJsonApiMenuItems(menuName, settings, prefix, query) : this.getMenuLinkContent(menuName, settings, prefix, query)).then((result) => {
|
|
112
131
|
const after = processCache("menu");
|
|
113
132
|
if (after && lifetimes.has(result))
|
|
114
133
|
after.set(sharedKey, result, lifetimes.get(result), since);
|
|
@@ -131,10 +150,8 @@ class DruxtMenu {
|
|
|
131
150
|
lifetimes.set(result, collections.length ? Math.min(...collections.map(lifetime)) : 0);
|
|
132
151
|
return result;
|
|
133
152
|
}
|
|
134
|
-
async getMenuLinkContent(menuName, settings, prefix) {
|
|
153
|
+
async getMenuLinkContent(menuName, settings, prefix, query = this.buildMenuLinkContentQuery(menuName, settings)) {
|
|
135
154
|
const resource = "menu_link_content--menu_link_content";
|
|
136
|
-
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
137
|
-
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
138
155
|
const entities = [];
|
|
139
156
|
const collections = await this.druxt.getCollectionAll(resource, query, prefix);
|
|
140
157
|
for (const collection of collections) {
|
|
@@ -144,24 +161,12 @@ class DruxtMenu {
|
|
|
144
161
|
}
|
|
145
162
|
return this.withLifetime({ entities }, collections);
|
|
146
163
|
}
|
|
147
|
-
async getJsonApiMenuItems(menuName, settings, prefix) {
|
|
164
|
+
async getJsonApiMenuItems(menuName, settings, prefix, query = this.buildJsonApiMenuItemsQuery(menuName, settings)) {
|
|
148
165
|
const menuItemsResource = `menu_items--${menuName}`;
|
|
149
|
-
const resource = "menu_link_content--menu_link_content";
|
|
150
|
-
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
151
166
|
await this.druxt.getIndex(void 0, prefix);
|
|
152
167
|
if (!(this.druxt.index[prefix][menuItemsResource] || {}).href) {
|
|
153
168
|
this.druxt.index[prefix][menuItemsResource] = { href: `${prefix || ""}${this.druxt.options.endpoint}/menu_items/${menuName}` };
|
|
154
169
|
}
|
|
155
|
-
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
156
|
-
if ((settings || {}).max_depth) {
|
|
157
|
-
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
158
|
-
}
|
|
159
|
-
if ((settings || {}).min_depth) {
|
|
160
|
-
query.addFilter("min_depth", parseInt(settings.min_depth));
|
|
161
|
-
}
|
|
162
|
-
if ((settings || {}).parent) {
|
|
163
|
-
query.addFilter("parent", settings.parent);
|
|
164
|
-
}
|
|
165
170
|
const entities = [];
|
|
166
171
|
let collections = [];
|
|
167
172
|
try {
|
|
@@ -192,6 +197,7 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
192
197
|
throw new TypeError("Vuex store not found.");
|
|
193
198
|
}
|
|
194
199
|
const namespace = "druxtMenu";
|
|
200
|
+
const generation = { value: 0 };
|
|
195
201
|
const module = {
|
|
196
202
|
namespaced: true,
|
|
197
203
|
state: () => ({
|
|
@@ -207,6 +213,7 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
207
213
|
}
|
|
208
214
|
},
|
|
209
215
|
flushEntities(state, { prefix }) {
|
|
216
|
+
generation.value += 1;
|
|
210
217
|
if (!prefix || typeof state.entities !== "object")
|
|
211
218
|
Vue.set(state, "entities", {});
|
|
212
219
|
if (prefix)
|
|
@@ -216,8 +223,10 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
216
223
|
actions: {
|
|
217
224
|
async get({ commit }, context) {
|
|
218
225
|
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
226
|
+
const since = generation.value;
|
|
219
227
|
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
220
|
-
|
|
228
|
+
if (since === generation.value)
|
|
229
|
+
commit("addEntities", { entities, prefix });
|
|
221
230
|
}
|
|
222
231
|
},
|
|
223
232
|
getters: {
|
package/dist/druxt-menu.ssr.js
CHANGED
|
@@ -99,6 +99,24 @@ class DruxtMenu {
|
|
|
99
99
|
}
|
|
100
100
|
return query;
|
|
101
101
|
}
|
|
102
|
+
buildMenuLinkContentQuery(menuName, settings) {
|
|
103
|
+
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
104
|
+
return this.buildQuery("menu_link_content--menu_link_content", menuName, requiredFields, settings);
|
|
105
|
+
}
|
|
106
|
+
buildJsonApiMenuItemsQuery(menuName, settings) {
|
|
107
|
+
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
108
|
+
const query = this.buildQuery("menu_link_content--menu_link_content", menuName, requiredFields, settings);
|
|
109
|
+
if ((settings || {}).max_depth) {
|
|
110
|
+
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
111
|
+
}
|
|
112
|
+
if ((settings || {}).min_depth) {
|
|
113
|
+
query.addFilter("min_depth", parseInt(settings.min_depth));
|
|
114
|
+
}
|
|
115
|
+
if ((settings || {}).parent) {
|
|
116
|
+
query.addFilter("parent", settings.parent);
|
|
117
|
+
}
|
|
118
|
+
return query;
|
|
119
|
+
}
|
|
102
120
|
async get(menuName, settings, prefix) {
|
|
103
121
|
if (!menuCache.has(this.druxt))
|
|
104
122
|
menuCache.set(this.druxt, new Map());
|
|
@@ -109,14 +127,15 @@ class DruxtMenu {
|
|
|
109
127
|
cache.generation = generation;
|
|
110
128
|
}
|
|
111
129
|
const jsonApiMenuItems = !!this.options.menu.jsonApiMenuItems;
|
|
112
|
-
const
|
|
130
|
+
const query = jsonApiMenuItems ? this.buildJsonApiMenuItemsQuery(menuName, settings) : this.buildMenuLinkContentQuery(menuName, settings);
|
|
131
|
+
const cacheKey = JSON.stringify([prefix || "", menuName, jsonApiMenuItems, query.getQueryString()]);
|
|
113
132
|
if (!cache.has(cacheKey)) {
|
|
114
133
|
const processCache = (scope) => typeof this.druxt.processCache === "function" ? this.druxt.processCache(scope) : null;
|
|
115
134
|
const sharedKey = JSON.stringify([this.druxt.indexKey, cacheKey]);
|
|
116
135
|
const shared = processCache("menu");
|
|
117
136
|
const stored = shared && shared.get(sharedKey);
|
|
118
137
|
const since = shared ? shared.generation : void 0;
|
|
119
|
-
const request = stored ? Promise.resolve(stored) : (jsonApiMenuItems ? this.getJsonApiMenuItems(menuName, settings, prefix) : this.getMenuLinkContent(menuName, settings, prefix)).then((result) => {
|
|
138
|
+
const request = stored ? Promise.resolve(stored) : (jsonApiMenuItems ? this.getJsonApiMenuItems(menuName, settings, prefix, query) : this.getMenuLinkContent(menuName, settings, prefix, query)).then((result) => {
|
|
120
139
|
const after = processCache("menu");
|
|
121
140
|
if (after && lifetimes.has(result))
|
|
122
141
|
after.set(sharedKey, result, lifetimes.get(result), since);
|
|
@@ -139,10 +158,8 @@ class DruxtMenu {
|
|
|
139
158
|
lifetimes.set(result, collections.length ? Math.min(...collections.map(lifetime)) : 0);
|
|
140
159
|
return result;
|
|
141
160
|
}
|
|
142
|
-
async getMenuLinkContent(menuName, settings, prefix) {
|
|
161
|
+
async getMenuLinkContent(menuName, settings, prefix, query = this.buildMenuLinkContentQuery(menuName, settings)) {
|
|
143
162
|
const resource = "menu_link_content--menu_link_content";
|
|
144
|
-
const requiredFields = ["bundle", "link", "menu_name", "parent", "title", "weight"];
|
|
145
|
-
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
146
163
|
const entities = [];
|
|
147
164
|
const collections = await this.druxt.getCollectionAll(resource, query, prefix);
|
|
148
165
|
for (const collection of collections) {
|
|
@@ -152,24 +169,12 @@ class DruxtMenu {
|
|
|
152
169
|
}
|
|
153
170
|
return this.withLifetime({ entities }, collections);
|
|
154
171
|
}
|
|
155
|
-
async getJsonApiMenuItems(menuName, settings, prefix) {
|
|
172
|
+
async getJsonApiMenuItems(menuName, settings, prefix, query = this.buildJsonApiMenuItemsQuery(menuName, settings)) {
|
|
156
173
|
const menuItemsResource = `menu_items--${menuName}`;
|
|
157
|
-
const resource = "menu_link_content--menu_link_content";
|
|
158
|
-
const requiredFields = ["menu_name", "parent", "title", "url", "weight"];
|
|
159
174
|
await this.druxt.getIndex(void 0, prefix);
|
|
160
175
|
if (!(this.druxt.index[prefix][menuItemsResource] || {}).href) {
|
|
161
176
|
this.druxt.index[prefix][menuItemsResource] = { href: `${prefix || ""}${this.druxt.options.endpoint}/menu_items/${menuName}` };
|
|
162
177
|
}
|
|
163
|
-
const query = this.buildQuery(resource, menuName, requiredFields, settings);
|
|
164
|
-
if ((settings || {}).max_depth) {
|
|
165
|
-
query.addFilter("max_depth", parseInt(settings.max_depth));
|
|
166
|
-
}
|
|
167
|
-
if ((settings || {}).min_depth) {
|
|
168
|
-
query.addFilter("min_depth", parseInt(settings.min_depth));
|
|
169
|
-
}
|
|
170
|
-
if ((settings || {}).parent) {
|
|
171
|
-
query.addFilter("parent", settings.parent);
|
|
172
|
-
}
|
|
173
178
|
const entities = [];
|
|
174
179
|
let collections = [];
|
|
175
180
|
try {
|
|
@@ -200,6 +205,7 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
200
205
|
throw new TypeError("Vuex store not found.");
|
|
201
206
|
}
|
|
202
207
|
const namespace = "druxtMenu";
|
|
208
|
+
const generation = { value: 0 };
|
|
203
209
|
const module = {
|
|
204
210
|
namespaced: true,
|
|
205
211
|
state: () => ({
|
|
@@ -215,6 +221,7 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
215
221
|
}
|
|
216
222
|
},
|
|
217
223
|
flushEntities(state, { prefix }) {
|
|
224
|
+
generation.value += 1;
|
|
218
225
|
if (!prefix || typeof state.entities !== "object")
|
|
219
226
|
Vue__default["default"].set(state, "entities", {});
|
|
220
227
|
if (prefix)
|
|
@@ -224,8 +231,10 @@ const DruxtMenuStore = ({ store }) => {
|
|
|
224
231
|
actions: {
|
|
225
232
|
async get({ commit }, context) {
|
|
226
233
|
const { name, settings, prefix } = typeof context === "object" ? context : { name: context };
|
|
234
|
+
const since = generation.value;
|
|
227
235
|
const { entities } = await this.$druxtMenu.get(name, settings, prefix) || {};
|
|
228
|
-
|
|
236
|
+
if (since === generation.value)
|
|
237
|
+
commit("addEntities", { entities, prefix });
|
|
229
238
|
}
|
|
230
239
|
},
|
|
231
240
|
getters: {
|
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.20261002115337",
|
|
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",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"deepmerge": "^4.3.1",
|
|
50
50
|
"drupal-jsonapi-params": "^2.3.2",
|
|
51
|
-
"druxt": "0.25.0-dev.
|
|
52
|
-
"druxt-blocks": "0.18.0-dev.
|
|
51
|
+
"druxt": "0.25.0-dev.20261002115337",
|
|
52
|
+
"druxt-blocks": "0.18.0-dev.20261002115337"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"axios": "0.33.0"
|