typecomposer 0.1.43 → 0.1.45

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.
Files changed (352) hide show
  1. package/core/components/AlertPanel.d.ts +7 -6
  2. package/core/components/AlertPanel.js +3 -2
  3. package/core/components/AlertPanel.js.map +1 -1
  4. package/core/components/AvatarPanel.d.ts +3 -2
  5. package/core/components/AvatarPanel.js +2 -2
  6. package/core/components/AvatarPanel.js.map +1 -1
  7. package/core/components/BorderPanel.d.ts +3 -2
  8. package/core/components/BorderPanel.js +2 -1
  9. package/core/components/BorderPanel.js.map +1 -1
  10. package/core/components/CardPanel.d.ts +3 -2
  11. package/core/components/CardPanel.js +2 -1
  12. package/core/components/CardPanel.js.map +1 -1
  13. package/core/components/CheckBox.d.ts +4 -2
  14. package/core/components/CheckBox.js +7 -5
  15. package/core/components/CheckBox.js.map +1 -1
  16. package/core/components/ColorPicker.d.ts +3 -2
  17. package/core/components/ColorPicker.js +11 -8
  18. package/core/components/ColorPicker.js.map +1 -1
  19. package/core/components/ContextMenu.d.ts +5 -3
  20. package/core/components/ContextMenu.js +5 -3
  21. package/core/components/ContextMenu.js.map +1 -1
  22. package/core/components/DialogPanel.d.ts +5 -4
  23. package/core/components/DialogPanel.js +8 -8
  24. package/core/components/DialogPanel.js.map +1 -1
  25. package/core/components/DropDown.d.ts +5 -3
  26. package/core/components/DropDown.js +5 -3
  27. package/core/components/DropDown.js.map +1 -1
  28. package/core/components/FlowPanel.d.ts +3 -2
  29. package/core/components/FlowPanel.js +3 -2
  30. package/core/components/FlowPanel.js.map +1 -1
  31. package/core/components/ForEach.d.ts +3 -2
  32. package/core/components/ForEach.js +2 -1
  33. package/core/components/ForEach.js.map +1 -1
  34. package/core/components/GridPanel.d.ts +3 -2
  35. package/core/components/GridPanel.js +2 -1
  36. package/core/components/GridPanel.js.map +1 -1
  37. package/core/components/HBox.d.ts +3 -2
  38. package/core/components/HBox.js +2 -1
  39. package/core/components/HBox.js.map +1 -1
  40. package/core/components/LazyLoading.d.ts +3 -2
  41. package/core/components/LazyLoading.js +3 -2
  42. package/core/components/LazyLoading.js.map +1 -1
  43. package/core/components/ListPanel.d.ts +3 -2
  44. package/core/components/ListPanel.js +2 -1
  45. package/core/components/ListPanel.js.map +1 -1
  46. package/core/components/PopUpButton.d.ts +3 -2
  47. package/core/components/PopUpButton.js +6 -3
  48. package/core/components/PopUpButton.js.map +1 -1
  49. package/core/components/ScrollPanel.d.ts +3 -2
  50. package/core/components/ScrollPanel.js +2 -1
  51. package/core/components/ScrollPanel.js.map +1 -1
  52. package/core/components/SliderPanel.d.ts +3 -2
  53. package/core/components/SliderPanel.js +4 -5
  54. package/core/components/SliderPanel.js.map +1 -1
  55. package/core/components/StackPanel.d.ts +3 -2
  56. package/core/components/StackPanel.js +2 -1
  57. package/core/components/StackPanel.js.map +1 -1
  58. package/core/components/TabItem.d.ts +1 -0
  59. package/core/components/TabItem.js +7 -4
  60. package/core/components/TabItem.js.map +1 -1
  61. package/core/components/TabPanel.d.ts +3 -2
  62. package/core/components/TabPanel.js +2 -1
  63. package/core/components/TabPanel.js.map +1 -1
  64. package/core/components/TablePanel.d.ts +6 -4
  65. package/core/components/TablePanel.js +4 -2
  66. package/core/components/TablePanel.js.map +1 -1
  67. package/core/components/TextEdit.d.ts +1 -0
  68. package/core/components/TextEdit.js +4 -2
  69. package/core/components/TextEdit.js.map +1 -1
  70. package/core/components/TextField.d.ts +1 -0
  71. package/core/components/TextField.js +3 -2
  72. package/core/components/TextField.js.map +1 -1
  73. package/core/components/ToggleButton.d.ts +3 -2
  74. package/core/components/ToggleButton.js +2 -1
  75. package/core/components/ToggleButton.js.map +1 -1
  76. package/core/components/Tooltip.d.ts +3 -2
  77. package/core/components/Tooltip.js +2 -1
  78. package/core/components/Tooltip.js.map +1 -1
  79. package/core/components/VBox.d.ts +3 -2
  80. package/core/components/VBox.js +2 -1
  81. package/core/components/VBox.js.map +1 -1
  82. package/core/components/VirtualScroll copy 2.d.ts +2 -2
  83. package/core/components/VirtualScroll copy 2.js +2 -8
  84. package/core/components/VirtualScroll copy 2.js.map +1 -1
  85. package/core/components/VirtualScroll.d.ts +3 -2
  86. package/core/components/VirtualScroll.js +3 -2
  87. package/core/components/VirtualScroll.js.map +1 -1
  88. package/core/element/AbbreviationElement.d.ts +3 -2
  89. package/core/element/AbbreviationElement.js +2 -3
  90. package/core/element/AbbreviationElement.js.map +1 -1
  91. package/core/element/AnchorElement.d.ts +4 -3
  92. package/core/element/AnchorElement.js +2 -1
  93. package/core/element/AnchorElement.js.map +1 -1
  94. package/core/element/AreaElement.d.ts +3 -2
  95. package/core/element/AreaElement.js +2 -1
  96. package/core/element/AreaElement.js.map +1 -1
  97. package/core/element/ArticleElement.d.ts +3 -2
  98. package/core/element/ArticleElement.js +2 -1
  99. package/core/element/ArticleElement.js.map +1 -1
  100. package/core/element/AudioElement.d.ts +3 -2
  101. package/core/element/AudioElement.js +2 -1
  102. package/core/element/AudioElement.js.map +1 -1
  103. package/core/element/BaseElement.d.ts +3 -2
  104. package/core/element/BaseElement.js +2 -1
  105. package/core/element/BaseElement.js.map +1 -1
  106. package/core/element/BodyElement.d.ts +3 -2
  107. package/core/element/BodyElement.js +2 -1
  108. package/core/element/BodyElement.js.map +1 -1
  109. package/core/element/BoldElement.d.ts +3 -2
  110. package/core/element/BoldElement.js +2 -1
  111. package/core/element/BoldElement.js.map +1 -1
  112. package/core/element/BreakElement.d.ts +3 -2
  113. package/core/element/BreakElement.js +2 -1
  114. package/core/element/BreakElement.js.map +1 -1
  115. package/core/element/ButtonElement.d.ts +3 -2
  116. package/core/element/ButtonElement.js +2 -1
  117. package/core/element/ButtonElement.js.map +1 -1
  118. package/core/element/CanvasElement.d.ts +3 -2
  119. package/core/element/CanvasElement.js +2 -1
  120. package/core/element/CanvasElement.js.map +1 -1
  121. package/core/element/CaptionElement.d.ts +3 -2
  122. package/core/element/CaptionElement.js +2 -1
  123. package/core/element/CaptionElement.js.map +1 -1
  124. package/core/element/CiteElement.d.ts +3 -2
  125. package/core/element/CiteElement.js +2 -1
  126. package/core/element/CiteElement.js.map +1 -1
  127. package/core/element/CodeElement.d.ts +3 -2
  128. package/core/element/CodeElement.js +2 -1
  129. package/core/element/CodeElement.js.map +1 -1
  130. package/core/element/DataListElement.d.ts +3 -2
  131. package/core/element/DataListElement.js +2 -1
  132. package/core/element/DataListElement.js.map +1 -1
  133. package/core/element/DefinitionDescriptionElement.d.ts +3 -2
  134. package/core/element/DefinitionDescriptionElement.js +2 -1
  135. package/core/element/DefinitionDescriptionElement.js.map +1 -1
  136. package/core/element/DefinitionElement.d.ts +3 -2
  137. package/core/element/DefinitionElement.js +2 -1
  138. package/core/element/DefinitionElement.js.map +1 -1
  139. package/core/element/DeletedTextElement.d.ts +3 -2
  140. package/core/element/DeletedTextElement.js +2 -1
  141. package/core/element/DeletedTextElement.js.map +1 -1
  142. package/core/element/DetailsElement.d.ts +3 -2
  143. package/core/element/DetailsElement.js +2 -1
  144. package/core/element/DetailsElement.js.map +1 -1
  145. package/core/element/DialogElement.d.ts +3 -2
  146. package/core/element/DialogElement.js +2 -1
  147. package/core/element/DialogElement.js.map +1 -1
  148. package/core/element/DivElement.d.ts +3 -2
  149. package/core/element/DivElement.js +2 -1
  150. package/core/element/DivElement.js.map +1 -1
  151. package/core/element/EmElement.d.ts +3 -2
  152. package/core/element/EmElement.js +2 -1
  153. package/core/element/EmElement.js.map +1 -1
  154. package/core/element/EmbedElement.d.ts +3 -2
  155. package/core/element/EmbedElement.js +2 -1
  156. package/core/element/EmbedElement.js.map +1 -1
  157. package/core/element/FieldSetElement.d.ts +3 -2
  158. package/core/element/FieldSetElement.js +2 -1
  159. package/core/element/FieldSetElement.js.map +1 -1
  160. package/core/element/FooterElement.d.ts +3 -2
  161. package/core/element/FooterElement.js +2 -1
  162. package/core/element/FooterElement.js.map +1 -1
  163. package/core/element/FormElement.d.ts +3 -2
  164. package/core/element/FormElement.js +2 -1
  165. package/core/element/FormElement.js.map +1 -1
  166. package/core/element/Fragment.d.ts +0 -1
  167. package/core/element/Fragment.js +6 -50
  168. package/core/element/Fragment.js.map +1 -1
  169. package/core/element/H1Element.d.ts +3 -2
  170. package/core/element/H1Element.js +2 -1
  171. package/core/element/H1Element.js.map +1 -1
  172. package/core/element/H2Element.d.ts +3 -2
  173. package/core/element/H2Element.js +2 -1
  174. package/core/element/H2Element.js.map +1 -1
  175. package/core/element/H3Element.d.ts +3 -2
  176. package/core/element/H3Element.js +2 -1
  177. package/core/element/H3Element.js.map +1 -1
  178. package/core/element/H4Element.d.ts +3 -2
  179. package/core/element/H4Element.js +2 -1
  180. package/core/element/H4Element.js.map +1 -1
  181. package/core/element/H5Element.d.ts +3 -2
  182. package/core/element/H5Element.js +2 -1
  183. package/core/element/H5Element.js.map +1 -1
  184. package/core/element/H6Element.d.ts +3 -2
  185. package/core/element/H6Element.js +2 -1
  186. package/core/element/H6Element.js.map +1 -1
  187. package/core/element/HeadElement.d.ts +3 -2
  188. package/core/element/HeadElement.js +2 -1
  189. package/core/element/HeadElement.js.map +1 -1
  190. package/core/element/HeaderElement.d.ts +3 -2
  191. package/core/element/HeaderElement.js +2 -1
  192. package/core/element/HeaderElement.js.map +1 -1
  193. package/core/element/HorizontalRuleElement.d.ts +3 -2
  194. package/core/element/HorizontalRuleElement.js +2 -1
  195. package/core/element/HorizontalRuleElement.js.map +1 -1
  196. package/core/element/HtmlElement.d.ts +3 -2
  197. package/core/element/HtmlElement.js +2 -1
  198. package/core/element/HtmlElement.js.map +1 -1
  199. package/core/element/IFrameElement.d.ts +3 -2
  200. package/core/element/IFrameElement.js +2 -1
  201. package/core/element/IFrameElement.js.map +1 -1
  202. package/core/element/ILayout.d.ts +3 -2
  203. package/core/element/ILayout.js +2 -1
  204. package/core/element/ILayout.js.map +1 -1
  205. package/core/element/IconElement.d.ts +3 -2
  206. package/core/element/IconElement.js +2 -1
  207. package/core/element/IconElement.js.map +1 -1
  208. package/core/element/IdiomaticElement.d.ts +1 -0
  209. package/core/element/IdiomaticElement.js +2 -1
  210. package/core/element/IdiomaticElement.js.map +1 -1
  211. package/core/element/ImageElement.d.ts +3 -2
  212. package/core/element/ImageElement.js +2 -1
  213. package/core/element/ImageElement.js.map +1 -1
  214. package/core/element/InputElement.d.ts +3 -2
  215. package/core/element/InputElement.js +2 -1
  216. package/core/element/InputElement.js.map +1 -1
  217. package/core/element/LabelElement.d.ts +3 -2
  218. package/core/element/LabelElement.js +2 -1
  219. package/core/element/LabelElement.js.map +1 -1
  220. package/core/element/LegendElement.d.ts +3 -2
  221. package/core/element/LegendElement.js +2 -1
  222. package/core/element/LegendElement.js.map +1 -1
  223. package/core/element/ListItemElement.d.ts +3 -2
  224. package/core/element/ListItemElement.js +2 -1
  225. package/core/element/ListItemElement.js.map +1 -1
  226. package/core/element/MainElement.d.ts +3 -2
  227. package/core/element/MainElement.js +2 -1
  228. package/core/element/MainElement.js.map +1 -1
  229. package/core/element/NavElement.d.ts +3 -2
  230. package/core/element/NavElement.js +2 -1
  231. package/core/element/NavElement.js.map +1 -1
  232. package/core/element/OrderedListElement.d.ts +3 -2
  233. package/core/element/OrderedListElement.js +2 -1
  234. package/core/element/OrderedListElement.js.map +1 -1
  235. package/core/element/ParagraphElement.d.ts +3 -2
  236. package/core/element/ParagraphElement.js +2 -1
  237. package/core/element/ParagraphElement.js.map +1 -1
  238. package/core/element/PreElement.d.ts +3 -2
  239. package/core/element/PreElement.js +2 -1
  240. package/core/element/PreElement.js.map +1 -1
  241. package/core/element/SectionElement.d.ts +3 -2
  242. package/core/element/SectionElement.js +2 -1
  243. package/core/element/SectionElement.js.map +1 -1
  244. package/core/element/SelectElement.d.ts +3 -2
  245. package/core/element/SelectElement.js +2 -1
  246. package/core/element/SelectElement.js.map +1 -1
  247. package/core/element/SourceElement.d.ts +3 -2
  248. package/core/element/SourceElement.js +2 -1
  249. package/core/element/SourceElement.js.map +1 -1
  250. package/core/element/SpanElement.d.ts +3 -2
  251. package/core/element/SpanElement.js +2 -1
  252. package/core/element/SpanElement.js.map +1 -1
  253. package/core/element/StrongElement.d.ts +3 -2
  254. package/core/element/StrongElement.js +2 -1
  255. package/core/element/StrongElement.js.map +1 -1
  256. package/core/element/StyleElement.d.ts +3 -2
  257. package/core/element/StyleElement.js +2 -1
  258. package/core/element/StyleElement.js.map +1 -1
  259. package/core/element/SummaryElement.d.ts +3 -2
  260. package/core/element/SummaryElement.js +2 -1
  261. package/core/element/SummaryElement.js.map +1 -1
  262. package/core/element/SvgElement.d.ts +4 -3
  263. package/core/element/SvgElement.js +1 -0
  264. package/core/element/SvgElement.js.map +1 -1
  265. package/core/element/TableBodyElement.d.ts +3 -2
  266. package/core/element/TableBodyElement.js +2 -1
  267. package/core/element/TableBodyElement.js.map +1 -1
  268. package/core/element/TableCellElement.d.ts +3 -2
  269. package/core/element/TableCellElement.js +2 -1
  270. package/core/element/TableCellElement.js.map +1 -1
  271. package/core/element/TableColElement.d.ts +3 -2
  272. package/core/element/TableColElement.js +2 -1
  273. package/core/element/TableColElement.js.map +1 -1
  274. package/core/element/TableColGroupElement.d.ts +3 -2
  275. package/core/element/TableColGroupElement.js +2 -1
  276. package/core/element/TableColGroupElement.js.map +1 -1
  277. package/core/element/TableElement.d.ts +3 -2
  278. package/core/element/TableElement.js +2 -1
  279. package/core/element/TableElement.js.map +1 -1
  280. package/core/element/TableFootElement.d.ts +3 -2
  281. package/core/element/TableFootElement.js +2 -1
  282. package/core/element/TableFootElement.js.map +1 -1
  283. package/core/element/TableFootRowElement.d.ts +3 -2
  284. package/core/element/TableFootRowElement.js +2 -1
  285. package/core/element/TableFootRowElement.js.map +1 -1
  286. package/core/element/TableHeadCellElement.d.ts +3 -2
  287. package/core/element/TableHeadCellElement.js +2 -1
  288. package/core/element/TableHeadCellElement.js.map +1 -1
  289. package/core/element/TableHeadElement.d.ts +3 -2
  290. package/core/element/TableHeadElement.js +2 -1
  291. package/core/element/TableHeadElement.js.map +1 -1
  292. package/core/element/TableHeadRowElement.d.ts +3 -2
  293. package/core/element/TableHeadRowElement.js +2 -1
  294. package/core/element/TableHeadRowElement.js.map +1 -1
  295. package/core/element/TableRowElement.d.ts +3 -2
  296. package/core/element/TableRowElement.js +2 -1
  297. package/core/element/TableRowElement.js.map +1 -1
  298. package/core/element/TextAreaElement.d.ts +3 -2
  299. package/core/element/TextAreaElement.js +2 -1
  300. package/core/element/TextAreaElement.js.map +1 -1
  301. package/core/element/UListElement.d.ts +3 -2
  302. package/core/element/UListElement.js +2 -1
  303. package/core/element/UListElement.js.map +1 -1
  304. package/core/element/VideoElement.d.ts +3 -2
  305. package/core/element/VideoElement.js +2 -1
  306. package/core/element/VideoElement.js.map +1 -1
  307. package/core/ref/Computed.d.ts +3 -0
  308. package/core/ref/Computed.js +75 -0
  309. package/core/ref/Computed.js.map +1 -0
  310. package/core/ref/RefBoolean.d.ts +72 -7
  311. package/core/ref/RefBoolean.js +68 -7
  312. package/core/ref/RefBoolean.js.map +1 -1
  313. package/core/ref/RefContainer.d.ts +5 -2
  314. package/core/ref/RefContainer.js +14 -6
  315. package/core/ref/RefContainer.js.map +1 -1
  316. package/core/ref/RefList.d.ts +84 -16
  317. package/core/ref/RefList.js +112 -32
  318. package/core/ref/RefList.js.map +1 -1
  319. package/core/ref/RefMap.d.ts +82 -7
  320. package/core/ref/RefMap.js +88 -10
  321. package/core/ref/RefMap.js.map +1 -1
  322. package/core/ref/RefNumber.d.ts +103 -15
  323. package/core/ref/RefNumber.js +117 -29
  324. package/core/ref/RefNumber.js.map +1 -1
  325. package/core/ref/RefObject copy.d.ts +124 -0
  326. package/core/ref/RefObject copy.js +271 -0
  327. package/core/ref/RefObject copy.js.map +1 -0
  328. package/core/ref/RefObject.d.ts +94 -8
  329. package/core/ref/RefObject.js +56 -51
  330. package/core/ref/RefObject.js.map +1 -1
  331. package/core/ref/RefSet.d.ts +78 -4
  332. package/core/ref/RefSet.js +86 -10
  333. package/core/ref/RefSet.js.map +1 -1
  334. package/core/ref/RefState.d.ts +1 -0
  335. package/core/ref/RefState.js +3 -0
  336. package/core/ref/RefState.js.map +1 -1
  337. package/core/ref/RefString.d.ts +114 -41
  338. package/core/ref/RefString.js +141 -164
  339. package/core/ref/RefString.js.map +1 -1
  340. package/core/ref/index.d.ts +1 -1
  341. package/core/ref/index.js +1 -2
  342. package/core/ref/index.js.map +1 -1
  343. package/core/router/RouteView.d.ts +3 -2
  344. package/core/router/RouteView.js +2 -1
  345. package/core/router/RouteView.js.map +1 -1
  346. package/core/styles/index.d.ts +2 -2
  347. package/core/styles/index.js.map +1 -1
  348. package/global/index.d.ts +5 -4
  349. package/global/index.js +395 -225
  350. package/global/index.js.map +1 -1
  351. package/package.json +3 -3
  352. package/typings/index.d.ts +11 -2
