druxt-router 0.24.2 → 0.26.1

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.
@@ -6,12 +6,9 @@ import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
6
6
  * The DruxtRouter component renders a Drupal decoupled route, or path, using
7
7
  * the appropriate Druxt component.
8
8
  *
9
- * `<DruxtRouter path="/" />`
9
+ * For instance, using the path `/node/1` would render a DruxtEntity component.
10
10
  *
11
- * If no Path is specified, the Vue router path will be used by default.
12
- *
13
- * For instance, using the `/node/1` route would result in a DruxtRouter
14
- * component for the content in Drupal with the Node ID of 1.
11
+ * The Vue router path will be used if not path is defined.
15
12
  *
16
13
  * @example <caption>Render using the Vue router path</caption> @lang vue
17
14
  * <DruxtRouter />
@@ -22,10 +19,22 @@ import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
22
19
  * @example <caption>Render the result of the model, bypasses Drupal backend</caption> @lang vue
23
20
  * <DruxtRouter v-model="route" />
24
21
  *
25
- * @example <caption>Render via a template</caption> @lang vue
22
+ * @example <caption>DruxtRouter Wrapper component boilerplate</caption> @lang vue
23
+ * <template>
24
+ * <DruxtDebug :json="route" />
25
+ * </template>
26
+ *
27
+ * <script>
28
+ * import { DruxtRouterMixin } from 'druxt-router'
29
+ * export default {
30
+ * mixins: [DruxtRouterMixin]
31
+ * }
32
+ *
33
+ * @example <caption>DruxtRouter with template injection</caption> @lang vue
26
34
  * <DruxtRouter>
27
35
  * <template #default="{ route }">
28
- * <DruxtRouter v-bind="route.props" />
36
+ * <!-- Do whatever you want here -->
37
+ * <DruxtDebug :json="route" open />
29
38
  * </template>
30
39
  * </DruxtRouter>
31
40
  */
@@ -99,6 +108,9 @@ export default {
99
108
  * @property {object} model - The model object.
100
109
  */
101
110
  data: ({ value }) => ({
111
+ debug: {
112
+ path: undefined,
113
+ },
102
114
  model: value,
103
115
  }),
104
116
 
@@ -197,7 +209,7 @@ export default {
197
209
  // Get the route from the Drupal decoupled router module via the
198
210
  // druxtRouter store.
199
211
  // Use the Path prop or the Vue Router as the route to lookup.
200
- const path = this.path || this.$route.fullPath
212
+ const path = this.debug.path || this.path || this.$route.fullPath
201
213
  const route = await this.$store.dispatch('druxtRouter/getRoute', path)
202
214
  this.model = route
203
215
 
@@ -219,7 +231,37 @@ export default {
219
231
  propsData: ({ $route, path, model }) => ({
220
232
  path: path || $route.fullPath,
221
233
  route: model
222
- })
234
+ }),
235
+
236
+ /**
237
+ * Provides the scoped slots object for the Module render function.
238
+ *
239
+ * - **debug**: A Debug component with a Path override field.
240
+ * - **default**: Default error handling.
241
+ *
242
+ * @example <caption>DruxtRouter**Module**.vue</caption> @lang vue
243
+ * <template>
244
+ * <div>
245
+ * <slot name="debug" />
246
+ * {{ route.props }}
247
+ * </div>
248
+ * </template>
249
+ *
250
+ * @return {ScopedSlots} The Scoped slots object.
251
+ */
252
+ slots(h) {
253
+ const scopedSlots = {}
254
+
255
+ // Provide defualt error message.
256
+ if (this.model.error) {
257
+ scopedSlots.default = () => h('div', [
258
+ h('h1', [`Error ${this.model.error.statusCode}`]),
259
+ h('p', [this.model.error.message]),
260
+ ])
261
+ }
262
+
263
+ return scopedSlots
264
+ }
223
265
  }
224
266
  }
225
267
 
@@ -267,4 +309,20 @@ export default {
267
309
  * }
268
310
  * }
269
311
  */
312
+
313
+ /**
314
+ * Provides scoped slots for use in the Wrapper component.
315
+ *
316
+ * @typedef {object} ScopedSlots
317
+ * @param {function} debug - A Debug component with a Path override field.
318
+ * @param {function} default - Default error handling.
319
+ *
320
+ * @example <caption>DruxtRouter**Module**.vue</caption> @lang vue
321
+ * <template>
322
+ * <div>
323
+ * <slot name="debug" />
324
+ * {{ route.props }}
325
+ * </div>
326
+ * </template>
327
+ */
270
328
  </script>
@@ -104,7 +104,7 @@ class DruxtRouter {
104
104
  }
