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.d.cts
CHANGED
|
@@ -244,12 +244,14 @@ interface PersistenceProvider {
|
|
|
244
244
|
type Listener = (state: FormState) => void;
|
|
245
245
|
type EventListener = (event: string, payload?: any) => void;
|
|
246
246
|
type UploadHandler = (file: File | Blob, filename: string) => Promise<string>;
|
|
247
|
+
type DraftChangeHandler = (payload: SavedState) => void | Promise<void>;
|
|
247
248
|
interface StoreConfig {
|
|
248
249
|
persistence?: PersistenceProvider;
|
|
249
250
|
prefillData?: Record<string, any>;
|
|
250
251
|
role?: string;
|
|
251
252
|
onEvent?: EventListener;
|
|
252
253
|
onUpload?: UploadHandler;
|
|
254
|
+
onDraftChange?: DraftChangeHandler;
|
|
253
255
|
}
|
|
254
256
|
declare class FormStore {
|
|
255
257
|
private state;
|
|
@@ -260,6 +262,7 @@ declare class FormStore {
|
|
|
260
262
|
private prefillData;
|
|
261
263
|
private config;
|
|
262
264
|
private saveTimeout;
|
|
265
|
+
private draftCallbackTimeout;
|
|
263
266
|
constructor(schema: FormDef, config?: StoreConfig);
|
|
264
267
|
private initializeDefaults;
|
|
265
268
|
getState(): FormState;
|
|
@@ -278,6 +281,7 @@ declare class FormStore {
|
|
|
278
281
|
setRole(role: string): void;
|
|
279
282
|
load(): Promise<void>;
|
|
280
283
|
private scheduleSave;
|
|
284
|
+
private scheduleDraftCallback;
|
|
281
285
|
save(): Promise<void>;
|
|
282
286
|
/**
|
|
283
287
|
* Prepare values for outbound submission to the backend.
|
package/dist/index.d.ts
CHANGED
|
@@ -244,12 +244,14 @@ interface PersistenceProvider {
|
|
|
244
244
|
type Listener = (state: FormState) => void;
|
|
245
245
|
type EventListener = (event: string, payload?: any) => void;
|
|
246
246
|
type UploadHandler = (file: File | Blob, filename: string) => Promise<string>;
|
|
247
|
+
type DraftChangeHandler = (payload: SavedState) => void | Promise<void>;
|
|
247
248
|
interface StoreConfig {
|
|
248
249
|
persistence?: PersistenceProvider;
|
|
249
250
|
prefillData?: Record<string, any>;
|
|
250
251
|
role?: string;
|
|
251
252
|
onEvent?: EventListener;
|
|
252
253
|
onUpload?: UploadHandler;
|
|
254
|
+
onDraftChange?: DraftChangeHandler;
|
|
253
255
|
}
|
|
254
256
|
declare class FormStore {
|
|
255
257
|
private state;
|
|
@@ -260,6 +262,7 @@ declare class FormStore {
|
|
|
260
262
|
private prefillData;
|
|
261
263
|
private config;
|
|
262
264
|
private saveTimeout;
|
|
265
|
+
private draftCallbackTimeout;
|
|
263
266
|
constructor(schema: FormDef, config?: StoreConfig);
|
|
264
267
|
private initializeDefaults;
|
|
265
268
|
getState(): FormState;
|
|
@@ -278,6 +281,7 @@ declare class FormStore {
|
|
|
278
281
|
setRole(role: string): void;
|
|
279
282
|
load(): Promise<void>;
|
|
280
283
|
private scheduleSave;
|
|
284
|
+
private scheduleDraftCallback;
|
|
281
285
|
save(): Promise<void>;
|
|
282
286
|
/**
|
|
283
287
|
* Prepare values for outbound submission to the backend.
|
package/dist/index.mjs
CHANGED
|
@@ -178,6 +178,7 @@ var FormStore = class {
|
|
|
178
178
|
config;
|
|
179
179
|
// Cache for debounce
|
|
180
180
|
saveTimeout = null;
|
|
181
|
+
draftCallbackTimeout = null;
|
|
181
182
|
constructor(schema, config = {}) {
|
|
182
183
|
this.schema = schema;
|
|
183
184
|
this.config = config;
|
|
@@ -247,7 +248,10 @@ var FormStore = class {
|
|
|
247
248
|
this.checkEvents(fieldId, "onValueChange", value);
|
|
248
249
|
this.evaluate();
|
|
249
250
|
this.notify();
|
|
250
|
-
this.
|
|
251
|
+
this.scheduleDraftCallback();
|
|
252
|
+
if (!this.config.onDraftChange) {
|
|
253
|
+
this.scheduleSave();
|
|
254
|
+
}
|
|
251
255
|
}
|
|
252
256
|
setTouched(fieldId) {
|
|
253
257
|
if (this.state.touched[fieldId]) return;
|
|
@@ -283,6 +287,26 @@ var FormStore = class {
|
|
|
283
287
|
this.save();
|
|
284
288
|
}, 1e3);
|
|
285
289
|
}
|
|
290
|
+
scheduleDraftCallback() {
|
|
291
|
+
if (!this.config.onDraftChange) return;
|
|
292
|
+
if (this.draftCallbackTimeout) {
|
|
293
|
+
clearTimeout(this.draftCallbackTimeout);
|
|
294
|
+
}
|
|
295
|
+
this.draftCallbackTimeout = setTimeout(() => {
|
|
296
|
+
const payload = {
|
|
297
|
+
// For consumer callbacks, send values in the same
|
|
298
|
+
// serialized shape used for outbound submissions so
|
|
299
|
+
// media/signature fields are wrapped consistently.
|
|
300
|
+
values: this.serializeValuesForSubmission(this.state.values),
|
|
301
|
+
meta: {
|
|
302
|
+
updatedAt: Date.now(),
|
|
303
|
+
workflowState: this.state.workflowState,
|
|
304
|
+
version: this.schema.version
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
this.config.onDraftChange?.(payload);
|
|
308
|
+
}, 2500);
|
|
309
|
+
}
|
|
286
310
|
async save() {
|
|
287
311
|
const payload = {
|
|
288
312
|
values: this.state.values,
|
|
@@ -470,6 +494,7 @@ var FormStore = class {
|
|
|
470
494
|
let needsReeval = false;
|
|
471
495
|
if (next.onUpload !== void 0) this.config.onUpload = next.onUpload;
|
|
472
496
|
if (next.onEvent !== void 0) this.config.onEvent = next.onEvent;
|
|
497
|
+
if (next.onDraftChange !== void 0) this.config.onDraftChange = next.onDraftChange;
|
|
473
498
|
if (next.role !== void 0 && next.role !== this.config.role) {
|
|
474
499
|
this.config.role = next.role;
|
|
475
500
|
needsReeval = true;
|