wenay-react2 1.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/lib/common/api.d.ts +17 -0
- package/lib/common/api.js +24 -0
- package/lib/common/src/components/Buttons/MiniButton.d.ts +17 -0
- package/lib/common/src/components/Buttons/MiniButton.js +18 -0
- package/lib/common/src/components/Buttons/index.d.ts +1 -0
- package/lib/common/src/components/Buttons/index.js +1 -0
- package/lib/common/src/components/Dnd/DraggableOutlineDiv.d.ts +1 -0
- package/lib/common/src/components/Dnd/DraggableOutlineDiv.js +31 -0
- package/lib/common/src/components/Dnd/RNDFunc.d.ts +13 -0
- package/lib/common/src/components/Dnd/RNDFunc.js +111 -0
- package/lib/common/src/components/Dnd/RNDFunc3.d.ts +81 -0
- package/lib/common/src/components/Dnd/RNDFunc3.js +380 -0
- package/lib/common/src/components/Dnd/Resizable.d.ts +15 -0
- package/lib/common/src/components/Dnd/Resizable.js +36 -0
- package/lib/common/src/components/Dnd/index.d.ts +4 -0
- package/lib/common/src/components/Dnd/index.js +4 -0
- package/lib/common/src/components/Input.d.ts +28 -0
- package/lib/common/src/components/Input.js +30 -0
- package/lib/common/src/components/Menu/RightMenu.d.ts +22 -0
- package/lib/common/src/components/Menu/RightMenu.js +179 -0
- package/lib/common/src/components/Menu/StickerMenu.d.ts +5 -0
- package/lib/common/src/components/Menu/StickerMenu.js +110 -0
- package/lib/common/src/components/Menu/index.d.ts +2 -0
- package/lib/common/src/components/Menu/index.js +2 -0
- package/lib/common/src/components/Modal/LeftModal.d.ts +58 -0
- package/lib/common/src/components/Modal/LeftModal.js +284 -0
- package/lib/common/src/components/Modal/Modal.d.ts +31 -0
- package/lib/common/src/components/Modal/Modal.js +104 -0
- package/lib/common/src/components/Modal/index.d.ts +2 -0
- package/lib/common/src/components/Modal/index.js +2 -0
- package/lib/common/src/components/MyResizeObserver.d.ts +10 -0
- package/lib/common/src/components/MyResizeObserver.js +94 -0
- package/lib/common/src/components/Other.d.ts +9 -0
- package/lib/common/src/components/Other.js +31 -0
- package/lib/common/src/components/Parameters.d.ts +10 -0
- package/lib/common/src/components/Parameters.js +24 -0
- package/lib/common/src/components/ParametersEngine.d.ts +8 -0
- package/lib/common/src/components/ParametersEngine.js +373 -0
- package/lib/common/src/components/index.d.ts +9 -0
- package/lib/common/src/components/index.js +9 -0
- package/lib/common/src/hooks/index.d.ts +3 -0
- package/lib/common/src/hooks/index.js +3 -0
- package/lib/common/src/hooks/useAddDownAnyKey.d.ts +5 -0
- package/lib/common/src/hooks/useAddDownAnyKey.js +22 -0
- package/lib/common/src/hooks/useDraggable.d.ts +15 -0
- package/lib/common/src/hooks/useDraggable.js +134 -0
- package/lib/common/src/hooks/useOutside.d.ts +40 -0
- package/lib/common/src/hooks/useOutside.js +68 -0
- package/lib/common/src/logs/logs.d.ts +163 -0
- package/lib/common/src/logs/logs.js +249 -0
- package/lib/common/src/logs/logs3.d.ts +63 -0
- package/lib/common/src/logs/logs3.js +245 -0
- package/lib/common/src/logs/miniLogs.d.ts +5 -0
- package/lib/common/src/logs/miniLogs.js +51 -0
- package/lib/common/src/menu/menu.d.ts +72 -0
- package/lib/common/src/menu/menu.js +230 -0
- package/lib/common/src/menu/menuMouse.d.ts +21 -0
- package/lib/common/src/menu/menuMouse.js +32 -0
- package/lib/common/src/menu/menuR.d.ts +17 -0
- package/lib/common/src/menu/menuR.js +116 -0
- package/lib/common/src/myChart/1/myChart.d.ts +40 -0
- package/lib/common/src/myChart/1/myChart.js +306 -0
- package/lib/common/src/myChart/1/myChartTest.d.ts +1 -0
- package/lib/common/src/myChart/1/myChartTest.js +45 -0
- package/lib/common/src/myChart/chartEngine/chartEngineReact.d.ts +164 -0
- package/lib/common/src/myChart/chartEngine/chartEngineReact.js +834 -0
- package/lib/common/src/styles/index.d.ts +1 -0
- package/lib/common/src/styles/index.js +1 -0
- package/lib/common/src/styles/styleGrid.d.ts +20 -0
- package/lib/common/src/styles/styleGrid.js +50 -0
- package/lib/common/src/utils/applyTransactionAsyncUpdate.d.ts +42 -0
- package/lib/common/src/utils/applyTransactionAsyncUpdate.js +97 -0
- package/lib/common/src/utils/arrayPromise.d.ts +5 -0
- package/lib/common/src/utils/arrayPromise.js +16 -0
- package/lib/common/src/utils/cache.d.ts +31 -0
- package/lib/common/src/utils/cache.js +119 -0
- package/lib/common/src/utils/index.d.ts +6 -0
- package/lib/common/src/utils/index.js +6 -0
- package/lib/common/src/utils/inputAutoStep.d.ts +4 -0
- package/lib/common/src/utils/inputAutoStep.js +79 -0
- package/lib/common/src/utils/mapMemory.d.ts +26 -0
- package/lib/common/src/utils/mapMemory.js +72 -0
- package/lib/common/src/utils/pageVisibilityContext.d.ts +5 -0
- package/lib/common/src/utils/pageVisibilityContext.js +18 -0
- package/lib/common/updateBy.d.ts +12 -0
- package/lib/common/updateBy.js +88 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lib/style/menuRight.css +139 -0
- package/lib/style/style.css +334 -0
- package/lib/tsconfig.json +6 -0
- package/package.json +50 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './styleGrid';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './styleGrid';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CellClassParams } from "ag-grid-community";
|
|
2
|
+
import type { Theme, ThemeDefaultParams } from "ag-grid-community";
|
|
3
|
+
import { provideGlobalGridOptions } from "ag-grid-community";
|
|
4
|
+
export { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
|
|
5
|
+
export declare function GridStyleDefault(): {
|
|
6
|
+
theme: Theme<ThemeDefaultParams>;
|
|
7
|
+
provideGlobalGridOptions: typeof provideGlobalGridOptions;
|
|
8
|
+
};
|
|
9
|
+
export declare const StyleGridDefault: {
|
|
10
|
+
fontFamily: string;
|
|
11
|
+
fontStyle: string;
|
|
12
|
+
fontWeight: string;
|
|
13
|
+
fontSize: string;
|
|
14
|
+
textAlign: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function StyleCSSHeadGridEdit(name: string, rules: string): void;
|
|
17
|
+
export declare function StyleCSSHeadGrid(): void;
|
|
18
|
+
export type tCallFuncAgGrid<T> = (params: CellClassParams & {
|
|
19
|
+
data: T;
|
|
20
|
+
}) => {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { colorSchemeDarkBlue, iconSetMaterial, provideGlobalGridOptions, themeAlpine } from "ag-grid-community";
|
|
2
|
+
import { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
|
|
3
|
+
export { AllCommunityModule, ModuleRegistry } from "ag-grid-community";
|
|
4
|
+
// import 'ag-grid-community/styles/ag-grid.css';
|
|
5
|
+
// import 'ag-grid-community/styles/ag-theme-alpine.css';
|
|
6
|
+
// Register all community features
|
|
7
|
+
ModuleRegistry.registerModules([AllCommunityModule]);
|
|
8
|
+
export function GridStyleDefault() {
|
|
9
|
+
const theme = themeAlpine
|
|
10
|
+
.withPart(colorSchemeDarkBlue)
|
|
11
|
+
.withPart(iconSetMaterial)
|
|
12
|
+
.withParams({
|
|
13
|
+
'fontFamily': 'Roboto',
|
|
14
|
+
'textColor': 'rgba(214,214,214,0.9)',
|
|
15
|
+
'tabTextColor': 'rgba(227,227,227,0.9)',
|
|
16
|
+
'fontSize': '10px',
|
|
17
|
+
'spacing': '3px',
|
|
18
|
+
'backgroundColor': 'rgb(19,24,33)'
|
|
19
|
+
});
|
|
20
|
+
// Mark all grids as using legacy themes
|
|
21
|
+
provideGlobalGridOptions({ theme: theme });
|
|
22
|
+
return { theme, provideGlobalGridOptions };
|
|
23
|
+
}
|
|
24
|
+
export const StyleGridDefault = {
|
|
25
|
+
// 'color':'#1d262c',
|
|
26
|
+
'fontFamily': 'Roboto',
|
|
27
|
+
'fontStyle': 'normal',
|
|
28
|
+
'fontWeight': '400',
|
|
29
|
+
'fontSize': '12px',
|
|
30
|
+
// 'paddingLeft': '1px',
|
|
31
|
+
// 'paddingRight': '1px',
|
|
32
|
+
// 'lineHeight': '12px',
|
|
33
|
+
// 'paddingTop': '10px',
|
|
34
|
+
// 'paddingBottom': '3px',
|
|
35
|
+
// 'background-color': 'whitesmoke',
|
|
36
|
+
'textAlign': 'center',
|
|
37
|
+
// "justifyContent":'center'
|
|
38
|
+
};
|
|
39
|
+
export function StyleCSSHeadGridEdit(name, rules) {
|
|
40
|
+
let style = document.createElement('style');
|
|
41
|
+
style.type = 'text/css';
|
|
42
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
43
|
+
style.sheet?.insertRule(name + "{" + rules + "}", 0);
|
|
44
|
+
}
|
|
45
|
+
export function StyleCSSHeadGrid() {
|
|
46
|
+
// уменьшаем отступы с боков для заголовков
|
|
47
|
+
StyleCSSHeadGridEdit('.ag-theme-alpine-dark .ag-theme-alpine .ag-header-cell, .ag-theme-alpine-dark .ag-header-group-cell', "padding-left: 3px; padding-right: 3px;");
|
|
48
|
+
// выравнивание в заголовке по центру
|
|
49
|
+
StyleCSSHeadGridEdit('.ag-header-cell-label', 'justify-content: center');
|
|
50
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ColDef, GridReadyEvent } from "ag-grid-community";
|
|
2
|
+
declare const optionsDef: {
|
|
3
|
+
update: boolean;
|
|
4
|
+
add: boolean;
|
|
5
|
+
updateBuffer: boolean;
|
|
6
|
+
sync: boolean;
|
|
7
|
+
};
|
|
8
|
+
type options = Partial<typeof optionsDef>;
|
|
9
|
+
export declare function applyTransactionAsyncUpdate<T>(grid: GridReadyEvent<T, any> | null | undefined, newData: (Partial<T>)[], getId: (...a: any[]) => string, bufTable: {
|
|
10
|
+
[id: string]: Partial<T>;
|
|
11
|
+
}, option?: options): void;
|
|
12
|
+
export declare function getUpdateTable<T>(grid: GridReadyEvent<T, any> | null | undefined, newData: (Partial<T>)[], getId: (...a: any[]) => string, bufTable: {
|
|
13
|
+
[id: string]: Partial<T>;
|
|
14
|
+
}, option?: options): {};
|
|
15
|
+
type CommonParams<T> = {
|
|
16
|
+
getId: (...a: any[]) => string;
|
|
17
|
+
bufTable: {
|
|
18
|
+
[id: string]: Partial<T>;
|
|
19
|
+
};
|
|
20
|
+
option?: options;
|
|
21
|
+
};
|
|
22
|
+
type params<T> = CommonParams<T> & ({
|
|
23
|
+
newData: (Partial<T>)[];
|
|
24
|
+
synchronization?: never;
|
|
25
|
+
gridRef?: React.RefObject<GridReadyEvent<T, any> | null | undefined>;
|
|
26
|
+
grid?: GridReadyEvent<T, any> | null | undefined;
|
|
27
|
+
} | ({
|
|
28
|
+
newData?: never;
|
|
29
|
+
synchronization: true;
|
|
30
|
+
} & ({
|
|
31
|
+
grid: GridReadyEvent<T, any> | null | undefined;
|
|
32
|
+
gridRef?: never;
|
|
33
|
+
} | {
|
|
34
|
+
gridRef: React.RefObject<GridReadyEvent<T, any> | null | undefined>;
|
|
35
|
+
grid?: never;
|
|
36
|
+
})));
|
|
37
|
+
export declare function applyTransactionAsyncUpdate2<T>(params: params<T>): void;
|
|
38
|
+
type UnUndefined<T extends (any | undefined)> = T extends undefined ? never : T;
|
|
39
|
+
type t1<T = any> = ColDef<T>["comparator"];
|
|
40
|
+
type paramsCompare<TData = any> = Parameters<UnUndefined<t1>>;
|
|
41
|
+
export declare function getComparatorGrid<T = any>(func?: (...param: paramsCompare<T>) => [a: number, b: number]): t1;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const optionsDef = {
|
|
2
|
+
update: true,
|
|
3
|
+
add: true,
|
|
4
|
+
updateBuffer: true,
|
|
5
|
+
sync: false
|
|
6
|
+
};
|
|
7
|
+
export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, option) {
|
|
8
|
+
// Установка параметров (объединение переданных опций с настройками по умолчанию)
|
|
9
|
+
const op = { ...optionsDef, ...(option ?? {}) };
|
|
10
|
+
// Проверка наличия сетки и доступа к данным через API
|
|
11
|
+
if (grid?.api.getRowNode) {
|
|
12
|
+
const arrNew = []; // Массив для новых данных (добавляемые строки)
|
|
13
|
+
// Основная обработка данных (map используется для обновления или создания записей)
|
|
14
|
+
const arr = newData.map(e => {
|
|
15
|
+
// Получение ID для текущей строки
|
|
16
|
+
const id = getId(e);
|
|
17
|
+
const newData = { ...(bufTable[id] ?? {}), ...e };
|
|
18
|
+
if (op.updateBuffer)
|
|
19
|
+
bufTable[id] = newData;
|
|
20
|
+
// Попытка найти существующую строку по ID
|
|
21
|
+
const a = grid.api.getRowNode(id)?.data;
|
|
22
|
+
if (!a) {
|
|
23
|
+
// Если строка не найдена - добавить в массив для добавления
|
|
24
|
+
arrNew.push(newData);
|
|
25
|
+
return null; // Новая строка обрабатывается отдельно
|
|
26
|
+
}
|
|
27
|
+
// Если строка найдена - обновить данные в буфере
|
|
28
|
+
return newData;
|
|
29
|
+
}) // Убираем `null` и оставляем только существующие строки
|
|
30
|
+
.filter(e => e);
|
|
31
|
+
if (op.sync) {
|
|
32
|
+
grid.api.applyTransaction({ add: op.add ? arrNew : [], update: op.update ? arr : [] });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Добавление новых строк (если есть элементы)
|
|
36
|
+
if (arrNew.length && op.add) {
|
|
37
|
+
// добавление элементов должно быть синхронно, т.к. может прейти его update до исполнения
|
|
38
|
+
grid.api.applyTransaction({ add: arrNew });
|
|
39
|
+
}
|
|
40
|
+
// Асинхронное обновление существующих строк
|
|
41
|
+
if (arr.length && op.update) {
|
|
42
|
+
grid.api.applyTransactionAsync({ update: arr });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const map = new WeakMap();
|
|
47
|
+
export function getUpdateTable(grid, newData, getId, bufTable, option) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
export function applyTransactionAsyncUpdate2(params) {
|
|
51
|
+
const { grid, gridRef, newData, getId, bufTable } = params;
|
|
52
|
+
// Установка параметров (объединение переданных опций с настройками по умолчанию)
|
|
53
|
+
const op = { ...optionsDef, ...(params.option ?? {}) };
|
|
54
|
+
// Проверка наличия сетки и доступа к данным через API
|
|
55
|
+
if (grid?.api.getRowNode) {
|
|
56
|
+
if (!newData) {
|
|
57
|
+
applyTransactionAsyncUpdate(grid, Object.values(bufTable), getId, bufTable, op);
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
applyTransactionAsyncUpdate(grid, newData, getId, bufTable, op);
|
|
61
|
+
}
|
|
62
|
+
else if (gridRef?.current?.api.getRowNode) {
|
|
63
|
+
if (!newData) {
|
|
64
|
+
applyTransactionAsyncUpdate(gridRef.current, Object.values(bufTable), getId, bufTable, op);
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
applyTransactionAsyncUpdate(gridRef.current, newData, getId, bufTable, op);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (map.get(bufTable))
|
|
71
|
+
map.set(bufTable, new Set());
|
|
72
|
+
const m = map.get(bufTable);
|
|
73
|
+
if (newData)
|
|
74
|
+
newData.forEach(e => {
|
|
75
|
+
// Получение ID для текущей строки
|
|
76
|
+
const id = getId(e);
|
|
77
|
+
// m? - это странно, но так надо
|
|
78
|
+
m?.add(id);
|
|
79
|
+
if (op.updateBuffer)
|
|
80
|
+
bufTable[id] = { ...(bufTable[id] ?? {}), ...e };
|
|
81
|
+
}); // Убираем `null` и оставляем только существующие строки
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function getComparatorGrid(func) {
|
|
85
|
+
return (...param) => {
|
|
86
|
+
const [a1, b1, modeA, modeB, inv] = param; // Распаковка параметров в функцию
|
|
87
|
+
const [a, b] = func ? func(...param) : [a1, b1]; // Использование преобразующей функции func, если передана
|
|
88
|
+
return ((typeof a == "number" && !Number.isNaN(a)) &&
|
|
89
|
+
(typeof b == "number" && !Number.isNaN(b))) // Если оба a и b - валидные числа
|
|
90
|
+
? a - b // Разница между числами
|
|
91
|
+
: a == b
|
|
92
|
+
? 0 // Если значения равны, возвращаем 0
|
|
93
|
+
: (!Number.isNaN(b) && b != undefined)
|
|
94
|
+
? (inv ? -1 : 1) // Если b существует: порядок определяется inv
|
|
95
|
+
: (inv ? 1 : -1); // Если b отсутствует: порядок определяется inv
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function ArrayPromise<T = unknown>({ arr, catchF, thenF }: {
|
|
2
|
+
arr: (() => Promise<T>)[];
|
|
3
|
+
thenF?: (data: T, i: number, countOk: number, countError: number, count: number) => unknown;
|
|
4
|
+
catchF?: (error: unknown, i: number, countOk: number, countError: number, count: number) => unknown;
|
|
5
|
+
}): (() => Promise<unknown>)[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function ArrayPromise({ arr, catchF, thenF }) {
|
|
2
|
+
let ok = 0, countError = 0;
|
|
3
|
+
const count = arr.length;
|
|
4
|
+
const a = (data, i) => {
|
|
5
|
+
++ok;
|
|
6
|
+
return thenF?.(data, i, ok, countError, count) ?? data;
|
|
7
|
+
};
|
|
8
|
+
const b = (error, i) => {
|
|
9
|
+
++countError;
|
|
10
|
+
if (catchF)
|
|
11
|
+
return catchF?.(error, i, ok, countError, count);
|
|
12
|
+
else
|
|
13
|
+
throw error;
|
|
14
|
+
};
|
|
15
|
+
return arr.map((e, i) => () => e().then(r => a(r, i)).catch((er) => b(er, i)));
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface IServerSaveBasePromise {
|
|
2
|
+
set(key: string, value: object): Promise<boolean>;
|
|
3
|
+
get<T extends (object)>(key: string): Promise<T | null>;
|
|
4
|
+
delete(key: string): Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
export declare class CSaveToCache implements IServerSaveBasePromise {
|
|
7
|
+
set(key: string, value: object): Promise<boolean>;
|
|
8
|
+
get<T extends object>(key: string): Promise<T | null>;
|
|
9
|
+
delete<T extends object>(key: string): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
export declare class CSaveToLocalStorage implements IServerSaveBasePromise {
|
|
12
|
+
set(key: string, value: object): Promise<boolean>;
|
|
13
|
+
get<T extends object>(key: string): Promise<T | null>;
|
|
14
|
+
delete<T extends object>(key: string): Promise<boolean>;
|
|
15
|
+
deleteAll(): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
export declare const CacheG: CSaveToCache;
|
|
18
|
+
export declare const CacheLocal: CSaveToLocalStorage;
|
|
19
|
+
export declare const ObjectStringToDate: (obj: unknown) => void;
|
|
20
|
+
export declare function CacheFuncMapBase(arr: [k: string, v: Map<string, unknown>][], Save: IServerSaveBasePromise): {
|
|
21
|
+
load(): Promise<void>;
|
|
22
|
+
save(): Promise<void>;
|
|
23
|
+
clear(): Promise<void>;
|
|
24
|
+
getArr: [k: string, v: Map<string, unknown>][];
|
|
25
|
+
};
|
|
26
|
+
export declare function CacheFuncMap(arr: [k: string, v: Map<string, unknown>][]): {
|
|
27
|
+
load(): Promise<void>;
|
|
28
|
+
save(): Promise<void>;
|
|
29
|
+
clear(): Promise<void>;
|
|
30
|
+
getArr: [k: string, v: Map<string, unknown>][];
|
|
31
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { renderBy } from "../../updateBy";
|
|
2
|
+
const HostName = location.toString();
|
|
3
|
+
export class CSaveToCache {
|
|
4
|
+
async set(key, value) {
|
|
5
|
+
const t = new Response(JSON.stringify(value));
|
|
6
|
+
if (window.caches) {
|
|
7
|
+
const Cache = await caches.open(key);
|
|
8
|
+
await Cache.put(HostName, t);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
async get(key) {
|
|
14
|
+
if (window.caches) {
|
|
15
|
+
const Cache = await caches.open(key);
|
|
16
|
+
const cachedResponse = await Cache.match(HostName);
|
|
17
|
+
if (cachedResponse) {
|
|
18
|
+
return (await cachedResponse.json());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
async delete(key) {
|
|
24
|
+
if (window.caches) {
|
|
25
|
+
return await caches.delete(key);
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class CSaveToLocalStorage {
|
|
31
|
+
async set(key, value) {
|
|
32
|
+
const t = new Response(JSON.stringify(value));
|
|
33
|
+
if (window.localStorage) {
|
|
34
|
+
await localStorage.setItem(key, JSON.stringify(value));
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
async get(key) {
|
|
40
|
+
if (window.localStorage) {
|
|
41
|
+
const st = await localStorage.getItem(key);
|
|
42
|
+
if (st)
|
|
43
|
+
return JSON.parse(st);
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
async delete(key) {
|
|
48
|
+
if (window.localStorage) {
|
|
49
|
+
localStorage.removeItem(key);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
async deleteAll() {
|
|
55
|
+
if (window.localStorage) {
|
|
56
|
+
await localStorage.clear();
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const CacheG = new CSaveToCache();
|
|
63
|
+
export const CacheLocal = new CSaveToLocalStorage();
|
|
64
|
+
async function addDataToMap(data, map) {
|
|
65
|
+
if (data) {
|
|
66
|
+
for (let [k, v] of data) {
|
|
67
|
+
const tr = (map.get(k) || map.set(k, v).get(k));
|
|
68
|
+
if (tr && typeof tr === 'object') {
|
|
69
|
+
Object.assign(tr, v);
|
|
70
|
+
renderBy(tr);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export const ObjectStringToDate = (obj) => {
|
|
76
|
+
if (typeof obj == "object" && obj) {
|
|
77
|
+
if (Array.isArray(obj))
|
|
78
|
+
obj.forEach(ObjectStringToDate);
|
|
79
|
+
else
|
|
80
|
+
Object.entries(obj).forEach(([k, v]) => {
|
|
81
|
+
if (typeof v == "string") {
|
|
82
|
+
if (isDate(v)) {
|
|
83
|
+
obj[k] = new Date(v);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (typeof v == "object")
|
|
87
|
+
ObjectStringToDate(v);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function isDate(_date) {
|
|
92
|
+
const _regExp = new RegExp('^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$');
|
|
93
|
+
return _regExp.test(_date);
|
|
94
|
+
}
|
|
95
|
+
export function CacheFuncMapBase(arr, Save) {
|
|
96
|
+
return {
|
|
97
|
+
async load() {
|
|
98
|
+
for (let [k, v] of arr) {
|
|
99
|
+
const t = await Save.get(k);
|
|
100
|
+
ObjectStringToDate(t);
|
|
101
|
+
await addDataToMap(t, v);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
async save() {
|
|
105
|
+
for (let [k, v] of arr) {
|
|
106
|
+
await Save.set(k, [...v.entries()]);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
async clear() {
|
|
110
|
+
for (let [k, v] of arr) {
|
|
111
|
+
await Save.delete(k);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
getArr: arr
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function CacheFuncMap(arr) {
|
|
118
|
+
return CacheFuncMapBase(arr, CacheLocal);
|
|
119
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
// задать автоматическое управление шагом для элемента input
|
|
3
|
+
import { GetDblPrecision, GetDblPrecision2, NormalizeDouble } from "wenay-common2";
|
|
4
|
+
export function SetAutoStepForElement(element, params = { maxStep: 1 }) {
|
|
5
|
+
function parse(valueStr) { let val = parseFloat(valueStr); return isNaN(val) ? null : val; }
|
|
6
|
+
const { minStep, maxStep = 1 } = params;
|
|
7
|
+
const maxDigits = minStep ? GetDblPrecision(minStep) : undefined;
|
|
8
|
+
const stepDefault = parse(element.step);
|
|
9
|
+
const minDefault = parse(element.min);
|
|
10
|
+
const maxDefault = parse(element.max);
|
|
11
|
+
const minDigits = maxStep > 0 ? Math.max(0, -Math.round(Math.log10(maxStep))) : 0;
|
|
12
|
+
let _digits = null;
|
|
13
|
+
let _step = parse(element.step);
|
|
14
|
+
let _min = parse(element.min);
|
|
15
|
+
function calculateStep(valueStr) {
|
|
16
|
+
//function NormalizeDouble(value :number, digits :number) { let factor=Math.pow(10, digits); return Math.round(value * factor)/factor; }
|
|
17
|
+
//if (dotPos===valueStr.length-1) dotPos--;
|
|
18
|
+
//let digits= GetDblPrecision2(parseFloat(valueStr), minDigits, 10);
|
|
19
|
+
let dotPos = valueStr.search(/\.|,/); // Находим точку или запятую
|
|
20
|
+
let digits = (dotPos >= 0) ? valueStr.length - dotPos - 1 : 0;
|
|
21
|
+
digits = Math.max(digits, minDigits);
|
|
22
|
+
if (digits > 10)
|
|
23
|
+
digits = GetDblPrecision2(parseFloat(valueStr), minDigits, 10);
|
|
24
|
+
if (maxDigits != null)
|
|
25
|
+
digits = Math.min(digits, maxDigits);
|
|
26
|
+
let step = NormalizeDouble(Math.pow(0.1, digits), digits);
|
|
27
|
+
if (minStep)
|
|
28
|
+
step = NormalizeDouble(Math.round(step / minStep) * minStep, digits);
|
|
29
|
+
if (maxDefault != null && minDefault != null)
|
|
30
|
+
if (maxDefault - minDefault < step * 2)
|
|
31
|
+
return _step;
|
|
32
|
+
_digits = digits;
|
|
33
|
+
_step = step;
|
|
34
|
+
//if (Math.abs(min) < step) min= Math.floor(Math.abs(min)/step)*step * Math.sign(min);
|
|
35
|
+
if (_min != null) {
|
|
36
|
+
if (Math.abs(_min) % step != 0)
|
|
37
|
+
_min = Math.floor(Math.abs(_min) / step) * step * Math.sign(minDefault);
|
|
38
|
+
element.min = _min + "";
|
|
39
|
+
}
|
|
40
|
+
//console.log("step:",element.step+"->"+step," min:",element.min+"->"+min);
|
|
41
|
+
//console.log("minDefault:",_minDefault,parseFloat(_minDefault));
|
|
42
|
+
element.step = step + "";
|
|
43
|
+
//console.log("dotPos:",dotPos," _digits:",_digits, "minDigits:",minDigits);
|
|
44
|
+
return step; ////lib.GetDblPrecision($fee[0].value)); }
|
|
45
|
+
}
|
|
46
|
+
let modeAuto = !_step || (_step < 1 && Math.log10(_step - Math.trunc(_step)) % 1 == 0); // является степенью 0.1
|
|
47
|
+
const modeAuto0 = modeAuto;
|
|
48
|
+
if (modeAuto) {
|
|
49
|
+
calculateStep((_step ? (Math.round(parseFloat(element.value) / _step) * _step) : element.value) + "");
|
|
50
|
+
//console.log(element.value, step);
|
|
51
|
+
}
|
|
52
|
+
if (_step && minDefault && Math.abs(minDefault % _step) > 1e-10)
|
|
53
|
+
modeAuto = false;
|
|
54
|
+
else if (_step && maxDefault && Math.abs(maxDefault % _step) > 1e-10)
|
|
55
|
+
modeAuto = false;
|
|
56
|
+
else
|
|
57
|
+
modeAuto ||= (_step != null && (minStep == null || _step > minStep));
|
|
58
|
+
//console.log("###",{value: element.value, modeAuto0, modeAuto, _step, _digits});
|
|
59
|
+
//element.onkeydown= (e)=> { if (_step) element.step = "0.00000001"; /*String(_step/10);*/ console.log("keydown", {value: element.value}); }
|
|
60
|
+
//element.onkeyup= ()=>{ if (_step) element.step= _step+""; console.log("keyup", {modeAuto, value: element.value, step: calculateStep(element.value), _digits}); if (modeAuto) calculateStep(element.value); }// console.log(element.step); }// console.log(element.value, element.step); }
|
|
61
|
+
element.onkeyup = () => { if (modeAuto)
|
|
62
|
+
calculateStep(element.value); }; // console.log(element.step); }// console.log(element.value, element.step); }
|
|
63
|
+
element.onchange = () => {
|
|
64
|
+
let digits = _digits;
|
|
65
|
+
if (digits != null)
|
|
66
|
+
element.value = parseFloat(element.value).toFixed(digits);
|
|
67
|
+
//console.log("change", {value: element.value, digits, minDigits});
|
|
68
|
+
if (minDefault != null && parseFloat(element.value) < minDefault) {
|
|
69
|
+
element.step = stepDefault + "";
|
|
70
|
+
element.value = minDefault + "";
|
|
71
|
+
element.min = minDefault + "";
|
|
72
|
+
_digits = null;
|
|
73
|
+
}
|
|
74
|
+
element.setAttribute("value", element.value);
|
|
75
|
+
}; //Math.round($fee[0].value/$fee[0].step)*$fee[0].step; }
|
|
76
|
+
//element.onkeyup();
|
|
77
|
+
}
|
|
78
|
+
//import * as Time from "./Time"
|
|
79
|
+
//import {const_Date} from "./Time";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare function staticSet(key: any, data: object): void;
|
|
2
|
+
export declare function staticGet(key: any): object | undefined;
|
|
3
|
+
export declare function deepMergeWithMap(target: any, source: any, visited?: Map<any, any>): any;
|
|
4
|
+
export declare function staticGetAdd<T extends object>(key: any, def: T, options?: {
|
|
5
|
+
abs?: boolean;
|
|
6
|
+
deepAutoMerge?: boolean;
|
|
7
|
+
reversDeep?: boolean;
|
|
8
|
+
}): T;
|
|
9
|
+
export declare function staticGetById<T extends object>(key: any, def: T, id: string | number): T;
|
|
10
|
+
export declare const MemoryMap: {
|
|
11
|
+
rnd: Map<string, {
|
|
12
|
+
position: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
16
|
+
size: {
|
|
17
|
+
height: number | string;
|
|
18
|
+
width: number | string;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
resize: Map<string, {
|
|
22
|
+
height?: number | string;
|
|
23
|
+
width?: number | string;
|
|
24
|
+
}>;
|
|
25
|
+
other: Map<string, object>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { deepClone } from "wenay-common2";
|
|
2
|
+
import { ExRNDMap3, mapResiReact } from "../components";
|
|
3
|
+
const staticProps = new Map();
|
|
4
|
+
export function staticSet(key, data) {
|
|
5
|
+
if (!staticProps.has(key))
|
|
6
|
+
staticProps.set(key, data);
|
|
7
|
+
}
|
|
8
|
+
export function staticGet(key) {
|
|
9
|
+
return staticProps.get(key);
|
|
10
|
+
}
|
|
11
|
+
function isObject(item) {
|
|
12
|
+
return item !== null && typeof item === 'object' && !Array.isArray(item);
|
|
13
|
+
}
|
|
14
|
+
export function deepMergeWithMap(target, source, visited = new Map()) {
|
|
15
|
+
if (isObject(target) && isObject(source)) {
|
|
16
|
+
for (const key in source) {
|
|
17
|
+
if (isObject(source[key])) {
|
|
18
|
+
if (!target[key]) {
|
|
19
|
+
target[key] = {};
|
|
20
|
+
}
|
|
21
|
+
// Check if the source object has already been visited
|
|
22
|
+
if (!visited.has(source[key])) {
|
|
23
|
+
visited.set(source[key], {});
|
|
24
|
+
deepMergeWithMap(target[key], source[key], visited);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
target[key] = visited.get(source[key]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
target[key] = source[key];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
}
|
|
37
|
+
const map = new Map;
|
|
38
|
+
export function staticGetAdd(key, def, options = { reversDeep: false }) {
|
|
39
|
+
if (options.deepAutoMerge && !map.get(def)) {
|
|
40
|
+
map.set(def, true);
|
|
41
|
+
if (options.deepAutoMerge) {
|
|
42
|
+
if (!options.reversDeep)
|
|
43
|
+
staticProps.set(key, deepMergeWithMap(staticProps.get(key) ?? {}, def));
|
|
44
|
+
else
|
|
45
|
+
staticProps.set(key, deepMergeWithMap(deepClone(def), staticProps.get(key) ?? {}));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (options.abs)
|
|
49
|
+
staticProps.set(key, def);
|
|
50
|
+
const t = (staticProps.get(key) || staticProps.set(key, def).get(key));
|
|
51
|
+
return t; // Object.assign(def, t) // t //
|
|
52
|
+
}
|
|
53
|
+
export function staticGetById(key, def, id) {
|
|
54
|
+
const t = map.get(key);
|
|
55
|
+
const el = { __id: id, data: def };
|
|
56
|
+
if ((el && el.__id != id) || !el) {
|
|
57
|
+
return staticGetAdd(key, el, { abs: true }).data;
|
|
58
|
+
}
|
|
59
|
+
return el.data;
|
|
60
|
+
}
|
|
61
|
+
// export const Cash = CashFuncMapCash(
|
|
62
|
+
// [
|
|
63
|
+
// ["mapResiReact", mapResiReact],
|
|
64
|
+
// ["ExRNDMap3", ExRNDMap3],
|
|
65
|
+
// ["staticProps", staticProps]
|
|
66
|
+
// ]
|
|
67
|
+
// )
|
|
68
|
+
export const MemoryMap = {
|
|
69
|
+
rnd: ExRNDMap3,
|
|
70
|
+
resize: mapResiReact,
|
|
71
|
+
other: staticProps
|
|
72
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useEffect, useState } from "react";
|
|
3
|
+
export const PageVisibilityContext = createContext(true);
|
|
4
|
+
export function PageVisibilityProvider({ children }) {
|
|
5
|
+
const [isVisible, setIsVisible] = useState(typeof document !== 'undefined' ? !document.hidden : true);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (typeof document === 'undefined')
|
|
8
|
+
return;
|
|
9
|
+
const handleVisibilityChange = () => {
|
|
10
|
+
setIsVisible(!document.hidden);
|
|
11
|
+
};
|
|
12
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
13
|
+
return () => {
|
|
14
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
15
|
+
};
|
|
16
|
+
}, []);
|
|
17
|
+
return (_jsx(PageVisibilityContext.Provider, { value: isVisible, children: children }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type tFunc2 = Map<object, (a?: any) => void>;
|
|
2
|
+
export declare const map3: WeakMap<object, tFunc2>;
|
|
3
|
+
export declare const mapWait: Map<object, {
|
|
4
|
+
refreshAsync: (ms: number, func: () => any) => void;
|
|
5
|
+
refreshAsync2: (ms: number, func: () => any) => Promise<void>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function renderBy(a: object, ms?: number): void;
|
|
8
|
+
export declare function renderByRevers(a: object, ms?: number, reverse?: boolean): void;
|
|
9
|
+
export declare function renderByLast(a: object, ms?: number): void;
|
|
10
|
+
export declare function useUpdateBy<T extends object>(a: T, f?: React.Dispatch<React.SetStateAction<T>> | ((a: T) => void)): void;
|
|
11
|
+
export declare function updateBy<T extends object>(a: T, f?: React.Dispatch<React.SetStateAction<T>> | ((a: T) => void)): void;
|
|
12
|
+
export {};
|