@updog/data-editor-wc 0.1.59 → 0.1.60
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/README.md +3 -3
- package/index.css +1 -1
- package/index.d.ts +36 -9
- package/index.js +4286 -3740
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -374,6 +374,7 @@ declare var export_default = {
|
|
|
374
374
|
redo: "Redo",
|
|
375
375
|
},
|
|
376
376
|
validation: {
|
|
377
|
+
alreadyExists: "Already exists in your database",
|
|
377
378
|
endDateBeforeStart: "End date must be after start date",
|
|
378
379
|
invalidDate: "Invalid date",
|
|
379
380
|
invalidEmail: "Invalid email address",
|
|
@@ -615,6 +616,38 @@ type BuiltInValidator = {
|
|
|
615
616
|
} | {
|
|
616
617
|
type: "numeric";
|
|
617
618
|
message?: string;
|
|
619
|
+
} | {
|
|
620
|
+
type: "unique";
|
|
621
|
+
message?: string;
|
|
622
|
+
fn?: UniqueRemoteFn;
|
|
623
|
+
};
|
|
624
|
+
/** One cell in an asyncFunction batch. Row is passed by reference. */
|
|
625
|
+
type AsyncValidatorCell = {
|
|
626
|
+
/** Value of the validated column for this cell. */
|
|
627
|
+
value: unknown;
|
|
628
|
+
/** The full row — for row-dependent checks. */
|
|
629
|
+
row: DataEditorRow;
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* Remote existence check for `{ type: "unique" }`. Called once per sweep
|
|
633
|
+
* with all distinct candidate values; report the subset that already exists —
|
|
634
|
+
* return it and/or stream it via onChunk (results are unioned). `signal`
|
|
635
|
+
* fires only when results can no longer be used. Client-mode only.
|
|
636
|
+
*/
|
|
637
|
+
type UniqueRemoteFn = (values: unknown[], onChunk: (existing: unknown[]) => void, signal: AbortSignal) => Promise<unknown[] | void>;
|
|
638
|
+
type AsyncFunctionValidator = {
|
|
639
|
+
type: "asyncFunction";
|
|
640
|
+
/**
|
|
641
|
+
* Called once per column per operation with every affected cell. Report
|
|
642
|
+
* failures by `index` into `cells`: return an array aligned with the input
|
|
643
|
+
* (null = valid) and/or stream sparse failures via onChunk (unioned, any
|
|
644
|
+
* order). `signal` fires only when results can no longer be used.
|
|
645
|
+
* Client-mode only. For uniqueness use `unique.fn`, not this.
|
|
646
|
+
*/
|
|
647
|
+
fn: (cells: AsyncValidatorCell[], onChunk: (failures: {
|
|
648
|
+
index: number;
|
|
649
|
+
error: ValidationError;
|
|
650
|
+
}[]) => void, signal: AbortSignal) => Promise<(ValidationError | null)[] | void>;
|
|
618
651
|
};
|
|
619
652
|
/**
|
|
620
653
|
* Server-mode-only escape hatch: an expression evaluated by the Go binary
|
|
@@ -641,7 +674,7 @@ type FunctionValidator = {
|
|
|
641
674
|
* Named `ValidatorRule` (not `Validator`) so it doesn't clash with the
|
|
642
675
|
* runtime `Validator` class in `core/Validator.ts`.
|
|
643
676
|
*/
|
|
644
|
-
type ValidatorRule = BuiltInValidator | ExpressionValidator | FunctionValidator;
|
|
677
|
+
type ValidatorRule = BuiltInValidator | ExpressionValidator | FunctionValidator | AsyncFunctionValidator;
|
|
645
678
|
|
|
646
679
|
/**
|
|
647
680
|
* Severity level for a validation message.
|
|
@@ -772,7 +805,7 @@ type ColumnLockMode = "all" | "default";
|
|
|
772
805
|
* ```ts
|
|
773
806
|
* const columns: DataEditorColumn[] = [
|
|
774
807
|
* { id: "name", title: "Full Name", size: 200, validators: [{ type: "required", message: "Name is required" }] },
|
|
775
|
-
* { id: "email", title: "Email", size: 250, validators: [{ type: "required", message: "Email is required" }, { type: "email", message: "Invalid email" }
|
|
808
|
+
* { id: "email", title: "Email", size: 250, validators: [{ type: "required", message: "Email is required" }, { type: "email", message: "Invalid email" }, { type: "unique" }] },
|
|
776
809
|
* { id: "role", title: "Role", editor: { type: "select", options: ["Admin", "Editor", "Viewer"] } },
|
|
777
810
|
* { id: "salary", title: "Salary", validators: [{ type: "numeric", message: "Must be a number" }], formatter: (v) => v ? `$${v}` : "" },
|
|
778
811
|
* ];
|
|
@@ -785,19 +818,13 @@ type DataEditorColumn = {
|
|
|
785
818
|
title: string;
|
|
786
819
|
/**
|
|
787
820
|
* One or more validators run on every edit. Accepts:
|
|
788
|
-
* - Built-in object literals: `{ type: "required" | "email" | "regex" | "range" | "oneOf" | "date" | "numeric", ... }`.
|
|
821
|
+
* - Built-in object literals: `{ type: "required" | "email" | "regex" | "range" | "oneOf" | "date" | "numeric" | "unique", ... }`.
|
|
789
822
|
* - `{ type: "expression", expr }` — server-mode only. Warned in client mode.
|
|
790
823
|
* - `{ type: "function", fn }` — client-mode only. Dropped+warned in server mode.
|
|
791
824
|
*
|
|
792
825
|
* See `_specs/VALIDATIONS.md` §4.5 for the per-mode support matrix.
|
|
793
826
|
*/
|
|
794
827
|
validators?: ValidatorRule[];
|
|
795
|
-
/**
|
|
796
|
-
* When `true`, the editor flags duplicate values in this column as errors.
|
|
797
|
-
* The error message is localized via the `translations` prop
|
|
798
|
-
* (`dataEditor.validation.valueMustBeUnique`).
|
|
799
|
-
*/
|
|
800
|
-
unique?: boolean;
|
|
801
828
|
/**
|
|
802
829
|
* Column IDs to revalidate when this column changes. Use for cross-field
|
|
803
830
|
* rules like "end date must be after start date".
|