artifactuse 0.1.24 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,7 @@ Artifactuse is a lightweight SDK that transforms AI-generated content into rich,
8
8
 
9
9
  - 🎨 **Rich Content Detection** - Automatically detect and render code blocks, images, videos, maps, embeds, and more
10
10
  - 📦 **Artifact Cards** - Beautiful inline cards for code artifacts
11
+ - 👁️ **Inline Code Preview** - Truncated syntax-highlighted code previews with click-to-open panel
11
12
  - 🖼️ **Media Lightbox** - Click images and PDFs to view fullscreen with zoom and download
12
13
  - 🖥️ **Panel Viewer** - Side panel with preview, code view, and split mode
13
14
  - 📝 **Interactive Forms** - Inline and panel forms with 17+ field types, auto-collapse after submission
@@ -421,11 +422,45 @@ Panel artifacts open in a side panel with preview, code view, and editing capabi
421
422
  - **HTML/React/Vue** - Live preview with code editing
422
423
  - **Mermaid** - Diagrams with live preview
423
424
  - **SVG** - SVG graphics with live preview and editing
424
- - **Diff / Patch** - Code diffs with side-by-side or unified view
425
+ - **Diff / Patch** - Code diffs with side-by-side or unified view (`diff`, `patch`, or `smartdiff` for structured JSON diffs)
425
426
  - **Canvas / Whiteboard** - Interactive drawing canvas and whiteboard
426
427
  - **Video Editor** - Timeline-based video editing interface
427
428
  - **Forms (Panel)** - Complex forms with wizard variant, file uploads, or 4+ fields
428
429
 
