@sydsoft/base 1.49.0 → 1.51.0
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/_dist/_lib/baseFunctions.js +24 -11
- package/_dist/_lib/inputMask.js +7 -3
- package/_dist/_lib/listFunctions.js +7 -2
- package/_dist/_lib/storage/cookies.js +20 -12
- package/_dist/_lib/storage/encData.js +10 -5
- package/_dist/_lib/storage/localStorage.js +23 -14
- package/_dist/_lib/storage/sessionStorage.js +23 -14
- package/_dist/_lib/useInterval.js +8 -5
- package/_dist/alert/index.js +22 -13
- package/_dist/box/Box.js +12 -8
- package/_dist/box/BoxContent.js +9 -4
- package/_dist/box/BoxFooter.js +9 -5
- package/_dist/box/BoxHeader.js +10 -6
- package/_dist/box/index.js +7 -4
- package/_dist/countDown/index.js +17 -12
- package/_dist/dateTime/index.js +4 -1
- package/_dist/form/Button.js +24 -20
- package/_dist/form/Checkbox.js +11 -6
- package/_dist/form/Dialog.js +12 -8
- package/_dist/form/Form.js +7 -4
- package/_dist/form/FormOlustur.js +16 -12
- package/_dist/form/Input.js +49 -44
- package/_dist/form/Label.js +10 -6
- package/_dist/form/SearchableInput.js +47 -43
- package/_dist/form/UploadBase.js +16 -11
- package/_dist/form/index.js +12 -9
- package/_dist/grid/index.js +38 -30
- package/_dist/icon/icons.js +10 -7
- package/_dist/icon/index.js +13 -9
- package/_dist/icon/mui.js +2 -1
- package/_dist/index.js +22 -19
- package/_dist/menu/index.js +20 -16
- package/_dist/modal/index.js +16 -12
- package/_dist/popover/index.js +37 -33
- package/_dist/tooltip/index.js +8 -4
- package/package.json +3 -5
- package/_lib/baseFunctions.ts +0 -94
- package/_lib/inputMask.ts +0 -257
- package/_lib/listFunctions.ts +0 -106
- package/_lib/storage/cookies.ts +0 -39
- package/_lib/storage/encData.ts +0 -41
- package/_lib/storage/localStorage.ts +0 -67
- package/_lib/storage/sessionStorage.ts +0 -67
- package/_lib/useInterval.ts +0 -30
- package/alert/index.module.css +0 -119
- package/alert/index.tsx +0 -131
- package/box/Box.module.css +0 -153
- package/box/Box.tsx +0 -33
- package/box/BoxContent.tsx +0 -18
- package/box/BoxFooter.tsx +0 -25
- package/box/BoxHeader.tsx +0 -46
- package/box/index.ts +0 -10
- package/countDown/index.tsx +0 -116
- package/dateTime/index.ts +0 -79
- package/form/Button.tsx +0 -143
- package/form/Checkbox.tsx +0 -48
- package/form/Dialog.tsx +0 -109
- package/form/Form.tsx +0 -19
- package/form/FormOlustur.tsx +0 -105
- package/form/Input.tsx +0 -364
- package/form/Label.tsx +0 -20
- package/form/SearchableInput.tsx +0 -406
- package/form/UploadBase.tsx +0 -133
- package/form/index.ts +0 -10
- package/form/styles/Button.module.css +0 -145
- package/form/styles/Input.module.css +0 -221
- package/form/styles/Label.module.css +0 -31
- package/form/styles/SearchableInput.module.css +0 -80
- package/global.d.ts +0 -9
- package/grid/index.module.css +0 -805
- package/grid/index.tsx +0 -171
- package/icon/icons.tsx +0 -33
- package/icon/index.tsx +0 -95
- package/icon/mui.tsx +0 -5932
- package/index.ts +0 -21
- package/menu/index.module.css +0 -92
- package/menu/index.tsx +0 -143
- package/modal/index.module.css +0 -77
- package/modal/index.tsx +0 -106
- package/npm_recovery_codes.txt +0 -5
- package/popover/index.module.css +0 -89
- package/popover/index.tsx +0 -392
- package/tooltip/index.tsx +0 -216
- package/tsconfig.json +0 -24
package/_lib/inputMask.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { isDev } from "./baseFunctions";
|
|
2
|
-
|
|
3
|
-
// Mask işleme core fonksiyonları
|
|
4
|
-
const createMaskCore = () => {
|
|
5
|
-
const defaultTranslation: any = {
|
|
6
|
-
"0": { pattern: /\d/ },
|
|
7
|
-
"9": { pattern: /\d/, optional: true },
|
|
8
|
-
"#": { pattern: /\d/, recursive: true },
|
|
9
|
-
A: { pattern: /[a-zA-Z0-9]/ },
|
|
10
|
-
S: { pattern: /[a-zA-Z]/ },
|
|
11
|
-
U: { pattern: /[a-zA-Z]/, transform: (char: any) => char.toUpperCase() },
|
|
12
|
-
L: { pattern: /[a-zA-Z]/, transform: (char: any) => char.toLowerCase() },
|
|
13
|
-
X: { pattern: /[0-9a-fA-F]/ }
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const parseMask = (maskString: string, translation = defaultTranslation) => {
|
|
17
|
-
const tokens = [];
|
|
18
|
-
let i = 0;
|
|
19
|
-
|
|
20
|
-
while (i < maskString.length) {
|
|
21
|
-
const char = maskString[i];
|
|
22
|
-
|
|
23
|
-
if (translation[char]) {
|
|
24
|
-
tokens.push({
|
|
25
|
-
type: "input",
|
|
26
|
-
pattern: translation[char].pattern,
|
|
27
|
-
optional: translation[char].optional,
|
|
28
|
-
recursive: translation[char].recursive,
|
|
29
|
-
transform: translation[char].transform
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
tokens.push({
|
|
33
|
-
type: "literal",
|
|
34
|
-
char: char
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
i++;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return tokens;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const applyMask = (inputValue: string, maskTokens: any, reverse = false) => {
|
|
44
|
-
if (!maskTokens.length) return inputValue;
|
|
45
|
-
|
|
46
|
-
const normalizedValue = inputValue == null ? "" : String(inputValue);
|
|
47
|
-
const cleanValue = normalizedValue.replace(/[^\w\s]/g, "");
|
|
48
|
-
|
|
49
|
-
if (reverse) {
|
|
50
|
-
return applyReverseMask(cleanValue, maskTokens);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let result = "";
|
|
54
|
-
let valueIndex = 0;
|
|
55
|
-
let maskIndex = 0;
|
|
56
|
-
|
|
57
|
-
while (maskIndex < maskTokens.length && valueIndex < cleanValue.length) {
|
|
58
|
-
const token = maskTokens[maskIndex];
|
|
59
|
-
|
|
60
|
-
if (token.type === "literal") {
|
|
61
|
-
result += token.char;
|
|
62
|
-
maskIndex++;
|
|
63
|
-
} else {
|
|
64
|
-
const char = cleanValue[valueIndex];
|
|
65
|
-
|
|
66
|
-
if (token.pattern.test(char)) {
|
|
67
|
-
const transformedChar = token.transform ? token.transform(char) : char;
|
|
68
|
-
result += transformedChar;
|
|
69
|
-
valueIndex++;
|
|
70
|
-
maskIndex++;
|
|
71
|
-
} else if (token.optional) {
|
|
72
|
-
maskIndex++;
|
|
73
|
-
} else {
|
|
74
|
-
valueIndex++;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
while (maskIndex < maskTokens.length) {
|
|
80
|
-
const token = maskTokens[maskIndex];
|
|
81
|
-
if (token.type === "literal") {
|
|
82
|
-
result += token.char;
|
|
83
|
-
} else if (!token.optional) {
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
maskIndex++;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return result;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const applyReverseMask = (inputValue: string, maskTokens: any) => {
|
|
93
|
-
const reversedMask = maskTokens.slice().reverse();
|
|
94
|
-
const reversedValue = inputValue.split("").reverse().join("");
|
|
95
|
-
let result = "";
|
|
96
|
-
let valueIndex = 0;
|
|
97
|
-
let maskIndex = 0;
|
|
98
|
-
|
|
99
|
-
while (maskIndex < reversedMask.length && valueIndex < reversedValue.length) {
|
|
100
|
-
const token = reversedMask[maskIndex];
|
|
101
|
-
|
|
102
|
-
if (token.type === "literal") {
|
|
103
|
-
result = token.char + result;
|
|
104
|
-
maskIndex++;
|
|
105
|
-
} else {
|
|
106
|
-
const char = reversedValue[valueIndex];
|
|
107
|
-
|
|
108
|
-
if (token.pattern.test(char)) {
|
|
109
|
-
const transformedChar = token.transform ? token.transform(char) : char;
|
|
110
|
-
result = transformedChar + result;
|
|
111
|
-
valueIndex++;
|
|
112
|
-
maskIndex++;
|
|
113
|
-
} else if (token.optional) {
|
|
114
|
-
maskIndex++;
|
|
115
|
-
} else {
|
|
116
|
-
valueIndex++;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return result;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const getCleanValue = (maskedValue: string, maskTokens: any) => {
|
|
125
|
-
if (!maskTokens.length) return maskedValue;
|
|
126
|
-
|
|
127
|
-
let clean = "";
|
|
128
|
-
let valueIndex = 0;
|
|
129
|
-
let maskIndex = 0;
|
|
130
|
-
|
|
131
|
-
while (maskIndex < maskTokens.length && valueIndex < maskedValue.length) {
|
|
132
|
-
const token = maskTokens[maskIndex];
|
|
133
|
-
|
|
134
|
-
if (token.type === "literal") {
|
|
135
|
-
if (maskedValue[valueIndex] === token.char) {
|
|
136
|
-
valueIndex++;
|
|
137
|
-
}
|
|
138
|
-
maskIndex++;
|
|
139
|
-
} else {
|
|
140
|
-
clean += maskedValue[valueIndex];
|
|
141
|
-
valueIndex++;
|
|
142
|
-
maskIndex++;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return clean;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
parseMask,
|
|
151
|
-
applyMask,
|
|
152
|
-
getCleanValue
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// Fonksiyonel yaklaşım - herhangi bir input elementine mask uygula
|
|
157
|
-
export const applyInputMask = (inputElement: any, mask: string, options: any = {}) => {
|
|
158
|
-
if (!inputElement || !mask) return null;
|
|
159
|
-
|
|
160
|
-
isDev && console.log("Input mask applied:", { inputElement, mask, options });
|
|
161
|
-
|
|
162
|
-
const { translation, reverse = false, clearIfNotMatch = true, selectOnFocus = false, onChange } = options;
|
|
163
|
-
|
|
164
|
-
const maskCore = createMaskCore();
|
|
165
|
-
const maskTokens = maskCore.parseMask(mask, translation);
|
|
166
|
-
|
|
167
|
-
const applyMaskToValue = (inputValue: any) => maskCore.applyMask(inputValue, maskTokens, reverse);
|
|
168
|
-
|
|
169
|
-
const getCleanValue = (maskedValue: any) => maskCore.getCleanValue(maskedValue, maskTokens);
|
|
170
|
-
|
|
171
|
-
const handleInputChange = (e: any) => {
|
|
172
|
-
const inputValue = e.target.value;
|
|
173
|
-
const maskedValue = applyMaskToValue(inputValue);
|
|
174
|
-
const cleanValue = getCleanValue(maskedValue);
|
|
175
|
-
|
|
176
|
-
e.target.value = maskedValue;
|
|
177
|
-
onChange?.(maskedValue, cleanValue, e);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const handleKeyDown = (e: any) => {
|
|
181
|
-
const { key, target } = e;
|
|
182
|
-
const cursorStart = target.selectionStart;
|
|
183
|
-
const cursorEnd = target.selectionEnd;
|
|
184
|
-
|
|
185
|
-
if (key === "Backspace" || key === "Delete") {
|
|
186
|
-
e.preventDefault();
|
|
187
|
-
|
|
188
|
-
let newValue = target.value;
|
|
189
|
-
|
|
190
|
-
if (cursorStart !== cursorEnd) {
|
|
191
|
-
newValue = newValue.substring(0, cursorStart) + newValue.substring(cursorEnd);
|
|
192
|
-
} else if (key === "Backspace" && cursorStart > 0) {
|
|
193
|
-
newValue = newValue.substring(0, cursorStart - 1) + newValue.substring(cursorStart);
|
|
194
|
-
} else if (key === "Delete" && cursorStart < newValue.length) {
|
|
195
|
-
newValue = newValue.substring(0, cursorStart) + newValue.substring(cursorStart + 1);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const maskedValue = applyMaskToValue(newValue);
|
|
199
|
-
target.value = maskedValue;
|
|
200
|
-
|
|
201
|
-
const cleanValue = getCleanValue(maskedValue);
|
|
202
|
-
onChange?.(maskedValue, cleanValue, e);
|
|
203
|
-
|
|
204
|
-
setTimeout(() => {
|
|
205
|
-
const newPos = key === "Backspace" ? Math.max(0, cursorStart - 1) : cursorStart;
|
|
206
|
-
target.setSelectionRange(newPos, newPos);
|
|
207
|
-
}, 0);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const handleFocus = (e: any) => {
|
|
212
|
-
if (selectOnFocus) {
|
|
213
|
-
setTimeout(() => {
|
|
214
|
-
e.target.select();
|
|
215
|
-
}, 0);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const handleBlur = (e: any) => {
|
|
220
|
-
if (clearIfNotMatch) {
|
|
221
|
-
const cleanValue = getCleanValue(e.target.value);
|
|
222
|
-
const expectedLength = maskTokens.filter((t) => t.type === "input" && !t.optional).length;
|
|
223
|
-
|
|
224
|
-
if (cleanValue.length < expectedLength) {
|
|
225
|
-
e.target.value = "";
|
|
226
|
-
onChange?.("", "", e);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
// Event listener'ları ekle
|
|
232
|
-
inputElement.addEventListener("input", handleInputChange);
|
|
233
|
-
inputElement.addEventListener("keydown", handleKeyDown);
|
|
234
|
-
inputElement.addEventListener("focus", handleFocus);
|
|
235
|
-
inputElement.addEventListener("blur", handleBlur);
|
|
236
|
-
|
|
237
|
-
// Cleanup fonksiyonu
|
|
238
|
-
const destroy = () => {
|
|
239
|
-
inputElement.removeEventListener("input", handleInputChange);
|
|
240
|
-
inputElement.removeEventListener("keydown", handleKeyDown);
|
|
241
|
-
inputElement.removeEventListener("focus", handleFocus);
|
|
242
|
-
inputElement.removeEventListener("blur", handleBlur);
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
// Utility fonksiyonları
|
|
246
|
-
return {
|
|
247
|
-
destroy,
|
|
248
|
-
setValue: (value: any) => {
|
|
249
|
-
if (!value) return;
|
|
250
|
-
const maskedValue = applyMaskToValue(value || "");
|
|
251
|
-
inputElement.value = maskedValue;
|
|
252
|
-
},
|
|
253
|
-
getValue: () => inputElement.value,
|
|
254
|
-
getCleanValue: () => getCleanValue(inputElement.value),
|
|
255
|
-
applyMask: applyMaskToValue
|
|
256
|
-
};
|
|
257
|
-
};
|
package/_lib/listFunctions.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
export const onKeyboardSelection = ({ e, targetElement, itemClass = `item`, selectedClass = "selected", checkByValue, checkByInput, clear }: any) => {
|
|
2
|
-
if (!targetElement.current) return null;
|
|
3
|
-
|
|
4
|
-
const config = {
|
|
5
|
-
e: e,
|
|
6
|
-
itemClass: itemClass,
|
|
7
|
-
selectedClass: selectedClass,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
function selectEnter() {
|
|
11
|
-
if (!targetElement.current) return null;
|
|
12
|
-
const text: any = targetElement.current.querySelector(`${config.itemClass}.${config.selectedClass}`);
|
|
13
|
-
if (text) {
|
|
14
|
-
checkByValue(text.dataset.value);
|
|
15
|
-
} else if (targetElement.current.querySelectorAll(`${config.itemClass}`).length > 0) {
|
|
16
|
-
const target: any = targetElement.current.querySelectorAll(`${config.itemClass}.${config.selectedClass}`)[0];
|
|
17
|
-
checkByValue(target.dataset.value);
|
|
18
|
-
} else {
|
|
19
|
-
clear(true, true);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function selectFirst() {
|
|
24
|
-
if (!targetElement.current) return null;
|
|
25
|
-
const showList = targetElement.current.querySelectorAll(`${config.itemClass}`);
|
|
26
|
-
if (showList.length > 0) {
|
|
27
|
-
showList[0].classList.add(config.selectedClass);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function selectLast() {
|
|
32
|
-
if (!targetElement.current) return null;
|
|
33
|
-
const showList = targetElement.current.querySelectorAll(`${config.itemClass}`);
|
|
34
|
-
if (showList.length > 0) {
|
|
35
|
-
showList[showList.length - 1].classList.add(config.selectedClass);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function selectNext(element: any) {
|
|
40
|
-
element.classList.remove(config.selectedClass);
|
|
41
|
-
const next = element.nextElementSibling;
|
|
42
|
-
if (next && next.nodeType !== -1) {
|
|
43
|
-
if (next.classList.contains("item")) {
|
|
44
|
-
next.classList.add(config.selectedClass);
|
|
45
|
-
} else {
|
|
46
|
-
selectNext(next);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
selectFirst();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function selectPrev(element: any) {
|
|
54
|
-
element.classList.remove(config.selectedClass);
|
|
55
|
-
const next = element.previousElementSibling;
|
|
56
|
-
if (next && next.nodeType !== -1) {
|
|
57
|
-
if (next.classList.contains("item")) {
|
|
58
|
-
next.classList.add(config.selectedClass);
|
|
59
|
-
} else {
|
|
60
|
-
selectPrev(next);
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
selectLast();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const selected = targetElement.current.querySelector(`${config.itemClass}.${config.selectedClass}`);
|
|
68
|
-
if (e.which == 40) {
|
|
69
|
-
if (selected) {
|
|
70
|
-
selectNext(selected);
|
|
71
|
-
} else {
|
|
72
|
-
selectFirst();
|
|
73
|
-
}
|
|
74
|
-
} else if (e.which == 38) {
|
|
75
|
-
if (selected) {
|
|
76
|
-
selectPrev(selected);
|
|
77
|
-
} else {
|
|
78
|
-
selectLast();
|
|
79
|
-
}
|
|
80
|
-
} else if (e.which == 35) {
|
|
81
|
-
selectLast();
|
|
82
|
-
} else if (e.which == 36) {
|
|
83
|
-
selectFirst();
|
|
84
|
-
} else if (e.which == 13) {
|
|
85
|
-
selectEnter();
|
|
86
|
-
} else if (e.which == 9) {
|
|
87
|
-
checkByInput();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
setScrollListPosition(targetElement);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export function setScrollListPosition(targetElement: any) {
|
|
94
|
-
if (targetElement.current) {
|
|
95
|
-
let position = 0;
|
|
96
|
-
const text = targetElement.current.querySelector(".selected");
|
|
97
|
-
if (text) {
|
|
98
|
-
position = text.offsetTop - 35;
|
|
99
|
-
} else if (targetElement.current.querySelector(".active")) {
|
|
100
|
-
position = targetElement.current.querySelector(".active").offsetTop - 35;
|
|
101
|
-
}
|
|
102
|
-
targetElement.current.scrollTop = position;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
package/_lib/storage/cookies.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import nookies, { destroyCookie, parseCookies, setCookie } from 'nookies';
|
|
2
|
-
|
|
3
|
-
import { getDomain } from '../baseFunctions';
|
|
4
|
-
|
|
5
|
-
export const cerezOku = (context: any | null = null, key: string) => {
|
|
6
|
-
const cookies = context ? nookies.get(context) : parseCookies();
|
|
7
|
-
return cookies[key] || false;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const cerezKaydet = (context: any | null = null, key: string, value: string, time: number = 0) => {
|
|
11
|
-
const newConfig = checkDomain(context);
|
|
12
|
-
setCookie(context, key, value, {
|
|
13
|
-
maxAge: time > 0 ? time : null,
|
|
14
|
-
...newConfig
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const cerezSil = (context: any | null = null, key: string) => {
|
|
19
|
-
const newConfig = checkDomain(context);
|
|
20
|
-
destroyCookie(context, key, newConfig);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const cerezTumuSil = (context: any | null = null) => {
|
|
24
|
-
const cookies = parseCookies(context);
|
|
25
|
-
if (cookies) {
|
|
26
|
-
Object.keys(cookies).forEach((key) => {
|
|
27
|
-
destroyCookie(context, key);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const checkDomain = (context: any | null = null, config: any = {}) => {
|
|
33
|
-
let cookieDomain = getDomain(context);
|
|
34
|
-
return {
|
|
35
|
-
...config,
|
|
36
|
-
domain: '.' + cookieDomain,
|
|
37
|
-
path: '/'
|
|
38
|
-
};
|
|
39
|
-
};
|
package/_lib/storage/encData.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { isDev } from "../baseFunctions";
|
|
2
|
-
|
|
3
|
-
const encDecDataKeys: number[] = [3, 5, 8, 11, 15, 22];
|
|
4
|
-
|
|
5
|
-
export const encData = (data: object | string | number, keys: number[] = encDecDataKeys) => {
|
|
6
|
-
try {
|
|
7
|
-
const newJSON = { data: data };
|
|
8
|
-
const utf8Data = unescape(encodeURIComponent(JSON.stringify(newJSON))); // Dizeyi UTF-8'e dönüştür
|
|
9
|
-
let newData = btoa(utf8Data);
|
|
10
|
-
keys.map((value) => {
|
|
11
|
-
const randomChar = String.fromCharCode(Math.floor(Math.random() * (122 - 97 + 1)) + 97);
|
|
12
|
-
newData = newData.slice(0, value) + randomChar + newData.slice(value);
|
|
13
|
-
});
|
|
14
|
-
return newData;
|
|
15
|
-
} catch (e) {
|
|
16
|
-
isDev && console.log("ERROR => encData =>", e);
|
|
17
|
-
return "";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const decData = (data: string, keys: number[] = encDecDataKeys) => {
|
|
22
|
-
try {
|
|
23
|
-
let decode = data;
|
|
24
|
-
keys.map((value, index) => {
|
|
25
|
-
const prevValue = keys[index - 1];
|
|
26
|
-
if (!prevValue) {
|
|
27
|
-
decode = decode.slice(0, value) + decode.slice(value + 1);
|
|
28
|
-
} else {
|
|
29
|
-
decode = decode.slice(0, value - index) + decode.slice(value - index + 1);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
const decodedString = atob(decode);
|
|
33
|
-
const utf8DecodedString = decodeURIComponent(escape(decodedString));
|
|
34
|
-
|
|
35
|
-
const parse = JSON.parse(utf8DecodedString);
|
|
36
|
-
return parse?.data ?? "";
|
|
37
|
-
} catch (e) {
|
|
38
|
-
isDev && console.log("ERROR => decData =>", e);
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { decData, encData } from './encData';
|
|
2
|
-
|
|
3
|
-
import { isDev } from '../baseFunctions';
|
|
4
|
-
|
|
5
|
-
const storageAvailable = typeof Storage === 'undefined' || !window.localStorage ? false : true;
|
|
6
|
-
|
|
7
|
-
export const setLocalStorage = (key: string, value: any) => {
|
|
8
|
-
if (!storageAvailable) return false;
|
|
9
|
-
try {
|
|
10
|
-
localStorage.setItem(key, encData(value));
|
|
11
|
-
return true;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
isDev && console.log('ERROR => localStorage =>', e);
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const getLocalStorage = (key: string) => {
|
|
19
|
-
if (!storageAvailable) return false;
|
|
20
|
-
try {
|
|
21
|
-
const saved = localStorage.getItem(key);
|
|
22
|
-
return saved ? decData(saved) : null;
|
|
23
|
-
} catch (e) {
|
|
24
|
-
isDev && console.log('ERROR => localStorage =>', e);
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export const removeLocalStorage = (key: string) => {
|
|
29
|
-
if (!storageAvailable) return false;
|
|
30
|
-
try {
|
|
31
|
-
localStorage.removeItem(key);
|
|
32
|
-
return true;
|
|
33
|
-
} catch (e) {
|
|
34
|
-
isDev && console.log('ERROR => localStorage =>', e);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const clearLocalStorage = () => {
|
|
40
|
-
if (!storageAvailable) return false;
|
|
41
|
-
try {
|
|
42
|
-
localStorage.clear();
|
|
43
|
-
return true;
|
|
44
|
-
} catch (e) {
|
|
45
|
-
isDev && console.log('ERROR => localStorage =>', e);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Tüm localStorage anahtarlarını getir
|
|
51
|
-
export const getLocalStorageAllKeys = (): string[] => {
|
|
52
|
-
if (!storageAvailable) return [];
|
|
53
|
-
return Object.keys(localStorage);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Tüm localStorage boyutunu getir
|
|
57
|
-
export const getLocalStorageSize = (): number => {
|
|
58
|
-
if (!storageAvailable) return 0;
|
|
59
|
-
|
|
60
|
-
let total = 0;
|
|
61
|
-
for (const key in localStorage) {
|
|
62
|
-
if (localStorage.hasOwnProperty(key)) {
|
|
63
|
-
total += localStorage[key].length + key.length;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return total;
|
|
67
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { decData, encData } from "./encData";
|
|
2
|
-
|
|
3
|
-
import { isDev } from "../baseFunctions";
|
|
4
|
-
|
|
5
|
-
const storageAvailable = typeof Storage === "undefined" || !window.sessionStorage ? false : true;
|
|
6
|
-
|
|
7
|
-
export const setSessionStorage = (key: string, value: any) => {
|
|
8
|
-
if (!storageAvailable) return false;
|
|
9
|
-
try {
|
|
10
|
-
sessionStorage.setItem(key, encData(value));
|
|
11
|
-
return true;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const getSessionStorage = (key: string) => {
|
|
19
|
-
if (!storageAvailable) return false;
|
|
20
|
-
try {
|
|
21
|
-
const saved = sessionStorage.getItem(key);
|
|
22
|
-
return saved ? decData(saved) : null;
|
|
23
|
-
} catch (e) {
|
|
24
|
-
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export const removeSessionStorage = (key: string) => {
|
|
29
|
-
if (!storageAvailable) return false;
|
|
30
|
-
try {
|
|
31
|
-
sessionStorage.removeItem(key);
|
|
32
|
-
return true;
|
|
33
|
-
} catch (e) {
|
|
34
|
-
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const clearSessionStorage = () => {
|
|
40
|
-
if (!storageAvailable) return false;
|
|
41
|
-
try {
|
|
42
|
-
sessionStorage.clear();
|
|
43
|
-
return true;
|
|
44
|
-
} catch (e) {
|
|
45
|
-
isDev && console.log("ERROR => SessionStorage =>", e);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Tüm SessionStorage anahtarlarını getir
|
|
51
|
-
export const getSessionStorageAllKeys = (): string[] => {
|
|
52
|
-
if (!storageAvailable) return [];
|
|
53
|
-
return Object.keys(sessionStorage);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Tüm SessionStorage boyutunu getir
|
|
57
|
-
export const getSessionStorageSize = (): number => {
|
|
58
|
-
if (!storageAvailable) return 0;
|
|
59
|
-
|
|
60
|
-
let total = 0;
|
|
61
|
-
for (const key in sessionStorage) {
|
|
62
|
-
if (sessionStorage.hasOwnProperty(key)) {
|
|
63
|
-
total += sessionStorage[key].length + key.length;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return total;
|
|
67
|
-
};
|
package/_lib/useInterval.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2023
|
|
3
|
-
* @author: izzetseydaoglu
|
|
4
|
-
* @last-modified: 29.01.2024 04:09
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// source: https://overreacted.io/making-setinterval-declarative-with-react-hooks/
|
|
8
|
-
|
|
9
|
-
import { useEffect, useRef } from "react";
|
|
10
|
-
|
|
11
|
-
export function useInterval(callback: any, delay: any) {
|
|
12
|
-
const savedCallback = useRef<any>(null);
|
|
13
|
-
|
|
14
|
-
// Remember the latest callback.
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
savedCallback.current = callback;
|
|
17
|
-
}, [callback]);
|
|
18
|
-
|
|
19
|
-
// Set up the interval.
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
function tick() {
|
|
22
|
-
savedCallback && savedCallback.current && savedCallback.current();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (delay !== null) {
|
|
26
|
-
const id = setInterval(tick, delay);
|
|
27
|
-
return () => clearInterval(id);
|
|
28
|
-
}
|
|
29
|
-
}, [delay]);
|
|
30
|
-
}
|