@formio/js 5.0.0-dev.5686.783670c → 5.0.0-dev.5687.925e544
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +13 -1
- package/dist/formio.form.js +7 -7
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.js +7 -7
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.js +1 -1
- package/dist/formio.min.js +1 -1
- package/lib/cjs/Webform.js +4 -0
- package/lib/cjs/components/_classes/component/Component.js +4 -0
- package/lib/cjs/components/_classes/component/editForm/Component.edit.display.js +8 -0
- package/lib/cjs/components/_classes/component/fixtures/comp7.d.ts +84 -0
- package/lib/cjs/components/_classes/component/fixtures/comp7.js +86 -0
- package/lib/cjs/components/_classes/component/fixtures/index.d.ts +2 -1
- package/lib/cjs/components/_classes/component/fixtures/index.js +3 -1
- package/lib/cjs/components/datagrid/DataGrid.d.ts +9 -0
- package/lib/cjs/components/datagrid/DataGrid.js +50 -32
- package/lib/cjs/components/datagrid/fixtures/comp-with-reorder.d.ts +100 -0
- package/lib/cjs/components/datagrid/fixtures/comp-with-reorder.js +139 -0
- package/lib/cjs/components/datagrid/fixtures/index.d.ts +2 -1
- package/lib/cjs/components/datagrid/fixtures/index.js +3 -1
- package/lib/cjs/components/day/fixtures/comp8.d.ts +41 -0
- package/lib/cjs/components/day/fixtures/comp8.js +40 -0
- package/lib/cjs/components/day/fixtures/index.d.ts +2 -1
- package/lib/cjs/components/day/fixtures/index.js +3 -1
- package/lib/cjs/components/editgrid/EditGrid.js +2 -2
- package/lib/cjs/providers/address/GoogleAddressProvider.d.ts +5 -0
- package/lib/cjs/providers/address/GoogleAddressProvider.js +23 -1
- package/lib/cjs/translations/en.d.ts +3 -0
- package/lib/cjs/translations/en.js +4 -1
- package/lib/mjs/Webform.js +4 -0
- package/lib/mjs/components/_classes/component/Component.js +4 -0
- package/lib/mjs/components/_classes/component/editForm/Component.edit.display.js +8 -0
- package/lib/mjs/components/_classes/component/fixtures/comp7.d.ts +84 -0
- package/lib/mjs/components/_classes/component/fixtures/comp7.js +84 -0
- package/lib/mjs/components/_classes/component/fixtures/index.d.ts +2 -1
- package/lib/mjs/components/_classes/component/fixtures/index.js +2 -1
- package/lib/mjs/components/datagrid/DataGrid.d.ts +9 -0
- package/lib/mjs/components/datagrid/DataGrid.js +50 -32
- package/lib/mjs/components/datagrid/fixtures/comp-with-reorder.d.ts +100 -0
- package/lib/mjs/components/datagrid/fixtures/comp-with-reorder.js +137 -0
- package/lib/mjs/components/datagrid/fixtures/index.d.ts +2 -1
- package/lib/mjs/components/datagrid/fixtures/index.js +2 -1
- package/lib/mjs/components/day/fixtures/comp8.d.ts +41 -0
- package/lib/mjs/components/day/fixtures/comp8.js +38 -0
- package/lib/mjs/components/day/fixtures/index.d.ts +2 -1
- package/lib/mjs/components/day/fixtures/index.js +2 -1
- package/lib/mjs/components/editgrid/EditGrid.js +2 -2
- package/lib/mjs/providers/address/GoogleAddressProvider.d.ts +5 -0
- package/lib/mjs/providers/address/GoogleAddressProvider.js +22 -1
- package/lib/mjs/translations/en.d.ts +3 -0
- package/lib/mjs/translations/en.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
"components": [
|
|
5
|
+
{
|
|
6
|
+
"label": "Day - Table",
|
|
7
|
+
"hideInputLabels": false,
|
|
8
|
+
"inputsLabelPosition": "top",
|
|
9
|
+
"useLocaleSettings": false,
|
|
10
|
+
"alwaysEnabled": false,
|
|
11
|
+
"tableView": false,
|
|
12
|
+
"fields": {
|
|
13
|
+
"day": {
|
|
14
|
+
"hide": false,
|
|
15
|
+
"required": true
|
|
16
|
+
},
|
|
17
|
+
"month": {
|
|
18
|
+
"hide": false,
|
|
19
|
+
"required": true
|
|
20
|
+
},
|
|
21
|
+
"year": {
|
|
22
|
+
"hide": false,
|
|
23
|
+
"required": true
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"key": "dayTable",
|
|
27
|
+
"type": "day",
|
|
28
|
+
"input": true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"label": "Submit",
|
|
32
|
+
"showValidations": false,
|
|
33
|
+
"alwaysEnabled": false,
|
|
34
|
+
"tableView": false,
|
|
35
|
+
"key": "submit",
|
|
36
|
+
"type": "button",
|
|
37
|
+
"input": true
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
};
|
|
@@ -5,4 +5,5 @@ import comp4 from './comp4';
|
|
|
5
5
|
import comp5 from './comp5';
|
|
6
6
|
import comp6 from './comp6';
|
|
7
7
|
import comp7 from './comp7';
|
|
8
|
-
|
|
8
|
+
import comp8 from './comp8';
|
|
9
|
+
export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8 };
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.comp7 = exports.comp6 = exports.comp5 = exports.comp4 = exports.comp3 = exports.comp2 = exports.comp1 = void 0;
|
|
6
|
+
exports.comp8 = exports.comp7 = exports.comp6 = exports.comp5 = exports.comp4 = exports.comp3 = exports.comp2 = exports.comp1 = void 0;
|
|
7
7
|
const comp1_1 = __importDefault(require("./comp1"));
|
|
8
8
|
exports.comp1 = comp1_1.default;
|
|
9
9
|
const comp2_1 = __importDefault(require("./comp2"));
|
|
@@ -18,3 +18,5 @@ const comp6_1 = __importDefault(require("./comp6"));
|
|
|
18
18
|
exports.comp6 = comp6_1.default;
|
|
19
19
|
const comp7_1 = __importDefault(require("./comp7"));
|
|
20
20
|
exports.comp7 = comp7_1.default;
|
|
21
|
+
const comp8_1 = __importDefault(require("./comp8"));
|
|
22
|
+
exports.comp8 = comp8_1.default;
|
|
@@ -88,7 +88,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
|
|
|
88
88
|
{% if (!instance.options.readOnly && !instance.disabled) { %}
|
|
89
89
|
<div class="col-sm-2">
|
|
90
90
|
<div class="btn-group pull-right">
|
|
91
|
-
<button class="btn btn-default btn-light btn-sm editRow"><i class="{{ iconClass('
|
|
91
|
+
<button class="btn btn-default btn-light btn-sm editRow"><i class="{{ iconClass('edit') }}"></i></button>
|
|
92
92
|
{% if (!instance.hasRemoveButtons || instance.hasRemoveButtons()) { %}
|
|
93
93
|
<button class="btn btn-danger btn-sm removeRow"><i class="{{ iconClass('trash') }}"></i></button>
|
|
94
94
|
{% } %}
|
|
@@ -109,7 +109,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
|
|
|
109
109
|
{% if (!instance.options.readOnly && !instance.disabled) { %}
|
|
110
110
|
<td class="editgrid-table-column">
|
|
111
111
|
<div class="btn-group">
|
|
112
|
-
<button class="btn btn-default btn-light btn-sm editRow" aria-label="{{ t('Edit row') }}"><i class="{{ iconClass('
|
|
112
|
+
<button class="btn btn-default btn-light btn-sm editRow" aria-label="{{ t('Edit row') }}"><i class="{{ iconClass('edit') }}"></i></button>
|
|
113
113
|
{% if (!instance.hasRemoveButtons || instance.hasRemoveButtons()) { %}
|
|
114
114
|
<button class="btn btn-danger btn-sm removeRow" aria-label="{{ t('Remove row') }}"><i class="{{ iconClass('trash') }}"></i></button>
|
|
115
115
|
{% } %}
|
|
@@ -82,6 +82,11 @@ export class GoogleAddressProvider extends AddressProvider {
|
|
|
82
82
|
search(): Promise<void>;
|
|
83
83
|
makeRequest(): Promise<void>;
|
|
84
84
|
getDisplayValue(address: any): any;
|
|
85
|
+
/**
|
|
86
|
+
* Tries to remove the library if api key for loaded script is different.
|
|
87
|
+
* @param {ProviderOptions} options - The options for the provider.
|
|
88
|
+
*/
|
|
89
|
+
tryRemoveLibrary(options?: ProviderOptions): void;
|
|
85
90
|
}
|
|
86
91
|
export type AutocompleteOptions = {
|
|
87
92
|
/**
|
|
@@ -8,6 +8,9 @@ exports.GoogleAddressProvider = void 0;
|
|
|
8
8
|
const Formio_1 = require("../../Formio");
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
10
10
|
const AddressProvider_1 = require("./AddressProvider");
|
|
11
|
+
const GOOGLE_MAPS_BASE_URL = 'https://maps.googleapis.com';
|
|
12
|
+
const GOOGLE_MAPS_JS_URL = `${GOOGLE_MAPS_BASE_URL}/maps/api/js`;
|
|
13
|
+
const GOOGLE_MAPS_JS_WITH_PARAMS_URL = `${GOOGLE_MAPS_JS_URL}?v=quarterly&libraries=places&loading=async&callback=googleMapsCallback`;
|
|
11
14
|
/**
|
|
12
15
|
* @typedef {object} AutocompleteOptions
|
|
13
16
|
* @property {string[]} fields - The fields to include in the autocomplete response.
|
|
@@ -55,10 +58,11 @@ class GoogleAddressProvider extends AddressProvider_1.AddressProvider {
|
|
|
55
58
|
var _a;
|
|
56
59
|
super(options);
|
|
57
60
|
this.setAutocompleteOptions();
|
|
58
|
-
let src =
|
|
61
|
+
let src = GOOGLE_MAPS_JS_WITH_PARAMS_URL;
|
|
59
62
|
if ((_a = options.params) === null || _a === void 0 ? void 0 : _a.key) {
|
|
60
63
|
src += `&key=${options.params.key}`;
|
|
61
64
|
}
|
|
65
|
+
this.tryRemoveLibrary(options);
|
|
62
66
|
Formio_1.Formio.requireLibrary(this.getLibraryName(), 'google.maps.places', src);
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
@@ -185,5 +189,23 @@ class GoogleAddressProvider extends AddressProvider_1.AddressProvider {
|
|
|
185
189
|
: this.alternativeDisplayValueProperty;
|
|
186
190
|
return lodash_1.default.get(address, displayedProperty, '');
|
|
187
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Tries to remove the library if api key for loaded script is different.
|
|
194
|
+
* @param {ProviderOptions} options - The options for the provider.
|
|
195
|
+
*/
|
|
196
|
+
tryRemoveLibrary(options = {}) {
|
|
197
|
+
var _a, _b, _c;
|
|
198
|
+
if (!Formio_1.Formio.libraries[this.getLibraryName()]) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const existingScript = document.querySelector(`script[src^="${GOOGLE_MAPS_JS_URL}"]`);
|
|
202
|
+
if (existingScript && ((_a = options.params) === null || _a === void 0 ? void 0 : _a.key) && !existingScript.attributes.src.value.endsWith(options.params.key)) {
|
|
203
|
+
const googleMapsScripts = (_b = document.querySelectorAll(`script[src^="${GOOGLE_MAPS_BASE_URL}"]`)) !== null && _b !== void 0 ? _b : [];
|
|
204
|
+
googleMapsScripts.forEach(script => script.parentNode.removeChild(script));
|
|
205
|
+
delete Formio_1.Formio.libraries[this.getLibraryName()];
|
|
206
|
+
(_c = global === null || global === void 0 ? void 0 : global.google) === null || _c === void 0 ? true : delete _c.maps;
|
|
207
|
+
delete global[`${this.getLibraryName()}Callback`];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
188
210
|
}
|
|
189
211
|
exports.GoogleAddressProvider = GoogleAddressProvider;
|
|
@@ -75,5 +75,8 @@ exports.default = {
|
|
|
75
75
|
reCaptchaTokenNotSpecifiedError: 'ReCAPTCHA: Token is not specified in submission',
|
|
76
76
|
apiKey: 'API Key is not unique: {{key}}',
|
|
77
77
|
typeRemaining: '{{ remaining }} {{ type }} remaining.',
|
|
78
|
-
typeCount: '{{ count }} {{ type }}'
|
|
78
|
+
typeCount: '{{ count }} {{ type }}',
|
|
79
|
+
requiredDayField: '{{ field }} is required',
|
|
80
|
+
requiredMonthField: '{{ field }} is required',
|
|
81
|
+
requiredYearField: '{{ field }} is required'
|
|
79
82
|
};
|
package/lib/mjs/Webform.js
CHANGED
|
@@ -8,6 +8,10 @@ import Components from "./components/Components";
|
|
|
8
8
|
import NestedDataComponent from "./components/_classes/nesteddata/NestedDataComponent";
|
|
9
9
|
import { fastCloneDeep, currentTimezone, unescapeHTML, getStringFromComponentPath, convertStringToHTMLElement, getArrayFromComponentPath, } from "./utils/utils";
|
|
10
10
|
import { eachComponent } from "./utils/formUtils";
|
|
11
|
+
// We need this here because dragula pulls in CustomEvent class that requires global to exist.
|
|
12
|
+
if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
|
|
13
|
+
window.global = window;
|
|
14
|
+
}
|
|
11
15
|
import dragula from "dragula";
|
|
12
16
|
// Initialize the available forms.
|
|
13
17
|
Formio.forms = {};
|
|
@@ -3361,6 +3361,10 @@ export default class Component extends Element {
|
|
|
3361
3361
|
const disabled = this.shouldDisabled;
|
|
3362
3362
|
// Change states which won't be recalculated during redrawing
|
|
3363
3363
|
if (this.visible !== visible) {
|
|
3364
|
+
// If the logic is triggered by an event and the action sets the hidden state then the original
|
|
3365
|
+
// component definition must be changed so that the components hidden state does not get flipped back by
|
|
3366
|
+
// the fieldLogic function
|
|
3367
|
+
this.originalComponent.hidden = !visible;
|
|
3364
3368
|
this.visible = visible;
|
|
3365
3369
|
}
|
|
3366
3370
|
if (this.disabled !== disabled) {
|
|
@@ -187,5 +187,13 @@ export default [
|
|
|
187
187
|
key: 'tableView',
|
|
188
188
|
input: true
|
|
189
189
|
},
|
|
190
|
+
{
|
|
191
|
+
weight: 1600,
|
|
192
|
+
type: 'checkbox',
|
|
193
|
+
label: 'Modal Edit',
|
|
194
|
+
tooltip: 'Opens up a modal to edit the value of this component.',
|
|
195
|
+
key: 'modalEdit',
|
|
196
|
+
input: true
|
|
197
|
+
}
|
|
190
198
|
];
|
|
191
199
|
/* eslint-enable max-len */
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
let components: ({
|
|
3
|
+
label: string;
|
|
4
|
+
action: string;
|
|
5
|
+
showValidations: boolean;
|
|
6
|
+
tableView: boolean;
|
|
7
|
+
key: string;
|
|
8
|
+
type: string;
|
|
9
|
+
event: string;
|
|
10
|
+
input: boolean;
|
|
11
|
+
theme?: undefined;
|
|
12
|
+
collapsible?: undefined;
|
|
13
|
+
hidden?: undefined;
|
|
14
|
+
logic?: undefined;
|
|
15
|
+
collapsed?: undefined;
|
|
16
|
+
components?: undefined;
|
|
17
|
+
applyMaskOn?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
label: string;
|
|
20
|
+
action: string;
|
|
21
|
+
showValidations: boolean;
|
|
22
|
+
theme: string;
|
|
23
|
+
tableView: boolean;
|
|
24
|
+
key: string;
|
|
25
|
+
type: string;
|
|
26
|
+
event: string;
|
|
27
|
+
input: boolean;
|
|
28
|
+
collapsible?: undefined;
|
|
29
|
+
hidden?: undefined;
|
|
30
|
+
logic?: undefined;
|
|
31
|
+
collapsed?: undefined;
|
|
32
|
+
components?: undefined;
|
|
33
|
+
applyMaskOn?: undefined;
|
|
34
|
+
} | {
|
|
35
|
+
collapsible: boolean;
|
|
36
|
+
hidden: boolean;
|
|
37
|
+
key: string;
|
|
38
|
+
logic: {
|
|
39
|
+
name: string;
|
|
40
|
+
trigger: {
|
|
41
|
+
type: string;
|
|
42
|
+
event: string;
|
|
43
|
+
};
|
|
44
|
+
actions: {
|
|
45
|
+
name: string;
|
|
46
|
+
type: string;
|
|
47
|
+
property: {
|
|
48
|
+
label: string;
|
|
49
|
+
value: string;
|
|
50
|
+
type: string;
|
|
51
|
+
};
|
|
52
|
+
state: boolean;
|
|
53
|
+
}[];
|
|
54
|
+
}[];
|
|
55
|
+
type: string;
|
|
56
|
+
label: string;
|
|
57
|
+
collapsed: boolean;
|
|
58
|
+
input: boolean;
|
|
59
|
+
tableView: boolean;
|
|
60
|
+
components: never[];
|
|
61
|
+
action?: undefined;
|
|
62
|
+
showValidations?: undefined;
|
|
63
|
+
event?: undefined;
|
|
64
|
+
theme?: undefined;
|
|
65
|
+
applyMaskOn?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
label: string;
|
|
68
|
+
applyMaskOn: string;
|
|
69
|
+
tableView: boolean;
|
|
70
|
+
key: string;
|
|
71
|
+
type: string;
|
|
72
|
+
input: boolean;
|
|
73
|
+
action?: undefined;
|
|
74
|
+
showValidations?: undefined;
|
|
75
|
+
event?: undefined;
|
|
76
|
+
theme?: undefined;
|
|
77
|
+
collapsible?: undefined;
|
|
78
|
+
hidden?: undefined;
|
|
79
|
+
logic?: undefined;
|
|
80
|
+
collapsed?: undefined;
|
|
81
|
+
components?: undefined;
|
|
82
|
+
})[];
|
|
83
|
+
}
|
|
84
|
+
export default _default;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
components: [
|
|
3
|
+
{
|
|
4
|
+
"label": "Show",
|
|
5
|
+
"action": "event",
|
|
6
|
+
"showValidations": false,
|
|
7
|
+
"tableView": false,
|
|
8
|
+
"key": "show",
|
|
9
|
+
"type": "button",
|
|
10
|
+
"event": "show",
|
|
11
|
+
"input": true
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"label": "Hide",
|
|
15
|
+
"action": "event",
|
|
16
|
+
"showValidations": false,
|
|
17
|
+
"theme": "danger",
|
|
18
|
+
"tableView": false,
|
|
19
|
+
"key": "hide",
|
|
20
|
+
"type": "button",
|
|
21
|
+
"event": "hide",
|
|
22
|
+
"input": true
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"collapsible": true,
|
|
26
|
+
"hidden": true,
|
|
27
|
+
"key": "panel",
|
|
28
|
+
"logic": [
|
|
29
|
+
{
|
|
30
|
+
"name": "ShowPanel",
|
|
31
|
+
"trigger": {
|
|
32
|
+
"type": "event",
|
|
33
|
+
"event": "show"
|
|
34
|
+
},
|
|
35
|
+
"actions": [
|
|
36
|
+
{
|
|
37
|
+
"name": "Show",
|
|
38
|
+
"type": "property",
|
|
39
|
+
"property": {
|
|
40
|
+
"label": "Hidden",
|
|
41
|
+
"value": "hidden",
|
|
42
|
+
"type": "boolean"
|
|
43
|
+
},
|
|
44
|
+
"state": false
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "HidePanel",
|
|
50
|
+
"trigger": {
|
|
51
|
+
"type": "event",
|
|
52
|
+
"event": "hide"
|
|
53
|
+
},
|
|
54
|
+
"actions": [
|
|
55
|
+
{
|
|
56
|
+
"name": "Hide",
|
|
57
|
+
"type": "property",
|
|
58
|
+
"property": {
|
|
59
|
+
"label": "Hidden",
|
|
60
|
+
"value": "hidden",
|
|
61
|
+
"type": "boolean"
|
|
62
|
+
},
|
|
63
|
+
"state": true
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"type": "panel",
|
|
69
|
+
"label": "Panel",
|
|
70
|
+
"collapsed": false,
|
|
71
|
+
"input": false,
|
|
72
|
+
"tableView": false,
|
|
73
|
+
"components": []
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"label": "Text Field",
|
|
77
|
+
"applyMaskOn": "change",
|
|
78
|
+
"tableView": true,
|
|
79
|
+
"key": "textField1",
|
|
80
|
+
"type": "textfield",
|
|
81
|
+
"input": true
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
};
|
|
@@ -61,6 +61,15 @@ export default class DataGridComponent extends NestedArrayComponent {
|
|
|
61
61
|
loadRefs(element: any, refs: any): void;
|
|
62
62
|
dragula: any;
|
|
63
63
|
getComponentsContainer(): any;
|
|
64
|
+
/**
|
|
65
|
+
* Reorder values in array based on the old and new position
|
|
66
|
+
* @param {any} valuesArr - An array of values.
|
|
67
|
+
* @param {number} oldPosition - The index of the value in array before reordering.
|
|
68
|
+
* @param {number} newPosition - The index of the value in array after reordering.
|
|
69
|
+
* @param {boolean|any} movedBelow - Whether or not the value is moved below.
|
|
70
|
+
* @returns {void}
|
|
71
|
+
*/
|
|
72
|
+
reorderValues(valuesArr: any, oldPosition: number, newPosition: number, movedBelow: boolean | any): void;
|
|
64
73
|
onReorder(element: any, _target: any, _source: any, sibling: any): void;
|
|
65
74
|
focusOnNewRowElement(row: any): void;
|
|
66
75
|
addRow(): void;
|
|
@@ -2,6 +2,7 @@ import _ from 'lodash';
|
|
|
2
2
|
import NestedArrayComponent from '../_classes/nestedarray/NestedArrayComponent';
|
|
3
3
|
import { fastCloneDeep, getFocusableElements } from '../../utils/utils';
|
|
4
4
|
import { Components } from '../Components';
|
|
5
|
+
import dragula from 'dragula';
|
|
5
6
|
export default class DataGridComponent extends NestedArrayComponent {
|
|
6
7
|
static schema(...extend) {
|
|
7
8
|
return NestedArrayComponent.schema({
|
|
@@ -278,34 +279,32 @@ export default class DataGridComponent extends NestedArrayComponent {
|
|
|
278
279
|
this.refs[`${this.datagridKey}-row`].forEach((row, index) => {
|
|
279
280
|
row.dragInfo = { index };
|
|
280
281
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return clickedElement.classList.contains('formio-drag-button');
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}).on('drop', this.onReorder.bind(this));
|
|
292
|
-
this.dragula.on('cloned', (el, original) => {
|
|
293
|
-
if (el && el.children && original && original.children) {
|
|
294
|
-
_.each(original.children, (child, index) => {
|
|
295
|
-
const styles = getComputedStyle(child, null);
|
|
296
|
-
if (styles.cssText !== '') {
|
|
297
|
-
el.children[index].style.cssText = styles.cssText;
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
const cssText = Object.values(styles).reduce((css, propertyName) => {
|
|
301
|
-
return `${css}${propertyName}:${styles.getPropertyValue(propertyName)};`;
|
|
302
|
-
}, '');
|
|
303
|
-
el.children[index].style.cssText = cssText;
|
|
304
|
-
}
|
|
305
|
-
});
|
|
282
|
+
this.dragula = dragula([this.refs[`${this.datagridKey}-tbody`]], {
|
|
283
|
+
moves: (_draggedElement, _oldParent, clickedElement) => {
|
|
284
|
+
const clickedElementKey = clickedElement.getAttribute('data-key');
|
|
285
|
+
const oldParentKey = _oldParent.getAttribute('data-key');
|
|
286
|
+
//Check if the clicked button belongs to that container, if false, it belongs to the nested container
|
|
287
|
+
if (oldParentKey === clickedElementKey) {
|
|
288
|
+
return clickedElement.classList.contains('formio-drag-button');
|
|
306
289
|
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
290
|
+
}
|
|
291
|
+
}).on('drop', this.onReorder.bind(this));
|
|
292
|
+
this.dragula.on('cloned', (el, original) => {
|
|
293
|
+
if (el && el.children && original && original.children) {
|
|
294
|
+
_.each(original.children, (child, index) => {
|
|
295
|
+
const styles = getComputedStyle(child, null);
|
|
296
|
+
if (styles.cssText !== '') {
|
|
297
|
+
el.children[index].style.cssText = styles.cssText;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
const cssText = Object.values(styles).reduce((css, propertyName) => {
|
|
301
|
+
return `${css}${propertyName}:${styles.getPropertyValue(propertyName)};`;
|
|
302
|
+
}, '');
|
|
303
|
+
el.children[index].style.cssText = cssText;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
});
|
|
309
308
|
}
|
|
310
309
|
this.refs[`${this.datagridKey}-addRow`].forEach((addButton) => {
|
|
311
310
|
this.addEventListener(addButton, 'click', this.addRow.bind(this));
|
|
@@ -333,6 +332,24 @@ export default class DataGridComponent extends NestedArrayComponent {
|
|
|
333
332
|
getComponentsContainer() {
|
|
334
333
|
return this.component.components;
|
|
335
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Reorder values in array based on the old and new position
|
|
337
|
+
* @param {any} valuesArr - An array of values.
|
|
338
|
+
* @param {number} oldPosition - The index of the value in array before reordering.
|
|
339
|
+
* @param {number} newPosition - The index of the value in array after reordering.
|
|
340
|
+
* @param {boolean|any} movedBelow - Whether or not the value is moved below.
|
|
341
|
+
* @returns {void}
|
|
342
|
+
*/
|
|
343
|
+
reorderValues(valuesArr, oldPosition, newPosition, movedBelow) {
|
|
344
|
+
if (!_.isArray(valuesArr) || _.isEmpty(valuesArr)) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const draggedRowData = valuesArr[oldPosition];
|
|
348
|
+
//insert element at new position
|
|
349
|
+
valuesArr.splice(newPosition, 0, draggedRowData);
|
|
350
|
+
//remove element from old position (if was moved above, after insertion it's at +1 index)
|
|
351
|
+
valuesArr.splice(movedBelow ? oldPosition : oldPosition + 1, 1);
|
|
352
|
+
}
|
|
336
353
|
onReorder(element, _target, _source, sibling) {
|
|
337
354
|
if (!element.dragInfo || (sibling && !sibling.dragInfo)) {
|
|
338
355
|
console.warn('There is no Drag Info available for either dragged or sibling element');
|
|
@@ -343,11 +360,12 @@ export default class DataGridComponent extends NestedArrayComponent {
|
|
|
343
360
|
const newPosition = sibling ? sibling.dragInfo.index : this.dataValue.length;
|
|
344
361
|
const movedBelow = newPosition > oldPosition;
|
|
345
362
|
const dataValue = fastCloneDeep(this.dataValue);
|
|
346
|
-
|
|
347
|
-
//
|
|
348
|
-
|
|
349
|
-
//
|
|
350
|
-
|
|
363
|
+
this.reorderValues(dataValue, oldPosition, newPosition, movedBelow);
|
|
364
|
+
//reorder select data
|
|
365
|
+
this.reorderValues(_.get(this.root, `submission.metadata.selectData.${this.path}`, []), oldPosition, newPosition, movedBelow);
|
|
366
|
+
// When components are reordered we need to set the dataGrid and form pristine properties to false
|
|
367
|
+
this.root.pristine = false;
|
|
368
|
+
this.pristine = false;
|
|
351
369
|
//need to re-build rows to re-calculate indexes and other indexed fields for component instance (like rows for ex.)
|
|
352
370
|
this.setValue(dataValue, { isReordered: true });
|
|
353
371
|
this.rebuild();
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { form };
|
|
3
|
+
export { submission };
|
|
4
|
+
}
|
|
5
|
+
export default _default;
|
|
6
|
+
declare namespace form {
|
|
7
|
+
let _id: string;
|
|
8
|
+
let title: string;
|
|
9
|
+
let name: string;
|
|
10
|
+
let path: string;
|
|
11
|
+
let type: string;
|
|
12
|
+
let display: string;
|
|
13
|
+
let components: ({
|
|
14
|
+
label: string;
|
|
15
|
+
reorder: boolean;
|
|
16
|
+
addAnotherPosition: string;
|
|
17
|
+
layoutFixed: boolean;
|
|
18
|
+
enableRowGroups: boolean;
|
|
19
|
+
initEmpty: boolean;
|
|
20
|
+
tableView: boolean;
|
|
21
|
+
defaultValue: {
|
|
22
|
+
select: string;
|
|
23
|
+
}[];
|
|
24
|
+
key: string;
|
|
25
|
+
type: string;
|
|
26
|
+
input: boolean;
|
|
27
|
+
components: {
|
|
28
|
+
label: string;
|
|
29
|
+
widget: string;
|
|
30
|
+
tableView: boolean;
|
|
31
|
+
dataSrc: string;
|
|
32
|
+
data: {
|
|
33
|
+
resource: string;
|
|
34
|
+
};
|
|
35
|
+
dataType: string;
|
|
36
|
+
valueProperty: string;
|
|
37
|
+
template: string;
|
|
38
|
+
validate: {
|
|
39
|
+
select: boolean;
|
|
40
|
+
};
|
|
41
|
+
key: string;
|
|
42
|
+
type: string;
|
|
43
|
+
searchField: string;
|
|
44
|
+
limit: number;
|
|
45
|
+
noRefreshOnScroll: boolean;
|
|
46
|
+
addResource: boolean;
|
|
47
|
+
reference: boolean;
|
|
48
|
+
input: boolean;
|
|
49
|
+
}[];
|
|
50
|
+
disableOnInvalid?: undefined;
|
|
51
|
+
} | {
|
|
52
|
+
type: string;
|
|
53
|
+
label: string;
|
|
54
|
+
key: string;
|
|
55
|
+
disableOnInvalid: boolean;
|
|
56
|
+
input: boolean;
|
|
57
|
+
tableView: boolean;
|
|
58
|
+
reorder?: undefined;
|
|
59
|
+
addAnotherPosition?: undefined;
|
|
60
|
+
layoutFixed?: undefined;
|
|
61
|
+
enableRowGroups?: undefined;
|
|
62
|
+
initEmpty?: undefined;
|
|
63
|
+
defaultValue?: undefined;
|
|
64
|
+
components?: undefined;
|
|
65
|
+
})[];
|
|
66
|
+
let created: string;
|
|
67
|
+
let modified: string;
|
|
68
|
+
let machineName: string;
|
|
69
|
+
}
|
|
70
|
+
declare namespace submission {
|
|
71
|
+
let form_1: string;
|
|
72
|
+
export { form_1 as form };
|
|
73
|
+
export namespace metadata {
|
|
74
|
+
namespace selectData {
|
|
75
|
+
let dataGrid: {
|
|
76
|
+
select: {
|
|
77
|
+
data: {
|
|
78
|
+
number: number;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}[];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export namespace data {
|
|
85
|
+
let dataGrid_1: {
|
|
86
|
+
select: string;
|
|
87
|
+
}[];
|
|
88
|
+
export { dataGrid_1 as dataGrid };
|
|
89
|
+
export let dataTable: never[];
|
|
90
|
+
export let submit: boolean;
|
|
91
|
+
}
|
|
92
|
+
let _id_1: string;
|
|
93
|
+
export { _id_1 as _id };
|
|
94
|
+
export let project: string;
|
|
95
|
+
export let state: string;
|
|
96
|
+
let created_1: string;
|
|
97
|
+
export { created_1 as created };
|
|
98
|
+
let modified_1: string;
|
|
99
|
+
export { modified_1 as modified };
|
|
100
|
+
}
|