@rainlanguage/ui-components 0.0.1-alpha.24 → 0.0.1-alpha.241

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 (299) hide show
  1. package/README.md +14 -6
  2. package/dist/__fixtures__/settings.yaml +123 -0
  3. package/dist/__mocks__/CodeMirrorRainlang.svelte +4 -0
  4. package/dist/__mocks__/CodeMirrorRainlang.svelte.d.ts +18 -0
  5. package/dist/__mocks__/MockCodeMirrorEditor.svelte +17 -0
  6. package/dist/__mocks__/MockCodeMirrorEditor.svelte.d.ts +21 -0
  7. package/dist/__mocks__/MockComponent.js +1 -1
  8. package/dist/__mocks__/MockComponent.svelte +10 -2
  9. package/dist/__mocks__/MockComponent.svelte.d.ts +4 -1
  10. package/dist/__mocks__/mockWeb3Config.d.ts +1 -1
  11. package/dist/__mocks__/mockWeb3Config.js +10 -7
  12. package/dist/__mocks__/queries.js +9 -9
  13. package/dist/__mocks__/stores.d.ts +55 -45
  14. package/dist/__mocks__/stores.js +85 -68
  15. package/dist/app.css +3 -3
  16. package/dist/components/ButtonDarkMode.svelte +7 -1
  17. package/dist/components/ButtonLoading.svelte +1 -1
  18. package/dist/components/ButtonScrub.svelte +22 -0
  19. package/dist/components/ButtonScrub.svelte.d.ts +25 -0
  20. package/dist/components/ButtonVaultLink.svelte +12 -11
  21. package/dist/components/ButtonVaultLink.svelte.d.ts +4 -3
  22. package/dist/components/CheckboxInactiveOrdersVault.svelte +20 -0
  23. package/dist/components/CheckboxInactiveOrdersVault.svelte.d.ts +19 -0
  24. package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +2 -2
  25. package/dist/components/CodeMirrorDotrain.svelte +4 -0
  26. package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
  27. package/dist/components/CodeMirrorRainlang.svelte +20 -12
  28. package/dist/components/CodeMirrorRainlang.svelte.d.ts +3 -2
  29. package/dist/components/EditableSpan.svelte +3 -14
  30. package/dist/components/EditableSpan.svelte.d.ts +0 -1
  31. package/dist/components/Hash.svelte +6 -5
  32. package/dist/components/License.svelte +5 -4
  33. package/dist/components/ListViewRaindexFilters.svelte +64 -0
  34. package/dist/components/ListViewRaindexFilters.svelte.d.ts +32 -0
  35. package/dist/components/LocalDbStatusBadge.svelte +27 -0
  36. package/dist/components/LocalDbStatusBadge.svelte.d.ts +19 -0
  37. package/dist/components/LocalDbStatusCard.svelte +43 -0
  38. package/dist/components/LocalDbStatusCard.svelte.d.ts +20 -0
  39. package/dist/components/LocalDbStatusModal.svelte +105 -0
  40. package/dist/components/LocalDbStatusModal.svelte.d.ts +21 -0
  41. package/dist/components/OrderOrVaultHash.svelte +12 -12
  42. package/dist/components/OrderOrVaultHash.svelte.d.ts +4 -4
  43. package/dist/components/PageHeader.svelte +1 -1
  44. package/dist/components/Sensitive.svelte +16 -0
  45. package/dist/components/Sensitive.svelte.d.ts +28 -0
  46. package/dist/components/TanstackAppTable.svelte +270 -60
  47. package/dist/components/TanstackAppTable.svelte.d.ts +15 -9
  48. package/dist/components/ToastDetail.svelte +42 -0
  49. package/dist/components/ToastDetail.svelte.d.ts +20 -0
  50. package/dist/components/Tooltip.svelte +8 -0
  51. package/dist/components/Tooltip.svelte.d.ts +21 -0
  52. package/dist/components/VaultBalanceChangeTypeFilter.svelte +23 -0
  53. package/dist/components/VaultBalanceChangeTypeFilter.svelte.d.ts +19 -0
  54. package/dist/components/VaultCard.svelte +18 -0
  55. package/dist/components/VaultCard.svelte.d.ts +19 -0
  56. package/dist/components/charts/LightweightChart.svelte +1 -1
  57. package/dist/components/charts/LightweightChart.svelte.d.ts +5 -5
  58. package/dist/components/charts/OrderTradesChart.svelte +319 -28
  59. package/dist/components/charts/OrderTradesChart.svelte.d.ts +4 -4
  60. package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
  61. package/dist/components/charts/VaultBalanceChart.svelte +8 -26
  62. package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -7
  63. package/dist/components/charts/transformAndSortData.d.ts +24 -0
  64. package/dist/components/charts/transformAndSortData.js +111 -0
  65. package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
  66. package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
  67. package/dist/components/deployment/ButtonSelectOption.svelte +2 -0
  68. package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +1 -0
  69. package/dist/components/deployment/ComposedRainlangModal.svelte +3 -2
  70. package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
  71. package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
  72. package/dist/components/deployment/DeploymentSteps.svelte +196 -221
  73. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +6 -12
  74. package/dist/components/deployment/DeploymentTile.svelte +2 -2
  75. package/dist/components/deployment/DeploymentTile.svelte.d.ts +1 -1
  76. package/dist/components/deployment/DeploymentsSection.svelte +15 -22
  77. package/dist/components/deployment/DeploymentsSection.svelte.d.ts +3 -2
  78. package/dist/components/deployment/DepositInput.svelte +10 -11
  79. package/dist/components/deployment/DepositInput.svelte.d.ts +2 -3
  80. package/dist/components/deployment/DisclaimerModal.svelte +6 -7
  81. package/dist/components/deployment/FieldDefinitionInput.svelte +10 -14
  82. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +2 -3
  83. package/dist/components/deployment/InvalidOrdersSection.svelte +17 -0
  84. package/dist/components/deployment/InvalidOrdersSection.svelte.d.ts +19 -0
  85. package/dist/components/deployment/{StrategyPage.svelte → OrderPage.svelte} +15 -24
  86. package/dist/components/deployment/OrderPage.svelte.d.ts +21 -0
  87. package/dist/components/deployment/SelectToken.svelte +127 -50
  88. package/dist/components/deployment/SelectToken.svelte.d.ts +5 -4
  89. package/dist/components/deployment/TokenBalance.svelte +19 -0
  90. package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
  91. package/dist/components/deployment/TokenIOInput.svelte +27 -17
  92. package/dist/components/deployment/TokenIOInput.svelte.d.ts +3 -3
  93. package/dist/components/deployment/TokenSelectionModal.svelte +148 -0
  94. package/dist/components/deployment/TokenSelectionModal.svelte.d.ts +20 -0
  95. package/dist/components/deployment/{ValidStrategiesSection.svelte → ValidOrdersSection.svelte} +7 -7
  96. package/dist/components/deployment/ValidOrdersSection.svelte.d.ts +19 -0
  97. package/dist/components/deployment/VaultIdInformation.svelte +17 -0
  98. package/dist/components/deployment/VaultIdInformation.svelte.d.ts +21 -0
  99. package/dist/components/detail/OrderDetail.svelte +220 -82
  100. package/dist/components/detail/OrderDetail.svelte.d.ts +21 -15
  101. package/dist/components/detail/TanstackOrderQuote.svelte +114 -46
  102. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +14 -16
  103. package/dist/components/detail/VaultDetail.svelte +82 -79
  104. package/dist/components/detail/VaultDetail.svelte.d.ts +12 -18
  105. package/dist/components/dropdown/DropdownActiveNetworks.svelte +44 -0
  106. package/dist/components/dropdown/DropdownActiveNetworks.svelte.d.ts +19 -0
  107. package/dist/components/dropdown/DropdownCheckbox.svelte +4 -4
  108. package/dist/components/dropdown/DropdownRaindexesFilter.svelte +172 -0
  109. package/dist/components/dropdown/DropdownRaindexesFilter.svelte.d.ts +25 -0
  110. package/dist/components/dropdown/DropdownTokensFilter.svelte +152 -0
  111. package/dist/components/dropdown/DropdownTokensFilter.svelte.d.ts +28 -0
  112. package/dist/components/icon/Refresh.svelte +4 -2
  113. package/dist/components/icon/Refresh.svelte.d.ts +2 -0
  114. package/dist/components/input/InputOrderHash.svelte +1 -1
  115. package/dist/components/input/InputOrderHash.svelte.d.ts +3 -3
  116. package/dist/components/input/InputOwnerFilter.svelte +48 -0
  117. package/dist/components/input/InputOwnerFilter.svelte.d.ts +19 -0
  118. package/dist/components/input/InputRegistryUrl.svelte +36 -14
  119. package/dist/components/input/InputToken.svelte +2 -2
  120. package/dist/components/input/InputTokenAmount.svelte +30 -20
  121. package/dist/components/input/InputTokenAmount.svelte.d.ts +3 -3
  122. package/dist/components/tables/OrderAPY.svelte +6 -33
  123. package/dist/components/tables/OrderAPY.svelte.d.ts +1 -4
  124. package/dist/components/tables/OrderTradesListTable.svelte +132 -124
  125. package/dist/components/tables/OrderTradesListTable.svelte.d.ts +4 -4
  126. package/dist/components/tables/OrderVaultsVolTable.svelte +17 -22
  127. package/dist/components/tables/OrderVaultsVolTable.svelte.d.ts +2 -2
  128. package/dist/components/tables/OrdersListTable.svelte +206 -115
  129. package/dist/components/tables/OrdersListTable.svelte.d.ts +18 -23
  130. package/dist/components/tables/VaultBalanceChangesTable.svelte +83 -43
  131. package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +13 -11
  132. package/dist/components/tables/VaultsListTable.svelte +275 -150
  133. package/dist/components/tables/VaultsListTable.svelte.d.ts +24 -33
  134. package/dist/components/transactions/FixedBottomTransaction.svelte +64 -0
  135. package/dist/components/transactions/FixedBottomTransaction.svelte.d.ts +16 -0
  136. package/dist/components/transactions/TransactionDetail.svelte +31 -0
  137. package/dist/components/transactions/TransactionDetail.svelte.d.ts +20 -0
  138. package/dist/components/transactions/TransactionList.svelte +17 -0
  139. package/dist/components/transactions/TransactionList.svelte.d.ts +16 -0
  140. package/dist/components/transactions/getStatusEmoji.d.ts +2 -0
  141. package/dist/components/transactions/getStatusEmoji.js +20 -0
  142. package/dist/components/wallet/WalletConnect.svelte +5 -4
  143. package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
  144. package/dist/consts.d.ts +1 -0
  145. package/dist/consts.js +1 -0
  146. package/dist/errors/DeploymentStepsError.d.ts +11 -5
  147. package/dist/errors/DeploymentStepsError.js +13 -7
  148. package/dist/errors/index.d.ts +1 -1
  149. package/dist/errors/index.js +1 -1
  150. package/dist/hooks/useLocalDb.d.ts +3 -0
  151. package/dist/hooks/useLocalDb.js +10 -0
  152. package/dist/hooks/useRaindexClient.d.ts +3 -0
  153. package/dist/hooks/useRaindexClient.js +11 -0
  154. package/dist/hooks/useRaindexOrderBuilder.d.ts +3 -0
  155. package/dist/hooks/useRaindexOrderBuilder.js +11 -0
  156. package/dist/index.d.ts +122 -91
  157. package/dist/index.js +118 -87
  158. package/dist/models/Transaction.d.ts +75 -0
  159. package/dist/models/Transaction.js +100 -0
  160. package/dist/providers/LocalDbProvider.svelte +8 -0
  161. package/dist/providers/LocalDbProvider.svelte.d.ts +21 -0
  162. package/dist/providers/RaindexClientProvider.svelte +8 -0
  163. package/dist/providers/RaindexClientProvider.svelte.d.ts +21 -0
  164. package/dist/providers/RaindexOrderBuilderProvider.svelte +8 -0
  165. package/dist/providers/RaindexOrderBuilderProvider.svelte.d.ts +21 -0
  166. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte +8 -0
  167. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +24 -0
  168. package/dist/providers/dotrainRegistry/context.d.ts +9 -0
  169. package/dist/providers/dotrainRegistry/context.js +43 -0
  170. package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +5 -0
  171. package/dist/providers/dotrainRegistry/useDotrainRegistry.js +35 -0
  172. package/dist/providers/registry/RegistryManager.d.ts +65 -0
  173. package/dist/providers/registry/RegistryManager.js +134 -0
  174. package/dist/providers/registry/RegistryProvider.svelte +6 -0
  175. package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
  176. package/dist/providers/registry/context.d.ts +10 -0
  177. package/dist/providers/registry/context.js +46 -0
  178. package/dist/providers/registry/useRegistry.d.ts +7 -0
  179. package/dist/providers/registry/useRegistry.js +29 -0
  180. package/dist/providers/toasts/ToastProvider.svelte +17 -0
  181. package/dist/providers/toasts/ToastProvider.svelte.d.ts +18 -0
  182. package/dist/providers/toasts/context.d.ts +14 -0
  183. package/dist/providers/toasts/context.js +22 -0
  184. package/dist/providers/toasts/useToasts.d.ts +16 -0
  185. package/dist/providers/toasts/useToasts.js +63 -0
  186. package/dist/providers/transactions/TransactionManager.d.ts +234 -0
  187. package/dist/providers/transactions/TransactionManager.js +509 -0
  188. package/dist/providers/transactions/TransactionProvider.svelte +11 -0
  189. package/dist/providers/transactions/TransactionProvider.svelte.d.ts +24 -0
  190. package/dist/providers/transactions/context.d.ts +19 -0
  191. package/dist/providers/transactions/context.js +28 -0
  192. package/dist/providers/transactions/useTransactions.d.ts +13 -0
  193. package/dist/providers/transactions/useTransactions.js +18 -0
  194. package/dist/providers/wallet/WalletProvider.svelte +7 -0
  195. package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
  196. package/dist/providers/wallet/context.d.ts +10 -0
  197. package/dist/providers/wallet/context.js +47 -0
  198. package/dist/providers/wallet/useAccount.d.ts +8 -0
  199. package/dist/providers/wallet/useAccount.js +148 -0
  200. package/dist/queries/keys.d.ts +1 -0
  201. package/dist/queries/keys.js +10 -9
  202. package/dist/queries/queryClient.d.ts +2 -2
  203. package/dist/queries/queryClient.js +16 -11
  204. package/dist/services/awaitTransactionIndexing.d.ts +107 -0
  205. package/dist/services/awaitTransactionIndexing.js +60 -0
  206. package/dist/services/getExplorerLink.d.ts +1 -1
  207. package/dist/services/getExplorerLink.js +3 -5
  208. package/dist/services/handleShareChoices.d.ts +2 -2
  209. package/dist/services/handleShareChoices.js +6 -5
  210. package/dist/services/historicalOrderCharts.d.ts +3 -3
  211. package/dist/services/historicalOrderCharts.js +364 -371
  212. package/dist/services/index.d.ts +5 -2
  213. package/dist/services/index.js +3 -1
  214. package/dist/services/loadRegistryUrl.d.ts +2 -0
  215. package/dist/services/loadRegistryUrl.js +22 -0
  216. package/dist/services/pairTradesChartData.d.ts +47 -0
  217. package/dist/services/pairTradesChartData.js +194 -0
  218. package/dist/services/registry.d.ts +5 -5
  219. package/dist/services/registry.js +17 -217
  220. package/dist/services/time.d.ts +12 -0
  221. package/dist/services/time.js +88 -6
  222. package/dist/services/validateAmount.d.ts +30 -0
  223. package/dist/services/validateAmount.js +53 -0
  224. package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
  225. package/dist/storesGeneric/cachedWritableStore.js +93 -0
  226. package/dist/storesGeneric/scrub.d.ts +14 -0
  227. package/dist/storesGeneric/scrub.js +22 -0
  228. package/dist/test/matchers.d.ts +2 -2
  229. package/dist/test/matchers.js +2 -2
  230. package/dist/types/account.d.ts +3 -0
  231. package/dist/types/appStores.d.ts +9 -16
  232. package/dist/types/modal.d.ts +26 -14
  233. package/dist/types/order.d.ts +10 -0
  234. package/dist/types/order.js +1 -0
  235. package/dist/types/toast.d.ts +11 -0
  236. package/dist/types/toast.js +1 -0
  237. package/dist/types/tokenBalance.d.ts +6 -0
  238. package/dist/types/tokenBalance.js +1 -0
  239. package/dist/types/transaction.d.ts +67 -22
  240. package/dist/types/transaction.js +31 -1
  241. package/dist/utils/breadcrumbs.js +2 -2
  242. package/dist/utils/codeMirrorThemes.js +80 -74
  243. package/dist/utils/configHelpers.d.ts +4 -0
  244. package/dist/utils/configHelpers.js +21 -0
  245. package/dist/utils/constructHashLink.d.ts +24 -0
  246. package/dist/utils/constructHashLink.js +117 -0
  247. package/dist/utils/getNetworkName.d.ts +1 -0
  248. package/dist/utils/getNetworkName.js +13 -0
  249. package/dist/utils/hex.js +1 -1
  250. package/dist/utils/lightweightChartsThemes.d.ts +1 -1
  251. package/dist/utils/lightweightChartsThemes.js +11 -11
  252. package/dist/utils/localDbStatus.d.ts +26 -0
  253. package/dist/utils/localDbStatus.js +22 -0
  254. package/dist/utils/number.d.ts +0 -7
  255. package/dist/utils/number.js +5 -30
  256. package/dist/utils/stripTrailingWhitespace.d.ts +16 -0
  257. package/dist/utils/stripTrailingWhitespace.js +22 -0
  258. package/dist/utils/tokens.d.ts +2 -0
  259. package/dist/utils/tokens.js +3 -0
  260. package/dist/utils/vaultBalanceChangeLabels.d.ts +4 -0
  261. package/dist/utils/vaultBalanceChangeLabels.js +18 -0
  262. package/package.json +89 -84
  263. package/dist/__fixtures__/orderDetail.d.ts +0 -99
  264. package/dist/__fixtures__/orderDetail.js +0 -204
  265. package/dist/__fixtures__/settings-12-11-24.json +0 -160
  266. package/dist/__mocks__/mockTransactionStore.d.ts +0 -22
  267. package/dist/__mocks__/mockTransactionStore.js +0 -56
  268. package/dist/__mocks__/settings.d.ts +0 -3
  269. package/dist/__mocks__/settings.js +0 -37
  270. package/dist/components/CheckboxMyItemsOnly.svelte +0 -23
  271. package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +0 -21
  272. package/dist/components/ListViewOrderbookFilters.svelte +0 -58
  273. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +0 -28
  274. package/dist/components/deployment/InvalidStrategiesSection.svelte +0 -19
  275. package/dist/components/deployment/InvalidStrategiesSection.svelte.d.ts +0 -19
  276. package/dist/components/deployment/StrategyPage.svelte.d.ts +0 -19
  277. package/dist/components/deployment/ValidStrategiesSection.svelte.d.ts +0 -19
  278. package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
  279. package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -28
  280. package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
  281. package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
  282. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +0 -38
  283. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +0 -21
  284. package/dist/components/dropdown/DropdownOrderListAccounts.svelte +0 -15
  285. package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +0 -20
  286. package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
  287. package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
  288. package/dist/hooks/useGui.d.ts +0 -3
  289. package/dist/hooks/useGui.js +0 -11
  290. package/dist/providers/GuiProvider.svelte +0 -8
  291. package/dist/providers/GuiProvider.svelte.d.ts +0 -21
  292. package/dist/stores/transactionStore.d.ts +0 -98
  293. package/dist/stores/transactionStore.js +0 -303
  294. package/dist/types/strategy.d.ts +0 -10
  295. package/dist/utils/time.d.ts +0 -12
  296. package/dist/utils/time.js +0 -27
  297. package/dist/utils/vault.d.ts +0 -2
  298. package/dist/utils/vault.js +0 -29
  299. /package/dist/types/{strategy.js → account.js} +0 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Manages registry URL settings, persisting values in localStorage and URL parameters
