artifactuse 0.1.20 → 0.1.22

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
@@ -525,9 +525,14 @@ const {
525
525
  closePanel, // Close panel
526
526
  togglePanel, // Toggle panel visibility
527
527
  toggleFullscreen, // Toggle fullscreen mode
528
- setViewMode, // Set 'preview' | 'code' | 'split'
528
+ setViewMode, // Set 'preview' | 'code' | 'split' | 'edit'
529
529
  getPanelUrl, // Get panel URL for artifact
530
-
530
+
531
+ // Programmatic API
532
+ openFile, // Open file in panel (auto-detect language from extension)
533
+ openCode, // Open code in panel (explicit language)
534
+ clearArtifacts, // Clear all artifacts
535
+
531
536
  // Panel management
532
537
  hasPanel, // Check if panel exists for artifact
533
538
  registerPanel, // Register panel (string or string[])
@@ -585,6 +590,24 @@ provideArtifactuse({
585
590
  minLines: 3,
586
591
  minLength: 50,
587
592
  },
593
+
594
+ // Code Editor (Optional) — CodeMirror 6 for the edit tab
595
+ // Requires: @codemirror/state, @codemirror/view, @codemirror/commands,
596
+ // @codemirror/language, @codemirror/autocomplete
597
+ // Optional: @codemirror/lang-javascript, @codemirror/lang-python, @lezer/highlight
598
+ editor: {
599
+ modules: {
600
+ state: cmState, // @codemirror/state
601
+ view: cmView, // @codemirror/view
602
+ commands: cmCommands, // @codemirror/commands
603
+ language: cmLanguage, // @codemirror/language
604
+ autocomplete: cmAutocomplete, // @codemirror/autocomplete
605
+ langJavascript: cmLangJavascript, // @codemirror/lang-javascript
606
+ langPython: cmLangPython, // @codemirror/lang-python
607
+ lezerHighlight: lezerHighlight, // @lezer/highlight (for syntax colors)
608
+ },
609
+ theme: 'dark', // 'dark' | 'light' | 'auto'
610
+ },
588
611
  });
589
612
  ```
590
613
 
@@ -658,6 +681,71 @@ on('social:copy', ({ platform, text }) => {
658
681
  on('media:open', ({ type, src, alt, caption }) => {
659
682
  console.log('Media opened:', type, src);
660
683
  });
684
+
685
+ // Code editor saved (edit tab)
686
+ on('edit:save', ({ artifactId, artifact, code }) => {
687
+ console.log('Code saved:', code);
688
+ });
689
+ ```
690
+
691
+ ## Programmatic API
692
+
693
+ Open artifacts directly without processing AI message content:
694
+
695
+ ### openFile
696
+
697
+ Opens a file in the panel, auto-detecting the language from the file extension:
698
+
699
+ ```js
700
+ const { openFile } = useArtifactuse();
701
+
702
+ // Basic usage
703
+ openFile('app.jsx', code);
704
+
705
+ // With options
706
+ openFile('utils.py', code, {
707
+ title: 'My Utils', // Custom display title (defaults to filename)
708
+ tabs: ['code', 'edit'], // Control which tabs are visible
709
+ viewMode: 'code', // Initial view mode
710
+ });
711
+ ```
712
+
713
+ | Parameter | Type | Required | Description |
714
+ |-----------|------|----------|-------------|
715
+ | `filename` | `string` | Yes | Filename with extension (e.g. `'app.jsx'`, `'style.css'`) |
716
+ | `code` | `string` | Yes | The file content |
717
+ | `options.title` | `string` | No | Custom title (defaults to filename) |
718
+ | `options.tabs` | `string[]` | No | Visible tabs: `'preview'`, `'code'`, `'split'`, `'edit'` |
719
+ | `options.viewMode` | `string` | No | Initial view mode |
720
+ | `options.language` | `string` | No | Override auto-detected language |
721
+
722
+ ### openCode
723
+
724
+ Opens code in the panel with an explicit language:
725
+
726
+ ```js
727
+ const { openCode } = useArtifactuse();
728
+
729
+ openCode('console.log("hello")', 'javascript');
730
+ openCode(pythonCode, 'python', { title: 'My Script', tabs: ['code', 'edit'] });
731
+ ```
732
+
733
+ | Parameter | Type | Required | Description |
734
+ |-----------|------|----------|-------------|
735
+ | `code` | `string` | Yes | The code content |
736
+ | `language` | `string` | Yes | Language identifier (e.g. `'javascript'`, `'python'`, `'html'`) |
737
+ | `options` | `object` | No | Same options as `openFile` |
738
+
739
+ > **Note:** If the language has no registered panel, it falls back to `txt` (plain text) in the code panel.
740
+
741
+ ### clearArtifacts
742
+
743
+ Removes all artifacts and closes the panel:
744
+
745
+ ```js
746
+ const { clearArtifacts } = useArtifactuse();
747
+
748
+ clearArtifacts();
661
749
  ```
