mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add ValueParser, use when pasting
Summary: Add ValueParser file, base class, and subclasses for column types. Only NumericParser is used for now. Add valueParser field to ViewFieldRec. Use valueParser when parsing pasted text data in Grid and Detail views. Test Plan: Add test to nbrowser CopyPaste suite, copying into a numeric column with different currency and locale settings. Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3082
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import {ColumnRec, DocModel, IRowModel, refRecord, ViewSectionRec} from 'app/client/models/DocModel';
|
||||
import { ColumnRec, DocModel, IRowModel, refRecord, ViewSectionRec } from 'app/client/models/DocModel';
|
||||
import * as modelUtil from 'app/client/models/modelUtil';
|
||||
import * as UserType from 'app/client/widgets/UserType';
|
||||
import {DocumentSettings} from 'app/common/DocumentSettings';
|
||||
import {BaseFormatter, createFormatter} from 'app/common/ValueFormatter';
|
||||
import {Computed, fromKo} from 'grainjs';
|
||||
import { DocumentSettings } from 'app/common/DocumentSettings';
|
||||
import { BaseFormatter, createFormatter } from 'app/common/ValueFormatter';
|
||||
import { createParser } from 'app/common/ValueParser';
|
||||
import { Computed, fromKo } from 'grainjs';
|
||||
import * as ko from 'knockout';
|
||||
|
||||
// Represents a page entry in the tree of pages.
|
||||
@@ -75,6 +76,8 @@ export interface ViewFieldRec extends IRowModel<"_grist_Views_section_field"> {
|
||||
|
||||
documentSettings: ko.PureComputed<DocumentSettings>;
|
||||
|
||||
valueParser: ko.Computed<((value: string) => any) | undefined>;
|
||||
|
||||
// Helper which adds/removes/updates field's displayCol to match the formula.
|
||||
saveDisplayFormula(formula: string): Promise<void>|undefined;
|
||||
|
||||
@@ -177,6 +180,10 @@ export function createViewFieldRec(this: ViewFieldRec, docModel: DocModel): void
|
||||
createFormatter(this.column().type(), this.widgetOptionsJson(), this.documentSettings());
|
||||
};
|
||||
|
||||
this.valueParser = ko.pureComputed(() =>
|
||||
createParser(this.column().type(), this.widgetOptionsJson(), this.documentSettings())
|
||||
);
|
||||
|
||||
// The widgetOptions to read and write: either the column's or the field's own.
|
||||
this._widgetOptionsStr = modelUtil.savingComputed({
|
||||
read: () => this._fieldOrColumn().widgetOptions(),
|
||||
|
||||
Reference in New Issue
Block a user