2020-10-02 15:10:00 +00:00
|
|
|
import { ColumnTransform } from 'app/client/components/ColumnTransform';
|
|
|
|
import { Cursor } from 'app/client/components/Cursor';
|
|
|
|
import { FormulaTransform } from 'app/client/components/FormulaTransform';
|
|
|
|
import { GristDoc } from 'app/client/components/GristDoc';
|
|
|
|
import { addColTypeSuffix } from 'app/client/components/TypeConversion';
|
|
|
|
import { TypeTransform } from 'app/client/components/TypeTransform';
|
2023-06-02 11:25:14 +00:00
|
|
|
import { FloatingEditor } from 'app/client/widgets/FloatingEditor';
|
|
|
|
import { UnsavedChange } from 'app/client/components/UnsavedChanges';
|
2022-07-04 14:14:55 +00:00
|
|
|
import dom from 'app/client/lib/dom';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { KoArray } from 'app/client/lib/koArray';
|
|
|
|
import * as kd from 'app/client/lib/koDom';
|
|
|
|
import * as kf from 'app/client/lib/koForm';
|
|
|
|
import * as koUtil from 'app/client/lib/koUtil';
|
2023-01-11 17:57:42 +00:00
|
|
|
import { makeT } from 'app/client/lib/localization';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { reportError } from 'app/client/models/AppModel';
|
|
|
|
import { DataRowModel } from 'app/client/models/DataRowModel';
|
|
|
|
import { ColumnRec, DocModel, ViewFieldRec } from 'app/client/models/DocModel';
|
|
|
|
import { SaveableObjObservable, setSaveValue } from 'app/client/models/modelUtil';
|
2022-03-22 13:41:11 +00:00
|
|
|
import { CombinedStyle, Style } from 'app/client/models/Styles';
|
2022-10-17 09:47:16 +00:00
|
|
|
import { COMMENTS } from 'app/client/models/features';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { FieldSettingsMenu } from 'app/client/ui/FieldMenus';
|
2022-08-08 13:32:50 +00:00
|
|
|
import { cssBlockedCursor, cssLabel, cssRow } from 'app/client/ui/RightPanelStyles';
|
2022-10-14 10:07:19 +00:00
|
|
|
import { buttonSelect, cssButtonSelect } from 'app/client/ui2018/buttonSelect';
|
2022-09-06 01:51:57 +00:00
|
|
|
import { theme } from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { IOptionFull, menu, select } from 'app/client/ui2018/menus';
|
|
|
|
import { DiffBox } from 'app/client/widgets/DiffBox';
|
|
|
|
import { buildErrorDom } from 'app/client/widgets/ErrorDom';
|
2023-06-02 11:25:14 +00:00
|
|
|
import { FieldEditor, saveWithoutEditor } from 'app/client/widgets/FieldEditor';
|
2022-10-17 09:47:16 +00:00
|
|
|
import { CellDiscussionPopup, EmptyCell } from 'app/client/widgets/DiscussionEditor';
|
2022-03-22 13:41:11 +00:00
|
|
|
import { openFormulaEditor } from 'app/client/widgets/FormulaEditor';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { NewAbstractWidget } from 'app/client/widgets/NewAbstractWidget';
|
2021-06-17 16:41:07 +00:00
|
|
|
import { NewBaseEditor } from "app/client/widgets/NewBaseEditor";
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as UserType from 'app/client/widgets/UserType';
|
|
|
|
import * as UserTypeImpl from 'app/client/widgets/UserTypeImpl';
|
|
|
|
import * as gristTypes from 'app/common/gristTypes';
|
2021-07-23 15:29:35 +00:00
|
|
|
import { getReferencedTableId, isFullReferencingType } from 'app/common/gristTypes';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { CellValue } from 'app/plugin/GristData';
|
2021-05-17 14:05:49 +00:00
|
|
|
import { Computed, Disposable, fromKo, dom as grainjsDom,
|
2023-06-02 11:25:14 +00:00
|
|
|
makeTestId, MultiHolder, Observable, styled, toKo } from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as ko from 'knockout';
|
|
|
|
import * as _ from 'underscore';
|
|
|
|
|
|
|
|
const testId = makeTestId('test-fbuilder-');
|
2023-01-11 17:57:42 +00:00
|
|
|
const t = makeT('FieldBuilder');
|
2022-10-17 09:47:16 +00:00
|
|
|
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Creates a FieldBuilder object for each field in viewFields
|
|
|
|
export function createAllFieldWidgets(gristDoc: GristDoc, viewFields: ko.Computed<KoArray<ViewFieldRec>>,
|
2021-11-19 05:35:01 +00:00
|
|
|
cursor: Cursor, options: { isPreview?: boolean } = {}) {
|
2020-10-02 15:10:00 +00:00
|
|
|
// TODO: Handle disposal from the map when fields are removed.
|
|
|
|
return viewFields().map(function(field) {
|
2021-11-19 05:35:01 +00:00
|
|
|
return new FieldBuilder(gristDoc, field, cursor, options);
|
2020-10-02 15:10:00 +00:00
|
|
|
}).setAutoDisposeValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the appropriate object from UserType.typeDefs, defaulting to Text for unknown types.
|
|
|
|
*/
|
|
|
|
function getTypeDefinition(type: string | false) {
|
|
|
|
if (!type) { return UserType.typeDefs.Text; }
|
|
|
|
return UserType.typeDefs[type] || UserType.typeDefs.Text;
|
|
|
|
}
|
|
|
|
|
2022-04-07 14:58:16 +00:00
|
|
|
type ComputedStyle = {style?: Style; error?: true} | null | undefined;
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
|
2022-04-07 14:58:16 +00:00
|
|
|
/**
|
|
|
|
* Builds a font option computed property.
|
|
|
|
*/
|
|
|
|
function buildFontOptions(
|
|
|
|
builder: FieldBuilder,
|
|
|
|
computedRule: ko.Computed<ComputedStyle>,
|
|
|
|
optionName: keyof Style) {
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
|
|
|
|
return koUtil.withKoUtils(ko.computed(() => {
|
2022-04-07 14:58:16 +00:00
|
|
|
if (builder.isDisposed()) { return false; }
|
|
|
|
const style = computedRule()?.style;
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
const styleFlag = style?.[optionName] || builder.field[optionName]();
|
2022-04-07 14:58:16 +00:00
|
|
|
return styleFlag;
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
})).onlyNotifyUnequal();
|
2022-04-07 14:58:16 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Creates an instance of FieldBuilder. Used to create all column configuration DOMs, cell DOMs,
|
|
|
|
* and cell editor DOMs for all Grist Types.
|
|
|
|
* @param {Object} field - The field for which the DOMs are to be created.
|
|
|
|
* @param {Object} cursor - The cursor object, used to get the cursor position while saving values.
|
|
|
|
*/
|
|
|
|
export class FieldBuilder extends Disposable {
|
|
|
|
public columnTransform: ColumnTransform | null;
|
|
|
|
public readonly origColumn: ColumnRec;
|
|
|
|
public readonly options: SaveableObjObservable<any>;
|
|
|
|
public readonly widget: ko.PureComputed<any>;
|
|
|
|
public readonly isCallPending: ko.Observable<boolean>;
|
|
|
|
public readonly widgetImpl: ko.Computed<NewAbstractWidget>;
|
|
|
|
public readonly diffImpl: NewAbstractWidget;
|
|
|
|
|
2021-05-23 17:43:11 +00:00
|
|
|
private readonly _availableTypes: Computed<Array<IOptionFull<string>>>;
|
|
|
|
private readonly _readOnlyPureType: ko.PureComputed<string>;
|
|
|
|
private readonly _isRightType: ko.PureComputed<(value: CellValue, options?: any) => boolean>;
|
|
|
|
private readonly _refTableId: ko.Computed<string | null>;
|
|
|
|
private readonly _isRef: ko.Computed<boolean>;
|
2020-10-02 15:10:00 +00:00
|
|
|
private readonly _rowMap: Map<DataRowModel, Element>;
|
2021-05-23 17:43:11 +00:00
|
|
|
private readonly _isTransformingFormula: ko.Computed<boolean>;
|
|
|
|
private readonly _isTransformingType: ko.Computed<boolean>;
|
|
|
|
private readonly _widgetCons: ko.Computed<{create: (...args: any[]) => NewAbstractWidget}>;
|
|
|
|
private readonly _docModel: DocModel;
|
2021-06-17 16:41:07 +00:00
|
|
|
private readonly _readonly: Computed<boolean>;
|
2022-10-17 09:47:16 +00:00
|
|
|
private readonly _comments: ko.Computed<boolean>;
|
2022-12-20 02:06:39 +00:00
|
|
|
private readonly _showRefConfigPopup: ko.Observable<boolean>;
|
2023-06-02 11:25:14 +00:00
|
|
|
private readonly _isEditorActive = Observable.create(this, false);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-04-26 21:54:09 +00:00
|
|
|
public constructor(public readonly gristDoc: GristDoc, public readonly field: ViewFieldRec,
|
2021-11-19 05:35:01 +00:00
|
|
|
private _cursor: Cursor, private _options: { isPreview?: boolean } = {}) {
|
2020-10-02 15:10:00 +00:00
|
|
|
super();
|
|
|
|
|
2021-05-23 17:43:11 +00:00
|
|
|
this._docModel = gristDoc.docModel;
|
2023-06-02 11:25:14 +00:00
|
|
|
this.origColumn = field.origCol();
|
2020-10-02 15:10:00 +00:00
|
|
|
this.options = field.widgetOptionsJson;
|
2022-10-17 09:47:16 +00:00
|
|
|
this._comments = ko.pureComputed(() => toKo(ko, COMMENTS())());
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-05-23 17:43:11 +00:00
|
|
|
this._readOnlyPureType = ko.pureComputed(() => this.field.column().pureType());
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-11-19 05:35:01 +00:00
|
|
|
this._readonly = Computed.create(this, (use) =>
|
|
|
|
use(gristDoc.isReadonly) || use(field.disableEditData) || Boolean(this._options.isPreview));
|
2021-06-17 16:41:07 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Observable with a list of available types.
|
2021-05-23 17:43:11 +00:00
|
|
|
this._availableTypes = Computed.create(this, (use) => {
|
2020-10-02 15:10:00 +00:00
|
|
|
const isFormula = use(this.origColumn.isFormula);
|
|
|
|
const types: Array<IOptionFull<string>> = [];
|
|
|
|
_.each(UserType.typeDefs, (def: any, key: string|number) => {
|
|
|
|
const o: IOptionFull<string> = {
|
|
|
|
value: key as string,
|
|
|
|
label: def.label,
|
|
|
|
icon: def.icon
|
|
|
|
};
|
|
|
|
if (key === 'Any') {
|
|
|
|
// User is unable to select the Any type in non-formula columns.
|
|
|
|
o.disabled = !isFormula;
|
|
|
|
}
|
|
|
|
types.push(o);
|
|
|
|
});
|
|
|
|
return types;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Observable which evaluates to a *function* that decides if a value is valid.
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
this._isRightType = ko.pureComputed<(value: CellValue, options?: any) => boolean>(() => {
|
2021-05-23 17:43:11 +00:00
|
|
|
return gristTypes.isRightType(this._readOnlyPureType()) || _.constant(false);
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-07-23 15:29:35 +00:00
|
|
|
// Returns a boolean indicating whether the column is type Reference or ReferenceList.
|
2021-05-23 17:43:11 +00:00
|
|
|
this._isRef = this.autoDispose(ko.computed(() => {
|
2022-04-01 16:00:15 +00:00
|
|
|
const type = this.field.column().type();
|
|
|
|
return type !== "Attachments" && isFullReferencingType(type);
|
2020-10-02 15:10:00 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
// Gives the table ID to which the reference points.
|
2021-05-23 17:43:11 +00:00
|
|
|
this._refTableId = this.autoDispose(ko.computed({
|
2021-07-23 15:29:35 +00:00
|
|
|
read: () => getReferencedTableId(this.field.column().type()),
|
|
|
|
write: val => {
|
|
|
|
const type = this.field.column().type();
|
|
|
|
if (type.startsWith('Ref:')) {
|
|
|
|
void this._setType(`Ref:${val}`);
|
|
|
|
} else {
|
|
|
|
void this._setType(`RefList:${val}`);
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}));
|
|
|
|
|
2022-10-14 10:07:19 +00:00
|
|
|
this.widget = ko.pureComputed(() => this.field.widget());
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Whether there is a pending call that transforms column.
|
|
|
|
this.isCallPending = ko.observable(false);
|
|
|
|
|
|
|
|
// Maintains an instance of the transform object if the field is currently being transformed,
|
|
|
|
// and null if not. Gets disposed along with the transform menu dom.
|
|
|
|
this.columnTransform = null;
|
|
|
|
|
|
|
|
// Returns a boolean indicating whether a formula transform is in progress.
|
2021-05-23 17:43:11 +00:00
|
|
|
this._isTransformingFormula = this.autoDispose(ko.computed(() => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return this.field.column().isTransforming() && this.columnTransform instanceof FormulaTransform;
|
|
|
|
}));
|
|
|
|
// Returns a boolean indicating whether a type transform is in progress.
|
2021-05-23 17:43:11 +00:00
|
|
|
this._isTransformingType = this.autoDispose(ko.computed(() => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return (this.field.column().isTransforming() || this.isCallPending()) &&
|
|
|
|
(this.columnTransform instanceof TypeTransform);
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Map from rowModel to cell dom for the field to which this fieldBuilder applies.
|
|
|
|
this._rowMap = new Map();
|
|
|
|
|
|
|
|
// Returns the constructor for the widget, and only notifies subscribers on changes.
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
this._widgetCons = this.autoDispose(koUtil.withKoUtils(ko.computed(() => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return UserTypeImpl.getWidgetConstructor(this.options().widget,
|
2021-05-23 17:43:11 +00:00
|
|
|
this._readOnlyPureType());
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
})).onlyNotifyUnequal());
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Computed builder for the widget.
|
|
|
|
this.widgetImpl = this.autoDispose(koUtil.computedBuilder(() => {
|
2021-05-23 17:43:11 +00:00
|
|
|
const cons = this._widgetCons();
|
2020-10-02 15:10:00 +00:00
|
|
|
// Must subscribe to `colId` so that field.colId is rechecked on transform.
|
|
|
|
return cons.create.bind(cons, this.field, this.field.colId());
|
|
|
|
}, this).extend({ deferred: true }));
|
|
|
|
|
|
|
|
this.diffImpl = this.autoDispose(DiffBox.create(this.field));
|
2022-12-20 02:06:39 +00:00
|
|
|
|
|
|
|
this._showRefConfigPopup = ko.observable(false);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public buildSelectWidgetDom() {
|
2021-05-23 17:43:11 +00:00
|
|
|
return grainjsDom.maybe((use) => !use(this._isTransformingType) && use(this._readOnlyPureType), type => {
|
2020-10-02 15:10:00 +00:00
|
|
|
const typeWidgets = getTypeDefinition(type).widgets;
|
|
|
|
const widgetOptions = Object.keys(typeWidgets).map(label => ({
|
|
|
|
label,
|
|
|
|
value: label,
|
|
|
|
icon: typeWidgets[label].icon
|
|
|
|
}));
|
2022-10-14 10:07:19 +00:00
|
|
|
if (widgetOptions.length <= 1) { return null; }
|
|
|
|
// Here we need to accommodate the fact that the widget can be null, which
|
|
|
|
// won't be visible on a select component when disabled.
|
|
|
|
const defaultWidget = Computed.create(null, use => {
|
|
|
|
if (widgetOptions.length <= 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const value = use(this.field.config.widget);
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
defaultWidget.onWrite((value) => this.field.config.widget(value));
|
|
|
|
const disabled = Computed.create(null, use => !use(this.field.config.sameWidgets));
|
|
|
|
return [
|
2023-01-11 17:57:42 +00:00
|
|
|
cssLabel(t('CELL FORMAT')),
|
2020-10-02 15:10:00 +00:00
|
|
|
cssRow(
|
2022-10-14 10:07:19 +00:00
|
|
|
grainjsDom.autoDispose(defaultWidget),
|
|
|
|
widgetOptions.length <= 2 ?
|
|
|
|
buttonSelect(
|
|
|
|
fromKo(this.field.config.widget),
|
|
|
|
widgetOptions,
|
|
|
|
cssButtonSelect.cls("-disabled", disabled),
|
|
|
|
) :
|
|
|
|
select(
|
|
|
|
defaultWidget,
|
|
|
|
widgetOptions,
|
|
|
|
{
|
|
|
|
disabled,
|
2023-01-11 17:57:42 +00:00
|
|
|
defaultLabel: t('Mixed format')
|
2022-10-14 10:07:19 +00:00
|
|
|
}
|
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('widget-select')
|
|
|
|
)
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the type change dom.
|
|
|
|
*/
|
|
|
|
public buildSelectTypeDom() {
|
2022-10-14 10:07:19 +00:00
|
|
|
const holder = new MultiHolder();
|
|
|
|
const commonType = Computed.create(holder, use => use(use(this.field.viewSection).columnsType));
|
|
|
|
const selectType = Computed.create(holder, (use) => {
|
|
|
|
const myType = use(fromKo(this._readOnlyPureType));
|
|
|
|
return use(commonType) === 'mixed' ? '' : myType;
|
|
|
|
});
|
|
|
|
selectType.onWrite(newType => {
|
|
|
|
const sameType = newType === this._readOnlyPureType.peek();
|
|
|
|
if (!sameType || commonType.get() === 'mixed') {
|
2022-12-20 02:06:39 +00:00
|
|
|
if (['Ref', 'RefList'].includes(newType)) {
|
|
|
|
this._showRefConfigPopup(true);
|
|
|
|
}
|
2022-10-14 10:07:19 +00:00
|
|
|
return this._setType(newType);
|
|
|
|
}
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
const onDispose = () => (this.isDisposed() || selectType.set(this.field.column().pureType()));
|
2022-10-14 10:07:19 +00:00
|
|
|
const allFormulas = Computed.create(holder, use => use(use(this.field.viewSection).columnsAllIsFormula));
|
2020-10-02 15:10:00 +00:00
|
|
|
return [
|
|
|
|
cssRow(
|
2022-10-14 10:07:19 +00:00
|
|
|
grainjsDom.autoDispose(holder),
|
2021-05-23 17:43:11 +00:00
|
|
|
select(selectType, this._availableTypes, {
|
2022-10-14 10:07:19 +00:00
|
|
|
disabled: (use) =>
|
|
|
|
// If we are transforming column at this moment (applying a formula to change data),
|
|
|
|
use(this._isTransformingFormula) ||
|
|
|
|
// If this is a summary column
|
|
|
|
use(this.origColumn.disableModifyBase) ||
|
|
|
|
// If there are multiple column selected, but all have different type than Any.
|
|
|
|
(use(this.field.config.multiselect) && !use(allFormulas)) ||
|
|
|
|
// If we are waiting for a server response
|
2021-08-12 18:06:40 +00:00
|
|
|
use(this.isCallPending),
|
|
|
|
menuCssClass: cssTypeSelectMenu.className,
|
2023-01-11 17:57:42 +00:00
|
|
|
defaultLabel: t('Mixed types'),
|
2022-12-20 02:06:39 +00:00
|
|
|
renderOptionArgs: (op) => {
|
|
|
|
if (['Ref', 'RefList'].includes(selectType.get())) {
|
|
|
|
// Don't show tip if a reference column type is already selected.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op.label === 'Reference') {
|
2023-01-13 07:39:33 +00:00
|
|
|
return this.gristDoc.behavioralPromptsManager.attachTip('referenceColumns', {
|
2022-12-20 02:06:39 +00:00
|
|
|
popupOptions: {
|
|
|
|
attach: `.${cssTypeSelectMenu.className}`,
|
|
|
|
placement: 'left-start',
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}),
|
2021-07-19 08:49:44 +00:00
|
|
|
testId('type-select'),
|
|
|
|
grainjsDom.cls('tour-type-selector'),
|
2022-10-14 10:07:19 +00:00
|
|
|
grainjsDom.cls(cssBlockedCursor.className, use =>
|
|
|
|
use(this.origColumn.disableModifyBase) ||
|
|
|
|
(use(this.field.config.multiselect) && !use(allFormulas))
|
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
2021-05-23 17:43:11 +00:00
|
|
|
grainjsDom.maybe((use) => use(this._isRef) && !use(this._isTransformingType), () => this._buildRefTableSelect()),
|
|
|
|
grainjsDom.maybe(this._isTransformingType, () => {
|
2020-10-02 15:10:00 +00:00
|
|
|
// Editor dom must be built before preparing transform.
|
|
|
|
return dom('div.type_transform_prompt',
|
|
|
|
kf.prompt(
|
|
|
|
dom('div',
|
2021-05-23 17:43:11 +00:00
|
|
|
grainjsDom.maybe(this._isRef, () => this._buildRefTableSelect()),
|
2020-10-02 15:10:00 +00:00
|
|
|
grainjsDom.maybe((use) => use(this.field.column().isTransforming),
|
|
|
|
() => this.columnTransform!.buildDom())
|
2021-05-23 17:43:11 +00:00
|
|
|
)
|
2020-10-02 15:10:00 +00:00
|
|
|
),
|
|
|
|
grainjsDom.onDispose(onDispose)
|
2021-05-23 17:43:11 +00:00
|
|
|
);
|
2020-10-02 15:10:00 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function to set the column type to newType.
|
|
|
|
public _setType(newType: string): Promise<unknown>|undefined {
|
|
|
|
if (this.origColumn.isFormula()) {
|
|
|
|
// Do not type transform a new/empty column or a formula column. Just make a best guess for
|
2022-10-14 10:07:19 +00:00
|
|
|
// the full type, and set it. If multiple columns are selected (and all are formulas/empty),
|
|
|
|
// then we will set the type for all of them using full type guessed from the first column.
|
2020-10-02 15:10:00 +00:00
|
|
|
const column = this.field.column();
|
2022-10-14 10:07:19 +00:00
|
|
|
const calculatedType = addColTypeSuffix(newType, column, this._docModel);
|
|
|
|
// If we selected multiple empty/formula columns, make the change for all of them.
|
|
|
|
if (this.field.viewSection.peek().selectedFields.peek().length > 1 &&
|
|
|
|
['formula', 'empty'].indexOf(this.field.viewSection.peek().columnsBehavior.peek())) {
|
2023-01-11 17:57:42 +00:00
|
|
|
return this.gristDoc.docData.bundleActions(t("Changing multiple column types"), () =>
|
2022-10-14 10:07:19 +00:00
|
|
|
Promise.all(this.field.viewSection.peek().selectedFields.peek().map(f =>
|
|
|
|
f.column.peek().type.setAndSave(calculatedType)
|
|
|
|
))).catch(reportError);
|
|
|
|
}
|
|
|
|
column.type.setAndSave(calculatedType).catch(reportError);
|
2020-10-02 15:10:00 +00:00
|
|
|
} else if (!this.columnTransform) {
|
|
|
|
this.columnTransform = TypeTransform.create(null, this.gristDoc, this);
|
|
|
|
return this.columnTransform.prepare(newType);
|
|
|
|
} else {
|
|
|
|
if (this.columnTransform instanceof TypeTransform) {
|
|
|
|
return this.columnTransform.setType(newType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Builds the reference type table selector. Built when the column is type reference.
|
|
|
|
public _buildRefTableSelect() {
|
|
|
|
const allTables = Computed.create(null, (use) =>
|
2022-11-17 15:06:53 +00:00
|
|
|
use(this._docModel.visibleTables.getObservable()).map(tableRec => ({
|
|
|
|
value: use(tableRec.tableId),
|
|
|
|
label: use(tableRec.tableNameDef),
|
2020-10-02 15:10:00 +00:00
|
|
|
icon: 'FieldTable' as const
|
|
|
|
}))
|
|
|
|
);
|
2022-10-14 10:07:19 +00:00
|
|
|
const isDisabled = Computed.create(null, use => {
|
|
|
|
return use(this.origColumn.disableModifyBase) || use(this.field.config.multiselect);
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
return [
|
2023-01-11 17:57:42 +00:00
|
|
|
cssLabel(t('DATA FROM TABLE'),
|
2023-01-13 07:39:33 +00:00
|
|
|
!this._showRefConfigPopup.peek() ? null : this.gristDoc.behavioralPromptsManager.attachTip(
|
2022-12-20 02:06:39 +00:00
|
|
|
'referenceColumnsConfig',
|
|
|
|
{
|
|
|
|
onDispose: () => this._showRefConfigPopup(false),
|
|
|
|
popupOptions: {
|
|
|
|
placement: 'left-start',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
),
|
|
|
|
),
|
2020-10-02 15:10:00 +00:00
|
|
|
cssRow(
|
|
|
|
dom.autoDispose(allTables),
|
2022-10-14 10:07:19 +00:00
|
|
|
dom.autoDispose(isDisabled),
|
2021-06-28 19:05:37 +00:00
|
|
|
select(fromKo(this._refTableId), allTables, {
|
|
|
|
// Disallow changing the destination table when the column should not be modified
|
|
|
|
// (specifically when it's a group-by column of a summary table).
|
2022-10-14 10:07:19 +00:00
|
|
|
disabled: isDisabled,
|
2021-06-28 19:05:37 +00:00
|
|
|
}),
|
2020-10-02 15:10:00 +00:00
|
|
|
testId('ref-table-select')
|
|
|
|
)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the formula transform dom
|
|
|
|
*/
|
|
|
|
public buildTransformDom() {
|
|
|
|
const transformButton = ko.computed({
|
|
|
|
read: () => this.field.column().isTransforming(),
|
|
|
|
write: val => {
|
|
|
|
if (val) {
|
|
|
|
this.columnTransform = FormulaTransform.create(null, this.gristDoc, this);
|
|
|
|
return this.columnTransform.prepare();
|
|
|
|
} else {
|
|
|
|
return this.columnTransform && this.columnTransform.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return dom('div',
|
|
|
|
dom.autoDispose(transformButton),
|
|
|
|
dom.onDispose(() => {
|
|
|
|
// When losing focus, if there's an active column transform, finalize it.
|
|
|
|
if (this.columnTransform) {
|
2020-11-09 23:40:43 +00:00
|
|
|
this.columnTransform.finalize().catch(reportError);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
kf.row(
|
2023-01-11 17:57:42 +00:00
|
|
|
15, kf.label(t('Apply Formula to Data')),
|
2020-10-02 15:10:00 +00:00
|
|
|
3, kf.buttonGroup(
|
|
|
|
kf.checkButton(transformButton,
|
|
|
|
dom('span.glyphicon.glyphicon-flash'),
|
|
|
|
dom.testId("FieldBuilder_editTransform"),
|
2023-05-05 09:52:24 +00:00
|
|
|
testId('edit-transform'),
|
2021-05-23 17:43:11 +00:00
|
|
|
kd.toggleClass('disabled', () => this._isTransformingType() || this.origColumn.isFormula() ||
|
2021-03-17 03:45:44 +00:00
|
|
|
this.origColumn.disableModifyBase())
|
2020-10-02 15:10:00 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
2021-05-23 17:43:11 +00:00
|
|
|
kd.maybe(this._isTransformingFormula, () => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return this.columnTransform!.buildDom();
|
|
|
|
})
|
2021-05-23 17:43:11 +00:00
|
|
|
);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the FieldBuilder Options Config DOM. Calls the buildConfigDom function of its widgetImpl.
|
|
|
|
*/
|
|
|
|
public buildConfigDom() {
|
2022-10-14 10:07:19 +00:00
|
|
|
// NOTE: adding a grainjsDom .maybe here causes the disposable order of the widgetImpl and
|
|
|
|
// the dom created by the widgetImpl to get out of sync.
|
|
|
|
return dom('div',
|
|
|
|
kd.maybe(() => !this._isTransformingType() && this.widgetImpl(), (widget: NewAbstractWidget) =>
|
|
|
|
dom('div', widget.buildConfigDom(), cssSeparator())
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildColorConfigDom() {
|
|
|
|
// NOTE: adding a grainjsDom .maybe here causes the disposable order of the widgetImpl and
|
|
|
|
// the dom created by the widgetImpl to get out of sync.
|
|
|
|
return dom('div',
|
|
|
|
kd.maybe(() => !this._isTransformingType() && this.widgetImpl(), (widget: NewAbstractWidget) =>
|
|
|
|
dom('div', widget.buildColorConfigDom(this.gristDoc))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the FieldBuilder Options Config DOM. Calls the buildConfigDom function of its widgetImpl.
|
|
|
|
*/
|
|
|
|
public buildSettingOptions() {
|
2020-10-02 15:10:00 +00:00
|
|
|
// NOTE: adding a grainjsDom .maybe here causes the disposable order of the widgetImpl and
|
|
|
|
// the dom created by the widgetImpl to get out of sync.
|
|
|
|
return dom('div',
|
2021-05-23 17:43:11 +00:00
|
|
|
kd.maybe(() => !this._isTransformingType() && this.widgetImpl(), (widget: NewAbstractWidget) =>
|
2020-10-02 15:10:00 +00:00
|
|
|
dom('div',
|
2022-10-14 10:07:19 +00:00
|
|
|
// If there is more than one field for this column (i.e. present in multiple views).
|
|
|
|
kd.maybe(() => this.origColumn.viewFields().all().length > 1, () =>
|
|
|
|
dom('div.fieldbuilder_settings',
|
|
|
|
kf.row(
|
|
|
|
kd.toggleClass('fieldbuilder_settings_header', true),
|
|
|
|
kf.label(
|
|
|
|
dom('div.fieldbuilder_settings_button',
|
|
|
|
dom.testId('FieldBuilder_settings'),
|
|
|
|
kd.text(() => this.field.useColOptions() ? 'Common' : 'Separate'), ' ▾',
|
|
|
|
menu(() => FieldSettingsMenu(
|
|
|
|
this.field.useColOptions(),
|
|
|
|
this.field.viewSection().isRaw(),
|
|
|
|
{
|
|
|
|
useSeparate: () => this.fieldSettingsUseSeparate(),
|
|
|
|
saveAsCommon: () => this.fieldSettingsSaveAsCommon(),
|
|
|
|
revertToCommon: () => this.fieldSettingsRevertToCommon(),
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
'Field in ',
|
|
|
|
kd.text(() => this.origColumn.viewFields().all().length),
|
|
|
|
' views'
|
|
|
|
)
|
2020-10-02 15:10:00 +00:00
|
|
|
)
|
2022-10-14 10:07:19 +00:00
|
|
|
)
|
|
|
|
)
|
2020-10-02 15:10:00 +00:00
|
|
|
)
|
2022-10-14 10:07:19 +00:00
|
|
|
)
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public fieldSettingsUseSeparate() {
|
|
|
|
return this.gristDoc.docData.bundleActions(
|
2023-01-11 17:57:42 +00:00
|
|
|
t("Use separate field settings for {{colId}}", { colId: this.origColumn.colId() }), () => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return Promise.all([
|
|
|
|
setSaveValue(this.field.widgetOptions, this.field.column().widgetOptions()),
|
|
|
|
setSaveValue(this.field.visibleCol, this.field.column().visibleCol()),
|
|
|
|
this.field.saveDisplayFormula(this.field.column()._displayColModel().formula() || '')
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public fieldSettingsSaveAsCommon() {
|
|
|
|
return this.gristDoc.docData.bundleActions(
|
2023-01-11 17:57:42 +00:00
|
|
|
t("Save field settings for {{colId}} as common", { colId: this.origColumn.colId() }), () => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return Promise.all([
|
|
|
|
setSaveValue(this.field.column().widgetOptions, this.field.widgetOptions()),
|
|
|
|
setSaveValue(this.field.column().visibleCol, this.field.visibleCol()),
|
|
|
|
this.field.column().saveDisplayFormula(this.field._displayColModel().formula() || ''),
|
|
|
|
setSaveValue(this.field.widgetOptions, ''),
|
|
|
|
setSaveValue(this.field.visibleCol, 0),
|
|
|
|
this.field.saveDisplayFormula('')
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public fieldSettingsRevertToCommon() {
|
|
|
|
return this.gristDoc.docData.bundleActions(
|
2023-01-11 17:57:42 +00:00
|
|
|
t("Revert field settings for {{colId}} to common", { colId: this.origColumn.colId() }), () => {
|
2020-10-02 15:10:00 +00:00
|
|
|
return Promise.all([
|
|
|
|
setSaveValue(this.field.widgetOptions, ''),
|
|
|
|
setSaveValue(this.field.visibleCol, 0),
|
|
|
|
this.field.saveDisplayFormula('')
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the cell and editor DOM for the chosen UserType. Calls the buildDom and
|
|
|
|
* buildEditorDom functions of its widgetImpl.
|
|
|
|
*/
|
2022-08-24 11:43:15 +00:00
|
|
|
public buildDomWithCursor(row: DataRowModel, isActive: ko.Computed<boolean>, isSelected: ko.Computed<boolean>) {
|
2022-03-22 13:41:11 +00:00
|
|
|
const computedFlags = koUtil.withKoUtils(ko.pureComputed(() => {
|
|
|
|
return this.field.rulesColsIds().map(colRef => row.cells[colRef]?.() ?? false);
|
|
|
|
}, this).extend({ deferred: true }));
|
|
|
|
// Here we are using computedWithPrevious helper, to return
|
|
|
|
// the previous value of computed rule. When user adds or deletes
|
|
|
|
// rules there is a brief moment that rule is still not evaluated
|
|
|
|
// (rules.length != value.length), in this case return last value
|
|
|
|
// and wait for the update.
|
2022-04-07 14:58:16 +00:00
|
|
|
const computedRule = koUtil.withKoUtils(ko.pureComputed<ComputedStyle>(() => {
|
2022-03-22 13:41:11 +00:00
|
|
|
if (this.isDisposed()) { return null; }
|
2022-04-20 15:57:44 +00:00
|
|
|
// If this is add row or a blank row (not loaded yet with all fields = '')
|
|
|
|
// don't use rules.
|
|
|
|
if (row._isAddRow() || !row.id()) { return null; }
|
2022-03-22 13:41:11 +00:00
|
|
|
const styles: Style[] = this.field.rulesStyles();
|
|
|
|
// Make sure that rules where computed.
|
|
|
|
if (!Array.isArray(styles) || styles.length === 0) { return null; }
|
|
|
|
const flags = computedFlags();
|
|
|
|
// Make extra sure that all rules are up to date.
|
|
|
|
// If not, fallback to the previous value.
|
|
|
|
// We need to make sure that all rules columns are created,
|
|
|
|
// sometimes there are more styles for a brief moment.
|
|
|
|
if (styles.length < flags.length) { return/* undefined */; }
|
|
|
|
// We will combine error information in the same computed value.
|
|
|
|
// If there is an error in rules - return it instead of the style.
|
|
|
|
const error = flags.some(f => !gristTypes.isValidRuleValue(f));
|
|
|
|
if (error) {
|
|
|
|
return { error };
|
|
|
|
}
|
|
|
|
// Combine them into a single style option.
|
|
|
|
return { style : new CombinedStyle(styles, flags) };
|
|
|
|
}, this).extend({ deferred: true })).previousOnUndefined();
|
|
|
|
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
const widgetObs = koUtil.withKoUtils(ko.computed(() => {
|
2020-10-02 15:10:00 +00:00
|
|
|
// TODO: Accessing row values like this doesn't always work (row and field might not be updated
|
|
|
|
// simultaneously).
|
|
|
|
if (this.isDisposed()) { return null; } // Work around JS errors during field removal.
|
|
|
|
const value = row.cells[this.field.colId()];
|
|
|
|
const cell = value && value();
|
2023-06-02 11:25:14 +00:00
|
|
|
if ((value as any) && this._isRightType()(cell, this.options) || row._isAddRow.peek()) {
|
2020-10-02 15:10:00 +00:00
|
|
|
return this.widgetImpl();
|
|
|
|
} else if (gristTypes.isVersions(cell)) {
|
|
|
|
return this.diffImpl;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
}).extend({ deferred: true })).onlyNotifyUnequal();
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2022-10-13 11:55:41 +00:00
|
|
|
const ruleText = koUtil.withKoUtils(ko.computed(() => {
|
2022-03-22 13:41:11 +00:00
|
|
|
if (this.isDisposed()) { return null; }
|
2022-10-13 11:55:41 +00:00
|
|
|
return computedRule()?.style?.textColor || '';
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
})).onlyNotifyUnequal();
|
2022-03-22 13:41:11 +00:00
|
|
|
|
2022-10-13 11:55:41 +00:00
|
|
|
const ruleFill = koUtil.withKoUtils(ko.computed(() => {
|
2022-03-22 13:41:11 +00:00
|
|
|
if (this.isDisposed()) { return null; }
|
2022-12-09 15:12:12 +00:00
|
|
|
return notTransparent(computedRule()?.style?.fillColor || '');
|
(core) Speed up and upgrade build.
Summary:
- Upgrades to build-related packages:
- Upgrade typescript, related libraries and typings.
- Upgrade webpack, eslint; add tsc-watch, node-dev, eslint_d.
- Build organization changes:
- Build webpack from original typescript, transpiling only; with errors still
reported by a background tsc watching process.
- Typescript-related changes:
- Reduce imports of AWS dependencies (very noticeable speedup)
- Avoid auto-loading global @types
- Client code is now built with isolatedModules flag (for safe transpilation)
- Use allowJs to avoid copying JS files manually.
- Linting changes
- Enhance Arcanist ESLintLinter to run before/after commands, and set up to use eslint_d
- Update eslint config, and include .eslintignore to avoid linting generated files.
- Include a bunch of eslint-prompted and eslint-generated fixes
- Add no-unused-expression rule to eslint, and fix a few warnings about it
- Other items:
- Refactor cssInput to avoid circular dependency
- Remove a bit of unused code, libraries, dependencies
Test Plan: No behavior changes, all existing tests pass. There are 30 tests fewer reported because `test_gpath.py` was removed (it's been unused for years)
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: paulfitz
Differential Revision: https://phab.getgrist.com/D3498
2022-06-27 20:09:41 +00:00
|
|
|
})).onlyNotifyUnequal();
|
2022-03-22 13:41:11 +00:00
|
|
|
|
2022-04-07 14:58:16 +00:00
|
|
|
const fontBold = buildFontOptions(this, computedRule, 'fontBold');
|
|
|
|
const fontItalic = buildFontOptions(this, computedRule, 'fontItalic');
|
|
|
|
const fontUnderline = buildFontOptions(this, computedRule, 'fontUnderline');
|
|
|
|
const fontStrikethrough = buildFontOptions(this, computedRule, 'fontStrikethrough');
|
|
|
|
|
2022-03-22 13:41:11 +00:00
|
|
|
const errorInStyle = ko.pureComputed(() => Boolean(computedRule()?.error));
|
2021-06-17 16:41:07 +00:00
|
|
|
|
2022-10-13 11:55:41 +00:00
|
|
|
const cellText = ko.pureComputed(() => this.field.textColor() || '');
|
2022-12-09 15:12:12 +00:00
|
|
|
const cellFill = ko.pureComputed(() => notTransparent(this.field.fillColor() || ''));
|
2022-10-17 09:47:16 +00:00
|
|
|
|
|
|
|
const hasComment = koUtil.withKoUtils(ko.computed(() => {
|
|
|
|
if (this.isDisposed()) { return false; } // Work around JS errors during field removal.
|
|
|
|
if (!this._comments()) { return false; }
|
|
|
|
if (this.gristDoc.isReadonlyKo()) { return false; }
|
|
|
|
const rowId = row.id();
|
|
|
|
const discussion = this.field.column().cells().all()
|
|
|
|
.find(d =>
|
|
|
|
d.rowId() === rowId
|
|
|
|
&& !d.resolved()
|
|
|
|
&& d.type() === gristTypes.CellInfoType.COMMENT
|
|
|
|
&& !d.hidden()
|
|
|
|
&& d.root());
|
|
|
|
return Boolean(discussion);
|
|
|
|
}).extend({ deferred: true })).onlyNotifyUnequal();
|
2022-10-13 11:55:41 +00:00
|
|
|
|
2022-10-17 09:47:16 +00:00
|
|
|
const domHolder = new MultiHolder();
|
|
|
|
domHolder.autoDispose(hasComment);
|
|
|
|
domHolder.autoDispose(widgetObs);
|
|
|
|
domHolder.autoDispose(computedFlags);
|
|
|
|
domHolder.autoDispose(errorInStyle);
|
|
|
|
domHolder.autoDispose(cellText);
|
|
|
|
domHolder.autoDispose(cellFill);
|
|
|
|
domHolder.autoDispose(computedRule);
|
|
|
|
domHolder.autoDispose(fontBold);
|
|
|
|
domHolder.autoDispose(fontItalic);
|
|
|
|
domHolder.autoDispose(fontUnderline);
|
|
|
|
domHolder.autoDispose(fontStrikethrough);
|
2022-10-13 11:55:41 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
return (elem: Element) => {
|
|
|
|
this._rowMap.set(row, elem);
|
|
|
|
dom(elem,
|
2022-10-17 09:47:16 +00:00
|
|
|
dom.autoDispose(domHolder),
|
2022-10-13 11:55:41 +00:00
|
|
|
kd.style('--grist-cell-color', cellText),
|
2022-10-17 09:47:16 +00:00
|
|
|
kd.style('--grist-cell-background-color', cellFill),
|
2022-10-13 11:55:41 +00:00
|
|
|
kd.style('--grist-rule-color', ruleText),
|
|
|
|
kd.style('--grist-column-rule-background-color', ruleFill),
|
2021-11-19 05:35:01 +00:00
|
|
|
this._options.isPreview ? null : kd.cssClass(this.field.formulaCssClass),
|
2022-10-17 09:47:16 +00:00
|
|
|
kd.toggleClass('field-with-comments', hasComment),
|
|
|
|
kd.maybe(hasComment, () => dom('div.field-comment-indicator')),
|
2021-06-17 16:41:07 +00:00
|
|
|
kd.toggleClass("readonly", toKo(ko, this._readonly)),
|
2020-10-02 15:10:00 +00:00
|
|
|
kd.maybe(isSelected, () => dom('div.selected_cursor',
|
|
|
|
kd.toggleClass('active_cursor', isActive)
|
|
|
|
)),
|
|
|
|
kd.scope(widgetObs, (widget: NewAbstractWidget) => {
|
|
|
|
if (this.isDisposed()) { return null; } // Work around JS errors during field removal.
|
|
|
|
const cellDom = widget ? widget.buildDom(row) : buildErrorDom(row, this.field);
|
2021-02-09 10:12:53 +00:00
|
|
|
return dom(cellDom, kd.toggleClass('has_cursor', isActive),
|
2022-03-22 13:41:11 +00:00
|
|
|
kd.toggleClass('field-error-from-style', errorInStyle),
|
2022-04-07 14:58:16 +00:00
|
|
|
kd.toggleClass('font-bold', fontBold),
|
|
|
|
kd.toggleClass('font-underline', fontUnderline),
|
|
|
|
kd.toggleClass('font-italic', fontItalic),
|
2022-10-13 11:55:41 +00:00
|
|
|
kd.toggleClass('font-strikethrough', fontStrikethrough));
|
2020-10-02 15:10:00 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildEditorDom(editRow: DataRowModel, mainRowModel: DataRowModel, options: {
|
2021-05-17 14:05:49 +00:00
|
|
|
init?: string,
|
|
|
|
state?: any
|
2020-10-02 15:10:00 +00:00
|
|
|
}) {
|
|
|
|
// If the user attempts to edit a value during transform, finalize (i.e. cancel or execute)
|
|
|
|
// the transform.
|
|
|
|
if (this.columnTransform) {
|
2020-11-09 23:40:43 +00:00
|
|
|
this.columnTransform.finalize().catch(reportError);
|
2020-10-02 15:10:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-02 11:25:14 +00:00
|
|
|
// Clear previous editor. Some caveats:
|
|
|
|
// - The floating editor has an async cleanup routine, but it promises that it won't affect as.
|
|
|
|
// - All other editors should be synchronous, so this line will remove all opened editors.
|
|
|
|
const holder = this.gristDoc.fieldEditorHolder;
|
|
|
|
// If the global editor is from our own field, we will dispose it immediately, otherwise we will
|
|
|
|
// rely on the clipboard to dispose it by grabbing focus.
|
|
|
|
const clearOwn = () => this.isEditorActive() && holder.clear();
|
|
|
|
|
2021-06-17 16:41:07 +00:00
|
|
|
// If this is censored value, don't open up the editor, unless it is a formula field.
|
|
|
|
const cell = editRow.cells[this.field.colId()];
|
|
|
|
const value = cell && cell();
|
|
|
|
if (gristTypes.isCensored(value) && !this.origColumn.isFormula.peek()) {
|
2023-06-02 11:25:14 +00:00
|
|
|
return clearOwn();
|
2021-06-17 16:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const editorCtor: typeof NewBaseEditor =
|
|
|
|
UserTypeImpl.getEditorConstructor(this.options().widget, this._readOnlyPureType());
|
2020-10-02 15:10:00 +00:00
|
|
|
// constructor may be null for a read-only non-formula field, though not today.
|
|
|
|
if (!editorCtor) {
|
2023-06-02 11:25:14 +00:00
|
|
|
return clearOwn();
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 16:41:07 +00:00
|
|
|
if (this._readonly.get() && editorCtor.supportsReadonly && !editorCtor.supportsReadonly()) {
|
2023-06-02 11:25:14 +00:00
|
|
|
return clearOwn();
|
2021-06-17 16:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._readonly.get() && saveWithoutEditor(editorCtor, editRow, this.field, options.init)) {
|
2023-06-02 11:25:14 +00:00
|
|
|
return clearOwn();
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const cellElem = this._rowMap.get(mainRowModel)!;
|
|
|
|
|
|
|
|
// The editor may dispose itself; the Holder will know to clear itself in this case.
|
2023-06-02 11:25:14 +00:00
|
|
|
const fieldEditor = FieldEditor.create(holder, {
|
2020-10-02 15:10:00 +00:00
|
|
|
gristDoc: this.gristDoc,
|
|
|
|
field: this.field,
|
|
|
|
cursor: this._cursor,
|
|
|
|
editRow,
|
|
|
|
cellElem,
|
|
|
|
editorCtor,
|
2021-06-17 16:41:07 +00:00
|
|
|
state: options.state,
|
|
|
|
startVal: this._readonly.get() ? undefined : options.init, // don't start with initial value
|
|
|
|
readonly: this._readonly.get() // readonly for editor will not be observable
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
2023-06-02 11:25:14 +00:00
|
|
|
this._isEditorActive.set(true);
|
2021-05-25 09:24:00 +00:00
|
|
|
|
|
|
|
// expose the active editor in a grist doc as an observable
|
2023-06-02 11:25:14 +00:00
|
|
|
fieldEditor.onDispose(() => {
|
|
|
|
this._isEditorActive.set(false);
|
|
|
|
this.gristDoc.activeEditor.set(null);
|
|
|
|
});
|
2021-05-25 09:24:00 +00:00
|
|
|
this.gristDoc.activeEditor.set(fieldEditor);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 09:47:16 +00:00
|
|
|
public buildDiscussionPopup(editRow: DataRowModel, mainRowModel: DataRowModel, discussionId?: number) {
|
|
|
|
const owner = this.gristDoc.fieldEditorHolder;
|
|
|
|
const cellElem: Element = this._rowMap.get(mainRowModel)!;
|
|
|
|
if (this.columnTransform) {
|
|
|
|
this.columnTransform.finalize().catch(reportError);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (editRow._isAddRow.peek() || this._readonly.get()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-06-02 11:25:14 +00:00
|
|
|
const holder = this.gristDoc.fieldEditorHolder;
|
2022-10-17 09:47:16 +00:00
|
|
|
|
|
|
|
const cell = editRow.cells[this.field.colId()];
|
|
|
|
const value = cell && cell();
|
|
|
|
if (gristTypes.isCensored(value)) {
|
2023-06-02 11:25:14 +00:00
|
|
|
holder.clear();
|
2022-10-17 09:47:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tableRef = this.field.viewSection.peek()!.tableRef.peek()!;
|
|
|
|
|
|
|
|
// Reuse fieldEditor holder to make sure only one popup/editor is attached to the cell.
|
|
|
|
const discussionHolder = MultiHolder.create(owner);
|
|
|
|
const discussions = EmptyCell.create(discussionHolder, {
|
|
|
|
gristDoc: this.gristDoc,
|
|
|
|
tableRef,
|
|
|
|
column: this.field.column.peek(),
|
|
|
|
rowId: editRow.id.peek(),
|
|
|
|
});
|
|
|
|
CellDiscussionPopup.create(discussionHolder, {
|
|
|
|
domEl: cellElem,
|
|
|
|
topic: discussions,
|
|
|
|
discussionId,
|
|
|
|
gristDoc: this.gristDoc,
|
|
|
|
closeClicked: () => owner.clear()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
public isEditorActive() {
|
2023-06-02 11:25:14 +00:00
|
|
|
const holder = this.gristDoc.fieldEditorHolder;
|
|
|
|
return !holder.isEmpty() && this._isEditorActive.get();
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2021-03-17 03:45:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the formula editor in the side pane. It will be positioned over refElem.
|
|
|
|
*/
|
2021-11-05 10:25:05 +00:00
|
|
|
public openSideFormulaEditor(
|
|
|
|
editRow: DataRowModel,
|
|
|
|
refElem: Element,
|
|
|
|
editValue?: string,
|
2021-11-30 08:59:04 +00:00
|
|
|
onSave?: (column: ColumnRec, formula: string) => Promise<void>,
|
2021-11-05 10:25:05 +00:00
|
|
|
onCancel?: () => void) {
|
2023-06-02 11:25:14 +00:00
|
|
|
// Remember position when the popup was opened.
|
|
|
|
const position = this.gristDoc.cursorPosition.get();
|
|
|
|
|
|
|
|
// Create a controller for the floating editor. It is primarily responsible for moving the editor
|
|
|
|
// dom from the place where it was rendered to the popup (and moving it back).
|
|
|
|
const floatController = {
|
|
|
|
attach: async (content: HTMLElement) => {
|
|
|
|
// If we haven't change page and the element is still in the DOM, move the editor to the
|
|
|
|
// back to where it was rendered. It still has it's content, so no need to dispose it.
|
|
|
|
if (refElem.isConnected) {
|
|
|
|
formulaEditor.attach(refElem);
|
|
|
|
} else {
|
|
|
|
// Else, we will navigate to the position we left off, dispose the editor and the content.
|
|
|
|
formulaEditor.dispose();
|
|
|
|
grainjsDom.domDispose(content);
|
|
|
|
await this.gristDoc.recursiveMoveToCursorPos(position!, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
detach() {
|
|
|
|
return formulaEditor.detach();
|
|
|
|
},
|
|
|
|
autoDispose(el: Disposable) {
|
|
|
|
return formulaEditor.autoDispose(el);
|
|
|
|
},
|
|
|
|
dispose() {
|
|
|
|
formulaEditor.dispose();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a custom cleanup method, that won't destroy us when we loose focus while being detached.
|
|
|
|
function setupEditorCleanup(
|
|
|
|
owner: MultiHolder, gristDoc: GristDoc,
|
|
|
|
editingFormula: ko.Computed<boolean>, _saveEdit: () => Promise<unknown>
|
|
|
|
) {
|
|
|
|
// Just override the behavior on focus lost.
|
|
|
|
const saveOnFocus = () => floatingExtension.active.get() ? void 0 : _saveEdit().catch(reportError);
|
|
|
|
UnsavedChange.create(owner, async () => { await saveOnFocus(); });
|
|
|
|
gristDoc.app.on('clipboard_focus', saveOnFocus);
|
|
|
|
owner.onDispose(() => {
|
|
|
|
gristDoc.app.off('clipboard_focus', saveOnFocus);
|
|
|
|
editingFormula(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the field model from metatables, as the one provided by the caller might be some floating one, that
|
|
|
|
// will change when user navigates around.
|
|
|
|
const field = this.gristDoc.docModel.viewFields.getRowModel(this.field.getRowId());
|
|
|
|
|
|
|
|
// Finally create the editor passing only the field, which will enable detachable flavor of formula editor.
|
|
|
|
const formulaEditor = openFormulaEditor({
|
2021-03-17 03:45:44 +00:00
|
|
|
gristDoc: this.gristDoc,
|
2023-06-02 11:25:14 +00:00
|
|
|
field,
|
2022-08-08 13:32:50 +00:00
|
|
|
editingFormula: this.field.editingFormula,
|
2021-11-09 20:03:12 +00:00
|
|
|
setupCleanup: setupEditorCleanup,
|
2021-03-17 03:45:44 +00:00
|
|
|
editRow,
|
|
|
|
refElem,
|
2021-11-05 10:25:05 +00:00
|
|
|
editValue,
|
2023-06-02 11:25:14 +00:00
|
|
|
canDetach: true,
|
2021-11-05 10:25:05 +00:00
|
|
|
onSave,
|
|
|
|
onCancel
|
2021-03-17 03:45:44 +00:00
|
|
|
});
|
2023-06-02 11:25:14 +00:00
|
|
|
|
|
|
|
// And now create the floating editor itself. It is just a floating wrapper that will grab the dom
|
|
|
|
// from the editor and show it in the popup. It also overrides various parts of Grist to make smoother experience.
|
|
|
|
const floatingExtension = FloatingEditor.create(formulaEditor, floatController, this.gristDoc);
|
|
|
|
|
2021-11-05 10:25:05 +00:00
|
|
|
// Add editor to document holder - this will prevent multiple formula editor instances.
|
2023-06-02 11:25:14 +00:00
|
|
|
this.gristDoc.fieldEditorHolder.autoDispose(formulaEditor);
|
2021-03-17 03:45:44 +00:00
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2021-08-12 18:06:40 +00:00
|
|
|
|
|
|
|
const cssTypeSelectMenu = styled('div', `
|
|
|
|
max-height: 500px;
|
|
|
|
`);
|
2022-03-22 13:41:11 +00:00
|
|
|
|
|
|
|
const cssSeparator = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
border-bottom: 1px solid ${theme.pagePanelsBorder};
|
2022-03-22 13:41:11 +00:00
|
|
|
margin-top: 16px;
|
|
|
|
`);
|
2022-12-09 15:12:12 +00:00
|
|
|
|
|
|
|
// Simple helper that removes transparency from a HEX or rgba color.
|
|
|
|
// User can set a transparent fill color using doc actions, but we don't want to show it well
|
|
|
|
// when a column is frozen.
|
|
|
|
function notTransparent(color: string): string {
|
|
|
|
if (!color) {
|
|
|
|
return color;
|
|
|
|
} else if (color.startsWith('#') && color.length === 9) {
|
|
|
|
return color.substring(0, 7);
|
|
|
|
} else if (color.startsWith('rgba')) {
|
|
|
|
// rgba(255, 255, 255)
|
|
|
|
// rgba(255, 255, 255, 0.5)
|
|
|
|
// rgba(255 255 255 / 0.5)
|
|
|
|
// rgba(255 255 255 / 50%)
|
|
|
|
return color.replace(/^rgba\((\d+)[,\s]+(\d+)[,\s]+(\d+)[/,\s]+([\d.%]+)\)$/i, 'rgb($1, $2, $3)');
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|