ar-design 0.2.44 → 0.2.46

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.
@@ -56,9 +56,13 @@
56
56
 
57
57
  .ar-table > .content > table > thead > tr > th,
58
58
  .ar-table > .content > table > tbody > tr > td {
59
- height: 3rem;
60
- padding: 0 1.5rem;
59
+ height: 2.5rem;
61
60
  }
61
+ .ar-table > .content > table > thead > tr > th,
62
+ .ar-table > .content > table > tbody > tr > td > .table-cell {
63
+ padding: 0 1rem;
64
+ }
65
+
62
66
  .ar-table > .content > table > thead > tr > th.min-w,
63
67
  .ar-table > .content > table > tbody > tr > td.min-w {
64
68
  min-width: 150px;
@@ -157,7 +161,10 @@
157
161
  text-wrap: nowrap;
158
162
  }
159
163
 
160
- .ar-table > .content > table > tbody > tr > td > span.subitem-open-button {
164
+ .ar-table > .content > table > tbody > tr > td > .subitem-open-button-wrapper {
165
+ padding: 0 1rem;
166
+ }
167
+ .ar-table > .content > table > tbody > tr > td > .subitem-open-button-wrapper > span {
161
168
  display: inline-block;
162
169
  width: 0.75rem;
163
170
  height: 0.75rem;
@@ -168,10 +175,10 @@
168
175
  cursor: pointer;
169
176
  transition: transform 100ms ease-in-out;
170
177
  }
171
- .ar-table > .content > table > tbody > tr > td > span.subitem-open-button.opened {
178
+ .ar-table > .content > table > tbody > tr > td > .subitem-open-button-wrapper > span.opened {
172
179
  transform: rotate(135deg);
173
180
  }
174
- .ar-table > .content > table > tbody > tr > td > span.subitem-open-button.passive {
181
+ .ar-table > .content > table > tbody > tr > td > .subitem-open-button-wrapper > span.passive {
175
182
  border-top-color: var(--gray-300);
176
183
  border-right-color: var(--gray-300);
177
184
  cursor: no-drop;
@@ -8,20 +8,23 @@
8
8
  display: flex;
9
9
  flex-direction: row;
10
10
  gap: 0.25rem;
11
+ margin-top: -1px;
12
+ border: solid 1px transparent;
13
+ border-left-color: var(--gray-300);
14
+ border-right-color: var(--gray-300);
15
+ border-bottom-color: var(--gray-300);
11
16
  }
12
17
  .ar-text-editor > iframe {
13
18
  width: 100%;
14
- border-bottom: none;
15
19
  border-bottom-left-radius: 0 !important;
16
20
  border-bottom-right-radius: 0 !important;
17
21
  }
18
22
  .ar-text-editor > .resize {
19
23
  position: relative;
20
- background-color: var(--gray-200);
24
+ background-color: var(--gray-100);
21
25
  width: 100%;
22
26
  height: 1.5rem;
23
27
  border: solid 1px transparent;
24
- border-top-color: var(--gray-400);
25
28
  border-left-color: var(--gray-300);
26
29
  border-right-color: var(--gray-300);
27
30
  border-bottom-color: var(--gray-300);
@@ -36,7 +39,7 @@
36
39
  left: 50%;
37
40
  transform: translate(-50%, -50%);
38
41
  background-color: var(--gray-500);
39
- width: 2rem;
42
+ width: 1.5rem;
40
43
  height: 0.1rem;
41
44
  box-shadow: 0px -5px 0 0px var(--gray-500), 0px 5px 0 0px var(--gray-500);
42
45
  }
@@ -7,6 +7,8 @@ export type SearchedParam = {
7
7
  type ImportActionType = {
8
8
  tooltip: string;
9
9
  allowedTypes?: AllowedTypes[];
10
+ prefixItem?: React.ReactNode;
11
+ suffixItem?: React.ReactNode;
10
12
  onClick: (formData: FormData | undefined, files: File[]) => void;
11
13
  };
12
14
  type CreateActionType = {
@@ -28,7 +30,7 @@ interface IProps<T> extends IChildren {
28
30
  pagination?: {
29
31
  totalRecords: number;
30
32
  perPage: number;
31
- onChange: (currentPage: number) => void;
33
+ onChange?: (currentPage: number) => void;
32
34
  };
33
35
  config?: {
34
36
  isServerSide?: boolean;
@@ -36,7 +38,11 @@ interface IProps<T> extends IChildren {
36
38
  scroll?: {
37
39
  maxHeight: number;
38
40
  };
39
- subrowSelector?: string;
41
+ subrow?: {
42
+ openAutomatically?: boolean;
43
+ selector?: string;
44
+ button?: boolean;
45
+ };
40
46
  };
41
47
  }
42
48
  export default IProps;
@@ -52,7 +52,7 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
52
52
  filterCleaner: () => {
53
53
  if (config.isServerSide) {
54
54
  setSearchedParams({});
55
- pagination && pagination.onChange(1);
55
+ // pagination && pagination.onChange(1);
56
56
  }
57
57
  else {
58
58
  setSearchedText({});
@@ -133,7 +133,7 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
133
133
  _searchTimeOut.current = setTimeout(() => {
134
134
  setSearchedParams((prev) => ({ ...prev, [event.target.name]: event.target.value }));
135
135
  setCurrentPage(1);
136
- pagination && pagination.onChange(1);
136
+ // pagination && pagination.onChange(1);
137
137
  }, 750);
138
138
  }
139
139
  else {
@@ -234,7 +234,7 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
234
234
  setSearchedText(checkboxSelectedParams);
235
235
  }
236
236
  setCurrentPage(1);
237
- pagination && pagination.onChange(1);
237
+ // pagination && pagination.onChange(1);
238
238
  // Filters...
239
239
  // setSelectedfilterCheckboxItems((prev) => {
240
240
  // debugger;
@@ -401,7 +401,7 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
401
401
  pagination?.perPage ?? getData().length,
402
402
  " agreement")),
403
403
  React.createElement(Pagination, { totalRecords: pagination.totalRecords, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
404
- config.isServerSide && pagination.onChange(currentPage);
404
+ // config.isServerSide && pagination.onChange(currentPage);
405
405
  setCurrentPage(currentPage);
406
406
  } })))));
