formanitor 0.0.10 → 0.0.11
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/index.cjs +26 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +26 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -204,6 +204,7 @@ var FormStore = class {
|
|
|
204
204
|
config;
|
|
205
205
|
// Cache for debounce
|
|
206
206
|
saveTimeout = null;
|
|
207
|
+
draftCallbackTimeout = null;
|
|
207
208
|
constructor(schema, config = {}) {
|
|
208
209
|
this.schema = schema;
|
|
209
210
|
this.config = config;
|
|
@@ -273,7 +274,10 @@ var FormStore = class {
|
|
|
273
274
|
this.checkEvents(fieldId, "onValueChange", value);
|
|
274
275
|
this.evaluate();
|
|
275
276
|
this.notify();
|
|
276
|
-
this.
|
|
277
|
+
this.scheduleDraftCallback();
|
|
278
|
+
if (!this.config.onDraftChange) {
|
|
279
|
+
this.scheduleSave();
|
|
280
|
+
}
|
|
277
281
|
}
|
|
278
282
|
setTouched(fieldId) {
|
|
279
283
|
if (this.state.touched[fieldId]) return;
|
|
@@ -309,6 +313,26 @@ var FormStore = class {
|
|
|
309
313
|
this.save();
|
|
310
314
|
}, 1e3);
|
|
311
315
|
}
|
|
316
|
+
scheduleDraftCallback() {
|
|
317
|
+
if (!this.config.onDraftChange) return;
|
|
318
|
+
if (this.draftCallbackTimeout) {
|
|
319
|
+
clearTimeout(this.draftCallbackTimeout);
|
|
320
|
+
}
|
|
321
|
+
this.draftCallbackTimeout = setTimeout(() => {
|
|
322
|
+
const payload = {
|
|
323
|
+
// For consumer callbacks, send values in the same
|
|
324
|
+
// serialized shape used for outbound submissions so
|
|
325
|
+
// media/signature fields are wrapped consistently.
|
|
326
|
+
values: this.serializeValuesForSubmission(this.state.values),
|
|
327
|
+
meta: {
|
|
328
|
+
updatedAt: Date.now(),
|
|
329
|
+
workflowState: this.state.workflowState,
|
|
330
|
+
version: this.schema.version
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
this.config.onDraftChange?.(payload);
|
|
334
|
+
}, 2500);
|
|
335
|
+
}
|
|
312
336
|
async save() {
|
|
313
337
|
const payload = {
|
|
314
338
|
values: this.state.values,
|
|
@@ -496,6 +520,7 @@ var FormStore = class {
|
|
|
496
520
|
let needsReeval = false;
|
|
497
521
|
if (next.onUpload !== void 0) this.config.onUpload = next.onUpload;
|
|
498
522
|
if (next.onEvent !== void 0) this.config.onEvent = next.onEvent;
|
|
523
|
+
if (next.onDraftChange !== void 0) this.config.onDraftChange = next.onDraftChange;
|
|
499
524
|
if (next.role !== void 0 && next.role !== this.config.role) {
|
|
500
525
|
this.config.role = next.role;
|
|
501
526
|
needsReeval = true;
|