main
js 87 lines 2.08 KB
Raw
1 import { createStore } from "/js/AlpineStore.js";
2 import { store as chatInputStore } from "/components/chat/input/input-store.js";
3
4 // Store model for the Full-Screen Input Modal
5 const model = {
6 // State
7 isOpen: false,
8 inputText: "",
9 wordWrap: true,
10 undoStack: [],
11 redoStack: [],
12 maxStackSize: 100,
13 lastSavedState: "",
14
15 // Lifecycle
16 init() {
17 // No-op for now; kept for parity and future side-effects
18 },
19
20 // Open modal with current chat input content
21 openModal() {
22 this.inputText = chatInputStore.message || "";
23 this.lastSavedState = this.inputText;
24 this.isOpen = true;
25 this.undoStack = [];
26 this.redoStack = [];
27
28 // Focus the full screen input after rendering
29 setTimeout(() => {
30 const fullScreenInput = document.getElementById("full-screen-input");
31 if (fullScreenInput) fullScreenInput.focus();
32 }, 50);
33 },
34
35 // Close modal and write value back into main chat input
36 handleClose() {
37 chatInputStore.message = this.inputText;
38 chatInputStore.adjustTextareaHeight();
39 this.isOpen = false;
40 },
41
42 // History management
43 updateHistory() {
44 if (this.lastSavedState === this.inputText) return; // no change
45 this.undoStack.push(this.lastSavedState);
46 if (this.undoStack.length > this.maxStackSize) this.undoStack.shift();
47 this.redoStack = [];
48 this.lastSavedState = this.inputText;
49 },
50
51 undo() {
52 if (!this.canUndo) return;
53 this.redoStack.push(this.inputText);
54 this.inputText = this.undoStack.pop();
55 this.lastSavedState = this.inputText;
56 },
57
58 redo() {
59 if (!this.canRedo) return;
60 this.undoStack.push(this.inputText);
61 this.inputText = this.redoStack.pop();
62 this.lastSavedState = this.inputText;
63 },
64
65 clearText() {
66 if (!this.inputText) return;
67 this.updateHistory();
68 this.inputText = "";
69 this.lastSavedState = "";
70 },
71
72 toggleWrap() {
73 this.wordWrap = !this.wordWrap;
74 },
75
76 // Computed
77 get canUndo() {
78 return this.undoStack.length > 0;
79 },
80
81 get canRedo() {
82 return this.redoStack.length > 0;
83 },
84 };
85
86 export const store = createStore("fullScreenInputModal", model);
87