@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.
Files changed (47) hide show
  1. package/dist/components/deployment/DeploymentSteps.svelte +3 -3
  2. package/dist/components/deployment/DeploymentTile.svelte +3 -3
  3. package/dist/components/deployment/ValidOrdersSection.svelte +3 -3
  4. package/dist/components/input/InputRegistryUrl.svelte +40 -0
  5. package/dist/components/input/InputRegistryUrl.svelte.d.ts +16 -0
  6. package/dist/index.d.ts +7 -7
  7. package/dist/index.js +6 -6
  8. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte +8 -0
  9. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +24 -0
  10. package/dist/providers/dotrainRegistry/context.d.ts +9 -0
  11. package/dist/providers/{dotrainRainlang → dotrainRegistry}/context.js +12 -12
  12. package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +5 -0
  13. package/dist/providers/dotrainRegistry/useDotrainRegistry.js +35 -0
  14. package/dist/providers/registry/RegistryManager.d.ts +65 -0
  15. package/dist/providers/registry/RegistryManager.js +133 -0
  16. package/dist/providers/registry/RegistryProvider.svelte +6 -0
  17. package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
  18. package/dist/providers/registry/context.d.ts +10 -0
  19. package/dist/providers/registry/context.js +46 -0
  20. package/dist/providers/registry/useRegistry.d.ts +7 -0
  21. package/dist/providers/registry/useRegistry.js +29 -0
  22. package/dist/services/handleShareChoices.d.ts +1 -1
  23. package/dist/services/handleShareChoices.js +2 -2
  24. package/dist/services/index.d.ts +3 -3
  25. package/dist/services/index.js +2 -2
  26. package/dist/services/loadRegistryUrl.d.ts +2 -0
  27. package/dist/services/loadRegistryUrl.js +22 -0
  28. package/dist/services/{rainlang.d.ts → registry.d.ts} +10 -10
  29. package/dist/services/{rainlang.js → registry.js} +15 -15
  30. package/package.json +3 -3
  31. package/dist/components/input/InputRainlangUrl.svelte +0 -40
  32. package/dist/components/input/InputRainlangUrl.svelte.d.ts +0 -16
  33. package/dist/providers/dotrainRainlang/DotrainRainlangProvider.svelte +0 -8
  34. package/dist/providers/dotrainRainlang/DotrainRainlangProvider.svelte.d.ts +0 -24
  35. package/dist/providers/dotrainRainlang/context.d.ts +0 -9
  36. package/dist/providers/dotrainRainlang/useDotrainRainlang.d.ts +0 -5
  37. package/dist/providers/dotrainRainlang/useDotrainRainlang.js +0 -35
  38. package/dist/providers/rainlang/RainlangManager.d.ts +0 -65
  39. package/dist/providers/rainlang/RainlangManager.js +0 -133
  40. package/dist/providers/rainlang/RainlangProvider.svelte +0 -6
  41. package/dist/providers/rainlang/RainlangProvider.svelte.d.ts +0 -21
  42. package/dist/providers/rainlang/context.d.ts +0 -10
  43. package/dist/providers/rainlang/context.js +0 -46
  44. package/dist/providers/rainlang/useRainlang.d.ts +0 -7
  45. package/dist/providers/rainlang/useRainlang.js +0 -29
  46. package/dist/services/loadRainlangUrl.d.ts +0 -2
  47. package/dist/services/loadRainlangUrl.js +0 -22
@@ -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
+ }
@@ -1,2 +1,2 @@
1
1
  import type { DotrainOrderGui } from '@rainlanguage/orderbook';
2
- export declare function handleShareChoices(gui: DotrainOrderGui, rainlangUrl: string): Promise<void>;
2
+ export declare function handleShareChoices(gui: DotrainOrderGui, registryUrl: 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, rainlangUrl) {
3
+ export async function handleShareChoices(gui, registryUrl) {
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, rainlangUrl) {
10
10
  }
11
11
  const state = result.value;
12
12
  url.searchParams.set('state', state || '');
13
- url.searchParams.set('rainlang', rainlangUrl);
13
+ url.searchParams.set('registry', registryUrl);
14
14
  navigator.clipboard.writeText(url.toString());
15
15
  }
