etudes 2.0.0 → 2.1.0

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.
@@ -1,12 +1,12 @@
1
1
  import React, { ComponentType, HTMLAttributes, PropsWithChildren, ReactElement, Ref } from 'react';
2
2
  import { ListItemProps } from './List';
3
- declare type Orientation = 'horizontal' | 'vertical';
4
- export declare type AccordionItemProps<T> = ListItemProps<T>;
5
- export declare type SectionData<T> = {
3
+ type Orientation = 'horizontal' | 'vertical';
4
+ export type AccordionItemProps<T> = ListItemProps<T>;
5
+ export type SectionData<T> = {
6
6
  label: string;
7
7
  items: T[];
8
8
  };
9
- export declare type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
9
+ export type AccordionProps<T> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
10
10
  /**
11
11
  * Data provided to each section.
12
12
  */
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes, PropsWithChildren } from 'react';
2
- export declare type BurgerButtonProps = HTMLAttributes<HTMLButtonElement> & PropsWithChildren<{
2
+ export type BurgerButtonProps = HTMLAttributes<HTMLButtonElement> & PropsWithChildren<{
3
3
  height?: number;
4
4
  isActive?: boolean;
5
5
  isDoubleJointed?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { PropsWithChildren } from 'react';
2
- export declare type ConditionalProps = PropsWithChildren<{
2
+ export type ConditionalProps = PropsWithChildren<{
3
3
  if: boolean | (() => boolean);
4
4
  }>;
5
5
  export default function Conditional({ children, if: boolOrExpression }: ConditionalProps): JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type DebugConsoleProps = HTMLAttributes<HTMLDivElement> & {
2
+ export type DebugConsoleProps = HTMLAttributes<HTMLDivElement> & {
3
3
  align?: 'tl' | 'tc' | 'tr' | 'cl' | 'cc' | 'cr' | 'bl' | 'bc' | 'br';
4
4
  margin?: number;
5
5
  maxEntries?: number;
package/lib/Dial.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes, PropsWithChildren, SVGAttributes } from 'react';
2
- export declare type DialProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
2
+ export type DialProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
3
3
  /**
4
4
  * Current angle reading of the compass, between 0.0 - 360.0 degrees,
5
5
  * inclusive.
package/lib/Dropdown.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import React, { ComponentType, HTMLAttributes, PropsWithChildren, ReactElement, Ref } from 'react';
2
2
  import { ListItemProps } from './List';
3
- declare type Orientation = 'horizontal' | 'vertical';
4
- export declare type DropdownData = {
3
+ type Orientation = 'horizontal' | 'vertical';
4
+ export type DropdownData = {
5
5
  label?: string;
6
6
  };
7
- export declare type DropdownItemProps<T extends DropdownData = DropdownData> = ListItemProps<T>;
8
- export declare type DropdownProps<T extends DropdownData = DropdownData> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
7
+ export type DropdownItemProps<T extends DropdownData = DropdownData> = ListItemProps<T>;
8
+ export type DropdownProps<T extends DropdownData = DropdownData> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
9
9
  /**
10
10
  * Data of every item in the component. This is used to generate individual
11
11
  * menu items. Data type is generic.
package/lib/Each.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- export declare type EachProps<T> = {
2
+ export type EachProps<T> = {
3
3
  children?: ReactNode | ((value: T, index: number) => ReactNode);
4
4
  in?: T[];
5
5
  render?: (value: T, index: number) => ReactNode;
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type ExtractChildProps = HTMLAttributes<HTMLElement>;
2
+ export type ExtractChildProps = HTMLAttributes<HTMLElement>;
3
3
  /**
4
4
  * Extracts a single child of a parent component into its own component. If the
5
5
  * parent component has multiple children, only the first one will be extracted,
@@ -1,5 +1,5 @@
1
1
  import { HTMLAttributes } from 'react';
2
- export declare type ExtractChildrenProps = HTMLAttributes<HTMLElement>;
2
+ export type ExtractChildrenProps = HTMLAttributes<HTMLElement>;
3
3
  /**
4
4
  * Extracts all children of a parent component into its own component.
5
5
  */
package/lib/FlatSVG.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type FlatSVGProps = HTMLAttributes<HTMLDivElement> & {
2
+ export type FlatSVGProps = HTMLAttributes<HTMLDivElement> & {
3
3
  /**
4
4
  * The SVG string markup, i.e. "<svg>...</svg>".
5
5
  */
package/lib/List.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import React, { ComponentType, HTMLAttributes, ReactElement, Ref } from 'react';
2
- declare type Orientation = 'horizontal' | 'vertical';
3
- export declare type ListItemProps<T> = HTMLAttributes<HTMLElement> & {
2
+ type Orientation = 'horizontal' | 'vertical';
3
+ export type ListItemProps<T> = HTMLAttributes<HTMLElement> & {
4
4
  data: T;
5
5
  index: number;
6
6
  isSelected: boolean;
7
7
  orientation: Orientation;
8
8
  };
9
- export declare type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
9
+ export type ListProps<T> = HTMLAttributes<HTMLDivElement> & {
10
10
  /**
11
11
  * Thickness of item borders (in pixels). 0 indicates no borders.
12
12
  */
@@ -1,6 +1,6 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- declare type Orientation = 'horizontal' | 'vertical';
3
- export declare type MasonryGridProps = HTMLAttributes<HTMLDivElement> & {
2
+ type Orientation = 'horizontal' | 'vertical';
3
+ export type MasonryGridProps = HTMLAttributes<HTMLDivElement> & {
4
4
  areSectionsAligned?: boolean;
5
5
  horizontalSpacing?: number;
6
6
  isReversed?: boolean;
package/lib/Panorama.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
2
  import { Size } from 'spase';
3
- export declare type PanoramaProps = Omit<HTMLAttributes<HTMLDivElement>, 'onResize'> & {
3
+ export type PanoramaProps = Omit<HTMLAttributes<HTMLDivElement>, 'onResize'> & {
4
4
  /**
5
5
  * The current angle in degrees, 0.0 - 360.0, inclusive. When angle is 0 or
6
6
  * 360, the left bound of the image is at the center of the component.
@@ -1,7 +1,7 @@
1
1
  import React, { HTMLAttributes, PropsWithChildren } from 'react';
2
2
  import { Size } from 'spase';
3
3
  import { PanoramaProps } from './Panorama';
4
- export declare type PanoramaSliderProps = HTMLAttributes<HTMLDivElement> & PanoramaProps & PropsWithChildren<{
4
+ export type PanoramaSliderProps = HTMLAttributes<HTMLDivElement> & PanoramaProps & PropsWithChildren<{
5
5
  /**
6
6
  * Field-of-view (0.0 - 360.0 degrees, inclusive) that represents the size of
7
7
  * the reticle. 360 indicates the reticle covers the entire image. If this is
@@ -1,7 +1,7 @@
1
1
  import React, { HTMLAttributes, PropsWithChildren } from 'react';
2
- declare type Orientation = 'horizontal' | 'vertical';
3
- declare type Range = [number, number];
4
- export declare type RangeSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
2
+ type Orientation = 'horizontal' | 'vertical';
3
+ type Range = [number, number];
4
+ export type RangeSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
5
5
  areLabelsVisible?: boolean;
6
6
  decimalPlaces?: number;
7
7
  knobPadding?: number;
package/lib/Repeat.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- export declare type RepeatProps = {
2
+ export type RepeatProps = {
3
3
  children?: ReactNode | ((index: number) => ReactNode);
4
4
  count?: number;
5
5
  render?: (index: number) => ReactNode;
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes, PropsWithChildren } from 'react';
2
- export declare type RotatingGalleryProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
2
+ export type RotatingGalleryProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
3
3
  /**
4
4
  * Current image index. An error is thrown if the index is invalid (must be
5
5
  * between 0 and length of `srcs` - 1, inclusive). This prop supports two-way
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes, ReactNode } from 'react';
2
- export declare type SelectableButtonProps = Omit<HTMLAttributes<HTMLButtonElement>, 'children'> & {
2
+ export type SelectableButtonProps = Omit<HTMLAttributes<HTMLButtonElement>, 'children'> & {
3
3
  children?: (props: Pick<SelectableButtonProps, 'isDeselectable' | 'isDisabled' | 'isSelected' | 'label'>) => ReactNode;
4
4
  isDeselectable?: boolean;
5
5
  isDisabled?: boolean;
package/lib/Slider.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { HTMLAttributes, PropsWithChildren } from 'react';
2
- declare type Orientation = 'horizontal' | 'vertical';
3
- export declare type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
2
+ type Orientation = 'horizontal' | 'vertical';
3
+ export type SliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
4
4
  /**
5
5
  * By default the position is a value from 0 - 1, 0 being the start of the
6
6
  * slider and 1 being the end. Switching on this flag inverts this behavior,
@@ -1,6 +1,6 @@
1
1
  import React, { HTMLAttributes, PropsWithChildren } from 'react';
2
- declare type Orientation = 'horizontal' | 'vertical';
3
- export declare type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
2
+ type Orientation = 'horizontal' | 'vertical';
3
+ export type StepwiseSliderProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
4
4
  /**
5
5
  * By default the position is a value from 0 - 1, 0 being the start of the
6
6
  * slider and 1 being the end. Switching on this flag inverts this behavior,
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type SwipeContainerProps = HTMLAttributes<HTMLDivElement> & {
2
+ export type SwipeContainerProps = HTMLAttributes<HTMLDivElement> & {
3
3
  isEnabled?: boolean;
4
4
  threshold?: number;
5
5
  onSwipeDown?: () => void;
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type TextFieldProps = HTMLAttributes<HTMLInputElement> & {
2
+ export type TextFieldProps = HTMLAttributes<HTMLInputElement> & {
3
3
  value?: string;
4
4
  onFocus?: (value: string) => void;
5
5
  onUnfocus?: (value: string) => void;
package/lib/Video.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { HTMLAttributes } from 'react';
2
- export declare type VideoProps = HTMLAttributes<HTMLDivElement> & {
2
+ export type VideoProps = HTMLAttributes<HTMLDivElement> & {
3
3
  autoLoop?: boolean;
4
4
  autoPlay?: boolean;
5
5
  hasControls?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { HTMLAttributes, PropsWithChildren } from 'react';
2
- export declare type WithToolTipProps = Pick<HTMLAttributes<HTMLElement>, 'className' | 'style'> & PropsWithChildren<{
2
+ export type WithToolTipProps = Pick<HTMLAttributes<HTMLElement>, 'className' | 'style'> & PropsWithChildren<{
3
3
  /**
4
4
  * The height of the arrow. The width (longest edge) of the arrow is always
5
5
  * twice its height.
@@ -1,11 +1,11 @@
1
1
  import { DependencyList, Dispatch, RefObject, SetStateAction } from 'react';
2
- declare type ReturnedStates<T> = {
2
+ type ReturnedStates<T> = {
3
3
  isDragging: [boolean, Dispatch<SetStateAction<boolean>>];
4
4
  isReleasing: [boolean, Dispatch<SetStateAction<boolean>>];
5
5
  value: [T, Dispatch<SetStateAction<T>>];
6
6
  };
7
- declare type InteractDraggableOptions = Parameters<Interact.Interactable['draggable']>[0];
8
- declare type Options<T> = Omit<InteractDraggableOptions, 'onstart' | 'onmove' | 'onend'> & {
7
+ type InteractDraggableOptions = Parameters<Interact.Interactable['draggable']>[0];
8
+ type Options<T> = Omit<InteractDraggableOptions, 'onstart' | 'onmove' | 'onend'> & {
9
9
  /**
10
10
  * The initial associated value of this hook.
11
11
  */
@@ -1,5 +1,5 @@
1
1
  import { DependencyList } from 'react';
2
- declare type Options = {
2
+ type Options = {
3
3
  /**
4
4
  * Specifies if the handler should be invoked initially (as opposed to waiting
5
5
  * for the specified interval for the initial invocation).
@@ -1,6 +1,6 @@
1
1
  import { DependencyList, Dispatch, SetStateAction } from 'react';
2
2
  import { Size } from 'spase';
3
- declare type ReturnedStates = {
3
+ type ReturnedStates = {
4
4
  /**
5
5
  * A tuple consisting of a stateful value indicating if the image is loading,
6
6
  * and a function that updates the loading state.
@@ -12,7 +12,7 @@ declare type ReturnedStates = {
12
12
  */
13
13
  imageSize: [Size | undefined, Dispatch<SetStateAction<Size | undefined>>];
14
14
  };
15
- declare type Options = {
15
+ type Options = {
16
16
  /**
17
17
  * Handler invoked when the image is done loading.
18
18
  *
@@ -1,6 +1,6 @@
1
1
  import { DependencyList, Dispatch, RefObject, SetStateAction } from 'react';
2
2
  import { Size } from 'spase';
3
- declare type Options = {
3
+ type Options = {
4
4
  /**
5
5
  * Handler invoked when the target element resizes.
6
6
  *
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- export declare type Options<T> = {
2
+ export type Options<T> = {
3
3
  /**
4
4
  * Function for transforming the search param value to the value of the mapped
5
5
  * state.
@@ -0,0 +1,179 @@
1
+ import Polyglot from 'node-polyglot';
2
+ import React, { Dispatch, PropsWithChildren } from 'react';
3
+ interface Translation {
4
+ [key: string]: Translation | string;
5
+ }
6
+ type I18nState = {
7
+ changeLocaleStrategy: 'action' | 'path' | 'query';
8
+ defaultLocale: string;
9
+ locale: string;
10
+ polyglots: Record<string, Polyglot>;
11
+ supportedLocales: string[];
12
+ getLocalizedPath?: (path: string) => string;
13
+ getLocalizedString: typeof Polyglot.prototype.t;
14
+ };
15
+ type I18nContextValue = {
16
+ state: I18nState;
17
+ dispatch?: Dispatch<I18nChangeLocaleAction>;
18
+ };
19
+ type I18nProviderProps = PropsWithChildren<{
20
+ changeLocaleStrategy?: I18nState['changeLocaleStrategy'];
21
+ defaultLocale?: I18nState['defaultLocale'];
22
+ translations: Record<string, Translation>;
23
+ }>;
24
+ type I18nChangeLocaleAction = {
25
+ type: '@i18n/CHANGE_LOCALE';
26
+ locale: string;
27
+ };
28
+ export declare const I18nContext: React.Context<I18nContextValue | undefined>;
29
+ /**
30
+ * Context provider whose value consists of the current i18n state. The method
31
+ * of modifying the locale is specified by `changeLocaleStrategy`, as follows:
32
+ * - If set to `action`, the locale can be modified by dispatching an action
33
+ * - If set to `path`, the locale is inferred from the current path name
34
+ * - If set to `query`, the locale is inferred from the search parameter
35
+ * `locale` in the current path
36
+ *
37
+ * @param props - See {@link I18nProviderProps}.
38
+ *
39
+ * @returns The context provider.
40
+ */
41
+ export default function I18nProvider({ children, defaultLocale, translations, changeLocaleStrategy, }: I18nProviderProps): JSX.Element;
42
+ /** @namespace Components */
43
+ /**
44
+ * Custom {@link Routes} container that generates child {@link Route} components
45
+ * for all locales supported by {@link I18nProvider}.
46
+ */
47
+ export declare function I18nRoutes({ children }: PropsWithChildren): JSX.Element;
48
+ /** @namespace Hooks */
49
+ /**
50
+ * Hook for retrieving the change locale function.
51
+ *
52
+ * @returns The change locale function.
53
+ */
54
+ export declare function useChangeLocale(): (locale: string) => void | undefined;
55
+ /**
56
+ * Hook for retrieving the current locale.
57
+ *
58
+ * @returns The current locale.
59
+ */
60
+ export declare function useLocale(): string;
61
+ /**
62
+ * Hook for retrieving the path localizing function for the current locale.
63
+ *
64
+ * @returns The path localizing function.
65
+ */
66
+ export declare function useLocalizedPath(): (path: string) => string;
67
+ /**
68
+ * Hook for retrieving the string localizing function for the current locale.
69
+ *
70
+ * @returns The string localizing function.
71
+ */
72
+ export declare function useLocalizedString(): (phrase: string, options?: number | Polyglot.InterpolationOptions | undefined) => string;
73
+ /**
74
+ * Hook for retrieving all supported locales.
75
+ *
76
+ * @returns All supported locales.
77
+ */
78
+ export declare function useSupportedLocales(): string[];
79
+ /** @namespace Utilities */
80
+ type URLParts = {
81
+ base?: string;
82
+ hash?: string;
83
+ host?: string;
84
+ path?: string;
85
+ port?: string;
86
+ protocol?: string;
87
+ query?: string;
88
+ };
89
+ type ResolveLocaleOptions = {
90
+ /**
91
+ * The locale to fallback to if one cannot be inferred from the provided URL.
92
+ */
93
+ defaultLocale?: string;
94
+ /**
95
+ * An array of supported locales to validate the inferred locale against. If
96
+ * it doesn't exist in the list of supported locales, the default locale (if
97
+ * specified) or `undefined` will be returned.
98
+ */
99
+ supportedLocales?: string[];
100
+ };
101
+ type ResolveLocalizedURLOptions = ResolveLocaleOptions & {
102
+ /**
103
+ * Specifies where in the URL the locale should be matched. If `resolver` is
104
+ * provided, this option is ignored.
105
+ */
106
+ resolveStrategy?: 'auto' | 'domain' | 'path' | 'query';
107
+ /**
108
+ * Custom resolver function.
109
+ *
110
+ * @param protocol - The matched protocol of the provided url, if available.
111
+ * @param host - The matched host of the provided url, if available.
112
+ * @param port - The matched port of the provided url, if available.
113
+ * @param path - The matched path of the provided url, if available.
114
+ *
115
+ * @returns The resolved locale.
116
+ */
117
+ resolver?: (urlParts: URLParts) => string | undefined;
118
+ };
119
+ type LocalizedURLInfo = {
120
+ /**
121
+ * The matched locale.
122
+ */
123
+ locale: string;
124
+ /**
125
+ * Specifies where in the URL the locale was matched.
126
+ */
127
+ resolveStrategy: ResolveLocalizedURLOptions['resolveStrategy'] | 'custom';
128
+ };
129
+ /**
130
+ * Resolves the specified locale with the provided options. All parameters are
131
+ * optional.
132
+ *
133
+ * @param locale - The locale to resolve.
134
+ * @param options - See {@link ResolveLocaleOptions}.
135
+ *
136
+ * @returns - The resolved locale.
137
+ */
138
+ export declare function resolveLocale(locale?: string, { defaultLocale, supportedLocales }?: ResolveLocaleOptions): string | undefined;
139
+ /**
140
+ * Retrieves the locale identifier from a URL. The default behavior of this
141
+ * function to look for the locale identifier in the domain first followed by
142
+ * the first directory of the path. You can provide a custom resolver.
143
+ *
144
+ * @param url - The URL, can be a full URL or a valid path.
145
+ * @param options - See {@link ResolveLocalizedURLOptions}.
146
+ *
147
+ * @returns The inferred locale if it exists.
148
+ */
149
+ export declare function getLocaleFromURL(url: string, { defaultLocale, resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): LocalizedURLInfo | undefined;
150
+ /**
151
+ * Returns the unlocalized version of a URL.
152
+ *
153
+ * @param url - The URL.
154
+ * @param options - See {@link ResolveLocalizedURLOptions}.
155
+ *
156
+ * @returns The unlocalized URL.
157
+ */
158
+ export declare function getUnlocalizedURL(url: string, { resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): string;
159
+ /**
160
+ * Returns the localized version of a URL.
161
+ *
162
+ * @param url - The URL.
163
+ * @param locale - The target locale.
164
+ * @param options - See {@link ResolveLocalizedURLOptions}.
165
+ *
166
+ * @returns The localized URL.
167
+ */
168
+ export declare function getLocalizedURL(url: string, locale: string, { defaultLocale, resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): string;
169
+ /**
170
+ * Returns all localized versions of a URL based on the specified
171
+ * `supportedLocales`.
172
+ *
173
+ * @param url - The URL.
174
+ * @param options - See {@link ResolveLocalizedURLOptions}.
175
+ *
176
+ * @returns The localized URLs.
177
+ */
178
+ export declare function getLocalizedURLs(url: string, { defaultLocale, resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): string[];
179
+ export {};