formeo 4.0.0 → 4.1.0

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.0.0
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -435,7 +435,7 @@ if (window !== void 0) {
435
435
  window.SmartTooltip = SmartTooltip;
436
436
  }
437
437
  const name$1 = "formeo";
438
- const version$2 = "3.1.4";
438
+ const version$2 = "4.0.0";
439
439
  const type = "module";
440
440
  const main = "dist/formeo.cjs.js";
441
441
  const module = "dist/formeo.es.js";
@@ -566,7 +566,7 @@ const dependencies = {
566
566
  sortablejs: "^1.15.3"
567
567
  };
568
568
  const release = {
569
- branch: "master",
569
+ branch: "main",
570
570
  verifyConditions: [
571
571
  "@semantic-release/changelog",
572
572
  "@semantic-release/npm",
@@ -5000,7 +5000,7 @@ class DOM {
5000
5000
  }
5001
5001
  const _this = this;
5002
5002
  const processed = ["children", "content"];
5003
- const { className, options, dataset, conditions, ...elem } = this.processElemArg(elemArg);
5003
+ const { className, options, dataset, ...elem } = this.processElemArg(elemArg);
5004
5004
  processed.push("tag");
5005
5005
  let childType;
5006
5006
  const { tag } = elem;
@@ -7032,7 +7032,7 @@ class Panels {
7032
7032
  }
7033
7033
  getPanelDisplay() {
7034
7034
  const column = this.panelsWrap;
7035
- const width = Number.parseInt(dom.getStyle(column, "width"));
7035
+ const width = Number.parseInt(dom.getStyle(column, "width"), 10);
7036
7036
  const autoDisplayType = width > 390 ? "tabbed" : "slider";
7037
7037
  const isAuto = this.opts.displayType === "auto";
7038
7038
  this.panelDisplay = isAuto ? autoDisplayType : this.opts.displayType || defaults$2.displayType;
@@ -7288,6 +7288,12 @@ class Component extends Data {
7288
7288
  }
7289
7289
  const parent = this.parent;
7290
7290
  const children = this.children;
7291
+ this.dispatchComponentEvent("onRemove", {
7292
+ path,
7293
+ parent,
7294
+ children: [...children]
7295
+ // copy array since children will be modified
7296
+ });
7291
7297
  forEach(children, (child) => child.remove());
7292
7298
  this.dom.parentElement.removeChild(this.dom);
7293
7299
  remove(components.getAddress(`${parent.name}s.${parent.id}.children`), this.id);
@@ -7429,6 +7435,11 @@ class Component extends Data {
7429
7435
  if (this.name !== "field") {
7430
7436
  this.cloneChildren(newClone);
7431
7437
  }
7438
+ this.dispatchComponentEvent("onClone", {
7439
+ original: this,
7440
+ clone: newClone,
7441
+ parent
7442
+ });
7432
7443
  return newClone;
7433
7444
  });
7434
7445
  __publicField(this, "createChildWrap", (children) => dom.create({
@@ -7500,11 +7511,91 @@ class Component extends Data {
7500
7511
  this.address = `${this.name}s.${this.id}`;
7501
7512
  this.dataPath = `${this.address}.`;
7502
7513
  this.editPanels = /* @__PURE__ */ new Map();
7514
+ this.eventListeners = /* @__PURE__ */ new Map();
7515
+ this.initEventHandlers();
7516
+ }
7517
+ /**
7518
+ * Initialize event handlers based on config
7519
+ */
7520
+ initEventHandlers() {
7521
+ if (!this.config.events) {
7522
+ return;
7523
+ }
7524
+ Object.entries(this.config.events).forEach(([eventName, handler]) => {
7525
+ this.addEventListener(eventName, handler);
7526
+ });
7527
+ }
7528
+ /**
7529
+ * Add an event listener to this component
7530
+ * @param {string} eventName - Name of the event
7531
+ * @param {function} handler - Event handler function
7532
+ */
7533
+ addEventListener(eventName, handler) {
7534
+ if (!this.eventListeners.has(eventName)) {
7535
+ this.eventListeners.set(eventName, []);
7536
+ }
7537
+ this.eventListeners.get(eventName).push(handler);
7538
+ }
7539
+ /**
7540
+ * Remove an event listener from this component
7541
+ * @param {string} eventName - Name of the event
7542
+ * @param {function} handler - Event handler function to remove
7543
+ */
7544
+ removeEventListener(eventName, handler) {
7545
+ var _a2;
7546
+ if (!((_a2 = this.eventListeners) == null ? void 0 : _a2.has(eventName))) {
7547
+ return;
7548
+ }
7549
+ const handlers = this.eventListeners.get(eventName);
7550
+ const index2 = handlers.indexOf(handler);
7551
+ if (index2 > -1) {
7552
+ handlers.splice(index2, 1);
7553
+ }
7554
+ }
7555
+ /**
7556
+ * Dispatch a component event to all registered listeners
7557
+ * @param {string} eventName - Name of the event to dispatch
7558
+ * @param {object} eventData - Data to pass to event handlers
7559
+ */
7560
+ dispatchComponentEvent(eventName, eventData = {}) {
7561
+ var _a2;
7562
+ const fullEventData = {
7563
+ component: this,
7564
+ type: eventName,
7565
+ timestamp: Date.now(),
7566
+ ...eventData
7567
+ };
7568
+ if ((_a2 = this.eventListeners) == null ? void 0 : _a2.has(eventName)) {
7569
+ this.eventListeners.get(eventName).forEach((handler) => {
7570
+ try {
7571
+ if (typeof handler === "function") {
7572
+ handler(fullEventData);
7573
+ }
7574
+ } catch (error) {
7575
+ console.error(`Error in ${eventName} event handler for ${this.name} ${this.id}:`, error);
7576
+ }
7577
+ });
7578
+ }
7579
+ return fullEventData;
7580
+ }
7581
+ /**
7582
+ * Override Data.set to dispatch component update events
7583
+ */
7584
+ set(path, newVal) {
7585
+ const oldVal = this.get(path);
7586
+ const result = super.set(path, newVal);
7587
+ if (oldVal !== newVal && this.dom) {
7588
+ this.dispatchComponentEvent("onUpdate", {
7589
+ path,
7590
+ oldValue: oldVal,
7591
+ newValue: newVal
7592
+ });
7593
+ }
7594
+ return result;
7503
7595
  }
7504
7596
  // mutationHandler = mutations =>
7505
7597
  // mutations.map(mutation => {
7506
- // @todo pull handler form config
7507
- // see dom.create.onRender for implementation pattern
7598
+ // @todo pull handler form config see dom.create.onRender for implementation pattern
7508
7599
  // })
7509
7600
  // observe(container) {
7510
7601
  // this.observer.disconnect()
@@ -7707,7 +7798,24 @@ class Component extends Data {
7707
7798
  }
7708
7799
  const childComponentType = `${childGroup}s`;
7709
7800
  const child = components.getAddress(`${childComponentType}.${childId}`) || components[childComponentType].add(childId, data);
7710
- childWrap.insertBefore(child.dom, childWrap.children[index2]);
7801
+ if (index2 >= childWrap.children.length) {
7802
+ childWrap.appendChild(child.dom);
7803
+ } else {
7804
+ childWrap.children[index2].before(child.dom);
7805
+ }
7806
+ this.dispatchComponentEvent("onAddChild", {
7807
+ parent: this,
7808
+ target: child,
7809
+ child,
7810
+ index: index2
7811
+ });
7812
+ child.dispatchComponentEvent("onAdd", {
7813
+ parent: this,
7814
+ target: child,
7815
+ index: index2,
7816
+ addedVia: "addChild"
7817
+ // indicate how the component was added
7818
+ });
7711
7819
  (_b2 = (_a2 = this.config.events) == null ? void 0 : _a2.onAddChild) == null ? void 0 : _b2.call(_a2, { parent: this, child });
7712
7820
  const grandChildren = child.get("children");
7713
7821
  if (grandChildren == null ? void 0 : grandChildren.length) {
@@ -7816,6 +7924,17 @@ class Component extends Data {
7816
7924
  }
7817
7925
  };
7818
7926
  const component = (_a2 = onAddConditions[fromType]) == null ? void 0 : _a2.call(onAddConditions, item, newIndex2);
7927
+ this.dispatchComponentEvent("onAdd", {
7928
+ from,
7929
+ to,
7930
+ item,
7931
+ newIndex: newIndex2,
7932
+ fromType,
7933
+ toType,
7934
+ addedComponent: component,
7935
+ addedVia: "dragDrop"
7936
+ // indicate how the component was added
7937
+ });
7819
7938
  defaultOnAdd();
7820
7939
  return component;
7821
7940
  }
@@ -7838,6 +7957,9 @@ class Component extends Data {
7838
7957
  * Callback for onRender, executes any defined onRender for component
7839
7958
  */
7840
7959
  onRender() {
7960
+ this.dispatchComponentEvent("onRender", {
7961
+ dom: this.dom
7962
+ });
7841
7963
  const { events: events2 } = this.config;
7842
7964
  if (!events2) {
7843
7965
  return null;
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 3.1.4
4
+ Version: 4.0.0
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -438,7 +438,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
438
438
  window.SmartTooltip = SmartTooltip;
439
439
  }
440
440
  const name$1 = "formeo";
441
- const version$2 = "3.1.4";
441
+ const version$2 = "4.0.0";
442
442
  const type = "module";
443
443
  const main = "dist/formeo.cjs.js";
444
444
  const module2 = "dist/formeo.es.js";
@@ -569,7 +569,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
569
569
  sortablejs: "^1.15.3"
570
570
  };
571
571
  const release = {
572
- branch: "master",
572
+ branch: "main",
573
573
  verifyConditions: [
574
574
  "@semantic-release/changelog",
575
575
  "@semantic-release/npm",
@@ -5003,7 +5003,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5003
5003
  }
5004
5004
  const _this = this;
5005
5005
  const processed = ["children", "content"];
5006
- const { className, options, dataset, conditions, ...elem } = this.processElemArg(elemArg);
5006
+ const { className, options, dataset, ...elem } = this.processElemArg(elemArg);
5007
5007
  processed.push("tag");
5008
5008
  let childType;
5009
5009
  const { tag } = elem;
@@ -7035,7 +7035,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7035
7035
  }
7036
7036
  getPanelDisplay() {
7037
7037
  const column = this.panelsWrap;
7038
- const width = Number.parseInt(dom.getStyle(column, "width"));
7038
+ const width = Number.parseInt(dom.getStyle(column, "width"), 10);
7039
7039
  const autoDisplayType = width > 390 ? "tabbed" : "slider";
7040
7040
  const isAuto = this.opts.displayType === "auto";
7041
7041
  this.panelDisplay = isAuto ? autoDisplayType : this.opts.displayType || defaults$2.displayType;
@@ -7291,6 +7291,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7291
7291
  }
7292
7292
  const parent = this.parent;
7293
7293
  const children = this.children;
7294
+ this.dispatchComponentEvent("onRemove", {
7295
+ path,
7296
+ parent,
7297
+ children: [...children]
7298
+ // copy array since children will be modified
7299
+ });
7294
7300
  forEach(children, (child) => child.remove());
7295
7301
  this.dom.parentElement.removeChild(this.dom);
7296
7302
  remove(components.getAddress(`${parent.name}s.${parent.id}.children`), this.id);
@@ -7432,6 +7438,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7432
7438
  if (this.name !== "field") {
7433
7439
  this.cloneChildren(newClone);
7434
7440
  }
7441
+ this.dispatchComponentEvent("onClone", {
7442
+ original: this,
7443
+ clone: newClone,
7444
+ parent
7445
+ });
7435
7446
  return newClone;
7436
7447
  });
7437
7448
  __publicField(this, "createChildWrap", (children) => dom.create({
@@ -7503,11 +7514,91 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7503
7514
  this.address = `${this.name}s.${this.id}`;
7504
7515
  this.dataPath = `${this.address}.`;
7505
7516
  this.editPanels = /* @__PURE__ */ new Map();
7517
+ this.eventListeners = /* @__PURE__ */ new Map();
7518
+ this.initEventHandlers();
7519
+ }
7520
+ /**
7521
+ * Initialize event handlers based on config
7522
+ */
7523
+ initEventHandlers() {
7524
+ if (!this.config.events) {
7525
+ return;
7526
+ }
7527
+ Object.entries(this.config.events).forEach(([eventName, handler]) => {
7528
+ this.addEventListener(eventName, handler);
7529
+ });
7530
+ }
7531
+ /**
7532
+ * Add an event listener to this component
7533
+ * @param {string} eventName - Name of the event
7534
+ * @param {function} handler - Event handler function
7535
+ */
7536
+ addEventListener(eventName, handler) {
7537
+ if (!this.eventListeners.has(eventName)) {
7538
+ this.eventListeners.set(eventName, []);
7539
+ }
7540
+ this.eventListeners.get(eventName).push(handler);
7541
+ }
7542
+ /**
7543
+ * Remove an event listener from this component
7544
+ * @param {string} eventName - Name of the event
7545
+ * @param {function} handler - Event handler function to remove
7546
+ */
7547
+ removeEventListener(eventName, handler) {
7548
+ var _a;
7549
+ if (!((_a = this.eventListeners) == null ? void 0 : _a.has(eventName))) {
7550
+ return;
7551
+ }
7552
+ const handlers = this.eventListeners.get(eventName);
7553
+ const index2 = handlers.indexOf(handler);
7554
+ if (index2 > -1) {
7555
+ handlers.splice(index2, 1);
7556
+ }
7557
+ }
7558
+ /**
7559
+ * Dispatch a component event to all registered listeners
7560
+ * @param {string} eventName - Name of the event to dispatch
7561
+ * @param {object} eventData - Data to pass to event handlers
7562
+ */
7563
+ dispatchComponentEvent(eventName, eventData = {}) {
7564
+ var _a;
7565
+ const fullEventData = {
7566
+ component: this,
7567
+ type: eventName,
7568
+ timestamp: Date.now(),
7569
+ ...eventData
7570
+ };
7571
+ if ((_a = this.eventListeners) == null ? void 0 : _a.has(eventName)) {
7572
+ this.eventListeners.get(eventName).forEach((handler) => {
7573
+ try {
7574
+ if (typeof handler === "function") {
7575
+ handler(fullEventData);
7576
+ }
7577
+ } catch (error) {
7578
+ console.error(`Error in ${eventName} event handler for ${this.name} ${this.id}:`, error);
7579
+ }
7580
+ });
7581
+ }
7582
+ return fullEventData;
7583
+ }
7584
+ /**
7585
+ * Override Data.set to dispatch component update events
7586
+ */
7587
+ set(path, newVal) {
7588
+ const oldVal = this.get(path);
7589
+ const result = super.set(path, newVal);
7590
+ if (oldVal !== newVal && this.dom) {
7591
+ this.dispatchComponentEvent("onUpdate", {
7592
+ path,
7593
+ oldValue: oldVal,
7594
+ newValue: newVal
7595
+ });
7596
+ }
7597
+ return result;
7506
7598
  }
7507
7599
  // mutationHandler = mutations =>
7508
7600
  // mutations.map(mutation => {
7509
- // @todo pull handler form config
7510
- // see dom.create.onRender for implementation pattern
7601
+ // @todo pull handler form config see dom.create.onRender for implementation pattern
7511
7602
  // })
7512
7603
  // observe(container) {
7513
7604
  // this.observer.disconnect()
@@ -7710,7 +7801,24 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7710
7801
  }
7711
7802
  const childComponentType = `${childGroup}s`;
7712
7803
  const child = components.getAddress(`${childComponentType}.${childId}`) || components[childComponentType].add(childId, data);
7713
- childWrap.insertBefore(child.dom, childWrap.children[index2]);
7804
+ if (index2 >= childWrap.children.length) {
7805
+ childWrap.appendChild(child.dom);
7806
+ } else {
7807
+ childWrap.children[index2].before(child.dom);
7808
+ }
7809
+ this.dispatchComponentEvent("onAddChild", {
7810
+ parent: this,
7811
+ target: child,
7812
+ child,
7813
+ index: index2
7814
+ });
7815
+ child.dispatchComponentEvent("onAdd", {
7816
+ parent: this,
7817
+ target: child,
7818
+ index: index2,
7819
+ addedVia: "addChild"
7820
+ // indicate how the component was added
7821
+ });
7714
7822
  (_b = (_a = this.config.events) == null ? void 0 : _a.onAddChild) == null ? void 0 : _b.call(_a, { parent: this, child });
7715
7823
  const grandChildren = child.get("children");
7716
7824
  if (grandChildren == null ? void 0 : grandChildren.length) {
@@ -7819,6 +7927,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7819
7927
  }
7820
7928
  };
7821
7929
  const component = (_a = onAddConditions[fromType]) == null ? void 0 : _a.call(onAddConditions, item, newIndex2);
7930
+ this.dispatchComponentEvent("onAdd", {
7931
+ from,
7932
+ to,
7933
+ item,
7934
+ newIndex: newIndex2,
7935
+ fromType,
7936
+ toType,
7937
+ addedComponent: component,
7938
+ addedVia: "dragDrop"
7939
+ // indicate how the component was added
7940
+ });
7822
7941
  defaultOnAdd();
7823
7942
  return component;
7824
7943
  }
@@ -7841,6 +7960,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7841
7960
  * Callback for onRender, executes any defined onRender for component
7842
7961
  */
7843
7962
  onRender() {
7963
+ this.dispatchComponentEvent("onRender", {
7964
+ dom: this.dom
7965
+ });
7844
7966
  const { events: events2 } = this.config;
7845
7967
  if (!events2) {
7846
7968
  return null;