@formio/js 5.1.0-dev.5913.5ccc183 → 5.1.0-dev.5936.81a1533
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/README.md +2 -0
- package/dist/formio.form.js +112 -123
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.js +119 -130
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.js +62 -51
- package/dist/formio.min.js +1 -1
- package/dist/formio.utils.js +73 -73
- package/dist/formio.utils.min.js +1 -1
- package/lib/cjs/Element.js +13 -36
- package/lib/cjs/EventEmitter.js +2 -25
- package/lib/cjs/Form.js +2 -25
- package/lib/cjs/PDF.js +1 -1
- package/lib/cjs/PDFBuilder.js +4 -5
- package/lib/cjs/Webform.js +5 -6
- package/lib/cjs/WebformBuilder.js +20 -15
- package/lib/cjs/Wizard.js +1 -1
- package/lib/cjs/WizardBuilder.js +1 -1
- package/lib/cjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/cjs/components/_classes/component/Component.js +36 -57
- package/lib/cjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/cjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -1
- package/lib/cjs/components/_classes/input/Input.js +1 -1
- package/lib/cjs/components/_classes/list/ListComponent.js +1 -1
- package/lib/cjs/components/_classes/nested/NestedComponent.js +6 -6
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
- package/lib/cjs/components/address/Address.js +1 -1
- package/lib/cjs/components/alert/Alert.js +1 -1
- package/lib/cjs/components/button/Button.js +1 -1
- package/lib/cjs/components/checkbox/Checkbox.js +1 -1
- package/lib/cjs/components/container/Container.js +1 -1
- package/lib/cjs/components/currency/Currency.js +1 -1
- package/lib/cjs/components/datagrid/DataGrid.js +1 -1
- package/lib/cjs/components/datetime/DateTime.d.ts +1 -1
- package/lib/cjs/components/datetime/DateTime.js +15 -13
- package/lib/cjs/components/day/Day.js +2 -2
- package/lib/cjs/components/editgrid/EditGrid.js +1 -1
- package/lib/cjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
- package/lib/cjs/components/file/File.js +1 -1
- package/lib/cjs/components/form/Form.js +14 -2
- package/lib/cjs/components/form/editForm/Form.edit.form.js +4 -3
- package/lib/cjs/components/number/Number.js +1 -1
- package/lib/cjs/components/panel/Panel.js +1 -1
- package/lib/cjs/components/radio/Radio.d.ts +4 -0
- package/lib/cjs/components/radio/Radio.js +69 -23
- package/lib/cjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
- package/lib/cjs/components/select/Select.js +1 -1
- package/lib/cjs/components/select/editForm/Select.edit.data.js +1 -1
- package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/cjs/components/signature/Signature.js +1 -1
- package/lib/cjs/components/survey/Survey.js +1 -1
- package/lib/cjs/components/tags/Tags.js +1 -1
- package/lib/cjs/components/textarea/TextArea.js +3 -3
- package/lib/cjs/components/textfield/TextField.js +7 -30
- package/lib/cjs/components/time/Time.js +1 -1
- package/lib/cjs/formio.form.js +3 -3
- package/lib/cjs/i18n.js +1 -1
- package/lib/cjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/cjs/utils/Evaluator.d.ts +20 -6
- package/lib/cjs/utils/Evaluator.js +38 -15
- package/lib/cjs/utils/builder.js +5 -5
- package/lib/cjs/utils/conditionOperators/IsEqualTo.js +3 -3
- package/lib/cjs/utils/i18n.js +3 -3
- package/lib/cjs/utils/index.d.ts +169 -2
- package/lib/cjs/utils/index.js +22 -2
- package/lib/cjs/utils/utils.d.ts +22 -37
- package/lib/cjs/utils/utils.js +54 -132
- package/lib/cjs/widgets/CalendarWidget.d.ts +1 -8
- package/lib/cjs/widgets/CalendarWidget.js +17 -43
- package/lib/mjs/Element.js +6 -6
- package/lib/mjs/EventEmitter.js +2 -2
- package/lib/mjs/Form.js +1 -1
- package/lib/mjs/PDF.js +1 -1
- package/lib/mjs/PDFBuilder.js +1 -2
- package/lib/mjs/Webform.js +3 -4
- package/lib/mjs/WebformBuilder.js +12 -7
- package/lib/mjs/Wizard.js +1 -1
- package/lib/mjs/WizardBuilder.js +1 -1
- package/lib/mjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/mjs/components/_classes/component/Component.js +9 -7
- package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -1
- package/lib/mjs/components/_classes/input/Input.js +1 -1
- package/lib/mjs/components/_classes/list/ListComponent.js +1 -1
- package/lib/mjs/components/_classes/nested/NestedComponent.js +6 -6
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
- package/lib/mjs/components/address/Address.js +1 -1
- package/lib/mjs/components/alert/Alert.js +1 -1
- package/lib/mjs/components/button/Button.js +1 -1
- package/lib/mjs/components/checkbox/Checkbox.js +1 -1
- package/lib/mjs/components/container/Container.js +1 -1
- package/lib/mjs/components/currency/Currency.js +1 -1
- package/lib/mjs/components/datagrid/DataGrid.js +1 -1
- package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
- package/lib/mjs/components/datetime/DateTime.js +15 -13
- package/lib/mjs/components/day/Day.js +2 -2
- package/lib/mjs/components/editgrid/EditGrid.js +1 -1
- package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
- package/lib/mjs/components/file/File.js +1 -1
- package/lib/mjs/components/form/Form.js +13 -2
- package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -2
- package/lib/mjs/components/number/Number.js +1 -1
- package/lib/mjs/components/panel/Panel.js +1 -1
- package/lib/mjs/components/radio/Radio.d.ts +4 -0
- package/lib/mjs/components/radio/Radio.js +68 -23
- package/lib/mjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
- package/lib/mjs/components/select/Select.js +1 -1
- package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -1
- package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/mjs/components/signature/Signature.js +1 -1
- package/lib/mjs/components/survey/Survey.js +1 -1
- package/lib/mjs/components/tags/Tags.js +1 -1
- package/lib/mjs/components/textarea/TextArea.js +3 -3
- package/lib/mjs/components/textfield/TextField.js +1 -1
- package/lib/mjs/components/time/Time.js +1 -1
- package/lib/mjs/formio.form.js +2 -2
- package/lib/mjs/i18n.js +1 -1
- package/lib/mjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/mjs/utils/Evaluator.d.ts +20 -6
- package/lib/mjs/utils/Evaluator.js +31 -13
- package/lib/mjs/utils/builder.js +1 -1
- package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
- package/lib/mjs/utils/i18n.js +1 -1
- package/lib/mjs/utils/index.d.ts +169 -2
- package/lib/mjs/utils/index.js +18 -1
- package/lib/mjs/utils/utils.d.ts +22 -37
- package/lib/mjs/utils/utils.js +47 -107
- package/lib/mjs/widgets/CalendarWidget.d.ts +1 -8
- package/lib/mjs/widgets/CalendarWidget.js +17 -43
- package/package.json +5 -3
@@ -2,6 +2,7 @@ import _ from 'lodash';
|
|
2
2
|
import ListComponent from '../_classes/list/ListComponent';
|
3
3
|
import { Formio } from '../../Formio';
|
4
4
|
import { boolValue, componentValueTypes, getComponentSavedTypes } from '../../utils/utils';
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
5
6
|
export default class RadioComponent extends ListComponent {
|
6
7
|
static schema(...extend) {
|
7
8
|
return ListComponent.schema({
|
@@ -142,6 +143,7 @@ export default class RadioComponent extends ListComponent {
|
|
142
143
|
});
|
143
144
|
this.optionsLoaded = !this.component.dataSrc || this.component.dataSrc === 'values';
|
144
145
|
this.loadedOptions = [];
|
146
|
+
this.valuesMap = new Map();
|
145
147
|
if (!this.visible) {
|
146
148
|
this.itemsLoadedResolve();
|
147
149
|
}
|
@@ -181,9 +183,12 @@ export default class RadioComponent extends ListComponent {
|
|
181
183
|
if (!_.isString(this.dataValue)) {
|
182
184
|
dataValue = _.toString(this.dataValue);
|
183
185
|
}
|
184
|
-
if (this.isSelectURL
|
185
|
-
const
|
186
|
-
|
186
|
+
if (this.isSelectURL) {
|
187
|
+
const valueKey = this.loadedOptions[index].value;
|
188
|
+
const optionValue = this.valuesMap.has(valueKey)
|
189
|
+
? this.valuesMap.get(valueKey)
|
190
|
+
: valueKey;
|
191
|
+
input.checked = _.isEqual(this.normalizeValue(optionValue), this.dataValue);
|
187
192
|
}
|
188
193
|
else {
|
189
194
|
input.checked = (dataValue === input.value && (input.value || this.component.dataSrc !== 'url'));
|
@@ -220,9 +225,14 @@ export default class RadioComponent extends ListComponent {
|
|
220
225
|
let value = this.component.inputType === 'checkbox' ? '' : this.dataValue;
|
221
226
|
this.refs.input.forEach((input, index) => {
|
222
227
|
if (input.checked) {
|
223
|
-
|
224
|
-
|
225
|
-
|
228
|
+
if (!this.isSelectURL) {
|
229
|
+
value = input.value;
|
230
|
+
return;
|
231
|
+
}
|
232
|
+
const optionValue = this.loadedOptions[index].value;
|
233
|
+
value = this.valuesMap.has(optionValue)
|
234
|
+
? this.valuesMap.get(optionValue)
|
235
|
+
: optionValue;
|
226
236
|
}
|
227
237
|
});
|
228
238
|
return value;
|
@@ -266,8 +276,8 @@ export default class RadioComponent extends ListComponent {
|
|
266
276
|
}
|
267
277
|
setValueAt(index, value) {
|
268
278
|
if (this.refs.input && this.refs.input[index] && value !== null && value !== undefined) {
|
269
|
-
const inputValue = this.refs.input[index]
|
270
|
-
this.refs.input[index].checked = (inputValue
|
279
|
+
const inputValue = this.getValueByInput(this.refs.input[index]);
|
280
|
+
this.refs.input[index].checked = _.isEqual(inputValue, value);
|
271
281
|
}
|
272
282
|
}
|
273
283
|
get shouldLoad() {
|
@@ -277,6 +287,23 @@ export default class RadioComponent extends ListComponent {
|
|
277
287
|
}
|
278
288
|
return super.shouldLoad;
|
279
289
|
}
|
290
|
+
prepareValue(item, options = {}) {
|
291
|
+
const value = this.component.valueProperty && !options.skipValueProperty
|
292
|
+
? _.get(item, this.component.valueProperty)
|
293
|
+
: item;
|
294
|
+
if (this.component.type === 'radio' && typeof value !== 'string') {
|
295
|
+
const uuid = uuidv4();
|
296
|
+
this.valuesMap.set(uuid, value);
|
297
|
+
return uuid;
|
298
|
+
}
|
299
|
+
return value;
|
300
|
+
}
|
301
|
+
getValueByInput(input) {
|
302
|
+
const inputValue = input.value;
|
303
|
+
return this.valuesMap.has(inputValue)
|
304
|
+
? this.valuesMap.get(inputValue)
|
305
|
+
: inputValue;
|
306
|
+
}
|
280
307
|
loadItems(url, search, headers, options, method, body) {
|
281
308
|
if (this.optionsLoaded) {
|
282
309
|
this.itemsLoadedResolve();
|
@@ -327,7 +354,7 @@ export default class RadioComponent extends ListComponent {
|
|
327
354
|
label: this.itemTemplate(item)
|
328
355
|
};
|
329
356
|
if (_.isEqual(item, this.selectData || _.pick(this.dataValue, _.keys(item)))) {
|
330
|
-
this.loadedOptions[i].value = this.dataValue;
|
357
|
+
this.loadedOptions[i].value = this.prepareValue(this.dataValue, { skipValueProperty: true });
|
331
358
|
}
|
332
359
|
});
|
333
360
|
this.optionsLoaded = true;
|
@@ -337,12 +364,15 @@ export default class RadioComponent extends ListComponent {
|
|
337
364
|
const listData = [];
|
338
365
|
items?.forEach((item, i) => {
|
339
366
|
const valueAtProperty = _.get(item, this.component.valueProperty);
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
367
|
+
const value = this.prepareValue(item);
|
368
|
+
const label = this.component.valueProperty
|
369
|
+
? this.itemTemplate(item, valueAtProperty, i)
|
370
|
+
: this.itemTemplate(item, item, i);
|
371
|
+
this.loadedOptions[i] = { label, value };
|
372
|
+
listData.push(this.templateData[i]);
|
373
|
+
if (this.valuesMap.has(value)) {
|
374
|
+
this.templateData[value] = this.templateData[i];
|
375
|
+
}
|
346
376
|
if (!this.isRadio && (_.isObject(value) || _.isBoolean(value) || _.isUndefined(value))) {
|
347
377
|
this.loadedOptions[i].invalid = true;
|
348
378
|
}
|
@@ -365,7 +395,11 @@ export default class RadioComponent extends ListComponent {
|
|
365
395
|
const value = this.dataValue;
|
366
396
|
this.refs.wrapper.forEach((wrapper, index) => {
|
367
397
|
const input = this.refs.input[index];
|
368
|
-
const checked = (value === undefined || value === null)
|
398
|
+
const checked = (value === undefined || value === null)
|
399
|
+
? false
|
400
|
+
: (input.type === 'checkbox')
|
401
|
+
? value[input.value] || input.checked
|
402
|
+
: _.isEqual(this.normalizeValue(this.getValueByInput(input)), value);
|
369
403
|
if (checked) {
|
370
404
|
//add class to container when selected
|
371
405
|
this.addClass(wrapper, this.optionSelectedClass);
|
@@ -379,10 +413,25 @@ export default class RadioComponent extends ListComponent {
|
|
379
413
|
});
|
380
414
|
}
|
381
415
|
}
|
416
|
+
setMetadata(value) {
|
417
|
+
let key = value;
|
418
|
+
if (typeof value !== 'string') {
|
419
|
+
const checkedInput = Array.prototype.find.call(this.refs.input ?? [], (input => input.type === 'radio' && input.getAttribute('checked')));
|
420
|
+
key = checkedInput?.value || key;
|
421
|
+
}
|
422
|
+
if (this.isSelectURL && this.templateData && this.templateData[key]) {
|
423
|
+
const submission = this.root.submission;
|
424
|
+
if (!submission.metadata.selectData) {
|
425
|
+
submission.metadata.selectData = {};
|
426
|
+
}
|
427
|
+
_.set(submission.metadata.selectData, this.path, this.templateData[key]);
|
428
|
+
}
|
429
|
+
}
|
382
430
|
updateValue(value, flags) {
|
383
431
|
const changed = super.updateValue(value, flags);
|
384
432
|
if (changed) {
|
385
433
|
this.setSelectedClasses();
|
434
|
+
this.setMetadata(this.dataValue);
|
386
435
|
}
|
387
436
|
if (!flags || !flags.modified || !this.isRadio) {
|
388
437
|
if (changed) {
|
@@ -438,13 +487,9 @@ export default class RadioComponent extends ListComponent {
|
|
438
487
|
value = !(!value || value.toString() === 'false');
|
439
488
|
break;
|
440
489
|
}
|
441
|
-
if (this.isSelectURL && this.templateData && this.templateData[value]) {
|
442
|
-
const submission = this.root.submission;
|
443
|
-
if (!submission.metadata.selectData) {
|
444
|
-
submission.metadata.selectData = {};
|
445
|
-
}
|
446
|
-
_.set(submission.metadata.selectData, this.path, this.templateData[value]);
|
447
|
-
}
|
448
490
|
return super.normalizeValue(value);
|
449
491
|
}
|
492
|
+
isSingleInputValue() {
|
493
|
+
return true;
|
494
|
+
}
|
450
495
|
}
|
@@ -2,7 +2,7 @@ import _ from 'lodash';
|
|
2
2
|
import { Formio } from '../../Formio';
|
3
3
|
import ListComponent from '../_classes/list/ListComponent';
|
4
4
|
import Form from '../../Form';
|
5
|
-
import { getRandomComponentId, boolValue, isPromise, componentValueTypes, getComponentSavedTypes, isSelectResourceWithObjectValue, removeHTML } from '../../utils
|
5
|
+
import { getRandomComponentId, boolValue, isPromise, componentValueTypes, getComponentSavedTypes, isSelectResourceWithObjectValue, removeHTML } from '../../utils';
|
6
6
|
import Choices from '../../utils/ChoicesWrapper';
|
7
7
|
export default class SelectComponent extends ListComponent {
|
8
8
|
static schema(...extend) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import _ from 'lodash';
|
2
|
-
import { eachComponent } from '../../../utils
|
2
|
+
import { eachComponent } from '../../../utils';
|
3
3
|
const calculateSingleSelectData = (context, defaultValue) => {
|
4
4
|
const { instance, data } = context;
|
5
5
|
const rawDefaultValue = instance.downloadedResources.find(resource => _.get(resource, data.valueProperty) === defaultValue);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import _ from 'lodash';
|
2
|
-
import { componentValueTypes, getComponentSavedTypes, boolValue, getComponent } from '../../utils
|
2
|
+
import { componentValueTypes, getComponentSavedTypes, boolValue, getComponent } from '../../utils';
|
3
3
|
import RadioComponent from '../radio/Radio';
|
4
4
|
export default class SelectBoxesComponent extends RadioComponent {
|
5
5
|
static schema(...extend) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import SignaturePad from 'signature_pad';
|
2
2
|
import Input from '../_classes/input/Input';
|
3
3
|
import _ from 'lodash';
|
4
|
-
import { componentValueTypes, getComponentSavedTypes } from '../../utils
|
4
|
+
import { componentValueTypes, getComponentSavedTypes } from '../../utils';
|
5
5
|
export default class SignatureComponent extends Input {
|
6
6
|
static schema(...extend) {
|
7
7
|
return Input.schema({
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import _ from 'lodash';
|
2
2
|
import Field from '../_classes/field/Field';
|
3
|
-
import { boolValue, componentValueTypes, getComponentSavedTypes } from '../../utils
|
3
|
+
import { boolValue, componentValueTypes, getComponentSavedTypes } from '../../utils';
|
4
4
|
export default class SurveyComponent extends Field {
|
5
5
|
static schema(...extend) {
|
6
6
|
return Field.schema({
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { componentValueTypes, getComponentSavedTypes } from '../../utils
|
1
|
+
import { componentValueTypes, getComponentSavedTypes } from '../../utils';
|
2
2
|
import Input from '../_classes/input/Input';
|
3
3
|
import Choices from 'choices.js';
|
4
4
|
export default class TagsComponent extends Input {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/* global Quill */
|
2
2
|
import TextFieldComponent from '../textfield/TextField';
|
3
3
|
import _ from 'lodash';
|
4
|
-
import { uniqueName, getBrowserInfo } from '../../utils
|
4
|
+
import { uniqueName, getBrowserInfo } from '../../utils';
|
5
5
|
export default class TextAreaComponent extends TextFieldComponent {
|
6
6
|
static schema(...extend) {
|
7
7
|
return TextFieldComponent.schema({
|
@@ -58,8 +58,8 @@ export default class TextAreaComponent extends TextFieldComponent {
|
|
58
58
|
if ((this.options.readOnly || this.disabled) && !this.isHtmlRenderMode()) {
|
59
59
|
const elementStyle = this.info.attr.style || '';
|
60
60
|
const children = `
|
61
|
-
<div ${this._referenceAttributeName}="input"
|
62
|
-
class="formio-editor-read-only-content"
|
61
|
+
<div ${this._referenceAttributeName}="input"
|
62
|
+
class="formio-editor-read-only-content"
|
63
63
|
${elementStyle ? `style='${elementStyle}'` : ''}
|
64
64
|
role="textbox"
|
65
65
|
aria-multiline="true"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import Input from '../_classes/input/Input';
|
2
2
|
import { conformToMask } from '@formio/vanilla-text-mask';
|
3
3
|
import Inputmask from 'inputmask';
|
4
|
-
import
|
4
|
+
import FormioUtils from '../../utils';
|
5
5
|
import _ from 'lodash';
|
6
6
|
export default class TextFieldComponent extends Input {
|
7
7
|
static schema(...extend) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import moment from 'moment';
|
2
2
|
import TextFieldComponent from '../textfield/TextField';
|
3
|
-
import { getBrowserInfo } from '../../utils
|
3
|
+
import { getBrowserInfo } from '../../utils';
|
4
4
|
const defaultDataFormat = 'HH:mm:ss';
|
5
5
|
export default class TimeComponent extends TextFieldComponent {
|
6
6
|
static schema(...extend) {
|
package/lib/mjs/formio.form.js
CHANGED
@@ -8,11 +8,11 @@ import Providers from './providers';
|
|
8
8
|
import Widgets from './widgets';
|
9
9
|
import Form from './Form';
|
10
10
|
import Utils from './utils';
|
11
|
-
import { Evaluator } from './utils/Evaluator';
|
12
11
|
import Licenses from './licenses';
|
13
12
|
import EventEmitter from './EventEmitter';
|
14
13
|
import Webform from './Webform';
|
15
14
|
import { I18n } from './utils/i18n';
|
15
|
+
import { Evaluator, registerEvaluator } from './utils';
|
16
16
|
Formio.loadModules = (path = `${Formio.getApiUrl()}/externalModules.js`, name = 'externalModules') => {
|
17
17
|
Formio.requireLibrary(name, name, path, true)
|
18
18
|
.then((modules) => {
|
@@ -83,7 +83,7 @@ export function registerModule(mod, defaultFn = null, options = {}) {
|
|
83
83
|
Formio.Displays.addDisplays(mod.displays);
|
84
84
|
break;
|
85
85
|
case 'evaluator':
|
86
|
-
|
86
|
+
registerEvaluator(mod.evaluator);
|
87
87
|
break;
|
88
88
|
case 'translations':
|
89
89
|
I18n.setDefaultTranslations(mod.translations);
|
package/lib/mjs/i18n.js
CHANGED
@@ -1,7 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
/**
|
2
|
+
* For backwards compatibility we a standalone interpolate function. This merely calls the
|
3
|
+
* global mutable Evaluator instance's interpolate function.
|
4
|
+
* @param {...any} args - interpolate arguments, typically "rawTemplate", "data", and "options"
|
5
|
+
* @returns {any} the interpolation result.
|
6
|
+
*/
|
7
|
+
export function interpolate(...args: any[]): any;
|
8
|
+
/**
|
9
|
+
* Set the evaluator to use for evaluating expressions.
|
10
|
+
* @param {CoreEvaluator} override - The new evaluator instance to use.
|
11
|
+
* @returns {void}
|
12
|
+
*/
|
13
|
+
export function registerEvaluator(override: CoreEvaluator): void;
|
14
|
+
export class DefaultEvaluator extends CoreEvaluator {
|
15
|
+
cache: {};
|
16
|
+
protectedEval: boolean;
|
17
|
+
template(template: any, hash: any): any;
|
18
|
+
interpolate(rawTemplate: any, data: any, _options: any): any;
|
7
19
|
}
|
20
|
+
export let Evaluator: DefaultEvaluator;
|
21
|
+
import { DefaultEvaluator as CoreEvaluator } from '@formio/core';
|
@@ -1,25 +1,24 @@
|
|
1
1
|
import _ from 'lodash';
|
2
2
|
import stringHash from 'string-hash';
|
3
|
-
import {
|
4
|
-
export class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
static template(template, hash) {
|
3
|
+
import { DefaultEvaluator as CoreEvaluator } from '@formio/core';
|
4
|
+
export class DefaultEvaluator extends CoreEvaluator {
|
5
|
+
cache = {};
|
6
|
+
protectedEval = false;
|
7
|
+
template(template, hash) {
|
9
8
|
hash = hash || stringHash(template);
|
10
|
-
if (
|
11
|
-
return
|
9
|
+
if (this.cache[hash]) {
|
10
|
+
return this.cache[hash];
|
12
11
|
}
|
13
12
|
try {
|
14
13
|
// Ensure we handle copied templates from the ejs files.
|
15
14
|
template = template.replace(/ctx\./g, '');
|
16
|
-
return (
|
15
|
+
return (this.cache[hash] = _.template(template, this.templateSettings));
|
17
16
|
}
|
18
17
|
catch (err) {
|
19
18
|
console.warn('Error while processing template', err, template);
|
20
19
|
}
|
21
20
|
}
|
22
|
-
|
21
|
+
interpolate(rawTemplate, data, _options) {
|
23
22
|
// Ensure reverse compatability.
|
24
23
|
const options = _.isObject(_options) ? _options : { noeval: _options };
|
25
24
|
if (typeof rawTemplate === 'function') {
|
@@ -33,11 +32,11 @@ export class Evaluator extends CoreEvaluator {
|
|
33
32
|
}
|
34
33
|
rawTemplate = String(rawTemplate);
|
35
34
|
let template;
|
36
|
-
if (
|
37
|
-
return
|
35
|
+
if (this.noeval || options.noeval) {
|
36
|
+
return this.interpolateString(rawTemplate, data, _options);
|
38
37
|
}
|
39
38
|
else {
|
40
|
-
template =
|
39
|
+
template = this.template(rawTemplate);
|
41
40
|
}
|
42
41
|
if (typeof template === 'function') {
|
43
42
|
try {
|
@@ -51,3 +50,22 @@ export class Evaluator extends CoreEvaluator {
|
|
51
50
|
return template;
|
52
51
|
}
|
53
52
|
}
|
53
|
+
export let Evaluator = new DefaultEvaluator();
|
54
|
+
// preserve the standalone interpolate function for backwards compatibility
|
55
|
+
/**
|
56
|
+
* For backwards compatibility we a standalone interpolate function. This merely calls the
|
57
|
+
* global mutable Evaluator instance's interpolate function.
|
58
|
+
* @param {...any} args - interpolate arguments, typically "rawTemplate", "data", and "options"
|
59
|
+
* @returns {any} the interpolation result.
|
60
|
+
*/
|
61
|
+
export function interpolate(...args) {
|
62
|
+
return Evaluator.interpolate(...args);
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* Set the evaluator to use for evaluating expressions.
|
66
|
+
* @param {CoreEvaluator} override - The new evaluator instance to use.
|
67
|
+
* @returns {void}
|
68
|
+
*/
|
69
|
+
export function registerEvaluator(override) {
|
70
|
+
Evaluator = override;
|
71
|
+
}
|
package/lib/mjs/utils/builder.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import ConditionOperator from './ConditionOperator';
|
2
2
|
import _ from 'lodash';
|
3
|
-
import { compareSelectResourceWithObjectTypeValues, isSelectResourceWithObjectValue } from '../
|
3
|
+
import { compareSelectResourceWithObjectTypeValues, isSelectResourceWithObjectValue } from '../';
|
4
4
|
export default class IsEqualTo extends ConditionOperator {
|
5
5
|
static get operatorKey() {
|
6
6
|
return 'isEqual';
|
package/lib/mjs/utils/i18n.js
CHANGED
package/lib/mjs/utils/index.d.ts
CHANGED
@@ -1,3 +1,170 @@
|
|
1
|
-
export
|
1
|
+
export * from "./utils";
|
2
|
+
export * from "./formUtils";
|
2
3
|
export default FormioUtils;
|
3
|
-
|
4
|
+
declare const FormioUtils: {
|
5
|
+
Evaluator: import("./Evaluator").DefaultEvaluator;
|
6
|
+
interpolate: typeof interpolate;
|
7
|
+
ConditionOperators: {
|
8
|
+
[x: string]: typeof import("./conditionOperators/IsEqualTo").default | typeof import("./conditionOperators/DateGreaterThan").default;
|
9
|
+
};
|
10
|
+
_: any;
|
11
|
+
moment: typeof moment;
|
12
|
+
flattenComponents: typeof import("@formio/core/lib/utils/formUtil").flattenComponents;
|
13
|
+
guid: typeof import("@formio/core/lib/utils/formUtil").guid;
|
14
|
+
uniqueName: typeof import("@formio/core/lib/utils/formUtil").uniqueName;
|
15
|
+
MODEL_TYPES_OF_KNOWN_COMPONENTS: {
|
16
|
+
nestedArray: string[];
|
17
|
+
nestedDataArray: string[];
|
18
|
+
dataObject: string[];
|
19
|
+
object: string[];
|
20
|
+
map: string[];
|
21
|
+
content: string[];
|
22
|
+
string: string[];
|
23
|
+
number: string[];
|
24
|
+
boolean: string[];
|
25
|
+
none: string[];
|
26
|
+
any: string[];
|
27
|
+
};
|
28
|
+
getModelType: typeof import("@formio/core/lib/utils/formUtil").getModelType;
|
29
|
+
getComponentPath: any;
|
30
|
+
setComponentScope: typeof import("@formio/core/lib/utils/formUtil").setComponentScope;
|
31
|
+
resetComponentScope: typeof import("@formio/core/lib/utils/formUtil").resetComponentScope;
|
32
|
+
isComponentNestedDataType: typeof import("@formio/core/lib/utils/formUtil").isComponentNestedDataType;
|
33
|
+
componentPath: typeof import("@formio/core/lib/utils/formUtil").componentPath;
|
34
|
+
getComponentPaths: typeof import("@formio/core/lib/utils/formUtil").getComponentPaths;
|
35
|
+
componentMatches: typeof import("@formio/core/lib/utils/formUtil").componentMatches;
|
36
|
+
getBestMatch: typeof import("@formio/core/lib/utils/formUtil").getBestMatch;
|
37
|
+
getComponentFromPath: typeof import("@formio/core/lib/utils/formUtil").getComponentFromPath;
|
38
|
+
getComponentValue: typeof import("@formio/core/lib/utils/formUtil").getComponentValue;
|
39
|
+
findComponents: typeof import("@formio/core/lib/utils/formUtil").findComponents;
|
40
|
+
eachComponentDataAsync: (components: import("@formio/core").Component[], data: import("@formio/core").DataObject, fn: import("@formio/core").EachComponentDataAsyncCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: import("@formio/core").Component | undefined, parentPaths?: import("@formio/core").ComponentPaths | undefined) => Promise<void>;
|
41
|
+
eachComponentData: (components: import("@formio/core").Component[], data: import("@formio/core").DataObject, fn: import("@formio/core").EachComponentDataCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: import("@formio/core").Component | undefined, parentPaths?: import("@formio/core").ComponentPaths | undefined) => void;
|
42
|
+
getComponentKey: typeof import("@formio/core/lib/utils/formUtil").getComponentKey;
|
43
|
+
getContextualRowPath: typeof import("@formio/core/lib/utils/formUtil").getContextualRowPath;
|
44
|
+
getContextualRowData: typeof import("@formio/core/lib/utils/formUtil").getContextualRowData;
|
45
|
+
componentInfo: typeof import("@formio/core/lib/utils/formUtil").componentInfo;
|
46
|
+
eachComponent: typeof import("@formio/core/lib/utils/formUtil").eachComponent;
|
47
|
+
eachComponentAsync: typeof import("@formio/core/lib/utils/formUtil").eachComponentAsync;
|
48
|
+
getComponentData: typeof import("@formio/core/lib/utils/formUtil").getComponentData;
|
49
|
+
getComponentActualValue: any;
|
50
|
+
isLayoutComponent: typeof import("@formio/core/lib/utils/formUtil").isLayoutComponent;
|
51
|
+
matchComponent: typeof import("@formio/core/lib/utils/formUtil").matchComponent;
|
52
|
+
getComponent: typeof import("@formio/core/lib/utils/formUtil").getComponent;
|
53
|
+
searchComponents: typeof import("@formio/core/lib/utils/formUtil").searchComponents;
|
54
|
+
removeComponent: typeof import("@formio/core/lib/utils/formUtil").removeComponent;
|
55
|
+
hasCondition: typeof import("@formio/core/lib/utils/formUtil").hasCondition;
|
56
|
+
parseFloatExt: typeof import("@formio/core/lib/utils/formUtil").parseFloatExt;
|
57
|
+
formatAsCurrency: typeof import("@formio/core/lib/utils/formUtil").formatAsCurrency;
|
58
|
+
escapeRegExCharacters: typeof import("@formio/core/lib/utils/formUtil").escapeRegExCharacters;
|
59
|
+
getValue: typeof import("@formio/core/lib/utils/formUtil").getValue;
|
60
|
+
getStrings: typeof import("@formio/core/lib/utils/formUtil").getStrings;
|
61
|
+
generateFormChange: typeof import("@formio/core/lib/utils/formUtil").generateFormChange;
|
62
|
+
applyFormChanges: typeof import("@formio/core/lib/utils/formUtil").applyFormChanges;
|
63
|
+
findComponent: typeof import("@formio/core/lib/utils/formUtil").findComponent;
|
64
|
+
getEmptyValue: typeof import("@formio/core/lib/utils/formUtil").getEmptyValue;
|
65
|
+
isComponentDataEmpty: typeof import("@formio/core/lib/utils/formUtil").isComponentDataEmpty;
|
66
|
+
isSelectResourceWithObjectValue: typeof import("@formio/core/lib/utils/formUtil").isSelectResourceWithObjectValue;
|
67
|
+
compareSelectResourceWithObjectTypeValues: typeof import("@formio/core/lib/utils/formUtil").compareSelectResourceWithObjectTypeValues;
|
68
|
+
getItemTemplateKeys: typeof import("@formio/core/lib/utils/formUtil").getItemTemplateKeys;
|
69
|
+
evaluate(func: string | object | Function, args: any, ret: string, interpolate: boolean, options?: import("@formio/core").EvaluatorOptions): any;
|
70
|
+
getRandomComponentId(): string;
|
71
|
+
getPropertyValue(style: CSSStyleDeclaration, prop: string): number;
|
72
|
+
getElementRect(element: HTMLElement): {
|
73
|
+
x: number;
|
74
|
+
y: number;
|
75
|
+
width: number;
|
76
|
+
height: number;
|
77
|
+
};
|
78
|
+
getScriptPlugin(property: string): any;
|
79
|
+
boolValue(value: string | boolean): boolean;
|
80
|
+
isMongoId(text: string): boolean;
|
81
|
+
checkCalculated(component: import("@formio/core").Component, submission: import("@formio/core").Submission, rowData: any): void;
|
82
|
+
checkSimpleConditional(component: any, condition: any, row: any, data: any, instance: any): boolean;
|
83
|
+
checkCustomConditional(component: import("@formio/core").Component, custom: string, row: any, data: any, form: import("@formio/core").Form, variable: string, onError: any, instance: any): any;
|
84
|
+
checkJsonConditional(component: import("@formio/core").Component, json: import("@formio/core").JSONConditional, row: any, data: any, form: import("@formio/core").Form, onError: any): boolean;
|
85
|
+
checkCondition(component: import("@formio/core").Component, row: any, data: any, form: import("@formio/core").Form, instance: any): boolean;
|
86
|
+
checkTrigger(component: import("@formio/core").Component, trigger: any, row: import("@formio/core").DataObject, data: import("@formio/core").DataObject, form: import("@formio/core").Form, instance: any): boolean;
|
87
|
+
setActionProperty(component: import("@formio/core").Component, action: any, result: string, row: import("@formio/core").DataObject, data: import("@formio/core").DataObject, instance: any): import("@formio/core").Component;
|
88
|
+
removeHTML(str: string): string;
|
89
|
+
unescapeHTML(str: string): string;
|
90
|
+
convertStringToHTMLElement(str: string, selector: string): HTMLElement;
|
91
|
+
getDateSetting(date: string | Date): import("dayjs").Dayjs | null;
|
92
|
+
isValidDate(date: string | Date): boolean;
|
93
|
+
currentTimezone(): string;
|
94
|
+
offsetDate(date: Date, timezone: string): {
|
95
|
+
date: Date;
|
96
|
+
abbr: string;
|
97
|
+
};
|
98
|
+
shouldHandleTimezone(timezone: string): boolean;
|
99
|
+
dayjsDate(value: string | Date, format: string, timezone: string, options: object): import("dayjs").Dayjs;
|
100
|
+
formatDate(value: string | Date, format: string, timezone: string, flatPickrInputFormat: string): string;
|
101
|
+
formatOffset(formatFn: Function, date: string | Date, format: string, timezone: string): string;
|
102
|
+
getLocaleDateFormatInfo(locale: Intl.LocalesArgument): object;
|
103
|
+
convertFormatToFlatpickr(format: string): string;
|
104
|
+
convertFormatToDayjs(format: string): string;
|
105
|
+
convertFormatToMask(format: string): string;
|
106
|
+
getInputMask(mask: string, placeholderChar: string): any[];
|
107
|
+
unmaskValue(value: string, mask: string, placeholderChar: string): string;
|
108
|
+
matchInputMask(value: string, inputMask: string): boolean;
|
109
|
+
getNumberSeparators(lang?: string): {
|
110
|
+
delimiter: string;
|
111
|
+
decimalSeparator: string;
|
112
|
+
};
|
113
|
+
getNumberDecimalLimit(component: import("@formio/core").Component, defaultLimit: number): number;
|
114
|
+
getCurrencyAffixes({ currency, decimalLimit, decimalSeparator, lang, }: {
|
115
|
+
currency: string;
|
116
|
+
decimalLimit: number;
|
117
|
+
decimalSeparator: string;
|
118
|
+
lang: string;
|
119
|
+
}): {
|
120
|
+
prefix: string;
|
121
|
+
suffix: string;
|
122
|
+
};
|
123
|
+
fieldData(data: import("@formio/core").DataObject, component: import("@formio/core").Component): any;
|
124
|
+
delay(fn: Function, delay?: number, ...args: any[]): any;
|
125
|
+
iterateKey(key: string): string;
|
126
|
+
uniqueKey(map: Record<string, string>, base: string): string;
|
127
|
+
bootstrapVersion(options: {
|
128
|
+
bootstrap: string;
|
129
|
+
}): number;
|
130
|
+
unfold(e: any): any;
|
131
|
+
withSwitch(a: any, b: any): Functions[];
|
132
|
+
observeOverload(callback: Function, options?: {
|
133
|
+
limit: number;
|
134
|
+
delay: number;
|
135
|
+
}): Function;
|
136
|
+
getContextComponents(context: any, excludeNested: boolean, excludedTypes?: string[]): any[];
|
137
|
+
getContextButtons(context: any): any[];
|
138
|
+
translateHTMLTemplate(template: string, translate: Function): string;
|
139
|
+
sanitize(string: string, options: any): string;
|
140
|
+
fastCloneDeep(obj: any): any;
|
141
|
+
isInputComponent(componentJson: import("@formio/core").Component): boolean;
|
142
|
+
getArrayFromComponentPath(pathStr: string): string[];
|
143
|
+
isChildOf(child: any, parent: any): boolean;
|
144
|
+
getStringFromComponentPath(path: number[]): string;
|
145
|
+
round(number: number, precision: number): string;
|
146
|
+
getIEBrowserVersion(): number | null;
|
147
|
+
getBrowserInfo(): object;
|
148
|
+
getComponentPathWithoutIndicies(path?: string): string;
|
149
|
+
getDataParentComponent(componentInstance: Component): any;
|
150
|
+
isPromise(value: any): boolean;
|
151
|
+
getFocusableElements(element: HTMLElement): NodeList<HTMLElement>;
|
152
|
+
getComponentSavedTypes(fullSchema: import("@formio/core").Component): string[] | null;
|
153
|
+
hasEncodedTimezone(value: string): boolean;
|
154
|
+
firstNonNil: any;
|
155
|
+
componentValueTypes: {
|
156
|
+
number: string;
|
157
|
+
string: string;
|
158
|
+
boolean: string;
|
159
|
+
array: string;
|
160
|
+
object: string;
|
161
|
+
date: string;
|
162
|
+
any: string;
|
163
|
+
};
|
164
|
+
interpolateErrors: (component: Component, errors: FieldError[], interpolateFn: Function) => [];
|
165
|
+
};
|
166
|
+
import { Evaluator } from './Evaluator';
|
167
|
+
import { registerEvaluator } from './Evaluator';
|
168
|
+
import { interpolate } from './Evaluator';
|
169
|
+
import moment from 'moment';
|
170
|
+
export { FormioUtils as Utils, Evaluator, registerEvaluator };
|
package/lib/mjs/utils/index.js
CHANGED
@@ -1,6 +1,23 @@
|
|
1
|
-
import * as
|
1
|
+
import * as utils from './utils';
|
2
|
+
import * as formUtils from './formUtils';
|
3
|
+
import { Evaluator, registerEvaluator, interpolate } from './Evaluator';
|
4
|
+
import ConditionOperators from './conditionOperators';
|
5
|
+
import _ from 'lodash';
|
6
|
+
import moment from 'moment';
|
7
|
+
const FormioUtils = {
|
8
|
+
...utils,
|
9
|
+
...formUtils,
|
10
|
+
Evaluator,
|
11
|
+
interpolate,
|
12
|
+
ConditionOperators,
|
13
|
+
_,
|
14
|
+
moment
|
15
|
+
};
|
2
16
|
if (typeof global === 'object') {
|
3
17
|
global.FormioUtils = FormioUtils;
|
4
18
|
}
|
5
19
|
export { FormioUtils as Utils };
|
20
|
+
export { Evaluator, registerEvaluator };
|
21
|
+
export * from './utils';
|
22
|
+
export * from './formUtils';
|
6
23
|
export default FormioUtils;
|