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