@sydsoft/base 1.47.0 → 1.49.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.
Files changed (151) hide show
  1. package/README.md +8 -1
  2. package/{dist/esm → _dist}/_lib/baseFunctions.d.ts +0 -1
  3. package/{dist/esm → _dist}/_lib/baseFunctions.js +25 -38
  4. package/{dist/esm → _dist}/_lib/inputMask.js +66 -69
  5. package/{dist/esm → _dist}/_lib/listFunctions.js +12 -13
  6. package/_dist/_lib/storage/cookies.d.ts +4 -0
  7. package/_dist/_lib/storage/cookies.js +33 -0
  8. package/_dist/_lib/storage/encData.js +41 -0
  9. package/{dist/esm → _dist}/_lib/storage/localStorage.js +10 -10
  10. package/{dist/esm → _dist}/_lib/storage/sessionStorage.js +10 -10
  11. package/{dist/esm → _dist}/_lib/useInterval.js +5 -5
  12. package/{dist/esm → _dist}/alert/index.js +28 -30
  13. package/_dist/box/Box.js +14 -0
  14. package/_dist/box/BoxContent.js +5 -0
  15. package/_dist/box/BoxFooter.js +10 -0
  16. package/_dist/box/BoxHeader.js +10 -0
  17. package/_dist/countDown/index.js +92 -0
  18. package/{dist/esm → _dist}/dateTime/index.js +25 -31
  19. package/_dist/form/Button.js +82 -0
  20. package/_dist/form/Checkbox.js +22 -0
  21. package/_dist/form/Dialog.js +53 -0
  22. package/_dist/form/Form.js +10 -0
  23. package/_dist/form/FormOlustur.js +50 -0
  24. package/{dist/esm → _dist}/form/Input.js +57 -56
  25. package/_dist/form/Label.js +7 -0
  26. package/{dist/esm → _dist}/form/SearchableInput.d.ts +0 -1
  27. package/_dist/form/SearchableInput.js +260 -0
  28. package/_dist/form/UploadBase.js +84 -0
  29. package/_dist/grid/index.js +96 -0
  30. package/{dist/esm → _dist}/icon/icons.js +1 -1
  31. package/{dist/esm → _dist}/icon/index.d.ts +1 -1
  32. package/_dist/icon/index.js +34 -0
  33. package/_dist/menu/index.js +50 -0
  34. package/_dist/modal/index.js +64 -0
  35. package/{dist/esm → _dist}/popover/index.js +100 -100
  36. package/_dist/tooltip/index.js +202 -0
  37. package/_lib/baseFunctions.ts +94 -0
  38. package/_lib/inputMask.ts +257 -0
  39. package/_lib/listFunctions.ts +106 -0
  40. package/_lib/storage/cookies.ts +39 -0
  41. package/_lib/storage/encData.ts +41 -0
  42. package/_lib/storage/localStorage.ts +67 -0
  43. package/_lib/storage/sessionStorage.ts +67 -0
  44. package/_lib/useInterval.ts +30 -0
  45. package/alert/index.module.css +119 -0
  46. package/alert/index.tsx +131 -0
  47. package/box/Box.module.css +153 -0
  48. package/box/Box.tsx +33 -0
  49. package/box/BoxContent.tsx +18 -0
  50. package/box/BoxFooter.tsx +25 -0
  51. package/box/BoxHeader.tsx +46 -0
  52. package/box/index.ts +10 -0
  53. package/countDown/index.tsx +116 -0
  54. package/dateTime/index.ts +79 -0
  55. package/form/Button.tsx +143 -0
  56. package/form/Checkbox.tsx +48 -0
  57. package/form/Dialog.tsx +109 -0
  58. package/form/Form.tsx +19 -0
  59. package/form/FormOlustur.tsx +105 -0
  60. package/form/Input.tsx +364 -0
  61. package/form/Label.tsx +20 -0
  62. package/form/SearchableInput.tsx +406 -0
  63. package/form/UploadBase.tsx +133 -0
  64. package/form/index.ts +10 -0
  65. package/form/styles/Button.module.css +145 -0
  66. package/form/styles/Input.module.css +221 -0
  67. package/form/styles/Label.module.css +31 -0
  68. package/form/styles/SearchableInput.module.css +80 -0
  69. package/global.d.ts +9 -0
  70. package/grid/index.module.css +805 -0
  71. package/grid/index.tsx +171 -0
  72. package/icon/icons.tsx +33 -0
  73. package/icon/index.tsx +95 -0
  74. package/icon/mui.tsx +5932 -0
  75. package/index.ts +21 -0
  76. package/menu/index.module.css +92 -0
  77. package/menu/index.tsx +143 -0
  78. package/modal/index.module.css +77 -0
  79. package/modal/index.tsx +106 -0
  80. package/npm_recovery_codes.txt +5 -0
  81. package/package.json +18 -11
  82. package/popover/index.module.css +89 -0
  83. package/popover/index.tsx +392 -0
  84. package/tooltip/index.tsx +216 -0
  85. package/tsconfig.json +24 -0
  86. package/dist/esm/_lib/storage/cookies.d.ts +0 -4
  87. package/dist/esm/_lib/storage/cookies.js +0 -34
  88. package/dist/esm/_lib/storage/encData.js +0 -43
  89. package/dist/esm/box/Box.js +0 -15
  90. package/dist/esm/box/BoxContent.js +0 -7
  91. package/dist/esm/box/BoxFooter.js +0 -8
  92. package/dist/esm/box/BoxHeader.js +0 -9
  93. package/dist/esm/countDown/index.js +0 -97
  94. package/dist/esm/form/Button.js +0 -76
  95. package/dist/esm/form/Checkbox.js +0 -23
  96. package/dist/esm/form/Dialog.js +0 -40
  97. package/dist/esm/form/Form.js +0 -12
  98. package/dist/esm/form/FormOlustur.js +0 -52
  99. package/dist/esm/form/Label.js +0 -9
  100. package/dist/esm/form/SearchableInput.js +0 -272
  101. package/dist/esm/form/UploadBase.js +0 -86
  102. package/dist/esm/grid/index.js +0 -97
  103. package/dist/esm/icon/index.js +0 -26
  104. package/dist/esm/menu/index.js +0 -52
  105. package/dist/esm/modal/index.js +0 -66
  106. package/dist/esm/tooltip/index.js +0 -119
  107. /package/{dist/esm → _dist}/_lib/inputMask.d.ts +0 -0
  108. /package/{dist/esm → _dist}/_lib/listFunctions.d.ts +0 -0
  109. /package/{dist/esm → _dist}/_lib/storage/encData.d.ts +0 -0
  110. /package/{dist/esm → _dist}/_lib/storage/localStorage.d.ts +0 -0
  111. /package/{dist/esm → _dist}/_lib/storage/sessionStorage.d.ts +0 -0
  112. /package/{dist/esm → _dist}/_lib/useInterval.d.ts +0 -0
  113. /package/{dist/esm → _dist}/alert/index.d.ts +0 -0
  114. /package/{dist/esm → _dist}/alert/index.module.css +0 -0
  115. /package/{dist/esm → _dist}/box/Box.d.ts +0 -0
  116. /package/{dist/esm → _dist}/box/Box.module.css +0 -0
  117. /package/{dist/esm → _dist}/box/BoxContent.d.ts +0 -0
  118. /package/{dist/esm → _dist}/box/BoxFooter.d.ts +0 -0
  119. /package/{dist/esm → _dist}/box/BoxHeader.d.ts +0 -0
  120. /package/{dist/esm → _dist}/box/index.d.ts +0 -0
  121. /package/{dist/esm → _dist}/box/index.js +0 -0
  122. /package/{dist/esm → _dist}/countDown/index.d.ts +0 -0
  123. /package/{dist/esm → _dist}/dateTime/index.d.ts +0 -0
  124. /package/{dist/esm → _dist}/form/Button.d.ts +0 -0
  125. /package/{dist/esm → _dist}/form/Checkbox.d.ts +0 -0
  126. /package/{dist/esm → _dist}/form/Dialog.d.ts +0 -0
  127. /package/{dist/esm → _dist}/form/Form.d.ts +0 -0
  128. /package/{dist/esm → _dist}/form/FormOlustur.d.ts +0 -0
  129. /package/{dist/esm → _dist}/form/Input.d.ts +0 -0
  130. /package/{dist/esm → _dist}/form/Label.d.ts +0 -0
  131. /package/{dist/esm → _dist}/form/UploadBase.d.ts +0 -0
  132. /package/{dist/esm → _dist}/form/index.d.ts +0 -0
  133. /package/{dist/esm → _dist}/form/index.js +0 -0
  134. /package/{dist/esm → _dist}/form/styles/Button.module.css +0 -0
  135. /package/{dist/esm → _dist}/form/styles/Input.module.css +0 -0
  136. /package/{dist/esm → _dist}/form/styles/Label.module.css +0 -0
  137. /package/{dist/esm → _dist}/form/styles/SearchableInput.module.css +0 -0
  138. /package/{dist/esm → _dist}/grid/index.d.ts +0 -0
  139. /package/{dist/esm → _dist}/grid/index.module.css +0 -0
  140. /package/{dist/esm → _dist}/icon/icons.d.ts +0 -0
  141. /package/{dist/esm → _dist}/icon/mui.d.ts +0 -0
  142. /package/{dist/esm → _dist}/icon/mui.js +0 -0
  143. /package/{dist/esm → _dist}/index.d.ts +0 -0
  144. /package/{dist/esm → _dist}/index.js +0 -0
  145. /package/{dist/esm → _dist}/menu/index.d.ts +0 -0
  146. /package/{dist/esm → _dist}/menu/index.module.css +0 -0
  147. /package/{dist/esm → _dist}/modal/index.d.ts +0 -0
  148. /package/{dist/esm → _dist}/modal/index.module.css +0 -0
  149. /package/{dist/esm → _dist}/popover/index.d.ts +0 -0
  150. /package/{dist/esm → _dist}/popover/index.module.css +0 -0
  151. /package/{dist/esm → _dist}/tooltip/index.d.ts +0 -0
