@simpleform/render 2.0.8 → 3.0.1

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/lib/store.d.ts CHANGED
@@ -1,36 +1,25 @@
1
1
  /// <reference types="react" />
2
- import { CustomUnionType, FormNodeProps, GenerateParams, PropertiesData } from "./types";
2
+ import { CustomUnionType, GenerateParams, WidgetItem, WidgetList } from "./types";
3
3
  export type FormRenderListener = (newValue?: any, oldValue?: any) => void;
4
4
  export declare class SimpleFormRender {
5
5
  plugins: any;
6
6
  components: any;
7
- private properties;
8
- private lastProperties;
9
- private propertiesListeners;
7
+ private widgetList;
8
+ private lastWidgetList;
9
+ private widgetListListeners;
10
10
  constructor();
11
11
  addPlugin(data: any): void;
12
12
  registry(data: any): void;
13
13
  getFormComponent(target?: CustomUnionType): import("react").ComponentType<{}> | null | undefined;
14
14
  createFormElement(target?: CustomUnionType, commonProps?: GenerateParams): any;
15
- getProperties(): PropertiesData;
16
- setProperties(data?: PropertiesData): void;
17
- updateItemByPath: (data?: any, path?: string, attributeName?: string) => void;
18
- setItemByPath: (data?: any, path?: string, attributeName?: string) => void;
19
- setItemByIndex: (data?: any, index?: number, parent?: {
20
- path?: string;
21
- attributeName?: string;
22
- }) => void;
23
- updateNameByPath: (endName?: string, path?: string) => void;
24
- insertItemByIndex: (data: Partial<PropertiesData> | Array<FormNodeProps>, index?: number, parent?: {
25
- path?: string;
26
- attributeName?: string;
27
- }) => void;
28
- delItemByPath: (path?: string, attributeName?: string) => void;
29
- getItemByPath: (path?: string, attributeName?: string) => any;
30
- getItemByIndex: (index: number, parent: {
31
- path?: string;
32
- attributeName?: string;
33
- }) => any;
15
+ getWidgetList(): WidgetList;
16
+ setWidgetList(data?: WidgetList): void;
17
+ setItemByPath: (data?: any, path?: string) => void;
18
+ setItemByIndex: (data?: any, index?: number, parent?: string) => void;
19
+ insertItemByIndex: (data?: WidgetItem | Array<WidgetItem>, index?: number, parent?: string) => void;
20
+ delItemByPath: (path?: string) => void;
21
+ getItemByPath: (path?: string) => any;
22
+ getItemByIndex: (index: number, parent?: string) => any;
34
23
  moveItemByPath: (from: {
35
24
  parent?: string;
36
25
  index: number;
@@ -38,7 +27,7 @@ export declare class SimpleFormRender {
38
27
  parent?: string;
39
28
  index?: number;
40
29
  }) => void;
41
- subscribeProperties(listener: FormRenderListener): () => void;
42
- unsubscribeProperties(): void;
43
- private notifyProperties;
30
+ subscribeWidgetList(listener: FormRenderListener): () => void;
31
+ unsubscribeWidgetList(): void;
32
+ private notifyWidgetList;
44
33
  }
package/lib/types.d.ts CHANGED
@@ -1,59 +1,49 @@
1
- import { ReactNode } from "react";
1
+ import React, { ReactNode } from "react";
2
2
  import { FormItemProps, FormProps, FormRule, SimpleForm } from "@simpleform/form";
3
3
  import { SimpleFormRender } from "./store";
4
- export interface FormComponent {
4
+ export interface CustomWidget {
5
5
  type?: string;
6
- props?: any & {
7
- children?: any | Array<FormComponent>;
6
+ props?: Record<string, any> & {
7
+ children?: any | Array<CustomWidget>;
8
8
  };
9
+ widgetList?: WidgetList;
9
10
  }
10
11
  export type UnionComponent<P> = React.ComponentType<P> | React.ForwardRefExoticComponent<P> | keyof React.ReactHTML;
11
- export type CustomUnionType = FormComponent | Array<FormComponent> | UnionComponent<any> | Function | ReactNode;
12
- export type PropertiesData = {
13
- [name: string]: FormNodeProps;
14
- } | FormNodeProps[];
15
- export type GenerateFormNodeProps<T = {}> = FormComponent & FormItemProps & T & {
16
- ignore?: boolean;
12
+ export type CustomUnionType = CustomWidget | Array<CustomWidget> | UnionComponent<any> | Function | ReactNode;
13
+ export type WidgetList = Array<WidgetItem>;
14
+ export type GenerateWidgetItem<T extends Record<string, any> = {}> = CustomWidget & FormItemProps & T & {
17
15
  inside?: CustomUnionType;
18
16
  outside?: CustomUnionType;
19
17
  readOnly?: boolean;
20
18
  readOnlyRender?: CustomUnionType;
21
19
  typeRender?: CustomUnionType;
22
- properties?: PropertiesData;
23
20
  hidden?: boolean;
24
21
  };
25
22
  export type CustomRenderType = (params: GenerateParams<any> & {
26
23
  children?: any;
27
24
  }) => any;
28
- export type FormNodeProps = {
29
- [key in keyof GenerateFormNodeProps]: key extends 'rules' ? (string | Array<{
25
+ export type WidgetItem = {
26
+ [key in keyof GenerateWidgetItem]: key extends 'rules' ? (string | Array<{
30
27
  [key in keyof FormRule]: FormRule[key] | string;
31
- }> | GenerateFormNodeProps[key]) : (key extends 'properties' ? GenerateFormNodeProps[key] : (string | GenerateFormNodeProps[key]));
28
+ }> | GenerateWidgetItem[key]) : (string | GenerateWidgetItem[key]);
32
29
  };
33
- export interface FormChildrenProps<T = {}> {
30
+ export interface FormChildrenProps<T extends Record<string, any> = {}> {
34
31
  form?: SimpleForm;
35
32
  formrender?: SimpleFormRender;
36
- options?: GenerateFormNodeProps<T> | ((params: GenerateFormNodeProps<T>) => GenerateFormNodeProps<T>);
37
- evalPropNames?: Array<string>;
33
+ options?: GenerateWidgetItem<T> | ((params: GenerateWidgetItem<T>) => GenerateWidgetItem<T>);
38
34
  uneval?: boolean;
39
- components?: any;
40
- plugins?: any;
35
+ components?: Record<string, any>;
36
+ plugins?: Record<string, any>;
41
37
  inside?: CustomUnionType;
42
- properties?: PropertiesData;
38
+ widgetList?: WidgetList;
43
39
  renderList?: CustomRenderType;
44
40
  renderItem?: CustomRenderType;
45
- onPropertiesChange?: (newValue: PropertiesData, oldValue?: PropertiesData) => void;
41
+ onRenderChange?: (newValue: WidgetList, oldValue?: WidgetList) => void;
46
42
  }
47
- export type FormRenderProps<T = {}> = Omit<FormProps, 'form'> & FormChildrenProps<T>;
48
- export interface GenerateParams<T = {}> {
49
- name?: string;
43
+ export type FormRenderProps<T extends Record<string, any> = {}> = Omit<FormProps, 'form'> & FormChildrenProps<T>;
44
+ export interface GenerateParams<T extends Record<string, any> = {}> {
50
45
  path?: string;
51
- field?: GenerateFormNodeProps<T>;
52
- parent?: {
53
- name?: string;
54
- path?: string;
55
- field?: GenerateFormNodeProps<T>;
56
- };
46
+ widgetItem?: GenerateWidgetItem<T>;
57
47
  formrender?: SimpleFormRender;
58
48
  form?: SimpleForm;
59
49
  }
@@ -1,3 +1,2 @@
1
1
  export declare function deepClone<T = any>(value: T): T;
2
2
  export declare function isEqual(a: any, b: any): boolean;
3
- export declare const deepMergeObject: (obj1: any, obj2: any) => any;
@@ -1,29 +1,17 @@
1
- import { FormNodeProps, PropertiesData } from "../types";
1
+ import { WidgetItem, WidgetList } from "../types";
2
2
  export declare const matchExpression: (value?: any) => string | undefined;
3
3
  export declare const getPathEnd: (path?: string) => string | number | undefined;
4
4
  export declare const getParent: (path?: string) => string;
5
5
  export declare const getPathLen: (path?: string) => number;
6
- export declare const updateItemByPath: (properties: PropertiesData, data?: any, path?: string, attributeName?: string) => PropertiesData;
7
- export declare const setItemByPath: (properties: PropertiesData, data?: any, path?: string, attributeName?: string) => PropertiesData;
8
- export declare const getItemByPath: (properties?: PropertiesData, path?: string, attributeName?: string) => any;
9
- export declare const getKeyValueByIndex: (properties: PropertiesData, index?: number, parent?: {
10
- path?: string | undefined;
11
- attributeName?: string | undefined;
12
- } | undefined) => [string | number, any] | undefined;
6
+ export declare const setItemByPath: (widgetList: WidgetList, data?: any, path?: string) => any;
7
+ export declare const getItemByPath: (widgetList?: WidgetList, path?: string) => any;
8
+ export declare const getKeyValueByIndex: (widgetList: WidgetList, index?: number, parent?: string) => [string | number, any] | undefined;
13
9
  export declare const toEntries: (data: any) => {
14
10
  isList: boolean;
15
11
  entries: [string, any][];
16
12
  };
17
- export declare const updateName: (properties: PropertiesData, newName?: string, path?: string) => any[] | {
18
- [k: string]: any;
19
- };
20
- export declare const insertItemByIndex: (properties: PropertiesData, data?: Partial<PropertiesData> | Array<FormNodeProps>, index?: number, parent?: {
21
- path?: string | undefined;
22
- attributeName?: string | undefined;
23
- } | undefined) => any[] | {
24
- [k: string]: any;
25
- };
26
- export declare const moveSameLevel: (properties: PropertiesData, from: {
13
+ export declare const insertItemByIndex: (widgetList: WidgetList, data?: WidgetItem | Array<WidgetItem>, index?: number, parent?: string) => any;
14
+ export declare const moveSameLevel: (widgetList: WidgetList, from: {
27
15
  parent?: string;
28
16
  index: number;
29
17
  }, to: {
@@ -32,13 +20,11 @@ export declare const moveSameLevel: (properties: PropertiesData, from: {
32
20
  }) => any[] | {
33
21
  [k: string]: any;
34
22
  } | undefined;
35
- export declare const moveDiffLevel: (properties: PropertiesData, from: {
23
+ export declare const moveDiffLevel: (widgetList: WidgetList, from: {
36
24
  parent?: string;
37
25
  index: number;
38
26
  }, to: {
39
27
  parent?: string;
40
28
  index?: number;
41
- }) => any[] | {
42
- [k: string]: any;
43
- };
44
- export declare const getInitialValues: (properties?: PropertiesData) => {} | undefined;
29
+ }) => any;
30
+ export declare const getInitialValues: (widgetList?: WidgetList) => {} | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleform/render",
3
- "version": "2.0.8",
3
+ "version": "3.0.1",
4
4
  "description": "dynamic rendering core of simple form",
5
5
  "author": "mezhanglei <496623925@qq.com>",
6
6
  "homepage": "https://github.com/mezhanglei/simpleform#readme",
@@ -43,7 +43,7 @@
43
43
  "react-router-dom": "^6.19.0"
44
44
  },
45
45
  "dependencies": {
46
- "@simpleform/form": "^2.0.8",
46
+ "@simpleform/form": "^2.0.9",
47
47
  "classnames": "^2.3.2",
48
48
  "copy-anything": "^3.0.5",
49
49
  "react-fast-compare": "^3.2.2"