@panneau/core 4.0.11 → 4.0.14
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/contexts.d.ts +450 -0
- package/{es → dist}/contexts.js +23 -23
- package/dist/hooks.d.ts +362 -0
- package/{es → dist}/hooks.js +4 -4
- package/dist/index.d.ts +502 -0
- package/{es → dist}/index.js +7 -258
- package/dist/utils.d.ts +207 -0
- package/{es → dist}/utils.js +7 -7
- package/package.json +23 -23
- package/es/types/core.d.ts +0 -133
- package/es/types/form.d.ts +0 -58
- package/es/types/index.d.ts +0 -20
- package/es/types/panneau.d.ts +0 -50
- package/es/types/resource.d.ts +0 -112
- package/lib/contexts.js +0 -1432
- package/lib/hooks.js +0 -1168
- package/lib/index.js +0 -1019
- package/lib/utils.js +0 -789
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
import { ReactNode, SubmitEvent, RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
interface UseAnimationFrameOptions {
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function useAnimationFrame(onFrame: (progress: number) => void, { disabled }?: UseAnimationFrameOptions): void;
|
|
8
|
+
|
|
9
|
+
interface UseFormattedDateOptions {
|
|
10
|
+
format?: Intl.DateTimeFormatOptions | null;
|
|
11
|
+
showToday?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface UseFormattedTimeOptions {
|
|
14
|
+
format?: Intl.DateTimeFormatOptions | null;
|
|
15
|
+
showNow?: boolean;
|
|
16
|
+
timeGap?: number;
|
|
17
|
+
}
|
|
18
|
+
declare const useFormattedDate: ({ format, showToday, }?: UseFormattedDateOptions) => ((date: string | Date | Dayjs) => string);
|
|
19
|
+
declare const useFormattedTime: ({ format, showNow, timeGap, }?: UseFormattedTimeOptions) => ((date: string | Date | Dayjs) => string);
|
|
20
|
+
|
|
21
|
+
declare const useDocumentEvent: (event: string, callback: (...args: unknown[]) => void, enabled?: boolean) => void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Form Types
|
|
25
|
+
* TypeScript interfaces for form-related components
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Field definition
|
|
30
|
+
*/
|
|
31
|
+
interface Field$1 {
|
|
32
|
+
name?: string;
|
|
33
|
+
type?: string;
|
|
34
|
+
component?: string;
|
|
35
|
+
label?: ReactNode;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Resource Types
|
|
40
|
+
* TypeScript interfaces for resources, items, users, media, and other entities
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
interface ResourceIntlValues {
|
|
44
|
+
a_singular?: string;
|
|
45
|
+
a_plural?: string;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Internationalization configuration
|
|
50
|
+
*/
|
|
51
|
+
interface ResourceIntl {
|
|
52
|
+
messages?: Record<string, string>;
|
|
53
|
+
values?: ResourceIntlValues;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Resource definition
|
|
57
|
+
*/
|
|
58
|
+
interface Resource {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
intl?: ResourceIntl;
|
|
62
|
+
fields?: Field$1[];
|
|
63
|
+
forms?: Record<string, unknown>;
|
|
64
|
+
shows_in_navbar?: boolean;
|
|
65
|
+
settings?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type FieldInput = string | Field$1;
|
|
69
|
+
interface FieldErrors {
|
|
70
|
+
[key: string]: string[] | FieldErrors;
|
|
71
|
+
}
|
|
72
|
+
interface FieldValue {
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
}
|
|
75
|
+
interface ProcessedField extends Field$1 {
|
|
76
|
+
name: string | null;
|
|
77
|
+
component: string | null;
|
|
78
|
+
value: unknown;
|
|
79
|
+
errors: string[] | null;
|
|
80
|
+
onChange: (fieldValue: unknown) => void;
|
|
81
|
+
fields?: ProcessedField[] | null;
|
|
82
|
+
}
|
|
83
|
+
interface RequestState {
|
|
84
|
+
success: boolean;
|
|
85
|
+
loading: boolean;
|
|
86
|
+
error: boolean;
|
|
87
|
+
}
|
|
88
|
+
interface UseFormOptions {
|
|
89
|
+
fields?: FieldInput[];
|
|
90
|
+
action?: string | null;
|
|
91
|
+
postForm?: ((action: string, data: Record<string, unknown>) => Promise<unknown>) | null;
|
|
92
|
+
initialErrors?: FieldErrors | null;
|
|
93
|
+
errors?: FieldErrors | null;
|
|
94
|
+
setErrors?: ((errors: FieldErrors | null) => void) | null;
|
|
95
|
+
initialGeneralError?: string | null;
|
|
96
|
+
generalError?: string | null;
|
|
97
|
+
setGeneralError?: ((error: string | null) => void) | null;
|
|
98
|
+
initialValue?: FieldValue | null;
|
|
99
|
+
value?: FieldValue | null;
|
|
100
|
+
setValue?: ((value: FieldValue) => void) | null;
|
|
101
|
+
withoutDefault?: boolean;
|
|
102
|
+
withoutPropagation?: boolean;
|
|
103
|
+
onComplete?: ((response: unknown) => void) | null;
|
|
104
|
+
onError?: ((error: Error) => void) | null;
|
|
105
|
+
locales?: string[];
|
|
106
|
+
}
|
|
107
|
+
interface UseFormReturn extends RequestState {
|
|
108
|
+
value: FieldValue | null;
|
|
109
|
+
setValue: (value: FieldValue) => void;
|
|
110
|
+
csrfToken: string | null;
|
|
111
|
+
submit: (submitValue?: FieldValue | null) => void;
|
|
112
|
+
onSubmit: (e: SubmitEvent) => void;
|
|
113
|
+
status: 'loading' | 'success' | 'error' | null;
|
|
114
|
+
response: unknown;
|
|
115
|
+
fields: ProcessedField[];
|
|
116
|
+
errors: FieldErrors | null;
|
|
117
|
+
generalError: string | null;
|
|
118
|
+
}
|
|
119
|
+
declare const useForm: (opts?: UseFormOptions) => UseFormReturn;
|
|
120
|
+
|
|
121
|
+
interface UseIsVisibleOptions {
|
|
122
|
+
rootMargin?: string;
|
|
123
|
+
threshold?: number;
|
|
124
|
+
persist?: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface UseIsVisibleResult {
|
|
127
|
+
ref: RefObject<HTMLElement>;
|
|
128
|
+
visible: boolean;
|
|
129
|
+
}
|
|
130
|
+
declare function useIsVisible({ rootMargin, threshold, persist, }?: UseIsVisibleOptions): UseIsVisibleResult;
|
|
131
|
+
|
|
132
|
+
declare const KEYCODES: {
|
|
133
|
+
ARROW_LEFT: number;
|
|
134
|
+
ARROW_UP: number;
|
|
135
|
+
ARROW_RIGHT: number;
|
|
136
|
+
ARROW_DOWN: number;
|
|
137
|
+
ESCAPE: number;
|
|
138
|
+
SPACE: number;
|
|
139
|
+
};
|
|
140
|
+
interface UseKeyboardKeysOptions {
|
|
141
|
+
eventName?: string;
|
|
142
|
+
}
|
|
143
|
+
declare function useKeyboardKeys(keys?: Record<number, (e: KeyboardEvent) => void>, { eventName }?: UseKeyboardKeysOptions): void;
|
|
144
|
+
|
|
145
|
+
interface FontConfig {
|
|
146
|
+
type?: 'google' | 'custom' | 'system';
|
|
147
|
+
name: string;
|
|
148
|
+
}
|
|
149
|
+
declare const useLoadedFonts: (fonts: (string | FontConfig)[]) => {
|
|
150
|
+
loaded: boolean;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
interface UseMediaApiOptions {
|
|
154
|
+
url?: string | null;
|
|
155
|
+
initialMuted?: boolean;
|
|
156
|
+
onTimeUpdate?: ((time: number) => void) | null;
|
|
157
|
+
onProgressStep?: ((step: number) => void) | null;
|
|
158
|
+
onDurationChanged?: ((duration: number) => void) | null;
|
|
159
|
+
onVolumeChanged?: ((muted: boolean, volume: number) => void) | null;
|
|
160
|
+
onPlay?: ((opts: {
|
|
161
|
+
initial: boolean;
|
|
162
|
+
}) => void) | null;
|
|
163
|
+
onPause?: ((opts: {
|
|
164
|
+
midway: boolean;
|
|
165
|
+
}) => void) | null;
|
|
166
|
+
onEnded?: (() => void) | null;
|
|
167
|
+
onSeeked?: ((time: number) => void) | null;
|
|
168
|
+
onLoadStart?: (() => void) | null;
|
|
169
|
+
onCanPlayThough?: (() => void) | null;
|
|
170
|
+
}
|
|
171
|
+
interface UseMediaApiReturn {
|
|
172
|
+
ref: RefObject<HTMLMediaElement>;
|
|
173
|
+
play: () => void;
|
|
174
|
+
pause: () => void;
|
|
175
|
+
togglePlay: () => void;
|
|
176
|
+
stop: () => void;
|
|
177
|
+
seek: (time: number) => void;
|
|
178
|
+
mute: () => void;
|
|
179
|
+
unMute: () => void;
|
|
180
|
+
toggleMute: () => void;
|
|
181
|
+
muted: boolean;
|
|
182
|
+
currentTime: number | null;
|
|
183
|
+
duration: number | null;
|
|
184
|
+
playing: boolean;
|
|
185
|
+
paused: boolean;
|
|
186
|
+
ready: boolean;
|
|
187
|
+
}
|
|
188
|
+
declare const useMediaApi: ({ url, initialMuted, onTimeUpdate, onProgressStep, onDurationChanged, onVolumeChanged, onPlay, onPause, onEnded, onSeeked, onLoadStart, onCanPlayThough, }?: UseMediaApiOptions) => UseMediaApiReturn;
|
|
189
|
+
|
|
190
|
+
interface Manager {
|
|
191
|
+
getDefinition: (type: string) => Record<string, unknown> | null;
|
|
192
|
+
}
|
|
193
|
+
interface MediasParserOptions {
|
|
194
|
+
fieldsManager: Manager;
|
|
195
|
+
screensManager: Manager;
|
|
196
|
+
}
|
|
197
|
+
interface Media$1 {
|
|
198
|
+
id?: string | null;
|
|
199
|
+
[key: string]: unknown;
|
|
200
|
+
}
|
|
201
|
+
interface Field {
|
|
202
|
+
id?: string | null;
|
|
203
|
+
name?: string | null;
|
|
204
|
+
type?: string | null;
|
|
205
|
+
media?: boolean;
|
|
206
|
+
fields?: Field[];
|
|
207
|
+
itemsField?: Field | null;
|
|
208
|
+
settings?: Field[];
|
|
209
|
+
[key: string]: unknown;
|
|
210
|
+
}
|
|
211
|
+
interface Screen$1 {
|
|
212
|
+
type: string;
|
|
213
|
+
[key: string]: unknown;
|
|
214
|
+
}
|
|
215
|
+
interface Story {
|
|
216
|
+
theme?: Story | null;
|
|
217
|
+
components?: Screen$1[];
|
|
218
|
+
medias?: Record<string, Media$1> | null;
|
|
219
|
+
[key: string]: unknown;
|
|
220
|
+
}
|
|
221
|
+
declare class MediasParser {
|
|
222
|
+
fieldsManager: Manager;
|
|
223
|
+
screensManager: Manager;
|
|
224
|
+
constructor({ fieldsManager, screensManager }: MediasParserOptions);
|
|
225
|
+
toPath(story: Story | null): Story | null;
|
|
226
|
+
fromPath(story: Story | null, defaultMedias?: Record<string, Media$1> | null): Story | null;
|
|
227
|
+
getMediaFieldsPattern(fields: Field[], namePrefix?: string | null): RegExp[];
|
|
228
|
+
static fieldIsMedia({ media }: Field): boolean;
|
|
229
|
+
static fieldIsFontFamily({ id }: Field): boolean;
|
|
230
|
+
static replacePathsWithMedias(data: unknown, medias: Record<string, Media$1>, patterns: RegExp[], keyPrefix?: string | null): unknown;
|
|
231
|
+
static getMediaPath({ id }: Media$1): string | null;
|
|
232
|
+
static replaceMediasWithPaths(data: unknown, patterns: RegExp[], medias?: Record<string, Media$1> | null, keyPrefix?: string | null): {
|
|
233
|
+
data: unknown;
|
|
234
|
+
medias: Record<string, Media$1> | null;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
interface UseMediasParserReturn {
|
|
239
|
+
toPath: (story: unknown) => string;
|
|
240
|
+
fromPath: (story: unknown) => unknown;
|
|
241
|
+
parser: MediasParser;
|
|
242
|
+
}
|
|
243
|
+
declare const useMediasParser: () => UseMediasParserReturn;
|
|
244
|
+
|
|
245
|
+
type ObserverConstructor<T> = (new (callback: (entries: T[]) => void, options?: Record<string, unknown>) => {
|
|
246
|
+
observe: (element: Element) => void;
|
|
247
|
+
unobserve?: (element: Element) => void;
|
|
248
|
+
disconnect: () => void;
|
|
249
|
+
}) | null;
|
|
250
|
+
interface ObserverWrapper<T> {
|
|
251
|
+
subscribe: (element: Element, callback: (entry: T) => void) => void;
|
|
252
|
+
unsubscribe: (element: Element, callback?: ((entry: T) => void) | null) => void;
|
|
253
|
+
observer: ReturnType<NonNullable<ObserverConstructor<T>>>;
|
|
254
|
+
}
|
|
255
|
+
interface ObserverOptions {
|
|
256
|
+
root?: Element | null;
|
|
257
|
+
rootMargin?: string | null;
|
|
258
|
+
threshold?: number | number[] | null;
|
|
259
|
+
disabled?: boolean;
|
|
260
|
+
}
|
|
261
|
+
declare const getObserver: <T>(Observer: ObserverConstructor<T>, options?: ObserverOptions) => ObserverWrapper<T>;
|
|
262
|
+
interface UseObserverReturn<T> {
|
|
263
|
+
ref: RefObject<Element>;
|
|
264
|
+
entry: T;
|
|
265
|
+
}
|
|
266
|
+
declare const useObserver: <T>(Observer: ObserverConstructor<T>, opts?: ObserverOptions, initialEntry?: T) => UseObserverReturn<T>;
|
|
267
|
+
interface IntersectionObserverEntry {
|
|
268
|
+
target: Element | null;
|
|
269
|
+
time: number | null;
|
|
270
|
+
isVisible: boolean;
|
|
271
|
+
isIntersecting: boolean;
|
|
272
|
+
intersectionRatio: number;
|
|
273
|
+
intersectionRect: DOMRectReadOnly | null;
|
|
274
|
+
boundingClientRect: DOMRectReadOnly | null;
|
|
275
|
+
rootBounds: DOMRectReadOnly | null;
|
|
276
|
+
}
|
|
277
|
+
interface UseIntersectionObserverOptions {
|
|
278
|
+
root?: Element | null;
|
|
279
|
+
rootMargin?: string;
|
|
280
|
+
threshold?: number | number[];
|
|
281
|
+
disabled?: boolean;
|
|
282
|
+
}
|
|
283
|
+
declare const useIntersectionObserver: ({ root, rootMargin, threshold, disabled, }?: UseIntersectionObserverOptions) => UseObserverReturn<IntersectionObserverEntry>;
|
|
284
|
+
/**
|
|
285
|
+
* Resize Observer
|
|
286
|
+
*/
|
|
287
|
+
interface ResizeObserverEntry {
|
|
288
|
+
target: Element | null;
|
|
289
|
+
contentRect: DOMRectReadOnly | null;
|
|
290
|
+
contentBoxSize: ReadonlyArray<ResizeObserverSize> | null;
|
|
291
|
+
borderBoxSize: ReadonlyArray<ResizeObserverSize> | null;
|
|
292
|
+
}
|
|
293
|
+
interface UseResizeObserverOptions {
|
|
294
|
+
disabled?: boolean;
|
|
295
|
+
}
|
|
296
|
+
declare const useResizeObserver: ({ disabled, }?: UseResizeObserverOptions) => UseObserverReturn<ResizeObserverEntry>;
|
|
297
|
+
|
|
298
|
+
interface ResourceType {
|
|
299
|
+
id?: string | null;
|
|
300
|
+
name?: string | null;
|
|
301
|
+
}
|
|
302
|
+
interface ResourceWithTypes extends Resource {
|
|
303
|
+
types?: ResourceType[];
|
|
304
|
+
settings?: {
|
|
305
|
+
hideTypeNames?: boolean;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
declare const useResourceTypeName: (resource: ResourceWithTypes | null, type?: string | null) => string | null;
|
|
309
|
+
|
|
310
|
+
type ResourceUrlGenerator = (routeResourceId: string | Resource, routeName?: string | Record<string, unknown> | null, params?: Record<string, unknown> | null) => string | null;
|
|
311
|
+
declare const useResourceUrlGenerator: (resourceId?: string | Resource | null) => ResourceUrlGenerator;
|
|
312
|
+
|
|
313
|
+
interface QueryParams {
|
|
314
|
+
page?: number;
|
|
315
|
+
count?: number;
|
|
316
|
+
[key: string]: unknown;
|
|
317
|
+
}
|
|
318
|
+
interface UseQueryReturn {
|
|
319
|
+
query: QueryParams | null;
|
|
320
|
+
onPageChange: (newPage: number) => void;
|
|
321
|
+
onQueryChange: (newQuery: QueryParams | null) => void;
|
|
322
|
+
onQueryReset: () => void;
|
|
323
|
+
}
|
|
324
|
+
declare const useQuery: (initialBaseQuery?: QueryParams | null, paginated?: boolean) => UseQueryReturn;
|
|
325
|
+
|
|
326
|
+
interface Screen {
|
|
327
|
+
name: string;
|
|
328
|
+
mediaQuery?: string | null;
|
|
329
|
+
}
|
|
330
|
+
interface Media {
|
|
331
|
+
type: string;
|
|
332
|
+
width: string;
|
|
333
|
+
height: string;
|
|
334
|
+
}
|
|
335
|
+
interface UseScreenSizeOptions {
|
|
336
|
+
width?: number | null;
|
|
337
|
+
height?: number | null;
|
|
338
|
+
landscape?: boolean;
|
|
339
|
+
screens?: Screen[];
|
|
340
|
+
mediaType?: string;
|
|
341
|
+
media?: Media | null;
|
|
342
|
+
}
|
|
343
|
+
interface ScreenSize {
|
|
344
|
+
screen: string | null;
|
|
345
|
+
screens: string[];
|
|
346
|
+
width: number | null;
|
|
347
|
+
height: number | null;
|
|
348
|
+
landscape: boolean;
|
|
349
|
+
}
|
|
350
|
+
interface UseScreenSizeFromElementOptions extends Omit<UseScreenSizeOptions, 'landscape'> {
|
|
351
|
+
withoutMaxSize?: boolean;
|
|
352
|
+
}
|
|
353
|
+
interface UseScreenSizeFromElementReturn {
|
|
354
|
+
ref: RefObject<Element>;
|
|
355
|
+
screenSize: ScreenSize;
|
|
356
|
+
}
|
|
357
|
+
declare const useScreenSizeFromElement: ({ width, height, ...opts }?: UseScreenSizeFromElementOptions) => UseScreenSizeFromElementReturn;
|
|
358
|
+
declare const useScreenSizeFromWindow: (opts?: UseScreenSizeOptions) => ScreenSize;
|
|
359
|
+
|
|
360
|
+
declare const useWindowEvent: (event: string, callback: (...args: unknown[]) => void, enabled?: boolean) => void;
|
|
361
|
+
|
|
362
|
+
export { KEYCODES, getObserver, useAnimationFrame, useDocumentEvent, useForm, useFormattedDate, useFormattedTime, useIntersectionObserver, useIsVisible, useKeyboardKeys, useLoadedFonts, useMediaApi, useMediasParser, useObserver, useQuery, useResizeObserver, useResourceTypeName, useResourceUrlGenerator, useScreenSizeFromElement, useScreenSizeFromWindow, useWindowEvent };
|
package/{es → dist}/hooks.js
RENAMED
|
@@ -7,10 +7,10 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
|
7
7
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
8
8
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
9
9
|
import { getCsrfToken, postJSON, getCSRFHeaders } from '@folklore/fetch';
|
|
10
|
-
import get from 'lodash
|
|
11
|
-
import isArray from 'lodash
|
|
12
|
-
import isObject from 'lodash
|
|
13
|
-
import isString from 'lodash
|
|
10
|
+
import get from 'lodash/get';
|
|
11
|
+
import isArray from 'lodash/isArray';
|
|
12
|
+
import isObject from 'lodash/isObject';
|
|
13
|
+
import isString from 'lodash/isString';
|
|
14
14
|
import { useFieldsManager, usePanneauResources, useResource, useUrlGenerator } from '@panneau/core/contexts';
|
|
15
15
|
import dayjs from 'dayjs';
|
|
16
16
|
import { useIntl } from 'react-intl';
|