@olenbetong/synergi-react 5.0.0 → 5.2.0

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 (168) hide show
  1. package/dist/styles/styles.css +1 -1
  2. package/dist/styles/styles.css.map +1 -1
  3. package/es/components/Checkbox/index.css +1 -1
  4. package/es/components/Checkbox/index.js +1 -9
  5. package/es/components/CodeEditor/CodeEditor.css +6 -6
  6. package/es/components/ColorCard/index.css +17 -28
  7. package/es/components/DateNavigator/index.css +5 -7
  8. package/es/components/FilePond.js +3 -12
  9. package/es/components/ImageEditor/ImageEditor.css +10 -10
  10. package/es/components/ImageEditor/ImageEditor.js +4 -4
  11. package/es/components/ImageEditor/ResponsiveButton.js +2 -2
  12. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +1 -1
  13. package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +1 -1
  14. package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
  15. package/es/components/ImageEditor/useImageHistory.js +13 -1
  16. package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +3 -3
  17. package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
  18. package/es/components/PageBanner/index.css +1 -1
  19. package/es/components/PdfViewer/PdfViewer.js +1 -1
  20. package/es/components/Portal/index.js +20 -20
  21. package/es/components/Spinner/index.css +1 -1
  22. package/es/components/SplitContainer/index.css +1 -1
  23. package/es/components/SplitContainer/index.js +3 -1
  24. package/es/components/Toolbar/Toolbar.css +137 -137
  25. package/es/components/Toolbar/index.js +6 -1
  26. package/es/components/ValueToggleGroup/index.css +2 -2
  27. package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +7 -7
  28. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
  29. package/es/elements/ElementLookupDialog/HIDScanner/useHIDScanner.js +3 -1
  30. package/es/elements-ds/DescriptionInput.d.ts +16 -0
  31. package/es/elements-ds/DescriptionInput.js +41 -0
  32. package/es/elements-ds/DuplicateElementDamage.d.ts +40 -0
  33. package/es/elements-ds/DuplicateElementDamage.js +57 -0
  34. package/es/elements-ds/ElementLookup.d.ts +23 -0
  35. package/es/elements-ds/ElementLookup.js +35 -0
  36. package/es/elements-ds/ElementLookupDialog.d.ts +7 -0
  37. package/es/elements-ds/ElementLookupDialog.js +84 -0
  38. package/es/elements-ds/FormFields.d.ts +43 -0
  39. package/es/elements-ds/FormFields.js +67 -0
  40. package/es/elements-ds/HIDScanner.d.ts +7 -0
  41. package/es/elements-ds/HIDScanner.js +36 -0
  42. package/es/elements-ds/ManualForm.d.ts +7 -0
  43. package/es/elements-ds/ManualForm.js +70 -0
  44. package/es/elements-ds/ProjectSelect.d.ts +28 -0
  45. package/es/elements-ds/ProjectSelect.js +45 -0
  46. package/es/elements-ds/elements-ds.css +157 -0
  47. package/es/elements-ds/index.d.ts +12 -0
  48. package/es/elements-ds/index.js +14 -0
  49. package/es/index.css +1 -1
  50. package/es/useTranslation/index.js +5 -3
  51. package/package.json +16 -4
  52. package/src/chrome/AppShell/AppShell.test.tsx +48 -0
  53. package/src/chrome/AppShell/index.tsx +29 -29
  54. package/src/chrome/openReport.test.ts +50 -0
  55. package/src/chrome/openReport.ts +34 -34
  56. package/src/colorScheme.test.ts +188 -0
  57. package/src/colorScheme.ts +125 -125
  58. package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
  59. package/src/components/Checkbox/index.scss +2 -2
  60. package/src/components/Checkbox/index.tsx +1 -10
  61. package/src/components/CodeEditor/CodeEditor.css +6 -6
  62. package/src/components/CodeEditor/CodeEditor.tsx +173 -173
  63. package/src/components/CodeEditor/index.ts +1 -1
  64. package/src/components/ColorCard/ColorCard.test.tsx +34 -0
  65. package/src/components/ColorCard/index.css +17 -28
  66. package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
  67. package/src/components/DateNavigator/index.css +5 -7
  68. package/src/components/DateNavigator/index.tsx +186 -186
  69. package/src/components/FilePond.browser.test.tsx +389 -0
  70. package/src/components/FilePond.tsx +303 -312
  71. package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
  72. package/src/components/ImageEditor/ImageEditor.css +10 -10
  73. package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
  74. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  75. package/src/components/ImageEditor/ResponsiveButton.tsx +2 -2
  76. package/src/components/ImageEditor/index.ts +9 -9
  77. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  78. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +42 -48
  79. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.test.ts +225 -0
  80. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  81. package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
  82. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  83. package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.test.ts +89 -0
  84. package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +16 -13
  85. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  86. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  87. package/src/components/ImageEditor/plugins/zoomPlugin/useZoomPan.test.ts +154 -0
  88. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  89. package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
  90. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  91. package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
  92. package/src/components/ImageEditor/useImageHistory.ts +206 -197
  93. package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
  94. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  95. package/src/components/LinkedCardList/index.scss +95 -95
  96. package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
  97. package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +4 -3
  98. package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
  99. package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
  100. package/src/components/PageBanner/index.scss +10 -10
  101. package/src/components/PageBanner/index.tsx +80 -80
  102. package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
  103. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  104. package/src/components/Portal/Portal.test.tsx +106 -0
  105. package/src/components/Portal/index.tsx +22 -25
  106. package/src/components/Sidebar/Sidebar.browser.test.tsx +57 -0
  107. package/src/components/Sidebar/Sidebar.test.tsx +123 -0
  108. package/src/components/Spinner/index.css +1 -1
  109. package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
  110. package/src/components/SplitContainer/index.scss +5 -1
  111. package/src/components/SplitContainer/index.tsx +335 -333
  112. package/src/components/Toolbar/Toolbar.css +137 -137
  113. package/src/components/Toolbar/Toolbar.test.tsx +216 -0
  114. package/src/components/Toolbar/ToolbarBreadcrumbs.browser.test.tsx +137 -0
  115. package/src/components/Toolbar/index.tsx +270 -265
  116. package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
  117. package/src/components/ValueToggleGroup/index.css +2 -2
  118. package/src/designsystemet-web-types.d.ts +24 -24
  119. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  120. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  121. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  122. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  123. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  124. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  125. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  126. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  127. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  128. package/src/elements/ElementLookup.tsx +123 -123
  129. package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.browser.test.tsx +175 -0
  130. package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +7 -7
  131. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +8 -0
  132. package/src/elements/ElementLookupDialog/BarcodeScanner/engines.browser.test.ts +225 -0
  133. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  134. package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
  135. package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
  136. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  137. package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
  138. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  139. package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
  140. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  141. package/src/elements/ProjectSelect.tsx +130 -130
  142. package/src/elements/index.ts +15 -15
  143. package/src/elements-ds/DamageForm.browser.test.tsx +530 -0
  144. package/src/elements-ds/DescriptionInput.tsx +114 -0
  145. package/src/elements-ds/DuplicateElementDamage.tsx +185 -0
  146. package/src/elements-ds/ElementLookup.tsx +114 -0
  147. package/src/elements-ds/ElementLookupDialog.browser.test.tsx +207 -0
  148. package/src/elements-ds/ElementLookupDialog.tsx +194 -0
  149. package/src/elements-ds/FormFields.tsx +176 -0
  150. package/src/elements-ds/HIDScanner.tsx +53 -0
  151. package/src/elements-ds/ManualForm.tsx +129 -0
  152. package/src/elements-ds/ProjectSelect.tsx +120 -0
  153. package/src/elements-ds/elements-ds.css +157 -0
  154. package/src/elements-ds/index.ts +16 -0
  155. package/src/filter/index.ts +34 -34
  156. package/src/i18n.test.ts +31 -0
  157. package/src/i18n.ts +13 -13
  158. package/src/mui/MuiThemeProvider.tsx +135 -135
  159. package/src/test/fakeCamera.ts +98 -0
  160. package/src/test/fakeDataApi.ts +90 -0
  161. package/src/test/setup.browser.ts +21 -0
  162. package/src/test/setup.ts +23 -23
  163. package/src/useTranslation/index.ts +5 -3
  164. package/src/useTranslation/useTranslation.test.ts +128 -0
  165. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts +0 -1
  166. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +0 -103
  167. package/es/test/setup.d.ts +0 -6
  168. package/es/test/setup.js +0 -6
