@nocobase/client-v2 2.2.9 → 2.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/form/ScanInput/useCodeScanner.d.ts +12 -2
- package/es/components/form/ScanInput/zxingWasmDecoder.d.ts +9 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +2 -0
- package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +1 -0
- package/es/index.mjs +13 -13
- package/lib/index.js +68 -68
- package/package.json +9 -8
- package/src/components/form/ScanInput/CodeScanner.tsx +3 -1
- package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +7 -1
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +182 -8
- package/src/components/form/ScanInput/__tests__/zxingWasmDecoder.test.ts +78 -0
- package/src/components/form/ScanInput/useCodeScanner.ts +135 -20
- package/src/components/form/ScanInput/zxingWasmDecoder.ts +64 -0
- package/src/flow/components/FieldAssignValueInput.tsx +4 -0
- package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +21 -12
- package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +9 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
let decoderPromise: Promise<typeof import('zxing-wasm/reader')> | undefined;
|
|
11
|
+
|
|
12
|
+
async function loadDecoder() {
|
|
13
|
+
if (!decoderPromise) {
|
|
14
|
+
decoderPromise = Promise.all([import('zxing-wasm/reader'), import('zxing-wasm/reader/zxing_reader.wasm')])
|
|
15
|
+
.then(async ([decoder, { default: wasmUrl }]) => {
|
|
16
|
+
try {
|
|
17
|
+
await decoder.prepareZXingModule({
|
|
18
|
+
fireImmediately: true,
|
|
19
|
+
overrides: { locateFile: () => wasmUrl },
|
|
20
|
+
});
|
|
21
|
+
} catch (error) {
|
|
22
|
+
decoder.purgeZXingModule();
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
return decoder;
|
|
26
|
+
})
|
|
27
|
+
.catch((error: unknown) => {
|
|
28
|
+
decoderPromise = undefined;
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return decoderPromise;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function decodeQrCodeWithZxingWasm(imageData: ImageData) {
|
|
36
|
+
const decoder = await loadDecoder();
|
|
37
|
+
const results = await decoder.readBarcodes(imageData, {
|
|
38
|
+
binarizer: 'GlobalHistogram',
|
|
39
|
+
downscaleThreshold: 300,
|
|
40
|
+
formats: ['QRCode'],
|
|
41
|
+
maxNumberOfSymbols: 1,
|
|
42
|
+
tryDenoise: true,
|
|
43
|
+
tryDownscale: true,
|
|
44
|
+
tryHarder: true,
|
|
45
|
+
tryInvert: true,
|
|
46
|
+
tryRotate: true,
|
|
47
|
+
});
|
|
48
|
+
if (results[0]?.text) {
|
|
49
|
+
return results[0].text;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const fallbackResults = await decoder.readBarcodes(imageData, {
|
|
53
|
+
binarizer: 'LocalAverage',
|
|
54
|
+
downscaleThreshold: 300,
|
|
55
|
+
formats: ['QRCode'],
|
|
56
|
+
maxNumberOfSymbols: 1,
|
|
57
|
+
tryDenoise: true,
|
|
58
|
+
tryDownscale: true,
|
|
59
|
+
tryHarder: true,
|
|
60
|
+
tryInvert: true,
|
|
61
|
+
tryRotate: true,
|
|
62
|
+
});
|
|
63
|
+
return fallbackResults[0]?.text;
|
|
64
|
+
}
|
|
@@ -71,6 +71,8 @@ interface Props {
|
|
|
71
71
|
enableDateVariableAsConstant?: boolean;
|
|
72
72
|
/** 是否允许在变量选择器中使用 RunJS。默认 true,保持历史行为。 */
|
|
73
73
|
allowRunJS?: boolean;
|
|
74
|
+
/** 是否允许在变量选择器中使用内置日期变量。默认 true。 */
|
|
75
|
+
allowDateVariables?: boolean;
|
|
74
76
|
maxAssociationFieldDepth?: number;
|
|
75
77
|
disabled?: boolean;
|
|
76
78
|
variableConverters?: VariableInputProps['converters'];
|
|
@@ -444,6 +446,7 @@ export const FieldAssignValueInput: React.FC<Props> = ({
|
|
|
444
446
|
preferFormItemFieldModel,
|
|
445
447
|
associationFieldNamesOverride,
|
|
446
448
|
allowRunJS = true,
|
|
449
|
+
allowDateVariables = true,
|
|
447
450
|
maxAssociationFieldDepth = 2,
|
|
448
451
|
disabled = false,
|
|
449
452
|
variableConverters,
|
|
@@ -972,6 +975,7 @@ export const FieldAssignValueInput: React.FC<Props> = ({
|
|
|
972
975
|
style={{ width: '100%' }}
|
|
973
976
|
clearValue={''}
|
|
974
977
|
allowRunJS={allowRunJS}
|
|
978
|
+
allowDateVariables={allowDateVariables}
|
|
975
979
|
disabled={disabled}
|
|
976
980
|
converters={variableConverters}
|
|
977
981
|
/>
|
|
@@ -71,6 +71,7 @@ export type FieldValueVariableInputProps = Omit<
|
|
|
71
71
|
isDateLikeField: boolean;
|
|
72
72
|
dateComponentProps: DateVariableComponentProps;
|
|
73
73
|
allowRunJS?: boolean;
|
|
74
|
+
allowDateVariables?: boolean;
|
|
74
75
|
converters?: VariableInputProps['converters'];
|
|
75
76
|
};
|
|
76
77
|
|
|
@@ -149,6 +150,7 @@ export const FieldValueVariableInput: React.FC<FieldValueVariableInputProps> = (
|
|
|
149
150
|
isDateLikeField,
|
|
150
151
|
dateComponentProps,
|
|
151
152
|
allowRunJS = true,
|
|
153
|
+
allowDateVariables = true,
|
|
152
154
|
converters,
|
|
153
155
|
clearValue = '',
|
|
154
156
|
disabled = false,
|
|
@@ -168,7 +170,7 @@ export const FieldValueVariableInput: React.FC<FieldValueVariableInputProps> = (
|
|
|
168
170
|
return Component;
|
|
169
171
|
}, [dateComponentProps, isDateLikeField]);
|
|
170
172
|
|
|
171
|
-
const parsedDateConfig = parseCtxDateExpressionConfig(value);
|
|
173
|
+
const parsedDateConfig = allowDateVariables ? parseCtxDateExpressionConfig(value) : undefined;
|
|
172
174
|
const restoreLegacyNowForPureDate =
|
|
173
175
|
dateComponentProps.exactNormalizeMode === 'date' &&
|
|
174
176
|
parsedDateConfig?.kind === 'preset' &&
|
|
@@ -230,14 +232,18 @@ export const FieldValueVariableInput: React.FC<FieldValueVariableInputProps> = (
|
|
|
230
232
|
paths: ['null'],
|
|
231
233
|
render: (props) => <NullComponent {...props} />,
|
|
232
234
|
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
235
|
+
...(allowDateVariables
|
|
236
|
+
? [
|
|
237
|
+
{
|
|
238
|
+
title: tExpr('Date'),
|
|
239
|
+
name: 'date',
|
|
240
|
+
type: 'date',
|
|
241
|
+
paths: ['date'],
|
|
242
|
+
selectable: false,
|
|
243
|
+
children: dateChildren,
|
|
244
|
+
} satisfies MetaTreeNode,
|
|
245
|
+
]
|
|
246
|
+
: []),
|
|
241
247
|
...(allowRunJS
|
|
242
248
|
? [
|
|
243
249
|
{
|
|
@@ -257,6 +263,7 @@ export const FieldValueVariableInput: React.FC<FieldValueVariableInputProps> = (
|
|
|
257
263
|
DateEditor,
|
|
258
264
|
NullComponent,
|
|
259
265
|
RunJSComponent,
|
|
266
|
+
allowDateVariables,
|
|
260
267
|
allowRunJS,
|
|
261
268
|
baseMetaTree,
|
|
262
269
|
dateComponentProps.exactNormalizeMode,
|
|
@@ -294,7 +301,7 @@ export const FieldValueVariableInput: React.FC<FieldValueVariableInputProps> = (
|
|
|
294
301
|
const firstPath = meta?.paths?.[0];
|
|
295
302
|
if (firstPath === 'constant') return ConstantComponent;
|
|
296
303
|
if (firstPath === 'null') return NullComponent;
|
|
297
|
-
if (firstPath === 'date') return DateEditor;
|
|
304
|
+
if (allowDateVariables && firstPath === 'date') return DateEditor;
|
|
298
305
|
if (allowRunJS && firstPath === 'runjs') return RunJSComponent;
|
|
299
306
|
return null;
|
|
300
307
|
},
|
|
@@ -304,7 +311,7 @@ export const FieldValueVariableInput: React.FC<FieldValueVariableInputProps> = (
|
|
|
304
311
|
const firstPath = item?.paths?.[0];
|
|
305
312
|
if (firstPath === 'constant') return '';
|
|
306
313
|
if (firstPath === 'null') return null;
|
|
307
|
-
if (firstPath === 'date') {
|
|
314
|
+
if (allowDateVariables && firstPath === 'date') {
|
|
308
315
|
return createInitialDateConfig(item.paths[1], isDateLikeField, dateComponentProps);
|
|
309
316
|
}
|
|
310
317
|
if (allowRunJS && firstPath === 'runjs') return { code: '', version: 'v2' };
|
|
@@ -315,7 +322,9 @@ export const FieldValueVariableInput: React.FC<FieldValueVariableInputProps> = (
|
|
|
315
322
|
if (external !== undefined) return external;
|
|
316
323
|
if (currentValue === null) return ['null'];
|
|
317
324
|
if (allowRunJS && isRunJSValue(currentValue)) return ['runjs'];
|
|
318
|
-
if (isDateVariableEditConfig(currentValue))
|
|
325
|
+
if (allowDateVariables && isDateVariableEditConfig(currentValue)) {
|
|
326
|
+
return ['date', getDateNodeName(currentValue)];
|
|
327
|
+
}
|
|
319
328
|
return typeof currentValue === 'string' && isVariableExpression(currentValue)
|
|
320
329
|
? parseValueToPath(currentValue)
|
|
321
330
|
: ['constant'];
|
|
@@ -50,6 +50,7 @@ function renderInput(options?: {
|
|
|
50
50
|
value?: unknown;
|
|
51
51
|
isDateLikeField?: boolean;
|
|
52
52
|
dateComponentProps?: DateVariableComponentProps;
|
|
53
|
+
allowDateVariables?: boolean;
|
|
53
54
|
}) {
|
|
54
55
|
const onChange = vi.fn();
|
|
55
56
|
render(
|
|
@@ -62,6 +63,7 @@ function renderInput(options?: {
|
|
|
62
63
|
runJSComponent={RunJSComponent}
|
|
63
64
|
isDateLikeField={options?.isDateLikeField ?? false}
|
|
64
65
|
dateComponentProps={options?.dateComponentProps ?? DEFAULT_DATE_VARIABLE_COMPONENT_PROPS}
|
|
66
|
+
allowDateVariables={options?.allowDateVariables}
|
|
65
67
|
/>,
|
|
66
68
|
);
|
|
67
69
|
return onChange;
|
|
@@ -110,6 +112,13 @@ describe('FieldValueVariableInput', () => {
|
|
|
110
112
|
expect(tree[4].name).toBe('currentUser');
|
|
111
113
|
});
|
|
112
114
|
|
|
115
|
+
it('omits the built-in Date variables when they are disabled', async () => {
|
|
116
|
+
renderInput({ isDateLikeField: true, allowDateVariables: false });
|
|
117
|
+
|
|
118
|
+
const tree = await resolveMetaTree();
|
|
119
|
+
expect(tree.map((node) => node.name)).toEqual(['constant', 'null', 'runjs', 'currentUser']);
|
|
120
|
+
});
|
|
121
|
+
|
|
113
122
|
it('does not allow Now for pure date fields', async () => {
|
|
114
123
|
const dateComponentProps: DateVariableComponentProps = {
|
|
115
124
|
...DEFAULT_DATE_VARIABLE_COMPONENT_PROPS,
|