@enyxs/wikex-components 0.11.29 → 0.11.31

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/dist/fees.mjs CHANGED
@@ -27,6 +27,7 @@ import { Box, Button, MenuItem, Stack, TextField, Typography } from "@mui/materi
27
27
  var FEES_FONT_SIZE_MIN = 8;
28
28
  var FEES_FONT_SIZE_MAX = 32;
29
29
  var FEES_FONT_WEIGHTS = [400, 500, 600, 700, 800];
30
+ var FEES_TEXT_ALIGNS = ["left", "center", "right"];
30
31
  var FEES_PAGE_SIZE = 25;
31
32
  function normalizeFeesSearch(value) {
32
33
  return value.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/đ/g, "d").replace(/Đ/g, "D").toLowerCase().trim();
@@ -35,6 +36,15 @@ function filterFeesRows(data, search, tag) {
35
36
  const query = normalizeFeesSearch(search);
36
37
  return data.rows.filter((row) => (!tag || row.tags.includes(tag)) && (!query || Object.values(row.cells).some((cell) => normalizeFeesSearch(cell).includes(query))));
37
38
  }
39
+ function sortFeesRowsByName(rows, language = "vi") {
40
+ const collator = new Intl.Collator(language, { sensitivity: "base", numeric: true });
41
+ return [...rows].sort((a, b) => {
42
+ const left = (a.cells.name ?? "").trim();
43
+ const right = (b.cells.name ?? "").trim();
44
+ if (!left || !right) return left ? -1 : right ? 1 : 0;
45
+ return collator.compare(left, right);
46
+ });
47
+ }
38
48
  function paginateFeesRows(rows, requestedPage, pageSize = FEES_PAGE_SIZE) {
39
49
  const size = pageSize === -1 ? Math.max(1, rows.length) : Number.isInteger(pageSize) && pageSize > 0 ? pageSize : FEES_PAGE_SIZE;
40
50
  const pageCount = Math.max(1, Math.ceil(rows.length / size));
@@ -52,6 +62,7 @@ function moveFeesItem(items, from, to) {
52
62
  // src/wikex/fees-typography-controls.tsx
53
63
  import { jsx, jsxs } from "react/jsx-runtime";
54
64
  var weightLabels = { 400: "Th\u01B0\u1EDDng", 500: "V\u1EEBa", 600: "H\u01A1i \u0111\u1EADm", 700: "\u0110\u1EADm", 800: "R\u1EA5t \u0111\u1EADm" };
65
+ var alignLabels = { left: "C\u0103n tr\xE1i", center: "C\u0103n gi\u1EEFa", right: "C\u0103n ph\u1EA3i" };
55
66
  function FontSizeInput({ label, value, onChange }) {
56
67
  const [draft, setDraft] = useState(String(value));
57
68
  const [error, setError] = useState(false);
@@ -92,7 +103,13 @@ function FontSizeInput({ label, value, onChange }) {
92
103
  }
93
104
  function FeesTypographyControls({ value, onChange }) {
94
105
  const root = useRef(null);
95
- const update = (part, patch) => onChange({ ...value, [part]: { ...value?.[part], ...patch } });
106
+ const update = (part, patch) => {
107
+ const style = Object.fromEntries(Object.entries({ ...value?.[part], ...patch }).filter(([, setting]) => setting !== void 0));
108
+ const next = { ...value };
109
+ if (Object.keys(style).length) next[part] = style;
110
+ else delete next[part];
111
+ onChange(Object.keys(next).length ? next : void 0);
112
+ };
96
113
  return /* @__PURE__ */ jsxs(Box, { ref: root, role: "group", "aria-label": "\u0110\u1ECBnh d\u1EA1ng ch\u1EEF b\u1EA3ng ph\xED", sx: { mt: 2, p: { xs: 2, sm: 2.5 }, border: "1px solid", borderColor: "divider", borderRadius: 1.5 }, children: [
97
114
  /* @__PURE__ */ jsxs(Stack, { direction: { xs: "column", sm: "row" }, gap: 1.5, justifyContent: "space-between", alignItems: { sm: "center" }, sx: { mb: 2 }, children: [
98
115
  /* @__PURE__ */ jsxs(Box, { children: [
@@ -100,7 +117,7 @@ function FeesTypographyControls({ value, onChange }) {
100
117
  /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: "\xC1p d\u1EE5ng cho to\xE0n b\u1EA3ng, theo ng\xF4n ng\u1EEF \u0111ang ch\u1ECDn. Xem thay \u0111\u1ED5i ngay b\xEAn d\u01B0\u1EDBi." })
101
118
  ] }),
102
119
  /* @__PURE__ */ jsxs(Stack, { direction: "row", gap: 1, flexShrink: 0, children: [
103
- /* @__PURE__ */ jsx(Button, { size: "small", variant: "outlined", onClick: () => onChange({ thead: { fontSize: 14, fontWeight: 700 }, tbody: { fontSize: 14, fontWeight: 500 } }), children: "D\u1EC5 \u0111\u1ECDc" }),
120
+ /* @__PURE__ */ jsx(Button, { size: "small", variant: "outlined", onClick: () => onChange({ thead: { ...value?.thead, fontSize: 14, fontWeight: 700 }, tbody: { ...value?.tbody, fontSize: 14, fontWeight: 500 } }), children: "D\u1EC5 \u0111\u1ECDc" }),
104
121
  /* @__PURE__ */ jsx(Button, { size: "small", color: "inherit", disabled: !value, onClick: () => onChange(void 0), children: "M\u1EB7c \u0111\u1ECBnh" })
105
122
  ] })
106
123
  ] }),
@@ -130,7 +147,24 @@ function FeesTypographyControls({ value, onChange }) {
130
147
  ] }, weight))
131
148
  }
132
149
  )
133
- ] })
150
+ ] }),
151
+ /* @__PURE__ */ jsxs(
152
+ TextField,
153
+ {
154
+ select: true,
155
+ fullWidth: true,
156
+ size: "small",
157
+ label: "C\u0103n l\u1EC1",
158
+ value: value?.[part]?.textAlign ?? "",
159
+ slotProps: { select: { displayEmpty: true, SelectDisplayProps: { "aria-labelledby": void 0 }, MenuProps: { container: () => root.current?.ownerDocument.body ?? document.body }, inputProps: { "aria-label": `C\u0103n l\u1EC1 ${title.toLocaleLowerCase("vi")}` } }, inputLabel: { shrink: true } },
160
+ helperText: "\xC1p d\u1EE5ng cho t\u1EA5t c\u1EA3 \xF4, c\u1EA3 tr\xEAn \u0111i\u1EC7n tho\u1EA1i",
161
+ onChange: (event) => update(part, { textAlign: event.target.value ? event.target.value : void 0 }),
162
+ children: [
163
+ /* @__PURE__ */ jsx(MenuItem, { value: "", children: "Theo m\u1EB7c \u0111\u1ECBnh" }),
164
+ FEES_TEXT_ALIGNS.map((align) => /* @__PURE__ */ jsx(MenuItem, { value: align, children: alignLabels[align] }, align))
165
+ ]
166
+ }
167
+ )
134
168
  ] }, part)) }),