662
750
 
663
751
  ## Framework Support
@@ -22,6 +22,10 @@ export function getLanguageDisplayName(language: any): any;
22
22
  * Get file extension for language/type
23
23
  */
24
24
  export function getFileExtension(language: any): any;
25
+ /**
26
+ * Get language from file extension (reverse of getFileExtension)
27
+ */
28
+ export function getLanguageFromExtension(ext: any): any;
25
29
  /**
26
30
  * Get language/type icon SVG path
27
31
  */
@@ -59,6 +63,29 @@ export function shouldFormBeInline(code: any): boolean;
59
63
  * Determine if artifact should be inline based on language
60
64
  */
61
65
  export function getIsInline(language: any, code: any): boolean;
66
+ /**
67
+ * Create artifact from code block
68
+ * Unified method for all artifact types (code, form, social)
69
+ *
70
+ * @param {string} code - Code/JSON content
71
+ * @param {string} language - Language identifier (js, html, form, social, etc.)
72
+ * @param {string} messageId - Message ID
73
+ * @param {number} blockIndex - Block index
74
+ */
75
+ export function createArtifact(code: string, language: string, messageId: string, blockIndex: number): {
76
+ id: string;
77
+ messageId: string;
78
+ type: string;
79
+ language: string;
80
+ title: any;
81
+ code: string;
82
+ isInline: boolean;
83
+ isPreviewable: boolean;
84
+ isPanelArtifact: boolean;
85
+ size: number;
86
+ lineCount: number;
87
+ createdAt: string;
88
+ };
62
89
  /**
63
90
  * Parse artifacts from rendered HTML (simple detection, no replacement)
64
91
  */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Create an editor manager that uses user-provided CodeMirror modules
3
+ *
4
+ * @param {object} editorConfig - config.editor from SDK config
5
+ * @param {object} editorConfig.modules - CodeMirror module imports
6
+ * @param {string} editorConfig.theme - 'dark' | 'light' | 'auto'
7
+ * @returns {object} Editor manager with create/destroy methods
8
+ */
9
+ export function createEditorManager(editorConfig?: {
10
+ modules: object;
11
+ theme: string;
12
+ }): object;
13
+ export default createEditorManager;
@@ -42,6 +42,34 @@ export function createArtifactuse(userConfig?: {}): {
42
42
  };
43
43
  initializeContent: (container?: Document) => Promise<void>;
44
44
  openArtifact: (artifact: any) => void;
45
+ openFile: (filename: any, code: any, options?: {}) => {
46
+ id: string;
47
+ messageId: string;
48
+ type: string;
49
+ language: string;
50
+ title: any;
51
+ code: string;
52
+ isInline: boolean;
53
+ isPreviewable: boolean;
54
+ isPanelArtifact: boolean;
55
+ size: number;
56
+ lineCount: number;
57
+ createdAt: string;
58
+ };
59
+ openCode: (code: any, language: any, options?: {}) => {
60
+ id: string;
61
+ messageId: string;
62
+ type: string;
63
+ language: string;
64
+ title: any;
65
+ code: string;
66
+ isInline: boolean;
67
+ isPreviewable: boolean;
68
+ isPanelArtifact: boolean;
69
+ size: number;
70
+ lineCount: number;
71
+ createdAt: string;
72
+ };
45
73
  closePanel: () => void;
46
74
  togglePanel: () => void;
47
75
  toggleFullscreen: () => void;
@@ -73,6 +101,7 @@ export function createArtifactuse(userConfig?: {}): {
73
101
  on: (event: any, callback: any) => () => void;
74
102
  off: (event: any, callback: any) => void;
75
103
  emit: (event: any, data: any) => void;
104
+ editor: any;
76
105
  bridge: {
77
106
  setIframe: (iframe: any) => void;
78
107
  send: (action: string, data: any, requestId?: string, targetOrigin?: string) => string;
@@ -116,6 +145,7 @@ export * from "./highlight.js";
116
145
  export { createState } from "./state.js";
117
146
  export { createBridge } from "./bridge.js";
118
147
  export { createTheme } from "./theme.js";
148
+ export { createEditorManager } from "./editor.js";
119
149
  export default createArtifactuse;
120
150
  export namespace DEFAULT_PANELS {
121
151
  let form: string;
@@ -129,6 +159,7 @@ export namespace DEFAULT_PANELS {
129
159
  let svg: string;
130
160
  let diff: string;
131
161
  let patch: string;
162
+ let txt: string;
132
163
  let javascript: string;
133
164
  let js: string;
134
165
  let python: string;