plug-code 2.0.4 → 2.3.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/LICENSE +11 -5
- package/README.md +203 -70
- package/dist/core/helpers/core.d.ts +3 -2
- package/dist/core/helpers/core.d.ts.map +1 -0
- package/dist/core/helpers/core.js +22 -17
- package/dist/core/helpers/core.js.map +1 -0
- package/dist/core/hooks/plcHooks.d.ts +1 -0
- package/dist/core/hooks/plcHooks.d.ts.map +1 -0
- package/dist/core/hooks/plcHooks.js +4 -9
- package/dist/core/hooks/plcHooks.js.map +1 -0
- package/dist/core/plcAPI.d.ts +13 -2
- package/dist/core/plcAPI.d.ts.map +1 -0
- package/dist/core/plcAPI.js +52 -26
- package/dist/core/plcAPI.js.map +1 -0
- package/dist/core/plcPipeline.d.ts +1 -0
- package/dist/core/plcPipeline.d.ts.map +1 -0
- package/dist/core/plcPipeline.js +1 -0
- package/dist/core/plcPipeline.js.map +1 -0
- package/dist/core/plcScheduler.d.ts +1 -0
- package/dist/core/plcScheduler.d.ts.map +1 -0
- package/dist/core/plcScheduler.js +1 -0
- package/dist/core/plcScheduler.js.map +1 -0
- package/dist/core/plcStore.d.ts +1 -0
- package/dist/core/plcStore.d.ts.map +1 -0
- package/dist/core/plcStore.js +4 -3
- package/dist/core/plcStore.js.map +1 -0
- package/dist/core/ui/plcCore.d.ts +9 -5
- package/dist/core/ui/plcCore.d.ts.map +1 -0
- package/dist/core/ui/plcCore.js +152 -36
- package/dist/core/ui/plcCore.js.map +1 -0
- package/dist/core/ui/plcErrorBoundary.d.ts +1 -0
- package/dist/core/ui/plcErrorBoundary.d.ts.map +1 -0
- package/dist/core/ui/plcErrorBoundary.js +1 -0
- package/dist/core/ui/plcErrorBoundary.js.map +1 -0
- package/dist/core/ui/plcInspector.d.ts +1 -0
- package/dist/core/ui/plcInspector.d.ts.map +1 -0
- package/dist/core/ui/plcInspector.js +1 -0
- package/dist/core/ui/plcInspector.js.map +1 -0
- package/dist/core/ui/plcLayout.d.ts +12 -0
- package/dist/core/ui/plcLayout.d.ts.map +1 -0
- package/dist/core/ui/plcLayout.js +53 -16
- package/dist/core/ui/plcLayout.js.map +1 -0
- package/dist/core/ui/plcSlotRenderer.d.ts +7 -0
- package/dist/core/ui/plcSlotRenderer.d.ts.map +1 -0
- package/dist/core/ui/plcSlotRenderer.js +11 -0
- package/dist/core/ui/plcSlotRenderer.js.map +1 -0
- package/dist/core/workers/codes.d.ts +2 -0
- package/dist/core/workers/codes.d.ts.map +1 -0
- package/dist/core/workers/codes.js +16 -0
- package/dist/core/workers/codes.js.map +1 -0
- package/dist/core/workers/helpers/filter.worker.d.ts +2 -0
- package/dist/core/workers/helpers/filter.worker.d.ts.map +1 -0
- package/dist/core/workers/helpers/filter.worker.js +57 -0
- package/dist/core/workers/helpers/filter.worker.js.map +1 -0
- package/dist/core/workers/search.worker.d.ts +2 -0
- package/dist/core/workers/search.worker.d.ts.map +1 -0
- package/dist/core/workers/search.worker.js +82 -0
- package/dist/core/workers/search.worker.js.map +1 -0
- package/dist/core.d.ts +5 -24
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +10 -1
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/simple.d.ts +42 -0
- package/dist/simple.d.ts.map +1 -0
- package/dist/simple.js +88 -0
- package/dist/simple.js.map +1 -0
- package/dist/types/core/api.d.ts +1 -0
- package/dist/types/core/api.d.ts.map +1 -0
- package/dist/types/core/api.js +1 -0
- package/dist/types/core/api.js.map +1 -0
- package/dist/types/core/general.d.ts +2 -2
- package/dist/types/core/general.d.ts.map +1 -0
- package/dist/types/core/general.js +1 -0
- package/dist/types/core/general.js.map +1 -0
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/index.js +1 -0
- package/dist/types/core/index.js.map +1 -0
- package/dist/types/core/ui.d.ts +8 -2
- package/dist/types/core/ui.d.ts.map +1 -0
- package/dist/types/core/ui.js +1 -0
- package/dist/types/core/ui.js.map +1 -0
- package/dist/types/core.d.ts +45 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +2 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/registry.d.ts +1 -0
- package/dist/types/registry.d.ts.map +1 -0
- package/dist/types/registry.js +1 -0
- package/dist/types/registry.js.map +1 -0
- package/package.json +27 -3
|
@@ -13,16 +13,28 @@ export declare class PlcLayout {
|
|
|
13
13
|
private wrappers;
|
|
14
14
|
private renderCache;
|
|
15
15
|
private cacheVersion;
|
|
16
|
+
private globalVersion;
|
|
16
17
|
markVirtual(slot: string, config?: {
|
|
17
18
|
itemHeight?: number;
|
|
18
19
|
overscan?: number;
|
|
20
|
+
initialEstimatedHeight?: number;
|
|
21
|
+
as?: any;
|
|
22
|
+
itemAs?: any;
|
|
19
23
|
}): void;
|
|
20
24
|
wrap(slot: string, wrapper: SlotWrapper, priority?: number): void;
|
|
21
25
|
register(slot: string, id: string, fn: (props?: any) => React.ReactNode, priority?: number, keepAlive?: boolean): void;
|
|
26
|
+
registerMany(slot: string, items: {
|
|
27
|
+
id: string;
|
|
28
|
+
fn: (props?: any) => React.ReactNode;
|
|
29
|
+
priority?: number;
|
|
30
|
+
keepAlive?: boolean;
|
|
31
|
+
}[]): void;
|
|
22
32
|
unregister(slot: string, id: string): void;
|
|
23
33
|
invalidate(slot?: string): void;
|
|
34
|
+
getSlotVersion(slot: string): number;
|
|
24
35
|
render(slot: string, props?: any): React.ReactNode;
|
|
25
36
|
private renderBase;
|
|
26
37
|
getSlotItems(slot: string): SlotItem[];
|
|
27
38
|
getPriority(slot: string, id: string): number | undefined;
|
|
28
39
|
}
|
|
40
|
+
//# sourceMappingURL=plcLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plcLayout.d.ts","sourceRoot":"","sources":["../../../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,EAAE,GAAG,KAAK,KAAK,CAAC,SAAS,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE;IAwBhI,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAcnC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM;IAWxB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIpC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,SAAS;IAYlD,OAAO,CAAC,UAAU;IAyDlB,YAAY,CAAC,IAAI,EAAE,MAAM;IACzB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAG5D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, Component } from "react";
|
|
2
|
+
import React, { createContext, Component } from "react";
|
|
3
3
|
import { VirtualContainer } from "./plcCore";
|
|
4
|
+
import { SlotItemRenderer } from "./plcSlotRenderer";
|
|
4
5
|
export const ScopeContext = createContext(undefined);
|
|
5
6
|
// ---------------------------------------------------------
|
|
6
7
|
// Error Boundary
|
|
@@ -26,16 +27,23 @@ export class PlcLayout {
|
|
|
26
27
|
wrappers = new Map();
|
|
27
28
|
renderCache = new Map();
|
|
28
29
|
cacheVersion = new Map();
|
|
30
|
+
globalVersion = 0;
|
|
29
31
|
// ---------------------------------------------------------
|
|
30
32
|
// Virtualization
|
|
31
33
|
// ---------------------------------------------------------
|
|
32
34
|
markVirtual(slot, config) {
|
|
35
|
+
const itemHeight = config?.itemHeight;
|
|
33
36
|
this.virtualRegistry.set(slot, {
|
|
34
|
-
itemHeight
|
|
35
|
-
overscan: config?.overscan ??
|
|
36
|
-
measured: !!
|
|
37
|
-
estimatedHeight: config?.
|
|
37
|
+
itemHeight,
|
|
38
|
+
overscan: config?.overscan ?? 5,
|
|
39
|
+
measured: !!itemHeight,
|
|
40
|
+
estimatedHeight: itemHeight ?? config?.initialEstimatedHeight ?? 48,
|
|
41
|
+
dynamicMeasurement: !itemHeight,
|
|
42
|
+
scrollTop: 0,
|
|
43
|
+
as: config?.as ?? 'div',
|
|
44
|
+
itemAs: config?.itemAs ?? 'div'
|
|
38
45
|
});
|
|
46
|
+
this.invalidate(slot);
|
|
39
47
|
}
|
|
40
48
|
// ---------------------------------------------------------
|
|
41
49
|
// Middleware (WRAP)
|
|
@@ -56,12 +64,35 @@ export class PlcLayout {
|
|
|
56
64
|
this.cacheVersion.set(slot, 0);
|
|
57
65
|
}
|
|
58
66
|
const list = this.slots.get(slot);
|
|
67
|
+
if (list.length > 1) {
|
|
68
|
+
list.sort((a, b) => b.priority - a.priority);
|
|
69
|
+
}
|
|
59
70
|
const existingIdx = list.findIndex(x => x.id === id);
|
|
60
71
|
const item = { id, priority, fn, keepAlive };
|
|
61
72
|
if (existingIdx >= 0)
|
|
62
73
|
list[existingIdx] = item;
|
|
63
74
|
else
|
|
64
75
|
list.push(item);
|
|
76
|
+
this.invalidate(slot);
|
|
77
|
+
}
|
|
78
|
+
registerMany(slot, items) {
|
|
79
|
+
if (!this.slots.has(slot)) {
|
|
80
|
+
this.slots.set(slot, []);
|
|
81
|
+
this.cacheVersion.set(slot, 0);
|
|
82
|
+
}
|
|
83
|
+
const list = this.slots.get(slot);
|
|
84
|
+
items.forEach(item => {
|
|
85
|
+
const existingIdx = list.findIndex(x => x.id === item.id);
|
|
86
|
+
const newItem = {
|
|
87
|
+
priority: 0,
|
|
88
|
+
keepAlive: false,
|
|
89
|
+
...item
|
|
90
|
+
};
|
|
91
|
+
if (existingIdx >= 0)
|
|
92
|
+
list[existingIdx] = newItem;
|
|
93
|
+
else
|
|
94
|
+
list.push(newItem);
|
|
95
|
+
});
|
|
65
96
|
list.sort((a, b) => b.priority - a.priority);
|
|
66
97
|
this.invalidate(slot);
|
|
67
98
|
}
|
|
@@ -81,15 +112,17 @@ export class PlcLayout {
|
|
|
81
112
|
invalidate(slot) {
|
|
82
113
|
if (slot) {
|
|
83
114
|
this.renderCache.delete(slot);
|
|
84
|
-
|
|
115
|
+
const current = this.cacheVersion.get(slot) || 0;
|
|
116
|
+
this.cacheVersion.set(slot, current + 1);
|
|
85
117
|
}
|
|
86
118
|
else {
|
|
87
119
|
this.renderCache.clear();
|
|
88
|
-
|
|
89
|
-
this.cacheVersion.set(k, (this.cacheVersion.get(k) || 0) + 1);
|
|
90
|
-
}
|
|
120
|
+
this.globalVersion++;
|
|
91
121
|
}
|
|
92
122
|
}
|
|
123
|
+
getSlotVersion(slot) {
|
|
124
|
+
return (this.cacheVersion.get(slot) || 0) + this.globalVersion;
|
|
125
|
+
}
|
|
93
126
|
render(slot, props) {
|
|
94
127
|
let content = this.renderBase(slot, props);
|
|
95
128
|
const slotWrappers = this.wrappers.get(slot);
|
|
@@ -103,19 +136,22 @@ export class PlcLayout {
|
|
|
103
136
|
renderBase(slot, props) {
|
|
104
137
|
const list = this.slots.get(slot) || [];
|
|
105
138
|
const virtualConfig = this.virtualRegistry.get(slot);
|
|
139
|
+
const dataItems = props?.items;
|
|
140
|
+
if (virtualConfig && Array.isArray(dataItems)) {
|
|
141
|
+
const templateItem = list[0];
|
|
142
|
+
if (!templateItem)
|
|
143
|
+
return null;
|
|
144
|
+
return (_jsx(VirtualContainer, { data: dataItems, renderItem: (item, index) => (_jsx(SlotErrorBoundary, { id: `${templateItem.id}-idx-${index}`, children: templateItem.fn(item) })), config: virtualConfig, contextData: props }));
|
|
145
|
+
}
|
|
106
146
|
if (virtualConfig && list.length > 0) {
|
|
107
|
-
|
|
108
|
-
...item,
|
|
109
|
-
fn: (p) => (_jsx(SlotErrorBoundary, { id: item.id, children: item.fn(p) }))
|
|
110
|
-
}));
|
|
111
|
-
const content = protectedItems.map((item, i) => (_jsx(ScopeContext.Provider, { value: props, children: item.fn(props) }, item.id)));
|
|
112
|
-
return (_jsx(VirtualContainer, { content: content, config: virtualConfig, contextData: props }));
|
|
147
|
+
return (_jsx(VirtualContainer, { data: list, renderItem: (item) => (_jsx(SlotErrorBoundary, { id: item.id, children: item.fn(props) })), config: virtualConfig, contextData: props }));
|
|
113
148
|
}
|
|
114
149
|
return list.map(item => {
|
|
115
150
|
const isActive = props?.activeId ? props.activeId === item.id : true;
|
|
116
151
|
if (!isActive && !item.keepAlive)
|
|
117
152
|
return null;
|
|
118
|
-
|
|
153
|
+
const Container = item.as || React.Fragment;
|
|
154
|
+
return (_jsx(Container, { children: _jsx("div", { style: { display: isActive ? undefined : 'none' }, children: _jsx(SlotErrorBoundary, { id: item.id, children: _jsx(SlotItemRenderer, { item: item, props: props }) }) }) }, item.id));
|
|
119
155
|
});
|
|
120
156
|
}
|
|
121
157
|
getSlotItems(slot) { return this.slots.get(slot) || []; }
|
|
@@ -123,3 +159,4 @@ export class PlcLayout {
|
|
|
123
159
|
return this.slots.get(slot)?.find(x => x.id === id)?.priority;
|
|
124
160
|
}
|
|
125
161
|
}
|
|
162
|
+
//# sourceMappingURL=plcLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plcLayout.js","sourceRoot":"","sources":["../../../src/core/ui/plcLayout.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAM,SAAS,CAAC,CAAC;AAE1D,4DAA4D;AAC5D,iBAAiB;AACjB,4DAA4D;AAC5D,MAAM,iBAAkB,SAAQ,SAAuG;IACnI,KAAK,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAE5B,MAAM,CAAC,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AAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC;IAClE,CAAC;CACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SlotItem } from "./plcLayout";
|
|
3
|
+
export declare const SlotItemRenderer: React.MemoExoticComponent<({ item, props }: {
|
|
4
|
+
item: SlotItem;
|
|
5
|
+
props: any;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element>;
|
|
7
|
+
//# sourceMappingURL=plcSlotRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plcSlotRenderer.d.ts","sourceRoot":"","sources":["../../../src/core/ui/plcSlotRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAgB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIrD,eAAO,MAAM,gBAAgB,8CAG1B;IACC,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,GAAG,CAAA;CACb,6CAUC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ScopeContext } from "./plcLayout";
|
|
4
|
+
import { SlotErrorBoundary } from "./plcErrorBoundary";
|
|
5
|
+
import { shallowEqual } from "../helpers/core";
|
|
6
|
+
export const SlotItemRenderer = React.memo(({ item, props }) => {
|
|
7
|
+
return (_jsx(SlotErrorBoundary, { id: item.id, children: _jsx(ScopeContext.Provider, { value: props, children: item.fn(props) }) }));
|
|
8
|
+
}, (prev, next) => {
|
|
9
|
+
return prev.item === next.item && shallowEqual(prev.props, next.props);
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=plcSlotRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plcSlotRenderer.js","sourceRoot":"","sources":["../../../src/core/ui/plcSlotRenderer.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAY,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,EACxC,IAAI,EACJ,KAAK,EAIR,EAAE,EAAE;IACD,OAAO,CACH,KAAC,iBAAiB,IAAC,EAAE,EAAE,IAAI,CAAC,EAAE,YAC1B,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC9B,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,GACK,GACR,CACvB,CAAC;AACN,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IACd,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const WORKER_FILTER_CODE = "\n self.onmessage = (e) => {\n const { data, query, fields } = e.data;\n if (!query) { self.postMessage(data); return; }\n \n const q = query.toLowerCase();\n \n const result = data.filter(item => \n fields.some(field => \n String(item[field] || \"\").toLowerCase().includes(q)\n )\n );\n self.postMessage(result);\n };\n";
|
|
2
|
+
//# sourceMappingURL=codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../../src/core/workers/codes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,yXAc9B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const WORKER_FILTER_CODE = `
|
|
2
|
+
self.onmessage = (e) => {
|
|
3
|
+
const { data, query, fields } = e.data;
|
|
4
|
+
if (!query) { self.postMessage(data); return; }
|
|
5
|
+
|
|
6
|
+
const q = query.toLowerCase();
|
|
7
|
+
|
|
8
|
+
const result = data.filter(item =>
|
|
9
|
+
fields.some(field =>
|
|
10
|
+
String(item[field] || "").toLowerCase().includes(q)
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
self.postMessage(result);
|
|
14
|
+
};
|
|
15
|
+
`;
|
|
16
|
+
//# sourceMappingURL=codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.js","sourceRoot":"","sources":["../../../src/core/workers/codes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;CAcjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.worker.d.ts","sourceRoot":"","sources":["../../../../src/core/workers/helpers/filter.worker.ts"],"names":[],"mappings":"AAoEA,OAAO,EAAG,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const ctx = self;
|
|
2
|
+
let SEARCH_CACHE = [];
|
|
3
|
+
let DATA_LENGTH = 0;
|
|
4
|
+
let PENDING_DATA = []; // Buffer temporal de arrays de strings
|
|
5
|
+
ctx.onmessage = (e) => {
|
|
6
|
+
const { type } = e.data;
|
|
7
|
+
// Reinicio de carga
|
|
8
|
+
if (type === "init-start") {
|
|
9
|
+
PENDING_DATA = [];
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// Recepción de paquete ligero
|
|
13
|
+
if (type === "init-chunk") {
|
|
14
|
+
const { chunk } = e.data;
|
|
15
|
+
// chunk es string[][] (array de filas, cada fila tiene array de valores)
|
|
16
|
+
// Usamos un bucle for clásico por velocidad
|
|
17
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
18
|
+
PENDING_DATA.push(chunk[i]);
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Commit final: Construir el índice de texto plano
|
|
23
|
+
if (type === "init-commit") {
|
|
24
|
+
const data = PENDING_DATA;
|
|
25
|
+
DATA_LENGTH = data.length;
|
|
26
|
+
SEARCH_CACHE = new Array(DATA_LENGTH);
|
|
27
|
+
for (let i = 0; i < DATA_LENGTH; i++) {
|
|
28
|
+
// Unimos los valores con espacio y a minúsculas
|
|
29
|
+
// data[i] ya contiene solo los valores que nos interesan
|
|
30
|
+
SEARCH_CACHE[i] = data[i].join(" ").toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
// Liberamos memoria
|
|
33
|
+
PENDING_DATA = [];
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Filtrado (Igual que antes)
|
|
37
|
+
if (type === "filter") {
|
|
38
|
+
const { query } = e.data;
|
|
39
|
+
const q = query.toLowerCase();
|
|
40
|
+
if (!q) {
|
|
41
|
+
ctx.postMessage(null);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const result = new Int32Array(DATA_LENGTH);
|
|
45
|
+
let count = 0;
|
|
46
|
+
// Búsqueda lineal ultrarrápida
|
|
47
|
+
for (let i = 0; i < DATA_LENGTH; i++) {
|
|
48
|
+
if (SEARCH_CACHE[i].includes(q)) {
|
|
49
|
+
result[count++] = i;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const finalResult = result.slice(0, count);
|
|
53
|
+
ctx.postMessage(finalResult.buffer, [finalResult.buffer]);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=filter.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.worker.js","sourceRoot":"","sources":["../../../../src/core/workers/helpers/filter.worker.ts"],"names":[],"mappings":"AAAA,MAAM,GAAG,GAAG,IAAyB,CAAC;AAEtC,IAAI,YAAY,GAAa,EAAE,CAAC;AAChC,IAAI,WAAW,GAAG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G,CAAC,CAAC,IAAI,CAAC;QACzB,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAE9B,IAAI,CAAC,CAAC,EAAE,CAAC;YACL,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO;QACX,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3C,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,+BAA+B;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC9B,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACL,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAC3C,GAAG,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const SEARCH_WORKER_CODE = "\nlet masterData = {};\nlet searchCache = {};\n\nfunction sendInChunks(id, reqId, indices, chunkSize = 1000, delay = 8) {\n let offset = 0;\n\n function pump() {\n const end = Math.min(offset + chunkSize, indices.length);\n\n // Copia segura en nuevo TypedArray\n const chunk = new Int32Array(end - offset);\n chunk.set(indices.subarray(offset, end));\n\n const isReset = offset === 0;\n const isDone = end >= indices.length;\n\n self.postMessage({\n type: 'SEARCH_CHUNK',\n id,\n reqId,\n chunk,\n reset: isReset,\n done: isDone\n }, [chunk.buffer]);\n\n offset = end;\n if (!isDone) setTimeout(pump, delay);\n }\n\n pump();\n}\n\nself.onmessage = (e) => {\n const { type, payload } = e.data;\n\n if (type === 'UPDATE_DATA') {\n const { sourceKey, data } = payload;\n masterData[sourceKey] = data;\n\n if (data && data.length > 0) {\n const keys = Object.keys(data[0]);\n searchCache[sourceKey] = new Array(data.length);\n for (let i = 0; i < data.length; i++) {\n let rowStr = '';\n const item = data[i];\n for (let k = 0; k < keys.length; k++) rowStr += item[keys[k]] + ' ';\n searchCache[sourceKey][i] = rowStr.toLowerCase();\n }\n }\n }\n\n if (type === 'FILTER') {\n const { id, sourceKey, query, reqId, limit } = payload;\n const cache = searchCache[sourceKey];\n if (!cache || !query) return;\n\n const lowerQ = query.toLowerCase();\n\n // \u26A1 Primera pasada r\u00E1pida: devolver primeros matches ASAP\n const fast = [];\n for (let i = 0; i < cache.length && fast.length < 200; i++) {\n if (cache[i].includes(lowerQ)) fast.push(i);\n }\n\n if (fast.length) {\n sendInChunks(id, reqId, new Int32Array(fast));\n }\n\n // \uD83D\uDC22 Segunda pasada completa\n const result = new Int32Array(cache.length);\n let count = 0;\n\n for (let i = 0; i < cache.length; i++) {\n if (cache[i].includes(lowerQ)) result[count++] = i;\n }\n\n sendInChunks(id, reqId, result.subarray(0, count));\n }\n};\n";
|
|
2
|
+
//# sourceMappingURL=search.worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.worker.d.ts","sourceRoot":"","sources":["../../../src/core/workers/search.worker.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,yyEAgF9B,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const SEARCH_WORKER_CODE = `
|
|
2
|
+
let masterData = {};
|
|
3
|
+
let searchCache = {};
|
|
4
|
+
|
|
5
|
+
function sendInChunks(id, reqId, indices, chunkSize = 1000, delay = 8) {
|
|
6
|
+
let offset = 0;
|
|
7
|
+
|
|
8
|
+
function pump() {
|
|
9
|
+
const end = Math.min(offset + chunkSize, indices.length);
|
|
10
|
+
|
|
11
|
+
// Copia segura en nuevo TypedArray
|
|
12
|
+
const chunk = new Int32Array(end - offset);
|
|
13
|
+
chunk.set(indices.subarray(offset, end));
|
|
14
|
+
|
|
15
|
+
const isReset = offset === 0;
|
|
16
|
+
const isDone = end >= indices.length;
|
|
17
|
+
|
|
18
|
+
self.postMessage({
|
|
19
|
+
type: 'SEARCH_CHUNK',
|
|
20
|
+
id,
|
|
21
|
+
reqId,
|
|
22
|
+
chunk,
|
|
23
|
+
reset: isReset,
|
|
24
|
+
done: isDone
|
|
25
|
+
}, [chunk.buffer]);
|
|
26
|
+
|
|
27
|
+
offset = end;
|
|
28
|
+
if (!isDone) setTimeout(pump, delay);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
pump();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
self.onmessage = (e) => {
|
|
35
|
+
const { type, payload } = e.data;
|
|
36
|
+
|
|
37
|
+
if (type === 'UPDATE_DATA') {
|
|
38
|
+
const { sourceKey, data } = payload;
|
|
39
|
+
masterData[sourceKey] = data;
|
|
40
|
+
|
|
41
|
+
if (data && data.length > 0) {
|
|
42
|
+
const keys = Object.keys(data[0]);
|
|
43
|
+
searchCache[sourceKey] = new Array(data.length);
|
|
44
|
+
for (let i = 0; i < data.length; i++) {
|
|
45
|
+
let rowStr = '';
|
|
46
|
+
const item = data[i];
|
|
47
|
+
for (let k = 0; k < keys.length; k++) rowStr += item[keys[k]] + ' ';
|
|
48
|
+
searchCache[sourceKey][i] = rowStr.toLowerCase();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (type === 'FILTER') {
|
|
54
|
+
const { id, sourceKey, query, reqId, limit } = payload;
|
|
55
|
+
const cache = searchCache[sourceKey];
|
|
56
|
+
if (!cache || !query) return;
|
|
57
|
+
|
|
58
|
+
const lowerQ = query.toLowerCase();
|
|
59
|
+
|
|
60
|
+
// ⚡ Primera pasada rápida: devolver primeros matches ASAP
|
|
61
|
+
const fast = [];
|
|
62
|
+
for (let i = 0; i < cache.length && fast.length < 200; i++) {
|
|
63
|
+
if (cache[i].includes(lowerQ)) fast.push(i);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (fast.length) {
|
|
67
|
+
sendInChunks(id, reqId, new Int32Array(fast));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 🐢 Segunda pasada completa
|
|
71
|
+
const result = new Int32Array(cache.length);
|
|
72
|
+
let count = 0;
|
|
73
|
+
|
|
74
|
+
for (let i = 0; i < cache.length; i++) {
|
|
75
|
+
if (cache[i].includes(lowerQ)) result[count++] = i;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
sendInChunks(id, reqId, result.subarray(0, count));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
`;
|
|
82
|
+
//# sourceMappingURL=search.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.worker.js","sourceRoot":"","sources":["../../../src/core/workers/search.worker.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgFjC,CAAC"}
|
package/dist/core.d.ts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
commands: Record<string, any>;
|
|
7
|
-
slots: Record<string, any>;
|
|
8
|
-
};
|
|
9
|
-
type GetStore<T extends PlcSchema> = T["store"] extends Record<string, any> ? T["store"] : {};
|
|
10
|
-
type GetCmds<T extends PlcSchema> = T["commands"] extends Record<string, any> ? T["commands"] : {};
|
|
11
|
-
type GetSlots<T extends PlcSchema> = T["slots"] extends Record<string, any> ? T["slots"] : {};
|
|
12
|
-
type TypedPlcAPI<T extends PlcSchema> = Omit<PlcAPI, 'getStore' | 'setStore' | 'createStore' | 'execute' | 'render' | 'register'> & {
|
|
13
|
-
createStore<K extends keyof GetStore<T> & string>(key: K, initial: GetStore<T>[K]): void;
|
|
14
|
-
getStore<K extends keyof GetStore<T> & string>(key: K): GetStore<T>[K];
|
|
15
|
-
setStore<K extends keyof GetStore<T> & string>(key: K, updater: GetStore<T>[K] | ((draft: Draft<GetStore<T>[K]>) => void | GetStore<T>[K]), priority?: number, useTransition?: boolean): void;
|
|
16
|
-
execute<K extends keyof GetCmds<T> & string>(id: K, payload?: GetCmds<T>[K] extends {
|
|
17
|
-
payload: infer P;
|
|
18
|
-
} ? P : void): Promise<GetCmds<T>[K] extends {
|
|
19
|
-
result: infer R;
|
|
20
|
-
} ? R : void>;
|
|
21
|
-
render<K extends keyof GetSlots<T> & string>(slot: K, props?: GetSlots<T>[K]): React.ReactNode;
|
|
22
|
-
register<K extends keyof GetSlots<T> & string>(slot: K, id: string, componentFn: (props?: GetSlots<T>[K]) => React.ReactNode, priority?: number, keepAlive?: boolean): void;
|
|
23
|
-
};
|
|
24
|
-
export declare const createPlugC: <T extends PlcSchema>() => {
|
|
2
|
+
import { GetCmds, GetSlots, GetStore, PlcSchema, TypedPlcAPI } from "./types/core";
|
|
3
|
+
export declare const createPlugC: <T extends PlcSchema>(config?: {
|
|
4
|
+
initialState: GetStore<T>;
|
|
5
|
+
}) => {
|
|
25
6
|
api: TypedPlcAPI<T>;
|
|
26
7
|
SystemPlcRoot: ({ children }: {
|
|
27
8
|
children: React.ReactNode;
|
|
@@ -37,4 +18,4 @@ export declare const createPlugC: <T extends PlcSchema>() => {
|
|
|
37
18
|
} ? R_1 : void>;
|
|
38
19
|
useSlot: <K extends keyof GetSlots<T> & string>(slot: K) => (props?: GetSlots<T>[K]) => React.ReactNode;
|
|
39
20
|
};
|
|
40
|
-
|
|
21
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKnF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,SAAS,EAC3C,SAAS;IACL,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CAC5B;;kCAaiC;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE;;;;eAKhD,CAAC,SAAS,MAAM,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,wBACzC,CAAC,aACK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAEK,CAAC;iBAGnC,CAAC,SAAS,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,MAAM,CAAC,KAMrC,CAAC,OAAO,CAAC;iBAH8B,MAAM,CAAC;gBAGvB,KAAK,OAAO;gBAFE,MAAM,GAAC;mBAEI;cAGxD,CAAC,SAAS,MAAM,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,QAAQ,CAAC,KAI9B,CAAC,KAAK,CAAC,gBAAY,KAAK,KAAK,CAAC,SAAS;CAGvE,CAAA"}
|
package/dist/core.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { PlcAPI } from "./core/plcAPI";
|
|
3
3
|
import { PlcProvider, useCommand, useSlot, useStore } from "./core/hooks/plcHooks";
|
|
4
|
-
|
|
4
|
+
// ----------------------
|
|
5
|
+
// Advanced Mode
|
|
6
|
+
// ----------------------
|
|
7
|
+
export const createPlugC = (config) => {
|
|
5
8
|
const rawApi = new PlcAPI();
|
|
6
9
|
const api = rawApi;
|
|
10
|
+
if (config?.initialState) {
|
|
11
|
+
Object.entries(config.initialState).forEach(([key, value]) => {
|
|
12
|
+
rawApi.createStore(key, value);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
7
15
|
return {
|
|
8
16
|
api,
|
|
9
17
|
SystemPlcRoot: ({ children }) => (_jsx(PlcProvider, { api: rawApi, children: children })),
|
|
@@ -21,3 +29,4 @@ export const createPlugC = () => {
|
|
|
21
29
|
}
|
|
22
30
|
};
|
|
23
31
|
};
|
|
32
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGnF,yBAAyB;AACzB,gBAAgB;AAChB,yBAAyB;AACzB,MAAM,CAAC,MAAM,WAAW,GAAG,CACvB,MAEC,EACH,EAAE;IACA,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;IAC5B,MAAM,GAAG,GAAG,MAAmC,CAAC;IAEhD,IAAI,MAAM,EAAE,YAAY,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YACzD,MAAM,CAAC,WAAW,CAAC,GAAU,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO;QACH,GAAG;QACH,aAAa,EAAE,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE,CAAC,CAC5D,KAAC,WAAW,IAAC,GAAG,EAAE,MAAM,YAAG,QAAQ,GAAe,CACrD;QAED,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;QACzB,QAAQ,EAAE,CACN,GAAM,EACN,QAAsC,EACxC,EAAE;YACA,OAAQ,QAAgB,CAAC,GAAG,EAAE,QAAQ,CAAM,CAAC;QACjD,CAAC;QAED,UAAU,EAAE,CAAsC,EAAK,EAAE,EAAE;YACvD,MAAM,GAAG,GAAG,UAAU,CAAC,EAAS,CAAC,CAAC;YAKlC,OAAO,GAAuD,CAAC;QACnE,CAAC;QAED,OAAO,EAAE,CAAuC,IAAO,EAAE,EAAE;YACvD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAW,CAAC,CAAC;YAGxC,OAAO,UAAqD,CAAC;QACjE,CAAC;KACJ,CAAC;AACN,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA"}
|
package/dist/simple.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { Draft } from "immer";
|
|
3
|
+
import { PlcAPI } from "./core/plcAPI";
|
|
4
|
+
import { ObjectType } from "./types/core/general";
|
|
5
|
+
type RemoveFirstArg<T extends any[]> = T extends [any, ...infer Rest] ? Rest : [];
|
|
6
|
+
type MapToExecutable<A> = {
|
|
7
|
+
[K in keyof A]: A[K] extends (...args: any) => any ? (...args: RemoveFirstArg<Parameters<A[K]>>) => Promise<void> : never;
|
|
8
|
+
};
|
|
9
|
+
type ModuleActionFn<T, RootExec> = (draft: Draft<T>, payload: any, root: RootExec) => void | T | Promise<void>;
|
|
10
|
+
export type ModuleConfig<T extends ObjectType, A extends Record<string, any>, RootExec, P> = {
|
|
11
|
+
name: string;
|
|
12
|
+
state: T;
|
|
13
|
+
actions?: A;
|
|
14
|
+
view?: (props: {
|
|
15
|
+
state: T;
|
|
16
|
+
actions: MapToExecutable<A>;
|
|
17
|
+
} & P) => React.ReactNode;
|
|
18
|
+
slots?: Record<string, React.FC<any>>;
|
|
19
|
+
};
|
|
20
|
+
export declare const createSimplePlugC: <T extends ObjectType, A extends Record<string, (draft: Draft<T>, ...args: any[]) => void | T | Promise<void>>>(config: {
|
|
21
|
+
initialState: T;
|
|
22
|
+
actions?: A;
|
|
23
|
+
options?: {
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
};
|
|
26
|
+
}) => {
|
|
27
|
+
api: PlcAPI;
|
|
28
|
+
Provider: ({ children }: {
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
useStore: <R>(selector?: (state: T) => R) => R;
|
|
32
|
+
useAction: <K extends keyof A & string>(actionName: K) => (...args: RemoveFirstArg<Parameters<A[K]>>) => Promise<void>;
|
|
33
|
+
createModule: <FT extends ObjectType, FA extends Record<string, ModuleActionFn<FT, MapToExecutable<A>>>, P = {}>(moduleConfig: ModuleConfig<FT, FA, MapToExecutable<A>, P>) => {
|
|
34
|
+
name: string;
|
|
35
|
+
View: React.FC<P>;
|
|
36
|
+
useModuleState: <R>(selector?: (state: FT) => R) => R;
|
|
37
|
+
useModuleAction: <K extends keyof FA & string>(actionName: K) => (...args: RemoveFirstArg<Parameters<FA[K]>>) => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
getState: () => T;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=simple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple.d.ts","sourceRoot":"","sources":["../src/simple.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAA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jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { PlcAPI } from "./core/plcAPI";
|
|
4
|
+
import { PlcProvider, useStore as useHookStore, useCommand } from "./core/hooks/plcHooks";
|
|
5
|
+
// ----------------------
|
|
6
|
+
// Simple Mode Factory
|
|
7
|
+
// ----------------------
|
|
8
|
+
export const createSimplePlugC = (config) => {
|
|
9
|
+
const api = new PlcAPI();
|
|
10
|
+
api.createStore("__simple_root", config.initialState);
|
|
11
|
+
if (config.options?.debug)
|
|
12
|
+
console.debug("[SimplePlugC] Initialized");
|
|
13
|
+
const rootActionsExecutable = {};
|
|
14
|
+
if (config.actions) {
|
|
15
|
+
Object.entries(config.actions).forEach(([actionName, actionFn]) => {
|
|
16
|
+
const commandId = `simple:${actionName}`;
|
|
17
|
+
api.registerCommand(commandId, async (payload) => {
|
|
18
|
+
if (config.options?.debug)
|
|
19
|
+
console.debug(`[RootAction] ${actionName}`, payload);
|
|
20
|
+
api.setStore("__simple_root", (draft) => actionFn(draft, payload));
|
|
21
|
+
});
|
|
22
|
+
rootActionsExecutable[actionName] = (payload) => api.execute(commandId, payload);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// ---------------------------------------------------------
|
|
26
|
+
// createModule (Bound Factory)
|
|
27
|
+
// ---------------------------------------------------------
|
|
28
|
+
const createModule = (moduleConfig) => {
|
|
29
|
+
api.createSubstore(moduleConfig.name, "__module_state", moduleConfig.state);
|
|
30
|
+
const boundModuleActions = {};
|
|
31
|
+
if (moduleConfig.actions) {
|
|
32
|
+
Object.entries(moduleConfig.actions).forEach(([actionName, actionFn]) => {
|
|
33
|
+
const commandId = `${moduleConfig.name}:${actionName}`;
|
|
34
|
+
api.registerCommand(commandId, async (payload) => {
|
|
35
|
+
if (config.options?.debug)
|
|
36
|
+
console.debug(`[Module: ${moduleConfig.name}] Action: ${actionName}`, payload);
|
|
37
|
+
api.setSubstore(moduleConfig.name, "__module_state", (draft) => {
|
|
38
|
+
return actionFn(draft, payload, rootActionsExecutable);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
boundModuleActions[actionName] = (payload) => api.execute(commandId, payload);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const useModuleState = (selector) => {
|
|
45
|
+
return useHookStore(`${moduleConfig.name}:__module_state`, selector ? ((s) => selector(s)) : undefined);
|
|
46
|
+
};
|
|
47
|
+
const useModuleAction = (actionName) => {
|
|
48
|
+
const commandId = `${moduleConfig.name}:${actionName}`;
|
|
49
|
+
return useCommand(commandId);
|
|
50
|
+
};
|
|
51
|
+
const ModuleView = React.memo((props) => {
|
|
52
|
+
const state = useModuleState((s) => s);
|
|
53
|
+
if (moduleConfig.view) {
|
|
54
|
+
return moduleConfig.view({
|
|
55
|
+
state,
|
|
56
|
+
actions: boundModuleActions,
|
|
57
|
+
...props
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
name: moduleConfig.name,
|
|
64
|
+
View: ModuleView,
|
|
65
|
+
useModuleState,
|
|
66
|
+
useModuleAction
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
// ---------------------------------------------------------
|
|
70
|
+
// Global Hooks
|
|
71
|
+
// ---------------------------------------------------------
|
|
72
|
+
const useStore = (selector) => {
|
|
73
|
+
return useHookStore("__simple_root", selector || ((s) => s));
|
|
74
|
+
};
|
|
75
|
+
const useAction = (actionName) => {
|
|
76
|
+
const commandId = `simple:${actionName}`;
|
|
77
|
+
return useCommand(commandId);
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
api,
|
|
81
|
+
Provider: ({ children }) => (_jsx(PlcProvider, { api: api, children: children })),
|
|
82
|
+
useStore,
|
|
83
|
+
useAction,
|
|
84
|
+
createModule,
|
|
85
|
+
getState: () => api.getStore("__simple_root"),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=simple.js.map
|