ar-design 0.3.47 → 0.3.49

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.
@@ -1,3 +1,9 @@
1
+ .ar-pagination {
2
+ display: flex;
3
+ flex-direction: row;
4
+ align-items: center;
5
+ gap: 0 0.5rem;
6
+ }
1
7
  .ar-pagination > ul {
2
8
  display: flex;
3
9
  flex-direction: row;
@@ -9,7 +15,7 @@
9
15
  display: flex;
10
16
  justify-content: center;
11
17
  align-items: center;
12
- width: 1.75rem;
18
+ min-width: 1.75rem;
13
19
  height: 100%;
14
20
  border-radius: var(--border-radius-pill);
15
21
  box-shadow: 0 0 0 0 rgba(var(--primary-rgb), 0.1);
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useRef, useState } from "react";
1
+ import React, { useEffect, useMemo, useRef, useState } from "react";
2
2
  import "../../../assets/css/components/data-display/diagram/styles.css";
3
3
  import Grid from "../grid-system";
4
4
  import Button from "../../form/button";
@@ -86,13 +86,14 @@ const Diagram = ({ nodes, edges }) => {
86
86
  };
87
87
  const pathData = `M${from.x} ${from.y} C${controlPoint1.x} ${controlPoint1.y}, ${controlPoint2.x} ${controlPoint2.y}, ${to.x} ${to.y}`;
88
88
  return (React.createElement("svg", { key: index, className: "edge" },
89
- React.createElement("path", { ref: _path, d: pathData, fill: "none", stroke: "var(--purple-500)", strokeWidth: 2, strokeDasharray: 10, strokeDashoffset: 10, strokeLinecap: "round", onClick: () => {
90
- setEdges((prev) => prev.filter((x) => x.id !== edge.id));
91
- } },
89
+ React.createElement("path", { ref: _path, d: pathData, fill: "none", stroke: "var(--purple-500)", strokeWidth: 2, strokeDasharray: 10, strokeDashoffset: 10, strokeLinecap: "round" },
92
90
  React.createElement("animate", { attributeName: "stroke-dashoffset", values: `${20 / scale};0`, dur: "1s", repeatCount: "indefinite" }))));
93
91
  });
94
92
  }, [_nodes, _edges, trigger]);
95
93
  const onPanStart = (e) => {
94
+ // Node sürükleniyorsa pan başlatma.
95
+ if (draggedNode)
96
+ return;
96
97
  setPanning(true);
97
98
  setStartPan({ x: e.clientX - pan.x, y: e.clientY - pan.y });
98
99
  };
