plug-code 1.2.0 → 2.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/README.md +135 -94
- package/dist/core/helpers/core.d.ts +2 -0
- package/dist/core/helpers/core.js +32 -0
- package/dist/core/hooks/plcHooks.d.ts +15 -0
- package/dist/core/hooks/plcHooks.js +47 -0
- package/dist/core/plcAPI.d.ts +83 -0
- package/dist/core/plcAPI.js +472 -0
- package/dist/core/plcPipeline.d.ts +8 -0
- package/dist/core/plcPipeline.js +35 -0
- package/dist/core/plcScheduler.d.ts +7 -0
- package/dist/core/plcScheduler.js +22 -0
- package/dist/core/plcStore.d.ts +33 -0
- package/dist/core/plcStore.js +159 -0
- package/dist/core/ui/plcCore.d.ts +8 -0
- package/dist/core/ui/plcCore.js +40 -0
- package/dist/core/ui/plcErrorBoundary.d.ts +17 -0
- package/dist/core/ui/plcErrorBoundary.js +17 -0
- package/dist/core/ui/plcInspector.d.ts +5 -0
- package/dist/core/ui/plcInspector.js +27 -0
- package/dist/core/ui/plcLayout.d.ts +28 -0
- package/dist/core/ui/plcLayout.js +125 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/types/core/api.d.ts +7 -0
- package/dist/types/core/api.js +1 -0
- package/dist/types/core/general.d.ts +15 -0
- package/dist/types/core/general.js +1 -0
- package/dist/types/core/registry.d.ts +7 -0
- package/dist/types/core/registry.js +1 -0
- package/dist/types/core/ui.d.ts +7 -0
- package/dist/types/core/ui.js +1 -0
- package/dist/types/registry.d.ts +20 -0
- package/dist/types/registry.js +1 -0
- package/package.json +16 -22
- package/index.d.ts +0 -1
- package/src/contexts/pipeline.tsx +0 -4
- package/src/core/plcAPI.tsx +0 -393
- package/src/core/plcPipeline.tsx +0 -87
- package/src/core/plcStore.tsx +0 -94
- package/src/helpers/core.ts +0 -10
- package/src/plug-code.tsx +0 -64
- package/src/types/api.ts +0 -8
- package/src/types/features.ts +0 -7
- package/src/types/general.ts +0 -2
- package/src/types/pipeline.ts +0 -3
- package/src/types/registry.ts +0 -4
- package/src/types/store.ts +0 -2
- package/tsconfig.json +0 -15
- package/types/plug-code.d.ts +0 -164
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2019",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"jsx": "react-jsx",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"emitDeclarationOnly": true,
|
|
8
|
-
"outDir": "types",
|
|
9
|
-
"strict": false,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"moduleResolution": "Node"
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*.ts", "src/**/*.tsx"]
|
|
15
|
-
}
|
package/types/plug-code.d.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
// ==========================================
|
|
4
|
-
// Tipos Generales
|
|
5
|
-
// ==========================================
|
|
6
|
-
|
|
7
|
-
export declare type ObjectType = Record<string, any>;
|
|
8
|
-
|
|
9
|
-
export type Slot = () => React.ReactNode;
|
|
10
|
-
interface SlotRegistry {}
|
|
11
|
-
type SlotKey = keyof SlotRegistry | (string & {});
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Función para ejecutar lógica de negocio (Acciones).
|
|
15
|
-
* Puede ser síncrona o asíncrona.
|
|
16
|
-
*/
|
|
17
|
-
export type CommandFn<T = any, R = any> = (payload: T) => Promise<R> | R;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Función para transformar datos (Pipes).
|
|
21
|
-
* Debe ser pura y síncrona preferiblemente.
|
|
22
|
-
*/
|
|
23
|
-
export type TransformerFn<D = any, C = any> = (data: D, context: C) => D;
|
|
24
|
-
|
|
25
|
-
// ==========================================
|
|
26
|
-
// Core: Store
|
|
27
|
-
// ==========================================
|
|
28
|
-
|
|
29
|
-
export declare class PlcStore<S extends ObjectType> {
|
|
30
|
-
constructor(initial: S, debug: boolean);
|
|
31
|
-
|
|
32
|
-
get<K extends keyof S>(key: K): S[K];
|
|
33
|
-
getState(): S;
|
|
34
|
-
set<K extends keyof S>(key: K, value: S[K]): void;
|
|
35
|
-
|
|
36
|
-
/** Agrupa múltiples actualizaciones en un solo evento de notificación */
|
|
37
|
-
batch(updater: (draft: S) => void): void;
|
|
38
|
-
|
|
39
|
-
subscribe(listener: () => void): () => void;
|
|
40
|
-
subscribe<K extends keyof S>(key: K, listener: () => void): () => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// ==========================================
|
|
44
|
-
// Core: API Principal
|
|
45
|
-
// ==========================================
|
|
46
|
-
|
|
47
|
-
export declare class PlcAPI<S extends ObjectType> {
|
|
48
|
-
constructor(store: PlcStore<S>);
|
|
49
|
-
|
|
50
|
-
// --- Configuración del Sistema (Fluent Interface) ---
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Registra un módulo o feature en el sistema.
|
|
54
|
-
* @param name Identificador único para debugging y prevención de duplicados.
|
|
55
|
-
* @param setupFn Función de configuración donde registras slots, comandos, etc.
|
|
56
|
-
*/
|
|
57
|
-
watch<T>(storeKey: string, selector: (data: any) => T, callback: (newValue: T, oldValue: T) => void): () => void
|
|
58
|
-
override<K extends string>(key: K & "root", data: any, slot?: string): void
|
|
59
|
-
// --- Gestión de UI (Slots & Rendering) ---
|
|
60
|
-
|
|
61
|
-
redraw(key: string): void
|
|
62
|
-
register(slot: string, node: (props?: any) => React.ReactNode): void;
|
|
63
|
-
register<K extends string>(slot: string, node: (data: any, props?: any) => React.ReactNode, dependencyKey: K): void;
|
|
64
|
-
|
|
65
|
-
/** Envuelve un slot existente (Decorador/Wrapper) */
|
|
66
|
-
wrap(slot: string, fn: (next: () => React.ReactNode) => () => React.ReactNode): void;
|
|
67
|
-
|
|
68
|
-
/** Agrega contenido después de un slot existente */
|
|
69
|
-
after(slot: string, node: () => React.ReactNode): void;
|
|
70
|
-
|
|
71
|
-
/** Renderiza el contenido de un slot */
|
|
72
|
-
render(slot: string, contextData?: any): React.ReactNode;
|
|
73
|
-
|
|
74
|
-
/** Fuerza la regeneración del caché de un slot */
|
|
75
|
-
invalidate(slot?: string): void;
|
|
76
|
-
|
|
77
|
-
// --- Gestión de Datos (Scope & State) ---
|
|
78
|
-
|
|
79
|
-
createData<K extends string, T>(key: K, initialState: T): void;
|
|
80
|
-
|
|
81
|
-
getData(key: string): any;
|
|
82
|
-
|
|
83
|
-
derive<K extends string>(outputKey: K, dependencies: string[], calculator: () => any): void
|
|
84
|
-
|
|
85
|
-
update(key: string | "root", updater: (draft: any) => void, slot?: string, triggerKey?: string): void;
|
|
86
|
-
|
|
87
|
-
subscribe(listener: () => void): () => void;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Obtiene una interfaz tipada para interactuar con una parte específica del estado.
|
|
91
|
-
*/
|
|
92
|
-
scope<T = any>(key: string): {
|
|
93
|
-
get: () => T;
|
|
94
|
-
update: (updater: (draft: T) => void, slot?: string, triggerKey?: string) => void;
|
|
95
|
-
connect: <P = {}, R = any>(
|
|
96
|
-
selector: (data: T, props: P) => R
|
|
97
|
-
) => (WrappedComponent: React.ComponentType<P & R>) => React.FC<P>;
|
|
98
|
-
|
|
99
|
-
render: (slotName: SlotKey) => React.FC;
|
|
100
|
-
receive: (context?: any) => any;
|
|
101
|
-
root: PlcAPI<S>;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/** Conecta un componente a una parte del estado (HOC) */
|
|
105
|
-
connect<State = any, OwnProps = {}, ResultProps = {}>(key: string, selector: (state: State, props: OwnProps) => ResultProps): (WrappedComponent: React.ComponentType<OwnProps & ResultProps>) => React.FC<OwnProps>;
|
|
106
|
-
|
|
107
|
-
// --- Pipeline de Datos (Transforms) ---
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Registra un transformador en un canal específico.
|
|
111
|
-
* @param channel Nombre del canal (ej: 'calculo-impuestos')
|
|
112
|
-
* @param id Identificador único del transformador
|
|
113
|
-
* @param fn Función transformadora
|
|
114
|
-
* @param priority Mayor número se ejecuta al final (default: 0)
|
|
115
|
-
*/
|
|
116
|
-
send(channel: string, id: string, fn: TransformerFn, priority?: number): void;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Ejecuta la tubería de transformación para un canal.
|
|
120
|
-
*/
|
|
121
|
-
receive(channel: string, initialData: any, context?: any): any;
|
|
122
|
-
|
|
123
|
-
// --- Sistema de Comandos (Actions) ---
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Registra una acción ejecutable.
|
|
127
|
-
*/
|
|
128
|
-
registerCommand<T = any, R = any>(id: string, fn: CommandFn<T, R>): void;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Envuelve o intercepta un comando existente.
|
|
132
|
-
*/
|
|
133
|
-
wrapCommand<T = any, R = any>(id: string, wrapper: (next: CommandFn<T, R>) => CommandFn<T, R>): void;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Ejecuta una acción registrada.
|
|
137
|
-
* @returns Promesa con el resultado del comando.
|
|
138
|
-
*/
|
|
139
|
-
execute<T = any, R = any>(id: string, payload?: T): Promise<R>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// ==========================================
|
|
143
|
-
// Entry Point & Hooks
|
|
144
|
-
// ==========================================
|
|
145
|
-
|
|
146
|
-
export type SystemInstance<S extends ObjectType> = {
|
|
147
|
-
api: PlcAPI<S>;
|
|
148
|
-
/** Hook para seleccionar datos del store reactivamente */
|
|
149
|
-
useSelector: <Result>(selector: (state: S) => Result) => Result;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Inicializa el framework.
|
|
154
|
-
* @param setupSystem Función callback para configurar las features iniciales.
|
|
155
|
-
*/
|
|
156
|
-
export declare function createPlugAndCode<S extends ObjectType>(
|
|
157
|
-
setupSystem: (api: PlcAPI<S>) => void
|
|
158
|
-
): {
|
|
159
|
-
useSystemPlc: (initialProps: S) => SystemInstance<S>;
|
|
160
|
-
SystemPlcRoot: React.FC<{ api: PlcAPI<S>; children?: React.ReactNode }>;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
/** Hook para acceder al contexto local dentro de un slot renderizado */
|
|
164
|
-
export declare function useScopeData<T>(): T;
|