b88a2370b3
Removes `propsForNextShape` and replaces it with the new styles API. Changes in here: - New custom style example - `setProp` is now `setStyle` and takes a `StyleProp` instead of a string - `Editor.props` and `Editor.opacity` are now `Editor.sharedStyles` and `Editor.sharedOpacity` - They return an object that flags mixed vs shared types instead of using null to signal mixed types - `Editor.styles` returns a `SharedStyleMap` - keyed on `StyleProp` instead of `string` - `StateNode.shapeType` is now the shape util rather than just a string. This lets us pull the styles from the shape type directly. - `color` is no longer a core part of the editor set on the shape parent. Individual child shapes have to use color directly. - `propsForNextShape` is now `stylesForNextShape` - `InstanceRecordType` is created at runtime in the same way `ShapeRecordType` is. This is so it can pull style validators out of shape defs for `stylesForNextShape` - Shape type are now defined by their props rather than having separate validators & type defs ### Change Type - [x] `major` — Breaking change ### Test Plan 1. Big time regression testing around styles! 2. Check UI works as intended for all shape/style/tool combos - [x] Unit Tests - [ ] End to end tests ### Release Notes - --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
199 lines
5.4 KiB
Markdown
199 lines
5.4 KiB
Markdown
## API Report File for "@tldraw/validate"
|
|
|
|
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
|
|
```ts
|
|
|
|
// @public
|
|
const any: Validator<any>;
|
|
|
|
// @public
|
|
const array: Validator<unknown[]>;
|
|
|
|
// @public
|
|
function arrayOf<T>(itemValidator: Validatable<T>): ArrayOfValidator<T>;
|
|
|
|
// @public (undocumented)
|
|
class ArrayOfValidator<T> extends Validator<T[]> {
|
|
constructor(itemValidator: Validatable<T>);
|
|
// (undocumented)
|
|
readonly itemValidator: Validatable<T>;
|
|
// (undocumented)
|
|
lengthGreaterThan1(): Validator<T[]>;
|
|
// (undocumented)
|
|
nonEmpty(): Validator<T[]>;
|
|
}
|
|
|
|
// @public
|
|
const bigint: Validator<bigint>;
|
|
|
|
// @public
|
|
const boolean: Validator<boolean>;
|
|
|
|
// @public
|
|
function dict<Key extends string, Value>(keyValidator: Validatable<Key>, valueValidator: Validatable<Value>): DictValidator<Key, Value>;
|
|
|
|
// @public (undocumented)
|
|
class DictValidator<Key extends string, Value> extends Validator<Record<Key, Value>> {
|
|
constructor(keyValidator: Validatable<Key>, valueValidator: Validatable<Value>);
|
|
// (undocumented)
|
|
readonly keyValidator: Validatable<Key>;
|
|
// (undocumented)
|
|
readonly valueValidator: Validatable<Value>;
|
|
}
|
|
|
|
// @public
|
|
const integer: Validator<number>;
|
|
|
|
// @public
|
|
function literal<T extends boolean | number | string>(expectedValue: T): Validator<T>;
|
|
|
|
// @public (undocumented)
|
|
function literalEnum<const Values extends readonly unknown[]>(...values: Values): Validator<Values[number]>;
|
|
|
|
// @public
|
|
function model<T extends {
|
|
readonly id: string;
|
|
}>(name: string, validator: Validatable<T>): Validator<T>;
|
|
|
|
// @public
|
|
const nonZeroInteger: Validator<number>;
|
|
|
|
// @public
|
|
const nonZeroNumber: Validator<number>;
|
|
|
|
// @public (undocumented)
|
|
function nullable<T>(validator: Validatable<T>): Validator<null | T>;
|
|
|
|
// @public
|
|
const number: Validator<number>;
|
|
|
|
// @public
|
|
function object<Shape extends object>(config: {
|
|
readonly [K in keyof Shape]: Validatable<Shape[K]>;
|
|
}): ObjectValidator<Shape>;
|
|
|
|
// @public (undocumented)
|
|
class ObjectValidator<Shape extends object> extends Validator<Shape> {
|
|
constructor(config: {
|
|
readonly [K in keyof Shape]: Validatable<Shape[K]>;
|
|
}, shouldAllowUnknownProperties?: boolean);
|
|
// (undocumented)
|
|
allowUnknownProperties(): ObjectValidator<Shape>;
|
|
// (undocumented)
|
|
readonly config: {
|
|
readonly [K in keyof Shape]: Validatable<Shape[K]>;
|
|
};
|
|
extend<Extension extends Record<string, unknown>>(extension: {
|
|
readonly [K in keyof Extension]: Validatable<Extension[K]>;
|
|
}): ObjectValidator<Shape & Extension>;
|
|
}
|
|
|
|
// @public (undocumented)
|
|
function optional<T>(validator: Validatable<T>): Validator<T | undefined>;
|
|
|
|
// @public
|
|
const positiveInteger: Validator<number>;
|
|
|
|
// @public
|
|
const positiveNumber: Validator<number>;
|
|
|
|
// @public (undocumented)
|
|
function setEnum<T>(values: ReadonlySet<T>): Validator<T>;
|
|
|
|
// @public
|
|
const string: Validator<string>;
|
|
|
|
declare namespace T {
|
|
export {
|
|
literal,
|
|
arrayOf,
|
|
object,
|
|
dict,
|
|
union,
|
|
model,
|
|
setEnum,
|
|
optional,
|
|
nullable,
|
|
literalEnum,
|
|
ValidatorFn,
|
|
Validatable,
|
|
ValidationError,
|
|
TypeOf,
|
|
Validator,
|
|
ArrayOfValidator,
|
|
ObjectValidator,
|
|
UnionValidator,
|
|
DictValidator,
|
|
unknown,
|
|
any,
|
|
string,
|
|
number,
|
|
positiveNumber,
|
|
nonZeroNumber,
|
|
integer,
|
|
positiveInteger,
|
|
nonZeroInteger,
|
|
boolean,
|
|
bigint,
|
|
array,
|
|
unknownObject
|
|
}
|
|
}
|
|
export { T }
|
|
|
|
// @public (undocumented)
|
|
type TypeOf<V extends Validatable<unknown>> = V extends Validatable<infer T> ? T : never;
|
|
|
|
// @public
|
|
function union<Key extends string, Config extends UnionValidatorConfig<Key, Config>>(key: Key, config: Config): UnionValidator<Key, Config>;
|
|
|
|
// @public (undocumented)
|
|
class UnionValidator<Key extends string, Config extends UnionValidatorConfig<Key, Config>, UnknownValue = never> extends Validator<TypeOf<Config[keyof Config]> | UnknownValue> {
|
|
constructor(key: Key, config: Config, unknownValueValidation: (value: object, variant: string) => UnknownValue);
|
|
// (undocumented)
|
|
validateUnknownVariants<Unknown>(unknownValueValidation: (value: object, variant: string) => Unknown): UnionValidator<Key, Config, Unknown>;
|
|
}
|
|
|
|
// @public
|
|
const unknown: Validator<unknown>;
|
|
|
|
// @public (undocumented)
|
|
const unknownObject: Validator<Record<string, unknown>>;
|
|
|
|
// @public (undocumented)
|
|
type Validatable<T> = {
|
|
validate: (value: unknown) => T;
|
|
};
|
|
|
|
// @public (undocumented)
|
|
class ValidationError extends Error {
|
|
constructor(rawMessage: string, path?: ReadonlyArray<number | string>);
|
|
// (undocumented)
|
|
name: string;
|
|
// (undocumented)
|
|
readonly path: ReadonlyArray<number | string>;
|
|
// (undocumented)
|
|
readonly rawMessage: string;
|
|
}
|
|
|
|
// @public (undocumented)
|
|
class Validator<T> implements Validatable<T> {
|
|
constructor(validationFn: ValidatorFn<T>);
|
|
check(name: string, checkFn: (value: T) => void): Validator<T>;
|
|
// (undocumented)
|
|
check(checkFn: (value: T) => void): Validator<T>;
|
|
nullable(): Validator<null | T>;
|
|
optional(): Validator<T | undefined>;
|
|
refine<U>(otherValidationFn: (value: T) => U): Validator<U>;
|
|
validate(value: unknown): T;
|
|
// (undocumented)
|
|
readonly validationFn: ValidatorFn<T>;
|
|
}
|
|
|
|
// @public (undocumented)
|
|
type ValidatorFn<T> = (value: unknown) => T;
|
|
|
|
// (No @packageDocumentation comment for this package)
|
|
|
|
```
|