mono-jsx 0.9.4 → 0.9.6
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/dom/jsx-runtime.mjs +29 -22
- package/jsx-runtime.mjs +1 -1
- package/package.json +1 -1
- package/types/dom/index.d.ts +4 -2
- package/types/html.d.ts +7 -7
- package/types/jsx.d.ts +2 -2
- package/types/mono.d.ts +3 -1
package/dom/jsx-runtime.mjs
CHANGED
|
@@ -77,6 +77,12 @@ var Signal = class extends Reactive {
|
|
|
77
77
|
watch(callback, abortSignal) {
|
|
78
78
|
onAbort(abortSignal, this.#scope[$watch](this.#key, callback));
|
|
79
79
|
}
|
|
80
|
+
ref(callback) {
|
|
81
|
+
if (callback) {
|
|
82
|
+
return new Computed(this.#scope, () => callback(this.get()));
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
80
86
|
};
|
|
81
87
|
var Computed = class extends Reactive {
|
|
82
88
|
#scope;
|
|
@@ -117,18 +123,18 @@ var Ref = class {
|
|
|
117
123
|
};
|
|
118
124
|
var InsertMark = class {
|
|
119
125
|
#root;
|
|
120
|
-
#
|
|
121
|
-
constructor(root) {
|
|
126
|
+
#anchor;
|
|
127
|
+
constructor(root, signal) {
|
|
128
|
+
const anchor = createTextNode();
|
|
129
|
+
root.appendChild(anchor);
|
|
130
|
+
onAbort(signal, anchor.remove.bind(anchor));
|
|
122
131
|
this.#root = root;
|
|
123
|
-
this.#
|
|
132
|
+
this.#anchor = anchor;
|
|
124
133
|
}
|
|
125
134
|
insert(...nodes) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (argsN > 1) tmp = createTextNode();
|
|
130
|
-
this.#root.insertBefore(tmp ?? nodes[0], this.#root.childNodes[this.#index]);
|
|
131
|
-
tmp?.replaceWith(...nodes);
|
|
135
|
+
const parent = this.#anchor.parentElement ?? this.#root;
|
|
136
|
+
for (const node of nodes) {
|
|
137
|
+
parent.insertBefore(node, this.#anchor);
|
|
132
138
|
}
|
|
133
139
|
}
|
|
134
140
|
insertHTML(html2) {
|
|
@@ -234,7 +240,9 @@ var createScope = (slots, abortSignal) => {
|
|
|
234
240
|
cleanup = callback.call(receiver);
|
|
235
241
|
}, abortSignal)
|
|
236
242
|
);
|
|
237
|
-
|
|
243
|
+
if (cleanup) {
|
|
244
|
+
onAbort(abortSignal, cleanup);
|
|
245
|
+
}
|
|
238
246
|
$depsMark = void 0;
|
|
239
247
|
});
|
|
240
248
|
};
|
|
@@ -310,7 +318,7 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
310
318
|
if (child !== null) {
|
|
311
319
|
if (child instanceof ReactiveList) {
|
|
312
320
|
let { reactive, callback } = child;
|
|
313
|
-
let insertMark = new InsertMark(root);
|
|
321
|
+
let insertMark = new InsertMark(root, abortSignal);
|
|
314
322
|
let list = /* @__PURE__ */ new Map();
|
|
315
323
|
let cleanup = () => {
|
|
316
324
|
list.forEach((items) => items.forEach(([ac]) => ac.abort()));
|
|
@@ -352,7 +360,7 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
352
360
|
textNode2.textContent = String(value);
|
|
353
361
|
}, abortSignal);
|
|
354
362
|
root.appendChild(textNode2);
|
|
355
|
-
onAbort(abortSignal,
|
|
363
|
+
onAbort(abortSignal, textNode2.remove.bind(textNode2));
|
|
356
364
|
return;
|
|
357
365
|
}
|
|
358
366
|
if (isVNode(child)) {
|
|
@@ -360,17 +368,16 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
360
368
|
switch (tag) {
|
|
361
369
|
// fragment element
|
|
362
370
|
case $fragment: {
|
|
363
|
-
const { children
|
|
364
|
-
const rootEl = rootProp instanceof HTMLElement ? rootProp : root;
|
|
371
|
+
const { children } = props;
|
|
365
372
|
if (children !== void 0) {
|
|
366
|
-
renderChildren(scope, children,
|
|
373
|
+
renderChildren(scope, children, root, abortSignal);
|
|
367
374
|
}
|
|
368
375
|
break;
|
|
369
376
|
}
|
|
370
377
|
// XSS!
|
|
371
378
|
case $html: {
|
|
372
379
|
const { innerHTML } = props;
|
|
373
|
-
const mark = new InsertMark(root);
|
|
380
|
+
const mark = new InsertMark(root, abortSignal);
|
|
374
381
|
if (innerHTML instanceof Reactive) {
|
|
375
382
|
let cleanup;
|
|
376
383
|
innerHTML.reactive((html2) => {
|
|
@@ -397,13 +404,13 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
397
404
|
let { when = true, children } = props;
|
|
398
405
|
if (children !== void 0) {
|
|
399
406
|
if (when instanceof Reactive) {
|
|
400
|
-
let mark = new InsertMark(root);
|
|
407
|
+
let mark = new InsertMark(root, abortSignal);
|
|
401
408
|
let ac;
|
|
402
409
|
when.reactive((value) => {
|
|
403
410
|
ac?.abort();
|
|
404
411
|
if (tag === "show" ? value : !value) {
|
|
405
412
|
ac = new AbortController();
|
|
406
|
-
mark.insert(renderToFragment(scope, children, ac.signal));
|
|
413
|
+
mark.insert(...renderToFragment(scope, children, ac.signal).childNodes);
|
|
407
414
|
}
|
|
408
415
|
}, abortSignal);
|
|
409
416
|
onAbort(abortSignal, () => ac?.abort());
|
|
@@ -421,14 +428,14 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
421
428
|
const { value: valueProp, children } = props;
|
|
422
429
|
if (children !== void 0) {
|
|
423
430
|
if (valueProp instanceof Reactive) {
|
|
424
|
-
let mark = new InsertMark(root);
|
|
431
|
+
let mark = new InsertMark(root, abortSignal);
|
|
425
432
|
let ac;
|
|
426
433
|
valueProp.reactive((value) => {
|
|
427
434
|
const slots = children.filter((v) => isVNode(v) && v[1].slot === String(value));
|
|
428
435
|
ac?.abort();
|
|
429
436
|
if (slots.length > 0) {
|
|
430
437
|
ac = new AbortController();
|
|
431
|
-
mark.insert(renderToFragment(scope, slots, ac.signal));
|
|
438
|
+
mark.insert(...renderToFragment(scope, slots, ac.signal).childNodes);
|
|
432
439
|
}
|
|
433
440
|
}, abortSignal);
|
|
434
441
|
onAbort(abortSignal, () => ac?.abort());
|
|
@@ -536,7 +543,7 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
536
543
|
break;
|
|
537
544
|
}
|
|
538
545
|
}
|
|
539
|
-
onAbort(abortSignal,
|
|
546
|
+
onAbort(abortSignal, el.remove.bind(el));
|
|
540
547
|
(portal instanceof HTMLElement ? portal : root).appendChild(el);
|
|
541
548
|
if (children !== void 0) {
|
|
542
549
|
renderChildren(scope, children, el, abortSignal);
|
|
@@ -550,7 +557,7 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
550
557
|
}
|
|
551
558
|
const textNode = createTextNode(String(child));
|
|
552
559
|
root.appendChild(textNode);
|
|
553
|
-
onAbort(abortSignal,
|
|
560
|
+
onAbort(abortSignal, textNode.remove.bind(textNode));
|
|
554
561
|
};
|
|
555
562
|
var renderChildren = (scope, children, root, aboutSignal) => {
|
|
556
563
|
if (Array.isArray(children) && !isVNode(children)) {
|
package/jsx-runtime.mjs
CHANGED
|
@@ -176,7 +176,7 @@ var $vnode = /* @__PURE__ */ Symbol.for("jsx.vnode");
|
|
|
176
176
|
var $setup = /* @__PURE__ */ Symbol.for("mono.setup");
|
|
177
177
|
|
|
178
178
|
// version.ts
|
|
179
|
-
var VERSION = "0.9.
|
|
179
|
+
var VERSION = "0.9.6";
|
|
180
180
|
|
|
181
181
|
// render.ts
|
|
182
182
|
var FunctionIdGenerator = class extends Map {
|
package/package.json
CHANGED
package/types/dom/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/// <reference types="../jsx.d.ts" />
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface Atom<T> {
|
|
4
4
|
get(): T;
|
|
5
5
|
set(value: T | ((prev: T) => T)): void;
|
|
6
6
|
map(callback: (value: T extends (infer V)[] ? V : T, index: number) => JSX.Element): JSX.Element[];
|
|
7
|
+
ref(): T;
|
|
8
|
+
ref<V>(callback: (value: T) => V): V;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
export const atom: <T>(initValue: T) =>
|
|
11
|
+
export const atom: <T>(initValue: T) => Atom<T>;
|
|
10
12
|
export const store: <T extends Record<string, unknown>>(initValue: T) => T;
|
package/types/html.d.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import type * as Aria from "./aria.d.ts";
|
|
4
4
|
import type * as CSS from "./css.d.ts";
|
|
5
|
-
import type * as Mono from "./
|
|
5
|
+
import type * as Mono from "./mono.d.ts";
|
|
6
6
|
|
|
7
7
|
export interface BaseCSSProperties extends CSS.Properties<string | number> {
|
|
8
8
|
/**
|
|
9
9
|
* The field-sizing CSS property enables you to control the sizing behavior of elements that are given a default preferred size, such as form control elements. This property enables you to override the default sizing behavior, allowing form controls to adjust in size to fit their contents.
|
|
10
10
|
* @see https://developer.mozilla.org/docs/Web/CSS/field-sizing
|
|
11
11
|
*/
|
|
12
|
-
fieldSizing?: "fixed" | "content";
|
|
12
|
+
fieldSizing?: "fixed" | "content" | (string & {});
|
|
13
13
|
/**
|
|
14
14
|
* The view-transition-class CSS property provides the selected elements with an identifying class (a <custom-ident>), providing an additional method of styling the view transitions for those elements.
|
|
15
15
|
* @see https://developer.mozilla.org/docs/Web/CSS/view-transition-class
|
|
@@ -33,7 +33,7 @@ export interface AtRuleCSSProperties {
|
|
|
33
33
|
/**
|
|
34
34
|
* Specifies the effect this at-rule will have on the document's view transition behavior.
|
|
35
35
|
*/
|
|
36
|
-
navigation?: "auto" | "none";
|
|
36
|
+
navigation?: "auto" | "none" | (string & {});
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -303,12 +303,12 @@ export namespace HTML {
|
|
|
303
303
|
* Two-way binding prop that automatically creates checked and oninput attributes for signal binding
|
|
304
304
|
* @mono-jsx
|
|
305
305
|
*/
|
|
306
|
-
$checked?: boolean
|
|
306
|
+
$checked?: Mono.MaybeGetter<boolean>;
|
|
307
307
|
/**
|
|
308
308
|
* Two-way binding prop that automatically creates value and oninput attributes for signal binding
|
|
309
309
|
* @mono-jsx
|
|
310
310
|
*/
|
|
311
|
-
$value?: string | number
|
|
311
|
+
$value?: Mono.MaybeGetter<string | number>;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
interface OptionAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
@@ -331,7 +331,7 @@ export namespace HTML {
|
|
|
331
331
|
* Two-way binding prop that automatically creates value and oninput attributes for signal binding
|
|
332
332
|
* @mono-jsx
|
|
333
333
|
*/
|
|
334
|
-
$value?: string | number
|
|
334
|
+
$value?: Mono.MaybeGetter<string | number>;
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
interface TextareaAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
|
@@ -354,7 +354,7 @@ export namespace HTML {
|
|
|
354
354
|
* Two-way binding prop that automatically creates value and oninput attributes for signal binding
|
|
355
355
|
* @mono-jsx
|
|
356
356
|
*/
|
|
357
|
-
$value?: string
|
|
357
|
+
$value?: Mono.MaybeGetter<string>;
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
interface ButtonAttributes<T extends EventTarget> extends GlobalAttributes<T> {
|
package/types/jsx.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { HTML } from "./html.d.ts";
|
|
2
2
|
|
|
3
3
|
export type ChildPrimitiveType = JSX.Element | string | number | bigint | boolean | null | undefined;
|
|
4
|
-
export type ChildType = MaybeArray<
|
|
4
|
+
export type ChildType = MaybeArray<MaybeGetter<ChildPrimitiveType>>;
|
|
5
5
|
export type MaybeArray<T> = T | T[];
|
|
6
|
-
export type MaybeGetter<T> = { get: () => T };
|
|
6
|
+
export type MaybeGetter<T> = T | { get: () => T };
|
|
7
7
|
export type MaybePromiseOrGenerator<T> = T | Promise<T> | Generator<T> | AsyncGenerator<T>;
|
|
8
8
|
|
|
9
9
|
export interface BaseAttributes {
|
package/types/mono.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AsyncComponentAttributes, BaseAttributes, ComponentType } from "./jsx.d.ts";
|
|
1
|
+
import type { AsyncComponentAttributes, BaseAttributes, ComponentType, MaybeGetter } from "./jsx.d.ts";
|
|
2
2
|
|
|
3
3
|
export type WithParams<T> = T & { params?: Record<string, string> };
|
|
4
4
|
|
|
@@ -263,3 +263,5 @@ declare global {
|
|
|
263
263
|
}
|
|
264
264
|
: never;
|
|
265
265
|
}
|
|
266
|
+
|
|
267
|
+
export type { AsyncComponentAttributes, BaseAttributes, MaybeGetter };
|