@pisell/private-materials 3.4.156 → 3.4.158

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 (70) 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 +14 -14
  7. package/build/lowcode/view.css +1 -1
  8. package/build/lowcode/view.js +14 -14
  9. package/es/index.d.ts +7 -1
  10. package/es/index.js +5 -1
  11. package/es/plus/inventory/BindingModal.js +94 -0
  12. package/es/plus/inventory/InventoryItemManagement.d.ts +7 -0
  13. package/es/plus/inventory/InventoryItemManagement.js +204 -0
  14. package/es/plus/inventory/InventoryLocationManagement.d.ts +7 -0
  15. package/es/plus/inventory/InventoryLocationManagement.js +296 -0
  16. package/es/plus/inventory/InventoryUnitManagement.d.ts +7 -0
  17. package/es/plus/inventory/InventoryUnitManagement.js +144 -0
  18. package/es/plus/inventory/ItemDrawer.js +266 -0
  19. package/es/plus/inventory/RecordDialog.js +141 -0
  20. package/es/plus/inventory/StockList.js +132 -0
  21. package/es/plus/inventory/api.js +66 -0
  22. package/es/plus/inventory/components.js +172 -0
  23. package/es/plus/inventory/context.js +118 -0
  24. package/es/plus/inventory/forms.js +46 -0
  25. package/es/plus/inventory/hooks.js +235 -0
  26. package/es/plus/inventory/index.less +559 -0
  27. package/es/plus/inventory/locales.js +277 -0
  28. package/es/plus/inventory/types.d.ts +10 -0
  29. package/es/plus/inventory/utils.js +24 -0
  30. package/es/plus/pisellSupersetDashboard/README.md +291 -0
  31. package/es/plus/pisellSupersetDashboard/index.d.ts +15 -0
  32. package/es/plus/pisellSupersetDashboard/index.js +187 -0
  33. package/es/plus/pisellSupersetDashboard/index.less +83 -0
  34. package/es/plus/pisellSupersetDashboard/locales.js +36 -0
  35. package/es/plus/pisellSupersetDashboard/serve.js +51 -0
  36. package/es/plus/pisellSupersetDashboard/types.d.ts +17 -0
  37. package/es/plus/skuOptionsSelection/store/createStore.js +2 -2
  38. package/lib/index.d.ts +7 -1
  39. package/lib/index.js +134 -126
  40. package/lib/plus/inventory/BindingModal.js +96 -0
  41. package/lib/plus/inventory/InventoryItemManagement.d.ts +7 -0
  42. package/lib/plus/inventory/InventoryItemManagement.js +206 -0
  43. package/lib/plus/inventory/InventoryLocationManagement.d.ts +7 -0
  44. package/lib/plus/inventory/InventoryLocationManagement.js +298 -0
  45. package/lib/plus/inventory/InventoryUnitManagement.d.ts +7 -0
  46. package/lib/plus/inventory/InventoryUnitManagement.js +146 -0
  47. package/lib/plus/inventory/ItemDrawer.js +268 -0
  48. package/lib/plus/inventory/RecordDialog.js +143 -0
  49. package/lib/plus/inventory/StockList.js +134 -0
  50. package/lib/plus/inventory/api.js +66 -0
  51. package/lib/plus/inventory/components.js +181 -0
  52. package/lib/plus/inventory/context.js +121 -0
  53. package/lib/plus/inventory/forms.js +50 -0
  54. package/lib/plus/inventory/hooks.js +240 -0
  55. package/lib/plus/inventory/index.less +559 -0
  56. package/lib/plus/inventory/locales.js +277 -0
  57. package/lib/plus/inventory/types.d.ts +10 -0
  58. package/lib/plus/inventory/utils.js +30 -0
  59. package/lib/plus/pisellSupersetDashboard/README.md +291 -0
  60. package/lib/plus/pisellSupersetDashboard/index.d.ts +15 -0
  61. package/lib/plus/pisellSupersetDashboard/index.js +189 -0
  62. package/lib/plus/pisellSupersetDashboard/index.less +83 -0
  63. package/lib/plus/pisellSupersetDashboard/locales.js +36 -0
  64. package/lib/plus/pisellSupersetDashboard/serve.js +52 -0
  65. package/lib/plus/pisellSupersetDashboard/types.d.ts +17 -0
  66. package/lowcode/inventory-item-management/meta.ts +20 -0
  67. package/lowcode/inventory-location-management/meta.ts +20 -0
  68. package/lowcode/inventory-unit-management/meta.ts +20 -0
  69. package/lowcode/pisell-superset-dashboard/meta.ts +75 -0
  70. package/package.json +5 -3
