druxt-entity 0.23.0 → 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.
- package/dist/components/DruxtEntity.vue +31 -6
- package/dist/components/DruxtEntityForm.vue +25 -2
- package/dist/druxt-entity.esm.js +29 -20
- package/dist/druxt-entity.ssr.js +29 -20
- package/package.json +4 -4
- package/templates/druxt-entity-form.instance.stories.js +86 -0
- package/templates/druxt-entity-form.stories.js +56 -61
- package/templates/druxt-entity.instance.stories.js +85 -0
- package/templates/druxt-entity.stories.js +60 -55
- package/dist/components/DruxtEntity.stories.mjs +0 -15
- package/dist/components/DruxtEntityForm.stories.mjs +0 -15
|
@@ -7,10 +7,10 @@ import DruxtModule from 'druxt/dist/components/DruxtModule.vue'
|
|
|
7
7
|
import { mapActions } from 'vuex'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
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
|
|
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',
|
|
@@ -258,7 +277,7 @@ export default {
|
|
|
258
277
|
|
|
259
278
|
// DruxtEntity[EntityType][ViewMode][SchemaType]
|
|
260
279
|
[
|
|
261
|
-
((schema || {}).resourceType || type).split('--').shift(),
|
|
280
|
+
(((schema || {}).resourceType || type) || '').split('--').shift(),
|
|
262
281
|
((schema || {}).config || {}).mode || mode,
|
|
263
282
|
((schema || {}).config || {}).schemaType || schemaType || 'view'
|
|
264
283
|
],
|
|
@@ -270,7 +289,7 @@ export default {
|
|
|
270
289
|
]),
|
|
271
290
|
|
|
272
291
|
/**
|
|
273
|
-
*
|
|
292
|
+
* Fetches the Druxt schema object.
|
|
274
293
|
*/
|
|
275
294
|
async fetchConfig() {
|
|
276
295
|
try {
|
|
@@ -285,9 +304,15 @@ export default {
|
|
|
285
304
|
},
|
|
286
305
|
|
|
287
306
|
/**
|
|
288
|
-
*
|
|
307
|
+
* Fetches the content entity JSON:API resource.
|
|
289
308
|
*/
|
|
290
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
|
+
|
|
291
316
|
if (this.uuid && !this.value) {
|
|
292
317
|
const query = this.getQuery(settings)
|
|
293
318
|
const resource = await this.getResource({ type: this.type, id: this.uuid, query })
|
|
@@ -3,18 +3,41 @@
|
|
|
3
3
|
import { default as DruxtEntity } from './DruxtEntity.vue'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
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
|
*/
|
package/dist/druxt-entity.esm.js
CHANGED
|
@@ -34,28 +34,38 @@ async function DruxtEntityStorybook({ stories }) {
|
|
|
34
34
|
}
|
|
35
35
|
})).flat()
|
|
36
36
|
]);
|
|
37
|
-
|
|
38
|
-
|
|
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 (
|
|
41
|
-
|
|
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
|
-
}))
|
|
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
|
};
|
package/dist/druxt-entity.ssr.js
CHANGED
|
@@ -38,28 +38,38 @@ async function DruxtEntityStorybook({ stories }) {
|
|
|
38
38
|
}
|
|
39
39
|
})).flat()
|
|
40
40
|
]);
|
|
41
|
-
|
|
42
|
-
|
|
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 (
|
|
45
|
-
|
|
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
|
-
}))
|
|
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.
|
|
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.
|
|
50
|
-
"druxt-router": "^0.
|
|
51
|
-
"druxt-schema": "^0.10.
|
|
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: '
|
|
4
|
+
title: 'Druxt/Entity/DruxtEntityForm',
|
|
5
5
|
component: DruxtEntityForm,
|
|
6
6
|
argTypes: {
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
export
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
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: '
|
|
4
|
+
title: 'Druxt/Entity/DruxtEntity',
|
|
5
5
|
component: DruxtEntity,
|
|
6
6
|
argTypes: {
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
14
|
-
},
|
|
10
|
+
type: 'select'
|
|
11
|
+
}
|
|
15
12
|
},
|
|
16
13
|
schemaType: {
|
|
14
|
+
options: ['view', 'form'],
|
|
17
15
|
control: {
|
|
18
|
-
type: 'select'
|
|
19
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
+
}
|
|
@@ -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'
|