mono-jsx 0.9.5 → 0.9.7
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 +22 -12
- 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;
|
|
@@ -121,7 +127,7 @@ var InsertMark = class {
|
|
|
121
127
|
constructor(root, signal) {
|
|
122
128
|
const anchor = createTextNode();
|
|
123
129
|
root.appendChild(anchor);
|
|
124
|
-
onAbort(signal,
|
|
130
|
+
onAbort(signal, anchor.remove.bind(anchor));
|
|
125
131
|
this.#root = root;
|
|
126
132
|
this.#anchor = anchor;
|
|
127
133
|
}
|
|
@@ -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
|
};
|
|
@@ -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)) {
|
|
@@ -535,7 +543,7 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
535
543
|
break;
|
|
536
544
|
}
|
|
537
545
|
}
|
|
538
|
-
onAbort(abortSignal,
|
|
546
|
+
onAbort(abortSignal, el.remove.bind(el));
|
|
539
547
|
(portal instanceof HTMLElement ? portal : root).appendChild(el);
|
|
540
548
|
if (children !== void 0) {
|
|
541
549
|
renderChildren(scope, children, el, abortSignal);
|
|
@@ -549,7 +557,7 @@ var render = (scope, child, root, abortSignal) => {
|
|
|
549
557
|
}
|
|
550
558
|
const textNode = createTextNode(String(child));
|
|
551
559
|
root.appendChild(textNode);
|
|
552
|
-
onAbort(abortSignal,
|
|
560
|
+
onAbort(abortSignal, textNode.remove.bind(textNode));
|
|
553
561
|
};
|
|
554
562
|
var renderChildren = (scope, children, root, aboutSignal) => {
|
|
555
563
|
if (Array.isArray(children) && !isVNode(children)) {
|
|
@@ -630,10 +638,10 @@ var applyStyle = (el, style, mark) => {
|
|
|
630
638
|
if (isPlainObject(style)) {
|
|
631
639
|
let { classList } = el;
|
|
632
640
|
let inline;
|
|
641
|
+
let css = [];
|
|
633
642
|
classList.remove(...classList.values().filter((key) => key.startsWith("css-")));
|
|
634
643
|
for (let [k, v] of Object.entries(style)) {
|
|
635
644
|
v = $(v, mark);
|
|
636
|
-
let css = [];
|
|
637
645
|
switch (k.charCodeAt(0)) {
|
|
638
646
|
case /* ':' */
|
|
639
647
|
58:
|
|
@@ -663,12 +671,14 @@ var applyStyle = (el, style, mark) => {
|
|
|
663
671
|
inline ??= {};
|
|
664
672
|
inline[k] = v;
|
|
665
673
|
}
|
|
666
|
-
if (css.length) {
|
|
667
|
-
classList.add(computeStyleClassName(css));
|
|
668
|
-
}
|
|
669
674
|
}
|
|
670
|
-
if (
|
|
671
|
-
|
|
675
|
+
if (css.length > 0) {
|
|
676
|
+
if (inline) {
|
|
677
|
+
css.unshift(null, renderStyle(inline));
|
|
678
|
+
}
|
|
679
|
+
classList.add(createStyleElement(css));
|
|
680
|
+
} else if (inline) {
|
|
681
|
+
el.style.cssText = renderStyle(inline).slice(1, -1);
|
|
672
682
|
}
|
|
673
683
|
} else if (isString(style)) {
|
|
674
684
|
el.style.cssText = style;
|
|
@@ -690,7 +700,7 @@ var renderStyle = (style, mark) => {
|
|
|
690
700
|
}
|
|
691
701
|
return "{" + css + "}";
|
|
692
702
|
};
|
|
693
|
-
var
|
|
703
|
+
var createStyleElement = (css) => {
|
|
694
704
|
const hash = hashCode(css.join("")).toString(36);
|
|
695
705
|
const className = "css-" + hash;
|
|
696
706
|
if (!document2.getElementById(className)) {
|
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 };
|