@@ -1,3 +1,3 @@
1
- export { fetchParseRainlang, fetchRainlangDotrains, validateOrders } from './rainlang';
2
- export { loadRainlangUrl } from './loadRainlangUrl';
3
- export type { RainlangDotrain, RainlangFile } from './rainlang';
1
+ export { fetchParseRegistry, fetchRegistryDotrains, validateOrders } from './registry';
2
+ export { loadRegistryUrl } from './loadRegistryUrl';
3
+ export type { RegistryDotrain, RegistryFile } from './registry';
@@ -1,2 +1,2 @@
1
- export { fetchParseRainlang, fetchRainlangDotrains, validateOrders } from './rainlang';
2
- export { loadRainlangUrl } from './loadRainlangUrl';
1
+ export { fetchParseRegistry, fetchRegistryDotrains, validateOrders } from './registry';
2
+ export { loadRegistryUrl } from './loadRegistryUrl';
@@ -0,0 +1,2 @@
1
+ import { RegistryManager } from '../providers/registry/RegistryManager';
2
+ export declare function loadRegistryUrl(url: string, registryManager: RegistryManager): Promise<void>;
@@ -0,0 +1,22 @@
1
+ import { RegistryManager } from '../providers/registry/RegistryManager';
2
+ import { DotrainRegistry } from '@rainlanguage/orderbook';
3
+ export async function loadRegistryUrl(url, registryManager) {
4
+ if (!url) {
5
+ throw new Error('No URL provided');
6
+ }
7
+ if (!registryManager) {
8
+ throw new Error('Registry manager is required');
9
+ }
10
+ try {
11
+ const validationResult = await DotrainRegistry.validate(url);
12
+ if (validationResult.error) {
13
+ throw new Error(validationResult.error.readableMsg);
14
+ }
15
+ registryManager.setRegistry(url);
16
+ window.location.reload();
17
+ }
18
+ catch (e) {
19
+ const errorMessage = e instanceof Error ? e.message : 'Failed to update registry URL';
20
+ throw new Error(errorMessage);
21
+ }
22
+ }
@@ -1,9 +1,9 @@
1
1
  import type { InvalidOrderDetail, ValidOrderDetail } from '../types/order';
