@pisell/private-materials 6.3.220 → 6.3.222

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 (125) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/meta.js +1 -1
  5. package/build/lowcode/render/default/view.css +1 -1
  6. package/build/lowcode/render/default/view.js +13 -13
  7. package/build/lowcode/view.css +1 -1
  8. package/build/lowcode/view.js +13 -13
  9. package/es/components/kioskSkuDetail/index.js +7 -7
  10. package/es/components/pay/toC/PaymentMethods/MWCreditCard/tds2.js +53 -26
  11. package/es/components/scanOrder/components/Content/index.js +14 -2
  12. package/es/components/scanOrder/components/ExitConfirmModal/index.js +84 -0
  13. package/es/components/scanOrder/components/ExitConfirmModal/index.less +182 -0
  14. package/es/components/scanOrder/locales.js +20 -0
  15. package/es/index.d.ts +9 -1
  16. package/es/index.js +6 -2
  17. package/es/plus/inventory/BindingModal.js +94 -0
  18. package/es/plus/inventory/InventoryItemManagement.d.ts +7 -0
  19. package/es/plus/inventory/InventoryItemManagement.js +204 -0
  20. package/es/plus/inventory/InventoryLocationManagement.d.ts +7 -0
  21. package/es/plus/inventory/InventoryLocationManagement.js +296 -0
  22. package/es/plus/inventory/InventoryUnitManagement.d.ts +7 -0
  23. package/es/plus/inventory/InventoryUnitManagement.js +144 -0
  24. package/es/plus/inventory/ItemDrawer.js +266 -0
  25. package/es/plus/inventory/RecordDialog.js +141 -0
  26. package/es/plus/inventory/StockList.js +132 -0
  27. package/es/plus/inventory/api.js +66 -0
  28. package/es/plus/inventory/components.js +172 -0
  29. package/es/plus/inventory/context.js +118 -0
  30. package/es/plus/inventory/forms.js +46 -0
  31. package/es/plus/inventory/hooks.js +235 -0
  32. package/es/plus/inventory/index.less +559 -0
  33. package/es/plus/inventory/locales.js +277 -0
  34. package/es/plus/inventory/types.d.ts +10 -0
  35. package/es/plus/inventory/utils.js +24 -0
  36. package/es/plus/panpacificTask/JobCard.js +22 -0
  37. package/es/plus/panpacificTask/JobDrawer.js +366 -0
  38. package/es/plus/panpacificTask/JobForm.js +312 -0
  39. package/es/plus/panpacificTask/JobStatus.js +29 -0
  40. package/es/plus/panpacificTask/PanpacificTask.d.ts +7 -0
  41. package/es/plus/panpacificTask/PanpacificTask.js +552 -0
  42. package/es/plus/panpacificTask/PhotoPreview.js +37 -0
  43. package/es/plus/panpacificTask/README.md +114 -0
  44. package/es/plus/panpacificTask/attachments.js +64 -0
  45. package/es/plus/panpacificTask/index.d.ts +2 -0
  46. package/es/plus/panpacificTask/index.less +539 -0
  47. package/es/plus/panpacificTask/locales.js +586 -0
  48. package/es/plus/panpacificTask/model.js +260 -0
  49. package/es/plus/panpacificTask/saveJob.js +68 -0
  50. package/es/plus/panpacificTask/serve.js +243 -0
  51. package/es/plus/panpacificTask/tenant.js +16 -0
  52. package/es/plus/panpacificTask/types.d.ts +19 -0
  53. package/es/plus/pisellReservation/data/bookingToReservationTables.js +1 -1
  54. package/es/plus/pisellReservation/floorMap/floorPlanApi.js +1 -1
  55. package/es/plus/pisellReservation/floorMap/reservationMock.js +1 -1
  56. package/es/plus/pisellSupersetDashboard/README.md +291 -0
  57. package/es/plus/pisellSupersetDashboard/index.d.ts +15 -0
  58. package/es/plus/pisellSupersetDashboard/index.js +187 -0
  59. package/es/plus/pisellSupersetDashboard/index.less +83 -0
  60. package/es/plus/pisellSupersetDashboard/locales.js +36 -0
  61. package/es/plus/pisellSupersetDashboard/serve.js +51 -0
  62. package/es/plus/pisellSupersetDashboard/types.d.ts +17 -0
  63. package/es/plus/skuOptionsSelection/store/createStore.js +2 -2
  64. package/es/private-materials/lowcode/authmodal/meta.d.ts +1 -0
  65. package/es/pro/Login2.0/AuthModal.d.ts +1 -1
  66. package/es/pro/Login2.0/index.d.ts +1 -2
  67. package/es/pro/Login2.0/shared/types.d.ts +1 -1
  68. package/lib/components/kioskSkuDetail/index.js +7 -7
  69. package/lib/components/pay/toC/PaymentMethods/MWCreditCard/tds2.js +53 -26
  70. package/lib/components/scanOrder/components/Content/index.js +14 -2
  71. package/lib/components/scanOrder/components/ExitConfirmModal/index.js +86 -0
  72. package/lib/components/scanOrder/components/ExitConfirmModal/index.less +182 -0
  73. package/lib/components/scanOrder/locales.js +20 -0
  74. package/lib/index.d.ts +9 -1
  75. package/lib/index.js +136 -126
  76. package/lib/plus/inventory/BindingModal.js +96 -0
  77. package/lib/plus/inventory/InventoryItemManagement.d.ts +7 -0
  78. package/lib/plus/inventory/InventoryItemManagement.js +206 -0
  79. package/lib/plus/inventory/InventoryLocationManagement.d.ts +7 -0
  80. package/lib/plus/inventory/InventoryLocationManagement.js +298 -0
  81. package/lib/plus/inventory/InventoryUnitManagement.d.ts +7 -0
  82. package/lib/plus/inventory/InventoryUnitManagement.js +146 -0
  83. package/lib/plus/inventory/ItemDrawer.js +268 -0
  84. package/lib/plus/inventory/RecordDialog.js +143 -0
  85. package/lib/plus/inventory/StockList.js +134 -0
  86. package/lib/plus/inventory/api.js +66 -0
  87. package/lib/plus/inventory/components.js +181 -0
  88. package/lib/plus/inventory/context.js +121 -0
  89. package/lib/plus/inventory/forms.js +50 -0
  90. package/lib/plus/inventory/hooks.js +240 -0
  91. package/lib/plus/inventory/index.less +559 -0
  92. package/lib/plus/inventory/locales.js +277 -0
  93. package/lib/plus/inventory/types.d.ts +10 -0
  94. package/lib/plus/inventory/utils.js +30 -0
  95. package/lib/plus/panpacificTask/JobCard.js +24 -0
  96. package/lib/plus/panpacificTask/JobDrawer.js +368 -0
  97. package/lib/plus/panpacificTask/JobForm.js +314 -0
  98. package/lib/plus/panpacificTask/JobStatus.js +33 -0
  99. package/lib/plus/panpacificTask/PanpacificTask.d.ts +7 -0
  100. package/lib/plus/panpacificTask/PanpacificTask.js +555 -0
  101. package/lib/plus/panpacificTask/PhotoPreview.js +39 -0
  102. package/lib/plus/panpacificTask/README.md +114 -0
  103. package/lib/plus/panpacificTask/attachments.js +66 -0
  104. package/lib/plus/panpacificTask/index.d.ts +2 -0
  105. package/lib/plus/panpacificTask/index.less +539 -0
  106. package/lib/plus/panpacificTask/locales.js +586 -0
  107. package/lib/plus/panpacificTask/model.js +289 -0
  108. package/lib/plus/panpacificTask/saveJob.js +68 -0
  109. package/lib/plus/panpacificTask/serve.js +260 -0
  110. package/lib/plus/panpacificTask/tenant.js +17 -0
  111. package/lib/plus/panpacificTask/types.d.ts +19 -0
  112. package/lib/plus/pisellSupersetDashboard/README.md +291 -0
  113. package/lib/plus/pisellSupersetDashboard/index.d.ts +15 -0
  114. package/lib/plus/pisellSupersetDashboard/index.js +189 -0
  115. package/lib/plus/pisellSupersetDashboard/index.less +83 -0
  116. package/lib/plus/pisellSupersetDashboard/locales.js +36 -0
  117. package/lib/plus/pisellSupersetDashboard/serve.js +52 -0
  118. package/lib/plus/pisellSupersetDashboard/types.d.ts +17 -0
  119. package/lowcode/inventory-item-management/meta.ts +20 -0
  120. package/lowcode/inventory-location-management/meta.ts +20 -0
  121. package/lowcode/inventory-unit-management/meta.ts +20 -0
  122. package/lowcode/panpacific-task/meta.ts +51 -0
  123. package/lowcode/pisell-superset-dashboard/meta.ts +75 -0
  124. package/package.json +4 -2
  125. package/es/plus/pisellReservation/index.js +0 -17
