aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/DocComponent.tsx17
-rw-r--r--src/client/views/StyleProvider.tsx20
-rw-r--r--src/client/views/global/globalScripts.ts4
-rw-r--r--src/client/views/nodes/DocumentView.tsx2
4 files changed, 18 insertions, 25 deletions
diff --git a/src/client/views/DocComponent.tsx b/src/client/views/DocComponent.tsx
index b8b70d9d2..45c80c6f7 100644
--- a/src/client/views/DocComponent.tsx
+++ b/src/client/views/DocComponent.tsx
@@ -19,6 +19,7 @@ import { FieldViewProps } from './nodes/FieldView';
* */
export interface DocComponentProps {
Document: Doc;
+ TemplateDataDocument?: Doc;
LayoutTemplate?: () => Opt<Doc>;
LayoutTemplateString?: string;
}
@@ -53,8 +54,8 @@ export function DocComponent<P extends DocComponentProps>() {
/**
* Whether the doc is a sub-componentn of a compound template doc.
*/
- get isTemplate() {
- return this.rootDoc !== this.layoutDoc;
+ get isTemplateForField() {
+ return this.rootDoc !== this.layoutDoc && this._props.TemplateDataDocument;
}
/**
* This is the document being rendered by the React component. In the
@@ -117,12 +118,6 @@ export function ViewBoxBaseComponent<P extends FieldViewProps>() {
return DocCast(this.Document.rootDocument, this.Document);
}
/**
- * Whether the doc is a sub-componentn of a compound template doc.
- */
- get isTemplate() {
- return this.rootDoc !== this.layoutDoc;
- }
- /**
* This is the document being rendered by the React component. In the
* case of a compound template, this will be the expanded template Doc
* that represents the component of the compound Doc being rendered.
@@ -197,12 +192,6 @@ export function ViewBoxAnnotatableComponent<P extends FieldViewProps>() {
return DocCast(this.Document.rootDocument, this.Document);
}
/**
- * Whether the doc is a sub-componentn of a compound template doc.
- */
- get isTemplate() {
- return this.rootDoc !== this.layoutDoc;
- }
- /**
* This is the document being rendered. It may be a template so it may or may no inherit from the data doc.
*/
@computed get layoutDoc() {
diff --git a/src/client/views/StyleProvider.tsx b/src/client/views/StyleProvider.tsx
index a1c6aa1a2..a3067907d 100644
--- a/src/client/views/StyleProvider.tsx
+++ b/src/client/views/StyleProvider.tsx
@@ -248,14 +248,18 @@ export function DefaultStyleProvider(doc: Opt<Doc>, props: Opt<FieldViewProps &
: 0;
case StyleProp.BackgroundColor: {
if (SnappingManager.LastPressedBtn === doc?.[Id]) return SnappingManager.userColor; // hack to indicate active menu panel item
- const dataKey = doc ? Doc.LayoutFieldKey(doc) : "";
- const usePath = StrCast(doc?.[dataKey + "_usePath"]);
- const alternate = usePath.includes(":hover") ? ( isHovering?.() ? '_' + usePath.replace(":hover","") : "") : usePath ? "_" +usePath:usePath;
- let docColor:Opt<string> = StrCast(doc?._backgroundColor, // renderDoc === this.layoutDoc
- StrCast(doc?.[fieldKey+alternate], // doc === this.Document
- StrCast(doc?.['backgroundColor' +alternate],
- isCaption ? 'rgba(0,0,0,0.4)' : '')));
-
+ const dataKey = doc ? Doc.LayoutFieldKey(doc) : '';
+ const usePath = StrCast(doc?.[dataKey + '_usePath']);
+ const alternate = usePath.includes(':hover') ? ( isHovering?.() ? '_' + usePath.replace(':hover','') : '') : usePath ? "_" +usePath:usePath;
+ let docColor:Opt<string> = layoutDoc &&
+ StrCast(alternate ? layoutDoc['backgroundColor' + alternate]:undefined,
+ doc.rootDocument
+ ? StrCast(layoutDoc.backgroundColor, StrCast(DocCast(doc.rootDocument).backgroundColor)) // for nested templates: use template's color, then root doc's color
+ : layoutDoc === doc
+ ? StrCast(doc.backgroundColor)
+ : StrCast(StrCast(Doc.GetT(layoutDoc, 'backgroundColor', 'string', true), StrCast(doc.backgroundColor, StrCast(layoutDoc.backgroundColor)) // otherwise, use expanded template coloor, then root doc's color, then template's inherited color
+ )));
+
// prettier-ignore
switch (layoutDoc?.type) {
case DocumentType.PRESELEMENT: docColor = docColor || ""; break;
diff --git a/src/client/views/global/globalScripts.ts b/src/client/views/global/globalScripts.ts
index caacd0a11..32afb3d3d 100644
--- a/src/client/views/global/globalScripts.ts
+++ b/src/client/views/global/globalScripts.ts
@@ -120,7 +120,7 @@ ScriptingGlobals.add(function setBackgroundColor(color?: string, checkResult?: b
const fieldKey = selView.Document._layout_isSvg ? 'fillColor' : 'backgroundColor';
const layoutFrameNumber = Cast(selView.containerViewPath?.().lastElement()?.Document?._currentFrame, 'number'); // frame number that container is at which determines layout frame values
const contentFrameNumber = Cast(selView.Document?._currentFrame, 'number', layoutFrameNumber ?? null); // frame number that content is at which determines what content is displayed
- return CollectionFreeFormDocumentView.getStringValues(selView?.Document, contentFrameNumber)[fieldKey] || defaultFill();
+ return (contentFrameNumber !== undefined ? CollectionFreeFormDocumentView.getStringValues(selView?.Document, contentFrameNumber)[fieldKey] : selView.backgroundColor()) || defaultFill();
}
!selectedViews.length && setDefaultFill(color ?? 'transparent');
selectedViews.forEach(dv => {
@@ -132,7 +132,7 @@ ScriptingGlobals.add(function setBackgroundColor(color?: string, checkResult?: b
obj[fieldKey] = color;
CollectionFreeFormDocumentView.setStringValues(contentFrameNumber, dv.Document, obj);
} else {
- const colorDoc = dv.isTemplate ? dv.layoutDoc : dv.dataDoc; // assigning to a template should not assign to the data doc
+ const colorDoc = dv.isTemplateForField ? dv.layoutDoc : dv.dataDoc; // assigning to a template's compoment field should not assign to the data doc
const dataKey = Doc.LayoutFieldKey(colorDoc);
const alternate = (dv.layoutDoc[dataKey + '_usePath'] ? '_' + dv.layoutDoc[dataKey + '_usePath'] : '').replace(':hover', '');
colorDoc[fieldKey + alternate] = color;
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 436f35d4c..b03dd3944 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -103,11 +103,11 @@ export class DocumentViewInternal extends DocComponent<DocumentViewProps & Field
@computed get border() { return this.style(this.layoutDoc, StyleProp.Border) as string || ""; } // prettier-ignore
@computed get borderRounding() { return this.style(this.layoutDoc, StyleProp.BorderRounding) as string; } // prettier-ignore
@computed get widgetDecorations() { return this.style(this.layoutDoc, StyleProp.Decorations) as JSX.Element; } // prettier-ignore
- @computed get backgroundBoxColor(){ return this.style(this.layoutDoc, StyleProp.BackgroundColor + ':docView') as string; } // prettier-ignore
@computed get showTitle() { return this.style(this.layoutDoc, StyleProp.ShowTitle) as Opt<string>; } // prettier-ignore
@computed get showCaption() { return this.style(this.layoutDoc, StyleProp.ShowCaption) as string ?? ""; } // prettier-ignore
@computed get headerMargin() { return this.style(this.layoutDoc, StyleProp.HeaderMargin) as number ?? 0; } // prettier-ignore
@computed get titleHeight() { return this.style(this.layoutDoc, StyleProp.TitleHeight) as number ?? 0; } // prettier-ignore
+ @computed get backgroundBoxColor(){ return this.style(this.Document, StyleProp.BackgroundColor + ':docView') as string; } // prettier-ignore
@computed get docContents() { return this.style(this.Document, StyleProp.DocContents) as JSX.Element; } // prettier-ignore
@computed get highlighting() { return this.style(this.Document, StyleProp.Highlighting); } // prettier-ignore
@computed get borderPath() { return this.style(this.Document, StyleProp.BorderPath); } // prettier-ignore