@vibes.diy/base 14.3.337 → 14.3.338

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.
@@ -64,6 +64,22 @@ export interface ComposerSlice {
64
64
  readonly rewrite?: ComposerRewrite;
65
65
  readonly newAppDoor?: ComposerNewAppDoor;
66
66
  readonly refusedSend?: ComposerRefusedSend;
67
+ readonly releaseHeld?: ComposerHeldRelease;
68
+ readonly onHeldFollowUpGone?: (how: ComposerHeldGone) => void;
69
+ }
70
+ export type ComposerHeldGone = "sent" | "edited";
71
+ export type ComposerHeldReleaseVia = ComposerIdeaVia | "pressed" | "restored";
72
+ export type ComposerHeldDropReason = "empty" | "edited" | "refused";
73
+ export type ComposerHeldReleaseOutcome = {
74
+ readonly released: true;
75
+ readonly via: ComposerHeldReleaseVia;
76
+ } | {
77
+ readonly released: false;
78
+ readonly reason: ComposerHeldDropReason;
79
+ };
80
+ export interface ComposerHeldRelease {
81
+ readonly key: string;
82
+ readonly onOutcome?: (outcome: ComposerHeldReleaseOutcome) => void;
67
83
  }
68
84
  export interface ComposerRefusedSend {
69
85
  readonly ideas: readonly string[];
@@ -5,6 +5,7 @@ export declare const QUEUE_FLUSH_MAX_ATTEMPTS = 25;
5
5
  export declare const QUEUE_STALE_BUILD_MS = 120000;
6
6
  export declare const QUEUED_CHANGE_KEY = "vibes.queuedChange.";
7
7
  export declare const HELD_CHANGE_KEY = "vibes.heldChange.";
8
+ export declare const HELD_FOLLOW_UP_KEY = "vibes.heldFollowUp.";
8
9
  export interface UseComposerDraftInput {
9
10
  readonly composer: ComposerSlice;
10
11
  readonly resetKey: string | null;
@@ -8,6 +8,7 @@ export const QUEUE_FLUSH_MAX_ATTEMPTS = 25;
8
8
  export const QUEUE_STALE_BUILD_MS = 120_000;
9
9
  export const QUEUED_CHANGE_KEY = "vibes.queuedChange.";
10
10
  export const HELD_CHANGE_KEY = "vibes.heldChange.";
11
+ export const HELD_FOLLOW_UP_KEY = "vibes.heldFollowUp.";
11
12
  function saveChange(prefix, appKey, text) {
12
13
  if (typeof sessionStorage === "undefined")
13
14
  return false;
@@ -72,6 +73,9 @@ export function useComposerDraft(input) {
72
73
  submittedRender.current = false;
73
74
  });
74
75
  const backgroundCopy = React.useRef({});
76
+ const heldPress = React.useRef(undefined);
77
+ const restoredHeld = React.useRef(undefined);
78
+ const heldWords = React.useRef(undefined);
75
79
  const prevResetKey = React.useRef(resetKey);
76
80
  if (prevResetKey.current !== resetKey) {
77
81
  prevResetKey.current = resetKey;
@@ -87,9 +91,18 @@ export function useComposerDraft(input) {
87
91
  setHandingOff(undefined);
88
92
  attachments.clear();
89
93
  backgroundCopy.current = {};
94
+ heldPress.current = undefined;
95
+ restoredHeld.current = undefined;
96
+ heldWords.current = undefined;
90
97
  }
91
98
  const queuedRef = React.useRef([]);
92
99
  const heldTextRef = React.useRef("");
100
+ const keepFollowUpMark = (saveKey, heldText) => {
101
+ if (heldWords.current === heldText)
102
+ saveChange(HELD_FOLLOW_UP_KEY, saveKey, heldText);
103
+ else
104
+ dropChange(HELD_FOLLOW_UP_KEY, saveKey);
105
+ };
93
106
  const persistKeyRef = React.useRef(persistKey);
94
107
  const onQueueDroppedRef = React.useRef(composer.onQueueDropped);
95
108
  React.useLayoutEffect(() => {
@@ -100,8 +113,10 @@ export function useComposerDraft(input) {
100
113
  const keep = (cause) => {
101
114
  const saveKey = persistKeyRef.current;
102
115
  const heldText = heldTextRef.current;
103
- if (heldText !== "" && saveKey !== null)
116
+ if (heldText !== "" && saveKey !== null) {
104
117
  saveChange(HELD_CHANGE_KEY, saveKey, heldText);
118
+ keepFollowUpMark(saveKey, heldText);
119
+ }
105
120
  const pending = queuedRef.current;
106
121
  if (pending.length === 0)
107
122
  return;
@@ -117,8 +132,10 @@ export function useComposerDraft(input) {
117
132
  if (saveKey === null)
118
133
  return;
119
134
  const heldText = heldTextRef.current;
120
- if (heldText !== "" && saveChange(HELD_CHANGE_KEY, saveKey, heldText))
135
+ if (heldText !== "" && saveChange(HELD_CHANGE_KEY, saveKey, heldText)) {
136
+ keepFollowUpMark(saveKey, heldText);
121
137
  backgroundCopy.current.held = saveKey;
138
+ }
122
139
  const pending = queuedRef.current;
123
140
  if (pending.length > 0 && saveChange(QUEUED_CHANGE_KEY, saveKey, pending.join("\n"))) {
124
141
  backgroundCopy.current.queued = saveKey;
@@ -143,7 +160,12 @@ export function useComposerDraft(input) {
143
160
  React.useEffect(() => {
144
161
  if (persistKey === null)
145
162
  return;
146
- const saved = [takeChange(QUEUED_CHANGE_KEY, persistKey), takeChange(HELD_CHANGE_KEY, persistKey)].filter((t) => t !== undefined);
163
+ const heldBack = takeChange(HELD_CHANGE_KEY, persistKey);
164
+ const followUp = takeChange(HELD_FOLLOW_UP_KEY, persistKey);
165
+ if (heldBack !== undefined && followUp !== undefined && followUp.trim() === heldBack.trim()) {
166
+ restoredHeld.current = heldBack.trim();
167
+ }
168
+ const saved = [takeChange(QUEUED_CHANGE_KEY, persistKey), heldBack].filter((t) => t !== undefined);
147
169
  let live = true;
148
170
  const restage = attachments.stage;
149
171
  const store = heldAttachmentStore();
@@ -182,6 +204,7 @@ export function useComposerDraft(input) {
182
204
  if (copy.held === undefined || holding)
183
205
  return;
184
206
  dropChange(HELD_CHANGE_KEY, copy.held);
207
+ dropChange(HELD_FOLLOW_UP_KEY, copy.held);
185
208
  copy.held = undefined;
186
209
  }, [holding]);
187
210
  React.useEffect(() => {
@@ -297,6 +320,7 @@ export function useComposerDraft(input) {
297
320
  if (ready.length > 0)
298
321
  attachments.clear();
299
322
  setText("");
323
+ heldWordsSent();
300
324
  if (cause === undefined)
301
325
  composer.onSendQueued?.(queued.length + 1);
302
326
  else
@@ -309,6 +333,13 @@ export function useComposerDraft(input) {
309
333
  return false;
310
334
  }
311
335
  if (composer.hold !== undefined) {
336
+ if (text.trim() !== "") {
337
+ heldPress.current = text.trim();
338
+ heldWords.current = text.trim();
339
+ }
340
+ else if (attachments.readyAttachments.length > 0) {
341
+ heldPress.current = "";
342
+ }
312
343
  composer.onSendBlocked?.(composer.hold.reason);
313
344
  return false;
314
345
  }
@@ -355,8 +386,15 @@ export function useComposerDraft(input) {
355
386
  attachments.clear();
356
387
  setSuggestion(undefined);
357
388
  setText("");
389
+ heldWordsSent();
358
390
  return true;
359
391
  }
392
+ function heldWordsSent() {
393
+ if (heldWords.current === undefined)
394
+ return;
395
+ heldWords.current = undefined;
396
+ composer.onHeldFollowUpGone?.("sent");
397
+ }
360
398
  function stop() {
361
399
  if (queued.length > 0) {
362
400
  composer.onQueueDropped?.({ cause: "stopped", messages: queued.length, kept: "field" });
@@ -369,6 +407,53 @@ export function useComposerDraft(input) {
369
407
  }
370
408
  composer.onStop();
371
409
  }
410
+ const release = composer.releaseHeld;
411
+ const releasedKey = React.useRef(undefined);
412
+ const attachmentsBusy = draftAttachments.busy === true;
413
+ React.useEffect(() => {
414
+ if (release === undefined || held || attachmentsBusy || releasedKey.current === release.key)
415
+ return;
416
+ releasedKey.current = release.key;
417
+ const trimmed = text.trim();
418
+ const fileOnlyPress = trimmed === "" && heldPress.current === "" && attachments.readyAttachments.length > 0;
419
+ if (trimmed === "" && fileOnlyPress === false) {
420
+ release.onOutcome?.({ released: false, reason: "empty" });
421
+ return;
422
+ }
423
+ const via = fileOnlyPress ? "pressed" : heldFollowUpVia(trimmed);
424
+ if (via === undefined) {
425
+ release.onOutcome?.({ released: false, reason: "edited" });
426
+ return;
427
+ }
428
+ heldPress.current = undefined;
429
+ restoredHeld.current = undefined;
430
+ if (submit())
431
+ release.onOutcome?.({ released: true, via });
432
+ else
433
+ release.onOutcome?.({ released: false, reason: "refused" });
434
+ }, [release, held, attachmentsBusy, text]);
435
+ React.useEffect(() => {
436
+ const trimmed = text.trim();
437
+ if (holding && trimmed !== "" && heldFollowUpVia(trimmed) !== undefined) {
438
+ heldWords.current = trimmed;
439
+ return;
440
+ }
441
+ if (heldWords.current === undefined || heldWords.current === trimmed)
442
+ return;
443
+ heldWords.current = undefined;
444
+ composer.onHeldFollowUpGone?.("edited");
445
+ }, [text, holding, suggestion, seed]);
446
+ function heldFollowUpVia(trimmed) {
447
+ if (suggestion !== undefined && suggestion === text)
448
+ return "chip";
449
+ if (seed !== null && seed.prefill === "select" && seed.text === text)
450
+ return "next";
451
+ if (heldPress.current === trimmed)
452
+ return "pressed";
453
+ if (restoredHeld.current === trimmed)
454
+ return "restored";
455
+ return undefined;
456
+ }
372
457
  const renderedEpoch = draftEpoch.current;
373
458
  return {
374
459
  text: writingRewrite ? rewriteText : text,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibes.diy/base",
3
- "version": "14.3.337",
3
+ "version": "14.3.338",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -10,10 +10,10 @@
10
10
  "dependencies": {
11
11
  "@adviser/cement": "~0.5.37",
12
12
  "@emotion/css": "~11.13.5",
13
- "@vibes.diy/api-types": "14.3.337",
14
- "@vibes.diy/use-vibes-types": "14.3.337",
15
- "@vibes.diy/vibe-runtime": "14.3.337",
16
- "@vibes.diy/vibe-types": "14.3.337",
13
+ "@vibes.diy/api-types": "14.3.338",
14
+ "@vibes.diy/use-vibes-types": "14.3.338",
15
+ "@vibes.diy/vibe-runtime": "14.3.338",
16
+ "@vibes.diy/vibe-types": "14.3.338",
17
17
  "arktype": "~2.2.9",
18
18
  "officeparser": "~8.7.1",
19
19
  "qrcode-generator": "~2.0.4",