@panneau/core 4.0.75 → 4.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.
package/dist/hooks.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Dayjs } from 'dayjs';
2
- import { ReactNode, ElementType, SubmitEvent, RefObject } from 'react';
3
- import { MessageDescriptor } from 'react-intl';
2
+ import { ReactNode, ComponentProps, ElementType, SyntheticEvent, RefObject } from 'react';
3
+ import { MessageDescriptor, FormattedMessage } from 'react-intl';
4
4
 
5
5
  interface UseAnimationFrameOptions {
6
6
  disabled?: boolean;
@@ -29,6 +29,12 @@ declare const useDocumentEvent: (event: string, callback: (...args: unknown[]) =
29
29
  * Internationalization message definition
30
30
  */
31
31
  type Message = MessageDescriptor;
32
+ /**
33
+ * Values that can be interpolated in an internationalization message
34
+ * (the `values` prop of FormattedMessage)
35
+ */
36
+ type MessageValues = NonNullable<ComponentProps<typeof FormattedMessage>['values']>;
37
+ type MessageValue = MessageValues[string];
32
38
  /**
33
39
  * Label can be either a message object or any React node
34
40
  */
@@ -37,14 +43,6 @@ type Label = Message | ReactNode;
37
43
  * Form control size
38
44
  */
39
45
  type ControlSize = 'lg' | 'sm' | null;
40
- /**
41
- * Generic definition
42
- */
43
- interface Definition {
44
- id: string;
45
- component?: string | ElementType;
46
- [key: string]: unknown;
47
- }
48
46
  interface RouteDefinition {
49
47
  path?: string;
50
48
  route?: string;
@@ -82,8 +80,6 @@ interface Form {
82
80
  submitButtonLabel?: Label | null;
83
81
  [key: string]: unknown;
84
82
  }
85
- interface FormDefinition extends Form, Definition {
86
- }
87
83
 
88
84
  /**
89
85
  * Resource Types
@@ -96,6 +92,7 @@ interface FormDefinition extends Form, Definition {
96
92
  type TableColumn = string | Column;
97
93
  interface Column extends Record<string, unknown> {
98
94
  id?: string | null;
95
+ name?: string | null;
99
96
  label?: unknown;
100
97
  path?: string;
101
98
  valueKey?: string;
@@ -121,7 +118,7 @@ type ActionDefinition = string | Action;
121
118
  interface ResourceIntlValues {
122
119
  a_singular?: string;
123
120
  a_plural?: string;
124
- [key: string]: unknown;
121
+ [key: string]: MessageValue;
125
122
  }
126
123
  /**
127
124
  * Internationalization configuration
@@ -149,13 +146,32 @@ interface ResourcePages {
149
146
  duplicate?: PageDefinition;
150
147
  [key: string]: PageDefinition | undefined;
151
148
  }
149
+ /**
150
+ * Form definition of a resource (the id is optional, the form is identified by its key)
151
+ */
152
+ interface ResourceForm extends Form {
153
+ id?: string;
154
+ component?: string | ElementType;
155
+ }
152
156
  interface ResourceForms {
153
- default: FormDefinition | null;
154
- create: FormDefinition | null;
155
- edit: FormDefinition | null;
156
- delete: FormDefinition | null;
157
- modal: FormDefinition | null;
158
- [key: string]: FormDefinition | null;
157
+ default?: ResourceForm | null;
158
+ create?: ResourceForm | null;
159
+ edit?: ResourceForm | null;
160
+ delete?: ResourceForm | null;
161
+ modal?: ResourceForm | null;
162
+ [key: string]: ResourceForm | null | undefined;
163
+ }
164
+ /**
165
+ * Resource type (sub-type of a resource, ex: page types)
166
+ */
167
+ interface ResourceType$1 {
168
+ id?: string;
169
+ name?: string;
170
+ fields?: Field$1[];
171
+ settings?: {
172
+ canCreate?: boolean;
173
+ [key: string]: unknown;
174
+ };
159
175
  }
160
176
  interface Resource {
161
177
  id: string;
@@ -167,6 +183,7 @@ interface Resource {
167
183
  settings?: Record<string, unknown>;
168
184
  extraRoutes?: RouteDefinition[];
169
185
  pages?: ResourcePages;
186
+ types?: ResourceType$1[];
170
187
  }
171
188
  /**
172
189
  * Filter definition
@@ -197,7 +214,7 @@ interface RequestState {
197
214
  loading: boolean;
198
215
  error: boolean;
199
216
  }
200
- interface UseFormOptions {
217
+ interface UseFormOptions<T extends FieldValue = FieldValue> {
201
218
  fields?: FieldInput[];
202
219
  action?: string | null;
203
220
  postForm?: ((action: string, data: Record<string, unknown>) => Promise<unknown>) | null;
@@ -207,28 +224,28 @@ interface UseFormOptions {
207
224
  initialGeneralError?: string | null;
208
225
  generalError?: string | null;
209
226
  setGeneralError?: ((error: string | null) => void) | null;
210
- initialValue?: FieldValue | null;
211
- value?: FieldValue | null;
212
- setValue?: ((value: FieldValue) => void) | null;
227
+ initialValue?: T | null;
228
+ value?: T | null;
229
+ setValue?: ((value: T) => void) | null;
213
230
  withoutDefault?: boolean;
214
231
  withoutPropagation?: boolean;
215
232
  onComplete?: ((response: unknown) => void) | null;
216
233
  onError?: ((error: Error) => void) | null;
217
234
  locales?: string[];
218
235
  }
219
- interface UseFormReturn extends RequestState {
220
- value: FieldValue | null;
221
- setValue: (value: FieldValue) => void;
236
+ interface UseFormReturn<T extends FieldValue = FieldValue> extends RequestState {
237
+ value: T | null;
238
+ setValue: (value: T) => void;
222
239
  csrfToken: string | null;
223
- submit: (submitValue?: FieldValue | null) => void;
224
- onSubmit: (e: SubmitEvent) => void;
240
+ submit: (submitValue?: T | null) => void;
241
+ onSubmit: (e: SyntheticEvent) => void;
225
242
  status: 'loading' | 'success' | 'error' | null;
226
243
  response: unknown;
227
244
  fields: ProcessedField[];
228
245
  errors: FieldErrors | null;
229
246
  generalError: string | null;
230
247
  }
231
- declare function useForm(opts?: UseFormOptions): UseFormReturn;
248
+ declare function useForm<T extends FieldValue = FieldValue>(opts?: UseFormOptions<T>): UseFormReturn<T>;
232
249
 
233
250
  interface UseIsVisibleOptions {
234
251
  rootMargin?: string;
@@ -236,7 +253,7 @@ interface UseIsVisibleOptions {
236
253
  persist?: boolean;
237
254
  }
238
255
  interface UseIsVisibleResult {
239
- ref: RefObject<HTMLElement>;
256
+ ref: RefObject<Element>;
240
257
  visible: boolean;
241
258
  }
242
259
  declare function useIsVisible({ rootMargin, threshold, persist, }?: UseIsVisibleOptions): UseIsVisibleResult;
@@ -304,7 +321,7 @@ interface Manager {
304
321
  }
305
322
  interface MediasParserOptions {
306
323
  fieldsManager: Manager;
307
- screensManager: Manager;
324
+ screensManager?: Manager | null;
308
325
  }
309
326
  interface Media$1 {
310
327
  id?: string | null;
@@ -324,18 +341,18 @@ interface Screen$1 {
324
341
  type: string;
325
342
  [key: string]: unknown;
326
343
  }
327
- interface Story {
328
- theme?: Story | null;
344
+ interface Story$1 {
345
+ theme?: Story$1 | null;
329
346
  components?: Screen$1[];
330
347
  medias?: Record<string, Media$1> | null;
331
348
  [key: string]: unknown;
332
349
  }
333
350
  declare class MediasParser {
334
351
  fieldsManager: Manager;
335
- screensManager: Manager;
352
+ screensManager: Manager | null;
336
353
  constructor({ fieldsManager, screensManager }: MediasParserOptions);
337
- toPath(story: Story | null): Story | null;
338
- fromPath(story: Story | null, defaultMedias?: Record<string, Media$1> | null): Story | null;
354
+ toPath(story: Story$1 | null): Story$1 | null;
355
+ fromPath(story: Story$1 | null, defaultMedias?: Record<string, Media$1> | null): Story$1 | null;
339
356
  getMediaFieldsPattern(fields: Field[], namePrefix?: string | null): RegExp[];
340
357
  static fieldIsMedia({ media }: Field): boolean;
341
358
  static fieldIsFontFamily({ id }: Field): boolean;
@@ -347,9 +364,10 @@ declare class MediasParser {
347
364
  };
348
365
  }
349
366
 
367
+ type Story = Parameters<MediasParser['toPath']>[0];
350
368
  interface UseMediasParserReturn {
351
- toPath: (story: unknown) => string;
352
- fromPath: (story: unknown) => unknown;
369
+ toPath: (story: Story) => Story;
370
+ fromPath: (story: Story) => Story;
353
371
  parser: MediasParser;
354
372
  }
355
373
  declare function useMediasParser(): UseMediasParserReturn;
@@ -362,7 +380,7 @@ type ObserverConstructor<T> = (new (callback: (entries: T[]) => void, options?:
362
380
  interface ObserverWrapper<T> {
363
381
  subscribe: (element: Element, callback: (entry: T) => void) => void;
364
382
  unsubscribe: (element: Element, callback?: ((entry: T) => void) | null) => void;
365
- observer: ReturnType<NonNullable<ObserverConstructor<T>>>;
383
+ observer: InstanceType<NonNullable<ObserverConstructor<T>>>;
366
384
  }
367
385
  interface ObserverOptions {
368
386
  root?: Element | null;
@@ -379,7 +397,7 @@ declare function useObserver<T>(Observer: ObserverConstructor<T>, opts?: Observe
379
397
  interface IntersectionObserverEntry {
380
398
  target: Element | null;
381
399
  time: number | null;
382
- isVisible: boolean;
400
+ isVisible?: boolean;
383
401
  isIntersecting: boolean;
384
402
  intersectionRatio: number;
385
403
  intersectionRect: DOMRectReadOnly | null;