mi-element 0.1.0 → 0.2.0
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/README.md +4 -0
- package/dist/case.js +3 -0
- package/dist/context.js +11 -12
- package/dist/element.js +26 -19
- package/dist/index.js +4 -2
- package/dist/refs.js +3 -3
- package/dist/signal.js +54 -16
- package/dist/store.js +6 -24
- package/dist/styling.js +17 -0
- package/package.json +13 -3
- package/src/case.js +15 -0
- package/src/context.js +19 -17
- package/src/element.js +39 -31
- package/src/index.js +6 -3
- package/src/refs.js +2 -8
- package/src/signal.js +84 -49
- package/src/store.js +27 -48
- package/src/styling.js +33 -0
- package/types/case.d.ts +2 -0
- package/types/context.d.ts +56 -58
- package/types/element.d.ts +101 -123
- package/types/escape.d.ts +3 -3
- package/types/index.d.ts +15 -14
- package/types/refs.d.ts +4 -6
- package/types/signal.d.ts +51 -33
- package/types/store.d.ts +53 -35
- package/types/styling.d.ts +8 -0
package/types/escape.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function escHtml(string: string): string
|
|
2
|
-
export function escAttr(string: string): string
|
|
3
|
-
export function esc(strings: string[], ...vars: any[]): string
|
|
1
|
+
export function escHtml(string: string): string;
|
|
2
|
+
export function escAttr(string: string): string;
|
|
3
|
+
export function esc(strings: string[], ...vars: any[]): string;
|
package/types/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
1
|
+
export { Signal };
|
|
2
|
+
export { Store } from "./store.js";
|
|
3
|
+
export type Context = import("./context.js").Context;
|
|
4
|
+
export type HostController = import("./element.js").HostController;
|
|
5
|
+
/**
|
|
6
|
+
* <T>
|
|
7
|
+
*/
|
|
8
|
+
export type SignalOptions<T> = import("./signal.js").SignalOptions<T>;
|
|
9
|
+
export type Action = import("./store.js").Action;
|
|
10
|
+
import Signal from './signal.js';
|
|
11
|
+
export { ContextConsumer, ContextProvider, ContextRequestEvent } from "./context.js";
|
|
12
|
+
export { MiElement, convertType, define } from "./element.js";
|
|
13
|
+
export { esc, escAttr, escHtml } from "./escape.js";
|
|
14
|
+
export { refsById, refsBySelector } from "./refs.js";
|
|
15
|
+
export { classMap, styleMap } from "./styling.js";
|
package/types/refs.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Helper function to find `id` attributes in `container`s node tree
|
|
2
|
+
* Helper function to find `id` attributes in `container`s node tree.
|
|
3
|
+
* id names are camelCased, e.g. 'list-container' becomes 'listContainer'
|
|
3
4
|
* @param {Element} container root element
|
|
4
5
|
* @returns {Record<string, Node>|{}} record of found references
|
|
5
6
|
* @example
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
* references = refs(el)
|
|
8
9
|
* //> references = { p: <p>, named: <span> }
|
|
9
10
|
*/
|
|
10
|
-
export function refsById(container: Element): Record<string, Node> | {}
|
|
11
|
+
export function refsById(container: Element): Record<string, Node> | {};
|
|
11
12
|
/**
|
|
12
13
|
* Helper function to gather references by a map of selectors
|
|
13
14
|
* @param {Element} container root element
|
|
@@ -18,7 +19,4 @@ export function refsById(container: Element): Record<string, Node> | {}
|
|
|
18
19
|
* references = refs(el, { p: 'p', named: 'p > span' })
|
|
19
20
|
* //> references = { p: <p>, named: <span> }
|
|
20
21
|
*/
|
|
21
|
-
export function refsBySelector(
|
|
22
|
-
container: Element,
|
|
23
|
-
selectors: Record<string, string>
|
|
24
|
-
): Record<string, Node> | {}
|
|
22
|
+
export function refsBySelector(container: Element, selectors: Record<string, string>): Record<string, Node> | {};
|
package/types/signal.d.ts
CHANGED
|
@@ -1,36 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @param {() => void} cb
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
4
|
+
export function effect(cb: () => void): () => void;
|
|
5
|
+
/**
|
|
6
|
+
* @template T
|
|
7
|
+
* @typedef {{equals: (value?: T|null, nextValue?: T|null) => boolean}} SignalOptions
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* tries to follow proposal (a bit)
|
|
11
|
+
* @see https://github.com/tc39/proposal-signals
|
|
12
|
+
* @template T
|
|
13
|
+
*/
|
|
14
|
+
export class State<T> {
|
|
15
|
+
/**
|
|
16
|
+
* @param {T|null} [value]
|
|
17
|
+
* @param {SignalOptions<T>} [options]
|
|
18
|
+
*/
|
|
19
|
+
constructor(value?: T | null | undefined, options?: SignalOptions<T> | undefined);
|
|
20
|
+
subscribers: Set<any>;
|
|
21
|
+
value: T | null | undefined;
|
|
22
|
+
equals: (value?: T | null | undefined, nextValue?: T | null | undefined) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* @returns {T|null|undefined}
|
|
25
|
+
*/
|
|
26
|
+
get(): T | null | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* @param {T|null|undefined} nextValue
|
|
29
|
+
*/
|
|
30
|
+
set(nextValue: T | null | undefined): void;
|
|
31
|
+
}
|
|
32
|
+
export function createSignal<T>(value: T): State<T>;
|
|
33
|
+
export class Computed {
|
|
34
|
+
/**
|
|
35
|
+
* @param {() => void} cb
|
|
36
|
+
*/
|
|
37
|
+
constructor(cb: () => void);
|
|
38
|
+
state: State<any>;
|
|
39
|
+
/**
|
|
40
|
+
* @template T
|
|
41
|
+
* @returns {T}
|
|
42
|
+
*/
|
|
43
|
+
get<T>(): T;
|
|
44
|
+
}
|
|
45
|
+
declare namespace _default {
|
|
46
|
+
export { State };
|
|
47
|
+
export { createSignal };
|
|
48
|
+
export { effect };
|
|
49
|
+
export { Computed };
|
|
33
50
|
}
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
-
|
|
51
|
+
export default _default;
|
|
52
|
+
export type SignalOptions<T> = {
|
|
53
|
+
equals: (value?: T | null, nextValue?: T | null) => boolean;
|
|
54
|
+
};
|
package/types/store.d.ts
CHANGED
|
@@ -4,43 +4,61 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {(state: any, data?: any) => any} Action
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* @template T
|
|
9
|
+
* @typedef {import('./signal.js').SignalOptions<T>} SignalOptions<T>
|
|
10
|
+
*/
|
|
7
11
|
/**
|
|
8
12
|
* Store implementing [Flux](https://www.npmjs.com/package/flux) pattern based
|
|
9
13
|
* on Signals
|
|
14
|
+
* @template T
|
|
10
15
|
*/
|
|
11
|
-
export class Store extends
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
export class Store<T> extends State<any> {
|
|
17
|
+
/**
|
|
18
|
+
* @param {Record<string, Action>} actions
|
|
19
|
+
* @param {T|null} [initialValue]
|
|
20
|
+
* @param {SignalOptions<T>} [options]
|
|
21
|
+
* @example
|
|
22
|
+
* ```js
|
|
23
|
+
* import { Signal, Store } from 'mi-element'
|
|
24
|
+
* const actions = { increment: (by = 1) => (current) => current + by }
|
|
25
|
+
* const initialValue = 1
|
|
26
|
+
* const store = new Store(actions, initialValue)
|
|
27
|
+
* // subscribe with a callback function
|
|
28
|
+
* const unsubscribe = Signal.effect(() => console.log(`count is ${store.get()}`))
|
|
29
|
+
* // change the store
|
|
30
|
+
* store.increment(2) // increment by 2
|
|
31
|
+
* //> count is 3
|
|
32
|
+
* unsubscribe()
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* if `initialValue` is an object, the object's reference must be changed
|
|
36
|
+
* using the spread operator, in order to notify on state changes, e.g.
|
|
37
|
+
* ```js
|
|
38
|
+
* const initialValue = { count: 0, other: 'foo' }
|
|
39
|
+
* const actions = {
|
|
40
|
+
* increment: (by = 1) => (state) => ({...state, count: state.count + by})
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
* or you change the signals options equality function
|
|
44
|
+
* ```js
|
|
45
|
+
* const actions = {
|
|
46
|
+
* increment: (by = 1) => (state) => {
|
|
47
|
+
* state.count += by
|
|
48
|
+
* return state
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* const initialValue = { count: 0, other: 'foo' }
|
|
52
|
+
* const options = { equals: (value, nextValue) => true }
|
|
53
|
+
* const store = new Store(actions, initialValue, options)
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
constructor(actions: Record<string, Action>, initialValue?: T | null | undefined, options?: SignalOptions<T> | undefined);
|
|
38
57
|
}
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export type
|
|
45
|
-
|
|
46
|
-
import { Signal } from './signal.js'
|
|
58
|
+
export type MiElement = import("./element.js").MiElement;
|
|
59
|
+
export type Action = (state: any, data?: any) => any;
|
|
60
|
+
/**
|
|
61
|
+
* <T>
|
|
62
|
+
*/
|
|
63
|
+
export type SignalOptions<T> = import("./signal.js").SignalOptions<T>;
|
|
64
|
+
import { State } from './signal.js';
|