rosetack 0.1.2 → 0.1.3

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.
Files changed (54) hide show
  1. package/deploy/cloudflare/functions/[[path]].ts +61 -0
  2. package/deploy/cloudflare/wrangler.toml +14 -0
  3. package/deploy/netlify/functions/rosetack.ts +38 -0
  4. package/deploy/netlify.toml +17 -0
  5. package/devtools/devtools.html +7 -0
  6. package/devtools/devtools.js +1 -0
  7. package/devtools/manifest.json +8 -0
  8. package/devtools/panel.html +28 -0
  9. package/devtools/panel.js +54 -0
  10. package/dist-cli/compiler.mjs +818 -445
  11. package/dist-cli/edge.mjs +115 -39
  12. package/dist-cli/rosetack.mjs +1078 -529
  13. package/dist-cli/runtime.mjs +115 -34
  14. package/dist-cli/test.mjs +875 -464
  15. package/package.json +4 -3
  16. package/src/FRAMEWORK_VERSION +1 -1
  17. package/src/cli/edge.ts +69 -61
  18. package/src/cli/index.ts +243 -328
  19. package/src/cli/prompt.ts +4 -1
  20. package/src/cli/shell.ts +67 -69
  21. package/src/cli/test.ts +9 -70
  22. package/src/compiler/index.ts +921 -851
  23. package/src/runtime/index.ts +155 -158
  24. package/src/types/rosetack.d.ts +16 -66
  25. package/templates/admin/package.json +14 -0
  26. package/templates/admin/rosetack.config.js +1 -0
  27. package/templates/admin/src/pages/_middleware.rose +33 -0
  28. package/templates/admin/src/pages/api/items.rose +37 -0
  29. package/templates/admin/src/pages/api/login.rose +25 -0
  30. package/templates/admin/src/pages/index.rose +79 -0
  31. package/templates/api/package.json +14 -0
  32. package/templates/api/rosetack.config.js +1 -0
  33. package/templates/api/src/pages/api/health.rose +7 -0
  34. package/templates/api/src/pages/api/items.rose +46 -0
  35. package/templates/api/src/pages/api/login.rose +24 -0
  36. package/templates/api/src/pages/index.rose +25 -0
  37. package/templates/blog/package.json +14 -0
  38. package/templates/blog/rosetack.config.js +1 -0
  39. package/templates/blog/src/pages/404.rose +2 -0
  40. package/templates/blog/src/pages/_layout.rose +42 -0
  41. package/templates/blog/src/pages/_middleware.rose +74 -0
  42. package/templates/blog/src/pages/admin.rose +85 -0
  43. package/templates/blog/src/pages/api/login.rose +46 -0
  44. package/templates/blog/src/pages/api/posts/[id].rose +37 -0
  45. package/templates/blog/src/pages/api/posts.rose +72 -0
  46. package/templates/blog/src/pages/index.rose +31 -0
  47. package/templates/blog/src/pages/post/[id].rose +36 -0
  48. package/templates/site/package.json +14 -0
  49. package/templates/site/rosetack.config.js +1 -0
  50. package/templates/site/src/pages/404.rose +2 -0
  51. package/templates/site/src/pages/_layout.rose +40 -0
  52. package/templates/site/src/pages/about.rose +6 -0
  53. package/templates/site/src/pages/index.rose +13 -0
  54. package/templates/site/src/pages/pricing.rose +8 -0
@@ -8,6 +8,7 @@ function entry(key, initial) {
8
8
  return e;
9
9
  }
