@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.
- package/README.md +14 -6
- package/dist/__fixtures__/settings.yaml +123 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte +4 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte.d.ts +18 -0
- package/dist/__mocks__/MockCodeMirrorEditor.svelte +17 -0
- package/dist/__mocks__/MockCodeMirrorEditor.svelte.d.ts +21 -0
- package/dist/__mocks__/MockComponent.js +1 -1
- package/dist/__mocks__/MockComponent.svelte +10 -2
- package/dist/__mocks__/MockComponent.svelte.d.ts +4 -1
- package/dist/__mocks__/mockWeb3Config.d.ts +1 -1
- package/dist/__mocks__/mockWeb3Config.js +10 -7
- package/dist/__mocks__/queries.js +9 -9
- package/dist/__mocks__/stores.d.ts +55 -45
- package/dist/__mocks__/stores.js +85 -68
- package/dist/app.css +3 -3
- package/dist/components/ButtonDarkMode.svelte +7 -1
- package/dist/components/ButtonLoading.svelte +1 -1
- package/dist/components/ButtonScrub.svelte +22 -0
- package/dist/components/ButtonScrub.svelte.d.ts +25 -0
- package/dist/components/ButtonVaultLink.svelte +12 -11
- package/dist/components/ButtonVaultLink.svelte.d.ts +4 -3
- package/dist/components/CheckboxInactiveOrdersVault.svelte +20 -0
- package/dist/components/CheckboxInactiveOrdersVault.svelte.d.ts +19 -0
- package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +2 -2
- package/dist/components/CodeMirrorDotrain.svelte +4 -0
- package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
- package/dist/components/CodeMirrorRainlang.svelte +20 -12
- package/dist/components/CodeMirrorRainlang.svelte.d.ts +3 -2
- package/dist/components/EditableSpan.svelte +3 -14
- package/dist/components/EditableSpan.svelte.d.ts +0 -1
- package/dist/components/Hash.svelte +6 -5
- package/dist/components/License.svelte +5 -4
- package/dist/components/ListViewRaindexFilters.svelte +64 -0
- package/dist/components/ListViewRaindexFilters.svelte.d.ts +32 -0
- package/dist/components/LocalDbStatusBadge.svelte +27 -0
- package/dist/components/LocalDbStatusBadge.svelte.d.ts +19 -0
- package/dist/components/LocalDbStatusCard.svelte +43 -0
- package/dist/components/LocalDbStatusCard.svelte.d.ts +20 -0
- package/dist/components/LocalDbStatusModal.svelte +105 -0
- package/dist/components/LocalDbStatusModal.svelte.d.ts +21 -0
- package/dist/components/OrderOrVaultHash.svelte +12 -12
- package/dist/components/OrderOrVaultHash.svelte.d.ts +4 -4
- package/dist/components/PageHeader.svelte +1 -1
- package/dist/components/Sensitive.svelte +16 -0
- package/dist/components/Sensitive.svelte.d.ts +28 -0
- package/dist/components/TanstackAppTable.svelte +270 -60
- package/dist/components/TanstackAppTable.svelte.d.ts +15 -9
- package/dist/components/ToastDetail.svelte +42 -0
- package/dist/components/ToastDetail.svelte.d.ts +20 -0
- package/dist/components/Tooltip.svelte +8 -0
- package/dist/components/Tooltip.svelte.d.ts +21 -0
- package/dist/components/VaultBalanceChangeTypeFilter.svelte +23 -0
- package/dist/components/VaultBalanceChangeTypeFilter.svelte.d.ts +19 -0
- package/dist/components/VaultCard.svelte +18 -0
- package/dist/components/VaultCard.svelte.d.ts +19 -0
- package/dist/components/charts/LightweightChart.svelte +1 -1
- package/dist/components/charts/LightweightChart.svelte.d.ts +5 -5
- package/dist/components/charts/OrderTradesChart.svelte +319 -28
- package/dist/components/charts/OrderTradesChart.svelte.d.ts +4 -4
- package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
- package/dist/components/charts/VaultBalanceChart.svelte +8 -26
- package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -7
- package/dist/components/charts/transformAndSortData.d.ts +24 -0
- package/dist/components/charts/transformAndSortData.js +111 -0
- package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
- package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
- package/dist/components/deployment/ButtonSelectOption.svelte +2 -0
- package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +1 -0
- package/dist/components/deployment/ComposedRainlangModal.svelte +3 -2
- package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
- package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
- package/dist/components/deployment/DeploymentSteps.svelte +196 -221
- package/dist/components/deployment/DeploymentSteps.svelte.d.ts +6 -12
- package/dist/components/deployment/DeploymentTile.svelte +2 -2
- package/dist/components/deployment/DeploymentTile.svelte.d.ts +1 -1
- package/dist/components/deployment/DeploymentsSection.svelte +15 -22
- package/dist/components/deployment/DeploymentsSection.svelte.d.ts +3 -2
- package/dist/components/deployment/DepositInput.svelte +10 -11
- package/dist/components/deployment/DepositInput.svelte.d.ts +2 -3
- package/dist/components/deployment/DisclaimerModal.svelte +6 -7
- package/dist/components/deployment/FieldDefinitionInput.svelte +10 -14
- package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +2 -3
- package/dist/components/deployment/InvalidOrdersSection.svelte +17 -0
- package/dist/components/deployment/InvalidOrdersSection.svelte.d.ts +19 -0
- package/dist/components/deployment/{StrategyPage.svelte → OrderPage.svelte} +15 -24
- package/dist/components/deployment/OrderPage.svelte.d.ts +21 -0
- package/dist/components/deployment/SelectToken.svelte +127 -50
- package/dist/components/deployment/SelectToken.svelte.d.ts +5 -4
- package/dist/components/deployment/TokenBalance.svelte +19 -0
- package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
- package/dist/components/deployment/TokenIOInput.svelte +27 -17
- package/dist/components/deployment/TokenIOInput.svelte.d.ts +3 -3
- package/dist/components/deployment/TokenSelectionModal.svelte +148 -0
- package/dist/components/deployment/TokenSelectionModal.svelte.d.ts +20 -0
- package/dist/components/deployment/{ValidStrategiesSection.svelte → ValidOrdersSection.svelte} +7 -7
- package/dist/components/deployment/ValidOrdersSection.svelte.d.ts +19 -0
- package/dist/components/deployment/VaultIdInformation.svelte +17 -0
- package/dist/components/deployment/VaultIdInformation.svelte.d.ts +21 -0
- package/dist/components/detail/OrderDetail.svelte +220 -82
- package/dist/components/detail/OrderDetail.svelte.d.ts +21 -15
- package/dist/components/detail/TanstackOrderQuote.svelte +114 -46
- package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +14 -16
- package/dist/components/detail/VaultDetail.svelte +82 -79
- package/dist/components/detail/VaultDetail.svelte.d.ts +12 -18
- package/dist/components/dropdown/DropdownActiveNetworks.svelte +44 -0
- package/dist/components/dropdown/DropdownActiveNetworks.svelte.d.ts +19 -0
- package/dist/components/dropdown/DropdownCheckbox.svelte +4 -4
- package/dist/components/dropdown/DropdownRaindexesFilter.svelte +172 -0
- package/dist/components/dropdown/DropdownRaindexesFilter.svelte.d.ts +25 -0
- package/dist/components/dropdown/DropdownTokensFilter.svelte +152 -0
- package/dist/components/dropdown/DropdownTokensFilter.svelte.d.ts +28 -0
- package/dist/components/icon/Refresh.svelte +4 -2
- package/dist/components/icon/Refresh.svelte.d.ts +2 -0
- package/dist/components/input/InputOrderHash.svelte +1 -1
- package/dist/components/input/InputOrderHash.svelte.d.ts +3 -3
- package/dist/components/input/InputOwnerFilter.svelte +48 -0
- package/dist/components/input/InputOwnerFilter.svelte.d.ts +19 -0
- package/dist/components/input/InputRegistryUrl.svelte +36 -14
- package/dist/components/input/InputToken.svelte +2 -2
- package/dist/components/input/InputTokenAmount.svelte +30 -20
- package/dist/components/input/InputTokenAmount.svelte.d.ts +3 -3
- package/dist/components/tables/OrderAPY.svelte +6 -33
- package/dist/components/tables/OrderAPY.svelte.d.ts +1 -4
- package/dist/components/tables/OrderTradesListTable.svelte +132 -124
- package/dist/components/tables/OrderTradesListTable.svelte.d.ts +4 -4
- package/dist/components/tables/OrderVaultsVolTable.svelte +17 -22
- package/dist/components/tables/OrderVaultsVolTable.svelte.d.ts +2 -2
- package/dist/components/tables/OrdersListTable.svelte +206 -115
- package/dist/components/tables/OrdersListTable.svelte.d.ts +18 -23
- package/dist/components/tables/VaultBalanceChangesTable.svelte +83 -43
- package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +13 -11
- package/dist/components/tables/VaultsListTable.svelte +275 -150
- package/dist/components/tables/VaultsListTable.svelte.d.ts +24 -33
- package/dist/components/transactions/FixedBottomTransaction.svelte +64 -0
- package/dist/components/transactions/FixedBottomTransaction.svelte.d.ts +16 -0
- package/dist/components/transactions/TransactionDetail.svelte +31 -0
- package/dist/components/transactions/TransactionDetail.svelte.d.ts +20 -0
- package/dist/components/transactions/TransactionList.svelte +17 -0
- package/dist/components/transactions/TransactionList.svelte.d.ts +16 -0
- package/dist/components/transactions/getStatusEmoji.d.ts +2 -0
- package/dist/components/transactions/getStatusEmoji.js +20 -0
- package/dist/components/wallet/WalletConnect.svelte +5 -4
- package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
- package/dist/consts.d.ts +1 -0
- package/dist/consts.js +1 -0
- package/dist/errors/DeploymentStepsError.d.ts +11 -5
- package/dist/errors/DeploymentStepsError.js +13 -7
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/hooks/useLocalDb.d.ts +3 -0
- package/dist/hooks/useLocalDb.js +10 -0
- package/dist/hooks/useRaindexClient.d.ts +3 -0
- package/dist/hooks/useRaindexClient.js +11 -0
- package/dist/hooks/useRaindexOrderBuilder.d.ts +3 -0
- package/dist/hooks/useRaindexOrderBuilder.js +11 -0
- package/dist/index.d.ts +122 -91
- package/dist/index.js +118 -87
- package/dist/models/Transaction.d.ts +75 -0
- package/dist/models/Transaction.js +100 -0
- package/dist/providers/LocalDbProvider.svelte +8 -0
- package/dist/providers/LocalDbProvider.svelte.d.ts +21 -0
- package/dist/providers/RaindexClientProvider.svelte +8 -0
- package/dist/providers/RaindexClientProvider.svelte.d.ts +21 -0
- package/dist/providers/RaindexOrderBuilderProvider.svelte +8 -0
- package/dist/providers/RaindexOrderBuilderProvider.svelte.d.ts +21 -0
- package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte +8 -0
- package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +24 -0
- package/dist/providers/dotrainRegistry/context.d.ts +9 -0
- package/dist/providers/dotrainRegistry/context.js +43 -0
- package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +5 -0
- package/dist/providers/dotrainRegistry/useDotrainRegistry.js +35 -0
- package/dist/providers/registry/RegistryManager.d.ts +65 -0
- package/dist/providers/registry/RegistryManager.js +134 -0
- package/dist/providers/registry/RegistryProvider.svelte +6 -0
- package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
- package/dist/providers/registry/context.d.ts +10 -0
- package/dist/providers/registry/context.js +46 -0
- package/dist/providers/registry/useRegistry.d.ts +7 -0
- package/dist/providers/registry/useRegistry.js +29 -0
- package/dist/providers/toasts/ToastProvider.svelte +17 -0
- package/dist/providers/toasts/ToastProvider.svelte.d.ts +18 -0
- package/dist/providers/toasts/context.d.ts +14 -0
- package/dist/providers/toasts/context.js +22 -0
- package/dist/providers/toasts/useToasts.d.ts +16 -0
- package/dist/providers/toasts/useToasts.js +63 -0
- package/dist/providers/transactions/TransactionManager.d.ts +234 -0
- package/dist/providers/transactions/TransactionManager.js +509 -0
- package/dist/providers/transactions/TransactionProvider.svelte +11 -0
- package/dist/providers/transactions/TransactionProvider.svelte.d.ts +24 -0
- package/dist/providers/transactions/context.d.ts +19 -0
- package/dist/providers/transactions/context.js +28 -0
- package/dist/providers/transactions/useTransactions.d.ts +13 -0
- package/dist/providers/transactions/useTransactions.js +18 -0
- package/dist/providers/wallet/WalletProvider.svelte +7 -0
- package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
- package/dist/providers/wallet/context.d.ts +10 -0
- package/dist/providers/wallet/context.js +47 -0
- package/dist/providers/wallet/useAccount.d.ts +8 -0
- package/dist/providers/wallet/useAccount.js +148 -0
- package/dist/queries/keys.d.ts +1 -0
- package/dist/queries/keys.js +10 -9
- package/dist/queries/queryClient.d.ts +2 -2
- package/dist/queries/queryClient.js +16 -11
- package/dist/services/awaitTransactionIndexing.d.ts +107 -0
- package/dist/services/awaitTransactionIndexing.js +60 -0
- package/dist/services/getExplorerLink.d.ts +1 -1
- package/dist/services/getExplorerLink.js +3 -5
- package/dist/services/handleShareChoices.d.ts +2 -2
- package/dist/services/handleShareChoices.js +6 -5
- package/dist/services/historicalOrderCharts.d.ts +3 -3
- package/dist/services/historicalOrderCharts.js +364 -371
- package/dist/services/index.d.ts +5 -2
- package/dist/services/index.js +3 -1
- package/dist/services/loadRegistryUrl.d.ts +2 -0
- package/dist/services/loadRegistryUrl.js +22 -0
- package/dist/services/pairTradesChartData.d.ts +47 -0
- package/dist/services/pairTradesChartData.js +194 -0
- package/dist/services/registry.d.ts +5 -5
- package/dist/services/registry.js +17 -217
- package/dist/services/time.d.ts +12 -0
- package/dist/services/time.js +88 -6
- package/dist/services/validateAmount.d.ts +30 -0
- package/dist/services/validateAmount.js +53 -0
- package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
- package/dist/storesGeneric/cachedWritableStore.js +93 -0
- package/dist/storesGeneric/scrub.d.ts +14 -0
- package/dist/storesGeneric/scrub.js +22 -0
- package/dist/test/matchers.d.ts +2 -2
- package/dist/test/matchers.js +2 -2
- package/dist/types/account.d.ts +3 -0
- package/dist/types/appStores.d.ts +9 -16
- package/dist/types/modal.d.ts +26 -14
- package/dist/types/order.d.ts +10 -0
- package/dist/types/order.js +1 -0
- package/dist/types/toast.d.ts +11 -0
- package/dist/types/toast.js +1 -0
- package/dist/types/tokenBalance.d.ts +6 -0
- package/dist/types/tokenBalance.js +1 -0
- package/dist/types/transaction.d.ts +67 -22
- package/dist/types/transaction.js +31 -1
- package/dist/utils/breadcrumbs.js +2 -2
- package/dist/utils/codeMirrorThemes.js +80 -74
- package/dist/utils/configHelpers.d.ts +4 -0
- package/dist/utils/configHelpers.js +21 -0
- package/dist/utils/constructHashLink.d.ts +24 -0
- package/dist/utils/constructHashLink.js +117 -0
- package/dist/utils/getNetworkName.d.ts +1 -0
- package/dist/utils/getNetworkName.js +13 -0
- package/dist/utils/hex.js +1 -1
- package/dist/utils/lightweightChartsThemes.d.ts +1 -1
- package/dist/utils/lightweightChartsThemes.js +11 -11
- package/dist/utils/localDbStatus.d.ts +26 -0
- package/dist/utils/localDbStatus.js +22 -0
- package/dist/utils/number.d.ts +0 -7
- package/dist/utils/number.js +5 -30
- package/dist/utils/stripTrailingWhitespace.d.ts +16 -0
- package/dist/utils/stripTrailingWhitespace.js +22 -0
- package/dist/utils/tokens.d.ts +2 -0
- package/dist/utils/tokens.js +3 -0
- package/dist/utils/vaultBalanceChangeLabels.d.ts +4 -0
- package/dist/utils/vaultBalanceChangeLabels.js +18 -0
- package/package.json +89 -84
- package/dist/__fixtures__/orderDetail.d.ts +0 -99
- package/dist/__fixtures__/orderDetail.js +0 -204
- package/dist/__fixtures__/settings-12-11-24.json +0 -160
- package/dist/__mocks__/mockTransactionStore.d.ts +0 -22
- package/dist/__mocks__/mockTransactionStore.js +0 -56
- package/dist/__mocks__/settings.d.ts +0 -3
- package/dist/__mocks__/settings.js +0 -37
- package/dist/components/CheckboxMyItemsOnly.svelte +0 -23
- package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +0 -21
- package/dist/components/ListViewOrderbookFilters.svelte +0 -58
- package/dist/components/ListViewOrderbookFilters.svelte.d.ts +0 -28
- package/dist/components/deployment/InvalidStrategiesSection.svelte +0 -19
- package/dist/components/deployment/InvalidStrategiesSection.svelte.d.ts +0 -19
- package/dist/components/deployment/StrategyPage.svelte.d.ts +0 -19
- package/dist/components/deployment/ValidStrategiesSection.svelte.d.ts +0 -19
- package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
- package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -28
- package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
- package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
- package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +0 -38
- package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +0 -21
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte +0 -15
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +0 -20
- package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
- package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
- package/dist/hooks/useGui.d.ts +0 -3
- package/dist/hooks/useGui.js +0 -11
- package/dist/providers/GuiProvider.svelte +0 -8
- package/dist/providers/GuiProvider.svelte.d.ts +0 -21
- package/dist/stores/transactionStore.d.ts +0 -98
- package/dist/stores/transactionStore.js +0 -303
- package/dist/types/strategy.d.ts +0 -10
- package/dist/utils/time.d.ts +0 -12
- package/dist/utils/time.js +0 -27
- package/dist/utils/vault.d.ts +0 -2
- package/dist/utils/vault.js +0 -29
- /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,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
|
+
}
|