druxt-blocks 0.12.0 → 0.14.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # druxt-blocks
2
2
 
3
+ ## 0.14.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [9161b38]
8
+ - druxt-router@0.24.0
9
+ - druxt-entity@0.21.2
10
+
11
+ ## 0.14.0
12
+
13
+ ### Minor Changes
14
+
15
+ - e7b1533: Refactored DruxtModule fetch hooks
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [025315a]
20
+ - druxt-entity@0.21.0
21
+ - druxt@0.13.0
22
+ - druxt-router@0.23.0
23
+
24
+ ## 0.13.1
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [4504a2f]
29
+ - druxt@0.12.0
30
+ - druxt-router@0.22.0
31
+ - druxt-entity@0.20.0
32
+
33
+ ## 0.13.0
34
+
35
+ ### Minor Changes
36
+
37
+ - dae345e: Moved `$druxtBlocks` plugin settings to `$druxt.settings.blocks`
38
+ - dae345e: Added module level options
39
+ - 8d28c18: Updated storybook integration
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [9d905e8]
44
+ - druxt-router@0.21.0
45
+ - druxt-entity@0.19.0
46
+ - druxt@0.11.0
47
+
3
48
  ## 0.12.0
4
49
 
5
50
  ### Minor Changes
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  ## Links
11
11
 
12
12
  - DruxtJS: https://druxtjs.org
13
- - Documentation: https://blocks.druxtjs.org/
13
+ - Documentation: https://druxtjs.org/modules/blocks
14
14
  - Community Discord server: https://discord.druxtjs.org
15
15
 
16
16
 
@@ -51,7 +51,7 @@ The DruxtBlock component renders a Drupal JSON:API Block resource by ID or UUID.
51
51
  <DruxtBlock :uuid="uuid" />
52
52
  ```
53
53
 
54
- See the [DruxtBlock API Documentation](https://blocks.druxtjs.org/api/components/DruxtBlock.html) for more information.
54
+ See the [DruxtBlock API Documentation](https://druxtjs.org/api/packages/blocks/components/DruxtBlock) for more information.
55
55
 
56
56
 
57
57
  ### DruxtBlockRegion
@@ -62,9 +62,9 @@ The DruxtBlockRegion component renders all visible blocks for the specified them
62
62
  <DruxtBlockRegion :name="name" :theme="theme" />
63
63
  ```
64
64
 
