@vibes.diy/vibe-runtime 14.3.341 → 14.3.343

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/img-gen.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Result } from "@adviser/cement";
2
- import { IMG_GEN_CANCELLED, IMG_GEN_NEEDS_TAP, IMG_GEN_PAUSED_CODE, IMG_GEN_UNREACHABLE, ImgGenPausedError, captureRefusedError, isResErrorImgGen, isResGetDocNotFound, mediaDbName, } from "@vibes.diy/vibe-types";
2
+ import { IMG_GEN_CANCELLED, IMG_GEN_NEEDS_TAP, IMG_GEN_PAUSED_CODE, ImgGenMadeElsewhereError, IMG_GEN_UNREACHABLE, ImgGenPausedError, captureRefusedError, isResErrorImgGen, isResGetDocNotFound, mediaDbName, } from "@vibes.diy/vibe-types";
3
3
  import { resizeImageToBase64 } from "./resize-image.js";
4
4
  import { noteCaptureDataExpected } from "./capture-seed-evidence.js";
5
5
  import { logDebug } from "@vibes.diy/base/utils/debug.js";
@@ -85,6 +85,10 @@ export function registerImgGen(vibeApi, regOpts = {}) {
85
85
  log("paused", { retryAfterMs: res.retryAfterMs ?? 0 });
86
86
  return Result.Err(new ImgGenPausedError(res.retryAfterMs ?? 0));
87
87
  }
88
+ if (res.madeElsewhere === true) {
89
+ log("made-elsewhere", {});
90
+ return Result.Err(new ImgGenMadeElsewhereError());
91
+ }
88
92
  if (res.reason === "cancelled") {
89
93
  log("cancelled", {});
90
94
  return Result.Err(new Error(IMG_GEN_CANCELLED));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibes.diy/vibe-runtime",
3
- "version": "14.3.341",
3
+ "version": "14.3.343",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -36,9 +36,9 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@adviser/cement": "~0.5.37",
39
- "@vibes.diy/api-types": "14.3.341",
40
- "@vibes.diy/base": "14.3.341",
41
- "@vibes.diy/vibe-types": "14.3.341",
39
+ "@vibes.diy/api-types": "14.3.343",
40
+ "@vibes.diy/base": "14.3.343",
41
+ "@vibes.diy/vibe-types": "14.3.343",
42
42
  "arktype": "~2.2.9",
43
43
  "charwise": "~3.0.1",
44
44
  "es-module-lexer": "~3.0.4",
@@ -23,6 +23,7 @@ import { clearAllWriteRejections } from "./write-rejections.js";
23
23
  import { RUNTIME_BUILD, announceRuntimeBuild, formatRuntimeBuild } from "./runtime-build.js";
24
24
  import { getActiveImportMap, getHotSwapBaseUrl, rewriteBareSpecifiers, rewriteRelativeSpecifiersWithBlobs, rewriteHotSwapEntrySpecifiers, orderCompanionGraph, } from "./bare-specifier-rewrite.js";
25
25
  import { lazyType } from "@vibes.diy/api-types/lazy-type";
26
+ import { createTypingHold } from "./typing-hold.js";
26
27
  export class VibeSandboxApi {
27
28
  svc;
28
29
  runtimeId = crypto.randomUUID();
@@ -726,7 +727,7 @@ export async function registerDependencies(vibeApp) {
726
727
  return (await applyHotSwap({ source, rollbackToken: token })).isOk();
727
728
  });
728
729
  seedHotSwapBootSource(vibeApp.bootSource);
729
- registerHotSwapHandler();
730
+ registerHotSwapHandler({ holdWhileTyping: vibeApp.captureRender !== true });
730
731
  registerScrollToTopHandler();
731
732
  registerPullToRefreshHandler();
732
733
  if (vibeApp.captureRender !== true)
@@ -804,10 +805,13 @@ function installFetchActivityMonitor() {
804
805
  });
805
806
  }
806
807
  let hotSwapRegistered = false;
807
- function registerHotSwapHandler() {
808
+ let typingHold;
809
+ function registerHotSwapHandler(opts) {
808
810
  if (hotSwapRegistered)
809
811
  return;
810
812
  hotSwapRegistered = true;
813
+ if (opts.holdWhileTyping)
814
+ typingHold = createTypingHold();
811
815
  window.addEventListener("message", handleHotSwapMessage);
812
816
  }
813
817
  let scrollToTopRegistered = false;
@@ -840,12 +844,20 @@ function scrollVibeToTop() {
840
844
  }
841
845
  }
842
846
  }
