typecomposer 0.0.6 → 0.0.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/cjs/core/element/action/CheckBox.d.ts +20 -5
- package/dist/cjs/core/element/action/CheckBox.js +58 -5
- package/dist/cjs/core/element/action/CheckBox.js.map +1 -1
- package/dist/cjs/core/element/action/DropDown.d.ts +40 -0
- package/dist/cjs/core/element/action/DropDown.js +159 -0
- package/dist/cjs/core/element/action/DropDown.js.map +1 -0
- package/dist/cjs/core/element/index.d.ts +3 -4
- package/dist/cjs/core/element/index.js +4 -5
- package/dist/cjs/core/element/index.js.map +1 -1
- package/dist/cjs/core/ref/Ref.d.ts +8 -9
- package/dist/cjs/core/ref/Ref.js +67 -111
- package/dist/cjs/core/ref/Ref.js.map +1 -1
- package/dist/cjs/core/ref/index.d.ts +1 -2
- package/dist/cjs/core/ref/index.js +2 -4
- package/dist/cjs/core/ref/index.js.map +1 -1
- package/dist/cjs/core/router/Router.js +3 -2
- package/dist/cjs/core/router/Router.js.map +1 -1
- package/dist/esm/core/element/action/CheckBox.d.ts +20 -5
- package/dist/esm/core/element/action/CheckBox.js +56 -4
- package/dist/esm/core/element/action/CheckBox.js.map +1 -1
- package/dist/esm/core/element/action/DropDown.d.ts +40 -0
- package/dist/esm/core/element/action/DropDown.js +154 -0
- package/dist/esm/core/element/action/DropDown.js.map +1 -0
- package/dist/esm/core/element/index.d.ts +3 -4
- package/dist/esm/core/element/index.js +4 -5
- package/dist/esm/core/element/index.js.map +1 -1
- package/dist/esm/core/ref/Ref.d.ts +8 -9
- package/dist/esm/core/ref/Ref.js +65 -109
- package/dist/esm/core/ref/Ref.js.map +1 -1
- package/dist/esm/core/ref/index.d.ts +1 -2
- package/dist/esm/core/ref/index.js +1 -2
- package/dist/esm/core/ref/index.js.map +1 -1
- package/dist/esm/core/router/Router.js +3 -2
- package/dist/esm/core/router/Router.js.map +1 -1
- package/package.json +1 -1
- package/styles/style.scss +108 -15
- package/dist/cjs/core/element/action/SelectBox.d.ts +0 -20
- package/dist/cjs/core/element/action/SelectBox.js +0 -77
- package/dist/cjs/core/element/action/SelectBox.js.map +0 -1
- package/dist/cjs/core/element/dropdown/DropdownElement.d.ts +0 -8
- package/dist/cjs/core/element/dropdown/DropdownElement.js +0 -34
- package/dist/cjs/core/element/dropdown/DropdownElement.js.map +0 -1
- package/dist/cjs/core/ref/Ref2.d.ts +0 -19
- package/dist/cjs/core/ref/Ref2.js +0 -65
- package/dist/cjs/core/ref/Ref2.js.map +0 -1
- package/dist/esm/core/element/action/SelectBox.d.ts +0 -20
- package/dist/esm/core/element/action/SelectBox.js +0 -73
- package/dist/esm/core/element/action/SelectBox.js.map +0 -1
- package/dist/esm/core/element/dropdown/DropdownElement.d.ts +0 -8
- package/dist/esm/core/element/dropdown/DropdownElement.js +0 -30
- package/dist/esm/core/element/dropdown/DropdownElement.js.map +0 -1
- package/dist/esm/core/ref/Ref2.d.ts +0 -19
- package/dist/esm/core/ref/Ref2.js +0 -61
- package/dist/esm/core/ref/Ref2.js.map +0 -1
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
import { Component, InputElement,
|
|
2
|
-
type ChecBoxType = "checkbox" | "radio";
|
|
1
|
+
import { Component, InputElement, LabelElement, StyleOptional, IconElement } from "../..";
|
|
3
2
|
export declare class CheckBox extends Component {
|
|
4
3
|
private _input;
|
|
5
4
|
private _label;
|
|
6
5
|
private static serial;
|
|
7
|
-
|
|
8
|
-
constructor(optional?:
|
|
6
|
+
private _variant;
|
|
7
|
+
constructor(optional?: StyleOptional & {
|
|
8
|
+
variant?: "checkbox" | "radio";
|
|
9
|
+
label?: string;
|
|
10
|
+
value?: any;
|
|
11
|
+
icon?: IconElement;
|
|
12
|
+
placeholderAnimation?: boolean;
|
|
13
|
+
});
|
|
14
|
+
onChange: (checked: boolean, value?: any) => void;
|
|
15
|
+
get id(): string;
|
|
9
16
|
get checked(): boolean;
|
|
10
17
|
set checked(value: boolean);
|
|
11
18
|
get value(): string;
|
|
12
19
|
set value(value: string);
|
|
13
20
|
get input(): InputElement;
|
|
14
21
|
get label(): LabelElement;
|
|
22
|
+
get variant(): "checkbox" | "radio";
|
|
23
|
+
set variant(value: "checkbox" | "radio");
|
|
24
|
+
}
|
|
25
|
+
export declare class CheckBoxGroup extends Component {
|
|
26
|
+
constructor(...checkBoxes: CheckBox[]);
|
|
27
|
+
append(...nodes: (string | Node)[]): void;
|
|
28
|
+
appendChild<T extends Node>(node: T): T;
|
|
29
|
+
onChange: (checkbox: CheckBox) => void;
|
|
30
|
+
private check;
|
|
15
31
|
}
|
|
16
|
-
export {};
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckBox = void 0;
|
|
3
|
+
exports.CheckBoxGroup = exports.CheckBox = void 0;
|
|
4
4
|
const __1 = require("../..");
|
|
5
5
|
class CheckBox extends __1.Component {
|
|
6
6
|
_input;
|
|
7
7
|
_label;
|
|
8
8
|
static serial = Math.round(Math.random() * 1000);
|
|
9
|
-
|
|
9
|
+
_variant = "checkbox";
|
|
10
10
|
constructor(optional) {
|
|
11
|
+
const label = optional?.label;
|
|
12
|
+
delete optional?.label;
|
|
11
13
|
super(optional);
|
|
14
|
+
this._variant = optional?.variant || "checkbox";
|
|
12
15
|
this._input = new __1.InputElement({
|
|
13
|
-
type: this.
|
|
14
|
-
className: this.
|
|
16
|
+
type: this.variant,
|
|
17
|
+
className: this.variant,
|
|
15
18
|
id: `checkbox-${CheckBox.serial++}-${Math.round(Math.random() * 100)}`,
|
|
16
19
|
});
|
|
17
|
-
this.
|
|
20
|
+
this.input.value = optional?.value || label || "";
|
|
21
|
+
this._label = new __1.LabelElement({ text: label });
|
|
18
22
|
this._label.setAttribute("for", this._input.id);
|
|
19
23
|
if (optional?.color)
|
|
20
24
|
this._input.style.accentColor = optional.color;
|
|
@@ -26,8 +30,13 @@ class CheckBox extends __1.Component {
|
|
|
26
30
|
}
|
|
27
31
|
else
|
|
28
32
|
this._label.style.color = labelColor;
|
|
33
|
+
this.onChange(this._input.checked, this.value);
|
|
29
34
|
});
|
|
30
35
|
}
|
|
36
|
+
onChange = () => { };
|
|
37
|
+
get id() {
|
|
38
|
+
return this.input.id;
|
|
39
|
+
}
|
|
31
40
|
get checked() {
|
|
32
41
|
return this.input.checked;
|
|
33
42
|
}
|
|
@@ -46,8 +55,52 @@ class CheckBox extends __1.Component {
|
|
|
46
55
|
get label() {
|
|
47
56
|
return this._label;
|
|
48
57
|
}
|
|
58
|
+
get variant() {
|
|
59
|
+
return this._variant;
|
|
60
|
+
}
|
|
61
|
+
set variant(value) {
|
|
62
|
+
this._variant = value;
|
|
63
|
+
this.input.type = value;
|
|
64
|
+
this.input.className = value;
|
|
65
|
+
}
|
|
49
66
|
}
|
|
50
67
|
exports.CheckBox = CheckBox;
|
|
51
68
|
// @ts-ignore
|
|
52
69
|
customElements.define("check-box", CheckBox);
|
|
70
|
+
class CheckBoxGroup extends __1.Component {
|
|
71
|
+
constructor(...checkBoxes) {
|
|
72
|
+
super({ display: "flex" });
|
|
73
|
+
this.append(...checkBoxes);
|
|
74
|
+
}
|
|
75
|
+
append(...nodes) {
|
|
76
|
+
nodes.forEach((node) => {
|
|
77
|
+
this.check(node);
|
|
78
|
+
});
|
|
79
|
+
super.append(...nodes);
|
|
80
|
+
}
|
|
81
|
+
appendChild(node) {
|
|
82
|
+
this.check(node);
|
|
83
|
+
return super.appendChild(node);
|
|
84
|
+
}
|
|
85
|
+
onChange = () => { };
|
|
86
|
+
check(node) {
|
|
87
|
+
if (node instanceof CheckBox) {
|
|
88
|
+
const checkbox = node;
|
|
89
|
+
checkbox.addEventListener("change", () => {
|
|
90
|
+
if (checkbox.checked) {
|
|
91
|
+
this.onChange(checkbox);
|
|
92
|
+
this.querySelectorAll("check-box").forEach((cb) => {
|
|
93
|
+
if (cb !== checkbox) {
|
|
94
|
+
cb.checked = false;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
console.log("checkbox: ", checkbox.id, "checked: ", checkbox.checked);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.CheckBoxGroup = CheckBoxGroup;
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
customElements.define("check-box-group", CheckBoxGroup);
|
|
53
106
|
//# sourceMappingURL=CheckBox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckBox.js","sourceRoot":"","sources":["../../../../../src/core/element/action/CheckBox.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"CheckBox.js","sourceRoot":"","sources":["../../../../../src/core/element/action/CheckBox.ts"],"names":[],"mappings":";;;AAAA,6BAMe;AAEf,MAAa,QAAS,SAAQ,aAAS;IAC7B,MAAM,CAAe;IACrB,MAAM,CAAe;IACrB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,QAAQ,GAAyB,UAAU,CAAC;IAEpD,YACE,QAMC;QAED,MAAM,KAAK,GAAG,QAAQ,EAAE,KAAK,CAAC;QAC9B,OAAO,QAAQ,EAAE,KAAK,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,EAAE,OAAO,IAAI,UAAU,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAY,CAAC;YAC7B,IAAI,EAAE,IAAI,CAAC,OAAO;YAClB,SAAS,EAAE,IAAI,CAAC,OAAO;YACvB,EAAE,EAAE,YAAY,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE;SACvE,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,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AAC;IACjC,CAAC;IAEM,QAAQ,GAAiC,GAAG,EAAE,GAAE,CAAC,CAAC;IAEjD,KAAK,CAAiB,IAAO;QACnC,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,IAAgB,CAAC;YAClC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACvC,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;oBACrB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBACxB,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;wBAChD,IAAI,EAAE,KAAK,QAAQ,EAAE,CAAC;4BACnB,EAAe,CAAC,OAAO,GAAG,KAAK,CAAC;wBACnC,CAAC;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AApCD,sCAoCC;AAED,aAAa;AACb,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Component, DivElement, StyleOptional } from "../..";
|
|
2
|
+
type SelectionType = "closeAndClean" | "closeAndKeep" | "openAndClean" | "openAndKeep";
|
|
3
|
+
export declare class DropDownItem extends DivElement {
|
|
4
|
+
}
|
|
5
|
+
export declare class DropDown<T = any> extends Component {
|
|
6
|
+
private onSelectionAction;
|
|
7
|
+
private _selectionType;
|
|
8
|
+
private previousSelected;
|
|
9
|
+
private _input;
|
|
10
|
+
private _inputAndButtonDiv;
|
|
11
|
+
private _options;
|
|
12
|
+
private _dropdownContent;
|
|
13
|
+
private _idClass;
|
|
14
|
+
onChange: (item: T) => void;
|
|
15
|
+
constructor(props: StyleOptional & {
|
|
16
|
+
placeHolder?: string;
|
|
17
|
+
noContent?: string;
|
|
18
|
+
options?: T[];
|
|
19
|
+
defaultOption?: string;
|
|
20
|
+
selectionType?: SelectionType;
|
|
21
|
+
});
|
|
22
|
+
onInit(): void;
|
|
23
|
+
private handleClickOutside;
|
|
24
|
+
private closeAndClean;
|
|
25
|
+
private closeAndKeep;
|
|
26
|
+
private openAndClean;
|
|
27
|
+
get selectionType(): SelectionType;
|
|
28
|
+
set selectionType(selectionType: SelectionType);
|
|
29
|
+
get input(): DivElement;
|
|
30
|
+
set input(input: DivElement);
|
|
31
|
+
get options(): T[];
|
|
32
|
+
set options(options: T[]);
|
|
33
|
+
get inputAndButtonDiv(): DivElement;
|
|
34
|
+
set inputAndButtonDiv(inputAndButtonDiv: DivElement);
|
|
35
|
+
get dropdownContent(): DivElement;
|
|
36
|
+
set dropdownContent(dropdownContent: DivElement);
|
|
37
|
+
get idClass(): number;
|
|
38
|
+
set idClass(idClass: number);
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DropDown = exports.DropDownItem = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
class DropDownItem extends __1.DivElement {
|
|
6
|
+
}
|
|
7
|
+
exports.DropDownItem = DropDownItem;
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
customElements.define("drop-down-item", DropDownItem, { extends: "div" });
|
|
10
|
+
class DropDown extends __1.Component {
|
|
11
|
+
onSelectionAction = this.closeAndClean.bind(this);
|
|
12
|
+
_selectionType;
|
|
13
|
+
previousSelected = [];
|
|
14
|
+
_input;
|
|
15
|
+
_inputAndButtonDiv;
|
|
16
|
+
_options = [];
|
|
17
|
+
_dropdownContent;
|
|
18
|
+
_idClass;
|
|
19
|
+
onChange = () => { };
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
this.inputAndButtonDiv = new __1.DivElement({
|
|
23
|
+
className: "input-and-button-div",
|
|
24
|
+
});
|
|
25
|
+
this.dropdownContent = new __1.DivElement({ className: "dropdown-content" });
|
|
26
|
+
this.append(this.inputAndButtonDiv, this.dropdownContent);
|
|
27
|
+
this.input = new __1.DivElement({ className: "input" });
|
|
28
|
+
this.input.textContent = props.placeHolder
|
|
29
|
+
? props.placeHolder
|
|
30
|
+
: props.defaultOption;
|
|
31
|
+
this.selectionType = props.selectionType || "closeAndClean";
|
|
32
|
+
this.onInit();
|
|
33
|
+
this.options =
|
|
34
|
+
props.options == undefined || props.options.length === 0
|
|
35
|
+
? [props.noContent]
|
|
36
|
+
: props.options;
|
|
37
|
+
}
|
|
38
|
+
onInit() {
|
|
39
|
+
this.className = "dropdown";
|
|
40
|
+
const arrow = new __1.DivElement({ className: "arrow-down" });
|
|
41
|
+
this.inputAndButtonDiv.append(this.input, arrow);
|
|
42
|
+
this.inputAndButtonDiv.onclick = () => {
|
|
43
|
+
if (this.options.length === 0)
|
|
44
|
+
return;
|
|
45
|
+
this.inputAndButtonDiv.classList.toggle("pressed");
|
|
46
|
+
arrow.classList.toggle("up");
|
|
47
|
+
console.log(this.inputAndButtonDiv.children[1].classList);
|
|
48
|
+
};
|
|
49
|
+
this.handleClickOutside = this.handleClickOutside.bind(this);
|
|
50
|
+
document.addEventListener("mousedown", this.handleClickOutside);
|
|
51
|
+
}
|
|
52
|
+
handleClickOutside(event) {
|
|
53
|
+
if (!this.inputAndButtonDiv.contains(event.target) &&
|
|
54
|
+
!this.dropdownContent.contains(event.target) &&
|
|
55
|
+
this.inputAndButtonDiv.classList.contains("pressed")) {
|
|
56
|
+
this.inputAndButtonDiv.children[1].classList.toggle("pressed");
|
|
57
|
+
this.inputAndButtonDiv.classList.toggle("pressed");
|
|
58
|
+
this.inputAndButtonDiv.children[1].classList.toggle("up");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
closeAndClean() {
|
|
62
|
+
Array.from(this.dropdownContent.children).forEach((child) => {
|
|
63
|
+
child.classList.remove("selected");
|
|
64
|
+
});
|
|
65
|
+
this.inputAndButtonDiv.children[1].classList.toggle("pressed");
|
|
66
|
+
this.inputAndButtonDiv.classList.toggle("pressed");
|
|
67
|
+
this.inputAndButtonDiv.children[1].classList.toggle("up");
|
|
68
|
+
}
|
|
69
|
+
closeAndKeep() {
|
|
70
|
+
this.inputAndButtonDiv.children[1].classList.toggle("pressed");
|
|
71
|
+
this.inputAndButtonDiv.classList.toggle("pressed");
|
|
72
|
+
this.inputAndButtonDiv.children[1].classList.toggle("up");
|
|
73
|
+
}
|
|
74
|
+
openAndClean() {
|
|
75
|
+
Array.from(this.dropdownContent.children).forEach((child) => {
|
|
76
|
+
child.classList.remove("selected");
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
get selectionType() {
|
|
80
|
+
return this._selectionType;
|
|
81
|
+
}
|
|
82
|
+
set selectionType(selectionType) {
|
|
83
|
+
if (selectionType == "closeAndKeep")
|
|
84
|
+
this.onSelectionAction = this.closeAndKeep.bind(this);
|
|
85
|
+
else if (selectionType == "openAndClean")
|
|
86
|
+
this.onSelectionAction = this.openAndClean.bind(this);
|
|
87
|
+
else if (selectionType == "openAndKeep")
|
|
88
|
+
this.onSelectionAction = () => { };
|
|
89
|
+
else
|
|
90
|
+
this.onSelectionAction = this.closeAndClean.bind(this);
|
|
91
|
+
this._selectionType = selectionType;
|
|
92
|
+
}
|
|
93
|
+
get input() {
|
|
94
|
+
return this._input;
|
|
95
|
+
}
|
|
96
|
+
set input(input) {
|
|
97
|
+
this._input = input;
|
|
98
|
+
}
|
|
99
|
+
get options() {
|
|
100
|
+
return this._options;
|
|
101
|
+
}
|
|
102
|
+
set options(options) {
|
|
103
|
+
this._options = options;
|
|
104
|
+
if (!this.dropdownContent)
|
|
105
|
+
return;
|
|
106
|
+
this.dropdownContent.innerHTML = "";
|
|
107
|
+
this.options.forEach((option) => {
|
|
108
|
+
let node;
|
|
109
|
+
if (option instanceof Node)
|
|
110
|
+
node = this.dropdownContent.appendChild(option);
|
|
111
|
+
else {
|
|
112
|
+
const div = new DropDownItem({
|
|
113
|
+
text: option?.toString() || "",
|
|
114
|
+
});
|
|
115
|
+
node = div;
|
|
116
|
+
if (this.previousSelected.includes(option)) {
|
|
117
|
+
div.classList.toggle("selected");
|
|
118
|
+
}
|
|
119
|
+
this.dropdownContent.append(div);
|
|
120
|
+
}
|
|
121
|
+
node.classList.add("option");
|
|
122
|
+
node.onclick = () => {
|
|
123
|
+
this.onSelectionAction();
|
|
124
|
+
node.classList.toggle("selected");
|
|
125
|
+
if (node.classList.contains("selected")) {
|
|
126
|
+
this.previousSelected.push(option);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.previousSelected = this.previousSelected.filter((selectedOption) => selectedOption !== option);
|
|
130
|
+
}
|
|
131
|
+
this.input.textContent = option?.toString() || "";
|
|
132
|
+
this.input.style.color = "black";
|
|
133
|
+
this.onChange(option);
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
get inputAndButtonDiv() {
|
|
138
|
+
return this._inputAndButtonDiv;
|
|
139
|
+
}
|
|
140
|
+
set inputAndButtonDiv(inputAndButtonDiv) {
|
|
141
|
+
this._inputAndButtonDiv = inputAndButtonDiv;
|
|
142
|
+
}
|
|
143
|
+
get dropdownContent() {
|
|
144
|
+
return this._dropdownContent;
|
|
145
|
+
}
|
|
146
|
+
set dropdownContent(dropdownContent) {
|
|
147
|
+
this._dropdownContent = dropdownContent;
|
|
148
|
+
}
|
|
149
|
+
get idClass() {
|
|
150
|
+
return this._idClass;
|
|
151
|
+
}
|
|
152
|
+
set idClass(idClass) {
|
|
153
|
+
this._idClass = idClass;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.DropDown = DropDown;
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
customElements.define("drop-down", DropDown);
|
|
159
|
+
//# sourceMapp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,CAAC,CAAC;YACxB,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;IAED,IAAI,iBAAiB,CAAC,iBAA6B;QACjD,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAC9C,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED,IAAI,eAAe,CAAC,eAA2B;QAC7C,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;IAC1C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,CAAC,OAAe;QACzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;CACF;AA1KD,4BA0KC;AAED,aAAa;AACb,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -6,7 +6,6 @@ import { VBoxElement } from "./layers/VBoxElement";
|
|
|
6
6
|
import { HBoxElement } from "./layers/HBoxElement";
|
|
7
7
|
import { GridElement } from "./layers/GridElement";
|
|
8
8
|
import { BorderPaneElement } from "./layers/BorderPaneElement";
|
|
9
|
-
import { DropdownElement } from "./dropdown/DropdownElement";
|
|
10
9
|
import { App } from "./base/App";
|
|
11
10
|
import { FlowPane } from "./layers/FlowPane";
|
|
12
11
|
import { ListElement } from "./action/ListElement";
|
|
@@ -15,12 +14,12 @@ import { IconElement } from "./image/IconElement";
|
|
|
15
14
|
import { TabElement } from "./action/TabElement";
|
|
16
15
|
import { PaneElement } from "./layers/PaneElement";
|
|
17
16
|
import { SlidePane } from "./action/SlidePane";
|
|
18
|
-
import {
|
|
17
|
+
import { DropDown } from "./action/DropDown";
|
|
19
18
|
import { Variant } from "./base/CSSStyle";
|
|
20
19
|
import { ChartElement } from "./action/ChartPane";
|
|
21
|
-
import { CheckBox } from "./action/CheckBox";
|
|
20
|
+
import { CheckBox, CheckBoxGroup } from "./action/CheckBox";
|
|
22
21
|
import { ToggleButton } from "./action/ToggleButton";
|
|
23
22
|
import { ILayout, StyleOptional } from "./base/Elements";
|
|
24
23
|
import { StackPane } from "./layers/StackPane";
|
|
25
|
-
export { App, CardElement,
|
|
24
|
+
export { App, CardElement, ChartElement, CheckBox, CheckBoxGroup, ToggleButton, DropDown, SlidePane, TabPane, TabElement, ListElement, IconElement, FlowPane, VBoxElement, HBoxElement, GridElement, PaneElement, BorderPaneElement, StyleLink, ILayout, StackPane, };
|
|
26
25
|
export type { Variant, StyleOptional };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StackPane = exports.ILayout = exports.StyleLink = exports.BorderPaneElement = exports.PaneElement = exports.GridElement = exports.HBoxElement = exports.VBoxElement = exports.FlowPane = exports.IconElement = exports.ListElement = exports.TabElement = exports.TabPane = exports.SlidePane = exports.
|
|
3
|
+
exports.StackPane = exports.ILayout = exports.StyleLink = exports.BorderPaneElement = exports.PaneElement = exports.GridElement = exports.HBoxElement = exports.VBoxElement = exports.FlowPane = exports.IconElement = exports.ListElement = exports.TabElement = exports.TabPane = exports.SlidePane = exports.DropDown = exports.ToggleButton = exports.CheckBoxGroup = exports.CheckBox = exports.ChartElement = exports.CardElement = exports.App = void 0;
|
|
4
4
|
__exportStar(require("./base/Elements"), exports);
|
|
5
5
|
__exportStar(require("./text"), exports);
|
|
6
6
|
const CardElement_1 = require("./layers/CardElement");
|
|
@@ -15,8 +15,6 @@ const GridElement_1 = require("./layers/GridElement");
|
|
|
15
15
|
Object.defineProperty(exports, "GridElement", { enumerable: true, get: function () { return GridElement_1.GridElement; } });
|
|
16
16
|
const BorderPaneElement_1 = require("./layers/BorderPaneElement");
|
|
17
17
|
Object.defineProperty(exports, "BorderPaneElement", { enumerable: true, get: function () { return BorderPaneElement_1.BorderPaneElement; } });
|
|
18
|
-
const DropdownElement_1 = require("./dropdown/DropdownElement");
|
|
19
|
-
Object.defineProperty(exports, "DropdownElement", { enumerable: true, get: function () { return DropdownElement_1.DropdownElement; } });
|
|
20
18
|
const App_1 = require("./base/App");
|
|
21
19
|
Object.defineProperty(exports, "App", { enumerable: true, get: function () { return App_1.App; } });
|
|
22
20
|
const FlowPane_1 = require("./layers/FlowPane");
|
|
@@ -33,12 +31,13 @@ const PaneElement_1 = require("./layers/PaneElement");
|
|
|
33
31
|
Object.defineProperty(exports, "PaneElement", { enumerable: true, get: function () { return PaneElement_1.PaneElement; } });
|
|
34
32
|
const SlidePane_1 = require("./action/SlidePane");
|
|
35
33
|
Object.defineProperty(exports, "SlidePane", { enumerable: true, get: function () { return SlidePane_1.SlidePane; } });
|
|
36
|
-
const
|
|
37
|
-
Object.defineProperty(exports, "
|
|
34
|
+
const DropDown_1 = require("./action/DropDown");
|
|
35
|
+
Object.defineProperty(exports, "DropDown", { enumerable: true, get: function () { return DropDown_1.DropDown; } });
|
|
38
36
|
const ChartPane_1 = require("./action/ChartPane");
|
|
39
37
|
Object.defineProperty(exports, "ChartElement", { enumerable: true, get: function () { return ChartPane_1.ChartElement; } });
|
|
40
38
|
const CheckBox_1 = require("./action/CheckBox");
|
|
41
39
|
Object.defineProperty(exports, "CheckBox", { enumerable: true, get: function () { return CheckBox_1.CheckBox; } });
|
|
40
|
+
Object.defineProperty(exports, "CheckBoxGroup", { enumerable: true, get: function () { return CheckBox_1.CheckBoxGroup; } });
|
|
42
41
|
const ToggleButton_1 = require("./action/ToggleButton");
|
|
43
42
|
Object.defineProperty(exports, "ToggleButton", { enumerable: true, get: function () { return ToggleButton_1.ToggleButton; } });
|
|
44
43
|
const Elements_1 = require("./base/Elements");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/element/index.ts"],"names":[],"mappings":";;;AAAA,kDAAgC;AAChC,yCAAuB;AAEvB,sDAAmD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/element/index.ts"],"names":[],"mappings":";;;AAAA,kDAAgC;AAChC,yCAAuB;AAEvB,sDAAmD;AAwBjD,4FAxBO,yBAAW,OAwBP;AAvBb,uDAAoD;AAkDlD,0FAlDO,qBAAS,OAkDP;AAjDX,sDAAmD;AA4CjD,4FA5CO,yBAAW,OA4CP;AA3Cb,sDAAmD;AA4CjD,4FA5CO,yBAAW,OA4CP;AA3Cb,sDAAmD;AA4CjD,4FA5CO,yBAAW,OA4CP;AA3Cb,kEAA+D;AA6C7D,kGA7CO,qCAAiB,OA6CP;AA5CnB,oCAAiC;AAiB/B,oFAjBO,SAAG,OAiBP;AAhBL,gDAA6C;AAsC3C,yFAtCO,mBAAQ,OAsCP;AArCV,sDAAmD;AAgCjD,4FAhCO,yBAAW,OAgCP;AA/Bb,8CAA2C;AA6BzC,wFA7BO,iBAAO,OA6BP;AA5BT,qDAAkD;AAgChD,4FAhCO,yBAAW,OAgCP;AA/Bb,oDAAiD;AA4B/C,2FA5BO,uBAAU,OA4BP;AA3BZ,sDAAmD;AAqCjD,4FArCO,yBAAW,OAqCP;AApCb,kDAA+C;AAwB7C,0FAxBO,qBAAS,OAwBP;AAvBX,gDAA6C;AAmB3C,yFAnBO,mBAAQ,OAmBP;AAjBV,kDAAkD;AAShD,6FATO,wBAAY,OASP;AARd,gDAA4D;AAS1D,yFATO,mBAAQ,OASP;AACR,8FAViB,wBAAa,OAUjB;AATf,wDAAqD;AAUnD,6FAVO,2BAAY,OAUP;AATd,8CAAyD;AAiCvD,wFAjCO,kBAAO,OAiCP;AAhCT,kDAA+C;AAiC7C,0FAjCO,qBAAS,OAiCP"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
export declare class
|
|
1
|
+
export declare class Ref<T> {
|
|
2
2
|
private _id;
|
|
3
|
+
private _value;
|
|
4
|
+
private registry;
|
|
3
5
|
private _subscribers;
|
|
4
|
-
proxy: any;
|
|
5
6
|
constructor(value: T);
|
|
6
|
-
destructor(): void;
|
|
7
|
-
private setData;
|
|
8
7
|
get value(): T;
|
|
9
8
|
set value(v: T);
|
|
10
9
|
get id(): string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
fun?: Function;
|
|
15
|
-
}): void;
|
|
10
|
+
private notify;
|
|
11
|
+
private setValueToSubscriber;
|
|
12
|
+
subscriber(target: {}, propertyKey: string | symbol): void;
|
|
16
13
|
unsubscribe(data: {
|
|
17
14
|
ref: any;
|
|
18
15
|
name: string;
|
|
19
16
|
fun?: Function;
|
|
20
17
|
}): void;
|
|
18
|
+
onChange(fun: (value: T) => void, target?: {}): void;
|
|
19
|
+
toString(): string;
|
|
21
20
|
}
|
package/dist/cjs/core/ref/Ref.js
CHANGED
|
@@ -1,130 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.Ref = void 0;
|
|
4
|
+
class Ref {
|
|
5
5
|
_id = Math.random().toString(36).substr(2, 9);
|
|
6
|
+
_value;
|
|
7
|
+
registry;
|
|
6
8
|
_subscribers = [];
|
|
7
|
-
proxy;
|
|
8
9
|
constructor(value) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
set: this.setData.bind(this),
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(this, "value", {
|
|
17
|
-
get: function () {
|
|
18
|
-
return this.proxy;
|
|
19
|
-
},
|
|
20
|
-
set: function (v) {
|
|
21
|
-
this.proxy = v;
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
this.toString = function () {
|
|
25
|
-
return JSON.stringify(this.proxy);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
this.proxy = value;
|
|
30
|
-
this.toString = function () {
|
|
31
|
-
return this.proxy;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
destructor() { }
|
|
36
|
-
setData(target, prop, value) {
|
|
37
|
-
this._subscribers.forEach((subscriber) => {
|
|
38
|
-
if (subscriber.fun)
|
|
39
|
-
subscriber.fun(this.toString());
|
|
40
|
-
else
|
|
41
|
-
subscriber.ref[subscriber.name] = this.toString();
|
|
10
|
+
this._value = value;
|
|
11
|
+
this._value = value;
|
|
12
|
+
this.registry = new FinalizationRegistry((target) => {
|
|
13
|
+
this._subscribers = this._subscribers.filter((subscriber) => subscriber.target != target);
|
|
14
|
+
console.log("registry: ", target);
|
|
42
15
|
});
|
|
43
|
-
target[prop] = value;
|
|
44
|
-
return true;
|
|
45
16
|
}
|
|
46
17
|
get value() {
|
|
47
|
-
return this.
|
|
18
|
+
return this._value;
|
|
48
19
|
}
|
|
49
20
|
set value(v) {
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
subscriber.fun(v);
|
|
53
|
-
else
|
|
54
|
-
subscriber.ref[subscriber.name] = v;
|
|
55
|
-
});
|
|
56
|
-
this.proxy = v;
|
|
21
|
+
this._value = v;
|
|
22
|
+
this.notify();
|
|
57
23
|
}
|
|
58
24
|
get id() {
|
|
59
25
|
return this._id;
|
|
60
26
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
27
|
+
notify() {
|
|
28
|
+
const remove = [];
|
|
29
|
+
this._subscribers.forEach((subscriber) => {
|
|
30
|
+
if (!this.setValueToSubscriber(subscriber))
|
|
31
|
+
remove.push(subscriber);
|
|
32
|
+
});
|
|
33
|
+
this._subscribers = this._subscribers.filter((subscriber) => !remove.includes(subscriber));
|
|
34
|
+
}
|
|
35
|
+
setValueToSubscriber(subscriber) {
|
|
36
|
+
try {
|
|
37
|
+
const target = subscriber.target?.deref();
|
|
38
|
+
if (target) {
|
|
39
|
+
if (subscriber.fun) {
|
|
40
|
+
const fun = subscriber.fun?.deref();
|
|
41
|
+
if (fun)
|
|
42
|
+
fun(this._value);
|
|
43
|
+
else
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
target[subscriber.propertyKey] = this._value;
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
subscriber(target, propertyKey) {
|
|
58
|
+
const item = { target: new WeakRef(target), propertyKey };
|
|
59
|
+
if (this.setValueToSubscriber(item)) {
|
|
60
|
+
this._subscribers.push(item);
|
|
61
|
+
this.registry.register(item.target, item);
|
|
62
|
+
}
|
|
66
63
|
}
|
|
67
64
|
unsubscribe(data) {
|
|
68
|
-
this._subscribers = this._subscribers.filter(
|
|
65
|
+
// this._subscribers = this._subscribers.filter(
|
|
66
|
+
// (subscriber) => subscriber != data,
|
|
67
|
+
// );
|
|
68
|
+
}
|
|
69
|
+
onChange(fun, target) {
|
|
70
|
+
const data = new WeakRef(fun);
|
|
71
|
+
const item = {
|
|
72
|
+
target: target ? new WeakRef(target) : data,
|
|
73
|
+
propertyKey: undefined,
|
|
74
|
+
fun: data,
|
|
75
|
+
};
|
|
76
|
+
if (this.setValueToSubscriber(item)) {
|
|
77
|
+
this._subscribers.push(item);
|
|
78
|
+
this.registry.register(item.target, item);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
toString() {
|
|
82
|
+
return this._value?.toString() || "";
|
|
69
83
|
}
|
|
70
84
|
}
|
|
71
|
-
exports.
|
|
72
|
-
// declare global {
|
|
73
|
-
// interface Ref<T extends any> {
|
|
74
|
-
// subscriber(data: { ref: any, name: string }): void;
|
|
75
|
-
// unsubscribe(data: { ref: any, name: string }): void;
|
|
76
|
-
// }
|
|
77
|
-
// interface String {
|
|
78
|
-
// toRef(): Ref<string>;
|
|
79
|
-
// }
|
|
80
|
-
// interface Number {
|
|
81
|
-
// toRef(): Ref<number>;
|
|
82
|
-
// }
|
|
83
|
-
// interface Boolean {
|
|
84
|
-
// toRef(): Ref<boolean>;
|
|
85
|
-
// }
|
|
86
|
-
// interface Date {
|
|
87
|
-
// toRef(): Ref<Date>;
|
|
88
|
-
// }
|
|
89
|
-
// interface Array<T> {
|
|
90
|
-
// toRef(): Ref<T[]>;
|
|
91
|
-
// clear(): void;
|
|
92
|
-
// }
|
|
93
|
-
// interface Object {
|
|
94
|
-
// toRef(): Ref<Object>;
|
|
95
|
-
// }
|
|
96
|
-
// interface Function {
|
|
97
|
-
// toRef(): Ref<Function>;
|
|
98
|
-
// }
|
|
99
|
-
// interface Symbol {
|
|
100
|
-
// toRef(): Ref<Symbol>;
|
|
101
|
-
// }
|
|
102
|
-
// interface BigInt {
|
|
103
|
-
// toRef(): Ref<BigInt>;
|
|
104
|
-
// }
|
|
105
|
-
// interface RegExp {
|
|
106
|
-
// toRef(): Ref<RegExp>;
|
|
107
|
-
// }
|
|
108
|
-
// interface Error {
|
|
109
|
-
// toRef(): Ref<Error>;
|
|
110
|
-
// }
|
|
111
|
-
// interface EvalError {
|
|
112
|
-
// toRef(): Ref<EvalError>;
|
|
113
|
-
// }
|
|
114
|
-
// interface RangeError {
|
|
115
|
-
// toRef(): Ref<RangeError>;
|
|
116
|
-
// }
|
|
117
|
-
// interface ReferenceError {
|
|
118
|
-
// toRef(): Ref<ReferenceError>;
|
|
119
|
-
// }
|
|
120
|
-
// interface SyntaxError {
|
|
121
|
-
// toRef(): Ref<SyntaxError>;
|
|
122
|
-
// }
|
|
123
|
-
// interface TypeError {
|
|
124
|
-
// toRef(): Ref<TypeError>;
|
|
125
|
-
// }
|
|
126
|
-
// }
|
|
127
|
-
// Array.prototype.clear = function () {
|
|
128
|
-
// this.length = 0;
|
|
129
|
-
// }
|
|
85
|
+
exports.Ref = Ref;
|
|
130
86
|
//# sourceMappingURL=Ref.js.map
|