allow metadata to override the frame title, icon, and text (#972)

This commit is contained in:
Mike Sawka 2024-10-06 22:08:26 -07:00 committed by GitHub
parent f835441507
commit d9d19f8368
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 17 deletions

View File

@ -113,10 +113,6 @@ function makeDefaultViewModel(blockId: string, viewType: string): ViewModel {
const blockData = get(blockDataAtom);
return blockViewToName(blockData?.meta?.view);
}),
viewText: jotai.atom((get) => {
const blockData = get(blockDataAtom);
return blockData?.meta?.title;
}),
preIconButton: jotai.atom(null),
endIconButtons: jotai.atom(null),
};

View File

@ -160,15 +160,25 @@ const BlockFrame_Header = ({
error,
}: BlockFrameProps & { changeConnModalAtom: jotai.PrimitiveAtom<boolean>; error?: Error }) => {
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", nodeModel.blockId));
const viewName = util.useAtomValueSafe(viewModel?.viewName) ?? blockViewToName(blockData?.meta?.view);
let viewName = util.useAtomValueSafe(viewModel?.viewName) ?? blockViewToName(blockData?.meta?.view);
const showBlockIds = jotai.useAtomValue(useSettingsKeyAtom("blockheader:showblockids"));
const viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(blockData?.meta?.view);
let viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(blockData?.meta?.view);
const preIconButton = util.useAtomValueSafe(viewModel?.preIconButton);
const headerTextUnion = util.useAtomValueSafe(viewModel?.viewText);
let headerTextUnion = util.useAtomValueSafe(viewModel?.viewText);
const magnified = jotai.useAtomValue(nodeModel.isMagnified);
const manageConnection = util.useAtomValueSafe(viewModel?.manageConnection);
const dragHandleRef = preview ? null : nodeModel.dragHandleRef;
if (blockData?.meta?.["frame:title"]) {
viewName = blockData.meta["frame:title"];
}
if (blockData?.meta?.["frame:icon"]) {
viewIconUnion = blockData.meta["frame:icon"];
}
if (blockData?.meta?.["frame:text"]) {
headerTextUnion = blockData.meta["frame:text"];
}
const onContextMenu = React.useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
handleHeaderContextMenu(e, blockData, viewModel, magnified, nodeModel.toggleMagnify, nodeModel.onClose);

View File

@ -107,7 +107,6 @@ class TermViewModel {
htmlElemFocusRef: React.RefObject<HTMLInputElement>;
blockId: string;
viewIcon: jotai.Atom<string>;
viewText: jotai.Atom<HeaderElem[]>;
viewName: jotai.Atom<string>;
blockBg: jotai.Atom<MetaType>;
manageConnection: jotai.Atom<boolean>;
@ -132,11 +131,6 @@ class TermViewModel {
return "Terminal";
});
this.manageConnection = jotai.atom(true);
this.viewText = jotai.atom((get) => {
const blockData = get(this.blockAtom);
const titleText: HeaderText = { elemtype: "text", text: blockData?.meta?.title ?? "" };
return [titleText] as HeaderElem[];
});
this.blockBg = jotai.atom((get) => {
const blockData = get(this.blockAtom);
const fullConfig = get(atoms.fullConfigAtom);

View File

@ -264,7 +264,6 @@ declare global {
type MetaType = {
view?: string;
controller?: string;
title?: string;
file?: string;
url?: string;
connection?: string;
@ -279,6 +278,9 @@ declare global {
"frame:*"?: boolean;
"frame:bordercolor"?: string;
"frame:bordercolor:focused"?: string;
"frame:title"?: string;
"frame:icon"?: string;
"frame:text"?: string;
cmd?: string;
"cmd:*"?: boolean;
"cmd:interactive"?: boolean;

View File

@ -10,8 +10,6 @@ const (
MetaKey_Controller = "controller"
MetaKey_Title = "title"
MetaKey_File = "file"
MetaKey_Url = "url"
@ -33,6 +31,9 @@ const (
MetaKey_FrameClear = "frame:*"
MetaKey_FrameBorderColor = "frame:bordercolor"
MetaKey_FrameBorderColor_Focused = "frame:bordercolor:focused"
MetaKey_FrameTitle = "frame:title"
MetaKey_FrameIcon = "frame:icon"
MetaKey_FrameText = "frame:text"
MetaKey_Cmd = "cmd"
MetaKey_CmdClear = "cmd:*"

View File

@ -14,7 +14,6 @@ type MetaTSType struct {
// shared
View string `json:"view,omitempty"`
Controller string `json:"controller,omitempty"`
Title string `json:"title,omitempty"`
File string `json:"file,omitempty"`
Url string `json:"url,omitempty"`
Connection string `json:"connection,omitempty"`
@ -32,6 +31,9 @@ type MetaTSType struct {
FrameClear bool `json:"frame:*,omitempty"`
FrameBorderColor string `json:"frame:bordercolor,omitempty"`
FrameBorderColor_Focused string `json:"frame:bordercolor:focused,omitempty"`
FrameTitle string `json:"frame:title,omitempty"`
FrameIcon string `json:"frame:icon,omitempty"`
FrameText string `json:"frame:text,omitempty"`
Cmd string `json:"cmd,omitempty"`
CmdClear bool `json:"cmd:*,omitempty"`