407
407
  });
@@ -19,7 +19,9 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
19
19
  const _searchTextInputs = useRef([]);
20
20
  const _searchTimeOut = useRef(null);
21
21
  // variables
22
- const _subrowSelector = config.subrowSelector ?? "subitems";
22
+ const _subrowOpenAutomatically = config.subrow?.openAutomatically ?? false;
23
+ const _subrowSelector = config.subrow?.selector ?? "subitems";
24
+ const _subrowButton = config.subrow?.button ?? false;
23
25
  // className
24
26
  const _tableClassName = ["ar-table", "scroll"];
25
27
  // states
@@ -113,7 +115,8 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
113
115
  clearTimeout(_searchTimeOut.current);
114
116
  _searchTimeOut.current = setTimeout(() => {
115
117
  setSearchedParams((prev) => ({ ...prev, [event.target.name]: event.target.value }));
116
- pagination && pagination.onChange(1);
118
+ if (pagination && pagination.onChange)
119
+ pagination.onChange(1);
117
120
  }, 750);
118
121
  }
119
122
  else {
@@ -164,10 +167,15 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
164
167
  if (value.length === 0)
165
168
  return true;
166
169
  else {
167
- return value.some((v) => Object.entries(_itemValue ?? {}).some(([_, objValue]) => String(objValue).toLocaleLowerCase().includes(v.toLocaleLowerCase())));
170
+ return value.some((v) => {
171
+ if (Array.isArray(_itemValue)) {
172
+ return Object.values(_itemValue?.[0] ?? {}).some((objValue) => {
173
+ return String(objValue).toLocaleLowerCase().includes(String(v).toLocaleLowerCase());
174
+ });
175
+ }
176
+ });
168
177
  }
169
178
  }
170
- return Object.entries(_itemValue ?? {}).some(([_, objValue]) => String(objValue).toLocaleLowerCase().includes(value.toLocaleLowerCase()));
171
179
  }
172
180
  if (Array.isArray(_itemValue)) {
173
181
  console.log("Buradasın", _itemValue);
@@ -177,6 +185,22 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
177
185
  };