@@ -169,7 +170,7 @@ const Diagram = ({ nodes, edges }) => {
169
170
  if (closest) {
170
171
  // Yakın port varsa, oraya bağla
171
172
  const newEdge = {
172
- id: _edges[_edges.length - 1]?.id + 1 || 1,
173
+ id: crypto.randomUUID(), // _edges[_edges.length - 1]?.id + 1 || 1,
173
174
  from: { id: drawingEdge.id, port: drawingEdge.port },
174
175
  to: { id: closest.id, port: closest.port },
175
176
  };
@@ -184,15 +185,15 @@ const Diagram = ({ nodes, edges }) => {
184
185
  }
185
186
  else {
186
187
  // Yakın port yoksa yeni node oluştur
187
- const newNodeId = _nodes[_nodes.length - 1]?.id + 1 || 1;
188
+ const newNodeId = crypto.randomUUID(); // _nodes[_nodes.length - 1]?.id + 1 || 1;
188
189
  const newNode = {
189
190
  id: newNodeId,
190
191
  position: mousePos,
191
- data: { label: `Node - ${newNodeId}` },
192
+ data: React.createElement(React.Fragment, null),
192
193
  };
193
194
  const newPort = mousePos.y < drawingEdge.start.y ? "bottom" : "top";
194
195
  const newEdge = {
195
- id: _edges[_edges.length - 1]?.id + 1 || 1,
196
+ id: crypto.randomUUID(), // _edges[_edges.length - 1]?.id + 1 || 1,
196
197
  from: { id: drawingEdge.id, port: drawingEdge.port },
197
198
  to: { id: newNodeId, port: newPort },
198
199
  };
@@ -205,6 +206,10 @@ const Diagram = ({ nodes, edges }) => {
205
206
  setDraggedNode(null);
206
207
  setTrigger((prev) => !prev);
207
208
  };
209
+ // useEffects
210
+ useEffect(() => {
211
+ setEdges([...edges]);
212
+ }, []);
208
213
  return (React.createElement("div", { ref: _arDiagram, className: "ar-diagram", onMouseDown: onPanStart, onMouseMove: (event) => {
209
214
  onPanMove(event);
210
215
  onMouseMove(event);
@@ -225,6 +230,8 @@ const Diagram = ({ nodes, edges }) => {
225
230
  top: node.position.y,
226
231
  }, onMouseDown: (event) => onNodeMouseDown(event, node.id, node.position) },
227
232
  React.createElement("span", { ref: (el) => {
233
+ if (!el)
234
+ return;
228
235
  _arNodes.current[`${node.id}_top`] = el;
229
236
  }, className: "port top", onMouseDown: (event) => {
230
237
  event.stopPropagation();
@@ -238,8 +245,10 @@ const Diagram = ({ nodes, edges }) => {
238
245
  });
239
246
  }
240
247
  } }),
241
- React.createElement("span", null, node.data.label),
248
+ React.createElement("span", null, node.data),
242
249
  React.createElement("span", { ref: (el) => {
250
+ if (!el)
251
+ return;
243
252
  _arNodes.current[`${node.id}_bottom`] = el;
244
253
  }, className: "port bottom", onMouseDown: (event) => {
245
254
  event.stopPropagation();
@@ -70,6 +70,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
70
70
  // states -> Pagination
71
71
  const [totalRecords, setTotalRecords] = useState(0);
72
72
  const [currentPage, setCurrentPage] = useState(1);
73
+ const [selectedPerPage, setSelectedPerPage] = useState(pagination?.perPage ?? 10);
73
74
  if (config && Object.keys(config.scroll || {}).length > 0) {
74
75
  if (_tableContent.current && config.scroll) {
75
76
  if (config.scroll.maxHeight) {
@@ -338,12 +339,12 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
338
339
  setTotalRecords(data.length);
339
340
  }
340
341
  if (pagination && !config.isServerSide) {
341
- const indexOfLastRow = currentPage * pagination.perPage;
342
- const indexOfFirstRow = indexOfLastRow - pagination.perPage;
342
+ const indexOfLastRow = currentPage * selectedPerPage;
343
+ const indexOfFirstRow = indexOfLastRow - selectedPerPage;
343
344
  _data = _data.slice(indexOfFirstRow, indexOfLastRow);
344
345
  }
345
346
  return _data;
346
- }, [data, searchedText, currentPage]);
347
+ }, [data, searchedText, currentPage, selectedPerPage]);
347
348
  const renderRow = (item, index, deph) => {
348
349
  const isHasSubitems = _subrowSelector in item;
349
350
  // TODO: Keylere bakılacak...
@@ -510,6 +511,10 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
510
511
  setTimeout(() => handleScroll(), 0);
511
512
  setCurrentPage(pagination?.currentPage ?? 1);
512
513
  }, [pagination?.currentPage]);
514
+ useLayoutEffect(() => {
515
+ setCurrentPage(1);
516
+ setTimeout(() => handleScroll(), 0);
517
+ }, [selectedPerPage]);
513
518
  return (React.createElement("div", { ref: _tableWrapper, className: _tableClassName.map((c) => c).join(" ") },
514
519
  (title || description || actions || React.Children.count(children) > 0) && (React.createElement("div", { className: "header" },
515
520
  React.createElement("div", { className: "title" },
@@ -636,9 +641,9 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
636
641
  " ",
637
642
  React.createElement("span", null,
638
643
  "of ",
639
- pagination?.perPage ?? getData.length,
644
+ selectedPerPage ?? getData.length,
640
645
  " agreement")),
641
- React.createElement(Pagination, { totalRecords: config.isServerSide ? pagination.totalRecords : totalRecords ?? 0, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
646
+ React.createElement(Pagination, { totalRecords: config.isServerSide ? pagination.totalRecords : totalRecords ?? 0, currentPage: currentPage, perPage: selectedPerPage, onPerPageChange: (perPage) => setSelectedPerPage(perPage), onChange: (currentPage) => {
642
647
  if (config.isServerSide && pagination && pagination.onChange)
643
648
  pagination.onChange(currentPage);
644
649
  setTimeout(() => handleScroll(), 0);
@@ -3,6 +3,7 @@ interface IProps {
3
3
  currentPage: number;
4
4
  totalRecords: number;
5
5
  perPage?: number;
6
+ onPerPageChange: (perPage: number) => void;
6
7
  onChange: (currentPage: number) => void;
7
8
  }
8
9
  export default IProps;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import IProps from "./IProps";
3
- import "../../../assets/css/components/navigation/pagination/pagination.css";
3
+ import "../../../assets/css/components/navigation/pagination/styles.css";
4
4
  declare const Pagination: React.FC<IProps>;
5
5
  export default Pagination;
@@ -1,13 +1,23 @@
1
1
  "use client";
2
2
  import React, { useContext, useEffect, useState } from "react";
3
- import "../../../assets/css/components/navigation/pagination/pagination.css";
3
+ import "../../../assets/css/components/navigation/pagination/styles.css";
4
4
  import { ConfigContext } from "../../../libs/core/application/contexts/Config";
5
- const Pagination = ({ currentPage, totalRecords, perPage, onChange }) => {
5
+ import Select from "../../form/select";
6
+ const perPageOptions = [
7
+ { value: 5, text: "5" },
8
+ { value: 10, text: "10" },
9
+ { value: 15, text: "15" },
10
+ { value: 50, text: "50" },
11
+ { value: 75, text: "75" },
12
+ { value: 100, text: "100" },
13
+ ];
14
+ const Pagination = ({ currentPage, totalRecords, perPage, onPerPageChange, onChange }) => {
6
15
  // context
7
16
  const { config } = useContext(ConfigContext);
8
17
  // states
9
18
  const [pages, setPages] = useState([]);
10
19
  const [totalPageCount, setTotalPageCount] = useState(0);
20
+ const [selectedPerPage, setSelectedPerPage] = useState(perPageOptions.find((x) => x.value === 10));
11
21
  // methods
12
22
  const handlePageChange = (page) => onChange(page);
13
23
  // useEffects
@@ -29,6 +39,10 @@ const Pagination = ({ currentPage, totalRecords, perPage, onChange }) => {
29
39
  setPages(liItems);
30
40
  }, [totalRecords, currentPage, perPage, config.perPage]);
31
41
  return (React.createElement("div", { className: "ar-pagination" },
42
+ React.createElement(Select, { value: selectedPerPage, options: [...perPageOptions, { value: totalRecords, text: "Tümü" }], onChange: (option) => {
43
+ setSelectedPerPage(option);
44
+ onPerPageChange(option?.value);
45
+ } }),
32
46
  React.createElement("ul", null,
33
47
  React.createElement("li", { className: currentPage === 1 ? "passive" : "", onClick: () => {
34
48
  if (currentPage === 1)
@@ -90,24 +90,22 @@ export type PieChartDataType = {
90
90
  text: string;
91
91
  };
92
92
  export type NodeData = {
93
- id: number;
93
+ id: string | number;
94
94
  position: {
95
95
  x: number;
96
96
  y: number;
97
97
  };
98
- data: {
99
- label: string;
100
- };
98
+ data: React.ReactNode;
101
99
  };
102
100
  type Port = "top" | "bottom";
103
101
  export type EdgeData = {
104
- id: number;
102
+ id: string | number;
105
103
  from: {
106
- id: number;
104
+ id: string | number;
107
105
  port: Port;
108
106
  };
109
107
  to: {
110
- id: number;
108
+ id: string | number;
111
109
  port: Port;
112
110
  };
113
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.3.47",
3
+ "version": "0.3.49",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",