430
+ #### Inline Code Preview (Optional)
431
+
432
+ By default, extracted code blocks render as compact artifact cards. With `inlinePreview` enabled, they show a **truncated syntax-highlighted preview** (first N lines) directly in the message. Click the preview to open the full artifact in the panel.
433
+
434
+ - Configurable per language — unlisted languages still render as cards
435
+ - Requires [Prism.js](https://prismjs.com/) for syntax highlighting (see [Syntax Highlighting](#syntax-highlighting))
436
+ - `smartdiff` artifacts use the actual language for full syntax highlighting with deleted/inserted backgrounds
437
+ - Truncated previews show a fade gradient with "View full code (N lines)" label
438
+
439
+ ```js
440
+ provideArtifactuse({
441
+ inlinePreview: {
442
+ maxLines: 15,
443
+ languages: ['smartdiff', 'html', 'javascript'],
444
+ },
445
+ });
446
+ ```
447
+
448
+ All config options (`inlinePreview`, `inlineCode`, `tabs`, `viewMode`, `inlineCards`) also work as component props for per-message overrides. Precedence: **component prop → global config → default**.
449
+
450
+ #### Inline Code (Optional)
451
+
452
+ Show full syntax-highlighted code directly in the message without extraction or panel:
453
+
454
+ ```js
455
+ provideArtifactuse({
456
+ inlineCode: {
457
+ languages: ['css', 'bash', 'sql'], // or true for all
458
+ },
459
+ });
460
+ ```
461
+
462
+ When a language matches both `inlineCode` and `inlinePreview`, `inlineCode` takes priority (no extraction).
463
+
429
464
  ### Inline Artifacts
430
465
 
431
466
  Inline artifacts render directly within the message.
@@ -531,6 +566,7 @@ const {
531
566
  // Programmatic API
532
567
  openFile, // Open file in panel (auto-detect language from extension)
533
568
  openCode, // Open code in panel (explicit language)
569
+ updateFile, // Update existing artifact's code and refresh panel
534
570
  clearArtifacts, // Clear all artifacts
535
571
 
536
572
  // Panel management
@@ -591,6 +627,30 @@ provideArtifactuse({
591
627
  minLength: 50,
592
628
  },
593
629
 
630
+ // Inline preview: show truncated code inline instead of artifact cards (optional)
631
+ // Default: null (disabled — all extracted code shows as cards)
632
+ inlinePreview: {
633
+ maxLines: 15, // max lines before truncation
634
+ languages: ['smartdiff', 'html', 'javascript', 'jsx'], // or true for all extracted languages
635
+ },
636
+
637
+ // Inline code: show full code inline with Prism highlighting, no extraction (optional)
638
+ // Default: null (disabled). Takes priority over inlinePreview when both match.
639
+ inlineCode: {
640
+ languages: ['css', 'bash', 'sql'], // or true for all
641
+ },
642
+
643
+ // Show clickable artifact cards inline (default: true)
644
+ inlineCards: true,
645
+
646
+ // Visible panel tabs for all extracted artifacts (optional)
647
+ // Default: null (all tabs shown). Options: 'preview', 'code', 'split', 'edit'
648
+ tabs: ['preview', 'code'],
649
+
650
+ // Initial panel view mode for all extracted artifacts (optional)
651
+ // Default: null (first available tab). Options: 'preview', 'code', 'split', 'edit'
652
+ viewMode: 'preview',
653
+
594
654
  // Code Editor (Optional) — CodeMirror 6 for the edit tab
595
655
  // Requires: @codemirror/state, @codemirror/view, @codemirror/commands,
596
656
  // @codemirror/language, @codemirror/autocomplete
@@ -758,6 +818,31 @@ openCode(pythonCode, 'python', { title: 'My Script', tabs: ['code', 'edit'] });
758
818
 
759
819
  > **Note:** If the language has no registered panel, it falls back to `txt` (plain text) in the code panel.
760
820
 
821
+ ### updateFile
822
+
823
+ Updates an existing artifact's code in place and refreshes the panel (no duplicate tabs):
824
+
825
+ ```js
826
+ const { openFile, updateFile } = useArtifactuse();
827
+
828
+ // First open — returns artifact reference
829
+ const artifact = openFile('app.html', code, { panelUrl: '...' });
830
+
831
+ // Later — update in place, refreshes iframe
832
+ updateFile(artifact, newCode);
833
+ updateFile(artifact.id, newCode, { panelUrl: newUrl });
834
+ ```
835
+
836
+ | Parameter | Type | Required | Description |
837
+ |-----------|------|----------|-------------|
838
+ | `artifact` | `object\|string` | Yes | Artifact object (from `openFile`) or artifact ID string |
839
+ | `code` | `string` | Yes | New code content |
840
+ | `options.title` | `string` | No | Update display title |
841
+ | `options.tabs` | `string[]` | No | Update visible tabs |
842
+ | `options.panelUrl` | `string` | No | Update custom iframe URL |
843
+
844
+ > **Note:** `updateFile` triggers the `artifact:updated` event with `{ artifactId, artifact }`.
845
+
761
846
  ### clearArtifacts
762
847
 
763
848
  Removes all artifacts and closes the panel:
@@ -54,6 +54,11 @@ export function decodeJsonFromAttribute(encoded: any): any;
54
54
  * Extract title from code content
55
55
  */
56
56
  export function extractArtifactTitle(code: any, language: any): any;
57
+ /**
58
+ * Compute a simple line-by-line diff for inline preview display
59
+ * Produces +/- prefixed lines that Prism highlights with language-diff
60
+ */
61
+ export function computeSimpleDiff(oldCode: any, newCode: any): string;
57
62
  /**
58
63
  * Determine if form should render inline or in panel
59
64
  * Parses JSON from code to check complexity
@@ -36,7 +36,7 @@ export function createArtifactuse(userConfig?: {}): {
36
36
  isFullscreen: boolean;
37
37
  };
38
38
  subscribe: (callback: any) => () => void;
39
- processMessage: (content: any, messageId: any) => {
39
+ processMessage: (content: any, messageId: any, overrides?: {}) => {
40
40
  html: string | Promise<string>;
41
41
  artifacts: any[];
42
42
  };
@@ -70,6 +70,7 @@ export function createArtifactuse(userConfig?: {}): {
70
70
  lineCount: number;
71
71
  createdAt: string;
72
72
  };
73
+ updateFile: (artifactOrId: any, code: any, options?: {}) => any;
73
74
  closePanel: () => void;
74
75
  togglePanel: () => void;
75
76
  toggleFullscreen: () => void;
@@ -159,6 +160,7 @@ export namespace DEFAULT_PANELS {
159
160
  let svg: string;
160
161
  let diff: string;
161
162
  let patch: string;
163
+ let smartdiff: string;
162
164
  let txt: string;
163
165
  let javascript: string;
164
166
  let js: string;