druxt-entity 0.21.3 → 0.24.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.
@@ -7,10 +7,10 @@ import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
7
7
  import { mapActions } from 'vuex'
8
8
 
9
9
  /**
10
- * Renders a Drupal Content Entity by JSON:API resource type, UUID, view
11
- * mode and schema type.
10
+ * The DruxtEntity component renders a Drupal Content Entity by JSON:API
11
+ * resource type, UUID, view mode and schema type.
12
12
  *
13
- * Fields are rendered as Druxt Field components, based on the Drupal display
13
+ * Fields are rendered as DruxtField components, based on the Drupal display
14
14
  * mode configuration.
15
15
  *
16
16
  * @example @lang vue
@@ -19,6 +19,25 @@ import { mapActions } from 'vuex'
19
19
  * :uuid="uuid"
20
20
  * mode="teaser"
21
21
  * />
22
+ *
23
+ * @example <caption>DruxtEntity Wrapper component boilerplate</caption> @lang vue
24
+ * <template>
25
+ * <DruxtDebug :json="entity" />
26
+ * </template>
27
+ *
28
+ * <script>
29
+ * import { DruxtEntityMixin } from 'druxt-entity'
30
+ * export default {
31
+ * mixins: [DruxtEntityMixin]
32
+ * }
33
+ *
34
+ * @example <caption>DruxtEntity with template injection</caption> @lang vue
35
+ * <DruxtEntity type="" uuid="">
36
+ * <template #default="{ entity }">
37
+ * <!-- Do whatever you want here -->
38
+ * <DruxtDebug :json="entity" />
39
+ * </template>
40
+ * </DruxtEntity>
22
41
  */