@@ -0,0 +1,132 @@
1
+ import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
3
+ import { canUnbind, inventoryQuantity } from "./utils.js";
4
+ import { useInventory } from "./context.js";
5
+ import { useInventoryList, useInventoryMutation } from "./hooks.js";
6
+ import { InventoryTable, RequestError, StatusTag } from "./components.js";
7
+ import BindingModal from "./BindingModal.js";
8
+ import React, { useMemo, useState } from "react";
9
+ import { Alert, Button, Space, Tooltip } from "antd";
10
+ //#region src/plus/inventory/StockList.tsx
11
+ function StockList({ owner, id, onChanged }) {
12
+ const { api, t, name, confirm, success } = useInventory();
13
+ const [binding, setBinding] = useState(false);
14
+ const mutation = useInventoryMutation();
15
+ const list = useInventoryList("stock", {
16
+ [owner === "item" ? "item_id" : "space_id"]: id,
17
+ with: owner === "item" ? ["space.shelf.location"] : ["item.unit"]
18
+ });
19
+ const unbind = (stock) => void mutation.run(_asyncToGenerator(function* () {
20
+ if (!canUnbind(stock)) return;
21
+ if (!(yield confirm("unbindTitle", t("unbindHint")))) return;
22
+ try {
23
+ yield api.unbind(stock.id);
24
+ success("unbound");
25
+ } finally {
26
+ list.reload();
27
+ onChanged === null || onChanged === void 0 || onChanged();
28
+ }
29
+ }));
30
+ const columns = useMemo(() => {
31
+ return [
32
+ ...owner === "item" ? [{
33
+ title: t("path"),
34
+ key: "path",
35
+ dataIndex: "space_id",
36
+ width: 320,
37
+ render: (_, stock) => {
38
+ var _space$shelf, _space$shelf2, _space$shelf3;
39
+ const space = stock.space;
40
+ return /* @__PURE__ */ React.createElement("div", { className: "inventory-path" }, /* @__PURE__ */ React.createElement("span", null, space ? `${name((_space$shelf = space.shelf) === null || _space$shelf === void 0 ? void 0 : _space$shelf.location)} / ${name(space.shelf)} / ${name(space)}` : `${t("missing")} (#${stock.space_id})`), /* @__PURE__ */ React.createElement(Space, {
41
+ size: 4,
42
+ wrap: true
43
+ }, (space === null || space === void 0 || (_space$shelf2 = space.shelf) === null || _space$shelf2 === void 0 || (_space$shelf2 = _space$shelf2.location) === null || _space$shelf2 === void 0 ? void 0 : _space$shelf2.status) === "inactive" && /* @__PURE__ */ React.createElement("span", null, t("location"), ": ", /* @__PURE__ */ React.createElement(StatusTag, { status: "inactive" })), (space === null || space === void 0 || (_space$shelf3 = space.shelf) === null || _space$shelf3 === void 0 ? void 0 : _space$shelf3.status) === "inactive" && /* @__PURE__ */ React.createElement("span", null, t("shelf"), ": ", /* @__PURE__ */ React.createElement(StatusTag, { status: "inactive" })), (space === null || space === void 0 ? void 0 : space.status) === "inactive" && /* @__PURE__ */ React.createElement("span", null, t("space"), ": ", /* @__PURE__ */ React.createElement(StatusTag, { status: "inactive" }))));
44
+ }
45
+ }] : [{
46
+ title: t("item"),
47
+ key: "item",
48
+ dataIndex: "item_id",
49
+ width: 230,
50
+ render: (_, stock) => {
51
+ var _stock$item, _stock$item2;
52
+ return /* @__PURE__ */ React.createElement(Space, {
53
+ direction: "vertical",
54
+ size: 0
55
+ }, /* @__PURE__ */ React.createElement("span", null, stock.item ? name(stock.item) : `${t("missing")} (#${stock.item_id})`), /* @__PURE__ */ React.createElement("span", { className: "inventory-muted" }, ((_stock$item = stock.item) === null || _stock$item === void 0 ? void 0 : _stock$item.sku) || "—", " ", /* @__PURE__ */ React.createElement(StatusTag, { status: (_stock$item2 = stock.item) === null || _stock$item2 === void 0 ? void 0 : _stock$item2.status })));
56
+ }
57
+ }, {
58
+ title: t("unit"),
59
+ key: "unit",
60
+ dataIndex: "unit",
61
+ render: (_, stock) => {
62
+ var _stock$item3;
63
+ return ((_stock$item3 = stock.item) === null || _stock$item3 === void 0 ? void 0 : _stock$item3.unit) ? name(stock.item.unit) : "—";
64
+ }
65
+ }],
66
+ {
67
+ title: t("quantity"),
68
+ key: "quantity",
69
+ dataIndex: "quantity",
70
+ align: "right",
71
+ render: inventoryQuantity
72
+ },
73
+ {
74
+ title: t("available"),
75
+ key: "available_quantity",
76
+ dataIndex: "available_quantity",
77
+ align: "right",
78
+ render: inventoryQuantity
79
+ },
80
+ ...owner === "item" ? [{
81
+ title: t("actions"),
82
+ key: "actions",
83
+ dataIndex: "actions",
84
+ render: (_, stock) => /* @__PURE__ */ React.createElement(Tooltip, { title: !canUnbind(stock) ? t("unbindBlocked") : void 0 }, /* @__PURE__ */ React.createElement("span", null, /* @__PURE__ */ React.createElement(Button, {
85
+ type: "link",
86
+ danger: true,
87
+ disabled: !canUnbind(stock) || mutation.busy || list.loading,
88
+ onClick: () => unbind(stock)
89
+ }, t("unbind"))))
90
+ }] : []
91
+ ];
92
+ }, [
93
+ owner,
94
+ t,
95
+ name,
96
+ mutation.busy,
97
+ list.loading,
98
+ confirm,
99
+ api,
100
+ onChanged
101
+ ]);
102
+ return /* @__PURE__ */ React.createElement("section", { className: "inventory-stock-list" }, /* @__PURE__ */ React.createElement(Alert, {
103
+ type: "info",
104
+ showIcon: true,
105
+ className: "inventory-notice",
106
+ message: t("stockReadOnly")
107
+ }), /* @__PURE__ */ React.createElement("div", { className: "inventory-toolbar inventory-toolbar-end" }, /* @__PURE__ */ React.createElement(Button, {
108
+ onClick: list.reload,
109
+ disabled: mutation.busy
110
+ }, t("refresh")), owner === "item" && /* @__PURE__ */ React.createElement(Button, {
111
+ type: "primary",
112
+ onClick: () => setBinding(true),
113
+ disabled: mutation.busy
114
+ }, t("bind"))), /* @__PURE__ */ React.createElement(RequestError, {
115
+ error: list.error,
116
+ retry: list.reload
117
+ }), /* @__PURE__ */ React.createElement(InventoryTable, _objectSpread2(_objectSpread2({}, list), {}, {
118
+ columns,
119
+ loading: list.loading || mutation.busy,
120
+ tableKey: `${owner}-${id}-stocks`
121
+ })), binding && /* @__PURE__ */ React.createElement(BindingModal, {
122
+ itemId: id,
123
+ onClose: () => setBinding(false),
124
+ onBound: () => {
125
+ setBinding(false);
126
+ list.reload();
127
+ onChanged === null || onChanged === void 0 || onChanged();
128
+ }
129
+ }));
130
+ }
131
+ //#endregion
132
+ export { StockList as default };
@@ -0,0 +1,66 @@
1
+ import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
2
+ //#region src/plus/inventory/api.ts
3
+ var InventoryRequestError = class extends Error {
4
+ constructor(message, code) {
5
+ super(message);
6
+ this.code = code;
7
+ this.name = "InventoryRequestError";
8
+ }
9
+ };
10
+ const CONFIG = {
11
+ isPisell2: true,
12
+ fullResult: true,
13
+ customToast: () => void 0
14
+ };
15
+ const PREFIX = "/tenant/inventory";
16
+ function createInventoryApi(client) {
17
+ function call(_x, _x2, _x3) {
18
+ return _call.apply(this, arguments);
19
+ }
20
+ function _call() {
21
+ _call = _asyncToGenerator(function* (method, path, params) {
22
+ if (!(client === null || client === void 0 ? void 0 : client[method])) throw new InventoryRequestError("noRequest");
23
+ const result = yield method === "remove" ? client.remove(`${PREFIX}/${path}`, CONFIG) : client[method](`${PREFIX}/${path}`, params, CONFIG);
24
+ if (!result || result.status !== true || result.code !== 200) throw new InventoryRequestError((result === null || result === void 0 ? void 0 : result.message) || "failed", result === null || result === void 0 ? void 0 : result.code);
25
+ return result.data;
26
+ });
27
+ return _call.apply(this, arguments);
28
+ }
29
+ function list(_x4, _x5) {
30
+ return _list.apply(this, arguments);
31
+ }
32
+ function _list() {
33
+ _list = _asyncToGenerator(function* (resource, params) {
34
+ const data = yield call("get", resource, params);
35
+ if (!data || !Array.isArray(data.list) || typeof data.count !== "number") throw new InventoryRequestError("invalidResponse");
36
+ return data;
37
+ });
38
+ return _list.apply(this, arguments);
39
+ }
40
+ return {
41
+ list,
42
+ units() {
43
+ return _asyncToGenerator(function* (params = {}) {
44
+ const data = yield call("get", "item-unit", params);
45
+ if (data !== null && !Array.isArray(data)) throw new InventoryRequestError("invalidResponse");
46
+ return data !== null && data !== void 0 ? data : [];
47
+ }).apply(this, arguments);
48
+ },
49
+ detail: (resource, id, withRelations) => call("get", `${resource}/${id}`, withRelations ? { with: withRelations } : {}),
50
+ save(resource, id, payload) {
51
+ return _asyncToGenerator(function* () {
52
+ const data = yield call(id ? "put" : "post", id ? `${resource}/${id}` : resource, payload);
53
+ if (!data || !Number.isInteger(data.id) || data.id <= 0) throw new InventoryRequestError("invalidResponse");
54
+ return data;
55
+ })();
56
+ },
57
+ remove: (resource, id) => call("remove", `${resource}/${id}`),
58
+ bind: (itemId, spaceId) => call("post", "stock", {
59
+ item_id: itemId,
60
+ space_id: spaceId
61
+ }),
62
+ unbind: (stockId) => call("remove", `stock/${stockId}`)
63
+ };
64
+ }
65
+ //#endregion
66
+ export { createInventoryApi };
@@ -0,0 +1,172 @@
1
+ import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ import { useInventory } from "./context.js";
3
+ import { useInventoryOptions } from "./hooks.js";
4
+ import React, { useMemo, useState } from "react";
5
+ import { Alert, Button, Empty, Input, Pagination, Select, Space, Spin, Tag } from "antd";
6
+ import { PisellDataSourceContainer } from "@pisell/materials";
7
+ import { useDebounce } from "ahooks";
8
+ import { LoadingOutlined } from "@ant-design/icons";
9
+ //#region src/plus/inventory/components.tsx
10
+ function RequestError({ error, retry }) {
11
+ const { errorText, t } = useInventory();
12
+ return error ? /* @__PURE__ */ React.createElement(Alert, {
13
+ type: "error",
14
+ showIcon: true,
15
+ message: errorText(error),
16
+ action: /* @__PURE__ */ React.createElement(Button, { onClick: retry }, t("retry"))
17
+ }) : null;
18
+ }
19
+ function StatusTag({ status }) {
20
+ const { t } = useInventory();
21
+ return status ? /* @__PURE__ */ React.createElement(Tag, { color: status === "active" ? "green" : "default" }, t(status)) : null;
22
+ }
23
+ function StatusSelect({ value, onChange }) {
24
+ const { t } = useInventory();
25
+ return /* @__PURE__ */ React.createElement(Select, {
26
+ className: "inventory-filter",
27
+ allowClear: true,
28
+ placeholder: t("allStatuses"),
29
+ value,
30
+ onChange,
31
+ options: ["active", "inactive"].map((status) => ({
32
+ value: status,
33
+ label: t(status)
34
+ }))
35
+ });
36
+ }
37
+ function SearchInput({ value, onChange, items = false }) {
38
+ const { t } = useInventory();
39
+ return /* @__PURE__ */ React.createElement(Input.Search, {
40
+ className: "inventory-search",
41
+ allowClear: true,
42
+ placeholder: t(items ? "searchItems" : "search"),
43
+ "aria-label": t(items ? "searchItems" : "search"),
44
+ value,
45
+ onChange: (event) => onChange(event.target.value)
46
+ });
47
+ }
48
+ function InventoryHeader({ title, description, children }) {
49
+ return /* @__PURE__ */ React.createElement("header", { className: "inventory-header" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h2", null, title), description && /* @__PURE__ */ React.createElement("p", null, description)), /* @__PURE__ */ React.createElement(Space, { wrap: true }, children));
50
+ }
51
+ function InventoryNavLoading() {
52
+ const { t } = useInventory();
53
+ return /* @__PURE__ */ React.createElement("div", {
54
+ className: "inventory-nav-loading",
55
+ role: "status"
56
+ }, /* @__PURE__ */ React.createElement(Spin, {
57
+ size: "small",
58
+ indicator: /* @__PURE__ */ React.createElement(LoadingOutlined, {
59
+ spin: true,
60
+ style: { fontSize: 16 }
61
+ })
62
+ }), /* @__PURE__ */ React.createElement("span", null, t("loading")));
63
+ }
64
+ function TableContent({ columns, loading, tableKey }) {
65
+ const context = PisellDataSourceContainer.useContainerContext();
66
+ const { t, scopeId } = useInventory();
67
+ return /* @__PURE__ */ React.createElement(Spin, {
68
+ spinning: loading,
69
+ delay: 150,
70
+ indicator: /* @__PURE__ */ React.createElement(LoadingOutlined, {
71
+ spin: true,
72
+ style: { fontSize: 24 }
73
+ }),
74
+ tip: t("loading"),
75
+ wrapperClassName: "inventory-table-loading"
76
+ }, /* @__PURE__ */ React.createElement(PisellDataSourceContainer.Table, _objectSpread2(_objectSpread2({}, context), {}, {
77
+ serverActions: _objectSpread2(_objectSpread2({}, context.serverActions), {}, { list: _objectSpread2(_objectSpread2({}, context.serverActions.list), {}, { loading: false }) }),
78
+ columns,
79
+ rowKey: "id",
80
+ scroll: { x: "max-content" },
81
+ __id: `${scopeId}-${tableKey}`,
82
+ scopeId: tableKey,
83
+ locale: { emptyText: loading ? /* @__PURE__ */ React.createElement("div", {
84
+ className: "inventory-table-loading-placeholder",
85
+ "aria-hidden": true
86
+ }) : /* @__PURE__ */ React.createElement(Empty, {
87
+ image: Empty.PRESENTED_IMAGE_SIMPLE,
88
+ description: t("empty")
89
+ }) }
90
+ })));
91
+ }
92
+ function InventoryTable(props) {
93
+ const { t, scopeId } = useInventory();
94
+ const overrideData = useMemo(() => ({ list: {
95
+ list: props.rows,
96
+ count: props.count
97
+ } }), [props.rows, props.count]);
98
+ const dataSource = useMemo(() => ({ key: `${scopeId}-${props.tableKey}` }), [scopeId, props.tableKey]);
99
+ return /* @__PURE__ */ React.createElement("div", { className: "inventory-table" }, /* @__PURE__ */ React.createElement(PisellDataSourceContainer, {
100
+ dataSource,
101
+ autoRun: { list: false },
102
+ pagination: false,
103
+ overrideData
104
+ }, /* @__PURE__ */ React.createElement(TableContent, {
105
+ columns: props.columns,
106
+ loading: props.loading,
107
+ tableKey: props.tableKey
108
+ })), /* @__PURE__ */ React.createElement(Pagination, {
109
+ className: "inventory-pagination",
110
+ current: props.page,
111
+ pageSize: props.size,
112
+ total: props.count,
113
+ showSizeChanger: true,
114
+ pageSizeOptions: [
115
+ 20,
116
+ 50,
117
+ 100
118
+ ],
119
+ onChange: props.onPageChange,
120
+ showTotal: (count) => `${t("count")} ${count}`,
121
+ disabled: props.loading
122
+ }));
123
+ }
124
+ function PagedInventorySelect({ resource, value, onChange, filters = {}, disabled = false, selected, placeholder, id }) {
125
+ const { name, t } = useInventory();
126
+ const [search, setSearch] = useState("");
127
+ const keyword = useDebounce(search, { wait: 250 });
128
+ const [revision, setRevision] = useState(0);
129
+ const [chosenRecord, setChosenRecord] = useState();
130
+ const options = useInventoryOptions(resource, _objectSpread2(_objectSpread2({}, filters), {}, { search: keyword || void 0 }), !disabled, revision);
131
+ const fallback = (chosenRecord === null || chosenRecord === void 0 ? void 0 : chosenRecord.id) === value ? chosenRecord : (selected === null || selected === void 0 ? void 0 : selected.id) === value ? selected : void 0;
132
+ const rows = fallback && !options.rows.some((record) => record.id === value) ? [fallback, ...options.rows] : options.rows;
133
+ return /* @__PURE__ */ React.createElement(Select, {
134
+ id,
135
+ style: { width: "100%" },
136
+ showSearch: true,
137
+ allowClear: true,
138
+ filterOption: false,
139
+ value,
140
+ placeholder,
141
+ disabled,
142
+ loading: options.loading,
143
+ onSearch: setSearch,
144
+ onChange: (nextValue) => {
145
+ setChosenRecord(rows.find((record) => record.id === nextValue));
146
+ onChange === null || onChange === void 0 || onChange(nextValue);
147
+ },
148
+ onDropdownVisibleChange: (open) => {
149
+ if (open) {
150
+ setSearch("");
151
+ setRevision((n) => n + 1);
152
+ }
153
+ },
154
+ options: rows.map((record) => ({
155
+ value: record.id,
156
+ label: `${name(record)}${record.status === "inactive" ? ` (${t("inactive")})` : ""}`
157
+ })),
158
+ notFoundContent: options.loading ? t("loading") : t("empty"),
159
+ dropdownRender: (menu) => /* @__PURE__ */ React.createElement(React.Fragment, null, menu, /* @__PURE__ */ React.createElement(RequestError, {
160
+ error: options.error,
161
+ retry: () => void options.reload()
162
+ }), options.hasMore && /* @__PURE__ */ React.createElement(Button, {
163
+ block: true,
164
+ type: "text",
165
+ loading: options.loading,
166
+ onMouseDown: (event) => event.preventDefault(),
167
+ onClick: () => void options.loadMore()
168
+ }, t("loadMore")))
169
+ });
170
+ }
171
+ //#endregion
172
+ export { InventoryHeader, InventoryNavLoading, InventoryTable, PagedInventorySelect, RequestError, SearchInput, StatusSelect, StatusTag };
@@ -0,0 +1,118 @@
1
+ import useEngineContext from "../../hooks/useEngineContext.js";
2
+ import useLocale from "../../hooks/useLocale.js";
3
+ import { createInventoryApi } from "./api.js";
4
+ import { getInventoryTexts } from "./locales.js";
5
+ import { inventoryName } from "./utils.js";
6
+ import React, { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
7
+ import { ConfigProvider } from "antd";
8
+ import { PisellModal, PisellToast } from "@pisell/materials";
9
+ import "./index.less";
10
+ //#region src/plus/inventory/context.tsx
11
+ const InventoryContext = createContext(null);
12
+ function InventorySession({ children, client, locale, id }) {
13
+ const instanceId = useId();
14
+ const [confirmation, setConfirmation] = useState(null);
15
+ const resolveConfirmation = useRef(null);
16
+ const api = useMemo(() => createInventoryApi(client), [client]);
17
+ const texts = getInventoryTexts(locale);
18
+ const t = useCallback((key) => texts[key], [texts]);
19
+ const name = useCallback((record) => record ? inventoryName(record.name, locale) : t("missing"), [locale, t]);
20
+ const errorText = useCallback((error) => {
21
+ const messageValue = error && typeof error === "object" && "message" in error ? error.message : error;
22
+ const text = typeof messageValue === "string" ? messageValue : "";
23
+ return Object.prototype.hasOwnProperty.call(texts, text) ? t(text) : text || t("failed");
24
+ }, [texts, t]);
25
+ const report = useCallback((error) => {
26
+ PisellToast({ content: errorText(error) });
27
+ }, [errorText]);
28
+ const success = useCallback((key) => {
29
+ PisellToast({ content: t(key) });
30
+ }, [t]);
31
+ const finishConfirmation = useCallback((accepted) => {
32
+ const resolve = resolveConfirmation.current;
33
+ resolveConfirmation.current = null;
34
+ setConfirmation(null);
35
+ resolve === null || resolve === void 0 || resolve(accepted);
36
+ }, []);
37
+ useEffect(() => () => {
38
+ var _resolveConfirmation$;
39
+ (_resolveConfirmation$ = resolveConfirmation.current) === null || _resolveConfirmation$ === void 0 || _resolveConfirmation$.call(resolveConfirmation, false);
40
+ resolveConfirmation.current = null;
41
+ }, []);
42
+ const confirm = useCallback((title, content, discard = false) => {
43
+ if (resolveConfirmation.current) return Promise.resolve(false);
44
+ return new Promise((resolve) => {
45
+ resolveConfirmation.current = resolve;
46
+ setConfirmation({
47
+ title,
48
+ content,
49
+ discard
50
+ });
51
+ });
52
+ }, []);
53
+ const value = useMemo(() => ({
54
+ api,
55
+ locale,
56
+ t,
57
+ name,
58
+ errorText,
59
+ report,
60
+ success,
61
+ confirm,
62
+ scopeId: id || instanceId
63
+ }), [
64
+ api,
65
+ locale,
66
+ t,
67
+ name,
68
+ errorText,
69
+ report,
70
+ success,
71
+ confirm,
72
+ id,
73
+ instanceId
74
+ ]);
75
+ return /* @__PURE__ */ React.createElement(InventoryContext.Provider, { value }, children, confirmation && /* @__PURE__ */ React.createElement(PisellModal, {
76
+ open: true,
77
+ size: "small",
78
+ title: t(confirmation.title),
79
+ okText: t(confirmation.discard ? "discard" : confirmation.title === "unbindTitle" ? "unbind" : "remove"),
80
+ cancelText: t("cancel"),
81
+ okButtonProps: { danger: true },
82
+ maskClosable: false,
83
+ onOk: () => finishConfirmation(true),
84
+ onCancel: () => finishConfirmation(false)
85
+ }, /* @__PURE__ */ React.createElement("div", { className: "inventory-modal-body" }, confirmation.content)));
86
+ }
87
+ function InventoryProvider({ children, id }) {
88
+ var _context$appHelper;
89
+ const context = useEngineContext();
90
+ const locale = useLocale();
91
+ const utils = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
92
+ const store = utils === null || utils === void 0 ? void 0 : utils.store;
93
+ const subscribe = useCallback((listener) => {
94
+ var _store$subscribe;
95
+ return (store === null || store === void 0 || (_store$subscribe = store.subscribe) === null || _store$subscribe === void 0 ? void 0 : _store$subscribe.call(store, listener)) || (() => void 0);
96
+ }, [store]);
97
+ const getTenant = useCallback(() => {
98
+ var _store$getState$core$, _store$getState;
99
+ return String((_store$getState$core$ = store === null || store === void 0 || (_store$getState = store.getState) === null || _store$getState === void 0 || (_store$getState = _store$getState.call(store)) === null || _store$getState === void 0 || (_store$getState = _store$getState.core) === null || _store$getState === void 0 || (_store$getState = _store$getState.core) === null || _store$getState === void 0 || (_store$getState = _store$getState.tenant) === null || _store$getState === void 0 ? void 0 : _store$getState.tenant_id) !== null && _store$getState$core$ !== void 0 ? _store$getState$core$ : "");
100
+ }, [store]);
101
+ const tenant = useSyncExternalStore(subscribe, getTenant, getTenant);
102
+ return /* @__PURE__ */ React.createElement(ConfigProvider, {
103
+ prefixCls: "pisell-lowcode",
104
+ componentSize: "large"
105
+ }, /* @__PURE__ */ React.createElement(InventorySession, {
106
+ key: tenant,
107
+ client: utils === null || utils === void 0 ? void 0 : utils.request,
108
+ locale: locale || "en",
109
+ id
110
+ }, children));
111
+ }
112
+ function useInventory() {
113
+ const context = useContext(InventoryContext);
114
+ if (!context) throw new Error("InventoryProvider is required");
115
+ return context;
116
+ }
117
+ //#endregion
118
+ export { InventoryProvider, useInventory };
@@ -0,0 +1,46 @@
1
+ import { useInventory } from "./context.js";
2
+ import React from "react";
3
+ import { Form, InputNumber, Select } from "antd";
4
+ import { BaseTranslation } from "@pisell/materials";
5
+ //#region src/plus/inventory/forms.tsx
6
+ function NameField({ disabled = false }) {
7
+ const { t } = useInventory();
8
+ return /* @__PURE__ */ React.createElement(Form.Item, {
9
+ name: "name",
10
+ label: t("name"),
11
+ rules: [{ validator: (_, value) => typeof (value === null || value === void 0 ? void 0 : value.original) === "string" && value.original.trim() ? Promise.resolve() : Promise.reject(new Error(t("originalRequired"))) }]
12
+ }, /* @__PURE__ */ React.createElement(BaseTranslation, {
13
+ renderMode: disabled ? "view" : "edit",
14
+ disabled,
15
+ placeholder: t("name")
16
+ }));
17
+ }
18
+ function StatusField() {
19
+ const { t } = useInventory();
20
+ return /* @__PURE__ */ React.createElement(Form.Item, {
21
+ name: "status",
22
+ label: t("status"),
23
+ rules: [{
24
+ required: true,
25
+ message: t("required")
26
+ }]
27
+ }, /* @__PURE__ */ React.createElement(Select, { options: ["active", "inactive"].map((value) => ({
28
+ value,
29
+ label: t(value)
30
+ })) }));
31
+ }
32
+ function SortField() {
33
+ const { t } = useInventory();
34
+ return /* @__PURE__ */ React.createElement(Form.Item, {
35
+ name: "sort",
36
+ label: t("sort"),
37
+ extra: t("sortHint"),
38
+ rules: [{ validator: (_, value) => Number.isInteger(value) && value >= 0 ? Promise.resolve() : Promise.reject(new Error(t("nonnegative"))) }]
39
+ }, /* @__PURE__ */ React.createElement(InputNumber, {
40
+ min: 0,
41
+ precision: 0,
42
+ style: { width: "100%" }
43
+ }));
44
+ }
45
+ //#endregion
46
+ export { NameField, SortField, StatusField };