@rainlanguage/ui-components 0.0.1-alpha.226 → 0.0.1-alpha.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/__fixtures__/settings.yaml +1 -1
  2. package/dist/components/deployment/DeploymentSteps.svelte +3 -3
  3. package/dist/components/deployment/DeploymentTile.svelte +3 -3
  4. package/dist/components/deployment/InvalidOrdersSection.svelte +1 -1
  5. package/dist/components/deployment/ValidOrdersSection.svelte +3 -3
  6. package/dist/components/input/InputRainlangUrl.svelte +40 -0
  7. package/dist/components/input/InputRainlangUrl.svelte.d.ts +16 -0
  8. package/dist/index.d.ts +7 -7
  9. package/dist/index.js +6 -6
  10. package/dist/providers/dotrainRainlang/DotrainRainlangProvider.svelte +8 -0
  11. package/dist/providers/dotrainRainlang/DotrainRainlangProvider.svelte.d.ts +24 -0
  12. package/dist/providers/dotrainRainlang/context.d.ts +9 -0
  13. package/dist/providers/{dotrainRegistry → dotrainRainlang}/context.js +12 -12
  14. package/dist/providers/dotrainRainlang/useDotrainRainlang.d.ts +5 -0
  15. package/dist/providers/dotrainRainlang/useDotrainRainlang.js +35 -0
  16. package/dist/providers/rainlang/RainlangManager.d.ts +65 -0
  17. package/dist/providers/rainlang/RainlangManager.js +133 -0
  18. package/dist/providers/rainlang/RainlangProvider.svelte +6 -0
  19. package/dist/providers/rainlang/RainlangProvider.svelte.d.ts +21 -0
  20. package/dist/providers/rainlang/context.d.ts +10 -0
  21. package/dist/providers/rainlang/context.js +46 -0
  22. package/dist/providers/rainlang/useRainlang.d.ts +7 -0
  23. package/dist/providers/rainlang/useRainlang.js +29 -0
  24. package/dist/services/handleShareChoices.d.ts +1 -1
  25. package/dist/services/handleShareChoices.js +2 -2
  26. package/dist/services/index.d.ts +3 -3
  27. package/dist/services/index.js +2 -2
  28. package/dist/services/loadRainlangUrl.d.ts +2 -0
  29. package/dist/services/loadRainlangUrl.js +22 -0
  30. package/dist/services/{registry.d.ts → rainlang.d.ts} +10 -10
  31. package/dist/services/{registry.js → rainlang.js} +15 -15
  32. package/package.json +2 -2
  33. package/dist/components/input/InputRegistryUrl.svelte +0 -40
  34. package/dist/components/input/InputRegistryUrl.svelte.d.ts +0 -16
  35. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte +0 -8
  36. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +0 -24
  37. package/dist/providers/dotrainRegistry/context.d.ts +0 -9
  38. package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +0 -5
  39. package/dist/providers/dotrainRegistry/useDotrainRegistry.js +0 -35
  40. package/dist/providers/registry/RegistryManager.d.ts +0 -65
  41. package/dist/providers/registry/RegistryManager.js +0 -133
  42. package/dist/providers/registry/RegistryProvider.svelte +0 -6
  43. package/dist/providers/registry/RegistryProvider.svelte.d.ts +0 -21
  44. package/dist/providers/registry/context.d.ts +0 -10
  45. package/dist/providers/registry/context.js +0 -46
  46. package/dist/providers/registry/useRegistry.d.ts +0 -7
  47. package/dist/providers/registry/useRegistry.js +0 -29
  48. package/dist/services/loadRegistryUrl.d.ts +0 -2
  49. package/dist/services/loadRegistryUrl.js +0 -22