178
186
  const getData = useMemo(() => {
179
187
  let _data = [...data];
188
+ if (_subrowOpenAutomatically) {
189
+ data.forEach((item, index) => {
190
+ if (_subrowSelector in item) {
191
+ setShowSubitems((prev) => ({
192
+ ...prev,
193
+ [`${index}`]: !prev[`${index}`],
194
+ }));
195
+ }
196
+ else {
197
+ setShowSubitems((prev) => ({
198
+ ...prev,
199
+ [`${index}`]: false,
200
+ }));
201
+ }
202
+ });
203
+ }
180
204
  if (searchedText && Object.keys(searchedText).length > 0) {
181
205
  _data = _data.filter((item) => deepSearch(item, searchedText));
182
206
  setTotalRecords(_data.length);
@@ -193,7 +217,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
193
217
  setTimeout(() => handleScroll(), 0);
194
218
  return _data;
195
219
  }, [data, searchedText, currentPage]);
196
- const renderCell = (item, c, cIndex, index) => {
220
+ const renderCell = (item, c, cIndex, index, depth) => {
197
221
  let render;
198
222
  // `c.key` bir string ise
199
223
  if (typeof c.key !== "object") {
@@ -206,8 +230,8 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
206
230
  render = c.render ? c.render(item) : _item[c.key.nestedKey];
207
231
  }
208
232
  }
209
- // Diğer durumlarda `null` döndür
210
233
  else {
234
+ // Diğer durumlarda `null` döndür
211
235
  render = null;
212
236
  }
213
237
  const _className = [];
@@ -217,9 +241,11 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
217
241
  _className.push(`align-content-${c.config.alignContent}`);
218
242
  if (c.config?.textWrap)
219
243
  _className.push(`text-${c.config.textWrap}`);
220
- return (React.createElement("td", { key: `cell-${index}-${cIndex}`, className: _className.join(" "), style: c.config?.width ? { minWidth: c.config.width, maxWidth: c.config.width } : {}, "data-sticky-position": c.config?.sticky }, React.isValidElement(render) ? render : String(render)));
244
+ return (React.createElement("td", { key: `cell-${index}-${cIndex}`, className: _className.join(" "), style: c.config?.width ? { minWidth: c.config.width, maxWidth: c.config.width, paddingLeft: `${depth}rem` } : {}, "data-sticky-position": c.config?.sticky },
245
+ React.createElement("div", { className: "table-cell" }, React.isValidElement(render) ? render : String(render))));
221
246
  };
222
247
  const renderRow = (item, index) => {
248
+ const isHasSubitems = _subrowSelector in item;
223
249
  return (React.createElement(React.Fragment, null,
224
250
  React.createElement("tr", { key: `row-${index}` },
225
251
  selections && (React.createElement("td", { className: "sticky-left", "data-sticky-position": "left" },
@@ -229,31 +255,34 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
229
255
  else
230
256
  setSelectionItems((prev) => prev.filter((_item) => _item !== item));
231
257
  } }))),
232
- data.some((item) => _subrowSelector in item) && (React.createElement("td", { style: { width: 1 } }, item[_subrowSelector] && (React.createElement("span", { className: `subitem-open-button ${showSubitems[index] && "opened"}`, onClick: () => {
233
- setShowSubitems((prev) => ({
234
- ...prev,
235
- [`${index}`]: !prev[`${index}`],
236
- }));
237
- } })))),
238
- columns.map((c, cIndex) => renderCell(item, c, cIndex, index))),
258
+ _subrowButton && isHasSubitems ? (React.createElement("td", null, item[_subrowSelector] && (React.createElement("div", { className: "subitem-open-button-wrapper" },
259
+ React.createElement("span", { className: `subitem-open-button ${(showSubitems[index] && "opened") ?? ""}`, onClick: () => {
260
+ console.log(showSubitems);
261
+ setShowSubitems((prev) => ({
262
+ ...prev,
263
+ [`${index}`]: !prev[`${index}`],
264
+ }));
265
+ } }))))) : _subrowButton ? (React.createElement("td", { style: { width: 0, minWidth: 0 } })) : null,
266
+ columns.map((c, cIndex) => renderCell(item, c, cIndex, index, 0))),
239
267
  showSubitems[index] && item[_subrowSelector] && (React.createElement(SubitemList, { items: item[_subrowSelector], columns: columns, index: index, depth: 1.5 }))));
240
268
  };