135
169
  /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", sx: { display: "block", mt: 1 }, children: "C\u1EE1 ch\u1EEF t\xF9y ch\u1EC9nh \xE1p d\u1EE5ng c\u1EA3 tr\xEAn \u0111i\u1EC7n tho\u1EA1i; b\u1EA3ng c\xF3 th\u1EC3 vu\u1ED1t ngang. \u201CM\u1EB7c \u0111\u1ECBnh\u201D kh\xF4i ph\u1EE5c c\u1EE1 ch\u1EEF t\u1EF1 th\xEDch \u1EE9ng theo m\xE0n h\xECnh." })
136
170
  ] });
@@ -850,32 +884,32 @@ var feesTheme = {
850
884
  ]))
851
885
  };
852
886
  var EditorActions = styled6.div.withConfig({
853
- componentId: "sc-a5657aea-0"
887
+ componentId: "sc-a14ae83-0"
854
888
  })([
855
889
  `display:flex;flex-wrap:wrap;gap:8px;margin-top:16px;`
856
890
  ]);
857
891
  var EditGroup = styled6.div.withConfig({
858
- componentId: "sc-a5657aea-1"
892
+ componentId: "sc-a14ae83-1"
859
893
  })([
860
894
  `display:flex;flex-direction:column;gap:6px;`
861
895
  ]);
862
896
  var HeaderGroup = styled6(EditGroup).withConfig({
863
- componentId: "sc-a5657aea-2"
897
+ componentId: "sc-a14ae83-2"
864
898
  })([
865
899
  `gap:8px;`
866
900
  ]);
867
901
  var HeaderTitle = styled6.div.withConfig({
868
- componentId: "sc-a5657aea-3"
902
+ componentId: "sc-a14ae83-3"
869
903
  })([
870
904
  `display:flex;align-items:flex-start;min-height:var(--fees-header-title-height,36px);`
871
905
  ]);
