@processmaker/screen-builder 3.8.45 → 3.8.47

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.
Files changed (33) hide show
  1. package/dist/vue-form-builder.css +1 -1
  2. package/dist/vue-form-builder.es.js +5729 -5040
  3. package/dist/vue-form-builder.es.js.map +1 -1
  4. package/dist/vue-form-builder.umd.js +43 -42
  5. package/dist/vue-form-builder.umd.js.map +1 -1
  6. package/package.json +3 -3
  7. package/src/DataProvider.js +2 -0
  8. package/src/ValidationsFactory.js +15 -12
  9. package/src/components/index.js +4 -0
  10. package/src/components/inspector/vueRender/EditorFieldInspector.vue +239 -0
  11. package/src/components/renderer/add-loop-row.vue +27 -1
  12. package/src/components/renderer/form-collection-record-control.vue +44 -10
  13. package/src/components/renderer/form-collection-view-control.vue +2 -0
  14. package/src/components/renderer/form-loop.vue +29 -2
  15. package/src/components/renderer/form-nested-screen.vue +17 -1
  16. package/src/components/renderer/form-record-list.vue +93 -13
  17. package/src/components/renderer/vueRender/VueRenderEditor.vue +99 -0
  18. package/src/components/renderer/vueRender/VueRenderPreview.vue +36 -0
  19. package/src/components/renderer/vueRender/VueRenderTemplate.js +245 -0
  20. package/src/components/screen-renderer.vue +5 -0
  21. package/src/components/task.vue +37 -5
  22. package/src/components/vue-form-renderer.vue +51 -8
  23. package/src/form-builder-controls.js +68 -1
  24. package/src/main.js +11 -0
  25. package/src/mixins/DeviceDetector.js +19 -3
  26. package/src/mixins/Json2Vue.js +12 -1
  27. package/src/mixins/ScreenBase.js +43 -16
  28. package/src/mixins/VisibilityRule.js +3 -3
  29. package/src/mixins/extensions/FormDynamicPanel.js +2 -2
  30. package/src/mixins/extensions/LoadFieldComponents.js +64 -39
  31. package/src/mixins/extensions/LoopContainer.js +2 -2
  32. package/src/mixins/extensions/VisibilityRule.js +8 -8
  33. package/src/stories/VueRender.stories.js +274 -0
@@ -2,10 +2,10 @@ import { Parser } from 'expr-eval';
2
2
 
