plug-code 1.0.1 → 1.0.2

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 CHANGED
@@ -11,6 +11,6 @@ You are welcome to use Plug&Code in your projects, **personal or commercial**, a
11
11
  You can install the framework via npm or yarn:
12
12
 
13
13
  ```bash
14
- npm install @alaumo/plug-code
14
+ npm install plug-code
15
15
  # or
16
- yarn add @alaumo/plug-code
16
+ yarn add plug-code
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./types/plug-code";
2
+ export * from "./types/core/plcAPI";
3
+ export * from "./types/core/plcStore";
4
+ export * from "./types/contexts/pipeline";
5
+
6
+ export * from "./types/types/api";
7
+ export * from "./types/types/features";
8
+ export * from "./types/types/general";
9
+ export * from "./types/types/pipeline";
10
+ export * from "./types/types/store";
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "plug-code",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "types": "types/src/plug-code.d.ts",
6
7
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build:types": "tsc -p tsconfig.json"
8
10
  },
9
11
  "repository": {
10
12
  "type": "git",
@@ -23,6 +25,7 @@
23
25
  "react": "^19.2.3"
24
26
  },
25
27
  "devDependencies": {
26
- "@types/react": "^19.2.7"
28
+ "@types/react": "^19.2.7",
29
+ "typescript": "^5.4.2"
27
30
  }
28
31
  }
@@ -44,7 +44,14 @@ export class PlcAPI<S extends ObjectType> {
44
44
  }
45
45
  }
46
46
 
47
- scope<T = any>(key: string & "root") {
47
+ scope<T = any>(key: string & "root"): {
48
+ get: () => T;
49
+ update: (updater: (draft: T) => void) => void;
50
+ connect: (renderer: (data: T) => React.ReactNode) => React.FC;
51
+ render: (slotName: string) => React.ReactNode | null;
52
+ receive: (context?: any) => any;
53
+ root: PlcAPI<S>;
54
+ } {
48
55
  return {
49
56
  get: (): T => this.getData(key),
50
57
 
@@ -58,8 +65,8 @@ export class PlcAPI<S extends ObjectType> {
58
65
 
59
66
  render: (slotName: string) => {
60
67
  return this.connect(key, (localData) => {
61
- return this.pipeline.render(slotName, localData);
62
- });
68
+ return this.pipeline.render(slotName, localData) as React.ReactNode;
69
+ }) as any;
63
70
  },
64
71
 
65
72
  receive: (context: any = {}) => {
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export declare const ScopeContext: import("react").Context<any>;
2
+ export declare const useScopeData: <T>() => T;
@@ -0,0 +1,30 @@
1
+ import type { ObjectType } from "../types/general";
2
+ import type { PlcStore } from "./plcStore";
3
+ export declare class PlcAPI<S extends ObjectType> {
4
+ private store;
5
+ private pipeline;
6
+ private substores;
7
+ private transformers;
8
+ constructor(store: PlcStore<S>);
9
+ register(slot: string, node: () => React.ReactNode): void;
10
+ register<K extends string>(slot: string, node: (data: any) => React.ReactNode, dependencyKey: K): void;
11
+ scope<T = any>(key: string & "root"): {
12
+ get: () => T;
13
+ update: (updater: (draft: T) => void) => void;
14
+ connect: (renderer: (data: T) => React.ReactNode) => React.FC;
15
+ render: (slotName: string) => React.ReactNode | null;
16
+ receive: (context?: any) => any;
17
+ root: PlcAPI<S>;
18
+ };
19
+ connect<T = any>(key: string, renderer: (data: T) => React.ReactNode): React.FC;
20
+ wrap(slot: string, fn: (next: () => React.ReactNode) => () => React.ReactNode): void;
21
+ after(slot: string, node: () => React.ReactNode): void;
22
+ render(slot: string): import("react").ReactNode[] | import("react/jsx-runtime").JSX.Element;
23
+ invalidate(slot?: string): void;
24
+ send(id: string, fn: (data: any, context: any) => any, priority: number): void;
25
+ receive(initialData: any, context?: any): any;
26
+ getData(key: string): any;
27
+ subscribe(listener: () => void): () => void;
28
+ createData<K extends string, T>(key: K, initialState: T): void;
29
+ update<K extends keyof S>(key: string & "root", updater: (draft: any) => void, slot?: string): void;
30
+ }
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import type { ObjectType } from "../types/general";
3
+ import type { Slot } from "../types/pipeline";
4
+ import type { PlcStore } from "./plcStore";
5
+ export declare class PlcPipeline<S extends ObjectType> {
6
+ private slots;
7
+ private store;
8
+ private cache;
9
+ private scheduleQueue;
10
+ constructor(store: PlcStore<S>);
11
+ register(slot: string, fn: Slot, priority?: number): void;
12
+ wrap(slot: string, wrapper: (next: Slot) => Slot, priority?: number): void;
13
+ render(slot: string, contextData?: any): React.ReactNode[] | import("react/jsx-runtime").JSX.Element;
14
+ invalidate(slot?: string): void;
15
+ private regenerateCache;
16
+ }
@@ -0,0 +1,17 @@
1
+ import { type Draft } from "immer";
2
+ import type { ObjectType } from "../types/general";
3
+ export declare class PlcStore<S extends ObjectType> {
4
+ private state;
5
+ private listeners;
6
+ private batchQueue;
7
+ private debug;
8
+ private isBatching;
9
+ constructor(initial: S, debug: boolean);
10
+ get<K extends keyof S>(key: K): S[K];
11
+ getState(): S;
12
+ set<K extends keyof S>(key: K, value: S[K]): void;
13
+ batch(updater: (draft: Draft<S>) => void): void;
14
+ subscribe(listener: () => void): () => void;
15
+ subscribe<K extends keyof S>(key: K, listener: () => void): () => void;
16
+ private emit;
17
+ }
@@ -0,0 +1,13 @@
1
+ import type { ObjectType } from "./types/general";
2
+ import type { FeatureType } from "./types/features";
3
+ import { PlcAPI } from "./core/plcAPI";
4
+ export declare function createPlugAndCode<S extends ObjectType>(features: FeatureType<S>[]): {
5
+ useSystemPlc: <T extends object>(initialProps: T) => {
6
+ api: PlcAPI<{}>;
7
+ useSelector: <Result>(selector: (state: any) => Result) => Result;
8
+ };
9
+ SystemPlcRoot: ({ api, children }: {
10
+ api: PlcAPI<any>;
11
+ children?: React.ReactNode;
12
+ }) => import("react/jsx-runtime").JSX.Element;
13
+ };
@@ -0,0 +1,5 @@
1
+ export type transformerType = {
2
+ id: string;
3
+ priority: number;
4
+ fn: (data: any, context: any) => any;
5
+ };
@@ -0,0 +1,6 @@
1
+ import type { PlcAPI } from "../core/plcAPI";
2
+ import type { ObjectType } from "./general";
3
+ export type FeatureType<S extends ObjectType> = {
4
+ name: string;
5
+ setup?: (api: PlcAPI<S>) => void | (() => void);
6
+ };
@@ -0,0 +1 @@
1
+ export type ObjectType = Record<string, any>;
@@ -0,0 +1,6 @@
1
+ export type Slot = () => React.ReactNode;
2
+ export type ScheduledSlot = {
3
+ slot: string;
4
+ fn: Slot;
5
+ priority: number;
6
+ };
@@ -0,0 +1,4 @@
1
+ export type Listener<S> = {
2
+ key?: keyof S;
3
+ callback: () => void;
4
+ };