xote 1.0.2 → 1.2.0

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,303 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Xote__Effect from "./Xote__Effect.res.mjs";
4
- import * as Xote__Signal from "./Xote__Signal.res.mjs";
5
- import * as Xote__Computed from "./Xote__Computed.res.mjs";
6
- import * as Xote__Component from "./Xote__Component.res.mjs";
7
-
8
- var todos = Xote__Signal.make([]);
9
-
10
- var nextId = {
11
- contents: 0
12
- };
13
-
14
- var inputValue = Xote__Signal.make("");
15
-
16
- var darkMode = Xote__Signal.make(false);
17
-
18
- var completedCount = Xote__Computed.make(function () {
19
- return Xote__Signal.get(todos).filter(function (todo) {
20
- return todo.completed;
21
- }).length;
22
- });
23
-
24
- var activeCount = Xote__Computed.make(function () {
25
- return Xote__Signal.get(todos).filter(function (todo) {
26
- return !todo.completed;
27
- }).length;
28
- });
29
-
30
- var totalCount = Xote__Computed.make(function () {
31
- return Xote__Signal.get(todos).length;
32
- });
33
-
34
- function addTodo(text) {
35
- if (text.trim() !== "") {
36
- Xote__Signal.update(todos, (function (list) {
37
- return list.concat([{
38
- id: nextId.contents,
39
- text: text,
40
- completed: false
41
- }]);
42
- }));
43
- nextId.contents = nextId.contents + 1 | 0;
44
- return Xote__Signal.set(inputValue, "");
45
- }
46
-
47
- }
48
-
49
- function toggleTodo(id) {
50
- Xote__Signal.update(todos, (function (list) {
51
- return list.map(function (todo) {
52
- if (todo.id === id) {
53
- return {
54
- id: todo.id,
55
- text: todo.text,
56
- completed: !todo.completed
57
- };
58
- } else {
59
- return todo;
60
- }
61
- });
62
- }));
63
- }
64
-
65
- function clearInput() {
66
- var input = document.querySelector(".todo-input");
67
- if (!(input == null)) {
68
- input.value = "";
69
- return ;
70
- }
71
-
72
- }
73
-
74
- function handleInput(evt) {
75
- var newValue = evt.target.value;
76
- Xote__Signal.set(inputValue, newValue);
77
- }
78
-
79
- function getInputValue() {
80
- var input = document.querySelector(".todo-input");
81
- if (input == null) {
82
- return "";
83
- } else {
84
- return input.value;
85
- }
86
- }
87
-
88
- function handleKeyDown(evt) {
89
- if (evt.key === "Enter") {
90
- addTodo(getInputValue());
91
- return clearInput();
92
- }
93
-
94
- }
95
-
96
- function handleAddClick(_evt) {
97
- addTodo(getInputValue());
98
- clearInput();
99
- }
100
-
101
- function toggleTheme(_evt) {
102
- Xote__Signal.update(darkMode, (function (mode) {
103
- return !mode;
104
- }));
105
- }
106
-
107
- Xote__Effect.run(function () {
108
- var isDark = Xote__Signal.get(darkMode);
109
- if (isDark) {
110
- return (document.documentElement.classList.add('dark'));
111
- } else {
112
- return (document.documentElement.classList.remove('dark'));
113
- }
114
- });
115
-
116
- function todoItem(todo) {
117
- var checkboxAttrs = todo.completed ? [
118
- [
119
- "type",
120
- "checkbox"
121
- ],
122
- [
123
- "checked",
124
- "checked"
125
- ],
126
- [
127
- "class",
128
- "w-5 h-5 cursor-pointer"
129
- ]
130
- ] : [
131
- [
132
- "type",
133
- "checkbox"
134
- ],
135
- [
136
- "class",
137
- "w-5 h-5 cursor-pointer"
138
- ]
139
- ];
140
- return Xote__Component.li([[
141
- "class",
142
- "flex items-center gap-3 p-3 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 mb-2 " + (
143
- todo.completed ? "completed" : ""
144
- )
145
- ]], undefined, [
146
- Xote__Component.input(checkboxAttrs, [[
147
- "change",
148
- (function (param) {
149
- toggleTodo(todo.id);
150
- })
151
- ]], undefined),
152
- Xote__Component.span([[
153
- "class",
154
- "flex-1 text-gray-900 dark:text-gray-100"
155
- ]], undefined, [Xote__Component.text(todo.text)], undefined)
156
- ], undefined);
157
- }
158
-
159
- var inputElement = Xote__Component.input([
160
- [
161
- "type",
162
- "text"
163
- ],
164
- [
165
- "placeholder",
166
- "What needs to be done?"
167
- ],
168
- [
169
- "class",
170
- "todo-input flex-1 px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
171
- ]
172
- ], [
173
- [
174
- "input",
175
- handleInput
176
- ],
177
- [
178
- "keydown",
179
- handleKeyDown
180
- ]
181
- ], undefined);
182
-
183
- var app = Xote__Component.div([[
184
- "class",
185
- "max-w-2xl mx-auto p-6 space-y-6"
186
- ]], undefined, [Xote__Component.div([[
187
- "class",
188
- "bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8"
189
- ]], undefined, [
190
- Xote__Component.div([[
191
- "class",
192
- "flex items-center justify-between mb-6"
193
- ]], undefined, [
194
- Xote__Component.h1([[
195
- "class",
196
- "text-3xl font-bold text-gray-900 dark:text-white"
197
- ]], undefined, [Xote__Component.text("Todo List")], undefined),
198
- Xote__Component.button([[
199
- "class",
200
- "px-4 py-2 rounded-lg bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors"
201
- ]], [[
202
- "click",
203
- toggleTheme
204
- ]], [Xote__Component.textSignal(Xote__Computed.make(function () {
205
- if (Xote__Signal.get(darkMode)) {
206
- return "☀️ Light";
207
- } else {
208
- return "🌙 Dark";
209
- }
210
- }))], undefined)
211
- ], undefined),
212
- Xote__Component.div([[
213
- "class",
214
- "grid grid-cols-3 gap-4 mb-6 p-4 bg-gray-50 dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700"
215
- ]], undefined, [
216
- Xote__Component.div([[
217
- "class",
218
- "flex flex-col items-center"
219
- ]], undefined, [
220
- Xote__Component.span([[
221
- "class",
222
- "text-xs text-gray-600 dark:text-gray-400 uppercase tracking-wide mb-1"
223
- ]], undefined, [Xote__Component.text("Total")], undefined),
224
- Xote__Component.span([[
225
- "class",
226
- "text-2xl font-bold text-gray-900 dark:text-white"
227
- ]], undefined, [Xote__Component.textSignal(Xote__Computed.make(function () {
228
- return Xote__Signal.get(totalCount).toString();
229
- }))], undefined)
230
- ], undefined),
231
- Xote__Component.div([[
232
- "class",
233
- "flex flex-col items-center"
234
- ]], undefined, [
235
- Xote__Component.span([[
236
- "class",
237
- "text-xs text-gray-600 dark:text-gray-400 uppercase tracking-wide mb-1"
238
- ]], undefined, [Xote__Component.text("Active")], undefined),
239
- Xote__Component.span([[
240
- "class",
241
- "text-2xl font-bold text-blue-600 dark:text-blue-400"
242
- ]], undefined, [Xote__Component.textSignal(Xote__Computed.make(function () {
243
- return Xote__Signal.get(activeCount).toString();
244
- }))], undefined)
245
- ], undefined),
246
- Xote__Component.div([[
247
- "class",
248
- "flex flex-col items-center"
249
- ]], undefined, [
250
- Xote__Component.span([[
251
- "class",
252
- "text-xs text-gray-600 dark:text-gray-400 uppercase tracking-wide mb-1"
253
- ]], undefined, [Xote__Component.text("Completed")], undefined),
254
- Xote__Component.span([[
255
- "class",
256
- "text-2xl font-bold text-green-600 dark:text-green-400"
257
- ]], undefined, [Xote__Component.textSignal(Xote__Computed.make(function () {
258
- return Xote__Signal.get(completedCount).toString();
259
- }))], undefined)
260
- ], undefined)
261
- ], undefined),
262
- Xote__Component.div([[
263
- "class",
264
- "flex gap-2 mb-6"
265
- ]], undefined, [
266
- inputElement,
267
- Xote__Component.button([[
268
- "class",
269
- "px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500"
270
- ]], [[
271
- "click",
272
- handleAddClick
273
- ]], [Xote__Component.text("Add")], undefined)
274
- ], undefined),
275
- Xote__Component.ul([[
276
- "class",
277
- "todo-list space-y-2"
278
- ]], undefined, [Xote__Component.list(todos, todoItem)], undefined)
279
- ], undefined)], undefined);
280
-
281
- Xote__Component.mountById(app, "app");
282
-
283
- export {
284
- todos ,
285
- nextId ,
286
- inputValue ,
287
- darkMode ,
288
- completedCount ,
289
- activeCount ,
290
- totalCount ,
291
- addTodo ,
292
- toggleTodo ,
293
- clearInput ,
294
- handleInput ,
295
- getInputValue ,
296
- handleKeyDown ,
297
- handleAddClick ,
298
- toggleTheme ,
299
- todoItem ,
300
- inputElement ,
301
- app ,
302
- }
303
- /* todos Not a pure module */
package/src/Xote__Id.res DELETED
@@ -1,5 +0,0 @@
1
- let next = ref(0)
2
- let make = () => {
3
- next := next.contents + 1
4
- next.contents
5
- }
@@ -1,17 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
-
4
- var next = {
5
- contents: 0
6
- };
7
-
8
- function make() {
9
- next.contents = next.contents + 1 | 0;
10
- return next.contents;
11
- }
12
-
13
- export {
14
- next ,
15
- make ,
16
- }
17
- /* No side effect */
@@ -1,12 +0,0 @@
1
- module IntSet = Belt.Set.Int
2
- module IntMap = Belt.Map.Int
3
-
4
- type kind = [#Effect | #Computed(int)] /* holds the signal id it writes to */
5
-
6
- type t = {
7
- id: int,
8
- kind: kind,
9
- run: unit => unit,
10
- /* current dependency set (signal ids) */
11
- mutable deps: IntSet.t,
12
- }
@@ -1,12 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
-
4
- var IntSet;
5
-
6
- var IntMap;
7
-
8
- export {
9
- IntSet ,
10
- IntMap ,
11
- }
12
- /* No side effect */
@@ -1,31 +0,0 @@
1
- module IntSet = Belt.Set.Int
2
- module IntMap = Belt.Map.Int
3
- module Observer = Xote__Observer
4
- module Id = Xote__Id
5
- module Core = Xote__Core
6
-
7
- let make = (v: 'a): Core.t<'a> => {
8
- let id = Id.make()
9
- Core.ensureSignalBucket(id)
10
- {id, value: ref(v), version: ref(0)}
11
- }
12
-
13
- let get = (s: Core.t<'a>): 'a => {
14
- switch Core.currentObserverId.contents {
15
- | None => ()
16
- | Some(obsId) => Core.addDep(obsId, s.id)
17
- }
18
- s.value.contents
19
- }
20
-
21
- /* read without tracking */
22
- let peek = (s: Core.t<'a>): 'a => s.value.contents
23
-
24
- let set = (s: Core.t<'a>, v: 'a) => {
25
- // Always update - skip equality check to avoid issues with complex types
26
- s.value := v
27
- s.version := s.version.contents + 1
28
- Core.notify(s.id)
29
- }
30
-
31
- let update = (s: Core.t<'a>, f: 'a => 'a) => set(s, f(s.value.contents))
@@ -1,64 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Xote__Id from "./Xote__Id.res.mjs";
4
- import * as Xote__Core from "./Xote__Core.res.mjs";
5
-
6
- function make(v) {
7
- var id = Xote__Id.make();
8
- Xote__Core.ensureSignalBucket(id);
9
- return {
10
- id: id,
11
- value: {
12
- contents: v
13
- },
14
- version: {
15
- contents: 0
16
- }
17
- };
18
- }
19
-
20
- function get(s) {
21
- var obsId = Xote__Core.currentObserverId.contents;
22
- if (obsId !== undefined) {
23
- Xote__Core.addDep(obsId, s.id);
24
- }
25
- return s.value.contents;
26
- }
27
-
28
- function peek(s) {
29
- return s.value.contents;
30
- }
31
-
32
- function set(s, v) {
33
- s.value.contents = v;
34
- s.version.contents = s.version.contents + 1 | 0;
35
- Xote__Core.notify(s.id);
36
- }
37
-
38
- function update(s, f) {
39
- set(s, f(s.value.contents));
40
- }
41
-
42
- var IntSet;
43
-
44
- var IntMap;
45
-
46
- var Observer;
47
-
48
- var Id;
49
-
50
- var Core;
51
-
52
- export {
53
- IntSet ,
54
- IntMap ,
55
- Observer ,
56
- Id ,
57
- Core ,
58
- make ,
59
- get ,
60
- peek ,
61
- set ,
62
- update ,
63
- }
64
- /* No side effect */