UNPKG

1.99 kBPlain TextView Raw
1import * as React from 'react';
2
3export * from './theme/types';
4import { IPropsTheme } from './theme/types';
5
6export type PropsData = Record<string, unknown> | PropArray;
7export type PropScalar = string | boolean | number | null | undefined;
8export type PropArray = Array<PropScalar | Record<string, unknown>>;
9export type PropValue = PropScalar | PropArray | Record<string, unknown> | Function; // eslint-disable-line
10
11export type PropDataObjectType = 'object' | 'array';
12export type PropObjectType = PropDataObjectType | 'function';
13export type PropTypeScalar = 'string' | 'boolean' | 'number';
14export type PropEmptyType = 'null' | 'undefined';
15export type PropType = PropTypeScalar | PropEmptyType | PropObjectType;
16
17export type PropValueFactory = (
18 e: PropValueFactoryArgs,
19) => PropValueFactoryResponse | undefined | void;
20
21export type PropValueFactoryResponse = {
22 el?: React.ReactNode;
23 underline?: {
24 color: string | number;
25 style: 'solid' | 'dashed';
26 };
27};
28
29export type PropValueFactoryArgs = {
30 path: string;
31 key: string | number;
32 value: PropValue;
33 type: PropType;
34 theme: IPropsTheme;
35 change(args: { to: string }): void;
36 onFocus(isFocused: boolean): void;
37};
38
39export type PropFilter = (e: PropFilterArgs) => boolean;
40export type PropFilterArgs = {
41 path: string;
42 key: string | number;
43 value: PropValue;
44 type: PropType;
45};
46
47/**
48 * [Events]
49 */
50export type PropsEvent = IPropsChangedEvent | IPropsFocusEvent;
51
52export type IPropsChangedEvent<D extends PropsData = any> = {
53 type: 'PROPS/changed';
54 payload: IPropsChange<D>;
55};
56export type IPropsChange<D extends PropsData = any> = {
57 action: PropChangeAction;
58 path: string;
59 key: string | number;
60 value: { from: PropValue; to: PropValue };
61 data: { from: D; to: D };
62};
63export type PropChangeAction = 'CHANGE' | 'INSERT' | 'DELETE';
64
65export type IPropsFocusEvent = {
66 type: 'PROPS/focus';
67 payload: IPropsFocus;
68};
69export type IPropsFocus = {
70 isFocused: boolean;
71 path: string;
72};