@@ -1,209 +1,209 @@
1
- import { getLocalizedString } from "../../../i18n.js";
2
-
3
- export type GiaiProps = {
4
- assetReference: string | number | bigint;
5
- companyPrefix: string | number | bigint;
6
- filter?: string | number | undefined;
7
- };
8
-
9
- /**
10
- * GIAI-96 encoder and decoder as defined by the GS1 EPC Tag data standard
11
- */
12
- export default class Giai {
13
- /// Bit lengths for company prefix given partition equal to index.
14
- ///
15
- /// Partition Company prefix Individual asset reference
16
- /// Bits Digits Bits Digits
17
- /// 0 40 12 42 13
18
- /// 1 37 11 45 14
19
- /// 2 34 10 48 15
20
- /// 3 30 9 52 16
21
- /// 4 27 8 55 17
22
- /// 5 24 7 58 18
23
- /// 6 20 6 62 19
24
- static PARTITION_TABLE = [40, 37, 34, 30, 27, 24, 20];
25
- // EPC header for GIAI-96 coding scheme
26
- static EPC_HEADER = "00110100";
27
- // Prefix for GS1 key used in barcodes;
28
- static BARCODE_PREFIX = "8004";
29
- // Group separator used to separate company prefix and asset reference (FNC1 in GS1-128 barcodes)
30
- static GROUP_SEPARATOR = String.fromCodePoint(0x001d);
31
-
32
- static URN_PREFIX = "urn:epc:id:giai:";
33
-
34
- static fromHex = (hexIdentifier: string) => {
35
- const bitIdentifier = hexToBitString(hexIdentifier);
36
-
37
- if (bitIdentifier.substring(0, 8) !== Giai.EPC_HEADER) {
38
- throw new Error("EPC value is not a valid GIAI value.");
39
- }
40
-
41
- const partition = Number.parseInt(bitIdentifier.substr(11, 3), 2);
42
- const companyPrefixLength = Giai.PARTITION_TABLE[partition];
43
- const filter = Number.parseInt(bitIdentifier.substring(8, 11), 2);
44
- const companyPrefix = BigInt(`0b${bitIdentifier.substring(14, 14 + companyPrefixLength)}`);
45
- const assetReference = BigInt(`0b${bitIdentifier.substring(14 + companyPrefixLength)}`);
46
-
47
- return new Giai({ assetReference, companyPrefix, filter });
48
- };
49
-
50
- /**
51
- *
52
- * @param {string | null | undefined} barcodeString
53
- * @returns
54
- */
55
- static fromBarcode = (barcodeString: string) => {
56
- const prefixLength = Giai.BARCODE_PREFIX.length;
57
-
58
- if (barcodeString[0] === Giai.GROUP_SEPARATOR) {
59
- barcodeString = barcodeString.substr(1);
60
- }
61
-
62
- if (barcodeString.substr(0, prefixLength) !== Giai.BARCODE_PREFIX) {
63
- throw new Error(`Barcode is not a valid GIAI barcode. (${Giai.BARCODE_PREFIX} prefix expected)`);
64
- }
65
-
66
- let giaiString = barcodeString.substring(prefixLength);
67
- const gsIndex = giaiString.indexOf(Giai.GROUP_SEPARATOR);
68
-
69
- if (gsIndex >= 0) {
70
- return new Giai({
71
- assetReference: giaiString.substring(gsIndex + 1),
72
- companyPrefix: giaiString.substring(0, gsIndex),
73
- });
74
- }
75
-
76
- // If no separator is found, assume a company prefix length of 7
77
- return new Giai({
78
- assetReference: giaiString.substring(7),
79
- companyPrefix: giaiString.substring(0, 7),
80
- });
81
- };
82
-
83
- /**
84
- * Creates a GIAI instance from a purse identity URI (urn:epc:giai:[companyprefix].[assetreference])
85
- * @param {string} uri EPC GIAI pure identity URI
86
- */
87
- static fromEpcPureIdentityUri(uri: string) {
88
- if (!uri.startsWith(Giai.URN_PREFIX)) {
89
- throw Error("URI is not a valid GIAI URI");
90
- }
91
-
92
- let [companyPrefix, assetReference] = uri.substring(Giai.URN_PREFIX.length).split(".");
93
-
94
- return new Giai({
95
- assetReference,
96
- companyPrefix,
97
- });
98
- }
99
-
100
- /**
101
- * Attempt to create a GIAI instance from a string with unknown format. Could be either a URN, barcode value
102
- * or EPC value.
103
- * @param {string} value
104
- * @returns
105
- */
106
- static fromString(value: string, ignoreError?: false): Giai;
107
- static fromString(value: string, ignoreError: true): Giai | undefined;
108
- static fromString(value: string, ignoreError = false) {
109
- try {
110
- if (value.startsWith("0x")) {
111
- value = value.replace("0x", "");
112
- return Giai.fromHex(value.substring(0, 24));
113
- // return Giai.fromHex(value.substring(6, value.length - 4));
114
- } else if (value.startsWith(Giai.URN_PREFIX)) {
115
- return Giai.fromEpcPureIdentityUri(value);
116
- } else if (value.startsWith(Giai.BARCODE_PREFIX)) {
117
- return Giai.fromBarcode(value);
118
- } else if (value.length === 24) {
119
- return Giai.fromHex(value);
120
- }
121
- } catch (ex) {
122
- if (!ignoreError) {
123
- throw ex;
124
- }
125
- }
126
-
127
- if (!ignoreError) {
128
- throw Error(
129
- getLocalizedString(
130
- "Can't create GIAI from string. Failed to match value '{value}' with known input formats.",
131
- ).replace("{value}", value),
132
- );
133
- }
134
-
135
- return undefined;
136
- }
137
-
138
- /**
139
- * @type {string | number | bigint}
140
- */
141
- #assetReference;
142
- /**
143
- * @type {string | number | bigint}
144
- */
145
- #companyPrefix;
146
-
147
- /**
148
- *
149
- * @param {GiaiProps} options
150
- */
151
- constructor({ assetReference, companyPrefix }: GiaiProps) {
152
- this.#assetReference = assetReference;
153
- this.#companyPrefix = companyPrefix;
154
- }
155
-
156
- get assetReference() {
157
- return this.#assetReference;
158
- }
159
-
160
- get companyPrefix() {
161
- return this.#companyPrefix;
162
- }
163
-
164
- // Returns the EPC pure identity uri for this identifier - as used by EPCIS.
165
- toEpcPureIdentityUri() {
166
- return `${Giai.URN_PREFIX}${this.companyPrefix}.${this.assetReference}`;
167
- }
168
-
169
- toGiaiBarcode() {
170
- return Giai.BARCODE_PREFIX + this.companyPrefix + Giai.GROUP_SEPARATOR + this.assetReference;
171
- }
172
-
173
- toEpcHex() {
174
- let bitIdentifier = Giai.EPC_HEADER;
175
- bitIdentifier += "000"; // Filter
176
- bitIdentifier += (5).toString(2).padStart(3, "0"); // Partition
177
- let companyPrefix = ["bigint", "number"].includes(typeof this.#companyPrefix)
178
- ? this.#companyPrefix
179
- : BigInt(this.#companyPrefix);
180
- let assetReference = ["bigint", "number"].includes(typeof this.#assetReference)
181
- ? this.#assetReference
182
- : BigInt(this.#assetReference);
183
- bitIdentifier += companyPrefix.toString(2).padStart(24, "0");
184
- bitIdentifier += assetReference.toString(2).padStart(58, "0");
185
-
186
- return BigInt(`0b${bitIdentifier}`).toString(16).toUpperCase();
187
- }
188
- }
189
-
190
- export function hexToBitString(hexString: string) {
191
- let bitString = "";
192
-
193
- for (let i = 0; i < hexString.length; i += 2) {
194
- const byteString = hexString.substr(i, 2);
195
- const byteBits = Number.parseInt(byteString, 16).toString(2);
196
-
197
- bitString += byteBits.padStart(8, "0");
198
- }
199
-
200
- return bitString;
201
- }
202
-
203
- declare global {
204
- interface Window {
205
- Giai: typeof Giai | undefined;
206
- }
207
- }
208
-
209
- window.Giai = Giai;
1
+ import { getLocalizedString } from "../../../i18n.js";
2
+
3
+ export type GiaiProps = {
4
+ assetReference: string | number | bigint;
5
+ companyPrefix: string | number | bigint;
6
+ filter?: string | number | undefined;
7
+ };
8
+
9
+ /**
10
+ * GIAI-96 encoder and decoder as defined by the GS1 EPC Tag data standard
11
+ */
12
+ export default class Giai {
13
+ /// Bit lengths for company prefix given partition equal to index.
14
+ ///
15
+ /// Partition Company prefix Individual asset reference
16
+ /// Bits Digits Bits Digits
17
+ /// 0 40 12 42 13
18
+ /// 1 37 11 45 14
19
+ /// 2 34 10 48 15
20
+ /// 3 30 9 52 16
21
+ /// 4 27 8 55 17
22
+ /// 5 24 7 58 18
23
+ /// 6 20 6 62 19
24
+ static PARTITION_TABLE = [40, 37, 34, 30, 27, 24, 20];
25
+ // EPC header for GIAI-96 coding scheme
26
+ static EPC_HEADER = "00110100";
27
+ // Prefix for GS1 key used in barcodes;
28
+ static BARCODE_PREFIX = "8004";
29
+ // Group separator used to separate company prefix and asset reference (FNC1 in GS1-128 barcodes)
30
+ static GROUP_SEPARATOR = String.fromCodePoint(0x001d);
31
+
32
+ static URN_PREFIX = "urn:epc:id:giai:";
33
+
34
+ static fromHex = (hexIdentifier: string) => {
35
+ const bitIdentifier = hexToBitString(hexIdentifier);
36
+
37
+ if (bitIdentifier.substring(0, 8) !== Giai.EPC_HEADER) {
38
+ throw new Error("EPC value is not a valid GIAI value.");
39
+ }
40
+
41
+ const partition = Number.parseInt(bitIdentifier.substr(11, 3), 2);
42
+ const companyPrefixLength = Giai.PARTITION_TABLE[partition];
43
+ const filter = Number.parseInt(bitIdentifier.substring(8, 11), 2);
44
+ const companyPrefix = BigInt(`0b${bitIdentifier.substring(14, 14 + companyPrefixLength)}`);
45
+ const assetReference = BigInt(`0b${bitIdentifier.substring(14 + companyPrefixLength)}`);
46
+
47
+ return new Giai({ assetReference, companyPrefix, filter });
48
+ };
49
+
50
+ /**
51
+ *
52
+ * @param {string | null | undefined} barcodeString
53
+ * @returns
54
+ */
55
+ static fromBarcode = (barcodeString: string) => {
56
+ const prefixLength = Giai.BARCODE_PREFIX.length;
57
+
58
+ if (barcodeString[0] === Giai.GROUP_SEPARATOR) {
59
+ barcodeString = barcodeString.substr(1);
60
+ }
61
+
62
+ if (barcodeString.substr(0, prefixLength) !== Giai.BARCODE_PREFIX) {
63
+ throw new Error(`Barcode is not a valid GIAI barcode. (${Giai.BARCODE_PREFIX} prefix expected)`);
64
+ }
65
+
66
+ let giaiString = barcodeString.substring(prefixLength);
67
+ const gsIndex = giaiString.indexOf(Giai.GROUP_SEPARATOR);
68
+
69
+ if (gsIndex >= 0) {
70
+ return new Giai({
71
+ assetReference: giaiString.substring(gsIndex + 1),
72
+ companyPrefix: giaiString.substring(0, gsIndex),
73
+ });
74
+ }
75
+
76
+ // If no separator is found, assume a company prefix length of 7
77
+ return new Giai({
78
+ assetReference: giaiString.substring(7),
79
+ companyPrefix: giaiString.substring(0, 7),
80
+ });
81
+ };
82
+
83
+ /**
84
+ * Creates a GIAI instance from a purse identity URI (urn:epc:giai:[companyprefix].[assetreference])
85
+ * @param {string} uri EPC GIAI pure identity URI
86
+ */
87
+ static fromEpcPureIdentityUri(uri: string) {
88
+ if (!uri.startsWith(Giai.URN_PREFIX)) {
89
+ throw Error("URI is not a valid GIAI URI");
90
+ }
91
+
92
+ let [companyPrefix, assetReference] = uri.substring(Giai.URN_PREFIX.length).split(".");
93
+
94
+ return new Giai({
95
+ assetReference,
96
+ companyPrefix,
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Attempt to create a GIAI instance from a string with unknown format. Could be either a URN, barcode value
102
+ * or EPC value.
103
+ * @param {string} value
104
+ * @returns
105
+ */
106
+ static fromString(value: string, ignoreError?: false): Giai;
107
+ static fromString(value: string, ignoreError: true): Giai | undefined;
108
+ static fromString(value: string, ignoreError = false) {
109
+ try {
110
+ if (value.startsWith("0x")) {
111
+ value = value.replace("0x", "");
112
+ return Giai.fromHex(value.substring(0, 24));
113
+ // return Giai.fromHex(value.substring(6, value.length - 4));
114
+ } else if (value.startsWith(Giai.URN_PREFIX)) {
115
+ return Giai.fromEpcPureIdentityUri(value);
116
+ } else if (value.startsWith(Giai.BARCODE_PREFIX)) {
117
+ return Giai.fromBarcode(value);
118
+ } else if (value.length === 24) {
119
+ return Giai.fromHex(value);
120
+ }
121
+ } catch (ex) {
122
+ if (!ignoreError) {
123
+ throw ex;
124
+ }
125
+ }
126
+
127
+ if (!ignoreError) {
128
+ throw Error(
129
+ getLocalizedString(
130
+ "Can't create GIAI from string. Failed to match value '{value}' with known input formats.",
131
+ ).replace("{value}", value),
132
+ );
133
+ }
134
+
135
+ return undefined;
136
+ }
137
+
138
+ /**
139
+ * @type {string | number | bigint}
140
+ */
141
+ #assetReference;
142
+ /**
143
+ * @type {string | number | bigint}
144
+ */
145
+ #companyPrefix;
146
+
147
+ /**
148
+ *
149
+ * @param {GiaiProps} options
150
+ */
151
+ constructor({ assetReference, companyPrefix }: GiaiProps) {
152
+ this.#assetReference = assetReference;
153
+ this.#companyPrefix = companyPrefix;
154
+ }
155
+
156
+ get assetReference() {
157
+ return this.#assetReference;
158
+ }
159
+
160
+ get companyPrefix() {
161
+ return this.#companyPrefix;
162
+ }
163
+
164
+ // Returns the EPC pure identity uri for this identifier - as used by EPCIS.
165
+ toEpcPureIdentityUri() {
166
+ return `${Giai.URN_PREFIX}${this.companyPrefix}.${this.assetReference}`;
167
+ }
168
+
169
+ toGiaiBarcode() {
170
+ return Giai.BARCODE_PREFIX + this.companyPrefix + Giai.GROUP_SEPARATOR + this.assetReference;
171
+ }
172
+
173
+ toEpcHex() {
174
+ let bitIdentifier = Giai.EPC_HEADER;
175
+ bitIdentifier += "000"; // Filter
176
+ bitIdentifier += (5).toString(2).padStart(3, "0"); // Partition
177
+ let companyPrefix = ["bigint", "number"].includes(typeof this.#companyPrefix)
178
+ ? this.#companyPrefix
179
+ : BigInt(this.#companyPrefix);
180
+ let assetReference = ["bigint", "number"].includes(typeof this.#assetReference)
181
+ ? this.#assetReference
182
+ : BigInt(this.#assetReference);
183
+ bitIdentifier += companyPrefix.toString(2).padStart(24, "0");
184
+ bitIdentifier += assetReference.toString(2).padStart(58, "0");
185
+
186
+ return BigInt(`0b${bitIdentifier}`).toString(16).toUpperCase();
187
+ }
188
+ }
189
+
190
+ export function hexToBitString(hexString: string) {
191
+ let bitString = "";
192
+
193
+ for (let i = 0; i < hexString.length; i += 2) {
194
+ const byteString = hexString.substr(i, 2);
195
+ const byteBits = Number.parseInt(byteString, 16).toString(2);
196
+
197
+ bitString += byteBits.padStart(8, "0");
198
+ }
199
+
200
+ return bitString;
201
+ }
202
+
203
+ declare global {
204
+ interface Window {
205
+ Giai: typeof Giai | undefined;
206
+ }
207
+ }
208
+
209
+ window.Giai = Giai;
@@ -1,130 +1,130 @@
1
- import { Autocomplete, ListItem, ListItemText, type SxProps, TextField, type Theme } from "@mui/material";
2
- import { useDataWithFilter, useDebounce } from "@olenbetong/appframe-react";
3
- import { useMemo, useRef, useState } from "react";
4
- import { dsProjects, type ProjectsRecord } from "./data/dsProjects";
5
- import { dsReportProjects } from "./data/dsReportProjects";
6
- import { getLocalizedString } from "../i18n.js";
7
-
8
- type ProjectSelectProps = {
9
- className?: string;
10
- disabled?: boolean;
11
- id?: string;
12
- names?: {
13
- domain?: string;
14
- projectId?: string;
15
- name?: string;
16
- };
17
- nullable?: boolean;
18
- readOnly?: boolean;
19
- required?: boolean;
20
- onChange?: (project: Partial<ProjectsRecord> | null) => void;
21
- defaultValue?: Partial<ProjectsRecord> | null;
22
- value?: Partial<ProjectsRecord> | null;
23
- label?: string;
24
- sx?: SxProps<Theme> | undefined;
25
- report?: boolean;
26
- };
27
-
28
- export function ProjectSelect({
29
- className,
30
- disabled,
31
- id,
32
- names,
33
- onChange,
34
- readOnly,
35
- required,
36
- defaultValue,
37
- value,
38
- label,
39
- sx,
40
- report,
41
- }: ProjectSelectProps) {
42
- let [selected, setSelected] = useState<Partial<ProjectsRecord | null>>(defaultValue ?? null);
43
- let [query, setQuery] = useState("");
44
- let search = useDebounce(query);
45
- let projects = useDataWithFilter(
46
- report ? dsReportProjects : dsProjects,
47
- search ? `[SearchColumn] LIKE '%${search}%'` : "",
48
- );
49
-
50
- let highlightRef = useRef<Partial<ProjectsRecord | null>>(null);
51
-
52
- function handleSelect(value: Partial<ProjectsRecord> | null) {
53
- highlightRef.current = null;
54
-
55
- if (!disabled && !readOnly) {
56
- if (onChange) {
57
- onChange(value);
58
- } else {
59
- setSelected(value);
60
- }
61
- }
62
- }
63
-
64
- let current = value === undefined ? selected : value;
65
-
66
- const duplicatedNames = useMemo(() => {
67
- const nameCount = new Map<string, number>();
68
- projects.forEach((opt) => {
69
- nameCount.set(opt.ProjectName, (nameCount.get(opt.ProjectName) || 0) + 1);
70
- });
71
-
72
- return new Set([...nameCount.entries()].filter(([, count]) => count > 1).map(([name]) => name));
73
- }, [projects]);
74
-
75
- return (
76
- <>
77
- <Autocomplete<Partial<ProjectsRecord>>
78
- sx={sx}
79
- autoHighlight
80
- autoSelect
81
- clearOnEscape
82
- className={className}
83
- options={projects}
84
- disabled={disabled}
85
- getOptionLabel={(option) =>
86
- option?.ProjectID !== undefined ? `${option.ProjectID}: ${option.ProjectName}` : ""
87
- }
88
- isOptionEqualToValue={(option, value) => option.Domain === value.Domain && option.ProjectID === value.ProjectID}
89
- onChange={(_, value) => handleSelect(value)}
90
- onClose={() => setQuery("")}
91
- value={value !== undefined ? value : selected}
92
- renderInput={(params) => (
93
- <TextField
94
- {...(params as any)}
95
- label={label ? label : getLocalizedString("Project ID")}
96
- id={id ?? "ProjectLookup"}
97
- fullWidth
98
- slotProps={{
99
- input: params.slotProps?.input,
100
- inputLabel: params.slotProps?.inputLabel,
101
- htmlInput: {
102
- readOnly,
103
- ...params.slotProps?.htmlInput,
104
- },
105
- }}
106
- autoComplete="off"
107
- variant="filled"
108
- required={required}
109
- onChange={(evt) => setQuery(evt.target.value)}
110
- value={query}
111
- />
112
- )}
113
- renderOption={(props, option) => {
114
- let isDuplicated = option.ProjectName && duplicatedNames.has(option.ProjectName);
115
- return (
116
- <ListItem {...props}>
117
- <ListItemText
118
- primary={isDuplicated ? `${option.ProjectName} (${option.Domain})` : option.ProjectName}
119
- secondary={option.ProjectID}
120
- />
121
- </ListItem>
122
- );
123
- }}
124
- />
125
- <input name={names?.domain ?? "Domain"} type="hidden" value={current?.Domain ?? ""} />
126
- <input name={names?.name ?? "ProjectName"} type="hidden" value={current?.ProjectName ?? ""} />
127
- <input name={names?.projectId ?? "ProjectID"} type="hidden" value={current?.ProjectID ?? ""} />
128
- </>
129
- );
130
- }
1
+ import { Autocomplete, ListItem, ListItemText, type SxProps, TextField, type Theme } from "@mui/material";
2
+ import { useDataWithFilter, useDebounce } from "@olenbetong/appframe-react";
3
+ import { useMemo, useRef, useState } from "react";
4
+ import { dsProjects, type ProjectsRecord } from "./data/dsProjects";
5
+ import { dsReportProjects } from "./data/dsReportProjects";
6
+ import { getLocalizedString } from "../i18n.js";
7
+
8
+ type ProjectSelectProps = {
9
+ className?: string;
10
+ disabled?: boolean;
11
+ id?: string;
12
+ names?: {
13
+ domain?: string;
14
+ projectId?: string;
15
+ name?: string;
16
+ };
17
+ nullable?: boolean;
18
+ readOnly?: boolean;
19
+ required?: boolean;
20
+ onChange?: (project: Partial<ProjectsRecord> | null) => void;
21
+ defaultValue?: Partial<ProjectsRecord> | null;
22
+ value?: Partial<ProjectsRecord> | null;
23
+ label?: string;
24
+ sx?: SxProps<Theme> | undefined;
25
+ report?: boolean;
26
+ };
27
+
28
+ export function ProjectSelect({
29
+ className,
30
+ disabled,
31
+ id,
32
+ names,
33
+ onChange,
34
+ readOnly,
35
+ required,
36
+ defaultValue,
37
+ value,
38
+ label,
39
+ sx,
40
+ report,
41
+ }: ProjectSelectProps) {
42
+ let [selected, setSelected] = useState<Partial<ProjectsRecord | null>>(defaultValue ?? null);
43
+ let [query, setQuery] = useState("");
44
+ let search = useDebounce(query);
45
+ let projects = useDataWithFilter(
46
+ report ? dsReportProjects : dsProjects,
47
+ search ? `[SearchColumn] LIKE '%${search}%'` : "",
48
+ );
49
+
50
+ let highlightRef = useRef<Partial<ProjectsRecord | null>>(null);
51
+
52
+ function handleSelect(value: Partial<ProjectsRecord> | null) {
53
+ highlightRef.current = null;
54
+
55
+ if (!disabled && !readOnly) {
56
+ if (onChange) {
57
+ onChange(value);
58
+ } else {
59
+ setSelected(value);
60
+ }
61
+ }
62
+ }
63
+
64
+ let current = value === undefined ? selected : value;
65
+
66
+ const duplicatedNames = useMemo(() => {
67
+ const nameCount = new Map<string, number>();
68
+ projects.forEach((opt) => {
69
+ nameCount.set(opt.ProjectName, (nameCount.get(opt.ProjectName) || 0) + 1);
70
+ });
71
+
72
+ return new Set([...nameCount.entries()].filter(([, count]) => count > 1).map(([name]) => name));
73
+ }, [projects]);
74
+
75
+ return (
76
+ <>
77
+ <Autocomplete<Partial<ProjectsRecord>>
78
+ sx={sx}
79
+ autoHighlight
80
+ autoSelect
81
+ clearOnEscape
82
+ className={className}
83
+ options={projects}
84
+ disabled={disabled}
85
+ getOptionLabel={(option) =>
86
+ option?.ProjectID !== undefined ? `${option.ProjectID}: ${option.ProjectName}` : ""
87
+ }
88
+ isOptionEqualToValue={(option, value) => option.Domain === value.Domain && option.ProjectID === value.ProjectID}
89
+ onChange={(_, value) => handleSelect(value)}
90
+ onClose={() => setQuery("")}
91
+ value={value !== undefined ? value : selected}
92
+ renderInput={(params) => (
93
+ <TextField
94
+ {...(params as any)}
95
+ label={label ? label : getLocalizedString("Project ID")}
96
+ id={id ?? "ProjectLookup"}
97
+ fullWidth
98
+ slotProps={{
99
+ input: params.slotProps?.input,
100
+ inputLabel: params.slotProps?.inputLabel,
101
+ htmlInput: {
102
+ readOnly,
103
+ ...params.slotProps?.htmlInput,
104
+ },
105
+ }}
106
+ autoComplete="off"
107
+ variant="filled"
108
+ required={required}
109
+ onChange={(evt) => setQuery(evt.target.value)}
110
+ value={query}
111
+ />
112
+ )}
113
+ renderOption={(props, option) => {
114
+ let isDuplicated = option.ProjectName && duplicatedNames.has(option.ProjectName);
115
+ return (
116
+ <ListItem {...props}>
117
+ <ListItemText
118
+ primary={isDuplicated ? `${option.ProjectName} (${option.Domain})` : option.ProjectName}
119
+ secondary={option.ProjectID}
120
+ />
121
+ </ListItem>
122
+ );
123
+ }}
124
+ />
125
+ <input name={names?.domain ?? "Domain"} type="hidden" value={current?.Domain ?? ""} />
126
+ <input name={names?.name ?? "ProjectName"} type="hidden" value={current?.ProjectName ?? ""} />
127
+ <input name={names?.projectId ?? "ProjectID"} type="hidden" value={current?.ProjectID ?? ""} />
128
+ </>
129
+ );
130
+ }