@radishland/runtime 0.1.0 → 0.1.2
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/client/boot.js +2 -4
- package/client/index.d.ts +19 -4
- package/client/index.js +0 -2
- package/client/utils.d.ts +30 -0
- package/client/utils.js +123 -0
- package/package.json +5 -1
package/client/boot.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
// src/
|
1
|
+
// src/utils.ts
|
2
|
+
var spaces_sep_by_comma = /\s*,\s*/;
|
2
3
|
var bindingConfig = {
|
3
4
|
"checked": {
|
4
5
|
element: ["input"],
|
@@ -12,9 +13,6 @@ var bindingConfig = {
|
|
12
13
|
}
|
13
14
|
};
|
14
15
|
|
15
|
-
// src/utils.ts
|
16
|
-
var spaces_sep_by_comma = /\s*,\s*/;
|
17
|
-
|
18
16
|
// src/boot.ts
|
19
17
|
var bindingsQueryString = Object.keys(bindingConfig).map(
|
20
18
|
(property) => `[\\@bind\\:${property}]`
|
package/client/index.d.ts
CHANGED
@@ -66,22 +66,37 @@ declare class HandlerRegistry extends HTMLElement implements AutonomousCustomEle
|
|
66
66
|
}
|
67
67
|
|
68
68
|
declare const isState: (value: unknown) => value is InstanceType<typeof Signal>;
|
69
|
+
/**
|
70
|
+
* Creates a new signal
|
71
|
+
*
|
72
|
+
* @param value The initial value
|
73
|
+
*/
|
69
74
|
declare const signal: <T>(value: T) => Signal<T>;
|
75
|
+
/**
|
76
|
+
* Creates a read-only computed signal based on the values of other signals
|
77
|
+
*
|
78
|
+
* The computed value is updated when a tracked dependency changes
|
79
|
+
*
|
80
|
+
* @param computation The callback function doing the computation
|
81
|
+
*/
|
70
82
|
declare const computed: <T>(computation: () => T) => ReadonlySignal<T>;
|
71
83
|
/**
|
72
|
-
*
|
84
|
+
* Creates an unowned effect that must be cleaned up manually and runs arbitrary code in response to signals change.
|
85
|
+
*
|
86
|
+
* @param cb The effect callback to run when a tracked dependency changes. Can return a cleanup function, executed when the effect is re-run or is disposed of.
|
87
|
+
*
|
88
|
+
* @param options An AbortSignal can be passed to abort the effect
|
73
89
|
*
|
74
|
-
*
|
90
|
+
* @return a function to unsubscribe and cleanup the effect
|
75
91
|
*/
|
76
92
|
declare const effect: (cb: EffectCallback, options?: EffectOptions) => Destructor;
|
77
93
|
/**
|
78
94
|
* Creates a deeply reactive proxied object or array
|
79
95
|
*
|
80
96
|
* @example const obj = reactive({ a: { b: { c: 1 } } });
|
81
|
-
|
82
97
|
const computation = computed(() => obj.a.b.c * 2});
|
83
|
-
assertEquals(computation.value, 2);
|
84
98
|
|
99
|
+
assertEquals(computation.value, 2);
|
85
100
|
obj.a.b.c = 2;
|
86
101
|
assertEquals(computation.value, 4);
|
87
102
|
*/
|
package/client/index.js
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
declare const spaces_sep_by_comma: RegExp;
|
2
|
+
/**
|
3
|
+
* Idempotent string conversion to kebab-case
|
4
|
+
*/
|
5
|
+
declare const toKebabCase: (str: string) => string;
|
6
|
+
/**
|
7
|
+
* Idempotent string conversion to PascalCase
|
8
|
+
*/
|
9
|
+
declare const toPascalCase: (str: string) => string;
|
10
|
+
type LooseAutocomplete<T extends string> = T | Omit<string, T>;
|
11
|
+
type Types = LooseAutocomplete<"null" | "undefined" | "boolean" | "number" | "bigint" | "string" | "symbol" | "function" | "class" | "array" | "date" | "error" | "regexp" | "object">;
|
12
|
+
/**
|
13
|
+
* A more reliable `typeof` function
|
14
|
+
*/
|
15
|
+
declare function type(value: unknown): Types;
|
16
|
+
declare const booleanAttributes: string[];
|
17
|
+
declare const bindingConfig: {
|
18
|
+
checked: {
|
19
|
+
element: string[];
|
20
|
+
type: string[];
|
21
|
+
event: string;
|
22
|
+
};
|
23
|
+
value: {
|
24
|
+
element: string[];
|
25
|
+
type: string[];
|
26
|
+
event: string;
|
27
|
+
};
|
28
|
+
};
|
29
|
+
|
30
|
+
export { bindingConfig, booleanAttributes, spaces_sep_by_comma, toKebabCase, toPascalCase, type };
|
package/client/utils.js
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
// src/utils.ts
|
2
|
+
var is_upper = /[A-Z]/;
|
3
|
+
var spaces_sep_by_comma = /\s*,\s*/;
|
4
|
+
var toKebabCase = (str) => {
|
5
|
+
let kebab = "";
|
6
|
+
for (let index = 0; index < str.length; index++) {
|
7
|
+
const char = str[index];
|
8
|
+
if (index !== 0 && is_upper.test(char)) {
|
9
|
+
kebab += `-${char.toLowerCase()}`;
|
10
|
+
} else {
|
11
|
+
kebab += char.toLowerCase();
|
12
|
+
}
|
13
|
+
}
|
14
|
+
return kebab;
|
15
|
+
};
|
16
|
+
var toPascalCase = (str) => {
|
17
|
+
let pascal = "";
|
18
|
+
let toUpper = true;
|
19
|
+
for (let index = 0; index < str.length; index++) {
|
20
|
+
const char = str[index];
|
21
|
+
if (char === "-") {
|
22
|
+
toUpper = true;
|
23
|
+
continue;
|
24
|
+
}
|
25
|
+
if (toUpper) {
|
26
|
+
pascal += char.toUpperCase();
|
27
|
+
toUpper = false;
|
28
|
+
} else {
|
29
|
+
pascal += char.toLowerCase();
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return pascal;
|
33
|
+
};
|
34
|
+
function type(value) {
|
35
|
+
if (value === null) {
|
36
|
+
return "null";
|
37
|
+
}
|
38
|
+
if (value === void 0) {
|
39
|
+
return "undefined";
|
40
|
+
}
|
41
|
+
const baseType = typeof value;
|
42
|
+
if (!["object", "function"].includes(baseType)) {
|
43
|
+
return baseType;
|
44
|
+
}
|
45
|
+
if (typeof value === "object" && Symbol.toStringTag in value) {
|
46
|
+
const tag = value[Symbol.toStringTag];
|
47
|
+
if (typeof tag === "string") {
|
48
|
+
return tag;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
if (baseType === "function" && Function.prototype.toString.call(value).startsWith("class")) {
|
52
|
+
return "class";
|
53
|
+
}
|
54
|
+
const className = value.constructor.name;
|
55
|
+
if (typeof className === "string" && className !== "") {
|
56
|
+
return className.toLowerCase();
|
57
|
+
}
|
58
|
+
return baseType;
|
59
|
+
}
|
60
|
+
var booleanAttributes = [
|
61
|
+
"allowfullscreen",
|
62
|
+
// on <iframe>
|
63
|
+
"async",
|
64
|
+
// on <script>
|
65
|
+
"autofocus",
|
66
|
+
// on <button>, <input>, <select>, <textarea>
|
67
|
+
"autoplay",
|
68
|
+
// on <audio>, <video>
|
69
|
+
"checked",
|
70
|
+
// on <input type="checkbox">, <input type="radio">
|
71
|
+
"controls",
|
72
|
+
// on <audio>, <video>
|
73
|
+
"default",
|
74
|
+
// on <track>
|
75
|
+
"defer",
|
76
|
+
// on <script>
|
77
|
+
"disabled",
|
78
|
+
// on form elements like <button>, <fieldset>, <input>, <optgroup>, <option>,<select>, <textarea>
|
79
|
+
"formnovalidate",
|
80
|
+
// on <button>, <input type="submit">
|
81
|
+
"hidden",
|
82
|
+
// global
|
83
|
+
"inert",
|
84
|
+
// global
|
85
|
+
"ismap",
|
86
|
+
// on <img>
|
87
|
+
"itemscope",
|
88
|
+
// global; part of microdata
|
89
|
+
"loop",
|
90
|
+
// on <audio>, <video>
|
91
|
+
"multiple",
|
92
|
+
// on <input type="file">, <select>
|
93
|
+
"muted",
|
94
|
+
// on <audio>, <video>
|
95
|
+
"nomodule",
|
96
|
+
// on <script>
|
97
|
+
"novalidate",
|
98
|
+
// on <form>
|
99
|
+
"open",
|
100
|
+
// on <details>
|
101
|
+
"readonly",
|
102
|
+
// on <input>, <textarea>
|
103
|
+
"required",
|
104
|
+
// on <input>, <select>, <textarea>
|
105
|
+
"reversed",
|
106
|
+
// on <ol>
|
107
|
+
"selected"
|
108
|
+
// on <option>
|
109
|
+
];
|
110
|
+
var bindingConfig = {
|
111
|
+
"checked": {
|
112
|
+
element: ["input"],
|
113
|
+
type: ["boolean"],
|
114
|
+
event: "change"
|
115
|
+
},
|
116
|
+
"value": {
|
117
|
+
element: ["input", "select", "textarea"],
|
118
|
+
type: ["string", "number"],
|
119
|
+
event: "input"
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
export { bindingConfig, booleanAttributes, spaces_sep_by_comma, toKebabCase, toPascalCase, type };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@radishland/runtime",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.2",
|
4
4
|
"type": "module",
|
5
5
|
"description": "The Radish runtime",
|
6
6
|
"author": "Frédéric Crozatier",
|
@@ -24,6 +24,10 @@
|
|
24
24
|
"./boot": {
|
25
25
|
"import": "./client/boot.js",
|
26
26
|
"types": "./client/boot.d.ts"
|
27
|
+
},
|
28
|
+
"./utils": {
|
29
|
+
"import": "./client/utils.js",
|
30
|
+
"types": "./client/utils.d.ts"
|
27
31
|
}
|
28
32
|
},
|
29
33
|
"files": [
|