@@ -0,0 +1,181 @@
1
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
2
+ const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
3
+ const require_context = require("./context.js");
4
+ const require_hooks = require("./hooks.js");
5
+ let react = require("react");
6
+ react = require_runtime.__toESM(react);
7
+ let antd = require("antd");
8
+ let _pisell_materials = require("@pisell/materials");
9
+ let ahooks = require("ahooks");
10
+ let _ant_design_icons = require("@ant-design/icons");
11
+ //#region src/plus/inventory/components.tsx
12
+ function RequestError({ error, retry }) {
13
+ const { errorText, t } = require_context.useInventory();
14
+ return error ? /* @__PURE__ */ react.default.createElement(antd.Alert, {
15
+ type: "error",
16
+ showIcon: true,
17
+ message: errorText(error),
18
+ action: /* @__PURE__ */ react.default.createElement(antd.Button, { onClick: retry }, t("retry"))
19
+ }) : null;
20
+ }
21
+ function StatusTag({ status }) {
22
+ const { t } = require_context.useInventory();
23
+ return status ? /* @__PURE__ */ react.default.createElement(antd.Tag, { color: status === "active" ? "green" : "default" }, t(status)) : null;
24
+ }
25
+ function StatusSelect({ value, onChange }) {
26
+ const { t } = require_context.useInventory();
27
+ return /* @__PURE__ */ react.default.createElement(antd.Select, {
28
+ className: "inventory-filter",
29
+ allowClear: true,
30
+ placeholder: t("allStatuses"),
31
+ value,
32
+ onChange,
33
+ options: ["active", "inactive"].map((status) => ({
34
+ value: status,
35
+ label: t(status)
36
+ }))
37
+ });
38
+ }
39
+ function SearchInput({ value, onChange, items = false }) {
40
+ const { t } = require_context.useInventory();
41
+ return /* @__PURE__ */ react.default.createElement(antd.Input.Search, {
42
+ className: "inventory-search",
43
+ allowClear: true,
44
+ placeholder: t(items ? "searchItems" : "search"),
45
+ "aria-label": t(items ? "searchItems" : "search"),
46
+ value,
47
+ onChange: (event) => onChange(event.target.value)
48
+ });
49
+ }
50
+ function InventoryHeader({ title, description, children }) {
51
+ return /* @__PURE__ */ react.default.createElement("header", { className: "inventory-header" }, /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("h2", null, title), description && /* @__PURE__ */ react.default.createElement("p", null, description)), /* @__PURE__ */ react.default.createElement(antd.Space, { wrap: true }, children));
52
+ }
53
+ function InventoryNavLoading() {
54
+ const { t } = require_context.useInventory();
55
+ return /* @__PURE__ */ react.default.createElement("div", {
56
+ className: "inventory-nav-loading",
57
+ role: "status"
58
+ }, /* @__PURE__ */ react.default.createElement(antd.Spin, {
59
+ size: "small",
60
+ indicator: /* @__PURE__ */ react.default.createElement(_ant_design_icons.LoadingOutlined, {
61
+ spin: true,
62
+ style: { fontSize: 16 }
63
+ })
64
+ }), /* @__PURE__ */ react.default.createElement("span", null, t("loading")));
65
+ }
66
+ function TableContent({ columns, loading, tableKey }) {
67
+ const context = _pisell_materials.PisellDataSourceContainer.useContainerContext();
68
+ const { t, scopeId } = require_context.useInventory();
69
+ return /* @__PURE__ */ react.default.createElement(antd.Spin, {
70
+ spinning: loading,
71
+ delay: 150,
72
+ indicator: /* @__PURE__ */ react.default.createElement(_ant_design_icons.LoadingOutlined, {
73
+ spin: true,
74
+ style: { fontSize: 24 }
75
+ }),
76
+ tip: t("loading"),
77
+ wrapperClassName: "inventory-table-loading"
78
+ }, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellDataSourceContainer.Table, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, context), {}, {
79
+ serverActions: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, context.serverActions), {}, { list: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, context.serverActions.list), {}, { loading: false }) }),
80
+ columns,
81
+ rowKey: "id",
82
+ scroll: { x: "max-content" },
83
+ __id: `${scopeId}-${tableKey}`,
84
+ scopeId: tableKey,
85
+ locale: { emptyText: loading ? /* @__PURE__ */ react.default.createElement("div", {
86
+ className: "inventory-table-loading-placeholder",
87
+ "aria-hidden": true
88
+ }) : /* @__PURE__ */ react.default.createElement(antd.Empty, {
89
+ image: antd.Empty.PRESENTED_IMAGE_SIMPLE,
90
+ description: t("empty")
91
+ }) }
92
+ })));
93
+ }
94
+ function InventoryTable(props) {
95
+ const { t, scopeId } = require_context.useInventory();
96
+ const overrideData = (0, react.useMemo)(() => ({ list: {
97
+ list: props.rows,
98
+ count: props.count
99
+ } }), [props.rows, props.count]);
100
+ const dataSource = (0, react.useMemo)(() => ({ key: `${scopeId}-${props.tableKey}` }), [scopeId, props.tableKey]);
101
+ return /* @__PURE__ */ react.default.createElement("div", { className: "inventory-table" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellDataSourceContainer, {
102
+ dataSource,
103
+ autoRun: { list: false },
104
+ pagination: false,
105
+ overrideData
106
+ }, /* @__PURE__ */ react.default.createElement(TableContent, {
107
+ columns: props.columns,
108
+ loading: props.loading,
109
+ tableKey: props.tableKey
110
+ })), /* @__PURE__ */ react.default.createElement(antd.Pagination, {
111
+ className: "inventory-pagination",
112
+ current: props.page,
113
+ pageSize: props.size,
114
+ total: props.count,
115
+ showSizeChanger: true,
116
+ pageSizeOptions: [
117
+ 20,
118
+ 50,
119
+ 100
120
+ ],
121
+ onChange: props.onPageChange,
122
+ showTotal: (count) => `${t("count")} ${count}`,
123
+ disabled: props.loading
124
+ }));
125
+ }
126
+ function PagedInventorySelect({ resource, value, onChange, filters = {}, disabled = false, selected, placeholder, id }) {
127
+ const { name, t } = require_context.useInventory();
128
+ const [search, setSearch] = (0, react.useState)("");
129
+ const keyword = (0, ahooks.useDebounce)(search, { wait: 250 });
130
+ const [revision, setRevision] = (0, react.useState)(0);
131
+ const [chosenRecord, setChosenRecord] = (0, react.useState)();
132
+ const options = require_hooks.useInventoryOptions(resource, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, filters), {}, { search: keyword || void 0 }), !disabled, revision);
133
+ 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;
134
+ const rows = fallback && !options.rows.some((record) => record.id === value) ? [fallback, ...options.rows] : options.rows;
135
+ return /* @__PURE__ */ react.default.createElement(antd.Select, {
136
+ id,
137
+ style: { width: "100%" },
138
+ showSearch: true,
139
+ allowClear: true,
140
+ filterOption: false,
141
+ value,
142
+ placeholder,
143
+ disabled,
144
+ loading: options.loading,
145
+ onSearch: setSearch,
146
+ onChange: (nextValue) => {
147
+ setChosenRecord(rows.find((record) => record.id === nextValue));
148
+ onChange === null || onChange === void 0 || onChange(nextValue);
149
+ },
150
+ onDropdownVisibleChange: (open) => {
151
+ if (open) {
152
+ setSearch("");
153
+ setRevision((n) => n + 1);
154
+ }
155
+ },
156
+ options: rows.map((record) => ({
157
+ value: record.id,
158
+ label: `${name(record)}${record.status === "inactive" ? ` (${t("inactive")})` : ""}`
159
+ })),
160
+ notFoundContent: options.loading ? t("loading") : t("empty"),
161
+ dropdownRender: (menu) => /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, menu, /* @__PURE__ */ react.default.createElement(RequestError, {
162
+ error: options.error,
163
+ retry: () => void options.reload()
164
+ }), options.hasMore && /* @__PURE__ */ react.default.createElement(antd.Button, {
165
+ block: true,
166
+ type: "text",
167
+ loading: options.loading,
168
+ onMouseDown: (event) => event.preventDefault(),
169
+ onClick: () => void options.loadMore()
170
+ }, t("loadMore")))
171
+ });
172
+ }
173
+ //#endregion
174
+ exports.InventoryHeader = InventoryHeader;
175
+ exports.InventoryNavLoading = InventoryNavLoading;
176
+ exports.InventoryTable = InventoryTable;
177
+ exports.PagedInventorySelect = PagedInventorySelect;
178
+ exports.RequestError = RequestError;
179
+ exports.SearchInput = SearchInput;
180
+ exports.StatusSelect = StatusSelect;
181
+ exports.StatusTag = StatusTag;
@@ -0,0 +1,121 @@
1
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
2
+ const require_useEngineContext = require("../../hooks/useEngineContext.js");
3
+ const require_useLocale = require("../../hooks/useLocale.js");
4
+ const require_api = require("./api.js");
5
+ const require_locales = require("./locales.js");
6
+ const require_utils = require("./utils.js");
7
+ let react = require("react");
8
+ react = require_runtime.__toESM(react);
9
+ let antd = require("antd");
10
+ let _pisell_materials = require("@pisell/materials");
11
+ require("./index.less");
12
+ //#region src/plus/inventory/context.tsx
13
+ const InventoryContext = (0, react.createContext)(null);
14
+ function InventorySession({ children, client, locale, id }) {
15
+ const instanceId = (0, react.useId)();
16
+ const [confirmation, setConfirmation] = (0, react.useState)(null);
17
+ const resolveConfirmation = (0, react.useRef)(null);
18
+ const api = (0, react.useMemo)(() => require_api.createInventoryApi(client), [client]);
19
+ const texts = require_locales.getInventoryTexts(locale);
20
+ const t = (0, react.useCallback)((key) => texts[key], [texts]);
21
+ const name = (0, react.useCallback)((record) => record ? require_utils.inventoryName(record.name, locale) : t("missing"), [locale, t]);
22
+ const errorText = (0, react.useCallback)((error) => {
23
+ const messageValue = error && typeof error === "object" && "message" in error ? error.message : error;
24
+ const text = typeof messageValue === "string" ? messageValue : "";
25
+ return Object.prototype.hasOwnProperty.call(texts, text) ? t(text) : text || t("failed");
26
+ }, [texts, t]);
27
+ const report = (0, react.useCallback)((error) => {
28
+ (0, _pisell_materials.PisellToast)({ content: errorText(error) });
29
+ }, [errorText]);
30
+ const success = (0, react.useCallback)((key) => {
31
+ (0, _pisell_materials.PisellToast)({ content: t(key) });
32
+ }, [t]);
33
+ const finishConfirmation = (0, react.useCallback)((accepted) => {
34
+ const resolve = resolveConfirmation.current;
35
+ resolveConfirmation.current = null;
36
+ setConfirmation(null);
37
+ resolve === null || resolve === void 0 || resolve(accepted);
38
+ }, []);
39
+ (0, react.useEffect)(() => () => {
40
+ var _resolveConfirmation$;
41
+ (_resolveConfirmation$ = resolveConfirmation.current) === null || _resolveConfirmation$ === void 0 || _resolveConfirmation$.call(resolveConfirmation, false);
42
+ resolveConfirmation.current = null;
43
+ }, []);
44
+ const confirm = (0, react.useCallback)((title, content, discard = false) => {
45
+ if (resolveConfirmation.current) return Promise.resolve(false);
46
+ return new Promise((resolve) => {
47
+ resolveConfirmation.current = resolve;
48
+ setConfirmation({
49
+ title,
50
+ content,
51
+ discard
52
+ });
53
+ });
54
+ }, []);
55
+ const value = (0, react.useMemo)(() => ({
56
+ api,
57
+ locale,
58
+ t,
59
+ name,
60
+ errorText,
61
+ report,
62
+ success,
63
+ confirm,
64
+ scopeId: id || instanceId
65
+ }), [
66
+ api,
67
+ locale,
68
+ t,
69
+ name,
70
+ errorText,
71
+ report,
72
+ success,
73
+ confirm,
74
+ id,
75
+ instanceId
76
+ ]);
77
+ return /* @__PURE__ */ react.default.createElement(InventoryContext.Provider, { value }, children, confirmation && /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
78
+ open: true,
79
+ size: "small",
80
+ title: t(confirmation.title),
81
+ okText: t(confirmation.discard ? "discard" : confirmation.title === "unbindTitle" ? "unbind" : "remove"),
82
+ cancelText: t("cancel"),
83
+ okButtonProps: { danger: true },
84
+ maskClosable: false,
85
+ onOk: () => finishConfirmation(true),
86
+ onCancel: () => finishConfirmation(false)
87
+ }, /* @__PURE__ */ react.default.createElement("div", { className: "inventory-modal-body" }, confirmation.content)));
88
+ }
89
+ function InventoryProvider({ children, id }) {
90
+ var _context$appHelper;
91
+ const context = require_useEngineContext.default();
92
+ const locale = require_useLocale.default();
93
+ const utils = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
94
+ const store = utils === null || utils === void 0 ? void 0 : utils.store;
95
+ const subscribe = (0, react.useCallback)((listener) => {
96
+ var _store$subscribe;
97
+ return (store === null || store === void 0 || (_store$subscribe = store.subscribe) === null || _store$subscribe === void 0 ? void 0 : _store$subscribe.call(store, listener)) || (() => void 0);
98
+ }, [store]);
99
+ const getTenant = (0, react.useCallback)(() => {
100
+ var _store$getState$core$, _store$getState;
101
+ 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$ : "");
102
+ }, [store]);
103
+ const tenant = (0, react.useSyncExternalStore)(subscribe, getTenant, getTenant);
104
+ return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, {
105
+ prefixCls: "pisell-lowcode",
106
+ componentSize: "large"
107
+ }, /* @__PURE__ */ react.default.createElement(InventorySession, {
108
+ key: tenant,
109
+ client: utils === null || utils === void 0 ? void 0 : utils.request,
110
+ locale: locale || "en",
111
+ id
112
+ }, children));
113
+ }
114
+ function useInventory() {
115
+ const context = (0, react.useContext)(InventoryContext);
116
+ if (!context) throw new Error("InventoryProvider is required");
117
+ return context;
118
+ }
119
+ //#endregion
120
+ exports.InventoryProvider = InventoryProvider;
121
+ exports.useInventory = useInventory;
@@ -0,0 +1,50 @@
1
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
2
+ const require_context = require("./context.js");
3
+ let react = require("react");
4
+ react = require_runtime.__toESM(react);
5
+ let antd = require("antd");
6
+ let _pisell_materials = require("@pisell/materials");
7
+ //#region src/plus/inventory/forms.tsx
8
+ function NameField({ disabled = false }) {
9
+ const { t } = require_context.useInventory();
10
+ return /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
11
+ name: "name",
12
+ label: t("name"),
13
+ 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"))) }]
14
+ }, /* @__PURE__ */ react.default.createElement(_pisell_materials.BaseTranslation, {
15
+ renderMode: disabled ? "view" : "edit",
16
+ disabled,
17
+ placeholder: t("name")
18
+ }));
19
+ }
20
+ function StatusField() {
21
+ const { t } = require_context.useInventory();
22
+ return /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
23
+ name: "status",
24
+ label: t("status"),
25
+ rules: [{
26
+ required: true,
27
+ message: t("required")
28
+ }]
29
+ }, /* @__PURE__ */ react.default.createElement(antd.Select, { options: ["active", "inactive"].map((value) => ({
30
+ value,
31
+ label: t(value)
32
+ })) }));
33
+ }
34
+ function SortField() {
35
+ const { t } = require_context.useInventory();
36
+ return /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
37
+ name: "sort",
38
+ label: t("sort"),
39
+ extra: t("sortHint"),
40
+ rules: [{ validator: (_, value) => Number.isInteger(value) && value >= 0 ? Promise.resolve() : Promise.reject(new Error(t("nonnegative"))) }]
41
+ }, /* @__PURE__ */ react.default.createElement(antd.InputNumber, {
42
+ min: 0,
43
+ precision: 0,
44
+ style: { width: "100%" }
45
+ }));
46
+ }
47
+ //#endregion
48
+ exports.NameField = NameField;
49
+ exports.SortField = SortField;
50
+ exports.StatusField = StatusField;
@@ -0,0 +1,240 @@
1
+ require("../../_virtual/_rolldown/runtime.js");
2
+ const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
3
+ const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
4
+ const require_utils = require("./utils.js");
5
+ const require_context = require("./context.js");
6
+ let react = require("react");
7
+ //#region src/plus/inventory/hooks.ts
8
+ function useInventoryQuery(load, queryKey, enabled = true) {
9
+ const { api } = require_context.useInventory();
10
+ const loadRef = (0, react.useRef)(load);
11
+ loadRef.current = load;
12
+ const [revision, setRevision] = (0, react.useState)(0);
13
+ const key = `${queryKey}:${revision}`;
14
+ const [result, setResult] = (0, react.useState)({
15
+ key: "",
16
+ loading: false
17
+ });
18
+ (0, react.useEffect)(() => {
19
+ if (!enabled) return;
20
+ let current = true;
21
+ setResult({
22
+ key,
23
+ api,
24
+ loading: true
25
+ });
26
+ Promise.resolve().then(() => loadRef.current()).then((data) => {
27
+ if (current) setResult({
28
+ key,
29
+ api,
30
+ data,
31
+ loading: false
32
+ });
33
+ }, (error) => {
34
+ if (current) setResult({
35
+ key,
36
+ api,
37
+ error,
38
+ loading: false
39
+ });
40
+ });
41
+ return () => {
42
+ current = false;
43
+ };
44
+ }, [
45
+ key,
46
+ enabled,
47
+ api
48
+ ]);
49
+ const reload = (0, react.useCallback)(() => setRevision((value) => value + 1), []);
50
+ const valid = enabled && result.key === key && result.api === api;
51
+ return {
52
+ data: valid ? result.data : void 0,
53
+ error: valid ? result.error : void 0,
54
+ loading: enabled && (!valid || result.loading),
55
+ reload
56
+ };
57
+ }
58
+ function useInventoryList(resource, filters = {}, enabled = true) {
59
+ var _query$data$count, _query$data, _query$data$list, _query$data2;
60
+ const { api } = require_context.useInventory();
61
+ const filterKey = JSON.stringify([resource, filters]);
62
+ const [pager, setPager] = (0, react.useState)({
63
+ key: filterKey,
64
+ page: 1,
65
+ size: 20
66
+ });
67
+ const page = pager.key === filterKey ? pager.page : 1;
68
+ const { size } = pager;
69
+ const local = resource === "item-unit";
70
+ const query = useInventoryQuery(require_asyncToGenerator._asyncToGenerator(function* () {
71
+ if (local) {
72
+ const units = yield api.units(filters);
73
+ return {
74
+ list: units,
75
+ count: units.length,
76
+ page: 1,
77
+ size: units.length
78
+ };
79
+ }
80
+ return api.list(resource, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, filters), {}, {
81
+ page,
82
+ size
83
+ }));
84
+ }), JSON.stringify([
85
+ filterKey,
86
+ local ? null : page,
87
+ local ? null : size
88
+ ]), enabled);
89
+ const count = (_query$data$count = (_query$data = query.data) === null || _query$data === void 0 ? void 0 : _query$data.count) !== null && _query$data$count !== void 0 ? _query$data$count : 0;
90
+ (0, react.useEffect)(() => {
91
+ if (!query.data) return;
92
+ const lastPage = Math.max(1, Math.ceil(query.data.count / size));
93
+ if (page > lastPage) setPager({
94
+ key: filterKey,
95
+ page: lastPage,
96
+ size
97
+ });
98
+ }, [
99
+ query.data,
100
+ page,
101
+ size,
102
+ filterKey
103
+ ]);
104
+ const rows = (_query$data$list = (_query$data2 = query.data) === null || _query$data2 === void 0 ? void 0 : _query$data2.list) !== null && _query$data$list !== void 0 ? _query$data$list : [];
105
+ return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, query), {}, {
106
+ count,
107
+ page,
108
+ size,
109
+ rows: local ? rows.slice((page - 1) * size, page * size) : rows,
110
+ onPageChange: (nextPage, nextSize) => setPager({
111
+ key: filterKey,
112
+ page: nextSize === size ? nextPage : 1,
113
+ size: nextSize
114
+ })
115
+ });
116
+ }
117
+ function useInventoryOptions(resource, filters = {}, enabled = true, revision = 0) {
118
+ const { api } = require_context.useInventory();
119
+ const key = JSON.stringify([
120
+ resource,
121
+ filters,
122
+ revision
123
+ ]);
124
+ const generation = (0, react.useRef)(0);
125
+ const busy = (0, react.useRef)(false);
126
+ const [result, setResult] = (0, react.useState)({
127
+ key: "",
128
+ rows: [],
129
+ count: 0,
130
+ page: 0,
131
+ loading: false
132
+ });
133
+ const valid = enabled && result.key === key;
134
+ const fetchPage = (0, react.useCallback)(function() {
135
+ var _ref = require_asyncToGenerator._asyncToGenerator(function* (page) {
136
+ if (!enabled || page > 1 && busy.current) return;
137
+ const requestId = ++generation.current;
138
+ busy.current = true;
139
+ setResult((previous) => ({
140
+ key,
141
+ rows: page === 1 ? [] : previous.rows,
142
+ count: page === 1 ? 0 : previous.count,
143
+ page: page === 1 ? 0 : previous.page,
144
+ loading: true
145
+ }));
146
+ try {
147
+ const data = yield api.list(resource, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, JSON.parse(key)[1]), {}, {
148
+ page,
149
+ size: 20
150
+ }));
151
+ if (generation.current !== requestId) return;
152
+ setResult((previous) => ({
153
+ key,
154
+ rows: page === 1 ? data.list : require_utils.mergeInventoryRecords(previous.rows, data.list),
155
+ count: data.count,
156
+ page,
157
+ loading: false
158
+ }));
159
+ } catch (error) {
160
+ if (generation.current === requestId) setResult((previous) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, previous), {}, {
161
+ loading: false,
162
+ error
163
+ }));
164
+ } finally {
165
+ if (generation.current === requestId) busy.current = false;
166
+ }
167
+ });
168
+ return function(_x) {
169
+ return _ref.apply(this, arguments);
170
+ };
171
+ }(), [
172
+ api,
173
+ resource,
174
+ key,
175
+ enabled
176
+ ]);
177
+ (0, react.useEffect)(() => {
178
+ if (enabled) fetchPage(1);
179
+ return () => {
180
+ ++generation.current;
181
+ busy.current = false;
182
+ };
183
+ }, [fetchPage, enabled]);
184
+ return {
185
+ rows: valid ? result.rows : [],
186
+ loading: enabled && (!valid || result.loading),
187
+ error: valid ? result.error : void 0,
188
+ hasMore: valid && result.page * 20 < result.count,
189
+ loadMore: () => fetchPage(result.page + 1),
190
+ reload: () => fetchPage(1)
191
+ };
192
+ }
193
+ function useInventoryMutation() {
194
+ const { report } = require_context.useInventory();
195
+ const locked = (0, react.useRef)(false);
196
+ const mounted = (0, react.useRef)(true);
197
+ const [busy, setBusy] = (0, react.useState)(false);
198
+ (0, react.useEffect)(() => {
199
+ mounted.current = true;
200
+ return () => {
201
+ mounted.current = false;
202
+ };
203
+ }, []);
204
+ return {
205
+ busy,
206
+ run: function() {
207
+ var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (operation) {
208
+ if (locked.current || !mounted.current) return;
209
+ locked.current = true;
210
+ setBusy(true);
211
+ try {
212
+ yield operation();
213
+ } catch (error) {
214
+ if (mounted.current) report(error);
215
+ } finally {
216
+ locked.current = false;
217
+ if (mounted.current) setBusy(false);
218
+ }
219
+ });
220
+ return function run(_x2) {
221
+ return _ref2.apply(this, arguments);
222
+ };
223
+ }()
224
+ };
225
+ }
226
+ function useUnsavedChanges() {
227
+ const { confirm, t } = require_context.useInventory();
228
+ const [dirty, setDirty] = (0, react.useState)(false);
229
+ return {
230
+ dirty,
231
+ setDirty,
232
+ canLeave: () => dirty ? confirm("unsavedTitle", t("unsavedHint"), true) : Promise.resolve(true)
233
+ };
234
+ }
235
+ //#endregion
236
+ exports.useInventoryList = useInventoryList;
237
+ exports.useInventoryMutation = useInventoryMutation;
238
+ exports.useInventoryOptions = useInventoryOptions;
239
+ exports.useInventoryQuery = useInventoryQuery;
240
+ exports.useUnsavedChanges = useUnsavedChanges;