10
10
  function state(key, initial) {
11
+ ownerKeys()?.add(key);
11
12
  const e = entry(key, initial);
12
13
  const getter = () => {
13
14
  if (currentEffect) e.subs.add(currentEffect);
@@ -28,6 +29,44 @@ function setState(key, value) {
28
29
  e.subs.forEach((fn) => fn());
29
30
  }
30
31
  var cleanups = /* @__PURE__ */ new Set();
32
+ var fxOwner = null;
33
+ var fxByOwner = /* @__PURE__ */ new WeakMap();
34
+ var keysByOwner = /* @__PURE__ */ new WeakMap();
35
+ var fxSet = () => {
36
+ if (!fxOwner) return cleanups;
37
+ let s = fxByOwner.get(fxOwner);
38
+ if (!s) {
39
+ s = /* @__PURE__ */ new Set();
40
+ fxByOwner.set(fxOwner, s);
41
+ }
42
+ return s;
43
+ };
44
+ var ownerKeys = () => {
45
+ if (!fxOwner) return null;
46
+ let s = keysByOwner.get(fxOwner);
47
+ if (!s) {
48
+ s = /* @__PURE__ */ new Set();
49
+ keysByOwner.set(fxOwner, s);
50
+ }
51
+ return s;
52
+ };
53
+ function setFxOwner(container) {
54
+ fxOwner = container;
55
+ }
56
+ function resetContainerFx(container) {
57
+ const set = fxByOwner.get(container);
58
+ if (set) {
59
+ set.forEach((fn) => fn());
60
+ fxByOwner.delete(container);
61
+ }
62
+ const keys = keysByOwner.get(container);
63
+ if (keys) {
64
+ keys.forEach((k) => signalMap.delete(k));
65
+ keysByOwner.delete(container);
66
+ }
67
+ dataCache.clear();
68
+ pendingDeltas.clear();
69
+ }
31
70
  function effect(fn) {
32
71
  const wrapped = () => {
33
72
  try {
@@ -41,9 +80,9 @@ function effect(fn) {
41
80
  currentEffect = prev;
42
81
  const cleanup = () => {
43
82
  signalMap.forEach((e) => e.subs.delete(wrapped));
44
- cleanups.delete(cleanup);
83
+ fxSet().delete(cleanup);
45
84
  };
46
- cleanups.add(cleanup);
85
+ fxSet().add(cleanup);
47
86
  return cleanup;
48
87
  }
49
88
  var ESC_MAP = {
@@ -58,35 +97,31 @@ function esc(v) {
58
97
  }
59
98
  function textMark(closes, fn, pair, arg) {
60
99
  const i = closes.push(fn) - 1;
61
- return `<!--\u27E6m:${i}\u27E7-->` + esc(closes[i](arg)) + (pair ? `<!--\u27E6/m:${i}\u27E7-->` : "");
100
+ return `<!--\u27E6m:${i}\u27E7-->` + esc(fn(arg)) + (pair ? `<!--\u27E6/m:${i}\u27E7-->` : "");
62
101
  }
63
102
  function attrMark(closes, fn, name, arg) {
64
103
  const i = closes.push(fn) - 1;
65
- return `${name}="${esc(closes[i](arg))}" data-b="${i}:${name}"`;
104
+ return `${name}="${esc(fn(arg))}" data-b="${i}:${name}"`;
66
105
  }
67
106
  function ifMark(closes, cond, fn, scope) {
68
- const i = closes.length;
69
107
  let snap = null;
70
- closes.push(() => {
108
+ const i = closes.push(() => {
71
109
  if (!cond()) {
72
110
  snap = null;
73
111
  return null;
74
112
  }
75
113
  if (!snap) {
76
- const c = [];
77
- snap = { html: String(fn(scope, c)), closes: c };
114
+ snap = { html: String(fn(scope, closes)), closes };
78
115
  }
79
116
  return snap;
80
- });
117
+ }) - 1;
81
118
  const r = closes[i]();
82
119
  return `<!--\u27E6i:${i}\u27E7-->` + (r ? r.html : "") + `<!--\u27E6/i:${i}\u27E7-->`;
83
120
  }
84
121
  function eachMark(closes, items, fn) {
85
- const i = closes.length;
86
- closes.push(() => items().map((v) => {
87
- const c = [];
88
- return { html: String(fn(v, c)), closes: c, scope: v };
89
- }));
122
+ const i = closes.push(() => items().map((v) => {
123
+ return { html: String(fn(v, closes)), closes, scope: v };
124
+ })) - 1;
90
125
  let h = `<!--\u27E6l:${i}\u27E7-->`;
91
126
  for (const r of closes[i]()) h += r.html;
92
127
  return h + `<!--\u27E6/l:${i}\u27E7-->`;
@@ -96,10 +131,18 @@ function headMark(closes, fn) {
96
131
  return `<!--\u27E6h:${i}\u27E7-->` + fn() + `<!--\u27E6/h:${i}\u27E7-->`;
97
132
  }
98
133
  function rawMark(closes, fn, arg) {
99
- const i = closes.push((s) => ({ html: String(fn(s) ?? ""), closes: [] })) - 1;
134
+ const i = closes.push((s) => ({ html: String(fn(s) ?? ""), closes })) - 1;
100
135
  const r = closes[i](arg);
101
136
  return `<!--\u27E6i:${i}\u27E7-->` + r.html + `<!--\u27E6/i:${i}\u27E7-->`;
102
137
  }
138
+ function slotBlockMark(closes, hit) {
139
+ if (!hit) return "";
140
+ const i = closes.push(() => {
141
+ if (!hit) return null;
142
+ return { html: String(hit.fn(hit.o, closes)), closes, scope: hit.o };
143
+ }) - 1;
144
+ return `<!--\u27E6i:${i}\u27E7-->` + String(hit.fn(hit.o, closes)) + `<!--\u27E6/i:${i}\u27E7-->`;
145
+ }
103
146
  var MARK_RE = /^\u27e6([milh]):(\d+)\u27e7$/;
104
147
  var END_RE = /^\u27e6\/([milh]):(\d+)\u27e7$/;
105
148
  var wired = /* @__PURE__ */ new WeakSet();
@@ -158,10 +201,11 @@ function wire(root, closes, scope) {
158
201
  const walker = document.createTreeWalker(holder, NodeFilter.SHOW_COMMENT);
159
202
  while (walker.nextNode()) comments.push(walker.currentNode);
160
203
  const nested = /* @__PURE__ */ new Set();
204
+ const headPair = /* @__PURE__ */ new Set();
161
205
  const open = [];
162
206
  for (let i = 0; i < comments.length; i++) {
163
207
  const m = (comments[i].nodeValue ?? "").match(MARK_RE);
164
- if (m && (m[1] === "i" || m[1] === "l")) {
208
+ if (m && (m[1] === "i" || m[1] === "l" || m[1] === "h")) {
165
209
  open.push(i);
166
210
  continue;
167
211
  }
@@ -170,16 +214,22 @@ function wire(root, closes, scope) {
170
214
  const key = em[1] + em[2];
171
215
  let at = -1;
172
216
  for (let k = open.length - 1; k >= 0; k--) {
173
- const om = (comments[open[k]].nodeValue ?? "").match(MARK_RE);
174
- if (om[1] + om[2] === key) {
217
+ const om2 = (comments[open[k]].nodeValue ?? "").match(MARK_RE);
218
+ if (om2[1] + om2[2] === key) {
175
219
  at = k;
176
220
  break;
177
221
  }
178
222
  }
179
223
  if (at < 0) continue;
224
+ const om = (comments[open[at]].nodeValue ?? "").match(MARK_RE);
225
+ if (om[1] === "h") {
226
+ headPair.add(comments[open[at]]);
227
+ headPair.add(comments[i]);
228
+ }
180
229
  for (let k = open[at] + 1; k < i; k++) nested.add(comments[k]);
181
230
  open.length = at;
182
231
  }
232
+ for (const c of headPair) nested.delete(c);
183
233
  const ends = /* @__PURE__ */ new Map();
184
234
  for (const c of comments) {
185
235
  if (nested.has(c)) continue;
@@ -187,13 +237,15 @@ function wire(root, closes, scope) {
187
237
  if (m) ends.set(+m[2], c);
188
238
  }
189
239
  const headBlocks = [];
240
+ const ownsHead = root === document.getElementById("app");
190
241
  for (const c of comments) {
191
242
  if (nested.has(c) || wired.has(c) || !c.parentNode) continue;
192
- wired.add(c);
193
243
  const m = (c.nodeValue ?? "").match(MARK_RE);
194
244
  if (!m) continue;
195
245
  const kind = m[1];
196
246
  const idx = +m[2];
247
+ if (kind === "h" && !ownsHead) continue;
248
+ wired.add(c);
197
249
  if (kind === "h") {
198
250
  const end = ends.get(idx);
199
251
  if (!end) continue;
@@ -256,7 +308,7 @@ function wire(root, closes, scope) {
256
308
  const disp = wire(frag, r.closes, r.scope ?? scope);
257
309
  const nodes = Array.from(frag.childNodes);
258
310
  const parent = anchor.parentNode;
259
- for (const nd of nodes) parent.insertBefore(nd, anchor.nextSibling);
311
+ for (const nd of nodes) parent.insertBefore(nd, end);
260
312
  st.__st = { nodes, disp };
261
313
  });
262
314
  } else {
@@ -287,19 +339,21 @@ function wire(root, closes, scope) {
287
339
  });
288
340
  }
289
341
  }
290
- if (headBlocks.length > 0) {
291
- const blocks = headBlocks;
292
- weff(() => {
293
- let html = "";
294
- for (const b of blocks) html += String(closes[b.idx](scope));
295
- applyHead(html);
296
- });
297
- for (const b of blocks) {
298
- b.nodes.forEach((nd) => nd.remove());
299
- b.start.remove();
300
- b.end.remove();
301
- }
302
- } else if (root.nodeType !== 11) clearHead();
342
+ if (root === document.getElementById("app")) {
343
+ if (headBlocks.length > 0) {
344
+ const blocks = headBlocks;
345
+ weff(() => {
346
+ let html = "";
347
+ for (const b of blocks) html += String(closes[b.idx](scope));
348
+ applyHead(html);
349
+ });
350
+ for (const b of blocks) {
351
+ b.nodes.forEach((nd) => nd.remove());
352
+ b.start.remove();
353
+ b.end.remove();
354
+ }
355
+ } else if (root.nodeType !== 11) clearHead();
356
+ }
303
357
  const els = holder.querySelectorAll("[data-b]");
304
358
  els.forEach((el) => {
305
359
  const spec = el.getAttribute("data-b");
@@ -425,7 +479,7 @@ function flushMounts() {
425
479
  for (const fn of q) fn();
426
480
  }
427
481
  function onCleanup(fn) {
428
- cleanups.add(fn);
482
+ fxSet().add(fn);
429
483
  }
430
484
  function adoptCleanups(fns) {
431
485
  for (const fn of fns) cleanups.add(fn);
@@ -467,6 +521,26 @@ function bestLocale(header) {
467
521
  }
468
522
  return null;
469
523
  }
524
+ var RoseRedirect = class extends Error {
525
+ constructor(path, status = 307) {
526
+ super(`redirect to ${path}`);
527
+ this.path = path;
528
+ this.status = status;
529
+ }
530
+ __rosetack = "redirect";
531
+ };
532
+ var RoseNotFound = class extends Error {
533
+ __rosetack = "notFound";
534
+ constructor() {
535
+ super("notFound()");
536
+ }
537
+ };
538
+ function redirect(path, status = 307) {
539
+ throw new RoseRedirect(path, status);
540
+ }
541
+ function notFound() {
542
+ throw new RoseNotFound();
543
+ }
470
544
  var RTL_RE = /^(ar|fa|he|ur|ps|sd|ug|yi|ckb|dv|ks|prs|haz|mzn|nqo)/;
471
545
  function localeDir(lang) {
472
546
  return RTL_RE.test(lang) ? "rtl" : "";
@@ -652,6 +726,8 @@ export {
652
726
  $store,
653
727
  $t,
654
728
  ActionError,
729
+ RoseNotFound,
730
+ RoseRedirect,
655
731
  StateDelta,
656
732
  adoptCleanups,
657
733
  applyHead,
@@ -678,16 +754,20 @@ export {
678
754
  loadLocale,
679
755
  localeDir,
680
756
  localeList,
757
+ notFound,
681
758
  onCleanup,
682
759
  onMount,
683
760
  rawMark,
761
+ redirect,
684
762
  refresh,
685
763
  reportVitals,
764
+ resetContainerFx,
686
765
  resetEffects,
687
766
  resetRequestContext,
688
767
  restoreState,
689
768
  resumeState,
690
769
  serializeState,
770
+ setFxOwner,
691
771
  setLocalePacks,
692
772
  setLocales,
693
773
  setPrefetchOverride,
@@ -696,6 +776,7 @@ export {
696
776
  setState,
697
777
  setStateDelta,
698
778
  setStoreTransport,
779
+ slotBlockMark,
699
780
  state,
700
781
  textMark,
701
782
  tpl,