UNPKG

schema-based-json-editor

Version:

A reactjs and vuejs component of schema based json editor.

404 lines (403 loc) 9.45 kB
import toNumber from 'lodash.tonumber'; import toInteger from 'lodash.tointeger'; export { toNumber, toInteger }; import * as monaco from 'monaco-editor'; /** * @public */ export declare type MonacoEditor = typeof monaco.editor; /** * @public */ export declare type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor; /** * @public */ export interface CommonSchema { $schema?: string; $ref?: string; definitions?: { [name: string]: Schema; }; title?: string; description?: string; default?: ValueType; readonly?: boolean; propertyOrder?: number; requiredWhen?: EqualCondition | InCondition | IsUndefinedCondition; optionalWhen?: EqualCondition | InCondition | IsUndefinedCondition; className?: string; propertyName?: string; } declare type EqualCondition = [string, '===', any]; declare type InCondition = [string, 'in', any]; declare type IsUndefinedCondition = [string, 'isUndefined']; /** * @public */ export declare type AnySchema = CommonSchema & { type: undefined; }; /** * @public */ export declare type ObjectSchema = CommonSchema & { type: 'object'; properties: { [name: string]: Schema; }; required?: string[]; maxProperties?: number; minProperties?: number; collapsed?: boolean; }; /** * @public */ export declare type ArraySchema = CommonSchema & { type: 'array'; items: Schema; minItems?: number; uniqueItems?: boolean; collapsed?: boolean; enum?: ValueType[]; enumTitles?: string[]; format?: 'select2'; }; /** * @public */ export declare type NumberSchema = CommonSchema & { type: 'number' | 'integer'; minimum?: number; exclusiveMinimum?: boolean; maximum?: number; exclusiveMaximum?: boolean; enum?: number[]; multipleOf?: number; enumTitles?: string[]; format?: 'select' | 'radiobox'; step?: number | 'any'; }; /** * @public */ export declare type StringSchema = CommonSchema & { type: 'string'; format?: 'textarea' | 'color' | 'date' | 'datetime' | 'datetime-local' | 'time' | 'month' | 'email' | 'uri' | 'url' | 'week' | 'hostname' | 'ipv4' | 'ipv6' | 'code' | 'markdown' | 'base64' | 'select' | 'radiobox' | 'json'; enum?: string[]; minLength?: number; maxLength?: number; pattern?: string; enumTitles?: string[]; step?: number | 'any'; }; /** * @public */ export declare type BooleanSchema = CommonSchema & { type: 'boolean'; format?: 'checkbox' | 'select' | 'select2'; }; /** * @public */ export declare type NullSchema = CommonSchema & { type: 'null'; }; /** * @public */ export declare type Schema = ObjectSchema | ArraySchema | NumberSchema | StringSchema | BooleanSchema | NullSchema | AnySchema; /** * @public */ export declare const themes: { [name: string]: Theme; }; /** * @public */ export declare const defaultTheme: { card: string; row: string; errorRow: string; input: string; errorInput: string; textarea: string; errorTextarea: string; checkbox: string; radiobox: string; button: string; buttonGroup: string; title: string; description: string; select: string; }; /** * @public */ export declare type Theme = typeof defaultTheme; /** * @public */ export declare function getTheme(name: string | undefined | Theme): Theme; /** * @public */ export declare const defaultLocale: { button: { collapse: string; expand: string; add: string; delete: string; }; error: { minLength: string; maxLength: string; pattern: string; minimum: string; maximum: string; largerThan: string; smallerThan: string; minItems: string; uniqueItems: string; multipleOf: string; minProperties: string; maxProperties: string; }; info: { notExists: string; true: string; false: string; search: string; }; markdownTipLocale: any; fileUploaderLocale: { dragAndDrop: string; selectFile: string; pasteFromClipboard: string; }; }; export declare type Locale = typeof defaultLocale; /** * @public */ export declare const locales: { [name: string]: Locale; }; /** * @public */ export declare function getLocale(locale: undefined | null | Locale): Locale; /** * @public */ export declare const bootstrap3Icon: { isText: boolean; collapse: string; expand: string; add: string; delete: string; }; /** * @public */ export declare type Icon = typeof bootstrap3Icon; /** * @public */ export declare const icons: { [name: string]: Icon; }; /** * @public */ export declare function getIcon(name: string | undefined | Icon, locale: Locale): Icon; /** * @public */ export declare type ValueType = { [name: string]: any; } | any[] | number | boolean | string | null | undefined; /** * @public */ export declare function getDefaultValue(required: boolean | undefined, schema: Schema, initialValue: ValueType | undefined): ValueType | undefined; /** * @public */ export declare const buttonGroupStyle: { marginLeft: string; }; /** * @public */ export declare const buttonGroupStyleString = "margin-left: 10px"; /** * @public */ export interface Props<TSchema extends CommonSchema, TValue> { schema: TSchema; initialValue: TValue; title?: string; updateValue: (value: TValue | undefined, isValid: boolean) => void; theme: Theme; icon: Icon; locale: Locale; onDelete?: () => void; readonly?: boolean; required?: boolean; dragula?: Dragula; md?: any; hljs?: HLJS; forceHttps?: boolean; disableCollapse?: boolean; noSelect2?: boolean; minItemCountIfNeedFilter?: number; monacoEditor?: MonacoEditor; getReference: (name: string) => TSchema | undefined; } /** * @public */ export declare function isSame(value1: ValueType, value2: ValueType): boolean; /** * @public */ export declare function switchItem(value: any[], el: HTMLElement, sibling: HTMLElement | null): void; /** * @public */ export declare function getErrorMessageOfArray(value: any[] | undefined, schema: ArraySchema, locale: Locale): string; /** * @public */ export declare function getErrorMessageOfNumber(value: number | undefined, schema: NumberSchema, locale: Locale): string; /** * @public */ export declare function getErrorMessageOfString(value: string | undefined, schema: StringSchema, locale: Locale): string; /** * @public */ export declare function getErrorMessageOfObject(value: { [name: string]: ValueType; } | undefined, schema: ObjectSchema, locale: Locale): string; /** * @public */ export declare function toggleOptional(value: ValueType | undefined, schema: Schema, initialValue: any): ValueType; /** * @public */ export interface ValidityValue<T> { value: T; isValid: boolean; } /** * @public */ export declare function recordInvalidPropertiesOfObject(invalidProperties: string[], isValid: boolean, property: string): void; /** * @public */ export declare function recordInvalidIndexesOfArray(invalidIndexes: number[], isValid: boolean, i: number): void; /** * @public */ export declare function isImageUrl(value?: string): boolean; /** * @public */ export declare function isBase64Image(value?: string): boolean; /** * @public */ export declare function replaceProtocal(src: string): string; /** * @public */ export declare const imagePreviewStyleString = "display: block; height: auto; margin: 6px 0; max-width: 100%;"; /** * @public */ export declare const imagePreviewStyle: { display: string; height: string; margin: string; maxWidth: string; }; /** * @public */ export declare function initializeMarkdown(markdownit: any, hljs: HLJS | undefined, forceHttps?: boolean | undefined): any; /** * @public */ export declare function findTitle(value: { [name: string]: ValueType; } | undefined, properties: { property: string; schema: Schema; }[]): string | undefined; /** * @public */ export declare function getTitle(...titles: any[]): string; /** * @public */ export declare function compare(a: { property: string; schema: Schema; }, b: { property: string; schema: Schema; }): number; /** * @public */ export declare function filterObject({ property, schema }: { property: string; schema: Schema; }, filterValue: string): boolean; /** * @public */ export declare function filterArray(value: ValueType, index: number, schema: Schema, filterValue: string): boolean; /** * @public */ export declare const minItemCountIfNeedFilter = 6; /** * @public */ export declare function isRequired(required: string[] | undefined, value: { [name: string]: ValueType; } | undefined, schema: ObjectSchema, property: string): boolean | undefined; /** * @public */ export declare function findContainer(childNodes: NodeList): HTMLElement | undefined; /** * @public */ export declare function getOptions(schema: NumberSchema | StringSchema | ArraySchema): { value: string | number; label: string | number; }[]; import dragula from 'dragula'; import hljs from 'highlight.js'; /** * @public */ export declare type Dragula = typeof dragula; /** * @public */ export declare type HLJS = typeof hljs; /** * @public */ export declare function getNumberStep(schema: NumberSchema): number | "any" | undefined;