@ratiosolver/flick 0.2.7 → 0.2.9
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/dist/app.d.ts +61 -0
- package/dist/app.js +61 -0
- package/dist/app.js.map +1 -0
- package/dist/component.d.ts +120 -0
- package/dist/component.js +161 -0
- package/dist/component.js.map +1 -0
- package/dist/components/app.d.ts +1 -1
- package/dist/components/app.js +2 -2
- package/dist/components/app.js.map +1 -1
- package/dist/components/brand.d.ts +15 -0
- package/dist/components/brand.js +39 -0
- package/dist/components/brand.js.map +1 -0
- package/dist/components/checkbox.d.ts +49 -0
- package/dist/components/checkbox.js +77 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/sidebar.d.ts +5 -0
- package/dist/components/sidebar.js +36 -0
- package/dist/components/sidebar.js.map +1 -0
- package/dist/components/table.js +1 -1
- package/dist/components/table.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/blink.d.ts +14 -0
- package/dist/utils/blink.js +28 -0
- package/dist/utils/blink.js.map +1 -0
- package/dist/utils/connection.d.ts +102 -0
- package/dist/utils/connection.js +177 -0
- package/dist/utils/connection.js.map +1 -0
- package/dist/utils/selector.d.ts +59 -0
- package/dist/utils/selector.js +44 -0
- package/dist/utils/selector.js.map +1 -0
- package/dist/utils/settings.d.ts +61 -0
- package/dist/utils/settings.js +72 -0
- package/dist/utils/settings.js.map +1 -0
- package/dist/utils/user_components.d.ts +83 -0
- package/dist/utils/user_components.js +358 -0
- package/dist/utils/user_components.js.map +1 -0
- package/package.json +1 -1
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Component } from "./component";
|
|
2
|
+
/**
|
|
3
|
+
* The `App` class implements the singleton pattern and manages the state and behavior of the application.
|
|
4
|
+
* It allows for the selection of components and notifies registered listeners of various events.
|
|
5
|
+
*
|
|
6
|
+
* @implements {AppListener}
|
|
7
|
+
*/
|
|
8
|
+
export declare class App implements AppListener {
|
|
9
|
+
private static instance;
|
|
10
|
+
private selected_comp;
|
|
11
|
+
private app_listeners;
|
|
12
|
+
private constructor();
|
|
13
|
+
static get_instance(): App;
|
|
14
|
+
/**
|
|
15
|
+
* Display a toast message.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} info The information to display.
|
|
18
|
+
*/
|
|
19
|
+
toast(info: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Get the selected component.
|
|
22
|
+
*
|
|
23
|
+
* @returns {Component<Node> | null} The selected component.
|
|
24
|
+
*/
|
|
25
|
+
get_selected_component(): Component<Node> | null;
|
|
26
|
+
/**
|
|
27
|
+
* Set the selected component.
|
|
28
|
+
*
|
|
29
|
+
* @param {Component<Node> | null} component The component to select.
|
|
30
|
+
*/
|
|
31
|
+
selected_component(component: Component<Node> | null): void;
|
|
32
|
+
/**
|
|
33
|
+
* Add an application listener.
|
|
34
|
+
*
|
|
35
|
+
* @param {AppListener} listener The listener to add.
|
|
36
|
+
*/
|
|
37
|
+
add_app_listener(listener: AppListener): void;
|
|
38
|
+
/**
|
|
39
|
+
* Remove an application listener.
|
|
40
|
+
*
|
|
41
|
+
* @param {AppListener} listener The listener to remove.
|
|
42
|
+
*/
|
|
43
|
+
remove_app_listener(listener: AppListener): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The `AppListener` interface defines the methods that an object must implement to listen to application events.
|
|
47
|
+
*/
|
|
48
|
+
export interface AppListener {
|
|
49
|
+
/**
|
|
50
|
+
* Request to display a toast message.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} info The information to display.
|
|
53
|
+
*/
|
|
54
|
+
toast(info: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Notification that a component has been selected.
|
|
57
|
+
*
|
|
58
|
+
* @param {Component<Node> | null} component The selected component.
|
|
59
|
+
*/
|
|
60
|
+
selected_component(component: Component<Node> | null): void;
|
|
61
|
+
}
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `App` class implements the singleton pattern and manages the state and behavior of the application.
|
|
3
|
+
* It allows for the selection of components and notifies registered listeners of various events.
|
|
4
|
+
*
|
|
5
|
+
* @implements {AppListener}
|
|
6
|
+
*/
|
|
7
|
+
export class App {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.selected_comp = null;
|
|
10
|
+
this.app_listeners = new Set();
|
|
11
|
+
}
|
|
12
|
+
static get_instance() {
|
|
13
|
+
if (!App.instance)
|
|
14
|
+
App.instance = new App();
|
|
15
|
+
return App.instance;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Display a toast message.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} info The information to display.
|
|
21
|
+
*/
|
|
22
|
+
toast(info) { for (const listener of this.app_listeners) {
|
|
23
|
+
listener.toast(info);
|
|
24
|
+
} }
|
|
25
|
+
/**
|
|
26
|
+
* Get the selected component.
|
|
27
|
+
*
|
|
28
|
+
* @returns {Component<Node> | null} The selected component.
|
|
29
|
+
*/
|
|
30
|
+
get_selected_component() { return this.selected_comp; }
|
|
31
|
+
/**
|
|
32
|
+
* Set the selected component.
|
|
33
|
+
*
|
|
34
|
+
* @param {Component<Node> | null} component The component to select.
|
|
35
|
+
*/
|
|
36
|
+
selected_component(component) {
|
|
37
|
+
if (this.selected_comp)
|
|
38
|
+
this.selected_comp.remove();
|
|
39
|
+
this.selected_comp = component;
|
|
40
|
+
for (const listener of this.app_listeners) {
|
|
41
|
+
listener.selected_component(component);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Add an application listener.
|
|
46
|
+
*
|
|
47
|
+
* @param {AppListener} listener The listener to add.
|
|
48
|
+
*/
|
|
49
|
+
add_app_listener(listener) {
|
|
50
|
+
this.app_listeners.add(listener);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Remove an application listener.
|
|
54
|
+
*
|
|
55
|
+
* @param {AppListener} listener The listener to remove.
|
|
56
|
+
*/
|
|
57
|
+
remove_app_listener(listener) {
|
|
58
|
+
this.app_listeners.delete(listener);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,GAAG;IAMd;QAHQ,kBAAa,GAA2B,IAAI,CAAC;QAC7C,kBAAa,GAAqB,IAAI,GAAG,EAAE,CAAC;IAE5B,CAAC;IAEzB,MAAM,CAAC,YAAY;QACjB,IAAI,CAAC,GAAG,CAAC,QAAQ;YACf,GAAG,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,OAAO,GAAG,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAY,IAAU,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAAC,CAAC,CAAC,CAAC;IAElG;;;;OAIG;IACH,sBAAsB,KAA6B,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAE/E;;;;OAIG;IACH,kBAAkB,CAAC,SAAiC;QAClD,IAAI,IAAI,CAAC,aAAa;YACpB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;QAC/B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAAC,QAAQ,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAAC,CAAC;IACxF,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,QAAqB;QACpC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,QAAqB;QACvC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class representing a UI component backed by a DOM Node.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam N - The type of DOM Node associated with this component.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* - Manages mounting state and child components.
|
|
8
|
+
* - Handles DOM node insertion and removal.
|
|
9
|
+
* - Provides lifecycle hooks for mounting and unmounting.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* class MyComponent extends Component<HTMLElement> {
|
|
14
|
+
* mounted() {
|
|
15
|
+
* // Called when the component is mounted
|
|
16
|
+
* }
|
|
17
|
+
* unmounting() {
|
|
18
|
+
* // Called before the component is unmounted
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @property node - The DOM node associated with this component.
|
|
24
|
+
* @property is_mounted - Indicates whether the component is currently mounted.
|
|
25
|
+
* @property child_nodes - The set of child components.
|
|
26
|
+
*
|
|
27
|
+
* @method add_child - Adds a child component and appends its node.
|
|
28
|
+
* @method remove_child - Removes a child component and its node.
|
|
29
|
+
* @method remove - Unmounts and removes this component's node from the DOM.
|
|
30
|
+
* @method mount - Mounts this component to a parent component.
|
|
31
|
+
* @method mounted - Lifecycle hook called after mounting.
|
|
32
|
+
* @method unmounting - Lifecycle hook called before unmounting.
|
|
33
|
+
*/
|
|
34
|
+
export declare abstract class Component<N extends Node> {
|
|
35
|
+
readonly node: N;
|
|
36
|
+
private is_mounted;
|
|
37
|
+
private readonly child_nodes;
|
|
38
|
+
constructor(node: N);
|
|
39
|
+
/**
|
|
40
|
+
* Adds a child component to this component.
|
|
41
|
+
*
|
|
42
|
+
* This method appends the child's node to this component's node and adds the child to the internal set of child nodes.
|
|
43
|
+
* If this component is already mounted, the child will also be marked as mounted.
|
|
44
|
+
*
|
|
45
|
+
* @param child - The child component to add.
|
|
46
|
+
*/
|
|
47
|
+
add_child(child: Component<Node>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Adds a child component before a specified node within this component.
|
|
50
|
+
*
|
|
51
|
+
* This method inserts the child's node before the specified node in this component's node
|
|
52
|
+
* and adds the child to the internal set of child nodes.
|
|
53
|
+
* If this component is already mounted, the child will also be marked as mounted.
|
|
54
|
+
*
|
|
55
|
+
* @param child - The child component to add.
|
|
56
|
+
* @param node - The node before which the child's node will be inserted.
|
|
57
|
+
*/
|
|
58
|
+
add_child_before(child: Component<Node>, node: Node): void;
|
|
59
|
+
/**
|
|
60
|
+
* Removes a child component from the current component.
|
|
61
|
+
*
|
|
62
|
+
* Attempts to delete the specified child from the `child_nodes` collection.
|
|
63
|
+
* If successful, it also calls the child's `remove()` method.
|
|
64
|
+
* Throws an error if the child is not found in the collection.
|
|
65
|
+
*
|
|
66
|
+
* @param child - The child component to remove.
|
|
67
|
+
* @throws {Error} If the child is not found in the `child_nodes` collection.
|
|
68
|
+
*/
|
|
69
|
+
remove_child(child: Component<Node>): void;
|
|
70
|
+
/**
|
|
71
|
+
* Removes the component from the DOM and marks it as unmounted.
|
|
72
|
+
*
|
|
73
|
+
* This method first sets the component's state to unmounted by calling `set_unmounted()`.
|
|
74
|
+
* If the associated node is an instance of `HTMLElement`, it removes the node from the DOM.
|
|
75
|
+
*/
|
|
76
|
+
remove(): void;
|
|
77
|
+
private set_mounted;
|
|
78
|
+
private set_unmounted;
|
|
79
|
+
/**
|
|
80
|
+
* Attaches this component to a parent component.
|
|
81
|
+
*
|
|
82
|
+
* This method performs the following steps:
|
|
83
|
+
* 1. Adds all child nodes of this component to the parent's child node set.
|
|
84
|
+
* 2. Appends this component's DOM node to the parent's DOM node.
|
|
85
|
+
* 3. Marks all child nodes of this component as mounted.
|
|
86
|
+
*
|
|
87
|
+
* @param parent - The parent component to attach this component to.
|
|
88
|
+
*/
|
|
89
|
+
attach_to(parent: Component<Node>): void;
|
|
90
|
+
/**
|
|
91
|
+
* Lifecycle hook called after the component has been mounted to the DOM.
|
|
92
|
+
* Override this method to perform initialization tasks such as fetching data or setting up event listeners.
|
|
93
|
+
*/
|
|
94
|
+
mounted(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Called when the component is about to be unmounted from the DOM.
|
|
97
|
+
* Override this method to perform cleanup tasks such as removing event listeners,
|
|
98
|
+
* cancelling network requests, or releasing resources.
|
|
99
|
+
*/
|
|
100
|
+
unmounting(): void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* An abstract component class that associates a payload of type `P` with a DOM node of type `N`.
|
|
104
|
+
*
|
|
105
|
+
* @typeParam P - The type of the payload data associated with the component.
|
|
106
|
+
* @typeParam N - The type of the DOM node, extending `Node`, that this component wraps.
|
|
107
|
+
* @extends Component<N>
|
|
108
|
+
*
|
|
109
|
+
* @property payload - The payload data associated with this component.
|
|
110
|
+
*
|
|
111
|
+
* @param node - The DOM node to associate with this component.
|
|
112
|
+
* @param payload - The payload data to associate with this component.
|
|
113
|
+
*/
|
|
114
|
+
export declare abstract class PayloadComponent<N extends Node, P> extends Component<N> {
|
|
115
|
+
readonly payload: P;
|
|
116
|
+
constructor(node: N, payload: P);
|
|
117
|
+
}
|
|
118
|
+
export declare class Fragment extends Component<DocumentFragment> {
|
|
119
|
+
constructor();
|
|
120
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class representing a UI component backed by a DOM Node.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam N - The type of DOM Node associated with this component.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* - Manages mounting state and child components.
|
|
8
|
+
* - Handles DOM node insertion and removal.
|
|
9
|
+
* - Provides lifecycle hooks for mounting and unmounting.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* class MyComponent extends Component<HTMLElement> {
|
|
14
|
+
* mounted() {
|
|
15
|
+
* // Called when the component is mounted
|
|
16
|
+
* }
|
|
17
|
+
* unmounting() {
|
|
18
|
+
* // Called before the component is unmounted
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @property node - The DOM node associated with this component.
|
|
24
|
+
* @property is_mounted - Indicates whether the component is currently mounted.
|
|
25
|
+
* @property child_nodes - The set of child components.
|
|
26
|
+
*
|
|
27
|
+
* @method add_child - Adds a child component and appends its node.
|
|
28
|
+
* @method remove_child - Removes a child component and its node.
|
|
29
|
+
* @method remove - Unmounts and removes this component's node from the DOM.
|
|
30
|
+
* @method mount - Mounts this component to a parent component.
|
|
31
|
+
* @method mounted - Lifecycle hook called after mounting.
|
|
32
|
+
* @method unmounting - Lifecycle hook called before unmounting.
|
|
33
|
+
*/
|
|
34
|
+
export class Component {
|
|
35
|
+
constructor(node) {
|
|
36
|
+
this.child_nodes = new Set(); // The children of the component
|
|
37
|
+
this.node = node;
|
|
38
|
+
this.is_mounted = node.isConnected;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Adds a child component to this component.
|
|
42
|
+
*
|
|
43
|
+
* This method appends the child's node to this component's node and adds the child to the internal set of child nodes.
|
|
44
|
+
* If this component is already mounted, the child will also be marked as mounted.
|
|
45
|
+
*
|
|
46
|
+
* @param child - The child component to add.
|
|
47
|
+
*/
|
|
48
|
+
add_child(child) {
|
|
49
|
+
this.child_nodes.add(child);
|
|
50
|
+
this.node.appendChild(child.node);
|
|
51
|
+
if (this.is_mounted)
|
|
52
|
+
child.set_mounted();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Adds a child component before a specified node within this component.
|
|
56
|
+
*
|
|
57
|
+
* This method inserts the child's node before the specified node in this component's node
|
|
58
|
+
* and adds the child to the internal set of child nodes.
|
|
59
|
+
* If this component is already mounted, the child will also be marked as mounted.
|
|
60
|
+
*
|
|
61
|
+
* @param child - The child component to add.
|
|
62
|
+
* @param node - The node before which the child's node will be inserted.
|
|
63
|
+
*/
|
|
64
|
+
add_child_before(child, node) {
|
|
65
|
+
this.child_nodes.add(child);
|
|
66
|
+
this.node.insertBefore(child.node, node);
|
|
67
|
+
if (this.is_mounted)
|
|
68
|
+
child.set_mounted();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Removes a child component from the current component.
|
|
72
|
+
*
|
|
73
|
+
* Attempts to delete the specified child from the `child_nodes` collection.
|
|
74
|
+
* If successful, it also calls the child's `remove()` method.
|
|
75
|
+
* Throws an error if the child is not found in the collection.
|
|
76
|
+
*
|
|
77
|
+
* @param child - The child component to remove.
|
|
78
|
+
* @throws {Error} If the child is not found in the `child_nodes` collection.
|
|
79
|
+
*/
|
|
80
|
+
remove_child(child) {
|
|
81
|
+
if (this.child_nodes.delete(child))
|
|
82
|
+
child.remove();
|
|
83
|
+
else
|
|
84
|
+
throw new Error('Child not found');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Removes the component from the DOM and marks it as unmounted.
|
|
88
|
+
*
|
|
89
|
+
* This method first sets the component's state to unmounted by calling `set_unmounted()`.
|
|
90
|
+
* If the associated node is an instance of `HTMLElement`, it removes the node from the DOM.
|
|
91
|
+
*/
|
|
92
|
+
remove() {
|
|
93
|
+
this.set_unmounted();
|
|
94
|
+
if (this.node instanceof HTMLElement)
|
|
95
|
+
this.node.remove();
|
|
96
|
+
}
|
|
97
|
+
set_mounted() {
|
|
98
|
+
this.is_mounted = true;
|
|
99
|
+
for (const child of this.child_nodes)
|
|
100
|
+
child.set_mounted();
|
|
101
|
+
this.mounted();
|
|
102
|
+
}
|
|
103
|
+
set_unmounted() {
|
|
104
|
+
this.unmounting();
|
|
105
|
+
for (const child of this.child_nodes)
|
|
106
|
+
child.set_unmounted();
|
|
107
|
+
this.is_mounted = false;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Attaches this component to a parent component.
|
|
111
|
+
*
|
|
112
|
+
* This method performs the following steps:
|
|
113
|
+
* 1. Adds all child nodes of this component to the parent's child node set.
|
|
114
|
+
* 2. Appends this component's DOM node to the parent's DOM node.
|
|
115
|
+
* 3. Marks all child nodes of this component as mounted.
|
|
116
|
+
*
|
|
117
|
+
* @param parent - The parent component to attach this component to.
|
|
118
|
+
*/
|
|
119
|
+
attach_to(parent) {
|
|
120
|
+
for (const child of this.child_nodes)
|
|
121
|
+
parent.child_nodes.add(child);
|
|
122
|
+
parent.node.appendChild(this.node);
|
|
123
|
+
for (const child of this.child_nodes)
|
|
124
|
+
child.set_mounted();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Lifecycle hook called after the component has been mounted to the DOM.
|
|
128
|
+
* Override this method to perform initialization tasks such as fetching data or setting up event listeners.
|
|
129
|
+
*/
|
|
130
|
+
mounted() { }
|
|
131
|
+
/**
|
|
132
|
+
* Called when the component is about to be unmounted from the DOM.
|
|
133
|
+
* Override this method to perform cleanup tasks such as removing event listeners,
|
|
134
|
+
* cancelling network requests, or releasing resources.
|
|
135
|
+
*/
|
|
136
|
+
unmounting() { }
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* An abstract component class that associates a payload of type `P` with a DOM node of type `N`.
|
|
140
|
+
*
|
|
141
|
+
* @typeParam P - The type of the payload data associated with the component.
|
|
142
|
+
* @typeParam N - The type of the DOM node, extending `Node`, that this component wraps.
|
|
143
|
+
* @extends Component<N>
|
|
144
|
+
*
|
|
145
|
+
* @property payload - The payload data associated with this component.
|
|
146
|
+
*
|
|
147
|
+
* @param node - The DOM node to associate with this component.
|
|
148
|
+
* @param payload - The payload data to associate with this component.
|
|
149
|
+
*/
|
|
150
|
+
export class PayloadComponent extends Component {
|
|
151
|
+
constructor(node, payload) {
|
|
152
|
+
super(node);
|
|
153
|
+
this.payload = payload;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export class Fragment extends Component {
|
|
157
|
+
constructor() {
|
|
158
|
+
super(document.createDocumentFragment());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAgB,SAAS;IAM7B,YAAY,IAAO;QAFF,gBAAW,GAAyB,IAAI,GAAG,EAAE,CAAC,CAAC,gCAAgC;QAG9F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC;IACrC,CAAC;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,KAAsB;QAC9B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,IAAI,CAAC,UAAU;YACjB,KAAK,CAAC,WAAW,EAAE,CAAC;IACxB,CAAC;IAED;;;;;;;;;OASG;IACH,gBAAgB,CAAC,KAAsB,EAAE,IAAU;QACjD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,UAAU;YACjB,KAAK,CAAC,WAAW,EAAE,CAAC;IACxB,CAAC;IAED;;;;;;;;;OASG;IACH,YAAY,CAAC,KAAsB;QACjC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;YAChC,KAAK,CAAC,MAAM,EAAE,CAAC;;YAEf,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;IAED;;;;;OAKG;I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"}
|
package/dist/components/app.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { VNode, VNodeChildren } from 'snabbdom';
|
|
|
2
2
|
export declare function Brand(content: VNodeChildren, onClick?: () => void): VNode;
|
|
3
3
|
export declare function OffcanvasBrand(content: VNodeChildren, id?: string): VNode;
|
|
4
4
|
export declare function IconBrand(icon: string, width?: number, height?: number, name?: string, onClick?: () => void): VNode;
|
|
5
|
-
export declare function NavbarItem(
|
|
5
|
+
export declare function NavbarItem(content: VNodeChildren, onClick?: () => void, active?: boolean): VNode;
|
|
6
6
|
export declare function NavbarList(items: VNodeChildren[]): VNode;
|
|
7
7
|
export declare function Navbar(brand?: VNodeChildren, navbar_content?: VNodeChildren, id?: string): VNode;
|
|
8
8
|
export declare function App(navbar?: VNodeChildren, content?: VNodeChildren): VNode;
|
package/dist/components/app.js
CHANGED
|
@@ -34,12 +34,12 @@ export function IconBrand(icon, width = 30, height = 30, name, onClick) {
|
|
|
34
34
|
name ? ` ${name}` : ''
|
|
35
35
|
]);
|
|
36
36
|
}
|
|
37
|
-
export function NavbarItem(
|
|
37
|
+
export function NavbarItem(content, onClick, active = false) {
|
|
38
38
|
return h('li.nav-item', { style: { cursor: 'pointer' } }, [
|
|
39
39
|
h('a.nav-link', {
|
|
40
40
|
class: { active },
|
|
41
41
|
on: { click: onClick || (() => { }) }
|
|
42
|
-
},
|
|
42
|
+
}, content)
|
|
43
43
|
]);
|
|
44
44
|
}
|
|
45
45
|
export function NavbarList(items) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/components/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,CAAC,EAAwB,MAAM,UAAU,CAAC;AAEnD,MAAM,UAAU,KAAK,CAAC,OAAsB,EAAE,OAAoB;IAChE,OAAO,CAAC,CAAC,gBAAgB,EACvB;QACE,KAAK,EAAE,EAAE,MAAM,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,OAAO;oBACxB,YAAY,EAAE,mBAAmB;iBAClC;aACF,EAAE;gBACD,CAAC,CAAC,0BAA0B,CAAC;aAC9B,CAAC;YACF,CAAC,CAAC,OAAO,EAAE,2BAA2B,EAAE,cAAc,CAAC;SACxD,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,SAAwB,MAAM,EAAE,EAAE,OAAuB;IAC3E,OAAO,CAAC,CAAC,mCAAmC,EAAE;QAC5C,MAAM;QACN,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Component } from "../app";
|
|
2
|
+
export declare class BrandComponent extends Component<void, HTMLAnchorElement> {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new brand component for the navigation bar.
|
|
5
|
+
*
|
|
6
|
+
* @param name - The display name of the brand. Defaults to 'Flick'.
|
|
7
|
+
* @param icon - The source URL or path for the brand icon. Defaults to 'favicon.ico'.
|
|
8
|
+
* @param icon_width - The width of the brand icon in pixels. Defaults to 32.
|
|
9
|
+
* @param icon_height - The height of the brand icon in pixels. Defaults to 32.
|
|
10
|
+
*
|
|
11
|
+
* The constructor initializes the brand element with an icon and text,
|
|
12
|
+
* styled and aligned for use in a navigation bar.
|
|
13
|
+
*/
|
|
14
|
+
constructor(name?: string, icon?: string, icon_width?: number, icon_height?: number);
|
|
15
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Component } from "../app";
|
|
2
|
+
export class BrandComponent extends Component {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new brand component for the navigation bar.
|
|
5
|
+
*
|
|
6
|
+
* @param name - The display name of the brand. Defaults to 'Flick'.
|
|
7
|
+
* @param icon - The source URL or path for the brand icon. Defaults to 'favicon.ico'.
|
|
8
|
+
* @param icon_width - The width of the brand icon in pixels. Defaults to 32.
|
|
9
|
+
* @param icon_height - The height of the brand icon in pixels. Defaults to 32.
|
|
10
|
+
*
|
|
11
|
+
* The constructor initializes the brand element with an icon and text,
|
|
12
|
+
* styled and aligned for use in a navigation bar.
|
|
13
|
+
*/
|
|
14
|
+
constructor(name = 'Flick', icon = 'favicon.ico', icon_width = 32, icon_height = 32) {
|
|
15
|
+
super(undefined, document.createElement('a'));
|
|
16
|
+
this.element.classList.add('navbar-brand');
|
|
17
|
+
this.element.href = '#';
|
|
18
|
+
const brand_container = document.createElement('div');
|
|
19
|
+
brand_container.style.display = 'flex';
|
|
20
|
+
brand_container.style.alignItems = 'center';
|
|
21
|
+
brand_container.style.gap = '0.5rem'; // Add space between icon and text
|
|
22
|
+
const brand_icon = document.createElement('img');
|
|
23
|
+
brand_icon.src = icon;
|
|
24
|
+
brand_icon.alt = name;
|
|
25
|
+
brand_icon.width = icon_width;
|
|
26
|
+
brand_icon.height = icon_height;
|
|
27
|
+
brand_icon.classList.add('d-inline-block', 'align-text-top');
|
|
28
|
+
brand_container.appendChild(brand_icon);
|
|
29
|
+
if (name) {
|
|
30
|
+
brand_icon.classList.add('me-1');
|
|
31
|
+
const brand_text = document.createElement('span');
|
|
32
|
+
brand_text.textContent = name;
|
|
33
|
+
brand_text.style.fontWeight = '500'; // Make text slightly bolder
|
|
34
|
+
brand_container.appendChild(brand_text);
|
|
35
|
+
}
|
|
36
|
+
this.element.appendChild(brand_container);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=brand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/components/brand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,OAAO,cAAe,SAAQ,SAAkC;IAEpE;;;;;;;;;;OAUG;IACH,YAAY,OAAe,OAAO,EAAE,OAAe,aAAa,EAAE,aAAqB,EAAE,EAAE,cAAsB,EAAE;QACjH,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,CAA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
+
/**
|
|
3
|
+
* A generic checkbox UI component that associates a payload with a checkbox input element.
|
|
4
|
+
*
|
|
5
|
+
* This component renders a checkbox with an optional label and allows tracking its checked state.
|
|
6
|
+
* It provides hooks (`selected` and `unselected`) for custom behavior when the checkbox is toggled.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam P - The type of the payload associated with the checkbox.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class MyCheckbox extends CheckboxComponent<MyPayloadType> {
|
|
13
|
+
* selected() {
|
|
14
|
+
* // Custom logic when checked
|
|
15
|
+
* }
|
|
16
|
+
* unselected() {
|
|
17
|
+
* // Custom logic when unchecked
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class CheckboxComponent<P> extends PayloadComponent<HTMLDivElement, P> {
|
|
23
|
+
private readonly checkbox;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new CheckboxComponent.
|
|
26
|
+
*
|
|
27
|
+
* @param payload The payload associated with the checkbox.
|
|
28
|
+
* @param id_factory A function to generate the ID for the checkbox based on the payload.
|
|
29
|
+
* @param selected Whether the checkbox is initially selected.
|
|
30
|
+
* @param label Optional label for the checkbox.
|
|
31
|
+
*/
|
|
32
|
+
constructor(payload: P, id_factory: (payload: P) => string, selected?: boolean, label?: string);
|
|
33
|
+
/**
|
|
34
|
+
* Sets the checked state of the checkbox.
|
|
35
|
+
*
|
|
36
|
+
* @param checked The new checked state.
|
|
37
|
+
*/
|
|
38
|
+
set_checked(checked: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Callback when the checkbox is selected.
|
|
41
|
+
* Override this method to define custom behavior when the checkbox is selected.
|
|
42
|
+
*/
|
|
43
|
+
selected(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Callback when the checkbox is unselected.
|
|
46
|
+
* Override this method to define custom behavior when the checkbox is unselected.
|
|
47
|
+
*/
|
|
48
|
+
unselected(): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { PayloadComponent } from "../component";
|
|
2
|
+
/**
|
|
3
|
+
* A generic checkbox UI component that associates a payload with a checkbox input element.
|
|
4
|
+
*
|
|
5
|
+
* This component renders a checkbox with an optional label and allows tracking its checked state.
|
|
6
|
+
* It provides hooks (`selected` and `unselected`) for custom behavior when the checkbox is toggled.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam P - The type of the payload associated with the checkbox.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class MyCheckbox extends CheckboxComponent<MyPayloadType> {
|
|
13
|
+
* selected() {
|
|
14
|
+
* // Custom logic when checked
|
|
15
|
+
* }
|
|
16
|
+
* unselected() {
|
|
17
|
+
* // Custom logic when unchecked
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class CheckboxComponent extends PayloadComponent {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new CheckboxComponent.
|
|
25
|
+
*
|
|
26
|
+
* @param payload The payload associated with the checkbox.
|
|
27
|
+
* @param id_factory A function to generate the ID for the checkbox based on the payload.
|
|
28
|
+
* @param selected Whether the checkbox is initially selected.
|
|
29
|
+
* @param label Optional label for the checkbox.
|
|
30
|
+
*/
|
|
31
|
+
constructor(payload, id_factory, selected = false, label) {
|
|
32
|
+
super(document.createElement('div'), payload);
|
|
33
|
+
this.node.classList.add('form-check');
|
|
34
|
+
this.checkbox = document.createElement('input');
|
|
35
|
+
this.checkbox.type = 'checkbox';
|
|
36
|
+
this.checkbox.classList.add('form-check-input');
|
|
37
|
+
this.checkbox.checked = selected;
|
|
38
|
+
this.checkbox.id = id_factory(payload);
|
|
39
|
+
this.node.appendChild(this.checkbox);
|
|
40
|
+
if (label) {
|
|
41
|
+
const labelElement = document.createElement('label');
|
|
42
|
+
labelElement.classList.add('form-check-label');
|
|
43
|
+
labelElement.textContent = label;
|
|
44
|
+
labelElement.setAttribute('for', this.checkbox.id);
|
|
45
|
+
this.node.appendChild(labelElement);
|
|
46
|
+
}
|
|
47
|
+
this.checkbox.addEventListener('click', () => {
|
|
48
|
+
if (this.checkbox.checked)
|
|
49
|
+
this.selected();
|
|
50
|
+
else
|
|
51
|
+
this.unselected();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets the checked state of the checkbox.
|
|
56
|
+
*
|
|
57
|
+
* @param checked The new checked state.
|
|
58
|
+
*/
|
|
59
|
+
set_checked(checked) {
|
|
60
|
+
this.checkbox.checked = checked;
|
|
61
|
+
if (checked)
|
|
62
|
+
this.selected();
|
|
63
|
+
else
|
|
64
|
+
this.unselected();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Callback when the checkbox is selected.
|
|
68
|
+
* Override this method to define custom behavior when the checkbox is selected.
|
|
69
|
+
*/
|
|
70
|
+
selected() { }
|
|
71
|
+
/**
|
|
72
|
+
* Callback when the checkbox is unselected.
|
|
73
|
+
* Override this method to define custom behavior when the checkbox is unselected.
|
|
74
|
+
*/
|
|
75
|
+
unselected() { }
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=checkbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/components/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,iBAAqB,SAAQ,gBAAmC;IAI3E;;;;;;;OAOG;IACH,YAAY,OAAU,EAAE,UAAkC,EAAE,WAAoB,KAAK,EAAE,KAAc;QACnG,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CA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AAW,CAAC;IAEpB;;;OAGG;IACH,UAAU,KAAW,CAAC;CACvB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Component } from "../component";
|
|
2
|
+
import { Selector, SelectorGroup } from "../utils/selector";
|
|
3
|
+
export declare class Sidebar extends Component<HTMLDivElement> {
|
|
4
|
+
constructor(group: SelectorGroup, top: Map<HTMLAnchorElement, Selector>, bottom?: Map<HTMLAnchorElement, Selector>);
|
|
5
|
+
}
|