3
3
  export default {
4
4
  methods: {
5
- visibilityRuleIsVisible(rule, name, deviceVisibility) {
6
- const visibility = deviceVisibility || { showForDesktop: true, showForMobile: true, isMobile: false };
5
+ visibilityRuleIsVisible(rule, name, deviceVisibility, isMobile = false) {
6
+ const visibility = deviceVisibility || { showForDesktop: true, showForMobile: true };
7
7
  const visibleInDevice =
8
- (visibility.isMobile && visibility.showForMobile) || (!visibility.isMobile && visibility.showForDesktop);
8
+ (isMobile && visibility.showForMobile) || (!isMobile && visibility.showForDesktop);
9
9
 
10
10
  try {
11
11
  if (rule && rule.trim().length > 0) {
@@ -20,8 +20,7 @@ export default {
20
20
  items: element.items,
21
21
  }
22
22
  ],
23
- watchers: [],
24
- isMobile: false
23
+ watchers: []
25
24
  };
26
25
  },
27
26
 
@@ -57,6 +56,7 @@ export default {
57
56
  return this.createComponent("ScreenRenderer", {
58
57
  ":definition": this.byRef(nested),
59
58
  ":value": valueExpression,
59
+ ":is-mobile": "isMobile",
60
60
  ":loop-context": loopContextExpression,
61
61
  ":_parent": "getValidationData()",
62
62
  ":components": this.byRef(this.components),
@@ -1,4 +1,12 @@
1
1
  /* eslint-disable no-param-reassign */
2
+ const RESPONSIVE_COMPONENTS = new Set([
3
+ "FormLoop",
4
+ "FormRecordList",
5
+ "FormNestedScreen",
6
+ "FormCollectionRecordControl",
7
+ "FormCollectionViewControl"
8
+ ]);
9
+
2
10
  export default {
3
11
  data() {
4
12
  return {
@@ -6,6 +14,11 @@ export default {
6
14
  };
7
15
  },
8
16
  methods: {
17
+ addResponsiveProperties(properties, componentName) {
18
+ if (RESPONSIVE_COMPONENTS.has(componentName)) {
19
+ properties[":is-mobile"] = "isMobile";
20
+ }
21
+ },
9
22
  searchForRecordList(items) {
10
23
  items.forEach((item) => {
11
24
  if (item instanceof Array) {
@@ -27,56 +40,58 @@ export default {
27
40
  }
28
41
  });
29
42
  },
43
+ bindFieldVariable(properties, element, componentName) {
44
+ if (componentName === "FormImage") {
45
+ this.registerVariable(element.config.variableName, element);
46
+ delete properties.image;
47
+ properties[":image"] = this.byRef(element.config.image);
48
+ return;
49
+ }
50
+ if (!this.validVariableName(element.config.name)) {
51
+ return;
52
+ }
53
+ this.registerVariable(element.config.name, element);
54
+ // v-model are not assigned directly to the field name, to prevent invalid references like:
55
+ // `person.content` when `person`=null
56
+ const safeDotName = this.safeDotName(element.config.name);
57
+ properties["v-model"] = safeDotName;
58
+ // Debounce input from FormTextArea and FormInput.
59
+ // Pass $event on @input so vdata is updated with the emitted value even
60
+ // if this handler runs before the v-model assignment (listener order race).
61
+ // Keep @change without $event: change payloads are not always the field value.
62
+ if (componentName === "FormTextArea" || componentName === "FormInput") {
63
+ properties[
64
+ "@input"
65
+ ] = `updateScreenData('${safeDotName}', '${element.config.name}', $event)`;
66
+ properties[
67
+ "@change"
68
+ ] = `updateScreenDataNow('${safeDotName}', '${element.config.name}')`;
69
+ } else {
70
+ properties[
71
+ "@input"
72
+ ] = `updateScreenDataNow('${safeDotName}', '${element.config.name}', true, $event)`;
73
+ properties[
74
+ "@change"
75
+ ] = `updateScreenDataNow('${safeDotName}', '${element.config.name}')`;
76
+ }
77
+ // Process the FormSelectList@reset event
78
+ properties[
79
+ "@reset"
80
+ ] = `resetValue('${safeDotName}', '${element.config.name}')`;
81
+ },
30
82
  loadFieldProperties({
31
83
  properties,
32
84
  element,
33
85
  componentName,
34
86
  definition,
35
- formIndex,
36
- screen
87
+ formIndex
37
88
  }) {
38
89
  properties.class = this.elementCssClass(element);
39
90
  properties[":validation-data"] = "getValidationData()";
40
91
 
41
92
  // verify if component is defined in popup
42
93
  if (!this.popups.includes(formIndex)) {
43
- if (componentName === "FormImage") {
44
- this.registerVariable(element.config.variableName, element);
45
- delete properties.image;
46
- properties[":image"] = this.byRef(element.config.image);
47
- } else if (this.validVariableName(element.config.name)) {
48
- this.registerVariable(element.config.name, element);
49
- // v-model are not assigned directly to the field name, to prevent invalid references like:
50
- // `person.content` when `person`=null
51
- const safeDotName = this.safeDotName(element.config.name);
52
- properties["v-model"] = safeDotName;
53
- // Debounce input from FormTextArea and FormInput.
54
- // Pass $event on @input so vdata is updated with the emitted value even
55
- // if this handler runs before the v-model assignment (listener order race).
56
- // Keep @change without $event: change payloads are not always the field value.
57
- if (
58
- componentName === "FormTextArea" ||
59
- componentName === "FormInput"
60
- ) {
61
- properties[
62
- "@input"
63
- ] = `updateScreenData('${safeDotName}', '${element.config.name}', $event)`;
64
- properties[
65
- "@change"
66
- ] = `updateScreenDataNow('${safeDotName}', '${element.config.name}')`;
67
- } else {
68
- properties[
69
- "@input"
70
- ] = `updateScreenDataNow('${safeDotName}', '${element.config.name}', true, $event)`;
71
- properties[
72
- "@change"
73
- ] = `updateScreenDataNow('${safeDotName}', '${element.config.name}')`;
74
- }
75
- // Process the FormSelectList@reset event
76
- properties[
77
- "@reset"
78
- ] = `resetValue('${safeDotName}', '${element.config.name}')`;
79
- }
94
+ this.bindFieldVariable(properties, element, componentName);
80
95
  }
81
96
  // Do not replace mustache in RichText control, it is replaced by the control
82
97
  if (
@@ -89,6 +104,7 @@ export default {
89
104
  if (componentName === "FormNestedScreen") {
90
105
  properties[":_parent"] = "_parent";
91
106
  }
107
+ this.addResponsiveProperties(properties, componentName);
92
108
  // Add cypress testing tags
93
109
  if (element.config.name) {
94
110
  properties["data-cy"] = `screen-field-${element.config.name}`;
@@ -110,6 +126,15 @@ export default {
110
126
  );
111
127
  properties[":readonly"] = isCalcProp || element.config.readonly;
112
128
  properties[":disabled"] = isCalcProp || element.config.disabled;
129
+ // Record List must read editability from the live config object so
130
+ // disableForm() mutations (completed/closed preview) take effect.
131
+ if (componentName === "FormRecordList") {
132
+ const configRef = this.byRef(element.config);
133
+ delete properties.editable;
134
+ // Avoid "&&" in attribute expressions: owner.innerHTML escapes & to &.
135
+ properties[":editable"] =
136
+ `(${configRef}.editable)?!(${configRef}.disabled||${configRef}.readonly):false`;
137
+ }
113
138
  // Events
114
139
  properties["@submit"] = "submitForm";
115
140
  // Add handler event if Button
@@ -28,8 +28,7 @@ export default {
28
28
  items: element.items
29
29
  }
30
30
  ],
31
- watchers: definition.watchers,
32
- isMobile: definition.isMobile
31
+ watchers: definition.watchers
33
32
  };
34
33
 
35
34
  let loopContext = "";
@@ -42,6 +41,7 @@ export default {
42
41
  const child = this.createComponent("ScreenRenderer", {
43
42
  ":definition": this.byRef(nested),
44
43
  ":value": "loopRow",
44
+ ":is-mobile": "isMobile",
45
45
  ":loop-context": `'${loopContext}.' + index`,
46
46
  ":_parent": "getValidationData()",
47
47
  ":components": this.byRef(this.components),
@@ -3,25 +3,25 @@ import VisibilityRule from '../VisibilityRule';
3
3
  export default {
4
4
  mounted() {
5
5
  this.extensions.push({
6
- onloaditems({ element, wrapper, definition }) {
6
+ onloaditems({ element, wrapper }) {
7
7
  const visibility = element.config.deviceVisibility || { showForDesktop: true, showForMobile: true }
8
8
  const restrictDeviceVisibility = !visibility.showForDesktop || !visibility.showForMobile;
9
9
 
10
-
11
- element.visibleInDevice =
12
- (definition.isMobile && visibility.showForMobile) ||
13
- (!definition.isMobile && visibility.showForDesktop);
14
-
15
10
  if (element.config.conditionalHide || restrictDeviceVisibility) {
16
- const deviceVisibility = JSON.stringify( { ...visibility, isMobile: definition.isMobile } );
11
+ const deviceVisibility = JSON.stringify(visibility);
17
12
  wrapper.setAttribute(
18
13
  'v-show',
19
14
  `visibilityRuleIsVisible(${JSON.stringify(element.config.conditionalHide)},
20
- ${JSON.stringify(element.config.name)}, ${deviceVisibility})`
15
+ ${JSON.stringify(element.config.name)}, ${deviceVisibility}, isMobile)`
21
16
  );
22
17
  }
23
18
  },
24
19
  onbuild({ screen }) {
20
+ this.addProp(screen, "isMobile", {
21
+ type: Boolean,
22
+ default: false,
23
+ });
24
+ this.addWatch(screen, "isMobile", "this.loadValidationRules();");
25
25
  screen.mixins.push(VisibilityRule);
26
26
  },
27
27
  });
@@ -0,0 +1,274 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ import { expect, within, userEvent } from '@storybook/test';
3
+ import '../bootstrap';
4
+ import VueRenderTemplate from '../components/renderer/vueRender/VueRenderTemplate';
5
+ import VueRenderEditor from '../components/renderer/vueRender/VueRenderEditor.vue';
6
+ import VueRenderPreview from '../components/renderer/vueRender/VueRenderPreview.vue';
7
+
8
+ const defaultHandler = 'return {}';
9
+
10
+ export default {
11
+ title: 'Components/VueRender',
12
+ tags: ['autodocs'],
13
+ parameters: {
14
+ layout: 'padded',
15
+ },
16
+ };
17
+
18
+ export const TemplateWithCustomMarkup = {
19
+ name: 'VueRenderTemplate / custom template',
20
+ render: () => ({
21
+ components: { VueRenderTemplate },
22
+ template: `
23
+ <vue-render-template
24
+ :template-vue="templateVue"
25
+ :handler-vue="handlerVue"
26
+ />
27
+ `,
28
+ data() {
29
+ return {
30
+ templateVue: '<p data-test="vue-render-message">Hello from templateVue</p>',
31
+ handlerVue: defaultHandler,
32
+ };
33
+ },
34
+ }),
35
+ play: async ({ canvasElement }) => {
36
+ const canvas = within(canvasElement);
37
+ await expect(canvas.getByTestId('vue-render-message')).toHaveTextContent('Hello from templateVue');
38
+ },
39
+ };
40
+
41
+ export const TemplateWithHandlerMethod = {
42
+ name: 'VueRenderTemplate / handlerVue methods',
43
+ render: () => ({
44
+ components: { VueRenderTemplate },
45
+ template: `
46
+ <vue-render-template
47
+ :template-vue="templateVue"
48
+ :handler-vue="handlerVue"
49
+ :validation-data="validationData"
50
+ />
51
+ `,
52
+ data() {
53
+ return {
54
+ validationData: {},
55
+ templateVue: `
56
+ <div>
57
+ <button type="button" data-test="vue-render-action" @click="onAction">Run</button>
58
+ <span data-test="vue-render-result">{{ result }}</span>
59
+ </div>
60
+ `,
61
+ handlerVue: `
62
+ return {
63
+ data() { return { result: '' }; },
64
+ methods: {
65
+ onAction() { this.result = 'done'; }
66
+ }
67
+ };
68
+ `,
69
+ };
70
+ },
71
+ }),
72
+ play: async ({ canvasElement }) => {
73
+ const canvas = within(canvasElement);
74
+ await userEvent.click(canvas.getByTestId('vue-render-action'));
75
+ await expect(canvas.getByTestId('vue-render-result')).toHaveTextContent('done');
76
+ },
77
+ };
78
+
79
+ export const TemplateHandlerError = {
80
+ name: 'VueRenderTemplate / invalid handlerVue',
81
+ render: () => ({
82
+ components: { VueRenderTemplate },
83
+ template: `
84
+ <vue-render-template
85
+ template-vue="<div></div>"
86
+ handler-vue="return null"
87
+ />
88
+ `,
89
+ }),
90
+ play: async ({ canvasElement }) => {
91
+ const canvas = within(canvasElement);
92
+ await expect(canvas.getByRole('alert')).toHaveTextContent(/plain object/i);
93
+ },
94
+ };
95
+
96
+ export const TemplateFieldError = {
97
+ name: 'VueRenderTemplate / error prop',
98
+ render: () => ({
99
+ components: { VueRenderTemplate },
100
+ template: `
101
+ <vue-render-template
102
+ template-vue="<div></div>"
103
+ :handler-vue="handlerVue"
104
+ error="Field error"
105
+ />
106
+ `,
107
+ data() {
108
+ return { handlerVue: defaultHandler };
109
+ },
110
+ }),
111
+ play: async ({ canvasElement }) => {
112
+ const canvas = within(canvasElement);
113
+ await expect(canvas.getByRole('alert')).toHaveTextContent('Field error');
114
+ },
115
+ };
116
+
117
+ export const TemplateWithHelper = {
118
+ name: 'VueRenderTemplate / helper',
119
+ render: () => ({
120
+ components: { VueRenderTemplate },
121
+ template: `
122
+ <vue-render-template
123
+ template-vue="<div></div>"
124
+ :handler-vue="handlerVue"
125
+ helper="Help text"
126
+ />
127
+ `,
128
+ data() {
129
+ return { handlerVue: defaultHandler };
130
+ },
131
+ }),
132
+ play: async ({ canvasElement }) => {
133
+ const canvas = within(canvasElement);
134
+ await expect(canvas.getByText('Help text')).toBeInTheDocument();
135
+ },
136
+ };
137
+
138
+ export const TemplateNamedFieldSync = {
139
+ name: 'VueRenderTemplate / named field data',
140
+ render: () => ({
141
+ components: { VueRenderTemplate },
142
+ template: `
143
+ <vue-render-template
144
+ name="myField"
145
+ :value="value"
146
+ :validation-data="validationData"
147
+ :template-vue="templateVue"
148
+ :handler-vue="handlerVue"
149
+ @input="onInput"
150
+ />
151
+ `,
152
+ data() {
153
+ return {
154
+ value: 'a',
155
+ validationData: { myField: 'a' },
156
+ templateVue: '<div data-test="vue-render-field">{{ data.myField }}</div>',
157
+ handlerVue: defaultHandler,
158
+ lastInput: null,
159
+ };
160
+ },
161
+ methods: {
162
+ onInput(next) {
163
+ this.lastInput = next;
164
+ },
165
+ },
166
+ }),
167
+ play: async ({ canvasElement }) => {
168
+ const canvas = within(canvasElement);
169
+ await expect(canvas.getByTestId('vue-render-field')).toHaveTextContent('a');
170
+ },
171
+ };
172
+
173
+ export const EditorDefault = {
174
+ name: 'VueRenderEditor / design canvas',
175
+ render: () => ({
176
+ components: { VueRenderEditor },
177
+ template: `
178
+ <div data-test="vue-render-editor-root">
179
+ <vue-render-editor
180
+ :template-vue="templateVue"
181
+ :handler-vue="handlerVue"
182
+ :validation-data="validationData"
183
+ />
184
+ </div>
185
+ `,
186
+ data() {
187
+ return {
188
+ templateVue: '<p data-test="vue-render-editor-content">Editor preview</p>',
189
+ handlerVue: defaultHandler,
190
+ validationData: { sample: 1 },
191
+ };
192
+ },
193
+ }),
194
+ play: async ({ canvasElement }) => {
195
+ const canvas = within(canvasElement);
196
+ const root = canvas.getByTestId('vue-render-editor-root');
197
+ await expect(root.querySelector('.form-group.pointer-events-none')).toBeTruthy();
198
+ await expect(canvas.getByTestId('vue-render-editor-content')).toHaveTextContent('Editor preview');
199
+ },
200
+ };
201
+
202
+ export const EditorWithValidationError = {
203
+ name: 'VueRenderEditor / error state',
204
+ render: () => ({
205
+ components: { VueRenderEditor },
206
+ template: `
207
+ <vue-render-editor
208
+ template-vue="<div></div>"
209
+ :handler-vue="handlerVue"
210
+ error="Invalid"
211
+ helper="Hint"
212
+ />
213
+ `,
214
+ data() {
215
+ return { handlerVue: defaultHandler };
216
+ },
217
+ }),
218
+ play: async ({ canvasElement }) => {
219
+ const canvas = within(canvasElement);
220
+ await expect(canvas.getByText('Invalid')).toBeInTheDocument();
221
+ await expect(canvas.getByText('Hint')).toBeInTheDocument();
222
+ await expect(canvasElement.querySelector('.is-invalid')).toBeTruthy();
223
+ },
224
+ };
225
+
226
+ export const PreviewDefault = {
227
+ name: 'VueRenderPreview / runtime',
228
+ render: () => ({
229
+ components: { VueRenderPreview },
230
+ template: `
231
+ <vue-render-preview
232
+ name="field1"
233
+ :template-vue="templateVue"
234
+ :handler-vue="handlerVue"
235
+ :validation-data="validationData"
236
+ data-test="vue-render-preview"
237
+ />
238
+ `,
239
+ data() {
240
+ return {
241
+ templateVue: '<p data-test="vue-render-preview-content">Preview content</p>',
242
+ handlerVue: defaultHandler,
243
+ validationData: { field1: 'value' },
244
+ };
245
+ },
246
+ }),
247
+ play: async ({ canvasElement }) => {
248
+ const canvas = within(canvasElement);
249
+ await expect(canvas.getByTestId('vue-render-preview-content')).toHaveTextContent('Preview content');
250
+ },
251
+ };
252
+
253
+ export const PreviewWithError = {
254
+ name: 'VueRenderPreview / error',
255
+ render: () => ({
256
+ components: { VueRenderPreview },
257
+ template: `
258
+ <vue-render-preview
259
+ template-vue="<div></div>"
260
+ :handler-vue="handlerVue"
261
+ error="Preview error"
262
+ helper="Preview helper"
263
+ />
264
+ `,
265
+ data() {
266
+ return { handlerVue: defaultHandler };
267
+ },
268
+ }),
269
+ play: async ({ canvasElement }) => {
270
+ const canvas = within(canvasElement);
271
+ await expect(canvas.getByText('Preview error')).toBeInTheDocument();
272
+ await expect(canvas.getByText('Preview helper')).toBeInTheDocument();
273
+ },
274
+ };