mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 13:38:49 +08:00
fix(editor): improve string conversion logic for checkbox property
- Add a FALSE_VALUES set containing various falsy string representations - Support Chinese negation terms like "否", "不", "错", etc. - Optimize the implementation of cellFromString method
This commit is contained in:
@@ -3,17 +3,30 @@ import { propertyType } from '../../core/property/property-config.js';
|
|||||||
|
|
||||||
export const checkboxPropertyType = propertyType('checkbox');
|
export const checkboxPropertyType = propertyType('checkbox');
|
||||||
|
|
||||||
|
const FALSE_VALUES = new Set([
|
||||||
|
'false',
|
||||||
|
'no',
|
||||||
|
'0',
|
||||||
|
'',
|
||||||
|
'undefined',
|
||||||
|
'null',
|
||||||
|
'否',
|
||||||
|
'不',
|
||||||
|
'错',
|
||||||
|
'错误',
|
||||||
|
'取消',
|
||||||
|
'关闭',
|
||||||
|
]);
|
||||||
|
|
||||||
export const checkboxPropertyModelConfig =
|
export const checkboxPropertyModelConfig =
|
||||||
checkboxPropertyType.modelConfig<boolean>({
|
checkboxPropertyType.modelConfig<boolean>({
|
||||||
name: 'Checkbox',
|
name: 'Checkbox',
|
||||||
type: () => t.boolean.instance(),
|
type: () => t.boolean.instance(),
|
||||||
defaultData: () => ({}),
|
defaultData: () => ({}),
|
||||||
cellToString: ({ value }) => (value ? 'True' : 'False'),
|
cellToString: ({ value }) => (value ? 'True' : 'False'),
|
||||||
cellFromString: ({ value }) => {
|
cellFromString: ({ value }) => ({
|
||||||
return {
|
value: !FALSE_VALUES.has((value?.trim() ?? '').toLowerCase()),
|
||||||
value: value !== 'False',
|
}),
|
||||||
};
|
|
||||||
},
|
|
||||||
cellToJson: ({ value }) => value ?? null,
|
cellToJson: ({ value }) => value ?? null,
|
||||||
cellFromJson: ({ value }) =>
|
cellFromJson: ({ value }) =>
|
||||||
typeof value !== 'boolean' ? undefined : value,
|
typeof value !== 'boolean' ? undefined : value,
|
||||||
|
|||||||
Reference in New Issue
Block a user