2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* NewAbstractWidget is equivalent to AbstractWidget for outside code, but is in typescript, and
|
|
|
|
* so is friendlier and clearer to derive TypeScript classes from.
|
|
|
|
*/
|
|
|
|
import {DocComm} from 'app/client/components/DocComm';
|
2022-03-22 13:41:11 +00:00
|
|
|
import {GristDoc} from 'app/client/components/GristDoc';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {DocData} from 'app/client/models/DocData';
|
|
|
|
import {ViewFieldRec} from 'app/client/models/entities/ViewFieldRec';
|
|
|
|
import {SaveableObjObservable} from 'app/client/models/modelUtil';
|
2023-09-21 16:57:58 +00:00
|
|
|
import {theme} from 'app/client/ui2018/cssVars';
|
2022-03-22 13:41:11 +00:00
|
|
|
import {CellStyle} from 'app/client/widgets/CellStyle';
|
2021-12-15 22:31:53 +00:00
|
|
|
import {BaseFormatter} from 'app/common/ValueFormatter';
|
2022-03-22 13:41:11 +00:00
|
|
|
import {
|
|
|
|
Disposable,
|
|
|
|
dom,
|
|
|
|
DomContents,
|
|
|
|
fromKo,
|
(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
|
|
|
IDisposableOwnerT,
|
2022-03-22 13:41:11 +00:00
|
|
|
Observable,
|
|
|
|
} from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-03-02 12:27:08 +00:00
|
|
|
export interface Options {
|
2023-09-21 16:57:58 +00:00
|
|
|
/**
|
|
|
|
* CSS value of the default widget text color. Defaults to the current theme's
|
|
|
|
* cell fg color.
|
|
|
|
*/
|
2021-03-02 12:27:08 +00:00
|
|
|
defaultTextColor?: string;
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* NewAbstractWidget - The base of the inheritance tree for widgets.
|
|
|
|
* @param {Function} field - The RowModel for this view field.
|
|
|
|
*/
|
|
|
|
export abstract class NewAbstractWidget extends Disposable {
|
|
|
|
/**
|
|
|
|
* Override the create() method to match the parameters of create() expected by FieldBuilder.
|
|
|
|
*/
|
(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
|
|
|
// We copy Disposable.create() signature (the second one) to pacify typescript, but code must
|
|
|
|
// use the first signature, which is compatible with old-style constructors.
|
|
|
|
public static create<T extends new (...args: any[]) => any>(field: ViewFieldRec): InstanceType<T>;
|
|
|
|
public static create<T extends new (...args: any[]) => any>(
|
|
|
|
this: T, owner: IDisposableOwnerT<InstanceType<T>>|null, ...args: ConstructorParameters<T>): InstanceType<T>;
|
|
|
|
public static create(...args: any[]) {
|
|
|
|
return Disposable.create.call(this as any, null, ...args);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected options: SaveableObjObservable<any>;
|
|
|
|
protected valueFormatter: Observable<BaseFormatter>;
|
2021-02-09 10:12:53 +00:00
|
|
|
protected textColor: Observable<string>;
|
|
|
|
protected fillColor: Observable<string>;
|
2023-09-21 16:57:58 +00:00
|
|
|
protected readonly defaultTextColor: string|undefined = this._opts.defaultTextColor
|
|
|
|
?? theme.cellFg.toString();
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2023-09-21 16:57:58 +00:00
|
|
|
constructor(protected field: ViewFieldRec, private _opts: Options = {}) {
|
2020-10-02 15:10:00 +00:00
|
|
|
super();
|
|
|
|
this.options = field.widgetOptionsJson;
|
2022-01-13 10:04:56 +00:00
|
|
|
this.valueFormatter = fromKo(field.formatter);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the DOM showing configuration buttons and fields in the sidebar.
|
|
|
|
*/
|
2024-05-29 21:55:21 +00:00
|
|
|
public buildConfigDom(_gristDoc: GristDoc): DomContents {
|
2022-03-22 13:41:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the transform prompt config DOM in the few cases where it is necessary.
|
|
|
|
* Child classes need not override this function if they do not require transform config options.
|
|
|
|
*/
|
2024-05-29 21:55:21 +00:00
|
|
|
public buildTransformConfigDom(_gristDoc: GristDoc): DomContents {
|
2022-03-22 13:41:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2022-03-22 13:41:11 +00:00
|
|
|
public buildColorConfigDom(gristDoc: GristDoc): DomContents {
|
|
|
|
return dom.create(CellStyle, this.field, gristDoc, this.defaultTextColor);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 21:18:09 +00:00
|
|
|
public buildFormConfigDom(): DomContents {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildFormTransformConfigDom(): DomContents {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Builds the data cell DOM.
|
|
|
|
* @param {DataRowModel} row - The rowModel object.
|
|
|
|
*/
|
|
|
|
public abstract buildDom(row: any): Element;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the DocData object to which this field belongs.
|
|
|
|
*/
|
|
|
|
protected _getDocData(): DocData {
|
|
|
|
// TODO: There should be a better way to access docData and docComm, or better yet GristDoc.
|
|
|
|
return this.field._table.tableData.docData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the docComm object for communicating with the server.
|
|
|
|
*/
|
2022-03-22 13:41:11 +00:00
|
|
|
protected _getDocComm(): DocComm {
|
|
|
|
return this._getDocData().docComm;
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|