wenay-react2 1.0.39 → 1.0.41

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.
Files changed (54) hide show
  1. package/doc/EXAMPLE_USAGE.md +915 -0
  2. package/doc/PROJECT_FUNCTIONALITY.md +401 -0
  3. package/doc/PROJECT_RULES.md +80 -0
  4. package/doc/WENAY_REACT2_RENAMES.md +177 -0
  5. package/doc/changes/v1.0.35.md +26 -0
  6. package/doc/changes/v1.0.37.md +13 -0
  7. package/doc/changes/v1.0.38.md +48 -0
  8. package/doc/changes/v1.0.39.md +35 -0
  9. package/doc/changes/v1.0.40.md +15 -0
  10. package/doc/changes/v1.0.41.md +13 -0
  11. package/doc/progress/README.md +14 -0
  12. package/doc/progress/hook-controller-opportunities.md +367 -0
  13. package/doc/progress/hook-extraction-audit.md +195 -0
  14. package/doc/progress/public-surface-normalization.md +368 -0
  15. package/doc/progress/style-system-normalization.md +121 -0
  16. package/doc/target/README.md +33 -0
  17. package/doc/target/my.md +109 -0
  18. package/doc/wenay-react2-1.0.8.tgz +0 -0
  19. package/doc/wenay-react2-rare.md +702 -0
  20. package/doc/wenay-react2.md +475 -0
  21. package/lib/common/src/components/Dnd/FloatingWindow.d.ts +29 -12
  22. package/lib/common/src/components/Dnd/FloatingWindow.js +100 -91
  23. package/lib/common/src/components/Menu/RightMenu.d.ts +28 -1
  24. package/lib/common/src/components/Menu/RightMenu.js +62 -35
  25. package/lib/common/src/components/Modal/LeftModal.js +5 -4
  26. package/lib/common/src/components/Modal/Modal.js +8 -7
  27. package/lib/common/src/components/ParamsEditor.d.ts +15 -0
  28. package/lib/common/src/components/ParamsEditor.js +45 -18
  29. package/lib/common/src/components/Settings/SettingsDialog.d.ts +68 -6
  30. package/lib/common/src/components/Settings/SettingsDialog.js +61 -12
  31. package/lib/common/src/components/Toolbar/Toolbar.js +64 -19
  32. package/lib/common/src/components/UiSlot/UiSlot.js +5 -4
  33. package/lib/common/src/grid/columnState/columnState.js +8 -6
  34. package/lib/common/src/hooks/useKeyboard.js +4 -3
  35. package/lib/common/src/logs/logs.d.ts +40 -133
  36. package/lib/common/src/logs/logs.js +96 -66
  37. package/lib/common/src/logs/logsContext.d.ts +26 -0
  38. package/lib/common/src/logs/logsContext.js +25 -20
  39. package/lib/common/src/logs/logsController.d.ts +88 -0
  40. package/lib/common/src/logs/logsController.js +54 -0
  41. package/lib/common/src/logs/miniLogs.d.ts +69 -3
  42. package/lib/common/src/logs/miniLogs.js +70 -15
  43. package/lib/common/src/menu/menu.d.ts +15 -3
  44. package/lib/common/src/menu/menu.js +81 -17
  45. package/lib/common/src/menu/menuMouse.d.ts +18 -0
  46. package/lib/common/src/menu/menuMouse.js +43 -1
  47. package/lib/common/src/styles/tokens.d.ts +7 -6
  48. package/lib/common/src/styles/tokens.js +8 -5
  49. package/lib/common/src/utils/memoryStore.d.ts +1 -10
  50. package/lib/common/src/utils/searchHistory.js +4 -3
  51. package/lib/style/menuRight.css +29 -23
  52. package/lib/style/style.css +15 -9
  53. package/lib/style/tokens.css +8 -4
  54. package/package.json +50 -49
