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.

Sound system and volume settings (#169)

Jacob Beckerman2b216110162c
diff --git a/js/app/packages/app/component/GlobalHotkeys.tsx b/js/app/packages/app/component/GlobalHotkeys.tsx
index fd9c44eb5d..df061683ca 100644
--- a/js/app/packages/app/component/GlobalHotkeys.tsx
+++ b/js/app/packages/app/component/GlobalHotkeys.tsx
@@ -20,7 +20,7 @@ import {
} from '../../block-theme/signals/themeSignals';
import { applyTheme } from '../../block-theme/utils/themeUtils';
-
+import { playSound } from '../util/sound';
import {
konsoleOpen,
resetKonsoleMode,
@@ -39,8 +39,13 @@ export default function GlobalShortcuts() {
const toggleRightPanel = useToggleRightPanel();
const handleCommandMenu = () => {
+ const wasOpen = konsoleOpen();
resetKonsoleMode();
toggleKonsoleVisibility();
+ // Play sound when opening (not closing)
+ if (!wasOpen) {
+ playSound('Kick - Struct - Tight Minimal 4');
+ }
return;
};
diff --git a/js/app/packages/app/component/Root.tsx b/js/app/packages/app/component/Root.tsx
index c3f9101e41..6867bc2c3f 100644
--- a/js/app/packages/app/component/Root.tsx
+++ b/js/app/packages/app/component/Root.tsx
@@ -52,6 +52,7 @@ import {
} from '../../block-theme/utils/themeUtils';
import { useNotificationState } from '../../notification-provider/src/NotificationProvider';
import { TauriRouteListener } from '../../tauri/src/TauriProvider';
+import { useSoundHover } from '../util/soundHover';
import { updateCookie } from '../util/updateCookie';
import { Login } from './auth/Login';
import { LOGIN_COOKIE_AGE, setCookie } from './auth/Shared';
@@ -273,6 +274,7 @@ const clearBodyInlineStyleColor = () => {
export function Root() {
const isAuthenticated = useIsAuthenticated();
useHotKeyRoot();
+ useSoundHover();
useMobileEffect();
diff --git a/js/app/packages/app/component/Soup.tsx b/js/app/packages/app/component/Soup.tsx
index 6a6766f857..7b3e3526dc 100644
--- a/js/app/packages/app/component/Soup.tsx
+++ b/js/app/packages/app/component/Soup.tsx
@@ -3,6 +3,7 @@ import {
useGlobalNotificationSource,
} from '@app/component/GlobalAppState';
import { useHandleFileUpload } from '@app/util/handleFileUpload';
+import { playSound } from '@app/util/sound';
import { useIsAuthenticated } from '@core/auth';
import { FileDropOverlay } from '@core/component/FileDropOverlay';
import { Button } from '@core/component/FormControls/Button';
@@ -267,6 +268,7 @@ export function Soup() {
description: 'Toggle Preview',
hotkeyToken: TOKENS.unifiedList.togglePreview,
keyDownHandler: () => {
+ playSound('open');
setPreview((prev) => !prev);
return true;
},
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index 76c28a6797..97730d69fe 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -32,6 +32,7 @@ import {
type Store,
} from 'solid-js/store';
import type { VirtualizerHandle } from 'virtua/solid';
+import { playSound } from '../util/sound';
import { useGlobalNotificationSource } from './GlobalAppState';
import type { SplitHandle } from './split-layout/layoutManager';
import {
@@ -453,6 +454,7 @@ export function createNavigationEntityListShortcut({
description: 'Down',
hotkeyToken: TOKENS.entity.step.end,
keyDownHandler: () => {
+ playSound('down');
navigateThroughList({ axis: 'end', mode: 'step' });
return true;
},
@@ -464,6 +466,7 @@ export function createNavigationEntityListShortcut({
hotkeyToken: TOKENS.entity.step.start,
description: 'Up',
keyDownHandler: () => {
+ playSound('up');
navigateThroughList({ axis: 'start', mode: 'step' });
return true;
},
diff --git a/js/app/packages/app/component/dock/Dock.tsx b/js/app/packages/app/component/dock/Dock.tsx
index 24688ed5ab..3e0d1990d3 100644
--- a/js/app/packages/app/component/dock/Dock.tsx
+++ b/js/app/packages/app/component/dock/Dock.tsx
@@ -4,6 +4,7 @@ import { IconButton } from '@core/component/IconButton';
const { track, TrackingEvents } = withAnalytics();
import { globalSplitManager } from '@app/signal/splitLayout';
+import { playSound } from '@app/util/sound';
import { useHasPaidAccess } from '@core/auth';
import { GlobalNotificationBell } from '@core/component/GlobalNotificationBell';
import { BasicHotkey } from '@core/component/Hotkey';
@@ -76,6 +77,7 @@ export function Dock() {
// Fullscreen API helpers
const enterPresentMode = async () => {
try {
+ playSound('Stab_Destruct');
const element = document.documentElement;
if (element.requestFullscreen) {
await element.requestFullscreen();
diff --git a/js/app/packages/app/component/settings/Appearance.tsx b/js/app/packages/app/component/settings/Appearance.tsx
index 39b39e594d..ff61a0de8a 100644
--- a/js/app/packages/app/component/settings/Appearance.tsx
+++ b/js/app/packages/app/component/settings/Appearance.tsx
@@ -12,16 +12,34 @@ import {
getCustomCursorEnabled,
setCustomCursorEnabled,
} from '../../util/cursor';
+import {
+ getSoundEffectsEnabled,
+ getSoundEffectsVolume,
+ setSoundEffectsEnabled,
+ setSoundEffectsVolume,
+} from '../../util/soundSettings';
export function Appearance() {
const [cursorEnabled, setCursorEnabled] = createSignal(
getCustomCursorEnabled()
);
+ const [soundEnabled, setSoundEnabled] = createSignal(
+ getSoundEffectsEnabled()
+ );
+ const [soundVolume, setSoundVolume] = createSignal(getSoundEffectsVolume());
createEffect(() => {
setCustomCursorEnabled(cursorEnabled());
});
+ createEffect(() => {
+ setSoundEffectsEnabled(soundEnabled());
+ });
+
+ createEffect(() => {
+ setSoundEffectsVolume(soundVolume());
+ });
+
return (
<TabContent title="Appearance">
<div
@@ -72,6 +90,112 @@ export function Appearance() {
onChange={(enabled) => setCursorEnabled(enabled)}
/>
</div>
+ <div
+ style={{
+ 'font-family': 'var(--font-mono)',
+ border: '1px solid var(--b4)',
+ 'box-sizing': 'border-box',
+ padding: '12px 20px',
+ display: 'flex',
+ 'flex-direction': 'column',
+ gap: '12px',
+ 'font-size': '14px',
+ }}
+ >
+ <div
+ style={{
+ display: 'flex',
+ 'align-items': 'center',
+ 'justify-content': 'space-between',
+ }}
+ >
+ <span>Sound effects</span>
+ <ToggleSwitch
+ checked={soundEnabled()}
+ onChange={(enabled) => setSoundEnabled(enabled)}
+ />
+ </div>
+ <div
+ style={{
+ display: 'flex',
+ 'align-items': 'center',
+ gap: '12px',
+ }}
+ >
+ <span style={{ 'min-width': '60px' }}>Volume</span>
+ <div
+ style={{
+ position: 'relative',
+ flex: 1,
+ height: '18px',
+ display: 'flex',
+ 'align-items': 'center',
+ }}
+ >
+ <input
+ type="range"
+ min="0"
+ max="1"
+ step="0.01"
+ value={soundVolume()}
+ onInput={(e) => {
+ const value = parseFloat(
+ (e.target as HTMLInputElement).value
+ );
+ setSoundVolume(value);
+ }}
+ style={{
+ '-webkit-appearance': 'none',
+ width: '100%',
+ 'box-sizing': 'border-box',
+ 'border-radius': '0px',
+ position: 'absolute',
+ background: 'transparent',
+ appearance: 'none',
+ cursor: 'pointer',
+ outline: 'none',
+ height: '100%',
+ margin: 0,
+ padding: 0,
+ }}
+ class="sound-volume-slider"
+ />
+ </div>
+ <span style={{ 'min-width': '40px', 'text-align': 'right' }}>
+ {Math.round(soundVolume() * 100)}%
+ </span>
+ </div>
+ <style>{`
+ .sound-volume-slider::-webkit-slider-thumb {
+ -webkit-appearance: none;
+ appearance: none;
+ width: 18px;
+ height: 18px;
+ background-color: var(--b0);
+ border: 1px solid var(--b4);
+ border-radius: 0px;
+ cursor: pointer;
+ }
+ .sound-volume-slider::-moz-range-thumb {
+ width: 18px;
+ height: 18px;
+ background-color: var(--b0);
+ border: 1px solid var(--b4);
+ border-radius: 0px;
+ cursor: pointer;
+ }
+ .sound-volume-slider::-webkit-slider-runnable-track {
+ width: 100%;
+ height: 1px;
+ background: var(--b4);
+ }
+ .sound-volume-slider::-moz-range-track {
+ width: 100%;
+ height: 1px;
+ background: var(--b4);
+ }
+ `}</style>
+ </div>
</div>
</TabContent>
);
diff --git a/js/app/packages/app/component/split-layout/components/SplitTabs.tsx b/js/app/packages/app/component/split-layout/components/SplitTabs.tsx
index 45a51d0f2f..bc71a123d5 100644
--- a/js/app/packages/app/component/split-layout/components/SplitTabs.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitTabs.tsx
@@ -1,3 +1,4 @@
+import { playSound } from '@app/util/sound';
import type { ViewId } from '@core/types/view';
import { Tabs } from '@kobalte/core';
import { createElementSize } from '@solid-primitives/resize-observer';
@@ -93,6 +94,16 @@ export function SplitTabs(props: {
updateClipIndicators();
});
+ // Play sound when tab changes
+ let previousActive: ViewId | undefined;
+ createEffect(() => {
+ const currentActive = props.active();
+ if (previousActive !== undefined && previousActive !== currentActive) {
+ playSound('open');
+ }
+ previousActive = currentActive;
+ });
+
return (
<div class="relative isolate h-full shrink grow-2 @container-normal">
{/* Left clip boundary indicator */}
diff --git a/js/app/packages/app/public/sounds/Kick - Struct - Tight Minimal 4.wav b/js/app/packages/app/public/sounds/Kick - Struct - Tight Minimal 4.wav
new file mode 100644
index 0000000000..cdbc1a5d7e
Binary files /dev/null and b/js/app/packages/app/public/sounds/Kick - Struct - Tight Minimal 4.wav differ
diff --git a/js/app/packages/app/public/sounds/Raygun_Destruct.wav b/js/app/packages/app/public/sounds/Raygun_Destruct.wav
new file mode 100644
index 0000000000..43ed946ced
Binary files /dev/null and b/js/app/packages/app/public/sounds/Raygun_Destruct.wav differ
diff --git a/js/app/packages/app/public/sounds/Stab_Destruct.wav b/js/app/packages/app/public/sounds/Stab_Destruct.wav
new file mode 100644
index 0000000000..4cd88807d0
Binary files /dev/null and b/js/app/packages/app/public/sounds/Stab_Destruct.wav differ
diff --git a/js/app/packages/app/public/sounds/down.wav b/js/app/packages/app/public/sounds/down.wav
new file mode 100644
index 0000000000..f7779bb6b2
Binary files /dev/null and b/js/app/packages/app/public/sounds/down.wav differ
diff --git a/js/app/packages/app/public/sounds/open.wav b/js/app/packages/app/public/sounds/open.wav
new file mode 100644
index 0000000000..48f19f8bea
Binary files /dev/null and b/js/app/packages/app/public/sounds/open.wav differ
diff --git a/js/app/packages/app/public/sounds/tag.mp3 b/js/app/packages/app/public/sounds/tag.mp3
new file mode 100644
index 0000000000..5d8ef7d91a
Binary files /dev/null and b/js/app/packages/app/public/sounds/tag.mp3 differ
diff --git a/js/app/packages/app/public/sounds/ting.mp3 b/js/app/packages/app/public/sounds/ting.mp3
new file mode 100644
index 0000000000..5d8ef7d91a
Binary files /dev/null and b/js/app/packages/app/public/sounds/ting.mp3 differ
diff --git a/js/app/packages/app/public/sounds/toggle.wav b/js/app/packages/app/public/sounds/toggle.wav
new file mode 100644
index 0000000000..6eb227784d
Binary files /dev/null and b/js/app/packages/app/public/sounds/toggle.wav differ
diff --git a/js/app/packages/app/public/sounds/trap_hat_8.wav b/js/app/packages/app/public/sounds/trap_hat_8.wav
new file mode 100644
index 0000000000..d444050d5a
Binary files /dev/null and b/js/app/packages/app/public/sounds/trap_hat_8.wav differ
diff --git a/js/app/packages/app/public/sounds/up.wav b/js/app/packages/app/public/sounds/up.wav
new file mode 100644
index 0000000000..2613922702
Binary files /dev/null and b/js/app/packages/app/public/sounds/up.wav differ
diff --git a/js/app/packages/app/public/sounds/zip.mp3 b/js/app/packages/app/public/sounds/zip.mp3
new file mode 100644
index 0000000000..5d8ef7d91a
Binary files /dev/null and b/js/app/packages/app/public/sounds/zip.mp3 differ
diff --git a/js/app/packages/app/types.d.ts b/js/app/packages/app/types.d.ts
index e049c9c605..ae21d348cd 100644
--- a/js/app/packages/app/types.d.ts
+++ b/js/app/packages/app/types.d.ts
@@ -2,4 +2,4 @@ declare module '*.svg' {
import type { Component, ComponentProps } from 'solid-js';
const c: Component<ComponentProps<'svg'>>;
export default c;
-}
+}
\ No newline at end of file
diff --git a/js/app/packages/app/util/sound.ts b/js/app/packages/app/util/sound.ts
new file mode 100644
index 0000000000..84fc75c487
--- /dev/null
+++ b/js/app/packages/app/util/sound.ts
@@ -0,0 +1,109 @@
+/**
+ * Sound utility for playing UI sounds
+ * Caches Audio objects to avoid reloading
+ */
+
+import { getSoundEffectsEnabled, getSoundEffectsVolume } from './soundSettings';
+
+const soundCache = new Map<string, HTMLAudioElement>();
+const _DEFAULT_VOLUME = 0.3;
+
+// Update cached audio volumes when preference changes
+if (typeof window !== 'undefined') {
+ window.addEventListener('sound-preference-changed', () => {
+ const newVolume = getSoundEffectsVolume();
+ soundCache.forEach((audio) => {
+ audio.volume = newVolume;
+ });
+ });
+}
+
+/**
+ * Get the sound file path, trying .wav first, then .mp3
+ * @param name - The name of the sound file (without extension)
+ */
+function _getSoundPath(name: string): string {
+ // Try .wav first, then fallback to .mp3
+ // This allows both formats to work seamlessly
+ return `/sounds/${name}.wav`;
+}
+
+/**
+ * Play a sound by name
+ * @param name - The name of the sound file (without extension)
+ * @param volume - Optional volume (0-1), defaults to user preference or 0.3
+ */
+export function playSound(name: string, volume?: number): void {
+ // Check if sound effects are enabled
+ if (!getSoundEffectsEnabled()) {
+ return;
+ }
+
+ // Use user preference volume if not specified, otherwise use provided volume
+ const finalVolume = volume ?? getSoundEffectsVolume();
+ // Get or create audio element
+ let audio = soundCache.get(name);
+
+ if (!audio) {
+ // Try .wav first, fallback to .mp3 if needed
+ const wavPath = `/sounds/${name}.wav`;
+ const mp3Path = `/sounds/${name}.mp3`;
+
+ // Create audio element - try .wav first
+ audio = new Audio(wavPath);
+ audio.volume = finalVolume;
+ audio.preload = 'auto';
+
+ // Handle errors gracefully - try mp3 fallback if .wav fails
+ const errorHandler = () => {
+ // If .wav fails, try .mp3
+ const fallbackAudio = new Audio(mp3Path);
+ fallbackAudio.volume = finalVolume;
+ fallbackAudio.preload = 'auto';
+
+ fallbackAudio.addEventListener('error', () => {
+ console.warn(
+ `Failed to load sound: ${name} (tried both .wav and .mp3)`
+ );
+ });
+
+ // Replace the cached audio with the fallback
+ soundCache.set(name, fallbackAudio);
+ };
+
+ audio.addEventListener('error', errorHandler, { once: true });
+ soundCache.set(name, audio);
+ }
+
+ // Reset to beginning and play
+ audio.currentTime = 0;
+ audio.volume = finalVolume;
+
+ // Play with error handling
+ audio.play().catch((error) => {
+ // Ignore play() errors (e.g., user hasn't interacted with page yet)
+ if (error.name !== 'NotAllowedError') {
+ console.warn(`Failed to play sound: ${name}`, error);
+ }
+ });
+}
+
+/**
+ * Preload a sound file
+ * @param name - The name of the sound file (without extension)
+ */
+export function preloadSound(name: string): void {
+ if (soundCache.has(name)) {
+ return;
+ }
+
+ const audio = new Audio(`/sounds/${name}.wav`);
+ audio.preload = 'auto';
+ audio.addEventListener('error', () => {
+ // Fallback to mp3
+ const fallbackAudio = new Audio(`/sounds/${name}.mp3`);
+ fallbackAudio.preload = 'auto';
+ soundCache.set(name, fallbackAudio);
+ });
+ soundCache.set(name, audio);
+}
diff --git a/js/app/packages/app/util/soundHover.ts b/js/app/packages/app/util/soundHover.ts
new file mode 100644
index 0000000000..e6c1ee337d
--- /dev/null
+++ b/js/app/packages/app/util/soundHover.ts
@@ -0,0 +1,117 @@
+/**
+ * Global hover sound system
+ * Detects hover events on elements with a `sound` attribute and plays sounds
+ */
+
+import { onCleanup, onMount } from 'solid-js';
+import { playSound } from './sound';
+
+let hoverListenerAttached = false;
+let lastHoveredElement: Element | null = null;
+let lastHoveredY: number | null = null;
+let hoverTimeout: ReturnType<typeof setTimeout> | null = null;
+
+/**
+ * Initialize the global sound hover listener
+ * Should be called once when the app mounts
+ */
+export function useSoundHover(): void {
+ if (hoverListenerAttached) {
+ return;
+ }
+
+ const handleMouseOver = (event: MouseEvent) => {
+ const target = event.target as Element;
+ if (!target) return;
+
+ // Find the closest element with a sound attribute
+ const soundElement = target.closest('[sound]');
+
+ if (!soundElement) {
+ // Clear hover state if we moved away from a sound element
+ if (lastHoveredElement) {
+ lastHoveredElement = null;
+ lastHoveredY = null;
+ if (hoverTimeout) {
+ clearTimeout(hoverTimeout);
+ hoverTimeout = null;
+ }
+ }
+ return;
+ }
+
+ // If we're already hovering over this element, don't play again
+ if (soundElement === lastHoveredElement) {
+ return;
+ }
+
+ // Clear any pending timeout
+ if (hoverTimeout) {
+ clearTimeout(hoverTimeout);
+ hoverTimeout = null;
+ }
+
+ // Get the sound name from the attribute
+ const soundName = soundElement.getAttribute('sound');
+ if (!soundName) return;
+
+ // Determine sound based on vertical direction
+ const currentY = event.clientY;
+ let soundToPlay = soundName;
+
+ if (lastHoveredY !== null && lastHoveredElement) {
+ // Determine direction: if moving down (Y increases), play "down", if moving up (Y decreases), play "up"
+ if (currentY > lastHoveredY) {
+ soundToPlay = 'down';
+ } else if (currentY < lastHoveredY) {
+ soundToPlay = 'up';
+ }
+ // If Y is the same, use the original sound name
+ }
+
+ // Update last hovered element and position
+ lastHoveredElement = soundElement;
+ lastHoveredY = currentY;
+
+ // Small debounce to prevent rapid playback when moving between child elements
+ hoverTimeout = setTimeout(() => {
+ playSound(soundToPlay);
+ hoverTimeout = null;
+ }, 50);
+ };
+
+ const handleMouseOut = (event: MouseEvent) => {
+ const target = event.target as Element;
+ if (!target) return;
+
+ // Check if we're leaving a sound element
+ const soundElement = target.closest('[sound]');
+ if (!soundElement && lastHoveredElement) {
+ // Clear hover state
+ lastHoveredElement = null;
+ lastHoveredY = null;
+ if (hoverTimeout) {
+ clearTimeout(hoverTimeout);
+ hoverTimeout = null;
+ }
+ }
+ };
+
+ onMount(() => {
+ hoverListenerAttached = true;
+ document.addEventListener('mouseover', handleMouseOver, { passive: true });
+ document.addEventListener('mouseout', handleMouseOut, { passive: true });
+ });
+
+ onCleanup(() => {
+ hoverListenerAttached = false;
+ document.removeEventListener('mouseover', handleMouseOver);
+ document.removeEventListener('mouseout', handleMouseOut);
+ if (hoverTimeout) {
+ clearTimeout(hoverTimeout);
+ hoverTimeout = null;
+ }
+ lastHoveredElement = null;
+ lastHoveredY = null;
+ });
+}
diff --git a/js/app/packages/app/util/soundSettings.ts b/js/app/packages/app/util/soundSettings.ts
new file mode 100644
index 0000000000..297bf50e6b
--- /dev/null
+++ b/js/app/packages/app/util/soundSettings.ts
@@ -0,0 +1,32 @@
+const SOUND_ENABLED_KEY = 'sound-effects-enabled';
+const SOUND_VOLUME_KEY = 'sound-effects-volume';
+
+const DEFAULT_ENABLED = true;
+const DEFAULT_VOLUME = 0.5; // 50%
+
+export function getSoundEffectsEnabled(): boolean {
+ const stored = localStorage.getItem(SOUND_ENABLED_KEY);
+ return stored === null ? DEFAULT_ENABLED : stored === 'true';
+}
+
+export function setSoundEffectsEnabled(enabled: boolean) {
+ localStorage.setItem(SOUND_ENABLED_KEY, String(enabled));
+ // Dispatch event to notify sound code of preference change
+ window.dispatchEvent(new CustomEvent('sound-preference-changed'));
+}
+
+export function getSoundEffectsVolume(): number {
+ const stored = localStorage.getItem(SOUND_VOLUME_KEY);
+ if (stored === null) return DEFAULT_VOLUME;
+ const volume = parseFloat(stored);
+ // Clamp between 0 and 1
+ return isNaN(volume) ? DEFAULT_VOLUME : Math.max(0, Math.min(1, volume));
+}
+
+export function setSoundEffectsVolume(volume: number) {
+ // Clamp between 0 and 1
+ const clampedVolume = Math.max(0, Math.min(1, volume));
+ localStorage.setItem(SOUND_VOLUME_KEY, String(clampedVolume));
+ // Dispatch event to notify sound code of preference change
+ window.dispatchEvent(new CustomEvent('sound-preference-changed'));
+}
diff --git a/js/app/packages/block-md/component/InlineProperties.tsx b/js/app/packages/block-md/component/InlineProperties.tsx
new file mode 100644
index 0000000000..daed2bb121
--- /dev/null
+++ b/js/app/packages/block-md/component/InlineProperties.tsx
@@ -0,0 +1,311 @@
+import { useBlockId } from '@core/block';
+import {
+ $getPinnedProperties,
+ ADD_PINNED_PROPERTY_COMMAND,
+ REMOVE_PINNED_PROPERTY_COMMAND,
+} from '@core/component/LexicalMarkdown/plugins';
+import {
+ PropertiesProvider,
+ usePropertiesContext,
+} from '@core/component/Properties/context/PropertiesContext';
+import { EntityValueDisplay } from '@core/component/Properties/EntityValueDisplay';
+import { useProperties } from '@core/component/Properties/hooks';
+import {
+ extractDomain,
+ formatPropertyValue,
+} from '@core/component/Properties/utils';
+import type { EntityReference } from '@service-properties/generated/schemas/entityReference';
+import type { EntityType } from '@service-properties/generated/schemas/entityType';
+import {
+ createEffect,
+ createMemo,
+ createSignal,
+ For,
+ type JSX,
+ Show,
+} from 'solid-js';
+import { mdStore } from '../signal/markdownBlockData';
+import { propertiesRefreshSignal } from '../signal/propertiesRefresh';
+
+interface InlinePropertiesProps {
+ canEdit: boolean;
+ documentName: string;
+ fallback: JSX.Element;
+}
+
+// Standard metadata properties that don't need labels
+const STANDARD_METADATA_NAMES = ['Owner', 'Created At', 'Last Updated'];
+
+function isStandardMetadata(property: {
+ displayName: string;
+ isMetadata?: boolean;
+}): boolean {
+ return (
+ property.isMetadata === true &&
+ STANDARD_METADATA_NAMES.includes(property.displayName)
+ );
+}
+
+// Helper component to handle property value clicks with context
+function InlinePropertyValue(props: {
+ property: any;
+ displayValue: string | null;
+}) {
+ const { openModal } = usePropertiesContext();
+
+ const handleClick = (e: MouseEvent) => {
+ if (props.property.valueType === 'DATE') {
+ openModal('date-picker', props.property, e.currentTarget as HTMLElement);
+ } else if (
+ props.property.valueType === 'SELECT_STRING' ||
+ props.property.valueType === 'SELECT_NUMBER' ||
+ props.property.valueType === 'ENTITY'
+ ) {
+ openModal(
+ 'edit-property',
+ props.property,
+ e.currentTarget as HTMLElement
+ );
+ }
+ };
+
+ const isClickable = () => {
+ return (
+ props.property.valueType === 'DATE' ||
+ props.property.valueType === 'SELECT_STRING' ||
+ props.property.valueType === 'SELECT_NUMBER' ||
+ props.property.valueType === 'ENTITY'
+ );
+ };
+
+ return (
+ <Show
+ when={isClickable()}
+ fallback={<span class="text-ink">{props.displayValue || '—'}</span>}
+ >
+ <button
+ onClick={handleClick}
+ class="text-ink hover:bg-hover cursor-pointer px-1 py-0.5 rounded"
+ >
+ {props.displayValue || '—'}
+ </button>
+ </Show>
+ );
+}
+
+// Helper component to handle entity value clicks
+function InlineEntityValue(props: {
+ property: any;
+ canEdit: boolean;
+ onRefresh: () => void;
+}) {
+ const { openModal } = usePropertiesContext();
+ const entities = () =>
+ (props.property.value as EntityReference[] | undefined) ?? [];
+
+ const handleEntityClick = (e: MouseEvent) => {
+ // Don't handle clicks if they're on a link (BlockLink handles navigation)
+ const target = e.target as HTMLElement;
+ if (target.closest('a')) {
+ return;
+ }
+ // Always allow clicking to open modal, even for metadata properties
+ openModal('edit-property', props.property, e.currentTarget as HTMLElement);
+ };
+
+ // For inline display, we want entity values to be clickable
+ // So we wrap EntityValueDisplay in a clickable element
+ return (
+ <div class="flex items-center gap-1">
+ <For each={entities()}>
+ {(entityRef) => (
+ <div onClick={handleEntityClick} class="cursor-pointer">
+ <EntityValueDisplay
+ property={props.property}
+ entityId={entityRef.entity_id}
+ entityType={entityRef.entity_type}
+ canEdit={false}
+ />
+ </div>
+ )}
+ </For>
+ </div>
+ );
+}
+
+export function InlineProperties(props: InlinePropertiesProps) {
+ const blockId = useBlockId();
+ const mdData = mdStore.get;
+
+ const { properties, isLoading, error, refetch } = useProperties(
+ blockId,
+ 'DOCUMENT' as EntityType,
+ true // includeMetadata
+ );
+
+ // Watch for property changes from MarkdownPropertiesModal and refetch
+ createEffect(() => {
+ const shouldRefresh = propertiesRefreshSignal.get();
+ if (shouldRefresh) {
+ propertiesRefreshSignal.set(false);
+ refetch();
+ }
+ });
+
+ // Track pinned property IDs from Lexical - reactively updates on editor state changes
+ const [pinnedPropertyIds, setPinnedPropertyIds] = createSignal<string[]>([]);
+
+ // Set up reactive listener for Lexical state changes
+ createEffect(() => {
+ const currentEditor = mdData.editor;
+ if (!currentEditor) return;
+ // Initial load - read from current editor state
+ currentEditor.getEditorState().read(() => {
+ const ids = $getPinnedProperties();
+ setPinnedPropertyIds(ids);
+ });
+
+ // Register listener for state updates (including from other users)
+ const unregister = currentEditor.registerUpdateListener(
+ ({ editorState }) => {
+ editorState.read(() => {
+ const ids = $getPinnedProperties();
+ setPinnedPropertyIds(ids);
+ });
+ }
+ );
+
+ return () => {
+ unregister();
+ };
+ });
+
+ // Filter properties to show metadata/system properties and pinned ones
+ const filteredPinnedProperties = createMemo(() => {
+ const allProps = properties();
+ const pinnedIds = pinnedPropertyIds();
+
+ return allProps.filter(
+ (prop) =>
+ (prop.isMetadata || pinnedIds.includes(prop.propertyId)) &&
+ !(prop.displayName === 'Document Name')
+ );
+ });
+
+ const handlePropertyAdded = async () => {
+ refetch();
+ };
+
+ const handlePropertyDeleted = async () => {
+ refetch();
+ };
+
+ const handlePropertyPinned = (propertyId: string) => {
+ const editor = mdData.editor;
+ if (editor) {
+ editor.dispatchCommand(ADD_PINNED_PROPERTY_COMMAND, propertyId);
+ }
+ };
+
+ const handlePropertyUnpinned = (propertyId: string) => {
+ const editor = mdData.editor;
+ if (editor) {
+ editor.dispatchCommand(REMOVE_PINNED_PROPERTY_COMMAND, propertyId);
+ }
+ };
+
+ return (
+ <Show when={!error()} fallback={props.fallback}>
+ <PropertiesProvider
+ entityType={'DOCUMENT' as EntityType}
+ canEdit={props.canEdit}
+ documentName={props.documentName}
+ properties={filteredPinnedProperties}
+ onRefresh={refetch}
+ onPropertyAdded={handlePropertyAdded}
+ onPropertyDeleted={handlePropertyDeleted}
+ onPropertyPinned={handlePropertyPinned}
+ onPropertyUnpinned={handlePropertyUnpinned}
+ pinnedPropertyIds={pinnedPropertyIds}
+ >
+ <Show when={!isLoading() && filteredPinnedProperties().length > 0}>
+ <div class="flex items-center gap-3 text-sm">
+ <For each={filteredPinnedProperties()}>
+ {(property, index) => {
+ const isStandard = isStandardMetadata(property);
+ const showLabel = !isStandard;
+
+ // Format value for display
+ const displayValue = createMemo(() => {
+ if (property.valueType === 'ENTITY') {
+ // For entity types (like Owner), we'll render EntityValueDisplay
+ return null;
+ }
+ if (
+ property.valueType === 'DATE' &&
+ property.value instanceof Date
+ ) {
+ return formatPropertyValue(property, property.value);
+ }
+ if (
+ property.valueType === 'SELECT_STRING' ||
+ property.valueType === 'SELECT_NUMBER'
+ ) {
+ const values = property.value as string[] | undefined;
+ if (!values || values.length === 0) return null;
+ return values
+ .map((id) => formatPropertyValue(property, id))
+ .join(', ');
+ }
+ if (property.valueType === 'BOOLEAN') {
+ return formatPropertyValue(property, property.value);
+ }
+ if (property.valueType === 'NUMBER') {
+ return formatPropertyValue(property, property.value);
+ }
+ if (property.valueType === 'STRING') {
+ return formatPropertyValue(property, property.value);
+ }
+ if (property.valueType === 'LINK') {
+ const links = property.value as string[] | undefined;
+ if (!links || links.length === 0) return null;
+ return links.map((url) => extractDomain(url)).join(', ');
+ }
+ return null;
+ });
+
+ return (
+ <>
+ {index() > 0 && <span class="text-ink-muted">·</span>}
+ <div class="flex items-center gap-1.5">
+ <Show when={showLabel}>
+ <span class="text-ink-muted">
+ {property.displayName}:
+ </span>
+ </Show>
+ <Show
+ when={property.valueType === 'ENTITY'}
+ fallback={
+ <InlinePropertyValue
+ property={property}
+ displayValue={displayValue()}
+ />
+ }
+ >
+ <InlineEntityValue
+ property={property}
+ canEdit={props.canEdit}
+ onRefresh={refetch}
+ />
+ </Show>
+ </div>
+ </>
+ );
+ }}
+ </For>
+ </div>
+ </Show>
+ </PropertiesProvider>
+ </Show>
+ );
+}