241
269
  const SubitemList = ({ items, columns, index, depth }) => {
242
270
  return items.map((subitem, subindex) => {
243
- const x = subitem[_subrowSelector];
271
+ const _subitem = subitem[_subrowSelector];
244
272
  return (React.createElement(React.Fragment, null,
245
273
  React.createElement("tr", { key: `subitem-${index}-${subindex}` },
246
- data.some((item) => _subrowSelector in item) && (React.createElement("td", { style: { paddingLeft: `${depth * 1.5}rem` } },
247
- React.createElement("span", { className: `subitem-open-button ${showSubitems[`${index}.${subindex}`] && "opened"} ${!x && "passive"}`, onClick: () => {
248
- if (!x)
249
- return;
250
- setShowSubitems((prev) => ({
251
- ...prev,
252
- [`${index}.${subindex}`]: !prev[`${index}.${subindex}`],
253
- }));
254
- } }))),
255
- columns.map((c, cIndex) => renderCell(subitem, c, cIndex, subindex))),
256
- showSubitems[`${index}.${subindex}`] && x && (React.createElement(SubitemList, { items: x, columns: columns, index: subindex, depth: depth * 1.5 }))));
274
+ _subrowSelector in subitem && _subrowButton && (React.createElement("td", { style: { paddingLeft: `${depth}rem` } },
275
+ React.createElement("div", { className: "subitem-open-button-wrapper" },
276
+ React.createElement("span", { className: `${(showSubitems[`${index}.${subindex}`] && "opened") ?? ""} ${!_subitem && "passive"}`, onClick: () => {
277
+ if (!_subitem)
278
+ return;
279
+ setShowSubitems((prev) => ({
280
+ ...prev,
281
+ [`${index}.${subindex}`]: !prev[`${index}.${subindex}`],
282
+ }));
283
+ } })))),
284
+ columns.map((c, cIndex) => renderCell(subitem, c, cIndex, subindex, depth * 1.5))),
285
+ showSubitems[`${index}.${subindex}`] && _subitem && (React.createElement(SubitemList, { items: _subitem, columns: columns, index: subindex, depth: depth * 1.5 }))));
257
286
  });
258
287
  };
259
288
  // useEffects
@@ -287,7 +316,8 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
287
316
  setSearchedText((prev) => ({ ...prev, ...checkboxSelectedParams }));
288
317
  }
289
318
  setCurrentPage(1);
290
- pagination && pagination.onChange(1);
319
+ if (pagination && pagination.onChange)
320
+ pagination.onChange(1);
291
321
  }, [checkboxSelectedParams]);