843
- async function handleHotSwapMessage(event) {
847
+ function handleHotSwapMessage(event) {
844
848
  if (!isEvtVibeSetSource(event.data))
845
849
  return;
846
- const attempt = { id: event.data.id, source: event.data.source };
850
+ const msg = event.data;
851
+ if (typingHold !== undefined && msg.id !== undefined) {
852
+ typingHold.run(() => void applySetSource(msg));
853
+ return;
854
+ }
855
+ void applySetSource(msg);
856
+ }
857
+ async function applySetSource(msg) {
858
+ const attempt = { id: msg.id, source: msg.source };
847
859
  noteBuildActivity(attempt);
848
- const result = await applyHotSwap({ source: event.data.source, attempt, files: event.data.files });
860
+ const result = await applyHotSwap({ source: msg.source, attempt, files: msg.files });
849
861
  if (result.isErr()) {
850
862
  reportHotSwapFailure(result.Err());
851
863
  postHotSwapErrorToParent(String(result.Err()), attempt.id, true);
@@ -0,0 +1,11 @@
1
+ export interface TypingHold {
2
+ run(apply: () => void): "now" | "held";
3
+ isTyping(): boolean;
4
+ hasHeld(): boolean;
5
+ dispose(): void;
6
+ }
7
+ export interface TypingHoldOptions {
8
+ readonly doc?: Document;
9
+ readonly recheckMs?: number;
10
+ }
11
+ export declare function createTypingHold(opts?: TypingHoldOptions): TypingHold;
package/typing-hold.js ADDED
@@ -0,0 +1,124 @@
1
+ const TEXT_INPUT_TYPES = new Set(["", "text", "search", "email", "url", "tel", "password", "number"]);
2
+ const EDIT_TEXT_ATTR = "data-edit-for";
3
+ const PILL_ATTR = "data-vibe-update-ready";
4
+ const RECHECK_MS = 400;
5
+ function isTextEntry(el) {
6
+ if (el.closest(`[${EDIT_TEXT_ATTR}]`) !== null)
7
+ return false;
8
+ if (el.closest(`[${PILL_ATTR}]`) !== null)
9
+ return false;
10
+ if (el instanceof HTMLTextAreaElement)
11
+ return true;
12
+ if (el instanceof HTMLInputElement)
13
+ return TEXT_INPUT_TYPES.has(el.type.toLowerCase());
14
+ return el instanceof HTMLElement && el.isContentEditable;
15
+ }
16
+ function typedText(el) {
17
+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)
18
+ return el.value;
19
+ return el.textContent ?? "";
20
+ }
21
+ export function createTypingHold(opts = {}) {
22
+ const doc = opts.doc ?? document;
23
+ const recheckMs = opts.recheckMs ?? RECHECK_MS;
24
+ const edited = new Set();
25
+ let held;
26
+ let timer;
27
+ let pill;
28
+ const isTyping = () => {
29
+ for (const el of edited) {
30
+ if (el.isConnected === false || typedText(el).trim() === "")
31
+ edited.delete(el);
32
+ }
33
+ return edited.size > 0;
34
+ };
35
+ const hidePill = () => {
36
+ pill?.remove();
37
+ pill = undefined;
38
+ };
39
+ const release = () => {
40
+ const apply = held;
41
+ held = undefined;
42
+ if (timer !== undefined)
43
+ clearInterval(timer);
44
+ timer = undefined;
45
+ hidePill();
46
+ apply?.();
47
+ };
48
+ const recheck = () => {
49
+ if (held !== undefined && isTyping() === false)
50
+ release();
51
+ };
52
+ const showPill = () => {
53
+ if (pill !== undefined || doc.body === null)
54
+ return;
55
+ const host = doc.createElement("div");
56
+ host.setAttribute(PILL_ATTR, "true");
57
+ const root = host.attachShadow({ mode: "open" });
58
+ const button = doc.createElement("button");
59
+ button.type = "button";
60
+ button.textContent = "Update ready · Show it";
61
+ button.setAttribute("aria-label", "Your app's update is ready. Show it now.");
62
+ const style = doc.createElement("style");
63
+ style.textContent =
64
+ ":host{position:fixed;left:50%;bottom:16px;transform:translateX(-50%);z-index:2147483647;}" +
65
+ "button{font:600 14px/1 system-ui,-apple-system,sans-serif;padding:10px 16px;border-radius:999px;" +
66
+ "border:0;background:#111;color:#fff;box-shadow:0 4px 16px rgba(0,0,0,.25);cursor:pointer;}" +
67
+ "@media (prefers-color-scheme: dark){button{background:#fff;color:#111;}}";
68
+ button.addEventListener("pointerdown", (e) => e.preventDefault());
69
+ button.addEventListener("click", () => {
70
+ edited.clear();
71
+ release();
72
+ });
73
+ root.append(style, button);
74
+ doc.body.append(host);
75
+ pill = host;
76
+ };
77
+ const onInput = (e) => {
78
+ const target = e.target;
79
+ if (!(target instanceof Element) || !isTextEntry(target))
80
+ return;
81
+ edited.add(target);
82
+ recheck();
83
+ };
84
+ const onSubmit = (e) => {
85
+ const form = e.target;
86
+ if (!(form instanceof HTMLFormElement))
87
+ return;
88
+ for (const el of edited)
89
+ if (form.contains(el))
90
+ edited.delete(el);
91
+ setTimeout(recheck, 0);
92
+ };
93
+ doc.addEventListener("input", onInput, true);
94
+ doc.addEventListener("submit", onSubmit, true);
95
+ return {
96
+ run(apply) {
97
+ if (isTyping() === false) {
98
+ held = undefined;
99
+ if (timer !== undefined)
100
+ clearInterval(timer);
101
+ timer = undefined;
102
+ hidePill();
103
+ apply();
104
+ return "now";
105
+ }
106
+ held = apply;
107
+ showPill();
108
+ timer ??= setInterval(recheck, recheckMs);
109
+ return "held";
110
+ },
111
+ isTyping,
112
+ hasHeld: () => held !== undefined,
113
+ dispose() {
114
+ doc.removeEventListener("input", onInput, true);
115
+ doc.removeEventListener("submit", onSubmit, true);
116
+ if (timer !== undefined)
117
+ clearInterval(timer);
118
+ timer = undefined;
119
+ held = undefined;
120
+ edited.clear();
121
+ hidePill();
122
+ },
123
+ };
124
+ }