Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Current behavior at a high level:
- IndexedDB store and index definitions are now declared in one schema manifest in `src/services/storage/indexedDbSchema.ts`
- schema migration markers now live in a dedicated IndexedDB schema metadata store instead of sharing the persisted Zustand state store
- local-first chat persistence now uses document-scoped IndexedDB indexes instead of full chat-message store scans
- user images/icons can be stored by content-hash ref in the IndexedDB `assets` store (`assetStoreV1` rollout flag) instead of embedding multi-MB data URLs into every document/history/snapshot copy; nodes hold `imageAssetId` / `iconAssetId` and resolve display URLs at render time

Important constraint:

Expand Down
17 changes: 14 additions & 3 deletions src/components/CustomNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NodeTransformControls } from './NodeTransformControls';
import { useActiveNodeSelection } from './useActiveNodeSelection';
import { useTranslation } from 'react-i18next';
import { useProviderShapePreview } from '@/hooks/useProviderShapePreview';
import { useResolvedMediaUrl } from '@/hooks/useResolvedMediaUrl';
import { useShiftHeld } from '@/hooks/useShiftHeld';
import { NodeShapeSVG } from './NodeShapeSVG';
import { DiffBadge, LintViolationBadge } from './NodeBadges';
Expand Down Expand Up @@ -73,10 +74,12 @@ function CustomNode(props: LegacyNodeProps<NodeData>): React.ReactElement {
const explicitHeightPx = getNumericNodeDimension(explicitHeight);
const measuredHeight = (props as { height?: number }).height;
const shiftHeld = useShiftHeld(Boolean(selected));
const resolvedUploadedIconUrl = useResolvedMediaUrl(data, 'image');
const resolvedCustomIconUrl = useResolvedMediaUrl(data, 'icon');
const resolvedAssetIconUrl = useProviderShapePreview(
typeof data.archIconPackId === 'string' ? data.archIconPackId : undefined,
typeof data.archIconShapeId === 'string' ? data.archIconShapeId : undefined,
typeof data.customIconUrl === 'string' ? data.customIconUrl : undefined
resolvedCustomIconUrl
);
const designSystem = useDesignSystem();
const isActiveSelected = useActiveNodeSelection(Boolean(selected));
Expand Down Expand Up @@ -107,7 +110,12 @@ function CustomNode(props: LegacyNodeProps<NodeData>): React.ReactElement {
const subLabelSizeClass = fontSizeClassFor(subLabelFontSize);
const subLabelFontSizeStyle = subLabelIsNumericSize ? { fontSize: subLabelFontSize + 'px' } : {};
const hasProviderIcon = Boolean(resolvedAssetIconUrl) || Boolean(data.archIconPackId);
const hasIcon = Boolean(iconName) || Boolean(data.customIconUrl) || hasProviderIcon;
const hasIcon =
Boolean(iconName)
|| Boolean(data.customIconUrl)
|| Boolean(data.iconAssetId)
|| Boolean(resolvedCustomIconUrl)
|| hasProviderIcon;
const hasLabel = Boolean(data.label?.trim());
const hasSubLabel = Boolean(data.subLabel);
const mermaidImportedNodeMetadata = readMermaidImportedNodeMetadataFromData(data);
Expand Down Expand Up @@ -294,7 +302,10 @@ function CustomNode(props: LegacyNodeProps<NodeData>): React.ReactElement {
)}

<CustomNodeContent
data={data}
data={{
...data,
imageUrl: resolvedUploadedIconUrl ?? data.imageUrl,
}}
hasIcon={hasIcon}
hasSubLabel={hasSubLabel}
resolvedAssetIconUrl={resolvedAssetIconUrl}
Expand Down
2 changes: 1 addition & 1 deletion src/components/FlowEditorPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export interface CommandBarPanelProps {
onAddSequence?: () => void;
onAddClassNode?: () => void;
onAddEntityNode?: () => void;
onAddImage: (imageUrl: string) => void;
onAddImage: (imageUrl: string, position?: { x: number; y: number }, imageAssetId?: string) => void;
onAddBrowserWireframe: () => void;
onAddMobileWireframe: () => void;
onAddDomainLibraryItem?: (item: DomainLibraryItem) => void;
Expand Down
7 changes: 5 additions & 2 deletions src/components/ImageNode.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, { memo } from 'react';
import type { LegacyNodeProps } from '@/lib/reactflowCompat';
import type { NodeData } from '@/lib/types';
import { useResolvedMediaUrl } from '@/hooks/useResolvedMediaUrl';
import { NodeChrome } from './NodeChrome';

function ImageNode({ id, data, selected }: LegacyNodeProps<NodeData>): React.ReactElement {
const imageSrc = useResolvedMediaUrl(data, 'image');

return (
<NodeChrome
nodeId={id}
Expand All @@ -22,9 +25,9 @@ function ImageNode({ id, data, selected }: LegacyNodeProps<NodeData>): React.Rea
transform: data.rotation ? `rotate(${data.rotation}deg)` : 'none',
}}
>
{data.imageUrl ? (
{imageSrc ? (
<img
src={data.imageUrl}
src={imageSrc}
alt={data.label || 'Image Node'}
className="w-full h-full object-contain pointer-events-none select-none"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/command-bar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface CommandBarProps {
onAddSequence?: () => void;
onAddClassNode?: () => void;
onAddEntityNode?: () => void;
onAddImage?: (imageUrl: string) => void;
onAddImage?: (imageUrl: string, position?: { x: number; y: number }, imageAssetId?: string) => void;
onAddBrowserWireframe?: () => void;
onAddMobileWireframe?: () => void;
onAddDomainLibraryItem?: (item: DomainLibraryItem) => void;
Expand Down
8 changes: 6 additions & 2 deletions src/components/custom-nodes/ArchitectureNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NodeChrome } from '@/components/NodeChrome';
import { getTransformDiagnosticsAttrs } from '@/components/transformDiagnostics';
import { resolveNodeVisualStyle } from '@/theme';
import { useProviderShapePreview } from '@/hooks/useProviderShapePreview';
import { useResolvedMediaUrl } from '@/hooks/useResolvedMediaUrl';
import type { DomainLibraryCategory } from '@/services/domainLibrary';
import type { LucideIcon } from 'lucide-react';
import {
Expand Down Expand Up @@ -57,13 +58,16 @@ function ArchitectureNode({ id, data, selected }: LegacyNodeProps<NodeData>): Re
};
const ResourceIcon: LucideIcon = resourceIconMap[resourceType] ?? Server;
const customIconUrl = typeof data.customIconUrl === 'string' ? data.customIconUrl : undefined;
const resolvedCustomIconUrl = useResolvedMediaUrl(data, 'icon');
const providerPreviewUrl = useProviderShapePreview(
typeof data.archIconPackId === 'string' ? data.archIconPackId : undefined,
typeof data.archIconShapeId === 'string' ? data.archIconShapeId : undefined,
customIconUrl
resolvedCustomIconUrl ?? customIconUrl
);
const resolvedProviderIconUrl =
provider === 'custom' && customIconUrl ? customIconUrl : providerPreviewUrl;
provider === 'custom' && (resolvedCustomIconUrl || customIconUrl)
? (resolvedCustomIconUrl ?? customIconUrl)
: providerPreviewUrl;

return (
<NodeChrome
Expand Down
4 changes: 3 additions & 1 deletion src/components/custom-nodes/BrowserNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import { NodeData } from '@/lib/types';
import { Lock } from 'lucide-react';
import { NodeChrome } from '@/components/NodeChrome';
import { useResolvedMediaUrl } from '@/hooks/useResolvedMediaUrl';
import { renderBrowserVariantContent } from './browserVariantRenderer';

import { getNodeColorPalette } from '../../theme';
Expand All @@ -12,6 +13,7 @@ const BrowserNode = ({ id, data, selected }: LegacyNodeProps<NodeData>): React.R
const { t } = useTranslation();
const nodeColorPalette = getNodeColorPalette(true);
const style = nodeColorPalette[data.color || 'slate'] || nodeColorPalette.slate;
const imageUrl = useResolvedMediaUrl(data, 'image');

return (
<NodeChrome
Expand Down Expand Up @@ -50,7 +52,7 @@ const BrowserNode = ({ id, data, selected }: LegacyNodeProps<NodeData>): React.R

{/* Content Area */}
{renderBrowserVariantContent({
imageUrl: data.imageUrl,
imageUrl,
variant: data.variant,
label: data.label,
style,
Expand Down
4 changes: 3 additions & 1 deletion src/components/custom-nodes/MobileNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import type { LegacyNodeProps } from '@/lib/reactflowCompat';
import { useTranslation } from 'react-i18next';
import { NodeData } from '@/lib/types';
import { NodeChrome } from '@/components/NodeChrome';
import { useResolvedMediaUrl } from '@/hooks/useResolvedMediaUrl';
import { renderMobileVariantContent } from './mobileVariantRenderer';
import { getNodeColorPalette } from '../../theme';

function MobileNode({ id, data, selected }: LegacyNodeProps<NodeData>): React.ReactElement {
const { t } = useTranslation();
const nodeColorPalette = getNodeColorPalette(true);
const style = nodeColorPalette[data.color || 'slate'] || nodeColorPalette.slate;
const imageUrl = useResolvedMediaUrl(data, 'image');

return (
<NodeChrome
Expand Down Expand Up @@ -46,7 +48,7 @@ function MobileNode({ id, data, selected }: LegacyNodeProps<NodeData>): React.Re
{/* Screen Content */}
<div className="flex-1 bg-[var(--brand-surface)] relative overflow-hidden flex flex-col">
{renderMobileVariantContent({
imageUrl: data.imageUrl,
imageUrl,
variant: data.variant,
style,
imageAlt: t('customNodes.mobileContent'),
Expand Down
36 changes: 25 additions & 11 deletions src/components/flow-canvas/useFlowCanvasDragDrop.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useCallback } from 'react';
import { ingestUserMediaFile } from '@/services/storage/assetStore';
import { reportStorageTelemetry } from '@/services/storage/storageTelemetry';

interface UseFlowCanvasDragDropParams {
screenToFlowPosition: (position: { x: number; y: number }) => { x: number; y: number };
handleAddImage: (imageUrl: string, position: { x: number; y: number }) => void;
handleAddImage: (imageUrl: string, position: { x: number; y: number }, imageAssetId?: string) => void;
onFileDrop?: (file: File, content: string) => void;
}

Expand Down Expand Up @@ -52,17 +54,29 @@ export function useFlowCanvasDragDrop({
if (!file) return;

if (file.type.startsWith('image/')) {
const reader = new FileReader();
reader.onload = (loadEvent) => {
const imageUrl = loadEvent.target?.result as string;
if (!imageUrl) return;
const position = screenToFlowPosition({
x: event.clientX,
y: event.clientY,
const position = screenToFlowPosition({
x: event.clientX,
y: event.clientY,
});
void ingestUserMediaFile(file, 'image', { fileName: file.name })
.then((result) => {
handleAddImage(
result.assetId ? '' : result.displayUrl,
position,
result.assetId
);
})
.catch((error) => {
// Best-effort: leave canvas unchanged so the user can retry.
reportStorageTelemetry({
area: 'persist',
code: 'ASSET_DROP_INGEST_FAILED',
severity: 'warning',
message: `Image drop ingest failed: ${
error instanceof Error ? error.message : String(error)
}`,
});
});
handleAddImage(imageUrl, position);
};
reader.readAsDataURL(file);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ interface BuildFlowEditorControllerChromeParams {
handleAddSequenceParticipant: () => void;
handleAddClassNode: () => void;
handleAddEntityNode: () => void;
handleAddImage: (imageUrl: string) => void;
handleAddImage: (imageUrl: string, position?: { x: number; y: number }, imageAssetId?: string) => void;
handleAddWireframe: (surface: 'browser' | 'mobile') => void;
handleAddDomainLibraryItem: (item: DomainLibraryItem) => void;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/flow-editor/panelProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface CommandBarPanelBuilderParams {
handleAddSequenceParticipant: () => void;
handleAddClassNode: () => void;
handleAddEntityNode: () => void;
handleAddImage: (imageUrl: string) => void;
handleAddImage: (imageUrl: string, position?: { x: number; y: number }, imageAssetId?: string) => void;
handleAddWireframe: (surface: 'browser' | 'mobile') => void;
handleAddDomainLibraryItem: (item: DomainLibraryItem) => void;
handleCodeAnalysis?: (code: string, language: SupportedLanguage) => Promise<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion src/components/flow-editor/useFlowEditorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export interface UseFlowEditorChromeParams {
handleAddSequenceParticipant: () => void;
handleAddClassNode: () => void;
handleAddEntityNode: () => void;
handleAddImage: (imageUrl: string) => void;
handleAddImage: (imageUrl: string, position?: { x: number; y: number }, imageAssetId?: string) => void;
handleAddWireframe: (surface: 'browser' | 'mobile') => void;
handleAddDomainLibraryItem: (item: DomainLibraryItem) => void;
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/properties/BulkNodeProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ export function BulkNodeProperties({
}));
}

function handleCustomIconChange(url?: string): void {
const updates = createUploadedIconData(url);
function handleCustomIconChange(url?: string, iconAssetId?: string): void {
const updates = createUploadedIconData(url, iconAssetId);
setForm((current) => ({
...current,
iconMode: url ? 'upload' : '',
iconMode: url || iconAssetId ? 'upload' : '',
icon: updates.icon ?? '',
customIconUrl: updates.customIconUrl,
iconAssetId: updates.iconAssetId,
assetProvider: updates.assetProvider as BulkNodePropertiesFormState['assetProvider'],
assetCategory: updates.assetCategory,
archIconPackId: updates.archIconPackId,
Expand Down Expand Up @@ -267,6 +268,7 @@ export function BulkNodeProperties({
<IconPicker
selectedIcon={form.icon || undefined}
customIconUrl={form.customIconUrl}
iconAssetId={form.iconAssetId}
selectedProvider={form.assetProvider}
selectedProviderCategory={form.assetCategory}
selectedProviderPackId={form.archIconPackId}
Expand Down
Loading