@appkit/dek-plugin 0.3.4 → 0.5.0

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/dist/lib/api.d.ts CHANGED
@@ -1,39 +1,59 @@
1
1
  /// <reference types="react" />
2
2
  import { DekPluginSchema } from './plugins';
3
+ import { DekRegistry } from './registry';
4
+ import { DekApiStateType } from './state';
3
5
  export type SetLocationFunc = (to: string, options?: {
4
6
  replace?: boolean | undefined;
5
7
  } | undefined) => void;
6
- export type ApiState = {
7
- get: (key: string, defaultValue?: string | number) => string | number | undefined;
8
- set: (key: string, value: string | number) => void;
8
+ export type DekApiState = {
9
+ get: (key: string, defaultValue?: DekApiStateType) => DekApiStateType | undefined;
10
+ set: (key: string, value: DekApiStateType) => void;
9
11
  };
10
- type ApiInfo = {
12
+ export type DekApiInfo = {
11
13
  components: string[];
12
14
  screens: string[];
13
15
  };
14
- type ApiPlugin = {
16
+ export type DekApiPlugin = {
15
17
  available: boolean;
16
18
  component: (key: string, props?: any) => JSX.Element | undefined;
17
19
  componentSchema: (key: string) => DekPluginSchema;
18
20
  screen: (path: string) => JSX.Element | undefined;
19
21
  board: (key: string) => JSX.Element | undefined;
20
22
  api: any;
21
- state: ApiState;
22
- info: ApiInfo;
23
+ state: DekApiState;
24
+ info: DekApiInfo;
23
25
  };
24
- export type BoardApiMessageType = 'trace' | 'error';
25
- export type BoardApiMessage = {
26
- type: BoardApiMessageType;
26
+ export type DekApiMessageType = 'trace' | 'error' | 'warn';
27
+ export type DekApiMessage = {
28
+ type: DekApiMessageType;
27
29
  body: string;
28
30
  data?: any[];
29
31
  at: number;
30
32
  };
31
- export declare class Api {
32
- private messageArray;
33
+ export type DekApi = {
34
+ trace: (message: string, ...data: any[]) => void;
35
+ warn: (message: string, ...data: any[]) => void;
36
+ error: (message: string, ...data: any[]) => void;
37
+ messages: () => DekApiMessage[];
38
+ plugin: (name: string) => DekApiPlugin;
39
+ registry: DekRegistry;
40
+ boardKey: string;
41
+ boards: Record<string, any>;
42
+ board: any;
43
+ layout: string;
44
+ commandGroups: Record<string, any>;
45
+ navigate: (path: string) => void;
46
+ navigateBack: () => void;
47
+ open: (boardKey: string) => void;
48
+ plugins: Record<string, DekApiPlugin>;
49
+ };
50
+ export declare class Api implements DekApi {
33
51
  trace(message: string, ...data: any[]): void;
52
+ warn(message: string, ...data: any[]): void;
34
53
  error(message: string, ...data: any[]): void;
35
- messages(): BoardApiMessage[];
36
- plugin(name: string): ApiPlugin;
54
+ messages(): DekApiMessage[];
55
+ plugin(name: string): DekApiPlugin;
56
+ get registry(): DekRegistry;
37
57
  get boardKey(): string;
38
58
  get boards(): Record<string, any>;
39
59
  get board(): any;
@@ -44,12 +64,12 @@ export declare class Api {
44
64
  open(boardKey: string): void;
45
65
  private createPluginWrapper;
46
66
  private get globals();
47
- get plugins(): Record<string, ApiPlugin>;
67
+ get plugins(): Record<string, DekApiPlugin>;
48
68
  private getPluginInstance;
49
69
  private getComponent;
50
70
  private getComponentSchema;
51
71
  private getScreen;
52
72
  private getBoard;
53
73
  }
54
- declare const _default: Api;
55
- export default _default;
74
+ declare const api: Api;
75
+ export default api;
@@ -1,3 +1,3 @@
1
- import { Api } from '../api';
2
- declare function usePluginApi(): Api;
1
+ import { DekApi } from '../api';
2
+ declare function usePluginApi(): DekApi;
3
3
  export default usePluginApi;
@@ -1,2 +1,9 @@
1
- declare function usePluginState(plugin: string): Record<string, string | number>;
1
+ import { DekApiStateType } from '../state';
2
+ export type ApiSetStateAction = (value: DekApiStateType) => void;
3
+ declare function usePluginState(plugin: string, key: string): [DekApiStateType | undefined, ApiSetStateAction];
4
+ declare function usePluginState(plugin: string, key: string, defaultValue: string): [string, ApiSetStateAction];
5
+ declare function usePluginState(plugin: string, key: string, defaultValue: number): [number, ApiSetStateAction];
6
+ declare function usePluginState(plugin: string, key: string, defaultValue: boolean): [boolean, ApiSetStateAction];
7
+ declare function usePluginState(plugin: string, key: string, defaultValue: Array<any>): [Array<any>, ApiSetStateAction];
8
+ declare function usePluginState(plugin: string, key: string, defaultValue: Record<string, any>): [Record<string, any>, ApiSetStateAction];
2
9
  export default usePluginState;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import { DekApi } from './api';
2
3
  export type PluginElementFactoryWithProps = (props: any) => JSX.Element;
3
4
  export type PluginElementFactory = () => JSX.Element;
4
5
  export type DekPluginSchemaItem = {
@@ -23,7 +24,7 @@ export type DekPluginBoardItem = {
23
24
  };
24
25
  export type DekPluginConfig = Record<string, string>;
25
26
  export type DekPlugin = {
26
- load?: (config: DekPluginConfig) => Promise<void>;
27
+ load?: (api: DekApi) => Promise<void>;
27
28
  unload?: () => Promise<void>;
28
29
  components?: DekPluginComponentItem[];
29
30
  screens?: DekPluginScreenItem[];
@@ -0,0 +1,26 @@
1
+ export type DekRegistrySchemaPropsItem = {
2
+ type: 'string' | 'number' | 'boolean' | 'list' | 'color';
3
+ title: string;
4
+ default?: any;
5
+ };
6
+ export type DekRegistrySchemaProps = Record<string, DekRegistrySchemaPropsItem>;
7
+ export type DekRegistrySchemaItem = {
8
+ type: 'string' | 'number' | 'boolean' | 'component' | 'array' | 'props';
9
+ title: string;
10
+ required: boolean;
11
+ };
12
+ export type DekRegistrySchema = Record<string, DekRegistrySchemaItem>;
13
+ export type DekRegistryCollectionItem = Record<string, any>;
14
+ export type DekRegistryCollection = {
15
+ key: string;
16
+ name: string;
17
+ schema: DekRegistrySchema;
18
+ items: Record<string, DekRegistryCollectionItem>;
19
+ };
20
+ export type DekRegistry = {
21
+ collections: Record<string, DekRegistryCollection>;
22
+ collection: (collectionKey: string) => DekRegistryCollection | undefined;
23
+ collectionItems: (collectionKey: string) => DekRegistryCollectionItem[] | undefined;
24
+ registerCollection: (collectionKey: string, name: string, schema: Record<string, DekRegistrySchemaItem>) => void;
25
+ registerCollectionItem: (collectionKey: string, itemKey: string, item: DekRegistryCollectionItem) => void;
26
+ };
@@ -1,5 +1,8 @@
1
- export type ApiState = Record<string, Record<string, string | number>>;
2
- declare const state: ApiState;
3
- export declare function setState(plugin: string, key: string, value: string | number): void;
4
- export declare function getState(plugin: string, key: string): string | number | undefined;
5
- export default state;
1
+ export type DekApiStateType = string | number | boolean | Array<any> | Record<string, any>;
2
+ export type DekApiStateItem = Record<string, DekApiStateType>;
3
+ export type DekApiState = Record<string, DekApiStateItem>;
4
+ export declare function setState(plugin: string, key: string, value: DekApiStateType): void;
5
+ export declare function getState(plugin: string, key: string): DekApiStateType | undefined;
6
+ export declare function tryParseJson(jsonString: string, defaultValue?: {}): object;
7
+ export declare function useState(plugin: string): DekApiStateItem;
8
+ export declare function isJsonString(str: any): boolean;
@@ -0,0 +1 @@
1
+ export default function extractErrorMessage(err: unknown): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@appkit/dek-plugin",
3
3
  "private": false,
4
- "version": "0.3.4",
4
+ "version": "0.5.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -11,7 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "react": "^16.8.0 || 17.x || 18.x",
14
- "react-dom": "^16.8.0 || 17.x || 18.x"
14
+ "react-dom": "^16.8.0 || 17.x || 18.x",
15
+ "usehooks-ts": "^2.9.1"
15
16
  },
16
17
  "devDependencies": {
17
18
  "@types/react": "^18.2.15",
@@ -1,4 +0,0 @@
1
- declare function usePluginStateValue(plugin: string, key: string): string | number | undefined;
2
- declare function usePluginStateValue(plugin: string, key: string, defaultValue: string): string;
3
- declare function usePluginStateValue(plugin: string, key: string, defaultValue: number): number;
4
- export default usePluginStateValue;