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.

2.4 KB
Raw Blame
import type {
  ArtifactLibrary,
  ArtifactLibraryEdit,
  ArtifactLibraryKind,
} from '@macro-inc/graphics/loro';
import { ARTIFACT_LIBRARY_ENTRY_MAX_LENGTH } from '@macro-inc/graphics/loro';
import { Button, Input } from '@ui';
import { createSignal, For } from 'solid-js';
import { InspectorField } from './inspector-field';
import { InspectorSection } from './inspector-section';

export function ArtifactLibraryInspector(props: {
  library: ArtifactLibrary;
  onEdit: (edit: ArtifactLibraryEdit) => void;
}) {
  const [name, setName] = createSignal('');
  const add = (kind: ArtifactLibraryKind) => {
    const trimmed = name().trim();
    // Adding over an existing name would blank it for everyone.
    if (!trimmed || Object.hasOwn(props.library[kind], trimmed)) return;

    props.onEdit({ kind, name: trimmed, source: '' });
    setName('');
  };
  const entries = (
    kind: ArtifactLibraryKind,
    label: (name: string) => string
  ) => (
    <For each={Object.keys(props.library[kind]).sort()}>
      {(entry) => (
        <InspectorField label={label(entry)}>
          <textarea
            class="h-24 w-full resize-y rounded border border-edge-muted bg-panel px-2 py-1 font-mono text-xs text-ink outline-none focus:border-edge-focus"
            aria-label={label(entry)}
            spellcheck={false}
            maxLength={ARTIFACT_LIBRARY_ENTRY_MAX_LENGTH}
            value={props.library[kind][entry]}
            onChange={(event) =>
              props.onEdit({
                kind,
                name: entry,
                // An emptied entry is a removed entry.
                source: event.currentTarget.value || null,
              })
            }
          />
        </InspectorField>
      )}
    </For>
  );

  return (
    <InspectorSection title="Shared with this canvas's artifacts">
      {entries('styles', (entry) => `Style: ${entry}`)}
      {entries('components', (entry) => `Component: ${entry}`)}
      <Input
        size="sm"
        aria-label="New shared entry name"
        placeholder="Name"
        value={name()}
        onInput={(event) => setName(event.currentTarget.value)}
      />
      <div class="flex gap-1">
        <Button variant="primary" size="sm" onClick={() => add('styles')}>
          Add style
        </Button>
        <Button variant="primary" size="sm" onClick={() => add('components')}>
          Add component
        </Button>
      </div>
    </InspectorSection>
  );
}