@zerotal/flow 1.0.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.
- package/CHANGELOG.md +61 -0
- package/LICENSE +21 -0
- package/README.md +148 -0
- package/package.json +84 -0
- package/src/Component.ts +1498 -0
- package/src/Form.ts +189 -0
- package/src/Layout.ts +47 -0
- package/src/augment.ts +94 -0
- package/src/client/FlowClientError.ts +12 -0
- package/src/client/FlowComponent.ts +96 -0
- package/src/client/alpinejs-morph.d.ts +5 -0
- package/src/client/bridge.ts +3463 -0
- package/src/client/confirm.ts +338 -0
- package/src/client/cspAdapter.ts +79 -0
- package/src/client/cspEvaluator.ts +494 -0
- package/src/client/errorOverlay.ts +124 -0
- package/src/client/headless.ts +948 -0
- package/src/client/index.csp.ts +47 -0
- package/src/client/index.ts +56 -0
- package/src/client/optimistic.ts +52 -0
- package/src/client/timeline.ts +160 -0
- package/src/client/url.ts +51 -0
- package/src/commands/MakeFlowCommand.ts +290 -0
- package/src/compiler/cache.ts +101 -0
- package/src/compiler/directives.ts +107 -0
- package/src/compiler/helpers.ts +26 -0
- package/src/compiler/index.ts +172 -0
- package/src/compiler/transform.ts +2070 -0
- package/src/components.ts +1465 -0
- package/src/config.ts +52 -0
- package/src/decorators.ts +978 -0
- package/src/dehydrate.ts +333 -0
- package/src/durable.ts +243 -0
- package/src/events.ts +118 -0
- package/src/frameworkEvents.ts +40 -0
- package/src/headless.ts +1147 -0
- package/src/index.ts +267 -0
- package/src/jsx-dev-runtime.ts +14 -0
- package/src/jsx-runtime.ts +1272 -0
- package/src/mixins.ts +199 -0
- package/src/observability.ts +167 -0
- package/src/pagination.ts +300 -0
- package/src/presence.ts +81 -0
- package/src/provider/FlowProvider.ts +1401 -0
- package/src/registry.ts +118 -0
- package/src/renderContext.ts +55 -0
- package/src/router.ts +401 -0
- package/src/shared.ts +226 -0
- package/src/store.ts +116 -0
- package/src/synths/CarbonIntervalSynth.ts +22 -0
- package/src/synths/CarbonSynth.ts +20 -0
- package/src/synths/CollectionSynth.ts +62 -0
- package/src/synths/DateSynth.ts +24 -0
- package/src/synths/ModelSynth.ts +78 -0
- package/src/synths/TemporaryUploadedFileSynth.ts +19 -0
- package/src/synths/index.ts +148 -0
- package/src/testing.ts +361 -0
- package/src/types.ts +315 -0
- package/src/uploads/FileUploads.ts +94 -0
- package/src/uploads/TemporaryUploadedFile.ts +274 -0
- package/src/uploads/sign.ts +18 -0
- package/src/urlSafety.ts +0 -0
- package/src/utils.ts +216 -0
- package/src/validation.ts +55 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flow — reactive server-side rendering over WebSocket for Zerotal.
|
|
3
|
+
*
|
|
4
|
+
* You write a {@link Component} as a server-side class: public state lives on
|
|
5
|
+
* the instance, `render()` returns server-rendered HTML, and methods marked
|
|
6
|
+
* {@link expose} are callable from the browser. When a user interacts, the
|
|
7
|
+
* action runs on the server, the component re-renders, and only the HTML diff
|
|
8
|
+
* is streamed back and morphed into the DOM (Alpine-style) — no client-side
|
|
9
|
+
* component code, no separate API. Snapshots that cross the wire are
|
|
10
|
+
* HMAC-signed and only {@link expose}d / {@link locked} properties are shared.
|
|
11
|
+
*
|
|
12
|
+
* The toolkit here covers the whole authoring surface: the {@link Component}
|
|
13
|
+
* base and {@link Layout}, the decorator set ({@link expose}, {@link locked},
|
|
14
|
+
* {@link computed}, {@link task}, {@link validate}, {@link on}, {@link url},
|
|
15
|
+
* {@link session}, {@link presence}, {@link shared}, …), {@link Form}s,
|
|
16
|
+
* {@link paginate | pagination}, file uploads ({@link FileUploads}), realtime
|
|
17
|
+
* presence and cross-client stores, and a library of ready-made view
|
|
18
|
+
* components ({@link Modal}, {@link Link}, {@link Flash}, …).
|
|
19
|
+
*
|
|
20
|
+
* @example Register the provider
|
|
21
|
+
* ```ts
|
|
22
|
+
* // bootstrap/providers.ts
|
|
23
|
+
* import { SessionProvider } from "@zerotal/session";
|
|
24
|
+
* import { FlowProvider } from "@zerotal/flow";
|
|
25
|
+
*
|
|
26
|
+
* export default [SessionProvider, FlowProvider];
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example A reactive counter component
|
|
30
|
+
* ```tsx
|
|
31
|
+
* import { Component, expose } from "@zerotal/flow";
|
|
32
|
+
* import type { HtmlNode } from "@zerotal/flow";
|
|
33
|
+
*
|
|
34
|
+
* export class Counter extends Component {
|
|
35
|
+
* count = 0;
|
|
36
|
+
*
|
|
37
|
+
* @expose increment(): void {
|
|
38
|
+
* this.count++;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* render(): HtmlNode {
|
|
42
|
+
* return (
|
|
43
|
+
* <button flow:click="increment">
|
|
44
|
+
* Clicked {this.count} times
|
|
45
|
+
* </button>
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* Components are authored in `.tsx` with `jsxImportSource` set to
|
|
53
|
+
* `@zerotal/flow` (see `@zerotal/flow/jsx-runtime`). Register
|
|
54
|
+
* `FlowProvider` after `SessionProvider`. Requires **Bun ≥ 1.1**.
|
|
55
|
+
*
|
|
56
|
+
* @packageDocumentation
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
// ── @zerotal/flow public API ────────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
// Side-effect import: augments @zerotal/core RouterMacros so Router.flow() is typed.
|
|
62
|
+
import "./augment.ts";
|
|
63
|
+
|
|
64
|
+
// Core Component class + layout base + decorators
|
|
65
|
+
export { Component, ErrorField } from "./Component.ts";
|
|
66
|
+
export type {
|
|
67
|
+
ErrorsProxy,
|
|
68
|
+
FlowEffects,
|
|
69
|
+
RedirectFlash,
|
|
70
|
+
FlashBuilder,
|
|
71
|
+
FlashOptions,
|
|
72
|
+
} from "./Component.ts";
|
|
73
|
+
// Compose focused feature mixins onto Component — `class extends ComponentWith(Pagination, …)`.
|
|
74
|
+
export { ComponentWith } from "./mixins.ts";
|
|
75
|
+
export type { Constructor, Mixin } from "./mixins.ts";
|
|
76
|
+
export { Layout } from "./Layout.ts";
|
|
77
|
+
export { Form, registerForm } from "./Form.ts";
|
|
78
|
+
// Global client store — app-wide, client-only reactive UI state, read in JSX as
|
|
79
|
+
// `$flow.$store.*`. `defineStore` declares its initial shape at app start; augment
|
|
80
|
+
// `FlowStore` to type it.
|
|
81
|
+
export { defineStore } from "./store.ts";
|
|
82
|
+
export type { FlowStore } from "./store.ts";
|
|
83
|
+
// Pagination state mixin (compose with `ComponentWith(Pagination)`); `paginate`/`Paginator`
|
|
84
|
+
// are the in-memory paginator.
|
|
85
|
+
export { paginate, Pagination } from "./pagination.ts";
|
|
86
|
+
export type { Paginator } from "./pagination.ts";
|
|
87
|
+
export {
|
|
88
|
+
Link,
|
|
89
|
+
Head,
|
|
90
|
+
Persist,
|
|
91
|
+
Title,
|
|
92
|
+
Modal,
|
|
93
|
+
Flash,
|
|
94
|
+
Errors,
|
|
95
|
+
ErrorMessage,
|
|
96
|
+
Dropdown,
|
|
97
|
+
Tabs,
|
|
98
|
+
InfiniteScroll,
|
|
99
|
+
For,
|
|
100
|
+
Loading,
|
|
101
|
+
Skeleton,
|
|
102
|
+
Pager,
|
|
103
|
+
FileUpload,
|
|
104
|
+
Tooltip,
|
|
105
|
+
Alert,
|
|
106
|
+
Table,
|
|
107
|
+
Drawer,
|
|
108
|
+
} from "./components.ts";
|
|
109
|
+
export type {
|
|
110
|
+
LinkProps,
|
|
111
|
+
ModalProps,
|
|
112
|
+
FlashProps,
|
|
113
|
+
ErrorsProps,
|
|
114
|
+
ErrorProps,
|
|
115
|
+
DropdownProps,
|
|
116
|
+
TabsProps,
|
|
117
|
+
TabItem,
|
|
118
|
+
InfiniteScrollProps,
|
|
119
|
+
ForProps,
|
|
120
|
+
LoadingProps,
|
|
121
|
+
SkeletonProps,
|
|
122
|
+
PagerProps,
|
|
123
|
+
FileUploadProps,
|
|
124
|
+
TooltipProps,
|
|
125
|
+
AlertProps,
|
|
126
|
+
TableProps,
|
|
127
|
+
TableColumn,
|
|
128
|
+
DrawerProps,
|
|
129
|
+
} from "./components.ts";
|
|
130
|
+
|
|
131
|
+
// Headless (unstyled, accessible) primitives — data-* state, Tailwind-friendly.
|
|
132
|
+
export {
|
|
133
|
+
Switch,
|
|
134
|
+
Disclosure,
|
|
135
|
+
Accordion,
|
|
136
|
+
Popover,
|
|
137
|
+
Checkbox,
|
|
138
|
+
Select,
|
|
139
|
+
RadioGroup,
|
|
140
|
+
Listbox,
|
|
141
|
+
Combobox,
|
|
142
|
+
Field,
|
|
143
|
+
Label,
|
|
144
|
+
Description,
|
|
145
|
+
Fieldset,
|
|
146
|
+
Legend,
|
|
147
|
+
Slider,
|
|
148
|
+
ToggleGroup,
|
|
149
|
+
Calendar,
|
|
150
|
+
} from "./headless.ts";
|
|
151
|
+
export type {
|
|
152
|
+
SwitchProps,
|
|
153
|
+
DisclosureProps,
|
|
154
|
+
AccordionProps,
|
|
155
|
+
AccordionItem,
|
|
156
|
+
PopoverProps,
|
|
157
|
+
CheckboxProps,
|
|
158
|
+
SelectProps,
|
|
159
|
+
SelectOption,
|
|
160
|
+
RadioGroupProps,
|
|
161
|
+
RadioOption,
|
|
162
|
+
ListboxProps,
|
|
163
|
+
ListboxOption,
|
|
164
|
+
ComboboxProps,
|
|
165
|
+
ComboboxOption,
|
|
166
|
+
FieldProps,
|
|
167
|
+
LabelProps,
|
|
168
|
+
DescriptionProps,
|
|
169
|
+
FieldsetProps,
|
|
170
|
+
LegendProps,
|
|
171
|
+
SliderProps,
|
|
172
|
+
ToggleGroupProps,
|
|
173
|
+
ToggleOption,
|
|
174
|
+
CalendarProps,
|
|
175
|
+
} from "./headless.ts";
|
|
176
|
+
export { computed } from "./decorators.ts";
|
|
177
|
+
export { transient } from "./decorators.ts";
|
|
178
|
+
export { expose } from "./decorators.ts";
|
|
179
|
+
export { locked } from "./decorators.ts";
|
|
180
|
+
export { renderless } from "./decorators.ts";
|
|
181
|
+
export { task } from "./decorators.ts";
|
|
182
|
+
export { validate } from "./decorators.ts";
|
|
183
|
+
export { on } from "./decorators.ts";
|
|
184
|
+
export { url } from "./decorators.ts";
|
|
185
|
+
export { param } from "./decorators.ts";
|
|
186
|
+
export { session } from "./decorators.ts";
|
|
187
|
+
export type { SessionOptions } from "./decorators.ts";
|
|
188
|
+
export { reactive } from "./decorators.ts";
|
|
189
|
+
export { modelable } from "./decorators.ts";
|
|
190
|
+
export { presence } from "./decorators.ts";
|
|
191
|
+
export type { PresenceChannel } from "./decorators.ts";
|
|
192
|
+
export type { PresenceMember } from "./presence.ts";
|
|
193
|
+
export { shared } from "./decorators.ts";
|
|
194
|
+
export type { SharedChannel } from "./decorators.ts";
|
|
195
|
+
export { getSharedStore, setSharedStore } from "./shared.ts";
|
|
196
|
+
export type { SharedStore } from "./shared.ts";
|
|
197
|
+
export { getDurableStore, setDurableStore } from "./durable.ts";
|
|
198
|
+
export type { DurableStore, DurableOption } from "./durable.ts";
|
|
199
|
+
export { registerFlowEvent } from "./events.ts";
|
|
200
|
+
export type { FlowEvents, EventName, EventPayload } from "./events.ts";
|
|
201
|
+
|
|
202
|
+
// Framework instrumentation events (emitted on the core FrameworkEvents bus)
|
|
203
|
+
export { WebSocketConnected, WebSocketDisconnected, FlowActionHandled } from "./frameworkEvents.ts";
|
|
204
|
+
|
|
205
|
+
// Provider + router helper
|
|
206
|
+
export { FlowProvider, flowActiveConnections, flowConnections } from "./provider/FlowProvider.ts";
|
|
207
|
+
export { FlowConfig, DEFAULT_PERSISTENT_MIDDLEWARE } from "./config.ts";
|
|
208
|
+
export type { FlowConfigShape } from "./config.ts";
|
|
209
|
+
export type { FlowConnection } from "./provider/FlowProvider.ts";
|
|
210
|
+
|
|
211
|
+
// Synthesizer extension point
|
|
212
|
+
export { registerSynth } from "./synths/index.ts";
|
|
213
|
+
export type { Synth } from "./synths/index.ts";
|
|
214
|
+
|
|
215
|
+
// Model registration helper
|
|
216
|
+
export { registerFlowModel } from "./synths/ModelSynth.ts";
|
|
217
|
+
|
|
218
|
+
// Side-effect imports: register built-in synths.
|
|
219
|
+
import "./synths/CarbonSynth.ts";
|
|
220
|
+
import "./synths/CarbonIntervalSynth.ts";
|
|
221
|
+
import "./synths/CollectionSynth.ts";
|
|
222
|
+
import "./synths/DateSynth.ts";
|
|
223
|
+
import "./synths/TemporaryUploadedFileSynth.ts";
|
|
224
|
+
import type { MiddlewareClass, RouteRegistration } from "@zerotal/core";
|
|
225
|
+
import type { PageClassWithMeta } from "./registry.ts";
|
|
226
|
+
|
|
227
|
+
// File uploads
|
|
228
|
+
export { TemporaryUploadedFile } from "./uploads/TemporaryUploadedFile.ts";
|
|
229
|
+
export type { UploadRef } from "./uploads/TemporaryUploadedFile.ts";
|
|
230
|
+
// File-upload management mixin (compose with `ComponentWith(FileUploads)`).
|
|
231
|
+
export { FileUploads } from "./uploads/FileUploads.ts";
|
|
232
|
+
|
|
233
|
+
// Validation
|
|
234
|
+
export { ValidationError } from "./validation.ts";
|
|
235
|
+
export type { ValidationRules } from "./validation.ts";
|
|
236
|
+
|
|
237
|
+
// Types
|
|
238
|
+
export type {
|
|
239
|
+
Snapshot,
|
|
240
|
+
SnapshotData,
|
|
241
|
+
SnapshotMemo,
|
|
242
|
+
ChildMemo,
|
|
243
|
+
CallFrame,
|
|
244
|
+
PatchFrame,
|
|
245
|
+
FlashFrame,
|
|
246
|
+
RedirectFrame,
|
|
247
|
+
ErrorFrame,
|
|
248
|
+
EventFrame,
|
|
249
|
+
DownloadFrame,
|
|
250
|
+
FlashLevel,
|
|
251
|
+
FlashMessage,
|
|
252
|
+
FlashPosition,
|
|
253
|
+
FlashAction,
|
|
254
|
+
FlashActionStyle,
|
|
255
|
+
FlashActionVariant,
|
|
256
|
+
FlashCallback,
|
|
257
|
+
} from "./types.ts";
|
|
258
|
+
|
|
259
|
+
export type { HtmlNode } from "./jsx-runtime.ts";
|
|
260
|
+
export type { PageClassWithMeta } from "./registry.ts";
|
|
261
|
+
export { registerComponent } from "./registry.ts";
|
|
262
|
+
export type { UrlOptions } from "./decorators.ts";
|
|
263
|
+
|
|
264
|
+
// Core utilities
|
|
265
|
+
export { flow, jsLiteral } from "./utils.ts";
|
|
266
|
+
export { isSafeUrl, sanitizeUrl, URL_ATTRIBUTES, BLOCKED_URL } from "./urlSafety.ts";
|
|
267
|
+
export type { FlowChain } from "./utils.ts";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// ── @zerotal/flow/jsx-dev-runtime ────────────────────────────────────────────────
|
|
2
|
+
//
|
|
3
|
+
// The dev-mode JSX entry the toolchain resolves to for non-production `.tsx` builds
|
|
4
|
+
// (`jsxImportSource: "@zerotal/flow"`). It simply re-exports the same factories as
|
|
5
|
+
// `jsx-runtime`, adding the `jsxDEV` alias Bun/TS emit in development. Compiler-facing —
|
|
6
|
+
// application code imports neither directly.
|
|
7
|
+
|
|
8
|
+
export { jsx, jsxs, Fragment, renderToString } from "./jsx-runtime.ts";
|
|
9
|
+
/**
|
|
10
|
+
* Dev-mode element factory Bun/TypeScript emit in non-production builds; aliased to `jsx`.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export { jsx as jsxDEV } from "./jsx-runtime.ts";
|
|
14
|
+
export type { HtmlNode } from "./jsx-runtime.ts";
|