@manyducks.co/dolla 2.0.0 → 3.1.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.
Files changed (112) hide show
  1. package/README.md +133 -284
  2. package/dist/context-B5blupD2.js +363 -0
  3. package/dist/context-B5blupD2.js.map +1 -0
  4. package/dist/core/context.d.ts +29 -144
  5. package/dist/core/debug.d.ts +19 -0
  6. package/dist/core/index.d.ts +15 -16
  7. package/dist/core/markup/helpers.d.ts +34 -0
  8. package/dist/core/markup/html.d.ts +3 -0
  9. package/dist/core/{nodes → markup/nodes}/dom.d.ts +5 -4
  10. package/dist/core/markup/nodes/dynamic.d.ts +16 -0
  11. package/dist/core/markup/nodes/element.d.ts +14 -0
  12. package/dist/core/markup/nodes/portal.d.ts +15 -0
  13. package/dist/core/markup/nodes/repeat.d.ts +21 -0
  14. package/dist/core/markup/nodes/view.d.ts +17 -0
  15. package/dist/core/markup/scheduler.d.ts +1 -0
  16. package/dist/core/markup/types.d.ts +62 -0
  17. package/dist/core/markup/utils.d.ts +22 -0
  18. package/dist/core/ref.d.ts +6 -12
  19. package/dist/core/root.d.ts +36 -0
  20. package/dist/core/signals.d.ts +46 -76
  21. package/dist/core/symbols.d.ts +2 -0
  22. package/dist/core-JHktdqjt.js +242 -0
  23. package/dist/core-JHktdqjt.js.map +1 -0
  24. package/dist/http/index.d.ts +21 -33
  25. package/dist/http.js +89 -149
  26. package/dist/http.js.map +1 -1
  27. package/dist/index.js +4 -174
  28. package/dist/jsx-dev-runtime.d.ts +4 -3
  29. package/dist/jsx-dev-runtime.js +12 -9
  30. package/dist/jsx-dev-runtime.js.map +1 -1
  31. package/dist/jsx-runtime.d.ts +5 -4
  32. package/dist/jsx-runtime.js +17 -12
  33. package/dist/jsx-runtime.js.map +1 -1
  34. package/dist/router/index.d.ts +4 -3
  35. package/dist/router/router.d.ts +19 -162
  36. package/dist/router/store.d.ts +12 -0
  37. package/dist/router/types.d.ts +152 -0
  38. package/dist/router/utils.d.ts +99 -0
  39. package/dist/router/utils.test.d.ts +1 -0
  40. package/dist/router.js +428 -5
  41. package/dist/router.js.map +1 -1
  42. package/dist/signals-CMJPGr_M.js +354 -0
  43. package/dist/signals-CMJPGr_M.js.map +1 -0
  44. package/dist/translate/index.d.ts +82 -0
  45. package/dist/translate.js +125 -0
  46. package/dist/translate.js.map +1 -0
  47. package/dist/types.d.ts +21 -39
  48. package/dist/utils.d.ts +41 -29
  49. package/dist/utils.test.d.ts +1 -0
  50. package/dist/virtual/index.d.ts +1 -0
  51. package/dist/virtual/list.d.ts +53 -0
  52. package/package.json +19 -16
  53. package/dist/core/app.d.ts +0 -24
  54. package/dist/core/env.d.ts +0 -3
  55. package/dist/core/hooks.d.ts +0 -70
  56. package/dist/core/logger.d.ts +0 -42
  57. package/dist/core/logger.test.d.ts +0 -0
  58. package/dist/core/markup.d.ts +0 -82
  59. package/dist/core/markup.test.d.ts +0 -0
  60. package/dist/core/nodes/_markup.d.ts +0 -36
  61. package/dist/core/nodes/dynamic.d.ts +0 -22
  62. package/dist/core/nodes/element.d.ts +0 -27
  63. package/dist/core/nodes/portal.d.ts +0 -18
  64. package/dist/core/nodes/repeat.d.ts +0 -27
  65. package/dist/core/nodes/view.d.ts +0 -25
  66. package/dist/core/views/default-crash-view.d.ts +0 -25
  67. package/dist/core/views/for.d.ts +0 -21
  68. package/dist/core/views/fragment.d.ts +0 -7
  69. package/dist/core/views/portal.d.ts +0 -16
  70. package/dist/core/views/show.d.ts +0 -25
  71. package/dist/fragment-BahD_BJA.js +0 -7
  72. package/dist/fragment-BahD_BJA.js.map +0 -1
  73. package/dist/i18n/index.d.ts +0 -134
  74. package/dist/i18n.js +0 -309
  75. package/dist/i18n.js.map +0 -1
  76. package/dist/index-DRJlxs-Q.js +0 -535
  77. package/dist/index-DRJlxs-Q.js.map +0 -1
  78. package/dist/index.js.map +0 -1
  79. package/dist/logger-Aqi9m1CF.js +0 -565
  80. package/dist/logger-Aqi9m1CF.js.map +0 -1
  81. package/dist/markup-8jNhoqDe.js +0 -1089
  82. package/dist/markup-8jNhoqDe.js.map +0 -1
  83. package/dist/router/hooks.d.ts +0 -2
  84. package/dist/router/router.utils.d.ts +0 -93
  85. package/dist/typeChecking-5kmX0ulW.js +0 -65
  86. package/dist/typeChecking-5kmX0ulW.js.map +0 -1
  87. package/dist/typeChecking.d.ts +0 -95
  88. package/docs/buildless.md +0 -132
  89. package/docs/components.md +0 -238
  90. package/docs/hooks.md +0 -356
  91. package/docs/http.md +0 -178
  92. package/docs/i18n.md +0 -220
  93. package/docs/index.md +0 -10
  94. package/docs/markup.md +0 -136
  95. package/docs/mixins.md +0 -176
  96. package/docs/ref.md +0 -77
  97. package/docs/router.md +0 -281
  98. package/docs/setup.md +0 -137
  99. package/docs/signals.md +0 -262
  100. package/docs/stores.md +0 -113
  101. package/docs/views.md +0 -356
  102. package/notes/atomic.md +0 -452
  103. package/notes/elimination.md +0 -33
  104. package/notes/observable.md +0 -180
  105. package/notes/scratch.md +0 -565
  106. package/notes/splitting.md +0 -5
  107. package/notes/views.md +0 -195
  108. package/vite.config.js +0 -22
  109. /package/dist/core/{hooks.test.d.ts → markup/html.test.d.ts} +0 -0
  110. /package/dist/core/{ref.test.d.ts → markup/utils.test.d.ts} +0 -0
  111. /package/dist/router/{router.utils.test.d.ts → matcher.test.d.ts} +0 -0
  112. /package/dist/{typeChecking.test.d.ts → router/router.test.d.ts} +0 -0
