From 058cf10e63fe784ba97f288e24fc58d41e0d46f3 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 8 Sep 2021 10:56:05 -0400 Subject: made setting background undoable. added setting header color/visibility from main toolbar. made changing header contents possible using #(; ; + const targetDoc = (showTitle?.startsWith("_") ? this.layoutDoc : this.rootDoc); const titleView = !showTitle ? (null) :
field + ":" + (this.dataDoc || this.props.Document)[field]?.toString()).join(" ")} + contents={showTitle.split(";").map(field => field.trim()).map(field => targetDoc[field]?.toString()).join("\\")} display={"block"} fontSize={10} - GetValue={() => Field.toString((this.dataDoc || this.props.Document)[showTitle.split(";")[0]] as any as Field)} - SetValue={undoBatch((value) => showTitle.includes("Date") ? true : (Doc.GetProto(this.dataDoc || this.props.Document)[showTitle] = value) ? true : true)} + GetValue={() => showTitle.split(";").length === 1 ? showTitle + "=" + Field.toString(targetDoc[showTitle.split(";")[0]] as any as Field) : "#" + showTitle} + SetValue={undoBatch(value => { + if (value?.startsWith(showTitle + "=")) { + value = value.substring((showTitle + "=").length); + if (showTitle !== "title" && Number(value).toString() === value) value = Number(value); + if (showTitle.includes("Date") || showTitle === "author") return true; + return Doc.SetInPlace(targetDoc, showTitle, value, true) ? true : true; + } else if (value?.startsWith("#")) { + Doc.UserDoc().showTitle = value?.substring(1) ? value.substring(1) : "creationDate"; + return true; + } + return true; + })} />
; return this.props.hideTitle || (!showTitle && !showCaption) ? diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx index b72f31ef8..4475cf347 100644 --- a/src/client/views/nodes/button/FontIconBox.tsx +++ b/src/client/views/nodes/button/FontIconBox.tsx @@ -15,7 +15,7 @@ import { DocumentType } from '../../../documents/DocumentTypes'; import { Scripting } from "../../../util/Scripting"; import { SelectionManager } from '../../../util/SelectionManager'; import { ColorScheme } from '../../../util/SettingsManager'; -import { UndoManager } from '../../../util/UndoManager'; +import { UndoManager, undoBatch } from '../../../util/UndoManager'; import { CollectionViewType } from '../../collections/CollectionView'; import { ContextMenu } from '../../ContextMenu'; import { DocComponent } from '../../DocComponent'; @@ -31,6 +31,7 @@ import { ToggleButton } from './toggleButton'; import { IButtonProps } from './ButtonInterface'; import { FontIconBadge } from './FontIconBadge'; import './FontIconBox.scss'; +import { undo } from 'prosemirror-history'; const FontIconSchema = createSchema({ icon: "string", }); @@ -303,7 +304,7 @@ export class FontIconBox extends DocComponent(Fon
this.rootDoc.dropDownOpen = !this.rootDoc.dropDownOpen : undefined}> - {dropdown || noneSelected ? (null) : } + {dropdown || noneSelected ? (null) : }
{text && text[0].toUpperCase() + text.slice(1)}
@@ -348,7 +349,7 @@ export class FontIconBox extends DocComponent(Fon const colorOptions: string[] = ['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', - '#FFFFFF', '#f1efeb']; + '#FFFFFF', '#f1efeb', "transparent"]; const colorBox = (func: (color: ColorState) => void) => (Fon const hex: string = value.hex; const s = ScriptField.MakeScript(script + '("' + hex + '", false)'); if (s) { - s.script.run().result; + undoBatch(() => s.script.run().result)(); } }; return ( @@ -493,7 +494,7 @@ export class FontIconBox extends DocComponent(Fon {this.label}
; - const buttonProps:IButtonProps = { + const buttonProps: IButtonProps = { type: this.type, rootDoc: this.rootDoc, label: label, @@ -512,9 +513,9 @@ export class FontIconBox extends DocComponent(Fon button = (
- {buttonText ? + {buttonText ?
- {buttonText} + {buttonText}
: null} {label} @@ -598,11 +599,18 @@ Scripting.addGlobal(function setBackgroundColor(color?: string, checkResult?: bo return "#FFFFFF"; } } - if (selected && selected.type === DocumentType.INK) selected.fillColor = color; + if (selected?.type === DocumentType.INK) selected.fillColor = color; if (selected) selected._backgroundColor = color; Doc.UserDoc()._fontColor = color; }); +// toggle: Set overlay status of selected document +Scripting.addGlobal(function setHeaderColor(color?: string, checkResult?: boolean) { + Doc.SharingDoc().userColor = undefined; + Doc.GetProto(Doc.SharingDoc()).userColor = color; + Doc.UserDoc().showTitle = color === "transparent" ? undefined : StrCast(Doc.UserDoc().showTitle, "creationDate"); +}); + // toggle: Set overlay status of selected document Scripting.addGlobal(function toggleOverlay(checkResult?: boolean) { const selected = SelectionManager.Views().length ? SelectionManager.Views()[0] : undefined; diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index bc19320e9..fbb291858 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -1484,15 +1484,16 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp const annotated = DocListCast(this.dataDoc[this.SidebarKey]).filter(d => d?.author).length; const color = !annotated ? Colors.WHITE : Colors.BLACK; const backgroundColor = !annotated ? this.sidebarWidth() ? Colors.MEDIUM_BLUE : Colors.BLACK : this.props.styleProvider?.(this.rootDoc, this.props, StyleProp.WidgetColor + (annotated ? ":annotated" : "")); - return (!annotated && !this.props.isContentActive()) ? (null) :
- -
; + return (!annotated && (!this.props.isContentActive() || SnappingManager.GetIsDragging())) ? (null) : +
+ +
; } @computed get sidebarCollection() { const renderComponent = (tag: string) => { -- cgit v1.2.3-70-g09d2