aio-entitykit 2.0.1 → 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.
- package/d1.css +2 -2
- package/index.d.ts +88 -0
- package/index.js +328 -0
- package/package.json +1 -1
package/d1.css
CHANGED
|
@@ -464,7 +464,7 @@
|
|
|
464
464
|
}
|
|
465
465
|
|
|
466
466
|
.d1 .ai-indent-line {
|
|
467
|
-
|
|
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
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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';
|
|
5
|
+
import './index.css';
|
|
6
|
+
type I_option = {
|
|
7
|
+
text: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
show?: boolean;
|
|
10
|
+
body?: () => ReactNode;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
};
|
|
13
|
+
type I_EntityTable<T> = {
|
|
14
|
+
root?: boolean;
|
|
15
|
+
popup?: any;
|
|
16
|
+
cordova?: AIOCordova;
|
|
17
|
+
io?: boolean;
|
|
18
|
+
sideOptions?: {
|
|
19
|
+
text: string;
|
|
20
|
+
value: any;
|
|
21
|
+
onClick?: () => void;
|
|
22
|
+
before?: ReactNode;
|
|
23
|
+
}[];
|
|
24
|
+
header?: () => ReactNode;
|
|
25
|
+
footer?: () => ReactNode;
|
|
26
|
+
entity: ReturnType<typeof useEntity<T>>;
|
|
27
|
+
table: Partial<I_table<T>>;
|
|
28
|
+
attrs?: any;
|
|
29
|
+
moveTo?: (moveFrom: T, moveTo: T) => boolean;
|
|
30
|
+
getCardContent: (row: T, parent: T | false, type: 'root' | 'leaf' | 'node') => ReactNode;
|
|
31
|
+
getCardOptions?: (row: T, parent: T | false) => I_option[];
|
|
32
|
+
getSelectedOptions?: (selected: T[], parent?: T) => I_option[];
|
|
33
|
+
getRootOptions?: () => I_option[];
|
|
34
|
+
getCardTitle: (row: T) => string;
|
|
35
|
+
archive?: boolean;
|
|
36
|
+
filteredData?: T[];
|
|
37
|
+
};
|
|
38
|
+
export declare const EntityTable: <T>(props: I_EntityTable<T>) => import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
export declare const Card: <T>({ row }: {
|
|
40
|
+
row: T;
|
|
41
|
+
index: number;
|
|
42
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
type I_DateFilter = {
|
|
44
|
+
result?: any;
|
|
45
|
+
fromDate?: number;
|
|
46
|
+
toDate?: number;
|
|
47
|
+
onChange: (p: {
|
|
48
|
+
fromDate?: number;
|
|
49
|
+
toDate?: number;
|
|
50
|
+
}) => void;
|
|
51
|
+
};
|
|
52
|
+
export declare const DateFilter: FC<I_DateFilter>;
|
|
53
|
+
export declare const TimeRange: FC<{
|
|
54
|
+
fromDate?: number;
|
|
55
|
+
toDate?: number;
|
|
56
|
+
onChange: (p: {
|
|
57
|
+
fromDate?: number;
|
|
58
|
+
toDate?: number;
|
|
59
|
+
}) => void;
|
|
60
|
+
}>;
|
|
61
|
+
export declare const CardRow: FC<{
|
|
62
|
+
label: string;
|
|
63
|
+
value: ReactNode;
|
|
64
|
+
color?: string;
|
|
65
|
+
onClick?: () => void;
|
|
66
|
+
}>;
|
|
67
|
+
export type I_CardRow = [label: string, value: ReactNode, config?: {
|
|
68
|
+
isPrice?: boolean;
|
|
69
|
+
onClick?: () => void;
|
|
70
|
+
}];
|
|
71
|
+
export declare const CardRows: FC<{
|
|
72
|
+
rows: I_CardRow[];
|
|
73
|
+
placeholder?: string;
|
|
74
|
+
}>;
|
|
75
|
+
export declare const CardBox: FC<{
|
|
76
|
+
label: string;
|
|
77
|
+
value: ReactNode;
|
|
78
|
+
color?: string;
|
|
79
|
+
onClick?: () => void;
|
|
80
|
+
type: number;
|
|
81
|
+
isPrice?: boolean;
|
|
82
|
+
thin?: boolean;
|
|
83
|
+
}>;
|
|
84
|
+
export declare const Panel: FC<{
|
|
85
|
+
label?: ReactNode;
|
|
86
|
+
content: ReactNode;
|
|
87
|
+
}>;
|
|
88
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
12
|
+
import { AIDate, AISelect, AITime, AITree } from 'aio-input';
|
|
13
|
+
import AIOTable from 'aio-table';
|
|
14
|
+
import { AddToAttrs, classListToString, GetSvg, SplitNumber, useSide } from 'aio-utils';
|
|
15
|
+
import AIODate from 'aio-date';
|
|
16
|
+
import Icon from '@mdi/react';
|
|
17
|
+
import { mdiCheckboxMarked, mdiClose, mdiDownload, mdiListBox, mdiUpload } from "@mdi/js";
|
|
18
|
+
import './index.css';
|
|
19
|
+
const Context = createContext({});
|
|
20
|
+
const Provider = ({ children, value }) => {
|
|
21
|
+
return _jsx(Context.Provider, { value: value, children: children });
|
|
22
|
+
};
|
|
23
|
+
const useProvider = () => useContext(Context);
|
|
24
|
+
export const EntityTable = (props) => {
|
|
25
|
+
const DATE = new AIODate();
|
|
26
|
+
const { table, moveTo, entity, popup, archive, filteredData } = props;
|
|
27
|
+
const [showArchive, setShowArchive] = useState(false);
|
|
28
|
+
const { data } = entity;
|
|
29
|
+
const [selected, setSelected] = useState({});
|
|
30
|
+
const select = (row) => {
|
|
31
|
+
if (!props.getSelectedOptions) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const rowId = entity.id.get(row);
|
|
35
|
+
const keys = Object.keys(selected);
|
|
36
|
+
const firstSelected = keys.length ? selected[keys[0]] : undefined;
|
|
37
|
+
if (firstSelected) {
|
|
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
|
+
if (firstSelectedParentId !== rowParentId) {
|
|
43
|
+
setSelected({ [rowId]: row });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (selected[rowId]) {
|
|
48
|
+
setSelected((prev) => {
|
|
49
|
+
const newSelected = {};
|
|
50
|
+
for (let prop in prev) {
|
|
51
|
+
if (rowId.toString() !== prop.toString()) {
|
|
52
|
+
newSelected[prop] = prev[prop];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return newSelected;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
setSelected((prev) => (Object.assign(Object.assign({}, prev), { [rowId]: row })));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const canMoveTo = (row) => {
|
|
63
|
+
const rowId = entity.id.get(row);
|
|
64
|
+
if (selected[rowId.toString()]) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (!moveTo) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const keys = Object.keys(selected);
|
|
71
|
+
if (!keys.length) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
};
|
|
76
|
+
const getOptionDetails = (options, deselect) => {
|
|
77
|
+
return options.map((o) => {
|
|
78
|
+
return {
|
|
79
|
+
text: o.text, show: o.show,
|
|
80
|
+
onClick: () => {
|
|
81
|
+
if (o.body) {
|
|
82
|
+
popup.addModal({ header: { title: o.title || o.text }, body: o.body() });
|
|
83
|
+
}
|
|
84
|
+
if (o.onClick) {
|
|
85
|
+
o.onClick();
|
|
86
|
+
}
|
|
87
|
+
if (deselect) {
|
|
88
|
+
setTimeout(() => setSelected({}), 0);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const getRootOptions = () => {
|
|
95
|
+
const options = props.getRootOptions ? props.getRootOptions() : [];
|
|
96
|
+
const res = [];
|
|
97
|
+
if (props.archive) {
|
|
98
|
+
res.push({
|
|
99
|
+
text: showArchive ? 'مخفی سازی آرشیو' : 'نمایش آرشیو', onClick: () => {
|
|
100
|
+
setShowArchive(!showArchive);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return [...options, ...res];
|
|
105
|
+
};
|
|
106
|
+
const getOptions = (row, parent) => {
|
|
107
|
+
const options = props.getCardOptions ? props.getCardOptions(row, parent) : [];
|
|
108
|
+
const res = getOptionDetails(options);
|
|
109
|
+
return [
|
|
110
|
+
...res,
|
|
111
|
+
{
|
|
112
|
+
show: canMoveTo(row), text: 'انتقال به اینجا', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const keys = Object.keys(selected);
|
|
114
|
+
const toRow = row;
|
|
115
|
+
const toId = entity.id.get(toRow);
|
|
116
|
+
if (!moveTo || !keys.length) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const { parents } = entity.getRowAndParentsById(toId);
|
|
120
|
+
for (let i = 0; i < parents.length; i++) {
|
|
121
|
+
const id = entity.id.get(parents[i]).toString();
|
|
122
|
+
if (selected[id]) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const rows = keys.map((key) => selected[key]).filter((fromRow) => !!moveTo(fromRow, toRow));
|
|
127
|
+
const fromIds = rows.map((o) => entity.id.get(o));
|
|
128
|
+
yield entity.moveTo(fromIds, toId);
|
|
129
|
+
setSelected({});
|
|
130
|
+
})
|
|
131
|
+
},
|
|
132
|
+
{ show: !!archive && !row.archive, text: 'انتقال به آرشیو', onClick: () => { if (!!archive) {
|
|
133
|
+
entity.edit(Object.assign(Object.assign({}, row), { archive: true }));
|
|
134
|
+
} } },
|
|
135
|
+
{ show: !!archive && !!row.archive, text: 'خروج از آرشیو', onClick: () => { if (!!archive) {
|
|
136
|
+
entity.edit(Object.assign(Object.assign({}, row), { archive: false }));
|
|
137
|
+
} } },
|
|
138
|
+
{ text: 'حذف', onClick: () => entity.remove(entity.id.get(row)) }
|
|
139
|
+
];
|
|
140
|
+
};
|
|
141
|
+
const side = useSide({
|
|
142
|
+
options: props.sideOptions || [],
|
|
143
|
+
option: {
|
|
144
|
+
before: (o) => _jsx(Icon, { path: { reports: mdiListBox, export: mdiDownload, import: mdiUpload }[o.value], size: 1 })
|
|
145
|
+
},
|
|
146
|
+
onChange: () => {
|
|
147
|
+
side.close();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const rows = filteredData ? filteredData : data;
|
|
151
|
+
const attrs = AddToAttrs(props.attrs, { className: 'entity-table' });
|
|
152
|
+
return (_jsx(Provider, { value: { selected, setSelected, getRootOptions, rootProps: props, getOptions, entity, getOptionDetails, showArchive, setShowArchive, select }, children: _jsxs("div", Object.assign({}, attrs, { children: [_jsx("div", { className: "entity-table-today", style: { background: 'rgba(0,0,0,0.2)' }, children: DATE.getDateByPattern(DATE.getToday(true), 'امروز {weekDay} {day} {monthString} {year}') }), _jsxs("div", { className: "flex flex-row", children: [!!props.sideOptions && !!props.sideOptions.length &&
|
|
153
|
+
_jsx("div", { className: "border-0 ml-2 px-2 py-2 rounded-full", onClick: () => side.open(), children: _jsx(Icon, { path: mdiListBox, size: 1 }) }), !!props.header && props.header()] }), _jsx(Selected, {}), _jsx(AIOTable, Object.assign({}, table, { value: rows, headerAttrs: { style: { display: 'none' } }, rowTemplate: ({ row, rowIndex }) => _jsx(Card, { row: row, index: rowIndex }), toolbar: () => _jsx(TableToolbar, {}) })), _jsx("div", { className: "mb-2" }), !!props.footer && props.footer(), side.render()] })) }));
|
|
154
|
+
};
|
|
155
|
+
const Selected = () => {
|
|
156
|
+
const { selected, rootProps, getOptionDetails, entity, setSelected } = useProvider();
|
|
157
|
+
const keys = Object.keys(selected);
|
|
158
|
+
const [options, setOptions] = useState([]);
|
|
159
|
+
function getOptions() {
|
|
160
|
+
const { getSelectedOptions } = rootProps;
|
|
161
|
+
if (!getSelectedOptions || !keys.length) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
const parent = keys.length ? entity.getParentByRowId(entity.data, entity.id.get(selected[keys[0]])) : undefined;
|
|
165
|
+
const list = [];
|
|
166
|
+
for (let prop in selected) {
|
|
167
|
+
list.push(selected[prop]);
|
|
168
|
+
}
|
|
169
|
+
const options = getSelectedOptions(list, parent);
|
|
170
|
+
return getOptionDetails(options, true);
|
|
171
|
+
}
|
|
172
|
+
useEffect(() => { setOptions(getOptions); }, [selected]);
|
|
173
|
+
if (!options.length) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return (_jsxs("div", { className: "entity-table-selected", children: [_jsx("div", { className: "entity-table-deselect-all", onClick: () => setSelected({}), children: _jsx(Icon, { path: mdiClose, size: 0.8 }) }), _jsx("div", { className: "msf", children: `${keys.length} مورد انتخاب شده` }), _jsx("div", { style: { flex: 1 } }), _jsx(AISelect, { rtl: true, options: options, text: new GetSvg().getIcon('mdiDotsHorizontal', .8), caret: false, justify: true, className: 'entity-table-selected-options', style: { background: 'orange', color: '#000', border: 'none', height: 30, width: 30, padding: 0, } })] }));
|
|
177
|
+
};
|
|
178
|
+
const TableToolbar = () => {
|
|
179
|
+
const { rootProps, getOptionDetails, getRootOptions } = useProvider();
|
|
180
|
+
const { table } = rootProps;
|
|
181
|
+
let node = null;
|
|
182
|
+
if (typeof table.toolbar === 'function') {
|
|
183
|
+
node = table.toolbar() || null;
|
|
184
|
+
}
|
|
185
|
+
else if (table.toolbar) {
|
|
186
|
+
node = table.toolbar || null;
|
|
187
|
+
}
|
|
188
|
+
const options = getRootOptions();
|
|
189
|
+
const res = getOptionDetails(options);
|
|
190
|
+
return (_jsxs("div", { className: "entity-table-toolbar", children: [!!res.length &&
|
|
191
|
+
_jsx(AISelect, { rtl: true, options: res, text: new GetSvg().getIcon('mdiPlusThick', .8), caret: false, justify: true, className: 'd1-bg-cream flex flex-row items-center justify-center', style: { background: 'none', border: 'none', height: 30, width: 30, padding: 0, } }), node] }));
|
|
192
|
+
};
|
|
193
|
+
export const Card = ({ row }) => {
|
|
194
|
+
const { rootProps, getOptions, entity, showArchive, select, selected } = useProvider();
|
|
195
|
+
const rowId = entity.id.get(row);
|
|
196
|
+
const isSelected = selected[rowId];
|
|
197
|
+
const { getCardContent, getCardTitle } = rootProps;
|
|
198
|
+
const [open, setOpen] = useState(false);
|
|
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')] }));
|
|
227
|
+
};
|
|
228
|
+
const CardOptions = ({ row, parent, isRoot }) => {
|
|
229
|
+
const { getOptions } = useProvider();
|
|
230
|
+
return (_jsx(AISelect, { text: new GetSvg().getIcon('mdiDotsHorizontal', .8), caret: false, options: getOptions(row, parent, !!isRoot), justify: true, className: `${!isRoot ? 'd1-bg-cream' : 'd1-bg-gray'}`, style: { background: 'none', border: 'none', height: 30, width: 42, fontSize: '0.7em' }, popover: { modalAttrs: { style: { fontSize: '0.8em' } } } }));
|
|
231
|
+
};
|
|
232
|
+
export const DateFilter = ({ result, fromDate, toDate, onChange }) => {
|
|
233
|
+
const DATE = new AIODate();
|
|
234
|
+
const changeDateByDay = (date) => {
|
|
235
|
+
const [year, month, day] = date;
|
|
236
|
+
const fromDate = DATE.getTime([year, month, day, 0, 0]);
|
|
237
|
+
const toDate = DATE.getTime([year, month, day, 23, 59]);
|
|
238
|
+
onChange({ fromDate, toDate });
|
|
239
|
+
};
|
|
240
|
+
return (_jsxs("div", { className: "date-filter", children: [_jsxs("div", { className: "date-filter-toolbar", children: [result !== undefined && _jsx("button", { className: 'date-filter-result', children: result }), _jsx("div", { style: { flex: 1 } }), _jsxs("div", { className: "date-filter-toolbar-buttons", children: [_jsx(AIDate, { className: 'date-filter-input', style: { background: 'none' }, caret: false, justify: true, jalali: true, calendarClose: true, text: _jsx(CalendarIcon, {}), dateUnit: 'day', dateType: 'dateArray', onChange: (v) => { changeDateByDay(v); }, popover: { position: 'center' } }), _jsx(DateBox, { unit: 'day', className: 'd1-bg-blue-grad', onChange: onChange }), _jsx(DateBox, { unit: 'month', className: 'd1-bg-green-grad', onChange: onChange }), _jsx(DateBox, { unit: 'year', className: 'd1-bg-red-grad', onChange: onChange })] })] }), _jsx(TimeRange, { fromDate: fromDate, toDate: toDate, onChange: ({ fromDate, toDate }) => { onChange({ fromDate, toDate }); } })] }));
|
|
241
|
+
};
|
|
242
|
+
const DateBox = ({ unit, onChange }) => {
|
|
243
|
+
const DATE = new AIODate();
|
|
244
|
+
const dic = { day: 'امروز', week: 'هفته جاری', month: 'انتخاب ماه', year: 'سال جاری' };
|
|
245
|
+
const changeDateByUnit = (unit) => {
|
|
246
|
+
let [fromArray, toArray] = DATE.getCurrentRange(unit, true);
|
|
247
|
+
const fromDate = DATE.getTime(fromArray);
|
|
248
|
+
const toDate = DATE.getTime(toArray);
|
|
249
|
+
onChange({ fromDate, toDate });
|
|
250
|
+
};
|
|
251
|
+
const changeDateByMonth = (month) => {
|
|
252
|
+
const [year] = DATE.getToday(true);
|
|
253
|
+
const dateArray = [year, month];
|
|
254
|
+
const monthDaysLength = DATE.getMonthDaysLength(dateArray);
|
|
255
|
+
const fromArray = [dateArray[0], dateArray[1], 1, 0, 0];
|
|
256
|
+
const toArray = [dateArray[0], dateArray[1], monthDaysLength, 23, 59];
|
|
257
|
+
const fromDate = DATE.getTime(fromArray);
|
|
258
|
+
const toDate = DATE.getTime(toArray);
|
|
259
|
+
onChange({ fromDate, toDate });
|
|
260
|
+
};
|
|
261
|
+
if (unit === 'month') {
|
|
262
|
+
return (_jsx(AISelect, { className: `date-box`, style: { color: '#ddd', background: 'none' }, caret: false, text: dic[unit], popover: { modalAttrs: { style: { width: '100vw' } } }, options: [
|
|
263
|
+
{ text: 'ماه جاری', onClick: () => changeDateByUnit('month') },
|
|
264
|
+
...DATE.getMonths(true).map((o, i) => ({ text: o, onClick: () => changeDateByMonth(i + 1) }))
|
|
265
|
+
] }));
|
|
266
|
+
}
|
|
267
|
+
return (_jsx("div", { className: `date-box`, style: { color: '#ddd' }, onClick: () => {
|
|
268
|
+
if (unit === 'day') {
|
|
269
|
+
changeDateByUnit('day');
|
|
270
|
+
}
|
|
271
|
+
if (unit === 'year') {
|
|
272
|
+
changeDateByUnit('year');
|
|
273
|
+
}
|
|
274
|
+
}, children: dic[unit] }));
|
|
275
|
+
};
|
|
276
|
+
const CalendarIcon = () => {
|
|
277
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.5rem', height: '1.5rem' }, children: _jsx("path", { d: "M19,19H5V8H19M16,1V3H8V1H6V3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3H18V1M17,12H12V17H17V12Z", style: { fill: 'currentcolor' } }) }));
|
|
278
|
+
};
|
|
279
|
+
export const TimeRange = ({ fromDate, toDate, onChange }) => {
|
|
280
|
+
const getText = (time, field) => {
|
|
281
|
+
if (!time) {
|
|
282
|
+
return field === 'fromDate' ? 'از تاریخ' : 'تا تاریخ';
|
|
283
|
+
}
|
|
284
|
+
const DATE = new AIODate();
|
|
285
|
+
const { weekDay, monthString, yearStr, dayStr } = DATE.getDetails(time, true);
|
|
286
|
+
return `${weekDay} ${dayStr} ${monthString} ${yearStr}`;
|
|
287
|
+
};
|
|
288
|
+
const renderTime = (time, field) => {
|
|
289
|
+
const text = getText(time, field);
|
|
290
|
+
return (_jsx(AITime, { dateType: "dateNumber", className: 'time-range-input', style: { background: 'none' }, value: time, text: text, jalali: true, caret: false, onChange: (v) => onChange({ fromDate, toDate, [field]: v }), deSelect: true }));
|
|
291
|
+
};
|
|
292
|
+
return (_jsxs("div", { className: "time-range", children: [_jsx("div", { style: { flex: 1 }, children: renderTime(fromDate, 'fromDate') }), _jsx("div", { className: "time-range-splitter" }), _jsx("div", { style: { flex: 1 }, children: renderTime(toDate, 'toDate') })] }));
|
|
293
|
+
};
|
|
294
|
+
export const CardRow = ({ label, value, color, onClick }) => {
|
|
295
|
+
return (_jsxs("div", { className: 'card-row', onClick: () => { if (onClick) {
|
|
296
|
+
onClick();
|
|
297
|
+
} }, children: [_jsx("div", { className: "text-sm", children: label }), _jsx("div", { className: "flex-1" }), _jsx("div", { className: "font-bold text-sm flex flex-row items-center justify-center", style: { color }, children: value })] }));
|
|
298
|
+
};
|
|
299
|
+
export const CardRows = ({ rows, placeholder = 'موردی وجود ندارد' }) => {
|
|
300
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [!rows.length && _jsx("div", { className: "text-xs w-full flex flex-row items-center justify-center", children: placeholder }), rows.map((r, i) => {
|
|
301
|
+
const { onClick, isPrice } = r[2] || {};
|
|
302
|
+
let value = r[1];
|
|
303
|
+
if (isPrice && (typeof r[1] === 'number' || typeof r[1] === 'string')) {
|
|
304
|
+
value = SplitNumber(r[1]);
|
|
305
|
+
}
|
|
306
|
+
return _jsx(CardRow, { label: r[0], value: value, onClick: onClick }, i);
|
|
307
|
+
})] }));
|
|
308
|
+
};
|
|
309
|
+
export const CardBox = ({ thin, type, label, value, color, onClick, isPrice }) => {
|
|
310
|
+
let cls = `flex flex-col flex-1 items-center rounded-lg${!thin ? ' py-2' : ''}`;
|
|
311
|
+
if (type === 0) {
|
|
312
|
+
cls += ' d1-bg-cream';
|
|
313
|
+
}
|
|
314
|
+
const style = {};
|
|
315
|
+
if (type === 1) {
|
|
316
|
+
style.boxShadow = 'inset 2px 2px 5px 0px rgb(110 85 27 / 40%)';
|
|
317
|
+
}
|
|
318
|
+
else if (type === 2) {
|
|
319
|
+
style.background = 'rgba(0,0,0,0.2)';
|
|
320
|
+
style.color = '#fff';
|
|
321
|
+
}
|
|
322
|
+
return (_jsxs("div", { className: cls, style: style, onClick: () => { if (onClick) {
|
|
323
|
+
onClick();
|
|
324
|
+
} }, children: [_jsx("div", { className: "text-xs", children: label }), _jsx("div", { className: "flex-1" }), _jsx("div", { className: "font-bold text-sm", style: { color }, children: isPrice ? SplitNumber(value) : value })] }));
|
|
325
|
+
};
|
|
326
|
+
export const Panel = ({ label, content }) => {
|
|
327
|
+
return (_jsxs("div", { className: 'd1-panel', children: [!!label && _jsx("div", { className: "d1-panel-label d1-panel-label-online-rtl", children: label }), content] }));
|
|
328
|
+
};
|