@@ -1,25 +1,100 @@
1
1
  import { ref } from ".";
2
- import { RefContainer } from "./RefContainer";
2
+ /**
3
+ * Creates a new reactive map from the given entries.
4
+ *
5
+ * @param entries - Optional initial key-value pairs.
6
+ * @returns A reactive RefMap instance.
7
+ */
3
8
  export declare function refMap<K, V>(entries?: readonly (readonly [K, V])[] | null): RefMap<K, V>;
9
+ /**
10
+ * A type representing either a native Map or a reactive RefMap.
11
+ */
4
12
  export type refMap<K, V> = Map<K, V> | RefMap<K, V>;
13
+ /**
14
+ * A reactive wrapper around the native Map object.
15
+ * Supports automatic reactivity and subscription to changes.
16
+ */
5
17
  export declare class RefMap<K, V> extends Map<K, V> implements ref<Map<K, V>> {
6
- readonly container: RefContainer;
7
- readonly refKey: string;
8
- constructor(entries?: readonly (readonly [K, V])[] | null, refKey?: string);
18
+ /**
19
+ * Internal container managing subscribers and value propagation.
20
+ */
21
+ private readonly container;
22
+ readonly id: string;
23
+ /**
24
+ * Constructs a new reactive map instance.
25
+ *
26
+ * @param entries - Optional initial entries to populate the map.
27
+ * @param refKey - Optional registration key for the Ref registry.
28
+ */
29
+ constructor(entries?: readonly (readonly [K, V])[] | null);
30
+ /**
31
+ * Emits a change event to all subscribers for a given mutation type.
32
+ *
33
+ * @param propertyName - The kind of mutation (e.g., "set", "clear").
34
+ * @param value - The current state of the map.
35
+ */
9
36
  private emit;
10
- subscribe(target: (arg: Map<K, V>) => void): boolean;
11
- subscribe(target: (arg: Map<K, V>) => void, onUnsubscribe: Function): boolean;
37
+ /** Reactive subscription methods **/
38
+ subscribe(target: (value: Map<K, V>, oldValue: Map<K, V>) => void): boolean;
39
+ subscribe(target: (value: Map<K, V>, oldValue: Map<K, V>) => void, onUnsubscribe: Function): boolean;
12
40
  subscribe(target: object, propertyName: string | symbol): boolean;
13
41
  subscribe(target: object, propertyName: string | symbol, onUnsubscribe: Function): boolean;
14
- subscribe(target: object | ((arg: Map<K, V>) => void), propertyName: string | symbol | Function, onUnsubscribe?: Function): boolean;
42
+ subscribe(target: object | ((value: Map<K, V>, oldValue: Map<K, V>) => void), propertyName: string | symbol | Function, onUnsubscribe?: Function): boolean;
43
+ /**
44
+ * Subscribes to future changes without emitting the current value.
45
+ *
46
+ * @param target - Function to call on change.
47
+ * @param onUnsubscribe - Optional callback to invoke on unsubscription.
48
+ */
49
+ listen(target: (value: Map<K, V>, oldValue: Map<K, V>) => void, onUnsubscribe?: Function): boolean;
50
+ /**
51
+ * Unsubscribes a function or object-property pair from receiving updates.
52
+ */
15
53
  unsubscribe(target: (arg: Map<K, V>) => void): boolean;
16
54
  unsubscribe(targe: object, propertyName: string | symbol): boolean;
55
+ /** Reactive mutation overrides **/
56
+ /**
57
+ * Sets a value for a given key and notifies subscribers.
58
+ *
59
+ * @param key - The key to insert or update.
60
+ * @param value - The value to associate with the key.
61
+ * @returns The map itself.
62
+ */
17
63
  set(key: K, value: V): this;
64
+ /**
65
+ * Deletes a key-value pair and notifies subscribers.
66
+ *
67
+ * @param key - The key to delete.
68
+ * @returns True if the key existed and was removed.
69
+ */
18
70
  delete(key: K): boolean;
71
+ /**
72
+ * Clears all entries from the map and notifies subscribers.
73
+ */
19
74
  clear(): void;
75
+ /**
76
+ * Returns a shallow copy of the current map state.
77
+ */
20
78
  valueOf(): Map<K, V>;
79
+ /**
80
+ * Ensures native `Map` is returned when using `Map` methods that create new instances.
81
+ */
21
82
  static get [Symbol.species](): MapConstructor;
83
+ /**
84
+ * Gets the current value of the reactive map.
85
+ * Returns a shallow copy to prevent unintended mutation.
86
+ */
22
87
  get value(): Map<K, V>;
88
+ /**
89
+ * Sets the entire contents of the map to match the given Map instance.
90
+ * If the same reference is passed, no update is triggered.
91
+ *
92
+ * @param value - A new Map to replace the current contents.
93
+ */
23
94
  set value(value: Map<K, V>);
95
+ /**
96
+ * Serializes the map to a plain JavaScript object for JSON output.
97
+ * Note: keys are converted to string.
98
+ */
24
99
  toJSON(): any;
25
100
  }