package/docs/views.md DELETED
@@ -1,356 +0,0 @@
1
- # Dolla Views: The Main Character
2
-
3
- Aight, let's talk about the main event, the star of the show: **Views**.
4
-
5
- Views are the components you're gonna be writing 99% of the time. They're the bread and butter of your Dolla app. Their whole job is to take some data and spit out the HTML that shows up on the screen. If you've ever written a React component, you're already basically a pro at this.
6
-
7
- ## So, what even IS a View?
8
-
9
- It's dead simple: **a View is just a JavaScript function that returns JSX.** That's it. No classes, no weird `render()` methods, just a function.
10
-
11
- ### The Simplest View
12
-
13
- Here's a View that literally just says hello. It doesn't get any easier than this.
14
-
15
- ```jsx
16
- // This is a totally valid View component!
17
- function HelloWorld() {
18
- return <h1>What up, world!</h1>;
19
- }
20
- ```
21
-
22
- You can then use this component in another component just like it's a regular HTML tag:
23
-
24
- ```jsx
25
- function App() {
26
- return (
27
- <div>
28
- <HelloWorld />
29
- </div>
30
- );
31
- }
32
- ```
33
-
34
- ## Props: Making Your Views Reusable
35
-
36
- A component that does the same thing every time is kinda boring. You're gonna want to pass data into your Views to make them dynamic. We do this with **props** (short for properties).
37
-
38
- Props are passed to your View function as a single object.
39
-
40
- ```jsx
41
- // This View can now greet anyone!
42
- function Greeting(props) {
43
- // `props` is an object: { name: "Alice" }
44
- return <h1>Yo, {props.name}!</h1>;
45
- }
46
-
47
- function App() {
48
- return <Greeting name="Alice" />;
49
- }
50
- ```
51
-
52
- ### Passing Dynamic Props (aka The Cool Part)
53
-
54
- You can pass anything as a prop: strings, numbers, arrays, objects, even other components. But the real magic is passing **signals**.
55
-
56
- If you're passing the whole signal, you can just pass it directly. It'll stay reactive.
57
-
58
- ```jsx
59
- function App() {
60
- const [$userName, setUserName] = useSignal("Guest");
61
- setTimeout(() => setUserName("Bob"), 2000);
62
-
63
- // Just pass the signal directly! It stays reactive.
64
- return <Greeting name={$userName} />;
65
- }
66
- ```
67
-
68
- But what if you need to pass a _piece_ of a signal, like a property from an object? If you just write `name={$currentUser().name}`, you're only getting the value _right now_, and it won't update later. That's a bummer.
69
-
70
- **Super Important Rule:** To keep it reactive when you're _accessing or deriving a value_ from a signal, you gotta wrap it in an arrow function `() => ...`. This tells Dolla to re-run that little function whenever the original signal changes.
71
-
72
- ```jsx
73
- function App() {
74
- const [$currentUser, setCurrentUser] = useSignal({ name: "Guest" });
75
- setTimeout(() => setCurrentUser({ name: "Alice" }), 2000);
76
-
77
- return (
78
- <div>
79
- {/* This LOSES reactivity because we're calling the function now */}
80
- <Greeting name={$currentUser().name} />
81
-
82
- {/* This STAYS reactive because we wrapped it in another function! */}
83
- <Greeting name={() => $currentUser().name} />
84
- </div>
85
- );
86
- }
87
- ```
88
-
89
- ### The Special `children` Prop
90
-
91
- Sometimes you wanna wrap one component inside another. The inner component gets passed to the outer one in a special prop called `children`.
92
-
93
- ```jsx
94
- function Card(props) {
95
- // This component is a generic "card" wrapper
96
- return <div class="card">{props.children}</div>;
97
- }
98
-
99
- function App() {
100
- return (
101
- <Card>
102
- {/* This stuff is the `children` prop for the Card */}
103
- <h2>This is a card</h2>
104
- <p>It can have anything inside it!</p>
105
- </Card>
106
- );
107
- }
108
- ```
109
-
110
- ## Superpowered JSX: Props, Events, and More
111
-
112
- When your View returns JSX, you can put some special props on the HTML elements that have superpowers. These are handled by Dolla directly and aren't passed down into child components.
113
-
114
- ### `ref`: Grabbing the HTML Element
115
-
116
- Sometimes you need to get your hands dirty and talk to the actual HTML element. The `ref` prop is your escape hatch for that.
117
-
118
- ```jsx
119
- import { useRef, useMount } from "@manyducks.co/dolla";
120
-
121
- function AutoFocusInput() {
122
- const inputEl = useRef();
123
-
124
- useMount(() => {
125
- // We can now talk to the real <input> element!
126
- inputEl.current.focus();
127
- });
128
-
129
- // Just pass the ref to the element
130
- return <input ref={inputEl} type="text" />;
131
- }
132
- ```
133
-
134
- ### `mixin`: Adding Superpowers
135
-
136
- We have [a whole doc page on mixins](./mixins.md), but just know you apply them to an element using the `mixin` prop.
137
-
138
- ```jsx
139
- import { autofocus } from "./mixins/autofocus.js";
140
-
141
- function MyForm() {
142
- return <input mixin={autofocus()} />;
143
- }
144
- ```
145
-
146
- ### `class`: The Class Name GOAT
147
-
148
- Managing CSS classes can be a pain. Dolla's `class` prop makes it a breeze. You can pass it an array of strings, or even better, an object where the keys are class names and the values are signals that toggle them. This is fully reactive\!
149
-
150
- ```jsx
151
- import { useSignal } from "@manyducks.co/dolla";
152
-
153
- function InteractiveBox() {
154
- const [$isActive, setActive] = useSignal(false);
155
-
156
- return (
157
- <div
158
- class={{
159
- box: true, // This class is always on
160
- active: $isActive, // This class toggles when $isActive changes
161
- }}
162
- onClick={() => setActive((current) => !current)}
163
- >
164
- Click me to toggle the 'active' class.
165
- </div>
166
- );
167
- }
168
- ```
169
-
170
- ### Handling Events
171
-
172
- Dolla gives you a few ways to listen for events.
173
-
174
- - **CamelCase:** Just like in React, you can use `onClick`, `onInput`, `onMouseEnter`, etc. This is the main way you'll do it.
175
- - **`on:` prefix:** You can also use `on:click`, `on:input`, etc. This is useful for custom events that aren't on Dolla's known event list.
176
- - **`onClickOutside`:** This is a special one\! It's a synthetic event that fires when you click anywhere _outside_ the element. It's perfect for closing modals and dropdowns.
177
-
178
- <!-- end list -->
179
-
180
- ```jsx
181
- function EventExample() {
182
- const handleClick = () => console.log("Clicked!");
183
- const handleCustom = () => console.log("Custom event fired!");
184
- const handleOutside = () => console.log("Clicked outside!");
185
-
186
- return (
187
- <div onClick={handleClick} on:my-custom-event={handleCustom} onClickOutside={handleOutside}>
188
- Click me!
189
- </div>
190
- );
191
- }
192
- ```
193
-
194
- ### `attr:` and `prop:` Prefixes
195
-
196
- Sometimes, HTML is weird. There's a difference between an element's _attribute_ (the thing you write in the HTML) and its _property_ (the thing on the DOM object in JavaScript). Usually, Dolla figures it out for you, but if you need to be specific, you can use prefixes.
197
-
198
- - `attr:my-attribute={...}`: This will _always_ set the HTML attribute.
199
- - `prop:myProperty={...}`: This will _always_ set the DOM property.
200
-
201
- <!-- end list -->
202
-
203
- ```jsx
204
- // This sets the `aria-label` attribute, which is what you want for accessibility.
205
- <button attr:aria-label="Close">X</button>
206
-
207
- // This sets the `.value` property of the input, which is what you want for controlled inputs.
208
- <input prop:value={$mySignal} />
209
- ```
210
-
211
- ### Other Cool Prop Tricks
212
-
213
- - **`style`:** You can pass a style object, and it works just like you'd expect. You can even pass signals as values, and the styles will update automatically\!
214
- - **`dataset`:** Pass an object to `dataset` to set a bunch of `data-*` attributes all at once.
215
- - **SVG Support:** Dolla automatically knows when you're making an `<svg>` element and will handle creating it and its children correctly. No extra work needed.
216
-
217
- ## Built-in Views: Control Flow & Utilities
218
-
219
- Dolla also gives you a few built-in views to make common UI patterns easier. They're just special components that you can use alongside your own.
220
-
221
- ### `<Show>`: The "Now You Can See Me, Now You Can't" Component
222
-
223
- The `<Show>` component is your new bestie for conditional rendering. It's a super clean way to show or hide stuff based on whether something is true or false. Way better than a messy ternary operator in your JSX, tbh.
224
-
225
- #### The Props
226
-
227
- - **`when`**: The main one. If the value you pass it is "truthy" (not `false`, `0`, `null`, or `undefined`), the children will show up.
228
- - **`unless`**: The opposite of `when`. If the value is "falsy," the children will show.
229
- - **`children`**: The stuff you actually wanna show or hide.
230
- - **`fallback`**: What to show if the condition isn't met. Kinda like an `else` statement.
231
-
232
- #### Example
233
-
234
- ```jsx
235
- import { Show, useSignal, useMemo } from "@manyducks.co/dolla";
236
-
237
- function UserProfile() {
238
- const [$user, setUser] = useSignal(null);
239
- const $isLoggedIn = useMemo(() => $user() !== null);
240
-
241
- // Pretend we log in after 2 seconds
242
- setTimeout(() => setUser({ name: "Alice" }), 2000);
243
-
244
- return (
245
- <div class="user-widget">
246
- <Show when={$isLoggedIn} fallback={<p>Loading profile...</p>}>
247
- <h2>Welcome back, {() => $user().name}!</h2>
248
- </Show>
249
- </div>
250
- );
251
- }
252
- ```
253
-
254
- ### `<For>`: The Looping GOAT
255
-
256
- When you have an array of stuff and you need to render a list, `<For>` is what you want. It's super optimized, so if you add, remove, or reorder items in your array, it only touches the exact HTML elements that need to change. It's way more efficient than just using `.map()`.
257
-
258
- #### The Props
259
-
260
- - **`each`**: The signal that holds your array of items.
261
- - **`key`** (optional but recommended): A function that returns a unique ID for each item. This helps Dolla keep track of things and makes updates way faster, especially if your list can be reordered. If you don't provide one, it just uses the item itself as the key.
262
- - **`children`**: A function that gets called for every item in the array. It's your job to return the JSX for that item.
263
-
264
- The `children` function gets two arguments, and they're both **signals**: `($item, $index) => { ... }`. Because they're signals, Dolla can do some really smart optimizations instead of just recreating everything when the list changes.
265
-
266
- #### Example
267
-
268
- ```jsx
269
- import { For, useSignal } from "@manyducks.co/dolla";
270
-
271
- function UserList() {
272
- const [$users, setUsers] = useSignal([
273
- { id: 1, name: "Alice" },
274
- { id: 2, name: "Bob" },
275
- ]);
276
-
277
- const addUser = () => {
278
- const id = Math.random();
279
- setUsers((current) => [...current, { id, name: "New User" }]);
280
- };
281
-
282
- return (
283
- <div>
284
- <button onClick={addUser}>Add User</button>
285
- <ul>
286
- <For each={$users} key={(user) => user.id}>
287
- {($item, $index) => (
288
- <li>
289
- User #{$index}: {() => $item().name}
290
- </li>
291
- )}
292
- </For>
293
- </ul>
294
- </div>
295
- );
296
- }
297
- ```
298
-
299
- ### `<Portal>`: The Teleporter
300
-
301
- A `<Portal>` takes its children and renders them somewhere else on the page, outside of your main app container. This is clutch for stuff like modals, pop-up notifications, or tooltips that need to break out of their parent's styling.
302
-
303
- And here's the best part: even though the HTML gets yeeted to another part of the DOM, the Portal is still your component's child in the "component tree". That means it can still access all the same context and stores as if it were rendered right there. It's a total game-changer for modals that need to talk to your app's state.
304
-
305
- #### The Props
306
-
307
- - **`into`**: Where you wanna yeet the content. This can be a DOM element (like `document.body`) or a CSS selector string (like `'#modal-root'`).
308
- - **`children`**: The stuff you wanna teleport.
309
-
310
- #### Example
311
-
312
- ```jsx
313
- import { Portal, Show, useSignal } from "@manyducks.co/dolla";
314
-
315
- function ModalExample() {
316
- const [$isOpen, setOpen] = useSignal(false);
317
-
318
- return (
319
- <>
320
- <button onClick={() => setOpen(true)}>Open Modal</button>
321
- <Show when={$isOpen}>
322
- <Portal into="#modal-root">
323
- <div class="modal-content">
324
- <h2>This is a modal!</h2>
325
- <p>It's living in a different part of the DOM.</p>
326
- <button onClick={() => setOpen(false)}>Close</button>
327
- </div>
328
- </Portal>
329
- </Show>
330
- </>
331
- );
332
- }
333
- ```
334
-
335
- ### `<Fragment>`: The Invisible Wrapper
336
-
337
- You're almost never gonna type `<Fragment>` yourself. It's the thing that lets you return a bunch of elements from a component without having to wrap them in a `<div>`. When you type `<>...</>`, you're actually using a Fragment. It's the GOAT for keeping your HTML clean.
338
-
339
- ## To Sum It Up
340
-
341
- - **Views** are just functions that return JSX.
342
- - You pass data to them using **props**.
343
- - To keep data reactive, pass signals directly (`prop={$mySignal}`), or wrap derived values in a function (`prop={() => $mySignal().value}`).
344
- - Dolla gives you special props like `ref`, `mixin`, and `class` for the DOM nodes inside your Views, plus a bunch of other cool tricks.
345
- - You also get handy built-in Views like `<Show>`, `<For>`, and `<Portal>` to make your life easier.
346
- - If you need to manage state that's shared between a bunch of views, that's a job for a **Store**.
347
- - If you just need to add behavior to a single HTML element, that's a job for a **Mixin**.
348
- - For everything else—the actual structure and UI of your app—you'll be writing **Views**.
349
-
350
- ---
351
-
352
- End.
353
-
354
- - [🗂️ Docs](./index.md)
355
- - [🏠 README](../README.md)
356
- - [🦆 That's a lot of ducks.](https://www.manyducks.co)