23
42
  export default {
24
43
  name: 'DruxtEntity',
@@ -120,7 +139,7 @@ export default {
120
139
  if (!schema) return false
121
140
 
122
141
  const fields = {}
123
- for (const field of schema.fields) {
142
+ for (const field of schema.fields || []) {
124
143
  const relationship = !!((field.settings || {}).storage || {}).target_type || !!(model.relationships || {})[field.id]
125
144
  const value = relationship ? ((model || {}).relationships || {})[field.id] : ((model || {}).attributes || {})[field.id]
126
145
 
@@ -249,12 +268,28 @@ export default {
249
268
  * @returns {ComponentOptions}
250
269
  */
251
270
  componentOptions: ({ mode, schema, schemaType, type }) => ([
252
- [(schema || {}).resourceType || type, ((schema || {}).config || {}).mode || mode, ((schema || {}).config || {}).schemaType || schemaType || 'view'],
253
- [((schema || {}).config || {}).mode || mode],
271
+ // DruxtEntity[ResourceType][ViewMode][SchemaType]
272
+ [
273
+ (schema || {}).resourceType || type,
274
+ ((schema || {}).config || {}).mode || mode,
275
+ ((schema || {}).config || {}).schemaType || schemaType || 'view'
276
+ ],
277
+
278
+ // DruxtEntity[EntityType][ViewMode][SchemaType]
279
+ [
280
+ (((schema || {}).resourceType || type) || '').split('--').shift(),
281
+ ((schema || {}).config || {}).mode || mode,
282
+ ((schema || {}).config || {}).schemaType || schemaType || 'view'
283
+ ],
284
+
285
+ // DruxtEntity[ViewMode]
286
+ [
287
+ ((schema || {}).config || {}).mode || mode,
288
+ ],
254
289
  ]),
255
290
 
256
291
  /**
257
- * Fetch Schema.
292
+ * Fetches the Druxt schema object.
258
293
  */
259
294
  async fetchConfig() {
260
295
  try {
@@ -269,9 +304,15 @@ export default {
269
304
  },
270
305
 
271
306
  /**
272
- * Fetch Entity resource.
307
+ * Fetches the content entity JSON:API resource.
273
308
  */
274
309
  async fetchData(settings) {
310
+ if (!this.type) return
311
+
312
+ if ((this.schemaType || 'view') === 'view' && !this.uuid && !this.value) {
313
+ throw new Error('Missing required props: uuid.')
314
+ }
315
+
275
316
  if (this.uuid && !this.value) {
276
317
  const query = this.getQuery(settings)
277
318
  const resource = await this.getResource({ type: this.type, id: this.uuid, query })
@@ -369,17 +410,23 @@ export default {
369
410
  * @example @lang js
370
411
  * [
371
412
  * 'DruxtEntity[ResourceType][DisplayMode][SchemaType]',
413
+ * 'DruxtEntity[EntityType][DisplayMode][SchemaType]',
372
414
  * 'DruxtEntity[ResourceType][DisplayMode]',
415
+ * 'DruxtEntity[EntityType][DisplayMode]',
373
416
  * 'DruxtEntity[ResourceType]',
417
+ * 'DruxtEntity[EntityType]',
374
418
  * 'DruxtEntity[DisplayMode]',
375
419
  * ]
376
420
  *
377
421
  * @example <caption>Article Node (default)</caption> @lang js
378
422
  * [
379
423
  * 'DruxtEntityNodeArticleDefaultView',
424
+ * 'DruxtEntityNodeDefaultView',
380
425
  * 'DruxtEntityNodeArticleDefault',
381
- * 'DruxtEntityNodeArticle',
382
426
  * 'DruxtEntityNodeDefault',
427
+ * 'DruxtEntityNodeArticle',
428
+ * 'DruxtEntityNode',
429
+ * 'DruxtEntityDefault',
383
430
  * ]
384
431
  */
385
432
 
@@ -3,18 +3,41 @@
3
3
  import { default as DruxtEntity } from './DruxtEntity.vue'
4
4
 
5
5
  /**
6
- * Renders a Drupal Content Entity form with submission and validation support.
6
+ * The DruxtEntityForm component renders a Drupal Content Entity edit form by
7
+ * JSON:API resource type, UUID, view mode and schema type.
8
+ *
9
+ * Fields are rendered as DruxtField components, based on the Drupal display
10
+ * mode configuration.
7
11
  *
8
12
  * @example @lang vue
9
13
  * <DruxtEntityForm
10
14
  * :type="resourceType"
11
15
  * :uuid="uuid"
12
- * mode="displayMode"
16
+ * :mode="displayMode"
13
17
  * v-on:error="onError()"
14
18
  * v-on:reset="onReset()"
15
19
  * v-on:submit="onSubmit()"
16
20
  * />
17
21
  *
22
+ * @example <caption>DruxtEntityForm Wrapper component boilerplate</caption> @lang vue
23
+ * <template>
24
+ * <DruxtDebug :json="entity" />
25
+ * </template>
26
+ *
27
+ * <script>
28
+ * import { DruxtEntityMixin } from 'druxt-entity'
29
+ * export default {
30
+ * mixins: [DruxtEntityMixin]
31
+ * }
32
+ *
33
+ * @example <caption>DruxtEntityForm with template injection</caption> @lang vue
34
+ * <DruxtEntityForm type="">
35
+ * <template #default="{ entity }">
36
+ * <!-- Do whatever you want here -->
37
+ * <DruxtDebug :json="entity" />
38
+ * </template>
39
+ * </DruxtEntity>
40
+ *
18
41
  * @extends DruxtEntity
19
42
  * @see {@link ./DruxtEntity|DruxtEntity}
20
43
  */
@@ -92,16 +115,15 @@ export default {
92
115
  if (this.model.id) {
93
116
  method = 'updateResource'
94
117
  }
95
- this.response = await this.$druxt[method](this.model)
96
118
 
97
- // Handle the response
98
- if (!this.response.errors) {
119
+ try {
120
+ this.response = await this.$druxt[method](this.model)
99
121
  const resource = this.response.data.data
100
122
  // Update the Vuex store.
101
123
  this.$store.commit('druxt/addResource', { resource })
102
124
  this.$emit('submit', resource)
103
- }
104
- else {
125
+ } catch (err) {
126
+ this.response = err.response.data
105
127
  this.$emit('error', this.response)
106
128
  }
107
129
 
@@ -1,5 +1,8 @@
1
1
  <template>
2
- <DruxtEntity v-bind="route.props" />
2
+ <DruxtEntity
3
+ v-bind="route.props"
4
+ mode="full"
5
+ />
3
6
  </template>
4
7
 
5
8
  <script>
@@ -34,28 +34,38 @@ async function DruxtEntityStorybook({ stories }) {
34
34
  }
35
35
  })).flat()
36
36
  ]);
37
- const entityStories = entityTypes.map(({ entity, bundles }) => bundles.map((bundle) => {
38
- return Object.entries({ view, form }).map(([type, schemas2]) => {
37
+ addTemplate({
38
+ src: resolve(__dirname, `../templates/druxt-entity.stories.js`),
39
+ fileName: `stories/druxt-entity.stories.js`,
40
+ options: { entityTypes }
41
+ });
42
+ stories.push(resolve(options.buildDir, `./stories/druxt-entity.stories.js`));
43
+ addTemplate({
44
+ src: resolve(__dirname, `../templates/druxt-entity-form.stories.js`),
45
+ fileName: `stories/druxt-entity-form.stories.js`,
46
+ options: { entityTypes }
47
+ });
48
+ stories.push(resolve(options.buildDir, `./stories/druxt-entity-form.stories.js`));
49
+ entityTypes.forEach(({ entity, bundles }) => bundles.map((bundle) => {
50
+ Object.entries({ view, form }).forEach(([type, schemas2]) => {
39
51
  const displays = Array.from(new Set(schemas2.filter((o) => o.attributes.targetEntityType === entity && o.attributes.bundle === bundle).map((o) => o.attributes.mode).sort((a) => a === "default" ? -1 : 0)));
40
- if (!displays) {
41
- return false;
52
+ if (displays) {
53
+ const resourceType = `${entity}--${bundle}`;
54
+ const component = type === "view" ? "druxt-entity" : "druxt-entity-form";
55
+ addTemplate({
56
+ src: resolve(__dirname, `../templates/${component}.instance.stories.js`),
57
+ fileName: `stories/${component}.${resourceType}.stories.js`,
58
+ options: {
59
+ displays,
60
+ entities: entities.find((o) => o.resourceType === resourceType).entities,
61
+ resourceType,
62
+ title: titleFn(["Druxt", "Entity", entity, bundle, `${type} displays`])
63
+ }
64
+ });
65
+ stories.push(resolve(options.buildDir, `./stories/${component}.${resourceType}.stories.js`));
42
66
  }
43
- const resourceType = `${entity}--${bundle}`;
44
- const component = type === "view" ? "druxt-entity" : "druxt-entity-form";
45
- addTemplate({
46
- src: resolve(__dirname, `../templates/${component}.stories.js`),
47
- fileName: `stories/${component}.${resourceType}.stories.js`,
48
- options: {
49
- displays,
50
- entities: entities.find((o) => o.resourceType === resourceType).entities,
51
- resourceType,
52
- title: titleFn(["Druxt", "Entity", entity, bundle, `${type} displays`])
53
- }
54
- });
55
- return resolve(options.buildDir, `./stories/${component}.${resourceType}.stories.js`);
56
67
  });
57
- })).flat(2);
58
- stories.push.apply(stories, entityStories);
68
+ }));
59
69
  }
60
70
 
61
71
  const DruxtEntityNuxtModule = function(moduleOptions = {}) {
@@ -85,7 +95,6 @@ const DruxtEntityNuxtModule = function(moduleOptions = {}) {
85
95
  }
86
96
  });
87
97
  this.nuxt.hook("storybook:config", async ({ stories }) => {
88
- stories.push("druxt-entity/dist/components/*.stories.mjs");
89
98
  await DruxtEntityStorybook.call(this, { stories });
90
99
  });
91
100
  };
@@ -38,28 +38,38 @@ async function DruxtEntityStorybook({ stories }) {
38
38
  }
39
39
  })).flat()
40
40
  ]);
41
- const entityStories = entityTypes.map(({ entity, bundles }) => bundles.map((bundle) => {
42
- return Object.entries({ view, form }).map(([type, schemas2]) => {
41
+ addTemplate({
42
+ src: path.resolve(__dirname, `../templates/druxt-entity.stories.js`),
43
+ fileName: `stories/druxt-entity.stories.js`,
44
+ options: { entityTypes }
45
+ });
46
+ stories.push(path.resolve(options.buildDir, `./stories/druxt-entity.stories.js`));
47
+ addTemplate({
48
+ src: path.resolve(__dirname, `../templates/druxt-entity-form.stories.js`),
49
+ fileName: `stories/druxt-entity-form.stories.js`,
50
+ options: { entityTypes }
51
+ });
52
+ stories.push(path.resolve(options.buildDir, `./stories/druxt-entity-form.stories.js`));
53
+ entityTypes.forEach(({ entity, bundles }) => bundles.map((bundle) => {
54
+ Object.entries({ view, form }).forEach(([type, schemas2]) => {
43
55
  const displays = Array.from(new Set(schemas2.filter((o) => o.attributes.targetEntityType === entity && o.attributes.bundle === bundle).map((o) => o.attributes.mode).sort((a) => a === "default" ? -1 : 0)));
44
- if (!displays) {
45
- return false;
56
+ if (displays) {
57
+ const resourceType = `${entity}--${bundle}`;
58
+ const component = type === "view" ? "druxt-entity" : "druxt-entity-form";
59
+ addTemplate({
60
+ src: path.resolve(__dirname, `../templates/${component}.instance.stories.js`),
61
+ fileName: `stories/${component}.${resourceType}.stories.js`,
62
+ options: {
63
+ displays,
64
+ entities: entities.find((o) => o.resourceType === resourceType).entities,
65
+ resourceType,
66
+ title: titleFn(["Druxt", "Entity", entity, bundle, `${type} displays`])
67
+ }
68
+ });
69
+ stories.push(path.resolve(options.buildDir, `./stories/${component}.${resourceType}.stories.js`));
46
70
  }
47
- const resourceType = `${entity}--${bundle}`;
48
- const component = type === "view" ? "druxt-entity" : "druxt-entity-form";
49
- addTemplate({
50
- src: path.resolve(__dirname, `../templates/${component}.stories.js`),
51
- fileName: `stories/${component}.${resourceType}.stories.js`,
52
- options: {
53
- displays,
54
- entities: entities.find((o) => o.resourceType === resourceType).entities,
55
- resourceType,
56
- title: titleFn(["Druxt", "Entity", entity, bundle, `${type} displays`])
57
- }
58
- });
59
- return path.resolve(options.buildDir, `./stories/${component}.${resourceType}.stories.js`);
60
71
  });
61
- })).flat(2);
62
- stories.push.apply(stories, entityStories);
72
+ }));
63
73
  }
64
74
 
65
75
  const DruxtEntityNuxtModule = function(moduleOptions = {}) {
@@ -89,7 +99,6 @@ const DruxtEntityNuxtModule = function(moduleOptions = {}) {
89
99
  }
90
100
  });
91
101
  this.nuxt.hook("storybook:config", async ({ stories }) => {
92
- stories.push("druxt-entity/dist/components/*.stories.mjs");
93
102
  await DruxtEntityStorybook.call(this, { stories });
94
103
  });
95
104
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "druxt-entity",
3
- "version": "0.21.3",
3
+ "version": "0.24.0",
4
4
  "description": "Drupal Display Mode powered Entity, Form and Field Druxt components.",
5
5
  "keywords": [
6
6
  "cms",
@@ -46,9 +46,9 @@
46
46
  "dependencies": {
47
47
  "deepmerge": "^4.2.2",
48
48
  "drupal-jsonapi-params": "^1.2.2",
49
- "druxt": "^0.14.0",
50
- "druxt-router": "^0.24.1",
51
- "druxt-schema": "^0.9.1"
49
+ "druxt": "^0.17.0",
50
+ "druxt-router": "^0.26.0",
51
+ "druxt-schema": "^0.10.1"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"
@@ -0,0 +1,86 @@
1
+ import DruxtEntityForm from 'druxt-entity/dist/components/DruxtEntityForm.vue'
2
+
3
+ export default {
4
+ title: '<%= options.title %>',
5
+ component: DruxtEntityForm,
6
+ argTypes: {
7
+ error: {
8
+ action: 'error',
9
+ },
10
+ input: {
11
+ action: 'input',
12
+ },
13
+ submit: {
14
+ action: 'submit',
15
+ },
16
+ reset: {
17
+ action: 'reset',
18
+ },
19
+ mode: {
20
+ options: [<%= (options.displays || []).map((s) => `'${s}'`).join(', ') %>],
21
+ control: {
22
+ type: 'select',
23
+ },
24
+ },
25
+ schemaType: {
26
+ table: {
27
+ disable: true
28
+ }
29
+ },
30
+ type: {
31
+ table: {
32
+ disable: true
33
+ }
34
+ },
35
+ uuid: {
36
+ options: [<%= (options.entities || []).map((o) => `'${o.id}'`).join(', ') %>],
37
+ control: {
38
+ type: 'select',
39
+ labels: Object.fromEntries([<%= (options.entities || []).map((o) => `['${o.id}', "${o.title} (${o.id})"]`).join(', ') %>])
40
+ },
41
+ },
42
+ value: {
43
+ control: {
44
+ type: 'object',
45
+ },
46
+ table: {
47
+ category: 'props',
48
+ },
49
+ },
50
+ },
51
+ parameters: {
52
+ docs: {
53
+ description: {
54
+ component: 'Renders a **<%= options.resourceType %>** content entity via the "Form" displays provided by Drupal.'
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ const Template = (args, ctx) => {
61
+ return {
62
+ props: Object.keys(args),
63
+ template: '<DruxtEntityForm v-bind="$props" v-on="$props" />',
64
+ }
65
+ }
66
+
67
+ <% for (mode of options.displays) { %>
68
+ // Display: <%= mode %>.
69
+ export const <%= mode.charAt(0).toUpperCase() + mode.slice(1) %> = Template.bind({})
70
+ <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.storyName = '<%= mode %>'
71
+ <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.args = {
72
+ mode: '<%= mode %>',
73
+ schemaType: 'form',
74
+ type: '<%= options.resourceType %>',
75
+ uuid: <%= devalue(((options.entities || [])[0] || {}).id || false) %>,
76
+ }
77
+ <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.parameters = {
78
+ docs: {
79
+ storyDescription: 'Render the content entity form using the **<%= mode %>** display mode.',
80
+ source: {
81
+ code: '<DruxtEntityForm\n mode="<%= mode %>"\n type="<%= options.resourceType %>"\n uuid=<%= devalue(((options.entities || [])[0] || {}).id || false) %>\n/>'
82
+ }
83
+ }
84
+ }
85
+
86
+ <% } %>
@@ -1,81 +1,76 @@
1
1
  import DruxtEntityForm from 'druxt-entity/dist/components/DruxtEntityForm.vue'
2
2
 
3
3
  export default {
4
- title: '<%= options.title %>',
4
+ title: 'Druxt/Entity/DruxtEntityForm',
5
5
  component: DruxtEntityForm,
6
6
  argTypes: {
7
- error: {
8
- action: 'error',
9
- },
10
- input: {
11
- action: 'input',
12
- },
13
- submit: {
14
- action: 'submit',
15
- },
16
- reset: {
17
- action: 'reset',
18
- },
19
- mode: {
7
+ type: {
8
+ options: [<%= (options.entityTypes || []).map(({ entity, bundles }) => bundles.map((bundle) => `'${entity}--${bundle}'`)).join(', ') %>],
20
9
  control: {
21
- type: 'select',
22
- options: [<%= (options.displays || []).map((s) => `'${s}'`).join(', ') %>],
23
- },
10
+ type: 'select'
11
+ }
24
12
  },
25
13
  schemaType: {
26
- control: {
27
- type: 'select',
28
- options: ['view', 'form'],
29
- },
30
- },
31
- type: {},
32
- uuid: {
33
- control: {
34
- type: 'select',
35
- options: [<%= (options.entities || []).map((o) => `'${o.id}'`).join(', ') %>],
36
- },
37
- },
38
- value: {
39
- control: {
40
- type: 'object',
41
- },
42
14
  table: {
43
- category: 'props',
44
- },
45
- },
46
- },
47
- parameters: {
48
- docs: {
49
- description: {
50
- component: 'The DruxtEntityForm component renders Drupal content entities via the "Form" displays provided by Drupal.'
15
+ disable: true
51
16
  }
52
17
  }
53
18
  }
54
19
  }
55
20
 
56
- const Template = (args, ctx) => {
57
- return {
58
- props: Object.keys(args),
59
- template: '<DruxtEntityForm v-bind="$props" v-on="$props" />',
60
- }
61
- }
21
+ export const Default = (args, { argTypes }) => ({
22
+ components: { DruxtEntityForm },
23
+ props: Object.keys(argTypes),
24
+ template: `<DruxtEntityForm v-bind="$props" />`
25
+ })
26
+
27
+ let code
28
+
29
+ // Wrapper story.
30
+ code = `<template>
31
+ <DruxtDebug :json="entity" />
32
+ </template>
62
33
 
63
- <% for (mode of options.displays) { %>
64
- // Display: <%= mode %>.
65
- export const <%= mode.charAt(0).toUpperCase() + mode.slice(1) %> = Template.bind({})
66
- <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.storyName = '<%= mode %>'
67
- <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.args = {
68
- mode: '<%= mode %>',
69
- schemaType: 'form',
70
- type: '<%= options.resourceType %>',
71
- uuid: <%= devalue(((options.entities || [])[0] || {}).id || false) %>,
34
+ <script>
35
+ import { DruxtEntityMixin } from 'druxt-entity'
36
+ export default {
37
+ mixins: [DruxtEntityMixin]
72
38
  }
73
- <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.parameters = {
39
+ </script>`
40
+ export const Wrapper = (args, { argTypes }) => ({
41
+ components: { DruxtEntityForm },
42
+ props: Object.keys(argTypes),
43
+ template: `<DruxtEntityForm v-bind="$props" ref="module">
44
+ <template #default>
45
+ Component options:
46
+ <ul>
47
+ <li v-for="option of $refs.module.getModuleComponents()" :key="option.name">{{ option.name }}</li>
48
+ </ul>
49
+ </template>
50
+ </DruxtEntityForm>`
51
+ })
52
+ Wrapper.parameters = {
74
53
  docs: {
75
- source: {
76
- code: '<DruxtEntityForm\n mode="<%= mode %>"\n type="<%= options.resourceType %>"\n uuid=<%= devalue(((options.entities || [])[0] || {}).id || false) %>\n/>'
77
- }
54
+ storyDescription: 'The DruxtEntityForm 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```',
55
+ source: { code }
78
56
  }
79
57
  }
80
58
 
81
- <% } %>
59
+ // Template injection story.
60
+ code = `<DruxtEntityForm type="" uuid="">
61
+ <template #default="{ entity }">
62
+ <!-- Do whatever you want here -->
63
+ <DruxtDebug :json="entity" open />
64
+ </template>
65
+ </DruxtEntityForm>`
66
+ export const TemplateInjection = (args, { argTypes }) => ({
67
+ components: { DruxtEntityForm },
68
+ props: Object.keys(argTypes),
69
+ template: code.replace('type="" uuid=""', 'v-bind="$props"')
70
+ })
71
+ TemplateInjection.parameters = {
72
+ docs: {
73
+ storyDescription: 'The DruxtEntityForm component can be themed by injecting the default template into the compomnent.\n\n```jsx\n' + code + '\n```',
74
+ source: { code }
75
+ }
76
+ }
@@ -0,0 +1,85 @@
1
+ import DruxtEntity from 'druxt-entity/dist/components/DruxtEntity.vue'
2
+
3
+ export default {
4
+ title: '<%= options.title %>',
5
+ component: DruxtEntity,
6
+ argTypes: {
7
+ input: {
8
+ action: 'input',
9
+ },
10
+ mode: {
11
+ options: [<%= (options.displays || []).map((s) => `'${s}'`).join(', ') %>],
12
+ control: {
13
+ type: 'select',
14
+ },
15
+ },
16
+ settings: {
17
+ control: {
18
+ type: 'object',
19
+ },
20
+ },
21
+ schemaType: {
22
+ table: {
23
+ disable: true,
24
+ }
25
+ },
26
+ type: {
27
+ table: {
28
+ disable: true,
29
+ }
30
+ },
31
+ uuid: {
32
+ options: [<%= (options.entities || []).map((o) => `'${o.id}'`).join(', ') %>],
33
+ control: {
34
+ type: 'select',
35
+ labels: Object.fromEntries([<%= (options.entities || []).map((o) => `['${o.id}', "${o.title} (${o.id})"]`).join(', ') %>])
36
+ },
37
+ type: {
38
+ required: true,
39
+ },
40
+ },
41
+ value: {
42
+ control: {
43
+ type: 'object',
44
+ },
45
+ table: {
46
+ category: 'props',
47
+ },
48
+ },
49
+ },
50
+ parameters: {
51
+ docs: {
52
+ description: {
53
+ component: 'Renders a **<%= options.resourceType %>** content entity via the "View" displays provided by Drupal.'
54
+ },
55
+ },
56
+ },
57
+ }
58
+
59
+ const Template = (args) => {
60
+ return {
61
+ props: Object.keys(args),
62
+ template: '<DruxtEntity v-bind="$props" v-on="$props" />',
63
+ }
64
+ }
65
+
66
+ <% for (mode of options.displays) { %>
67
+ // Display: <%= mode %>.
68
+ export const <%= mode.charAt(0).toUpperCase() + mode.slice(1) %> = Template.bind({})
69
+ <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.storyName = '<%= mode %>'
70
+ <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.args = {
71
+ mode: '<%= mode %>',
72
+ schemaType: 'view',
73
+ type: '<%= options.resourceType %>',
74
+ uuid: <%= devalue(((options.entities || [])[0] || {}).id || false) %>,
75
+ }
76
+ <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.parameters = {
77
+ docs: {
78
+ storyDescription: 'Render the content entity using the **<%= mode %>** display mode.',
79
+ source: {
80
+ code: '<DruxtEntity\n mode="<%= mode %>"\n type="<%= options.resourceType %>"\n uuid=<%= devalue(((options.entities || [])[0] || {}).id || false) %>\n/>'
81
+ }
82
+ }
83
+ }
84
+
85
+ <% } %>
@@ -1,72 +1,77 @@
1
1
  import DruxtEntity from 'druxt-entity/dist/components/DruxtEntity.vue'
2
2
 
3
3
  export default {
4
- title: '<%= options.title %>',
4
+ title: 'Druxt/Entity/DruxtEntity',
5
5
  component: DruxtEntity,
6
6
  argTypes: {
7
- input: {
8
- action: 'input',
9
- },
10
- mode: {
7
+ type: {
8
+ options: [<%= (options.entityTypes || []).map(({ entity, bundles }) => bundles.map((bundle) => `'${entity}--${bundle}'`)).join(', ') %>],
11
9
  control: {
12
- type: 'select',
13
- options: [<%= (options.displays || []).map((s) => `'${s}'`).join(', ') %>],
14
- },
10
+ type: 'select'
11
+ }
15
12
  },
16
13
  schemaType: {
14
+ options: ['view', 'form'],
17
15
  control: {
18
- type: 'select',
19
- options: ['view', 'form'],
20
- },
21
- },
22
- type: {},
23
- uuid: {
24
- control: {
25
- type: 'select',
26
- options: [<%= (options.entities || []).map((o) => `'${o.id}'`).join(', ') %>],
27
- },
28
- },
29
- value: {
30
- control: {
31
- type: 'object',
32
- },
33
- table: {
34
- category: 'props',
35
- },
36
- },
37
- },
38
- parameters: {
39
- docs: {
40
- description: {
41
- component: 'The DruxtEntity component renders Drupal content entities via the "View" displays provided by Drupal.'
42
- },
43
- },
44
- },
45
- }
46
-
47
- const Template = (args, { argTypes }) => {
48
- return {
49
- props: Object.keys(argTypes),
50
- template: '<DruxtEntity v-bind="$props" v-on="$props" />',
16
+ type: 'select'
17
+ }
18
+ }
51
19
  }
52
20
  }
53
21
 
54
- <% for (mode of options.displays) { %>
55
- // Display: <%= mode %>.
56
- export const <%= mode.charAt(0).toUpperCase() + mode.slice(1) %> = Template.bind({})
57
- <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.storyName = '<%= mode %>'
58
- <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.args = {
59
- mode: '<%= mode %>',
60
- schemaType: 'view',
61
- type: '<%= options.resourceType %>',
62
- uuid: <%= devalue(((options.entities || [])[0] || {}).id || false) %>,
22
+ export const Default = (args, { argTypes }) => ({
23
+ components: { DruxtEntity },
24
+ props: Object.keys(argTypes),
25
+ template: `<DruxtEntity v-bind="$props" />`
26
+ })
27
+
28
+ let code
29
+
30
+ // Wrapper story.
31
+ code = `<template>
32
+ <DruxtDebug :json="entity" />
33
+ </template>
34
+
35
+ <script>
36
+ import { DruxtEntityMixin } from 'druxt-entity'
37
+ export default {
38
+ mixins: [DruxtEntityMixin]
63
39
  }
64
- <%= mode.charAt(0).toUpperCase() + mode.slice(1) %>.parameters = {
40
+ </script>`
41
+ export const Wrapper = (args, { argTypes }) => ({
42
+ components: { DruxtEntity },
43
+ props: Object.keys(argTypes),
44
+ template: `<DruxtEntity v-bind="$props" ref="module">
45
+ <template #default>
46
+ Component options:
47
+ <ul>
48
+ <li v-for="option of $refs.module.getModuleComponents()" :key="option.name">{{ option.name }}</li>
49
+ </ul>
50
+ </template>
51
+ </DruxtEntity>`
52
+ })
53
+ Wrapper.parameters = {
65
54
  docs: {
66
- source: {
67
- code: '<DruxtEntity\n mode="<%= mode %>"\n type="<%= options.resourceType %>"\n uuid=<%= devalue(((options.entities || [])[0] || {}).id || false) %>\n/>'
68
- }
55
+ storyDescription: 'The DruxtEntity 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```',
56
+ source: { code }
69
57
  }
70
58
  }
71
59
 
72
- <% } %>
60
+ // Template injection story.
61
+ code = `<DruxtEntity type="" uuid="">
62
+ <template #default="{ entity }">
63
+ <!-- Do whatever you want here -->
64
+ <DruxtDebug :json="entity" open />
65
+ </template>
66
+ </DruxtEntity>`
67
+ export const TemplateInjection = (args, { argTypes }) => ({
68
+ components: { DruxtEntity },
69
+ props: Object.keys(argTypes),
70
+ template: code.replace('type="" uuid=""', 'v-bind="$props"')
71
+ })
72
+ TemplateInjection.parameters = {
73
+ docs: {
74
+ storyDescription: 'The DruxtEntity component can be themed by injecting the default template into the compomnent.\n\n```jsx\n' + code + '\n```',
75
+ source: { code }
76
+ }
77
+ }
package/CHANGELOG.md DELETED
@@ -1,393 +0,0 @@
1
- # druxt-entity
2
-
3
- ## 0.21.3
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [45bc0b9]
8
- - druxt@0.14.0
9
- - druxt-router@0.24.1
10
- - druxt-schema@0.9.1
11
-
12
- ## 0.21.2
13
-
14
- ### Patch Changes
15
-
16
- - Updated dependencies [9161b38]
17
- - druxt-router@0.24.0
18
-
19
- ## 0.21.1
20
-
21
- ### Patch Changes
22
-
23
- - 6ade3a2: Fixed Vuex mutation error
24
-
25
- ## 0.21.0
26
-
27
- ### Minor Changes
28
-
29
- - 025315a: Added **include** option and the ability to filter related resources.
30
-
31
- ```js
32
- export default {
33
- druxt: {
34
- query: {
35
- include: ["field_media_image", "field_media_image.field_media_image"],
36
- fields: [
37
- ["file--file", ["uri"]],
38
- ["media--image", []]
39
- ]
40
- }
41
- }
42
- };
43
- ```
44
-
45
- - 025315a: Added **settings** property to the DruxtEntity and DruxtEntityForm components.
46
-
47
- ```vue
48
- <template>
49
- <DruxtEntity
50
- :settings="{ query: { include: ['uid'] } }"
51
- type="node--page"
52
- :uuid="uuid"
53
- />
54
- </template>
55
- ```
56
-
57
- - e7b1533: Refactored DruxtModule fetch hooks
58
-
59
- ### Patch Changes
60
-
61
- - Updated dependencies [77ab204]
62
- - druxt-schema@0.9.0
63
- - druxt@0.13.0
64
- - druxt-router@0.23.0
65
-
66
- ## 0.20.0
67
-
68
- ### Minor Changes
69
-
70
- - 897dcbc: Updated DruxtEntityForm to use new DruxtClient methods
71
-
72
- ### Patch Changes
73
-
74
- - Updated dependencies [4504a2f]
75
- - druxt@0.12.0
76
- - druxt-router@0.22.0
77
- - druxt-schema@0.8.1
78
-
79
- ## 0.19.0
80
-
81
- ### Minor Changes
82
-
83
- - dae345e: Added module level options
84
- - 8d28c18: Updated storybook integration
85
- - dae345e: Moved `$druxtEntity` plugin settings to `$druxt.settings.entity`
86
-
87
- ### Patch Changes
88
-
89
- - Updated dependencies [9d905e8]
90
- - druxt-router@0.21.0
91
- - druxt-schema@0.8.0
92
- - druxt@0.11.0
93
-
94
- ## 0.18.0
95
-
96
- ### Minor Changes
97
-
98
- - 715e5ef: Updated component registration method to use the Nuxt `components:dirs` hook
99
- - 2b8c3f3: Updated to use DruxtDebug component
100
-
101
- ### Patch Changes
102
-
103
- - 49454cb: Fixed path to components in Storybook
104
- - Updated dependencies [1ab762c]
105
- - druxt-router@0.20.0
106
- - druxt@0.10.0
107
- - druxt-schema@0.7.10
108
-
109
- ## 0.17.1
110
-
111
- ### Patch Changes
112
-
113
- - c4616df: Fixed dependencies
114
- - Updated dependencies [c4616df]
115
- - druxt-router@0.19.1
116
- - druxt-schema@0.7.9
117
-
118
- ## 0.17.0
119
-
120
- ### Minor Changes
121
-
122
- - 21170fb: Moved Vue components out of bundle
123
-
124
- ⚠ Potential breaking change
125
-
126
- _**Note:** This only effects custom Druxt modules and implementations._
127
-
128
- ```diff
129
- -import { DruxtEntity } from 'druxt-entity'
130
- +import DruxtEntity from 'druxt-entity/dist/components/DruxtEntity.vue'
131
- ```
132
-
133
- ### Patch Changes
134
-
135
- - Updated dependencies [21170fb]
136
- - druxt@0.9.0
137
- - druxt-router@0.19.0
138
- - druxt-schema@0.7.8
139
-
140
- ## 0.16.0
141
-
142
- ### Minor Changes
143
-
144
- - Added support for default template injection
145
-
146
- - For details, see the [Druxt 0.8.0 release notes](/api/packages/druxt/CHANGELOG#080)
147
-
148
- - Added support for schema-less entities
149
- - Added improved defaults to the DruxtField component
150
- - Deprecated DruxtField default field components
151
-
152
- The components can be tree shaken with the following setting in `nuxt.config.js`:
153
-
154
- ```js
155
- module.exports = {
156
- druxt: {
157
- entity: {
158
- components: {
159
- fields: false
160
- }
161
- }
162
- }
163
- };
164
- ```
165
-
166
- ## 0.15.0
167
-
168
- ### Minor Changes
169
-
170
- - Fixed issue with EntityReferenceLabel component
171
- - Added watch to update DeruxtEntity data on props change
172
- - Updated components v-model support
173
- - Updated Storybook integration
174
- - Updated dependencies
175
-
176
- ## 0.14.2
177
-
178
- ### Patch Changes
179
-
180
- - Updated fetchKey
181
-
182
- ## 0.14.1
183
-
184
- ### Patch Changes
185
-
186
- - Added custom fetchKey to fix hydration issues
187
-
188
- ## 0.14.0
189
-
190
- ### Minor Changes
191
-
192
- - Added v-model support for DruxtEntity/DruxtEntityForm components
193
-
194
- ```vue
195
- <template>
196
- <DruxtEntity v-model="entity" />
197
- <DruxtEntityForm v-model="entity" />
198
- </template>
199
- ```
200
-
201
- ## 0.13.0
202
-
203
- ### Minor Changes
204
-
205
- - Added DruxtEntityForm component
206
-
207
- ```vue
208
- <DruxtEntityForm type="node--page" @submit="onSubmit" @error="onError" />
209
- ```
210
-
211
- - For more details, refer to the [DruxtEntityForm API documentation](/api/packages/entity/components/DruxtEntityForm)
212
-
213
- ## 0.12.0
214
-
215
- ### Minor Changes
216
-
217
- - Added ability to filter JSON:API fields
218
- - Updated Storybook integration
219
-
220
- ## 0.11.2
221
-
222
- ### Patch Changes
223
-
224
- - Fixed issue with Storybook intergration
225
- - Updated Storybook integration
226
-
227
- ## 0.11.1
228
-
229
- ### Patch Changes
230
-
231
- - Fixed issue with Storybook intergration
232
-
233
- ## 0.11.0
234
-
235
- ### Minor Changes
236
-
237
- - Added DruxtEntity Storybook integration
238
- - Updated dependencies
239
-
240
- ## 0.10.1
241
-
242
- ### Patch Changes
243
-
244
- - Added TextSummaryOrTrimmed field
245
- - Added TextTrimmed field
246
- - Updated dependencies
247
-
248
- ## 0.10.0
249
-
250
- ### Minor Changes
251
-
252
- - Refactored module to use DruxtClient/DruxtStore
253
-
254
- ## 0.9.0
255
-
256
- ### Minor Changes
257
-
258
- - Added support for Entity reference view mode
259
- - Add ability to passthrough \$attrs
260
-
261
- ## 0.8.1
262
-
263
- ### Patch Changes
264
-
265
- - Updated dependencies
266
-
267
- ## 0.8.0
268
-
269
- ### Minor Changes
270
-
271
- - Added DruxtRouter Entity component
272
- - Updated dependencies
273
-
274
- ## 0.7.2
275
-
276
- ### Patch Changes
277
-
278
- - Updated dependencies
279
-
280
- ## 0.7.1
281
-
282
- ### Patch Changes
283
-
284
- - Updated DruxtEntity for DruxtComponentMixin
285
- - Updatd Field component mixins
286
- - Updated dependencies
287
-
288
- ## 0.7.0
289
-
290
- ### Minor Changes
291
-
292
- - Updated DruxtEntity for DruxtComponentMixin
293
-
294
- ## 0.6.3
295
-
296
- ### Patch Changes
297
-
298
- - Fixed issue with images and HMR
299
-
300
- ## 0.6.2
301
-
302
- ### Patch Changes
303
-
304
- - Fixed issue with `internal:` links
305
- - Updated dependencies
306
-
307
- ## 0.6.1
308
-
309
- ### Patch Changes
310
-
311
- - Updated dependencies
312
-
313
- ## 0.6.0
314
-
315
- ### Minor Changes
316
-
317
- - Refactored to use Nuxt fetch hook
318
-
319
- ## 0.5.2
320
-
321
- ### Patch Changes
322
-
323
- - Updated documentation
324
-
325
- ## 0.5.1
326
-
327
- ### Patch Changes
328
-
329
- - Added support for UUIDs in component suggestions
330
-
331
- ## 0.5.0
332
-
333
- ### Minor Changes
334
-
335
- - Added isEmpty method
336
- - Added FileDefault and Image fields
337
- - Added mode to EntityReferenceEntityView field
338
- - Added component suggestion system
339
- - Added context mixin
340
-
341
- ## 0.4.0
342
-
343
- ### Minor Changes
344
-
345
- - Update Field and label system
346
- - Updated Entity suggestions
347
-
348
- ## 0.3.1
349
-
350
- ### Patch Changes
351
-
352
- - Added named slots for fields
353
-
354
- ## 0.3.0
355
-
356
- ### Minor Changes
357
-
358
- - Added view mode suggestions
359
- - Added field id suggestions
360
-
361
- ## 0.2.2
362
-
363
- ### Patch Changes
364
-
365
- - Fixed issues with EntityReferenceLabel field
366
- - Updated NuberInteger field
367
-
368
- ## 0.2.1
369
-
370
- ### Patch Changes
371
-
372
- - Added BasicString field
373
- - Added Timestamp field
374
- - Fixed issue with ReferenceLabel field
375
- - Fixed empty field filter
376
-
377
- ## 0.2.0
378
-
379
- ### Minor Changes
380
-
381
- - Added better multivalue field support
382
- - Added ResponsiveImage field
383
- - Added EntityReferenceEntityView field
384
- - Added NumberInteger field
385
- - Added EntityReferenceRevisionsEntityView field
386
- - Added ListDefault field
387
- - Added Link field
388
- - Added DatetimeDefault field
389
- - Updated dependencies
390
-
391
- ## 0.1.0
392
-
393
- ### Initial release
@@ -1,15 +0,0 @@
1
- import DruxtEntity from './DruxtEntity.vue'
2
-
3
- export default {
4
- title: 'Druxt/Entity/DruxtEntity',
5
- component: DruxtEntity
6
- }
7
-
8
- const Template = (args, { argTypes }) => ({
9
- components: { DruxtEntity },
10
- props: Object.keys(argTypes),
11
- template: `<DruxtEntity v-bind="$props" />`
12
- })
13
-
14
- export const Default = Template.bind({})
15
- Default.storyName = 'DruxtEntity'
@@ -1,15 +0,0 @@
1
- import DruxtEntityForm from './DruxtEntityForm.vue'
2
-
3
- export default {
4
- title: 'Druxt/Entity/DruxtEntityForm',
5
- component: DruxtEntityForm
6
- }
7
-
8
- const Template = (args, { argTypes }) => ({
9
- components: { DruxtEntityForm },
10
- props: Object.keys(argTypes),
11
- template: `<DruxtEntityForm v-bind="$props" />`
12
- })
13
-
14
- export const Default = Template.bind({})
15
- Default.storyName = 'DruxtEntityForm'