bhl-forms 0.3.3 → 0.3.4

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.
@@ -10759,39 +10759,46 @@ function syncListNodes$1(node2, context) {
10759
10759
  var newChildren = [];
10760
10760
  var unused = new Set(context.children);
10761
10761
  var placeholderValues = /* @__PURE__ */ new Map();
10762
- _value.forEach((value2, i2) => {
10763
- if (context.children[i2] && context.children[i2]._value === value2) {
10762
+ _value.forEach((value, i2) => {
10763
+ if (context.children[i2] && context.children[i2]._value === value) {
10764
10764
  newChildren.push(context.children[i2]);
10765
10765
  unused.delete(context.children[i2]);
10766
10766
  } else {
10767
10767
  newChildren.push(null);
10768
- placeholderValues.set(value2, i2);
10768
+ var indexes = placeholderValues.get(value) || [];
10769
+ indexes.push(i2);
10770
+ placeholderValues.set(value, indexes);
10769
10771
  }
10770
10772
  });
10771
10773
  if (unused.size && placeholderValues.size) {
10772
10774
  unused.forEach((child2) => {
10773
10775
  if (placeholderValues.has(child2._value)) {
10774
- newChildren[placeholderValues.get(child2._value)] = child2;
10776
+ var indexes = placeholderValues.get(child2._value);
10777
+ var index3 = indexes.shift();
10778
+ newChildren[index3] = child2;
10775
10779
  unused.delete(child2);
10776
- placeholderValues.delete(child2._value);
10780
+ if (!indexes.length)
10781
+ placeholderValues.delete(child2._value);
10777
10782
  }
10778
10783
  });
10779
10784
  }
10780
- while (unused.size && placeholderValues.size) {
10785
+ var emptyIndexes = [];
10786
+ placeholderValues.forEach((indexes) => {
10787
+ emptyIndexes.push(...indexes);
10788
+ });
10789
+ while (unused.size && emptyIndexes.length) {
10781
10790
  var child = unused.values().next().value;
10782
- var placeholders = placeholderValues[Symbol.iterator]();
10783
- var [value, index2] = placeholders.next().value;
10791
+ var index2 = emptyIndexes.shift();
10792
+ if (index2 === void 0)
10793
+ break;
10784
10794
  newChildren[index2] = child;
10785
10795
  unused.delete(child);
10786
- placeholderValues.delete(value);
10787
10796
  }
10788
- if (placeholderValues.size) {
10789
- placeholderValues.forEach((index3, value2) => {
10790
- newChildren[index3] = createPlaceholder$1({
10791
- value: value2
10792
- });
10797
+ emptyIndexes.forEach((index3, value) => {
10798
+ newChildren[index3] = createPlaceholder$1({
10799
+ value
10793
10800
  });
10794
- }
10801
+ });
10795
10802
  if (unused.size) {
10796
10803
  unused.forEach((child2) => {
10797
10804
  if (!("__FKP" in child2)) {
@@ -12804,39 +12811,46 @@ function syncListNodes(node2, context) {
12804
12811
  var newChildren = [];
12805
12812
  var unused = new Set(context.children);
12806
12813
  var placeholderValues = /* @__PURE__ */ new Map();
12807
- _value.forEach((value2, i2) => {
12808
- if (context.children[i2] && context.children[i2]._value === value2) {
12814
+ _value.forEach((value, i2) => {
12815
+ if (context.children[i2] && context.children[i2]._value === value) {
12809
12816
  newChildren.push(context.children[i2]);
12810
12817
  unused.delete(context.children[i2]);
12811
12818
  } else {
12812
12819
  newChildren.push(null);
12813
- placeholderValues.set(value2, i2);
12820
+ var indexes = placeholderValues.get(value) || [];
12821
+ indexes.push(i2);
12822
+ placeholderValues.set(value, indexes);
12814
12823
  }
12815
12824
  });
12816
12825
  if (unused.size && placeholderValues.size) {
12817
12826
  unused.forEach((child2) => {
12818
12827
  if (placeholderValues.has(child2._value)) {
12819
- newChildren[placeholderValues.get(child2._value)] = child2;
12828
+ var indexes = placeholderValues.get(child2._value);
12829
+ var index3 = indexes.shift();
12830
+ newChildren[index3] = child2;
12820
12831
  unused.delete(child2);
12821
- placeholderValues.delete(child2._value);
12832
+ if (!indexes.length)
12833
+ placeholderValues.delete(child2._value);
12822
12834
  }
12823
12835
  });
12824
12836
  }
12825
- while (unused.size && placeholderValues.size) {
12837
+ var emptyIndexes = [];
12838
+ placeholderValues.forEach((indexes) => {
12839
+ emptyIndexes.push(...indexes);
12840
+ });
12841
+ while (unused.size && emptyIndexes.length) {
12826
12842
  var child = unused.values().next().value;
12827
- var placeholders = placeholderValues[Symbol.iterator]();
12828
- var [value, index2] = placeholders.next().value;
12843
+ var index2 = emptyIndexes.shift();
12844
+ if (index2 === void 0)
12845
+ break;
12829
12846
  newChildren[index2] = child;
12830
12847
  unused.delete(child);
12831
- placeholderValues.delete(value);
12832
12848
  }
12833
- if (placeholderValues.size) {
12834
- placeholderValues.forEach((index3, value2) => {
12835
- newChildren[index3] = createPlaceholder({
12836
- value: value2
12837
- });
12849
+ emptyIndexes.forEach((index3, value) => {
12850
+ newChildren[index3] = createPlaceholder({
12851
+ value
12838
12852
  });
12839
- }
12853
+ });
12840
12854
  if (unused.size) {
12841
12855
  unused.forEach((child2) => {
12842
12856
  if (!("__FKP" in child2)) {
@@ -13848,7 +13862,7 @@ function clearErrors(id2) {
13848
13862
  warn(652, id2);
13849
13863
  }
13850
13864
  }
13851
- var FORMKIT_VERSION = "0.17.0";
13865
+ var FORMKIT_VERSION = "0.17.2";
13852
13866
  function createLibraryPlugin() {
13853
13867
  for (var _len = arguments.length, libraries = new Array(_len), _key = 0; _key < _len; _key++) {
13854
13868
  libraries[_key] = arguments[_key];
@@ -18630,7 +18644,7 @@ function useInput(props2, context) {
18630
18644
  }
18631
18645
  if (isVModeled && node2.context) {
18632
18646
  clonedValueBeforeVmodel = cloneAny(node2.value);
18633
- context.emit("update:modelValue", node2.value);
18647
+ context.emit("update:modelValue", shallowClone(node2.value));
18634
18648
  }
18635
18649
  });
18636
18650
  if (isVModeled) {
@@ -18675,6 +18689,9 @@ function createInput(schemaOrComponent) {
18675
18689
  schema = createSection("input", () => cloneAny(schemaOrComponent));
18676
18690
  }
18677
18691
  definition2.schema = useSchema(schema || "Schema undefined");
18692
+ if (!definition2.schemaMemoKey) {
18693
+ definition2.schemaMemoKey = "".concat(Math.random());
18694
+ }
18678
18695
  return definition2;
18679
18696
  }
18680
18697
  var messages = createSection("messages", () => ({
@@ -18973,8 +18990,12 @@ var vueBindings = function vueBindings2(node2) {
18973
18990
  var {
18974
18991
  payload
18975
18992
  } = _ref10;
18976
- value.value = _value.value = payload;
18977
- triggerRef(value);
18993
+ if (node2.type !== "input" && !isRef(payload) && !isReactive(payload)) {
18994
+ value.value = _value.value = shallowClone(payload);
18995
+ } else {
18996
+ value.value = _value.value = payload;
18997
+ triggerRef(value);
18998
+ }
18978
18999
  node2.emit("modelUpdated");
18979
19000
  });
18980
19001
  node2.on("commit", () => {
@@ -19646,42 +19667,112 @@ var multiStepOuter = createSection("multiStepOuter", () => ({
19646
19667
  props: ["previousLabel", "nextLabel", "beforeStepChange", "previousAttrs", "nextAttrs", "validStepIcon"],
19647
19668
  features: [localize$2("next"), localize$2("prev")]
19648
19669
  });
19649
- function createLocalStoragePlugin(LocalStorageOptions) {
19670
+ function createLocalStoragePlugin(localStorageOptions) {
19650
19671
  var localStoragePlugin = (node2) => {
19651
- if (node2.props.type !== "form")
19672
+ if (node2.type !== "group")
19652
19673
  return;
19653
- node2.addProps(["useLocalStorage"]);
19654
- node2.on("created", () => {
19655
- var _a, _b;
19656
- var useLocalStorage = undefine(node2.props.useLocalStorage);
19657
- if (!useLocalStorage)
19658
- return;
19659
- var prefix2 = (_a = LocalStorageOptions === null || LocalStorageOptions === void 0 ? void 0 : LocalStorageOptions.prefix) !== null && _a !== void 0 ? _a : "formkit";
19660
- var maxAge = (_b = LocalStorageOptions === null || LocalStorageOptions === void 0 ? void 0 : LocalStorageOptions.maxAge) !== null && _b !== void 0 ? _b : 36e5;
19661
- var key = "".concat(prefix2, "-").concat(node2.name);
19662
- var value = localStorage.getItem(key);
19663
- if (value) {
19664
- var localStorageValue = JSON.parse(value);
19665
- if (localStorageValue.maxAge > Date.now()) {
19666
- node2.input(localStorageValue.data);
19667
- } else {
19668
- localStorage.removeItem(key);
19674
+ var shouldUseLocalStorage = (controlNode) => {
19675
+ var controlFieldValue = true;
19676
+ if (controlNode) {
19677
+ controlFieldValue = controlNode.value === true;
19678
+ }
19679
+ return undefine(node2.props.useLocalStorage) && controlFieldValue;
19680
+ };
19681
+ node2.on("created", /* @__PURE__ */ _asyncToGenerator(function* () {
19682
+ var _a, _b, _c;
19683
+ node2.addProps(["useLocalStorage"]);
19684
+ yield node2.settled;
19685
+ var controlField = (_a = localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.control) !== null && _a !== void 0 ? _a : void 0;
19686
+ var controlNode;
19687
+ if (typeof controlField === "string") {
19688
+ var _controlNode = node2.at(controlField);
19689
+ if (_controlNode) {
19690
+ _controlNode.on("commit", () => {
19691
+ useLocalStorage = shouldUseLocalStorage(_controlNode);
19692
+ if (!useLocalStorage) {
19693
+ localStorage.removeItem(storageKey);
19694
+ }
19695
+ });
19669
19696
  }
19670
19697
  }
19671
- node2.on("commit", (_ref6) => {
19698
+ var useLocalStorage = shouldUseLocalStorage(controlNode);
19699
+ var saveTimeout = 0;
19700
+ var debounce = typeof (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.debounce) === "number" ? localStorageOptions.debounce : 200;
19701
+ var prefix2 = (_b = localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.prefix) !== null && _b !== void 0 ? _b : "formkit";
19702
+ var maxAge = (_c = localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.maxAge) !== null && _c !== void 0 ? _c : 36e5;
19703
+ var key = (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.key) ? "-".concat(localStorageOptions.key) : "";
19704
+ var storageKey = "".concat(prefix2).concat(key, "-").concat(node2.name);
19705
+ var loadValue = /* @__PURE__ */ function() {
19706
+ var _ref7 = _asyncToGenerator(function* () {
19707
+ var value = localStorage.getItem(storageKey);
19708
+ if (!value)
19709
+ return;
19710
+ var loadValue2 = JSON.parse(value);
19711
+ if (typeof (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.beforeLoad) === "function") {
19712
+ node2.props.disabled = true;
19713
+ try {
19714
+ loadValue2.data = yield localStorageOptions.beforeLoad(loadValue2.data);
19715
+ } catch (error2) {
19716
+ console.error(error2);
19717
+ }
19718
+ node2.props.disabled = false;
19719
+ }
19720
+ if (!loadValue2 || typeof loadValue2.data !== "object")
19721
+ return;
19722
+ if (loadValue2.maxAge > Date.now()) {
19723
+ node2.input(loadValue2.data, false);
19724
+ } else {
19725
+ localStorage.removeItem(storageKey);
19726
+ }
19727
+ });
19728
+ return function loadValue2() {
19729
+ return _ref7.apply(this, arguments);
19730
+ };
19731
+ }();
19732
+ var saveValue = /* @__PURE__ */ function() {
19733
+ var _ref8 = _asyncToGenerator(function* (payload) {
19734
+ var savePayload = payload;
19735
+ if (typeof (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.beforeSave) === "function") {
19736
+ try {
19737
+ savePayload = yield localStorageOptions.beforeSave(payload);
19738
+ } catch (error2) {
19739
+ console.error(error2);
19740
+ }
19741
+ }
19742
+ if (!savePayload)
19743
+ return;
19744
+ localStorage.setItem(storageKey, JSON.stringify({
19745
+ maxAge: Date.now() + maxAge,
19746
+ data: savePayload
19747
+ }));
19748
+ });
19749
+ return function saveValue2(_x) {
19750
+ return _ref8.apply(this, arguments);
19751
+ };
19752
+ }();
19753
+ node2.on("commit", (_ref9) => {
19672
19754
  var {
19673
19755
  payload
19674
- } = _ref6;
19675
- localStorage.setItem(key, JSON.stringify({
19676
- maxAge: Date.now() + maxAge,
19677
- data: payload
19678
- }));
19756
+ } = _ref9;
19757
+ if (!useLocalStorage)
19758
+ return;
19759
+ clearTimeout(saveTimeout);
19760
+ saveTimeout = setTimeout(/* @__PURE__ */ _asyncToGenerator(function* () {
19761
+ saveValue(payload);
19762
+ }), debounce);
19763
+ });
19764
+ node2.on("prop:useLocalStorage", () => {
19765
+ useLocalStorage = shouldUseLocalStorage(controlNode);
19766
+ if (!useLocalStorage) {
19767
+ localStorage.removeItem(storageKey);
19768
+ }
19679
19769
  });
19680
19770
  node2.hook.submit((payload, next3) => {
19681
- localStorage.removeItem(key);
19771
+ localStorage.removeItem(storageKey);
19682
19772
  return next3(payload);
19683
19773
  });
19684
- });
19774
+ yield loadValue();
19775
+ }));
19685
19776
  };
19686
19777
  return localStoragePlugin;
19687
19778
  }