bhl-forms 0.3.3 → 0.4.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.
- package/dist/bhl-forms.es.js +190 -90
- package/dist/bhl-forms.iife.js +7 -7
- package/dist/bhl-forms.modern.es.js +219 -104
- package/dist/bhl-forms.modern.iife.js +9 -9
- package/dist/bhl-forms.modern.umd.js +9 -9
- package/dist/bhl-forms.umd.js +7 -7
- package/dist/forms/accidentsAndInjuries.es.js +19 -9
- package/dist/forms/accidentsAndInjuries.iife.js +1 -1
- package/dist/forms/accidentsAndInjuries.json +1 -1
- package/dist/forms/appraisals.es.js +14 -4
- package/dist/forms/appraisals.iife.js +1 -1
- package/dist/forms/appraisals.json +1 -1
- package/dist/forms/childAndFamily.es.js +19 -9
- package/dist/forms/childAndFamily.iife.js +1 -1
- package/dist/forms/childAndFamily.json +1 -1
- package/dist/forms/civilLawsuit.es.js +22 -10
- package/dist/forms/civilLawsuit.iife.js +1 -1
- package/dist/forms/civilLawsuit.json +1 -1
- package/dist/forms/coins.es.js +14 -4
- package/dist/forms/coins.iife.js +1 -1
- package/dist/forms/coins.json +1 -1
- package/dist/forms/contracts.es.js +19 -9
- package/dist/forms/contracts.iife.js +1 -1
- package/dist/forms/contracts.json +1 -1
- package/dist/forms/criminal.es.js +19 -9
- package/dist/forms/criminal.iife.js +1 -1
- package/dist/forms/criminal.json +1 -1
- package/dist/forms/employmentAndWorkplace.es.js +19 -9
- package/dist/forms/employmentAndWorkplace.iife.js +1 -1
- package/dist/forms/employmentAndWorkplace.json +1 -1
- package/dist/forms/generalLegal.es.js +247 -18
- package/dist/forms/generalLegal.iife.js +1 -1
- package/dist/forms/generalLegal.json +1 -1
- package/dist/forms/generalLegalPopUnder.es.js +22 -10
- package/dist/forms/generalLegalPopUnder.iife.js +1 -1
- package/dist/forms/generalLegalPopUnder.json +1 -1
- package/dist/forms/generalLegalPopUnderTF.es.js +19 -9
- package/dist/forms/generalLegalPopUnderTF.iife.js +1 -1
- package/dist/forms/generalLegalPopUnderTF.json +1 -1
- package/dist/forms/generalLegalThankYou.es.js +19 -9
- package/dist/forms/generalLegalThankYou.iife.js +1 -1
- package/dist/forms/generalLegalThankYou.json +1 -1
- package/dist/forms/harassmentAndDiscrimination.es.js +19 -9
- package/dist/forms/harassmentAndDiscrimination.iife.js +1 -1
- package/dist/forms/harassmentAndDiscrimination.json +1 -1
- package/dist/forms/malpractice.es.js +19 -9
- package/dist/forms/malpractice.iife.js +1 -1
- package/dist/forms/malpractice.json +1 -1
- package/dist/forms/mechanics.es.js +14 -4
- package/dist/forms/mechanics.iife.js +1 -1
- package/dist/forms/mechanics.json +1 -1
- package/dist/forms/realEstate.es.js +19 -9
- package/dist/forms/realEstate.iife.js +1 -1
- package/dist/forms/realEstate.json +1 -1
- package/dist/forms/repossession.es.js +19 -9
- package/dist/forms/repossession.iife.js +1 -1
- package/dist/forms/repossession.json +1 -1
- package/dist/forms/ssdi.es.js +19 -9
- package/dist/forms/ssdi.iife.js +1 -1
- package/dist/forms/ssdi.json +1 -1
- package/dist/forms/testForm.es.js +19 -9
- package/dist/forms/testForm.iife.js +1 -1
- package/dist/forms/testForm.json +1 -1
- package/dist/forms/testRedirects.es.js +14 -4
- package/dist/forms/testRedirects.iife.js +1 -1
- package/dist/forms/testRedirects.json +1 -1
- package/dist/forms/vets.es.js +15 -5
- package/dist/forms/vets.iife.js +1 -1
- package/dist/forms/vets.json +1 -1
- package/dist/forms/willsAndTrusts.es.js +19 -9
- package/dist/forms/willsAndTrusts.iife.js +1 -1
- package/dist/forms/willsAndTrusts.json +1 -1
- package/package.json +6 -6
package/dist/bhl-forms.es.js
CHANGED
|
@@ -4789,7 +4789,17 @@ const getRedirect = (formData, node) => {
|
|
|
4789
4789
|
}
|
|
4790
4790
|
return redirectUrl;
|
|
4791
4791
|
};
|
|
4792
|
+
var clearErrorTimeout = 0;
|
|
4793
|
+
const setNodeError = (node, message2) => {
|
|
4794
|
+
node.setErrors(message2);
|
|
4795
|
+
clearErrorTimeout = setTimeout(() => {
|
|
4796
|
+
node.store.filter((m3) => {
|
|
4797
|
+
return m3.type !== "error";
|
|
4798
|
+
});
|
|
4799
|
+
}, 5e3);
|
|
4800
|
+
};
|
|
4792
4801
|
const handleSubmitError = (err, node) => {
|
|
4802
|
+
clearTimeout(clearErrorTimeout);
|
|
4793
4803
|
if (err.response) {
|
|
4794
4804
|
const code = err.response.status;
|
|
4795
4805
|
if (node.props.attrs.errorCodes && code in node.props.attrs.errorCodes) {
|
|
@@ -4807,12 +4817,12 @@ const handleSubmitError = (err, node) => {
|
|
|
4807
4817
|
}
|
|
4808
4818
|
}
|
|
4809
4819
|
if (message2) {
|
|
4810
|
-
node
|
|
4820
|
+
setNodeError(node, message2);
|
|
4811
4821
|
}
|
|
4812
4822
|
return abort;
|
|
4813
4823
|
}
|
|
4814
4824
|
}
|
|
4815
|
-
node
|
|
4825
|
+
setNodeError(node, err.toString());
|
|
4816
4826
|
return true;
|
|
4817
4827
|
};
|
|
4818
4828
|
const getKey = (d3, path, def2) => {
|
|
@@ -5417,31 +5427,38 @@ function syncListNodes$1(node, context) {
|
|
|
5417
5427
|
unused.delete(context.children[i2]);
|
|
5418
5428
|
} else {
|
|
5419
5429
|
newChildren.push(null);
|
|
5420
|
-
placeholderValues.
|
|
5430
|
+
const indexes = placeholderValues.get(value) || [];
|
|
5431
|
+
indexes.push(i2);
|
|
5432
|
+
placeholderValues.set(value, indexes);
|
|
5421
5433
|
}
|
|
5422
5434
|
});
|
|
5423
5435
|
if (unused.size && placeholderValues.size) {
|
|
5424
5436
|
unused.forEach((child) => {
|
|
5425
5437
|
if (placeholderValues.has(child._value)) {
|
|
5426
|
-
|
|
5438
|
+
const indexes = placeholderValues.get(child._value);
|
|
5439
|
+
const index2 = indexes.shift();
|
|
5440
|
+
newChildren[index2] = child;
|
|
5427
5441
|
unused.delete(child);
|
|
5428
|
-
|
|
5442
|
+
if (!indexes.length)
|
|
5443
|
+
placeholderValues.delete(child._value);
|
|
5429
5444
|
}
|
|
5430
5445
|
});
|
|
5431
5446
|
}
|
|
5432
|
-
|
|
5447
|
+
const emptyIndexes = [];
|
|
5448
|
+
placeholderValues.forEach((indexes) => {
|
|
5449
|
+
emptyIndexes.push(...indexes);
|
|
5450
|
+
});
|
|
5451
|
+
while (unused.size && emptyIndexes.length) {
|
|
5433
5452
|
const child = unused.values().next().value;
|
|
5434
|
-
const
|
|
5435
|
-
|
|
5453
|
+
const index2 = emptyIndexes.shift();
|
|
5454
|
+
if (index2 === void 0)
|
|
5455
|
+
break;
|
|
5436
5456
|
newChildren[index2] = child;
|
|
5437
5457
|
unused.delete(child);
|
|
5438
|
-
placeholderValues.delete(value);
|
|
5439
|
-
}
|
|
5440
|
-
if (placeholderValues.size) {
|
|
5441
|
-
placeholderValues.forEach((index2, value) => {
|
|
5442
|
-
newChildren[index2] = createPlaceholder$1({ value });
|
|
5443
|
-
});
|
|
5444
5458
|
}
|
|
5459
|
+
emptyIndexes.forEach((index2, value) => {
|
|
5460
|
+
newChildren[index2] = createPlaceholder$1({ value });
|
|
5461
|
+
});
|
|
5445
5462
|
if (unused.size) {
|
|
5446
5463
|
unused.forEach((child) => {
|
|
5447
5464
|
if (!("__FKP" in child)) {
|
|
@@ -5967,6 +5984,9 @@ function useSteps() {
|
|
|
5967
5984
|
const setStepQueue = (value) => {
|
|
5968
5985
|
stepQueue2.value = [...value];
|
|
5969
5986
|
};
|
|
5987
|
+
const stepEnabled2 = (stepName) => {
|
|
5988
|
+
return enabledSteps2().indexOf(stepName) > -1;
|
|
5989
|
+
};
|
|
5970
5990
|
const queueStep = (stepName, next = false) => {
|
|
5971
5991
|
if (next == true) {
|
|
5972
5992
|
stepQueue2.value.unshift(stepName);
|
|
@@ -6026,16 +6046,18 @@ function useSteps() {
|
|
|
6026
6046
|
throw Error("Unexpected value for nextStep: " + nextStep);
|
|
6027
6047
|
}
|
|
6028
6048
|
if (autoFocus) {
|
|
6029
|
-
|
|
6030
|
-
const firstInput = findFirstInput(newNode);
|
|
6031
|
-
if (firstInput && autoFocusTypes.indexOf(firstInput.context.type) > -1) {
|
|
6032
|
-
const elem = document.getElementById(firstInput.context.id);
|
|
6049
|
+
setTimeout(function() {
|
|
6033
6050
|
try {
|
|
6034
|
-
|
|
6051
|
+
const newNode = steps2[activeStep2.value].node;
|
|
6052
|
+
const firstInput = findFirstInput(newNode);
|
|
6053
|
+
if (firstInput && autoFocusTypes.indexOf(firstInput.context.type) > -1) {
|
|
6054
|
+
const elem = document.getElementById(firstInput.context.id);
|
|
6055
|
+
focusAndOpenKeyboard(elem);
|
|
6056
|
+
}
|
|
6035
6057
|
} catch (e2) {
|
|
6036
6058
|
console.warn("Failed to autoFocus:", e2);
|
|
6037
6059
|
}
|
|
6038
|
-
}
|
|
6060
|
+
}, 50);
|
|
6039
6061
|
}
|
|
6040
6062
|
return true;
|
|
6041
6063
|
};
|
|
@@ -6058,39 +6080,40 @@ function useSteps() {
|
|
|
6058
6080
|
if (node.props.attrs.defaultOrder) {
|
|
6059
6081
|
defaultOrder2.push(...node.props.attrs.defaultOrder);
|
|
6060
6082
|
}
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6083
|
+
node.on("child", ({ payload: childNode }) => {
|
|
6084
|
+
if (childNode.type === "group") {
|
|
6085
|
+
if (defaultOrder2.length > 0) {
|
|
6086
|
+
if (Object.keys(steps2).length === 0) {
|
|
6087
|
+
setStepQueue(defaultOrder2);
|
|
6088
|
+
}
|
|
6089
|
+
} else {
|
|
6090
|
+
if (!stepEnabled2(childNode.name)) {
|
|
6091
|
+
queueStep(childNode.name);
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
steps2[childNode.name] = {};
|
|
6095
|
+
steps2[childNode.name].node = childNode;
|
|
6096
|
+
childNode.on("created", () => {
|
|
6097
|
+
steps2[childNode.name].valid = toRef(childNode.context.state, "valid");
|
|
6098
|
+
});
|
|
6099
|
+
childNode.on("count:errors", ({ payload: count2 }) => {
|
|
6100
|
+
steps2[childNode.name].errorCount = count2;
|
|
6101
|
+
});
|
|
6102
|
+
childNode.on("count:blocking", ({ payload: count2 }) => {
|
|
6103
|
+
steps2[childNode.name].blockingCount = count2;
|
|
6104
|
+
});
|
|
6105
|
+
if (activeStep2.value === "") {
|
|
6106
|
+
activeStep2.value = childNode.name;
|
|
6107
|
+
}
|
|
6071
6108
|
}
|
|
6072
|
-
}
|
|
6073
|
-
steps2[node.name] = steps2[node.name] || {};
|
|
6074
|
-
steps2[node.name].node = node;
|
|
6075
|
-
node.on("created", () => {
|
|
6076
|
-
steps2[node.name].valid = toRef(node.context.state, "valid");
|
|
6077
|
-
});
|
|
6078
|
-
node.on("count:errors", ({ payload: count2 }) => {
|
|
6079
|
-
steps2[node.name].errorCount = count2;
|
|
6080
|
-
});
|
|
6081
|
-
node.on("count:blocking", ({ payload: count2 }) => {
|
|
6082
|
-
steps2[node.name].blockingCount = count2;
|
|
6083
6109
|
});
|
|
6084
|
-
|
|
6085
|
-
activeStep2.value = node.name;
|
|
6086
|
-
}
|
|
6087
|
-
return false;
|
|
6110
|
+
return true;
|
|
6088
6111
|
}
|
|
6089
6112
|
};
|
|
6090
|
-
return { stepPlugin: stepPlugin2, steps: steps2, stepHistory: stepHistory2, stepQueue: stepQueue2, enabledSteps: enabledSteps2, defaultOrder: defaultOrder2, activeStep: activeStep2, firstStep: firstStep2, lastStep: lastStep2, setStep: setStep2, setStepQueue, setNextStep: setNextStep2, setPreviousStep: setPreviousStep2 };
|
|
6113
|
+
return { stepPlugin: stepPlugin2, steps: steps2, stepHistory: stepHistory2, stepQueue: stepQueue2, enabledSteps: enabledSteps2, stepEnabled: stepEnabled2, defaultOrder: defaultOrder2, activeStep: activeStep2, firstStep: firstStep2, lastStep: lastStep2, setStep: setStep2, setStepQueue, setNextStep: setNextStep2, setPreviousStep: setPreviousStep2 };
|
|
6091
6114
|
}
|
|
6092
6115
|
let { prepopPlugin } = usePrepop();
|
|
6093
|
-
let { stepPlugin, steps: steps$1, stepHistory, stepQueue, enabledSteps, defaultOrder, activeStep, firstStep, lastStep, setStep, setNextStep, setPreviousStep } = useSteps();
|
|
6116
|
+
let { stepPlugin, steps: steps$1, stepHistory, stepQueue, enabledSteps, stepEnabled, defaultOrder, activeStep, firstStep, lastStep, setStep, setNextStep, setPreviousStep } = useSteps();
|
|
6094
6117
|
const urlParams$2 = new URLSearchParams(window.location.search);
|
|
6095
6118
|
const dataDefaults = {
|
|
6096
6119
|
steps: steps$1,
|
|
@@ -6104,6 +6127,9 @@ const dataDefaults = {
|
|
|
6104
6127
|
urlParam: (name, backup = null) => {
|
|
6105
6128
|
return urlParams$2.get(name) || backup;
|
|
6106
6129
|
},
|
|
6130
|
+
stepKeys: () => {
|
|
6131
|
+
return Object.keys(steps$1);
|
|
6132
|
+
},
|
|
6107
6133
|
firstStep: () => {
|
|
6108
6134
|
return firstStep();
|
|
6109
6135
|
},
|
|
@@ -6119,19 +6145,19 @@ const dataDefaults = {
|
|
|
6119
6145
|
setStep: (nextStep, validate2, autoFocus, preStep) => () => {
|
|
6120
6146
|
return setStep({ nextStep, validate: validate2, autoFocus, preStep });
|
|
6121
6147
|
},
|
|
6122
|
-
|
|
6148
|
+
stepValid: (stepName) => {
|
|
6123
6149
|
return steps$1[stepName].valid && steps$1[stepName].errorCount === 0;
|
|
6124
6150
|
},
|
|
6125
|
-
|
|
6151
|
+
stepEnabled: (stepName) => {
|
|
6126
6152
|
if (!enabledSteps().length) {
|
|
6127
6153
|
return true;
|
|
6128
6154
|
}
|
|
6129
|
-
return
|
|
6155
|
+
return stepEnabled(stepName);
|
|
6130
6156
|
},
|
|
6131
6157
|
getKey: (d3, k2, def2) => {
|
|
6132
6158
|
return getKey(d3, k2, def2);
|
|
6133
6159
|
},
|
|
6134
|
-
|
|
6160
|
+
inputEnabled: (node, key, inputName) => {
|
|
6135
6161
|
if (!node || !key || !node.attrs.inputMap) {
|
|
6136
6162
|
return true;
|
|
6137
6163
|
}
|
|
@@ -7252,31 +7278,38 @@ function syncListNodes(node, context) {
|
|
|
7252
7278
|
unused.delete(context.children[i2]);
|
|
7253
7279
|
} else {
|
|
7254
7280
|
newChildren.push(null);
|
|
7255
|
-
placeholderValues.
|
|
7281
|
+
const indexes = placeholderValues.get(value) || [];
|
|
7282
|
+
indexes.push(i2);
|
|
7283
|
+
placeholderValues.set(value, indexes);
|
|
7256
7284
|
}
|
|
7257
7285
|
});
|
|
7258
7286
|
if (unused.size && placeholderValues.size) {
|
|
7259
7287
|
unused.forEach((child) => {
|
|
7260
7288
|
if (placeholderValues.has(child._value)) {
|
|
7261
|
-
|
|
7289
|
+
const indexes = placeholderValues.get(child._value);
|
|
7290
|
+
const index2 = indexes.shift();
|
|
7291
|
+
newChildren[index2] = child;
|
|
7262
7292
|
unused.delete(child);
|
|
7263
|
-
|
|
7293
|
+
if (!indexes.length)
|
|
7294
|
+
placeholderValues.delete(child._value);
|
|
7264
7295
|
}
|
|
7265
7296
|
});
|
|
7266
7297
|
}
|
|
7267
|
-
|
|
7298
|
+
const emptyIndexes = [];
|
|
7299
|
+
placeholderValues.forEach((indexes) => {
|
|
7300
|
+
emptyIndexes.push(...indexes);
|
|
7301
|
+
});
|
|
7302
|
+
while (unused.size && emptyIndexes.length) {
|
|
7268
7303
|
const child = unused.values().next().value;
|
|
7269
|
-
const
|
|
7270
|
-
|
|
7304
|
+
const index2 = emptyIndexes.shift();
|
|
7305
|
+
if (index2 === void 0)
|
|
7306
|
+
break;
|
|
7271
7307
|
newChildren[index2] = child;
|
|
7272
7308
|
unused.delete(child);
|
|
7273
|
-
placeholderValues.delete(value);
|
|
7274
|
-
}
|
|
7275
|
-
if (placeholderValues.size) {
|
|
7276
|
-
placeholderValues.forEach((index2, value) => {
|
|
7277
|
-
newChildren[index2] = createPlaceholder({ value });
|
|
7278
|
-
});
|
|
7279
7309
|
}
|
|
7310
|
+
emptyIndexes.forEach((index2, value) => {
|
|
7311
|
+
newChildren[index2] = createPlaceholder({ value });
|
|
7312
|
+
});
|
|
7280
7313
|
if (unused.size) {
|
|
7281
7314
|
unused.forEach((child) => {
|
|
7282
7315
|
if (!("__FKP" in child)) {
|
|
@@ -8228,7 +8261,7 @@ function clearErrors(id, clearChildren = true) {
|
|
|
8228
8261
|
warn(652, id);
|
|
8229
8262
|
}
|
|
8230
8263
|
}
|
|
8231
|
-
const FORMKIT_VERSION = "0.17.
|
|
8264
|
+
const FORMKIT_VERSION = "0.17.2";
|
|
8232
8265
|
function createLibraryPlugin(...libraries) {
|
|
8233
8266
|
const library = libraries.reduce((merged, lib) => extend$1(merged, lib), {});
|
|
8234
8267
|
const plugin2 = () => {
|
|
@@ -11229,7 +11262,7 @@ function useInput(props2, context, options2 = {}) {
|
|
|
11229
11262
|
}
|
|
11230
11263
|
if (isVModeled && node.context) {
|
|
11231
11264
|
clonedValueBeforeVmodel = cloneAny(node.value);
|
|
11232
|
-
context.emit("update:modelValue", node.value);
|
|
11265
|
+
context.emit("update:modelValue", shallowClone(node.value));
|
|
11233
11266
|
}
|
|
11234
11267
|
});
|
|
11235
11268
|
if (isVModeled) {
|
|
@@ -11269,6 +11302,9 @@ function createInput(schemaOrComponent, definitionOptions = {}) {
|
|
|
11269
11302
|
schema = createSection("input", () => cloneAny(schemaOrComponent));
|
|
11270
11303
|
}
|
|
11271
11304
|
definition2.schema = useSchema(schema || "Schema undefined");
|
|
11305
|
+
if (!definition2.schemaMemoKey) {
|
|
11306
|
+
definition2.schemaMemoKey = `${Math.random()}`;
|
|
11307
|
+
}
|
|
11272
11308
|
return definition2;
|
|
11273
11309
|
}
|
|
11274
11310
|
const messages = createSection("messages", () => ({
|
|
@@ -11539,8 +11575,12 @@ const vueBindings = function vueBindings2(node) {
|
|
|
11539
11575
|
}
|
|
11540
11576
|
});
|
|
11541
11577
|
node.on("commitRaw", ({ payload }) => {
|
|
11542
|
-
|
|
11543
|
-
|
|
11578
|
+
if (node.type !== "input" && !isRef(payload) && !isReactive(payload)) {
|
|
11579
|
+
value.value = _value.value = shallowClone(payload);
|
|
11580
|
+
} else {
|
|
11581
|
+
value.value = _value.value = payload;
|
|
11582
|
+
triggerRef(value);
|
|
11583
|
+
}
|
|
11544
11584
|
node.emit("modelUpdated");
|
|
11545
11585
|
});
|
|
11546
11586
|
node.on("commit", () => {
|
|
@@ -12190,39 +12230,99 @@ const multiStepOuter = createSection("multiStepOuter", () => ({
|
|
|
12190
12230
|
],
|
|
12191
12231
|
features: [localize$2("next"), localize$2("prev")]
|
|
12192
12232
|
});
|
|
12193
|
-
function createLocalStoragePlugin(
|
|
12233
|
+
function createLocalStoragePlugin(localStorageOptions) {
|
|
12194
12234
|
const localStoragePlugin = (node) => {
|
|
12195
|
-
if (node.
|
|
12235
|
+
if (node.type !== "group")
|
|
12196
12236
|
return;
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
|
|
12201
|
-
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
|
|
12205
|
-
|
|
12206
|
-
|
|
12207
|
-
|
|
12208
|
-
|
|
12209
|
-
|
|
12210
|
-
|
|
12211
|
-
|
|
12212
|
-
|
|
12237
|
+
const shouldUseLocalStorage = (controlNode) => {
|
|
12238
|
+
let controlFieldValue = true;
|
|
12239
|
+
if (controlNode) {
|
|
12240
|
+
controlFieldValue = controlNode.value === true;
|
|
12241
|
+
}
|
|
12242
|
+
return undefine(node.props.useLocalStorage) && controlFieldValue;
|
|
12243
|
+
};
|
|
12244
|
+
node.on("created", () => __async(this, null, function* () {
|
|
12245
|
+
var _a, _b, _c;
|
|
12246
|
+
node.addProps(["useLocalStorage"]);
|
|
12247
|
+
yield node.settled;
|
|
12248
|
+
const controlField = (_a = localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.control) !== null && _a !== void 0 ? _a : void 0;
|
|
12249
|
+
let controlNode;
|
|
12250
|
+
if (typeof controlField === "string") {
|
|
12251
|
+
const controlNode2 = node.at(controlField);
|
|
12252
|
+
if (controlNode2) {
|
|
12253
|
+
controlNode2.on("commit", () => {
|
|
12254
|
+
useLocalStorage = shouldUseLocalStorage(controlNode2);
|
|
12255
|
+
if (!useLocalStorage) {
|
|
12256
|
+
localStorage.removeItem(storageKey);
|
|
12257
|
+
}
|
|
12258
|
+
});
|
|
12213
12259
|
}
|
|
12214
12260
|
}
|
|
12215
|
-
|
|
12216
|
-
|
|
12261
|
+
let useLocalStorage = shouldUseLocalStorage(controlNode);
|
|
12262
|
+
let saveTimeout = 0;
|
|
12263
|
+
const debounce = typeof (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.debounce) === "number" ? localStorageOptions.debounce : 200;
|
|
12264
|
+
const prefix2 = (_b = localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.prefix) !== null && _b !== void 0 ? _b : "formkit";
|
|
12265
|
+
const maxAge = (_c = localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.maxAge) !== null && _c !== void 0 ? _c : 36e5;
|
|
12266
|
+
const key = (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.key) ? `-${localStorageOptions.key}` : "";
|
|
12267
|
+
const storageKey = `${prefix2}${key}-${node.name}`;
|
|
12268
|
+
const loadValue = () => __async(this, null, function* () {
|
|
12269
|
+
const value = localStorage.getItem(storageKey);
|
|
12270
|
+
if (!value)
|
|
12271
|
+
return;
|
|
12272
|
+
const loadValue2 = JSON.parse(value);
|
|
12273
|
+
if (typeof (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.beforeLoad) === "function") {
|
|
12274
|
+
node.props.disabled = true;
|
|
12275
|
+
try {
|
|
12276
|
+
loadValue2.data = yield localStorageOptions.beforeLoad(loadValue2.data);
|
|
12277
|
+
} catch (error2) {
|
|
12278
|
+
console.error(error2);
|
|
12279
|
+
}
|
|
12280
|
+
node.props.disabled = false;
|
|
12281
|
+
}
|
|
12282
|
+
if (!loadValue2 || typeof loadValue2.data !== "object")
|
|
12283
|
+
return;
|
|
12284
|
+
if (loadValue2.maxAge > Date.now()) {
|
|
12285
|
+
node.input(loadValue2.data, false);
|
|
12286
|
+
} else {
|
|
12287
|
+
localStorage.removeItem(storageKey);
|
|
12288
|
+
}
|
|
12289
|
+
});
|
|
12290
|
+
const saveValue = (payload) => __async(this, null, function* () {
|
|
12291
|
+
let savePayload = payload;
|
|
12292
|
+
if (typeof (localStorageOptions === null || localStorageOptions === void 0 ? void 0 : localStorageOptions.beforeSave) === "function") {
|
|
12293
|
+
try {
|
|
12294
|
+
savePayload = yield localStorageOptions.beforeSave(payload);
|
|
12295
|
+
} catch (error2) {
|
|
12296
|
+
console.error(error2);
|
|
12297
|
+
}
|
|
12298
|
+
}
|
|
12299
|
+
if (!savePayload)
|
|
12300
|
+
return;
|
|
12301
|
+
localStorage.setItem(storageKey, JSON.stringify({
|
|
12217
12302
|
maxAge: Date.now() + maxAge,
|
|
12218
|
-
data:
|
|
12303
|
+
data: savePayload
|
|
12219
12304
|
}));
|
|
12220
12305
|
});
|
|
12306
|
+
node.on("commit", ({ payload }) => {
|
|
12307
|
+
if (!useLocalStorage)
|
|
12308
|
+
return;
|
|
12309
|
+
clearTimeout(saveTimeout);
|
|
12310
|
+
saveTimeout = setTimeout(() => __async(this, null, function* () {
|
|
12311
|
+
saveValue(payload);
|
|
12312
|
+
}), debounce);
|
|
12313
|
+
});
|
|
12314
|
+
node.on("prop:useLocalStorage", () => {
|
|
12315
|
+
useLocalStorage = shouldUseLocalStorage(controlNode);
|
|
12316
|
+
if (!useLocalStorage) {
|
|
12317
|
+
localStorage.removeItem(storageKey);
|
|
12318
|
+
}
|
|
12319
|
+
});
|
|
12221
12320
|
node.hook.submit((payload, next) => {
|
|
12222
|
-
localStorage.removeItem(
|
|
12321
|
+
localStorage.removeItem(storageKey);
|
|
12223
12322
|
return next(payload);
|
|
12224
12323
|
});
|
|
12225
|
-
|
|
12324
|
+
yield loadValue();
|
|
12325
|
+
}));
|
|
12226
12326
|
};
|
|
12227
12327
|
return localStoragePlugin;
|
|
12228
12328
|
}
|