mono-jsx 0.7.3 → 0.7.4
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/jsx-runtime.mjs +13 -7
- package/package.json +1 -1
- package/types/html.d.ts +7 -0
- package/types/mono.d.ts +81 -54
package/jsx-runtime.mjs
CHANGED
|
@@ -143,7 +143,7 @@ var $signal = Symbol.for("mono.signal");
|
|
|
143
143
|
var $vnode = Symbol.for("jsx.vnode");
|
|
144
144
|
|
|
145
145
|
// version.ts
|
|
146
|
-
var VERSION = "0.7.
|
|
146
|
+
var VERSION = "0.7.3";
|
|
147
147
|
|
|
148
148
|
// render.ts
|
|
149
149
|
var cdn = "https://raw.esm.sh";
|
|
@@ -408,12 +408,15 @@ async function render(node, options, write, writeJS, componentMode, routeForm) {
|
|
|
408
408
|
mcs.clear();
|
|
409
409
|
}
|
|
410
410
|
if (session && session.isDirty) {
|
|
411
|
-
const
|
|
411
|
+
const sessionStore = session.all();
|
|
412
412
|
const { name = "session", domain, path, expires, maxAge, secure, sameSite, secret } = options.session?.cookie ?? {};
|
|
413
413
|
if (secret) {
|
|
414
414
|
let cookie = name + "=";
|
|
415
|
-
if (
|
|
416
|
-
const data = JSON.stringify(
|
|
415
|
+
if (Object.keys(sessionStore).length > 0) {
|
|
416
|
+
const data = JSON.stringify([
|
|
417
|
+
sessionStore,
|
|
418
|
+
Math.floor((expires ? expires.getTime() : Date.now() + (maxAge ?? 18e5)) / 1e3)
|
|
419
|
+
]);
|
|
417
420
|
const signature = await subtle.sign(
|
|
418
421
|
"HMAC",
|
|
419
422
|
await subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]),
|
|
@@ -1230,7 +1233,7 @@ async function createSession(request, options) {
|
|
|
1230
1233
|
return isDirty;
|
|
1231
1234
|
},
|
|
1232
1235
|
get: (key) => sessionStore.get(key),
|
|
1233
|
-
|
|
1236
|
+
all: () => Object.fromEntries(sessionStore.entries()),
|
|
1234
1237
|
set: (key, value) => {
|
|
1235
1238
|
sessionStore.set(key, value);
|
|
1236
1239
|
isDirty = true;
|
|
@@ -1263,8 +1266,11 @@ async function createSession(request, options) {
|
|
|
1263
1266
|
encoder.encode(data)
|
|
1264
1267
|
);
|
|
1265
1268
|
if (verified) {
|
|
1266
|
-
|
|
1267
|
-
|
|
1269
|
+
const [map, exp] = JSON.parse(data);
|
|
1270
|
+
if (typeof exp === "number" && exp * 1e3 > Date.now()) {
|
|
1271
|
+
sessionStore = new Map(Object.entries(map));
|
|
1272
|
+
sessionId = sid;
|
|
1273
|
+
}
|
|
1268
1274
|
}
|
|
1269
1275
|
} catch (_) {
|
|
1270
1276
|
}
|
package/package.json
CHANGED
package/types/html.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export namespace HTML {
|
|
|
46
46
|
interface GlobalAttributes<T extends EventTarget> extends EventAttributes<T>, Aria.Attributes, Mono.BaseAttributes, JSX.HtmlTag {
|
|
47
47
|
/**
|
|
48
48
|
* A reference to the element.
|
|
49
|
+
* @mono-jsx
|
|
49
50
|
*/
|
|
50
51
|
ref?: HTMLElement | ((el: T) => unknown);
|
|
51
52
|
/** Defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS). */
|
|
@@ -105,6 +106,12 @@ export namespace HTML {
|
|
|
105
106
|
is?: string;
|
|
106
107
|
/** A boolean value that makes the browser disregard user input events for the element. Useful when click events are present. */
|
|
107
108
|
inert?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Enables view transition for the element.
|
|
111
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
|
|
112
|
+
* @mono-jsx
|
|
113
|
+
*/
|
|
114
|
+
viewTransition?: string | boolean;
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
interface HtmlAttributes<T extends EventTarget> extends GlobalAttributes<T>, RenderOptions {}
|
package/types/mono.d.ts
CHANGED
|
@@ -98,11 +98,6 @@ export interface BaseAttributes {
|
|
|
98
98
|
* The `slot` attribute assigns a slot in a [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM) shadow tree to an element: An element with a `slot` attribute is assigned to the slot created by the `<slot>` element whose name attribute's value matches that slot attribute's value.
|
|
99
99
|
*/
|
|
100
100
|
slot?: string;
|
|
101
|
-
/**
|
|
102
|
-
* The `viewTransition` attribute is used to control the view transition of the children.
|
|
103
|
-
* @mono-jsx
|
|
104
|
-
*/
|
|
105
|
-
viewTransition?: string | boolean;
|
|
106
101
|
}
|
|
107
102
|
|
|
108
103
|
export interface AsyncComponentAttributes {
|
|
@@ -123,95 +118,123 @@ export interface AsyncComponentAttributes {
|
|
|
123
118
|
|
|
124
119
|
export interface Elements {
|
|
125
120
|
/**
|
|
126
|
-
*
|
|
121
|
+
* A built-in element of mono-jsx that toggles the visibility of its children.
|
|
122
|
+
* @mono-jsx
|
|
127
123
|
*/
|
|
128
124
|
toggle: BaseAttributes & {
|
|
129
125
|
/**
|
|
130
|
-
* The
|
|
126
|
+
* The visibility of the children.
|
|
131
127
|
*/
|
|
132
128
|
show?: any;
|
|
133
129
|
/**
|
|
134
|
-
* The
|
|
130
|
+
* The visibility of the children.
|
|
135
131
|
*/
|
|
136
132
|
hidden?: any;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Enables view transition for the children.
|
|
136
|
+
*/
|
|
137
|
+
viewTransition?: string | boolean;
|
|
137
138
|
};
|
|
138
139
|
/**
|
|
139
|
-
*
|
|
140
|
+
* A a built-in element of mono-jsx that chooses one of its children based on the `slot` attribute to display.
|
|
140
141
|
* It is similar to a switch statement in programming languages.
|
|
142
|
+
* @mono-jsx
|
|
141
143
|
*/
|
|
142
144
|
switch: BaseAttributes & {
|
|
143
145
|
/**
|
|
144
|
-
*
|
|
146
|
+
* Which child to display.
|
|
145
147
|
*/
|
|
146
148
|
value?: string | number | boolean | null;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Enables view transition for the children.
|
|
152
|
+
*/
|
|
153
|
+
viewTransition?: string | boolean;
|
|
147
154
|
};
|
|
148
155
|
/**
|
|
149
|
-
*
|
|
156
|
+
* A built-in element of mono-jsx that is used to load components lazily,
|
|
150
157
|
* which can improve performance by reducing the initial load time of the application.
|
|
158
|
+
* @mono-jsx
|
|
151
159
|
*/
|
|
152
160
|
component: BaseAttributes & AsyncComponentAttributes & {
|
|
153
161
|
/**
|
|
154
|
-
* The
|
|
162
|
+
* The name of the component to render.
|
|
155
163
|
*/
|
|
156
164
|
name?: string;
|
|
157
165
|
/**
|
|
158
|
-
* The
|
|
166
|
+
* The props of the component to render.
|
|
159
167
|
*/
|
|
160
168
|
props?: Record<string, unknown>;
|
|
161
169
|
/**
|
|
162
|
-
* The
|
|
170
|
+
* The ref of the component.
|
|
163
171
|
*/
|
|
164
172
|
ref?: ComponentElement | ((el: ComponentElement) => void);
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Enables view transition for the children.
|
|
176
|
+
*/
|
|
177
|
+
viewTransition?: string | boolean;
|
|
165
178
|
};
|
|
166
179
|
/**
|
|
167
|
-
*
|
|
180
|
+
* A built-in element of mono-jsx that provides SPA routing.
|
|
181
|
+
* @mono-jsx
|
|
168
182
|
*/
|
|
169
183
|
router: BaseAttributes & AsyncComponentAttributes & {
|
|
170
184
|
/**
|
|
171
|
-
* The
|
|
185
|
+
* The base URL for the router.
|
|
172
186
|
*/
|
|
173
187
|
base?: string;
|
|
174
188
|
/**
|
|
175
|
-
* The
|
|
189
|
+
* The ref of the router.
|
|
176
190
|
*/
|
|
177
191
|
ref?: RouterElement | ((el: RouterElement) => void);
|
|
192
|
+
/**
|
|
193
|
+
* Enables view transition for the children.
|
|
194
|
+
* @mono-jsx
|
|
195
|
+
*/
|
|
196
|
+
viewTransition?: string | boolean;
|
|
178
197
|
};
|
|
179
198
|
/**
|
|
180
|
-
*
|
|
199
|
+
* A built-in element of mono-jsx that caches the rendered content of the child nodes
|
|
181
200
|
* with the given key and TTL.
|
|
201
|
+
* @mono-jsx
|
|
182
202
|
*/
|
|
183
203
|
cache: BaseAttributes & {
|
|
184
204
|
/**
|
|
185
|
-
* The
|
|
205
|
+
* The key of the cache.
|
|
186
206
|
*/
|
|
187
207
|
key?: string;
|
|
188
208
|
/**
|
|
189
|
-
* The
|
|
209
|
+
* The time-to-live of the cache in seconds.
|
|
190
210
|
*/
|
|
191
211
|
ttl?: number;
|
|
192
212
|
};
|
|
193
213
|
/**
|
|
194
|
-
*
|
|
214
|
+
* A built-in element of mono-jsx that treats the child nodes as static content,
|
|
195
215
|
* When the child nodes are rendered once, they will be cached in memory and reused on subsequent renders.
|
|
216
|
+
* @mono-jsx
|
|
196
217
|
*/
|
|
197
218
|
static: BaseAttributes;
|
|
198
219
|
/**
|
|
199
|
-
*
|
|
220
|
+
* A built-in element of mono-jsx that redirects to the given URL in the client side.
|
|
221
|
+
* @mono-jsx
|
|
200
222
|
*/
|
|
201
223
|
redirect: {
|
|
202
224
|
/**
|
|
203
|
-
* The
|
|
225
|
+
* The redirect URL.
|
|
204
226
|
*/
|
|
205
227
|
to?: string | URL;
|
|
206
228
|
/**
|
|
207
|
-
* The
|
|
229
|
+
* The replace behavior of the redirect.
|
|
208
230
|
* Only works when the `router` element is used.
|
|
209
231
|
*/
|
|
210
232
|
replace?: boolean;
|
|
211
233
|
};
|
|
212
234
|
/**
|
|
213
|
-
*
|
|
235
|
+
* A built-in element of mono-jsx that sets custom validation
|
|
214
236
|
* state for the form elements.
|
|
237
|
+
* @mono-jsx
|
|
215
238
|
*/
|
|
216
239
|
invalid: BaseAttributes & {
|
|
217
240
|
/**
|
|
@@ -220,63 +243,67 @@ export interface Elements {
|
|
|
220
243
|
for?: string;
|
|
221
244
|
};
|
|
222
245
|
/**
|
|
223
|
-
*
|
|
246
|
+
* A built-in element of mono-jsx that is used to display the content of the route form
|
|
224
247
|
* in the `form` element.
|
|
248
|
+
* @mono-jsx
|
|
225
249
|
*/
|
|
226
250
|
formslot: BaseAttributes & {
|
|
251
|
+
/**
|
|
252
|
+
* The insert position of the formslot.
|
|
253
|
+
*/
|
|
227
254
|
mode?: "insertbefore" | "insertafter" | "replace";
|
|
228
255
|
};
|
|
229
256
|
}
|
|
230
257
|
|
|
231
258
|
/**
|
|
232
|
-
* The
|
|
259
|
+
* The session storage API.
|
|
233
260
|
*/
|
|
234
261
|
export interface Session {
|
|
235
262
|
/**
|
|
236
|
-
* The
|
|
263
|
+
* The session ID.
|
|
237
264
|
*/
|
|
238
265
|
readonly sessionId: string;
|
|
239
266
|
/**
|
|
240
|
-
*
|
|
267
|
+
* If true, update the session cookie to the client.
|
|
241
268
|
*/
|
|
242
269
|
readonly isDirty: boolean;
|
|
243
270
|
/**
|
|
244
|
-
*
|
|
271
|
+
* Gets a value from the session.
|
|
245
272
|
*/
|
|
246
273
|
get<T = unknown>(key: string): T | undefined;
|
|
247
274
|
/**
|
|
248
|
-
*
|
|
275
|
+
* Gets all the entries from the session.
|
|
249
276
|
*/
|
|
250
|
-
|
|
277
|
+
all(): Record<string, unknown>;
|
|
251
278
|
/**
|
|
252
|
-
*
|
|
279
|
+
* Sets a value in the session.
|
|
253
280
|
*/
|
|
254
281
|
set(key: string, value: string | number | boolean | any[] | Record<string, unknown>): void;
|
|
255
282
|
/**
|
|
256
|
-
*
|
|
283
|
+
* Deletes a value from the session.
|
|
257
284
|
*/
|
|
258
285
|
delete(key: string): void;
|
|
259
286
|
/**
|
|
260
|
-
*
|
|
287
|
+
* Destroys the session.
|
|
261
288
|
*/
|
|
262
289
|
destroy(): void;
|
|
263
290
|
}
|
|
264
291
|
|
|
265
292
|
declare global {
|
|
266
293
|
/**
|
|
267
|
-
*
|
|
294
|
+
* Creates XSS-unsafed HTML content.
|
|
268
295
|
*/
|
|
269
296
|
var html: JSX.Raw;
|
|
270
297
|
/**
|
|
271
|
-
*
|
|
298
|
+
* An alias to `html`.
|
|
272
299
|
*/
|
|
273
300
|
var css: JSX.Raw;
|
|
274
301
|
/**
|
|
275
|
-
*
|
|
302
|
+
* An alias to `html`.
|
|
276
303
|
*/
|
|
277
304
|
var js: JSX.Raw;
|
|
278
305
|
/**
|
|
279
|
-
*
|
|
306
|
+
* Defines the Signals/Context/Refs types.
|
|
280
307
|
*/
|
|
281
308
|
type FC<Signals = {}, AppSignals = {}, Context = {}, Refs = {}, AppRefs = {}> = {
|
|
282
309
|
/**
|
|
@@ -284,78 +311,78 @@ declare global {
|
|
|
284
311
|
*/
|
|
285
312
|
readonly app: {
|
|
286
313
|
/**
|
|
287
|
-
* The `app.refs` object
|
|
314
|
+
* The `app.refs` object stores variables in the application scope.
|
|
288
315
|
* It is similar to `refs`, but it is shared across all components in the application.
|
|
289
316
|
*
|
|
290
317
|
* **⚠ This is a client-side only API.**
|
|
291
318
|
*/
|
|
292
319
|
readonly refs: AppRefs;
|
|
293
320
|
/**
|
|
294
|
-
* The `app.url` object contains the current URL
|
|
321
|
+
* The `app.url` object contains the current URL.
|
|
295
322
|
*/
|
|
296
323
|
readonly url: WithParams<URL>;
|
|
297
324
|
} & Omit<AppSignals, "refs" | "url">;
|
|
298
325
|
/**
|
|
299
|
-
* The rendering context.
|
|
326
|
+
* The rendering context object.
|
|
300
327
|
*
|
|
301
328
|
* **⚠ This is a server-side only API.**
|
|
302
329
|
*/
|
|
303
330
|
readonly context: Context;
|
|
304
331
|
/**
|
|
305
|
-
* The `request` object contains the current request
|
|
332
|
+
* The `request` object contains the current request.
|
|
306
333
|
*
|
|
307
334
|
* **⚠ This is a server-side only API.**
|
|
308
335
|
*/
|
|
309
336
|
readonly request: WithParams<
|
|
310
337
|
Request & {
|
|
311
338
|
/**
|
|
312
|
-
* Returns the URL of request as a URL object.
|
|
339
|
+
* Returns the URL of the request as a URL object.
|
|
313
340
|
*/
|
|
314
341
|
URL: URL;
|
|
315
342
|
}
|
|
316
343
|
>;
|
|
317
344
|
/**
|
|
318
|
-
* The `form` object created by the route form
|
|
345
|
+
* The `form` object created by the route form.
|
|
319
346
|
*
|
|
320
347
|
* **⚠ This is a server-side only API.**
|
|
321
348
|
*/
|
|
322
349
|
readonly form?: FormData;
|
|
323
350
|
/**
|
|
324
|
-
* The `session` object contains the current session
|
|
351
|
+
* The `session` object contains the current session.
|
|
325
352
|
*
|
|
326
353
|
* **⚠ This is a server-side only API.**
|
|
327
354
|
*/
|
|
328
355
|
readonly session: Session;
|
|
329
356
|
/**
|
|
330
|
-
* The `refs` object
|
|
357
|
+
* The `refs` object stores variables in clide side.
|
|
331
358
|
*
|
|
332
359
|
* **⚠ This is a client-side only API.**
|
|
333
360
|
*/
|
|
334
361
|
readonly refs: Refs;
|
|
335
362
|
/**
|
|
336
|
-
*
|
|
363
|
+
* Creates a computed signal.
|
|
337
364
|
*/
|
|
338
365
|
readonly computed: <T = unknown>(fn: () => T) => T;
|
|
339
366
|
/**
|
|
340
|
-
*
|
|
367
|
+
* A shortcut for `this.computed(fn)`.
|
|
341
368
|
*/
|
|
342
369
|
readonly $: FC["computed"];
|
|
343
370
|
/**
|
|
344
|
-
*
|
|
371
|
+
* Creates a side effect.
|
|
345
372
|
* **The effect function is only called on client side.**
|
|
346
373
|
*/
|
|
347
374
|
readonly effect: (fn: () => void | (() => void)) => void;
|
|
348
375
|
} & Omit<Signals, "app" | "context" | "request" | "session" | "form" | "refs" | "computed" | "$" | "effect">;
|
|
349
376
|
/**
|
|
350
|
-
*
|
|
377
|
+
* Defines the `refs` type.
|
|
351
378
|
*/
|
|
352
379
|
type Refs<T, R = {}, RR = {}> = T extends FC<infer S, infer A, infer C> ? FC<S, A, C, R, RR> : never;
|
|
353
380
|
/**
|
|
354
|
-
*
|
|
381
|
+
* Defines the `context` type.
|
|
355
382
|
*/
|
|
356
383
|
type Context<T, C = {}> = T extends FC<infer S, infer A, infer _, infer R, infer RR> ? FC<S, A, C, R, RR> : never;
|
|
357
384
|
/**
|
|
358
|
-
* The
|
|
385
|
+
* The `<component>` element.
|
|
359
386
|
*/
|
|
360
387
|
type ComponentElement = {
|
|
361
388
|
name: string;
|
|
@@ -363,7 +390,7 @@ declare global {
|
|
|
363
390
|
refresh: () => Promise<void>;
|
|
364
391
|
};
|
|
365
392
|
/**
|
|
366
|
-
* The
|
|
393
|
+
* The `<router>` element.
|
|
367
394
|
*/
|
|
368
395
|
type RouterElement = {
|
|
369
396
|
navigate: (url: string | URL, options?: { replace?: boolean }) => Promise<void>;
|