druxt-site 0.8.0 → 0.10.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,70 @@
1
1
  # druxt-site
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [9161b38]
8
+ - druxt-router@0.24.0
9
+ - druxt-blocks@0.14.1
10
+ - druxt-breadcrumb@0.13.1
11
+ - druxt-entity@0.21.2
12
+ - druxt-views@0.16.1
13
+
14
+ ## 0.10.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 77ab204: Replaced File Proxy with Druxt proxy
19
+ - e7b1533: Refactored DruxtModule fetch hooks
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [025315a]
24
+ - druxt-entity@0.21.0
25
+ - druxt-views@0.16.0
26
+ - druxt-schema@0.9.0
27
+ - druxt-blocks@0.14.0
28
+ - druxt-breadcrumb@0.13.0
29
+ - druxt@0.13.0
30
+ - druxt-menu@0.15.0
31
+ - druxt-router@0.23.0
32
+
33
+ ## 0.9.1
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [4504a2f]
38
+ - druxt@0.12.0
39
+ - druxt-router@0.22.0
40
+ - druxt-menu@0.14.1
41
+ - druxt-entity@0.20.0
42
+ - druxt-views@0.15.0
43
+ - druxt-blocks@0.13.1
44
+ - druxt-breadcrumb@0.12.1
45
+ - druxt-schema@0.8.1
46
+
47
+ ## 0.9.0
48
+
49
+ ### Minor Changes
50
+
51
+ - 8d28c18: Updated storybook integration
52
+ - 97d24d5: Added default theme option and fallback to DruxtSite component
53
+ - 97d24d5: Added default layout
54
+
55
+ ### Patch Changes
56
+
57
+ - dae345e: Fixed default @nuxtjs/proxy settings
58
+ - Updated dependencies [9d905e8]
59
+ - druxt-router@0.21.0
60
+ - druxt-views@0.14.0
61
+ - druxt-breadcrumb@0.12.0
62
+ - druxt-blocks@0.13.0
63
+ - druxt-entity@0.19.0
64
+ - druxt-menu@0.14.0
65
+ - druxt-schema@0.8.0
66
+ - druxt@0.11.0
67
+
3
68
  ## 0.8.0
4
69
 
5
70
  ### Minor Changes
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  ## Links
12
12
 
13
13
  - DruxtJS: https://druxtjs.org
14
- - Documentation: https://site.druxtjs.org
14
+ - Documentation: https://druxtjs.org/modules/site
15
15
  - Community Discord server: https://discord.druxtjs.org
16
16
 
17
17
  ## Install
@@ -0,0 +1,15 @@
1
+ import DruxtSite from './DruxtSite.vue'
2
+
3
+ export default {
4
+ title: 'Druxt/Site/DruxtSite',
5
+ component: DruxtSite
6
+ }
7
+
8
+ const Template = (args, { argTypes }) => ({
9
+ components: { DruxtSite },
10
+ props: Object.keys(argTypes),
11
+ template: `<DruxtSite v-bind="$props" />`
12
+ })
13
+
14
+ export const Default = Template.bind({})
15
+ Default.storyName = 'DruxtSite'
@@ -55,31 +55,13 @@ export default {
55
55
  */
56
56
  theme: {
57
57
  type: String,
58
- required: true
58
+ default: undefined,
59
59
  }
60
60
  },
61
61
 
62
- /**
63
- * Nuxt.js fetch method.
64
- *
65
- * Fetches theme filtered region names from the Block JSON:API resources to be
66
- * used to render the `<DruxtBlockRegion />`'s.
67
- */
68
- async fetch() {
69
- // Fetch all available regions.
70
- if (!this.value) {
71
- const type = 'block--block'
72
- this.model = await this.getCollection({
73
- type,
74
- query: new DrupalJsonApiParams()
75
- .addFilter('theme', this.theme)
76
- .addFields(type, ['region']),
77
- }).then((resources) => resources.data.map((resource) => resource.attributes.region).filter((v, i, s) => s.indexOf(v) === i))
78
- }
79
-
80
- // Call DruxtModule fetch hook.
81
- await DruxtModule.fetch.call(this)
82
- },
62
+ data: ({ $druxt }) => ({
63
+ defaultTheme: ($druxt.settings.site || {}).theme,
64
+ }),
83
65
 
84
66
  /**
85
67
  * Vue.js Computed properties.
@@ -90,11 +72,11 @@ export default {
90
72
  *
91
73
  * @return {object}
92
74
  */
93
- props: ({ regions, theme }) =>
75
+ props: ({ defaultTheme, regions, theme }) =>
94
76
  Object.fromEntries(regions.map((region) => [region, {
95
77
  key: region,
96
78
  name: region,
97
- theme,
79
+ theme: theme || defaultTheme,
98
80
  }])),