@@ -0,0 +1,202 @@
1
+ import React, { memo, useEffect } from "react";
2
+ export const Tooltip = memo(function MemoFunction({ children, title, position = "top", arrow = false, distance = 5, ...other }) {
3
+ useEffect(() => {
4
+ if (typeof window === "undefined")
5
+ return null;
6
+ const cssCheck = document.getElementsByClassName("stooltip_css")[0];
7
+ if (!cssCheck) {
8
+ const head = document.getElementsByTagName('head')[0];
9
+ const s = document.createElement('style');
10
+ s.setAttribute('type', 'text/css');
11
+ s.classList.add("stooltip_css");
12
+ s.appendChild(document.createTextNode(tooltipCss));
13
+ head.appendChild(s);
14
+ }
15
+ return () => tooltipSil();
16
+ }, []);
17
+ const tooltipEkle = (e) => {
18
+ tooltipSil();
19
+ const tooltip = document.createElement("div");
20
+ tooltip.innerHTML = title;
21
+ tooltip.classList.add("stooltip");
22
+ document.body.appendChild(tooltip);
23
+ tooltipPosition({ target: e.currentTarget, position: position });
24
+ };
25
+ const tooltipSil = () => {
26
+ const check = document.body.getElementsByClassName("stooltip")[0];
27
+ if (check)
28
+ check.remove();
29
+ };
30
+ const tooltipPosition = ({ target, position }) => {
31
+ const tooltip = document.body.getElementsByClassName("stooltip")[0];
32
+ if (tooltip) {
33
+ const arrowMargin = (arrow) ? 5 : 0;
34
+ const margin = distance + arrowMargin;
35
+ if (arrow)
36
+ tooltip.classList.add("arrow");
37
+ const targetPosition = target.getBoundingClientRect();
38
+ const tooltipPosition = tooltip.getBoundingClientRect();
39
+ const style = [];
40
+ if (position === "top" || position === "bottom") {
41
+ if (position === "top") {
42
+ if ((targetPosition.top - tooltipPosition.height - margin) < 0) {
43
+ style.push("top:" + (targetPosition.bottom + margin) + "px");
44
+ tooltip.classList.add("bottom");
45
+ }
46
+ else {
47
+ style.push("top:" + (targetPosition.top - tooltipPosition.height - margin) + "px");
48
+ tooltip.classList.add("top");
49
+ }
50
+ }
51
+ if (position === "bottom") {
52
+ if ((targetPosition.bottom + tooltipPosition.height + margin) > window.innerHeight) {
53
+ style.push("top:" + (targetPosition.top - tooltipPosition.height - margin) + "px");
54
+ tooltip.classList.add("top");
55
+ }
56
+ else {
57
+ style.push("top:" + (targetPosition.bottom + margin) + "px");
58
+ tooltip.classList.add("bottom");
59
+ }
60
+ }
61
+ // if ((targetPosition.left - tooltipPosition.width) < 0) {
62
+ if ((targetPosition.left + (targetPosition.width / 2) - (tooltipPosition.width / 2)) < 0) {
63
+ style.push("left:2px");
64
+ tooltip.classList.add("start");
65
+ }
66
+ else if ((targetPosition.left + (targetPosition.width / 2) + tooltipPosition.width) > window.innerWidth) {
67
+ style.push("right:2px");
68
+ tooltip.classList.add("end");
69
+ }
70
+ else {
71
+ style.push("left:" + (targetPosition.left + (targetPosition.width / 2)) + "px");
72
+ style.push("transform:translate(-50%,0)");
73
+ tooltip.classList.add("center");
74
+ }
75
+ }
76
+ if (position === "left" || position === "right") {
77
+ if (position === "left") {
78
+ if ((targetPosition.left - tooltipPosition.width - margin) < 0) {
79
+ style.push("left:" + (targetPosition.right + margin) + "px");
80
+ tooltip.classList.add("right");
81
+ }
82
+ else {
83
+ style.push("left:" + (targetPosition.left - tooltipPosition.width - margin) + "px");
84
+ tooltip.classList.add("left");
85
+ }
86
+ }
87
+ if (position === "right") {
88
+ if ((targetPosition.left + (targetPosition.width / 2) + tooltipPosition.width + margin) > window.innerWidth) {
89
+ style.push("left:" + (targetPosition.left - tooltipPosition.width - margin) + "px");
90
+ tooltip.classList.add("left");
91
+ }
92
+ else {
93
+ style.push("left:" + (targetPosition.right + margin) + "px");
94
+ tooltip.classList.add("right");
95
+ }
96
+ }
97
+ if ((targetPosition.top + (targetPosition.height / 2) - (tooltipPosition.height / 2)) < 0) {
98
+ style.push("top:2px");
99
+ tooltip.classList.add("start");
100
+ }
101
+ else if ((targetPosition.top + (targetPosition.height / 2) + (tooltipPosition.height / 2)) > window.innerHeight) {
102
+ style.push("bottom:2px");
103
+ tooltip.classList.add("end");
104
+ }
105
+ else {
106
+ style.push("top:" + (targetPosition.top + (targetPosition.height / 2)) + "px");
107
+ style.push("transform:translate(0,-50%)");
108
+ tooltip.classList.add("center");
109
+ }
110
+ }
111
+ tooltip.setAttribute("style", style.join(";"));
112
+ }
113
+ };
114
+ return React.cloneElement(children, {
115
+ onMouseEnter: tooltipEkle,
116
+ onMouseLeave: tooltipSil,
117
+ onMouseDown: tooltipSil,
118
+ ...other
119
+ });
120
+ });
121
+ const tooltipCss = `
122
+ .stooltip {
123
+ position: fixed;
124
+ display: flex;
125
+ align-items: center;
126
+ justify-content: center;
127
+ background-color: #1a1a1a;
128
+ color: rgba(255,255,255,0.9);
129
+ text-align: center;
130
+ font-size: 0.9rem;
131
+ font-weight:400;
132
+ padding: 5px 10px;
133
+ border-radius: 8px;
134
+ z-index: 1000000;
135
+ opacity: 0.9;
136
+ pointer-events: none;
137
+ /*transition: all 0.1s;*/
138
+ white-space:pre-line;
139
+ max-width: 300px;
140
+ animation: stooltip_fadein 0.7s;
141
+ }
142
+
143
+ .stooltip.arrow:after {
144
+ content: "";
145
+ position: absolute;
146
+ margin-left: -5px;
147
+ border-width: 5px;
148
+ border-style: solid;
149
+ }
150
+
151
+ .stooltip.arrow.top:after {
152
+ top: 100%;
153
+ border-color: #1a1a1a transparent transparent transparent;
154
+ }
155
+
156
+ .stooltip.arrow.top.start:after { left: 15px;}
157
+
158
+ .stooltip.arrow.top.center:after { left: 50%;}
159
+
160
+ .stooltip.arrow.top.end:after { right: 15px;}
161
+
162
+
163
+ .stooltip.arrow.bottom:after {
164
+ bottom: 100%;
165
+ border-color: transparent transparent #1a1a1a transparent;
166
+ }
167
+
168
+ .stooltip.arrow.bottom.start:after { left: 15px;}
169
+
170
+ .stooltip.arrow.bottom.center:after { left: 50%;}
171
+
172
+ .stooltip.bottom.end:after { right: 15px;}
173
+
174
+ .stooltip.arrow.left:after {
175
+ margin-left: -1px;
176
+ left: 100%;
177
+ border-color: transparent transparent transparent #1a1a1a;
178
+ }
179
+
180
+ .stooltip.arrow.left.start:after { top: 5px;}
181
+
182
+ .stooltip.arrow.left.center:after { top: 50%; margin-top: -5px;}
183
+
184
+ .stooltip.arrow.left.end:after { bottom: 15px;}
185
+
186
+ .stooltip.arrow.right:after {
187
+ margin-right: -1px;
188
+ right: 100%;
189
+ border-color: transparent #1a1a1a transparent transparent;
190
+ }
191
+
192
+ .stooltip.arrow.right.start:after { top: 5px;}
193
+
194
+ .stooltip.arrow.right.center:after { top: 50%; margin-top: -5px;}
195
+
196
+ .stooltip.arrow.right.end:after { bottom: 15px;}
197
+
198
+ @keyframes stooltip_fadein {
199
+ from { opacity: 0; }
200
+ to { opacity: 0.85; }
201
+ }
202
+ `;
@@ -0,0 +1,94 @@
1
+ export const isDev = !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
2
+ export const isServerReq = (context: any) => !context?.req?.url?.startsWith('/_next');
3
+ export const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
4
+
5
+ export const padNumber = (num: number, padLength = 2, padString = '0') => String(num).padStart(padLength, padString);
6
+
7
+ export function inputTumuBuyukCevir(e: React.ChangeEvent<HTMLInputElement>) {
8
+ if (e?.target && e?.target?.setSelectionRange) {
9
+ const start = e.target.selectionStart;
10
+ const end = e.target.selectionEnd;
11
+ e.target.value = e.target.value.toString().toLocaleUpperCase('tr-TR');
12
+ e.target.setSelectionRange(start, end);
13
+ }
14
+ }
15
+
16
+ export function inputTumuKucukCevir(e: React.ChangeEvent<HTMLInputElement>) {
17
+ if (e?.target && e?.target?.setSelectionRange) {
18
+ const start = e.target.selectionStart;
19
+ const end = e.target.selectionEnd;
20
+ e.target.value = e.target.value.toString().toLocaleLowerCase('tr-TR');
21
+ e.target.setSelectionRange(start, end);
22
+ }
23
+ }
24
+
25
+ export const convertLowerCase = (text: any = '') => text.toString().toLocaleLowerCase('tr-TR');
26
+
27
+ export const convertForSearch = (value: string) => {
28
+ let data = value?.toString().toLocaleLowerCase('tr-TR');
29
+ data = data.replace(/ö/g, 'o');
30
+ data = data.replace(/ç/g, 'c');
31
+ data = data.replace(/ş/g, 's');
32
+ data = data.replace(/ı/g, 'i');
33
+ data = data.replace(/ğ/g, 'g');
34
+ data = data.replace(/ü/g, 'u');
35
+ data = data.replace(/[^a-z\d]/g, ''); // %_- are allowed
36
+ data = data.replace(/^\s+|\s+$/g, '');
37
+ return data;
38
+ };
39
+
40
+ export function convertForSEO(e: React.ChangeEvent<HTMLInputElement>) {
41
+ if (e?.target && e?.target?.setSelectionRange) {
42
+ const start = e.target.selectionStart;
43
+ const end = e.target.selectionEnd;
44
+ let string = e.target.value.toString().toLocaleLowerCase('tr');
45
+ const turkce = [' ', '-', 'ş', 'Ş', 'ı', 'ü', 'Ü', 'ö', 'Ö', 'ç', 'Ç', 'ş', 'Ş', 'ı', 'ğ', 'Ğ', 'İ', 'ö', 'Ö', 'Ç', 'ç', 'ü', 'Ü', 'â', 'ê', 'Â', '“', '”'];
46
+ const duzgun = ['-', '-', 's', 'S', 'i', 'u', 'U', 'o', 'O', 'c', 'C', 's', 'S', 'i', 'g', 'G', 'I', 'o', 'O', 'C', 'c', 'u', 'U', 'a', 'ê', 'a', '', ''];
47
+ for (let i = 0; i < turkce.length; i++) {
48
+ string = string.split(turkce[i]).join(duzgun[i]);
49
+ }
50
+ string = string.replace(/[^a-z0-9\-_şıüğçİŞĞÜÇ]+/gi, '_');
51
+ string = string.replace(/_+/g, '_');
52
+ string = string.replace(/^-/, '_');
53
+ string = string.replace(/-$/, '_');
54
+
55
+ e.target.value = string;
56
+ e.target.setSelectionRange(start, end);
57
+ }
58
+ }
59
+
60
+ export function getDomain(context: any = null) {
61
+ let url = '';
62
+ if (context) {
63
+ url = context.req.headers.host;
64
+ } else if (typeof window !== 'undefined') {
65
+ url = window.location.hostname;
66
+ }
67
+
68
+ if (url.length) {
69
+ const parts = url.split('.').reverse();
70
+ const cnt = parts.length;
71
+ if (cnt >= 3) {
72
+ // see if the second level domain is a common SLD.
73
+ if (parts[1].match(/^(com|edu|gov|net|mil|org|nom|co|name|info|biz)$/i)) {
74
+ const domain = parts[2] + '.' + parts[1] + '.' + parts[0];
75
+ return domain.split(':')[0];
76
+ }
77
+ }
78
+ const domain = parts[1] + '.' + parts[0];
79
+ return domain.split(':')[0];
80
+ }
81
+ return url;
82
+ }
83
+
84
+ export const uniqueID = (key = '', length = 16) => {
85
+ return (
86
+ key +
87
+ parseInt(
88
+ Math.ceil(Math.random() * Date.now())
89
+ .toPrecision(length)
90
+ .toString()
91
+ .replace('.', '')
92
+ )
93
+ );
94
+ };
@@ -0,0 +1,257 @@
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
+ };
@@ -0,0 +1,106 @@
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
+
@@ -0,0 +1,39 @@
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
+ };