3
+ */
4
+ export declare class RegistryManager {
5
+ /** The default registry URL to fall back to */
6
+ private defaultRegistry;
7
+ /** The currently selected registry URL */
8
+ private currentRegistry;
9
+ /** Key used for localStorage and URL parameters */
10
+ private static STORAGE_KEY;
11
+ /**
12
+ * Create a new RegistryManager
13
+ * @param defaultRegistry The default registry URL to use.
14
+ */
15
+ constructor(defaultRegistry: string);
16
+ /**
17
+ * Initialize registry from URL param or local storage
18
+ * @returns The registry URL to use
19
+ */
20
+ private loadRegistryFromStorageOrUrl;
21
+ /**
22
+ * Get the registry from the URL param
23
+ * @returns The registry value from URL or null if not present
24
+ * @throws Error if URL parsing fails
25
+ */
26
+ private getRegistryParamFromUrl;
27
+ /**
28
+ * Save the registry to local storage
29
+ * @param registry The registry URL to save
30
+ * @throws Error if localStorage is not available
31
+ */
32
+ private setRegistryToLocalStorage;
33
+ /**
34
+ * Retrieve the registry from local storage
35
+ * @returns The stored registry URL or null if not found
36
+ * @throws Error if localStorage is not available
37
+ */
38
+ private getRegistryFromLocalStorage;
39
+ /**
40
+ * Get the currently active registry
41
+ * @returns The current registry URL, falling back to default if not set
42
+ */
43
+ getCurrentRegistry(): string;
44
+ /**
45
+ * Set the registry and update both localStorage and URL
46
+ * @param registry The new registry URL to set
47
+ */
48
+ setRegistry(registry: string): void;
49
+ /**
50
+ * Reset to the default registry, clearing both localStorage and URL param
51
+ * @throws Error if localStorage is not available
52
+ */
53
+ resetToDefault(): void;
54
+ /**
55
+ * Update the URL param to reflect the current or specified registry
56
+ * @param value The registry value to set in URL, defaults to current registry
57
+ * @throws Error if URL manipulation fails
58
+ */
59
+ updateUrlWithRegistry(value?: string | null): void;
60
+ /**
61
+ * Check if the current registry is custom (different from the default)
62
+ * @returns True if using a non-default registry
63
+ */
64
+ isCustomRegistry(): boolean;
65
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Manages registry URL settings, persisting values in localStorage and URL parameters
3
+ */
4
+ export class RegistryManager {
5
+ /** The default registry URL to fall back to */
6
+ defaultRegistry;
7
+ /** The currently selected registry URL */
8
+ currentRegistry;
9
+ /** Key used for localStorage and URL parameters */
10
+ static STORAGE_KEY = "registry";
11
+ /**
12
+ * Create a new RegistryManager
13
+ * @param defaultRegistry The default registry URL to use.
14
+ */
15
+ constructor(defaultRegistry) {
16
+ this.defaultRegistry = defaultRegistry;
17
+ this.currentRegistry = this.loadRegistryFromStorageOrUrl();
18
+ }
19
+ /**
20
+ * Initialize registry from URL param or local storage
21
+ * @returns The registry URL to use
22
+ */
23
+ loadRegistryFromStorageOrUrl() {
24
+ const urlParam = this.getRegistryParamFromUrl();
25
+ if (urlParam) {
26
+ this.setRegistryToLocalStorage(urlParam);
27
+ return urlParam;
28
+ }
29
+ return this.getRegistryFromLocalStorage() ?? this.defaultRegistry;
30
+ }
31
+ /**
32
+ * Get the registry from the URL param
33
+ * @returns The registry value from URL or null if not present
34
+ * @throws Error if URL parsing fails
35
+ */
36
+ getRegistryParamFromUrl() {
37
+ try {
38
+ return new URL(window.location.href).searchParams.get(RegistryManager.STORAGE_KEY);
39
+ }
40
+ catch (error) {
41
+ throw new Error("Failed to get registry parameter: " +
42
+ (error instanceof Error ? error.message : String(error)));
43
+ }
44
+ }
45
+ /**
46
+ * Save the registry to local storage
47
+ * @param registry The registry URL to save
48
+ * @throws Error if localStorage is not available
49
+ */
50
+ setRegistryToLocalStorage(registry) {
51
+ try {
52
+ localStorage.setItem(RegistryManager.STORAGE_KEY, registry);
53
+ }
54
+ catch (error) {
55
+ throw new Error("Failed to save to localStorage: " +
56
+ (error instanceof Error ? error.message : String(error)));
57
+ }
58
+ }
59
+ /**
60
+ * Retrieve the registry from local storage
61
+ * @returns The stored registry URL or null if not found
62
+ * @throws Error if localStorage is not available
63
+ */
64
+ getRegistryFromLocalStorage() {
65
+ try {
66
+ return localStorage.getItem(RegistryManager.STORAGE_KEY);
67
+ }
68
+ catch (error) {
69
+ throw new Error("Failed to access localStorage: " +
70
+ (error instanceof Error ? error.message : String(error)));
71
+ }
72
+ }
73
+ /**
74
+ * Get the currently active registry
75
+ * @returns The current registry URL, falling back to default if not set
76
+ */
77
+ getCurrentRegistry() {
78
+ return this.currentRegistry ?? this.defaultRegistry;
79
+ }
80
+ /**
81
+ * Set the registry and update both localStorage and URL
82
+ * @param registry The new registry URL to set
83
+ */
84
+ setRegistry(registry) {
85
+ this.currentRegistry = registry;
86
+ this.setRegistryToLocalStorage(registry);
87
+ this.updateUrlWithRegistry();
88
+ }
89
+ /**
90
+ * Reset to the default registry, clearing both localStorage and URL param
91
+ * @throws Error if localStorage is not available
92
+ */
93
+ resetToDefault() {
94
+ this.currentRegistry = this.defaultRegistry;
95
+ try {
96
+ localStorage.removeItem(RegistryManager.STORAGE_KEY);
97
+ }
98
+ catch (error) {
99
+ throw new Error("Failed to clear registry from localStorage: " +
100
+ (error instanceof Error ? error.message : String(error)));
101
+ }
102
+ this.updateUrlWithRegistry(null);
103
+ }
104
+ /**
105
+ * Update the URL param to reflect the current or specified registry
106
+ * @param value The registry value to set in URL, defaults to current registry
107
+ * @throws Error if URL manipulation fails
108
+ */
109
+ updateUrlWithRegistry(value = this.currentRegistry) {
110
+ try {
111
+ const url = new URL(window.location.href);
112
+ if (value) {
113
+ url.searchParams.set(RegistryManager.STORAGE_KEY, value);
114
+ }
115
+ else {
116
+ url.searchParams.delete(RegistryManager.STORAGE_KEY);
117
+ }
118
+ window.history.pushState({}, "", url.toString());
119
+ }
120
+ catch (error) {
121
+ throw new Error("Failed to update URL parameter: " +
122
+ (error instanceof Error ? error.message : String(error)));
123
+ }
124
+ }
125
+ /**
126
+ * Check if the current registry is custom (different from the default)
127
+ * @returns True if using a non-default registry
128
+ */
129
+ isCustomRegistry() {
130
+ return (this.currentRegistry !== undefined &&
131
+ this.currentRegistry !== null &&
132
+ this.currentRegistry !== this.defaultRegistry);
133
+ }
134
+ }
@@ -0,0 +1,6 @@
1
+ <script>import { setRegistryContext } from "./context";
2
+ export let registryManager;
3
+ setRegistryContext(registryManager);
4
+ </script>
5
+
6
+ <slot />
@@ -0,0 +1,21 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { RegistryManager } from './RegistryManager';
3
+ declare const __propDef: {
4
+ props: {
5
+ registryManager: RegistryManager;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {
11
+ default: {};
12
+ };
13
+ exports?: {} | undefined;
14
+ bindings?: string | undefined;
15
+ };
16
+ export type RegistryProviderProps = typeof __propDef.props;
17
+ export type RegistryProviderEvents = typeof __propDef.events;
18
+ export type RegistryProviderSlots = typeof __propDef.slots;
19
+ export default class RegistryProvider extends SvelteComponent<RegistryProviderProps, RegistryProviderEvents, RegistryProviderSlots> {
20
+ }
21
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { RegistryManager } from "./RegistryManager";
2
+ export declare const REGISTRY_KEY = "registry_key";
3
+ /**
4
+ * Retrieves the registry manager directly from Svelte's context
5
+ */
6
+ export declare const getRegistryContext: () => RegistryManager;
7
+ /**
8
+ * Sets the registry manager in Svelte's context
9
+ */
10
+ export declare const setRegistryContext: (registry: RegistryManager) => void;
@@ -0,0 +1,46 @@
1
+ import { getContext, setContext } from "svelte";
2
+ export const REGISTRY_KEY = "registry_key";
3
+ /**
4
+ * Retrieves the registry manager directly from Svelte's context
5
+ */
6
+ export const getRegistryContext = () => {
7
+ const registry = getContext(REGISTRY_KEY);
8
+ if (!registry) {
9
+ throw new Error("No registry manager was found in Svelte context. Did you forget to wrap your component with RegistryProvider?");
10
+ }
11
+ return registry;
12
+ };
13
+ /**
14
+ * Sets the registry manager in Svelte's context
15
+ */
16
+ export const setRegistryContext = (registry) => {
17
+ setContext(REGISTRY_KEY, registry);
18
+ };
19
+ if (import.meta.vitest) {
20
+ const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
21
+ vi.mock("svelte", async (importOriginal) => ({
22
+ ...(await importOriginal()),
23
+ getContext: vi.fn(),
24
+ }));
25
+ describe("getRegistryContext", () => {
26
+ const mockGetContext = vi.mocked(getContext);
27
+ beforeEach(() => {
28
+ mockGetContext.mockReset();
29
+ });
30
+ it("should return the registry from context when it exists", () => {
31
+ const mockRegistry = {};
32
+ mockGetContext.mockImplementation((key) => {
33
+ if (key === REGISTRY_KEY)
34
+ return mockRegistry;
35
+ return undefined;
36
+ });
37
+ const result = getRegistryContext();
38
+ expect(mockGetContext).toHaveBeenCalledWith(REGISTRY_KEY);
39
+ expect(result).toEqual(mockRegistry);
40
+ });
41
+ it("should throw an error when registry is not in context", () => {
42
+ mockGetContext.mockReturnValue(undefined);
43
+ expect(() => getRegistryContext()).toThrow("No registry manager was found in Svelte context. Did you forget to wrap your component with RegistryProvider?");
44
+ });
45
+ });
46
+ }
@@ -0,0 +1,7 @@
1
+ import type { RegistryManager } from "./RegistryManager";
2
+ /**
3
+ * Hook to access registry manager information from context
4
+ * Must be used within a component that is a child of RegistryProvider
5
+ * @returns An object containing the registry manager
6
+ */
7
+ export declare function useRegistry(): RegistryManager;
@@ -0,0 +1,29 @@
1
+ import { getRegistryContext } from "./context";
2
+ /**
3
+ * Hook to access registry manager information from context
4
+ * Must be used within a component that is a child of RegistryProvider
5
+ * @returns An object containing the registry manager
6
+ */
7
+ export function useRegistry() {
8
+ const registry = getRegistryContext();
9
+ return registry;
10
+ }
11
+ if (import.meta.vitest) {
12
+ const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
13
+ vi.mock("./context", () => ({
14
+ getRegistryContext: vi.fn(),
15
+ }));
16
+ describe("useRegistry", () => {
17
+ const mockGetRegistryContext = vi.mocked(getRegistryContext);
18
+ beforeEach(() => {
19
+ mockGetRegistryContext.mockReset();
20
+ });
21
+ it("should return registry", () => {
22
+ const mockRegistry = {};
23
+ mockGetRegistryContext.mockReturnValue(mockRegistry);
24
+ const result = useRegistry();
25
+ expect(mockGetRegistryContext).toHaveBeenCalled();
26
+ expect(result).toEqual(mockRegistry);
27
+ });
28
+ });
29
+ }
@@ -0,0 +1,17 @@
1
+ <script>import ToastDetail from "../../components/ToastDetail.svelte";
2
+ import { setToastsContext } from "./context";
3
+ import { writable } from "svelte/store";
4
+ import { fade } from "svelte/transition";
5
+ const toasts = writable([]);
6
+ setToastsContext(toasts);
7
+ </script>
8
+
9
+ <div class="fixed right-4 top-4 z-[100]">
10
+ {#each $toasts as toast, i}
11
+ <div out:fade data-testid="toast">
12
+ <ToastDetail {toast} {i} />
13
+ </div>
14
+ {/each}
15
+ </div>
16
+
17
+ <slot />
@@ -0,0 +1,18 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: Record<string, never>;
4
+ events: {
5
+ [evt: string]: CustomEvent<any>;
6
+ };
7
+ slots: {
8
+ default: {};
9
+ };
10
+ exports?: {} | undefined;
11
+ bindings?: string | undefined;
12
+ };
13
+ export type ToastProviderProps = typeof __propDef.props;
14
+ export type ToastProviderEvents = typeof __propDef.events;
15
+ export type ToastProviderSlots = typeof __propDef.slots;
16
+ export default class ToastProvider extends SvelteComponent<ToastProviderProps, ToastProviderEvents, ToastProviderSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,14 @@
1
+ import { type Writable } from "svelte/store";
2
+ import type { ToastProps } from "../../types/toast";
3
+ export declare const TOASTS_KEY = "rain:ui-components:toasts";
4
+ /**
5
+ * Retrieves the toasts store from Svelte's context
6
+ */
7
+ export declare function getToastsContext(): Writable<ToastProps[]>;
8
+ /**
9
+ * Sets the toasts store in Svelte's context
10
+ *
11
+ * @param {Writable<ToastProps[]>} toasts - The writable store containing all active toast notifications
12
+ * @returns {void}
13
+ */
14
+ export declare function setToastsContext(toasts: Writable<ToastProps[]>): void;
@@ -0,0 +1,22 @@
1
+ import { getContext, setContext } from "svelte";
2
+ import {} from "svelte/store";
3
+ export const TOASTS_KEY = "rain:ui-components:toasts";
4
+ /**
5
+ * Retrieves the toasts store from Svelte's context
6
+ */
7
+ export function getToastsContext() {
8
+ const toasts = getContext(TOASTS_KEY);
9
+ if (!toasts) {
10
+ throw new Error("No toasts context found. Did you forget to wrap your component with ToastProvider?");
11
+ }
12
+ return toasts;
13
+ }
14
+ /**
15
+ * Sets the toasts store in Svelte's context
16
+ *
17
+ * @param {Writable<ToastProps[]>} toasts - The writable store containing all active toast notifications
18
+ * @returns {void}
19
+ */
20
+ export function setToastsContext(toasts) {
21
+ setContext(TOASTS_KEY, toasts);
22
+ }
@@ -0,0 +1,16 @@
1
+ import type { ToastProps } from "../../types/toast";
2
+ /**
3
+ * Hook for managing toast notifications in the application.
4
+ * Provides functionality to add, remove, and access toast notifications.
5
+ *
6
+ * @returns {Object} An object containing:
7
+ * - toasts: Writable store containing all active toast notifications
8
+ * - addToast: Function to add a new toast notification
9
+ * - removeToast: Function to remove a toast notification by index
10
+ */
11
+ export declare function useToasts(): {
12
+ toasts: import("svelte/store").Writable<ToastProps[]>;
13
+ addToast: (toast: ToastProps) => void;
14
+ removeToast: (index: number) => void;
15
+ errToast: (message: string, detail?: string) => void;
16
+ };
@@ -0,0 +1,63 @@
1
+ import { getToastsContext } from "./context";
2
+ /**
3
+ * Hook for managing toast notifications in the application.
4
+ * Provides functionality to add, remove, and access toast notifications.
5
+ *
6
+ * @returns {Object} An object containing:
7
+ * - toasts: Writable store containing all active toast notifications
8
+ * - addToast: Function to add a new toast notification
9
+ * - removeToast: Function to remove a toast notification by index
10
+ */
11
+ export function useToasts() {
12
+ const toasts = getToastsContext();
13
+ /**
14
+ * Removes a toast notification by its index from the toasts store
15
+ *
16
+ * @param {number} index - The index of the toast to remove
17
+ * @returns {void}
18
+ */
19
+ const removeToast = (index) => {
20
+ toasts.update((toasts) => {
21
+ if (index < 0 || index >= toasts.length) {
22
+ return toasts;
23
+ }
24
+ return toasts.filter((_, i) => i !== index);
25
+ });
26
+ };
27
+ /**
28
+ * Adds a new toast notification to the toasts store
29
+ *
30
+ * @param {ToastProps} toast - The toast configuration object containing:
31
+ * - message: The text to display in the toast
32
+ * - type: The type of toast (success, error, warning, info)
33
+ * - color: The color theme of the toast (green, red, yellow, blue)
34
+ * - links: Optional array of links to display in the toast
35
+ * @returns {void}
36
+ */
37
+ const addToast = (toast) => {
38
+ toasts.update((toasts) => {
39
+ const updatedToasts = [...toasts, toast];
40
+ return updatedToasts;
41
+ });
42
+ };
43
+ /**
44
+ * Adds a standardized error toast notification
45
+ *
46
+ * @param message - The error message to display
47
+ * @param detail - The detail of the error
48
+ */
49
+ const errToast = (message, detail) => {
50
+ addToast({
51
+ message,
52
+ detail,
53
+ type: "error",
54
+ color: "red",
55
+ });
56
+ };
57
+ return {
58
+ toasts,
59
+ addToast,
60
+ removeToast,
61
+ errToast,
62
+ };
63
+ }