@etsoo/smarterp-core 1.0.69 → 1.0.71

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.
@@ -151,7 +151,7 @@ class CoreApp {
151
151
  */
152
152
  getIdentityFlags(identity) {
153
153
  if (identity == null)
154
- return this.app.getEnumList(appscript_1.IdentityTypeFlags, "id");
154
+ return this.app.getEnumList(appscript_1.IdentityTypeFlags, "id", (id) => id > 0 ? id : undefined);
155
155
  return this.app.getEnumList(appscript_1.IdentityTypeFlags, "id", (id, _key) => {
156
156
  if ((id & identity) > 0)
157
157
  return id;
@@ -0,0 +1,20 @@
1
+ import { ButtonPopupCheckboxProps } from "@etsoo/materialui";
2
+ import { ListType } from "@etsoo/shared";
3
+ import { IdentityTypeFlags } from "@etsoo/appscript";
4
+ export type ButtonIdentityTypesProps = Omit<ButtonPopupCheckboxProps<ListType>, "labelField" | "loadData" | "ids" | "value" | "onValueChange"> & {
5
+ /**
6
+ * Base identity type
7
+ */
8
+ baseIdentity?: IdentityTypeFlags;
9
+ /**
10
+ * Value
11
+ * 值
12
+ */
13
+ value?: IdentityTypeFlags;
14
+ /**
15
+ * Value change handler
16
+ * @param value New value
17
+ */
18
+ onValueChange: (value: IdentityTypeFlags) => void;
19
+ };
20
+ export declare function ButtonIdentityTypes(props: ButtonIdentityTypesProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ButtonIdentityTypes = ButtonIdentityTypes;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const materialui_1 = require("@etsoo/materialui");
9
+ const appscript_1 = require("@etsoo/appscript");
10
+ const react_1 = __importDefault(require("react"));
11
+ const ICoreServiceApp_1 = require("../../ICoreServiceApp");
12
+ function ButtonIdentityTypes(props) {
13
+ // App
14
+ const app = (0, ICoreServiceApp_1.useRequiredAppContext)();
15
+ // Labels
16
+ const labels = app.getLabels("clickToChoose", "identityType");
17
+ // Destruct
18
+ const { inputName = "identityType", label = labels.identityType, labelEnd = labels.clickToChoose, baseIdentity, onValueChange, value, ...rest } = props;
19
+ // Identities
20
+ const identities = react_1.default.useMemo(() => app.core.getIdentityFlags(baseIdentity), [baseIdentity]);
21
+ const ids = [];
22
+ if (value != null) {
23
+ // Convert to ids
24
+ for (const identity of identities) {
25
+ if ((value & identity.id) === identity.id) {
26
+ ids.push(identity.id);
27
+ }
28
+ }
29
+ }
30
+ return ((0, jsx_runtime_1.jsx)(materialui_1.ButtonPopupCheckbox, { inputName: inputName, label: label, labelFormatter: (data) => data.label, labelEnd: labelEnd, labelField: "label", loadData: async () => identities, ids: ids, onValueChange: (ids) => {
31
+ let newValue = appscript_1.IdentityTypeFlags.None;
32
+ for (const id of ids) {
33
+ newValue |= id;
34
+ }
35
+ onValueChange(newValue);
36
+ }, ...rest }));
37
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./DefaultUI";
2
2
  export * from "./app/AppSwitchPopover";
3
+ export * from "./app/ButtonIdentityTypes";
3
4
  export * from "./app/IdentityFlagsList";
4
5
  export * from "./app/IdentityTypeList";
5
6
  export * from "./app/SearchDays";
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./DefaultUI"), exports);
19
19
  // app
20
20
  __exportStar(require("./app/AppSwitchPopover"), exports);
21
+ __exportStar(require("./app/ButtonIdentityTypes"), exports);
21
22
  __exportStar(require("./app/IdentityFlagsList"), exports);
22
23
  __exportStar(require("./app/IdentityTypeList"), exports);
23
24
  __exportStar(require("./app/SearchDays"), exports);
@@ -148,7 +148,7 @@ export class CoreApp {
148
148
  */
149
149
  getIdentityFlags(identity) {
150
150
  if (identity == null)
151
- return this.app.getEnumList(IdentityTypeFlags, "id");
151
+ return this.app.getEnumList(IdentityTypeFlags, "id", (id) => id > 0 ? id : undefined);
152
152
  return this.app.getEnumList(IdentityTypeFlags, "id", (id, _key) => {
153
153
  if ((id & identity) > 0)
154
154
  return id;
@@ -0,0 +1,20 @@
1
+ import { ButtonPopupCheckboxProps } from "@etsoo/materialui";
2
+ import { ListType } from "@etsoo/shared";
3
+ import { IdentityTypeFlags } from "@etsoo/appscript";
4
+ export type ButtonIdentityTypesProps = Omit<ButtonPopupCheckboxProps<ListType>, "labelField" | "loadData" | "ids" | "value" | "onValueChange"> & {
5
+ /**
6
+ * Base identity type
7
+ */
8
+ baseIdentity?: IdentityTypeFlags;
9
+ /**
10
+ * Value
11
+ * 值
12
+ */
13
+ value?: IdentityTypeFlags;
14
+ /**
15
+ * Value change handler
16
+ * @param value New value
17
+ */
18
+ onValueChange: (value: IdentityTypeFlags) => void;
19
+ };
20
+ export declare function ButtonIdentityTypes(props: ButtonIdentityTypesProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ButtonPopupCheckbox } from "@etsoo/materialui";
3
+ import { IdentityTypeFlags } from "@etsoo/appscript";
4
+ import React from "react";
5
+ import { useRequiredAppContext } from "../../ICoreServiceApp";
6
+ export function ButtonIdentityTypes(props) {
7
+ // App
8
+ const app = useRequiredAppContext();
9
+ // Labels
10
+ const labels = app.getLabels("clickToChoose", "identityType");
11
+ // Destruct
12
+ const { inputName = "identityType", label = labels.identityType, labelEnd = labels.clickToChoose, baseIdentity, onValueChange, value, ...rest } = props;
13
+ // Identities
14
+ const identities = React.useMemo(() => app.core.getIdentityFlags(baseIdentity), [baseIdentity]);
15
+ const ids = [];
16
+ if (value != null) {
17
+ // Convert to ids
18
+ for (const identity of identities) {
19
+ if ((value & identity.id) === identity.id) {
20
+ ids.push(identity.id);
21
+ }
22
+ }
23
+ }
24
+ return (_jsx(ButtonPopupCheckbox, { inputName: inputName, label: label, labelFormatter: (data) => data.label, labelEnd: labelEnd, labelField: "label", loadData: async () => identities, ids: ids, onValueChange: (ids) => {
25
+ let newValue = IdentityTypeFlags.None;
26
+ for (const id of ids) {
27
+ newValue |= id;
28
+ }
29
+ onValueChange(newValue);
30
+ }, ...rest }));
31
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./DefaultUI";
2
2
  export * from "./app/AppSwitchPopover";
3
+ export * from "./app/ButtonIdentityTypes";
3
4
  export * from "./app/IdentityFlagsList";
4
5
  export * from "./app/IdentityTypeList";
5
6
  export * from "./app/SearchDays";
@@ -2,6 +2,7 @@
2
2
  export * from "./DefaultUI";
3
3
  // app
4
4
  export * from "./app/AppSwitchPopover";
5
+ export * from "./app/ButtonIdentityTypes";
5
6
  export * from "./app/IdentityFlagsList";
6
7
  export * from "./app/IdentityTypeList";
7
8
  export * from "./app/SearchDays";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/smarterp-core",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "description": "TypeScript APIs for SmartERP Core",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -45,7 +45,7 @@
45
45
  "@babel/plugin-transform-runtime": "^7.27.1",
46
46
  "@babel/preset-env": "^7.27.2",
47
47
  "@babel/runtime-corejs3": "^7.27.1",
48
- "@types/react": "^18.3.22",
48
+ "@types/react": "^18.3.23",
49
49
  "@types/react-dom": "^18.3.7",
50
50
  "@vitejs/plugin-react": "^4.5.0",
51
51
  "jsdom": "^26.1.0",
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@etsoo/appscript": "^1.6.36",
57
- "@etsoo/materialui": "^1.5.51",
57
+ "@etsoo/materialui": "^1.5.52",
58
58
  "@etsoo/react": "^1.8.45",
59
59
  "@etsoo/shared": "^1.2.74",
60
60
  "@etsoo/toolpad": "^1.0.39",
package/src/CoreApp.ts CHANGED
@@ -270,7 +270,11 @@ export class CoreApp implements ICoreApp {
270
270
  * @returns List
271
271
  */
272
272
  getIdentityFlags(identity?: number) {
273
- if (identity == null) return this.app.getEnumList(IdentityTypeFlags, "id");
273
+ if (identity == null)
274
+ return this.app.getEnumList(IdentityTypeFlags, "id", (id) =>
275
+ id > 0 ? id : undefined
276
+ );
277
+
274
278
  return this.app.getEnumList(IdentityTypeFlags, "id", (id, _key) => {
275
279
  if ((id & identity) > 0) return id;
276
280
  });
@@ -0,0 +1,85 @@
1
+ import {
2
+ ButtonPopupCheckbox,
3
+ ButtonPopupCheckboxProps
4
+ } from "@etsoo/materialui";
5
+ import { ListType } from "@etsoo/shared";
6
+ import { IdentityTypeFlags } from "@etsoo/appscript";
7
+ import React from "react";
8
+ import { useRequiredAppContext } from "../../ICoreServiceApp";
9
+
10
+ export type ButtonIdentityTypesProps = Omit<
11
+ ButtonPopupCheckboxProps<ListType>,
12
+ "labelField" | "loadData" | "ids" | "value" | "onValueChange"
13
+ > & {
14
+ /**
15
+ * Base identity type
16
+ */
17
+ baseIdentity?: IdentityTypeFlags;
18
+
19
+ /**
20
+ * Value
21
+ * 值
22
+ */
23
+ value?: IdentityTypeFlags;
24
+
25
+ /**
26
+ * Value change handler
27
+ * @param value New value
28
+ */
29
+ onValueChange: (value: IdentityTypeFlags) => void;
30
+ };
31
+
32
+ export function ButtonIdentityTypes(props: ButtonIdentityTypesProps) {
33
+ // App
34
+ const app = useRequiredAppContext();
35
+
36
+ // Labels
37
+ const labels = app.getLabels("clickToChoose", "identityType");
38
+
39
+ // Destruct
40
+ const {
41
+ inputName = "identityType",
42
+ label = labels.identityType,
43
+ labelEnd = labels.clickToChoose,
44
+ baseIdentity,
45
+ onValueChange,
46
+ value,
47
+ ...rest
48
+ } = props;
49
+
50
+ // Identities
51
+ const identities = React.useMemo(
52
+ () => app.core.getIdentityFlags(baseIdentity),
53
+ [baseIdentity]
54
+ );
55
+
56
+ const ids: number[] = [];
57
+ if (value != null) {
58
+ // Convert to ids
59
+ for (const identity of identities) {
60
+ if ((value & identity.id) === identity.id) {
61
+ ids.push(identity.id);
62
+ }
63
+ }
64
+ }
65
+
66
+ return (
67
+ <ButtonPopupCheckbox<ListType>
68
+ inputName={inputName}
69
+ label={label}
70
+ labelFormatter={(data) => data.label}
71
+ labelEnd={labelEnd}
72
+ labelField="label"
73
+ loadData={async () => identities}
74
+ ids={ids}
75
+ onValueChange={(ids) => {
76
+ let newValue = IdentityTypeFlags.None;
77
+ for (const id of ids) {
78
+ newValue |= id;
79
+ }
80
+ onValueChange(newValue);
81
+ }}
82
+ {...rest}
83
+ />
84
+ );
85
+ }
@@ -3,6 +3,7 @@ export * from "./DefaultUI";
3
3
 
4
4
  // app
5
5
  export * from "./app/AppSwitchPopover";
6
+ export * from "./app/ButtonIdentityTypes";
6
7
  export * from "./app/IdentityFlagsList";
7
8
  export * from "./app/IdentityTypeList";
8
9
  export * from "./app/SearchDays";