99
81
 
100
82
  /**
@@ -118,7 +100,36 @@ export default {
118
100
  * @param {object} context - The module component ViewModel.
119
101
  * @returns {ComponentOptions}
120
102
  */
121
- componentOptions: ({ theme }) => [[theme], ['default']],
103
+ componentOptions: ({ defaultTheme, theme }) => [[theme || defaultTheme], ['default']],
104
+
105
+ /**
106
+ * Fetches theme filtered region names from the Block JSON:API resources to
107
+ * be used to render the `<DruxtBlockRegion />`'s.
108
+ */
109
+ async fetchConfig() {
110
+ const type = 'block--block'
111
+
112
+ // If no default theme is provided, get the first available valid theme.
113
+ if (!this.defaultTheme) {
114
+ this.defaultTheme = await this.getCollection({
115
+ type,
116
+ query: new DrupalJsonApiParams()
117
+ .addFields(type, ['theme'])
118
+ .addFilter('plugin', 'system_main_block')
119
+ .addPageLimit(1)
120
+ }).then((resources) => resources.data[0].attributes.theme)
121
+ }
122
+
123
+ // Fetch all available regions.
124
+ if (!this.value) {
125
+ this.model = await this.getCollection({
126
+ type,
127
+ query: new DrupalJsonApiParams()
128
+ .addFilter('theme', this.theme || this.defaultTheme)
129
+ .addFields(type, ['region']),
130
+ }).then((resources) => resources.data.map((resource) => resource.attributes.region).filter((v, i, s) => s.indexOf(v) === i))
131
+ }
132
+ },
122
133
 
123
134
  /**
124
135
  * Provides propsData for the DruxtWrapper.
@@ -126,7 +137,7 @@ export default {
126
137
  * @param {object} context - The module component ViewModel.
127
138
  * @returns {PropsData}
128
139
  */
129
- propsData: ({ props, regions, theme }) => ({ props, regions, theme }),
140
+ propsData: ({ defaultTheme, props, regions, theme }) => ({ props, regions, theme: theme || defaultTheme }),
130
141
 
