@nonoun/native-playground 0.2.14 → 0.2.15

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.
@@ -1,2 +1,2 @@
1
- import { a as e, i as t, n, r, t as i } from "./playground-element-ZQhZxB3I.js";
1
+ import { a as e, i as t, n, r, t as i } from "./playground-element-FVaaBTmI.js";
2
2
  export { i as NPlayground, r as TAB_LABELS, n as buildSrcdoc, e as createPlaygroundStore, t as getLanguageExtension };
@@ -124,13 +124,15 @@ var p = [
124
124
  #u = [];
125
125
  #d = null;
126
126
  #f = null;
127
+ #p = null;
128
+ #m = [];
127
129
  /** Manually trigger a preview update. */
128
130
  run() {
129
- return this.#y();
131
+ return this.#x();
130
132
  }
131
133
  /** Reset all code to initial values. */
132
134
  reset() {
133
- this.#b();
135
+ this.#S();
134
136
  }
135
137
  /** Get the current code from all three editors. */
136
138
  getCode() {
@@ -147,7 +149,7 @@ var p = [
147
149
  let n = this.#t.get(t);
148
150
  n && (n.value = e[t]);
149
151
  }
150
- this.#e.autoRun.value && this.#v();
152
+ this.#e.autoRun.value && this.#b();
151
153
  }
152
154
  attributeChangedCallback(e, t, n) {
153
155
  if (t !== n && this.#e) {
@@ -178,7 +180,7 @@ var p = [
178
180
  }
179
181
  }
180
182
  setup() {
181
- if (super.setup(), this.#e = c("", "", ""), this.#S(), this.#i = new e(this, { value: () => this.#e[this.#e.activeTab.value].value }), this.#p(), this.#o = new n(this), this.#f) {
183
+ if (super.setup(), this.#e = c("", "", ""), this.#w(), this.#i = new e(this, { value: () => this.#e[this.#e.activeTab.value].value }), this.#h(), this.#o = new n(this), this.#f) {
182
184
  let e = this.#e.orientation.value === "vertical";
183
185
  this.#a = new r(this.#f, {
184
186
  handleSelector: ".pg-resize-handle",
@@ -201,29 +203,31 @@ var p = [
201
203
  this.#d && (this.#d.hidden = !e);
202
204
  }), this.addEffect(() => {
203
205
  let e = this.#e.consoleEntries.value;
204
- this.#x(e);
206
+ this.#C(e);
205
207
  }), this.addEffect(() => {
206
- this.#e.html.value, this.#e.css.value, this.#e.js.value, this.#e.autoRun.value && this.#v();
207
- }), window.addEventListener("message", this.#k), this.deferChildren(() => {
208
- this.#h(), this.#g(), this.#y();
208
+ this.#e.html.value, this.#e.css.value, this.#e.js.value, this.#e.autoRun.value && this.#b();
209
+ }), window.addEventListener("message", this.#j), this.deferChildren(() => {
210
+ this.#_(), this.#v(), this.#x();
209
211
  });
210
212
  }
211
213
  teardown() {
212
- window.removeEventListener("message", this.#k), clearTimeout(this.#r), this.#t.clear(), this.#i.destroy(), this.#a?.destroy(), this.#a = null, this.#o?.destroy(), this.#o = null, this.#n = null, this.#d = null, this.#f = null, this.#l = null, this.#u = [], super.teardown();
214
+ window.removeEventListener("message", this.#j), clearTimeout(this.#r), this.#t.clear(), this.#i.destroy(), this.#a?.destroy(), this.#a = null, this.#o?.destroy(), this.#o = null;
215
+ for (let e of this.#m) e.parentNode?.removeChild(e);
216
+ this.#m = [], this.#n = null, this.#d = null, this.#f = null, this.#l = null, this.#u = [], super.teardown();
213
217
  }
214
- #p() {
218
+ #h() {
215
219
  let e = document.createElement("n-header"), t = document.createElement("n-toolbar");
216
220
  t.setAttribute("variant", "plain"), t.setAttribute("size", "md"), t.setAttribute("fill", "");
217
- let n = this.#m("pg-btn-run", "Run", "▶ Run");
218
- n.addEventListener("native:press", this.#C);
219
- let r = this.#m("", "Reset", "↺ Reset");
220
- r.addEventListener("native:press", this.#w);
221
- let i = this.#m("", "Copy", "Copy");
222
- i.addEventListener("native:press", this.#T);
223
- let a = this.#m("", "Console", "Console");
224
- a.addEventListener("native:press", this.#E);
225
- let o = this.#m("", "Expand", "Expand");
226
- o.addEventListener("native:press", this.#D), t.append(n, r, i, a, o), e.appendChild(t);
221
+ let n = this.#g("pg-btn-run", "Run", "▶ Run");
222
+ n.addEventListener("native:press", this.#T);
223
+ let r = this.#g("", "Reset", "↺ Reset");
224
+ r.addEventListener("native:press", this.#E);
225
+ let i = this.#g("", "Copy", "Copy");
226
+ i.addEventListener("native:press", this.#D);
227
+ let a = this.#g("", "Console", "Console");
228
+ a.addEventListener("native:press", this.#O);
229
+ let o = this.#g("", "Expand", "Expand");
230
+ o.addEventListener("native:press", this.#k), t.append(n, r, i, a, o), e.appendChild(t);
227
231
  let s = document.createElement("div");
228
232
  s.className = "pg-split";
229
233
  let c = document.createElement("div");
@@ -234,7 +238,7 @@ var p = [
234
238
  let t = document.createElement("n-tab");
235
239
  t.setAttribute("value", e), t.textContent = l[e], d.appendChild(t);
236
240
  }
237
- d.addEventListener("native:change", this.#O), this.#l = d, u.appendChild(d), c.appendChild(u);
241
+ d.addEventListener("native:change", this.#A), this.#l = d, u.appendChild(d), c.appendChild(u);
238
242
  for (let e = 0; e < p.length; e++) {
239
243
  let t = document.createElement("div");
240
244
  t.className = "pg-code-panel", t.setAttribute("role", "tabpanel"), t.hidden = p[e] !== this.#e.activeTab.value;
@@ -248,13 +252,13 @@ var p = [
248
252
  let h = document.createElement("div");
249
253
  h.className = "pg-preview";
250
254
  let g = document.createElement("iframe");
251
- g.setAttribute("sandbox", "allow-scripts"), g.setAttribute("title", "Preview"), h.appendChild(g), this.#n = g, s.appendChild(h), this.append(e, s);
255
+ g.setAttribute("sandbox", "allow-scripts"), g.setAttribute("title", "Preview"), h.appendChild(g), this.#n = g, s.appendChild(h), this.append(e, s), this.#m = [e, s];
252
256
  }
253
- #m(e, t, n) {
257
+ #g(e, t, n) {
254
258
  let r = document.createElement("n-button");
255
259
  return r.className = e, r.title = t, r.setAttribute("variant", "ghost"), r.textContent = n, r;
256
260
  }
257
- #h() {
261
+ #_() {
258
262
  let e = this.querySelectorAll("script[type^=\"playground/\"]"), t = "", n = "", r = "";
259
263
  for (let i of e) {
260
264
  let e = (i.getAttribute("type") ?? "").replace("playground/", ""), a = (i.textContent ?? "").trim();
@@ -271,9 +275,13 @@ var p = [
271
275
  }
272
276
  i.remove();
273
277
  }
274
- this.#e.html.value = t, this.#e.css.value = n, this.#e.js.value = r, this.#e.initialHtml = t, this.#e.initialCss = n, this.#e.initialJs = r;
278
+ !t && !n && !r && this.#p && (t = this.#p.html, n = this.#p.css, r = this.#p.js), (t || n || r) && (this.#p = {
279
+ html: t,
280
+ css: n,
281
+ js: r
282
+ }), this.#e.html.value = t, this.#e.css.value = n, this.#e.js.value = r, this.#e.initialHtml = t, this.#e.initialCss = n, this.#e.initialJs = r;
275
283
  }
276
- #g() {
284
+ #v() {
277
285
  let e = this.#e.readonly.value;
278
286
  for (let t of p) {
279
287
  let n = this.#t.get(t);
@@ -298,7 +306,7 @@ var p = [
298
306
  * gets the resolved CSS as a string. Falls back to fetch() for production
299
307
  * CDN URLs where ?inline isn't available.
300
308
  */
301
- async #_(e) {
309
+ async #y(e) {
302
310
  if (!e) return "";
303
311
  if (e === this.#c && this.#s) return this.#s;
304
312
  let t = "";
@@ -312,12 +320,12 @@ var p = [
312
320
  }
313
321
  return this.#c = e, this.#s = t, t;
314
322
  }
315
- #v() {
323
+ #b() {
316
324
  clearTimeout(this.#r), this.#r = setTimeout(() => {
317
- this.#y();
325
+ this.#x();
318
326
  }, this.#e.debounce.value);
319
327
  }
320
- async #y() {
328
+ async #x() {
321
329
  let e = this.#n;
322
330
  if (!e) return;
323
331
  let t = this.getAttribute("css-url") ?? "", n = this.getAttribute("register-url") ?? "", r = this.#e.html.value, i = this.#e.css.value, a = this.#e.js.value;
@@ -325,7 +333,7 @@ var p = [
325
333
  html: r,
326
334
  css: i,
327
335
  js: a,
328
- frameworkCss: await this.#_(t),
336
+ frameworkCss: await this.#y(t),
329
337
  registerUrl: n,
330
338
  themeOverrides: this.#e.previewTheme.value || void 0
331
339
  }), this.dispatchEvent(new CustomEvent("playground:run", {
@@ -337,7 +345,7 @@ var p = [
337
345
  }
338
346
  }));
339
347
  }
340
- #b() {
348
+ #S() {
341
349
  let { initialHtml: e, initialCss: t, initialJs: n } = this.#e;
342
350
  this.#e.html.value = e, this.#e.css.value = t, this.#e.js.value = n;
343
351
  let r = this.#t.get("html"), i = this.#t.get("css"), a = this.#t.get("js");
@@ -348,9 +356,9 @@ var p = [
348
356
  css: t,
349
357
  js: n
350
358
  }
351
- })), this.#y();
359
+ })), this.#x();
352
360
  }
353
- #x(e) {
361
+ #C(e) {
354
362
  let t = this.#d;
355
363
  if (t) {
356
364
  t.textContent = "";
@@ -365,7 +373,7 @@ var p = [
365
373
  t.scrollTop = t.scrollHeight;
366
374
  }
367
375
  }
368
- #S() {
376
+ #w() {
369
377
  let e = this.getAttribute("orientation");
370
378
  (e === "horizontal" || e === "vertical" || e === "auto") && (this.#e.orientation.value = e), this.hasAttribute("auto-run") && (this.#e.autoRun.value = !0);
371
379
  let t = this.getAttribute("debounce");
@@ -375,13 +383,13 @@ var p = [
375
383
  let r = this.getAttribute("preview-theme");
376
384
  r && (this.#e.previewTheme.value = r);
377
385
  }
378
- #C = () => {
379
- this.#y();
386
+ #T = () => {
387
+ this.#x();
380
388
  };
381
- #w = () => {
382
- this.#b();
389
+ #E = () => {
390
+ this.#S();
383
391
  };
384
- #T = async () => {
392
+ #D = async () => {
385
393
  let e = this.#e.activeTab.value, t = this.#e[e].value;
386
394
  await this.#i.copy(), this.dispatchEvent(new CustomEvent("playground:copy", {
387
395
  bubbles: !0,
@@ -391,17 +399,17 @@ var p = [
391
399
  }
392
400
  }));
393
401
  };
394
- #E = () => {
402
+ #O = () => {
395
403
  this.#e.consoleOpen.value = !this.#e.consoleOpen.value;
396
404
  };
397
- #D = () => {
405
+ #k = () => {
398
406
  this.#o?.present();
399
407
  };
400
- #O = (e) => {
408
+ #A = (e) => {
401
409
  let t = e.detail;
402
410
  (t?.value === "html" || t?.value === "css" || t?.value === "js") && (this.#e.activeTab.value = t.value);
403
411
  };
404
- #k = (e) => {
412
+ #j = (e) => {
405
413
  if (e.source !== this.#n?.contentWindow) return;
406
414
  let t = e.data;
407
415
  if (!(!t || typeof t != "object") && t.type === "playground:console") {
package/dist/register.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./playground-element-ZQhZxB3I.js";
1
+ import { t as e } from "./playground-element-FVaaBTmI.js";
2
2
  import { define as t } from "@nonoun/native-ui";
3
3
  /**
4
4
  * Register native-playground
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nonoun/native-playground",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Embeddable live code sandbox for @nonoun/native-ui",
5
5
  "license": "MIT",
6
6
  "type": "module",