triafly-ui-kit 1.0.23 → 1.0.25

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 (181) hide show
  1. package/dist/_virtual/_commonjsHelpers.js +6 -0
  2. package/dist/_virtual/index.js +7 -0
  3. package/dist/_virtual/index2.js +7 -0
  4. package/dist/_virtual/index3.js +4 -0
  5. package/dist/_virtual/papaparse.min.js +7 -0
  6. package/dist/_virtual/papaparse.min2.js +4 -0
  7. package/dist/_virtual/react-paginate.js +7 -0
  8. package/dist/_virtual/react-paginate2.js +4 -0
  9. package/dist/assets/fonts/FiraCode-Regular.ttf +0 -0
  10. package/dist/assets/fonts/Manrope-Bold.ttf +0 -0
  11. package/dist/assets/fonts/Manrope-Regular.ttf +0 -0
  12. package/dist/assets/fonts/Manrope-SemiBold.ttf +0 -0
  13. package/dist/assets/fonts/RobotoSlab-SemiBold.ttf +0 -0
  14. package/dist/assets/src/components/Ui/Accordeon/Accordeon.css +1 -0
  15. package/dist/assets/src/components/Ui/Alert/Alert.css +1 -0
  16. package/dist/assets/src/components/Ui/Avatar/Avatar.css +1 -0
  17. package/dist/assets/src/components/Ui/Badge/Badge.module.css +1 -0
  18. package/dist/assets/src/components/Ui/Button/Button.css +1 -0
  19. package/dist/assets/src/components/Ui/ButtonsArray/ButtonsArray.css +1 -0
  20. package/dist/assets/src/components/Ui/Checkbox/Checkbox.css +1 -0
  21. package/dist/assets/src/components/Ui/CliTextareaInput/CliTextareaInput.css +1 -0
  22. package/dist/assets/src/components/Ui/CustomLink/CustomLink.css +1 -0
  23. package/dist/assets/src/components/Ui/DatePicker/DatePicker.css +1 -0
  24. package/dist/assets/src/components/Ui/DropdownInput/DropdownInput.css +1 -0
  25. package/dist/assets/src/components/Ui/DropdownMenu/DropdownMenu.css +1 -0
  26. package/dist/assets/src/components/Ui/FileUpload/FileUpload.css +1 -0
  27. package/dist/assets/src/components/Ui/Form/FormRoot/Form.css +1 -0
  28. package/dist/assets/src/components/Ui/Loader/Loader.css +1 -0
  29. package/dist/assets/src/components/Ui/ModalWindow/ModalWindow.css +1 -0
  30. package/dist/assets/src/components/Ui/Pagination/Pagination.css +1 -0
  31. package/dist/assets/src/components/Ui/Radio/Radio.css +1 -0
  32. package/dist/assets/src/components/Ui/SearchInput/SearchInput.css +1 -0
  33. package/dist/assets/src/components/Ui/Skeleton/Skeleton.module.css +1 -0
  34. package/dist/assets/src/components/Ui/Switch/Switch.css +1 -0
  35. package/dist/assets/src/components/Ui/Table/Table.css +1 -0
  36. package/dist/assets/src/components/Ui/Tabs/Tabs.css +1 -0
  37. package/dist/assets/src/components/Ui/TextInput/TextInput.css +1 -0
  38. package/dist/assets/src/components/Ui/TextareaInput/TextareaInput.css +1 -0
  39. package/dist/assets/src/components/Ui/Tooltip/Tooltip.css +1 -0
  40. package/dist/assets/src/components/Ui/Tooltip/Tooltip.stories.module.css +1 -0
  41. package/dist/assets/src/context/ToastContext/ToastContext.module.css +1 -0
  42. package/dist/components/Ui/Accordeon/Accordeon.js +34 -0
  43. package/dist/components/Ui/Accordeon/Accordeon.stories.js +72 -0
  44. package/dist/components/Ui/Accordeon/index.js +4 -0
  45. package/dist/components/Ui/Alert/Alert.js +15 -0
  46. package/dist/components/Ui/Alert/index.js +4 -0
  47. package/dist/components/Ui/Avatar/Avatar.js +11 -0
  48. package/dist/components/Ui/Avatar/index.js +4 -0
  49. package/dist/components/Ui/Badge/Badge.js +30 -0
  50. package/dist/components/Ui/Badge/index.js +4 -0
  51. package/dist/components/Ui/Button/Button.js +50 -0
  52. package/dist/components/Ui/Button/index.js +4 -0
  53. package/dist/components/Ui/ButtonsArray/ButtonsArray.js +29 -0
  54. package/dist/components/Ui/ButtonsArray/ButtonsArray.stories.js +78 -0
  55. package/dist/components/Ui/ButtonsArray/index.js +4 -0
  56. package/dist/components/Ui/Checkbox/Checkbox.js +40 -0
  57. package/dist/components/Ui/Checkbox/Checkbox.stories.js +120 -0
  58. package/dist/components/Ui/Checkbox/index.js +4 -0
  59. package/dist/components/Ui/CliTextareaInput/CliTextareaInput.js +122 -0
  60. package/dist/components/Ui/CliTextareaInput/index.js +23 -0
  61. package/dist/components/Ui/CliTextareaInput/utils/escapeHtml/escapeHtml.js +4 -0
  62. package/dist/components/Ui/CliTextareaInput/utils/fixJson/fixJson.js +12 -0
  63. package/dist/components/Ui/CliTextareaInput/utils/highlightSyntax/highlightSyntax.js +20 -0
  64. package/dist/components/Ui/CliTextareaInput/utils/highlightSyntax/index.js +4 -0
  65. package/dist/components/Ui/CliTextareaInput/utils/hooks/index.js +17 -0
  66. package/dist/components/Ui/CliTextareaInput/utils/hooks/useFixFormat/index.js +4 -0
  67. package/dist/components/Ui/CliTextareaInput/utils/hooks/useFixFormat/useFixFormat.js +29 -0
  68. package/dist/components/Ui/CliTextareaInput/utils/hooks/useHistoryNavigation/index.js +4 -0
  69. package/dist/components/Ui/CliTextareaInput/utils/hooks/useHistoryNavigation/useHistoryNavigation.js +34 -0
  70. package/dist/components/Ui/CliTextareaInput/utils/hooks/useKeyHandlers/index.js +4 -0
  71. package/dist/components/Ui/CliTextareaInput/utils/hooks/useKeyHandlers/useKeyHandlers.js +45 -0
  72. package/dist/components/Ui/CliTextareaInput/utils/hooks/useLineNumbers/index.js +5 -0
  73. package/dist/components/Ui/CliTextareaInput/utils/hooks/useLineNumbers/useLineNumbers.js +17 -0
  74. package/dist/components/Ui/CliTextareaInput/utils/hooks/useScrollSync/index.js +4 -0
  75. package/dist/components/Ui/CliTextareaInput/utils/hooks/useScrollSync/useScrollSync.js +13 -0
  76. package/dist/components/Ui/CliTextareaInput/utils/hooks/useTextActions/index.js +4 -0
  77. package/dist/components/Ui/CliTextareaInput/utils/hooks/useTextActions/useTextActions.js +37 -0
  78. package/dist/components/Ui/CliTextareaInput/utils/hooks/useTextCoursore/index.js +4 -0
  79. package/dist/components/Ui/CliTextareaInput/utils/hooks/useTextCoursore/useTextCoursore.js +14 -0
  80. package/dist/components/Ui/CliTextareaInput/utils/index.js +21 -0
  81. package/dist/components/Ui/CliTextareaInput/utils/processJson/index.js +4 -0
  82. package/dist/components/Ui/CliTextareaInput/utils/processJson/processJson.js +11 -0
  83. package/dist/components/Ui/CliTextareaInput/utils/processXml/processXml.js +8 -0
  84. package/dist/components/Ui/CliTextareaInput/utils/processYml/processYml.js +27 -0
  85. package/dist/components/Ui/CliTextareaInput/utils/types.js +1 -0
  86. package/dist/components/Ui/CustomLink/CustomLink.js +50 -0
  87. package/dist/components/Ui/CustomLink/index.js +4 -0
  88. package/dist/components/Ui/DatePicker/DatePicker.js +183 -0
  89. package/dist/components/Ui/DatePicker/DatePicker.stories.js +120 -0
  90. package/dist/components/Ui/DropdownInput/DropdownInput.js +92 -0
  91. package/dist/components/Ui/DropdownInput/DropdownInput.stories.js +77 -0
  92. package/dist/components/Ui/DropdownInput/index.js +4 -0
  93. package/dist/components/Ui/DropdownMenu/DropdownMenu.js +84 -0
  94. package/dist/components/Ui/DropdownMenu/DropdownMenu.stories.js +50 -0
  95. package/dist/components/Ui/DropdownMenu/index.js +4 -0
  96. package/dist/components/Ui/FileUpload/FileUpload.js +197 -0
  97. package/dist/components/Ui/FileUpload/fn.js +10 -0
  98. package/dist/components/Ui/FileUpload/index.js +4 -0
  99. package/dist/components/Ui/FileUpload/types.js +1 -0
  100. package/dist/components/Ui/Form/FormContext/FormContext.js +5 -0
  101. package/dist/components/Ui/Form/FormItem/FormItem.js +107 -0
  102. package/dist/components/Ui/Form/FormItem/fn.js +25 -0
  103. package/dist/components/Ui/Form/FormItem/types.js +1 -0
  104. package/dist/components/Ui/Form/FormRoot/FormRoot.js +26 -0
  105. package/dist/components/Ui/Form/FormRoot/index.js +4 -0
  106. package/dist/components/Ui/Form/FormRoot/types.js +1 -0
  107. package/dist/components/Ui/Form/index.js +6 -0
  108. package/dist/components/Ui/Form/useForm/index.js +4 -0
  109. package/dist/components/Ui/Form/useForm/useForm.js +111 -0
  110. package/dist/components/Ui/Form/utils/fn.js +31 -0
  111. package/dist/components/Ui/Form/utils/types.js +1 -0
  112. package/dist/components/Ui/Icons/Icons.js +577 -0
  113. package/dist/components/Ui/Icons/index.js +97 -0
  114. package/dist/components/Ui/Icons/utils/CreateIcon.js +23 -0
  115. package/dist/components/Ui/Loader/Loader.js +7 -0
  116. package/dist/components/Ui/Loader/index.js +4 -0
  117. package/dist/components/Ui/ModalWindow/ModalWindow.js +51 -0
  118. package/dist/components/Ui/ModalWindow/index.js +4 -0
  119. package/dist/components/Ui/Pagination/Pagination.js +39 -0
  120. package/dist/components/Ui/Pagination/index.js +4 -0
  121. package/dist/components/Ui/Radio/Radio.js +31 -0
  122. package/dist/components/Ui/Radio/Radio.stories.js +42 -0
  123. package/dist/components/Ui/Radio/index.js +4 -0
  124. package/dist/components/Ui/SearchInput/SearchData.js +30 -0
  125. package/dist/components/Ui/SearchInput/SearchInput.js +110 -0
  126. package/dist/components/Ui/Skeleton/Skeleton.js +26 -0
  127. package/dist/components/Ui/Skeleton/index.js +4 -0
  128. package/dist/components/Ui/Switch/Switch.js +26 -0
  129. package/dist/components/Ui/Switch/index.js +4 -0
  130. package/dist/components/Ui/Table/MemoizedRow/MemoizedRow.js +50 -0
  131. package/dist/components/Ui/Table/Table.js +161 -0
  132. package/dist/components/Ui/Table/TableTypes.js +1 -0
  133. package/dist/components/Ui/Table/index.js +4 -0
  134. package/dist/components/Ui/Tabs/Tabs.js +25 -0
  135. package/dist/components/Ui/Tabs/Tabs.stories.js +67 -0
  136. package/dist/components/Ui/Tabs/index.js +4 -0
  137. package/dist/components/Ui/TextInput/TextInput.js +86 -0
  138. package/dist/components/Ui/TextInput/TextInput.stories.js +225 -0
  139. package/dist/components/Ui/TextInput/index.js +4 -0
  140. package/dist/components/Ui/TextareaInput/TextareaInput.js +69 -0
  141. package/dist/components/Ui/TextareaInput/TextareaInput.stories.js +19 -0
  142. package/dist/components/Ui/TextareaInput/index.js +4 -0
  143. package/dist/components/Ui/Tooltip/Tooltip.js +93 -0
  144. package/dist/components/Ui/Tooltip/Tooltip.stories.js +87 -0
  145. package/dist/components/Ui/Tooltip/index.js +4 -0
  146. package/dist/context/ToastContext/ToastContext.js +38 -0
  147. package/dist/context/ToastContext/index.js +5 -0
  148. package/dist/context/TriaflyContext/TriaflyContext.types.js +1 -0
  149. package/dist/context/TriaflyContext/TriaflyProvider.js +27 -0
  150. package/dist/context/TriaflyContext/hooks/index.js +8 -0
  151. package/dist/context/TriaflyContext/hooks/useBreakpointValue/index.js +4 -0
  152. package/dist/context/TriaflyContext/hooks/useBreakpointValue/useBreakpointValue.js +11 -0
  153. package/dist/context/TriaflyContext/hooks/useModal/index.js +4 -0
  154. package/dist/context/TriaflyContext/hooks/useModal/useModal.js +16 -0
  155. package/dist/context/TriaflyContext/hooks/useTheme/index.js +4 -0
  156. package/dist/context/TriaflyContext/hooks/useTheme/useTheme.js +17 -0
  157. package/dist/context/TriaflyContext/index.js +12 -0
  158. package/dist/main.d.ts +1229 -0
  159. package/dist/main.js +162 -0
  160. package/dist/node_modules/classnames/index.js +42 -0
  161. package/dist/node_modules/fast-deep-equal/index.js +31 -0
  162. package/dist/node_modules/papaparse/papaparse.min.js +421 -0
  163. package/dist/node_modules/react-paginate/dist/react-paginate.js +259 -0
  164. package/dist/src/components/Ui/Badge/Badge.module.scss.js +30 -0
  165. package/dist/src/components/Ui/Skeleton/Skeleton.module.scss.js +9 -0
  166. package/dist/src/components/Ui/Tooltip/Tooltip.stories.module.css.js +15 -0
  167. package/dist/src/context/ToastContext/ToastContext.module.scss.js +9 -0
  168. package/dist/styles/_mixins.scss +22 -0
  169. package/dist/styles/fix.scss +4 -0
  170. package/dist/styles/main.scss +27 -0
  171. package/dist/styles/reset.scss +106 -0
  172. package/dist/styles/typography.scss +102 -0
  173. package/dist/styles/variables.scss +278 -0
  174. package/dist/vite-env.d.js +1 -0
  175. package/package.json +6 -2
  176. package/src/styles/_mixins.scss +22 -0
  177. package/src/styles/fix.scss +4 -0
  178. package/src/styles/main.scss +27 -0
  179. package/src/styles/reset.scss +106 -0
  180. package/src/styles/typography.scss +102 -0
  181. package/src/styles/variables.scss +278 -0