131
142
  /**
132
143
  * Provides the scoped slots object for the Module render function.
@@ -1,36 +1,73 @@
1
- import { join } from 'path';
1
+ import { existsSync } from 'fs';
2
+ import { resolve, join } from 'path';
3
+ import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
4
+ import { DruxtClient } from 'druxt';
2
5
 
3
- const DruxtSiteNuxtModule = function() {
4
- if (typeof this.options === "undefined" || !this.options.druxt) {
5
- throw new TypeError("Druxt settings missing.");
6
- }
6
+ const titleFn = (parts) => parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1).replace(/_/g, " ")).join("/");
7
+ async function DruxtSiteStorybook({ options, stories }) {
8
+ const { addTemplate } = this;
9
+ const druxt = new DruxtClient(options.baseUrl, { ...options, proxy: { api: false } });
10
+ const type = "block--block";
11
+ const query = new DrupalJsonApiParams().addFields(type, ["theme"]);
12
+ const resources = (await druxt.getCollectionAll(type, query)).map((collection) => collection.data).flat();
13
+ const themes = [...new Set(resources.map((o) => o.attributes.theme))].sort();
14
+ const siteStories = themes.map((theme) => {
15
+ addTemplate({
16
+ src: resolve(__dirname, "../templates/druxt-site.stories.js"),
17
+ fileName: `stories/druxt-site.${theme}.stories.js`,
18
+ options: {
19
+ theme,
20
+ title: titleFn(["Druxt", "Site", "Themes", theme])
21
+ }
22
+ });
23
+ return resolve(this.options.buildDir, `./stories/druxt-site.${theme}.stories.js`);
24
+ });
25
+ stories.push.apply(stories, siteStories);
26
+ }
27
+
28
+ const DruxtSiteNuxtModule = async function(moduleOptions = {}) {
29
+ const options = {
30
+ baseUrl: moduleOptions.baseUrl,
31
+ ...(this.options || {}).druxt || {},
32
+ menu: {
33
+ jsonApiMenuItems: true,
34
+ ...((this.options || {}).druxt || {}).menu
35
+ },
36
+ proxy: {
37
+ api: false,
38
+ files: true,
39
+ ...((this.options || {}).druxt || {}).proxy
40
+ },
41
+ site: {
42
+ layout: true,
43
+ ...((this.options || {}).druxt || {}).site,
44
+ ...moduleOptions
45
+ }
46
+ };
47
+ this.options.druxt = options;
7
48
  this.nuxt.hook("components:dirs", (dirs) => {
8
49
  dirs.push({ path: join(__dirname, "components") });
9
50
  });
10
- const modules = [
11
- "@nuxtjs/proxy",
51
+ const druxtModules = [
12
52
  "druxt",
13
53
  "druxt-blocks",
14
54
  "druxt-breadcrumb",
15
55
  "druxt-entity",
16
56
  "druxt-menu",
17
- "druxt-router",
57
+ "druxt-router/nuxt",
18
58
  "druxt-schema",
19
59
  "druxt-views"
20
60
  ];
21
- for (const key in modules) {
22
- this.addModule(modules[key]);
61
+ for (const module of druxtModules) {
62
+ this.addModule(module);
23
63
  }
24
- if (typeof this.options.proxy === "undefined") {
25
- this.options.proxy = [this.options.druxt.baseUrl + "/sites/default/files"];
64
+ if (!await existsSync(resolve(this.options.srcDir, this.options.dir.layouts)) && options.site.layout) {
65
+ this.addLayout(resolve(__dirname, "./layouts/default.vue"), "default");
26
66
  }
27
- if (typeof ((this.options.druxt || {}).menu || {}).jsonApiMenuItems === "undefined") {
28
- this.options.druxt.menu = {
29
- ...this.options.druxt.menu,
30
- ...{ jsonApiMenuItems: true }
31
- };
32
- }
33
- this.options.store = true;
67
+ this.nuxt.hook("storybook:config", async ({ stories }) => {
68
+ stories.push("druxt-site/dist/components/*.stories.mjs");
69
+ await DruxtSiteStorybook.call(this, { options, stories });
70
+ });
34
71
  };
35
72
  DruxtSiteNuxtModule.meta = require("../package.json");
36
73
 
@@ -2,39 +2,76 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ const fs = require('fs');
5
6
  const path = require('path');
7
+ const drupalJsonapiParams = require('drupal-jsonapi-params');
8
+ const druxt = require('druxt');
6
9
 
7
- const DruxtSiteNuxtModule = function() {
8
- if (typeof this.options === "undefined" || !this.options.druxt) {
9
- throw new TypeError("Druxt settings missing.");
10
- }
10
+ const titleFn = (parts) => parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1).replace(/_/g, " ")).join("/");
11
+ async function DruxtSiteStorybook({ options, stories }) {
12
+ const { addTemplate } = this;
13
+ const druxt$1 = new druxt.DruxtClient(options.baseUrl, { ...options, proxy: { api: false } });
14
+ const type = "block--block";
15
+ const query = new drupalJsonapiParams.DrupalJsonApiParams().addFields(type, ["theme"]);
16
+ const resources = (await druxt$1.getCollectionAll(type, query)).map((collection) => collection.data).flat();
17
+ const themes = [...new Set(resources.map((o) => o.attributes.theme))].sort();
18
+ const siteStories = themes.map((theme) => {
19
+ addTemplate({
20
+ src: path.resolve(__dirname, "../templates/druxt-site.stories.js"),
21
+ fileName: `stories/druxt-site.${theme}.stories.js`,
22
+ options: {
23
+ theme,
24
+ title: titleFn(["Druxt", "Site", "Themes", theme])
25
+ }
26
+ });
27
+ return path.resolve(this.options.buildDir, `./stories/druxt-site.${theme}.stories.js`);
28
+ });
29
+ stories.push.apply(stories, siteStories);
30
+ }
31
+
32
+ const DruxtSiteNuxtModule = async function(moduleOptions = {}) {
33
+ const options = {
34
+ baseUrl: moduleOptions.baseUrl,
35
+ ...(this.options || {}).druxt || {},
36
+ menu: {
37
+ jsonApiMenuItems: true,
38
+ ...((this.options || {}).druxt || {}).menu
39
+ },
40
+ proxy: {
41
+ api: false,
42
+ files: true,
43
+ ...((this.options || {}).druxt || {}).proxy
44
+ },
45
+ site: {
46
+ layout: true,
47
+ ...((this.options || {}).druxt || {}).site,
48
+ ...moduleOptions
49
+ }
50
+ };
51
+ this.options.druxt = options;
11
52
  this.nuxt.hook("components:dirs", (dirs) => {
12
53
  dirs.push({ path: path.join(__dirname, "components") });
13
54
  });
14
- const modules = [
15
- "@nuxtjs/proxy",
55
+ const druxtModules = [
16
56
  "druxt",
17
57
  "druxt-blocks",
18
58
  "druxt-breadcrumb",
19
59
  "druxt-entity",
20
60
  "druxt-menu",
21
- "druxt-router",
61
+ "druxt-router/nuxt",
22
62
  "druxt-schema",
23
63
  "druxt-views"
24
64
  ];
25
- for (const key in modules) {
26
- this.addModule(modules[key]);
65
+ for (const module of druxtModules) {
66
+ this.addModule(module);
27
67
  }
28
- if (typeof this.options.proxy === "undefined") {
29
- this.options.proxy = [this.options.druxt.baseUrl + "/sites/default/files"];
68
+ if (!await fs.existsSync(path.resolve(this.options.srcDir, this.options.dir.layouts)) && options.site.layout) {
69
+ this.addLayout(path.resolve(__dirname, "./layouts/default.vue"), "default");
30
70
  }
31
- if (typeof ((this.options.druxt || {}).menu || {}).jsonApiMenuItems === "undefined") {
32
- this.options.druxt.menu = {
33
- ...this.options.druxt.menu,
34
- ...{ jsonApiMenuItems: true }
35
- };
36
- }
37
- this.options.store = true;
71
+ this.nuxt.hook("storybook:config", async ({ stories }) => {
72
+ stories.push("druxt-site/dist/components/*.stories.mjs");
73
+ await DruxtSiteStorybook.call(this, { options, stories });
74
+ });
38
75
  };
39
76
  DruxtSiteNuxtModule.meta = require("../package.json");
40
77
 
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <DruxtSite />
3
+ </template>
package/package.json CHANGED
@@ -1,36 +1,56 @@
1
1
  {
2
2
  "name": "druxt-site",
3
- "version": "0.8.0",
3
+ "version": "0.10.1",
4
4
  "description": "Out of the box Decoupled Drupal sites with Druxt.",
5
5
  "keywords": [
6
+ "cms",
7
+ "decoupled",
6
8
  "drupal",
7
9
  "druxt",
10
+ "druxtjs",
11
+ "headless",
8
12
  "jsonapi",
9
- "nuxt"
13
+ "json:api",
14
+ "nuxt",
15
+ "nuxtjs",
16
+ "module",
17
+ "storybook",
18
+ "site",
19
+ "vue"
10
20
  ],
21
+ "homepage": "https://druxtjs.org",
22
+ "bugs": {
23
+ "url": "https://github.com/druxt/druxt.js/issues"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/druxt/druxt.js"
28
+ },
29
+ "license": "MIT",
11
30
  "exports": {
12
31
  ".": {
13
32
  "require": "./dist/druxt-site.ssr.js",
14
33
  "import": "./dist/druxt-site.esm.js"
15
34
  },
16
- "./components/*": "./dist/components/*"
35
+ "./components/*": "./dist/components/*",
36
+ "./layouts/*": "./dist/layouts/*"
17
37
  },
18
38
  "main": "dist/druxt-site.ssr.js",
19
39
  "module": "dist/druxt-site.esm.js",
20
40
  "files": [
21
41
  "dist",
22
- "nuxt"
42
+ "templates"
23
43
  ],
24
44
  "dependencies": {
25
- "@nuxtjs/proxy": "^2.1.0",
26
- "druxt": "^0.10.0",
27
- "druxt-blocks": "^0.12.0",
28
- "druxt-breadcrumb": "^0.11.0",
29
- "druxt-entity": "^0.18.0",
30
- "druxt-menu": "^0.13.0",
31
- "druxt-router": "^0.20.0",
32
- "druxt-schema": "^0.7.10",
33
- "druxt-views": "^0.13.0",
45
+ "drupal-jsonapi-params": "^1.2.2",
46
+ "druxt": "^0.13.0",
47
+ "druxt-blocks": "^0.14.1",
48
+ "druxt-breadcrumb": "^0.13.1",
49
+ "druxt-entity": "^0.21.2",
50
+ "druxt-menu": "^0.15.0",
51
+ "druxt-router": "^0.24.0",
52
+ "druxt-schema": "^0.9.0",
53
+ "druxt-views": "^0.16.1",
34
54
  "md5": "^2.2.1"
35
55
  },
36
56
  "optionalDependencies": {
@@ -0,0 +1,33 @@
1
+ import DruxtSite from 'druxt-site/dist/components/DruxtSite.vue'
2
+
3
+ export default {
4
+ title: '<%= options.title %>',
5
+ component: DruxtSite,
6
+ parameters: {
7
+ docs: {
8
+ description: {
9
+ component: ' '
10
+ },
11
+ },
12
+ },
13
+ }
14
+
15
+ const Template = (args, { argTypes }) => {
16
+ return {
17
+ props: Object.keys(argTypes),
18
+ template: '<DruxtSite v-bind="$props" />',
19
+ }
20
+ }
21
+
22
+ export const Default = Template.bind({})
23
+ Default.args = {
24
+ theme: '<%= options.theme %>',
25
+ }
26
+ Default.storyName = '<%= options.theme.charAt(0).toUpperCase() + options.theme.slice(1) %>'
27
+ Default.parameters = {
28
+ docs: {
29
+ source: {
30
+ code: '<DruxtSite theme="<%= options.theme %>" />'
31
+ }
32
+ }
33
+ }