@nocobase/client-v2 2.2.0-alpha.1 → 2.2.0-alpha.2
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/PluginSettingsManager.d.ts +33 -0
- package/es/RouteRepository.d.ts +21 -6
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/JsonTextArea.d.ts +2 -1
- package/es/components/form/TypedVariableInput.d.ts +22 -4
- package/es/components/form/VariableJsonTextArea.d.ts +19 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/index.d.ts +1 -0
- package/es/components/index.d.ts +2 -0
- package/es/flow/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
- package/es/flow/components/FieldAssignRulesEditor.d.ts +3 -1
- package/es/flow/components/FieldAssignValueInput.d.ts +2 -0
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/GridModel.d.ts +1 -1
- package/es/flow/models/blocks/filter-form/FilterFormBlockModel.d.ts +5 -0
- package/es/flow/models/blocks/form/FormBlockModel.d.ts +4 -0
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- package/es/flow/models/blocks/form/value-runtime/rules.d.ts +21 -0
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +21 -0
- package/es/flow/models/blocks/form/value-runtime/types.d.ts +2 -2
- package/es/flow/models/blocks/table/TableActionsColumnModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +1 -1
- package/es/flow/models/blocks/table/dragSort/dragSortSettings.d.ts +2 -1
- package/es/flow/models/blocks/table/dragSort/dragSortUtils.d.ts +6 -4
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +2 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +6 -0
- package/es/flow/resolveViewParamsToViewList.d.ts +1 -1
- package/es/flow/utils/dataScopeRowSnapshot.d.ts +59 -0
- package/es/flow/utils/dateTimeDisplayProps.d.ts +49 -0
- package/es/flow/utils/formValueDeps.d.ts +32 -0
- package/es/flow-compat/FieldValidation.d.ts +2 -1
- package/es/index.d.ts +2 -1
- package/es/index.mjs +233 -137
- package/lib/index.js +234 -138
- package/package.json +7 -7
- package/src/PluginSettingsManager.ts +53 -0
- package/src/RouteRepository.ts +126 -24
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/RouteRepository.test.ts +216 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/exports.test.ts +16 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +199 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +40 -1
- package/src/collection-manager/field-configure.ts +1 -1
- package/src/collection-manager/interfaces/id.ts +1 -1
- package/src/collection-manager/interfaces/m2m.tsx +2 -2
- package/src/collection-manager/interfaces/m2o.tsx +2 -2
- package/src/collection-manager/interfaces/nanoid.ts +1 -1
- package/src/collection-manager/interfaces/o2m.tsx +2 -2
- package/src/collection-manager/interfaces/obo.tsx +2 -2
- package/src/collection-manager/interfaces/oho.tsx +2 -2
- package/src/collection-manager/interfaces/properties/index.ts +2 -2
- package/src/collection-manager/interfaces/uuid.ts +1 -1
- package/src/components/AppComponents.tsx +19 -3
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/JsonTextArea.tsx +21 -11
- package/src/components/form/TypedVariableInput.tsx +416 -93
- package/src/components/form/VariableJsonTextArea.tsx +175 -0
- package/src/components/form/__tests__/JsonTextArea.test.tsx +43 -0
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +266 -9
- package/src/components/form/__tests__/VariableJsonTextArea.test.tsx +86 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/index.tsx +1 -0
- package/src/components/index.ts +2 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +443 -5
- package/src/flow/__tests__/getKey.test.ts +7 -0
- package/src/flow/__tests__/resolveViewParamsToViewList.test.ts +34 -0
- package/src/flow/actions/__tests__/afterSuccess.test.ts +73 -0
- package/src/flow/actions/__tests__/dataScopeFilter.test.ts +58 -0
- package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +1022 -0
- package/src/flow/actions/__tests__/fieldLinkageRules.scopeDepth.test.ts +150 -1
- package/src/flow/actions/__tests__/linkageAssignField.legacy.test.ts +135 -0
- package/src/flow/actions/__tests__/linkageRules.hiddenSync.restore.test.ts +19 -5
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +92 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +104 -0
- package/src/flow/actions/__tests__/subFormFieldLinkageRules.inputArgs.test.ts +2 -2
- package/src/flow/actions/afterSuccess.tsx +142 -3
- package/src/flow/actions/customVariable.tsx +1 -2
- package/src/flow/actions/dataScopeFilter.ts +10 -0
- package/src/flow/actions/dateTimeFormat.tsx +42 -28
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/linkageRules.tsx +123 -35
- package/src/flow/actions/linkageRulesFormValueRefresh.ts +22 -130
- package/src/flow/actions/openView.tsx +38 -4
- package/src/flow/actions/runjs.tsx +2 -14
- package/src/flow/actions/validation.tsx +62 -30
- package/src/flow/admin-shell/BaseLayoutModel.tsx +25 -3
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +5 -2
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +34 -10
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +310 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +44 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
- package/src/flow/admin-shell/admin-layout/HelpLite.tsx +1 -3
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +188 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +166 -2
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
- package/src/flow/components/DefaultValue.tsx +1 -2
- package/src/flow/components/DynamicFlowsIcon.tsx +447 -126
- package/src/flow/components/FieldAssignRulesEditor.tsx +128 -21
- package/src/flow/components/FieldAssignValueInput.tsx +10 -5
- package/src/flow/components/FlowRoute.tsx +56 -11
- package/src/flow/components/__tests__/DynamicFlowsIcon.test.tsx +148 -2
- package/src/flow/components/__tests__/FieldAssignRulesEditor.test.tsx +508 -4
- package/src/flow/components/__tests__/fieldAssignOptions.test.ts +151 -3
- package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
- package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
- package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
- package/src/flow/components/fieldAssignOptions.ts +155 -27
- package/src/flow/flows/editMarkdownFlow.tsx +1 -1
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/index.ts +2 -1
- package/src/flow/internal/utils/operatorSchemaHelper.ts +15 -1
- package/src/flow/models/actions/JSActionModel.tsx +2 -7
- package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
- package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
- package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
- package/src/flow/models/base/ActionModel.tsx +12 -1
- package/src/flow/models/base/GridModel.tsx +38 -7
- package/src/flow/models/base/PageModel/PageModel.tsx +4 -1
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +28 -4
- package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
- package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +31 -3
- package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
- package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +77 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +1 -1
- package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/customizeFilterRender.test.tsx +56 -1
- package/src/flow/models/blocks/form/EditFormModel.tsx +1 -0
- package/src/flow/models/blocks/form/FormActionModel.tsx +1 -1
- package/src/flow/models/blocks/form/FormBlockModel.tsx +7 -0
- package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +17 -0
- package/src/flow/models/blocks/form/__tests__/submitHandler.test.ts +54 -1
- package/src/flow/models/blocks/form/submitHandler.ts +17 -3
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +880 -102
- package/src/flow/models/blocks/form/value-runtime/rules.ts +445 -13
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +257 -13
- package/src/flow/models/blocks/form/value-runtime/types.ts +2 -2
- package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
- package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +36 -13
- package/src/flow/models/blocks/table/TableBlockModel.tsx +38 -17
- package/src/flow/models/blocks/table/TableColumnModel.tsx +36 -3
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +111 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +1 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +159 -1
- package/src/flow/models/blocks/table/dragSort/dragSortHooks.tsx +28 -17
- package/src/flow/models/blocks/table/dragSort/dragSortSettings.ts +13 -6
- package/src/flow/models/blocks/table/dragSort/dragSortUtils.ts +15 -2
- package/src/flow/models/fields/AssociationFieldModel/AssociationFieldModel.tsx +1 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +29 -6
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +16 -4
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +141 -19
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableField.tsx +13 -1
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.rowRecord.test.ts +197 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableFieldModel.reset.test.ts +180 -0
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/index.tsx +6 -4
- package/src/flow/models/fields/AssociationFieldModel/__tests__/AssociationFieldModel.updateAssociation.test.ts +72 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +23 -0
- package/src/flow/models/fields/ClickableFieldModel.tsx +5 -0
- package/src/flow/models/fields/DisplayDateTimeFieldModel.tsx +29 -1
- package/src/flow/models/fields/InputFieldModel.tsx +40 -2
- package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
- package/src/flow/models/fields/JSFieldModel.tsx +2 -7
- package/src/flow/models/fields/JSItemModel.tsx +2 -14
- package/src/flow/models/fields/SelectFieldModel.tsx +6 -4
- package/src/flow/models/fields/TextareaFieldModel.tsx +49 -3
- package/src/flow/models/fields/__tests__/DisplayDateTimeFieldModel.test.tsx +96 -0
- package/src/flow/models/fields/__tests__/InputFieldModel.test.tsx +117 -1
- package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +43 -0
- package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +100 -0
- package/src/flow/models/topbar/TopbarActionModel.tsx +93 -10
- package/src/flow/resolveViewParamsToViewList.tsx +11 -3
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +258 -0
- package/src/flow/utils/dataScopeFormValueClear.ts +218 -81
- package/src/flow/utils/dataScopeRowSnapshot.ts +616 -0
- package/src/flow/utils/dateTimeDisplayProps.ts +135 -0
- package/src/flow/utils/formValueDeps.ts +170 -0
- package/src/flow-compat/FieldValidation.tsx +122 -60
- package/src/flow-compat/Popover.tsx +43 -4
- package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
- package/src/index.ts +8 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
- package/src/nocobase-buildin-plugin/index.tsx +44 -14
- package/src/settings-center/AdminSettingsLayout.tsx +10 -2
- package/src/settings-center/SystemSettingsPage.tsx +1 -2
- package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
- package/src/settings-center/plugin-manager/index.tsx +3 -0
- package/src/settings-center/utils.tsx +0 -6
|
@@ -112,6 +112,11 @@ export class SubTableFieldModel extends AssociationFieldModel {
|
|
|
112
112
|
};
|
|
113
113
|
const isConfigMode = !!this.context.flowSettingsEnabled;
|
|
114
114
|
const fieldPathArray = this.context.fieldPathArray ?? this.parent?.context?.fieldPathArray;
|
|
115
|
+
const onResetFieldValue = () => {
|
|
116
|
+
const value = [];
|
|
117
|
+
this.setProps({ value });
|
|
118
|
+
this.context.blockModel?.setFieldValue?.(fieldPathArray, value);
|
|
119
|
+
};
|
|
115
120
|
return (
|
|
116
121
|
<SubTableField
|
|
117
122
|
{...this.props}
|
|
@@ -124,6 +129,7 @@ export class SubTableFieldModel extends AssociationFieldModel {
|
|
|
124
129
|
formValuesChangeEmitter={this.context.blockModel?.emitter}
|
|
125
130
|
fieldPathArray={fieldPathArray}
|
|
126
131
|
getCurrentValue={() => this.getCurrentValue()}
|
|
132
|
+
onResetFieldValue={onResetFieldValue}
|
|
127
133
|
/>
|
|
128
134
|
);
|
|
129
135
|
}
|
|
@@ -136,10 +142,6 @@ export class SubTableFieldModel extends AssociationFieldModel {
|
|
|
136
142
|
this.context.defineProperty('collection', {
|
|
137
143
|
get: () => this.context.collectionField.targetCollection,
|
|
138
144
|
});
|
|
139
|
-
// 监听表单reset
|
|
140
|
-
this.context.blockModel.emitter.on('onFieldReset', () => {
|
|
141
|
-
this.props.onChange([]);
|
|
142
|
-
});
|
|
143
145
|
this.onSelectExitRecordClick = (setCurrentPage, currentPageSize) => {
|
|
144
146
|
this.setCurrentPage = setCurrentPage;
|
|
145
147
|
this.currentPageSize = currentPageSize;
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
import { FlowEngine, FlowModel } from '@nocobase/flow-engine';
|
|
11
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
12
|
+
import { AssociationFieldModel } from '../AssociationFieldModel';
|
|
13
|
+
|
|
14
|
+
class DefaultAssociationFieldModel extends AssociationFieldModel {}
|
|
15
|
+
|
|
16
|
+
class UpdateAssociationFieldModel extends AssociationFieldModel {
|
|
17
|
+
updateAssociation = true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function runAssociationFieldInit(FieldModelClass: typeof AssociationFieldModel) {
|
|
21
|
+
const engine = new FlowEngine();
|
|
22
|
+
engine.registerModels({
|
|
23
|
+
DefaultAssociationFieldModel,
|
|
24
|
+
UpdateAssociationFieldModel,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const addUpdateAssociationValues = vi.fn();
|
|
28
|
+
const blockModel = engine.createModel<FlowModel>({
|
|
29
|
+
use: 'FlowModel',
|
|
30
|
+
uid: 'form-block',
|
|
31
|
+
});
|
|
32
|
+
blockModel.context.defineProperty('resource', {
|
|
33
|
+
value: { addUpdateAssociationValues },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const formItem = engine.createModel<FlowModel>({
|
|
37
|
+
use: 'FlowModel',
|
|
38
|
+
uid: 'form-item',
|
|
39
|
+
});
|
|
40
|
+
(formItem as FlowModel & { fieldPath: string }).fieldPath = 'author';
|
|
41
|
+
formItem.context.defineProperty('blockModel', { value: blockModel });
|
|
42
|
+
|
|
43
|
+
const field = engine.createModel<AssociationFieldModel>({
|
|
44
|
+
use: FieldModelClass,
|
|
45
|
+
uid: 'association-field',
|
|
46
|
+
parentId: formItem.uid,
|
|
47
|
+
});
|
|
48
|
+
field.context.defineProperty('collectionField', {
|
|
49
|
+
value: {
|
|
50
|
+
dataSourceKey: 'main',
|
|
51
|
+
target: 'users',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await field.applyFlow('AssociationFieldInit');
|
|
56
|
+
|
|
57
|
+
return addUpdateAssociationValues;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('AssociationFieldModel updateAssociation', () => {
|
|
61
|
+
it('does not add updateAssociationValues by default', async () => {
|
|
62
|
+
const addUpdateAssociationValues = await runAssociationFieldInit(DefaultAssociationFieldModel);
|
|
63
|
+
|
|
64
|
+
expect(addUpdateAssociationValues).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('adds updateAssociationValues for opt-in association fields', async () => {
|
|
68
|
+
const addUpdateAssociationValues = await runAssociationFieldInit(UpdateAssociationFieldModel);
|
|
69
|
+
|
|
70
|
+
expect(addUpdateAssociationValues).toHaveBeenCalledWith('author');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
normalizeRecordPickerValue,
|
|
29
29
|
shouldClearRecordPickerValueOnMultipleChange,
|
|
30
30
|
} from '../RecordPickerFieldModel';
|
|
31
|
+
import { getAssociationHydrationNamePath, getAssociationHydrationSetterContext } from '../RecordSelectFieldModel';
|
|
31
32
|
|
|
32
33
|
function createMockCollection() {
|
|
33
34
|
return {
|
|
@@ -93,6 +94,28 @@ describe('RecordPickerFieldModel item context', () => {
|
|
|
93
94
|
expect(shouldClearRecordPickerValueOnMultipleChange({ type: 'belongsTo' }, true, false)).toBe(false);
|
|
94
95
|
});
|
|
95
96
|
|
|
97
|
+
it('uses the current field context for association hydration writes', () => {
|
|
98
|
+
const setFormValue = vi.fn();
|
|
99
|
+
const blockSetFormValue = vi.fn();
|
|
100
|
+
const model = {
|
|
101
|
+
props: {
|
|
102
|
+
name: 'orders',
|
|
103
|
+
},
|
|
104
|
+
context: {
|
|
105
|
+
fieldPathArray: ['orders', 0, 'lines', 1, 'product'],
|
|
106
|
+
setFormValue,
|
|
107
|
+
blockModel: {
|
|
108
|
+
context: {
|
|
109
|
+
setFormValue: blockSetFormValue,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
expect(getAssociationHydrationNamePath(model)).toEqual(['orders', 0, 'lines', 1, 'product']);
|
|
116
|
+
expect(getAssociationHydrationSetterContext(model)).toBe(model.context);
|
|
117
|
+
});
|
|
118
|
+
|
|
96
119
|
it('itemChain helpers: createParentItemAccessorsFromInputArgs works', () => {
|
|
97
120
|
const inputArgs = {
|
|
98
121
|
parentItem: { value: { id: 1 } },
|
|
@@ -8,14 +8,42 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { DisplayItemModel, tExpr } from '@nocobase/flow-engine';
|
|
11
|
+
import { getDateTimeFormat, getPickerFormat } from '@nocobase/utils/client';
|
|
11
12
|
import dayjs from 'dayjs';
|
|
12
13
|
import React from 'react';
|
|
13
14
|
import { ClickableFieldModel } from './ClickableFieldModel';
|
|
14
15
|
|
|
16
|
+
const stripTimeFromFormat = (format?: string) =>
|
|
17
|
+
format ? format.replace(/\s*[Hh]{1,2}:mm(?::ss)?(?:\.SSS)?(?:\s*[aA])?/g, '').trim() : format;
|
|
18
|
+
|
|
19
|
+
interface DisplayDateTimeFormatProps {
|
|
20
|
+
dateOnly?: boolean;
|
|
21
|
+
picker?: string;
|
|
22
|
+
format?: string;
|
|
23
|
+
dateFormat?: string;
|
|
24
|
+
showTime?: boolean;
|
|
25
|
+
timeFormat?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const resolveDisplayDateTimeFormat = (props: DisplayDateTimeFormatProps) => {
|
|
29
|
+
const { dateOnly, picker = 'date', format, dateFormat, showTime, timeFormat } = props;
|
|
30
|
+
const normalizedFormat = stripTimeFromFormat(format);
|
|
31
|
+
if (picker !== 'date') {
|
|
32
|
+
return dateFormat || normalizedFormat || getPickerFormat(picker);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!dateOnly && !dateFormat && typeof showTime === 'undefined' && !timeFormat && normalizedFormat) {
|
|
36
|
+
return format;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const normalizedDateFormat = dateFormat || normalizedFormat || getPickerFormat(picker);
|
|
40
|
+
return getDateTimeFormat(picker, normalizedDateFormat, showTime, timeFormat);
|
|
41
|
+
};
|
|
42
|
+
|
|
15
43
|
export class DisplayDateTimeFieldModel extends ClickableFieldModel {
|
|
16
44
|
public renderComponent(value) {
|
|
17
45
|
const { className, style } = this.props;
|
|
18
|
-
const finalFormat = this.props
|
|
46
|
+
const finalFormat = resolveDisplayDateTimeFormat(this.props);
|
|
19
47
|
let formattedValue = '';
|
|
20
48
|
if (value) {
|
|
21
49
|
const day = dayjs(value);
|
|
@@ -9,18 +9,56 @@
|
|
|
9
9
|
|
|
10
10
|
import { EditableItemModel, FilterableItemModel, tExpr } from '@nocobase/flow-engine';
|
|
11
11
|
import { Input } from 'antd';
|
|
12
|
-
import
|
|
12
|
+
import type { InputProps } from 'antd';
|
|
13
|
+
import React, { useEffect, useState } from 'react';
|
|
13
14
|
import { customAlphabet as Alphabet } from 'nanoid';
|
|
14
15
|
import { FieldModel } from '../base/FieldModel';
|
|
15
16
|
import { ScanInput } from '../../../components/form/ScanInput';
|
|
16
17
|
|
|
18
|
+
function IMESafeInput(props: InputProps) {
|
|
19
|
+
const { value, onChange, onCompositionStart, onCompositionEnd, ...rest } = props;
|
|
20
|
+
const [inputValue, setInputValue] = useState<InputProps['value']>(() => normalizeInputValue(value));
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setInputValue(normalizeInputValue(value));
|
|
24
|
+
}, [value]);
|
|
25
|
+
|
|
26
|
+
const getEventValue = (event: React.ChangeEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) =>
|
|
27
|
+
event.currentTarget.value;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Input
|
|
31
|
+
{...rest}
|
|
32
|
+
value={inputValue}
|
|
33
|
+
onChange={(event) => {
|
|
34
|
+
setInputValue(getEventValue(event));
|
|
35
|
+
onChange?.(event);
|
|
36
|
+
}}
|
|
37
|
+
onCompositionStart={(event) => {
|
|
38
|
+
setInputValue(getEventValue(event));
|
|
39
|
+
onCompositionStart?.(event);
|
|
40
|
+
}}
|
|
41
|
+
onCompositionEnd={(event) => {
|
|
42
|
+
setInputValue(getEventValue(event));
|
|
43
|
+
onCompositionEnd?.(event);
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function normalizeInputValue(nextValue: unknown): InputProps['value'] {
|
|
50
|
+
if (typeof nextValue === 'bigint') return String(nextValue);
|
|
51
|
+
if (nextValue == null) return '';
|
|
52
|
+
return nextValue as InputProps['value'];
|
|
53
|
+
}
|
|
54
|
+
|
|
17
55
|
export class InputFieldModel extends FieldModel {
|
|
18
56
|
render() {
|
|
19
57
|
if (this.props.enableScan) {
|
|
20
58
|
return <ScanInput {...this.props} />;
|
|
21
59
|
}
|
|
22
60
|
const { enableScan, disableManualInput, ...inputProps } = this.props;
|
|
23
|
-
return <
|
|
61
|
+
return <IMESafeInput {...inputProps} />;
|
|
24
62
|
}
|
|
25
63
|
}
|
|
26
64
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { ElementProxy, tExpr
|
|
10
|
+
import { ElementProxy, tExpr } from '@nocobase/flow-engine';
|
|
11
11
|
import React, { useEffect, useMemo, useRef } from 'react';
|
|
12
12
|
import { Input } from 'antd';
|
|
13
13
|
import { FieldModel } from '../base/FieldModel';
|
|
@@ -398,16 +398,7 @@ JSEditableFieldModel.registerFlow({
|
|
|
398
398
|
get: () => isReadOnlyMode(ctx.model),
|
|
399
399
|
cache: false,
|
|
400
400
|
});
|
|
401
|
-
|
|
402
|
-
await ctx.runjs(
|
|
403
|
-
code,
|
|
404
|
-
{
|
|
405
|
-
window: createSafeWindow({ navigator }),
|
|
406
|
-
document: createSafeDocument(),
|
|
407
|
-
navigator,
|
|
408
|
-
},
|
|
409
|
-
{ version },
|
|
410
|
-
);
|
|
401
|
+
await ctx.runjs(code, undefined, { version });
|
|
411
402
|
});
|
|
412
403
|
},
|
|
413
404
|
},
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { ElementProxy, tExpr
|
|
10
|
+
import { ElementProxy, tExpr } from '@nocobase/flow-engine';
|
|
11
11
|
import React, { useEffect } from 'react';
|
|
12
12
|
import { FieldModel } from '../base/FieldModel';
|
|
13
13
|
import { resolveRunJsParams } from '../utils/resolveRunJsParams';
|
|
@@ -211,12 +211,7 @@ JSFieldModel.registerFlow({
|
|
|
211
211
|
get: () => ctx.model.props?.value,
|
|
212
212
|
cache: false,
|
|
213
213
|
});
|
|
214
|
-
|
|
215
|
-
await ctx.runjs(
|
|
216
|
-
code,
|
|
217
|
-
{ window: createSafeWindow({ navigator }), document: createSafeDocument(), navigator },
|
|
218
|
-
{ version },
|
|
219
|
-
);
|
|
214
|
+
await ctx.runjs(code, undefined, { version });
|
|
220
215
|
});
|
|
221
216
|
},
|
|
222
217
|
},
|
|
@@ -7,14 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
ElementProxy,
|
|
12
|
-
FormItem,
|
|
13
|
-
createSafeDocument,
|
|
14
|
-
createSafeWindow,
|
|
15
|
-
createSafeNavigator,
|
|
16
|
-
tExpr,
|
|
17
|
-
} from '@nocobase/flow-engine';
|
|
10
|
+
import { ElementProxy, FormItem, tExpr } from '@nocobase/flow-engine';
|
|
18
11
|
import React from 'react';
|
|
19
12
|
import { CodeEditor } from '../../components/code-editor';
|
|
20
13
|
import { CommonItemModel } from '../base/CommonItemModel';
|
|
@@ -150,12 +143,7 @@ ctx.render(<JsItem />);
|
|
|
150
143
|
ctx.defineProperty('element', {
|
|
151
144
|
get: () => new ElementProxy(element),
|
|
152
145
|
});
|
|
153
|
-
|
|
154
|
-
await ctx.runjs(
|
|
155
|
-
code,
|
|
156
|
-
{ window: createSafeWindow({ navigator }), document: createSafeDocument(), navigator },
|
|
157
|
-
{ version },
|
|
158
|
-
);
|
|
146
|
+
await ctx.runjs(code, undefined, { version });
|
|
159
147
|
});
|
|
160
148
|
},
|
|
161
149
|
},
|
|
@@ -15,17 +15,20 @@ import { MobileSelect } from './mobile-components/MobileSelect';
|
|
|
15
15
|
import { enumToOptions, getSelectedEnumLabels, translateOptionLabel } from '../../internal/utils/enumOptionsUtils';
|
|
16
16
|
|
|
17
17
|
const getOriginalEnumOptions = (model: SelectFieldModel) => {
|
|
18
|
-
const fromEnum = enumToOptions(model.context.collectionField?.uiSchema?.enum,
|
|
18
|
+
const fromEnum = enumToOptions(model.context.collectionField?.uiSchema?.enum, model.translate) || [];
|
|
19
19
|
if (fromEnum.length > 0) {
|
|
20
20
|
return fromEnum.map((option) => ({ ...option }));
|
|
21
21
|
}
|
|
22
22
|
const current = Array.isArray(model.props.options) ? model.props.options : [];
|
|
23
|
-
return current.map((option) => ({
|
|
23
|
+
return current.map((option) => ({
|
|
24
|
+
...option,
|
|
25
|
+
label: translateOptionLabel(option.label, model.translate),
|
|
26
|
+
}));
|
|
24
27
|
};
|
|
25
|
-
|
|
26
28
|
export class SelectFieldModel extends FieldModel {
|
|
27
29
|
render() {
|
|
28
30
|
const fallbackOptions = getOriginalEnumOptions(this);
|
|
31
|
+
|
|
29
32
|
const options = this.props.options?.map((v) => {
|
|
30
33
|
return {
|
|
31
34
|
...v,
|
|
@@ -46,7 +49,6 @@ export class SelectFieldModel extends FieldModel {
|
|
|
46
49
|
if (this.context.isMobileLayout) {
|
|
47
50
|
return <MobileSelect {...this.props} options={options} displayValue={value} />;
|
|
48
51
|
}
|
|
49
|
-
|
|
50
52
|
return (
|
|
51
53
|
<Select
|
|
52
54
|
{...this.props}
|
|
@@ -8,15 +8,61 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { Input } from 'antd';
|
|
11
|
-
import
|
|
12
|
-
import
|
|
11
|
+
import type { TextAreaProps } from 'antd/es/input';
|
|
12
|
+
import type { TextAreaRef } from 'antd/es/input/TextArea';
|
|
13
|
+
import React, { useEffect, useRef } from 'react';
|
|
13
14
|
import { largeField, EditableItemModel } from '@nocobase/flow-engine';
|
|
14
15
|
import { FieldModel } from '../base/FieldModel';
|
|
15
16
|
|
|
17
|
+
function IMESafeTextArea(props: TextAreaProps) {
|
|
18
|
+
const { value, onChange, onCompositionStart, onCompositionEnd, ...rest } = props;
|
|
19
|
+
const textAreaRef = useRef<TextAreaRef>(null);
|
|
20
|
+
const previousValueRef = useRef(value);
|
|
21
|
+
const defaultValue = typeof value === 'bigint' ? String(value) : value;
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (Object.is(previousValueRef.current, value)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
previousValueRef.current = value;
|
|
28
|
+
|
|
29
|
+
const textArea = textAreaRef.current?.resizableTextArea?.textArea;
|
|
30
|
+
if (textArea) {
|
|
31
|
+
const nextValue = value == null ? '' : String(value);
|
|
32
|
+
if (textArea.value !== nextValue) {
|
|
33
|
+
textArea.value = nextValue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, [value]);
|
|
37
|
+
|
|
38
|
+
const getEventValue = (event: React.ChangeEvent<HTMLTextAreaElement> | React.CompositionEvent<HTMLTextAreaElement>) =>
|
|
39
|
+
event.currentTarget.value;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Input.TextArea
|
|
43
|
+
{...rest}
|
|
44
|
+
ref={textAreaRef}
|
|
45
|
+
defaultValue={defaultValue}
|
|
46
|
+
onChange={(event) => {
|
|
47
|
+
previousValueRef.current = getEventValue(event);
|
|
48
|
+
onChange?.(event);
|
|
49
|
+
}}
|
|
50
|
+
onCompositionStart={(event) => {
|
|
51
|
+
previousValueRef.current = getEventValue(event);
|
|
52
|
+
onCompositionStart?.(event);
|
|
53
|
+
}}
|
|
54
|
+
onCompositionEnd={(event) => {
|
|
55
|
+
previousValueRef.current = getEventValue(event);
|
|
56
|
+
onCompositionEnd?.(event);
|
|
57
|
+
}}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
16
62
|
@largeField()
|
|
17
63
|
export class TextareaFieldModel extends FieldModel {
|
|
18
64
|
render() {
|
|
19
|
-
return <
|
|
65
|
+
return <IMESafeTextArea {...this.props} />;
|
|
20
66
|
}
|
|
21
67
|
}
|
|
22
68
|
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
import { FlowEngine } from '@nocobase/flow-engine';
|
|
11
|
+
import { render, screen } from '@testing-library/react';
|
|
12
|
+
import { describe, expect, it } from 'vitest';
|
|
13
|
+
import { DisplayDateTimeFieldModel } from '../DisplayDateTimeFieldModel';
|
|
14
|
+
|
|
15
|
+
describe('DisplayDateTimeFieldModel', () => {
|
|
16
|
+
it('uses dateFormat, showTime, and timeFormat when rendering read pretty datetime text', () => {
|
|
17
|
+
const engine = new FlowEngine();
|
|
18
|
+
engine.registerModels({ DisplayDateTimeFieldModel });
|
|
19
|
+
|
|
20
|
+
const model = engine.createModel<DisplayDateTimeFieldModel>({
|
|
21
|
+
use: DisplayDateTimeFieldModel,
|
|
22
|
+
uid: 'display-datetime-field-format',
|
|
23
|
+
props: {
|
|
24
|
+
value: '2026-06-15 13:05:06',
|
|
25
|
+
dateFormat: 'YYYY-MM-DD',
|
|
26
|
+
showTime: true,
|
|
27
|
+
timeFormat: 'HH:mm:ss',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
render(model.render());
|
|
32
|
+
|
|
33
|
+
expect(screen.getByText('2026-06-15 13:05:06')).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('does not reuse a time-only format when rendering datetime text', () => {
|
|
37
|
+
const engine = new FlowEngine();
|
|
38
|
+
engine.registerModels({ DisplayDateTimeFieldModel });
|
|
39
|
+
|
|
40
|
+
const model = engine.createModel<DisplayDateTimeFieldModel>({
|
|
41
|
+
use: DisplayDateTimeFieldModel,
|
|
42
|
+
uid: 'display-datetime-field-stale-time-format',
|
|
43
|
+
props: {
|
|
44
|
+
value: '2026-06-15 13:05:06',
|
|
45
|
+
format: 'HH:mm:ss',
|
|
46
|
+
showTime: true,
|
|
47
|
+
timeFormat: 'HH:mm:ss',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
render(model.render());
|
|
52
|
+
|
|
53
|
+
expect(screen.getByText('2026-06-15 13:05:06')).toBeInTheDocument();
|
|
54
|
+
expect(screen.queryByText('13:05:06')).not.toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('keeps an existing complete datetime format when no split format props are configured', () => {
|
|
58
|
+
const engine = new FlowEngine();
|
|
59
|
+
engine.registerModels({ DisplayDateTimeFieldModel });
|
|
60
|
+
|
|
61
|
+
const model = engine.createModel<DisplayDateTimeFieldModel>({
|
|
62
|
+
use: DisplayDateTimeFieldModel,
|
|
63
|
+
uid: 'display-datetime-field-complete-format',
|
|
64
|
+
props: {
|
|
65
|
+
value: '2026-06-15 13:05:06',
|
|
66
|
+
format: 'YYYY/MM/DD HH:mm:ss',
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
render(model.render());
|
|
71
|
+
|
|
72
|
+
expect(screen.getByText('2026/06/15 13:05:06')).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('renders only the date for date-only fields even when a datetime format remains', () => {
|
|
76
|
+
const engine = new FlowEngine();
|
|
77
|
+
engine.registerModels({ DisplayDateTimeFieldModel });
|
|
78
|
+
|
|
79
|
+
const model = engine.createModel<DisplayDateTimeFieldModel>({
|
|
80
|
+
use: DisplayDateTimeFieldModel,
|
|
81
|
+
uid: 'display-datetime-field-date-only',
|
|
82
|
+
props: {
|
|
83
|
+
value: '2026-06-15 13:05:06',
|
|
84
|
+
dateOnly: true,
|
|
85
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
86
|
+
showTime: false,
|
|
87
|
+
timeFormat: 'HH:mm:ss',
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
render(model.render());
|
|
92
|
+
|
|
93
|
+
expect(screen.getByText('2026-06-15')).toBeInTheDocument();
|
|
94
|
+
expect(screen.queryByText('2026-06-15 13:05:06')).not.toBeInTheDocument();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { FlowEngine } from '@nocobase/flow-engine';
|
|
11
|
-
import { render, screen } from '@testing-library/react';
|
|
11
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import { describe, expect, it, vi } from 'vitest';
|
|
14
14
|
import { InputFieldModel } from '../InputFieldModel';
|
|
@@ -43,6 +43,122 @@ describe('InputFieldModel', () => {
|
|
|
43
43
|
consoleError.mockRestore();
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
it('keeps IME composition text visible before the parent value is committed', () => {
|
|
47
|
+
const onChange = vi.fn();
|
|
48
|
+
const onCompositionStart = vi.fn();
|
|
49
|
+
const onCompositionEnd = vi.fn();
|
|
50
|
+
const model = createInputFieldModel({
|
|
51
|
+
value: '',
|
|
52
|
+
onChange,
|
|
53
|
+
onCompositionStart,
|
|
54
|
+
onCompositionEnd,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
render(<>{model.render()}</>);
|
|
58
|
+
|
|
59
|
+
const input = screen.getByRole('textbox') as HTMLInputElement;
|
|
60
|
+
|
|
61
|
+
fireEvent.compositionStart(input);
|
|
62
|
+
fireEvent.change(input, { target: { value: 'ni' }, nativeEvent: { isComposing: true } });
|
|
63
|
+
|
|
64
|
+
expect(input.value).toBe('ni');
|
|
65
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
66
|
+
expect(onCompositionStart).toHaveBeenCalledTimes(1);
|
|
67
|
+
|
|
68
|
+
fireEvent.compositionEnd(input, { target: { value: '你' } });
|
|
69
|
+
|
|
70
|
+
expect(input.value).toBe('你');
|
|
71
|
+
expect(onCompositionEnd).toHaveBeenCalledTimes(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('returns to the committed parent value after IME composition is submitted', () => {
|
|
75
|
+
const onChange = vi.fn();
|
|
76
|
+
const onCompositionEnd = vi.fn();
|
|
77
|
+
const createModel = (value: string) =>
|
|
78
|
+
createInputFieldModel({
|
|
79
|
+
value,
|
|
80
|
+
onChange,
|
|
81
|
+
onCompositionEnd,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const { rerender } = render(<>{createModel('').render()}</>);
|
|
85
|
+
const input = screen.getByRole('textbox') as HTMLInputElement;
|
|
86
|
+
|
|
87
|
+
fireEvent.compositionStart(input);
|
|
88
|
+
fireEvent.change(input, { target: { value: 'ni' }, nativeEvent: { isComposing: true } });
|
|
89
|
+
fireEvent.compositionEnd(input, { target: { value: '你' } });
|
|
90
|
+
|
|
91
|
+
expect(input.value).toBe('你');
|
|
92
|
+
|
|
93
|
+
rerender(<>{createModel('你').render()}</>);
|
|
94
|
+
|
|
95
|
+
expect(input.value).toBe('你');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('does not overwrite in-progress DOM input with a stale parent value', async () => {
|
|
99
|
+
const onChange = vi.fn();
|
|
100
|
+
const createModel = (value: string) =>
|
|
101
|
+
createInputFieldModel({
|
|
102
|
+
value,
|
|
103
|
+
onChange,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const { rerender } = render(<>{createModel('').render()}</>);
|
|
107
|
+
const input = screen.getByRole('textbox') as HTMLInputElement;
|
|
108
|
+
|
|
109
|
+
fireEvent.change(input, { target: { value: 'té' } });
|
|
110
|
+
rerender(<>{createModel('').render()}</>);
|
|
111
|
+
|
|
112
|
+
expect(input.value).toBe('té');
|
|
113
|
+
|
|
114
|
+
rerender(<>{createModel('reset').render()}</>);
|
|
115
|
+
|
|
116
|
+
await waitFor(() => {
|
|
117
|
+
expect((screen.getByRole('textbox') as HTMLInputElement).value).toBe('reset');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('keeps replacement-style Vietnamese IME edits in the DOM', () => {
|
|
122
|
+
const onChange = vi.fn();
|
|
123
|
+
const createModel = (value: string) =>
|
|
124
|
+
createInputFieldModel({
|
|
125
|
+
value,
|
|
126
|
+
onChange,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const { rerender } = render(<>{createModel('').render()}</>);
|
|
130
|
+
const input = screen.getByRole('textbox') as HTMLInputElement;
|
|
131
|
+
|
|
132
|
+
fireEvent.change(input, { target: { value: 'te' } });
|
|
133
|
+
rerender(<>{createModel('te').render()}</>);
|
|
134
|
+
expect(input.value).toBe('te');
|
|
135
|
+
|
|
136
|
+
fireEvent.change(input, { target: { value: 'té' } });
|
|
137
|
+
rerender(<>{createModel('te').render()}</>);
|
|
138
|
+
expect(input.value).toBe('té');
|
|
139
|
+
|
|
140
|
+
fireEvent.change(input, { target: { value: 'tét' } });
|
|
141
|
+
rerender(<>{createModel('té').render()}</>);
|
|
142
|
+
expect(input.value).toBe('tét');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('does not overwrite local replacement edit when parent advances to an older value', () => {
|
|
146
|
+
const onChange = vi.fn();
|
|
147
|
+
const createModel = (value: string) =>
|
|
148
|
+
createInputFieldModel({
|
|
149
|
+
value,
|
|
150
|
+
onChange,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const { rerender } = render(<>{createModel('').render()}</>);
|
|
154
|
+
const input = screen.getByRole('textbox') as HTMLInputElement;
|
|
155
|
+
|
|
156
|
+
fireEvent.change(input, { target: { value: 'té' } });
|
|
157
|
+
rerender(<>{createModel('t').render()}</>);
|
|
158
|
+
|
|
159
|
+
expect(input.value).toBe('té');
|
|
160
|
+
});
|
|
161
|
+
|
|
46
162
|
it('renders ScanInput when scan input is enabled', () => {
|
|
47
163
|
const model = createInputFieldModel({ enableScan: true });
|
|
48
164
|
|