formeo 3.0.0 → 3.0.2
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/demo/assets/css/demo.min.css +2 -2
- package/dist/demo/assets/css/demo.min.css.gz +0 -0
- package/dist/demo/assets/css/formeo.min.css +2 -2
- package/dist/demo/assets/css/formeo.min.css.gz +0 -0
- package/dist/demo/assets/js/demo.min.js +2 -2
- package/dist/demo/assets/js/demo.min.js.gz +0 -0
- package/dist/demo/assets/js/formeo.min.js +3 -3
- package/dist/demo/assets/js/formeo.min.js.gz +0 -0
- package/dist/demo/index.html +1 -1
- package/dist/formData_schema.json +8 -4
- package/dist/formeo.cjs.js +3 -3
- package/dist/formeo.es.js +206 -99
- package/dist/formeo.min.css +2 -2
- package/dist/formeo.min.js +3 -3
- package/dist/formeo.umd.js +3 -3
- package/package.json +1 -1
package/dist/formeo.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
formeo - https://formeo.io
|
|
4
|
-
Version:
|
|
4
|
+
Version: 3.0.1
|
|
5
5
|
Author: Draggable https://draggable.io
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -434,7 +434,7 @@ if (window !== void 0) {
|
|
|
434
434
|
window.SmartTooltip = SmartTooltip;
|
|
435
435
|
}
|
|
436
436
|
const name$1 = "formeo";
|
|
437
|
-
const version$2 = "
|
|
437
|
+
const version$2 = "3.0.1";
|
|
438
438
|
const type = "module";
|
|
439
439
|
const main = "dist/formeo.cjs.js";
|
|
440
440
|
const module = "dist/formeo.es.js";
|
|
@@ -2662,6 +2662,25 @@ class Data {
|
|
|
2662
2662
|
});
|
|
2663
2663
|
__publicField(this, "setCallbacks", {});
|
|
2664
2664
|
__publicField(this, "configVal", /* @__PURE__ */ Object.create(null));
|
|
2665
|
+
/**
|
|
2666
|
+
* Parses the provided data argument. If the argument is a string, it attempts to parse it as JSON.
|
|
2667
|
+
* If the parsing fails, it logs an error and returns an empty object.
|
|
2668
|
+
* If the argument is not a string, it returns the argument as is.
|
|
2669
|
+
*
|
|
2670
|
+
* @param {string|Object} dataArg - The data to be parsed. Can be a JSON string or an object.
|
|
2671
|
+
* @returns {Object} - The parsed object or the original object if the input was not a string.
|
|
2672
|
+
*/
|
|
2673
|
+
__publicField(this, "parseformData", (dataArg = /* @__PURE__ */ Object.create(null)) => {
|
|
2674
|
+
if (typeof dataArg === "string") {
|
|
2675
|
+
try {
|
|
2676
|
+
return JSON.parse(dataArg);
|
|
2677
|
+
} catch (e) {
|
|
2678
|
+
console.error("Invalid JSON string provided:", e);
|
|
2679
|
+
return /* @__PURE__ */ Object.create(null);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
return dataArg;
|
|
2683
|
+
});
|
|
2665
2684
|
this.name = name2;
|
|
2666
2685
|
this.data = data;
|
|
2667
2686
|
this.dataPath = "";
|
|
@@ -5239,17 +5258,15 @@ function toTitleCase(str) {
|
|
|
5239
5258
|
const slugify = (str, separator = "-") => str.toString().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^a-z0-9 -]/g, "").replace(/\s+/g, separator);
|
|
5240
5259
|
const BASE_NAME = "f-autocomplete";
|
|
5241
5260
|
const HIGHLIGHT_CLASS_NAME = "highlight-component";
|
|
5242
|
-
let lastCache = Date.now();
|
|
5243
|
-
let optionsCache;
|
|
5244
5261
|
const labelCount = (arr, label) => {
|
|
5245
5262
|
const count = arr.reduce((n, x) => n + (x === label), 0);
|
|
5246
5263
|
return count > 1 ? `(${count})` : "";
|
|
5247
5264
|
};
|
|
5248
5265
|
const getComponentLabel = ({ name: name2, id, ...component }) => {
|
|
5249
|
-
const labelPaths = ["config.label", "
|
|
5266
|
+
const labelPaths = ["config.label", "config.controlId", "meta.id", "attrs.id"];
|
|
5250
5267
|
const label = labelPaths.reduce((acc, cur) => {
|
|
5251
5268
|
if (!acc) {
|
|
5252
|
-
|
|
5269
|
+
return component.get(cur);
|
|
5253
5270
|
}
|
|
5254
5271
|
return acc;
|
|
5255
5272
|
}, null);
|
|
@@ -5294,7 +5311,15 @@ const componentOptions = (selectedId) => {
|
|
|
5294
5311
|
return options.filter(Boolean);
|
|
5295
5312
|
};
|
|
5296
5313
|
class Autocomplete {
|
|
5314
|
+
/**
|
|
5315
|
+
* Create an Autocomplete instance
|
|
5316
|
+
* @param {String} key - The key for the autocomplete instance
|
|
5317
|
+
* @param {String} value - The initial value for the autocomplete input
|
|
5318
|
+
* @param {String} i18nKey - The internationalization key for the autocomplete
|
|
5319
|
+
*/
|
|
5297
5320
|
constructor(key, value, i18nKey) {
|
|
5321
|
+
__publicField(this, "lastCache", Date.now());
|
|
5322
|
+
__publicField(this, "optionsCache", null);
|
|
5298
5323
|
this.key = key;
|
|
5299
5324
|
this.className = key.replace(/\./g, "-");
|
|
5300
5325
|
this.value = value;
|
|
@@ -5389,6 +5414,7 @@ class Autocomplete {
|
|
|
5389
5414
|
const value = evt.target.value.trim();
|
|
5390
5415
|
this.hiddenField.value = value;
|
|
5391
5416
|
this.value = value;
|
|
5417
|
+
this.setValue({ dataset: { label: value, value } });
|
|
5392
5418
|
}
|
|
5393
5419
|
};
|
|
5394
5420
|
this.displayField = dom.create({
|
|
@@ -5411,31 +5437,31 @@ class Autocomplete {
|
|
|
5411
5437
|
attrs: { className: `${BASE_NAME}-list` }
|
|
5412
5438
|
});
|
|
5413
5439
|
this.dom = dom.create({
|
|
5414
|
-
children: [this.displayField, this.hiddenField
|
|
5440
|
+
children: [this.displayField, this.hiddenField],
|
|
5415
5441
|
className: this.className,
|
|
5416
5442
|
action: {
|
|
5417
|
-
onRender: () => {
|
|
5443
|
+
onRender: (element) => {
|
|
5444
|
+
this.stage = element.closest(".formeo-stage");
|
|
5418
5445
|
const component = this.value && components.getAddress(this.value);
|
|
5419
5446
|
this.label = component && getComponentLabel(component);
|
|
5420
5447
|
if (this.label) {
|
|
5421
5448
|
this.displayField.value = this.label;
|
|
5422
5449
|
}
|
|
5423
|
-
this.updateOptions();
|
|
5424
5450
|
}
|
|
5425
5451
|
}
|
|
5426
5452
|
});
|
|
5427
5453
|
return this.dom;
|
|
5428
5454
|
}
|
|
5429
5455
|
updateOptions() {
|
|
5456
|
+
let options = this.optionsCache;
|
|
5430
5457
|
const now = Date.now();
|
|
5431
|
-
if (now - lastCache > ANIMATION_SPEED_SLOW) {
|
|
5458
|
+
if (!options || now - this.lastCache > ANIMATION_SPEED_SLOW * 10) {
|
|
5432
5459
|
dom.empty(this.list);
|
|
5433
|
-
this.generateOptions();
|
|
5434
|
-
lastCache = now;
|
|
5460
|
+
options = this.generateOptions();
|
|
5461
|
+
this.lastCache = now;
|
|
5435
5462
|
}
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
this.list.appendChild(option2);
|
|
5463
|
+
if (!this.list.children.length) {
|
|
5464
|
+
this.list.append(...options);
|
|
5439
5465
|
}
|
|
5440
5466
|
}
|
|
5441
5467
|
generateOptions() {
|
|
@@ -5447,7 +5473,7 @@ class Autocomplete {
|
|
|
5447
5473
|
}
|
|
5448
5474
|
return target;
|
|
5449
5475
|
};
|
|
5450
|
-
optionsCache = options.map((optionData) => {
|
|
5476
|
+
this.optionsCache = options.map((optionData) => {
|
|
5451
5477
|
const { value, textLabel, htmlLabel } = optionData;
|
|
5452
5478
|
const optionConfig = {
|
|
5453
5479
|
tag: "li",
|
|
@@ -5473,15 +5499,19 @@ class Autocomplete {
|
|
|
5473
5499
|
};
|
|
5474
5500
|
return dom.create(optionConfig);
|
|
5475
5501
|
});
|
|
5476
|
-
return optionsCache;
|
|
5477
|
-
}
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5502
|
+
return this.optionsCache;
|
|
5503
|
+
}
|
|
5504
|
+
setListPosition() {
|
|
5505
|
+
const { offsetHeight, offsetWidth } = this.displayField;
|
|
5506
|
+
const containerRect = this.displayField.closest(".formeo-stage").getBoundingClientRect();
|
|
5507
|
+
const triggerRect = this.displayField.getBoundingClientRect();
|
|
5508
|
+
const listStyle = {
|
|
5509
|
+
position: "absolute",
|
|
5510
|
+
top: `${triggerRect.y + offsetHeight + window.scrollY - containerRect.y}px`,
|
|
5511
|
+
left: `${triggerRect.x + window.scrollX - containerRect.x}px`,
|
|
5512
|
+
width: `${offsetWidth + 1}px`
|
|
5513
|
+
};
|
|
5514
|
+
Object.assign(this.list.style, listStyle);
|
|
5485
5515
|
}
|
|
5486
5516
|
/**
|
|
5487
5517
|
* Shows autocomplete list. Automatically selects 'selectedOption'
|
|
@@ -5489,17 +5519,32 @@ class Autocomplete {
|
|
|
5489
5519
|
* @param {Object} selectedOption - option to be selected
|
|
5490
5520
|
*/
|
|
5491
5521
|
showList(selectedOption, list = this.list) {
|
|
5522
|
+
if (!this.stage.contains(this.list)) {
|
|
5523
|
+
this.stage.appendChild(this.list);
|
|
5524
|
+
}
|
|
5525
|
+
this.setListPosition();
|
|
5492
5526
|
this.selectOption(selectedOption);
|
|
5493
5527
|
animate.slideDown(list, ANIMATION_SPEED_FAST);
|
|
5494
5528
|
}
|
|
5529
|
+
/**
|
|
5530
|
+
* Hides autocomplete list and deselects all the options
|
|
5531
|
+
* @param {Object} list - list of autocomplete options
|
|
5532
|
+
*/
|
|
5533
|
+
hideList(list = this.list) {
|
|
5534
|
+
animate.slideUp(list, ANIMATION_SPEED_FAST);
|
|
5535
|
+
this.removeHighlight();
|
|
5536
|
+
if (this.stage.contains(this.list)) {
|
|
5537
|
+
this.stage.removeChild(this.list);
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5495
5540
|
/**
|
|
5496
5541
|
* Returns first option from autocomplete list with 'active-option' class
|
|
5497
5542
|
* @param {Object} list - list of autocomplete options
|
|
5498
5543
|
* @return {Object} first list option with 'active-option' class
|
|
5499
5544
|
*/
|
|
5500
5545
|
getActiveOption(list = this.list) {
|
|
5501
|
-
const activeOption = list.
|
|
5502
|
-
if (activeOption
|
|
5546
|
+
const activeOption = list.querySelector(".active-option");
|
|
5547
|
+
if ((activeOption == null ? void 0 : activeOption.style.display) !== "none") {
|
|
5503
5548
|
return activeOption;
|
|
5504
5549
|
}
|
|
5505
5550
|
return null;
|
|
@@ -5853,10 +5898,9 @@ class EditPanelItem {
|
|
|
5853
5898
|
return field2;
|
|
5854
5899
|
};
|
|
5855
5900
|
const conditionChangeAction = ({ target }) => {
|
|
5856
|
-
const
|
|
5901
|
+
const conditionRow = target.closest(".f-condition-row");
|
|
5857
5902
|
const regex = new RegExp(`${target.className}(?:\\S?)+`, "gm");
|
|
5858
|
-
|
|
5859
|
-
row.classList.add([target.className, target.value].filter(Boolean).join("-"));
|
|
5903
|
+
conditionRow.className = conditionRow.className.replace(regex, "");
|
|
5860
5904
|
const evtData = {
|
|
5861
5905
|
dataPath,
|
|
5862
5906
|
value: target.value,
|
|
@@ -5864,7 +5908,6 @@ class EditPanelItem {
|
|
|
5864
5908
|
};
|
|
5865
5909
|
events.formeoUpdated(evtData);
|
|
5866
5910
|
components.setAddress(dataPath, target.value);
|
|
5867
|
-
const conditionRow = target.closest(".f-condition-row");
|
|
5868
5911
|
const rowIndex = indexOfNode(conditionRow);
|
|
5869
5912
|
this.processConditionUIState(this.itemFieldGroups[rowIndex]);
|
|
5870
5913
|
};
|
|
@@ -6006,7 +6049,8 @@ class EditPanel {
|
|
|
6006
6049
|
* @param {String} attr
|
|
6007
6050
|
* @param {String|Array} val
|
|
6008
6051
|
*/
|
|
6009
|
-
__publicField(this, "addAttribute", (attr,
|
|
6052
|
+
__publicField(this, "addAttribute", (attr, valArg) => {
|
|
6053
|
+
let val = valArg;
|
|
6010
6054
|
const safeAttr = slugify(attr);
|
|
6011
6055
|
const itemKey = `attrs.${safeAttr}`;
|
|
6012
6056
|
if (!mi18n.current[itemKey]) {
|
|
@@ -6029,15 +6073,15 @@ class EditPanel {
|
|
|
6029
6073
|
* Add option to options panel
|
|
6030
6074
|
*/
|
|
6031
6075
|
__publicField(this, "addOption", () => {
|
|
6032
|
-
const
|
|
6076
|
+
const controlId = this.field.data.config.controlId;
|
|
6033
6077
|
const fieldOptionData = this.field.get("options");
|
|
6034
|
-
const type2 =
|
|
6078
|
+
const type2 = controlId === "select" ? "option" : controlId;
|
|
6035
6079
|
const newOptionLabel = mi18n.get("newOptionLabel", { type: type2 }) || "New Option";
|
|
6036
6080
|
const itemKey = `options.${this.data.length}`;
|
|
6037
6081
|
const lastOptionData = fieldOptionData[fieldOptionData.length - 1];
|
|
6038
6082
|
const optionTemplate = fieldOptionData.length ? lastOptionData : {};
|
|
6039
6083
|
const itemData = { ...optionTemplate, label: newOptionLabel };
|
|
6040
|
-
if (
|
|
6084
|
+
if (controlId !== "button") {
|
|
6041
6085
|
itemData.value = slugify(newOptionLabel);
|
|
6042
6086
|
}
|
|
6043
6087
|
const newOption = new EditPanelItem({
|
|
@@ -6551,6 +6595,7 @@ class Component extends Data {
|
|
|
6551
6595
|
}
|
|
6552
6596
|
/**
|
|
6553
6597
|
* Method for handling onAdd for all components
|
|
6598
|
+
* @todo improve readability of this method
|
|
6554
6599
|
* @param {Object} evt
|
|
6555
6600
|
* @return {Object} Component
|
|
6556
6601
|
*/
|
|
@@ -6592,10 +6637,13 @@ class Component extends Data {
|
|
|
6592
6637
|
]);
|
|
6593
6638
|
const onAddConditions = {
|
|
6594
6639
|
controls: () => {
|
|
6595
|
-
const { controlData } = Controls$2.get(item.id);
|
|
6596
6640
|
const {
|
|
6597
|
-
|
|
6598
|
-
|
|
6641
|
+
controlData: {
|
|
6642
|
+
meta: { id: metaId },
|
|
6643
|
+
...elementData
|
|
6644
|
+
}
|
|
6645
|
+
} = Controls$2.get(item.id);
|
|
6646
|
+
set(elementData, "config.controlId", metaId);
|
|
6599
6647
|
const controlType = metaId.startsWith("layout-") ? metaId.replace(/^layout-/, "") : "field";
|
|
6600
6648
|
const targets = {
|
|
6601
6649
|
stage: {
|
|
@@ -6618,7 +6666,7 @@ class Component extends Data {
|
|
|
6618
6666
|
const depth = get(targets, `${this.name}.${controlType}`);
|
|
6619
6667
|
const action = depthMap.get(depth)();
|
|
6620
6668
|
dom.remove(item);
|
|
6621
|
-
const component2 = action(
|
|
6669
|
+
const component2 = action(elementData, newIndex2);
|
|
6622
6670
|
return component2;
|
|
6623
6671
|
},
|
|
6624
6672
|
row: () => {
|
|
@@ -6668,10 +6716,23 @@ class Component extends Data {
|
|
|
6668
6716
|
}
|
|
6669
6717
|
events2.onRender && dom.onRender(this.dom, events2.onRender);
|
|
6670
6718
|
}
|
|
6719
|
+
/**
|
|
6720
|
+
* Sets the configuration for the component. See src/demo/js/options/config.js for example
|
|
6721
|
+
* @param {Object} config - Configuration object with possible structures:
|
|
6722
|
+
* @param {Object} [config.all] - Global configuration applied to all components
|
|
6723
|
+
* @param {Object} [config[controlId]] - Configuration specific to a control type
|
|
6724
|
+
* @param {Object} [config[id]] - Configuration specific to a component instance
|
|
6725
|
+
* @description Merges configurations in order of precedence:
|
|
6726
|
+
* 1. Existing config (this.configVal)
|
|
6727
|
+
* 2. Global config (all)
|
|
6728
|
+
* 3. Control type specific config
|
|
6729
|
+
* 4. Instance specific config
|
|
6730
|
+
* The merged result is stored in this.configVal
|
|
6731
|
+
*/
|
|
6671
6732
|
set config(config2) {
|
|
6672
|
-
const metaId = get(this.data, "meta.id");
|
|
6673
6733
|
const allConfig = get(config2, "all");
|
|
6674
|
-
const
|
|
6734
|
+
const controlId = get(this.data, "config.controlId");
|
|
6735
|
+
const typeConfig = controlId && get(config2, controlId);
|
|
6675
6736
|
const idConfig = get(config2, this.id);
|
|
6676
6737
|
const mergedConfig = [allConfig, typeConfig, idConfig].reduce(
|
|
6677
6738
|
(acc, cur) => cur ? merge(acc, cur) : acc,
|
|
@@ -6838,7 +6899,7 @@ class Field extends Component {
|
|
|
6838
6899
|
get labelConfig() {
|
|
6839
6900
|
const hideLabel = !!this.get("config.hideLabel");
|
|
6840
6901
|
if (hideLabel) {
|
|
6841
|
-
return;
|
|
6902
|
+
return null;
|
|
6842
6903
|
}
|
|
6843
6904
|
const labelVal = this.get("config.editorLabel") || this.get("config.label");
|
|
6844
6905
|
const required = this.get("attrs.required");
|
|
@@ -6990,7 +7051,7 @@ class Field extends Component {
|
|
|
6990
7051
|
fieldPreview() {
|
|
6991
7052
|
var _a;
|
|
6992
7053
|
const prevData = clone$1(this.data);
|
|
6993
|
-
const { action = {} } = Controls$2.get(prevData.
|
|
7054
|
+
const { action = {} } = Controls$2.get(prevData.config.controlId);
|
|
6994
7055
|
prevData.id = `prev-${this.id}`;
|
|
6995
7056
|
prevData.action = action;
|
|
6996
7057
|
if ((_a = this.data) == null ? void 0 : _a.config.editableContent) {
|
|
@@ -7673,21 +7734,25 @@ const defaultElements = [...formControls, ...htmlControls, ...layoutControls];
|
|
|
7673
7734
|
let Controls$1 = class Controls {
|
|
7674
7735
|
constructor() {
|
|
7675
7736
|
__publicField(this, "groupLabel", (key) => mi18n.get(key) || key || "");
|
|
7737
|
+
__publicField(this, "layoutTypes", {
|
|
7738
|
+
row: () => Stages2.active.addChild(),
|
|
7739
|
+
column: () => this.layoutTypes.row().addChild(),
|
|
7740
|
+
field: (controlData) => this.layoutTypes.column().addChild(controlData)
|
|
7741
|
+
});
|
|
7676
7742
|
/**
|
|
7677
7743
|
* Append an element to the stage
|
|
7678
7744
|
* @param {String} id of elements
|
|
7679
7745
|
*/
|
|
7680
7746
|
__publicField(this, "addElement", (id) => {
|
|
7681
|
-
const controlData = get(this.get(id), "controlData");
|
|
7682
7747
|
const {
|
|
7683
|
-
meta: { group, id: metaId }
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
}
|
|
7690
|
-
return
|
|
7748
|
+
meta: { group, id: metaId },
|
|
7749
|
+
...elementData
|
|
7750
|
+
} = get(this.get(id), "controlData");
|
|
7751
|
+
set(elementData, "config.controlId", metaId);
|
|
7752
|
+
if (group === "layout") {
|
|
7753
|
+
return this.layoutTypes[metaId.replace("layout-", "")]();
|
|
7754
|
+
}
|
|
7755
|
+
return this.layoutTypes.field(elementData);
|
|
7691
7756
|
});
|
|
7692
7757
|
__publicField(this, "applyOptions", async (controlOptions = {}) => {
|
|
7693
7758
|
const { container, elements, groupOrder, ...options } = merge(defaultOptions, controlOptions);
|
|
@@ -7767,16 +7832,16 @@ let Controls$1 = class Controls {
|
|
|
7767
7832
|
elements = orderObjectsBy(elements, group.elementOrder, "meta.id");
|
|
7768
7833
|
groupConfig.content = elements.filter((control) => {
|
|
7769
7834
|
const { controlData: field } = this.get(control.id);
|
|
7770
|
-
const
|
|
7835
|
+
const controlId = field.meta.id || "";
|
|
7771
7836
|
const filters = [
|
|
7772
|
-
match(
|
|
7837
|
+
match(controlId, this.options.disable.elements),
|
|
7773
7838
|
field.meta.group === group.id,
|
|
7774
|
-
!usedElementIds.includes(
|
|
7839
|
+
!usedElementIds.includes(controlId)
|
|
7775
7840
|
];
|
|
7776
7841
|
let shouldFilter = true;
|
|
7777
7842
|
shouldFilter = filters.every((val) => val === true);
|
|
7778
7843
|
if (shouldFilter) {
|
|
7779
|
-
usedElementIds.push(
|
|
7844
|
+
usedElementIds.push(controlId);
|
|
7780
7845
|
}
|
|
7781
7846
|
return shouldFilter;
|
|
7782
7847
|
});
|
|
@@ -7970,15 +8035,28 @@ const Controls$2 = new Controls$1();
|
|
|
7970
8035
|
class ComponentData extends Data {
|
|
7971
8036
|
constructor() {
|
|
7972
8037
|
super(...arguments);
|
|
7973
|
-
__publicField(this, "load", (
|
|
8038
|
+
__publicField(this, "load", (dataArg) => {
|
|
8039
|
+
const data = this.parseformData(dataArg);
|
|
7974
8040
|
this.empty();
|
|
7975
|
-
|
|
7976
|
-
|
|
8041
|
+
for (const [key, val] of Object.entries(data)) {
|
|
8042
|
+
this.add(key, val);
|
|
7977
8043
|
}
|
|
7978
|
-
Object.entries(data).forEach(([key, val]) => this.add(key, val));
|
|
7979
8044
|
return this.data;
|
|
7980
8045
|
});
|
|
8046
|
+
/**
|
|
8047
|
+
* Retrieves data from the specified path or adds new data if no path is provided.
|
|
8048
|
+
*
|
|
8049
|
+
* @param {string} [path] - The path to retrieve data from. If not provided, new data will be added.
|
|
8050
|
+
* @returns {*} The data retrieved from the specified path or the result of adding new data.
|
|
8051
|
+
*/
|
|
7981
8052
|
__publicField(this, "get", (path) => path ? get(this.data, path) : this.add());
|
|
8053
|
+
/**
|
|
8054
|
+
* Adds a new component with the given id and data.
|
|
8055
|
+
*
|
|
8056
|
+
* @param {string} id - The unique identifier for the component. If not provided, a new UUID will be generated.
|
|
8057
|
+
* @param {Object} [data=Object.create(null)] - The data to initialize the component with.
|
|
8058
|
+
* @returns {Object} The newly created component.
|
|
8059
|
+
*/
|
|
7982
8060
|
__publicField(this, "add", (id, data = /* @__PURE__ */ Object.create(null)) => {
|
|
7983
8061
|
const elemId = id || uuid();
|
|
7984
8062
|
const component = this.Component({ ...data, id: elemId });
|
|
@@ -7992,14 +8070,20 @@ class ComponentData extends Data {
|
|
|
7992
8070
|
*/
|
|
7993
8071
|
__publicField(this, "remove", (componentId) => {
|
|
7994
8072
|
if (Array.isArray(componentId)) {
|
|
7995
|
-
|
|
8073
|
+
for (const id of componentId) {
|
|
7996
8074
|
this.get(id).remove();
|
|
7997
|
-
}
|
|
8075
|
+
}
|
|
7998
8076
|
} else {
|
|
7999
8077
|
this.get(componentId).remove();
|
|
8000
8078
|
}
|
|
8001
8079
|
return this.data;
|
|
8002
8080
|
});
|
|
8081
|
+
/**
|
|
8082
|
+
* Deletes a component from the data object.
|
|
8083
|
+
*
|
|
8084
|
+
* @param {string} componentId - The ID of the component to delete.
|
|
8085
|
+
* @returns {string} The ID of the deleted component.
|
|
8086
|
+
*/
|
|
8003
8087
|
__publicField(this, "delete", (componentId) => {
|
|
8004
8088
|
delete this.data[componentId];
|
|
8005
8089
|
return componentId;
|
|
@@ -8719,6 +8803,18 @@ let Fields$1 = class Fields extends ComponentData {
|
|
|
8719
8803
|
return acc;
|
|
8720
8804
|
}, {});
|
|
8721
8805
|
});
|
|
8806
|
+
__publicField(this, "load", (dataArg = /* @__PURE__ */ Object.create(null)) => {
|
|
8807
|
+
const allFieldData = this.parseformData(dataArg);
|
|
8808
|
+
this.empty();
|
|
8809
|
+
for (const [key, val] of Object.entries(allFieldData)) {
|
|
8810
|
+
const { meta, ...data } = val;
|
|
8811
|
+
if (meta == null ? void 0 : meta.id) {
|
|
8812
|
+
set(data, "config.controlId", meta == null ? void 0 : meta.id);
|
|
8813
|
+
}
|
|
8814
|
+
this.add(key, data);
|
|
8815
|
+
}
|
|
8816
|
+
return this.data;
|
|
8817
|
+
});
|
|
8722
8818
|
this.config = { all: DEFAULT_CONFIG };
|
|
8723
8819
|
}
|
|
8724
8820
|
Component(data) {
|
|
@@ -9600,6 +9696,8 @@ const defaults = {
|
|
|
9600
9696
|
// loads csspreloadrel
|
|
9601
9697
|
i18n: {
|
|
9602
9698
|
location: "https://draggable.github.io/formeo/assets/lang/"
|
|
9699
|
+
},
|
|
9700
|
+
onLoad: () => {
|
|
9603
9701
|
}
|
|
9604
9702
|
};
|
|
9605
9703
|
}
|
|
@@ -9641,7 +9739,7 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
9641
9739
|
* @return {Promise} asynchronously loaded remote resources
|
|
9642
9740
|
*/
|
|
9643
9741
|
async loadResources() {
|
|
9644
|
-
var _a;
|
|
9742
|
+
var _a, _b, _c;
|
|
9645
9743
|
document.removeEventListener("DOMContentLoaded", this.loadResources);
|
|
9646
9744
|
const promises = [];
|
|
9647
9745
|
if (this.opts.polyfills) {
|
|
@@ -9650,10 +9748,11 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
9650
9748
|
await fetchIcons(this.opts.svgSprite);
|
|
9651
9749
|
promises.push(fetchFormeoStyle(this.opts.style));
|
|
9652
9750
|
promises.push(mi18n.init({ ...this.opts.i18n, locale: (_a = window.sessionStorage) == null ? void 0 : _a.getItem(SESSION_LOCALE_KEY) }));
|
|
9653
|
-
const resolvedPromises = await Promise.all(promises);
|
|
9654
9751
|
if (this.opts.allowEdit) {
|
|
9655
|
-
this.init();
|
|
9752
|
+
promises.push(this.init());
|
|
9656
9753
|
}
|
|
9754
|
+
const resolvedPromises = await Promise.all(promises);
|
|
9755
|
+
(_c = (_b = this.opts).onLoad) == null ? void 0 : _c.call(_b, this);
|
|
9657
9756
|
return resolvedPromises;
|
|
9658
9757
|
}
|
|
9659
9758
|
/**
|
|
@@ -9662,7 +9761,7 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
9662
9761
|
* dom elements, actions events and more.
|
|
9663
9762
|
*/
|
|
9664
9763
|
init() {
|
|
9665
|
-
Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
|
|
9764
|
+
return Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
|
|
9666
9765
|
this.controls = controls;
|
|
9667
9766
|
this.load(this.userFormData, this.opts);
|
|
9668
9767
|
this.formId = components.get("id");
|
|
@@ -9857,51 +9956,59 @@ let FormeoRenderer$1 = class FormeoRenderer {
|
|
|
9857
9956
|
(column) => this.cacheComponent(this.processColumn(column))
|
|
9858
9957
|
);
|
|
9859
9958
|
});
|
|
9860
|
-
__publicField(this, "
|
|
9861
|
-
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
-
|
|
9870
|
-
}
|
|
9871
|
-
const mergedFieldData = merge({ action }, field);
|
|
9872
|
-
return this.cacheComponent({ ...mergedFieldData, id: this.prefixId(id) });
|
|
9873
|
-
});
|
|
9874
|
-
});
|
|
9959
|
+
__publicField(this, "processFields", (fieldIds) => this.orderChildren("fields", fieldIds).map(({ id, ...field }) => {
|
|
9960
|
+
var _a, _b;
|
|
9961
|
+
const controlId = ((_a = field.config) == null ? void 0 : _a.controlId) || ((_b = field.meta) == null ? void 0 : _b.id);
|
|
9962
|
+
const { action = {}, dependencies: dependencies2 = {} } = this.elements[controlId] || {};
|
|
9963
|
+
if (dependencies2) {
|
|
9964
|
+
fetchDependencies(dependencies2);
|
|
9965
|
+
}
|
|
9966
|
+
const mergedFieldData = merge({ action }, field);
|
|
9967
|
+
return this.cacheComponent({ ...mergedFieldData, id: this.prefixId(id) });
|
|
9968
|
+
}));
|
|
9875
9969
|
/**
|
|
9876
9970
|
* Evaulate and execute conditions for fields by creating listeners for input and changes
|
|
9877
9971
|
* @return {Array} flattened array of conditions
|
|
9878
9972
|
*/
|
|
9973
|
+
__publicField(this, "handleComponentCondition", (component, ifRest, thenConditions) => {
|
|
9974
|
+
const listenerEvent = LISTEN_TYPE_MAP(component);
|
|
9975
|
+
if (listenerEvent) {
|
|
9976
|
+
component.addEventListener(
|
|
9977
|
+
listenerEvent,
|
|
9978
|
+
(evt) => {
|
|
9979
|
+
if (this.evaluateCondition(ifRest, evt)) {
|
|
9980
|
+
for (const thenCondition of thenConditions) {
|
|
9981
|
+
this.execResult(thenCondition, evt);
|
|
9982
|
+
}
|
|
9983
|
+
}
|
|
9984
|
+
},
|
|
9985
|
+
false
|
|
9986
|
+
);
|
|
9987
|
+
}
|
|
9988
|
+
const fakeEvt = { target: component };
|
|
9989
|
+
if (this.evaluateCondition(ifRest, fakeEvt)) {
|
|
9990
|
+
for (const thenCondition of thenConditions) {
|
|
9991
|
+
this.execResult(thenCondition, fakeEvt);
|
|
9992
|
+
}
|
|
9993
|
+
}
|
|
9994
|
+
});
|
|
9879
9995
|
__publicField(this, "applyConditions", () => {
|
|
9880
|
-
Object.values(this.components)
|
|
9996
|
+
for (const { conditions } of Object.values(this.components)) {
|
|
9881
9997
|
if (conditions) {
|
|
9882
|
-
|
|
9998
|
+
for (const condition of conditions) {
|
|
9883
9999
|
const { if: ifConditions, then: thenConditions } = condition;
|
|
9884
|
-
|
|
10000
|
+
for (const ifCondition of ifConditions) {
|
|
9885
10001
|
const { source, ...ifRest } = ifCondition;
|
|
9886
10002
|
if (isAddress(source)) {
|
|
9887
10003
|
const components2 = this.getComponents(source);
|
|
9888
|
-
|
|
9889
|
-
|
|
9890
|
-
|
|
9891
|
-
component.addEventListener(
|
|
9892
|
-
listenerEvent,
|
|
9893
|
-
(evt) => this.evaluateCondition(ifRest, evt) && thenConditions.forEach((thenCondition) => this.execResult(thenCondition, evt)),
|
|
9894
|
-
false
|
|
9895
|
-
);
|
|
9896
|
-
}
|
|
9897
|
-
const fakeEvt = { target: component };
|
|
9898
|
-
this.evaluateCondition(ifRest, fakeEvt) && thenConditions.forEach((thenCondition) => this.execResult(thenCondition, fakeEvt));
|
|
9899
|
-
});
|
|
10004
|
+
for (const component of components2) {
|
|
10005
|
+
this.handleComponentCondition(component, ifRest, thenConditions);
|
|
10006
|
+
}
|
|
9900
10007
|
}
|
|
9901
|
-
}
|
|
9902
|
-
}
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
9903
10010
|
}
|
|
9904
|
-
}
|
|
10011
|
+
}
|
|
9905
10012
|
});
|
|
9906
10013
|
/**
|
|
9907
10014
|
* Evaulate conditions
|