typecomposer 0.1.47 → 0.1.50
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/assets/index.js +1 -2
- package/core/components/AlertPanel.d.ts +6 -6
- package/core/components/AlertPanel.js +1 -75
- package/core/components/AlertPanel.js.map +1 -1
- package/core/components/AvatarPanel.d.ts +2 -2
- package/core/components/AvatarPanel.js +1 -62
- package/core/components/AvatarPanel.js.map +1 -1
- package/core/components/BorderPanel.d.ts +2 -2
- package/core/components/BorderPanel.js +1 -90
- package/core/components/BorderPanel.js.map +1 -1
- package/core/components/CardPanel.d.ts +2 -2
- package/core/components/CardPanel.js +1 -11
- package/core/components/CardPanel.js.map +1 -1
- package/core/components/CheckBox.d.ts +2 -2
- package/core/components/CheckBox.js +1 -109
- package/core/components/CheckBox.js.map +1 -1
- package/core/components/ColorPicker.d.ts +2 -2
- package/core/components/ColorPicker.js +1 -36
- package/core/components/ColorPicker.js.map +1 -1
- package/core/components/ContextMenu.d.ts +3 -3
- package/core/components/ContextMenu.js +1 -64
- package/core/components/ContextMenu.js.map +1 -1
- package/core/components/DialogPanel.d.ts +2 -2
- package/core/components/DialogPanel.js +1 -62
- package/core/components/DialogPanel.js.map +1 -1
- package/core/components/DropDown.d.ts +3 -3
- package/core/components/DropDown.js +1 -231
- package/core/components/DropDown.js.map +1 -1
- package/core/components/FlowPanel.d.ts +2 -2
- package/core/components/FlowPanel.js +1 -40
- package/core/components/FlowPanel.js.map +1 -1
- package/core/components/ForEach.d.ts +2 -2
- package/core/components/ForEach.js +1 -88
- package/core/components/ForEach.js.map +1 -1
- package/core/components/GridPanel.d.ts +4 -7
- package/core/components/GridPanel.js +1 -30
- package/core/components/GridPanel.js.map +1 -1
- package/core/components/HBox.d.ts +2 -2
- package/core/components/HBox.js +1 -10
- package/core/components/HBox.js.map +1 -1
- package/core/components/LazyLoading.d.ts +2 -2
- package/core/components/LazyLoading.js +1 -36
- package/core/components/LazyLoading.js.map +1 -1
- package/core/components/ListPanel.d.ts +2 -2
- package/core/components/ListPanel.js +1 -153
- package/core/components/ListPanel.js.map +1 -1
- package/core/components/PopUpButton.d.ts +2 -2
- package/core/components/PopUpButton.js +1 -57
- package/core/components/PopUpButton.js.map +1 -1
- package/core/components/ScrollPanel.d.ts +2 -2
- package/core/components/ScrollPanel.js +1 -35
- package/core/components/ScrollPanel.js.map +1 -1
- package/core/components/SliderPanel.d.ts +2 -2
- package/core/components/SliderPanel.js +1 -135
- package/core/components/SliderPanel.js.map +1 -1
- package/core/components/StackPanel.d.ts +2 -2
- package/core/components/StackPanel.js +1 -10
- package/core/components/StackPanel.js.map +1 -1
- package/core/components/TabItem.js +1 -84
- package/core/components/TabPanel.d.ts +2 -2
- package/core/components/TabPanel.js +1 -96
- package/core/components/TabPanel.js.map +1 -1
- package/core/components/TextEdit.js +1 -174
- package/core/components/TextField.d.ts +2 -2
- package/core/components/TextField.js +1 -140
- package/core/components/TextField.js.map +1 -1
- package/core/components/ToggleButton.d.ts +2 -2
- package/core/components/ToggleButton.js +1 -20
- package/core/components/ToggleButton.js.map +1 -1
- package/core/components/Tooltip.d.ts +4 -6
- package/core/components/Tooltip.js +1 -14
- package/core/components/Tooltip.js.map +1 -1
- package/core/components/VBox.d.ts +2 -2
- package/core/components/VBox.js +1 -10
- package/core/components/VBox.js.map +1 -1
- package/core/components/VirtualScroll.d.ts +2 -2
- package/core/components/VirtualScroll.js +1 -47
- package/core/components/index.d.ts +1 -2
- package/core/components/index.js +1 -30
- package/core/components/index.js.map +1 -1
- package/core/decorators/RegisterComponent.js +1 -20
- package/core/decorators/StyleLink.js +1 -13
- package/core/decorators/index.js +1 -6
- package/core/element/AbbreviationElement.d.ts +2 -4
- package/core/element/AbbreviationElement.js +1 -10
- package/core/element/AbbreviationElement.js.map +1 -1
- package/core/element/AnchorElement.d.ts +2 -18
- package/core/element/AnchorElement.js +1 -31
- package/core/element/AnchorElement.js.map +1 -1
- package/core/element/AreaElement.d.ts +2 -15
- package/core/element/AreaElement.js +1 -11
- package/core/element/AreaElement.js.map +1 -1
- package/core/element/ArticleElement.d.ts +2 -2
- package/core/element/ArticleElement.js +1 -12
- package/core/element/ArticleElement.js.map +1 -1
- package/core/element/AudioElement.d.ts +2 -9
- package/core/element/AudioElement.js +1 -10
- package/core/element/AudioElement.js.map +1 -1
- package/core/element/BaseElement.d.ts +2 -5
- package/core/element/BaseElement.js +1 -11
- package/core/element/BaseElement.js.map +1 -1
- package/core/element/BodyElement.d.ts +2 -2
- package/core/element/BodyElement.js +1 -11
- package/core/element/BodyElement.js.map +1 -1
- package/core/element/BoldElement.d.ts +2 -2
- package/core/element/BoldElement.js +1 -10
- package/core/element/BoldElement.js.map +1 -1
- package/core/element/BreakElement.d.ts +2 -2
- package/core/element/BreakElement.js +1 -10
- package/core/element/BreakElement.js.map +1 -1
- package/core/element/ButtonElement.d.ts +4 -21
- package/core/element/ButtonElement.js +1 -47
- package/core/element/ButtonElement.js.map +1 -1
- package/core/element/CanvasElement.d.ts +2 -2
- package/core/element/CanvasElement.js +1 -14
- package/core/element/CanvasElement.js.map +1 -1
- package/core/element/CaptionElement.d.ts +2 -2
- package/core/element/CaptionElement.js +1 -13
- package/core/element/CaptionElement.js.map +1 -1
- package/core/element/CiteElement.d.ts +2 -2
- package/core/element/CiteElement.js +1 -11
- package/core/element/CiteElement.js.map +1 -1
- package/core/element/CodeElement.d.ts +2 -2
- package/core/element/CodeElement.js +1 -13
- package/core/element/CodeElement.js.map +1 -1
- package/core/element/DataListElement.d.ts +2 -2
- package/core/element/DataListElement.js +1 -13
- package/core/element/DataListElement.js.map +1 -1
- package/core/element/DefinitionDescriptionElement.d.ts +2 -2
- package/core/element/DefinitionDescriptionElement.js +1 -13
- package/core/element/DefinitionDescriptionElement.js.map +1 -1
- package/core/element/DefinitionElement.d.ts +2 -2
- package/core/element/DefinitionElement.js +1 -13
- package/core/element/DefinitionElement.js.map +1 -1
- package/core/element/DeletedTextElement.d.ts +2 -4
- package/core/element/DeletedTextElement.js +1 -15
- package/core/element/DeletedTextElement.js.map +1 -1
- package/core/element/DetailsElement.d.ts +3 -6
- package/core/element/DetailsElement.js +1 -28
- package/core/element/DetailsElement.js.map +1 -1
- package/core/element/DialogElement.d.ts +2 -4
- package/core/element/DialogElement.js +1 -14
- package/core/element/DialogElement.js.map +1 -1
- package/core/element/DivElement.d.ts +2 -2
- package/core/element/DivElement.js +1 -10
- package/core/element/DivElement.js.map +1 -1
- package/core/element/EmElement.d.ts +2 -2
- package/core/element/EmElement.js +1 -10
- package/core/element/EmElement.js.map +1 -1
- package/core/element/EmbedElement.d.ts +2 -7
- package/core/element/EmbedElement.js +1 -19
- package/core/element/EmbedElement.js.map +1 -1
- package/core/element/FieldSetElement.d.ts +3 -6
- package/core/element/FieldSetElement.js +1 -34
- package/core/element/FieldSetElement.js.map +1 -1
- package/core/element/FooterElement.d.ts +2 -2
- package/core/element/FooterElement.js +1 -13
- package/core/element/FooterElement.js.map +1 -1
- package/core/element/FormElement.d.ts +2 -17
- package/core/element/FormElement.js +1 -36
- package/core/element/FormElement.js.map +1 -1
- package/core/element/Fragment.js +1 -103
- package/core/element/H1Element.d.ts +2 -2
- package/core/element/H1Element.js +1 -10
- package/core/element/H1Element.js.map +1 -1
- package/core/element/H2Element.d.ts +2 -2
- package/core/element/H2Element.js +1 -10
- package/core/element/H2Element.js.map +1 -1
- package/core/element/H3Element.d.ts +2 -2
- package/core/element/H3Element.js +1 -10
- package/core/element/H3Element.js.map +1 -1
- package/core/element/H4Element.d.ts +2 -2
- package/core/element/H4Element.js +1 -10
- package/core/element/H4Element.js.map +1 -1
- package/core/element/H5Element.d.ts +2 -2
- package/core/element/H5Element.js +1 -10
- package/core/element/H5Element.js.map +1 -1
- package/core/element/H6Element.d.ts +2 -2
- package/core/element/H6Element.js +1 -10
- package/core/element/H6Element.js.map +1 -1
- package/core/element/HeadElement.d.ts +2 -2
- package/core/element/HeadElement.js +1 -11
- package/core/element/HeadElement.js.map +1 -1
- package/core/element/HeaderElement.d.ts +2 -2
- package/core/element/HeaderElement.js +1 -13
- package/core/element/HeaderElement.js.map +1 -1
- package/core/element/HorizontalRuleElement.d.ts +2 -2
- package/core/element/HorizontalRuleElement.js +1 -13
- package/core/element/HorizontalRuleElement.js.map +1 -1
- package/core/element/HtmlElement.d.ts +2 -4
- package/core/element/HtmlElement.js +1 -19
- package/core/element/HtmlElement.js.map +1 -1
- package/core/element/IFrameElement.d.ts +2 -15
- package/core/element/IFrameElement.js +1 -67
- package/core/element/IFrameElement.js.map +1 -1
- package/core/element/ILayout.d.ts +2 -2
- package/core/element/ILayout.js +1 -9
- package/core/element/ILayout.js.map +1 -1
- package/core/element/IconElement.d.ts +2 -2
- package/core/element/IconElement.js +1 -32
- package/core/element/IconElement.js.map +1 -1
- package/core/element/IdiomaticElement.d.ts +2 -1
- package/core/element/IdiomaticElement.js +1 -6
- package/core/element/IdiomaticElement.js.map +1 -1
- package/core/element/ImageElement.d.ts +2 -2
- package/core/element/ImageElement.js +1 -17
- package/core/element/ImageElement.js.map +1 -1
- package/core/element/InputElement.d.ts +2 -16
- package/core/element/InputElement.js +1 -81
- package/core/element/InputElement.js.map +1 -1
- package/core/element/LabelElement.d.ts +2 -5
- package/core/element/LabelElement.js +1 -10
- package/core/element/LabelElement.js.map +1 -1
- package/core/element/LegendElement.d.ts +2 -4
- package/core/element/LegendElement.js +1 -15
- package/core/element/LegendElement.js.map +1 -1
- package/core/element/ListItemElement.d.ts +2 -4
- package/core/element/ListItemElement.js +1 -28
- package/core/element/ListItemElement.js.map +1 -1
- package/core/element/MainElement.d.ts +2 -2
- package/core/element/MainElement.js +1 -10
- package/core/element/MainElement.js.map +1 -1
- package/core/element/NavElement.d.ts +2 -2
- package/core/element/NavElement.js +1 -10
- package/core/element/NavElement.js.map +1 -1
- package/core/element/OrderedListElement.d.ts +2 -2
- package/core/element/OrderedListElement.js +1 -10
- package/core/element/OrderedListElement.js.map +1 -1
- package/core/element/ParagraphElement.d.ts +2 -2
- package/core/element/ParagraphElement.js +1 -10
- package/core/element/ParagraphElement.js.map +1 -1
- package/core/element/PreElement.d.ts +2 -2
- package/core/element/PreElement.js +1 -10
- package/core/element/PreElement.js.map +1 -1
- package/core/element/SectionElement.d.ts +2 -2
- package/core/element/SectionElement.js +1 -12
- package/core/element/SectionElement.js.map +1 -1
- package/core/element/SelectElement.d.ts +2 -2
- package/core/element/SelectElement.js +1 -12
- package/core/element/SelectElement.js.map +1 -1
- package/core/element/SourceElement.d.ts +2 -5
- package/core/element/SourceElement.js +1 -14
- package/core/element/SourceElement.js.map +1 -1
- package/core/element/SpanElement.d.ts +2 -2
- package/core/element/SpanElement.js +1 -10
- package/core/element/SpanElement.js.map +1 -1
- package/core/element/StrongElement.d.ts +2 -2
- package/core/element/StrongElement.js +1 -12
- package/core/element/StrongElement.js.map +1 -1
- package/core/element/StyleElement.d.ts +2 -2
- package/core/element/StyleElement.js +1 -10
- package/core/element/StyleElement.js.map +1 -1
- package/core/element/SummaryElement.d.ts +2 -2
- package/core/element/SummaryElement.js +1 -12
- package/core/element/SummaryElement.js.map +1 -1
- package/core/element/SvgElement.d.ts +3 -3
- package/core/element/SvgElement.js +1 -151
- package/core/element/SvgElement.js.map +1 -1
- package/core/element/TableBodyElement.d.ts +2 -2
- package/core/element/TableBodyElement.js +1 -10
- package/core/element/TableBodyElement.js.map +1 -1
- package/core/element/TableCellElement.d.ts +3 -6
- package/core/element/TableCellElement.js +1 -25
- package/core/element/TableCellElement.js.map +1 -1
- package/core/element/TableColElement.d.ts +2 -4
- package/core/element/TableColElement.js +1 -13
- package/core/element/TableColElement.js.map +1 -1
- package/core/element/TableColGroupElement.d.ts +2 -4
- package/core/element/TableColGroupElement.js +1 -15
- package/core/element/TableColGroupElement.js.map +1 -1
- package/core/element/TableElement.d.ts +2 -42
- package/core/element/TableElement.js +1 -228
- package/core/element/TableElement.js.map +1 -1
- package/core/element/TableFootElement.d.ts +2 -2
- package/core/element/TableFootElement.js +1 -10
- package/core/element/TableFootElement.js.map +1 -1
- package/core/element/TableFootRowElement.d.ts +2 -2
- package/core/element/TableFootRowElement.js +1 -23
- package/core/element/TableFootRowElement.js.map +1 -1
- package/core/element/TableHeadCellElement.d.ts +2 -2
- package/core/element/TableHeadCellElement.js +1 -24
- package/core/element/TableHeadCellElement.js.map +1 -1
- package/core/element/TableHeadElement.d.ts +2 -2
- package/core/element/TableHeadElement.js +1 -10
- package/core/element/TableHeadElement.js.map +1 -1
- package/core/element/TableHeadRowElement.d.ts +2 -2
- package/core/element/TableHeadRowElement.js +1 -29
- package/core/element/TableHeadRowElement.js.map +1 -1
- package/core/element/TableRowElement.d.ts +2 -2
- package/core/element/TableRowElement.js +1 -29
- package/core/element/TableRowElement.js.map +1 -1
- package/core/element/TextAreaElement.d.ts +2 -4
- package/core/element/TextAreaElement.js +1 -10
- package/core/element/TextAreaElement.js.map +1 -1
- package/core/element/UListElement.d.ts +2 -2
- package/core/element/UListElement.js +1 -10
- package/core/element/UListElement.js.map +1 -1
- package/core/element/VideoElement.d.ts +2 -10
- package/core/element/VideoElement.js +1 -16
- package/core/element/VideoElement.js.map +1 -1
- package/core/element/index.d.ts +3 -3
- package/core/element/index.js +1 -73
- package/core/element/index.js.map +1 -1
- package/core/event/index.js +1 -75
- package/core/index.d.ts +0 -3
- package/core/index.js +1 -10
- package/core/index.js.map +1 -1
- package/core/ref/Computed.js +1 -75
- package/core/ref/Computed.js.map +1 -1
- package/core/ref/RefBoolean.js +1 -119
- package/core/ref/RefContainer.js +1 -114
- package/core/ref/RefContainer.js.map +1 -1
- package/core/ref/RefList.js +1 -240
- package/core/ref/RefMap.js +1 -149
- package/core/ref/RefNumber.js +1 -157
- package/core/ref/RefObject.js +1 -265
- package/core/ref/RefObject.js.map +1 -1
- package/core/ref/RefProperty.js +1 -46
- package/core/ref/RefSet.js +1 -148
- package/core/ref/RefState.js +1 -89
- package/core/ref/RefString.js +1 -179
- package/core/ref/RefString.js.map +1 -1
- package/core/ref/index.js +1 -71
- package/core/router/RouteView.d.ts +2 -2
- package/core/router/RouteView.js +1 -84
- package/core/router/RouteView.js.map +1 -1
- package/core/router/Router.d.ts +8 -9
- package/core/router/Router.js +1 -307
- package/core/router/Router.js.map +1 -1
- package/core/router/RouterEvent.js +1 -43
- package/core/router/RouterGuard.js +1 -3
- package/core/router/index.js +1 -5
- package/core/styles/index.d.ts +3 -3
- package/core/styles/index.js +1 -36
- package/core/styles/index.js.map +1 -1
- package/{core/app/index.d.ts → global/app.d.ts} +5 -7
- package/global/app.js +1 -0
- package/global/app.js.map +1 -0
- package/global/index.d.ts +10 -4
- package/global/index.js +1 -1286
- package/global/index.js.map +1 -1
- package/global/safari-polyfill.js +1 -234
- package/index.d.ts +1 -0
- package/index.js +1 -4
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/styles/style.scss +2 -17
- package/typings/index.d.ts +58 -66
- package/LICENSE +0 -21
- package/README.md +0 -62
- package/core/app/Validate.d.ts +0 -61
- package/core/app/Validate.js +0 -2
- package/core/app/Validate.js.map +0 -1
- package/core/app/index.js +0 -181
- package/core/app/index.js.map +0 -1
- package/core/components/TablePanel.d.ts +0 -34
- package/core/components/TablePanel.js +0 -127
- package/core/components/TablePanel.js.map +0 -1
- package/core/components/VirtualScroll copy 2.d.ts +0 -24
- package/core/components/VirtualScroll copy 2.js +0 -92
- package/core/components/VirtualScroll copy 2.js.map +0 -1
- package/core/ref/RefObject copy.d.ts +0 -124
- package/core/ref/RefObject copy.js +0 -271
- package/core/ref/RefObject copy.js.map +0 -1
package/core/ref/RefObject.js
CHANGED
|
@@ -1,265 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RefContainer } from "./RefContainer";
|
|
3
|
-
import { RefSet } from "./RefSet";
|
|
4
|
-
class RefObjectContainer extends RefContainer {
|
|
5
|
-
root;
|
|
6
|
-
instance = { value: null };
|
|
7
|
-
constructor(value, root) {
|
|
8
|
-
super(value, root);
|
|
9
|
-
this.root = root;
|
|
10
|
-
this.value = createObservador(value, this);
|
|
11
|
-
if (isApplyProxy(value)) {
|
|
12
|
-
RefObjectContainer.createObject.bind(this)(this.value, value, this);
|
|
13
|
-
}
|
|
14
|
-
else
|
|
15
|
-
this.value = value;
|
|
16
|
-
}
|
|
17
|
-
valueOf() {
|
|
18
|
-
return this.instance.value;
|
|
19
|
-
}
|
|
20
|
-
static createObject(proxy, value, container) {
|
|
21
|
-
if (Object.getPrototypeOf(proxy) === Object.prototype) {
|
|
22
|
-
for (const key in value) {
|
|
23
|
-
try {
|
|
24
|
-
if (Object.getOwnPropertyDescriptor(proxy, key)?.writable === false
|
|
25
|
-
|| Object.getOwnPropertyDescriptor(proxy, key)?.get
|
|
26
|
-
|| Object.getOwnPropertyDescriptor(proxy, key)?.set) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (value[key] === undefined || value[key] === null) {
|
|
30
|
-
proxy[key] = value[key];
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (value[key] instanceof Array) {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
proxy[key] = new RefList(value[key]);
|
|
36
|
-
}
|
|
37
|
-
else if (value[key] instanceof Set) {
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
proxy[key] = new RefSet(value[key]);
|
|
40
|
-
}
|
|
41
|
-
else if (value[key] instanceof Map) {
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
proxy[key] = new RefMap(value[key]);
|
|
44
|
-
}
|
|
45
|
-
else if (typeof value[key] === "string" || value[key] instanceof String) {
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
proxy[key] = new RefString(value[key].valueOf());
|
|
48
|
-
}
|
|
49
|
-
else if (typeof value[key] === "number" || value[key] instanceof Number) {
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
proxy[key] = new RefNumber(value[key].valueOf());
|
|
52
|
-
}
|
|
53
|
-
else if (typeof value[key] === "boolean" || value[key] instanceof Boolean) {
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
proxy[key] = new RefBoolean(value[key].valueOf());
|
|
56
|
-
}
|
|
57
|
-
else if (value[key] instanceof Element) {
|
|
58
|
-
//proxy[key] =
|
|
59
|
-
}
|
|
60
|
-
else if (value[key] instanceof Object) {
|
|
61
|
-
if (Object.getPrototypeOf(proxy) === Object.prototype) {
|
|
62
|
-
const con = new RefObjectContainer(value[key], (container["root"] || this));
|
|
63
|
-
proxy[key] = con.value;
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
proxy[key] = value[key];
|
|
67
|
-
}
|
|
68
|
-
if (proxy[key] instanceof ref) {
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
proxy[key]["container"].root = container.root || this;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
static applyObject(proxy, value, container) {
|
|
79
|
-
const keysOld = Object.keys(proxy);
|
|
80
|
-
const keys = Object.keys(value);
|
|
81
|
-
const keysRemove = keysOld.filter((k) => !keys.includes(k));
|
|
82
|
-
const keysUpdate = keys.filter((k) => keysOld.includes(k));
|
|
83
|
-
const keysNew = keys.filter((k) => !keysOld.includes(k));
|
|
84
|
-
for (const key of keysRemove) {
|
|
85
|
-
if (!keys.includes(key)) {
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
delete proxy[key];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
for (const key of keysUpdate) {
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
if (proxy[key] instanceof ref) {
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
proxy[key].emit(key, value[key]);
|
|
95
|
-
}
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
else if (!(proxy[key] instanceof Element) && proxy[key] instanceof Object) {
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
RefObjectContainer.applyObject.bind(this)(proxy[key], value[key], container);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (keysNew.length === 0)
|
|
103
|
-
return;
|
|
104
|
-
const newObject = {};
|
|
105
|
-
for (const key of keysNew) {
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
newObject[key] = value[key];
|
|
108
|
-
}
|
|
109
|
-
RefObjectContainer.createObject.bind(this)(proxy, newObject, container);
|
|
110
|
-
}
|
|
111
|
-
emitAll(propertyName, value) {
|
|
112
|
-
super.emitAll(propertyName, value, value);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function applyProxy(target, key, value, receiver, container) {
|
|
116
|
-
if (target[key] instanceof ref) {
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
target[key].emit(key, value);
|
|
119
|
-
}
|
|
120
|
-
else if ((!(target[key] instanceof Element)) && target[key] instanceof Object) {
|
|
121
|
-
if (Object.getPrototypeOf(target[key]) === Object.prototype)
|
|
122
|
-
RefObjectContainer.applyObject(target[key], value, container);
|
|
123
|
-
}
|
|
124
|
-
else if (value !== undefined && value !== null) {
|
|
125
|
-
RefObjectContainer.createObject(target, { [key]: value }, container);
|
|
126
|
-
}
|
|
127
|
-
else
|
|
128
|
-
Reflect.set(target, key, value, receiver);
|
|
129
|
-
return receiver;
|
|
130
|
-
}
|
|
131
|
-
function isApplyProxy(value) {
|
|
132
|
-
if (!value)
|
|
133
|
-
return false;
|
|
134
|
-
if (typeof value !== "object")
|
|
135
|
-
return true;
|
|
136
|
-
return (Object.getPrototypeOf(value) === Object.prototype || Array.isArray(value)
|
|
137
|
-
|| value instanceof Map || value instanceof Set || value instanceof Number || value instanceof Boolean || value instanceof String);
|
|
138
|
-
}
|
|
139
|
-
function createObservador(obj, container) {
|
|
140
|
-
// if (!obj) obj = {} as T;
|
|
141
|
-
const refObject = new Proxy(obj || {}, {
|
|
142
|
-
// @ts-ignore
|
|
143
|
-
get(target, key, receiver) {
|
|
144
|
-
if (key == "toString")
|
|
145
|
-
return JSON.stringify(obj);
|
|
146
|
-
if (key == "toJSON")
|
|
147
|
-
return () => {
|
|
148
|
-
return JSON.parse(JSON.stringify(obj));
|
|
149
|
-
};
|
|
150
|
-
if (key == "valueOf")
|
|
151
|
-
return JSON.parse(JSON.stringify(obj));
|
|
152
|
-
return Reflect.get(target, key, receiver);
|
|
153
|
-
},
|
|
154
|
-
// @ts-ignore
|
|
155
|
-
set(target, key, value, receiver) {
|
|
156
|
-
if (value && value instanceof ref)
|
|
157
|
-
value = value?.valueOf() || value;
|
|
158
|
-
if (isApplyProxy(value))
|
|
159
|
-
receiver = applyProxy(target, key, value, receiver, container);
|
|
160
|
-
else {
|
|
161
|
-
receiver = Reflect.set(target, key, value, receiver);
|
|
162
|
-
}
|
|
163
|
-
container.emitAll(key, value);
|
|
164
|
-
return receiver;
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
container.value = refObject;
|
|
168
|
-
return refObject;
|
|
169
|
-
}
|
|
170
|
-
export function ref(value) {
|
|
171
|
-
// if (value === undefined || value === null) throw new Error("ref: value cannot be null or undefined");
|
|
172
|
-
value = deepCopy(value);
|
|
173
|
-
if (typeof value === "string" || value instanceof String) {
|
|
174
|
-
return new RefString(value.valueOf());
|
|
175
|
-
}
|
|
176
|
-
else if (typeof value === "number" || value instanceof Number) {
|
|
177
|
-
return new RefNumber(value.valueOf());
|
|
178
|
-
}
|
|
179
|
-
else if (typeof value === "boolean" || value instanceof Boolean) {
|
|
180
|
-
return new RefBoolean(value.valueOf());
|
|
181
|
-
}
|
|
182
|
-
else if (value instanceof Array) {
|
|
183
|
-
return new RefList(value);
|
|
184
|
-
}
|
|
185
|
-
else if (value instanceof Set) {
|
|
186
|
-
return new RefSet(value);
|
|
187
|
-
}
|
|
188
|
-
else if (value instanceof Map) {
|
|
189
|
-
return new RefMap(value);
|
|
190
|
-
}
|
|
191
|
-
const container = new RefObjectContainer(value);
|
|
192
|
-
const instance = {
|
|
193
|
-
value: container.value,
|
|
194
|
-
subscribe: container.subscribe.bind(container),
|
|
195
|
-
listen: container.listen.bind(container),
|
|
196
|
-
unsubscribe: container.unsubscribe.bind(container),
|
|
197
|
-
toString: container.toString.bind(container),
|
|
198
|
-
toJSON: container.toJSON.bind(container),
|
|
199
|
-
valueOf: container.valueOf.bind(container),
|
|
200
|
-
id: container.id
|
|
201
|
-
};
|
|
202
|
-
container["instance"] = instance;
|
|
203
|
-
Object.defineProperty(instance, Symbol.iterator, {
|
|
204
|
-
value: function* () {
|
|
205
|
-
for (const key in instance.value) {
|
|
206
|
-
yield instance.value[key]?.valueOf() || instance.value[key];
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
Object.defineProperty(instance, "value", {
|
|
211
|
-
get() {
|
|
212
|
-
return container.value;
|
|
213
|
-
},
|
|
214
|
-
set(value) {
|
|
215
|
-
RefObjectContainer.applyObject(container.value, value, container);
|
|
216
|
-
container.emitAll("value", value);
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
Object.setPrototypeOf(instance, ref.prototype);
|
|
220
|
-
// @ts-ignore
|
|
221
|
-
Ref.set(container.id, instance);
|
|
222
|
-
return instance;
|
|
223
|
-
}
|
|
224
|
-
Object.defineProperty(ref, Symbol.hasInstance, {
|
|
225
|
-
value: function (instance) {
|
|
226
|
-
return (!!instance && typeof instance === "object" &&
|
|
227
|
-
(instance === ref ||
|
|
228
|
-
Object.getPrototypeOf(instance) === ref.prototype ||
|
|
229
|
-
instance instanceof RefString ||
|
|
230
|
-
instance instanceof RefNumber ||
|
|
231
|
-
instance instanceof RefBoolean ||
|
|
232
|
-
instance instanceof RefList ||
|
|
233
|
-
instance instanceof RefSet ||
|
|
234
|
-
instance instanceof RefMap ||
|
|
235
|
-
instance instanceof RefState));
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
// function computedTemplateStringsArray<T>(fn: TemplateStringsArray, ...values: any[]): DynamicRef<T> {
|
|
239
|
-
// const observers: any[] = values.pop();
|
|
240
|
-
// console.log("computed", fn, "values", values);
|
|
241
|
-
// const r = ref(fn.reduce((acc, str, i) => {
|
|
242
|
-
// // @ts-ignore
|
|
243
|
-
// return acc + str + (values[i] !== undefined ? (values[i] instanceof ref) ? values[i].value : values[i] : "");
|
|
244
|
-
// }, ""));
|
|
245
|
-
// const func = () => {
|
|
246
|
-
// r.value = fn.reduce((acc, str, i) => {
|
|
247
|
-
// // @ts-ignore
|
|
248
|
-
// return acc + str + (values[i] !== undefined ? (values[i] instanceof ref) ? values[i].value : values[i] : "");
|
|
249
|
-
// }, "");
|
|
250
|
-
// }
|
|
251
|
-
// for (const item of observers) {
|
|
252
|
-
// if (item instanceof ref) {
|
|
253
|
-
// // @ts-ignore
|
|
254
|
-
// item.listen(func);
|
|
255
|
-
// }
|
|
256
|
-
// }
|
|
257
|
-
// // @ts-ignore
|
|
258
|
-
// return r
|
|
259
|
-
// }
|
|
260
|
-
export const Interface = {
|
|
261
|
-
empty: function () {
|
|
262
|
-
return {};
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
//# sourceMappingURL=RefObject.js.map
|
|
1
|
+
import{RefNumber,RefString,RefBoolean,RefMap,RefList,Ref,RefState}from".";import{RefContainer}from"./RefContainer";import{RefSet}from"./RefSet";class RefObjectContainer extends RefContainer{root;instance={value:null};constructor(e,t){super(e,t),this.root=t,this.value=createObservador(e,this),isApplyProxy(e)?RefObjectContainer.createObject.bind(this)(this.value,e,this):this.value=e}valueOf(){return this.instance.value}subscribeAndEmit(e,t,n){const o=this.subscribe(e,t,n);return this.emit(o,this.value,this.value),o}static createObject(e,t,n){if(Object.getPrototypeOf(e)===Object.prototype)for(const o in t)try{if(!1===Object.getOwnPropertyDescriptor(e,o)?.writable||Object.getOwnPropertyDescriptor(e,o)?.get||Object.getOwnPropertyDescriptor(e,o)?.set)continue;if(void 0===t[o]||null===t[o]){e[o]=t[o];continue}if(t[o]instanceof Array)e[o]=new RefList(t[o]);else if(t[o]instanceof Set)e[o]=new RefSet(t[o]);else if(t[o]instanceof Map)e[o]=new RefMap(t[o]);else if("string"==typeof t[o]||t[o]instanceof String)e[o]=new RefString(t[o].valueOf());else if("number"==typeof t[o]||t[o]instanceof Number)e[o]=new RefNumber(t[o].valueOf());else if("boolean"==typeof t[o]||t[o]instanceof Boolean)e[o]=new RefBoolean(t[o].valueOf());else if(t[o]instanceof Element);else if(t[o]instanceof Object)if(Object.getPrototypeOf(e)===Object.prototype){const i=new RefObjectContainer(t[o],n.root||this);e[o]=i.value}else e[o]=t[o];e[o]instanceof ref&&(e[o].container.root=n.root||this)}catch(e){}}static applyObject(e,t,n){const o=Object.keys(e),i=Object.keys(t),r=o.filter(e=>!i.includes(e)),f=i.filter(e=>o.includes(e)),s=i.filter(e=>!o.includes(e));for(const t of r)i.includes(t)||delete e[t];for(const o of f)e[o]instanceof ref?e[o].emit(o,t[o]):!(e[o]instanceof Element)&&e[o]instanceof Object&&RefObjectContainer.applyObject.bind(this)(e[o],t[o],n);if(0===s.length)return;const c={};for(const e of s)c[e]=t[e];RefObjectContainer.createObject.bind(this)(e,c,n)}emitAll(e,t){super.emitAll(e,t,t)}}function applyProxy(e,t,n,o,i){return e[t]instanceof ref?e[t].emit(t,n):!(e[t]instanceof Element)&&e[t]instanceof Object?Object.getPrototypeOf(e[t])===Object.prototype&&RefObjectContainer.applyObject(e[t],n,i):null!=n?RefObjectContainer.createObject(e,{[t]:n},i):Reflect.set(e,t,n,o),o}function isApplyProxy(e){return!!e&&("object"!=typeof e||(Object.getPrototypeOf(e)===Object.prototype||Array.isArray(e)||e instanceof Map||e instanceof Set||e instanceof Number||e instanceof Boolean||e instanceof String))}function createObservador(e,t){const n=new Proxy(e||{},{get:(t,n,o)=>"toString"==n?JSON.stringify(e):"toJSON"==n?()=>JSON.parse(JSON.stringify(e)):"valueOf"==n?JSON.parse(JSON.stringify(e)):Reflect.get(t,n,o),set:(e,n,o,i)=>(o&&o instanceof ref&&(o=o?.valueOf()||o),i=isApplyProxy(o)?applyProxy(e,n,o,i,t):Reflect.set(e,n,o,i),t.emitAll(n,o),i)});return t.value=n,n}export function ref(e){if("string"==typeof(e=TypeComposer.deepCopy(e))||e instanceof String)return new RefString(e.valueOf());if("number"==typeof e||e instanceof Number)return new RefNumber(e.valueOf());if("boolean"==typeof e||e instanceof Boolean)return new RefBoolean(e.valueOf());if(e instanceof Array)return new RefList(e);if(e instanceof Set)return new RefSet(e);if(e instanceof Map)return new RefMap(e);const t=new RefObjectContainer(e),n={value:t.value,subscribe:t.subscribeAndEmit.bind(t),listen:t.listen.bind(t),unsubscribe:t.unsubscribe.bind(t),toString:t.toString.bind(t),toJSON:t.toJSON.bind(t),valueOf:t.valueOf.bind(t),id:t.id};return t.instance=n,Object.defineProperty(n,Symbol.iterator,{value:function*(){for(const e in n.value)yield n.value[e]?.valueOf()||n.value[e]}}),Object.defineProperty(n,"value",{get:()=>t.value,set(e){RefObjectContainer.applyObject(t.value,e,t),t.emitAll("value",e)}}),Object.setPrototypeOf(n,ref.prototype),Ref.set(t.id,n),n}Object.defineProperty(ref,Symbol.hasInstance,{value:function(e){return!!e&&"object"==typeof e&&(e===ref||Object.getPrototypeOf(e)===ref.prototype||e instanceof RefString||e instanceof RefNumber||e instanceof RefBoolean||e instanceof RefList||e instanceof RefSet||e instanceof RefMap||e instanceof RefState)}});export const Interface={empty:function(){return{}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefObject.js","sourceRoot":"","sources":["../../../src/core/ref/RefObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAwB,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAmB,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AACxI,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAU,MAAM,UAAU,CAAC;AAE1C,MAAM,kBAAmB,SAAQ,YAAY;
|
|
1
|
+
{"version":3,"file":"RefObject.js","sourceRoot":"","sources":["../../../src/core/ref/RefObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EA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;IACjB,CAAC;CACF,CAAC"}
|
package/core/ref/RefProperty.js
CHANGED
|
@@ -1,46 +1 @@
|
|
|
1
|
-
import { RefString }
|
|
2
|
-
export function refProperty(value, propertyName, target) {
|
|
3
|
-
if (!target)
|
|
4
|
-
throw new Error("refProperty: needs to be inside a component");
|
|
5
|
-
const ref = new RefString(value || target?.getAttribute(propertyName) || "");
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
ref.propertyName = propertyName;
|
|
8
|
-
ref.subscribe((value) => {
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
if (target?.getAttribute(ref.propertyName) === value)
|
|
11
|
-
return;
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
target.setAttribute(ref.propertyName, value || "");
|
|
14
|
-
});
|
|
15
|
-
createObserver(target, ref);
|
|
16
|
-
return ref;
|
|
17
|
-
}
|
|
18
|
-
Object.defineProperty(refProperty, Symbol.hasInstance, {
|
|
19
|
-
value: function (instance) {
|
|
20
|
-
return !!instance && (instance instanceof RefString);
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
function createObserver(target, ref) {
|
|
24
|
-
if (target["___observer___"]) {
|
|
25
|
-
const ___refs___ = target["___observer___"]["___refs___"];
|
|
26
|
-
___refs___.push(ref);
|
|
27
|
-
return target["___observer___"];
|
|
28
|
-
}
|
|
29
|
-
const observer = new MutationObserver((mutations) => {
|
|
30
|
-
mutations.forEach((mutation) => {
|
|
31
|
-
const items = observer["___refs___"];
|
|
32
|
-
if (mutation.attributeName) {
|
|
33
|
-
for (const ref of items) {
|
|
34
|
-
if (mutation.attributeName === ref.propertyName) {
|
|
35
|
-
ref.value = target.getAttribute(ref.propertyName) || "";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
observer["___refs___"] = [ref];
|
|
42
|
-
observer.observe(target, { attributes: true });
|
|
43
|
-
target["___observer___"] = observer;
|
|
44
|
-
return observer;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=RefProperty.js.map
|
|
1
|
+
import{RefString}from".";export function refProperty(e,r,t){if(!t)throw new Error("refProperty: needs to be inside a component");const _=new RefString(e||t?.getAttribute(r)||"");return _.propertyName=r,_.subscribe(e=>{t?.getAttribute(_.propertyName)!==e&&t.setAttribute(_.propertyName,e||"")}),createObserver(t,_),_}function createObserver(e,r){if(e.___observer___){return e.___observer___.___refs___.push(r),e.___observer___}const t=new MutationObserver(r=>{r.forEach(r=>{const _=t.___refs___;if(r.attributeName)for(const t of _)r.attributeName===t.propertyName&&(t.value=e.getAttribute(t.propertyName)||"")})});return t.___refs___=[r],t.observe(e,{attributes:!0}),e.___observer___=t,t}Object.defineProperty(refProperty,Symbol.hasInstance,{value:function(e){return!!e&&e instanceof RefString}});
|
package/core/ref/RefSet.js
CHANGED
|
@@ -1,148 +1 @@
|
|
|
1
|
-
import { Ref }
|
|
2
|
-
import { RefContainer } from "./RefContainer";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a reactive wrapper for a Set of values.
|
|
5
|
-
*
|
|
6
|
-
* @param values - Optional array of initial values for the Set.
|
|
7
|
-
* @returns A new instance of RefSet.
|
|
8
|
-
*/
|
|
9
|
-
export function refSet(values) {
|
|
10
|
-
return new RefSet(values);
|
|
11
|
-
}
|
|
12
|
-
// Enables `instanceof refSet` to work with RefSet instances
|
|
13
|
-
Object.defineProperty(refSet, Symbol.hasInstance, {
|
|
14
|
-
value: function (instance) {
|
|
15
|
-
return !!instance && instance instanceof RefSet;
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* A reactive wrapper around the native Set object.
|
|
20
|
-
* Notifies subscribers when the contents of the Set are mutated.
|
|
21
|
-
*/
|
|
22
|
-
export class RefSet extends Set {
|
|
23
|
-
/**
|
|
24
|
-
* Internal container that manages the reactive value and subscribers.
|
|
25
|
-
*/
|
|
26
|
-
container = new RefContainer(this);
|
|
27
|
-
id;
|
|
28
|
-
/**
|
|
29
|
-
* Constructs a new reactive Set instance.
|
|
30
|
-
*
|
|
31
|
-
* @param values - Optional array of initial values.
|
|
32
|
-
* @param refKey - Optional identifier to register in the global Ref registry.
|
|
33
|
-
*/
|
|
34
|
-
constructor(values) {
|
|
35
|
-
super();
|
|
36
|
-
this.id = this.container.id;
|
|
37
|
-
this.value = new Set(values);
|
|
38
|
-
Ref.set(this.id, this);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Emits a change event to all subscribers for a given mutation.
|
|
42
|
-
*
|
|
43
|
-
* @param propertyName - The mutation name (e.g., "add", "delete", "clear").
|
|
44
|
-
* @param value - The current state of the Set.
|
|
45
|
-
*/
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
emit(propertyName, value) {
|
|
48
|
-
this.container.emitAll(propertyName, value, this.valueOf());
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Subscribes to changes and immediately emits the current Set.
|
|
52
|
-
*/
|
|
53
|
-
subscribe(target, propertyName, onUnsubscribe) {
|
|
54
|
-
return this.container.emit(this.container.subscribe(target, propertyName, onUnsubscribe), this, this.valueOf());
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Subscribes to future changes without emitting the current value.
|
|
58
|
-
*
|
|
59
|
-
* @param target - A callback function to be called on update.
|
|
60
|
-
* @param onUnsubscribe - Optional callback for when unsubscribed.
|
|
61
|
-
* @returns true if subscription was successful.
|
|
62
|
-
*/
|
|
63
|
-
listen(target, onUnsubscribe) {
|
|
64
|
-
return this.container.subscribe(target, onUnsubscribe) !== undefined;
|
|
65
|
-
}
|
|
66
|
-
unsubscribe(targe, propertyName = "") {
|
|
67
|
-
return this.container.unsubscribe(targe, propertyName);
|
|
68
|
-
}
|
|
69
|
-
/** Reactive mutation overrides **/
|
|
70
|
-
/**
|
|
71
|
-
* Adds a new value to the Set and notifies subscribers.
|
|
72
|
-
*
|
|
73
|
-
* @param value - The value to add.
|
|
74
|
-
* @returns The Set instance.
|
|
75
|
-
*/
|
|
76
|
-
add(value) {
|
|
77
|
-
const oldValue = this.valueOf();
|
|
78
|
-
const result = super.add(value);
|
|
79
|
-
this.container.emitAll("add", this, oldValue);
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Removes a value from the Set and notifies subscribers.
|
|
84
|
-
*
|
|
85
|
-
* @param value - The value to remove.
|
|
86
|
-
* @returns True if the value was present and removed.
|
|
87
|
-
*/
|
|
88
|
-
delete(value) {
|
|
89
|
-
const oldValue = this.valueOf();
|
|
90
|
-
const result = super.delete(value);
|
|
91
|
-
this.container.emitAll("delete", this, oldValue);
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Removes all values from the Set and notifies subscribers.
|
|
96
|
-
*/
|
|
97
|
-
clear() {
|
|
98
|
-
const oldValue = this.valueOf();
|
|
99
|
-
super.clear();
|
|
100
|
-
this.container.emitAll("clear", this, oldValue);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns a shallow copy of the current Set state.
|
|
104
|
-
*/
|
|
105
|
-
valueOf() {
|
|
106
|
-
return new Set(Array.from(this));
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Ensures native Set is used in methods like `slice`, `filter`, etc.
|
|
110
|
-
*/
|
|
111
|
-
static get [Symbol.species]() {
|
|
112
|
-
return Set;
|
|
113
|
-
}
|
|
114
|
-
/** Value access and serialization **/
|
|
115
|
-
/**
|
|
116
|
-
* Gets the current Set value.
|
|
117
|
-
*/
|
|
118
|
-
get value() {
|
|
119
|
-
return this.container.value.valueOf();
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Replaces the entire Set with a new Set and notifies subscribers.
|
|
123
|
-
* If the same Set reference is passed, no update is triggered.
|
|
124
|
-
*
|
|
125
|
-
* @param value - A new Set instance to replace the current content.
|
|
126
|
-
*/
|
|
127
|
-
set value(value) {
|
|
128
|
-
if (this === value)
|
|
129
|
-
return;
|
|
130
|
-
super.clear();
|
|
131
|
-
for (const val of value) {
|
|
132
|
-
super.add(val);
|
|
133
|
-
}
|
|
134
|
-
this.emit("value", value);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Serializes the Set to an object with numeric keys for JSON output.
|
|
138
|
-
*/
|
|
139
|
-
toJSON() {
|
|
140
|
-
const obj = {};
|
|
141
|
-
let i = 0;
|
|
142
|
-
for (const v of this.value) {
|
|
143
|
-
obj[i++] = v;
|
|
144
|
-
}
|
|
145
|
-
return obj;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
//# sourceMappingURL=RefSet.js.map
|
|
1
|
+
import{Ref}from".";import{RefContainer}from"./RefContainer";export function refSet(e){return new RefSet(e)}Object.defineProperty(refSet,Symbol.hasInstance,{value:function(e){return!!e&&e instanceof RefSet}});export class RefSet extends Set{container=new RefContainer(this);id;constructor(e){super(),this.id=this.container.id,this.value=new Set(e),Ref.set(this.id,this)}emit(e,t){this.container.emitAll(e,t,this.valueOf())}subscribe(e,t,i){return this.container.emit(this.container.subscribe(e,t,i),this,this.valueOf())}listen(e,t){return void 0!==this.container.subscribe(e,t)}unsubscribe(e,t=""){return this.container.unsubscribe(e,t)}add(e){const t=this.valueOf(),i=super.add(e);return this.container.emitAll("add",this,t),i}delete(e){const t=this.valueOf(),i=super.delete(e);return this.container.emitAll("delete",this,t),i}clear(){const e=this.valueOf();super.clear(),this.container.emitAll("clear",this,e)}valueOf(){return new Set(Array.from(this))}static get[Symbol.species](){return Set}get value(){return this.container.value.valueOf()}set value(e){if(this!==e){super.clear();for(const t of e)super.add(t);this.emit("value",e)}}toJSON(){const e={};let t=0;for(const i of this.value)e[t++]=i;return e}}
|
package/core/ref/RefState.js
CHANGED
|
@@ -1,89 +1 @@
|
|
|
1
|
-
import { Ref }
|
|
2
|
-
export function refState(refKey) {
|
|
3
|
-
return new RefState(refKey);
|
|
4
|
-
}
|
|
5
|
-
Object.defineProperty(refState, Symbol.hasInstance, {
|
|
6
|
-
value: function (instance) {
|
|
7
|
-
return !!instance && instance instanceof RefState;
|
|
8
|
-
},
|
|
9
|
-
});
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
export class RefState {
|
|
12
|
-
refKey;
|
|
13
|
-
#ref;
|
|
14
|
-
#subscribers = [];
|
|
15
|
-
constructor(refKey) {
|
|
16
|
-
this.refKey = refKey;
|
|
17
|
-
this.#ref = Ref.get(refKey);
|
|
18
|
-
if (!this.#ref) {
|
|
19
|
-
Ref.onCreated(refKey, (ref) => {
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
this.#ref = ref;
|
|
22
|
-
for (const subscriber of this.#subscribers) {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
this.#ref?.subscribe(subscriber.target, subscriber.propertyName, subscriber.onUnsubscribe);
|
|
25
|
-
}
|
|
26
|
-
this.#subscribers = undefined;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
get status() {
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
return Ref.getStatus(this.refKey);
|
|
33
|
-
}
|
|
34
|
-
get active() {
|
|
35
|
-
return !!this.#ref;
|
|
36
|
-
}
|
|
37
|
-
get ref() {
|
|
38
|
-
return this.#ref;
|
|
39
|
-
}
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
emit(propertyName, value) {
|
|
42
|
-
if (this.ref) {
|
|
43
|
-
this.ref.value = value;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
subscribe(target, propertyName, onUnsubscribe) {
|
|
47
|
-
if (this.ref) {
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
return this.ref.subscribe(target, propertyName, onUnsubscribe);
|
|
50
|
-
}
|
|
51
|
-
this.#subscribers.push({ target, propertyName, onUnsubscribe });
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
listen(target, onUnsubscribe) {
|
|
55
|
-
return this.subscribe(target, onUnsubscribe);
|
|
56
|
-
}
|
|
57
|
-
unsubscribe(targe, propertyName = "") {
|
|
58
|
-
if (this.ref) {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
return this.ref.unsubscribe(targe, propertyName);
|
|
61
|
-
}
|
|
62
|
-
this.#subscribers = this.#subscribers.filter(subscriber => subscriber.target !== targe && subscriber.propertyName !== propertyName);
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
get value() {
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
return this.ref?.value;
|
|
69
|
-
}
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
set value(value) {
|
|
72
|
-
if (this.ref) {
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
this.ref.value = value;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
valueOf() {
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
return this.ref?.valueOf();
|
|
80
|
-
}
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
toJSON() {
|
|
83
|
-
return this.ref?.toJSON() || {};
|
|
84
|
-
}
|
|
85
|
-
toString() {
|
|
86
|
-
return "this.ref?.toString() || ";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=RefState.js.map
|
|
1
|
+
import{Ref}from".";export function refState(e){return new RefState(e)}Object.defineProperty(refState,Symbol.hasInstance,{value:function(e){return!!e&&e instanceof RefState}});export class RefState{refKey;#e;#r=[];constructor(e){this.refKey=e,this.#e=Ref.get(e),this.#e||Ref.onCreated(e,e=>{this.#e=e;for(const e of this.#r)this.#e?.subscribe(e.target,e.propertyName,e.onUnsubscribe);this.#r=void 0})}get status(){return Ref.getStatus(this.refKey)}get active(){return!!this.#e}get ref(){return this.#e}emit(e,r){this.ref&&(this.ref.value=r)}subscribe(e,r,t){return this.ref?this.ref.subscribe(e,r,t):(this.#r.push({target:e,propertyName:r,onUnsubscribe:t}),!0)}listen(e,r){return this.subscribe(e,r)}unsubscribe(e,r=""){return this.ref?this.ref.unsubscribe(e,r):(this.#r=this.#r.filter(t=>t.target!==e&&t.propertyName!==r),!0)}get value(){return this.ref?.value}set value(e){this.ref&&(this.ref.value=e)}valueOf(){return this.ref?.valueOf()}toJSON(){return this.ref?.toJSON()||{}}toString(){return"this.ref?.toString() || "}}
|