@rainlanguage/ui-components 0.0.1-alpha.21 → 0.0.1-alpha.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__fixtures__/settings.yaml +125 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte +4 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte.d.ts +18 -0
- package/dist/__mocks__/MockComponent.svelte +4 -0
- package/dist/__mocks__/MockComponent.svelte.d.ts +3 -1
- package/dist/__mocks__/stores.d.ts +47 -33
- package/dist/__mocks__/stores.js +61 -38
- package/dist/components/ButtonLoading.svelte +1 -1
- package/dist/components/ButtonVaultLink.svelte +11 -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/CheckboxMyItemsOnly.svelte +3 -2
- package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +2 -3
- 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 +3 -12
- package/dist/components/CodeMirrorRainlang.svelte.d.ts +2 -2
- package/dist/components/EditableSpan.svelte +3 -14
- package/dist/components/EditableSpan.svelte.d.ts +0 -1
- package/dist/components/Hash.svelte +3 -3
- package/dist/components/License.svelte +5 -4
- package/dist/components/ListViewOrderbookFilters.svelte +45 -23
- package/dist/components/ListViewOrderbookFilters.svelte.d.ts +27 -22
- package/dist/components/LocalDbStatusBadge.svelte +27 -0
- package/dist/components/LocalDbStatusBadge.svelte.d.ts +19 -0
- package/dist/components/LocalDbStatusCard.svelte +40 -0
- package/dist/components/LocalDbStatusCard.svelte.d.ts +20 -0
- package/dist/components/LocalDbStatusModal.svelte +103 -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/TanstackAppTable.svelte +179 -28
- package/dist/components/TanstackAppTable.svelte.d.ts +14 -8
- 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 +300 -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 +2 -1
- package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
- package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
- package/dist/components/deployment/DeploymentSteps.svelte +209 -216
- 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 +8 -10
- package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
- package/dist/components/deployment/DisclaimerModal.svelte +6 -7
- package/dist/components/deployment/FieldDefinitionInput.svelte +7 -11
- package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
- 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 +125 -48
- package/dist/components/deployment/SelectToken.svelte.d.ts +4 -3
- package/dist/components/deployment/TokenBalance.svelte +19 -0
- package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
- package/dist/components/deployment/TokenIOInput.svelte +25 -15
- 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 +184 -80
- package/dist/components/detail/OrderDetail.svelte.d.ts +21 -15
- package/dist/components/detail/TanstackOrderQuote.svelte +92 -46
- package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +14 -16
- package/dist/components/detail/VaultDetail.svelte +78 -77
- 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/DropdownOrderListAccounts.svelte +5 -2
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +2 -3
- package/dist/components/dropdown/DropdownOrderbooksFilter.svelte +172 -0
- package/dist/components/dropdown/DropdownOrderbooksFilter.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 +2 -1
- package/dist/components/icon/Refresh.svelte.d.ts +1 -0
- package/dist/components/input/InputOrderHash.svelte +1 -1
- package/dist/components/input/InputOrderHash.svelte.d.ts +3 -3
- package/dist/components/input/InputRegistryUrl.svelte +36 -14
- package/dist/components/input/InputToken.svelte +2 -2
- package/dist/components/input/InputTokenAmount.svelte +16 -21
- 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 +84 -81
- 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 +200 -108
- package/dist/components/tables/OrdersListTable.svelte.d.ts +17 -21
- package/dist/components/tables/VaultBalanceChangesTable.svelte +83 -43
- package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +13 -11
- package/dist/components/tables/VaultsListTable.svelte +268 -145
- package/dist/components/tables/VaultsListTable.svelte.d.ts +24 -32
- package/dist/components/transactions/FixedBottomTransaction.svelte +63 -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 +8 -2
- package/dist/errors/DeploymentStepsError.js +7 -1
- package/dist/hooks/useGui.d.ts +1 -1
- package/dist/hooks/useGui.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/index.d.ts +42 -19
- package/dist/index.js +41 -16
- package/dist/models/Transaction.d.ts +75 -0
- package/dist/models/Transaction.js +100 -0
- package/dist/providers/GuiProvider.svelte +1 -1
- package/dist/providers/GuiProvider.svelte.d.ts +1 -1
- 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/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 +40 -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 +133 -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 +235 -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 +1 -0
- package/dist/queries/queryClient.d.ts +1 -1
- package/dist/queries/queryClient.js +11 -6
- package/dist/services/awaitTransactionIndexing.d.ts +107 -0
- package/dist/services/awaitTransactionIndexing.js +58 -0
- package/dist/services/getExplorerLink.d.ts +1 -1
- package/dist/services/getExplorerLink.js +2 -4
- package/dist/services/handleShareChoices.d.ts +2 -2
- package/dist/services/handleShareChoices.js +7 -2
- package/dist/services/historicalOrderCharts.d.ts +2 -2
- package/dist/services/historicalOrderCharts.js +267 -333
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +2 -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 +190 -0
- package/dist/services/registry.d.ts +5 -5
- package/dist/services/registry.js +8 -208
- package/dist/services/time.d.ts +12 -0
- package/dist/services/time.js +88 -6
- package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
- package/dist/storesGeneric/cachedWritableStore.js +93 -0
- package/dist/types/account.d.ts +3 -0
- package/dist/types/appStores.d.ts +9 -14
- package/dist/types/modal.d.ts +26 -14
- package/dist/types/{strategy.d.ts → order.d.ts} +3 -3
- 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 +66 -21
- package/dist/types/transaction.js +31 -1
- 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 +115 -0
- package/dist/utils/getNetworkName.d.ts +1 -0
- package/dist/utils/getNetworkName.js +13 -0
- package/dist/utils/number.d.ts +0 -7
- package/dist/utils/number.js +0 -27
- 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 +39 -34
- 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/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/DropdownOrderStatus.svelte +0 -31
- package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
- package/dist/stores/transactionStore.d.ts +0 -98
- package/dist/stores/transactionStore.js +0 -303
- 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,100 @@
|
|
|
1
|
+
import { waitForTransactionReceipt } from '@wagmi/core';
|
|
2
|
+
import { TransactionStatusMessage, TransactionStoreErrorMessage } from '../types/transaction';
|
|
3
|
+
import { writable } from 'svelte/store';
|
|
4
|
+
/**
|
|
5
|
+
* Manages the lifecycle of an individual transaction, including waiting for
|
|
6
|
+
* blockchain confirmation (receipt) and subgraph indexing.
|
|
7
|
+
* It exposes its state as a Svelte writable store.
|
|
8
|
+
* @class TransactionStore
|
|
9
|
+
* @implements {Transaction}
|
|
10
|
+
*/
|
|
11
|
+
export class TransactionStore {
|
|
12
|
+
name;
|
|
13
|
+
config;
|
|
14
|
+
txHash;
|
|
15
|
+
links;
|
|
16
|
+
onSuccess;
|
|
17
|
+
onError;
|
|
18
|
+
// Optional indexing function called after receipt confirmation.
|
|
19
|
+
// TransactionStore doesn't know what this function does - it just calls it.
|
|
20
|
+
awaitIndexingFn;
|
|
21
|
+
state;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new TransactionStore instance.
|
|
24
|
+
* @param {TransactionArgs & { config: Config }} args - Configuration arguments for the transaction, including the wagmi `Config`.
|
|
25
|
+
* @param {() => void} onSuccess - Callback invoked when the transaction successfully completes (including indexing).
|
|
26
|
+
* @param {() => void} onError - Callback invoked if the transaction fails at any stage.
|
|
27
|
+
*/
|
|
28
|
+
constructor(args, onSuccess, onError) {
|
|
29
|
+
this.config = args.config;
|
|
30
|
+
this.txHash = args.txHash;
|
|
31
|
+
this.name = args.name;
|
|
32
|
+
this.links = args.toastLinks;
|
|
33
|
+
this.state = writable({
|
|
34
|
+
name: this.name,
|
|
35
|
+
status: TransactionStatusMessage.IDLE,
|
|
36
|
+
links: this.links
|
|
37
|
+
});
|
|
38
|
+
this.awaitIndexingFn = args.awaitIndexingFn;
|
|
39
|
+
this.onSuccess = onSuccess;
|
|
40
|
+
this.onError = onError;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Updates the internal Svelte store with new state values.
|
|
44
|
+
* @param {Partial<TransactionStoreState>} partialState - An object containing the state properties to update.
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
updateState(partialState) {
|
|
48
|
+
this.state.update((currentState) => ({
|
|
49
|
+
...currentState,
|
|
50
|
+
...partialState
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Executes the transaction and begins monitoring its status
|
|
55
|
+
* @returns {Promise<void>}
|
|
56
|
+
*/
|
|
57
|
+
async execute() {
|
|
58
|
+
this.updateState({
|
|
59
|
+
status: TransactionStatusMessage.PENDING_RECEIPT
|
|
60
|
+
});
|
|
61
|
+
await this.waitForTxReceipt(this.txHash);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Waits for the transaction receipt to be confirmed on the blockchain.
|
|
65
|
+
* If an indexing function is provided, it will be called after receipt confirmation.
|
|
66
|
+
* TransactionStore doesn't know what the indexing function does - it just calls it.
|
|
67
|
+
* @param {Hex} hash - The transaction hash to monitor
|
|
68
|
+
* @returns {Promise<void>}
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async waitForTxReceipt(hash) {
|
|
72
|
+
try {
|
|
73
|
+
await waitForTransactionReceipt(this.config, { hash });
|
|
74
|
+
if (this.awaitIndexingFn) {
|
|
75
|
+
// Call the indexing function with the context it needs.
|
|
76
|
+
// The function handles everything: updating state, calling callbacks, etc.
|
|
77
|
+
await this.awaitIndexingFn({
|
|
78
|
+
updateState: this.updateState.bind(this),
|
|
79
|
+
onSuccess: this.onSuccess,
|
|
80
|
+
onError: this.onError,
|
|
81
|
+
links: this.links
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// No indexing needed, mark as success immediately
|
|
86
|
+
this.updateState({
|
|
87
|
+
status: TransactionStatusMessage.SUCCESS
|
|
88
|
+
});
|
|
89
|
+
return this.onSuccess();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
this.updateState({
|
|
94
|
+
status: TransactionStatusMessage.ERROR,
|
|
95
|
+
errorDetails: TransactionStoreErrorMessage.RECEIPT_FAILED
|
|
96
|
+
});
|
|
97
|
+
return this.onError();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { setContext } from "svelte";
|
|
2
|
-
import { DotrainOrderGui } from "@rainlanguage/orderbook
|
|
2
|
+
import { DotrainOrderGui } from "@rainlanguage/orderbook";
|
|
3
3
|
import { GUI_CONTEXT_KEY } from "../hooks/useGui";
|
|
4
4
|
export let gui;
|
|
5
5
|
setContext(GUI_CONTEXT_KEY, gui);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { SQLiteWasmDatabase } from '@rainlanguage/sqlite-web';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
localDb: SQLiteWasmDatabase;
|
|
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 LocalDbProviderProps = typeof __propDef.props;
|
|
17
|
+
export type LocalDbProviderEvents = typeof __propDef.events;
|
|
18
|
+
export type LocalDbProviderSlots = typeof __propDef.slots;
|
|
19
|
+
export default class LocalDbProvider extends SvelteComponent<LocalDbProviderProps, LocalDbProviderEvents, LocalDbProviderSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<script>import { setContext } from "svelte";
|
|
2
|
+
import { RaindexClient } from "@rainlanguage/orderbook";
|
|
3
|
+
import { RAINDEX_CLIENT_CONTEXT_KEY } from "../hooks/useRaindexClient";
|
|
4
|
+
export let raindexClient;
|
|
5
|
+
setContext(RAINDEX_CLIENT_CONTEXT_KEY, raindexClient);
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<slot />
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { RaindexClient } from '@rainlanguage/orderbook';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
raindexClient: RaindexClient;
|
|
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 RaindexClientProviderProps = typeof __propDef.props;
|
|
17
|
+
export type RaindexClientProviderEvents = typeof __propDef.events;
|
|
18
|
+
export type RaindexClientProviderSlots = typeof __propDef.slots;
|
|
19
|
+
export default class RaindexClientProvider extends SvelteComponent<RaindexClientProviderProps, RaindexClientProviderEvents, RaindexClientProviderSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { DotrainRegistry } from '@rainlanguage/orderbook';
|
|
3
|
+
import type { RegistryManager } from '../registry/RegistryManager';
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
registry?: DotrainRegistry | null;
|
|
7
|
+
error: string | undefined;
|
|
8
|
+
manager: RegistryManager;
|
|
9
|
+
};
|
|
10
|
+
events: {
|
|
11
|
+
[evt: string]: CustomEvent<any>;
|
|
12
|
+
};
|
|
13
|
+
slots: {
|
|
14
|
+
default: {};
|
|
15
|
+
};
|
|
16
|
+
exports?: {} | undefined;
|
|
17
|
+
bindings?: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
export type DotrainRegistryProviderProps = typeof __propDef.props;
|
|
20
|
+
export type DotrainRegistryProviderEvents = typeof __propDef.events;
|
|
21
|
+
export type DotrainRegistryProviderSlots = typeof __propDef.slots;
|
|
22
|
+
export default class DotrainRegistryProvider extends SvelteComponent<DotrainRegistryProviderProps, DotrainRegistryProviderEvents, DotrainRegistryProviderSlots> {
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DotrainRegistry } from '@rainlanguage/orderbook';
|
|
2
|
+
import type { RegistryManager } from '../registry/RegistryManager';
|
|
3
|
+
export type DotrainRegistryContext = {
|
|
4
|
+
registry: DotrainRegistry | null;
|
|
5
|
+
error?: string;
|
|
6
|
+
manager: RegistryManager;
|
|
7
|
+
};
|
|
8
|
+
export declare const setDotrainRegistryContext: (context: DotrainRegistryContext) => void;
|
|
9
|
+
export declare const getDotrainRegistryContext: () => DotrainRegistryContext;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
const DOTRAIN_REGISTRY_CONTEXT_KEY = 'dotrain-registry-context';
|
|
3
|
+
export const setDotrainRegistryContext = (context) => {
|
|
4
|
+
setContext(DOTRAIN_REGISTRY_CONTEXT_KEY, context);
|
|
5
|
+
};
|
|
6
|
+
export const getDotrainRegistryContext = () => {
|
|
7
|
+
const ctx = getContext(DOTRAIN_REGISTRY_CONTEXT_KEY);
|
|
8
|
+
if (!ctx) {
|
|
9
|
+
throw new Error('Dotrain registry context not found. Did you forget to wrap your app in DotrainRegistryProvider?');
|
|
10
|
+
}
|
|
11
|
+
return ctx;
|
|
12
|
+
};
|
|
13
|
+
if (import.meta.vitest) {
|
|
14
|
+
const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
|
|
15
|
+
vi.mock('svelte', async (importOriginal) => ({
|
|
16
|
+
...(await importOriginal()),
|
|
17
|
+
getContext: vi.fn()
|
|
18
|
+
}));
|
|
19
|
+
describe('getDotrainRegistryContext', () => {
|
|
20
|
+
const mockGetContext = vi.mocked(getContext);
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
mockGetContext.mockReset();
|
|
23
|
+
});
|
|
24
|
+
it('should return the context when it exists', () => {
|
|
25
|
+
const mockCtx = { registry: null, manager: {} };
|
|
26
|
+
mockGetContext.mockImplementation((key) => {
|
|
27
|
+
if (key === DOTRAIN_REGISTRY_CONTEXT_KEY)
|
|
28
|
+
return mockCtx;
|
|
29
|
+
return undefined;
|
|
30
|
+
});
|
|
31
|
+
const result = getDotrainRegistryContext();
|
|
32
|
+
expect(mockGetContext).toHaveBeenCalledWith(DOTRAIN_REGISTRY_CONTEXT_KEY);
|
|
33
|
+
expect(result).toEqual(mockCtx);
|
|
34
|
+
});
|
|
35
|
+
it('should throw an error when context is not set', () => {
|
|
36
|
+
mockGetContext.mockReturnValue(undefined);
|
|
37
|
+
expect(() => getDotrainRegistryContext()).toThrow('Dotrain registry context not found. Did you forget to wrap your app in DotrainRegistryProvider?');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getDotrainRegistryContext } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to access the current Dotrain registry context.
|
|
4
|
+
*/
|
|
5
|
+
export function useDotrainRegistry() {
|
|
6
|
+
return getDotrainRegistryContext();
|
|
7
|
+
}
|
|
8
|
+
if (import.meta.vitest) {
|
|
9
|
+
const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
|
|
10
|
+
vi.mock('./context', () => ({
|
|
11
|
+
getDotrainRegistryContext: vi.fn()
|
|
12
|
+
}));
|
|
13
|
+
describe('useDotrainRegistry', () => {
|
|
14
|
+
const mockGetContext = vi.mocked(getDotrainRegistryContext);
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
mockGetContext.mockReset();
|
|
17
|
+
});
|
|
18
|
+
it('should return the registry context', () => {
|
|
19
|
+
const mockContext = {
|
|
20
|
+
registry: null,
|
|
21
|
+
manager: {
|
|
22
|
+
getCurrentRegistry: vi.fn().mockReturnValue(''),
|
|
23
|
+
setRegistry: vi.fn(),
|
|
24
|
+
resetToDefault: vi.fn(),
|
|
25
|
+
updateUrlWithRegistry: vi.fn(),
|
|
26
|
+
isCustomRegistry: vi.fn().mockReturnValue(false)
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
mockGetContext.mockReturnValue(mockContext);
|
|
30
|
+
const result = useDotrainRegistry();
|
|
31
|
+
expect(mockGetContext).toHaveBeenCalled();
|
|
32
|
+
expect(result).toEqual(mockContext);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -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,133 @@
|
|
|
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: ' + (error instanceof Error ? error.message : String(error)));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the currently active registry
|
|
74
|
+
* @returns The current registry URL, falling back to default if not set
|
|
75
|
+
*/
|
|
76
|
+
getCurrentRegistry() {
|
|
77
|
+
return this.currentRegistry ?? this.defaultRegistry;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Set the registry and update both localStorage and URL
|
|
81
|
+
* @param registry The new registry URL to set
|
|
82
|
+
*/
|
|
83
|
+
setRegistry(registry) {
|
|
84
|
+
this.currentRegistry = registry;
|
|
85
|
+
this.setRegistryToLocalStorage(registry);
|
|
86
|
+
this.updateUrlWithRegistry();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Reset to the default registry, clearing both localStorage and URL param
|
|
90
|
+
* @throws Error if localStorage is not available
|
|
91
|
+
*/
|
|
92
|
+
resetToDefault() {
|
|
93
|
+
this.currentRegistry = this.defaultRegistry;
|
|
94
|
+
try {
|
|
95
|
+
localStorage.removeItem(RegistryManager.STORAGE_KEY);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new Error('Failed to clear registry from localStorage: ' +
|
|
99
|
+
(error instanceof Error ? error.message : String(error)));
|
|
100
|
+
}
|
|
101
|
+
this.updateUrlWithRegistry(null);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Update the URL param to reflect the current or specified registry
|
|
105
|
+
* @param value The registry value to set in URL, defaults to current registry
|
|
106
|
+
* @throws Error if URL manipulation fails
|
|
107
|
+
*/
|
|
108
|
+
updateUrlWithRegistry(value = this.currentRegistry) {
|
|
109
|
+
try {
|
|
110
|
+
const url = new URL(window.location.href);
|
|
111
|
+
if (value) {
|
|
112
|
+
url.searchParams.set(RegistryManager.STORAGE_KEY, value);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
url.searchParams.delete(RegistryManager.STORAGE_KEY);
|
|
116
|
+
}
|
|
117
|
+
window.history.pushState({}, '', url.toString());
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new Error('Failed to update URL parameter: ' +
|
|
121
|
+
(error instanceof Error ? error.message : String(error)));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Check if the current registry is custom (different from the default)
|
|
126
|
+
* @returns True if using a non-default registry
|
|
127
|
+
*/
|
|
128
|
+
isCustomRegistry() {
|
|
129
|
+
return (this.currentRegistry !== undefined &&
|
|
130
|
+
this.currentRegistry !== null &&
|
|
131
|
+
this.currentRegistry !== this.defaultRegistry);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -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 {};
|