aio-entitykit 2.0.0 → 2.0.2

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 (4) hide show
  1. package/d1.css +2 -2
  2. package/index.d.ts +3 -3
  3. package/index.js +42 -31
  4. package/package.json +1 -1
package/d1.css CHANGED
@@ -464,7 +464,7 @@
464
464
  }
465
465
 
466
466
  .d1 .ai-indent-line {
467
- stroke: var(--d1-border-light);
467
+ color: var(--d1-border-light);
468
468
  }
469
469
 
470
470
 
@@ -911,4 +911,4 @@
911
911
  text-align: center;
912
912
  border:1px solid var(--d1-border-medium);
913
913
  padding:0;
914
- }
914
+ }
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type FC, type ReactNode } from "react";
2
- import { type I_table } from './../aio-table';
3
- import type { AIOCordova } from './../aio-cordova';
4
- import { useEntity } from './../aio-entity';
2
+ import { type I_table } from 'aio-table';
3
+ import type { AIOCordova } from 'aio-cordova';
4
+ import { useEntity } from 'aio-entity';
5
5
  import './index.css';
6
6
  type I_option = {
7
7
  text: string;
package/index.js CHANGED
@@ -25,20 +25,20 @@ export const EntityTable = (props) => {
25
25
  const DATE = new AIODate();
26
26
  const { table, moveTo, entity, popup, archive, filteredData } = props;
27
27
  const [showArchive, setShowArchive] = useState(false);
28
- const { getId, data } = entity;
28
+ const { data } = entity;
29
29
  const [selected, setSelected] = useState({});
30
30
  const select = (row) => {
31
31
  if (!props.getSelectedOptions) {
32
32
  return;
33
33
  }
34
- const rowId = entity.getId(row);
34
+ const rowId = entity.id.get(row);
35
35
  const keys = Object.keys(selected);
36
36
  const firstSelected = keys.length ? selected[keys[0]] : undefined;
37
37
  if (firstSelected) {
38
- const firstSelectedParent = entity.getParentByRowId({ rowId: entity.getId(firstSelected), rows: entity.data });
39
- const firstSelectedParentId = firstSelectedParent ? entity.getId(firstSelectedParent) : undefined;
40
- const rowParent = entity.getParentByRowId({ rowId: entity.getId(row), rows: entity.data });
41
- const rowParentId = rowParent ? entity.getId(rowParent) : undefined;
38
+ const firstSelectedParent = entity.getParentByRowId(entity.data, entity.id.get(firstSelected));
39
+ const firstSelectedParentId = firstSelectedParent ? entity.id.get(firstSelectedParent) : undefined;
40
+ const rowParent = entity.getParentByRowId(entity.data, entity.id.get(row));
41
+ const rowParentId = rowParent ? entity.id.get(rowParent) : undefined;
42
42
  if (firstSelectedParentId !== rowParentId) {
43
43
  setSelected({ [rowId]: row });
44
44
  return;
@@ -60,7 +60,7 @@ export const EntityTable = (props) => {
60
60
  }
61
61
  };
62
62
  const canMoveTo = (row) => {
63
- const rowId = entity.getId(row);
63
+ const rowId = entity.id.get(row);
64
64
  if (selected[rowId.toString()]) {
65
65
  return false;
66
66
  }
@@ -112,19 +112,19 @@ export const EntityTable = (props) => {
112
112
  show: canMoveTo(row), text: 'انتقال به اینجا', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
113
113
  const keys = Object.keys(selected);
114
114
  const toRow = row;
115
- const toId = getId(toRow);
115
+ const toId = entity.id.get(toRow);
116
116
  if (!moveTo || !keys.length) {
117
117
  return;
118
118
  }
119
- const { parents } = entity.getRowAndParentsById({ rowId: toId });
119
+ const { parents } = entity.getRowAndParentsById(toId);
120
120
  for (let i = 0; i < parents.length; i++) {
121
- const id = getId(parents[i]).toString();
121
+ const id = entity.id.get(parents[i]).toString();
122
122
  if (selected[id]) {
123
123
  return;
124
124
  }
125
125
  }
126
126
  const rows = keys.map((key) => selected[key]).filter((fromRow) => !!moveTo(fromRow, toRow));
127
- const fromIds = rows.map((o) => getId(o));
127
+ const fromIds = rows.map((o) => entity.id.get(o));
128
128
  yield entity.moveTo(fromIds, toId);
129
129
  setSelected({});
130
130
  })
@@ -135,7 +135,7 @@ export const EntityTable = (props) => {
135
135
  { show: !!archive && !!row.archive, text: 'خروج از آرشیو', onClick: () => { if (!!archive) {
136
136
  entity.edit(Object.assign(Object.assign({}, row), { archive: false }));
137
137
  } } },
138
- { text: 'حذف', onClick: () => entity.remove(getId(row)) }
138
+ { text: 'حذف', onClick: () => entity.remove(entity.id.get(row)) }
139
139
  ];
140
140
  };
141
141
  const side = useSide({
@@ -161,7 +161,7 @@ const Selected = () => {
161
161
  if (!getSelectedOptions || !keys.length) {
162
162
  return [];
163
163
  }
164
- const parent = keys.length ? entity.getParentByRowId({ rowId: entity.getId(selected[keys[0]]), rows: entity.data }) : undefined;
164
+ const parent = keys.length ? entity.getParentByRowId(entity.data, entity.id.get(selected[keys[0]])) : undefined;
165
165
  const list = [];
166
166
  for (let prop in selected) {
167
167
  list.push(selected[prop]);
@@ -192,27 +192,38 @@ const TableToolbar = () => {
192
192
  };
193
193
  export const Card = ({ row }) => {
194
194
  const { rootProps, getOptions, entity, showArchive, select, selected } = useProvider();
195
- const rowId = entity.getId(row);
195
+ const rowId = entity.id.get(row);
196
196
  const isSelected = selected[rowId];
197
197
  const { getCardContent, getCardTitle } = rootProps;
198
198
  const [open, setOpen] = useState(false);
199
- const childs = entity.getChilds(row);
200
- return (_jsxs("div", { className: "entity-card", children: [_jsxs("div", { className: "entity-card-header", children: [_jsx("div", { className: "entity-card-toggle-icon", onClick: () => setOpen(!open), children: new GetSvg().getIcon(open ? 'mdiChevronDown' : 'mdiChevronLeft', .8) }), _jsxs("div", { className: "entity-card-title", style: { flex: 1, color: isSelected ? 'orange' : undefined }, onClick: () => select(row), children: [!!isSelected && _jsx(Icon, { path: mdiCheckboxMarked, size: 0.8, color: 'orange' }), getCardTitle(row)] }), !!getOptions && _jsx(CardOptions, { row: row, parent: false, isRoot: true })] }), getCardContent(row, false, 'root'), !!childs && !!open &&
201
- _jsx(AITree, { rtl: true, autoHeight: true, indent: 24, value: childs, option: {
202
- childs: (o) => entity.getChilds(o),
203
- text: (row, { parentOptions }) => {
204
- const rowId = entity.getId(row);
205
- const isSelected = selected[rowId];
206
- const childs = entity.getChilds(row);
207
- const parentOption = parentOptions.length ? parentOptions[parentOptions.length - 1] : undefined;
208
- const parent = parentOption ? parentOption.optionOrg : false;
209
- return (_jsxs("div", { className: classListToString(["entity-row", isSelected ? 'selected' : undefined]), children: [_jsxs("div", { className: "entity-row-header", children: [!!isSelected && _jsx(Icon, { path: mdiCheckboxMarked, size: 0.8, color: 'orange' }), _jsx("div", { className: 'entity-row-title', style: { color: isSelected ? 'orange' : undefined }, onClick: () => select(row), children: getCardTitle(row) }), !!getOptions && _jsx(CardOptions, { row: row, parent: parent })] }), getCardContent(row, parent, childs ? 'node' : 'leaf')] }));
210
- },
211
- value: (o) => entity.getId(o),
212
- show: (o) => showArchive ? true : !o.archive,
213
- className: () => `${'d1-bg-dark-gray'} !rounded-md`,
214
- style: () => ({ borderBottom: '2px dashed #333' })
215
- } })] }));
199
+ //const tree = useMemo(() => {return <CardTree<T> row={row as any} open={open} />}, [row, selected, open])
200
+ return (_jsxs("div", { className: "entity-card", children: [_jsxs("div", { className: "entity-card-header", children: [_jsx("div", { className: "entity-card-toggle-icon", onClick: () => setOpen(!open), children: new GetSvg().getIcon(open ? 'mdiChevronDown' : 'mdiChevronLeft', .8) }), _jsxs("div", { className: "entity-card-title", style: { flex: 1, color: isSelected ? 'orange' : undefined }, onClick: () => select(row), children: [!!isSelected && _jsx(Icon, { path: mdiCheckboxMarked, size: 0.8, color: 'orange' }), getCardTitle(row)] }), !!getOptions && _jsx(CardOptions, { row: row, parent: false, isRoot: true })] }), getCardContent(row, false, 'root'), _jsx(CardTree, { row: row, open: open })] }));
201
+ };
202
+ const CardTree = ({ row, open }) => {
203
+ const { entity, showArchive } = useProvider();
204
+ const childs = entity.childs.get(row);
205
+ if (!childs || !childs.length || !open) {
206
+ return null;
207
+ }
208
+ return (_jsx(AITree, { rtl: true, autoHeight: true, indent: 24, value: childs, option: {
209
+ childs: (o) => entity.childs.get(o),
210
+ text: (row, { parentOptions }) => _jsx(CardTreeRow, { row: row, parentOptions: parentOptions }),
211
+ value: (o) => entity.id.get(o),
212
+ show: (o) => showArchive ? true : !o.archive,
213
+ className: () => `${'d1-bg-dark-gray'} !rounded-md`,
214
+ style: () => ({ borderBottom: '2px dashed #333' })
215
+ } }));
216
+ };
217
+ const CardTreeRow = ({ row, parentOptions }) => {
218
+ const { rootProps, getOptions, entity, select, selected } = useProvider();
219
+ const { getCardContent, getCardTitle } = rootProps;
220
+ const rowId = entity.id.get(row);
221
+ const isSelected = selected[rowId];
222
+ const childs = entity.childs.get(row);
223
+ const parentOption = parentOptions.length ? parentOptions[parentOptions.length - 1] : undefined;
224
+ const parent = parentOption ? parentOption.optionOrg : false;
225
+ console.log('tree row');
226
+ return (_jsxs("div", { className: classListToString(["entity-row", isSelected ? 'selected' : undefined]), children: [_jsxs("div", { className: "entity-row-header", children: [!!isSelected && _jsx(Icon, { path: mdiCheckboxMarked, size: 0.8, color: 'orange' }), _jsx("div", { className: 'entity-row-title', style: { color: isSelected ? 'orange' : undefined }, onClick: () => select(row), children: getCardTitle(row) }), !!getOptions && _jsx(CardOptions, { row: row, parent: parent })] }), getCardContent(row, parent, childs ? 'node' : 'leaf')] }));
216
227
  };
217
228
  const CardOptions = ({ row, parent, isRoot }) => {
218
229
  const { getOptions } = useProvider();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-entitykit",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "kit",
5
5
  "main": "index.js",
6
6
  "scripts": {