@@ -1,92 +1,13 @@
1
- import { Params } from "wenay-common2";
2
- type LogInput<T extends object> = T & {
3
- id: string;
4
- var?: number;
5
- time: Date;
6
- txt: string;
7
- };
8
- declare const getSettingLogs: () => {
9
- minVarLogs: {
10
- name: string;
11
- range: {
12
- min: number;
13
- max: number;
14
- step: number;
15
- };
16
- value: number;
17
- };
18
- minVarMessage: {
19
- name: string;
20
- range: {
21
- min: number;
22
- max: number;
23
- step: number;
24
- };
25
- value: number;
26
- };
27
- timeShow: {
28
- name: string;
29
- range: {
30
- min: number;
31
- max: number;
32
- step: number;
33
- };
34
- value: number;
35
- };
36
- show: {
37
- name: string;
38
- value: boolean;
39
- };
40
- };
41
- export declare function getLogsApi<T extends object = {}>(setting: {
42
- limit?: number;
43
- limitPer: number;
44
- varMin?: number;
45
- }): {
46
- addLogs(a: LogInput<T>): void;
1
+ import React from "react";
2
+ import { getSettingLogs, type LogEntry, type LogsApiOptions } from "./logsController";
3
+ export { createLogsController, createLogsControllerState, getSettingLogs, } from "./logsController";
4
+ export type { CreateLogsControllerOptions, LogsApiOptions, LogsController, LogsControllerState, LogsFullState, LogsMiniState, } from "./logsController";
5
+ export declare function getLogsApi<T extends object = {}>(setting: LogsApiOptions): {
6
+ addLogs: (input: import("./logsController").LogInput<T>) => LogEntry<T>;
47
7
  params: {
48
- def: () => {
49
- minVarLogs: {
50
- name: string;
51
- range: {
52
- min: number;
53
- max: number;
54
- step: number;
55
- };
56
- value: number;
57
- };
58
- minVarMessage: {
59
- name: string;
60
- range: {
61
- min: number;
62
- max: number;
63
- step: number;
64
- };
65
- value: number;
66
- };
67
- timeShow: {
68
- name: string;
69
- range: {
70
- min: number;
71
- max: number;
72
- step: number;
73
- };
74
- value: number;
75
- };
76
- show: {
77
- name: string;
78
- value: boolean;
79
- };
80
- };
81
- get(): {
82
- minVarLogs: number;
83
- minVarMessage: number;
84
- timeShow: number;
85
- show: boolean;
86
- } & {
87
- readonly [key: number]: void;
88
- };
89
- set(a: Params.SimpleParams<ReturnType<typeof getSettingLogs>>): void;
8
+ def: typeof getSettingLogs;
9
+ get(): import("./logsController").LogsSettings;
10
+ set(settings: import("./logsController").LogsSettings): void;
90
11
  };
91
12
  React: {
92
13
  Setting: typeof InputSettingLogs;
@@ -95,55 +16,16 @@ export declare function getLogsApi<T extends object = {}>(setting: {
95
16
  };
96
17
  };
97
18
  export declare const logsApi: {
98
- addLogs(a: {
19
+ addLogs: (input: {
99
20
  id: string;
100
21
  var?: number;
101
22
  time: Date;
102
23
  txt: string;
103
- }): void;
24
+ }) => LogEntry<{}>;
104
25
  params: {
105
- def: () => {
106
- minVarLogs: {
107
- name: string;
108
- range: {
109
- min: number;
110
- max: number;
111
- step: number;
112
- };
113
- value: number;
114
- };
115
- minVarMessage: {
116
- name: string;
117
- range: {
118
- min: number;
119
- max: number;
120
- step: number;
121
- };
122
- value: number;
123
- };
124
- timeShow: {
125
- name: string;
126
- range: {
127
- min: number;
128
- max: number;
129
- step: number;
130
- };
131
- value: number;
132
- };
133
- show: {
134
- name: string;
135
- value: boolean;
136
- };
137
- };
138
- get(): {
139
- minVarLogs: number;
140
- minVarMessage: number;
141
- timeShow: number;
142
- show: boolean;
143
- } & {
144
- readonly [key: number]: void;
145
- };
146
- set(a: Params.SimpleParams<ReturnType<typeof getSettingLogs>>): void;
26
+ def: typeof getSettingLogs;
27
+ get(): import("./logsController").LogsSettings;
28
+ set(settings: import("./logsController").LogsSettings): void;
147
29
  };
148
30
  React: {
149
31
  Setting: typeof InputSettingLogs;
@@ -157,10 +39,35 @@ declare function InputSettingLogs({}: {
157
39
  export declare function PageLogs({ update }: {
158
40
  update?: number;
159
41
  }): import("react/jsx-runtime").JSX.Element;
42
+ export type MessageEventLogsItem = {
43
+ key: string;
44
+ logs: LogEntry;
45
+ };
46
+ export type UseMessageEventLogsControllerOptions = {
47
+ maxVisible?: number;
48
+ };
49
+ export type MessageEventLogsController = {
50
+ show: boolean;
51
+ setShow(value: boolean): void;
52
+ toggleShow(): void;
53
+ notifications: MessageEventLogsItem[];
54
+ visibleNotifications: MessageEventLogsItem[];
55
+ maxVisible: number;
56
+ };
57
+ export type MessageEventLogsViewProps = {
58
+ controller: MessageEventLogsController;
59
+ zIndex?: number;
60
+ className?: string;
61
+ style?: React.CSSProperties;
62
+ };
63
+ export declare function MessageEventLogCard({ logs }: {
64
+ logs: LogEntry;
65
+ }): import("react/jsx-runtime").JSX.Element;
66
+ export declare function useMessageEventLogsController(options?: UseMessageEventLogsControllerOptions): MessageEventLogsController;
67
+ export declare function MessageEventLogsView({ controller, zIndex, className, style }: MessageEventLogsViewProps): import("react/jsx-runtime").JSX.Element;
160
68
  export declare function MessageEventLogs({ zIndex }: {
161
69
  zIndex?: number;
162
70
  }): import("react/jsx-runtime").JSX.Element;
163
71
  export declare function LogsPage({ update }: {
164
72
  update?: number;
165
73
  }): import("react/jsx-runtime").JSX.Element;
166
- export {};
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { AgGridReact } from "ag-grid-react";
3
- import { useCallback, useEffect, useRef } from "react";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
3
  import { copyToClipboard, Params, timeLocalToStr_hhmmss } from "wenay-common2";
5
4
  import { renderBy, updateBy } from "../../updateBy";
6
5
  import { contextMenu } from "../menu/menuMouse";
7
6
  import { memoryGetOrCreate } from "../utils/memoryStore";
8
7
  import { ParamsEditor } from "../components/ParamsEditor";
9
8
  import { logDividerGradient, logSeverityBackground, logStyleTokens } from "./logStyles";
9
+ import { AgGridTable, colDefCentered } from "../grid/agGrid4";
10
+ import { createLogsController, createLogsControllerState, getSettingLogs, } from "./logsController";
11
+ export { createLogsController, createLogsControllerState, getSettingLogs, } from "./logsController";
10
12
  const cashLogs = new Map();
11
13
  const datumConst = {
12
14
  map: cashLogs,
@@ -14,39 +16,25 @@ const datumConst = {
14
16
  const datumMiniConst = {
15
17
  last: []
16
18
  };
17
- const getSettingLogs = () => ({
18
- minVarLogs: { name: "min. importance for notifications", range: { min: 0, max: 25, step: 1 }, value: 0 },
19
- minVarMessage: { name: "min. importance for log table", range: { min: 0, max: 25, step: 1 }, value: 0 },
20
- timeShow: { name: "screen display time", range: { min: 1, max: 20, step: 1 }, value: 2 },
21
- show: { name: "show", value: true }
22
- });
23
19
  const settingLogs = { params: Params.GetSimpleParams(getSettingLogs()) };
20
+ const logGridDefaultColDef = { ...colDefCentered, wrapText: true };
24
21
  // varMin - minimum importance
25
22
  export function getLogsApi(setting) {
26
23
  const datum = memoryGetOrCreate("settingLogs", settingLogs);
27
- function addToArr(arr, data, limit) {
28
- arr.unshift(data);
29
- if (arr.length > limit)
30
- arr.length = limit;
31
- }
32
- let num = 0;
24
+ const controller = createLogsController({
25
+ options: setting,
26
+ state: createLogsControllerState({
27
+ full: datumConst,
28
+ mini: datumMiniConst,
29
+ settings: datum,
30
+ }),
31
+ onFullChange: () => renderBy(datumConst),
32
+ onMiniChange: () => renderBy(datumMiniConst),
33
+ onSettingsChange: () => renderBy(datum),
34
+ });
33
35
  return {
34
- addLogs(a) {
35
- const item = { ...a, num: num++ };
36
- addToArr(datumMiniConst.last, item, setting.limit ?? 50);
37
- addToArr(datumConst.map.get(a.id) ?? datumConst.map.set(a.id, []).get(a.id), item, setting.limitPer);
38
- renderBy(datumConst);
39
- renderBy(datumMiniConst);
40
- },
41
- params: {
42
- def: getSettingLogs,
43
- get() { return datum.params; },
44
- set(a) {
45
- datum.params = a;
46
- renderBy(datumMiniConst);
47
- renderBy(datumConst);
48
- },
49
- },
36
+ addLogs: controller.addLogs,
37
+ params: controller.params,
50
38
  React: {
51
39
  Setting: InputSettingLogs,
52
40
  Message: MessageEventLogs,
@@ -136,7 +124,7 @@ export function PageLogs({ update }) {
136
124
  width: 150,
137
125
  },
138
126
  ];
139
- return _jsx("div", { className: "maxSize", children: _jsx(AgGridReact
127
+ return _jsx("div", { className: "maxSize", children: _jsx(AgGridTable
140
128
  // className = "ag-theme-alpine-dark ag-theme-alpine2" // ag-theme-alpine-dark3
141
129
  , {
142
130
  // className = "ag-theme-alpine-dark ag-theme-alpine2" // ag-theme-alpine-dark3
@@ -153,18 +141,11 @@ export function PageLogs({ update }) {
153
141
  });
154
142
  }
155
143
  }, onSortChanged: (e) => {
156
- }, defaultColDef: {
157
- headerClass: () => ("gridTable-header"),
158
- resizable: true,
159
- cellStyle: { textAlign: "center" },
160
- sortable: true,
161
- filter: true,
162
- wrapText: true,
163
- }, headerHeight: 30, rowHeight: 26, autoSizePadding: 1, rowData: rowData, columnDefs: columns, onCellMouseDown: (e) => {
144
+ }, defaultColDef: logGridDefaultColDef, headerHeight: 30, rowHeight: 26, autoSizePadding: 1, rowData: rowData, columnDefs: columns, onCellMouseDown: (e) => {
164
145
  if (e.event instanceof MouseEvent && e.event.button == 2) {
165
146
  contextMenu.openAt(e.event, [
166
147
  {
167
- name: "copy", onClick: () => { copyToClipboard(e.value); }
148
+ name: "copy", actionKey: "logs.copyCell", onClick: () => { copyToClipboard(e.value); }
168
149
  }
169
150
  ]);
170
151
  }
@@ -172,7 +153,7 @@ export function PageLogs({ update }) {
172
153
  }, [true]);
173
154
  return _jsx(Main, {});
174
155
  }
175
- function Message({ logs }) {
156
+ export function MessageEventLogCard({ logs }) {
176
157
  return _jsxs("div", { className: "testAnime", style: { width: "200px", color: logStyleTokens.text, height: "auto", marginTop: "10px", borderRight: `5px solid ${logStyleTokens.accent}`, background: logSeverityBackground(logs.var) }, children: [_jsx("p", { style: { textAlign: "center", fontSize: "10px", marginBottom: "1px" }, children: "notification" }), _jsx("hr", { style: {
177
158
  backgroundImage: logDividerGradient(),
178
159
  border: 0,
@@ -180,35 +161,84 @@ function Message({ logs }) {
180
161
  margin: "0 0 0 0",
181
162
  boxSizing: "content-box",
182
163
  display: "block"
183
- } }), _jsx("div", { style: { textAlign: "right", marginRight: "10px", height: "auto", overflowWrap: "break-word", textOverflow: "ellipsis" }, children: typeof logs.txt == "object" ? JSON.stringify(logs.txt) : logs.txt }), _jsx("p", { style: { float: "inline-end", textAlign: "right", marginRight: "10px" }, children: (new Date()).toLocaleDateString() })] });
164
+ } }), _jsx("div", { style: { textAlign: "right", marginRight: "10px", height: "auto", overflowWrap: "break-word", textOverflow: "ellipsis" }, children: typeof logs.txt == "object" ? JSON.stringify(logs.txt) : logs.txt }), _jsx("p", { style: { float: "inline-end", textAlign: "right", marginRight: "10px" }, children: (new Date(logs.time)).toLocaleDateString() })] });
184
165
  }
185
- const tt = {};
186
- let r = 0;
187
- export function MessageEventLogs({ zIndex }) {
166
+ export function useMessageEventLogsController(options = {}) {
188
167
  const setting = memoryGetOrCreate("settingLogs", settingLogs);
189
- updateBy(tt);
190
- updateBy(datumMiniConst, () => {
191
- const last = datumMiniConst.last[0];
192
- if (!last)
168
+ const maxVisible = Math.max(1, options.maxVisible ?? 10);
169
+ const [notifications, setNotifications] = useState([]);
170
+ const counterRef = useRef(0);
171
+ const lastLogRef = useRef(null);
172
+ const timersRef = useRef(new Map());
173
+ updateBy(setting);
174
+ const addNotification = useCallback((last) => {
175
+ if ((last.var ?? 0) < (setting.params.minVarMessage ?? 0))
193
176
  return;
194
- if (setting.params.minVarMessage && (!last.var || last.var < setting.params.minVarMessage))
177
+ const key = String(counterRef.current++);
178
+ const item = { key, logs: last };
179
+ const displayMs = (setting.params.timeShow ? setting.params.timeShow : 2) * 1000;
180
+ setNotifications(prev => [item, ...prev]);
181
+ const timer = setTimeout(() => {
182
+ timersRef.current.delete(key);
183
+ setNotifications(prev => prev.filter(e => e.key !== key));
184
+ }, displayMs);
185
+ timersRef.current.set(key, timer);
186
+ }, [setting]);
187
+ const onMiniChange = useCallback(() => {
188
+ const last = datumMiniConst.last[0];
189
+ if (!last || last === lastLogRef.current)
195
190
  return;
196
- let key = String(r++);
197
- tt[key] = _jsx("div", { className: "example-exit", children: _jsx(Message, { logs: last }) }, key);
198
- setTimeout(() => {
199
- if (tt[key]) {
200
- delete tt[key];
201
- renderBy(tt, 100);
202
- }
203
- }, setting.params.timeShow ? setting.params.timeShow * 1000 : 2000);
204
- renderBy(tt);
205
- });
206
- const tr = [...Object.values(tt)].reverse().slice(0, 10);
207
- return _jsxs("div", { style: { maxHeight: "50vh", position: "absolute", right: "1px", zIndex }, children: [_jsx("div", { onClick: () => { setting.params.show = !setting.params.show; renderBy(tt); }, style: { margin: 3, padding: 3, right: 0, position: "absolute", zIndex: 120,
208
- ...setting.params.show ?
209
- { background: logStyleTokens.toggleBg, fontSize: "25px" } :
210
- { background: logStyleTokens.toggleOffBg }
211
- }, children: setting.params.show ? "X" : "log" }), _jsx("div", { children: setting.params.show ? tr : null })] });
191
+ lastLogRef.current = last;
192
+ addNotification(last);
193
+ }, [addNotification]);
194
+ updateBy(datumMiniConst, onMiniChange);
195
+ useEffect(() => () => {
196
+ timersRef.current.forEach(clearTimeout);
197
+ timersRef.current.clear();
198
+ }, []);
199
+ const setShow = useCallback((value) => {
200
+ setting.params.show = value;
201
+ renderBy(setting);
202
+ }, [setting]);
203
+ const toggleShow = useCallback(() => {
204
+ setShow(!setting.params.show);
205
+ }, [setShow, setting]);
206
+ return useMemo(() => ({
207
+ show: Boolean(setting.params.show),
208
+ setShow,
209
+ toggleShow,
210
+ notifications,
211
+ visibleNotifications: notifications.slice(0, maxVisible),
212
+ maxVisible,
213
+ }), [maxVisible, notifications, setShow, setting.params.show, toggleShow]);
214
+ }
215
+ export function MessageEventLogsView({ controller, zIndex, className, style }) {
216
+ const toggleTitle = controller.show ? "Hide log notifications" : "Show log notifications";
217
+ const toggleStyle = {
218
+ position: "absolute",
219
+ right: 0,
220
+ top: 0,
221
+ zIndex: 120,
222
+ minWidth: controller.show ? 24 : 42,
223
+ height: 24,
224
+ padding: controller.show ? 0 : "0 8px",
225
+ border: `1px solid ${logStyleTokens.accent}`,
226
+ borderRadius: 999,
227
+ background: controller.show ? logStyleTokens.toggleBg : logStyleTokens.toggleOffBg,
228
+ color: logStyleTokens.text,
229
+ cursor: "pointer",
230
+ display: "inline-flex",
231
+ alignItems: "center",
232
+ justifyContent: "center",
233
+ fontSize: controller.show ? 18 : 12,
234
+ lineHeight: 1,
235
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.35)",
236
+ };
237
+ return _jsxs("div", { className: className, style: { maxHeight: "50vh", position: "absolute", right: "1px", zIndex, ...style }, children: [_jsx("button", { type: "button", "aria-label": toggleTitle, title: toggleTitle, onClick: controller.toggleShow, style: toggleStyle, children: controller.show ? "\u00d7" : "log" }), _jsx("div", { children: controller.show ? controller.visibleNotifications.map(e => (_jsx("div", { className: "example-exit", children: _jsx(MessageEventLogCard, { logs: e.logs }) }, e.key))) : null })] });
238
+ }
239
+ export function MessageEventLogs({ zIndex }) {
240
+ const controller = useMessageEventLogsController();
241
+ return _jsx(MessageEventLogsView, { controller: controller, zIndex: zIndex });
212
242
  }
213
243
  const defPageBase = {
214
244
  keyPage: "PageLogs"
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { ColDef, GridReadyEvent } from 'ag-grid-community';
2
3
  /** -----------------------------
3
4
  * 1. Log types
4
5
  * -----------------------------
@@ -42,7 +43,32 @@ export declare function useLogsContext(): LogsContextValue;
42
43
  * (PageLogs equivalent)
43
44
  * -----------------------------
44
45
  */
46
+ export type LogsTableController = {
47
+ logs: LogEntry[];
48
+ minVarLogs: number;
49
+ gridRef: React.MutableRefObject<GridReadyEvent | null>;
50
+ columnDefs: ColDef[];
51
+ defaultColDef: ColDef;
52
+ onGridReady(params: GridReadyEvent): void;
53
+ };
54
+ export declare function useLogsTableController(): LogsTableController;
45
55
  export declare function LogsTable(): import("react/jsx-runtime").JSX.Element;
56
+ /** -----------------------------
57
+ * 7. LogsNotifications component
58
+ * (MessageEventLogs equivalent)
59
+ * -----------------------------
60
+ */
61
+ export interface NotificationItem {
62
+ id: number;
63
+ log: LogEntry;
64
+ }
65
+ export type LogsNotificationsController = {
66
+ showMessages: boolean;
67
+ setShowMessages(value: boolean): void;
68
+ notifications: NotificationItem[];
69
+ visibleNotifications: NotificationItem[];
70
+ };
71
+ export declare function useLogsNotificationsController(): LogsNotificationsController;
46
72
  export declare function LogsNotifications(): import("react/jsx-runtime").JSX.Element;
47
73
  /** -----------------------------
48
74
  * 8. LogsSettings component
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
- import { AgGridReact } from 'ag-grid-react';
3
+ import { AgGridTable, colDefCentered } from '../grid/agGrid4';
4
4
  import { logDividerGradient, logSeverityBackground, logStyleTokens } from './logStyles';
5
5
  /** -----------------------------
6
6
  * 2. memoryGetOrCreate function -
@@ -93,15 +93,9 @@ export function useLogsContext() {
93
93
  }
94
94
  return ctx;
95
95
  }
96
- /** -----------------------------
97
- * 6. LogsTable component
98
- * (PageLogs equivalent)
99
- * -----------------------------
100
- */
101
- export function LogsTable() {
96
+ export function useLogsTableController() {
102
97
  const { logs, minVarLogs } = useLogsContext();
103
98
  const gridRef = useRef(null);
104
- // Column definitions
105
99
  const columnDefs = useMemo(() => [
106
100
  {
107
101
  field: 'time',
@@ -126,12 +120,9 @@ export function LogsTable() {
126
120
  }
127
121
  ], []);
128
122
  const defaultColDef = useMemo(() => ({
129
- resizable: true,
130
- sortable: true,
131
- filter: true,
123
+ ...colDefCentered,
132
124
  wrapText: true,
133
125
  }), []);
134
- // Watch minVarLogs and configure the AG Grid filter
135
126
  useEffect(() => {
136
127
  if (gridRef.current?.api) {
137
128
  if (minVarLogs > 0) {
@@ -148,14 +139,19 @@ export function LogsTable() {
148
139
  }
149
140
  }
150
141
  }, [minVarLogs]);
142
+ const onGridReady = useCallback((params) => {
143
+ gridRef.current = params;
144
+ params.api.sizeColumnsToFit();
145
+ }, []);
146
+ return { logs, minVarLogs, gridRef, columnDefs, defaultColDef, onGridReady };
147
+ }
148
+ export function LogsTable() {
149
+ const table = useLogsTableController();
151
150
  return (
152
151
  // <div className="ag-theme-alpine-dark" style={{ width: '100%', height: '100%' }}>
153
- _jsx("div", { style: { width: '100%', height: '100%' }, children: _jsx(AgGridReact, { ref: gridRef, onGridReady: (params) => {
154
- gridRef.current = params;
155
- params.api.sizeColumnsToFit();
156
- }, rowData: logs, columnDefs: columnDefs, defaultColDef: defaultColDef, headerHeight: 30, rowHeight: 26 }) }));
152
+ _jsx("div", { style: { width: '100%', height: '100%' }, children: _jsx(AgGridTable, { onGridReady: table.onGridReady, rowData: table.logs, columnDefs: table.columnDefs, defaultColDef: table.defaultColDef, headerHeight: 30, rowHeight: 26 }) }));
157
153
  }
158
- export function LogsNotifications() {
154
+ export function useLogsNotificationsController() {
159
155
  const { logs, minVarMessage, timeShow, showMessages, setShowMessages } = useLogsContext();
160
156
  const [notifications, setNotifications] = useState([]);
161
157
  const counterRef = useRef(0);
@@ -183,13 +179,22 @@ export function LogsNotifications() {
183
179
  timersRef.current.add(timer);
184
180
  }, [logs, minVarMessage, timeShow]);
185
181
  useEffect(() => () => { timersRef.current.forEach(clearTimeout); }, []);
186
- if (!showMessages) {
182
+ return {
183
+ showMessages,
184
+ setShowMessages,
185
+ notifications,
186
+ visibleNotifications: notifications.slice(0, 10),
187
+ };
188
+ }
189
+ export function LogsNotifications() {
190
+ const controller = useLogsNotificationsController();
191
+ if (!controller.showMessages) {
187
192
  // If popups are hidden, show only "log"
188
193
  return (_jsx("div", { style: { position: 'absolute', right: 10, top: 10, zIndex: 999 }, children: _jsx("div", { style: {
189
194
  background: logStyleTokens.toggleOffBg,
190
195
  padding: '6px 10px',
191
196
  cursor: 'pointer'
192
- }, onClick: () => setShowMessages(true), children: "log" }) }));
197
+ }, onClick: () => controller.setShowMessages(true), children: "log" }) }));
193
198
  }
194
199
  // Otherwise render the current notification list
195
200
  return (_jsxs("div", { style: { position: 'absolute', right: 10, top: 10, zIndex: 999 }, children: [_jsx("div", { style: {
@@ -197,7 +202,7 @@ export function LogsNotifications() {
197
202
  fontSize: '20px',
198
203
  padding: '6px 10px',
199
204
  cursor: 'pointer'
200
- }, onClick: () => setShowMessages(false), children: "X" }), _jsx("div", { children: notifications.slice(0, 10).map(({ id, log }) => (_jsxs("div", { className: "testAnime example-exit", style: {
205
+ }, onClick: () => controller.setShowMessages(false), children: "X" }), _jsx("div", { children: controller.visibleNotifications.map(({ id, log }) => (_jsxs("div", { className: "testAnime example-exit", style: {
201
206
  width: 200,
202
207
  color: logStyleTokens.text,
203
208
  marginTop: 10,
@@ -0,0 +1,88 @@
1
+ import { Params } from "wenay-common2";
2
+ export type LogInput<T extends object = {}> = T & {
3
+ id: string;
4
+ var?: number;
5
+ time: Date;
6
+ txt: string;
7
+ };
8
+ export type LogEntry<T extends object = {}> = LogInput<T> & {
9
+ num: number;
10
+ };
11
+ export type LogsApiOptions = {
12
+ limit?: number;
13
+ limitPer: number;
14
+ varMin?: number;
15
+ };
16
+ export declare const getSettingLogs: () => {
17
+ minVarLogs: {
18
+ name: string;
19
+ range: {
20
+ min: number;
21
+ max: number;
22
+ step: number;
23
+ };
24
+ value: number;
25
+ };
26
+ minVarMessage: {
27
+ name: string;
28
+ range: {
29
+ min: number;
30
+ max: number;
31
+ step: number;
32
+ };
33
+ value: number;
34
+ };
35
+ timeShow: {
36
+ name: string;
37
+ range: {
38
+ min: number;
39
+ max: number;
40
+ step: number;
41
+ };
42
+ value: number;
43
+ };
44
+ show: {
45
+ name: string;
46
+ value: boolean;
47
+ };
48
+ };
49
+ export type LogsSettingsDefinition = ReturnType<typeof getSettingLogs>;
50
+ export type LogsSettings = Params.SimpleParams<LogsSettingsDefinition>;
51
+ export type LogsFullState<T extends object = {}> = {
52
+ map: Map<string, LogEntry<T>[]>;
53
+ };
54
+ export type LogsMiniState<T extends object = {}> = {
55
+ last: LogEntry<T>[];
56
+ };
57
+ export type LogsSettingsState = {
58
+ params: LogsSettings;
59
+ };
60
+ export type LogsControllerState<T extends object = {}> = {
61
+ full: LogsFullState<T>;
62
+ mini: LogsMiniState<T>;
63
+ settings: LogsSettingsState;
64
+ };
65
+ export type LogsControllerEvents = {
66
+ onFullChange?: () => void;
67
+ onMiniChange?: () => void;
68
+ onSettingsChange?: () => void;
69
+ };
70
+ export type CreateLogsControllerOptions<T extends object = {}> = LogsControllerEvents & {
71
+ options: LogsApiOptions;
72
+ state?: LogsControllerState<T>;
73
+ };
74
+ export type LogsController<T extends object = {}> = {
75
+ state: LogsControllerState<T>;
76
+ options: LogsApiOptions;
77
+ addLogs(input: LogInput<T>): LogEntry<T>;
78
+ getRows(): LogEntry<T>[];
79
+ getMiniRows(): LogEntry<T>[];
80
+ getLatest(): LogEntry<T> | undefined;
81
+ params: {
82
+ def: typeof getSettingLogs;
83
+ get(): LogsSettings;
84
+ set(settings: LogsSettings): void;
85
+ };
86
+ };
87
+ export declare function createLogsControllerState<T extends object = {}>(state?: Partial<LogsControllerState<T>>): LogsControllerState<T>;
88
+ export declare function createLogsController<T extends object = {}>({ options, state, onFullChange, onMiniChange, onSettingsChange, }: CreateLogsControllerOptions<T>): LogsController<T>;