872
906
  var HeaderActions = styled6.div.withConfig({
873
- componentId: "sc-a5657aea-4"
907
+ componentId: "sc-a14ae83-4"
874
908
  })([
875
909
  `display:flex;align-items:center;min-height:24px;`
876
910
  ]);
877
911
  var AlignedFeesTable = styled6(FeesAndMarginTable).withConfig({
878
- componentId: "sc-a5657aea-5"
912
+ componentId: "sc-a14ae83-5"
879
913
  })([
880
914
  `&[data-editable] th{vertical-align:top;}--fees-row-background:`,
881
915
  `;--fees-stripe-background:`,
@@ -886,9 +920,11 @@ var AlignedFeesTable = styled6(FeesAndMarginTable).withConfig({
886
920
  `;}&&& thead > tr > th{height:52px;padding:11.5px 8px;color:`,
887
921
  `;font-size:`,
888
922
  `px;font-weight:`,
923
+ `;text-align:`,
889
924
  `;line-height:`,
890
925
  `;white-space:pre-line;}tbody > tr{background:var(--fees-row-background);}tbody > tr:nth-child(even){background:var(--fees-stripe-background);}&&& tbody > tr > td{height:32px;padding:7.5px 8px;background:inherit;color:var(--fees-text);font-size:`,
891
926
  `px;font-weight:`,
927
+ `;text-align:`,
892
928
  `;line-height:`,
893
929
  `;}thead > tr > th:first-child,tbody > tr > td:first-child{padding-left:16px;}@media (max-width:767px){&&:not([data-editable]){table{min-width:100%;width:`,
894
930
  `px;table-layout:fixed;}`,
@@ -896,23 +932,25 @@ var AlignedFeesTable = styled6(FeesAndMarginTable).withConfig({
896
932
  `px;line-height:`,
897
933
  `;}tbody > tr > td{height:40px;padding-top:5.5px;padding-bottom:5.5px;font-size:`,
898
934
  `px;line-height:`,
899
- `;}thead > tr > th:last-child,tbody > tr > td:last-child{padding-right:12px;}th > span,td > span{text-align:left;}thead > tr > th:first-child,tbody > tr > td:first-child{position:sticky;left:0;padding-left:12px;}thead > tr > th:first-child{z-index:3;background:`,
935
+ `;}thead > tr > th:last-child,tbody > tr > td:last-child{padding-right:12px;}th > span{text-align:`,
936
+ `;}td > span{text-align:`,
937
+ `;}thead > tr > th:first-child,tbody > tr > td:first-child{position:sticky;left:0;padding-left:12px;}thead > tr > th:first-child{z-index:3;background:`,
900
938
  `;}tbody > tr > td:first-child{z-index:2;background:var(--fees-row-background);}tbody > tr:nth-child(even) > td:first-child{background:var(--fees-stripe-background);}}}`
901
- ], ({ theme }) => theme.colors.background.deep, ({ theme }) => theme.colors.background.input, ({ theme }) => theme.colors.accent.foreground, ({ theme }) => theme.colors.background.card, ({ theme }) => theme.colors.text.primary, ({ theme }) => theme.colors.accent.primary, ({ theme }) => theme.colors.accent.foreground, ({ $typography }) => $typography?.thead?.fontSize ?? 10, ({ $typography }) => $typography?.thead?.fontWeight ?? 600, ({ $typography }) => $typography?.thead?.fontSize ? 1.4 : "14px", ({ $typography }) => $typography?.tbody?.fontSize ?? 12, ({ $typography }) => $typography?.tbody?.fontWeight ?? 500, ({ $typography }) => $typography?.tbody?.fontSize ? 1.4 : "16px", ({ $mobileColumnWidths }) => $mobileColumnWidths.reduce((sum, width) => sum + width, 0), ({ $mobileColumnWidths }) => $mobileColumnWidths.map((width, index) => `
939
+ ], ({ theme }) => theme.colors.background.deep, ({ theme }) => theme.colors.background.input, ({ theme }) => theme.colors.accent.foreground, ({ theme }) => theme.colors.background.card, ({ theme }) => theme.colors.text.primary, ({ theme }) => theme.colors.accent.primary, ({ theme }) => theme.colors.accent.foreground, ({ $typography }) => $typography?.thead?.fontSize ?? 10, ({ $typography }) => $typography?.thead?.fontWeight ?? 600, ({ $typography }) => $typography?.thead?.textAlign ?? "left", ({ $typography }) => $typography?.thead?.fontSize ? 1.4 : "14px", ({ $typography }) => $typography?.tbody?.fontSize ?? 12, ({ $typography }) => $typography?.tbody?.fontWeight ?? 500, ({ $typography }) => $typography?.tbody?.textAlign ?? "left", ({ $typography }) => $typography?.tbody?.fontSize ? 1.4 : "16px", ({ $mobileColumnWidths }) => $mobileColumnWidths.reduce((sum, width) => sum + width, 0), ({ $mobileColumnWidths }) => $mobileColumnWidths.map((width, index) => `
902
940
  th:nth-child(${index + 1}), td:nth-child(${index + 1}) {
903
941
  width: ${width}px;
904
942
  min-width: ${width}px;
905
943
  max-width: ${width}px;
906
944
  }
907
- `).join(""), ({ $typography }) => $typography?.thead?.fontSize ?? 8, ({ $typography }) => $typography?.thead?.fontSize ? 1.4 : "10px", ({ $typography }) => $typography?.tbody?.fontSize ?? 10, ({ $typography }) => $typography?.tbody?.fontSize ? 1.4 : "14px", ({ theme }) => theme.colors.accent.primary);
945
+ `).join(""), ({ $typography }) => $typography?.thead?.fontSize ?? 8, ({ $typography }) => $typography?.thead?.fontSize ? 1.4 : "10px", ({ $typography }) => $typography?.tbody?.fontSize ?? 10, ({ $typography }) => $typography?.tbody?.fontSize ? 1.4 : "14px", ({ $typography }) => $typography?.thead?.textAlign ?? "left", ({ $typography }) => $typography?.tbody?.textAlign ?? "left", ({ theme }) => theme.colors.accent.primary);
908
946
  var FeesCellContent = styled6.span.withConfig({
909
- componentId: "sc-a5657aea-6"
947
+ componentId: "sc-a14ae83-6"
910
948
  })([
911
949
  `display:block;text-align:`,
912
950
  `;`
913
- ], ({ $alignRight }) => $alignRight ? "right" : "left");
951
+ ], ({ $align }) => $align);
914
952
  var EditorButton = styled6.button.withConfig({
915
- componentId: "sc-a5657aea-7"
953
+ componentId: "sc-a14ae83-7"
916
954
  })([
917
955
  `padding:7px 12px;border:1px solid `,
918
956
  `;border-radius:6px;background:`,
@@ -921,17 +959,17 @@ var EditorButton = styled6.button.withConfig({
921
959
  `;}&:disabled{cursor:default;opacity:.4;}`
922
960
  ], ({ theme }) => theme.colors.border.line, ({ theme }) => theme.colors.background.input, ({ theme }) => theme.colors.text.primary, ({ theme }) => theme.colors.accent.primary);
923
961
  var OrderActions = styled6.div.withConfig({
924
- componentId: "sc-a5657aea-8"
962
+ componentId: "sc-a14ae83-8"
925
963
  })([
926
964
  `display:flex;gap:6px;align-items:center;flex-wrap:wrap;`
927
965
  ]);
928
966
  var PositionLabel = styled6.label.withConfig({
929
- componentId: "sc-a5657aea-9"
967
+ componentId: "sc-a14ae83-9"
930
968
  })([
931
969
  `display:inline-flex;align-items:center;gap:6px;font-size:12px;`
932
970
  ]);
933
971
  var PositionInput = styled6.input.withConfig({
934
- componentId: "sc-a5657aea-10"
972
+ componentId: "sc-a14ae83-10"
935
973
  })([
936
974
  `width:56px;padding:5px;border:1px solid `,
937
975
  `;border-radius:4px;background:`,
@@ -940,17 +978,17 @@ var PositionInput = styled6.input.withConfig({
940
978
  `;}`
941
979
  ], ({ theme }) => theme.colors.border.line, ({ theme }) => theme.colors.background.input, ({ theme }) => theme.colors.text.primary, ({ theme }) => theme.colors.accent.primary);
942
980
  var ColumnRow = styled6.div.withConfig({
943
- componentId: "sc-a5657aea-11"
981
+ componentId: "sc-a14ae83-11"
944
982
  })([
945
983
  `display:flex;gap:12px;align-items:center;margin:16px 0;> textarea{flex:1;min-width:120px;}@media (max-width:600px){align-items:stretch;flex-direction:column;}`
946
984
  ]);
947
985
  var PaginationControls = styled6(FeesAndMarginPagination).withConfig({
948
- componentId: "sc-a5657aea-12"
986
+ componentId: "sc-a14ae83-12"
949
987
  })([
950
988
  `align-items:center;flex-wrap:wrap;gap:16px 24px;`
951
989
  ]);
952
990
  var PageSizeLabel = styled6.div.withConfig({
953
- componentId: "sc-a5657aea-13"
991
+ componentId: "sc-a14ae83-13"
954
992
  })([
955
993
  `display:inline-flex;align-items:center;gap:8px;color:`,
956
994
  `;font:inherit;font-size:13px;`
@@ -978,14 +1016,14 @@ function Position({ value, max, label, onMove }) {
978
1016
  });
979
1017
  }
980
1018
  var DeleteButton = styled6(EditorButton).withConfig({
981
- componentId: "sc-a5657aea-14"
1019
+ componentId: "sc-a14ae83-14"
982
1020
  })([
983
1021
  `align-self:flex-start;padding:4px 8px;border:0;border-radius:4px;background:#d32f2f;color:#fff;font-size:11px;font-weight:600;line-height:16px;white-space:nowrap;text-decoration:none;&:hover{background:#b71c1c;}&:focus-visible{outline:2px solid #d32f2f;outline-offset:2px;}`
984
1022
  ]);
985
1023
  var CellEditorInput = styled6.textarea.withConfig({
986
- componentId: "sc-a5657aea-15"
1024
+ componentId: "sc-a14ae83-15"
987
1025
  })([
988
- `display:block;box-sizing:border-box;width:100%;min-width:0;padding:3px;border:1px solid transparent;border-radius:3px;color:inherit;background:transparent;font:inherit;line-height:inherit;resize:none;overflow:hidden;&:hover{border-color:`,
1026
+ `display:block;box-sizing:border-box;width:100%;min-width:0;padding:3px;border:1px solid transparent;border-radius:3px;color:inherit;background:transparent;font:inherit;line-height:inherit;text-align:inherit;resize:none;overflow:hidden;&:hover{border-color:`,
989
1027
  `;}&:focus{outline:1px solid `,
990
1028
  `;}`
991
1029
  ], ({ theme }) => theme.colors.border.line, ({ theme }) => theme.colors.accent.primary);
@@ -1196,7 +1234,8 @@ function FeesTable({ value, editable = false, onChange, labels, size = "md", tag
1196
1234
  };
1197
1235
  const activeTag = tags.includes(tag) ? tag : "";
1198
1236
  const filtered = filterFeesRows(value, search, activeTag);
1199
- const pagination = paginateFeesRows(filtered, page, pageSize);
1237
+ const displayedRows = canEdit ? filtered : sortFeesRowsByName(filtered, language);
1238
+ const pagination = paginateFeesRows(displayedRows, page, pageSize);
1200
1239
  const moveColumn = (from, to) => onChange?.({
1201
1240
  ...value,
1202
1241
  columns: moveFeesItem(value.columns, from, to)
@@ -1273,7 +1312,7 @@ function FeesTable({ value, editable = false, onChange, labels, size = "md", tag
1273
1312
  })
1274
1313
  ]
1275
1314
  }) : /* @__PURE__ */ _jsx(FeesCellContent, {
1276
- $alignRight: rightAlignedColumns.has(column.key),
1315
+ $align: value.typography?.thead?.textAlign ?? (rightAlignedColumns.has(column.key) ? "right" : "left"),
1277
1316
  children: column.title
1278
1317
  }),
1279
1318
  render: (_unused, row) => canEdit ? /* @__PURE__ */ _jsx(CellEditor, {
@@ -1287,7 +1326,7 @@ function FeesTable({ value, editable = false, onChange, labels, size = "md", tag
1287
1326
  }
1288
1327
  })
1289
1328
  }) : /* @__PURE__ */ _jsx(FeesCellContent, {
1290
- $alignRight: rightAlignedColumns.has(column.key),
1329
+ $align: value.typography?.tbody?.textAlign ?? (rightAlignedColumns.has(column.key) ? "right" : "left"),
1291
1330
  children: row.cells[column.key] ?? ""
1292
1331
  })
1293
1332
  }));
@@ -1404,6 +1443,17 @@ function FeesTable({ value, editable = false, onChange, labels, size = "md", tag
1404
1443
  }),
1405
1444
  canEdit && /* @__PURE__ */ _jsxs(EditorActions, {
1406
1445
  children: [
1446
+ /* @__PURE__ */ _jsx(EditorButton, {
1447
+ type: "button",
1448
+ onClick: () => {
1449
+ onChange?.({
1450
+ ...value,
1451
+ rows: sortFeesRowsByName(value.rows, language)
1452
+ });
1453
+ setPage(1);
1454
+ },
1455
+ children: english ? "Sort names A\u2013Z" : "S\u1EAFp x\u1EBFp t\xEAn A\u2013Z"
1456
+ }),
1407
1457
  /* @__PURE__ */ _jsx(EditorButton, {
1408
1458
  type: "button",
1409
1459
  onClick: () => {