@@ -1,56 +1,130 @@
1
1
  import { Ref } from ".";
2
2
  import { RefContainer } from "./RefContainer";
3
+ /**
4
+ * Creates a new reactive map from the given entries.
5
+ *
6
+ * @param entries - Optional initial key-value pairs.
7
+ * @returns A reactive RefMap instance.
8
+ */
3
9
  export function refMap(entries) {
4
10
  return new RefMap(entries);
5
11
  }
12
+ // Enables `instanceof refMap` to work correctly
6
13
  Object.defineProperty(refMap, Symbol.hasInstance, {
7
14
  value: function (instance) {
8
15
  return !!instance && instance instanceof RefMap;
9
16
  },
10
17
  });
11
- // @ts-ignore
18
+ /**
19
+ * A reactive wrapper around the native Map object.
20
+ * Supports automatic reactivity and subscription to changes.
21
+ */
12
22
  export class RefMap extends Map {
23
+ /**
24
+ * Internal container managing subscribers and value propagation.
25
+ */
13
26
  container = new RefContainer(this);
14
- refKey;
15
- constructor(entries, refKey) {
27
+ id;
28
+ /**
29
+ * Constructs a new reactive map instance.
30
+ *
31
+ * @param entries - Optional initial entries to populate the map.
32
+ * @param refKey - Optional registration key for the Ref registry.
33
+ */
34
+ constructor(entries) {
16
35
  super();
17
- this.refKey = refKey;
18
- refKey && Ref.set(refKey, this);
36
+ this.id = this.container.id;
37
+ Ref.set(this.id, this);
19
38
  this.value = new Map(entries);
20
39
  }
40
+ /**
41
+ * Emits a change event to all subscribers for a given mutation type.
42
+ *
43
+ * @param propertyName - The kind of mutation (e.g., "set", "clear").
44
+ * @param value - The current state of the map.
45
+ */
21
46
  // @ts-ignore
22
47
  emit(propertyName, value) {
23
- this.container.emitAll(propertyName, value);
48
+ const oldValue = this.valueOf();
49
+ this.container.emitAll(propertyName, value, oldValue);
24
50
  }
51
+ /**
52
+ * Subscribes to changes and immediately emits the current map value.
53
+ */
25
54
  subscribe(target, propertyName, onUnsubscribe) {
26
- return this.container.emit(this.container.subscribe(target, propertyName, onUnsubscribe), this);
55
+ return this.container.emit(this.container.subscribe(target, propertyName, onUnsubscribe), this, this.valueOf());
56
+ }
57
+ /**
58
+ * Subscribes to future changes without emitting the current value.
59
+ *
60
+ * @param target - Function to call on change.
61
+ * @param onUnsubscribe - Optional callback to invoke on unsubscription.
62
+ */
63
+ listen(target, onUnsubscribe) {
64
+ return this.container.subscribe(target, onUnsubscribe) !== undefined;
27
65
  }
28
66
  unsubscribe(targe, propertyName = "") {
29
67
  return this.container.unsubscribe(targe, propertyName);
30
68
  }
69
+ /** Reactive mutation overrides **/
70
+ /**
71
+ * Sets a value for a given key and notifies subscribers.
72
+ *
73
+ * @param key - The key to insert or update.
74
+ * @param value - The value to associate with the key.
75
+ * @returns The map itself.
76
+ */
31
77
  set(key, value) {
78
+ const oldValue = this.valueOf();
32
79
  const result = super.set(key, value);
33
- this.container.emitAll("set", this);
80
+ this.container.emitAll("set", this, oldValue);
34
81
  return result;
35
82
  }
83
+ /**
84
+ * Deletes a key-value pair and notifies subscribers.
85
+ *
86
+ * @param key - The key to delete.
87
+ * @returns True if the key existed and was removed.
88
+ */
36
89
  delete(key) {
90
+ const oldValue = this.valueOf();
37
91
  const result = super.delete(key);
38
- this.container.emitAll("delete", this);
92
+ this.container.emitAll("delete", this, oldValue);
39
93
  return result;
40
94
  }
95
+ /**
96
+ * Clears all entries from the map and notifies subscribers.
97
+ */
41
98
  clear() {
99
+ const oldValue = this.valueOf();
42
100
  super.clear();
43
- this.container.emitAll("clear", this);
101
+ this.container.emitAll("clear", this, oldValue);
44
102
  }
103
+ /**
104
+ * Returns a shallow copy of the current map state.
105
+ */
45
106
  valueOf() {
46
107
  return new Map(Array.from(this));
47
108
  }
109
+ /**
110
+ * Ensures native `Map` is returned when using `Map` methods that create new instances.
111
+ */
48
112
  static get [Symbol.species]() {
49
113
  return Map;
50
114
  }
115
+ /**
116
+ * Gets the current value of the reactive map.
117
+ * Returns a shallow copy to prevent unintended mutation.
118
+ */
51
119
  get value() {
52
120
  return this.container.value.valueOf();
53
121
  }
122
+ /**
123
+ * Sets the entire contents of the map to match the given Map instance.
124
+ * If the same reference is passed, no update is triggered.
125
+ *
126
+ * @param value - A new Map to replace the current contents.
127
+ */
54
128
  set value(value) {
55
129
  if (this === value)
56
130
  return;
@@ -60,6 +134,10 @@ export class RefMap extends Map {
60
134
  }
61
135
  this.emit("value", value);
62
136
  }
137
+ /**
138
+ * Serializes the map to a plain JavaScript object for JSON output.
139
+ * Note: keys are converted to string.
140
+ */
63
141
  toJSON() {
64
142
  const obj = {};
65
143
  for (const [k, v] of this.value) {
@@ -1 +1 @@
1
- {"version":3,"file":"RefMap.js","sourceRoot":"","sources":["../../../src/core/ref/RefMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAO,MAAM,GAAG,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,MAAM,CAAO,OAA6C;IACxE,OAAO,IAAI,MAAM,CAAO,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;IAChD,KAAK,EAAE,UAAU,QAAa;QAC5B,OAAO,CAAC,CAAC,QAAQ,IAAI,QAAQ,YAAY,MAAM,CAAC;IAClD,CAAC;CACF,CAAC,CAAC;AAGH,aAAa;AACb,MAAM,OAAO,MAAa,SAAQ,GAAS;IAChC,SAAS,GAAiB,IAAI,YAAY,CAAC,IAAI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;;;;OAKG;IACH,IAAI,KAAK,CAAC,KAAgB;QACxB,IAAI,IAAI,KAAK,KAAK;YAAE,OAAO;QAC3B,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC;YAC/B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,MAAM,GAAG,GAAQ,EAAE,CAAC;QACpB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -1,30 +1,118 @@
1
1
  import { ref } from ".";
2
- import { RefContainer } from "./RefContainer";
2
+ /**
3
+ * Creates a reactive wrapper for a numeric value.
4
+ *
5
+ * @param value - The initial number value.
6
+ * @returns A new instance of RefNumber.
7
+ */
3
8
  export declare function refNumber(value: number): RefNumber;
9
+ /**
10
+ * A union type representing either a primitive number or a reactive RefNumber.
11
+ */
4
12
  export type refNumber = number | RefNumber;
13
+ /**
14
+ * A reactive wrapper for numbers that behaves like a Number object.
15
+ * Allows subscriptions to value changes and integrates with primitive operations.
16
+ */
5
17
  export declare class RefNumber implements Number, ref<number> {
6
- readonly container: RefContainer;
7
- readonly refKey: string;
8
- constructor(value: number, refKey?: string);
9
- toFixed(fractionDigits?: number): string;
10
- toExponential(fractionDigits?: number): string;
11
- toPrecision(precision?: number): string;
12
- valueOf(): number;
13
- toLocaleString(locales?: string, options?: Intl.NumberFormatOptions): string;
18
+ /**
19
+ * The container holding the internal value and managing subscriptions.
20
+ */
21
+ private readonly container;
22
+ readonly id: string;
23
+ /**
24
+ * Constructs a new reactive number wrapper.
25
+ *
26
+ * @param value - The initial number value.
27
+ */
28
+ constructor(value: number);
29
+ /**
30
+ * Emits a change notification if the value has changed.
31
+ *
32
+ * @param propertyName - The name of the property being updated (usually "value").
33
+ * @param value - The new number value to assign.
34
+ */
14
35
  private emit;
15
- subscribe(target: (arg: number) => void): boolean;
16
- subscribe(target: (arg: number) => void, onUnsubscribe: Function): boolean;
36
+ /** Reactive subscription methods **/
37
+ subscribe(target: (value: number, oldValue: number) => void): boolean;
38
+ subscribe(target: (value: number, oldValue: number) => void, onUnsubscribe: Function): boolean;
17
39
  subscribe(target: object, propertyName: string | symbol): boolean;
18
40
  subscribe(target: object, propertyName: string | symbol, onUnsubscribe: Function): boolean;
19
- subscribe(target: object | ((arg: number) => void), propertyName: string | symbol | Function, onUnsubscribe?: Function): boolean;
41
+ subscribe(target: object | ((value: number, oldValue: number) => void), propertyName: string | symbol | Function, onUnsubscribe?: Function): boolean;
42
+ /**
43
+ * Subscribes to future value changes without emitting the current number.
44
+ *
45
+ * @param target - A function to be called on future updates.
46
+ * @param onUnsubscribe - Optional callback to be called upon unsubscription.
47
+ * @returns true if successfully subscribed.
48
+ */
49
+ listen(target: (value: number, oldValue: number) => void, onUnsubscribe?: Function): boolean;
50
+ /**
51
+ * Unsubscribes a function or object property from receiving value updates.
52
+ */
20
53
  unsubscribe(target: (arg: number) => void): boolean;
21
54
  unsubscribe(targe: object, propertyName: string | symbol): boolean;
22
- [Symbol.toPrimitive](hint: string): number;
23
- static get [Symbol.species](): NumberConstructor;
55
+ /** Value access and primitives **/
56
+ /**
57
+ * Gets the current number value.
58
+ */
24
59
  get value(): number;
60
+ /**
61
+ * Sets a new number value and notifies subscribers if it changed.
62
+ *
63
+ * @param value - The new number to set.
64
+ */
25
65
  set value(value: number);
66
+ /**
67
+ * Returns the primitive number value.
68
+ */
69
+ valueOf(): number;
70
+ /**
71
+ * Converts the value to a string using an optional radix.
72
+ *
73
+ * @param radix - An integer between 2 and 36 specifying the base.
74
+ */
75
+ toString(radix?: number): string;
76
+ /**
77
+ * Converts the value to fixed-point notation.
78
+ *
79
+ * @param fractionDigits - Number of digits after the decimal point.
80
+ */
81
+ toFixed(fractionDigits?: number): string;
82
+ /**
83
+ * Converts the value to exponential notation.
84
+ *
85
+ * @param fractionDigits - Number of digits after the decimal point.
86
+ */
87
+ toExponential(fractionDigits?: number): string;
88
+ /**
89
+ * Formats the number to a specified precision.
90
+ *
91
+ * @param precision - Total number of significant digits.
92
+ */
93
+ toPrecision(precision?: number): string;
94
+ /**
95
+ * Formats the number according to locale-specific rules.
96
+ *
97
+ * @param locales - A locale string or array of locale strings.
98
+ * @param options - Formatting options.
99
+ */
100
+ toLocaleString(locales?: string, options?: Intl.NumberFormatOptions): string;
101
+ /**
102
+ * Supports automatic type coercion to a number in JS expressions.
103
+ *
104
+ * @param hint - Either "number", "string", or "default".
105
+ */
106
+ [Symbol.toPrimitive](hint: string): number;
107
+ /**
108
+ * Identifies this class as a subtype of `Number`.
109
+ */
110
+ static get [Symbol.species](): NumberConstructor;
111
+ /**
112
+ * Serializes the current value for JSON output.
113
+ * If this instance is the root ref, emits the raw value, otherwise wraps it.
114
+ */
26
115
  toJSON(): number | {
27
116
  value: number;
28
117
  };
29
- toString(radix?: number): string;
30
118
  }
@@ -1,69 +1,157 @@
1
1
  import { Ref } from ".";
2
2
  import { RefContainer } from "./RefContainer";
3
+ /**
4
+ * Creates a reactive wrapper for a numeric value.
5
+ *
6
+ * @param value - The initial number value.
7
+ * @returns A new instance of RefNumber.
8
+ */
3
9
  export function refNumber(value) {
4
10
  return new RefNumber(value);
5
11
  }
12
+ // Enables `instanceof refNumber` to return true for RefNumber instances
6
13
  Object.defineProperty(refNumber, Symbol.hasInstance, {
7
14
  value: function (instance) {
8
15
  return !!instance && instance instanceof RefNumber;
9
16
  },
10
17
  });
11
- // @ts-ignore
18
+ /**
19
+ * A reactive wrapper for numbers that behaves like a Number object.
20
+ * Allows subscriptions to value changes and integrates with primitive operations.
21
+ */
12
22
  export class RefNumber {
23
+ /**
24
+ * The container holding the internal value and managing subscriptions.
25
+ */
13
26
  container;
14
- refKey;
15
- constructor(value, refKey) {
16
- this.refKey = refKey;
27
+ id;
28
+ /**
29
+ * Constructs a new reactive number wrapper.
30
+ *
31
+ * @param value - The initial number value.
32
+ */
33
+ constructor(value) {
17
34
  this.container = new RefContainer(value);
18
- refKey && Ref.set(refKey, this);
35
+ this.id = this.container.id;
36
+ Ref.set(this.id, this);
19
37
  }
38
+ /**
39
+ * Emits a change notification if the value has changed.
40
+ *
41
+ * @param propertyName - The name of the property being updated (usually "value").
42
+ * @param value - The new number value to assign.
43
+ */
44
+ // @ts-ignore
45
+ emit(propertyName, value) {
46
+ if (this.value === value.valueOf())
47
+ return;
48
+ const oldValue = this.valueOf();
49
+ this.container.emitAll(propertyName, (this.container.value = value.valueOf()), oldValue);
50
+ }
51
+ /**
52
+ * Subscribes to value changes and immediately emits the current number.
53
+ */
54
+ subscribe(target, propertyName, onUnsubscribe) {
55
+ return this.container.emit(this.container.subscribe(target, propertyName, onUnsubscribe), this.value, this.valueOf());
56
+ }
57
+ /**
58
+ * Subscribes to future value changes without emitting the current number.
59
+ *
60
+ * @param target - A function to be called on future updates.
61
+ * @param onUnsubscribe - Optional callback to be called upon unsubscription.
62
+ * @returns true if successfully subscribed.
63
+ */
64
+ listen(target, onUnsubscribe) {
65
+ return this.container.subscribe(target, onUnsubscribe) !== undefined;
66
+ }
67
+ unsubscribe(targe, propertyName = "") {
68
+ return this.container.unsubscribe(targe, propertyName);
69
+ }
70
+ /** Value access and primitives **/
71
+ /**
72
+ * Gets the current number value.
73
+ */
74
+ get value() {
75
+ return this.container.value;
76
+ }
77
+ /**
78
+ * Sets a new number value and notifies subscribers if it changed.
79
+ *
80
+ * @param value - The new number to set.
81
+ */
82
+ set value(value) {
83
+ this.emit("value", value);
84
+ }
85
+ /**
86
+ * Returns the primitive number value.
87
+ */
88
+ valueOf() {
89
+ return this.value.valueOf();
90
+ }
91
+ /**
92
+ * Converts the value to a string using an optional radix.
93
+ *
94
+ * @param radix - An integer between 2 and 36 specifying the base.
95
+ */
96
+ toString(radix) {
97
+ return this.value.toString(radix);
98
+ }
99
+ /**
100
+ * Converts the value to fixed-point notation.
101
+ *
102
+ * @param fractionDigits - Number of digits after the decimal point.
103
+ */
20
104
  toFixed(fractionDigits) {
21
105
  return this.value.toFixed(fractionDigits);
22
106
  }
107
+ /**
108
+ * Converts the value to exponential notation.
109
+ *
110
+ * @param fractionDigits - Number of digits after the decimal point.
111
+ */
23
112
  toExponential(fractionDigits) {
24
113
  return this.value.toExponential(fractionDigits);
25
114
  }
115
+ /**
116
+ * Formats the number to a specified precision.
117
+ *
118
+ * @param precision - Total number of significant digits.
119
+ */
26
120
  toPrecision(precision) {
27
121
  return this.value.toPrecision(precision);
28
122
  }
29
- valueOf() {
30
- return this.value.valueOf();
31
- }
123
+ /**
124
+ * Formats the number according to locale-specific rules.
125
+ *
126
+ * @param locales - A locale string or array of locale strings.
127
+ * @param options - Formatting options.
128
+ */
32
129
  toLocaleString(locales, options) {
33
130
  return this.value.toLocaleString(locales, options);
34
131
  }
35
- // @ts-ignore
36
- emit(propertyName, value) {
37
- if (this.value === value.valueOf())
38
- return;
39
- this.container.emitAll(propertyName, (this.container.value = value.valueOf()));
40
- }
41
- subscribe(target, propertyName, onUnsubscribe) {
42
- return this.container.emit(this.container.subscribe(target, propertyName, onUnsubscribe), this.value);
43
- }
44
- unsubscribe(targe, propertyName = "") {
45
- return this.container.unsubscribe(targe, propertyName);
46
- }
132
+ /**
133
+ * Supports automatic type coercion to a number in JS expressions.
134
+ *
135
+ * @param hint - Either "number", "string", or "default".
136
+ */
47
137
  [Symbol.toPrimitive](hint) {
48
138
  if (hint === "number" || hint === "default") {
49
139
  return this.value;
50
140
  }
51
141
  return this.valueOf();
52
142
  }
143
+ /**
144
+ * Identifies this class as a subtype of `Number`.
145
+ */
53
146
  static get [Symbol.species]() {
54
147
  return Number;
55
148
  }
56
- get value() {
57
- return this.container.value;
58
- }
59
- set value(value) {
60
- this.emit("value", value);
61
- }
149
+ /**
150
+ * Serializes the current value for JSON output.
151
+ * If this instance is the root ref, emits the raw value, otherwise wraps it.
152
+ */
62
153
  toJSON() {
63
154
  return this.container.root ? this.value : { value: this.value };
64
155
  }
65
- toString(radix) {
66
- return this.value.toString(radix);
67
- }
68
156
  }
69
157
  //# sourceMappingURL=RefNumber.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RefNumber.js","sourceRoot":"","sources":["../../../src/core/ref/RefNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAO,MAAM,GAAG,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE;IACnD,KAAK,EAAE,UAAU,QAAa;QAC5B,OAAO,CAAC,CAAC,QAAQ,IAAI,QAAQ,YAAY,SAAS,CAAC;IACrD,CAAC;CACF,CAAC,CAAC;AAGH,aAAa;AACb,MAAM,OAAO,SAAS;IACX,SAAS,CAAe;IACxB,MAAM,CAAS;IAExB,YAAY,KAAa,EAAE,MAAe;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,IAAW,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,cAAuB;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC5C,CAAC;IACD,aAAa,CAAC,cAAuB;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAA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