druxt-router 0.24.0 → 0.26.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.
@@ -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.0",
3
+ "version": "0.26.0",
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.13.0",
45
+ "druxt": "^0.17.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,286 +0,0 @@
1
- # druxt-router
2
-
3
- ## 0.24.0
4
-
5
- ### Minor Changes
6
-
7
- - 9161b38: Added Storybook integration for the DruxtRouter component.
8
- - 9161b38: Added ability to render a specific route using the Path property.
9
-
10
- ```jsx
11
- <DruxtRouter path="/node/1" />
12
- ```
13
-
14
- - 9161b38: Added fetch hook to DruxtRouter component.
15
- - 9161b38: Added option to disable the DruxtRouter page middleware.
16
-
17
- ```js
18
- export default {
19
- druxt: {
20
- router: {
21
- middleware: false
22
- }
23
- }
24
- };
25
- ```
26
-
27
- Note: This is experimental and your results may vary.
28
-
29
- ## 0.23.0
30
-
31
- ### Minor Changes
32
-
33
- - 77ab204: Added support for API Proxy
34
-
35
- ### Patch Changes
36
-
37
- - Updated dependencies [77ab204]
38
- - druxt@0.13.0
39
-
40
- ## 0.22.0
41
-
42
- ### Minor Changes
43
-
44
- - c7b267a: Throw Error on router errors
45
-
46
- ### Patch Changes
47
-
48
- - Updated dependencies [4504a2f]
49
- - druxt@0.12.0
50
-
51
- ## 0.21.0
52
-
53
- ### Minor Changes
54
-
55
- - 9d905e8: Set router `pages` option default based on presence of `pages/` directory.
56
- - 9d905e8: Moved Nuxt module to `druxt-router/nuxt`
57
-
58
- ⚠ Potential breaking change
59
-
60
- ```diff
61
- -modules: ['druxt-router']
62
- +modules: ['druxt-router/nuxt']
63
- ```
64
-
65
- - dae345e: Added module level options
66
-
67
- ### Patch Changes
68
-
69
- - Updated dependencies [dae345e]
70
- - druxt@0.11.0
71
-
72
- ## 0.20.0
73
-
74
- ### Minor Changes
75
-
76
- - 1ab762c: Enabled Nuxt Vuex store by default
77
- - ecefef5: Added option to disable wildcard route
78
- - 715e5ef: Updated component registration method to use the Nuxt `components:dirs` hook
79
- - cbc66cd: Added option to disable `pages/` routes
80
-
81
- ### Patch Changes
82
-
83
- - Updated dependencies [715e5ef]
84
- - druxt@0.10.0
85
-
86
- ## 0.19.1
87
-
88
- ### Patch Changes
89
-
90
- - c4616df: Fixed dependencies
91
-
92
- ## 0.19.0
93
-
94
- ### Minor Changes
95
-
96
- - 21170fb: Moved Vue components out of bundle
97
-
98
- ⚠ Potential breaking change
99
-
100
- _**Note:** This only effects custom Druxt modules and implementations._
101
-
102
- ```diff
103
- -import { DruxtRouter } from 'druxt-router'
104
- +import DruxtRouter from 'druxt-router/dist/components/DruxtRouter.vue'
105
- ```
106
-
107
- ### Patch Changes
108
-
109
- - Updated dependencies [21170fb]
110
- - druxt@0.9.0
111
-
112
- ## 0.18.1
113
-
114
- ### Patch Changes
115
-
116
- - Added `hid` to canonical meta tag
117
- - Fixed issue with metatags
118
-
119
- ## 0.18.0
120
-
121
- ### Minor Changes
122
-
123
- - Deprecated client methods in favour of DruxtClient
124
-
125
- ## 0.17.3
126
-
127
- ### Patch Changes
128
-
129
- - Fixed issue with querystring and getRedirect()
130
-
131
- ## 0.17.2
132
-
133
- ### Patch Changes
134
-
135
- - Updated dependencies
136
-
137
- ## 0.17.1
138
-
139
- ### Patch Changes
140
-
141
- - Fixed issue with permission check
142
-
143
- ## 0.17.0
144
-
145
- ### Minor Changes
146
-
147
- - Added support for DruxtComponentMixin
148
-
149
- ## 0.16.1
150
-
151
- ### Patch Changes
152
-
153
- - Updated Nuxt module
154
- - Updated dependencies
155
-
156
- ## 0.16.0
157
-
158
- ### Minor Changes
159
-
160
- - Added documentation
161
- - Updated dependencies
162
-
163
- ## 0.15.0
164
-
165
- ### Minor Changes
166
-
167
- - Added resolved path to router information
168
- - Added `all` option to getResources
169
-
170
- ## 0.14.0
171
-
172
- ### Minor Changes
173
-
174
- - Added support for Drupal JSON:API Params
175
- - Added addHeaders() method
176
-
177
- ## 0.13.0
178
-
179
- ### Minor Changes
180
-
181
- - Added resource index
182
- - Added support for remapped resources
183
- - Added getResources method
184
-
185
- ## 0.12.0
186
-
187
- ### Minor Changes
188
-
189
- - Added support for customisable endpoint
190
- - Added type and uuid data
191
- - Fixed hydration issue
192
-
193
- ## 0.11.1
194
-
195
- ### Patch Changes
196
-
197
- - Fixed hydration issue
198
-
199
- ## 0.11.0
200
-
201
- ### Minor Changes
202
-
203
- - Added support for additional router types
204
- - Added support for JSON:API Views routes
205
-
206
- ## 0.10.1
207
-
208
- ### Patch Changes
209
-
210
- - Fixed router WSOD error
211
-
212
- ## 0.10.0
213
-
214
- ### Minor Changes
215
-
216
- - Add configurable Router component
217
- - Refactored DruxtRouterEntityMixin
218
- - Removed support for JSON API Deserializer
219
-
220
- ## 0.9.0
221
-
222
- ### Minor Changes
223
-
224
- - Updated module to use shared Druxt configruation
225
-
226
- ## 0.8.0
227
-
228
- ### Minor Changes
229
-
230
- - Improved error handling for missing routes
231
-
232
- ## 0.7.0
233
-
234
- ### Minor Changes
235
-
236
- - Added getRoute action to Vuex store
237
- - Refactored Nuxt plugin
238
-
239
- ## 0.6.0
240
-
241
- ### Minor Changes
242
-
243
- - Added Axios settings support
244
-
245
- ## 0.5.0
246
-
247
- ### Minor Changes
248
-
249
- - Added support for redirects
250
- - Added support for JSON API resourceName
251
-
252
- ## 0.4.2
253
-
254
- ### Patch Changes
255
-
256
- - Fixed various issues
257
-
258
- ## 0.4.1
259
-
260
- ### Patch Changes
261
-
262
- - Fixed various issues
263
-
264
- ## 0.4.0
265
-
266
- ### Minor Changes
267
-
268
- ## 0.3.0
269
-
270
- ### Minor Changes
271
-
272
- ## 0.2.2
273
-
274
- ### Patch Changes
275
-
276
- ## 0.2.1
277
-
278
- ### Patch Changes
279
-
280
- ## 0.2.0
281
-
282
- ### Minor Changes
283
-
284
- ## 0.1.0
285
-
286
- ### 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: '/' }