@@ -0,0 +1,46 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ export const RAINLANG_KEY = 'rainlang_key';
3
+ /**
4
+ * Retrieves the rainlang manager directly from Svelte's context
5
+ */
6
+ export const getRainlangContext = () => {
7
+ const rainlang = getContext(RAINLANG_KEY);
8
+ if (!rainlang) {
9
+ throw new Error('No rainlang manager was found in Svelte context. Did you forget to wrap your component with RainlangProvider?');
10
+ }
11
+ return rainlang;
12
+ };
13
+ /**
14
+ * Sets the rainlang manager in Svelte's context
15
+ */
16
+ export const setRainlangContext = (rainlang) => {
17
+ setContext(RAINLANG_KEY, rainlang);
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('getRainlangContext', () => {
26
+ const mockGetContext = vi.mocked(getContext);
27
+ beforeEach(() => {
28
+ mockGetContext.mockReset();
29
+ });
30
+ it('should return the rainlang from context when it exists', () => {
31
+ const mockRainlang = {};
32
+ mockGetContext.mockImplementation((key) => {
33
+ if (key === RAINLANG_KEY)
34
+ return mockRainlang;
35
+ return undefined;
36
+ });
37
+ const result = getRainlangContext();
38
+ expect(mockGetContext).toHaveBeenCalledWith(RAINLANG_KEY);
39
+ expect(result).toEqual(mockRainlang);
40
+ });
41
+ it('should throw an error when rainlang is not in context', () => {
42
+ mockGetContext.mockReturnValue(undefined);
43
+ expect(() => getRainlangContext()).toThrow('No rainlang manager was found in Svelte context. Did you forget to wrap your component with RainlangProvider?');
44
+ });
45
+ });
46
+ }
@@ -0,0 +1,7 @@
1
+ import type { RainlangManager } from './RainlangManager';
2
+ /**
3
+ * Hook to access rainlang manager information from context
4
+ * Must be used within a component that is a child of RainlangProvider
5
+ * @returns An object containing the rainlang manager
6
+ */
7
+ export declare function useRainlang(): RainlangManager;
@@ -0,0 +1,29 @@
1
+ import { getRainlangContext } from './context';
2
+ /**
3
+ * Hook to access rainlang manager information from context
4
+ * Must be used within a component that is a child of RainlangProvider
5
+ * @returns An object containing the rainlang manager
6
+ */
7
+ export function useRainlang() {
8
+ const rainlang = getRainlangContext();
9
+ return rainlang;
10
+ }
11
+ if (import.meta.vitest) {
12
+ const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
13
+ vi.mock('./context', () => ({
14
+ getRainlangContext: vi.fn()
15
+ }));
16
+ describe('useRainlang', () => {
17
+ const mockGetRainlangContext = vi.mocked(getRainlangContext);
18
+ beforeEach(() => {
19
+ mockGetRainlangContext.mockReset();
20
+ });
21
+ it('should return rainlang', () => {
22
+ const mockRainlang = {};
23
+ mockGetRainlangContext.mockReturnValue(mockRainlang);
24
+ const result = useRainlang();
25
+ expect(mockGetRainlangContext).toHaveBeenCalled();
26
+ expect(result).toEqual(mockRainlang);
27
+ });
28
+ });
29
+ }
@@ -1,2 +1,2 @@
1
1
  import type { DotrainOrderGui } from '@rainlanguage/orderbook';
2
- export declare function handleShareChoices(gui: DotrainOrderGui, registryUrl: string): Promise<void>;
2
+ export declare function handleShareChoices(gui: DotrainOrderGui, rainlangUrl: string): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { page } from '$app/stores';
2
2
  import { get } from 'svelte/store';
