@radishland/runtime 0.0.8 → 1.0.0-alpha.1
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/build.ts +14 -0
- package/client/config.js +12 -0
- package/client/handler-registry.js +236 -0
- package/client/handlers.js +174 -0
- package/client/index.js +3 -378
- package/client/reactivity.js +162 -0
- package/client/types.d.js +1 -0
- package/client/utils.js +65 -0
- package/deno.json +21 -0
- package/package.json +2 -21
- package/src/config.ts +12 -0
- package/src/handler-registry.ts +274 -0
- package/src/handlers.ts +174 -0
- package/src/index.ts +3 -0
- package/src/reactivity.ts +179 -0
- package/src/types.d.ts +75 -0
- package/src/utils.ts +71 -0
- package/README.md +0 -3
- package/client/index.d.ts +0 -89
package/src/utils.ts
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
const is_upper = /[A-Z]/;
|
2
|
+
export const spaces_sep_by_comma = /\s*,\s*/;
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Idempotent string conversion to kebab-case
|
6
|
+
*/
|
7
|
+
export const toKebabCase = (str: string) => {
|
8
|
+
let kebab = "";
|
9
|
+
for (let index = 0; index < str.length; index++) {
|
10
|
+
const char = str[index];
|
11
|
+
|
12
|
+
if (index !== 0 && is_upper.test(char)) {
|
13
|
+
kebab += `-${char.toLowerCase()}`;
|
14
|
+
} else {
|
15
|
+
kebab += char.toLowerCase();
|
16
|
+
}
|
17
|
+
}
|
18
|
+
return kebab;
|
19
|
+
};
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Idempotent string conversion to PascalCase
|
23
|
+
*/
|
24
|
+
export const toPascalCase = (str: string) => {
|
25
|
+
let pascal = "";
|
26
|
+
let toUpper = true;
|
27
|
+
|
28
|
+
for (let index = 0; index < str.length; index++) {
|
29
|
+
const char = str[index];
|
30
|
+
|
31
|
+
if (char === "-") {
|
32
|
+
toUpper = true;
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
|
36
|
+
if (toUpper) {
|
37
|
+
pascal += char.toUpperCase();
|
38
|
+
toUpper = false;
|
39
|
+
} else {
|
40
|
+
pascal += char.toLowerCase();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return pascal;
|
44
|
+
};
|
45
|
+
|
46
|
+
export const booleanAttributes = [
|
47
|
+
"allowfullscreen", // on <iframe>
|
48
|
+
"async", // on <script>
|
49
|
+
"autofocus", // on <button>, <input>, <select>, <textarea>
|
50
|
+
"autoplay", // on <audio>, <video>
|
51
|
+
"checked", // on <input type="checkbox">, <input type="radio">
|
52
|
+
"controls", // on <audio>, <video>
|
53
|
+
"default", // on <track>
|
54
|
+
"defer", // on <script>
|
55
|
+
"disabled", // on form elements like <button>, <fieldset>, <input>, <optgroup>, <option>,<select>, <textarea>
|
56
|
+
"formnovalidate", // on <button>, <input type="submit">
|
57
|
+
"hidden", // global
|
58
|
+
"inert", // global
|
59
|
+
"ismap", // on <img>
|
60
|
+
"itemscope", // global; part of microdata
|
61
|
+
"loop", // on <audio>, <video>
|
62
|
+
"multiple", // on <input type="file">, <select>
|
63
|
+
"muted", // on <audio>, <video>
|
64
|
+
"nomodule", // on <script>
|
65
|
+
"novalidate", // on <form>
|
66
|
+
"open", // on <details>
|
67
|
+
"readonly", // on <input>, <textarea>
|
68
|
+
"required", // on <input>, <select>, <textarea>
|
69
|
+
"reversed", // on <ol>
|
70
|
+
"selected", // on <option>
|
71
|
+
];
|
package/README.md
DELETED
package/client/index.d.ts
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
import { Signal } from 'signal-polyfill';
|
2
|
-
|
3
|
-
interface AutonomousCustomElement {
|
4
|
-
/**
|
5
|
-
* A static getter
|
6
|
-
*/
|
7
|
-
readonly observedAttributes?: string[] | undefined;
|
8
|
-
/**
|
9
|
-
* A static getter
|
10
|
-
*/
|
11
|
-
readonly disabledFeatures?: ("internals" | "shadow")[] | undefined;
|
12
|
-
/**
|
13
|
-
* A static getter
|
14
|
-
*/
|
15
|
-
readonly formAssociated?: boolean | undefined;
|
16
|
-
|
17
|
-
connectedCallback?(): void;
|
18
|
-
disconnectedCallback?(): void;
|
19
|
-
adoptedCallback?(): void;
|
20
|
-
|
21
|
-
attributeChangedCallback?(
|
22
|
-
name: string,
|
23
|
-
previous: string,
|
24
|
-
next: string,
|
25
|
-
): void;
|
26
|
-
|
27
|
-
formAssociatedCallback?(): void;
|
28
|
-
formResetCallback?(): void;
|
29
|
-
formDisabledCallback?(): void;
|
30
|
-
formStateRestoreCallback?(): void;
|
31
|
-
}
|
32
|
-
|
33
|
-
type ReactivityOptions = { deep: boolean };
|
34
|
-
type Destructor = () => void;
|
35
|
-
type EffectCallback = () => Destructor | void;
|
36
|
-
type EffectOptions = {
|
37
|
-
signal: AbortSignal;
|
38
|
-
};
|
39
|
-
|
40
|
-
/**
|
41
|
-
* A Scoped Handler Registry implements the logic for handling effect requests.
|
42
|
-
*
|
43
|
-
* Extend this class by adding new methods in your subclass to implement your own effect handlers
|
44
|
-
*/
|
45
|
-
declare class HandlerRegistry extends HTMLElement implements AutonomousCustomElement {
|
46
|
-
#private;
|
47
|
-
[key: string]: any;
|
48
|
-
/**
|
49
|
-
* References the handler's `AbortController`.
|
50
|
-
*
|
51
|
-
* The `abort` method of the controller is called in the `disconnectedCallback` method. It allows to cleanup event handlers and other abortable operations
|
52
|
-
*/
|
53
|
-
abortController: AbortController;
|
54
|
-
constructor();
|
55
|
-
/**
|
56
|
-
* Creates an effect that is automatically cleaned up when the component is disconnected
|
57
|
-
*
|
58
|
-
* An optional AbortSignal can be provided to abort the effect prematurely
|
59
|
-
*/
|
60
|
-
$effect(callback: EffectCallback, options?: EffectOptions): void;
|
61
|
-
connectedCallback(): void;
|
62
|
-
disconnectedCallback(): void;
|
63
|
-
}
|
64
|
-
|
65
|
-
declare class ReactiveValue<T> extends Signal.State<T> {
|
66
|
-
private get;
|
67
|
-
private set;
|
68
|
-
get value(): T;
|
69
|
-
set value(newValue: T);
|
70
|
-
}
|
71
|
-
declare class ReactiveComputation<T> extends Signal.Computed<T> {
|
72
|
-
private get;
|
73
|
-
get value(): T;
|
74
|
-
}
|
75
|
-
declare const $object: <T extends Record<PropertyKey, any>>(init: T, options?: ReactivityOptions) => T;
|
76
|
-
declare const $array: <T extends ArrayLike<any>>(init: T, options?: ReactivityOptions) => T;
|
77
|
-
declare const isState: (s: unknown) => s is InstanceType<typeof ReactiveValue>;
|
78
|
-
declare const isComputed: (s: unknown) => s is InstanceType<typeof ReactiveComputation>;
|
79
|
-
declare const getValue: (signal: unknown) => unknown;
|
80
|
-
declare const $state: <T>(initialValue: T, options?: Signal.Options<T | undefined>) => ReactiveValue<T>;
|
81
|
-
declare const $computed: <T>(computation: () => T, options?: Signal.Options<T>) => ReactiveComputation<T>;
|
82
|
-
/**
|
83
|
-
* Create an unowned effect that must be cleanup up manually
|
84
|
-
*
|
85
|
-
* Accept an AbortSignal to abort the effect
|
86
|
-
*/
|
87
|
-
declare const $effect: (cb: EffectCallback, options?: EffectOptions) => Destructor;
|
88
|
-
|
89
|
-
export { $array, $computed, $effect, $object, $state, HandlerRegistry, ReactiveComputation, ReactiveValue, getValue, isComputed, isState };
|