65
- ![Example DruxtBlockRegion component](https://raw.githubusercontent.com/druxt/druxt-blocks/HEAD/docs/images/druxt-block-region.png)
65
+ ![Example DruxtBlockRegion component](https://druxtjs.org/images/druxt-block-region.png)
66
66
 
67
- See the [DruxtBlockRegion API Documentation](https://blocks.druxtjs.org/api/components/DruxtBlockRegion.html) for more information.
67
+ See the [DruxtBlockRegion API Documentation](https://druxtjs.org/api/packages/blocks/components/DruxtBlockRegion) for more information.
68
68
 
69
69
 
70
70
  ### Theming
@@ -81,7 +81,7 @@ Both components can be themed by providing a default template:
81
81
 
82
82
  The module also provides Wrapper components with scoped slots for theming.
83
83
 
84
- See the [Druxt Theming guide](https://druxtjs.org/guide/theming.html) for more information.
84
+ See the [Druxt Theming guide](https://druxtjs.org/guide/theming) for more information.
85
85
 
86
86
 
87
87
  ## Options
@@ -0,0 +1,15 @@
1
+ import DruxtBlock from './DruxtBlock.vue'
2
+
3
+ export default {
4
+ title: 'Druxt/Blocks/DruxtBlock',
5
+ component: DruxtBlock
6
+ }
7
+
8
+ const Template = (args, { argTypes }) => ({
9
+ components: { DruxtBlock },
10
+ props: Object.keys(argTypes),
11
+ template: `<DruxtBlock v-bind="$props" />`
12
+ })
13
+
14
+ export const Default = Template.bind({})
15
+ Default.storyName = 'DruxtBlock'
@@ -56,41 +56,6 @@ export default {
56
56
  resource: {},
57
57
  }),
58
58
 
59
- /**
60
- * The Nuxt Fetch hook.
61
- *
62
- * Fetches the Block JSON:API resource by either UUID or ID.
63
- */
64
- async fetch() {
65
- // Build query.
66
- const type = 'block--block'
67
- const query = new DrupalJsonApiParams()
68
- if (Array.isArray((((this.$druxtBlocks || {}).options || {}).query || {}).fields)) {
69
- query.addFields(type, [
70
- ...this.$druxtBlocks.options.query.fields,
71
- 'plugin',
72
- 'region',
73
- 'settings',
74
- 'theme',
75
- ])
76
- }
77
-
78
- // Fetch Block by UUID.
79
- if (this.uuid) {
80
- const id = this.uuid
81
- this.resource = await this.getResource({ type, id, query })
82
- }
83
-
84
- // Fetch Block by Drupal internal ID.
85
- else if (this.id) {
86
- query.addFilter('drupal_internal__id', this.id)
87
- const collection = await this.getCollection({ type, query })
88
- this.resource = { data: collection.data[0] }
89
- }
90
-
91
- await DruxtModule.fetch.call(this)
92
- },
93
-
94
59
  fetchKey(getCounter) {
95
60
  const parts = ['DruxtBlock', this.uuid || this.id].filter((o) => o)
96
61
  return [...parts, getCounter(parts.join(':'))].join(':')
@@ -146,6 +111,39 @@ export default {
146
111
  return componentOptions
147
112
  },
148
113
 
114
+ /**
115
+ * Fetches the Block JSON:API resource by either UUID or ID.
116
+ */
117
+ async fetchConfig() {
118
+ // Build query.
119
+ const type = 'block--block'
120
+ const query = new DrupalJsonApiParams()
121
+
122
+ const fields = ((this.$druxt.settings.blocks || {}).query || {}).fields
123
+ if (Array.isArray(fields)) {
124
+ query.addFields(type, [
125
+ ...fields,
126
+ 'plugin',
127
+ 'region',
128
+ 'settings',
129
+ 'theme',
130
+ ])
131
+ }
132
+
133
+ // Fetch Block by UUID.
134
+ if (this.uuid) {
135
+ const id = this.uuid
136
+ this.resource = await this.getResource({ type, id, query })
137
+ }
138
+
139
+ // Fetch Block by Drupal internal ID.
140
+ else if (this.id) {
141
+ query.addFilter('drupal_internal__id', this.id)
142
+ const collection = await this.getCollection({ type, query })
143
+ this.resource = { data: collection.data[0] }
144
+ }
145
+ },
146
+
149
147
  /**
150
148
  * Provides propsData for the DruxtWrapper.
151
149
  *
@@ -0,0 +1,15 @@
1
+ import DruxtBlockRegion from './DruxtBlockRegion.vue'
2
+
3
+ export default {
4
+ title: 'Druxt/Blocks/DruxtBlockRegion',
5
+ component: DruxtBlockRegion
6
+ }
7
+
8
+ const Template = (args, { argTypes }) => ({
9
+ components: { DruxtBlockRegion },
10
+ props: Object.keys(argTypes),
11
+ template: `<DruxtBlockRegion v-bind="$props" />`
12
+ })
13
+
14
+ export const Default = Template.bind({})
15
+ Default.storyName = 'DruxtBlockRegion'
@@ -58,27 +58,6 @@ export default {
58
58
  blocks: []
59
59
  }),
60
60
 
61
- /**
62
- * The Nuxt Fetch hook.
63
- *
64
- * Fetches all blocks by region and theme.
65
- */
66
- async fetch() {
67
- const type = 'block--block'
68
- const query = new DrupalJsonApiParams()
69
- query
70
- .addFilter('region', this.name)
71
- .addFilter('status', '1')
72
- .addFilter('theme', this.theme)
73
- .addSort('weight')
74
- .addFields(type, ['drupal_internal__id', 'visibility', 'weight'])
75
-
76
- const collection = await this.getCollection({ type, query })
77
- this.blocks = collection.data
78
-
79
- await DruxtModule.fetch.call(this)
80
- },
81
-
82
61
  fetchKey(getCounter) {
83
62
  const parts = ['DruxtBlockRegion', this.name].filter((o) => o)
84
63
  return [...parts, getCounter(parts.join(':'))].join(':')
@@ -146,6 +125,23 @@ export default {
146
125
  */
147
126
  componentOptions: ({ name, theme }) => [[name, theme], ['default']],
148
127
 
128
+ /**
129
+ * Fetches all blocks by region and theme.
130
+ */
131
+ async fetchConfig() {
132
+ const type = 'block--block'
133
+ const query = new DrupalJsonApiParams()
134
+ query
135
+ .addFilter('region', this.name)
136
+ .addFilter('status', '1')
137
+ .addFilter('theme', this.theme)
138
+ .addSort('weight')
139
+ .addFields(type, ['drupal_internal__id', 'visibility', 'weight'])
140
+
141
+ const collection = await this.getCollection({ type, query })
142
+ this.blocks = collection.data
143
+ },
144
+
149
145
  /**
150
146
  * Provides propsData for the DruxtWrapper.
151
147
  *
@@ -5,16 +5,16 @@ import { DruxtClient } from 'druxt';
5
5
  const titleFn = (parts) => parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1).replace(/_/g, " ")).join("/");
6
6
  async function DruxtBlocksStorybook({ stories }) {
7
7
  const { addTemplate, options } = this;
8
- const druxt = new DruxtClient(options.druxt.baseUrl, options.druxt);
8
+ const druxt = new DruxtClient(options.druxt.baseUrl, { ...options.druxt, proxy: { api: false } });
9
9
  const query = new DrupalJsonApiParams().addFilter("status", true);
10
10
  const blocks = (await druxt.getCollectionAll("block--block", query)).map((collection) => collection.data).flat();
11
11
  const blockStories = blocks.map((block) => {
12
12
  addTemplate({
13
- src: resolve(__dirname, `../nuxt/druxt-block.stories.js`),
13
+ src: resolve(__dirname, `../templates/druxt-block.stories.js`),
14
14
  fileName: `stories/druxt-block.${block.attributes.drupal_internal__id}.stories.js`,
15
15
  options: {
16
16
  block,
17
- title: titleFn(["Druxt Blocks", block.attributes.theme, block.attributes.region, block.attributes.drupal_internal__id])
17
+ title: titleFn(["Druxt", "Blocks", block.attributes.theme, block.attributes.region, block.attributes.drupal_internal__id])
18
18
  }
19
19
  });
20
20
  return resolve(options.buildDir, `./stories/druxt-block.${block.attributes.drupal_internal__id}.stories.js`);
@@ -25,11 +25,11 @@ async function DruxtBlocksStorybook({ stories }) {
25
25
  const regions = Array.from(new Set(blocks.filter((o) => o.attributes.theme === theme).map((o) => o.attributes.region)));
26
26
  return regions.map((region) => {
27
27
  addTemplate({
28
- src: resolve(__dirname, `../nuxt/druxt-block-region.stories.js`),
28
+ src: resolve(__dirname, `../templates/druxt-block-region.stories.js`),
29
29
  fileName: `stories/druxt-block-region.${theme}.${region}.stories.js`,
30
30
  options: {
31
31
  region,
32
- title: titleFn(["Druxt Blocks", theme, region]),
32
+ title: titleFn(["Druxt", "Blocks", theme, region]),
33
33
  theme
34
34
  }
35
35
  });
@@ -39,28 +39,27 @@ async function DruxtBlocksStorybook({ stories }) {
39
39
  stories.push.apply(stories, regionStories);
40
40
  }
41
41
 
42
- const DruxtBlocksNuxtModule = function() {
43
- const { options } = this;
44
- if (typeof options === "undefined" || !options.druxt) {
45
- throw new TypeError("Druxt settings missing.");
46
- }
47
- const modules = ["druxt"].filter((module) => !(options.modules || []).includes(module));
48
- for (const module of modules) {
49
- this.addModule(module);
50
- }
42
+ const DruxtBlocksNuxtModule = function(moduleOptions = {}) {
43
+ const options = {
44
+ baseUrl: moduleOptions.baseUrl,
45
+ ...(this.options || {}).druxt || {},
46
+ blocks: {
47
+ query: {},
48
+ ...((this.options || {}).druxt || {}).site,
49
+ ...moduleOptions
50
+ }
51
+ };
52
+ this.addModule(["druxt", options]);
51
53
  this.nuxt.hook("components:dirs", (dirs) => {
52
54
  dirs.push({ path: join(__dirname, "components") });
53
55
  dirs.push({ path: join(__dirname, "components/blocks") });
54
56
  });
55
- this.addPlugin({
56
- src: resolve(__dirname, "../nuxt/plugin.js"),
57
- fileName: "druxt-blocks.js",
58
- options: options.druxt
59
- });
60
57
  this.nuxt.hook("storybook:config", async ({ stories }) => {
58
+ stories.push("druxt-blocks/dist/components/*.stories.mjs");
61
59
  await DruxtBlocksStorybook.call(this, { stories });
62
60
  });
63
61
  };
62
+ DruxtBlocksNuxtModule.meta = require("../package.json");
64
63
 
65
64
  const DruxtBlocksBlockMixin = {
66
65
  props: {
@@ -9,16 +9,16 @@ const druxt = require('druxt');
9
9
  const titleFn = (parts) => parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1).replace(/_/g, " ")).join("/");
10
10
  async function DruxtBlocksStorybook({ stories }) {
11
11
  const { addTemplate, options } = this;
12
- const druxt$1 = new druxt.DruxtClient(options.druxt.baseUrl, options.druxt);
12
+ const druxt$1 = new druxt.DruxtClient(options.druxt.baseUrl, { ...options.druxt, proxy: { api: false } });
13
13
  const query = new drupalJsonapiParams.DrupalJsonApiParams().addFilter("status", true);
14
14
  const blocks = (await druxt$1.getCollectionAll("block--block", query)).map((collection) => collection.data).flat();
15
15
  const blockStories = blocks.map((block) => {
16
16
  addTemplate({
17
- src: path.resolve(__dirname, `../nuxt/druxt-block.stories.js`),
17
+ src: path.resolve(__dirname, `../templates/druxt-block.stories.js`),
18
18
  fileName: `stories/druxt-block.${block.attributes.drupal_internal__id}.stories.js`,
19
19
  options: {
20
20
  block,
21
- title: titleFn(["Druxt Blocks", block.attributes.theme, block.attributes.region, block.attributes.drupal_internal__id])
21
+ title: titleFn(["Druxt", "Blocks", block.attributes.theme, block.attributes.region, block.attributes.drupal_internal__id])
22
22
  }
23
23
  });
24
24
  return path.resolve(options.buildDir, `./stories/druxt-block.${block.attributes.drupal_internal__id}.stories.js`);
@@ -29,11 +29,11 @@ async function DruxtBlocksStorybook({ stories }) {
29
29
  const regions = Array.from(new Set(blocks.filter((o) => o.attributes.theme === theme).map((o) => o.attributes.region)));
30
30
  return regions.map((region) => {
31
31
  addTemplate({
32
- src: path.resolve(__dirname, `../nuxt/druxt-block-region.stories.js`),
32
+ src: path.resolve(__dirname, `../templates/druxt-block-region.stories.js`),
33
33
  fileName: `stories/druxt-block-region.${theme}.${region}.stories.js`,
34
34
  options: {
35
35
  region,
36
- title: titleFn(["Druxt Blocks", theme, region]),
36
+ title: titleFn(["Druxt", "Blocks", theme, region]),
37
37
  theme
38
38
  }
39
39
  });
@@ -43,28 +43,27 @@ async function DruxtBlocksStorybook({ stories }) {
43
43
  stories.push.apply(stories, regionStories);
44
44
  }
45
45
 
46
- const DruxtBlocksNuxtModule = function() {
47
- const { options } = this;
48
- if (typeof options === "undefined" || !options.druxt) {
49
- throw new TypeError("Druxt settings missing.");
50
- }
51
- const modules = ["druxt"].filter((module) => !(options.modules || []).includes(module));
52
- for (const module of modules) {
53
- this.addModule(module);
54
- }
46
+ const DruxtBlocksNuxtModule = function(moduleOptions = {}) {
47
+ const options = {
48
+ baseUrl: moduleOptions.baseUrl,
49
+ ...(this.options || {}).druxt || {},
50
+ blocks: {
51
+ query: {},
52
+ ...((this.options || {}).druxt || {}).site,
53
+ ...moduleOptions
54
+ }
55
+ };
56
+ this.addModule(["druxt", options]);
55
57
  this.nuxt.hook("components:dirs", (dirs) => {
56
58
  dirs.push({ path: path.join(__dirname, "components") });
57
59
  dirs.push({ path: path.join(__dirname, "components/blocks") });
58
60
  });
59
- this.addPlugin({
60
- src: path.resolve(__dirname, "../nuxt/plugin.js"),
61
- fileName: "druxt-blocks.js",
62
- options: options.druxt
63
- });
64
61
  this.nuxt.hook("storybook:config", async ({ stories }) => {
62
+ stories.push("druxt-blocks/dist/components/*.stories.mjs");
65
63
  await DruxtBlocksStorybook.call(this, { stories });
66
64
  });
67
65
  };
66
+ DruxtBlocksNuxtModule.meta = require("../package.json");
68
67
 
69
68
  const DruxtBlocksBlockMixin = {
70
69
  props: {
package/package.json CHANGED
@@ -1,20 +1,33 @@
1
1
  {
2
2
  "name": "druxt-blocks",
3
- "version": "0.12.0",
3
+ "version": "0.14.1",
4
4
  "description": "Drupal Block and Block Region Druxt components.",
5
5
  "keywords": [
6
6
  "block",
7
7
  "blocks",
8
+ "cms",
9
+ "decoupled",
8
10
  "drupal",
9
11
  "druxt",
10
- "nuxt"
12
+ "druxtjs",
13
+ "headless",
14
+ "jsonapi",
15
+ "json:api",
16
+ "nuxt",
17
+ "nuxtjs",
18
+ "module",
19
+ "storybook",
20
+ "vue"
11
21
  ],
12
- "license": "MIT",
13
- "author": {
14
- "name": "Stuart Clark",
15
- "email": "stuart@realityloop.com",
16
- "url": "https://realityloop.com"
22
+ "homepage": "https://druxtjs.org",
23
+ "bugs": {
24
+ "url": "https://github.com/druxt/druxt.js/issues"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/druxt/druxt.js"
17
29
  },
30
+ "license": "MIT",
18
31
  "exports": {
19
32
  ".": {
20
33
  "require": "./dist/druxt-blocks.ssr.js",
@@ -26,14 +39,14 @@
26
39
  "module": "dist/druxt-blocks.esm.js",
27
40
  "files": [
28
41
  "dist",
29
- "nuxt"
42
+ "templates"
30
43
  ],
31
44
  "dependencies": {
32
45
  "axios": "^0.21.1",
33
46
  "drupal-jsonapi-params": "^1.1.12",
34
- "druxt": "^0.10.0",
35
- "druxt-entity": "^0.18.0",
36
- "druxt-router": "^0.20.0"
47
+ "druxt": "^0.13.0",
48
+ "druxt-entity": "^0.21.2",
49
+ "druxt-router": "^0.24.0"
37
50
  },
38
51
  "optionalDependencies": {
39
52
  "vue": "^2.6.14",
File without changes
package/nuxt/plugin.js DELETED
@@ -1,11 +0,0 @@
1
- export default (context, inject) => {
2
- const options = {}
3
-
4
- <% if (Array.isArray(((options.blocks || {}).query || {}).fields)) { %>
5
- options.query = {
6
- fields: [<%= options.blocks.query.fields.map((s) => `"${s}"`).join(', ') %>],
7
- }
8
- <% } %>
9
-
10
- inject('druxtBlocks', { options })
11
- }