3
- export async function handleShareChoices(gui, registryUrl) {
3
+ export async function handleShareChoices(gui, rainlangUrl) {
4
4
  // get the current url
5
5
  const url = get(page).url;
6
6
  // get the current state
@@ -10,6 +10,6 @@ export async function handleShareChoices(gui, registryUrl) {
10
10
  }
11
11
  const state = result.value;
12
12
  url.searchParams.set('state', state || '');
13
- url.searchParams.set('registry', registryUrl);
13
+ url.searchParams.set('rainlang', rainlangUrl);
14
14
  navigator.clipboard.writeText(url.toString());
15
15
  }
@@ -1,3 +1,3 @@
1
- export { fetchParseRegistry, fetchRegistryDotrains, validateOrders } from './registry';
2
- export { loadRegistryUrl } from './loadRegistryUrl';
3
- export type { RegistryDotrain, RegistryFile } from './registry';
1
+ export { fetchParseRainlang, fetchRainlangDotrains, validateOrders } from './rainlang';
2
+ export { loadRainlangUrl } from './loadRainlangUrl';
3
+ export type { RainlangDotrain, RainlangFile } from './rainlang';
@@ -1,2 +1,2 @@
1
- export { fetchParseRegistry, fetchRegistryDotrains, validateOrders } from './registry';
2
- export { loadRegistryUrl } from './loadRegistryUrl';
1
+ export { fetchParseRainlang, fetchRainlangDotrains, validateOrders } from './rainlang';
2
+ export { loadRainlangUrl } from './loadRainlangUrl';
@@ -0,0 +1,2 @@
1
+ import { RainlangManager } from '../providers/rainlang/RainlangManager';
2
+ export declare function loadRainlangUrl(url: string, rainlangManager: RainlangManager): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { RainlangManager } from '../providers/rainlang/RainlangManager';
2
+ import { DotrainRainlang } from '@rainlanguage/orderbook';
3
+ export async function loadRainlangUrl(url, rainlangManager) {
4
+ if (!url) {
5
+ throw new Error('No URL provided');
6
+ }
7
+ if (!rainlangManager) {
8
+ throw new Error('Rainlang manager is required');
9
+ }
10
+ try {
11
+ const validationResult = await DotrainRainlang.validate(url);
12
+ if (validationResult.error) {
13
+ throw new Error(validationResult.error.readableMsg);
14
+ }
15
+ rainlangManager.setRainlang(url);
16
+ window.location.reload();
17
+ }
18
+ catch (e) {
19
+ const errorMessage = e instanceof Error ? e.message : 'Failed to update rainlang URL';
20
+ throw new Error(errorMessage);
21
+ }
22
+ }
@@ -1,9 +1,9 @@
1
1
  import type { InvalidOrderDetail, ValidOrderDetail } from '../types/order';
2
- export type RegistryFile = {
2
+ export type RainlangFile = {
3
3
  name: string;
4
4
  url: string;
5
5
  };
6
- export type RegistryDotrain = {
6
+ export type RainlangDotrain = {
7
7
  name: string;
8
8
  dotrain: string;
9
9
  };
@@ -12,20 +12,20 @@ export interface OrderValidationResult {
12
12
  invalidOrders: InvalidOrderDetail[];
13
13
  }
14
14
  /**
15
- * Fetches and parses a file registry from a given URL.
16
- * The registry is expected to be a text file where each line contains a file name and URL separated by a space.
15
+ * Fetches and parses a file rainlang from a given URL.
16
+ * The rainlang is expected to be a text file where each line contains a file name and URL separated by a space.
17
17
  *
18
- * @param url - The URL of the registry file to fetch
18
+ * @param url - The URL of the rainlang file to fetch
19
19
  * @returns A Promise that resolves to an array of objects containing file names and their corresponding URLs
20
- * @throws Will throw an error if the fetch fails, if the response is not ok, or if the registry format is invalid
20
+ * @throws Will throw an error if the fetch fails, if the response is not ok, or if the rainlang format is invalid
21
21
  *
22
22
  * @example
23
- * const files = await fetchParseRegistryFile('https://example.com/registry');
23
+ * const files = await fetchParseRainlangFile('https://example.com/rainlang');
24
24
  * // Returns: [{ name: 'file1', url: 'https://example.com/file1.rain' }, ...]
25
25
  */
26
- export declare const fetchParseRegistry: (url: string) => Promise<{
26
+ export declare const fetchParseRainlang: (url: string) => Promise<{
27
27
  name: string;
28
28
  url: string;
29
29
  }[]>;
30
- export declare const fetchRegistryDotrains: (url: string) => Promise<RegistryDotrain[]>;
31
- export declare function validateOrders(registryDotrains: RegistryDotrain[]): Promise<OrderValidationResult>;
30
+ export declare const fetchRainlangDotrains: (url: string) => Promise<RainlangDotrain[]>;
31
+ export declare function validateOrders(rainlangDotrains: RainlangDotrain[]): Promise<OrderValidationResult>;
@@ -1,21 +1,21 @@
1
1
  import { DotrainOrderGui } from '@rainlanguage/orderbook';
2
2
  /**
3
- * Fetches and parses a file registry from a given URL.
4
- * The registry is expected to be a text file where each line contains a file name and URL separated by a space.
3
+ * Fetches and parses a file rainlang from a given URL.
4
+ * The rainlang is expected to be a text file where each line contains a file name and URL separated by a space.
5
5
  *
6
- * @param url - The URL of the registry file to fetch
6
+ * @param url - The URL of the rainlang file to fetch
7
7
  * @returns A Promise that resolves to an array of objects containing file names and their corresponding URLs
8
- * @throws Will throw an error if the fetch fails, if the response is not ok, or if the registry format is invalid
8
+ * @throws Will throw an error if the fetch fails, if the response is not ok, or if the rainlang format is invalid
9
9
  *
10
10
  * @example
11
- * const files = await fetchParseRegistryFile('https://example.com/registry');
11
+ * const files = await fetchParseRainlangFile('https://example.com/rainlang');
12
12
  * // Returns: [{ name: 'file1', url: 'https://example.com/file1.rain' }, ...]
13
13
  */
14
- export const fetchParseRegistry = async (url) => {
14
+ export const fetchParseRainlang = async (url) => {
15
15
  try {
16
16
  const response = await fetch(url);
17
17
  if (!response.ok) {
18
- throw new Error('Failed to fetch registry.');
18
+ throw new Error('Failed to fetch rainlang.');
19
19
  }
20
20
  const filesList = await response.text();
21
21
  const files = filesList
@@ -26,7 +26,7 @@ export const fetchParseRegistry = async (url) => {
26
26
  return { name, url };
27
27
  });
28
28
  if (!files) {
29
- throw new Error('Invalid stategy registry.');
29
+ throw new Error('Invalid stategy rainlang.');
30
30
  }
31
31
  return files;
32
32
  }
@@ -34,8 +34,8 @@ export const fetchParseRegistry = async (url) => {
34
34
  throw new Error(e instanceof Error ? e.message : 'Unknown error.');
35
35
  }
36
36
  };
37
- export const fetchRegistryDotrains = async (url) => {
38
- const files = await fetchParseRegistry(url);
37
+ export const fetchRainlangDotrains = async (url) => {
38
+ const files = await fetchParseRainlang(url);
39
39
  const dotrains = await Promise.all(files.map(async (file) => {
40
40
  try {
41
41
  const response = await fetch(file.url);
@@ -53,17 +53,17 @@ export const fetchRegistryDotrains = async (url) => {
53
53
  }));
54
54
  return dotrains;
55
55
  };
56
- export async function validateOrders(registryDotrains) {
57
- const ordersPromises = registryDotrains.map(async (registryDotrain) => {
56
+ export async function validateOrders(rainlangDotrains) {
57
+ const ordersPromises = rainlangDotrains.map(async (rainlangDotrain) => {
58
58
  try {
59
- const result = await DotrainOrderGui.getOrderDetails(registryDotrain.dotrain);
59
+ const result = await DotrainOrderGui.getOrderDetails(rainlangDotrain.dotrain);
60
60
  if (result.error) {
61
61
  throw new Error(result.error.msg);
62
62
  }
63
63
  return {
64
64
  valid: true,
65
65
  data: {
66
- ...registryDotrain,
66
+ ...rainlangDotrain,
67
67
  details: result.value
68
68
  }
69
69
  };
@@ -72,7 +72,7 @@ export async function validateOrders(registryDotrains) {
72
72
  return {
73
73
  valid: false,
74
74
  data: {
75
- name: registryDotrain.name,
75
+ name: rainlangDotrain.name,
76
76
  error: error instanceof Error ? error.message : String(error)
77
77
  }
78
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainlanguage/ui-components",
3
- "version": "0.0.1-alpha.226",
3
+ "version": "0.0.1-alpha.227",
4
4
  "description": "A component library for building Svelte applications to be used with Raindex.",
5
5
  "license": "LicenseRef-DCL-1.0",
6
6
  "author": "Rain Open Source Software Ltd",
@@ -57,7 +57,7 @@
57
57
  "@fontsource/dm-sans": "5.1.0",
58
58
  "@imask/svelte": "7.6.1",
59
59
  "@observablehq/plot": "0.6.16",
60
- "@rainlanguage/orderbook": "0.0.1-alpha.226",
60
+ "@rainlanguage/orderbook": "0.0.1-alpha.227",
61
61
  "@reown/appkit": "1.6.4",
62
62
  "@reown/appkit-adapter-wagmi": "1.6.4",
63
63
  "@sentry/sveltekit": "7.120.0",
@@ -1,40 +0,0 @@
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>
@@ -1,16 +0,0 @@
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 {};
@@ -1,8 +0,0 @@
1
- <script>import { setDotrainRegistryContext } from "./context";
2
- export let registry = null;
3
- export let error;
4
- export let manager;
5
- $: setDotrainRegistryContext({ registry, error, manager });
6
- </script>
7
-
8
- <slot />
@@ -1,24 +0,0 @@
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 {};
@@ -1,9 +0,0 @@
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,5 +0,0 @@
1
- import { type DotrainRegistryContext } from './context';
2
- /**
3
- * Hook to access the current Dotrain registry context.
4
- */
5
- export declare function useDotrainRegistry(): DotrainRegistryContext;
@@ -1,35 +0,0 @@
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
- }
@@ -1,65 +0,0 @@
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
- }
@@ -1,133 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- <script>import { setRegistryContext } from "./context";
2
- export let registryManager;
3
- setRegistryContext(registryManager);
4
- </script>
5
-
6
- <slot />
@@ -1,21 +0,0 @@
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 {};