wgsl-edit 0.0.13 → 0.0.14

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.
@@ -126,12 +126,17 @@ var WgslEdit = class extends HTMLElement {
126
126
  this.updateLint();
127
127
  this.dispatchChange();
128
128
  }
129
- /** Active file content (backward compatible). */
129
+ /** Active file content (single-file API). */
130
130
  get source() {
131
131
  return this.editorView?.state.doc.toString() ?? this._pendingSource ?? "";
132
132
  }
133
- /** Set active file content (backward compatible). */
133
+ /** Set active file content (single-file API). Auto-creates a default file entry. */
134
134
  set source(value) {
135
+ if (!this._activeFile && this._files.size === 0) {
136
+ this._files.set("main.wesl", { doc: Text.of(value.split("\n")) });
137
+ this._activeFile = "main.wesl";
138
+ this.renderTabs();
139
+ }
135
140
  if (this.editorView) {
136
141
  const to = this.editorView.state.doc.length;
137
142
  this.editorView.dispatch({ changes: {
@@ -139,7 +144,11 @@ var WgslEdit = class extends HTMLElement {
139
144
  to,
140
145
  insert: value
141
146
  } });
142
- } else this._pendingSource = value;
147
+ } else {
148
+ this._pendingSource = value;
149
+ const entry = this._files.get(this._activeFile);
150
+ if (entry) entry.doc = Text.of(value.split("\n"));
151
+ }
143
152
  }
144
153
  /** All file contents keyed by module path (e.g., "package::main"). */
