@rainlanguage/ui-components 0.0.1-alpha.229 → 0.0.1-alpha.230
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/components/deployment/DeploymentSteps.svelte +3 -3
- package/dist/components/deployment/DeploymentTile.svelte +3 -3
- package/dist/components/deployment/ValidOrdersSection.svelte +3 -3
- package/dist/components/input/InputRegistryUrl.svelte +40 -0
- package/dist/components/input/InputRegistryUrl.svelte.d.ts +16 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +6 -6
- 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/{dotrainRainlang → dotrainRegistry}/context.js +12 -12
- 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/services/handleShareChoices.d.ts +1 -1
- package/dist/services/handleShareChoices.js +2 -2
- package/dist/services/index.d.ts +3 -3
- package/dist/services/index.js +2 -2
- package/dist/services/loadRegistryUrl.d.ts +2 -0
- package/dist/services/loadRegistryUrl.js +22 -0
- package/dist/services/{rainlang.d.ts → registry.d.ts} +10 -10
- package/dist/services/{rainlang.js → registry.js} +15 -15
- package/package.json +3 -3
- package/dist/components/input/InputRainlangUrl.svelte +0 -40
- package/dist/components/input/InputRainlangUrl.svelte.d.ts +0 -16
- package/dist/providers/dotrainRainlang/DotrainRainlangProvider.svelte +0 -8
- package/dist/providers/dotrainRainlang/DotrainRainlangProvider.svelte.d.ts +0 -24
- package/dist/providers/dotrainRainlang/context.d.ts +0 -9
- package/dist/providers/dotrainRainlang/useDotrainRainlang.d.ts +0 -5
- package/dist/providers/dotrainRainlang/useDotrainRainlang.js +0 -35
- package/dist/providers/rainlang/RainlangManager.d.ts +0 -65
- package/dist/providers/rainlang/RainlangManager.js +0 -133
- package/dist/providers/rainlang/RainlangProvider.svelte +0 -6
- package/dist/providers/rainlang/RainlangProvider.svelte.d.ts +0 -21
- package/dist/providers/rainlang/context.d.ts +0 -10
- package/dist/providers/rainlang/context.js +0 -46
- package/dist/providers/rainlang/useRainlang.d.ts +0 -7
- package/dist/providers/rainlang/useRainlang.js +0 -29
- package/dist/services/loadRainlangUrl.d.ts +0 -2
- package/dist/services/loadRainlangUrl.js +0 -22
|
@@ -19,7 +19,7 @@ import DeploymentSectionHeader from "./DeploymentSectionHeader.svelte";
|
|
|
19
19
|
import { useGui } from "../../hooks/useGui";
|
|
20
20
|
import { fade } from "svelte/transition";
|
|
21
21
|
import ShareChoicesButton from "./ShareChoicesButton.svelte";
|
|
22
|
-
import {
|
|
22
|
+
import { useRegistry } from "../../providers/registry/useRegistry";
|
|
23
23
|
import { useRaindexClient } from "../../hooks/useRaindexClient";
|
|
24
24
|
export let deployment;
|
|
25
25
|
export let orderDetail;
|
|
@@ -39,7 +39,7 @@ let selectTokens = void 0;
|
|
|
39
39
|
let checkingDeployment = false;
|
|
40
40
|
let tokenBalances = /* @__PURE__ */ new Map();
|
|
41
41
|
const gui = useGui();
|
|
42
|
-
const
|
|
42
|
+
const registry = useRegistry();
|
|
43
43
|
const raindexClient = useRaindexClient();
|
|
44
44
|
let deploymentStepsError = DeploymentStepsError.error;
|
|
45
45
|
onMount(async () => {
|
|
@@ -93,7 +93,7 @@ function updateFields() {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
async function _handleShareChoices() {
|
|
96
|
-
await handleShareChoices(gui,
|
|
96
|
+
await handleShareChoices(gui, registry.getCurrentRegistry());
|
|
97
97
|
}
|
|
98
98
|
async function fetchTokenBalance(tokenInfo) {
|
|
99
99
|
if (!$account) return;
|
|
@@ -4,14 +4,14 @@ export let orderName;
|
|
|
4
4
|
export let key;
|
|
5
5
|
export let name;
|
|
6
6
|
export let description;
|
|
7
|
-
let
|
|
7
|
+
let customRegistryParam = "";
|
|
8
8
|
onMount(async () => {
|
|
9
|
-
|
|
9
|
+
customRegistryParam = $page.url.searchParams.get("registry") ? `?registry=${$page.url.searchParams.get("registry")}` : "";
|
|
10
10
|
});
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
13
|
<a
|
|
14
|
-
href={`/deploy/${orderName}/${key}${
|
|
14
|
+
href={`/deploy/${orderName}/${key}${customRegistryParam}`}
|
|
15
15
|
class="flex h-full w-full max-w-sm cursor-pointer flex-col gap-y-4 rounded-3xl border border-gray-200 bg-white p-4 text-left hover:bg-gray-100 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700"
|
|
16
16
|
>
|
|
17
17
|
<h1 class="text-2xl font-semibold text-gray-900 dark:text-white">{name}</h1>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<script>import { onMount } from "svelte";
|
|
2
2
|
import { page } from "$app/stores";
|
|
3
3
|
export let orders;
|
|
4
|
-
let
|
|
4
|
+
let customRegistryParam = "";
|
|
5
5
|
onMount(async () => {
|
|
6
|
-
|
|
6
|
+
customRegistryParam = $page.url.searchParams.get("registry") ? `?registry=${$page.url.searchParams.get("registry")}` : "";
|
|
7
7
|
});
|
|
8
8
|
</script>
|
|
9
9
|
|
|
10
10
|
<div class="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3" data-testid="valid-orders">
|
|
11
11
|
{#each orders as order}
|
|
12
12
|
<a
|
|
13
|
-
href={`/deploy/${order.name}${
|
|
13
|
+
href={`/deploy/${order.name}${customRegistryParam}`}
|
|
14
14
|
data-testid="order-short-tile"
|
|
15
15
|
class="flex flex-col gap-y-2 rounded-xl border border-gray-200 p-4 hover:bg-gray-50 dark:border-gray-800 dark:hover:bg-gray-900"
|
|
16
16
|
>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script>import { Button, Input } from "flowbite-svelte";
|
|
2
|
+
import { useRegistry } from "../../providers/registry/useRegistry";
|
|
3
|
+
import { loadRegistryUrl } from "../../services/loadRegistryUrl";
|
|
4
|
+
const registry = useRegistry();
|
|
5
|
+
let newRegistryUrl = registry.getCurrentRegistry();
|
|
6
|
+
let error = null;
|
|
7
|
+
let loading = false;
|
|
8
|
+
async function handleClick() {
|
|
9
|
+
loading = true;
|
|
10
|
+
error = null;
|
|
11
|
+
try {
|
|
12
|
+
if (!registry) {
|
|
13
|
+
throw new Error("Registry manager not yet available.");
|
|
14
|
+
}
|
|
15
|
+
await loadRegistryUrl(newRegistryUrl, registry);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
error = err instanceof Error ? err.message : "Unknown error";
|
|
18
|
+
}
|
|
19
|
+
loading = false;
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<div class="flex w-full flex-col items-end gap-2">
|
|
24
|
+
<div class="flex w-full items-start gap-4" data-testid="registry-input">
|
|
25
|
+
<Input
|
|
26
|
+
id="order-url"
|
|
27
|
+
type="url"
|
|
28
|
+
placeholder="Enter URL to raw order registry file"
|
|
29
|
+
bind:value={newRegistryUrl}
|
|
30
|
+
/>
|
|
31
|
+
<Button class="w-36 text-nowrap" on:click={handleClick} disabled={loading}>
|
|
32
|
+
{loading ? 'Loading registry...' : 'Load registry URL'}
|
|
33
|
+
</Button>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="h-4">
|
|
36
|
+
{#if error}
|
|
37
|
+
<p data-testid="registry-error" class="text-red-500">{error}</p>
|
|
38
|
+
{/if}
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
exports?: {} | undefined;
|
|
9
|
+
bindings?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type InputRegistryUrlProps = typeof __propDef.props;
|
|
12
|
+
export type InputRegistryUrlEvents = typeof __propDef.events;
|
|
13
|
+
export type InputRegistryUrlSlots = typeof __propDef.slots;
|
|
14
|
+
export default class InputRegistryUrl extends SvelteComponent<InputRegistryUrlProps, InputRegistryUrlEvents, InputRegistryUrlSlots> {
|
|
15
|
+
}
|
|
16
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export { default as WalletConnect } from './components/wallet/WalletConnect.svel
|
|
|
66
66
|
export { default as DisclaimerModal } from './components/deployment/DisclaimerModal.svelte';
|
|
67
67
|
export { default as InvalidOrdersSection } from './components/deployment/InvalidOrdersSection.svelte';
|
|
68
68
|
export { default as ValidOrdersSection } from './components/deployment/ValidOrdersSection.svelte';
|
|
69
|
-
export { default as
|
|
69
|
+
export { default as InputRegistryUrl } from './components/input/InputRegistryUrl.svelte';
|
|
70
70
|
export { default as TransactionList } from './components/transactions/TransactionList.svelte';
|
|
71
71
|
export { default as FixedBottomTransaction } from './components/transactions/FixedBottomTransaction.svelte';
|
|
72
72
|
export { default as LocalDbStatusCard } from './components/LocalDbStatusCard.svelte';
|
|
@@ -77,7 +77,7 @@ export { TransactionStatusMessage, TransactionStoreErrorMessage, type Transactio
|
|
|
77
77
|
export type { VaultActionModalProps, QuoteDebugModalHandler, DebugTradeModalHandler, DisclaimerModalProps, TransactionConfirmationProps, HandleTransactionConfirmationModal } from './types/modal';
|
|
78
78
|
export type { ValidOrderDetail, InvalidOrderDetail } from './types/order.ts';
|
|
79
79
|
export type { ToastProps } from './types/toast';
|
|
80
|
-
export type {
|
|
80
|
+
export type { DotrainRegistryContext } from './providers/dotrainRegistry/context';
|
|
81
81
|
export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks__/queries';
|
|
82
82
|
export { formatTimestampSecondsAsLocal, timestampSecondsToUTCTimestamp, promiseTimeout } from './services/time';
|
|
83
83
|
export { bigintStringToHex, HEX_INPUT_REGEX } from './utils/hex';
|
|
@@ -95,20 +95,20 @@ export { default as logoDark } from './assets/logo-dark.svg';
|
|
|
95
95
|
export { default as GuiProvider } from './providers/GuiProvider.svelte';
|
|
96
96
|
export { default as RaindexClientProvider } from './providers/RaindexClientProvider.svelte';
|
|
97
97
|
export { default as WalletProvider } from './providers/wallet/WalletProvider.svelte';
|
|
98
|
-
export { default as
|
|
98
|
+
export { default as RegistryProvider } from './providers/registry/RegistryProvider.svelte';
|
|
99
99
|
export { default as ToastProvider } from './providers/toasts/ToastProvider.svelte';
|
|
100
100
|
export { default as TransactionProvider } from './providers/transactions/TransactionProvider.svelte';
|
|
101
101
|
export { default as LocalDbProvider } from './providers/LocalDbProvider.svelte';
|
|
102
|
-
export { default as
|
|
102
|
+
export { default as DotrainRegistryProvider } from './providers/dotrainRegistry/DotrainRegistryProvider.svelte';
|
|
103
103
|
export { useGui } from './hooks/useGui';
|
|
104
104
|
export { useRaindexClient, RAINDEX_CLIENT_CONTEXT_KEY } from './hooks/useRaindexClient';
|
|
105
105
|
export { useLocalDb } from './hooks/useLocalDb';
|
|
106
106
|
export { useAccount } from './providers/wallet/useAccount';
|
|
107
|
-
export {
|
|
107
|
+
export { useRegistry } from './providers/registry/useRegistry';
|
|
108
108
|
export { useToasts } from './providers/toasts/useToasts';
|
|
109
109
|
export { useTransactions } from './providers/transactions/useTransactions';
|
|
110
|
-
export {
|
|
111
|
-
export {
|
|
110
|
+
export { useDotrainRegistry } from './providers/dotrainRegistry/useDotrainRegistry';
|
|
111
|
+
export { RegistryManager } from './providers/registry/RegistryManager';
|
|
112
112
|
export { TransactionStore } from './models/Transaction';
|
|
113
113
|
export { TransactionManager } from './providers/transactions/TransactionManager';
|
|
114
114
|
export { mockPageStore } from './__mocks__/stores';
|
package/dist/index.js
CHANGED
|
@@ -67,7 +67,7 @@ export { default as WalletConnect } from './components/wallet/WalletConnect.svel
|
|
|
67
67
|
export { default as DisclaimerModal } from './components/deployment/DisclaimerModal.svelte';
|
|
68
68
|
export { default as InvalidOrdersSection } from './components/deployment/InvalidOrdersSection.svelte';
|
|
69
69
|
export { default as ValidOrdersSection } from './components/deployment/ValidOrdersSection.svelte';
|
|
70
|
-
export { default as
|
|
70
|
+
export { default as InputRegistryUrl } from './components/input/InputRegistryUrl.svelte';
|
|
71
71
|
export { default as TransactionList } from './components/transactions/TransactionList.svelte';
|
|
72
72
|
export { default as FixedBottomTransaction } from './components/transactions/FixedBottomTransaction.svelte';
|
|
73
73
|
export { default as LocalDbStatusCard } from './components/LocalDbStatusCard.svelte';
|
|
@@ -96,22 +96,22 @@ export { default as logoDark } from './assets/logo-dark.svg';
|
|
|
96
96
|
export { default as GuiProvider } from './providers/GuiProvider.svelte';
|
|
97
97
|
export { default as RaindexClientProvider } from './providers/RaindexClientProvider.svelte';
|
|
98
98
|
export { default as WalletProvider } from './providers/wallet/WalletProvider.svelte';
|
|
99
|
-
export { default as
|
|
99
|
+
export { default as RegistryProvider } from './providers/registry/RegistryProvider.svelte';
|
|
100
100
|
export { default as ToastProvider } from './providers/toasts/ToastProvider.svelte';
|
|
101
101
|
export { default as TransactionProvider } from './providers/transactions/TransactionProvider.svelte';
|
|
102
102
|
export { default as LocalDbProvider } from './providers/LocalDbProvider.svelte';
|
|
103
|
-
export { default as
|
|
103
|
+
export { default as DotrainRegistryProvider } from './providers/dotrainRegistry/DotrainRegistryProvider.svelte';
|
|
104
104
|
// Hooks
|
|
105
105
|
export { useGui } from './hooks/useGui';
|
|
106
106
|
export { useRaindexClient, RAINDEX_CLIENT_CONTEXT_KEY } from './hooks/useRaindexClient';
|
|
107
107
|
export { useLocalDb } from './hooks/useLocalDb';
|
|
108
108
|
export { useAccount } from './providers/wallet/useAccount';
|
|
109
|
-
export {
|
|
109
|
+
export { useRegistry } from './providers/registry/useRegistry';
|
|
110
110
|
export { useToasts } from './providers/toasts/useToasts';
|
|
111
111
|
export { useTransactions } from './providers/transactions/useTransactions';
|
|
112
|
-
export {
|
|
112
|
+
export { useDotrainRegistry } from './providers/dotrainRegistry/useDotrainRegistry';
|
|
113
113
|
// Classes
|
|
114
|
-
export {
|
|
114
|
+
export { RegistryManager } from './providers/registry/RegistryManager';
|
|
115
115
|
export { TransactionStore } from './models/Transaction';
|
|
116
116
|
export { TransactionManager } from './providers/transactions/TransactionManager';
|
|
117
117
|
// Mocks
|
|
@@ -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;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte';
|
|
2
|
-
const
|
|
3
|
-
export const
|
|
4
|
-
setContext(
|
|
2
|
+
const DOTRAIN_REGISTRY_CONTEXT_KEY = 'dotrain-registry-context';
|
|
3
|
+
export const setDotrainRegistryContext = (context) => {
|
|
4
|
+
setContext(DOTRAIN_REGISTRY_CONTEXT_KEY, context);
|
|
5
5
|
};
|
|
6
|
-
export const
|
|
7
|
-
const ctx = getContext(
|
|
6
|
+
export const getDotrainRegistryContext = () => {
|
|
7
|
+
const ctx = getContext(DOTRAIN_REGISTRY_CONTEXT_KEY);
|
|
8
8
|
if (!ctx) {
|
|
9
|
-
throw new Error('Dotrain
|
|
9
|
+
throw new Error('Dotrain registry context not found. Did you forget to wrap your app in DotrainRegistryProvider?');
|
|
10
10
|
}
|
|
11
11
|
return ctx;
|
|
12
12
|
};
|
|
@@ -16,25 +16,25 @@ if (import.meta.vitest) {
|
|
|
16
16
|
...(await importOriginal()),
|
|
17
17
|
getContext: vi.fn()
|
|
18
18
|
}));
|
|
19
|
-
describe('
|
|
19
|
+
describe('getDotrainRegistryContext', () => {
|
|
20
20
|
const mockGetContext = vi.mocked(getContext);
|
|
21
21
|
beforeEach(() => {
|
|
22
22
|
mockGetContext.mockReset();
|
|
23
23
|
});
|
|
24
24
|
it('should return the context when it exists', () => {
|
|
25
|
-
const mockCtx = {
|
|
25
|
+
const mockCtx = { registry: null, manager: {} };
|
|
26
26
|
mockGetContext.mockImplementation((key) => {
|
|
27
|
-
if (key ===
|
|
27
|
+
if (key === DOTRAIN_REGISTRY_CONTEXT_KEY)
|
|
28
28
|
return mockCtx;
|
|
29
29
|
return undefined;
|
|
30
30
|
});
|
|
31
|
-
const result =
|
|
32
|
-
expect(mockGetContext).toHaveBeenCalledWith(
|
|
31
|
+
const result = getDotrainRegistryContext();
|
|
32
|
+
expect(mockGetContext).toHaveBeenCalledWith(DOTRAIN_REGISTRY_CONTEXT_KEY);
|
|
33
33
|
expect(result).toEqual(mockCtx);
|
|
34
34
|
});
|
|
35
35
|
it('should throw an error when context is not set', () => {
|
|
36
36
|
mockGetContext.mockReturnValue(undefined);
|
|
37
|
-
expect(() =>
|
|
37
|
+
expect(() => getDotrainRegistryContext()).toThrow('Dotrain registry context not found. Did you forget to wrap your app in DotrainRegistryProvider?');
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
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;
|