2
- export type RainlangFile = {
2
+ export type RegistryFile = {
3
3
  name: string;
4
4
  url: string;
5
5
  };
6
- export type RainlangDotrain = {
6
+ export type RegistryDotrain = {
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 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.
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.
17
17
  *
18
- * @param url - The URL of the rainlang file to fetch
18
+ * @param url - The URL of the registry 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 rainlang format is invalid
20
+ * @throws Will throw an error if the fetch fails, if the response is not ok, or if the registry format is invalid
21
21
  *
22
22
  * @example
23
- * const files = await fetchParseRainlangFile('https://example.com/rainlang');
23
+ * const files = await fetchParseRegistryFile('https://example.com/registry');
24
24
  * // Returns: [{ name: 'file1', url: 'https://example.com/file1.rain' }, ...]
25
25
  */
26
- export declare const fetchParseRainlang: (url: string) => Promise<{
26
+ export declare const fetchParseRegistry: (url: string) => Promise<{
27
27
  name: string;
28
28
  url: string;
29
29
  }[]>;
30
- export declare const fetchRainlangDotrains: (url: string) => Promise<RainlangDotrain[]>;
31
- export declare function validateOrders(rainlangDotrains: RainlangDotrain[]): Promise<OrderValidationResult>;
30
+ export declare const fetchRegistryDotrains: (url: string) => Promise<RegistryDotrain[]>;
31
+ export declare function validateOrders(registryDotrains: RegistryDotrain[]): Promise<OrderValidationResult>;
@@ -1,21 +1,21 @@
1
1
  import { DotrainOrderGui } from '@rainlanguage/orderbook';
2
2
  /**
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.
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.
5
5
  *
6
- * @param url - The URL of the rainlang file to fetch
6
+ * @param url - The URL of the registry 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 rainlang format is invalid
8
+ * @throws Will throw an error if the fetch fails, if the response is not ok, or if the registry format is invalid
9
9
  *
10
10
  * @example
11
- * const files = await fetchParseRainlangFile('https://example.com/rainlang');
11
+ * const files = await fetchParseRegistryFile('https://example.com/registry');
12
12
  * // Returns: [{ name: 'file1', url: 'https://example.com/file1.rain' }, ...]
13
13
  */
14
- export const fetchParseRainlang = async (url) => {
14
+ export const fetchParseRegistry = async (url) => {
15
15
  try {
16
16
  const response = await fetch(url);
17
17
  if (!response.ok) {
18
- throw new Error('Failed to fetch rainlang.');
18
+ throw new Error('Failed to fetch registry.');
19
19
  }
20
20
  const filesList = await response.text();
21
21
  const files = filesList
@@ -26,7 +26,7 @@ export const fetchParseRainlang = async (url) => {
26
26
  return { name, url };
27
27
  });
28
28
  if (!files) {
29
- throw new Error('Invalid stategy rainlang.');
29
+ throw new Error('Invalid stategy registry.');
30
30
  }
31
31
  return files;
32
32
  }
@@ -34,8 +34,8 @@ export const fetchParseRainlang = async (url) => {
34
34
  throw new Error(e instanceof Error ? e.message : 'Unknown error.');
35
35
  }
36
36
  };
37
- export const fetchRainlangDotrains = async (url) => {
38
- const files = await fetchParseRainlang(url);
37
+ export const fetchRegistryDotrains = async (url) => {
38
+ const files = await fetchParseRegistry(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 fetchRainlangDotrains = async (url) => {
53
53
  }));
54
54
  return dotrains;
55
55
  };
56
- export async function validateOrders(rainlangDotrains) {
57
- const ordersPromises = rainlangDotrains.map(async (rainlangDotrain) => {
56
+ export async function validateOrders(registryDotrains) {
57
+ const ordersPromises = registryDotrains.map(async (registryDotrain) => {
58
58
  try {
59
- const result = await DotrainOrderGui.getOrderDetails(rainlangDotrain.dotrain);
59
+ const result = await DotrainOrderGui.getOrderDetails(registryDotrain.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
- ...rainlangDotrain,
66
+ ...registryDotrain,
67
67
  details: result.value
68
68
  }
69
69
  };
@@ -72,7 +72,7 @@ export async function validateOrders(rainlangDotrains) {
72
72
  return {
73
73
  valid: false,
74
74
  data: {
75
- name: rainlangDotrain.name,
75
+ name: registryDotrain.name,
76
76
  error: error instanceof Error ? error.message : String(error)
77
77
  }
78
78
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@rainlanguage/ui-components",
3
- "version": "0.0.1-alpha.229",
3
+ "version": "0.0.1-alpha.230",
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",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/rainlanguage/rain.orderbook.git"
9
+ "url": "https://github.com/rainlanguage/raindex.git"
10
10
  },
11
11
  "main": "dist/index.js",
12
12
  "module": "dist/index.js",
@@ -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.229",
60
+ "@rainlanguage/orderbook": "0.0.1-alpha.231",
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 { useRainlang } from "../../providers/rainlang/useRainlang";
3
- import { loadRainlangUrl } from "../../services/loadRainlangUrl";
4
- const rainlang = useRainlang();
5
- let newRainlangUrl = rainlang.getCurrentRainlang();
6
- let error = null;
7
- let loading = false;
8
- async function handleClick() {
9
- loading = true;
10
- error = null;
11
- try {
12
- if (!rainlang) {
13
- throw new Error("Rainlang manager not yet available.");
14
- }
15
- await loadRainlangUrl(newRainlangUrl, rainlang);
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="rainlang-input">
25
- <Input
26
- id="order-url"
27
- type="url"
28
- placeholder="Enter URL to raw order rainlang file"
29
- bind:value={newRainlangUrl}
30
- />
31
- <Button class="w-36 text-nowrap" on:click={handleClick} disabled={loading}>
32
- {loading ? 'Loading rainlang...' : 'Load rainlang URL'}
33
- </Button>
34
- </div>
35
- <div class="h-4">
36
- {#if error}
37
- <p data-testid="rainlang-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 InputRainlangUrlProps = typeof __propDef.props;
12
- export type InputRainlangUrlEvents = typeof __propDef.events;
13
- export type InputRainlangUrlSlots = typeof __propDef.slots;
14
- export default class InputRainlangUrl extends SvelteComponent<InputRainlangUrlProps, InputRainlangUrlEvents, InputRainlangUrlSlots> {
15
- }
16
- export {};
@@ -1,8 +0,0 @@
1
- <script>import { setDotrainRainlangContext } from "./context";
2
- export let rainlang = null;
3
- export let error;
4
- export let manager;
5
- $: setDotrainRainlangContext({ rainlang, error, manager });
6
- </script>
7
-
8
- <slot />
@@ -1,24 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { DotrainRainlang } from '@rainlanguage/orderbook';
3
- import type { RainlangManager } from '../rainlang/RainlangManager';
4
- declare const __propDef: {
5
- props: {
6
- rainlang?: DotrainRainlang | null;
7
- error: string | undefined;
8
- manager: RainlangManager;
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 DotrainRainlangProviderProps = typeof __propDef.props;
20
- export type DotrainRainlangProviderEvents = typeof __propDef.events;
21
- export type DotrainRainlangProviderSlots = typeof __propDef.slots;
22
- export default class DotrainRainlangProvider extends SvelteComponent<DotrainRainlangProviderProps, DotrainRainlangProviderEvents, DotrainRainlangProviderSlots> {
23
- }
24
- export {};
@@ -1,9 +0,0 @@
1
- import type { DotrainRainlang } from '@rainlanguage/orderbook';
2
- import type { RainlangManager } from '../rainlang/RainlangManager';
3
- export type DotrainRainlangContext = {
4
- rainlang: DotrainRainlang | null;
5
- error?: string;
6
- manager: RainlangManager;
7
- };
8
- export declare const setDotrainRainlangContext: (context: DotrainRainlangContext) => void;
9
- export declare const getDotrainRainlangContext: () => DotrainRainlangContext;
@@ -1,5 +0,0 @@
1
- import { type DotrainRainlangContext } from './context';
2
- /**
3
- * Hook to access the current Dotrain rainlang context.
4
- */
5
- export declare function useDotrainRainlang(): DotrainRainlangContext;
@@ -1,35 +0,0 @@
1
- import { getDotrainRainlangContext } from './context';
2
- /**
3
- * Hook to access the current Dotrain rainlang context.
4
- */
5
- export function useDotrainRainlang() {
6
- return getDotrainRainlangContext();
7
- }
8
- if (import.meta.vitest) {
9
- const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
10
- vi.mock('./context', () => ({
11
- getDotrainRainlangContext: vi.fn()
12
- }));
13
- describe('useDotrainRainlang', () => {
14
- const mockGetContext = vi.mocked(getDotrainRainlangContext);
15
- beforeEach(() => {
16
- mockGetContext.mockReset();
17
- });
18
- it('should return the rainlang context', () => {
19
- const mockContext = {
20
- rainlang: null,
21
- manager: {
22
- getCurrentRainlang: vi.fn().mockReturnValue(''),
23
- setRainlang: vi.fn(),
24
- resetToDefault: vi.fn(),
25
- updateUrlWithRainlang: vi.fn(),
26
- isCustomRainlang: vi.fn().mockReturnValue(false)
27
- }
28
- };
29
- mockGetContext.mockReturnValue(mockContext);
30
- const result = useDotrainRainlang();
31
- expect(mockGetContext).toHaveBeenCalled();
32
- expect(result).toEqual(mockContext);
33
- });
34
- });
35
- }
@@ -1,65 +0,0 @@
1
- /**
2
- * Manages rainlang URL settings, persisting values in localStorage and URL parameters
3
- */
4
- export declare class RainlangManager {
5
- /** The default rainlang URL to fall back to */
6
- private defaultRainlang;
7
- /** The currently selected rainlang URL */
8
- private currentRainlang;
9
- /** Key used for localStorage and URL parameters */
10
- private static STORAGE_KEY;
11
- /**
12
- * Create a new RainlangManager
13
- * @param defaultRainlang The default rainlang URL to use.
14
- */
15
- constructor(defaultRainlang: string);
16
- /**
17
- * Initialize rainlang from URL param or local storage
18
- * @returns The rainlang URL to use
19
- */
20
- private loadRainlangFromStorageOrUrl;
21
- /**
22
- * Get the rainlang from the URL param
23
- * @returns The rainlang value from URL or null if not present
24
- * @throws Error if URL parsing fails
25
- */
26
- private getRainlangParamFromUrl;
27
- /**
28
- * Save the rainlang to local storage
29
- * @param rainlang The rainlang URL to save
30
- * @throws Error if localStorage is not available
31
- */
32
- private setRainlangToLocalStorage;
33
- /**
34
- * Retrieve the rainlang from local storage
35
- * @returns The stored rainlang URL or null if not found
36
- * @throws Error if localStorage is not available
37
- */
38
- private getRainlangFromLocalStorage;
39
- /**
40
- * Get the currently active rainlang
41
- * @returns The current rainlang URL, falling back to default if not set
42
- */
43
- getCurrentRainlang(): string;
44
- /**
45
- * Set the rainlang and update both localStorage and URL
46
- * @param rainlang The new rainlang URL to set
47
- */
48
- setRainlang(rainlang: string): void;
49
- /**
50
- * Reset to the default rainlang, 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 rainlang
56
- * @param value The rainlang value to set in URL, defaults to current rainlang
57
- * @throws Error if URL manipulation fails
58
- */
59
- updateUrlWithRainlang(value?: string | null): void;
60
- /**
61
- * Check if the current rainlang is custom (different from the default)
62
- * @returns True if using a non-default rainlang
63
- */
64
- isCustomRainlang(): boolean;
65
- }
@@ -1,133 +0,0 @@
1
- /**
2
- * Manages rainlang URL settings, persisting values in localStorage and URL parameters
3
- */
4
- export class RainlangManager {
5
- /** The default rainlang URL to fall back to */
6
- defaultRainlang;
7
- /** The currently selected rainlang URL */
8
- currentRainlang;
9
- /** Key used for localStorage and URL parameters */
10
- static STORAGE_KEY = 'rainlang';
11
- /**
12
- * Create a new RainlangManager
13
- * @param defaultRainlang The default rainlang URL to use.
14
- */
15
- constructor(defaultRainlang) {
16
- this.defaultRainlang = defaultRainlang;
17
- this.currentRainlang = this.loadRainlangFromStorageOrUrl();
18
- }
19
- /**
20
- * Initialize rainlang from URL param or local storage
21
- * @returns The rainlang URL to use
22
- */
23
- loadRainlangFromStorageOrUrl() {
24
- const urlParam = this.getRainlangParamFromUrl();
25
- if (urlParam) {
26
- this.setRainlangToLocalStorage(urlParam);
27
- return urlParam;
28
- }
29
- return this.getRainlangFromLocalStorage() ?? this.defaultRainlang;
30
- }
31
- /**
32
- * Get the rainlang from the URL param
33
- * @returns The rainlang value from URL or null if not present
34
- * @throws Error if URL parsing fails
35
- */
36
- getRainlangParamFromUrl() {
37
- try {
38
- return new URL(window.location.href).searchParams.get(RainlangManager.STORAGE_KEY);
39
- }
40
- catch (error) {
41
- throw new Error('Failed to get rainlang parameter: ' +
42
- (error instanceof Error ? error.message : String(error)));
43
- }
44
- }
45
- /**
46
- * Save the rainlang to local storage
47
- * @param rainlang The rainlang URL to save
48
- * @throws Error if localStorage is not available
49
- */
50
- setRainlangToLocalStorage(rainlang) {
51
- try {
52
- localStorage.setItem(RainlangManager.STORAGE_KEY, rainlang);
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 rainlang from local storage
61
- * @returns The stored rainlang URL or null if not found
62
- * @throws Error if localStorage is not available
63
- */
64
- getRainlangFromLocalStorage() {
65
- try {
66
- return localStorage.getItem(RainlangManager.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 rainlang
74
- * @returns The current rainlang URL, falling back to default if not set
75
- */
76
- getCurrentRainlang() {
77
- return this.currentRainlang ?? this.defaultRainlang;
78
- }
79
- /**
80
- * Set the rainlang and update both localStorage and URL
81
- * @param rainlang The new rainlang URL to set
82
- */
83
- setRainlang(rainlang) {
84
- this.currentRainlang = rainlang;
85
- this.setRainlangToLocalStorage(rainlang);
86
- this.updateUrlWithRainlang();
87
- }
88
- /**
89
- * Reset to the default rainlang, clearing both localStorage and URL param
90
- * @throws Error if localStorage is not available
91
- */
92
- resetToDefault() {
93
- this.currentRainlang = this.defaultRainlang;
94
- try {
95
- localStorage.removeItem(RainlangManager.STORAGE_KEY);
96
- }
97
- catch (error) {
98
- throw new Error('Failed to clear rainlang from localStorage: ' +
99
- (error instanceof Error ? error.message : String(error)));
100
- }
101
- this.updateUrlWithRainlang(null);
102
- }
103
- /**
104
- * Update the URL param to reflect the current or specified rainlang
105
- * @param value The rainlang value to set in URL, defaults to current rainlang
106
- * @throws Error if URL manipulation fails
107
- */
108
- updateUrlWithRainlang(value = this.currentRainlang) {
109
- try {
110
- const url = new URL(window.location.href);
111
- if (value) {
112
- url.searchParams.set(RainlangManager.STORAGE_KEY, value);
113
- }
114
- else {
115
- url.searchParams.delete(RainlangManager.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 rainlang is custom (different from the default)
126
- * @returns True if using a non-default rainlang
127
- */
128
- isCustomRainlang() {
129
- return (this.currentRainlang !== undefined &&
130
- this.currentRainlang !== null &&
131
- this.currentRainlang !== this.defaultRainlang);
132
- }
133
- }
@@ -1,6 +0,0 @@
1
- <script>import { setRainlangContext } from "./context";
2
- export let rainlangManager;
3
- setRainlangContext(rainlangManager);
4
- </script>
5
-
6
- <slot />
@@ -1,21 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RainlangManager } from './RainlangManager';
3
- declare const __propDef: {
4
- props: {
5
- rainlangManager: RainlangManager;
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 RainlangProviderProps = typeof __propDef.props;
17
- export type RainlangProviderEvents = typeof __propDef.events;
18
- export type RainlangProviderSlots = typeof __propDef.slots;
19
- export default class RainlangProvider extends SvelteComponent<RainlangProviderProps, RainlangProviderEvents, RainlangProviderSlots> {
20
- }
21
- export {};
@@ -1,10 +0,0 @@
1
- import type { RainlangManager } from './RainlangManager';
2
- export declare const RAINLANG_KEY = "rainlang_key";
3
- /**
4
- * Retrieves the rainlang manager directly from Svelte's context
5
- */
6
- export declare const getRainlangContext: () => RainlangManager;
7
- /**
8
- * Sets the rainlang manager in Svelte's context
9
- */
10
- export declare const setRainlangContext: (rainlang: RainlangManager) => void;