@panneau/core 4.0.8 → 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 +25 -25
- package/dist/hooks.d.ts +362 -0
- package/{es → dist}/hooks.js +7 -174
- 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 +8 -8
- package/package.json +21 -37
- package/contexts.js +0 -1
- package/es/types/core.d.ts +0 -133
- package/es/types/form.d.ts +0 -58
- package/es/types/index.d.ts +0 -39
- package/es/types/panneau.d.ts +0 -49
- package/es/types/resource.d.ts +0 -93
- package/hooks.js +0 -1
- package/lib/contexts.js +0 -1420
- package/lib/hooks.js +0 -1337
- package/lib/index.js +0 -1019
- package/lib/utils.js +0 -789
- package/utils.js +0 -1
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
|
@@ -1,188 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import isArray from 'lodash-es/isArray';
|
|
3
|
-
import { useMemo, useRef, useEffect, useCallback, useState } from 'react';
|
|
4
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
5
|
-
import isObject from 'lodash-es/isObject';
|
|
6
|
-
import isString from 'lodash-es/isString';
|
|
1
|
+
import { useRef, useEffect, useCallback, useState, useMemo } from 'react';
|
|
7
2
|
import { EventsManager, MediasParser } from '@panneau/core';
|
|
8
3
|
import { createUseEvent, loadPackage } from '@panneau/core/utils';
|
|
9
4
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
10
5
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
11
7
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
12
8
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
13
9
|
import { getCsrfToken, postJSON, getCSRFHeaders } from '@folklore/fetch';
|
|
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';
|
|
17
17
|
import { match } from 'css-mediaquery';
|
|
18
18
|
|
|
19
|
-
function useActionProps(action, value) {
|
|
20
|
-
var labelPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
21
|
-
var values = useMemo(function () {
|
|
22
|
-
if (value === null) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
if (isArray(value)) {
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
return value || null;
|
|
29
|
-
}, [value]);
|
|
30
|
-
var ids = useMemo(function () {
|
|
31
|
-
if (value === null) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
if (isArray(value)) {
|
|
35
|
-
return value.map(function () {
|
|
36
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
37
|
-
_ref$id = _ref.id,
|
|
38
|
-
id = _ref$id === void 0 ? null : _ref$id;
|
|
39
|
-
return id;
|
|
40
|
-
}).filter(function (id) {
|
|
41
|
-
return id !== null;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return value !== null && typeof value.id !== 'undefined' ? [value.id] : null;
|
|
45
|
-
}, [value]);
|
|
46
|
-
var idKeys = useMemo(function () {
|
|
47
|
-
return (ids || []).map(function (id) {
|
|
48
|
-
return "".concat(id);
|
|
49
|
-
}).join('-');
|
|
50
|
-
}, [ids]);
|
|
51
|
-
var idLabels = useMemo(function () {
|
|
52
|
-
return isArray(values) ? values.map(function () {
|
|
53
|
-
var it = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
54
|
-
return "#".concat(get(it, 'id', '')).concat(labelPath !== null ? " ".concat(get(it, labelPath, '')) : '');
|
|
55
|
-
}).join(', ') : get(values, 'id', 'no-value');
|
|
56
|
-
}, [ids]);
|
|
57
|
-
var modalKey = useMemo(function () {
|
|
58
|
-
return "".concat(action, "-").concat(idKeys);
|
|
59
|
-
}, [idKeys]);
|
|
60
|
-
return {
|
|
61
|
-
ids: ids,
|
|
62
|
-
idKeys: idKeys,
|
|
63
|
-
idLabels: idLabels,
|
|
64
|
-
modalKey: modalKey
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// For backwards compatibility with the old actions element
|
|
69
|
-
|
|
70
|
-
function useActions() {
|
|
71
|
-
var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
72
|
-
var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
73
|
-
var urlGenerator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
74
|
-
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
75
|
-
_ref$iconsOnly = _ref.iconsOnly,
|
|
76
|
-
iconsOnly = _ref$iconsOnly === void 0 ? true : _ref$iconsOnly,
|
|
77
|
-
_ref$showLabel = _ref.showLabel,
|
|
78
|
-
showLabel = _ref$showLabel === void 0 ? null : _ref$showLabel,
|
|
79
|
-
_ref$editLabel = _ref.editLabel,
|
|
80
|
-
editLabel = _ref$editLabel === void 0 ? null : _ref$editLabel,
|
|
81
|
-
_ref$deleteLabel = _ref.deleteLabel,
|
|
82
|
-
deleteLabel = _ref$deleteLabel === void 0 ? null : _ref$deleteLabel,
|
|
83
|
-
_ref$onClickShow = _ref.onClickShow,
|
|
84
|
-
onClickShow = _ref$onClickShow === void 0 ? null : _ref$onClickShow,
|
|
85
|
-
_ref$onClickEdit = _ref.onClickEdit,
|
|
86
|
-
onClickEdit = _ref$onClickEdit === void 0 ? null : _ref$onClickEdit,
|
|
87
|
-
_ref$onClickDelete = _ref.onClickDelete,
|
|
88
|
-
onClickDelete = _ref$onClickDelete === void 0 ? null : _ref$onClickDelete,
|
|
89
|
-
_ref$getShowPropsFrom = _ref.getShowPropsFromItem,
|
|
90
|
-
getShowPropsFromItem = _ref$getShowPropsFrom === void 0 ? null : _ref$getShowPropsFrom,
|
|
91
|
-
_ref$getEditPropsFrom = _ref.getEditPropsFromItem,
|
|
92
|
-
getEditPropsFromItem = _ref$getEditPropsFrom === void 0 ? null : _ref$getEditPropsFrom,
|
|
93
|
-
_ref$getDeletePropsFr = _ref.getDeletePropsFromItem,
|
|
94
|
-
getDeletePropsFromItem = _ref$getDeletePropsFr === void 0 ? null : _ref$getDeletePropsFr,
|
|
95
|
-
_ref$showUrl = _ref.showUrl,
|
|
96
|
-
showUrl = _ref$showUrl === void 0 ? null : _ref$showUrl,
|
|
97
|
-
_ref$withoutItemShowU = _ref.withoutItemShowUrl,
|
|
98
|
-
withoutItemShowUrl = _ref$withoutItemShowU === void 0 ? null : _ref$withoutItemShowU,
|
|
99
|
-
_ref$preferEditModal = _ref.preferEditModal,
|
|
100
|
-
preferEditModal = _ref$preferEditModal === void 0 ? false : _ref$preferEditModal,
|
|
101
|
-
_ref$preferDeleteModa = _ref.preferDeleteModal,
|
|
102
|
-
preferDeleteModal = _ref$preferDeleteModa === void 0 ? false : _ref$preferDeleteModa,
|
|
103
|
-
_ref$hasDuplicateRout = _ref.hasDuplicateRoute,
|
|
104
|
-
hasDuplicateRoute = _ref$hasDuplicateRout === void 0 ? false : _ref$hasDuplicateRout;
|
|
105
|
-
var _ref2 = item || {},
|
|
106
|
-
id = _ref2.id,
|
|
107
|
-
_ref2$url = _ref2.url,
|
|
108
|
-
url = _ref2$url === void 0 ? null : _ref2$url;
|
|
109
|
-
var hasCustomShowUrl = showUrl !== null || url !== null;
|
|
110
|
-
return (actions || []).map(function (action) {
|
|
111
|
-
if (isString(action)) {
|
|
112
|
-
switch (action) {
|
|
113
|
-
case 'show':
|
|
114
|
-
return _objectSpread({
|
|
115
|
-
id: 'show',
|
|
116
|
-
component: 'show',
|
|
117
|
-
label: iconsOnly ? null : showLabel,
|
|
118
|
-
icon: iconsOnly ? 'eye' : null,
|
|
119
|
-
href: urlGenerator !== null && (!hasCustomShowUrl || withoutItemShowUrl) ? urlGenerator('show', {
|
|
120
|
-
id: id
|
|
121
|
-
}) || null : showUrl || url,
|
|
122
|
-
external: hasCustomShowUrl,
|
|
123
|
-
theme: 'info',
|
|
124
|
-
target: '_blank',
|
|
125
|
-
onClick: onClickShow
|
|
126
|
-
}, getShowPropsFromItem !== null ? getShowPropsFromItem(item) : null);
|
|
127
|
-
case 'edit':
|
|
128
|
-
return _objectSpread({
|
|
129
|
-
id: 'edit',
|
|
130
|
-
component: 'edit',
|
|
131
|
-
label: iconsOnly ? null : editLabel,
|
|
132
|
-
icon: iconsOnly ? 'pencil-square' : null,
|
|
133
|
-
href: urlGenerator !== null && !preferEditModal ? urlGenerator('edit', {
|
|
134
|
-
id: id
|
|
135
|
-
}) || null : null,
|
|
136
|
-
theme: 'primary',
|
|
137
|
-
onClick: onClickEdit
|
|
138
|
-
}, getEditPropsFromItem !== null ? getEditPropsFromItem(item) : null);
|
|
139
|
-
case 'duplicate':
|
|
140
|
-
return {
|
|
141
|
-
id: 'duplicate',
|
|
142
|
-
component: 'duplicate',
|
|
143
|
-
label: null,
|
|
144
|
-
href: urlGenerator !== null && hasDuplicateRoute ? urlGenerator('duplicate', {
|
|
145
|
-
id: id
|
|
146
|
-
}) || null : null
|
|
147
|
-
};
|
|
148
|
-
case 'restore':
|
|
149
|
-
return {
|
|
150
|
-
id: 'restore',
|
|
151
|
-
component: 'restore',
|
|
152
|
-
label: null
|
|
153
|
-
};
|
|
154
|
-
case 'delete':
|
|
155
|
-
return _objectSpread({
|
|
156
|
-
id: 'delete',
|
|
157
|
-
component: 'delete',
|
|
158
|
-
label: iconsOnly ? null : deleteLabel,
|
|
159
|
-
icon: iconsOnly ? 'trash3' : null,
|
|
160
|
-
href: urlGenerator !== null && !preferDeleteModal ? urlGenerator('delete', {
|
|
161
|
-
id: id
|
|
162
|
-
}) || null : null,
|
|
163
|
-
theme: 'danger',
|
|
164
|
-
onClick: onClickDelete,
|
|
165
|
-
endpoint: urlGenerator !== null && preferDeleteModal ? urlGenerator('delete', {
|
|
166
|
-
id: id
|
|
167
|
-
}) || null : null,
|
|
168
|
-
withConfirmation: preferDeleteModal
|
|
169
|
-
}, getDeletePropsFromItem !== null ? getDeletePropsFromItem(item) : null);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (isObject(action)) {
|
|
173
|
-
var _ref3 = action || {},
|
|
174
|
-
_ref3$itemLinkProp = _ref3.itemLinkProp,
|
|
175
|
-
itemLinkProp = _ref3$itemLinkProp === void 0 ? null : _ref3$itemLinkProp;
|
|
176
|
-
return _objectSpread(_objectSpread({}, action), itemLinkProp !== null && isObject(item) && typeof item[itemLinkProp] !== 'undefined' ? {
|
|
177
|
-
href: item[itemLinkProp]
|
|
178
|
-
} : null);
|
|
179
|
-
}
|
|
180
|
-
return action;
|
|
181
|
-
}).filter(function (action) {
|
|
182
|
-
return action !== null;
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
19
|
function useAnimationFrame(onFrame) {
|
|
187
20
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
188
21
|
_ref$disabled = _ref.disabled,
|
|
@@ -1310,4 +1143,4 @@ var useScreenSizeFromWindow = function useScreenSizeFromWindow() {
|
|
|
1310
1143
|
var eventsManager = typeof window !== 'undefined' ? new EventsManager(window) : null;
|
|
1311
1144
|
var useWindowEvent = createUseEvent(eventsManager);
|
|
1312
1145
|
|
|
1313
|
-
export { KEYCODES, getObserver,
|
|
1146
|
+
export { KEYCODES, getObserver, useAnimationFrame, useDocumentEvent, useForm, useFormattedDate, useFormattedTime, useIntersectionObserver, useIsVisible, useKeyboardKeys, useLoadedFonts, useMediaApi, useMediasParser, useObserver, useQuery, useResizeObserver, useResourceTypeName, useResourceUrlGenerator, useScreenSizeFromElement, useScreenSizeFromWindow, useWindowEvent };
|