2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* GristDoc manages an open Grist document on the client side.
|
|
|
|
*/
|
|
|
|
// tslint:disable:no-console
|
|
|
|
|
2020-12-23 03:18:07 +00:00
|
|
|
import {AccessRules} from 'app/client/aclui/AccessRules';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {ActionLog} from 'app/client/components/ActionLog';
|
2022-07-04 14:14:55 +00:00
|
|
|
import BaseView from 'app/client/components/BaseView';
|
2022-01-17 16:08:43 +00:00
|
|
|
import {isNumericLike, isNumericOnly} from 'app/client/components/ChartView';
|
2022-04-27 17:46:24 +00:00
|
|
|
import {CodeEditorPanel} from 'app/client/components/CodeEditorPanel';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as commands from 'app/client/components/commands';
|
2021-09-20 20:35:14 +00:00
|
|
|
import {CursorMonitor, ViewCursorPos} from "app/client/components/CursorMonitor";
|
2022-06-04 04:12:30 +00:00
|
|
|
import {DocComm} from 'app/client/components/DocComm';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as DocConfigTab from 'app/client/components/DocConfigTab';
|
2021-09-20 20:35:14 +00:00
|
|
|
import {Drafts} from "app/client/components/Drafts";
|
|
|
|
import {EditorMonitor} from "app/client/components/EditorMonitor";
|
2023-10-17 18:14:54 +00:00
|
|
|
import GridView from 'app/client/components/GridView';
|
2023-08-04 12:33:33 +00:00
|
|
|
import {importFromFile, selectAndImport} from 'app/client/components/Importer';
|
2022-08-24 11:43:15 +00:00
|
|
|
import {RawDataPage, RawDataPopup} from 'app/client/components/RawDataPage';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {ActionGroupWithCursorPos, UndoStack} from 'app/client/components/UndoStack';
|
|
|
|
import {ViewLayout} from 'app/client/components/ViewLayout';
|
|
|
|
import {get as getBrowserGlobals} from 'app/client/lib/browserGlobals';
|
|
|
|
import {DocPluginManager} from 'app/client/lib/DocPluginManager';
|
|
|
|
import {ImportSourceElement} from 'app/client/lib/ImportSourceElement';
|
2022-10-28 16:11:08 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {createSessionObs} from 'app/client/lib/sessionObs';
|
2023-11-01 13:54:19 +00:00
|
|
|
import {logTelemetryEvent} from 'app/client/lib/telemetry';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {setTestState} from 'app/client/lib/testState';
|
|
|
|
import {selectFiles} from 'app/client/lib/uploads';
|
2023-06-02 11:25:14 +00:00
|
|
|
import {AppModel, reportError} from 'app/client/models/AppModel';
|
2023-03-07 01:11:43 +00:00
|
|
|
import BaseRowModel from 'app/client/models/BaseRowModel';
|
2022-07-04 14:14:55 +00:00
|
|
|
import DataTableModel from 'app/client/models/DataTableModel';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {DataTableModelWithDiff} from 'app/client/models/DataTableModelWithDiff';
|
|
|
|
import {DocData} from 'app/client/models/DocData';
|
2023-03-07 01:11:43 +00:00
|
|
|
import {DocInfoRec, DocModel, ViewFieldRec, ViewRec, ViewSectionRec} from 'app/client/models/DocModel';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {DocPageModel} from 'app/client/models/DocPageModel';
|
|
|
|
import {UserError} from 'app/client/models/errors';
|
2023-03-27 17:25:25 +00:00
|
|
|
import {getMainOrgUrl, urlState} from 'app/client/models/gristUrlState';
|
2021-09-20 20:35:14 +00:00
|
|
|
import {getFilterFunc, QuerySetManager} from 'app/client/models/QuerySet';
|
2022-03-21 03:41:59 +00:00
|
|
|
import {getUserOrgPrefObs, getUserOrgPrefsObs, markAsSeen} from 'app/client/models/UserPrefs';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {App} from 'app/client/ui/App';
|
|
|
|
import {DocHistory} from 'app/client/ui/DocHistory';
|
2021-09-20 20:35:14 +00:00
|
|
|
import {startDocTour} from "app/client/ui/DocTour";
|
2023-03-22 13:48:50 +00:00
|
|
|
import {DocTutorial} from 'app/client/ui/DocTutorial';
|
2023-07-18 07:24:10 +00:00
|
|
|
import {DocSettingsPage} from 'app/client/ui/DocumentSettings';
|
2022-03-21 03:41:59 +00:00
|
|
|
import {isTourActive} from "app/client/ui/OnBoardingPopups";
|
2020-10-02 15:10:00 +00:00
|
|
|
import {IPageWidget, toPageWidget} from 'app/client/ui/PageWidgetPicker';
|
2022-07-18 11:39:58 +00:00
|
|
|
import {linkFromId, selectBy} from 'app/client/ui/selectBy';
|
2023-05-08 22:06:24 +00:00
|
|
|
import {WebhookPage} from 'app/client/ui/WebhookPage';
|
2023-04-17 15:12:30 +00:00
|
|
|
import {startWelcomeTour} from 'app/client/ui/WelcomeTour';
|
2023-03-27 17:25:25 +00:00
|
|
|
import {PlayerState, YouTubePlayer} from 'app/client/ui/YouTubePlayer';
|
|
|
|
import {isNarrowScreen, mediaSmall, mediaXSmall, testId, theme} from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {IconName} from 'app/client/ui2018/IconList';
|
2023-03-27 17:25:25 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
2022-07-18 11:39:58 +00:00
|
|
|
import {invokePrompt} from 'app/client/ui2018/modals';
|
2022-10-17 09:47:16 +00:00
|
|
|
import {DiscussionPanel} from 'app/client/widgets/DiscussionEditor';
|
2023-07-18 07:24:10 +00:00
|
|
|
import {FieldEditor} from "app/client/widgets/FieldEditor";
|
2021-09-29 13:57:55 +00:00
|
|
|
import {MinimalActionGroup} from 'app/common/ActionGroup';
|
2023-07-19 17:37:22 +00:00
|
|
|
import {ClientQuery, FilterColValues} from "app/common/ActiveDocAPI";
|
2023-05-08 22:06:24 +00:00
|
|
|
import {CommDocChatter, CommDocUsage, CommDocUserAction} from 'app/common/CommTypes';
|
2022-07-18 11:39:58 +00:00
|
|
|
import {delay} from 'app/common/delay';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {DisposableWithEvents} from 'app/common/DisposableWithEvents';
|
2022-01-17 16:08:43 +00:00
|
|
|
import {isSchemaAction, UserAction} from 'app/common/DocActions';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {OpenLocalDocResult} from 'app/common/DocListAPI';
|
2022-06-07 14:57:29 +00:00
|
|
|
import {isList, isListType, isRefListType, RecalcWhen} from 'app/common/gristTypes';
|
2023-11-01 13:54:19 +00:00
|
|
|
import {HashLink, IDocPage, isViewDocPage, parseUrlId, SpecialDocPage, ViewDocPage} from 'app/common/gristUrls';
|
2021-09-01 21:07:53 +00:00
|
|
|
import {undef, waitObs} from 'app/common/gutil';
|
2021-08-05 15:12:46 +00:00
|
|
|
import {LocalPlugin} from "app/common/plugin";
|
2020-10-02 15:10:00 +00:00
|
|
|
import {StringUnion} from 'app/common/StringUnion';
|
|
|
|
import {TableData} from 'app/common/TableData';
|
2023-10-30 03:21:28 +00:00
|
|
|
import {getGristConfig} from 'app/common/urlUtils';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {DocStateComparison} from 'app/common/UserAPI';
|
2023-10-13 13:01:12 +00:00
|
|
|
import {AttachedCustomWidgets, IAttachedCustomWidget, IWidgetType} from 'app/common/widgetTypes';
|
2023-08-28 09:16:17 +00:00
|
|
|
import {CursorPos} from 'app/plugin/GristAPI';
|
2022-07-18 11:39:58 +00:00
|
|
|
import {
|
|
|
|
bundleChanges,
|
|
|
|
Computed,
|
|
|
|
dom,
|
2022-10-17 09:47:16 +00:00
|
|
|
DomContents,
|
2022-07-18 11:39:58 +00:00
|
|
|
Emitter,
|
2022-08-24 11:43:15 +00:00
|
|
|
fromKo,
|
2022-07-18 11:39:58 +00:00
|
|
|
Holder,
|
|
|
|
IDisposable,
|
|
|
|
IDomComponent,
|
2023-03-27 17:25:25 +00:00
|
|
|
keyframes,
|
2022-07-18 11:39:58 +00:00
|
|
|
Observable,
|
|
|
|
styled,
|
|
|
|
subscribe,
|
|
|
|
toKo
|
|
|
|
} from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as ko from 'knockout';
|
|
|
|
import cloneDeepWith = require('lodash/cloneDeepWith');
|
|
|
|
import isEqual = require('lodash/isEqual');
|
|
|
|
|
2023-03-27 17:25:25 +00:00
|
|
|
const RICK_ROLL_YOUTUBE_EMBED_ID = 'dQw4w9WgXcQ';
|
|
|
|
|
2022-12-09 15:46:03 +00:00
|
|
|
const t = makeT('GristDoc');
|
2022-10-28 16:11:08 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
const G = getBrowserGlobals('document', 'window');
|
|
|
|
|
2021-07-22 22:17:55 +00:00
|
|
|
// Re-export some tools to move them from main webpack bundle to the one with GristDoc.
|
2023-01-05 08:11:54 +00:00
|
|
|
export {DocComm, startDocTour};
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
export interface TabContent {
|
|
|
|
showObs?: any;
|
|
|
|
header?: boolean;
|
|
|
|
label?: any;
|
|
|
|
items?: any;
|
|
|
|
buildDom?: any;
|
|
|
|
keywords?: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TabOptions {
|
|
|
|
shortLabel?: string;
|
|
|
|
hideSearchContent?: boolean;
|
|
|
|
showObs?: any;
|
|
|
|
category?: any;
|
|
|
|
}
|
|
|
|
|
2022-10-17 09:47:16 +00:00
|
|
|
const RightPanelTool = StringUnion("none", "docHistory", "validations", "discussion");
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
export interface IExtraTool {
|
|
|
|
icon: IconName;
|
2022-10-17 09:47:16 +00:00
|
|
|
label: DomContents;
|
2023-07-18 07:24:10 +00:00
|
|
|
content: TabContent[] | IDomComponent;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2023-07-18 07:24:10 +00:00
|
|
|
|
2023-01-18 19:33:45 +00:00
|
|
|
interface RawSectionOptions {
|
2022-08-24 11:43:15 +00:00
|
|
|
viewSection: ViewSectionRec;
|
|
|
|
hash: HashLink;
|
|
|
|
close: () => void;
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
export class GristDoc extends DisposableWithEvents {
|
|
|
|
public docModel: DocModel;
|
|
|
|
public viewModel: ViewRec;
|
|
|
|
public activeViewId: Computed<IDocPage>;
|
|
|
|
public currentPageName: Observable<string>;
|
|
|
|
public docData: DocData;
|
|
|
|
public docInfo: DocInfoRec;
|
|
|
|
public docPluginManager: DocPluginManager;
|
|
|
|
public querySetManager: QuerySetManager;
|
2023-07-18 07:24:10 +00:00
|
|
|
public rightPanelTool: Observable<IExtraTool | null>;
|
2020-10-02 15:10:00 +00:00
|
|
|
public isReadonly = this.docPageModel.isReadonly;
|
|
|
|
public isReadonlyKo = toKo(ko, this.isReadonly);
|
2023-07-18 07:24:10 +00:00
|
|
|
public comparison: DocStateComparison | null;
|
2021-05-17 14:05:49 +00:00
|
|
|
// component for keeping track of latest cursor position
|
|
|
|
public cursorMonitor: CursorMonitor;
|
|
|
|
// component for keeping track of a cell that is being edited
|
|
|
|
public editorMonitor: EditorMonitor;
|
2021-05-25 09:24:00 +00:00
|
|
|
// component for keeping track of a cell that is being edited
|
|
|
|
public draftMonitor: Drafts;
|
2021-07-22 09:14:35 +00:00
|
|
|
// will document perform its own navigation (from anchor link)
|
|
|
|
public hasCustomNav: Observable<boolean>;
|
2020-10-02 15:10:00 +00:00
|
|
|
// Emitter triggered when the main doc area is resized.
|
|
|
|
public readonly resizeEmitter = this.autoDispose(new Emitter());
|
|
|
|
|
|
|
|
// This holds a single FieldEditor. When a new FieldEditor is created (on edit), it replaces the
|
|
|
|
// previous one if any. The holder is maintained by GristDoc, so that we are guaranteed at
|
|
|
|
// most one instance of FieldEditor at any time.
|
|
|
|
public readonly fieldEditorHolder = Holder.create(this);
|
2021-05-25 09:24:00 +00:00
|
|
|
// active field editor
|
|
|
|
public readonly activeEditor: Observable<FieldEditor | null> = Observable.create(this, null);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2021-05-17 14:05:49 +00:00
|
|
|
// Holds current view that is currently rendered
|
2021-05-23 17:43:11 +00:00
|
|
|
public currentView: Observable<BaseView | null>;
|
2021-05-17 14:05:49 +00:00
|
|
|
|
|
|
|
// Holds current cursor position with a view id
|
2021-05-23 17:43:11 +00:00
|
|
|
public cursorPosition: Computed<ViewCursorPos | undefined>;
|
2021-05-17 14:05:49 +00:00
|
|
|
|
2022-01-04 00:20:58 +00:00
|
|
|
public readonly userOrgPrefs = getUserOrgPrefsObs(this.docPageModel.appModel);
|
|
|
|
|
2023-01-13 07:39:33 +00:00
|
|
|
public readonly behavioralPromptsManager = this.docPageModel.appModel.behavioralPromptsManager;
|
2023-02-24 11:12:55 +00:00
|
|
|
// One of the section can be expanded (as requested from the Layout), we will
|
|
|
|
// store its id in this variable. NOTE: expanded section looks exactly the same as a section
|
|
|
|
// in the popup. But they are rendered differently, as section in popup is probably an external
|
|
|
|
// section (or raw data section) that is not part of this view. Maximized section is a section
|
|
|
|
// in the view, so there is no need to render it twice, layout just hides all other sections to make
|
|
|
|
// the space.
|
2023-07-18 07:24:10 +00:00
|
|
|
public maximizedSectionId: Observable<number | null> = Observable.create(this, null);
|
2023-02-24 11:12:55 +00:00
|
|
|
// This is id of the section that is currently shown in the popup. Probably this is an external
|
|
|
|
// section, like raw data view, or a section from another view..
|
2023-07-18 07:24:10 +00:00
|
|
|
public externalSectionId: Computed<number | null>;
|
|
|
|
public viewLayout: ViewLayout | null = null;
|
2022-12-20 02:06:39 +00:00
|
|
|
|
2023-03-23 18:22:28 +00:00
|
|
|
// Holder for the popped up formula editor.
|
|
|
|
public readonly formulaPopup = Holder.create(this);
|
|
|
|
|
2023-04-11 05:00:28 +00:00
|
|
|
public readonly currentTheme = this.docPageModel.appModel.currentTheme;
|
|
|
|
|
2023-07-05 15:36:45 +00:00
|
|
|
public get docApi() {
|
|
|
|
return this.docPageModel.appModel.api.getDocAPI(this.docPageModel.currentDocId.get()!);
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
private _actionLog: ActionLog;
|
|
|
|
private _undoStack: UndoStack;
|
2023-07-18 07:24:10 +00:00
|
|
|
private _lastOwnActionGroup: ActionGroupWithCursorPos | null = null;
|
2020-10-02 15:10:00 +00:00
|
|
|
private _rightPanelTabs = new Map<string, TabContent[]>();
|
|
|
|
private _docHistory: DocHistory;
|
2022-10-17 09:47:16 +00:00
|
|
|
private _discussionPanel: DiscussionPanel;
|
2020-10-02 15:10:00 +00:00
|
|
|
private _rightPanelTool = createSessionObs(this, "rightPanelTool", "none", RightPanelTool.guard);
|
2022-01-04 00:20:58 +00:00
|
|
|
private _showGristTour = getUserOrgPrefObs(this.userOrgPrefs, 'showGristTour');
|
2022-03-21 03:41:59 +00:00
|
|
|
private _seenDocTours = getUserOrgPrefObs(this.userOrgPrefs, 'seenDocTours');
|
2023-07-18 07:24:10 +00:00
|
|
|
private _rawSectionOptions: Observable<RawSectionOptions | null> = Observable.create(this, null);
|
|
|
|
private _activeContent: Computed<IDocPage | RawSectionOptions>;
|
2023-03-22 13:48:50 +00:00
|
|
|
private _docTutorialHolder = Holder.create<DocTutorial>(this);
|
2023-03-27 17:25:25 +00:00
|
|
|
private _isRickRowing: Observable<boolean> = Observable.create(this, false);
|
|
|
|
private _showBackgroundVideoPlayer: Observable<boolean> = Observable.create(this, false);
|
|
|
|
private _backgroundVideoPlayerHolder: Holder<YouTubePlayer> = Holder.create(this);
|
2023-03-29 13:45:19 +00:00
|
|
|
private _disableAutoStartingTours: boolean = false;
|
2022-08-24 11:43:15 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
public readonly app: App,
|
2023-06-02 11:25:14 +00:00
|
|
|
public readonly appModel: AppModel,
|
2020-10-02 15:10:00 +00:00
|
|
|
public readonly docComm: DocComm,
|
|
|
|
public readonly docPageModel: DocPageModel,
|
|
|
|
openDocResponse: OpenLocalDocResult,
|
2021-08-05 15:12:46 +00:00
|
|
|
plugins: LocalPlugin[],
|
2020-10-02 15:10:00 +00:00
|
|
|
options: {
|
|
|
|
comparison?: DocStateComparison // initial comparison with another document
|
|
|
|
} = {}
|
|
|
|
) {
|
|
|
|
super();
|
(core) Grace period and delete-only mode when exceeding row limit
Summary:
Builds upon https://phab.getgrist.com/D3328
- Add HomeDB column `Document.gracePeriodStart`
- When the row count moves above the limit, set it to the current date. When it moves below, set it to null.
- Add DataLimitStatus type indicating if the document is approaching the limit, is in a grace period, or is in delete only mode if the grace period started at least 14 days ago. Compute it in ActiveDoc and send it to client when opening.
- Only allow certain user actions when in delete-only mode.
Follow-up tasks related to this diff:
- When DataLimitStatus in the client is non-empty, show a banner to the appropriate users.
- Only send DataLimitStatus to users with the appropriate access. There's no risk landing this now since real users will only see null until free team sites are released.
- Update DataLimitStatus immediately in the client when it changes, e.g. when user actions are applied or the product is changed. Right now it's only sent when the document loads.
- Update row limit, grace period start, and data limit status in ActiveDoc when the product changes, i.e. the user upgrades/downgrades.
- Account for data size when computing data limit status, not just row counts.
See also the tasks mentioned in https://phab.getgrist.com/D3331
Test Plan: Extended FreeTeam nbrowser test, testing the 4 statuses.
Reviewers: georgegevoian
Reviewed By: georgegevoian
Differential Revision: https://phab.getgrist.com/D3331
2022-03-24 12:05:51 +00:00
|
|
|
console.log("RECEIVED DOC RESPONSE", openDocResponse);
|
2020-10-02 15:10:00 +00:00
|
|
|
this.docData = new DocData(this.docComm, openDocResponse.doc);
|
2023-03-22 13:48:50 +00:00
|
|
|
this.docModel = new DocModel(this.docData, this.docPageModel);
|
2020-10-02 15:10:00 +00:00
|
|
|
this.querySetManager = QuerySetManager.create(this, this.docModel, this.docComm);
|
2023-09-19 18:44:22 +00:00
|
|
|
this.docPluginManager = new DocPluginManager({
|
|
|
|
plugins,
|
|
|
|
untrustedContentOrigin: app.topAppModel.getUntrustedContentOrigin(),
|
|
|
|
docComm: this.docComm,
|
|
|
|
clientScope: app.clientScope,
|
|
|
|
theme: this.currentTheme,
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Maintain the MetaRowModel for the global document info, including docId and peers.
|
2021-08-26 16:35:11 +00:00
|
|
|
this.docInfo = this.docModel.docInfoRow;
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
const defaultViewId = this.docInfo.newDefaultViewId;
|
|
|
|
|
|
|
|
// Grainjs observable for current view id, which may be a string such as 'code'.
|
2021-06-10 03:48:39 +00:00
|
|
|
this.activeViewId = Computed.create(this, (use) => {
|
2022-02-10 13:17:46 +00:00
|
|
|
const {docPage} = use(urlState().state);
|
|
|
|
|
|
|
|
// Return most special pages like 'code' and 'acl' as is
|
|
|
|
if (typeof docPage === 'string' && docPage !== 'GristDocTour' && SpecialDocPage.guard(docPage)) {
|
|
|
|
return docPage;
|
2021-07-30 18:05:16 +00:00
|
|
|
}
|
2022-02-10 13:17:46 +00:00
|
|
|
|
|
|
|
// GristDocTour is a special table that is usually hidden from users, but putting /p/GristDocTour
|
|
|
|
// in the URL navigates to it and makes it visible in the list of pages in the sidebar
|
|
|
|
// For GristDocTour, find the view with that name.
|
|
|
|
// Otherwise find the view with the given row ID, because letting a non-existent row ID pass through here is bad.
|
|
|
|
// If no such view exists, return the default view.
|
|
|
|
const viewId = this.docModel.views.tableData.findRow(docPage === 'GristDocTour' ? 'name' : 'id', docPage);
|
|
|
|
return viewId || use(defaultViewId);
|
2021-06-10 03:48:39 +00:00
|
|
|
});
|
2023-01-18 19:33:45 +00:00
|
|
|
this._activeContent = Computed.create(this, use => use(this._rawSectionOptions) ?? use(this.activeViewId));
|
2023-02-24 11:12:55 +00:00
|
|
|
this.externalSectionId = Computed.create(this, use => {
|
|
|
|
const externalContent = use(this._rawSectionOptions);
|
|
|
|
return externalContent ? use(externalContent.viewSection.id) : null;
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
// This viewModel reflects the currently active view, relying on the fact that
|
|
|
|
// createFloatingRowModel() supports an observable rowId for its argument.
|
|
|
|
// Although typings don't reflect it, createFloatingRowModel() accepts non-numeric values,
|
|
|
|
// which yield an empty row, which is why we can cast activeViewId.
|
|
|
|
this.viewModel = this.autoDispose(
|
|
|
|
this.docModel.views.createFloatingRowModel(toKo(ko, this.activeViewId) as ko.Computed<number>));
|
|
|
|
|
2023-01-18 19:33:45 +00:00
|
|
|
// When active section is changed, clear the maximized state.
|
2023-03-22 15:21:53 +00:00
|
|
|
this.autoDispose(this.viewModel.activeSectionId.subscribe((id) => {
|
|
|
|
if (id === this.maximizedSectionId.get()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-24 11:12:55 +00:00
|
|
|
this.maximizedSectionId.set(null);
|
2023-01-18 19:33:45 +00:00
|
|
|
// If we have layout, update it.
|
2023-02-24 11:12:55 +00:00
|
|
|
if (!this.viewLayout?.isDisposed()) {
|
|
|
|
this.viewLayout?.maximized.set(null);
|
2023-01-18 19:33:45 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Grainjs observable reflecting the name of the current document page.
|
|
|
|
this.currentPageName = Computed.create(this, this.activeViewId,
|
|
|
|
(use, docPage) => typeof docPage === 'number' ? use(this.viewModel.name) : docPage);
|
|
|
|
|
|
|
|
// Whenever the active viewModel is deleted, switch to the default view.
|
|
|
|
this.autoDispose(this.viewModel._isDeleted.subscribe((isDeleted) => {
|
|
|
|
if (isDeleted) {
|
|
|
|
// This should not be done synchronously, as that affects the same viewModel that triggered
|
|
|
|
// this callback, and causes some obscure effects on knockout subscriptions.
|
|
|
|
Promise.resolve().then(() => urlState().pushUrl({docPage: undefined})).catch(() => null);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2023-07-18 07:24:10 +00:00
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
// Subscribe to URL state, and navigate to anchor or open a popup if necessary.
|
2020-10-02 15:10:00 +00:00
|
|
|
this.autoDispose(subscribe(urlState().state, async (use, state) => {
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!state.hash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-29 13:45:19 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (state.hash.popup) {
|
|
|
|
await this.openPopup(state.hash);
|
|
|
|
} else {
|
|
|
|
// Navigate to an anchor if one is present in the url hash.
|
|
|
|
const cursorPos = this._getCursorPosFromHash(state.hash);
|
|
|
|
await this.recursiveMoveToCursorPos(cursorPos, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const isTourOrTutorialActive = isTourActive() || this.docModel.isTutorial();
|
|
|
|
if (state.hash.rickRow && !this._isRickRowing.get() && !isTourOrTutorialActive) {
|
|
|
|
YouTubePlayer.create(this._backgroundVideoPlayerHolder, RICK_ROLL_YOUTUBE_EMBED_ID, {
|
|
|
|
height: '100%',
|
|
|
|
width: '100%',
|
|
|
|
origin: getMainOrgUrl(),
|
|
|
|
playerVars: {
|
|
|
|
controls: 0,
|
|
|
|
disablekb: 1,
|
|
|
|
fs: 0,
|
|
|
|
iv_load_policy: 3,
|
|
|
|
modestbranding: 1,
|
|
|
|
},
|
|
|
|
onPlayerStateChange: (_player, event) => {
|
|
|
|
if (event.data === PlayerState.Playing) {
|
|
|
|
this._isRickRowing.set(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}, cssYouTubePlayer.cls(''));
|
|
|
|
this._showBackgroundVideoPlayer.set(true);
|
|
|
|
this._waitForView()
|
|
|
|
.then(() => {
|
|
|
|
const cursor = document.querySelector('.selected_cursor.active_cursor');
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!cursor) {
|
|
|
|
return;
|
|
|
|
}
|
2023-03-29 13:45:19 +00:00
|
|
|
|
|
|
|
this.behavioralPromptsManager.showTip(cursor, 'rickRow', {
|
|
|
|
onDispose: () => this.playRickRollVideo(),
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(reportError);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2023-03-29 13:45:19 +00:00
|
|
|
} catch (e) {
|
|
|
|
reportError(e);
|
|
|
|
} finally {
|
|
|
|
setTimeout(finalizeAnchor, 0);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2023-03-29 19:52:04 +00:00
|
|
|
if (this.docModel.isTutorial()) {
|
|
|
|
this.behavioralPromptsManager.disable();
|
|
|
|
}
|
|
|
|
|
2023-03-22 13:48:50 +00:00
|
|
|
let isStartingTourOrTutorial = false;
|
2021-07-19 08:49:44 +00:00
|
|
|
this.autoDispose(subscribe(urlState().state, async (_use, state) => {
|
2023-03-22 13:48:50 +00:00
|
|
|
// Only start a tour or tutorial when the full interface is showing, i.e. not when in
|
|
|
|
// embedded mode.
|
2023-08-15 17:29:29 +00:00
|
|
|
if (state.params?.style === 'singlePage') {
|
2022-03-21 03:41:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-22 13:48:50 +00:00
|
|
|
|
2023-03-29 13:45:19 +00:00
|
|
|
const isTutorial = this.docModel.isTutorial();
|
2023-03-22 13:48:50 +00:00
|
|
|
// Onboarding tours were not designed with mobile support in mind. Disable until fixed.
|
2023-03-29 13:45:19 +00:00
|
|
|
if (isNarrowScreen() && !isTutorial) {
|
2022-08-26 09:51:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-22 13:48:50 +00:00
|
|
|
|
2023-03-29 13:45:19 +00:00
|
|
|
// Onboarding tours can conflict with rick rowing.
|
|
|
|
if (state.hash?.rickRow) {
|
|
|
|
this._disableAutoStartingTours = true;
|
|
|
|
}
|
|
|
|
|
2023-03-22 13:48:50 +00:00
|
|
|
// If we have an active tour or tutorial (or are in the process of starting one), don't start
|
|
|
|
// a new one.
|
|
|
|
const hasActiveTourOrTutorial = isTourActive() || !this._docTutorialHolder.isEmpty();
|
|
|
|
if (isStartingTourOrTutorial || hasActiveTourOrTutorial) {
|
2022-03-21 03:41:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-30 15:16:33 +00:00
|
|
|
|
2023-03-29 13:45:19 +00:00
|
|
|
const shouldStartTutorial = isTutorial;
|
2023-03-22 13:48:50 +00:00
|
|
|
const shouldStartDocTour = state.docTour || this._shouldAutoStartDocTour();
|
|
|
|
const shouldStartWelcomeTour = state.welcomeTour || this._shouldAutoStartWelcomeTour();
|
|
|
|
if (shouldStartTutorial || shouldStartDocTour || shouldStartWelcomeTour) {
|
|
|
|
isStartingTourOrTutorial = true;
|
2022-03-21 03:41:59 +00:00
|
|
|
try {
|
|
|
|
await this._waitForView();
|
2021-07-30 15:16:33 +00:00
|
|
|
|
2022-03-21 03:41:59 +00:00
|
|
|
// Remove any tour-related hash-tags from the URL. So #repeat-welcome-tour and
|
|
|
|
// #repeat-doc-tour are used as triggers, but will immediately disappear.
|
|
|
|
await urlState().pushUrl({welcomeTour: false, docTour: false},
|
|
|
|
{replace: true, avoidReload: true});
|
|
|
|
|
2023-03-22 13:48:50 +00:00
|
|
|
if (shouldStartTutorial) {
|
|
|
|
await DocTutorial.create(this._docTutorialHolder, this).start();
|
|
|
|
} else if (shouldStartDocTour) {
|
|
|
|
const onFinishCB = () => (
|
|
|
|
!this._seenDocTours.get()?.includes(this.docId())
|
|
|
|
&& markAsSeen(this._seenDocTours, this.docId())
|
|
|
|
);
|
2022-03-21 03:41:59 +00:00
|
|
|
await startDocTour(this.docData, this.docComm, onFinishCB);
|
2023-11-01 13:54:19 +00:00
|
|
|
if (this.docPageModel.isTemplate.get()) {
|
|
|
|
const doc = this.docPageModel.currentDoc.get();
|
|
|
|
if (!doc) { return; }
|
|
|
|
|
|
|
|
logTelemetryEvent('openedTemplateTour', {
|
|
|
|
full: {
|
|
|
|
templateId: parseUrlId(doc.urlId || doc.id).trunkId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-03-22 13:48:50 +00:00
|
|
|
} else {
|
|
|
|
startWelcomeTour(() => this._showGristTour.set(false));
|
2022-03-21 03:41:59 +00:00
|
|
|
}
|
|
|
|
} finally {
|
2023-03-22 13:48:50 +00:00
|
|
|
isStartingTourOrTutorial = false;
|
2021-07-23 16:24:17 +00:00
|
|
|
}
|
2021-07-19 08:49:44 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Importer takes a function for creating previews.
|
2023-04-04 07:51:34 +00:00
|
|
|
const createPreview = (vs: ViewSectionRec) => {
|
|
|
|
const preview = GridView.create(this, vs, true);
|
|
|
|
// We need to set the instance to the newly created section. This is important, as
|
|
|
|
// GristDoc is responsible for changing the cursor position not the cursor itself. Final
|
|
|
|
// cursor position is determined by finding active (or visible) section and passing this
|
|
|
|
// command (setCursor) to its instance.
|
|
|
|
vs.viewInstance(preview);
|
|
|
|
preview.autoDisposeCallback(() => vs.viewInstance(null));
|
|
|
|
return preview;
|
|
|
|
};
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
const importSourceElems = ImportSourceElement.fromArray(this.docPluginManager.pluginsList);
|
|
|
|
const importMenuItems = [
|
|
|
|
{
|
2022-12-06 13:40:02 +00:00
|
|
|
label: t("Import from file"),
|
2023-08-04 12:33:33 +00:00
|
|
|
action: () => importFromFile(this, createPreview),
|
2020-10-02 15:10:00 +00:00
|
|
|
},
|
|
|
|
...importSourceElems.map(importSourceElem => ({
|
|
|
|
label: importSourceElem.importSource.label,
|
2023-08-04 12:33:33 +00:00
|
|
|
action: () => selectAndImport(this, importSourceElems, importSourceElem, createPreview)
|
2020-10-02 15:10:00 +00:00
|
|
|
}))
|
|
|
|
];
|
|
|
|
|
|
|
|
// Set the available import sources in the DocPageModel.
|
|
|
|
this.docPageModel.importSources = importMenuItems;
|
|
|
|
|
2023-07-18 07:24:10 +00:00
|
|
|
this._actionLog = this.autoDispose(ActionLog.create({gristDoc: this}));
|
|
|
|
this._undoStack = this.autoDispose(UndoStack.create(openDocResponse.log, {gristDoc: this}));
|
2020-10-02 15:10:00 +00:00
|
|
|
this._docHistory = DocHistory.create(this, this.docPageModel, this._actionLog);
|
2022-10-17 09:47:16 +00:00
|
|
|
this._discussionPanel = DiscussionPanel.create(this, this);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Tap into docData's sendActions method to save the cursor position with every action, so that
|
|
|
|
// undo/redo can jump to the right place.
|
|
|
|
this.autoDispose(this.docData.sendActionsEmitter.addListener(this._onSendActionsStart, this));
|
|
|
|
this.autoDispose(this.docData.sendActionsDoneEmitter.addListener(this._onSendActionsEnd, this));
|
|
|
|
|
|
|
|
/* Command binding */
|
|
|
|
this.autoDispose(commands.createGroup({
|
2023-07-18 07:24:10 +00:00
|
|
|
undo() {
|
|
|
|
this._undoStack.sendUndoAction().catch(reportError);
|
|
|
|
},
|
|
|
|
redo() {
|
|
|
|
this._undoStack.sendRedoAction().catch(reportError);
|
|
|
|
},
|
|
|
|
reloadPlugins() {
|
|
|
|
void this.docComm.reloadPlugins().then(() => G.window.location.reload(false));
|
|
|
|
},
|
2023-03-07 01:11:43 +00:00
|
|
|
|
|
|
|
// Command to be manually triggered on cell selection. Moves the cursor to the selected cell.
|
|
|
|
// This is overridden by the formula editor to insert "$col" variables when clicking cells.
|
2023-06-02 11:25:14 +00:00
|
|
|
setCursor: this.onSetCursorPos.bind(this),
|
2020-10-02 15:10:00 +00:00
|
|
|
}, this, true));
|
|
|
|
|
|
|
|
this.listenTo(app.comm, 'docUserAction', this.onDocUserAction);
|
|
|
|
|
2022-06-06 16:21:26 +00:00
|
|
|
this.listenTo(app.comm, 'docUsage', this.onDocUsageMessage);
|
|
|
|
|
2023-05-08 22:06:24 +00:00
|
|
|
this.listenTo(app.comm, 'docChatter', this.onDocChatter);
|
|
|
|
|
2023-07-18 07:24:10 +00:00
|
|
|
this._handleTriggerQueueOverflowMessage();
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
this.autoDispose(DocConfigTab.create({gristDoc: this}));
|
|
|
|
|
|
|
|
this.rightPanelTool = Computed.create(this, (use) => this._getToolContent(use(this._rightPanelTool)));
|
|
|
|
|
|
|
|
this.comparison = options.comparison || null;
|
|
|
|
|
|
|
|
// We need prevent default here to allow drop events to fire.
|
|
|
|
this.autoDispose(dom.onElem(window, 'dragover', (ev) => ev.preventDefault()));
|
|
|
|
// The default action is to open dragged files as a link, navigating out of the app.
|
|
|
|
this.autoDispose(dom.onElem(window, 'drop', (ev) => ev.preventDefault()));
|
2021-02-04 03:17:17 +00:00
|
|
|
|
|
|
|
// On window resize, trigger the resizeEmitter to update ViewLayout and individual BaseViews.
|
|
|
|
this.autoDispose(dom.onElem(window, 'resize', () => this.resizeEmitter.emit()));
|
2021-05-17 14:05:49 +00:00
|
|
|
|
|
|
|
// create current view observer
|
|
|
|
this.currentView = Observable.create<BaseView | null>(this, null);
|
2021-06-09 15:07:16 +00:00
|
|
|
|
|
|
|
// create computed observable for viewInstance - if it is loaded or not
|
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
// GrainJS will not recalculate section.viewInstance correctly because it will be
|
|
|
|
// modified (updated from null to a correct instance) in the same tick. We need to
|
|
|
|
// switch for a moment to knockout to fix this.
|
|
|
|
const viewInstance = fromKo(this.autoDispose(ko.pureComputed(() => {
|
|
|
|
const viewId = toKo(ko, this.activeViewId)();
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!isViewDocPage(viewId)) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-08-24 11:43:15 +00:00
|
|
|
const section = this.viewModel.activeSection();
|
2023-07-07 08:54:01 +00:00
|
|
|
if (section?.isDisposed()) { return null; }
|
2022-08-24 11:43:15 +00:00
|
|
|
const view = section.viewInstance();
|
|
|
|
return view;
|
|
|
|
})));
|
|
|
|
|
2021-05-17 14:05:49 +00:00
|
|
|
// then listen if the view is present, because we still need to wait for it load properly
|
|
|
|
this.autoDispose(viewInstance.addListener(async (view) => {
|
2022-03-22 12:38:56 +00:00
|
|
|
if (view) {
|
|
|
|
await view.getLoadingDonePromise();
|
|
|
|
}
|
2023-07-18 07:24:10 +00:00
|
|
|
if (view?.isDisposed()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-09 15:07:16 +00:00
|
|
|
// finally set the current view as fully loaded
|
2021-05-17 14:05:49 +00:00
|
|
|
this.currentView.set(view);
|
2021-05-23 17:43:11 +00:00
|
|
|
}));
|
2021-05-17 14:05:49 +00:00
|
|
|
|
|
|
|
// create observable for current cursor position
|
|
|
|
this.cursorPosition = Computed.create<ViewCursorPos | undefined>(this, use => {
|
|
|
|
// get the BaseView
|
2022-08-24 11:43:15 +00:00
|
|
|
const view = use(this.currentView);
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!view) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
const viewId = use(this.activeViewId);
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!isViewDocPage(viewId)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
// read latest position
|
|
|
|
const currentPosition = use(view.cursor.currentPosition);
|
2023-07-18 07:24:10 +00:00
|
|
|
if (currentPosition) {
|
|
|
|
return {...currentPosition, viewId};
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
|
2021-07-22 09:14:35 +00:00
|
|
|
this.hasCustomNav = Computed.create(this, urlState().state, (_, state) => {
|
|
|
|
const hash = state.hash;
|
|
|
|
return !!(hash && (undef(hash.colRef, hash.rowId, hash.sectionId) !== undefined));
|
|
|
|
});
|
|
|
|
|
2021-05-25 09:24:00 +00:00
|
|
|
this.draftMonitor = Drafts.create(this, this);
|
2021-05-17 14:05:49 +00:00
|
|
|
this.cursorMonitor = CursorMonitor.create(this, this);
|
|
|
|
this.editorMonitor = EditorMonitor.create(this, this);
|
2023-04-14 10:09:50 +00:00
|
|
|
|
|
|
|
// When active section is changed to a chart or custom widget, change the tab in the creator
|
|
|
|
// panel to the table.
|
|
|
|
this.autoDispose(this.viewModel.activeSection.subscribe((section) => {
|
2023-07-18 07:24:10 +00:00
|
|
|
if (section.isDisposed() || section._isDeleted.peek()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-04-18 11:43:29 +00:00
|
|
|
if (['chart', 'custom'].includes(section.parentKey.peek())) {
|
2023-04-14 10:09:50 +00:00
|
|
|
commands.allCommands.viewTabFocus.run();
|
|
|
|
}
|
|
|
|
}));
|
2021-05-17 14:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns current document's id
|
|
|
|
*/
|
|
|
|
public docId() {
|
|
|
|
return this.docPageModel.currentDocId.get()!;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 09:47:16 +00:00
|
|
|
// DEPRECATED This is used only for validation, which is not used anymore.
|
2020-10-02 15:10:00 +00:00
|
|
|
public addOptionsTab(label: string, iconElem: any, contentObj: TabContent[], options: TabOptions): IDisposable {
|
|
|
|
this._rightPanelTabs.set(label, contentObj);
|
|
|
|
// Return a do-nothing disposable, to satisfy the previous interface.
|
|
|
|
return {dispose: () => null};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the DOM for this GristDoc.
|
|
|
|
*/
|
|
|
|
public buildDom() {
|
2023-02-24 11:12:55 +00:00
|
|
|
const isMaximized = Computed.create(this, use => use(this.maximizedSectionId) !== null);
|
2023-01-18 19:33:45 +00:00
|
|
|
const isPopup = Computed.create(this, use => {
|
2023-01-05 08:11:54 +00:00
|
|
|
return ['data', 'settings'].includes(use(this.activeViewId) as any) // On Raw data or doc settings pages
|
2023-01-18 19:33:45 +00:00
|
|
|
|| use(isMaximized) // Layout has a maximized section visible
|
|
|
|
|| typeof use(this._activeContent) === 'object'; // We are on show raw data popup
|
|
|
|
});
|
2022-08-24 11:43:15 +00:00
|
|
|
return cssViewContentPane(
|
|
|
|
testId('gristdoc'),
|
2023-01-18 19:33:45 +00:00
|
|
|
cssViewContentPane.cls("-contents", isPopup),
|
2023-03-27 17:25:25 +00:00
|
|
|
dom.maybe(this._isRickRowing, () => cssStopRickRowingButton(
|
|
|
|
cssCloseIcon('CrossBig'),
|
|
|
|
dom.on('click', () => {
|
|
|
|
this._isRickRowing.set(false);
|
|
|
|
this._showBackgroundVideoPlayer.set(false);
|
|
|
|
}),
|
|
|
|
testId('gristdoc-stop-rick-rowing'),
|
|
|
|
)),
|
2022-08-24 11:43:15 +00:00
|
|
|
dom.domComputed(this._activeContent, (content) => {
|
|
|
|
return (
|
|
|
|
content === 'code' ? dom.create(CodeEditorPanel, this) :
|
|
|
|
content === 'acl' ? dom.create(AccessRules, this) :
|
|
|
|
content === 'data' ? dom.create(RawDataPage, this) :
|
2023-01-05 08:11:54 +00:00
|
|
|
content === 'settings' ? dom.create(DocSettingsPage, this) :
|
2023-05-08 22:06:24 +00:00
|
|
|
content === 'webhook' ? dom.create(WebhookPage, this) :
|
2022-08-24 11:43:15 +00:00
|
|
|
content === 'GristDocTour' ? null :
|
2023-01-18 19:33:45 +00:00
|
|
|
(typeof content === 'object') ? dom.create(owner => {
|
2022-08-24 11:43:15 +00:00
|
|
|
// In case user changes a page, close the popup.
|
|
|
|
owner.autoDispose(this.activeViewId.addListener(content.close));
|
|
|
|
// In case the section is removed, close the popup.
|
|
|
|
content.viewSection.autoDispose({dispose: content.close});
|
|
|
|
return dom.create(RawDataPopup, this, content.viewSection, content.close);
|
|
|
|
}) :
|
2023-01-18 19:33:45 +00:00
|
|
|
dom.create((owner) => {
|
2023-02-24 11:12:55 +00:00
|
|
|
this.viewLayout = ViewLayout.create(owner, this, content);
|
|
|
|
this.viewLayout.maximized.addListener(n => this.maximizedSectionId.set(n));
|
|
|
|
owner.onDispose(() => this.viewLayout = null);
|
|
|
|
return this.viewLayout;
|
2023-01-18 19:33:45 +00:00
|
|
|
})
|
2022-08-24 11:43:15 +00:00
|
|
|
);
|
|
|
|
}),
|
2023-03-27 17:25:25 +00:00
|
|
|
dom.maybe(this._showBackgroundVideoPlayer, () => [
|
|
|
|
cssBackgroundVideo(
|
|
|
|
this._backgroundVideoPlayerHolder.get()?.buildDom(),
|
|
|
|
cssBackgroundVideo.cls('-fade-in-and-out', this._isRickRowing),
|
|
|
|
testId('gristdoc-background-video'),
|
|
|
|
),
|
|
|
|
]),
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the given page. Note that links to pages should use <a> elements together with setLinkUrl().
|
|
|
|
public openDocPage(viewId: IDocPage) {
|
|
|
|
return urlState().pushUrl({docPage: viewId});
|
|
|
|
}
|
|
|
|
|
|
|
|
public showTool(tool: typeof RightPanelTool.type): void {
|
|
|
|
this._rightPanelTool.set(tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an object representing the position of the cursor, including the section. It will have
|
|
|
|
* fields { sectionId, rowId, fieldIndex }. Fields may be missing if no section is active.
|
|
|
|
*/
|
|
|
|
public getCursorPos(): CursorPos {
|
2023-07-18 07:24:10 +00:00
|
|
|
const pos = {sectionId: this.viewModel.activeSectionId()};
|
2020-10-02 15:10:00 +00:00
|
|
|
const viewInstance = this.viewModel.activeSection.peek().viewInstance.peek();
|
|
|
|
return Object.assign(pos, viewInstance ? viewInstance.cursor.getCursorPos() : {});
|
|
|
|
}
|
|
|
|
|
2023-07-18 07:24:10 +00:00
|
|
|
public async onSetCursorPos(rowModel: BaseRowModel | undefined, fieldModel?: ViewFieldRec) {
|
2023-06-02 11:25:14 +00:00
|
|
|
return this.setCursorPos({
|
|
|
|
rowIndex: rowModel?._index() || 0,
|
|
|
|
fieldIndex: fieldModel?._index() || 0,
|
|
|
|
sectionId: fieldModel?.viewSection().getRowId(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-07 01:11:43 +00:00
|
|
|
public async setCursorPos(cursorPos: CursorPos) {
|
2023-03-23 15:53:42 +00:00
|
|
|
if (cursorPos.sectionId && cursorPos.sectionId !== this.externalSectionId.get()) {
|
2023-03-07 01:11:43 +00:00
|
|
|
const desiredSection: ViewSectionRec = this.docModel.viewSections.getRowModel(cursorPos.sectionId);
|
2023-07-07 08:54:01 +00:00
|
|
|
// If the section id is 0, the section doesn't exist (can happen during undo/redo), and should
|
|
|
|
// be fixed there. For now ignore it, to not create empty sections or views (peeking a view will create it).
|
|
|
|
if (!desiredSection.id.peek()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-04-04 07:51:34 +00:00
|
|
|
// If this is completely unknown section (without a parent), it is probably an import preview.
|
|
|
|
if (!desiredSection.parentId.peek() && !desiredSection.isRaw.peek()) {
|
|
|
|
const view = desiredSection.viewInstance.peek();
|
|
|
|
// Make sure we have a view instance here - it will prove our assumption that this is
|
|
|
|
// an import preview. Section might also be disconnected during undo/redo.
|
|
|
|
if (view && !view.isDisposed()) {
|
|
|
|
view.setCursorPos(cursorPos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-03-07 01:11:43 +00:00
|
|
|
if (desiredSection.view.peek().getRowId() !== this.activeViewId.get()) {
|
|
|
|
// This may be asynchronous. In other cases, the change is synchronous, and some code
|
|
|
|
// relies on it (doesn't wait for this function to resolve).
|
|
|
|
await this._switchToSectionId(cursorPos.sectionId);
|
|
|
|
} else if (desiredSection !== this.viewModel.activeSection.peek()) {
|
|
|
|
this.viewModel.activeSectionId(cursorPos.sectionId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const viewInstance = this.viewModel.activeSection.peek().viewInstance.peek();
|
|
|
|
viewInstance?.setCursorPos(cursorPos);
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Switch to the view/section and scroll to the record indicated by cursorPos. If cursorPos is
|
|
|
|
* null, then moves to a position best suited for optActionGroup (not yet implemented).
|
|
|
|
*/
|
2021-09-29 13:57:55 +00:00
|
|
|
public async moveToCursorPos(cursorPos?: CursorPos, optActionGroup?: MinimalActionGroup): Promise<void> {
|
2022-04-27 17:46:24 +00:00
|
|
|
if (!cursorPos || !cursorPos.sectionId) {
|
2020-10-02 15:10:00 +00:00
|
|
|
// TODO We could come up with a suitable cursorPos here based on the action itself.
|
|
|
|
// This should only come up if trying to undo/redo after reloading a page (since the cursorPos
|
|
|
|
// associated with the action is only stored in memory of the current JS process).
|
|
|
|
// A function like `getCursorPosForActionGroup(ag)` would also be useful to jump to the best
|
|
|
|
// place from any action in the action log.
|
2022-04-27 17:46:24 +00:00
|
|
|
// When user deletes table from Raw Data view, the section id will be 0 and undoing that
|
|
|
|
// operation will move cursor to the empty section row (with id 0).
|
2020-10-02 15:10:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
try {
|
2023-03-07 01:11:43 +00:00
|
|
|
await this.setCursorPos(cursorPos);
|
2023-07-18 07:24:10 +00:00
|
|
|
} catch (e) {
|
2021-05-17 14:05:49 +00:00
|
|
|
reportError(e);
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process actions received from the server by forwarding them to `docData.receiveAction()` and
|
|
|
|
* pushing them to actionLog.
|
|
|
|
*/
|
2022-06-04 04:12:30 +00:00
|
|
|
public onDocUserAction(message: CommDocUserAction) {
|
2020-10-02 15:10:00 +00:00
|
|
|
console.log("GristDoc.onDocUserAction", message);
|
|
|
|
let schemaUpdated = false;
|
2021-03-01 16:51:30 +00:00
|
|
|
/**
|
|
|
|
* If an operation is applied successfully to a document, and then information about
|
|
|
|
* it is broadcast to clients, and one of those broadcasts has a failure (due to
|
|
|
|
* granular access control, which is client-specific), then that error is logged on
|
|
|
|
* the server and also sent to the client via an `error` field. Under normal operation,
|
|
|
|
* there should be no such errors, but if they do arise it is best to make them as visible
|
|
|
|
* as possible.
|
|
|
|
*/
|
|
|
|
if (message.data.error) {
|
|
|
|
reportError(new Error(message.data.error));
|
|
|
|
return;
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
if (this.docComm.isActionFromThisDoc(message)) {
|
|
|
|
const docActions = message.data.docActions;
|
|
|
|
for (let i = 0, len = docActions.length; i < len; i++) {
|
|
|
|
console.log("GristDoc applying #%d", i, docActions[i]);
|
|
|
|
this.docData.receiveAction(docActions[i]);
|
|
|
|
this.docPluginManager.receiveAction(docActions[i]);
|
|
|
|
|
|
|
|
if (!schemaUpdated && isSchemaAction(docActions[i])) {
|
|
|
|
schemaUpdated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add fromSelf property to actionGroup indicating if it's from the current session.
|
|
|
|
const actionGroup = message.data.actionGroup;
|
|
|
|
actionGroup.fromSelf = message.fromSelf || false;
|
|
|
|
// Push to the actionLog and the undoStack.
|
|
|
|
if (!actionGroup.internal) {
|
|
|
|
this._actionLog.pushAction(actionGroup);
|
|
|
|
this._undoStack.pushAction(actionGroup);
|
|
|
|
if (actionGroup.fromSelf) {
|
|
|
|
this._lastOwnActionGroup = actionGroup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (schemaUpdated) {
|
|
|
|
this.trigger('schemaUpdateAction', docActions);
|
|
|
|
}
|
2022-05-16 17:41:12 +00:00
|
|
|
this.docPageModel.updateCurrentDocUsage(message.data.docUsage);
|
2022-10-21 10:55:01 +00:00
|
|
|
this.trigger('onDocUserAction', docActions);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-08 22:06:24 +00:00
|
|
|
public getUndoStack() {
|
|
|
|
return this._undoStack;
|
|
|
|
}
|
|
|
|
|
2022-06-06 16:21:26 +00:00
|
|
|
/**
|
|
|
|
* Process usage and product received from the server by updating their respective
|
|
|
|
* observables.
|
|
|
|
*/
|
2022-06-04 04:12:30 +00:00
|
|
|
public onDocUsageMessage(message: CommDocUsage) {
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!this.docComm.isActionFromThisDoc(message)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-06-06 16:21:26 +00:00
|
|
|
|
|
|
|
bundleChanges(() => {
|
|
|
|
this.docPageModel.updateCurrentDocUsage(message.data.docUsage);
|
|
|
|
this.docPageModel.currentProduct.set(message.data.product ?? null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-08 22:06:24 +00:00
|
|
|
public onDocChatter(message: CommDocChatter) {
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!this.docComm.isActionFromThisDoc(message) ||
|
|
|
|
!message.data.webhooks) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (message.data.webhooks.type == 'webhookOverflowError') {
|
|
|
|
this.trigger('webhookOverflowError',
|
|
|
|
t('New changes are temporarily suspended. Webhooks queue overflowed.' +
|
|
|
|
' Please check webhooks settings, remove invalid webhooks, and clean the queue.'),);
|
|
|
|
} else {
|
2023-05-08 22:06:24 +00:00
|
|
|
this.trigger('webhooks', message.data.webhooks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
public getTableModel(tableId: string): DataTableModel {
|
2023-10-17 18:14:54 +00:00
|
|
|
return this.docModel.getTableModel(tableId);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get a DataTableModel, possibly wrapped to include diff data if a comparison is
|
|
|
|
// in effect.
|
|
|
|
public getTableModelMaybeWithDiff(tableId: string): DataTableModel {
|
|
|
|
const tableModel = this.getTableModel(tableId);
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!this.comparison?.details) {
|
|
|
|
return tableModel;
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
// TODO: cache wrapped models and share between views.
|
|
|
|
return new DataTableModelWithDiff(tableModel, this.comparison.details);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends an action to create a new empty table and switches to that table's primary view.
|
|
|
|
*/
|
|
|
|
public async addEmptyTable(): Promise<void> {
|
2022-05-04 09:54:30 +00:00
|
|
|
const name = await this._promptForName();
|
2023-07-18 07:24:10 +00:00
|
|
|
if (name === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-04 09:54:30 +00:00
|
|
|
const tableInfo = await this.docData.sendAction(['AddEmptyTable', name || null]);
|
2020-10-02 15:10:00 +00:00
|
|
|
await this.openDocPage(this.docModel.tables.getRowModel(tableInfo.id).primaryViewId());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a view section described by val to the current page.
|
|
|
|
*/
|
|
|
|
public async addWidgetToPage(val: IPageWidget) {
|
|
|
|
const docData = this.docModel.docData;
|
|
|
|
const viewName = this.viewModel.name.peek();
|
2023-07-18 07:24:10 +00:00
|
|
|
let tableId: string | null | undefined;
|
2022-05-04 09:54:30 +00:00
|
|
|
if (val.table === 'New Table') {
|
|
|
|
tableId = await this._promptForName();
|
|
|
|
if (tableId === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
const res = await docData.bundleActions(
|
2022-12-06 13:40:02 +00:00
|
|
|
t("Added new linked section to view {{viewName}}", {viewName}),
|
2022-05-04 09:54:30 +00:00
|
|
|
() => this.addWidgetToPageImpl(val, tableId ?? null)
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// The newly-added section should be given focus.
|
|
|
|
this.viewModel.activeSectionId(res.sectionRef);
|
2022-12-20 02:06:39 +00:00
|
|
|
|
|
|
|
this._maybeShowEditCardLayoutTip(val.type).catch(reportError);
|
2023-09-19 02:48:56 +00:00
|
|
|
|
|
|
|
if (AttachedCustomWidgets.guard(val.type)) {
|
|
|
|
this._handleNewAttachedCustomWidget(val.type).catch(reportError);
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The actual implementation of addWidgetToPage
|
|
|
|
*/
|
2023-07-18 07:24:10 +00:00
|
|
|
public async addWidgetToPageImpl(val: IPageWidget, tableId: string | null = null) {
|
2020-10-02 15:10:00 +00:00
|
|
|
const viewRef = this.activeViewId.get();
|
2022-05-04 09:54:30 +00:00
|
|
|
const tableRef = val.table === 'New Table' ? 0 : val.table;
|
2020-10-02 15:10:00 +00:00
|
|
|
const result = await this.docData.sendAction(
|
2022-05-04 09:54:30 +00:00
|
|
|
['CreateViewSection', tableRef, viewRef, val.type, val.summarize ? val.columns : null, tableId]
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
2022-01-17 16:08:43 +00:00
|
|
|
if (val.type === 'chart') {
|
|
|
|
await this._ensureOneNumericSeries(result.sectionRef);
|
|
|
|
}
|
2022-07-18 11:39:58 +00:00
|
|
|
await this.saveLink(val.link, result.sectionRef);
|
2020-10-02 15:10:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new page (aka: view) with a single view section (aka: page widget) described by `val`.
|
|
|
|
*/
|
|
|
|
public async addNewPage(val: IPageWidget) {
|
|
|
|
if (val.table === 'New Table') {
|
2022-05-04 09:54:30 +00:00
|
|
|
const name = await this._promptForName();
|
2023-07-18 07:24:10 +00:00
|
|
|
if (name === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-04 09:54:30 +00:00
|
|
|
const result = await this.docData.sendAction(['AddEmptyTable', name]);
|
2020-10-02 15:10:00 +00:00
|
|
|
await this.openDocPage(result.views[0].id);
|
|
|
|
} else {
|
2022-01-17 16:08:43 +00:00
|
|
|
let result: any;
|
|
|
|
await this.docData.bundleActions(`Add new page`, async () => {
|
|
|
|
result = await this.docData.sendAction(
|
2022-05-04 09:54:30 +00:00
|
|
|
['CreateViewSection', val.table, 0, val.type, val.summarize ? val.columns : null, null]
|
2022-01-17 16:08:43 +00:00
|
|
|
);
|
|
|
|
if (val.type === 'chart') {
|
|
|
|
await this._ensureOneNumericSeries(result.sectionRef);
|
|
|
|
}
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
await this.openDocPage(result.viewRef);
|
|
|
|
// The newly-added section should be given focus.
|
|
|
|
this.viewModel.activeSectionId(result.sectionRef);
|
2022-12-20 02:06:39 +00:00
|
|
|
|
|
|
|
this._maybeShowEditCardLayoutTip(val.type).catch(reportError);
|
2023-09-19 02:48:56 +00:00
|
|
|
|
|
|
|
if (AttachedCustomWidgets.guard(val.type)) {
|
|
|
|
this._handleNewAttachedCustomWidget(val.type).catch(reportError);
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a dialog to upload one or multiple files as tables and then switches to the first table's
|
|
|
|
* primary view.
|
|
|
|
*/
|
|
|
|
public async uploadNewTable(): Promise<void> {
|
2023-07-18 07:24:10 +00:00
|
|
|
const uploadResult = await selectFiles({
|
|
|
|
docWorkerUrl: this.docComm.docWorkerUrl,
|
|
|
|
multiple: true
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
if (uploadResult) {
|
|
|
|
const dataSource = {uploadId: uploadResult.uploadId, transforms: []};
|
2021-09-15 06:12:34 +00:00
|
|
|
const importResult = await this.docComm.finishImportFiles(dataSource, [], {});
|
2020-10-02 15:10:00 +00:00
|
|
|
const tableId = importResult.tables[0].hiddenTableId;
|
|
|
|
const tableRowModel = this.docModel.dataTables[tableId].tableMetaRow;
|
|
|
|
await this.openDocPage(tableRowModel.primaryViewId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async saveViewSection(section: ViewSectionRec, newVal: IPageWidget) {
|
|
|
|
const docData = this.docModel.docData;
|
|
|
|
const oldVal: IPageWidget = toPageWidget(section);
|
|
|
|
const viewModel = section.view();
|
2022-05-10 15:35:42 +00:00
|
|
|
const colIds = section.viewFields().all().map((f) => f.column().colId());
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
if (isEqual(oldVal, newVal)) {
|
|
|
|
// nothing to be done
|
2022-04-07 10:10:58 +00:00
|
|
|
return section;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
return await this.viewLayout!.freezeUntil(docData.bundleActions(
|
2023-07-18 07:24:10 +00:00
|
|
|
t("Saved linked section {{title}} in view {{name}}", {title: section.title(), name: viewModel.name()}),
|
2020-10-02 15:10:00 +00:00
|
|
|
async () => {
|
|
|
|
|
|
|
|
// if table changes or a table is made a summary table, let's replace the view section by a
|
|
|
|
// new one, and return.
|
|
|
|
if (oldVal.table !== newVal.table || oldVal.summarize !== newVal.summarize) {
|
2022-10-17 21:45:42 +00:00
|
|
|
return await this._replaceViewSection(section, oldVal, newVal);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if type changes, let's save it.
|
|
|
|
if (oldVal.type !== newVal.type) {
|
|
|
|
await section.parentKey.saveOnly(newVal.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if grouped by column changes, let's use the specific user action.
|
|
|
|
if (!isEqual(oldVal.columns, newVal.columns)) {
|
|
|
|
await docData.sendAction(
|
|
|
|
['UpdateSummaryViewSection', section.getRowId(), newVal.columns]
|
|
|
|
);
|
2022-05-10 15:35:42 +00:00
|
|
|
// Charts needs to keep view fields consistent across update.
|
|
|
|
if (newVal.type === 'chart' && oldVal.type === 'chart') {
|
|
|
|
await this.setSectionViewFieldsFromArray(section, colIds);
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update link
|
|
|
|
if (oldVal.link !== newVal.link) {
|
2022-07-18 11:39:58 +00:00
|
|
|
await this.saveLink(newVal.link);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2022-04-07 10:10:58 +00:00
|
|
|
return section;
|
|
|
|
},
|
|
|
|
{nestInActiveBundle: true}
|
2020-10-02 15:10:00 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2022-04-07 10:10:58 +00:00
|
|
|
// Set section's viewFields to be colIds in that order. Omit any colum id that do not belong to
|
|
|
|
// section's table.
|
|
|
|
public async setSectionViewFieldsFromArray(section: ViewSectionRec, colIds: string[]) {
|
|
|
|
|
|
|
|
// remove old view fields
|
|
|
|
await Promise.all(section.viewFields.peek().all().map((viewField) => (
|
|
|
|
this.docModel.viewFields.sendTableAction(['RemoveRecord', viewField.id()])
|
|
|
|
)));
|
|
|
|
|
|
|
|
// create map
|
|
|
|
const mapColIdToColumn = new Map();
|
|
|
|
for (const col of section.table().columns().all()) {
|
|
|
|
mapColIdToColumn.set(col.colId(), col);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If split series and/or x-axis do not exist any more in new table, update options to make them
|
|
|
|
// undefined
|
2022-05-10 15:35:42 +00:00
|
|
|
if (colIds.length) {
|
2022-04-07 10:10:58 +00:00
|
|
|
if (section.optionsObj.prop('multiseries')()) {
|
|
|
|
if (!mapColIdToColumn.has(colIds[0])) {
|
2022-05-10 15:35:42 +00:00
|
|
|
await section.optionsObj.prop('multiseries').saveOnly(false);
|
|
|
|
}
|
|
|
|
if (colIds.length > 1 && !mapColIdToColumn.has(colIds[1])) {
|
2022-04-07 10:10:58 +00:00
|
|
|
await section.optionsObj.prop('isXAxisUndefined').saveOnly(true);
|
|
|
|
}
|
2022-05-10 15:35:42 +00:00
|
|
|
} else if (!mapColIdToColumn.has(colIds[0])) {
|
2022-04-07 10:10:58 +00:00
|
|
|
await section.optionsObj.prop('isXAxisUndefined').saveOnly(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// adds new view fields; ignore colIds that do not exist in new table.
|
|
|
|
await Promise.all(colIds.map((colId, i) => {
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!mapColIdToColumn.has(colId)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-07 10:10:58 +00:00
|
|
|
const colInfo = {
|
|
|
|
parentId: section.id(),
|
|
|
|
colRef: mapColIdToColumn.get(colId).id(),
|
|
|
|
parentPos: i
|
|
|
|
};
|
|
|
|
const action = ['AddRecord', null, colInfo];
|
|
|
|
return this.docModel.viewFields.sendTableAction(action);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-07-18 11:39:58 +00:00
|
|
|
// Save link for a given section, by default the active section.
|
|
|
|
public async saveLink(linkId: string, sectionId?: number) {
|
|
|
|
sectionId = sectionId || this.viewModel.activeSection.peek().getRowId();
|
|
|
|
const link = linkFromId(linkId);
|
|
|
|
if (link.targetColRef) {
|
|
|
|
const targetTable = this.docModel.viewSections.getRowModel(sectionId).table();
|
|
|
|
const targetCol = this.docModel.columns.getRowModel(link.targetColRef);
|
|
|
|
if (targetTable.id() !== targetCol.table().id()) {
|
|
|
|
// targetColRef is actually not a column in the target table.
|
|
|
|
// This should mean that the target table is a summary table (which didn't exist when the
|
|
|
|
// option was selected) and targetColRef is from the source table.
|
|
|
|
// Change it to the corresponding summary table column instead.
|
|
|
|
link.targetColRef = targetTable.columns().all().find(c => c.summarySourceCol() === link.targetColRef)!.id();
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
return this.docData.sendAction(
|
2022-07-18 11:39:58 +00:00
|
|
|
['UpdateRecord', '_grist_Views_section', sectionId, {
|
2020-10-02 15:10:00 +00:00
|
|
|
linkSrcSectionRef: link.srcSectionRef,
|
|
|
|
linkSrcColRef: link.srcColRef,
|
|
|
|
linkTargetColRef: link.targetColRef
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the list of all the valid links to link from one of the sections in the active view to
|
|
|
|
// the page widget 'widget'.
|
|
|
|
public selectBy(widget: IPageWidget) {
|
|
|
|
const viewSections = this.viewModel.viewSections.peek().peek();
|
|
|
|
return selectBy(this.docModel, viewSections, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fork the document if it is in prefork mode.
|
|
|
|
public async forkIfNeeded() {
|
|
|
|
if (this.docPageModel.isPrefork.get()) {
|
|
|
|
await this.docComm.forkAndUpdateUrl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 03:45:44 +00:00
|
|
|
// Turn the given columns into empty columns, losing any data stored in them.
|
2023-07-18 07:24:10 +00:00
|
|
|
public async clearColumns(colRefs: number[], {keepType}: { keepType?: boolean } = {}): Promise<void> {
|
2021-03-17 03:45:44 +00:00
|
|
|
await this.docModel.columns.sendTableAction(
|
|
|
|
['BulkUpdateRecord', colRefs, {
|
|
|
|
isFormula: colRefs.map(f => true),
|
|
|
|
formula: colRefs.map(f => ''),
|
2022-10-28 00:23:18 +00:00
|
|
|
...(keepType ? {} : {
|
|
|
|
type: colRefs.map(f => 'Any'),
|
|
|
|
widgetOptions: colRefs.map(f => ''),
|
|
|
|
visibleCol: colRefs.map(f => null),
|
|
|
|
displayCol: colRefs.map(f => null),
|
|
|
|
rules: colRefs.map(f => null),
|
|
|
|
}),
|
2021-06-29 04:47:59 +00:00
|
|
|
// Set recalc settings to defaults when emptying a column.
|
|
|
|
recalcWhen: colRefs.map(f => RecalcWhen.DEFAULT),
|
|
|
|
recalcDeps: colRefs.map(f => null),
|
2021-03-17 03:45:44 +00:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the given columns to data, saving the calculated values and unsetting the formulas.
|
2023-07-18 07:24:10 +00:00
|
|
|
public async convertIsFormula(colRefs: number[], opts: { toFormula: boolean, noRecalc?: boolean }): Promise<void> {
|
2021-03-17 03:45:44 +00:00
|
|
|
return this.docModel.columns.sendTableAction(
|
|
|
|
['BulkUpdateRecord', colRefs, {
|
2021-06-29 04:47:59 +00:00
|
|
|
isFormula: colRefs.map(f => opts.toFormula),
|
|
|
|
recalcWhen: colRefs.map(f => opts.noRecalc ? RecalcWhen.NEVER : RecalcWhen.DEFAULT),
|
|
|
|
recalcDeps: colRefs.map(f => null),
|
2021-03-17 03:45:44 +00:00
|
|
|
}]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-30 08:59:04 +00:00
|
|
|
// Updates formula for a column.
|
|
|
|
public async updateFormula(colRef: number, formula: string): Promise<void> {
|
|
|
|
return this.docModel.columns.sendTableAction(
|
|
|
|
['UpdateRecord', colRef, {
|
|
|
|
formula,
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:25:05 +00:00
|
|
|
// Convert column to pure formula column.
|
2021-11-30 08:59:04 +00:00
|
|
|
public async convertToFormula(colRef: number, formula: string): Promise<void> {
|
2021-11-05 10:25:05 +00:00
|
|
|
return this.docModel.columns.sendTableAction(
|
2021-11-30 08:59:04 +00:00
|
|
|
['UpdateRecord', colRef, {
|
2021-11-05 10:25:05 +00:00
|
|
|
isFormula: true,
|
|
|
|
formula,
|
|
|
|
recalcWhen: RecalcWhen.DEFAULT,
|
|
|
|
recalcDeps: null,
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert column to data column with a trigger formula
|
2023-10-13 13:01:12 +00:00
|
|
|
public async convertToTrigger(
|
|
|
|
colRefs: number,
|
|
|
|
formula: string,
|
|
|
|
recalcWhen: RecalcWhen = RecalcWhen.DEFAULT ): Promise<void> {
|
2021-11-05 10:25:05 +00:00
|
|
|
return this.docModel.columns.sendTableAction(
|
|
|
|
['UpdateRecord', colRefs, {
|
|
|
|
isFormula: false,
|
|
|
|
formula,
|
2023-10-13 13:01:12 +00:00
|
|
|
recalcWhen: recalcWhen,
|
2021-11-05 10:25:05 +00:00
|
|
|
recalcDeps: null,
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
public getCsvLink() {
|
2022-09-14 18:55:44 +00:00
|
|
|
const params = this._getDocApiDownloadParams();
|
|
|
|
return this.docPageModel.appModel.api.getDocAPI(this.docId()).getDownloadCsvUrl(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getXlsxActiveViewLink() {
|
|
|
|
const params = this._getDocApiDownloadParams();
|
|
|
|
return this.docPageModel.appModel.api.getDocAPI(this.docId()).getDownloadXlsxUrl(params);
|
|
|
|
}
|
|
|
|
|
2021-03-25 23:15:34 +00:00
|
|
|
public hasGranularAccessRules(): boolean {
|
2021-12-07 11:21:16 +00:00
|
|
|
const rulesTable = this.docData.getMetaTable('_grist_ACLRules');
|
2021-03-25 23:15:34 +00:00
|
|
|
// To check if there are rules, ignore the default no-op rule created for an older incarnation
|
|
|
|
// of ACLs. It exists in older documents, and is still created for new ones. We detect it by
|
|
|
|
// the use of the deprecated 'permissions' field, and not the new 'permissionsText' field.
|
|
|
|
return rulesTable.numRecords() > rulesTable.filterRowIds({permissionsText: '', permissions: 63}).length;
|
|
|
|
}
|
|
|
|
|
2021-05-17 14:05:49 +00:00
|
|
|
/**
|
|
|
|
* Move to the desired cursor position. If colRef is supplied, the cursor will be
|
|
|
|
* moved to a field with that colRef. Any linked sections that need their cursors
|
|
|
|
* moved in order to achieve the desired outcome are handled recursively.
|
|
|
|
* If setAsActiveSection is true, the section in cursorPos is set as the current
|
|
|
|
* active section.
|
|
|
|
*/
|
2022-03-22 12:38:56 +00:00
|
|
|
public async recursiveMoveToCursorPos(
|
|
|
|
cursorPos: CursorPos,
|
|
|
|
setAsActiveSection: boolean,
|
2023-09-25 22:48:18 +00:00
|
|
|
silent: boolean = false,
|
|
|
|
visitedSections: number[] = []): Promise<boolean> {
|
2021-05-17 14:05:49 +00:00
|
|
|
try {
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!cursorPos.sectionId) {
|
|
|
|
throw new Error('sectionId required');
|
|
|
|
}
|
|
|
|
if (!cursorPos.rowId) {
|
|
|
|
throw new Error('rowId required');
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
const section = this.docModel.viewSections.getRowModel(cursorPos.sectionId);
|
2022-04-27 17:46:24 +00:00
|
|
|
if (!section.id.peek()) {
|
|
|
|
throw new Error(`Section ${cursorPos.sectionId} does not exist`);
|
|
|
|
}
|
2023-09-25 22:48:18 +00:00
|
|
|
|
|
|
|
if (visitedSections.includes(section.id.peek())) {
|
|
|
|
// We've already been here (we hit a cycle), just return immediately
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-17 14:05:49 +00:00
|
|
|
const srcSection = section.linkSrcSection.peek();
|
|
|
|
if (srcSection.id.peek()) {
|
|
|
|
// We're in a linked section, so we need to recurse to make sure the row we want
|
|
|
|
// will be visible.
|
|
|
|
const linkTargetCol = section.linkTargetCol.peek();
|
|
|
|
let controller: any;
|
|
|
|
if (linkTargetCol.colId.peek()) {
|
|
|
|
const destTable = await this._getTableData(section);
|
|
|
|
controller = destTable.getValue(cursorPos.rowId, linkTargetCol.colId.peek());
|
|
|
|
} else {
|
|
|
|
controller = cursorPos.rowId;
|
|
|
|
}
|
|
|
|
const colId = section.linkSrcCol.peek().colId.peek();
|
|
|
|
let srcRowId: any;
|
|
|
|
const isSrcSummary = srcSection.table.peek().summarySource.peek().id.peek();
|
|
|
|
if (!colId && !isSrcSummary) {
|
|
|
|
// Simple case - source linked by rowId, not a summary.
|
2021-09-20 20:35:14 +00:00
|
|
|
if (isList(controller)) {
|
|
|
|
// Should be a reference list. Pick the first reference.
|
|
|
|
controller = controller[1]; // [0] is the L type code, [1] is the first value
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
srcRowId = controller;
|
|
|
|
} else {
|
|
|
|
const srcTable = await this._getTableData(srcSection);
|
2021-09-20 20:35:14 +00:00
|
|
|
const query: ClientQuery = {tableId: srcTable.tableId, filters: {}, operations: {}};
|
|
|
|
if (colId) {
|
2022-02-07 14:02:26 +00:00
|
|
|
query.operations[colId] = isRefListType(section.linkSrcCol.peek().type.peek()) ? 'intersects' : 'in';
|
2021-09-20 20:35:14 +00:00
|
|
|
query.filters[colId] = isList(controller) ? controller.slice(1) : [controller];
|
|
|
|
} else {
|
2021-05-17 14:05:49 +00:00
|
|
|
// must be a summary -- otherwise dealt with earlier.
|
|
|
|
const destTable = await this._getTableData(section);
|
2021-09-20 20:35:14 +00:00
|
|
|
for (const srcCol of srcSection.table.peek().groupByColumns.peek()) {
|
2022-06-07 14:57:29 +00:00
|
|
|
const filterCol = srcCol.summarySource.peek();
|
|
|
|
const filterColId = filterCol.colId.peek();
|
2021-09-20 20:35:14 +00:00
|
|
|
controller = destTable.getValue(cursorPos.rowId, filterColId);
|
2022-06-07 14:57:29 +00:00
|
|
|
// If the source groupby column is a ChoiceList or RefList, then null or '' in the summary table
|
|
|
|
// should match against an empty list in the source table.
|
|
|
|
query.operations[filterColId] = isListType(filterCol.type.peek()) && !controller ? 'empty' : 'in';
|
2021-09-20 20:35:14 +00:00
|
|
|
query.filters[filterColId] = isList(controller) ? controller.slice(1) : [controller];
|
2021-05-17 14:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-20 20:35:14 +00:00
|
|
|
srcRowId = srcTable.getRowIds().find(getFilterFunc(this.docData, query));
|
2021-05-17 14:05:49 +00:00
|
|
|
}
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!srcRowId || typeof srcRowId !== 'number') {
|
|
|
|
throw new Error('cannot trace rowId');
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
await this.recursiveMoveToCursorPos({
|
|
|
|
rowId: srcRowId,
|
2022-03-22 12:38:56 +00:00
|
|
|
sectionId: srcSection.id.peek(),
|
2023-09-25 22:48:18 +00:00
|
|
|
}, false, silent, visitedSections.concat([section.id.peek()]));
|
2021-05-17 14:05:49 +00:00
|
|
|
}
|
|
|
|
const view: ViewRec = section.view.peek();
|
2022-03-22 12:38:56 +00:00
|
|
|
const docPage: ViewDocPage = section.isRaw.peek() ? "data" : view.getRowId();
|
2023-07-18 07:24:10 +00:00
|
|
|
if (docPage != this.activeViewId.get()) {
|
|
|
|
await this.openDocPage(docPage);
|
|
|
|
}
|
|
|
|
if (setAsActiveSection) {
|
|
|
|
view.activeSectionId(cursorPos.sectionId);
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
const fieldIndex = cursorPos.fieldIndex;
|
|
|
|
const viewInstance = await waitObs(section.viewInstance);
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!viewInstance) {
|
|
|
|
throw new Error('view not found');
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
// Give any synchronous initial cursor setting a chance to happen.
|
|
|
|
await delay(0);
|
2023-07-18 07:24:10 +00:00
|
|
|
viewInstance.setCursorPos({...cursorPos, fieldIndex});
|
2021-05-17 14:05:49 +00:00
|
|
|
// TODO: column selection not working on card/detail view, or getting overridden -
|
|
|
|
// look into it (not a high priority for now since feature not easily discoverable
|
|
|
|
// in this view).
|
2021-05-19 11:56:31 +00:00
|
|
|
|
|
|
|
// even though the cursor is at right place, the scroll could not have yet happened
|
|
|
|
// wait for a bit (scroll is done in a setTimeout 0)
|
|
|
|
await delay(0);
|
2022-10-17 09:47:16 +00:00
|
|
|
return true;
|
2021-05-17 14:05:49 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.debug(`_recursiveMoveToCursorPos(${JSON.stringify(cursorPos)}): ${e}`);
|
2022-03-22 12:38:56 +00:00
|
|
|
if (!silent) {
|
|
|
|
throw new UserError('There was a problem finding the desired cell.');
|
|
|
|
}
|
2022-10-17 09:47:16 +00:00
|
|
|
return false;
|
2021-05-17 14:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens up an editor at cursor position
|
|
|
|
* @param input Optional. Cell's initial value
|
|
|
|
*/
|
2023-07-18 07:24:10 +00:00
|
|
|
public async activateEditorAtCursor(options?: { init?: string, state?: any }) {
|
2021-05-23 17:43:11 +00:00
|
|
|
const view = await this._waitForView();
|
2021-05-17 14:05:49 +00:00
|
|
|
view?.activateEditorAtCursor(options);
|
|
|
|
}
|
|
|
|
|
2022-04-27 17:46:24 +00:00
|
|
|
/**
|
|
|
|
* Renames table. Method exposed primarily for tests.
|
|
|
|
*/
|
|
|
|
public async renameTable(tableId: string, newTableName: string) {
|
2022-12-27 18:35:03 +00:00
|
|
|
const tableRec = this.docModel.visibleTables.all().find(tb => tb.tableId.peek() === tableId);
|
2022-04-27 17:46:24 +00:00
|
|
|
if (!tableRec) {
|
|
|
|
throw new UserError(`No table with id ${tableId}`);
|
|
|
|
}
|
|
|
|
await tableRec.tableName.saveOnly(newTableName);
|
|
|
|
}
|
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
/**
|
|
|
|
* Opens popup with a section data (used by Raw Data view).
|
|
|
|
*/
|
|
|
|
public async openPopup(hash: HashLink) {
|
|
|
|
// We can only open a popup for a section.
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!hash.sectionId) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-18 19:33:45 +00:00
|
|
|
// We might open popup either for a section in this view or some other section (like Raw Data Page).
|
2023-03-22 15:21:53 +00:00
|
|
|
if (this.viewModel.viewSections.peek().peek().some(s => s.id.peek() === hash.sectionId)) {
|
|
|
|
if (this.viewLayout) {
|
|
|
|
this.viewLayout.previousSectionId = this.viewModel.activeSectionId.peek();
|
|
|
|
}
|
2023-01-18 19:33:45 +00:00
|
|
|
this.viewModel.activeSectionId(hash.sectionId);
|
|
|
|
// If the anchor link is valid, set the cursor.
|
|
|
|
if (hash.colRef && hash.rowId) {
|
|
|
|
const activeSection = this.viewModel.activeSection.peek();
|
|
|
|
const fieldIndex = activeSection.viewFields.peek().all().findIndex(f => f.colRef.peek() === hash.colRef);
|
|
|
|
if (fieldIndex >= 0) {
|
|
|
|
const view = await this._waitForView(activeSection);
|
2023-08-28 09:16:17 +00:00
|
|
|
view?.setCursorPos({rowId: hash.rowId, fieldIndex});
|
2023-01-18 19:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-22 15:21:53 +00:00
|
|
|
this.viewLayout?.maximized.set(hash.sectionId);
|
2023-01-18 19:33:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-24 11:43:15 +00:00
|
|
|
// We will borrow active viewModel and will trick him into believing that
|
|
|
|
// the section from the link is his viewSection and it is active. Fortunately
|
|
|
|
// he doesn't care. After popup is closed, we will restore the original.
|
|
|
|
const prevSection = this.viewModel.activeSection.peek();
|
|
|
|
this.viewModel.activeSectionId(hash.sectionId);
|
|
|
|
// Now we have view section we want to show in the popup.
|
|
|
|
const popupSection = this.viewModel.activeSection.peek();
|
|
|
|
// We need to make it active, so that cursor on this section will be the
|
|
|
|
// active one. This will change activeViewSectionId on a parent view of this section,
|
|
|
|
// which might be a diffrent view from what we currently have. If the section is
|
|
|
|
// a raw data section it will use `EmptyRowModel` as raw sections don't have parents.
|
|
|
|
popupSection.hasFocus(true);
|
2023-01-18 19:33:45 +00:00
|
|
|
this._rawSectionOptions.set({
|
2022-08-24 11:43:15 +00:00
|
|
|
hash,
|
|
|
|
viewSection: popupSection,
|
|
|
|
close: () => {
|
|
|
|
// In case we are already close, do nothing.
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!this._rawSectionOptions.get()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-24 11:43:15 +00:00
|
|
|
if (popupSection !== prevSection) {
|
|
|
|
// We need to blur raw view section. Otherwise it will automatically be opened
|
|
|
|
// on raw data view. Note: raw data section doesn't have its own view, it uses
|
|
|
|
// empty row model as a parent (which feels like a hack).
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!popupSection.isDisposed()) {
|
|
|
|
popupSection.hasFocus(false);
|
|
|
|
}
|
2022-08-24 11:43:15 +00:00
|
|
|
// We need to restore active viewSection for a view that we borrowed.
|
|
|
|
// When this popup was opened we tricked active view by setting its activeViewSection
|
|
|
|
// to our viewSection (which might be a completely diffrent section or a raw data section) not
|
|
|
|
// connected to this view.
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!prevSection.isDisposed()) {
|
|
|
|
prevSection.hasFocus(true);
|
|
|
|
}
|
2022-08-24 11:43:15 +00:00
|
|
|
}
|
|
|
|
// Clearing popup data will close this popup.
|
2023-01-18 19:33:45 +00:00
|
|
|
this._rawSectionOptions.set(null);
|
2022-08-24 11:43:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// If the anchor link is valid, set the cursor.
|
|
|
|
if (hash.colRef && hash.rowId) {
|
|
|
|
const fieldIndex = popupSection.viewFields.peek().all().findIndex(f => f.colRef.peek() === hash.colRef);
|
|
|
|
if (fieldIndex >= 0) {
|
|
|
|
const view = await this._waitForView(popupSection);
|
2023-08-28 09:16:17 +00:00
|
|
|
view?.setCursorPos({rowId: hash.rowId, fieldIndex});
|
2022-08-24 11:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-27 17:25:25 +00:00
|
|
|
/**
|
|
|
|
* Starts playing the music video for Never Gonna Give You Up in the background.
|
|
|
|
*/
|
|
|
|
public async playRickRollVideo() {
|
|
|
|
const backgroundVideoPlayer = this._backgroundVideoPlayerHolder.get();
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!backgroundVideoPlayer) {
|
|
|
|
return;
|
|
|
|
}
|
2023-03-27 17:25:25 +00:00
|
|
|
|
|
|
|
await backgroundVideoPlayer.isLoaded();
|
|
|
|
backgroundVideoPlayer.play();
|
|
|
|
|
|
|
|
const setVolume = async (start: number, end: number, step: number) => {
|
|
|
|
let volume: number;
|
|
|
|
const condition = start <= end
|
|
|
|
? () => volume <= end
|
|
|
|
: () => volume >= end;
|
|
|
|
const afterthought = start <= end
|
|
|
|
? () => volume += step
|
|
|
|
: () => volume -= step;
|
|
|
|
for (volume = start; condition(); afterthought()) {
|
|
|
|
backgroundVideoPlayer.setVolume(volume);
|
|
|
|
await delay(250);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
await setVolume(0, 100, 5);
|
|
|
|
|
|
|
|
await delay(190 * 1000);
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!this._isRickRowing.get()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-03-27 17:25:25 +00:00
|
|
|
|
|
|
|
await setVolume(100, 0, 5);
|
|
|
|
|
|
|
|
this._isRickRowing.set(false);
|
|
|
|
this._showBackgroundVideoPlayer.set(false);
|
|
|
|
}
|
|
|
|
|
2021-05-17 14:05:49 +00:00
|
|
|
/**
|
|
|
|
* Waits for a view to be ready
|
|
|
|
*/
|
2022-08-24 11:43:15 +00:00
|
|
|
private async _waitForView(popupSection?: ViewSectionRec) {
|
|
|
|
const sectionToCheck = popupSection ?? this.viewModel.activeSection.peek();
|
2022-03-21 03:41:59 +00:00
|
|
|
// For pages like ACL's, there isn't a view instance to wait for.
|
2022-08-24 11:43:15 +00:00
|
|
|
if (!sectionToCheck.getRowId()) {
|
2022-03-22 12:38:56 +00:00
|
|
|
return null;
|
2022-03-21 03:41:59 +00:00
|
|
|
}
|
2023-07-18 07:24:10 +00:00
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
async function singleWait(s: ViewSectionRec): Promise<BaseView> {
|
|
|
|
const view = await waitObs(
|
|
|
|
sectionToCheck.viewInstance,
|
|
|
|
vsi => Boolean(vsi && !vsi.isDisposed())
|
|
|
|
);
|
|
|
|
return view!;
|
|
|
|
}
|
2023-07-18 07:24:10 +00:00
|
|
|
|
2022-08-24 11:43:15 +00:00
|
|
|
let view = await singleWait(sectionToCheck);
|
|
|
|
if (view.isDisposed()) {
|
|
|
|
// If the view is disposed (it can happen, as wait is not reliable enough, because it uses
|
|
|
|
// subscription for testing the predicate, which might dispose object before we have a chance to test it).
|
|
|
|
// This can happen when section is recreating itself on a popup.
|
|
|
|
if (popupSection) {
|
|
|
|
view = await singleWait(popupSection);
|
|
|
|
}
|
|
|
|
if (view.isDisposed()) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-03-22 12:38:56 +00:00
|
|
|
}
|
|
|
|
await view.getLoadingDonePromise();
|
|
|
|
// Wait extra bit for scroll to happen.
|
|
|
|
await delay(0);
|
2021-05-17 14:05:49 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _getToolContent(tool: typeof RightPanelTool.type): IExtraTool | null {
|
2020-10-02 15:10:00 +00:00
|
|
|
switch (tool) {
|
|
|
|
case 'docHistory': {
|
|
|
|
return {icon: 'Log', label: 'Document History', content: this._docHistory};
|
|
|
|
}
|
|
|
|
case 'validations': {
|
|
|
|
const content = this._rightPanelTabs.get("Validate Data");
|
|
|
|
return content ? {icon: 'Validation', label: 'Validation Rules', content} : null;
|
|
|
|
}
|
2022-10-17 09:47:16 +00:00
|
|
|
case 'discussion': {
|
2023-07-18 07:24:10 +00:00
|
|
|
return {icon: 'Chat', label: this._discussionPanel.buildMenu(), content: this._discussionPanel};
|
2022-10-17 09:47:16 +00:00
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
case 'none':
|
|
|
|
default: {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 02:06:39 +00:00
|
|
|
private async _maybeShowEditCardLayoutTip(selectedWidgetType: IWidgetType) {
|
|
|
|
if (
|
|
|
|
// Don't show the tip if a non-card widget was selected.
|
|
|
|
!['single', 'detail'].includes(selectedWidgetType) ||
|
2023-09-27 00:40:34 +00:00
|
|
|
// Or if we shouldn't see the tip.
|
|
|
|
!this.behavioralPromptsManager.shouldShowTip('editCardLayout')
|
2022-12-20 02:06:39 +00:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the right panel to the widget subtab.
|
|
|
|
commands.allCommands.viewTabOpen.run();
|
|
|
|
|
|
|
|
// Wait for the right panel to finish animation if it was collapsed before.
|
|
|
|
await commands.allCommands.rightPanelOpen.run();
|
|
|
|
|
|
|
|
const editLayoutButton = document.querySelector('.behavioral-prompt-edit-card-layout');
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!editLayoutButton) {
|
|
|
|
throw new Error('GristDoc failed to find edit card layout button');
|
|
|
|
}
|
2022-12-20 02:06:39 +00:00
|
|
|
|
2023-01-13 07:39:33 +00:00
|
|
|
this.behavioralPromptsManager.showTip(editLayoutButton, 'editCardLayout', {
|
2022-12-20 02:06:39 +00:00
|
|
|
popupOptions: {
|
|
|
|
placement: 'left-start',
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-19 02:48:56 +00:00
|
|
|
private async _handleNewAttachedCustomWidget(widget: IAttachedCustomWidget) {
|
|
|
|
switch (widget) {
|
|
|
|
case 'custom.calendar': {
|
2023-09-27 00:40:34 +00:00
|
|
|
if (this.behavioralPromptsManager.shouldShowTip('calendarConfig')) {
|
|
|
|
// Open the right panel to the calendar subtab.
|
|
|
|
commands.allCommands.viewTabOpen.run();
|
2023-09-19 02:48:56 +00:00
|
|
|
|
2023-09-27 00:40:34 +00:00
|
|
|
// Wait for the right panel to finish animation if it was collapsed before.
|
|
|
|
await commands.allCommands.rightPanelOpen.run();
|
|
|
|
}
|
2023-09-19 02:48:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-04 09:54:30 +00:00
|
|
|
private async _promptForName() {
|
|
|
|
return await invokePrompt("Table name", "Create", '', "Default table name");
|
|
|
|
}
|
|
|
|
|
2022-10-17 21:45:42 +00:00
|
|
|
private async _replaceViewSection(
|
|
|
|
section: ViewSectionRec,
|
|
|
|
oldVal: IPageWidget,
|
|
|
|
newVal: IPageWidget
|
|
|
|
) {
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
const docModel = this.docModel;
|
|
|
|
const viewModel = section.view();
|
|
|
|
const docData = this.docModel.docData;
|
2022-04-07 10:10:58 +00:00
|
|
|
const options = section.options();
|
|
|
|
const colIds = section.viewFields().all().map((f) => f.column().colId());
|
|
|
|
const chartType = section.chartType();
|
2023-04-03 16:55:08 +00:00
|
|
|
const sectionTheme = section.theme();
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// we must read the current layout from the view layout because it can override the one in
|
|
|
|
// `section.layoutSpec` (in particular it provides a default layout when missing from the
|
|
|
|
// latter).
|
2023-02-24 11:12:55 +00:00
|
|
|
const layoutSpec = this.viewLayout!.layoutSpec();
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
const sectionTitle = section.title();
|
|
|
|
const sectionId = section.id();
|
|
|
|
|
|
|
|
// create a new section
|
|
|
|
const sectionCreationResult = await this.addWidgetToPageImpl(newVal);
|
|
|
|
|
|
|
|
// update section name
|
|
|
|
const newSection: ViewSectionRec = docModel.viewSections.getRowModel(sectionCreationResult.sectionRef);
|
|
|
|
await newSection.title.saveOnly(sectionTitle);
|
|
|
|
|
|
|
|
// replace old section id with new section id in the layout spec and save
|
|
|
|
const newLayoutSpec = cloneDeepWith(layoutSpec, (val) => {
|
|
|
|
if (typeof val === 'object' && val.leaf === sectionId) {
|
|
|
|
return {...val, leaf: newSection.id()};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
await viewModel.layoutSpec.saveOnly(JSON.stringify(newLayoutSpec));
|
|
|
|
|
2022-04-07 10:10:58 +00:00
|
|
|
// persist options
|
|
|
|
await newSection.options.saveOnly(options);
|
|
|
|
|
2022-10-17 21:45:42 +00:00
|
|
|
// charts needs to keep view fields consistent across updates
|
|
|
|
if (oldVal.type === 'chart' && newVal.type === 'chart') {
|
|
|
|
await this.setSectionViewFieldsFromArray(newSection, colIds);
|
|
|
|
}
|
2022-04-07 10:10:58 +00:00
|
|
|
|
|
|
|
// update theme, and chart type
|
2023-04-03 16:55:08 +00:00
|
|
|
await newSection.theme.saveOnly(sectionTheme);
|
2022-04-07 10:10:58 +00:00
|
|
|
await newSection.chartType.saveOnly(chartType);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// The newly-added section should be given focus.
|
|
|
|
this.viewModel.activeSectionId(newSection.getRowId());
|
|
|
|
|
|
|
|
// remove old section
|
|
|
|
await docData.sendAction(['RemoveViewSection', sectionId]);
|
2022-04-07 10:10:58 +00:00
|
|
|
return newSection;
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper called before an action is sent to the server. It saves cursor position to come back to
|
|
|
|
* in case of Undo.
|
|
|
|
*/
|
2023-07-18 07:24:10 +00:00
|
|
|
private _onSendActionsStart(ev: { cursorPos: CursorPos }) {
|
2020-10-02 15:10:00 +00:00
|
|
|
this._lastOwnActionGroup = null;
|
|
|
|
ev.cursorPos = this.getCursorPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper called when server responds to an action. It attaches the saved cursor position to the
|
|
|
|
* received action (if any), and stores also the resulting position.
|
|
|
|
*/
|
2023-07-18 07:24:10 +00:00
|
|
|
private _onSendActionsEnd(ev: { cursorPos: CursorPos }) {
|
2020-10-02 15:10:00 +00:00
|
|
|
const a = this._lastOwnActionGroup;
|
|
|
|
if (a) {
|
|
|
|
a.cursorPos = ev.cursorPos;
|
|
|
|
if (a.rowIdHint) {
|
|
|
|
a.cursorPos.rowId = a.rowIdHint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 14:59:39 +00:00
|
|
|
private _getDocApiDownloadParams() {
|
2023-07-19 17:37:22 +00:00
|
|
|
const activeSection = this.viewModel.activeSection();
|
|
|
|
const filters = activeSection.activeFilters.get().map(filterInfo => ({
|
2023-07-18 07:24:10 +00:00
|
|
|
colRef: filterInfo.fieldOrColumn.origCol().origColRef(),
|
|
|
|
filter: filterInfo.filter()
|
2022-10-05 14:59:39 +00:00
|
|
|
}));
|
2023-07-19 17:37:22 +00:00
|
|
|
const linkingFilter: FilterColValues = activeSection.linkingFilter();
|
2022-10-05 14:59:39 +00:00
|
|
|
|
2023-07-19 17:37:22 +00:00
|
|
|
return {
|
2022-10-05 14:59:39 +00:00
|
|
|
viewSection: this.viewModel.activeSectionId(),
|
2023-07-19 17:37:22 +00:00
|
|
|
tableId: activeSection.table().tableId(),
|
|
|
|
activeSortSpec: JSON.stringify(activeSection.activeSortSpec()),
|
2023-07-18 07:24:10 +00:00
|
|
|
filters: JSON.stringify(filters),
|
2023-07-19 17:37:22 +00:00
|
|
|
linkingFilter: JSON.stringify(linkingFilter),
|
2022-10-05 14:59:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Switch to a given sectionId, wait for it to load, and return a Promise for the instantiated
|
|
|
|
* viewInstance (such as an instance of GridView or DetailView).
|
|
|
|
*/
|
|
|
|
private async _switchToSectionId(sectionId: number) {
|
|
|
|
const section: ViewSectionRec = this.docModel.viewSections.getRowModel(sectionId);
|
2022-03-24 18:33:53 +00:00
|
|
|
if (section.isRaw.peek()) {
|
2022-03-11 10:48:36 +00:00
|
|
|
// This is raw data view
|
|
|
|
await urlState().pushUrl({docPage: 'data'});
|
|
|
|
this.viewModel.activeSectionId(sectionId);
|
2023-05-08 22:06:24 +00:00
|
|
|
} else if (section.isVirtual.peek()) {
|
|
|
|
// this is a virtual table, and therefore a webhook page (that is the only
|
|
|
|
// place virtual tables are used so far)
|
|
|
|
await urlState().pushUrl({docPage: 'webhook'});
|
|
|
|
this.viewModel.activeSectionId(sectionId);
|
2022-03-11 10:48:36 +00:00
|
|
|
} else {
|
2022-03-24 18:33:53 +00:00
|
|
|
const view: ViewRec = section.view.peek();
|
2022-03-11 10:48:36 +00:00
|
|
|
await this.openDocPage(view.getRowId());
|
|
|
|
view.activeSectionId(sectionId); // this.viewModel will reflect this with a delay.
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Returns the value of section.viewInstance() as soon as it is truthy.
|
|
|
|
return waitObs(section.viewInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async _getTableData(section: ViewSectionRec): Promise<TableData> {
|
|
|
|
const viewInstance = await waitObs(section.viewInstance);
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!viewInstance) {
|
|
|
|
throw new Error('view not found');
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
await viewInstance.getLoadingDonePromise();
|
|
|
|
const table = this.docData.getTable(section.table.peek().tableId.peek());
|
2023-07-18 07:24:10 +00:00
|
|
|
if (!table) {
|
|
|
|
throw new Error('no section table');
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2021-05-17 14:05:49 +00:00
|
|
|
/**
|
|
|
|
* Convert a url hash to a cursor position.
|
|
|
|
*/
|
|
|
|
private _getCursorPosFromHash(hash: HashLink): CursorPos {
|
2023-07-18 07:24:10 +00:00
|
|
|
const cursorPos: CursorPos = {rowId: hash.rowId, sectionId: hash.sectionId};
|
|
|
|
if (cursorPos.sectionId != undefined && hash.colRef !== undefined) {
|
2021-05-17 14:05:49 +00:00
|
|
|
// translate colRef to a fieldIndex
|
|
|
|
const section = this.docModel.viewSections.getRowModel(cursorPos.sectionId);
|
|
|
|
const fieldIndex = section.viewFields.peek().all()
|
2023-07-18 07:24:10 +00:00
|
|
|
.findIndex(x => x.colRef.peek() == hash.colRef);
|
|
|
|
if (fieldIndex >= 0) {
|
|
|
|
cursorPos.fieldIndex = fieldIndex;
|
|
|
|
}
|
2021-05-17 14:05:49 +00:00
|
|
|
}
|
|
|
|
return cursorPos;
|
|
|
|
}
|
2021-07-30 15:16:33 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-22 13:48:50 +00:00
|
|
|
* Returns whether a doc tour should automatically be started.
|
|
|
|
*
|
|
|
|
* Currently, tours are started if a GristDocTour table exists and the user hasn't
|
|
|
|
* seen the tour before.
|
|
|
|
*/
|
|
|
|
private _shouldAutoStartDocTour(): boolean {
|
2023-03-29 13:45:19 +00:00
|
|
|
if (this._disableAutoStartingTours || this.docModel.isTutorial()) {
|
2023-03-22 13:48:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.docModel.hasDocTour() && !this._seenDocTours.get()?.includes(this.docId());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether a welcome tour should automatically be started.
|
|
|
|
*
|
|
|
|
* Currently, tours are started for first-time users on a personal org, as long as
|
|
|
|
* a doc tutorial or tour isn't available.
|
2021-07-30 15:16:33 +00:00
|
|
|
*/
|
|
|
|
private _shouldAutoStartWelcomeTour(): boolean {
|
2023-10-30 03:21:28 +00:00
|
|
|
// For non-SaaS flavors of Grist, don't show the tour if the Help Center is explicitly
|
|
|
|
// disabled. A separate opt-out feature could be added down the road for more granularity,
|
|
|
|
// but will require communication in advance to avoid disrupting users.
|
|
|
|
const {features} = getGristConfig();
|
|
|
|
if (!features?.includes('helpCenter')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-22 13:48:50 +00:00
|
|
|
// If a doc tutorial or tour are available, leave the welcome tour for another
|
|
|
|
// doc (e.g. a new one).
|
2023-03-29 13:45:19 +00:00
|
|
|
if (this._disableAutoStartingTours || this.docModel.isTutorial() || this.docModel.hasDocTour()) {
|
2022-03-21 03:41:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-07-30 15:16:33 +00:00
|
|
|
|
|
|
|
// Only show the tour if one is on a personal org and can edit. This excludes templates (on
|
|
|
|
// the Templates org, which may have their own tour) and team sites (where user's intended
|
|
|
|
// role is often other than document creator).
|
|
|
|
const appModel = this.docPageModel.appModel;
|
|
|
|
if (!appModel.currentOrg?.owner || this.isReadonly.get()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Use the showGristTour pref if set; otherwise default to true for anonymous users, and false
|
|
|
|
// for real returning users.
|
|
|
|
return this._showGristTour.get() ?? (!appModel.currentValidUser);
|
|
|
|
}
|
2022-01-17 16:08:43 +00:00
|
|
|
|
|
|
|
/**
|
2022-01-19 11:13:18 +00:00
|
|
|
* Makes sure that the first y-series (ie: the view fields at index 1) is a numeric series. Does
|
|
|
|
* not handle chart with the group by option on: it is only intended to be used to make sure that
|
|
|
|
* newly created chart do have a visible y series.
|
2022-01-17 16:08:43 +00:00
|
|
|
*/
|
|
|
|
private async _ensureOneNumericSeries(id: number) {
|
|
|
|
const viewSection = this.docModel.viewSections.getRowModel(id);
|
2022-01-19 11:13:18 +00:00
|
|
|
const viewFields = viewSection.viewFields.peek().peek();
|
|
|
|
|
|
|
|
// If no y-series, then simply return.
|
2023-07-18 07:24:10 +00:00
|
|
|
if (viewFields.length === 1) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-19 11:13:18 +00:00
|
|
|
|
2022-01-17 16:08:43 +00:00
|
|
|
const field = viewSection.viewFields.peek().peek()[1];
|
|
|
|
if (isNumericOnly(viewSection.chartTypeDef.peek()) &&
|
2023-07-18 07:24:10 +00:00
|
|
|
!isNumericLike(field.column.peek())) {
|
2022-01-17 16:08:43 +00:00
|
|
|
const actions: UserAction[] = [];
|
|
|
|
|
|
|
|
// remove non-numeric field
|
|
|
|
actions.push(['RemoveRecord', field.id.peek()]);
|
|
|
|
|
|
|
|
// add new field
|
|
|
|
const newField = viewSection.hiddenColumns.peek().find((col) => isNumericLike(col));
|
|
|
|
if (newField) {
|
|
|
|
const colInfo = {
|
|
|
|
parentId: viewSection.id.peek(),
|
|
|
|
colRef: newField.id.peek(),
|
|
|
|
};
|
|
|
|
actions.push(['AddRecord', null, colInfo]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// send actions
|
|
|
|
await this.docModel.viewFields.sendTableActions(actions);
|
|
|
|
}
|
|
|
|
}
|
2023-07-18 07:24:10 +00:00
|
|
|
|
|
|
|
private _handleTriggerQueueOverflowMessage() {
|
|
|
|
this.listenTo(this, 'webhookOverflowError', (err: any) => {
|
|
|
|
this.app.topAppModel.notifier.createNotification({
|
|
|
|
message: err.toString(),
|
|
|
|
canUserClose: false,
|
|
|
|
level: "error",
|
|
|
|
badgeCounter: true,
|
|
|
|
expireSec: 5,
|
|
|
|
key: 'webhookOverflowError',
|
|
|
|
actions: [{
|
|
|
|
label: t('go to webhook settings'), action: async () => {
|
|
|
|
await urlState().pushUrl({docPage: 'webhook'});
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function finalizeAnchor() {
|
2023-07-18 07:24:10 +00:00
|
|
|
await urlState().pushUrl({hash: {}}, {replace: true});
|
2020-10-02 15:10:00 +00:00
|
|
|
setTestState({anchorApplied: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
const cssViewContentPane = styled('div', `
|
2023-06-29 14:44:37 +00:00
|
|
|
--view-content-page-margin: 12px;
|
2020-10-02 15:10:00 +00:00
|
|
|
flex: auto;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2022-09-29 16:32:54 +00:00
|
|
|
overflow: visible;
|
2020-10-02 15:10:00 +00:00
|
|
|
position: relative;
|
|
|
|
min-width: 240px;
|
2023-06-29 14:44:37 +00:00
|
|
|
margin: var(--view-content-page-margin, 12px);
|
2021-02-09 04:40:04 +00:00
|
|
|
@media ${mediaSmall} {
|
|
|
|
& {
|
|
|
|
margin: 4px;
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 21:39:13 +00:00
|
|
|
@media print {
|
|
|
|
& {
|
|
|
|
margin: 0px;
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 10:48:36 +00:00
|
|
|
&-contents {
|
|
|
|
margin: 0px;
|
2022-10-05 14:59:39 +00:00
|
|
|
overflow: hidden;
|
2022-03-11 10:48:36 +00:00
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
`);
|
2023-03-27 17:25:25 +00:00
|
|
|
|
|
|
|
const fadeInAndOut = keyframes(`
|
|
|
|
0% {
|
|
|
|
opacity: 0.01;
|
|
|
|
}
|
|
|
|
5%, 95% {
|
|
|
|
opacity: 0.2;
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
opacity: 0.01;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssBackgroundVideo = styled('div', `
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
opacity: 0;
|
|
|
|
pointer-events: none;
|
|
|
|
|
|
|
|
&-fade-in-and-out {
|
|
|
|
animation: ${fadeInAndOut} 200s;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssYouTubePlayer = styled('div', `
|
|
|
|
position: absolute;
|
|
|
|
width: 450%;
|
|
|
|
height: 450%;
|
|
|
|
top: -175%;
|
|
|
|
left: -175%;
|
|
|
|
|
|
|
|
@media ${mediaXSmall} {
|
|
|
|
& {
|
|
|
|
width: 450%;
|
|
|
|
height: 450%;
|
|
|
|
top: -175%;
|
|
|
|
left: -175%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssStopRickRowingButton = styled('div', `
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
padding: 8px;
|
|
|
|
margin: 16px;
|
|
|
|
border-radius: 24px;
|
|
|
|
background-color: ${theme.toastBg};
|
|
|
|
cursor: pointer;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssCloseIcon = styled(icon, `
|
|
|
|
height: 24px;
|
|
|
|
width: 24px;
|
|
|
|
--icon-color: ${theme.toastControlFg};
|
|
|
|
`);
|