druxt-entity 0.21.4 → 0.24.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.
@@ -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.4",
3
+ "version": "0.24.1",
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.15.0",
50
- "druxt-router": "^0.24.2",
51
- "druxt-schema": "^0.9.2"
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.replace(/\'/g, "\\'")} (${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.replace(/\'/g, "\\'")} (${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,402 +0,0 @@
1
- # druxt-entity
2
-
3
- ## 0.21.4
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [2ae1d6d]
8
- - druxt@0.15.0
9
- - druxt-router@0.24.2
10
- - druxt-schema@0.9.2
11
-
12
- ## 0.21.3
13
-
14
- ### Patch Changes
15
-
16
- - Updated dependencies [45bc0b9]
17
- - druxt@0.14.0
18
- - druxt-router@0.24.1
19
- - druxt-schema@0.9.1
20
-
21
- ## 0.21.2
22
-
23
- ### Patch Changes
24
-
25
- - Updated dependencies [9161b38]
26
- - druxt-router@0.24.0
27
-
28
- ## 0.21.1
29
-
30
- ### Patch Changes
31
-
32
- - 6ade3a2: Fixed Vuex mutation error
33
-
34
- ## 0.21.0
35
-
36
- ### Minor Changes
37
-
38
- - 025315a: Added **include** option and the ability to filter related resources.
39
-
40
- ```js
41
- export default {
42
- druxt: {
43
- query: {
44
- include: ["field_media_image", "field_media_image.field_media_image"],
45
- fields: [
46
- ["file--file", ["uri"]],
47
- ["media--image", []]
48
- ]
49
- }
50
- }
51
- };
52
- ```
53
-
54
- - 025315a: Added **settings** property to the DruxtEntity and DruxtEntityForm components.
55
-
56
- ```vue
57
- <template>
58
- <DruxtEntity
59
- :settings="{ query: { include: ['uid'] } }"
60
- type="node--page"
61
- :uuid="uuid"
62
- />
63
- </template>
64
- ```
65
-
66
- - e7b1533: Refactored DruxtModule fetch hooks
67
-
68
- ### Patch Changes
69
-
70
- - Updated dependencies [77ab204]
71
- - druxt-schema@0.9.0
72
- - druxt@0.13.0
73
- - druxt-router@0.23.0
74
-
75
- ## 0.20.0
76
-
77
- ### Minor Changes
78
-
79
- - 897dcbc: Updated DruxtEntityForm to use new DruxtClient methods
80
-
81
- ### Patch Changes
82
-
83
- - Updated dependencies [4504a2f]
84
- - druxt@0.12.0
85
- - druxt-router@0.22.0
86
- - druxt-schema@0.8.1
87
-
88
- ## 0.19.0
89
-
90
- ### Minor Changes
91
-
92
- - dae345e: Added module level options
93
- - 8d28c18: Updated storybook integration
94
- - dae345e: Moved `$druxtEntity` plugin settings to `$druxt.settings.entity`
95
-
96
- ### Patch Changes
97
-
98
- - Updated dependencies [9d905e8]
99
- - druxt-router@0.21.0
100
- - druxt-schema@0.8.0
101
- - druxt@0.11.0
102
-
103
- ## 0.18.0
104
-
105
- ### Minor Changes
106
-
107
- - 715e5ef: Updated component registration method to use the Nuxt `components:dirs` hook
108
- - 2b8c3f3: Updated to use DruxtDebug component
109
-
110
- ### Patch Changes
111
-
112
- - 49454cb: Fixed path to components in Storybook
113
- - Updated dependencies [1ab762c]
114
- - druxt-router@0.20.0
115
- - druxt@0.10.0
116
- - druxt-schema@0.7.10
117
-
118
- ## 0.17.1
119
-
120
- ### Patch Changes
121
-
122
- - c4616df: Fixed dependencies
123
- - Updated dependencies [c4616df]
124
- - druxt-router@0.19.1
125
- - druxt-schema@0.7.9
126
-
127
- ## 0.17.0
128
-
129
- ### Minor Changes
130
-
131
- - 21170fb: Moved Vue components out of bundle
132
-
133
- ⚠ Potential breaking change
134
-
135
- _**Note:** This only effects custom Druxt modules and implementations._
136
-
137
- ```diff
138
- -import { DruxtEntity } from 'druxt-entity'
139
- +import DruxtEntity from 'druxt-entity/dist/components/DruxtEntity.vue'
140
- ```
141
-
142
- ### Patch Changes
143
-
144
- - Updated dependencies [21170fb]
145
- - druxt@0.9.0
146
- - druxt-router@0.19.0
147
- - druxt-schema@0.7.8
148
-
149
- ## 0.16.0
150
-
151
- ### Minor Changes
152
-
153
- - Added support for default template injection
154
-
155
- - For details, see the [Druxt 0.8.0 release notes](/api/packages/druxt/CHANGELOG#080)
156
-
157
- - Added support for schema-less entities
158
- - Added improved defaults to the DruxtField component
159
- - Deprecated DruxtField default field components
160
-
161
- The components can be tree shaken with the following setting in `nuxt.config.js`:
162
-
163
- ```js
164
- module.exports = {
165
- druxt: {
166
- entity: {
167
- components: {
168
- fields: false
169
- }
170
- }
171
- }
172
- };
173
- ```
174
-
175
- ## 0.15.0
176
-
177
- ### Minor Changes
178
-
179
- - Fixed issue with EntityReferenceLabel component
180
- - Added watch to update DeruxtEntity data on props change
181
- - Updated components v-model support
182
- - Updated Storybook integration
183
- - Updated dependencies
184
-
185
- ## 0.14.2
186
-
187
- ### Patch Changes
188
-
189
- - Updated fetchKey
190
-
191
- ## 0.14.1
192
-
193
- ### Patch Changes
194
-
195
- - Added custom fetchKey to fix hydration issues
196
-
197
- ## 0.14.0
198
-
199
- ### Minor Changes
200
-
201
- - Added v-model support for DruxtEntity/DruxtEntityForm components
202
-
203
- ```vue
204
- <template>
205
- <DruxtEntity v-model="entity" />
206
- <DruxtEntityForm v-model="entity" />
207
- </template>
208
- ```
209
-
210
- ## 0.13.0
211
-
212
- ### Minor Changes
213
-
214
- - Added DruxtEntityForm component
215
-
216
- ```vue
217
- <DruxtEntityForm type="node--page" @submit="onSubmit" @error="onError" />
218
- ```
219
-
220
- - For more details, refer to the [DruxtEntityForm API documentation](/api/packages/entity/components/DruxtEntityForm)
221
-
222
- ## 0.12.0
223
-
224
- ### Minor Changes
225
-
226
- - Added ability to filter JSON:API fields
227
- - Updated Storybook integration
228
-
229
- ## 0.11.2
230
-
231
- ### Patch Changes
232
-
233
- - Fixed issue with Storybook intergration
234
- - Updated Storybook integration
235
-
236
- ## 0.11.1
237
-
238
- ### Patch Changes
239
-
240
- - Fixed issue with Storybook intergration
241
-
242
- ## 0.11.0
243
-
244
- ### Minor Changes
245
-
246
- - Added DruxtEntity Storybook integration
247
- - Updated dependencies
248
-
249
- ## 0.10.1
250
-
251
- ### Patch Changes
252
-
253
- - Added TextSummaryOrTrimmed field
254
- - Added TextTrimmed field
255
- - Updated dependencies
256
-
257
- ## 0.10.0
258
-
259
- ### Minor Changes
260
-
261
- - Refactored module to use DruxtClient/DruxtStore
262
-
263
- ## 0.9.0
264
-
265
- ### Minor Changes
266
-
267
- - Added support for Entity reference view mode
268
- - Add ability to passthrough \$attrs
269
-
270
- ## 0.8.1
271
-
272
- ### Patch Changes
273
-
274
- - Updated dependencies
275
-
276
- ## 0.8.0
277
-
278
- ### Minor Changes
279
-
280
- - Added DruxtRouter Entity component
281
- - Updated dependencies
282
-
283
- ## 0.7.2
284
-
285
- ### Patch Changes
286
-
287
- - Updated dependencies
288
-
289
- ## 0.7.1
290
-
291
- ### Patch Changes
292
-
293
- - Updated DruxtEntity for DruxtComponentMixin
294
- - Updatd Field component mixins
295
- - Updated dependencies
296
-
297
- ## 0.7.0
298
-
299
- ### Minor Changes
300
-
301
- - Updated DruxtEntity for DruxtComponentMixin
302
-
303
- ## 0.6.3
304
-
305
- ### Patch Changes
306
-
307
- - Fixed issue with images and HMR
308
-
309
- ## 0.6.2
310
-
311
- ### Patch Changes
312
-
313
- - Fixed issue with `internal:` links
314
- - Updated dependencies
315
-
316
- ## 0.6.1
317
-
318
- ### Patch Changes
319
-
320
- - Updated dependencies
321
-
322
- ## 0.6.0
323
-
324
- ### Minor Changes
325
-
326
- - Refactored to use Nuxt fetch hook
327
-
328
- ## 0.5.2
329
-
330
- ### Patch Changes
331
-
332
- - Updated documentation
333
-
334
- ## 0.5.1
335
-
336
- ### Patch Changes
337
-
338
- - Added support for UUIDs in component suggestions
339
-
340
- ## 0.5.0
341
-
342
- ### Minor Changes
343
-
344
- - Added isEmpty method
345
- - Added FileDefault and Image fields
346
- - Added mode to EntityReferenceEntityView field
347
- - Added component suggestion system
348
- - Added context mixin
349
-
350
- ## 0.4.0
351
-
352
- ### Minor Changes
353
-
354
- - Update Field and label system
355
- - Updated Entity suggestions
356
-
357
- ## 0.3.1
358
-
359
- ### Patch Changes
360
-
361
- - Added named slots for fields
362
-
363
- ## 0.3.0
364
-
365
- ### Minor Changes
366
-
367
- - Added view mode suggestions
368
- - Added field id suggestions
369
-
370
- ## 0.2.2
371
-
372
- ### Patch Changes
373
-
374
- - Fixed issues with EntityReferenceLabel field
375
- - Updated NuberInteger field
376
-
377
- ## 0.2.1
378
-
379
- ### Patch Changes
380
-
381
- - Added BasicString field
382
- - Added Timestamp field
383
- - Fixed issue with ReferenceLabel field
384
- - Fixed empty field filter
385
-
386
- ## 0.2.0
387
-
388
- ### Minor Changes
389
-
390
- - Added better multivalue field support
391
- - Added ResponsiveImage field
392
- - Added EntityReferenceEntityView field
393
- - Added NumberInteger field
394
- - Added EntityReferenceRevisionsEntityView field
395
- - Added ListDefault field
396
- - Added Link field
397
- - Added DatetimeDefault field
398
- - Updated dependencies
399
-
400
- ## 0.1.0
401
-
402
- ### 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'