2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* Exports `docBreadcrumbs()` which returns a styled breadcrumb for the current page:
|
|
|
|
*
|
|
|
|
* [icon] Workspace (link) / Document name (editable) / Page name (editable)
|
|
|
|
*
|
|
|
|
* Workspace is a clickable link and document and page names are editable labels.
|
|
|
|
*/
|
2022-10-28 16:11:08 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { urlState } from 'app/client/models/gristUrlState';
|
2022-09-06 01:51:57 +00:00
|
|
|
import { cssHideForNarrowScreen, mediaNotSmall, testId, theme } from 'app/client/ui2018/cssVars';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { editableLabel } from 'app/client/ui2018/editableLabel';
|
|
|
|
import { icon } from 'app/client/ui2018/icons';
|
2022-09-06 01:51:57 +00:00
|
|
|
import { cssLink } from 'app/client/ui2018/links';
|
2021-01-15 21:56:58 +00:00
|
|
|
import { UserOverride } from 'app/common/DocListAPI';
|
2021-03-08 21:08:13 +00:00
|
|
|
import { userOverrideParams } from 'app/common/gristUrls';
|
2020-10-02 15:10:00 +00:00
|
|
|
import { BindableValue, dom, Observable, styled } from 'grainjs';
|
|
|
|
import { tooltip } from 'popweasel';
|
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('ui2018.breadcrumbs');
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
export const cssBreadcrumbs = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.lightText};
|
2020-10-02 15:10:00 +00:00
|
|
|
white-space: nowrap;
|
|
|
|
cursor: default;
|
|
|
|
`);
|
|
|
|
|
|
|
|
export const separator = styled('span', `
|
|
|
|
padding: 0 2px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssIcon = styled(icon, `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.accentIcon};
|
2020-10-02 15:10:00 +00:00
|
|
|
margin-top: -2px;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssPublicIcon = styled(cssIcon, `
|
|
|
|
margin-left: 8px;
|
|
|
|
margin-top: -4px;
|
|
|
|
`);
|
|
|
|
|
2022-09-06 01:51:57 +00:00
|
|
|
const cssWorkspaceName = styled(cssLink, `
|
2020-10-02 15:10:00 +00:00
|
|
|
margin-left: 8px;
|
|
|
|
`);
|
|
|
|
|
2021-01-18 12:43:24 +00:00
|
|
|
const cssWorkspaceNarrowScreen = styled(icon, `
|
|
|
|
transform: rotateY(180deg);
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
margin-bottom: 4px;
|
|
|
|
margin-left: -7px;
|
|
|
|
margin-right: 8px;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.lightText};
|
2021-01-18 12:43:24 +00:00
|
|
|
cursor: pointer;
|
2021-01-21 19:12:24 +00:00
|
|
|
@media ${mediaNotSmall} {
|
2021-01-18 12:43:24 +00:00
|
|
|
& {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
const cssEditableName = styled('input', `
|
|
|
|
&:hover, &:focus {
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.text};
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssTag = styled('span', `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.breadcrumbsTagBg};
|
|
|
|
color: ${theme.breadcrumbsTagFg};
|
2020-10-02 15:10:00 +00:00
|
|
|
border-radius: 3px;
|
|
|
|
padding: 0 4px;
|
|
|
|
margin-left: 4px;
|
|
|
|
`);
|
|
|
|
|
2020-12-14 17:42:09 +00:00
|
|
|
const cssAlertTag = styled(cssTag, `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.breadcrumbsTagAlertBg};
|
|
|
|
--icon-color: ${theme.breadcrumbsTagFg};
|
2020-12-14 17:42:09 +00:00
|
|
|
a {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
interface PartialWorkspace {
|
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function docBreadcrumbs(
|
|
|
|
workspace: Observable<PartialWorkspace|null>,
|
|
|
|
docName: Observable<string>,
|
|
|
|
pageName: Observable<string>,
|
|
|
|
options: {
|
|
|
|
docNameSave: (val: string) => Promise<void>,
|
|
|
|
pageNameSave: (val: string) => Promise<void>,
|
2020-12-14 17:42:09 +00:00
|
|
|
cancelRecoveryMode: () => Promise<void>,
|
2020-10-02 15:10:00 +00:00
|
|
|
isDocNameReadOnly?: BindableValue<boolean>,
|
|
|
|
isPageNameReadOnly?: BindableValue<boolean>,
|
|
|
|
isFork: Observable<boolean>,
|
2021-08-05 21:22:50 +00:00
|
|
|
isBareFork: Observable<boolean>,
|
2020-10-02 15:10:00 +00:00
|
|
|
isFiddle: Observable<boolean>,
|
2020-12-14 17:42:09 +00:00
|
|
|
isRecoveryMode: Observable<boolean>,
|
2021-01-15 21:56:58 +00:00
|
|
|
userOverride: Observable<UserOverride|null>,
|
2020-10-02 15:10:00 +00:00
|
|
|
isSnapshot?: Observable<boolean>,
|
|
|
|
isPublic?: Observable<boolean>,
|
|
|
|
}
|
|
|
|
): Element {
|
|
|
|
return cssBreadcrumbs(
|
2021-08-05 21:22:50 +00:00
|
|
|
dom.domComputed<[boolean, PartialWorkspace|null]>(
|
|
|
|
(use) => [use(options.isBareFork), use(workspace)],
|
|
|
|
([isBareFork, ws]) => {
|
|
|
|
if (isBareFork || !ws) { return null; }
|
|
|
|
return [
|
|
|
|
cssIcon('Home',
|
2021-01-18 12:43:24 +00:00
|
|
|
testId('bc-home'),
|
|
|
|
cssHideForNarrowScreen.cls('')),
|
2021-08-05 21:22:50 +00:00
|
|
|
cssWorkspaceName(
|
|
|
|
urlState().setLinkUrl({ws: ws.id}),
|
|
|
|
dom.text(ws.name),
|
|
|
|
testId('bc-workspace'),
|
|
|
|
cssHideForNarrowScreen.cls('')
|
|
|
|
),
|
|
|
|
cssWorkspaceNarrowScreen(
|
|
|
|
'Expand',
|
|
|
|
urlState().setLinkUrl({ws: ws.id}),
|
|
|
|
testId('bc-workspace-ns')
|
|
|
|
),
|
|
|
|
separator(' / ',
|
|
|
|
testId('bc-separator'),
|
|
|
|
cssHideForNarrowScreen.cls(''))
|
|
|
|
];
|
|
|
|
}
|
|
|
|
),
|
2022-07-18 17:05:35 +00:00
|
|
|
editableLabel(docName, {
|
|
|
|
save: options.docNameSave,
|
|
|
|
inputArgs: [
|
|
|
|
testId('bc-doc'),
|
|
|
|
cssEditableName.cls(''),
|
|
|
|
dom.boolAttr('disabled', options.isDocNameReadOnly || false),
|
|
|
|
],
|
|
|
|
}),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.maybe(options.isPublic, () => cssPublicIcon('PublicFilled', testId('bc-is-public'))),
|
|
|
|
dom.domComputed((use) => {
|
|
|
|
if (options.isSnapshot && use(options.isSnapshot)) {
|
2022-10-28 16:11:08 +00:00
|
|
|
return cssTag(t('Snapshot'), testId('snapshot-tag'));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
if (use(options.isFork)) {
|
2022-10-28 16:11:08 +00:00
|
|
|
return cssTag(t('Unsaved'), testId('unsaved-tag'));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2020-12-14 17:42:09 +00:00
|
|
|
if (use(options.isRecoveryMode)) {
|
2022-10-28 16:11:08 +00:00
|
|
|
return cssAlertTag(t('RecoveryMode'),
|
2021-01-15 21:56:58 +00:00
|
|
|
dom('a', dom.on('click', () => options.cancelRecoveryMode()),
|
|
|
|
icon('CrossSmall')),
|
2020-12-14 17:42:09 +00:00
|
|
|
testId('recovery-mode-tag'));
|
|
|
|
}
|
2021-01-15 21:56:58 +00:00
|
|
|
const userOverride = use(options.userOverride);
|
|
|
|
if (userOverride) {
|
2022-10-28 16:11:08 +00:00
|
|
|
return cssAlertTag(userOverride.user?.email || t('Override'),
|
2021-03-08 21:08:13 +00:00
|
|
|
dom('a',
|
|
|
|
urlState().setHref(userOverrideParams(null)),
|
|
|
|
icon('CrossSmall')
|
|
|
|
),
|
|
|
|
testId('user-override-tag')
|
|
|
|
);
|
2021-01-15 21:56:58 +00:00
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
if (use(options.isFiddle)) {
|
2022-10-28 16:11:08 +00:00
|
|
|
return cssTag(t('Fiddle'), tooltip({title: t('FiddleExplanation')}), testId('fiddle-tag'));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}),
|
2021-01-18 12:43:24 +00:00
|
|
|
separator(' / ',
|
|
|
|
testId('bc-separator'),
|
|
|
|
cssHideForNarrowScreen.cls('')),
|
2022-07-18 17:05:35 +00:00
|
|
|
editableLabel(pageName, {
|
|
|
|
save: options.pageNameSave,
|
|
|
|
inputArgs: [
|
|
|
|
testId('bc-page'),
|
|
|
|
cssEditableName.cls(''),
|
|
|
|
dom.boolAttr('disabled', options.isPageNameReadOnly || false),
|
|
|
|
dom.cls(cssHideForNarrowScreen.className),
|
|
|
|
],
|
|
|
|
}),
|
2020-10-02 15:10:00 +00:00
|
|
|
);
|
|
|
|
}
|