artifactuse 0.1.23 → 0.1.25

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
@@ -531,6 +531,7 @@ const {
531
531
  // Programmatic API
532
532
  openFile, // Open file in panel (auto-detect language from extension)
533
533
  openCode, // Open code in panel (explicit language)
534
+ updateFile, // Update existing artifact's code and refresh panel
534
535
  clearArtifacts, // Clear all artifacts
535
536
 
536
537
  // Panel management
@@ -594,17 +595,36 @@ provideArtifactuse({
594
595
  // Code Editor (Optional) — CodeMirror 6 for the edit tab
595
596
  // Requires: @codemirror/state, @codemirror/view, @codemirror/commands,
596
597
  // @codemirror/language, @codemirror/autocomplete
597
- // Optional: @codemirror/lang-javascript, @codemirror/lang-python, @lezer/highlight
598
+ // Optional: language packages and @lezer/highlight (for syntax highlighting)
598
599
  editor: {
599
600
  modules: {
601
+ // Required
600
602
  state: cmState, // @codemirror/state
601
603
  view: cmView, // @codemirror/view
602
604
  commands: cmCommands, // @codemirror/commands
603
605
  language: cmLanguage, // @codemirror/language
604
606
  autocomplete: cmAutocomplete, // @codemirror/autocomplete
605
- langJavascript: cmLangJavascript, // @codemirror/lang-javascript
607
+ // Syntax highlighting (optional)
608
+ lezerHighlight: lezerHighlight, // @lezer/highlight
609
+ // Language packages (all optional — add only what you need)
610
+ langJavascript: cmLangJavascript, // @codemirror/lang-javascript (js/jsx/ts/tsx)
606
611
  langPython: cmLangPython, // @codemirror/lang-python
607
- lezerHighlight: lezerHighlight, // @lezer/highlight (for syntax colors)
612
+ langHtml: cmLangHtml, // @codemirror/lang-html
613
+ langCss: cmLangCss, // @codemirror/lang-css
614
+ langJson: cmLangJson, // @codemirror/lang-json
615
+ langMarkdown: cmLangMarkdown, // @codemirror/lang-markdown
616
+ langXml: cmLangXml, // @codemirror/lang-xml
617
+ langYaml: cmLangYaml, // @codemirror/lang-yaml
618
+ langSql: cmLangSql, // @codemirror/lang-sql
619
+ langJava: cmLangJava, // @codemirror/lang-java
620
+ langCpp: cmLangCpp, // @codemirror/lang-cpp (c/c++)
621
+ langGo: cmLangGo, // @codemirror/lang-go
622
+ langRust: cmLangRust, // @codemirror/lang-rust
623
+ langPhp: cmLangPhp, // @codemirror/lang-php
624
+ langVue: cmLangVue, // @codemirror/lang-vue
625
+ langAngular: cmLangAngular, // @codemirror/lang-angular
626
+ langLess: cmLangLess, // @codemirror/lang-less
627
+ langSass: cmLangSass, // @codemirror/lang-sass (sass/scss)
608
628
  },
609
629
  theme: 'dark', // 'dark' | 'light' | 'auto'
610
630
  },
@@ -739,6 +759,31 @@ openCode(pythonCode, 'python', { title: 'My Script', tabs: ['code', 'edit'] });
739
759
 
740
760
  > **Note:** If the language has no registered panel, it falls back to `txt` (plain text) in the code panel.
741
761
 
762
+ ### updateFile
763
+
764
+ Updates an existing artifact's code in place and refreshes the panel (no duplicate tabs):
765
+
766
+ ```js
767
+ const { openFile, updateFile } = useArtifactuse();
768
+
769
+ // First open — returns artifact reference
770
+ const artifact = openFile('app.html', code, { panelUrl: '...' });
771
+
772
+ // Later — update in place, refreshes iframe
773
+ updateFile(artifact, newCode);
774
+ updateFile(artifact.id, newCode, { panelUrl: newUrl });
775
+ ```
776
+
777
+ | Parameter | Type | Required | Description |
778
+ |-----------|------|----------|-------------|
779
+ | `artifact` | `object\|string` | Yes | Artifact object (from `openFile`) or artifact ID string |
780
+ | `code` | `string` | Yes | New code content |
781
+ | `options.title` | `string` | No | Update display title |
782
+ | `options.tabs` | `string[]` | No | Update visible tabs |
783
+ | `options.panelUrl` | `string` | No | Update custom iframe URL |
784
+
785
+ > **Note:** `updateFile` triggers the `artifact:updated` event with `{ artifactId, artifact }`.
786
+
742
787
  ### clearArtifacts
743
788
 
744
789
  Removes all artifacts and closes the panel:
@@ -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;