105
105
  async getRoute(path) {
106
106
  const url = `/router/translate-path?path=${path}`;
107
- const response = await this.druxt.axios.get(url, {
107
+ const response = await this.druxt.get(url, {
108
108
  validateStatus: (status) => status < 500
109
109
  });
110
110
  const data = {
@@ -147,9 +147,16 @@ class DruxtRouter {
147
147
  break;
148
148
  }
149
149
  if (!(response.status >= 200 && response.status < 300)) {
150
- const error = new Error();
151
- error.response = response;
152
- throw error;
150
+ if (response.status === 404) {
151
+ if (typeof response.data !== "object") {
152
+ response.data = { errors: [{
153
+ detail: "Please ensure the Decoupled Router module is installed and configured correctly."
154
+ }] };
155
+ } else if (response.data.message || response.data.details) {
156
+ response.data.errors = [{ detail: [response.data.message, response.data.details].filter((s) => s).join("\n") }];
157
+ }
158
+ }
159
+ this.druxt.error({ response }, { url });
153
160
  }
154
161
  return route;
155
162
  }
@@ -112,7 +112,7 @@ class DruxtRouter {
112
112
  }
113
113
  async getRoute(path) {
114
114
  const url = `/router/translate-path?path=${path}`;
115
- const response = await this.druxt.axios.get(url, {
115
+ const response = await this.druxt.get(url, {
116
116
  validateStatus: (status) => status < 500
117
117
  });
118
118
  const data = {
@@ -155,9 +155,16 @@ class DruxtRouter {
155
155
  break;
156
156
  }
157
157
  if (!(response.status >= 200 && response.status < 300)) {
158
- const error = new Error();
159
- error.response = response;
160
- throw error;
158
+ if (response.status === 404) {
159
+ if (typeof response.data !== "object") {
160
+ response.data = { errors: [{
161
+ detail: "Please ensure the Decoupled Router module is installed and configured correctly."
162
+ }] };
163
+ } else if (response.data.message || response.data.details) {
164
+ response.data.errors = [{ detail: [response.data.message, response.data.details].filter((s) => s).join("\n") }];
165
+ }
166
+ }
167
+ this.druxt.error({ response }, { url });
161
168
  }
162
169
  return route;
163
170
  }
package/nuxt/index.js CHANGED
@@ -49,7 +49,12 @@ const DruxtRouterNuxtModule = async function(moduleOptions = {}) {
49
49
  options
50
50
  });
51
51
  this.nuxt.hook("storybook:config", async ({ stories }) => {
52
- stories.push("druxt-router/dist/components/*.stories.mjs");
52
+ this.addTemplate({
53
+ src: path.resolve(__dirname, "../templates/druxt-router.stories.js"),
54
+ fileName: "stories/druxt-router.stories.js",
55
+ options: {}
56
+ });
57
+ stories.push(path.resolve(this.options.buildDir, "./stories/druxt-router.stories.js"));
53
58
  });
54
59
  };
55
60
  DruxtRouterNuxtModule.meta = require("../package.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "druxt-router",
3
- "version": "0.24.2",
3
+ "version": "0.26.1",
4
4
  "description": "Drupal router for Nuxt, powered by the Drupal Decoupled Router module.",
5
5
  "keywords": [
6
6
  "cms",
@@ -42,7 +42,7 @@
42
42
  "templates"
43
43
  ],
44
44
  "dependencies": {
45
- "druxt": "^0.15.0",
45
+ "druxt": "^0.18.0",
46
46
  "url-parse": "^1.4.7"
47
47
  },
48
48
  "optionalDependencies": {
@@ -0,0 +1,65 @@
1
+ import DruxtRouter from 'druxt-router/dist/components/DruxtRouter.vue'
2
+
3
+ export default {
4
+ title: 'Druxt/Router/DruxtRouter',
5
+ component: DruxtRouter
6
+ }
7
+
8
+ // Default story.
9
+ export const Default = (args, { argTypes }) => ({
10
+ components: { DruxtRouter },
11
+ props: Object.keys(argTypes),
12
+ template: `<DruxtRouter v-bind="$props" />`
13
+ })
14
+ Default.args = { path: '/' }
15
+
16
+ let code
17
+
18
+ // Wrapper story.
19
+ code = `<template>
20
+ <DruxtDebug :json="route" />
21
+ </template>
22
+
23
+ <script>
24
+ import { DruxtRouterMixin } from 'druxt-router'
25
+ export default {
26
+ mixins: [DruxtRouterMixin]
27
+ }
28
+ </script>`
29
+ export const Wrapper = (args, { argTypes }) => ({
30
+ components: { DruxtRouter },
31
+ props: Object.keys(argTypes),
32
+ template: `<DruxtRouter v-bind="$props" ref="module">
33
+ <template #default>
34
+ Component options:
35
+ <ul>
36
+ <li v-for="option of $refs.module.getModuleComponents()" :key="option.name">{{ option.name }}</li>
37
+ </ul>
38
+ </template>
39
+ </DruxtRouter>`
40
+ })
41
+ Wrapper.parameters = {
42
+ docs: {
43
+ storyDescription: 'The DruxtRouter component can be themed by using a Druxt Wrapper component.\n\nCreate an appropriately named component, using the relevant component option, with the following boilerplate:\n\n```jsx\n' + code + '\n```',
44
+ source: { code }
45
+ }
46
+ }
47
+
48
+ // Template injection story.
49
+ code = `<DruxtRouter path="">
50
+ <template #default="{ route }">
51
+ <!-- Do whatever you want here -->
52
+ <DruxtDebug :json="route" open />
53
+ </template>
54
+ </DruxtRouter>`
55
+ export const TemplateInjection = (args, { argTypes }) => ({
56
+ components: { DruxtRouter },
57
+ props: Object.keys(argTypes),
58
+ template: code.replace('path=""', 'v-bind="$props"')
59
+ })
60
+ TemplateInjection.parameters = {
61
+ docs: {
62
+ storyDescription: 'The DruxtRouter component can be themed by injecting the default template into the compomnent.\n\n```jsx\n' + code + '\n```',
63
+ source: { code }
64
+ }
65
+ }
package/CHANGELOG.md DELETED
@@ -1,300 +0,0 @@
1
- # druxt-router
2
-
3
- ## 0.24.2
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [2ae1d6d]
8
- - druxt@0.15.0
9
-
10
- ## 0.24.1
11
-
12
- ### Patch Changes
13
-
14
- - Updated dependencies [45bc0b9]
15
- - druxt@0.14.0
16
-
17
- ## 0.24.0
18
-
19
- ### Minor Changes
20
-
21
- - 9161b38: Added Storybook integration for the DruxtRouter component.
22
- - 9161b38: Added ability to render a specific route using the Path property.
23
-
24
- ```jsx
25
- <DruxtRouter path="/node/1" />
26
- ```
27
-
28
- - 9161b38: Added fetch hook to DruxtRouter component.
29
- - 9161b38: Added option to disable the DruxtRouter page middleware.
30
-
31
- ```js
32
- export default {
33
- druxt: {
34
- router: {
35
- middleware: false
36
- }
37
- }
38
- };
39
- ```
40
-
41
- Note: This is experimental and your results may vary.
42
-
43
- ## 0.23.0
44
-
45
- ### Minor Changes
46
-
47
- - 77ab204: Added support for API Proxy
48
-
49
- ### Patch Changes
50
-
51
- - Updated dependencies [77ab204]
52
- - druxt@0.13.0
53
-
54
- ## 0.22.0
55
-
56
- ### Minor Changes
57
-
58
- - c7b267a: Throw Error on router errors
59
-
60
- ### Patch Changes
61
-
62
- - Updated dependencies [4504a2f]
63
- - druxt@0.12.0
64
-
65
- ## 0.21.0
66
-
67
- ### Minor Changes
68
-
69
- - 9d905e8: Set router `pages` option default based on presence of `pages/` directory.
70
- - 9d905e8: Moved Nuxt module to `druxt-router/nuxt`
71
-
72
- ⚠ Potential breaking change
73
-
74
- ```diff
75
- -modules: ['druxt-router']
76
- +modules: ['druxt-router/nuxt']
77
- ```
78
-
79
- - dae345e: Added module level options
80
-
81
- ### Patch Changes
82
-
83
- - Updated dependencies [dae345e]
84
- - druxt@0.11.0
85
-
86
- ## 0.20.0
87
-
88
- ### Minor Changes
89
-
90
- - 1ab762c: Enabled Nuxt Vuex store by default
91
- - ecefef5: Added option to disable wildcard route
92
- - 715e5ef: Updated component registration method to use the Nuxt `components:dirs` hook
93
- - cbc66cd: Added option to disable `pages/` routes
94
-
95
- ### Patch Changes
96
-
97
- - Updated dependencies [715e5ef]
98
- - druxt@0.10.0
99
-
100
- ## 0.19.1
101
-
102
- ### Patch Changes
103
-
104
- - c4616df: Fixed dependencies
105
-
106
- ## 0.19.0
107
-
108
- ### Minor Changes
109
-
110
- - 21170fb: Moved Vue components out of bundle
111
-
112
- ⚠ Potential breaking change
113
-
114
- _**Note:** This only effects custom Druxt modules and implementations._
115
-
116
- ```diff
117
- -import { DruxtRouter } from 'druxt-router'
118
- +import DruxtRouter from 'druxt-router/dist/components/DruxtRouter.vue'
119
- ```
120
-
121
- ### Patch Changes
122
-
123
- - Updated dependencies [21170fb]
124
- - druxt@0.9.0
125
-
126
- ## 0.18.1
127
-
128
- ### Patch Changes
129
-
130
- - Added `hid` to canonical meta tag
131
- - Fixed issue with metatags
132
-
133
- ## 0.18.0
134
-
135
- ### Minor Changes
136
-
137
- - Deprecated client methods in favour of DruxtClient
138
-
139
- ## 0.17.3
140
-
141
- ### Patch Changes
142
-
143
- - Fixed issue with querystring and getRedirect()
144
-
145
- ## 0.17.2
146
-
147
- ### Patch Changes
148
-
149
- - Updated dependencies
150
-
151
- ## 0.17.1
152
-
153
- ### Patch Changes
154
-
155
- - Fixed issue with permission check
156
-
157
- ## 0.17.0
158
-
159
- ### Minor Changes
160
-
161
- - Added support for DruxtComponentMixin
162
-
163
- ## 0.16.1
164
-
165
- ### Patch Changes
166
-
167
- - Updated Nuxt module
168
- - Updated dependencies
169
-
170
- ## 0.16.0
171
-
172
- ### Minor Changes
173
-
174
- - Added documentation
175
- - Updated dependencies
176
-
177
- ## 0.15.0
178
-
179
- ### Minor Changes
180
-
181
- - Added resolved path to router information
182
- - Added `all` option to getResources
183
-
184
- ## 0.14.0
185
-
186
- ### Minor Changes
187
-
188
- - Added support for Drupal JSON:API Params
189
- - Added addHeaders() method
190
-
191
- ## 0.13.0
192
-
193
- ### Minor Changes
194
-
195
- - Added resource index
196
- - Added support for remapped resources
197
- - Added getResources method
198
-
199
- ## 0.12.0
200
-
201
- ### Minor Changes
202
-
203
- - Added support for customisable endpoint
204
- - Added type and uuid data
205
- - Fixed hydration issue
206
-
207
- ## 0.11.1
208
-
209
- ### Patch Changes
210
-
211
- - Fixed hydration issue
212
-
213
- ## 0.11.0
214
-
215
- ### Minor Changes
216
-
217
- - Added support for additional router types
218
- - Added support for JSON:API Views routes
219
-
220
- ## 0.10.1
221
-
222
- ### Patch Changes
223
-
224
- - Fixed router WSOD error
225
-
226
- ## 0.10.0
227
-
228
- ### Minor Changes
229
-
230
- - Add configurable Router component
231
- - Refactored DruxtRouterEntityMixin
232
- - Removed support for JSON API Deserializer
233
-
234
- ## 0.9.0
235
-
236
- ### Minor Changes
237
-
238
- - Updated module to use shared Druxt configruation
239
-
240
- ## 0.8.0
241
-
242
- ### Minor Changes
243
-
244
- - Improved error handling for missing routes
245
-
246
- ## 0.7.0
247
-
248
- ### Minor Changes
249
-
250
- - Added getRoute action to Vuex store
251
- - Refactored Nuxt plugin
252
-
253
- ## 0.6.0
254
-
255
- ### Minor Changes
256
-
257
- - Added Axios settings support
258
-
259
- ## 0.5.0
260
-
261
- ### Minor Changes
262
-
263
- - Added support for redirects
264
- - Added support for JSON API resourceName
265
-
266
- ## 0.4.2
267
-
268
- ### Patch Changes
269
-
270
- - Fixed various issues
271
-
272
- ## 0.4.1
273
-
274
- ### Patch Changes
275
-
276
- - Fixed various issues
277
-
278
- ## 0.4.0
279
-
280
- ### Minor Changes
281
-
282
- ## 0.3.0
283
-
284
- ### Minor Changes
285
-
286
- ## 0.2.2
287
-
288
- ### Patch Changes
289
-
290
- ## 0.2.1
291
-
292
- ### Patch Changes
293
-
294
- ## 0.2.0
295
-
296
- ### Minor Changes
297
-
298
- ## 0.1.0
299
-
300
- ### Initial release
@@ -1,16 +0,0 @@
1
- import DruxtRouter from './DruxtRouter.vue'
2
-
3
- export default {
4
- title: 'Druxt/Router/DruxtRouter',
5
- component: DruxtRouter
6
- }
7
-
8
- const Template = (args, { argTypes }) => ({
9
- components: { DruxtRouter },
10
- props: Object.keys(argTypes),
11
- template: `<DruxtRouter v-bind="$props" />`
12
- })
13
-
14
- export const Default = Template.bind({})
15
- Default.storyName = 'DruxtRouter'
16
- Default.args = { path: '/' }