add config option to show block header ids

This commit is contained in:
sawka 2024-06-24 16:25:53 -07:00
parent 77b5acfc5a
commit a0b8bd5c0b
3 changed files with 27 additions and 13 deletions

View File

@ -92,10 +92,14 @@ function processTitleString(titleString: string): React.ReactNode[] {
return partsStack[0]; return partsStack[0];
} }
function getBlockHeaderText(blockIcon: string, blockData: Block): React.ReactNode { function getBlockHeaderText(blockIcon: string, blockData: Block, settings: SettingsConfigType): React.ReactNode {
if (!blockData) { if (!blockData) {
return "no block data"; return "no block data";
} }
let blockIdStr = "";
if (settings?.blockheader?.showblockids) {
blockIdStr = ` [${blockData.oid.substring(0, 8)}]`;
}
let blockIconElem: React.ReactNode = null; let blockIconElem: React.ReactNode = null;
if (!util.isBlank(blockIcon)) { if (!util.isBlank(blockIcon)) {
let iconColor = blockData?.meta?.["icon:color"]; let iconColor = blockData?.meta?.["icon:color"];
@ -114,20 +118,17 @@ function getBlockHeaderText(blockIcon: string, blockData: Block): React.ReactNod
if (!util.isBlank(blockData?.meta?.title)) { if (!util.isBlank(blockData?.meta?.title)) {
try { try {
const rtn = processTitleString(blockData.meta.title) ?? []; const rtn = processTitleString(blockData.meta.title) ?? [];
if (blockIconElem) { return [blockIconElem, ...rtn, blockIdStr == "" ? null : blockIdStr];
rtn.unshift(blockIconElem);
}
return rtn;
} catch (e) { } catch (e) {
console.error("error processing title", blockData.meta.title, e); console.error("error processing title", blockData.meta.title, e);
return [blockIconElem, blockData.meta.title]; return [blockIconElem, blockData.meta.title + blockIdStr];
} }
} }
let viewString = blockData?.view; let viewString = blockData?.view;
if (blockData.controller == "cmd") { if (blockData.controller == "cmd") {
viewString = "cmd"; viewString = "cmd";
} }
return [blockIconElem, `${viewString} [${blockData.oid.substring(0, 8)}]`]; return [blockIconElem, viewString + blockIdStr];
} }
interface FramelessBlockHeaderProps { interface FramelessBlockHeaderProps {
@ -138,10 +139,11 @@ interface FramelessBlockHeaderProps {
const FramelessBlockHeader = ({ blockId, onClose, dragHandleRef }: FramelessBlockHeaderProps) => { const FramelessBlockHeader = ({ blockId, onClose, dragHandleRef }: FramelessBlockHeaderProps) => {
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId)); const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
const settingsConfig = jotai.useAtomValue(atoms.settingsConfigAtom);
return ( return (
<div key="header" className="block-header" ref={dragHandleRef}> <div key="header" className="block-header" ref={dragHandleRef}>
<div className="block-header-text text-fixed">{getBlockHeaderText(null, blockData)}</div> <div className="block-header-text text-fixed">{getBlockHeaderText(null, blockData, settingsConfig)}</div>
{onClose && ( {onClose && (
<div className="close-button" onClick={onClose}> <div className="close-button" onClick={onClose}>
<i className="fa fa-solid fa-xmark-large" /> <i className="fa fa-solid fa-xmark-large" />
@ -175,6 +177,7 @@ const BlockFrame_Tech = ({
children, children,
}: BlockFrameProps) => { }: BlockFrameProps) => {
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId)); const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
const settingsConfig = jotai.useAtomValue(atoms.settingsConfigAtom);
const isFocusedAtom = useBlockAtom<boolean>(blockId, "isFocused", () => { const isFocusedAtom = useBlockAtom<boolean>(blockId, "isFocused", () => {
return jotai.atom((get) => { return jotai.atom((get) => {
const winData = get(atoms.waveWindow); const winData = get(atoms.waveWindow);
@ -215,7 +218,7 @@ const BlockFrame_Tech = ({
style={style} style={style}
> >
<div className="block-frame-tech-header" ref={dragHandleRef} onContextMenu={handleContextMenu}> <div className="block-frame-tech-header" ref={dragHandleRef} onContextMenu={handleContextMenu}>
{getBlockHeaderText(blockIcon, blockData)} {getBlockHeaderText(blockIcon, blockData, settingsConfig)}
</div> </div>
<div className={clsx("block-frame-tech-close")} onClick={onClose}> <div className={clsx("block-frame-tech-close")} onClick={onClose}>
<i className="fa fa-solid fa-xmark fa-fw" /> <i className="fa fa-solid fa-xmark fa-fw" />

View File

@ -54,6 +54,11 @@ declare global {
oref: string; oref: string;
}; };
// wconfig.BlockHeaderOpts
type BlockHeaderOpts = {
showblockids: boolean;
};
// wshutil.BlockInputCommand // wshutil.BlockInputCommand
type BlockInputCommand = { type BlockInputCommand = {
blockid: string; blockid: string;
@ -214,6 +219,7 @@ declare global {
datetime: DateTimeConfigType; datetime: DateTimeConfigType;
term: TerminalConfigType; term: TerminalConfigType;
widgets: WidgetsConfigType[]; widgets: WidgetsConfigType[];
blockheader: BlockHeaderOpts;
}; };
// wstore.StickerClickOptsType // wstore.StickerClickOptsType

View File

@ -42,11 +42,16 @@ type MimeTypeConfigType struct {
Icon string `json:"icon"` Icon string `json:"icon"`
} }
type BlockHeaderOpts struct {
ShowBlockIds bool `json:"showblockids"`
}
type SettingsConfigType struct { type SettingsConfigType struct {
MimeTypes map[string]MimeTypeConfigType `json:"mimetypes"` MimeTypes map[string]MimeTypeConfigType `json:"mimetypes"`
DateTime DateTimeConfigType `json:"datetime"` DateTime DateTimeConfigType `json:"datetime"`
Term TerminalConfigType `json:"term"` Term TerminalConfigType `json:"term"`
Widgets []WidgetsConfigType `json:"widgets"` Widgets []WidgetsConfigType `json:"widgets"`
BlockHeader BlockHeaderOpts `json:"blockheader"`
} }
func getSettingsConfigDefaults() SettingsConfigType { func getSettingsConfigDefaults() SettingsConfigType {