wgsl-edit 0.0.25 → 0.0.26

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.
@@ -3,6 +3,19 @@ import { Conditions, LinkParams, WeslBundle, WeslProject } from "wesl";
3
3
  //#region src/WgslEdit.d.ts
4
4
  type Theme = "light" | "dark" | "auto";
5
5
  type LintMode = "on" | "off";
6
+ /** `autosave` CustomEvent detail: full project snapshot + dirty file names. */
7
+ interface AutosaveDetail {
8
+ project: WeslProject;
9
+ dirty: string[];
10
+ }
11
+ /** Attributes accepted by `<wgsl-edit>` beyond standard HTML.
12
+ * Source of truth for framework-specific JSX augmentations (see `./jsx-preact.ts`). */
13
+ interface WgslEditAttrs {
14
+ /** Color theme; `"auto"` follows `prefers-color-scheme`. */
15
+ theme?: "light" | "dark" | "auto";
16
+ /** ID of an element (e.g. `<wgsl-play>`) to source compile diagnostics from. */
17
+ "lint-from"?: string;
18
+ }
6
19
  declare class WgslEdit extends HTMLElement {
7
20
  static observedAttributes: string[];
8
21
  private editorView;
@@ -32,6 +45,10 @@ declare class WgslEdit extends HTMLElement {
32
45
  private _fetchingPkgs;
33
46
  private _fetchedPkgs;
34
47
  private _snackTimer;
48
+ private _devSaveListener;
49
+ private _saveTimer;
50
+ private _dirtyFiles;
51
+ private _switchingFile;
35
52
  private _externalDiagnostics;
36
53
  private _lintFromEl;
37
54
  /** Bound listeners for lint-from element's compile events. */
@@ -44,6 +61,8 @@ declare class WgslEdit extends HTMLElement {
44
61
  /** Conditions for conditional compilation (@if/@elif/@else). */
45
62
  get conditions(): Conditions;
46
63
  set conditions(value: Conditions);
64
+ /** Reconfigure a compartment via the active editor view (no-op if unmounted). */
65
+ private reconfigure;
47
66
  /** Active file content (single-file API). */
48
67
  get source(): string;
49
68
  /** Set active file content (single-file API). Auto-creates a default file entry. */
@@ -52,6 +71,7 @@ declare class WgslEdit extends HTMLElement {
52
71
  get sources(): Record<string, string>;
53
72
  /** Set all files (replaces existing). */
54
73
  set sources(value: Record<string, string>);
74
+ /** Snapshot of all editor state needed to link: sources, conditions, libs, root module. */
55
75
  get project(): WeslProject;
56
76
  set project(value: WeslProject);
57
77
  /** Link/compile WESL sources into WGSL. Returns the compiled WGSL string. */
@@ -75,6 +95,10 @@ declare class WgslEdit extends HTMLElement {
75
95
  /** GPU validation of linked WGSL (default: true). Set to false to disable. */
76
96
  get gpuLint(): boolean;
77
97
  set gpuLint(value: boolean);
98
+ /** Persist edits to disk via the dev-server save endpoint.
99
+ * Requires `wgslEditAutosave()` to be installed in vite.config.ts. */
100
+ get autosave(): boolean;
101
+ set autosave(value: boolean);
78
102
  /** Whether to auto-fetch missing library packages from npm (default: true). */
79
103
  get fetchLibs(): boolean;
80
104
  set fetchLibs(value: boolean);
@@ -89,16 +113,34 @@ declare class WgslEdit extends HTMLElement {
89
113
  set theme(value: Theme);
90
114
  get shaderRoot(): string | null;
91
115
  set shaderRoot(value: string | null);
116
+ /** Add a new file and switch to it. No-op if `name` already exists. */
92
117
  addFile(name: string, content?: string): void;
118
+ /** Remove a file. No-op if it is missing or is the last remaining file. */
93
119
  removeFile(name: string): void;
120
+ /** Rename a file, preserving its document and editor state. No-op on collision. */
94
121
  renameFile(oldName: string, newName: string): void;
95
122
  /** Switch to a file, saving current state and restoring target state. */
96
123
  private switchToFile;
124
+ /** Build a fresh EditorState seeded with `doc` and the current extension set. */
125
+ private createFileState;
97
126
  private saveCurrentFileState;
127
+ private pkgName;
128
+ private activeModulePath;
98
129
  private dispatchChange;
99
130
  private dispatchFileChange;
131
+ private scheduleAutosave;
132
+ /** Dispatch an `autosave` event with a fresh project snapshot and the dirty-file list. */
133
+ private fireAutosave;
134
+ private enableDevSave;
135
+ private disableDevSave;
136
+ /** Built-in `autosave` listener: POST each dirty file to the dev-server save endpoint. */
137
+ private devSave;
138
+ /** One-shot disable on first failure: avoids spamming the console on every keystroke. */
139
+ private devSaveFailed;
140
+ /** First-time setup: read attributes, parse inline content, mount the EditorView. */
100
141
  private initEditor;
101
142
  private readInitialAttributes;
143
+ /** Assemble the full CodeMirror extension set for a fresh EditorState. */
102
144
  private buildExtensions;
103
145
  private resolveTheme;
104
146
  private updateTheme;
@@ -111,6 +153,7 @@ declare class WgslEdit extends HTMLElement {
111
153
  private updateLint;
112
154
  /** Listen for compile-error/compile-success events from a lint source element. */
113
155
  private connectLintSource;
156
+ /** Convert external compile-error locations into CodeMirror diagnostics for the active file. */
114
157
  private onCompileError;
115
158
  private onCompileSuccess;
116
159
  private resolveLineNumbers;
@@ -120,9 +163,10 @@ declare class WgslEdit extends HTMLElement {
120
163
  private renderTabs;
121
164
  private createTab;
122
165
  private createAddButton;
166
+ /** Replace the tab name span with an editable input; commit on Enter/blur, cancel on Escape. */
123
167
  private startRenameTab;
124
168
  private loadFromUrl;
125
169
  private loadInitialContent;
126
170
  }
127
171
  //#endregion
128
- export { WgslEdit };
172
+ export { AutosaveDetail, WgslEdit, WgslEditAttrs };
package/dist/WgslEdit.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./Language.js";
2
- import { t as WgslEdit } from "./WgslEdit-ByXfb3R9.js";
2
+ import { t as WgslEdit } from "./WgslEdit-CNK80480.js";
3
3
  export { WgslEdit };
@@ -0,0 +1,11 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/autosave.d.ts
4
+ interface WgslEditAutosaveOptions {
5
+ /** Disable the save endpoint without removing the plugin (default: enabled). */
6
+ disabled?: boolean;
7
+ }
8
+ /** Vite dev plugin: lets <wgsl-edit autosave> persist edits to disk via the save endpoint. */
9
+ declare function wgslEditAutosave(options?: WgslEditAutosaveOptions): Plugin;
10
+ //#endregion
11
+ export { WgslEditAutosaveOptions, wgslEditAutosave as default };
@@ -0,0 +1,18 @@
1
+ import { pendingSaves, weslSaveMiddleware } from "./SaveMiddleware.mjs";
2
+ //#region src/autosave.ts
3
+ /** Vite dev plugin: lets <wgsl-edit autosave> persist edits to disk via the save endpoint. */
4
+ function wgslEditAutosave(options) {
5
+ return {
6
+ name: "wgsl-edit-autosave",
7
+ apply: "serve",
8
+ configureServer(server) {
9
+ if (options?.disabled) return;
10
+ server.middlewares.use(weslSaveMiddleware(server.config.root));
11
+ },
12
+ hotUpdate({ file }) {
13
+ if (pendingSaves.delete(file)) return [];
14
+ }
15
+ };
16
+ }
17
+ //#endregion
18
+ export { wgslEditAutosave as default };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { wesl, weslLanguage } from "./Language.js";
2
- import { t as WgslEdit } from "./WgslEdit-ByXfb3R9.js";
2
+ import { t as WgslEdit } from "./WgslEdit-CNK80480.js";
3
3
  //#region src/index.ts
4
4
  if (!customElements.get("wgsl-edit")) customElements.define("wgsl-edit", WgslEdit);
5
5
  //#endregion
@@ -0,0 +1,12 @@
1
+ import { WgslEdit, WgslEditAttrs } from "./WgslEdit.js";
2
+ import { HTMLAttributes } from "preact";
3
+
4
+ //#region src/jsx-preact.d.ts
5
+ type WgslEditTag = HTMLAttributes<WgslEdit> & WgslEditAttrs;
6
+ declare module "preact" {
7
+ namespace JSX {
8
+ interface IntrinsicElements {
9
+ "wgsl-edit": WgslEditTag;
10
+ }
11
+ }
12
+ }
File without changes