@@ -0,0 +1,197 @@
1
+ import { jsxs as i, jsx as a } from "react/jsx-runtime";
2
+ import { forwardRef as Y, useState as w, useRef as F, useCallback as P, useImperativeHandle as R } from "react";
3
+ import b from "../../../_virtual/papaparse.min.js";
4
+ import '../../../assets/src/components/Ui/FileUpload/FileUpload.css';/* empty css */
5
+ import { Button as V } from "../Button/Button.js";
6
+ import { IconFile as E } from "../Icons/Icons.js";
7
+ import { Loader as C } from "../Loader/Loader.js";
8
+ import { formatFileSize as ee, SIZE_UNITS as le } from "./fn.js";
9
+ const ae = Y(
10
+ ({
11
+ acceptedFormats: _ = [".csv", ".pdf", ".jpg", ".png", ".xlsx"],
12
+ maxSize: v = 7,
13
+ sizeUnit: N = "MB",
14
+ multiple: x = !1,
15
+ onFilesChange: d,
16
+ onError: s,
17
+ parserCsv: $ = !1,
18
+ onReset: h,
19
+ visibilityFileUpload: W = !0,
20
+ onVisibilityChange: c,
21
+ onChange: m,
22
+ isDisabled: p = !1,
23
+ hasError: A = !1,
24
+ errorMessage: S,
25
+ label: k,
26
+ isNotDeleteElement: H
27
+ }, O) => {
28
+ const [f, T] = w([]), [U, B] = w(!1), [D, n] = w(""), L = F(null), [Z, g] = w(!1), q = P(() => {
29
+ T([]), n(""), L.current && (L.current.value = ""), h == null || h(), m == null || m([]), d == null || d([], []), c == null || c(!0);
30
+ }, [h, d, c]);
31
+ R(O, () => ({
32
+ reset: q,
33
+ getFiles: () => f.map((e) => e.file),
34
+ getParsedData: () => f.map((e) => e.parsedData)
35
+ }));
36
+ const G = v * le[N], J = P(
37
+ async (e) => $ && e.name.endsWith(".csv") ? new Promise((o, r) => {
38
+ b.parse(e, {
39
+ complete: (u) => {
40
+ u.errors.length && r(new Error("Ошибка при парсинге CSV файла")), o(u.data);
41
+ },
42
+ error: () => {
43
+ r(new Error("Не удалось прочитать CSV файл"));
44
+ },
45
+ skipEmptyLines: !0
46
+ });
47
+ }) : [],
48
+ [$]
49
+ ), M = async (e) => {
50
+ if (!e.target.files || p) return;
51
+ n("");
52
+ const o = Array.from(e.target.files), r = [];
53
+ B(!0);
54
+ try {
55
+ for (const l of o) {
56
+ const y = _.some(
57
+ (t) => l.name.toLowerCase().endsWith(t.replace(".", ""))
58
+ ), X = l.size <= G;
59
+ if (f.some(
60
+ (t) => t.file.name === l.name && t.file.size === l.size && t.file.lastModified === l.lastModified
61
+ )) {
62
+ s == null || s(`Файл "${l.name}" уже загружен`), n(`Файл "${l.name}" уже загружен`);
63
+ continue;
64
+ }
65
+ if (!y) {
66
+ const t = `Неподдерживаемый формат: ${l.name}`;
67
+ s == null || s(t), n(`Неподдерживаемый формат: ${l.name}`);
68
+ continue;
69
+ }
70
+ if (!X) {
71
+ const t = `Файл слишком большой (максимум ${v} ${N}): ${l.name}`;
72
+ s == null || s(t), n(`Файл слишком большой (максимум ${v} ${N}): ${l.name}`);
73
+ continue;
74
+ }
75
+ try {
76
+ const t = $ ? await J(l) : void 0;
77
+ r.push({ file: l, parsedData: t });
78
+ } catch (t) {
79
+ const z = t instanceof Error ? t.message : "Неизвестная ошибка";
80
+ s == null || s(z), r.push({
81
+ file: l,
82
+ error: z,
83
+ isLoading: !1
84
+ });
85
+ }
86
+ }
87
+ T((l) => x ? [...l, ...r] : r);
88
+ const I = (x ? [...f, ...r] : r).filter((l) => !l.error);
89
+ m == null || m(I.map((l) => l.file)), d == null || d(
90
+ I.map((l) => l.file),
91
+ $ ? I.map((l) => l.parsedData).filter(Boolean) : void 0
92
+ ), I.length > 0 && (c == null || c(!1));
93
+ } finally {
94
+ B(!1);
95
+ }
96
+ }, j = (e) => {
97
+ e.preventDefault(), g(!0);
98
+ }, K = (e) => {
99
+ e.preventDefault(), g(!1);
100
+ }, Q = (e) => {
101
+ if (e.preventDefault(), n(""), g(!1), e.dataTransfer.files && e.dataTransfer.files.length > 0) {
102
+ if (!_.some(
103
+ (u) => e.dataTransfer.files[0].name.toLowerCase().endsWith(u.replace(".", ""))
104
+ )) {
105
+ n(`Неподдерживаемый формат: ${e.dataTransfer.files[0].name}`);
106
+ return;
107
+ }
108
+ const r = {
109
+ target: { files: e.dataTransfer.files }
110
+ };
111
+ M(r);
112
+ }
113
+ };
114
+ return /* @__PURE__ */ i("div", { className: "file-upload", children: [
115
+ k && /* @__PURE__ */ a("label", { className: "form-item-label", children: k }),
116
+ W && /* @__PURE__ */ a("div", { children: U ? /* @__PURE__ */ i("div", { className: "file-upload__loading", children: [
117
+ /* @__PURE__ */ a("div", { style: { position: "relative", height: "40px", width: "40px" }, children: /* @__PURE__ */ a(C, { size: 40 }) }),
118
+ /* @__PURE__ */ a("span", { children: "Файл загружается..." })
119
+ ] }) : /* @__PURE__ */ i(
120
+ "label",
121
+ {
122
+ htmlFor: "fileInput",
123
+ className: `file-upload__label ${p ? "disabled" : ""}`,
124
+ children: [
125
+ /* @__PURE__ */ a(
126
+ "input",
127
+ {
128
+ ref: L,
129
+ type: "file",
130
+ id: "fileInput",
131
+ multiple: !1,
132
+ accept: _.join(","),
133
+ onChange: M,
134
+ className: "file-upload__input",
135
+ disabled: p
136
+ }
137
+ ),
138
+ /* @__PURE__ */ i(
139
+ "div",
140
+ {
141
+ onDragEnter: j,
142
+ onDragOver: j,
143
+ onDragLeave: K,
144
+ onDrop: Q,
145
+ className: `file-upload__drop-area ${Z ? "dragging" : ""} ${D ? "error" : ""} ${p ? "disabled" : ""}`,
146
+ children: [
147
+ /* @__PURE__ */ a("p", { children: "Перетащите или выберите файлы чтобы загрузить" }),
148
+ /* @__PURE__ */ a(
149
+ V,
150
+ {
151
+ onClick: () => {
152
+ var e;
153
+ return !p && ((e = document.getElementById("fileInput")) == null ? void 0 : e.click());
154
+ },
155
+ label: "Выбрать файлы",
156
+ type: "button",
157
+ className: "file-upload__select-btn",
158
+ isDisabled: p
159
+ }
160
+ ),
161
+ /* @__PURE__ */ i("div", { className: "file-upload__formats", children: [
162
+ /* @__PURE__ */ i("span", { children: [
163
+ "Поддерживаемые форматы: ",
164
+ _.join(", ")
165
+ ] }),
166
+ /* @__PURE__ */ i("span", { children: [
167
+ "Максимальный размер: ",
168
+ v,
169
+ " ",
170
+ N
171
+ ] })
172
+ ] }),
173
+ (D || A && S) && /* @__PURE__ */ a("span", { style: { color: "red" }, children: D || S })
174
+ ]
175
+ }
176
+ )
177
+ ]
178
+ }
179
+ ) }),
180
+ f.length > 0 && /* @__PURE__ */ a("div", { className: "file-upload__files-list", children: /* @__PURE__ */ a("ul", { children: f == null ? void 0 : f.map((e, o) => /* @__PURE__ */ i("li", { className: "file-upload__file-item", children: [
181
+ /* @__PURE__ */ i("div", { className: "file-upload__file-info", children: [
182
+ /* @__PURE__ */ a("div", { className: "file-upload__box-icon", children: /* @__PURE__ */ a(E, { className: "icon" }) }),
183
+ /* @__PURE__ */ i("div", { className: "file-upload__block-text", children: [
184
+ /* @__PURE__ */ a("span", { className: "file-upload__file-name", children: e.file.name }),
185
+ /* @__PURE__ */ a("span", { className: "file-upload__file-size", children: ee(e.file.size) })
186
+ ] }),
187
+ e.error && /* @__PURE__ */ a("span", { className: "file-upload__file-error", children: e.error })
188
+ ] }),
189
+ null
190
+ ] }, `${e.file.name}-${o}`)) }) })
191
+ ] });
192
+ }
193
+ );
194
+ ae.displayName = "FileUpload";
195
+ export {
196
+ ae as FileUpload
197
+ };
@@ -0,0 +1,10 @@
1
+ const r = {
2
+ B: 1,
3
+ KB: 1024,
4
+ MB: 1048576,
5
+ GB: 1073741824
6
+ }, i = (B) => B < r.KB ? `${B} B` : B < r.MB ? `${(B / r.KB).toFixed(2)} KB` : B < r.GB ? `${(B / r.MB).toFixed(2)} MB` : `${(B / r.GB).toFixed(2)} GB`;
7
+ export {
8
+ r as SIZE_UNITS,
9
+ i as formatFileSize
10
+ };
@@ -0,0 +1,4 @@
1
+ import { FileUpload as l } from "./FileUpload.js";
2
+ export {
3
+ l as FileUpload
4
+ };
@@ -0,0 +1,5 @@
1
+ import { createContext as t } from "react";
2
+ const e = t(null);
3
+ export {
4
+ e as FormContext
5
+ };
@@ -0,0 +1,107 @@
1
+ import { jsx as k } from "react/jsx-runtime";
2
+ import d, { useContext as A, useMemo as C, useEffect as E, useCallback as I } from "react";
3
+ import { FormContext as f } from "../FormContext/FormContext.js";
4
+ import { validateRule as D } from "../utils/fn.js";
5
+ import { getChildType as R } from "./fn.js";
6
+ const N = d.memo(
7
+ ({
8
+ name: t,
9
+ children: r,
10
+ rules: c,
11
+ label: h,
12
+ isDisabled: p,
13
+ style: b,
14
+ classNameItem: m
15
+ }) => {
16
+ const e = A(f), [, v] = d.useReducer((a) => a + 1, 0), u = p || (e == null ? void 0 : e.disabled), s = C(() => Array.isArray(t) ? t : [t], [t]);
17
+ E(() => {
18
+ if (e)
19
+ return e.setFieldRules(s, c || []), e.subscribe(s, v);
20
+ }, [s, c, e]);
21
+ const n = e == null ? void 0 : e.getFieldValue(s), l = e == null ? void 0 : e.getFieldError(s), o = I(
22
+ (a) => {
23
+ if (!u && (e == null || e.setFieldValue(s, a), c)) {
24
+ const i = c.map((F) => D(F, a)).filter(Boolean);
25
+ e == null || e.setFieldError(s, i);
26
+ }
27
+ },
28
+ [s, c, u]
29
+ ), g = R(r), y = C(() => {
30
+ const a = {
31
+ name: s,
32
+ label: h,
33
+ isDisabled: u,
34
+ hasError: !!(l != null && l.length),
35
+ errorMessage: l == null ? void 0 : l[0]
36
+ };
37
+ switch (g) {
38
+ case "TextareaInput":
39
+ return {
40
+ ...a,
41
+ value: n || "",
42
+ onChange: o
43
+ };
44
+ case "DropdownInput":
45
+ return {
46
+ ...a,
47
+ value: n,
48
+ onChange: o
49
+ };
50
+ case "TextInput":
51
+ return {
52
+ ...a,
53
+ value: n || "",
54
+ onChange: (i) => o(i.target.value)
55
+ };
56
+ case "Checkbox":
57
+ return {
58
+ ...a,
59
+ isChecked: !!n,
60
+ onChange: (i) => o(i.target.checked)
61
+ };
62
+ case "Radio":
63
+ return {
64
+ ...a,
65
+ radioId: `radio-${Array.isArray(t) ? t.join("-") : t}`,
66
+ value: r.props.value,
67
+ isChecked: n === r.props.value,
68
+ onChange: () => o(r.props.value)
69
+ };
70
+ case "SearchInput":
71
+ return {
72
+ ...a,
73
+ value: n,
74
+ onChange: o
75
+ };
76
+ case "Switch":
77
+ return {
78
+ ...a,
79
+ isChecked: !!n,
80
+ onChange: (i) => o(i.target.checked)
81
+ };
82
+ case "FileUpload":
83
+ return {
84
+ ...a,
85
+ value: Array.isArray(n) ? n : [],
86
+ onChange: (i) => o(i)
87
+ };
88
+ default:
89
+ return a;
90
+ }
91
+ }, [
92
+ s,
93
+ h,
94
+ l,
95
+ n,
96
+ g,
97
+ o,
98
+ r.props.value,
99
+ u
100
+ ]);
101
+ return /* @__PURE__ */ k("div", { className: m, style: b, children: d.cloneElement(r, y) });
102
+ },
103
+ (t, r) => t.name === r.name && t.rules === r.rules && t.label === r.label && t.isDisabled === r.isDisabled
104
+ );
105
+ export {
106
+ N as FormItem
107
+ };
@@ -0,0 +1,25 @@
1
+ const p = (e) => {
2
+ var n, r, a, f;
3
+ if (typeof e == "string")
4
+ return e;
5
+ if (typeof e == "object" && e !== null) {
6
+ const t = e;
7
+ if (t.$$typeof === Symbol.for("react.forward_ref")) {
8
+ const o = e;
9
+ return o.displayName || ((n = o.render) == null ? void 0 : n.displayName) || ((r = o.render) == null ? void 0 : r.name) || "ForwardRefComponent";
10
+ }
11
+ if (t.$$typeof === Symbol.for("react.memo")) {
12
+ const o = e;
13
+ return o.displayName || ((a = o.type) == null ? void 0 : a.displayName) || ((f = o.type) == null ? void 0 : f.name) || "MemoComponent";
14
+ }
15
+ }
16
+ if (typeof e == "function") {
17
+ const t = e;
18
+ return t.displayName || t.name || "FunctionComponent";
19
+ }
20
+ return "UnknownComponent";
21
+ }, m = (e) => e.props.name || p(e.type);
22
+ export {
23
+ m as getChildType,
24
+ p as getComponentName
25
+ };
@@ -0,0 +1,26 @@
1
+ import { jsx as a } from "react/jsx-runtime";
2
+ import '../../../../assets/src/components/Ui/Form/FormRoot/Form.css';/* empty css */
3
+ import { useMemo as l } from "react";
4
+ import { FormContext as f } from "../FormContext/FormContext.js";
5
+ import { FormItem as i } from "../FormItem/FormItem.js";
6
+ import { useForm as p } from "../useForm/useForm.js";
7
+ const v = ({ form: m, children: c, onFinish: o, disabled: t = !1 }) => {
8
+ const n = p()[0], s = l(() => {
9
+ const r = m || n;
10
+ return r.disabled = t, r;
11
+ }, [m, n, t]), u = async (r) => {
12
+ r.preventDefault();
13
+ try {
14
+ if (t) return;
15
+ const e = await s.validateFields();
16
+ o == null || o(e);
17
+ } catch (e) {
18
+ console.error("Form submission error:", e);
19
+ }
20
+ };
21
+ return /* @__PURE__ */ a(f.Provider, { value: s || null, children: /* @__PURE__ */ a("form", { onSubmit: u, children: c }) });
22
+ };
23
+ v.Item = i;
24
+ export {
25
+ v as Form
26
+ };
@@ -0,0 +1,4 @@
1
+ import { Form as m } from "./FormRoot.js";
2
+ export {
3
+ m as Form
4
+ };
@@ -0,0 +1,6 @@
1
+ import { Form as m } from "./FormRoot/FormRoot.js";
2
+ import { useForm as f } from "./useForm/useForm.js";
3
+ export {
4
+ m as Form,
5
+ f as useForm
6
+ };
@@ -0,0 +1,4 @@
1
+ import { useForm as e } from "./useForm.js";
2
+ export {
3
+ e as useForm
4
+ };
@@ -0,0 +1,111 @@
1
+ import { useRef as y, useCallback as g } from "react";
2
+ import { normalizePath as i, validateRule as b, getFieldKey as f, getByPath as k, getNestedValue as V, setByPath as v } from "../utils/fn.js";
3
+ class O extends Error {
4
+ constructor(l) {
5
+ super("Form validation failed"), this.errorFields = l, this.name = "FormValidationError";
6
+ }
7
+ }
8
+ function N() {
9
+ const a = y({}), l = y({}), p = y({}), o = y({}), d = g((t) => {
10
+ const r = i(t), e = /* @__PURE__ */ new Set();
11
+ e.add(r.join("."));
12
+ for (let n = 1; n < r.length; n++)
13
+ e.add(r.slice(0, n).join("."));
14
+ e.forEach((n) => {
15
+ var s;
16
+ (s = o.current[n]) == null || s.forEach((c) => c());
17
+ });
18
+ }, []), m = g(
19
+ async (t, r, e) => {
20
+ if (!e) return [];
21
+ const n = (await Promise.all(e.map((c) => b(c, r)))).filter(Boolean), s = f(t);
22
+ return l.current[s] = n, d(s), n;
23
+ },
24
+ [d]
25
+ ), w = g(
26
+ async (t) => {
27
+ const r = t || Object.keys(p.current).map((n) => n.includes(".") ? n.split(".") : n), e = {};
28
+ if (await Promise.all(
29
+ r.map(async (n) => {
30
+ const s = i(n), c = f(s), u = p.current[c] || [], F = k(a.current, s), h = await m(s, F, u);
31
+ h.length && (e[c] = h);
32
+ })
33
+ ), Object.keys(e).length)
34
+ throw new O(
35
+ Object.entries(e).map(([n, s]) => ({
36
+ name: n,
37
+ errors: s
38
+ }))
39
+ );
40
+ return { ...a.current };
41
+ },
42
+ [m]
43
+ ), E = (t) => Array.isArray(t) ? t : typeof t == "string" && t.includes(".") ? t.split(".") : [t], j = y({
44
+ resetFields: () => {
45
+ a.current = {}, l.current = {}, Object.keys(o.current).forEach(d);
46
+ },
47
+ setFieldsValue: (t) => {
48
+ const r = { ...a.current };
49
+ Object.entries(t).forEach(([e, n]) => {
50
+ const s = E(e);
51
+ v(r, s, n);
52
+ }), a.current = r, Object.keys(t).forEach((e) => {
53
+ d(Array.isArray(e) ? e.join(".") : e);
54
+ });
55
+ },
56
+ setFieldValue: (t, r) => {
57
+ const e = i(t), n = JSON.parse(JSON.stringify(a.current));
58
+ let s = n;
59
+ for (let c = 0; c < e.length - 1; c++) {
60
+ const u = e[c];
61
+ s[u] || (s[u] = {}), s = s[u];
62
+ }
63
+ s[e[e.length - 1]] = r, a.current = n, d(e);
64
+ },
65
+ getFieldValue: (t) => {
66
+ const r = i(t);
67
+ return V(a.current, r);
68
+ },
69
+ getFieldsValue: () => ({ ...a.current }),
70
+ submit: async () => {
71
+ await j.validateFields();
72
+ },
73
+ validateFields: w,
74
+ getFieldError: (t) => {
75
+ const r = f(i(t));
76
+ return l.current[r] || [];
77
+ },
78
+ setFieldError: (t, r) => {
79
+ const e = f(i(t));
80
+ l.current[e] = r, d(e);
81
+ },
82
+ getFieldRules: (t) => {
83
+ const r = f(i(t));
84
+ return p.current[r] || [];
85
+ },
86
+ setFieldRules: (t, r) => {
87
+ const e = f(i(t));
88
+ p.current[e] = r;
89
+ },
90
+ subscribe: (t, r) => {
91
+ const e = i(t), n = e.join(".");
92
+ if (o.current[n] || (o.current[n] = /* @__PURE__ */ new Set()), o.current[n].add(r), e.length > 1) {
93
+ const c = e.slice(0, -1).join(".");
94
+ o.current[c] || (o.current[c] = /* @__PURE__ */ new Set());
95
+ const u = () => r();
96
+ return o.current[c].add(u), () => {
97
+ var F, h;
98
+ (F = o.current[n]) == null || F.delete(r), (h = o.current[c]) == null || h.delete(u);
99
+ };
100
+ }
101
+ return () => {
102
+ var s;
103
+ return (s = o.current[n]) == null ? void 0 : s.delete(r);
104
+ };
105
+ }
106
+ }).current;
107
+ return [j];
108
+ }
109
+ export {
110
+ N as useForm
111
+ };
@@ -0,0 +1,31 @@
1
+ const f = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, c = (t, s) => {
2
+ const e = s == null ? "" : String(s);
3
+ return t.required && e.trim() === "" ? t.message || "Это поле обязательно" : t.pattern && e && !t.pattern.test(e) ? t.message || "Некорректный формат" : t.type === "email" && e && !f.test(e) ? t.message || "Некорректный email" : t.validator ? t.validator(s) : typeof t.min == "number" && e.length < t.min ? t.message || `Минимум ${t.min} символов` : typeof t.max == "number" && e.length > t.max ? t.message || `Максимум ${t.max} символов` : null;
4
+ }, a = (t) => Array.isArray(t) ? t : [t], g = (t) => Array.isArray(t) ? t.join(".") : t, m = (t, s, e) => {
5
+ const n = a(s);
6
+ let r = t;
7
+ for (let i = 0; i < n.length - 1; i++) {
8
+ const o = n[i];
9
+ (!r[o] || typeof r[o] != "object") && (r[o] = {}), r = r[o];
10
+ }
11
+ r[n[n.length - 1]] = e;
12
+ }, p = (t, s) => {
13
+ const e = a(s);
14
+ let n = t;
15
+ for (const r of e) {
16
+ if (!n || typeof n != "object") return;
17
+ n = n[r];
18
+ }
19
+ return n;
20
+ }, y = (t, s) => s.reduce((e, n) => {
21
+ if (e && typeof e == "object" && n in e)
22
+ return e[n];
23
+ }, t);
24
+ export {
25
+ p as getByPath,
26
+ g as getFieldKey,
27
+ y as getNestedValue,
28
+ a as normalizePath,
29
+ m as setByPath,
30
+ c as validateRule
31
+ };