145
154
  get sources() {
@@ -347,6 +356,10 @@ var WgslEdit = class extends HTMLElement {
347
356
  const initialDoc = this._pendingSource ?? (firstFile ? this._files.get(firstFile).doc.toString() : "");
348
357
  this._pendingSource = null;
349
358
  if (firstFile) this._activeFile = firstFile;
359
+ else if (initialDoc) {
360
+ this._files.set("main.wesl", { doc: Text.of(initialDoc.split("\n")) });
361
+ this._activeFile = "main.wesl";
362
+ }
350
363
  this.editorView = new EditorView({
351
364
  state: EditorState.create({
352
365
  doc: initialDoc,
@@ -40,9 +40,9 @@ declare class WgslEdit extends HTMLElement {
40
40
  /** Conditions for conditional compilation (@if/@elif/@else). */
41
41
  get conditions(): Conditions;
42
42
  set conditions(value: Conditions);
43
- /** Active file content (backward compatible). */
43
+ /** Active file content (single-file API). */
44
44
  get source(): string;
45
- /** Set active file content (backward compatible). */
45
+ /** Set active file content (single-file API). Auto-creates a default file entry. */
46
46
  set source(value: string);
47
47
  /** All file contents keyed by module path (e.g., "package::main"). */
48
48
  get sources(): Record<string, string>;
package/dist/WgslEdit.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./Language.js";
2
- import { t as WgslEdit } from "./WgslEdit-BSUXQfGS.js";
2
+ import { t as WgslEdit } from "./WgslEdit-CWF7QS5Y.js";
3
3
 
4
4
  export { WgslEdit };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { wesl, weslLanguage } from "./Language.js";
2
- import { t as WgslEdit } from "./WgslEdit-BSUXQfGS.js";
2
+ import { t as WgslEdit } from "./WgslEdit-CWF7QS5Y.js";
3
3
 
4
4
  //#region src/index.ts
5
5
  if (!customElements.get("wgsl-edit")) customElements.define("wgsl-edit", WgslEdit);
package/dist/wgsl-edit.js CHANGED
@@ -28400,12 +28400,17 @@ var WgslEdit = class extends HTMLElement {
28400
28400
  this.updateLint();
28401
28401
  this.dispatchChange();
28402
28402
  }
28403
- /** Active file content (backward compatible). */
28403
+ /** Active file content (single-file API). */
28404
28404
  get source() {
28405
28405
  return this.editorView?.state.doc.toString() ?? this._pendingSource ?? "";
28406
28406
  }
28407
- /** Set active file content (backward compatible). */
28407
+ /** Set active file content (single-file API). Auto-creates a default file entry. */
28408
28408
  set source(value) {
28409
+ if (!this._activeFile && this._files.size === 0) {
28410
+ this._files.set("main.wesl", { doc: Text.of(value.split("\n")) });
28411
+ this._activeFile = "main.wesl";
28412
+ this.renderTabs();
28413
+ }
28409
28414
  if (this.editorView) {
28410
28415
  const to = this.editorView.state.doc.length;
28411
28416
  this.editorView.dispatch({ changes: {
@@ -28413,7 +28418,11 @@ var WgslEdit = class extends HTMLElement {
28413
28418
  to,
28414
28419
  insert: value
28415
28420
  } });
28416
- } else this._pendingSource = value;
28421
+ } else {
28422
+ this._pendingSource = value;
28423
+ const entry = this._files.get(this._activeFile);
28424
+ if (entry) entry.doc = Text.of(value.split("\n"));
28425
+ }
28417
28426
  }
28418
28427
  /** All file contents keyed by module path (e.g., "package::main"). */
28419
28428
  get sources() {
@@ -28621,6 +28630,10 @@ var WgslEdit = class extends HTMLElement {
28621
28630
  const initialDoc = this._pendingSource ?? (firstFile ? this._files.get(firstFile).doc.toString() : "");
28622
28631
  this._pendingSource = null;
28623
28632
  if (firstFile) this._activeFile = firstFile;
28633
+ else if (initialDoc) {
28634
+ this._files.set("main.wesl", { doc: Text.of(initialDoc.split("\n")) });
28635
+ this._activeFile = "main.wesl";
28636
+ }
28624
28637
  this.editorView = new EditorView({
28625
28638
  state: EditorState.create({
28626
28639
  doc: initialDoc,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wgsl-edit",
3
3
  "description": "Web component for editing WGSL/WESL with CodeMirror",
4
- "version": "0.0.13",
4
+ "version": "0.0.14",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
package/src/WgslEdit.ts CHANGED
@@ -194,18 +194,25 @@ export class WgslEdit extends HTMLElement {
194
194
  this.dispatchChange();
195
195
  }
196
196
 
197
- /** Active file content (backward compatible). */
197
+ /** Active file content (single-file API). */
198
198
  get source(): string {
199
199
  return this.editorView?.state.doc.toString() ?? this._pendingSource ?? "";
200
200
  }
201
201
 
202
- /** Set active file content (backward compatible). */
202
+ /** Set active file content (single-file API). Auto-creates a default file entry. */
203
203
  set source(value: string) {
204
+ if (!this._activeFile && this._files.size === 0) {
205
+ this._files.set("main.wesl", { doc: Text.of(value.split("\n")) });
206
+ this._activeFile = "main.wesl";
207
+ this.renderTabs();
208
+ }
204
209
  if (this.editorView) {
205
210
  const to = this.editorView.state.doc.length;
206
211
  this.editorView.dispatch({ changes: { from: 0, to, insert: value } });
207
212
  } else {
208
213
  this._pendingSource = value;
214
+ const entry = this._files.get(this._activeFile);
215
+ if (entry) entry.doc = Text.of(value.split("\n"));
209
216
  }
210
217
  }
211
218
 
@@ -444,7 +451,12 @@ export class WgslEdit extends HTMLElement {
444
451
  this._pendingSource ??
445
452
  (firstFile ? this._files.get(firstFile)!.doc.toString() : "");
446
453
  this._pendingSource = null;
447
- if (firstFile) this._activeFile = firstFile;
454
+ if (firstFile) {
455
+ this._activeFile = firstFile;
456
+ } else if (initialDoc) {
457
+ this._files.set("main.wesl", { doc: Text.of(initialDoc.split("\n")) });
458
+ this._activeFile = "main.wesl";
459
+ }
448
460
 
449
461
  const state = EditorState.create({
450
462
  doc: initialDoc,