292
322
  useEffect(() => {
293
323
  if (!selections)
@@ -307,10 +337,13 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
307
337
  React.createElement("h3", null, title),
308
338
  description && React.createElement("h5", null, description)),
309
339
  React.createElement("div", { className: "actions" }, actions && (React.createElement(React.Fragment, null,
310
- actions.import && (React.createElement(Popover, { title: "\u0130\u00E7eri Aktar", message: "Se\u00E7ti\u011Finiz dosyalar\u0131 uygulamaya y\u00FCkleyebilirsiniz. Bu i\u015Flem, dosyalardaki verileri sistemimize aktar\u0131r ve verilerle i\u015Flem yapman\u0131za olanak tan\u0131r.", content: React.createElement(Upload, { text: "Belge Y\u00FCkleyin", allowedTypes: actions.import.allowedTypes, file: files, onChange: (formData, files) => {
311
- setFormData(formData);
312
- setFiles(files);
313
- }, multiple: true }), onConfirm: (confirm) => {
340
+ actions.import && (React.createElement(Popover, { title: "\u0130\u00E7eri Aktar", message: "Se\u00E7ti\u011Finiz dosyalar\u0131 uygulamaya y\u00FCkleyebilirsiniz. Bu i\u015Flem, dosyalardaki verileri sistemimize aktar\u0131r ve verilerle i\u015Flem yapman\u0131za olanak tan\u0131r.", content: React.createElement(React.Fragment, null,
341
+ actions.import.prefixItem,
342
+ React.createElement(Upload, { text: "Belge Y\u00FCkleyin", allowedTypes: actions.import.allowedTypes, file: files, onChange: (formData, files) => {
343
+ setFormData(formData);
344
+ setFiles(files);
345
+ }, multiple: true }),
346
+ actions.import.suffixItem), onConfirm: (confirm) => {
314
347
  if (!confirm) {
315
348
  setFiles([]);
316
349
  return;
@@ -324,7 +357,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
324
357
  React.createElement("table", { ref: ref },
325
358
  React.createElement("thead", null,
326
359
  React.createElement("tr", { key: "selection" },
327
- data.some((item) => _subrowSelector in item) && React.createElement("td", { style: { width: 1 } }),
360
+ _subrowButton && React.createElement("td", { style: { width: 0, minWidth: 0 } }),
328
361
  selections && (React.createElement("th", { className: "selection-col sticky-left", "data-sticky-position": "left" },
329
362
  React.createElement(Checkbox, { variant: "filled", status: "primary", checked: selectAll, onChange: (event) => {
330
363
  if (_checkboxItems.current.length > 0) {
@@ -391,7 +424,8 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
391
424
  pagination?.perPage ?? getData.length,
392
425
  " agreement")),
393
426
  React.createElement(Pagination, { totalRecords: config.isServerSide ? pagination.totalRecords : totalRecords ?? 0, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
394
- config.isServerSide && pagination.onChange(currentPage);
427
+ if (config.isServerSide && pagination && pagination.onChange)
428
+ pagination.onChange(currentPage);
395
429
  setCurrentPage(currentPage);
396
430
  } })))));
397
431
  });
@@ -8,6 +8,8 @@ const TextEditor = ({ name, value, onChange, placeholder, height, multilang, val
8
8
  // refs
9
9
  const _container = useRef(null);
10
10
  const _arIframe = useRef(null);
11
+ const _onChange = useRef(onChange);
12
+ const _onChangeTimeOut = useRef(null);
11
13
  // states
12
14
  const [iframe, setIframe] = useState(null);
13
15
  const [iframeDocument, setIframeDocument] = useState(undefined);
@@ -74,6 +76,10 @@ const TextEditor = ({ name, value, onChange, placeholder, height, multilang, val
74
76
  selection?.addRange(range);
75
77
  }
76
78
  }, [value, iframeDocument]);
79
+ useEffect(() => {
80
+ // onChange değiştiğinde ref'i güncelle
81
+ _onChange.current = onChange;
82
+ }, [onChange]);
77
83
  useEffect(() => {
78
84
  // Iframe yüklendikten sonra çalışacaktır.
79
85
  if (!iframe)
@@ -85,11 +91,15 @@ const TextEditor = ({ name, value, onChange, placeholder, height, multilang, val
85
91
  _iframeDocument.designMode = "on";
86
92
  // Herhangi bir değişikliği izlemek için MutationObserver kullan
87
93
  const observer = new MutationObserver((mutationsList) => {
88
- mutationsList.forEach(() => {
89
- _iframeDocument?.body.innerHTML === "<br>"
90
- ? onChangeRef.current(undefined)
91
- : onChangeRef.current(_iframeDocument.body.innerHTML);
92
- });
94
+ if (_onChangeTimeOut.current)
95
+ clearTimeout(_onChangeTimeOut.current);
96
+ _onChangeTimeOut.current = setTimeout(() => {
97
+ mutationsList.forEach(() => {
98
+ _iframeDocument?.body.innerHTML === "<br>"
99
+ ? _onChange.current(undefined)
100
+ : _onChange.current(_iframeDocument.body.innerHTML);
101
+ });
102
+ }, 750);
93
103
  });
94
104
  // Observer'ı body üzerinde başlat
95
105
  observer.observe(_iframeDocument.body, { childList: true, subtree: true, characterData: true, attributes: true });
@@ -112,16 +122,11 @@ const TextEditor = ({ name, value, onChange, placeholder, height, multilang, val
112
122
  }
113
123
  };
114
124
  }, []);
115
- const onChangeRef = useRef(onChange);
116
- // onChange değiştiğinde ref'i güncelle
117
- useEffect(() => {
118
- onChangeRef.current = onChange;
119
- }, [onChange]);
120
125
  return (React.createElement("div", { ref: _container, className: "ar-text-editor" },
121
- React.createElement("div", { className: "toolbar" }, toolbarButtons.map(({ command, icon, tooltip }) => (React.createElement(Button, { key: command, type: "button", variant: "borderless", status: "secondary", icon: { element: React.createElement(ARIcon, { icon: icon, size: 18, fill: "var(--gray-700)" }) }, tooltip: {
126
+ React.createElement("iframe", { ref: _arIframe, name: name, className: _iframeClassName.map((c) => c).join(" "), height: height }),
127
+ React.createElement("div", { className: "toolbar" }, toolbarButtons.map(({ command, icon, tooltip }) => (React.createElement(Button, { key: command, type: "button", variant: "borderless", status: "secondary", border: { radius: "none" }, icon: { element: React.createElement(ARIcon, { icon: icon, size: 18, fill: "var(--gray-700)" }) }, tooltip: {
122
128
  text: tooltip,
123
129
  }, onClick: () => execCommand(command) })))),
124
- React.createElement("iframe", { ref: _arIframe, name: name, className: _iframeClassName.map((c) => c).join(" "), height: height }),
125
130
  React.createElement("div", { className: "resize", onMouseDown: handleMouseDown }),
126
131
  validation?.text && React.createElement("span", { className: "validation" }, validation.text)));
127
132
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.2.44",
3
+ "version": "0.2.46",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",