Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix: theme sharing (#1300)

Peter Chinman8c9a4f10c366
diff --git a/js/app/packages/block-theme/components/ThemeEditorAdvanced.tsx b/js/app/packages/block-theme/components/ThemeEditorAdvanced.tsx
index aa6bfc90ee..dd7a904ba8 100644
--- a/js/app/packages/block-theme/components/ThemeEditorAdvanced.tsx
+++ b/js/app/packages/block-theme/components/ThemeEditorAdvanced.tsx
@@ -98,6 +98,8 @@ export function ThemeEditorAdvanced(){
<For each={Object.entries(themeReactive)}>
{([colorKey, colorValue]) => {
+ // a1 thru a4 are not currently being used, so we will hide them
+ if (['a1', 'a2', 'a3', 'a4'].includes(colorKey)) return null;
const [isSetByInput, setIsSetByInput] = createSignal(false);
const [inputValue, setInputValue] = createSignal('');
diff --git a/js/app/packages/block-theme/components/ThemeTools.tsx b/js/app/packages/block-theme/components/ThemeTools.tsx
index 2822a59192..253832c351 100644
--- a/js/app/packages/block-theme/components/ThemeTools.tsx
+++ b/js/app/packages/block-theme/components/ThemeTools.tsx
@@ -1,11 +1,10 @@
-import { deleteTheme, exportTheme, invertTheme, saveTheme } from '../utils/themeUtils';
+import { deleteTheme, exportTheme, importTheme, invertTheme, saveTheme } from '../utils/themeUtils';
import { currentThemeId, isThemeSaved, themes } from '../signals/themeSignals';
import { createEffect, createMemo, createSignal, Show } from 'solid-js';
import IconLightDark from '@macro-icons/macro-light-dark.svg';
import IconClipboard from '@macro-icons/macro-clipboard.svg';
-import { DEV_MODE_ENV } from '@core/constant/featureFlags';
+import IconImport from '@macro-icons/macro-import.svg';
import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';
-// import IconFigma from '@macro-icons/macro-figma.svg';
import IconTrash from '@macro-icons/macro-trash.svg';
import { randomizeTheme } from './ThemeEditorBasic';
import IconDice from '@macro-icons/macro-dice.svg';
@@ -15,11 +14,13 @@ import { DEFAULT_THEMES } from '../constants';
export function ThemeTools() {
let themeName!: HTMLDivElement;
+
+ const defaultThemeName = 'New Theme';
const currentThemeName = createMemo(() => {
const theme = themes().find((theme) => theme.id === currentThemeId());
if(isThemeSaved()){return theme?.name}
- else{return 'Theme Name'}
+ else{return defaultThemeName}
});
const [showTrash, setShowTrash] = createSignal<boolean>(true);
@@ -30,9 +31,7 @@ export function ThemeTools() {
const [columnCount, setColumnCount] = createSignal(0);
createEffect(() => {
- let count = 3;
- if(!isThemeSaved()){count++}
- if(DEV_MODE_ENV){count++}
+ let count = 5;
if(showTrash()){count++}
setColumnCount(count);
});
@@ -54,7 +53,29 @@ export function ThemeTools() {
'width': '100%',
}}
>
- <div ref={themeName} contentEditable style="white-space: nowrap;">
+ <div
+ ref={themeName}
+ contentEditable
+ style="white-space: nowrap;"
+ onBlur={() => {
+ if(!themeName.innerText.trim()){
+ themeName.innerText = defaultThemeName;
+ }
+ }}
+ onKeyDown={(e) => {
+ if(e.key === 'Enter'){
+ e.preventDefault();
+ const name = themeName.innerText.trim();
+ if(name){
+ saveTheme(name);
+ themeName.blur();
+ }
+ else {
+ themeName.innerText = defaultThemeName;
+ }
+ }
+ }}
+ >
{currentThemeName()}
</div>
@@ -72,7 +93,7 @@ export function ThemeTools() {
onPointerDown={() => {
deleteTheme(currentThemeId());
}}
- // tooltip={{label: "Delete Theme"}}
+ tooltip={{label: "Delete Theme"}}
icon={IconTrash}
theme="clear"
size="sm"
@@ -84,7 +105,7 @@ export function ThemeTools() {
onPointerDown={() => {
saveTheme(themeName.innerText);
}}
- // tooltip={{label: "Save Theme"}}
+ tooltip={{label: "Save Theme"}}
icon={IconSave}
theme="clear"
size="sm"
@@ -101,9 +122,9 @@ export function ThemeTools() {
/>
</Show>*/}
- <Show when={DEV_MODE_ENV}>
+ <Show when={isThemeSaved()}>
<DeprecatedIconButton
- // tooltip={{label: "Copy To Clipboard"}}
+ tooltip={{label: "Copy To Clipboard"}}
onPointerDown={exportTheme}
icon={IconClipboard}
theme="clear"
@@ -111,8 +132,16 @@ export function ThemeTools() {
/>
</Show>
+ <DeprecatedIconButton
+ tooltip={{label: "Import From Clipboard"}}
+ onPointerDown={importTheme}
+ icon={IconImport}
+ theme="clear"
+ size="sm"
+ />
+
<DeprecatedIconButton
- // tooltip={{label: "Toggle Light / Dark"}}
+ tooltip={{label: "Toggle Light / Dark"}}
onPointerDown={invertTheme}
icon={IconLightDark}
theme="clear"
@@ -120,7 +149,7 @@ export function ThemeTools() {
/>
<DeprecatedIconButton
- // tooltip={{label: "Randomize Theme"}}
+ tooltip={{label: "Randomize Theme"}}
onPointerDown={randomizeTheme}
icon={IconDice}
theme="clear"
diff --git a/js/app/packages/block-theme/utils/themeUtils.ts b/js/app/packages/block-theme/utils/themeUtils.ts
index 0905e0e182..b9c6a91b79 100644
--- a/js/app/packages/block-theme/utils/themeUtils.ts
+++ b/js/app/packages/block-theme/utils/themeUtils.ts
@@ -11,6 +11,43 @@ export function exportTheme(){
navigator.clipboard.writeText(theme);
}
+export async function importTheme(): Promise<void>{
+ try {
+ const text = await navigator.clipboard.readText();
+ const parsed: unknown = JSON.parse(text);
+ if(!isThemeV1(parsed)){
+ toast.alert('Clipboard does not contain a valid theme.');
+ return;
+ }
+ const id = crypto.randomUUID();
+ const newTheme: ThemeV1 = {
+ id,
+ name: parsed.name,
+ version: parsed.version,
+ tokens: parsed.tokens,
+ };
+ setUserThemes([...userThemes(), newTheme]);
+ applyTheme(id);
+ } catch(e) {
+ console.error('Failed to import theme:', e);
+ toast.alert('Failed to import theme from clipboard.');
+ }
+}
+
+function isThemeV1(value: unknown): value is ThemeV1 {
+ if(typeof value !== 'object' || value === null){return false}
+ const v = value as Record<string, unknown>;
+ if(typeof v.name !== 'string' || typeof v.version !== 'number' || typeof v.tokens !== 'object' || v.tokens === null){return false}
+ const tokenKeys: Array<keyof ThemeV1Tokens> = ['a0','a1','a2','a3','a4','b0','b1','b2','b3','b4','c0','c1','c2','c3','c4'];
+ const tokens = v.tokens as Record<string, unknown>;
+ return tokenKeys.every((key) => {
+ const t = tokens[key];
+ if(typeof t !== 'object' || t === null){return false}
+ const tok = t as Record<string, unknown>;
+ return typeof tok.l === 'number' && typeof tok.c === 'number' && typeof tok.h === 'number';
+ });
+}
+
export function systemThemeEffect(){
createEffect(
on(