formeo 4.0.0 → 4.1.1

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.
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 3.1.4
4
+ Version: 4.1.0
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -9,6 +9,7 @@ Author: Draggable https://draggable.io
9
9
  var __defProp = Object.defineProperty;
10
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
11
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
+ var _a;
12
13
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
13
14
  async function fetchData(url) {
14
15
  try {
@@ -86,8 +87,8 @@ class I18N {
86
87
  * @return {String} language string or undefined
87
88
  */
88
89
  getValue(key, locale = this.locale) {
89
- var _a;
90
- const value = (_a = this.langs[locale]) == null ? void 0 : _a[key];
90
+ var _a2;
91
+ const value = (_a2 = this.langs[locale]) == null ? void 0 : _a2[key];
91
92
  return value || this.getFallbackValue(key);
92
93
  }
93
94
  /**
@@ -436,7 +437,7 @@ if (window !== void 0) {
436
437
  window.SmartTooltip = SmartTooltip;
437
438
  }
438
439
  const name$1 = "formeo";
439
- const version$2 = "3.1.4";
440
+ const version$2 = "4.1.0";
440
441
  const type = "module";
441
442
  const main = "dist/formeo.cjs.js";
442
443
  const module$1 = "dist/formeo.es.js";
@@ -567,7 +568,7 @@ const dependencies = {
567
568
  sortablejs: "^1.15.3"
568
569
  };
569
570
  const release = {
570
- branch: "master",
571
+ branch: "main",
571
572
  verifyConditions: [
572
573
  "@semantic-release/changelog",
573
574
  "@semantic-release/npm",
@@ -1557,14 +1558,14 @@ const remove = (arr, val) => {
1557
1558
  }
1558
1559
  };
1559
1560
  const componentType = (node) => {
1560
- var _a;
1561
- const classMatch = (_a = node.className) == null ? void 0 : _a.match(COMPONENT_TYPE_CLASSNAMES_REGEXP);
1561
+ var _a2;
1562
+ const classMatch = (_a2 = node.className) == null ? void 0 : _a2.match(COMPONENT_TYPE_CLASSNAMES_REGEXP);
1562
1563
  return classMatch && COMPONENT_TYPE_CLASSNAMES_LOOKUP[classMatch[0]];
1563
1564
  };
1564
1565
  const unique = (array) => Array.from(new Set(array));
1565
1566
  const uuid = (elem) => {
1566
- var _a;
1567
- return ((_a = elem == null ? void 0 : elem.attrs) == null ? void 0 : _a.id) || (elem == null ? void 0 : elem.id) || shortId();
1567
+ var _a2;
1568
+ return ((_a2 = elem == null ? void 0 : elem.attrs) == null ? void 0 : _a2.id) || (elem == null ? void 0 : elem.id) || shortId();
1568
1569
  };
1569
1570
  const merge = (obj1, obj2) => {
1570
1571
  const customizer = (objValue, srcValue) => {
@@ -1618,8 +1619,8 @@ const numToPercent = (num) => `${num.toString()}%`;
1618
1619
  const sessionStorage = Object.create(null, {
1619
1620
  get: {
1620
1621
  value: (key) => {
1621
- var _a;
1622
- const itemValue = (_a = window.sessionStorage) == null ? void 0 : _a.getItem(key);
1622
+ var _a2;
1623
+ const itemValue = (_a2 = window.sessionStorage) == null ? void 0 : _a2.getItem(key);
1623
1624
  try {
1624
1625
  return JSON.parse(itemValue);
1625
1626
  } catch (_err) {
@@ -1629,9 +1630,9 @@ const sessionStorage = Object.create(null, {
1629
1630
  },
1630
1631
  set: {
1631
1632
  value: (key, itemValue) => {
1632
- var _a;
1633
+ var _a2;
1633
1634
  try {
1634
- return (_a = window.sessionStorage) == null ? void 0 : _a.setItem(key, JSON.stringify(itemValue));
1635
+ return (_a2 = window.sessionStorage) == null ? void 0 : _a2.setItem(key, JSON.stringify(itemValue));
1635
1636
  } catch (error) {
1636
1637
  console.error(error);
1637
1638
  }
@@ -1681,7 +1682,7 @@ function parseData(data = /* @__PURE__ */ Object.create(null)) {
1681
1682
  }
1682
1683
  const cleanFormData = (formData) => formData ? clone$1(parseData(formData)) : DEFAULT_FORMDATA();
1683
1684
  function buildFlatDataStructure(data, componentId, componentType2, result = {}) {
1684
- var _a;
1685
+ var _a2;
1685
1686
  if (!componentId || !data[componentType2][componentId]) {
1686
1687
  return result;
1687
1688
  }
@@ -1689,7 +1690,7 @@ function buildFlatDataStructure(data, componentId, componentType2, result = {})
1689
1690
  result[key] = data[componentType2][componentId];
1690
1691
  const childType = CHILD_TYPE_INDEX_MAP.get(componentType2);
1691
1692
  if (childType) {
1692
- const childrenIds = ((_a = data[componentType2][componentId].data) == null ? void 0 : _a.children) || [];
1693
+ const childrenIds = ((_a2 = data[componentType2][componentId].data) == null ? void 0 : _a2.children) || [];
1693
1694
  for (const childId of childrenIds) {
1694
1695
  buildFlatDataStructure(data, childId, childType, result);
1695
1696
  }
@@ -1707,7 +1708,7 @@ const POLYFILLS = [
1707
1708
  ];
1708
1709
  const relativeSpritePath = `../../lib/icons/${formeoSpriteId}.svg`;
1709
1710
  const localSpriteUrl = false ? (void 0)(relativeSpritePath) : relativeSpritePath;
1710
- const isDev = process.env.NODE_ENV === "development" || false;
1711
+ const isDev = typeof process !== "undefined" && ((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "development" || false;
1711
1712
  const SVG_SPRITE_URL = isDev ? localSpriteUrl : `https://cdn.jsdelivr.net/npm/formeo@${version$1}/dist/${formeoSpriteId}.svg`;
1712
1713
  const FALLBACK_SVG_SPRITE_URL = `https://draggable.github.io/formeo/assets/img/${formeoSpriteId}.svg`;
1713
1714
  const CSS_URL = `https://cdn.jsdelivr.net/npm/formeo@${version$1}/dist/formeo.min.css`;
@@ -4954,8 +4955,8 @@ const iconFontTemplates = {
4954
4955
  };
4955
4956
  const inputTags = /* @__PURE__ */ new Set(["input", "textarea", "select"]);
4956
4957
  const getName = (elem = {}) => {
4957
- var _a, _b, _c;
4958
- let name2 = ((_a = elem == null ? void 0 : elem.attrs) == null ? void 0 : _a.name) || (elem == null ? void 0 : elem.name);
4958
+ var _a2, _b, _c;
4959
+ let name2 = ((_a2 = elem == null ? void 0 : elem.attrs) == null ? void 0 : _a2.name) || (elem == null ? void 0 : elem.name);
4959
4960
  if (name2) {
4960
4961
  return name2;
4961
4962
  }
@@ -5001,7 +5002,7 @@ class DOM {
5001
5002
  }
5002
5003
  const _this = this;
5003
5004
  const processed = ["children", "content"];
5004
- const { className, options, dataset, conditions, ...elem } = this.processElemArg(elemArg);
5005
+ const { className, options, dataset, ...elem } = this.processElemArg(elemArg);
5005
5006
  processed.push("tag");
5006
5007
  let childType;
5007
5008
  const { tag } = elem;
@@ -5289,12 +5290,12 @@ class DOM {
5289
5290
  * @return {String} icon markup
5290
5291
  */
5291
5292
  icon(name2, config2) {
5292
- var _a, _b;
5293
+ var _a2, _b;
5293
5294
  if (!name2) {
5294
5295
  return;
5295
5296
  }
5296
5297
  const cacheKey = `${name2}?${new URLSearchParams(config2).toString()}`;
5297
- if ((_a = this.cachedIcons) == null ? void 0 : _a[cacheKey]) {
5298
+ if ((_a2 = this.cachedIcons) == null ? void 0 : _a2[cacheKey]) {
5298
5299
  return this.cachedIcons[cacheKey];
5299
5300
  }
5300
5301
  const iconConfig = this.icons[name2];
@@ -5365,7 +5366,7 @@ class DOM {
5365
5366
  const fieldType = attrs.type || elem.tag;
5366
5367
  const id = attrs.id || elem.id;
5367
5368
  const optionMap = (option2, i) => {
5368
- var _a;
5369
+ var _a2;
5369
5370
  const { label, value, ...rest } = option2;
5370
5371
  const defaultInput = () => {
5371
5372
  const input = {
@@ -5432,7 +5433,7 @@ class DOM {
5432
5433
  checkbox: defaultInput,
5433
5434
  radio: defaultInput
5434
5435
  };
5435
- return (_a = optionMarkup[fieldType]) == null ? void 0 : _a.call(optionMarkup, option2);
5436
+ return (_a2 = optionMarkup[fieldType]) == null ? void 0 : _a2.call(optionMarkup, option2);
5436
5437
  };
5437
5438
  const mappedOptions = options.map(optionMap);
5438
5439
  return mappedOptions;
@@ -6107,7 +6108,7 @@ class Autocomplete {
6107
6108
  * @param {Object} selectedOption - option - 'li' element - to be selected in autocomplete list
6108
6109
  */
6109
6110
  selectOption(selectedOption, list = this.list) {
6110
- var _a;
6111
+ var _a2;
6111
6112
  const options = list.querySelectorAll("li");
6112
6113
  for (const option2 of options) {
6113
6114
  const {
@@ -6116,7 +6117,7 @@ class Autocomplete {
6116
6117
  option2.classList.remove("active-option");
6117
6118
  if (isAddress(value)) {
6118
6119
  const component = components.getAddress(value);
6119
- (_a = component == null ? void 0 : component.dom) == null ? void 0 : _a.classList.remove(HIGHLIGHT_CLASSNAME);
6120
+ (_a2 = component == null ? void 0 : component.dom) == null ? void 0 : _a2.classList.remove(HIGHLIGHT_CLASSNAME);
6120
6121
  }
6121
6122
  }
6122
6123
  if (selectedOption) {
@@ -6137,7 +6138,7 @@ class Autocomplete {
6137
6138
  * Highlight a component that maps to the option
6138
6139
  */
6139
6140
  highlightComponent(option2) {
6140
- var _a;
6141
+ var _a2;
6141
6142
  const {
6142
6143
  dataset: { value }
6143
6144
  } = option2;
@@ -6166,7 +6167,7 @@ class Autocomplete {
6166
6167
  component.dom.classList.add(HIGHLIGHT_CLASSNAME);
6167
6168
  if (isOptionAddress) {
6168
6169
  const checkboxes = component.dom.querySelectorAll(".field-preview .f-checkbox, .field-preview .f-radio");
6169
- (_a = checkboxes[optionIndex]) == null ? void 0 : _a.classList.add(HIGHLIGHT_CLASSNAME);
6170
+ (_a2 = checkboxes[optionIndex]) == null ? void 0 : _a2.classList.add(HIGHLIGHT_CLASSNAME);
6170
6171
  }
6171
6172
  }
6172
6173
  }
@@ -6185,13 +6186,13 @@ class Autocomplete {
6185
6186
  * @param {String} value display text
6186
6187
  */
6187
6188
  setValue(target) {
6188
- var _a;
6189
+ var _a2;
6189
6190
  const { label, value } = target.dataset;
6190
6191
  this.displayField.value = label;
6191
6192
  this.hiddenField.value = value;
6192
6193
  this.value = value;
6193
6194
  this.clearButton.classList.toggle("hidden", !value.length);
6194
- (_a = this.onChange) == null ? void 0 : _a.call(this, { target: this.hiddenField });
6195
+ (_a2 = this.onChange) == null ? void 0 : _a2.call(this, { target: this.hiddenField });
6195
6196
  }
6196
6197
  }
6197
6198
  function inputConfigBase({ key, value, type: type2 = "text", checked }) {
@@ -6393,16 +6394,16 @@ const fieldVisibilityMap = {
6393
6394
  }
6394
6395
  };
6395
6396
  const toggleFieldVisibility = (fields2) => {
6396
- var _a;
6397
+ var _a2;
6397
6398
  for (const [fieldName, field2] of fields2) {
6398
- const shouldHide = !!((_a = fieldVisibilityMap[fieldName]) == null ? void 0 : _a.call(fieldVisibilityMap, fields2)) || false;
6399
+ const shouldHide = !!((_a2 = fieldVisibilityMap[fieldName]) == null ? void 0 : _a2.call(fieldVisibilityMap, fields2)) || false;
6399
6400
  field2.classList.toggle(hiddenPropertyClassname, shouldHide);
6400
6401
  }
6401
6402
  };
6402
6403
  const isCheckedValue = "isChecked";
6403
6404
  const isCheckedOption = (option2) => option2.value.endsWith("Checked");
6404
6405
  const toggleCheckablePropertyOptions = (isCheckable, propertyField) => {
6405
- var _a;
6406
+ var _a2;
6406
6407
  if (isCheckable && isCheckedOption(propertyField)) {
6407
6408
  return null;
6408
6409
  }
@@ -6417,7 +6418,7 @@ const toggleCheckablePropertyOptions = (isCheckable, propertyField) => {
6417
6418
  option2.classList.toggle(hiddenOptionClassname, shouldHide);
6418
6419
  }
6419
6420
  if (hiddenOptionValues.includes(propertyField.value)) {
6420
- propertyField.value = isCheckable ? isCheckedValue : ((_a = options.find((opt) => !isCheckedOption(opt))) == null ? void 0 : _a.value) || propertyField.value;
6421
+ propertyField.value = isCheckable ? isCheckedValue : ((_a2 = options.find((opt) => !isCheckedOption(opt))) == null ? void 0 : _a2.value) || propertyField.value;
6421
6422
  }
6422
6423
  };
6423
6424
  function orderConditionValues(conditionValues, fieldOrder = CONDITION_INPUT_ORDER) {
@@ -6714,9 +6715,9 @@ class EditPanelItem {
6714
6715
  return controls;
6715
6716
  }
6716
6717
  itemInput(key, value) {
6717
- var _a, _b;
6718
+ var _a2, _b;
6718
6719
  const valType = dom.childType(value) || "string";
6719
- const dataKey = ((_a = panelDataKeyMap.get(this.panelName)) == null ? void 0 : _a({ itemKey: this.itemKey, key })) || this.itemKey;
6720
+ const dataKey = ((_a2 = panelDataKeyMap.get(this.panelName)) == null ? void 0 : _a2({ itemKey: this.itemKey, key })) || this.itemKey;
6720
6721
  const labelKey = dataKey.split(".").filter(Number.isNaN).join(".") || key;
6721
6722
  const baseConfig = ITEM_INPUT_TYPE_MAP[valType]({ key, value });
6722
6723
  const name2 = `${this.field.shortId}-${slugifyAddress(dataKey).replace(/-\d+-(selected)/g, "-$1")}`;
@@ -6761,7 +6762,7 @@ class EditPanel {
6761
6762
  * @param {String|Array} val
6762
6763
  */
6763
6764
  __publicField(this, "addAttribute", (attr, valArg) => {
6764
- var _a;
6765
+ var _a2;
6765
6766
  let val = valArg;
6766
6767
  const safeAttr = safeAttrName(attr);
6767
6768
  const itemKey = `attrs.${safeAttr}`;
@@ -6772,7 +6773,7 @@ class EditPanel {
6772
6773
  val = JSON.parse(val);
6773
6774
  }
6774
6775
  this.component.set(`attrs.${attr}`, val);
6775
- (_a = addAttributeActions[safeAttr]) == null ? void 0 : _a.call(addAttributeActions, val, this.component);
6776
+ (_a2 = addAttributeActions[safeAttr]) == null ? void 0 : _a2.call(addAttributeActions, val, this.component);
6776
6777
  const existingAttr = this.props.querySelector(`.${this.component.name}-attrs-${safeAttr}`);
6777
6778
  const newAttr = new EditPanelItem({
6778
6779
  key: itemKey,
@@ -6990,10 +6991,10 @@ class Panels {
6990
6991
  */
6991
6992
  constructor(options) {
6992
6993
  __publicField(this, "toggleTabbedLayout", () => {
6993
- var _a;
6994
+ var _a2;
6994
6995
  this.getPanelDisplay();
6995
6996
  const isTabbed = this.isTabbed;
6996
- (_a = this.panelsWrap.parentElement) == null ? void 0 : _a.classList.toggle("tabbed-panels", isTabbed);
6997
+ (_a2 = this.panelsWrap.parentElement) == null ? void 0 : _a2.classList.toggle("tabbed-panels", isTabbed);
6997
6998
  if (isTabbed) {
6998
6999
  this.panelNav.removeAttribute("style");
6999
7000
  }
@@ -7033,7 +7034,7 @@ class Panels {
7033
7034
  }
7034
7035
  getPanelDisplay() {
7035
7036
  const column = this.panelsWrap;
7036
- const width = Number.parseInt(dom.getStyle(column, "width"));
7037
+ const width = Number.parseInt(dom.getStyle(column, "width"), 10);
7037
7038
  const autoDisplayType = width > 390 ? "tabbed" : "slider";
7038
7039
  const isAuto = this.opts.displayType === "auto";
7039
7040
  this.panelDisplay = isAuto ? autoDisplayType : this.opts.displayType || defaults$2.displayType;
@@ -7289,6 +7290,12 @@ class Component extends Data {
7289
7290
  }
7290
7291
  const parent = this.parent;
7291
7292
  const children = this.children;
7293
+ this.dispatchComponentEvent("onRemove", {
7294
+ path,
7295
+ parent,
7296
+ children: [...children]
7297
+ // copy array since children will be modified
7298
+ });
7292
7299
  forEach(children, (child) => child.remove());
7293
7300
  this.dom.parentElement.removeChild(this.dom);
7294
7301
  remove(components.getAddress(`${parent.name}s.${parent.id}.children`), this.id);
@@ -7430,6 +7437,11 @@ class Component extends Data {
7430
7437
  if (this.name !== "field") {
7431
7438
  this.cloneChildren(newClone);
7432
7439
  }
7440
+ this.dispatchComponentEvent("onClone", {
7441
+ original: this,
7442
+ clone: newClone,
7443
+ parent
7444
+ });
7433
7445
  return newClone;
7434
7446
  });
7435
7447
  __publicField(this, "createChildWrap", (children) => dom.create({
@@ -7501,11 +7513,91 @@ class Component extends Data {
7501
7513
  this.address = `${this.name}s.${this.id}`;
7502
7514
  this.dataPath = `${this.address}.`;
7503
7515
  this.editPanels = /* @__PURE__ */ new Map();
7516
+ this.eventListeners = /* @__PURE__ */ new Map();
7517
+ this.initEventHandlers();
7518
+ }
7519
+ /**
7520
+ * Initialize event handlers based on config
7521
+ */
7522
+ initEventHandlers() {
7523
+ if (!this.config.events) {
7524
+ return;
7525
+ }
7526
+ Object.entries(this.config.events).forEach(([eventName, handler]) => {
7527
+ this.addEventListener(eventName, handler);
7528
+ });
7529
+ }
7530
+ /**
7531
+ * Add an event listener to this component
7532
+ * @param {string} eventName - Name of the event
7533
+ * @param {function} handler - Event handler function
7534
+ */
7535
+ addEventListener(eventName, handler) {
7536
+ if (!this.eventListeners.has(eventName)) {
7537
+ this.eventListeners.set(eventName, []);
7538
+ }
7539
+ this.eventListeners.get(eventName).push(handler);
7540
+ }
7541
+ /**
7542
+ * Remove an event listener from this component
7543
+ * @param {string} eventName - Name of the event
7544
+ * @param {function} handler - Event handler function to remove
7545
+ */
7546
+ removeEventListener(eventName, handler) {
7547
+ var _a2;
7548
+ if (!((_a2 = this.eventListeners) == null ? void 0 : _a2.has(eventName))) {
7549
+ return;
7550
+ }
7551
+ const handlers = this.eventListeners.get(eventName);
7552
+ const index2 = handlers.indexOf(handler);
7553
+ if (index2 > -1) {
7554
+ handlers.splice(index2, 1);
7555
+ }
7556
+ }
7557
+ /**
7558
+ * Dispatch a component event to all registered listeners
7559
+ * @param {string} eventName - Name of the event to dispatch
7560
+ * @param {object} eventData - Data to pass to event handlers
7561
+ */
7562
+ dispatchComponentEvent(eventName, eventData = {}) {
7563
+ var _a2;
7564
+ const fullEventData = {
7565
+ component: this,
7566
+ type: eventName,
7567
+ timestamp: Date.now(),
7568
+ ...eventData
7569
+ };
7570
+ if ((_a2 = this.eventListeners) == null ? void 0 : _a2.has(eventName)) {
7571
+ this.eventListeners.get(eventName).forEach((handler) => {
7572
+ try {
7573
+ if (typeof handler === "function") {
7574
+ handler(fullEventData);
7575
+ }
7576
+ } catch (error) {
7577
+ console.error(`Error in ${eventName} event handler for ${this.name} ${this.id}:`, error);
7578
+ }
7579
+ });
7580
+ }
7581
+ return fullEventData;
7582
+ }
7583
+ /**
7584
+ * Override Data.set to dispatch component update events
7585
+ */
7586
+ set(path, newVal) {
7587
+ const oldVal = this.get(path);
7588
+ const result = super.set(path, newVal);
7589
+ if (oldVal !== newVal && this.dom) {
7590
+ this.dispatchComponentEvent("onUpdate", {
7591
+ path,
7592
+ oldValue: oldVal,
7593
+ newValue: newVal
7594
+ });
7595
+ }
7596
+ return result;
7504
7597
  }
7505
7598
  // mutationHandler = mutations =>
7506
7599
  // mutations.map(mutation => {
7507
- // @todo pull handler form config
7508
- // see dom.create.onRender for implementation pattern
7600
+ // @todo pull handler form config see dom.create.onRender for implementation pattern
7509
7601
  // })
7510
7602
  // observe(container) {
7511
7603
  // this.observer.disconnect()
@@ -7653,8 +7745,8 @@ class Component extends Data {
7653
7745
  const { buttons, disabled } = this.config.actionButtons;
7654
7746
  const activeButtons = buttons.filter((btn) => !disabled.includes(btn));
7655
7747
  const actionButtonsConfigs = activeButtons.map((btn) => {
7656
- var _a;
7657
- return ((_a = buttonConfig[btn]) == null ? void 0 : _a.call(buttonConfig)) || btn;
7748
+ var _a2;
7749
+ return ((_a2 = buttonConfig[btn]) == null ? void 0 : _a2.call(buttonConfig)) || btn;
7658
7750
  });
7659
7751
  this.actionButtons = actionButtonsConfigs;
7660
7752
  return this.actionButtons;
@@ -7695,7 +7787,7 @@ class Component extends Data {
7695
7787
  * @return {Object} child DOM element
7696
7788
  */
7697
7789
  addChild(childData = {}, index2 = this.domChildren.length) {
7698
- var _a, _b;
7790
+ var _a2, _b;
7699
7791
  let data = childData;
7700
7792
  if (typeof childData !== "object") {
7701
7793
  data = { id: data };
@@ -7708,8 +7800,25 @@ class Component extends Data {
7708
7800
  }
7709
7801
  const childComponentType = `${childGroup}s`;
7710
7802
  const child = components.getAddress(`${childComponentType}.${childId}`) || components[childComponentType].add(childId, data);
7711
- childWrap.insertBefore(child.dom, childWrap.children[index2]);
7712
- (_b = (_a = this.config.events) == null ? void 0 : _a.onAddChild) == null ? void 0 : _b.call(_a, { parent: this, child });
7803
+ if (index2 >= childWrap.children.length) {
7804
+ childWrap.appendChild(child.dom);
7805
+ } else {
7806
+ childWrap.children[index2].before(child.dom);
7807
+ }
7808
+ this.dispatchComponentEvent("onAddChild", {
7809
+ parent: this,
7810
+ target: child,
7811
+ child,
7812
+ index: index2
7813
+ });
7814
+ child.dispatchComponentEvent("onAdd", {
7815
+ parent: this,
7816
+ target: child,
7817
+ index: index2,
7818
+ addedVia: "addChild"
7819
+ // indicate how the component was added
7820
+ });
7821
+ (_b = (_a2 = this.config.events) == null ? void 0 : _a2.onAddChild) == null ? void 0 : _b.call(_a2, { parent: this, child });
7713
7822
  const grandChildren = child.get("children");
7714
7823
  if (grandChildren == null ? void 0 : grandChildren.length) {
7715
7824
  child.loadChildren(grandChildren);
@@ -7725,7 +7834,7 @@ class Component extends Data {
7725
7834
  * @return {Object} Component
7726
7835
  */
7727
7836
  onAdd({ from, to, item, newIndex: newIndex2 }) {
7728
- var _a;
7837
+ var _a2;
7729
7838
  if (!from.classList.contains(CONTROL_GROUP_CLASSNAME)) {
7730
7839
  from = from.parentElement;
7731
7840
  }
@@ -7816,7 +7925,18 @@ class Component extends Data {
7816
7925
  return action == null ? void 0 : action(item.id);
7817
7926
  }
7818
7927
  };
7819
- const component = (_a = onAddConditions[fromType]) == null ? void 0 : _a.call(onAddConditions, item, newIndex2);
7928
+ const component = (_a2 = onAddConditions[fromType]) == null ? void 0 : _a2.call(onAddConditions, item, newIndex2);
7929
+ this.dispatchComponentEvent("onAdd", {
7930
+ from,
7931
+ to,
7932
+ item,
7933
+ newIndex: newIndex2,
7934
+ fromType,
7935
+ toType,
7936
+ addedComponent: component,
7937
+ addedVia: "dragDrop"
7938
+ // indicate how the component was added
7939
+ });
7820
7940
  defaultOnAdd();
7821
7941
  return component;
7822
7942
  }
@@ -7839,6 +7959,9 @@ class Component extends Data {
7839
7959
  * Callback for onRender, executes any defined onRender for component
7840
7960
  */
7841
7961
  onRender() {
7962
+ this.dispatchComponentEvent("onRender", {
7963
+ dom: this.dom
7964
+ });
7842
7965
  const { events: events2 } = this.config;
7843
7966
  if (!events2) {
7844
7967
  return null;
@@ -8761,8 +8884,8 @@ class Control {
8761
8884
  this.id = controlData.id || uuid();
8762
8885
  }
8763
8886
  get controlId() {
8764
- var _a, _b;
8765
- return ((_a = this.controlData.meta) == null ? void 0 : _a.id) || ((_b = this.controlData.config) == null ? void 0 : _b.controlId);
8887
+ var _a2, _b;
8888
+ return ((_a2 = this.controlData.meta) == null ? void 0 : _a2.id) || ((_b = this.controlData.config) == null ? void 0 : _b.controlId);
8766
8889
  }
8767
8890
  get dom() {
8768
8891
  const { meta, config: config2 } = this.controlData;
@@ -8784,8 +8907,8 @@ class Control {
8784
8907
  return group && Controls$2.panels.nav.refresh(indexOfNode(group));
8785
8908
  },
8786
8909
  click: ({ target }) => {
8787
- var _a;
8788
- const controlId = (_a = target.closest(".field-control")) == null ? void 0 : _a.id;
8910
+ var _a2;
8911
+ const controlId = (_a2 = target.closest(".field-control")) == null ? void 0 : _a2.id;
8789
8912
  if (controlId) {
8790
8913
  Controls$2.addElement(controlId);
8791
8914
  }
@@ -8813,9 +8936,9 @@ class Control {
8813
8936
  * @return {String} the translated label
8814
8937
  */
8815
8938
  i18n(lookup, args) {
8816
- var _a, _b;
8939
+ var _a2, _b;
8817
8940
  const locale = mi18n.locale;
8818
- const controlTranslations = (_a = this.definition) == null ? void 0 : _a.i18n;
8941
+ const controlTranslations = (_a2 = this.definition) == null ? void 0 : _a2.i18n;
8819
8942
  const localeTranslations = (controlTranslations == null ? void 0 : controlTranslations[locale]) || {};
8820
8943
  return (((_b = localeTranslations[lookup]) == null ? void 0 : _b.call(localeTranslations)) ?? localeTranslations[lookup]) || mi18n.get(lookup, args);
8821
8944
  }
@@ -9192,8 +9315,8 @@ class Field extends Component {
9192
9315
  this.controlId = this.get("config.controlId") || this.get("meta.id");
9193
9316
  const actionButtons = this.getActionButtons();
9194
9317
  const hasEditButton = this.actionButtons.some((child) => {
9195
- var _a;
9196
- return ((_a = child.meta) == null ? void 0 : _a.id) === "edit";
9318
+ var _a2;
9319
+ return ((_a2 = child.meta) == null ? void 0 : _a2.id) === "edit";
9197
9320
  });
9198
9321
  this.updateEditPanels();
9199
9322
  const field2 = dom.create({
@@ -9276,13 +9399,13 @@ class Field extends Component {
9276
9399
  get defaultPreviewActions() {
9277
9400
  return {
9278
9401
  change: (evt) => {
9279
- var _a;
9402
+ var _a2;
9280
9403
  const { target } = evt;
9281
9404
  const { type: type2 } = target;
9282
9405
  if (isSelectableType.has(type2)) {
9283
9406
  const selectedOptions = this.preview.querySelectorAll(":checked");
9284
9407
  const optionsData = this.get("options");
9285
- const checkedType = ((_a = optionsData == null ? void 0 : optionsData[0]) == null ? void 0 : _a.selected) !== void 0 ? "selected" : "checked";
9408
+ const checkedType = ((_a2 = optionsData == null ? void 0 : optionsData[0]) == null ? void 0 : _a2.selected) !== void 0 ? "selected" : "checked";
9286
9409
  const optionsDataMap = optionsData.reduce((acc, option2) => {
9287
9410
  acc[option2.value] = option2;
9288
9411
  acc[option2.value][checkedType] = false;
@@ -9301,12 +9424,12 @@ class Field extends Component {
9301
9424
  }
9302
9425
  },
9303
9426
  input: ({ target }) => {
9304
- var _a;
9427
+ var _a2;
9305
9428
  if (["input", "meter", "progress", "button"].includes(target.tagName.toLowerCase())) {
9306
9429
  super.set("attrs.value", target.value);
9307
9430
  return this.debouncedUpdateEditPanels();
9308
9431
  }
9309
- if (target.contentEditable && !((_a = target.type) == null ? void 0 : _a.startsWith("select-"))) {
9432
+ if (target.contentEditable && !((_a2 = target.type) == null ? void 0 : _a2.startsWith("select-"))) {
9310
9433
  const parentClassList = target.parentElement.classList;
9311
9434
  const isOption = parentClassList.contains("f-checkbox") || parentClassList.contains("f-radio");
9312
9435
  if (isOption) {
@@ -9325,14 +9448,14 @@ class Field extends Component {
9325
9448
  * @return {Object} fieldPreview
9326
9449
  */
9327
9450
  fieldPreview() {
9328
- var _a;
9451
+ var _a2;
9329
9452
  const { action = {}, ...prevData } = clone$1(this.data);
9330
9453
  prevData.id = `prev-${this.id}`;
9331
9454
  prevData.action = Object.entries(action).reduce((acc, [key, value]) => {
9332
9455
  acc[key] = value.bind(this);
9333
9456
  return acc;
9334
9457
  }, {});
9335
- if ((_a = this.data) == null ? void 0 : _a.config.editableContent) {
9458
+ if ((_a2 = this.data) == null ? void 0 : _a2.config.editableContent) {
9336
9459
  prevData.attrs = { ...prevData.attrs, contenteditable: true };
9337
9460
  }
9338
9461
  const fieldPreview = {
@@ -9552,28 +9675,28 @@ const defaults$1 = {
9552
9675
  },
9553
9676
  onChange: (...args) => defaults$1.onUpdate(...args),
9554
9677
  onUpdate: (evt) => {
9555
- var _a;
9556
- return ((_a = events.opts) == null ? void 0 : _a.debug) && console.log(evt);
9678
+ var _a2;
9679
+ return ((_a2 = events.opts) == null ? void 0 : _a2.debug) && console.log(evt);
9557
9680
  },
9558
9681
  onUpdateStage: (evt) => {
9559
- var _a;
9560
- return ((_a = events.opts) == null ? void 0 : _a.debug) && console.log(evt);
9682
+ var _a2;
9683
+ return ((_a2 = events.opts) == null ? void 0 : _a2.debug) && console.log(evt);
9561
9684
  },
9562
9685
  onUpdateRow: (evt) => {
9563
- var _a;
9564
- return ((_a = events.opts) == null ? void 0 : _a.debug) && console.log(evt);
9686
+ var _a2;
9687
+ return ((_a2 = events.opts) == null ? void 0 : _a2.debug) && console.log(evt);
9565
9688
  },
9566
9689
  onUpdateColumn: (evt) => {
9567
- var _a;
9568
- return ((_a = events.opts) == null ? void 0 : _a.debug) && console.log(evt);
9690
+ var _a2;
9691
+ return ((_a2 = events.opts) == null ? void 0 : _a2.debug) && console.log(evt);
9569
9692
  },
9570
9693
  onUpdateField: (evt) => {
9571
- var _a;
9572
- return ((_a = events.opts) == null ? void 0 : _a.debug) && console.log(evt);
9694
+ var _a2;
9695
+ return ((_a2 = events.opts) == null ? void 0 : _a2.debug) && console.log(evt);
9573
9696
  },
9574
9697
  onRender: (evt) => {
9575
- var _a;
9576
- return ((_a = events.opts) == null ? void 0 : _a.debug) && console.log(evt);
9698
+ var _a2;
9699
+ return ((_a2 = events.opts) == null ? void 0 : _a2.debug) && console.log(evt);
9577
9700
  },
9578
9701
  onSave: (_evt) => {
9579
9702
  },
@@ -9584,10 +9707,10 @@ const defaults$1 = {
9584
9707
  }
9585
9708
  };
9586
9709
  const defaultCustomEvent = ({ src, ...evtData }, type2 = EVENT_FORMEO_UPDATED) => {
9587
- var _a, _b;
9710
+ var _a2, _b;
9588
9711
  const evt = new window.CustomEvent(type2, {
9589
9712
  detail: evtData,
9590
- bubbles: ((_a = events.opts) == null ? void 0 : _a.debug) || ((_b = events.opts) == null ? void 0 : _b.bubbles)
9713
+ bubbles: ((_a2 = events.opts) == null ? void 0 : _a2.debug) || ((_b = events.opts) == null ? void 0 : _b.bubbles)
9591
9714
  });
9592
9715
  evt.data = (src || document).dispatchEvent(evt);
9593
9716
  return evt;
@@ -9848,7 +9971,7 @@ let FormeoEditor$1 = class FormeoEditor {
9848
9971
  * @return {Promise} asynchronously loaded remote resources
9849
9972
  */
9850
9973
  async loadResources() {
9851
- var _a;
9974
+ var _a2;
9852
9975
  document.removeEventListener("DOMContentLoaded", this.loadResources);
9853
9976
  const promises = [];
9854
9977
  if (this.opts.polyfills) {
@@ -9856,7 +9979,7 @@ let FormeoEditor$1 = class FormeoEditor {
9856
9979
  }
9857
9980
  await fetchIcons(this.opts.svgSprite);
9858
9981
  promises.push(fetchFormeoStyle(this.opts.style));
9859
- promises.push(mi18n.init({ ...this.opts.i18n, locale: (_a = window.sessionStorage) == null ? void 0 : _a.getItem(SESSION_LOCALE_KEY) }));
9982
+ promises.push(mi18n.init({ ...this.opts.i18n, locale: (_a2 = window.sessionStorage) == null ? void 0 : _a2.getItem(SESSION_LOCALE_KEY) }));
9860
9983
  const resolvedPromises = await Promise.all(promises);
9861
9984
  if (this.opts.allowEdit) {
9862
9985
  this.init();
@@ -9870,21 +9993,21 @@ let FormeoEditor$1 = class FormeoEditor {
9870
9993
  */
9871
9994
  init() {
9872
9995
  return Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
9873
- var _a, _b;
9996
+ var _a2, _b;
9874
9997
  this.controls = controls;
9875
9998
  this.load(this.userFormData, this.opts);
9876
9999
  this.formId = components.get("id");
9877
10000
  this.i18n = {
9878
10001
  setLang: (formeoLocale) => {
9879
- var _a2;
9880
- (_a2 = window.sessionStorage) == null ? void 0 : _a2.setItem(SESSION_LOCALE_KEY, formeoLocale);
10002
+ var _a3;
10003
+ (_a3 = window.sessionStorage) == null ? void 0 : _a3.setItem(SESSION_LOCALE_KEY, formeoLocale);
9881
10004
  const loadLang = mi18n.setCurrent(formeoLocale);
9882
10005
  loadLang.then(() => {
9883
10006
  this.init();
9884
10007
  }, console.error);
9885
10008
  }
9886
10009
  };
9887
- (_b = (_a = this.opts).onLoad) == null ? void 0 : _b.call(_a, this);
10010
+ (_b = (_a2 = this.opts).onLoad) == null ? void 0 : _b.call(_a2, this);
9888
10011
  });
9889
10012
  }
9890
10013
  load(formData = this.userFormData, opts = this.opts) {
@@ -10009,8 +10132,8 @@ const targetPropertyMap = {
10009
10132
  elem.checked = false;
10010
10133
  },
10011
10134
  value: (elem, { assignment, ...rest }) => {
10012
- var _a;
10013
- const assignmentAction = (_a = assignmentMap[assignment]) == null ? void 0 : _a.call(assignmentMap, elem, rest);
10135
+ var _a2;
10136
+ const assignmentAction = (_a2 = assignmentMap[assignment]) == null ? void 0 : _a2.call(assignmentMap, elem, rest);
10014
10137
  const event = new Event("input", { bubbles: true });
10015
10138
  elem.dispatchEvent(event);
10016
10139
  return assignmentAction;
@@ -10118,8 +10241,8 @@ let FormeoRenderer$1 = class FormeoRenderer {
10118
10241
  );
10119
10242
  });
10120
10243
  __publicField(this, "processFields", (fieldIds) => this.orderChildren("fields", fieldIds).map(({ id, ...field2 }) => {
10121
- var _a, _b;
10122
- const controlId = ((_a = field2.config) == null ? void 0 : _a.controlId) || ((_b = field2.meta) == null ? void 0 : _b.id);
10244
+ var _a2, _b;
10245
+ const controlId = ((_a2 = field2.config) == null ? void 0 : _a2.controlId) || ((_b = field2.meta) == null ? void 0 : _b.id);
10123
10246
  const { action = {}, dependencies: dependencies2 = {} } = this.elements[controlId] || {};
10124
10247
  if (dependencies2) {
10125
10248
  fetchDependencies(dependencies2);
@@ -10185,27 +10308,27 @@ let FormeoRenderer$1 = class FormeoRenderer {
10185
10308
  * Evaulate conditions
10186
10309
  */
10187
10310
  __publicField(this, "evaluateCondition", ({ source, sourceProperty, targetProperty, comparison, target }) => {
10188
- var _a;
10311
+ var _a2;
10189
10312
  const sourceValue = this.getComponentProperty(source, sourceProperty);
10190
10313
  if (typeof sourceValue === "boolean") {
10191
10314
  return sourceValue;
10192
10315
  }
10193
10316
  const targetValue = String(isAddress(target) ? this.getComponentProperty(target, targetProperty) : target);
10194
- return (_a = comparisonMap[comparison]) == null ? void 0 : _a.call(comparisonMap, sourceValue, targetValue);
10317
+ return (_a2 = comparisonMap[comparison]) == null ? void 0 : _a2.call(comparisonMap, sourceValue, targetValue);
10195
10318
  });
10196
10319
  __publicField(this, "execResult", ({ target, targetProperty, assignment, value }) => {
10197
- var _a;
10320
+ var _a2;
10198
10321
  if (isAddress(target)) {
10199
10322
  const { component, option: option2 } = this.getComponent(target);
10200
10323
  const elem = option2 || component;
10201
- (_a = targetPropertyMap[targetProperty]) == null ? void 0 : _a.call(targetPropertyMap, elem, { targetProperty, assignment, value });
10324
+ (_a2 = targetPropertyMap[targetProperty]) == null ? void 0 : _a2.call(targetPropertyMap, elem, { targetProperty, assignment, value });
10202
10325
  }
10203
10326
  });
10204
10327
  __publicField(this, "getComponentProperty", (address, propertyName) => {
10205
- var _a;
10328
+ var _a2;
10206
10329
  const { component, option: option2 } = this.getComponent(address);
10207
10330
  const elem = option2 || component;
10208
- return ((_a = propertyMap[propertyName]) == null ? void 0 : _a.call(propertyMap, elem)) || elem[propertyName];
10331
+ return ((_a2 = propertyMap[propertyName]) == null ? void 0 : _a2.call(propertyMap, elem)) || elem[propertyName];
10209
10332
  });
10210
10333
  __publicField(this, "getComponent", (address) => {
10211
10334
  const result = {
@@ -10579,7 +10702,7 @@ class RadioGroupControl extends Control {
10579
10702
  }
10580
10703
  class SelectControl extends Control {
10581
10704
  constructor(controlConfig = {}) {
10582
- var _a;
10705
+ var _a2;
10583
10706
  const selectConfig = {
10584
10707
  tag: "select",
10585
10708
  config: {
@@ -10595,7 +10718,7 @@ class SelectControl extends Control {
10595
10718
  icon: "select",
10596
10719
  id: "select"
10597
10720
  },
10598
- options: generateOptionConfig({ type: "option", isMultiple: (_a = controlConfig.attrs) == null ? void 0 : _a.multiple })
10721
+ options: generateOptionConfig({ type: "option", isMultiple: (_a2 = controlConfig.attrs) == null ? void 0 : _a2.multiple })
10599
10722
  };
10600
10723
  const mergedConfig = merge(selectConfig, controlConfig);
10601
10724
  super(mergedConfig);