@panneau/core 3.0.223 → 3.0.224

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/lib/contexts.js DELETED
@@ -1,1624 +0,0 @@
1
- 'use strict';
2
-
3
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var isString = require('lodash/isString');
5
- var PropTypes = require('prop-types');
6
- var React = require('react');
7
- var core = require('@panneau/core');
8
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
9
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
10
- var uniqBy = require('lodash/uniqBy');
11
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
12
- var fetch = require('@folklore/fetch');
13
- var isObject = require('lodash/isObject');
14
- var services = require('@folklore/services');
15
- var reactIntl = require('react-intl');
16
- var utils = require('@panneau/core/utils');
17
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
18
- var jsxRuntime = require('react/jsx-runtime');
19
- var pathToRegexp = require('path-to-regexp');
20
- var regexparam = require('regexparam');
21
- var index_js = require('use-sync-external-store/shim/index.js');
22
- var tracking = require('@folklore/tracking');
23
-
24
- function _interopNamespaceDefault(e) {
25
- var n = Object.create(null);
26
- if (e) {
27
- Object.keys(e).forEach(function (k) {
28
- if (k !== 'default') {
29
- var d = Object.getOwnPropertyDescriptor(e, k);
30
- Object.defineProperty(n, k, d.get ? d : {
31
- enumerable: true,
32
- get: function () { return e[k]; }
33
- });
34
- }
35
- });
36
- }
37
- n.default = e;
38
- return Object.freeze(n);
39
- }
40
-
41
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
42
-
43
- var MODALS_NAMESPACE = 'modals';
44
- var FIELDS_NAMESPACE = 'fields';
45
- var FORMS_NAMESPACE = 'forms';
46
- var FILTERS_NAMESPACE = 'filters';
47
- var LISTS_NAMESPACE = 'lists';
48
- var DISPLAYS_NAMESPACE = 'displays';
49
- var ACTIONS_NAMESPACE = 'actions';
50
- var BUTTONS_NAMESPACE = 'buttons';
51
- var PAGES_NAMESPACE = 'pages';
52
- var APP_NAMESPACE = 'app';
53
- var ComponentsContext = /*#__PURE__*/React.createContext(null);
54
-
55
- /**
56
- * Hooks
57
- */
58
- var useComponentsManager = function useComponentsManager() {
59
- var namespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
60
- var manager = React.useContext(ComponentsContext);
61
- var finalManager = React.useMemo(function () {
62
- return namespace !== null ? new core.ComponentsManager(manager.getComponents(namespace)) : manager;
63
- }, [manager, namespace]);
64
- return finalManager;
65
- };
66
- var useComponents = function useComponents() {
67
- var namespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
68
- var defaultComponents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
69
- var manager = useComponentsManager();
70
- return manager.getComponents(namespace) || defaultComponents;
71
- };
72
- var useComponent = function useComponent(name) {
73
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
74
- var namespace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
75
- var manager = useComponentsManager(namespace);
76
- return React.useMemo(function () {
77
- if (!isString(name)) {
78
- return name || defaultComponent;
79
- }
80
- return manager.getComponent(name) || defaultComponent;
81
- }, [manager, name, defaultComponent]);
82
- };
83
-
84
- /**
85
- * Fields hooks
86
- */
87
- var useFieldsComponentsManager = function useFieldsComponentsManager() {
88
- return useComponentsManager(FIELDS_NAMESPACE);
89
- };
90
- var useFieldsComponents = function useFieldsComponents() {
91
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92
- return useComponents(FIELDS_NAMESPACE, defaultComponents);
93
- };
94
- var useFieldComponent = function useFieldComponent(name) {
95
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
96
- return useComponent(name, defaultComponent, FIELDS_NAMESPACE);
97
- };
98
-
99
- /**
100
- * Forms hooks
101
- */
102
- var useFormsComponentsManager = function useFormsComponentsManager() {
103
- return useComponentsManager(FORMS_NAMESPACE);
104
- };
105
- var useFormsComponents = function useFormsComponents() {
106
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
107
- return useComponents(FORMS_NAMESPACE, defaultComponents);
108
- };
109
- var useFormComponent = function useFormComponent(name) {
110
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
111
- return useComponent(name, defaultComponent, FORMS_NAMESPACE);
112
- };
113
-
114
- /**
115
- * Modals hooks
116
- */
117
- var useModalsComponentsManager = function useModalsComponentsManager() {
118
- return useComponentsManager(MODALS_NAMESPACE);
119
- };
120
- var useModalsComponents = function useModalsComponents() {
121
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
122
- return useComponents(MODALS_NAMESPACE, defaultComponents);
123
- };
124
- var useModalComponent = function useModalComponent(name) {
125
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
126
- return useComponent(name, defaultComponent, MODALS_NAMESPACE);
127
- };
128
-
129
- /**
130
- * Filters hooks
131
- */
132
- var useFiltersComponentsManager = function useFiltersComponentsManager() {
133
- return useComponentsManager(FILTERS_NAMESPACE);
134
- };
135
- var useFiltersComponents = function useFiltersComponents() {
136
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
137
- return useComponents(FILTERS_NAMESPACE, defaultComponents);
138
- };
139
- var useFilterComponent = function useFilterComponent(name) {
140
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
141
- return useComponent(name, defaultComponent, FILTERS_NAMESPACE);
142
- };
143
-
144
- /**
145
- * Lists hooks
146
- */
147
- var useListsComponentsManager = function useListsComponentsManager() {
148
- return useComponentsManager(LISTS_NAMESPACE);
149
- };
150
- var useListsComponents = function useListsComponents() {
151
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
152
- return useComponents(LISTS_NAMESPACE, defaultComponents);
153
- };
154
- var useListComponent = function useListComponent(name) {
155
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
156
- return useComponent(name, defaultComponent, LISTS_NAMESPACE);
157
- };
158
-
159
- /**
160
- * Displays hooks
161
- */
162
- var useDisplaysComponentsManager = function useDisplaysComponentsManager() {
163
- return useComponentsManager(DISPLAYS_NAMESPACE);
164
- };
165
- var useDisplaysComponents = function useDisplaysComponents() {
166
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
167
- return useComponents(DISPLAYS_NAMESPACE, defaultComponents);
168
- };
169
- var useDisplayComponent = function useDisplayComponent(name) {
170
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
171
- return useComponent(name, defaultComponent, DISPLAYS_NAMESPACE);
172
- };
173
-
174
- /**
175
- * Actions hooks
176
- */
177
- var useActionsComponentsManager = function useActionsComponentsManager() {
178
- return useComponentsManager(ACTIONS_NAMESPACE);
179
- };
180
- var useActionsComponents = function useActionsComponents() {
181
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
182
- return useComponents(ACTIONS_NAMESPACE, defaultComponents);
183
- };
184
- var useActionComponent = function useActionComponent(name) {
185
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
186
- return useComponent(name, defaultComponent, ACTIONS_NAMESPACE);
187
- };
188
-
189
- /**
190
- * Buttons hooks
191
- */
192
- var useButtonsComponentsManager = function useButtonsComponentsManager() {
193
- return useComponentsManager(BUTTONS_NAMESPACE);
194
- };
195
- var useButtonsComponents = function useButtonsComponents() {
196
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
197
- return useComponents(BUTTONS_NAMESPACE, defaultComponents);
198
- };
199
- var useButtonComponent = function useButtonComponent(name) {
200
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
201
- return useComponent(name, defaultComponent, BUTTONS_NAMESPACE);
202
- };
203
-
204
- /**
205
- * Pages hooks
206
- */
207
- var usePagesComponentsManager = function usePagesComponentsManager() {
208
- return useComponentsManager(PAGES_NAMESPACE);
209
- };
210
- var usePagesComponents = function usePagesComponents() {
211
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
212
- return useComponents(PAGES_NAMESPACE, defaultComponents);
213
- };
214
- var usePageComponent = function usePageComponent(name) {
215
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
216
- return useComponent(name, defaultComponent, PAGES_NAMESPACE);
217
- };
218
-
219
- /**
220
- * App hooks
221
- */
222
- var useAppComponentsManager = function useAppComponentsManager() {
223
- return useComponentsManager(APP_NAMESPACE);
224
- };
225
- var useAppComponents = function useAppComponents() {
226
- var defaultComponents = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
227
- return useComponents(APP_NAMESPACE, defaultComponents);
228
- };
229
- var useAppComponent = function useAppComponent(name) {
230
- var defaultComponent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
231
- return useComponent(name, defaultComponent, APP_NAMESPACE);
232
- };
233
-
234
- /**
235
- * Provider
236
- */
237
- var propTypes$e = {
238
- children: PropTypes.node.isRequired,
239
- namespace: PropTypes.string,
240
- manager: PropTypes.instanceOf(core.ComponentsManager),
241
- components: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.object, PropTypes.func]))
242
- };
243
- var defaultProps$e = {
244
- namespace: null,
245
- components: {},
246
- manager: null
247
- };
248
- var ComponentsProvider = function ComponentsProvider(_ref) {
249
- var components = _ref.components,
250
- manager = _ref.manager,
251
- namespace = _ref.namespace,
252
- children = _ref.children;
253
- var previousManager = useComponentsManager() || null;
254
- var finalManager = React.useMemo(function () {
255
- return new core.ComponentsManager(_objectSpread(_objectSpread(_objectSpread({}, previousManager !== null ? previousManager.getComponents() : null), manager !== null ? manager.getComponents() : null), new core.ComponentsManager(components).addNamespace(namespace).getComponents()));
256
- }, [previousManager, manager, components, namespace]);
257
- return /*#__PURE__*/React.createElement(ComponentsContext.Provider, {
258
- value: finalManager
259
- }, children);
260
- };
261
- ComponentsProvider.propTypes = propTypes$e;
262
- ComponentsProvider.defaultProps = defaultProps$e;
263
-
264
- var message = PropTypes.shape({
265
- id: PropTypes.string.isRequired,
266
- defaultMessage: PropTypes.string
267
- });
268
- var label = PropTypes.oneOfType([message, PropTypes.node]);
269
- PropTypes.oneOfType([PropTypes.number, PropTypes.string]);
270
-
271
- /**
272
- * Core
273
- */
274
- var menuItem = PropTypes.shape({
275
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
276
- label: label,
277
- url: PropTypes.string,
278
- external: PropTypes.bool,
279
- active: PropTypes.bool
280
- });
281
- PropTypes.arrayOf(menuItem);
282
- var button = PropTypes.shape({
283
- id: PropTypes.string,
284
- label: label,
285
- onClick: PropTypes.func
286
- });
287
- PropTypes.arrayOf(button);
288
- PropTypes.oneOf(['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', null]);
289
- PropTypes.oneOf(['lg', 'md', 'sm', null]);
290
- PropTypes.oneOf(['button', 'submit']);
291
- PropTypes.oneOf(['start', 'end']);
292
- PropTypes.oneOf(['lg', 'sm', null]);
293
- PropTypes.oneOf(['loading', 'success', 'error', null]);
294
- var fieldOption = PropTypes.shape({
295
- value: PropTypes.string,
296
- label: PropTypes.string
297
- });
298
- PropTypes.arrayOf(fieldOption);
299
- var toggle = PropTypes.shape({
300
- key: PropTypes.string,
301
- label: PropTypes.string
302
- });
303
- PropTypes.arrayOf(toggle);
304
- var tableColumn = PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
305
- id: PropTypes.string,
306
- component: PropTypes.string,
307
- path: PropTypes.string,
308
- field: PropTypes.string,
309
- columnClassName: PropTypes.string
310
- })]);
311
- PropTypes.arrayOf(tableColumn);
312
-
313
- /**
314
- * Panneau Definitions
315
- */
316
- var routes = PropTypes.shape({
317
- 'resources.index': PropTypes.string.isRequired,
318
- 'resources.create': PropTypes.string.isRequired,
319
- 'resources.store': PropTypes.string.isRequired,
320
- 'resources.show': PropTypes.string.isRequired,
321
- 'resources.edit': PropTypes.string.isRequired,
322
- 'resources.update': PropTypes.string.isRequired,
323
- 'resources.delete': PropTypes.string.isRequired,
324
- 'resources.destroy': PropTypes.string.isRequired
325
- // 'resources.duplicate': PropTypes.string.isRequired,
326
- });
327
- var intl = PropTypes.shape({
328
- locale: PropTypes.string,
329
- messages: PropTypes.objectOf(PropTypes.string),
330
- values: PropTypes.objectOf(PropTypes.string)
331
- });
332
- var page = PropTypes.shape({
333
- component: PropTypes.string.isRequired
334
- });
335
- var pages = PropTypes.objectOf(page);
336
- var field = PropTypes.shape({
337
- name: PropTypes.string,
338
- // Not required on localized fields
339
- type: PropTypes.string,
340
- component: PropTypes.string,
341
- label: PropTypes.node
342
- });
343
- var fields = PropTypes.arrayOf(field);
344
- var form = PropTypes.shape({
345
- // type: PropTypes.string.isRequired,
346
- title: PropTypes.isRequired,
347
- fields: fields
348
- });
349
- PropTypes.arrayOf(form);
350
- var resource = PropTypes.shape({
351
- id: PropTypes.string.isRequired,
352
- name: PropTypes.string.isRequired,
353
- intl: intl,
354
- fields: fields,
355
- forms: PropTypes.shape({}),
356
- shows_in_navbar: PropTypes.bool
357
- });
358
- var resources = PropTypes.arrayOf(resource);
359
- var panneauDefinition = PropTypes.shape({
360
- name: PropTypes.string,
361
- resources: resources,
362
- routes: routes,
363
- pages: pages,
364
- intl: intl
365
- // intl,
366
- });
367
- var definition = PropTypes.shape({
368
- name: PropTypes.string
369
- // resources,
370
- // routes,
371
- // intl,
372
- });
373
- var item = PropTypes.shape({
374
- id: PropTypes.string.isRequired
375
- });
376
- PropTypes.arrayOf(item);
377
- var user = PropTypes.shape({
378
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
379
- });
380
- PropTypes.arrayOf(user);
381
- var selectOption = PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.shape({
382
- value: PropTypes.any,
383
- // eslint-disable-line
384
- label: label
385
- }), PropTypes.object]);
386
- PropTypes.arrayOf(selectOption);
387
- PropTypes.oneOf(['valid', 'invalid', 'loading', null]);
388
- var formError = PropTypes.shape({
389
- message: PropTypes.string
390
- });
391
- PropTypes.arrayOf(formError);
392
- PropTypes.shape({
393
- tus: PropTypes.object
394
- }); // eslint-disable-line
395
-
396
- PropTypes.string;
397
- var breadcrumb = PropTypes.shape({
398
- url: PropTypes.string
399
- });
400
- PropTypes.arrayOf(breadcrumb);
401
- var font = PropTypes.shape({
402
- // url: PropTypes.string,
403
- });
404
- PropTypes.arrayOf(font);
405
- PropTypes.shape({});
406
- var modal = PropTypes.shape({
407
- name: PropTypes.string
408
- });
409
- PropTypes.arrayOf(modal);
410
- var filter = PropTypes.shape({
411
- id: PropTypes.string,
412
- component: PropTypes.string
413
- });
414
- PropTypes.arrayOf(filter);
415
- var media = PropTypes.shape({
416
- id: PropTypes.string.isRequired,
417
- name: PropTypes.string.isRequired,
418
- type: PropTypes.string.isRequired,
419
- thumbnail_url: PropTypes.string
420
- });
421
- PropTypes.arrayOf(media);
422
-
423
- /* eslint-disable react/jsx-props-no-spreading */
424
- var DefinitionContext = /*#__PURE__*/React.createContext(null);
425
- var useDefinitionContext = function useDefinitionContext() {
426
- return React.useContext(DefinitionContext);
427
- };
428
- var useDefinition = function useDefinition() {
429
- var _useDefinitionContext = useDefinitionContext(),
430
- _useDefinitionContext2 = _useDefinitionContext.definition,
431
- definition = _useDefinitionContext2 === void 0 ? null : _useDefinitionContext2;
432
- return definition;
433
- };
434
- var propTypes$d = {
435
- definition: definition.isRequired,
436
- children: PropTypes.node.isRequired
437
- };
438
- var defaultProps$d = {};
439
- var DefinitionProvider = function DefinitionProvider(_ref) {
440
- var definition = _ref.definition,
441
- children = _ref.children;
442
- return /*#__PURE__*/React.createElement(DefinitionContext.Provider, {
443
- value: definition
444
- }, children);
445
- };
446
- DefinitionProvider.propTypes = propTypes$d;
447
- DefinitionProvider.defaultProps = defaultProps$d;
448
-
449
- var FieldsContext = /*#__PURE__*/React.createContext(null);
450
- var useFieldsManager = function useFieldsManager() {
451
- return React.useContext(FieldsContext);
452
- };
453
- var useField = function useField(id) {
454
- var manager = useFieldsManager();
455
- return manager.getDefinition(id);
456
- };
457
- var useFields = function useFields() {
458
- var manager = useFieldsManager();
459
- return manager.getDefinitions();
460
- };
461
- var propTypes$c = {
462
- fields: core.PropTypes.fields,
463
- manager: PropTypes.instanceOf(core.FieldsManager),
464
- children: PropTypes.node.isRequired
465
- };
466
- var defaultProps$c = {
467
- fields: null,
468
- manager: null
469
- };
470
- var FieldsProvider = function FieldsProvider(_ref) {
471
- var fields = _ref.fields,
472
- manager = _ref.manager,
473
- children = _ref.children;
474
- var previousManager = useFieldsManager() || null;
475
- var finalManager = React.useMemo(function () {
476
- var newFields = uniqBy([].concat(_toConsumableArray(fields || []), _toConsumableArray(manager !== null ? manager.getDefinitions() : []), _toConsumableArray(previousManager !== null ? previousManager.getDefinitions() : [])), function (_ref2) {
477
- var id = _ref2.id;
478
- return id;
479
- }).reverse();
480
- return new core.FieldsManager(newFields);
481
- }, [previousManager, manager, fields]);
482
- var components = React.useMemo(function () {
483
- var newComponents = finalManager.getComponents();
484
- return Object.keys(newComponents).reduce(function (map, id) {
485
- var component = newComponents[id];
486
- return isString(component) ? map : _objectSpread(_objectSpread({}, map), {}, _defineProperty({}, id, component));
487
- }, {});
488
- }, [finalManager]);
489
- return /*#__PURE__*/React.createElement(FieldsContext.Provider, {
490
- value: finalManager
491
- }, /*#__PURE__*/React.createElement(ComponentsProvider, {
492
- namespace: FIELDS_NAMESPACE,
493
- components: components
494
- }, children));
495
- };
496
- FieldsProvider.propTypes = propTypes$c;
497
- FieldsProvider.defaultProps = defaultProps$c;
498
-
499
- /* eslint-disable react/jsx-props-no-spreading */
500
- var GoogleKeysContext = /*#__PURE__*/React.createContext({
501
- apiKey: null
502
- });
503
- var useGoogleKeys = function useGoogleKeys() {
504
- return React.useContext(GoogleKeysContext);
505
- };
506
- var propTypes$b = {
507
- children: PropTypes.node.isRequired,
508
- apiKey: PropTypes.string // .isRequired,
509
- };
510
- var defaultProps$b = {
511
- apiKey: null
512
- };
513
- var GoogleKeysProvider = function GoogleKeysProvider(_ref) {
514
- var children = _ref.children,
515
- apiKey = _ref.apiKey;
516
- var _useGoogleKeys = useGoogleKeys(),
517
- previousApiKey = _useGoogleKeys.apiKey;
518
- var value = React.useMemo(function () {
519
- return {
520
- apiKey: apiKey || previousApiKey
521
- };
522
- }, [previousApiKey, apiKey]);
523
- return /*#__PURE__*/React.createElement(GoogleKeysContext.Provider, {
524
- value: value
525
- }, children);
526
- };
527
- GoogleKeysProvider.propTypes = propTypes$b;
528
- GoogleKeysProvider.defaultProps = defaultProps$b;
529
-
530
- var FontsContext = /*#__PURE__*/React.createContext({
531
- systemFonts: null,
532
- googleFonts: null,
533
- customFonts: null
534
- });
535
- var useGoogleFonts = function useGoogleFonts() {
536
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
537
- _ref$disabled = _ref.disabled,
538
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
539
- _ref$setFonts = _ref.setFonts,
540
- setFonts = _ref$setFonts === void 0 ? null : _ref$setFonts;
541
- var _useGoogleKeys = useGoogleKeys(),
542
- apiKey = _useGoogleKeys.apiKey;
543
- var _useState = React.useState(null),
544
- _useState2 = _slicedToArray(_useState, 2),
545
- googleFonts = _useState2[0],
546
- setGoogleFonts = _useState2[1];
547
- React.useEffect(function () {
548
- var canceled = false;
549
- if (apiKey !== null && !disabled) {
550
- fetch.getJSON("https://www.googleapis.com/webfonts/v1/webfonts?key=".concat(apiKey, "&sort=popularity")).then(function (_ref2) {
551
- var _ref2$items = _ref2.items,
552
- items = _ref2$items === void 0 ? [] : _ref2$items;
553
- if (!canceled) {
554
- var newFonts = items.map(function (it) {
555
- return {
556
- type: 'google',
557
- name: it.family,
558
- variants: it.variants
559
- };
560
- });
561
- if (setFonts !== null) {
562
- setFonts(newFonts);
563
- } else {
564
- setGoogleFonts(newFonts);
565
- }
566
- }
567
- });
568
- }
569
- return function () {
570
- canceled = true;
571
- };
572
- }, [apiKey, disabled, setFonts, setGoogleFonts]);
573
- return googleFonts;
574
- };
575
- var useFonts = function useFonts() {
576
- var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
577
- _ref3$withoutGoogleFo = _ref3.withoutGoogleFonts,
578
- withoutGoogleFonts = _ref3$withoutGoogleFo === void 0 ? false : _ref3$withoutGoogleFo;
579
- var _useContext = React.useContext(FontsContext),
580
- _useContext$setGoogle = _useContext.setGoogleFonts,
581
- setGoogleFonts = _useContext$setGoogle === void 0 ? null : _useContext$setGoogle,
582
- _useContext$systemFon = _useContext.systemFonts,
583
- systemFonts = _useContext$systemFon === void 0 ? null : _useContext$systemFon,
584
- _useContext$googleFon = _useContext.googleFonts,
585
- googleFonts = _useContext$googleFon === void 0 ? null : _useContext$googleFon,
586
- _useContext$customFon = _useContext.customFonts,
587
- customFonts = _useContext$customFon === void 0 ? null : _useContext$customFon;
588
- useGoogleFonts({
589
- disabled: withoutGoogleFonts || googleFonts !== null && googleFonts.length > 0,
590
- setFonts: setGoogleFonts
591
- });
592
- var fonts = React.useMemo(function () {
593
- return {
594
- systemFonts: systemFonts,
595
- googleFonts: googleFonts,
596
- customFonts: customFonts
597
- };
598
- }, [systemFonts, googleFonts, customFonts]);
599
- return fonts;
600
- };
601
- var propTypes$a = {
602
- children: PropTypes.node.isRequired,
603
- systemFonts: core.PropTypes.fonts,
604
- customFonts: core.PropTypes.fonts
605
- };
606
- var defaultProps$a = {
607
- systemFonts: ['Arial', 'Courier', 'Georgia', 'Times New Roman', 'Verdana'],
608
- customFonts: null
609
- };
610
- var FontsProvider = function FontsProvider(_ref4) {
611
- var systemFonts = _ref4.systemFonts,
612
- customFonts = _ref4.customFonts,
613
- children = _ref4.children;
614
- var _useFonts = useFonts(),
615
- _useFonts$systemFonts = _useFonts.systemFonts,
616
- previousSystemFonts = _useFonts$systemFonts === void 0 ? null : _useFonts$systemFonts,
617
- _useFonts$googleFonts = _useFonts.googleFonts,
618
- previousGoogleFonts = _useFonts$googleFonts === void 0 ? null : _useFonts$googleFonts,
619
- previousCustomFonts = _useFonts.customFonts;
620
- var _useState3 = React.useState(null),
621
- _useState4 = _slicedToArray(_useState3, 2),
622
- googleFonts = _useState4[0],
623
- setGoogleFonts = _useState4[1];
624
- var fonts = React.useMemo(function () {
625
- return {
626
- systemFonts: uniqBy([].concat(_toConsumableArray(previousSystemFonts || []), _toConsumableArray(systemFonts || [])), function (font) {
627
- return isObject(font) ? font.name : font;
628
- }),
629
- googleFonts: uniqBy([].concat(_toConsumableArray(previousGoogleFonts || []), _toConsumableArray(googleFonts || [])), function (font) {
630
- return isObject(font) ? font.name : font;
631
- }),
632
- customFonts: uniqBy([].concat(_toConsumableArray(previousCustomFonts || []), _toConsumableArray(customFonts || [])), function (font) {
633
- return isObject(font) ? font.name : font;
634
- }),
635
- setGoogleFonts: setGoogleFonts
636
- };
637
- }, [previousSystemFonts, previousGoogleFonts, previousCustomFonts, customFonts, systemFonts, googleFonts, setGoogleFonts]);
638
- return /*#__PURE__*/React.createElement(FontsContext.Provider, {
639
- value: fonts
640
- }, children);
641
- };
642
- FontsProvider.propTypes = propTypes$a;
643
- FontsProvider.defaultProps = defaultProps$a;
644
-
645
- /* eslint-disable react/jsx-props-no-spreading */
646
- var FormContext = /*#__PURE__*/React.createContext(null);
647
- var useForm = function useForm() {
648
- return React.useContext(FormContext);
649
- };
650
- var useFormValue = function useFormValue() {
651
- var _useForm = useForm(),
652
- value = _useForm.value;
653
- return value;
654
- };
655
- var useFormSetValue = function useFormSetValue() {
656
- var _useForm2 = useForm(),
657
- setValue = _useForm2.setValue;
658
- return setValue;
659
- };
660
- var propTypes$9 = {
661
- value: PropTypes.object.isRequired,
662
- // eslint-disable-line react/forbid-prop-types
663
- setValue: PropTypes.func.isRequired,
664
- children: PropTypes.node.isRequired
665
- };
666
- var defaultProps$9 = {};
667
- var FormProvider = function FormProvider(_ref) {
668
- var value = _ref.value,
669
- setValue = _ref.setValue,
670
- children = _ref.children;
671
- var values = React.useMemo(function () {
672
- return {
673
- value: value,
674
- setValue: setValue
675
- };
676
- }, [value, setValue]);
677
- return /*#__PURE__*/React.createElement(FormContext.Provider, {
678
- value: values
679
- }, children);
680
- };
681
- FormProvider.propTypes = propTypes$9;
682
- FormProvider.defaultProps = defaultProps$9;
683
-
684
- var GoogleApiClientContext = /*#__PURE__*/React.createContext(null);
685
- var useGoogleApiClient = function useGoogleApiClient() {
686
- return React.useContext(GoogleApiClientContext);
687
- };
688
- var withGoogleApiClient = function withGoogleApiClient(WrappedComponent) {
689
- var getDisplayName = function getDisplayName(_ref) {
690
- var _ref$displayName = _ref.displayName,
691
- displayName = _ref$displayName === void 0 ? null : _ref$displayName,
692
- _ref$name = _ref.name,
693
- name = _ref$name === void 0 ? null : _ref$name;
694
- return displayName || name || 'Component';
695
- };
696
- var WithGoogleApiClientComponent = function WithGoogleApiClientComponent(props) {
697
- return /*#__PURE__*/React.createElement(GoogleApiClientContext.Consumer, null, function (client) {
698
- return /*#__PURE__*/React.createElement(WrappedComponent, Object.assign({
699
- googleApiClient: client
700
- }, props));
701
- });
702
- };
703
- WithGoogleApiClientComponent.displayName = "WithGoogleApiClient(".concat(getDisplayName(WrappedComponent), ")");
704
- return WithGoogleApiClientComponent;
705
- };
706
- var propTypes$8 = {
707
- children: PropTypes.node.isRequired
708
- };
709
- var defaultProps$8 = {};
710
- var GoogleApiClientProvider = function GoogleApiClientProvider(_ref2) {
711
- var children = _ref2.children;
712
- var _useGoogleKeys = useGoogleKeys(),
713
- apiKey = _useGoogleKeys.apiKey;
714
- var _useState = React.useState(null),
715
- _useState2 = _slicedToArray(_useState, 2),
716
- client = _useState2[0],
717
- setClient = _useState2[1];
718
- React.useEffect(function () {
719
- services.loadGoogleApi().then(function (gapi) {
720
- return gapi.client.init({
721
- apiKey: apiKey
722
- }).then(function () {
723
- return gapi;
724
- });
725
- }).then(function (gapi) {
726
- return setClient(gapi);
727
- });
728
- }, [apiKey, setClient]);
729
- return /*#__PURE__*/React.createElement(GoogleApiClientContext.Provider, {
730
- value: client
731
- }, children);
732
- };
733
- GoogleApiClientProvider.propTypes = propTypes$8;
734
- GoogleApiClientProvider.defaultProps = defaultProps$8;
735
-
736
- var GoogleMapsClientContext = /*#__PURE__*/React.createContext(null);
737
- var useGoogleMapsClient = function useGoogleMapsClient() {
738
- return React.useContext(GoogleMapsClientContext);
739
- };
740
- var withGoogleMapsClient = function withGoogleMapsClient(WrappedComponent) {
741
- var getDisplayName = function getDisplayName(_ref) {
742
- var _ref$displayName = _ref.displayName,
743
- displayName = _ref$displayName === void 0 ? null : _ref$displayName,
744
- _ref$name = _ref.name,
745
- name = _ref$name === void 0 ? null : _ref$name;
746
- return displayName || name || 'Component';
747
- };
748
- var WithGoogleMapsClientComponent = function WithGoogleMapsClientComponent(props) {
749
- return /*#__PURE__*/React.createElement(GoogleMapsClientContext.Consumer, null, function (client) {
750
- return /*#__PURE__*/React.createElement(WrappedComponent, Object.assign({
751
- googleApiClient: client
752
- }, props));
753
- });
754
- };
755
- WithGoogleMapsClientComponent.displayName = "WithGoogleMapsClient(".concat(getDisplayName(WrappedComponent), ")");
756
- return WithGoogleMapsClientComponent;
757
- };
758
- var propTypes$7 = {
759
- children: PropTypes.node.isRequired,
760
- locale: PropTypes.string,
761
- libraries: PropTypes.arrayOf(PropTypes.string)
762
- };
763
- var defaultProps$7 = {
764
- locale: 'fr',
765
- libraries: null
766
- };
767
- var GoogleMapsClientProvider = function GoogleMapsClientProvider(_ref2) {
768
- var children = _ref2.children,
769
- locale = _ref2.locale,
770
- libraries = _ref2.libraries;
771
- var _useGoogleKeys = useGoogleKeys(),
772
- apiKey = _useGoogleKeys.apiKey;
773
- var exisitingClient = useGoogleMapsClient();
774
- var _useState = React.useState(exisitingClient),
775
- _useState2 = _slicedToArray(_useState, 2),
776
- client = _useState2[0],
777
- setClient = _useState2[1];
778
- React.useEffect(function () {
779
- if (exisitingClient === null) {
780
- services.loadGoogleMaps({
781
- apiKey: apiKey,
782
- locale: locale,
783
- libraries: libraries
784
- }).then(function (newClient) {
785
- setClient(newClient);
786
- });
787
- }
788
- }, [apiKey, locale, libraries, setClient, exisitingClient]);
789
- return /*#__PURE__*/React.createElement(GoogleMapsClientContext.Provider, {
790
- value: client
791
- }, children);
792
- };
793
- GoogleMapsClientProvider.propTypes = propTypes$7;
794
- GoogleMapsClientProvider.defaultProps = defaultProps$7;
795
-
796
- /* eslint-disable react/jsx-props-no-spreading */
797
- var defaultLocales = ['en', 'fr'];
798
- var LocalesContext = /*#__PURE__*/React.createContext({
799
- locales: defaultLocales
800
- });
801
- var useLocales = function useLocales() {
802
- var _useContext = React.useContext(LocalesContext),
803
- locales = _useContext.locales;
804
- return locales;
805
- };
806
- var useOtherLocales = function useOtherLocales() {
807
- var _useLocales = useLocales(),
808
- locales = _useLocales.locales;
809
- var _useIntl = reactIntl.useIntl(),
810
- locale = _useIntl.locale;
811
- var otherLocales = React.useMemo(function () {
812
- return locales.filter(function (it) {
813
- return it !== locale;
814
- });
815
- }, [locales, locale]);
816
- return otherLocales;
817
- };
818
- var propTypes$6 = {
819
- locales: PropTypes.arrayOf(PropTypes.string),
820
- children: PropTypes.node.isRequired
821
- };
822
- var defaultProps$6 = {
823
- locales: []
824
- };
825
- var LocalesProvider = function LocalesProvider(_ref) {
826
- var locales = _ref.locales,
827
- children = _ref.children;
828
- var value = React.useMemo(function () {
829
- return {
830
- locales: locales
831
- };
832
- }, [locales]);
833
- return /*#__PURE__*/React.createElement(LocalesContext.Provider, {
834
- value: value
835
- }, children);
836
- };
837
- LocalesProvider.propTypes = propTypes$6;
838
- LocalesProvider.defaultProps = defaultProps$6;
839
-
840
- // import { getDisplayName } from '../utils';
841
-
842
- var ModalContext = /*#__PURE__*/React.createContext(null);
843
- var useModal = function useModal() {
844
- return React.useContext(ModalContext) || {};
845
- };
846
- var propTypes$5 = {
847
- children: PropTypes.node.isRequired,
848
- container: PropTypes.object // eslint-disable-line
849
- };
850
- var defaultProps$5 = {
851
- container: null
852
- };
853
- var ModalProvider = function ModalProvider(_ref) {
854
- var children = _ref.children,
855
- initialContainer = _ref.container;
856
- var _useState = React.useState(initialContainer),
857
- _useState2 = _slicedToArray(_useState, 2),
858
- container = _useState2[0],
859
- setContainer = _useState2[1];
860
- var _useState3 = React.useState([]),
861
- _useState4 = _slicedToArray(_useState3, 2),
862
- modals = _useState4[0],
863
- setModals = _useState4[1];
864
- var modalsRef = React.useRef(modals);
865
- var register = React.useCallback(function (id) {
866
- var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
867
- var _modalsRef$current = modalsRef.current,
868
- currentModals = _modalsRef$current === void 0 ? [] : _modalsRef$current;
869
- var newModals = [].concat(_toConsumableArray(currentModals), [_objectSpread({
870
- id: id
871
- }, data)]);
872
- setModals(newModals);
873
- modalsRef.current = newModals;
874
- }, [modals, setModals]);
875
- var unregister = React.useCallback(function () {
876
- var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
877
- var _modalsRef$current2 = modalsRef.current,
878
- currentModals = _modalsRef$current2 === void 0 ? [] : _modalsRef$current2;
879
- var foundIndex = currentModals.findIndex(function (_ref2) {
880
- var modalId = _ref2.id;
881
- return modalId === id;
882
- });
883
- if (foundIndex !== -1) {
884
- var newModals = currentModals.filter(function (_ref3) {
885
- var modalId = _ref3.id;
886
- return modalId !== id;
887
- });
888
- setModals(newModals);
889
- modalsRef.current = newModals;
890
- }
891
- }, [modals, setModals]);
892
- var closeLastModal = React.useCallback(function () {
893
- var lastModal = modals.pop() || null;
894
- if (lastModal !== null) {
895
- var _ref4 = lastModal || {},
896
- _ref4$id = _ref4.id,
897
- lastModalId = _ref4$id === void 0 ? null : _ref4$id;
898
- var newModals = modals.filter(function (_ref5) {
899
- var modalId = _ref5.id;
900
- return modalId !== lastModalId;
901
- });
902
- setModals(newModals);
903
- modalsRef.current = newModals;
904
- }
905
- }, [modals, setModals]);
906
- var getModalByKey = React.useCallback(function (key) {
907
- return (modals || []).find(function (modal) {
908
- return (modal === null || modal === void 0 ? void 0 : modal.id) === key;
909
- }) || null;
910
- }, [modals]);
911
- var modalIsOpen = React.useCallback(function (key) {
912
- return getModalByKey(key) !== null;
913
- }, [getModalByKey]);
914
- var value = React.useMemo(function () {
915
- return {
916
- modals: modals,
917
- container: container,
918
- setContainer: setContainer,
919
- register: register,
920
- unregister: unregister,
921
- closeLastModal: closeLastModal,
922
- getModalByKey: getModalByKey,
923
- modalIsOpen: modalIsOpen
924
- };
925
- }, [modals, container, setContainer, register, unregister, closeLastModal, getModalByKey, modalIsOpen]);
926
- return /*#__PURE__*/React.createElement(ModalContext.Provider, {
927
- value: value
928
- }, children);
929
- };
930
- ModalProvider.propTypes = propTypes$5;
931
- ModalProvider.defaultProps = defaultProps$5;
932
-
933
- var PanelsContext = /*#__PURE__*/React.createContext({
934
- container: null
935
- });
936
- var usePanels = function usePanels() {
937
- return React.useContext(PanelsContext) || {};
938
- };
939
- var withPanels = function withPanels(WrappedComponent) {
940
- var WithPanelsComponent = function WithPanelsComponent(props) {
941
- return /*#__PURE__*/React.createElement(PanelsContext.Consumer, null, function (_ref) {
942
- var panels = _ref.panels,
943
- setContainer = _ref.setContainer,
944
- container = _ref.container,
945
- register = _ref.register,
946
- unregister = _ref.unregister;
947
- return /*#__PURE__*/React.createElement(WrappedComponent, Object.assign({
948
- panelsContainer: container,
949
- setPanelsContainer: setContainer,
950
- panels: panels,
951
- registerPanel: register,
952
- unregisterPanel: unregister
953
- }, props));
954
- });
955
- };
956
- WithPanelsComponent.displayName = "WithPanels(".concat(utils.getDisplayName(WrappedComponent), ")");
957
- return WithPanelsComponent;
958
- };
959
- var propTypes$4 = {
960
- children: PropTypes.node.isRequired,
961
- container: PropTypes.object // eslint-disable-line
962
- };
963
- var defaultProps$4 = {
964
- container: null
965
- };
966
- var PanelsProvider = function PanelsProvider(_ref2) {
967
- var children = _ref2.children,
968
- initialContainer = _ref2.container;
969
- var _useState = React.useState(initialContainer),
970
- _useState2 = _slicedToArray(_useState, 2),
971
- container = _useState2[0],
972
- setContainer = _useState2[1];
973
- var _useState3 = React.useState([]),
974
- _useState4 = _slicedToArray(_useState3, 2),
975
- panels = _useState4[0],
976
- setPanels = _useState4[1];
977
- var panelsRef = React.useRef(panels);
978
- var register = React.useCallback(function (id) {
979
- var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
980
- var currentPanels = panelsRef.current;
981
- var newPanels = [].concat(_toConsumableArray(currentPanels), [_objectSpread({
982
- id: id
983
- }, data)]);
984
- setPanels(newPanels);
985
- panelsRef.current = newPanels;
986
- }, [panels, setPanels]);
987
- var unregister = React.useCallback(function (id) {
988
- var currentPanels = panelsRef.current;
989
- var foundIndex = currentPanels.findIndex(function (_ref3) {
990
- var modalId = _ref3.id;
991
- return modalId === id;
992
- });
993
- if (foundIndex !== -1) {
994
- var newPanels = currentPanels.filter(function (_ref4) {
995
- var modalId = _ref4.id;
996
- return modalId !== id;
997
- });
998
- setPanels(newPanels);
999
- panelsRef.current = newPanels;
1000
- }
1001
- }, [panels, setPanels]);
1002
- var value = React.useMemo(function () {
1003
- return {
1004
- panels: panels,
1005
- setContainer: setContainer,
1006
- container: container,
1007
- register: register,
1008
- unregister: unregister
1009
- };
1010
- }, [panels, setContainer, container, register, unregister]);
1011
- return /*#__PURE__*/React.createElement(PanelsContext.Provider, {
1012
- value: value
1013
- }, children);
1014
- };
1015
- PanelsProvider.propTypes = propTypes$4;
1016
- PanelsProvider.defaultProps = defaultProps$4;
1017
-
1018
- var _excluded = ["component"];
1019
- var PanneauContext = /*#__PURE__*/React.createContext(null);
1020
- var usePanneau = function usePanneau() {
1021
- return React.useContext(PanneauContext);
1022
- };
1023
- var usePanneauResources = function usePanneauResources() {
1024
- var _ref = usePanneau() || {},
1025
- _ref$resources = _ref.resources,
1026
- resources = _ref$resources === void 0 ? [] : _ref$resources;
1027
- return resources;
1028
- };
1029
- var usePanneauResource = function usePanneauResource(id) {
1030
- var resources = usePanneauResources();
1031
- return resources.find(function (it) {
1032
- return it.id === id;
1033
- }) || null;
1034
- };
1035
- var usePanneauColorScheme = function usePanneauColorScheme() {
1036
- var _ref2 = usePanneau() || {},
1037
- _ref2$theme = _ref2.theme,
1038
- theme = _ref2$theme === void 0 ? {} : _ref2$theme;
1039
- var _ref3 = theme || {},
1040
- _ref3$colorScheme = _ref3.colorScheme,
1041
- colorScheme = _ref3$colorScheme === void 0 ? 'light' : _ref3$colorScheme;
1042
- if (colorScheme === null || colorScheme === 'light' || colorScheme === 'dark') {
1043
- return colorScheme === 'dark' ? {
1044
- theme: 'dark',
1045
- background: 'dark',
1046
- text: 'light'
1047
- } : {
1048
- theme: 'light',
1049
- background: 'light',
1050
- text: 'dark'
1051
- };
1052
- }
1053
- return {
1054
- theme: colorScheme,
1055
- background: null,
1056
- text: null
1057
- };
1058
- };
1059
- var usePanneauComponents = function usePanneauComponents() {
1060
- var _ref4 = usePanneau() || {},
1061
- _ref4$components = _ref4.components,
1062
- components = _ref4$components === void 0 ? {} : _ref4$components;
1063
- return components;
1064
- };
1065
- var usePanneauComponent = function usePanneauComponent(namespace, name) {
1066
- var _ref5 = usePanneau() || {},
1067
- _ref5$components = _ref5.components,
1068
- components = _ref5$components === void 0 ? {} : _ref5$components;
1069
- var path = namespace !== null ? "".concat(namespace, ".").concat(name) : name || null;
1070
- var component = components[path] || null;
1071
- if (isString(component)) {
1072
- return component;
1073
- }
1074
- if (isObject(component) && isString(component === null || component === void 0 ? void 0 : component.componnent)) {
1075
- // eslint-disable-next-line no-unused-vars
1076
- component.component;
1077
- _objectWithoutProperties(component, _excluded);
1078
- return component.component;
1079
- }
1080
- return null;
1081
- };
1082
- var usePanneauAuth = function usePanneauAuth() {
1083
- var _ref6 = usePanneau() || {},
1084
- _ref6$auth = _ref6.auth,
1085
- auth = _ref6$auth === void 0 ? {} : _ref6$auth;
1086
- return auth;
1087
- };
1088
- var usePanneauSettings = function usePanneauSettings() {
1089
- var _ref7 = usePanneau() || {},
1090
- _ref7$settings = _ref7.settings,
1091
- settings = _ref7$settings === void 0 ? {} : _ref7$settings;
1092
- return settings;
1093
- };
1094
- var propTypes$3 = {
1095
- definition: panneauDefinition.isRequired,
1096
- children: PropTypes.node.isRequired
1097
- };
1098
- var defaultProps$3 = {};
1099
- var PanneauProvider = function PanneauProvider(_ref8) {
1100
- var definition = _ref8.definition,
1101
- children = _ref8.children;
1102
- return /*#__PURE__*/React.createElement(PanneauContext.Provider, {
1103
- value: definition
1104
- }, children);
1105
- };
1106
- PanneauProvider.propTypes = propTypes$3;
1107
- PanneauProvider.defaultProps = defaultProps$3;
1108
-
1109
- /* eslint-disable react/jsx-props-no-spreading */
1110
- var ResourceContext = /*#__PURE__*/React.createContext(null);
1111
- var useResource = function useResource() {
1112
- return React.useContext(ResourceContext);
1113
- };
1114
- var propTypes$2 = {
1115
- resource: resource.isRequired,
1116
- children: PropTypes.node.isRequired
1117
- };
1118
- var defaultProps$2 = {};
1119
- var ResourceProvider = function ResourceProvider(_ref) {
1120
- var resource = _ref.resource,
1121
- children = _ref.children;
1122
- return /*#__PURE__*/React.createElement(ResourceContext.Provider, {
1123
- value: resource
1124
- }, children);
1125
- };
1126
- ResourceProvider.propTypes = propTypes$2;
1127
- ResourceProvider.defaultProps = defaultProps$2;
1128
-
1129
- var useEffect = React__namespace.useEffect,
1130
- useLayoutEffect = React__namespace.useLayoutEffect,
1131
- useRef = React__namespace.useRef;
1132
-
1133
- // React.useInsertionEffect is not available in React <18
1134
- // This hack fixes a transpilation issue on some apps
1135
- var useBuiltinInsertionEffect = React__namespace['useInsertion' + 'Effect'];
1136
-
1137
- // Copied from:
1138
- // https://github.com/facebook/react/blob/main/packages/shared/ExecutionEnvironment.js
1139
- var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
1140
-
1141
- // Copied from:
1142
- // https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.ts
1143
- // "React currently throws a warning when using useLayoutEffect on the server.
1144
- // To get around it, we can conditionally useEffect on the server (no-op) and
1145
- // useLayoutEffect in the browser."
1146
- var useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
1147
-
1148
- // useInsertionEffect is already a noop on the server.
1149
- // See: https://github.com/facebook/react/blob/main/packages/react-server/src/ReactFizzHooks.js
1150
- var useInsertionEffect = useBuiltinInsertionEffect || useIsomorphicLayoutEffect;
1151
-
1152
- // Userland polyfill while we wait for the forthcoming
1153
- // https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
1154
- // Note: "A high-fidelity polyfill for useEvent is not possible because
1155
- // there is no lifecycle or Hook in React that we can use to switch
1156
- // .current at the right timing."
1157
- // So we will have to make do with this "close enough" approach for now.
1158
- var useEvent = function useEvent(fn) {
1159
- var ref = useRef([fn, function () {
1160
- return ref[0].apply(ref, arguments);
1161
- }]).current;
1162
- // Per Dan Abramov: useInsertionEffect executes marginally closer to the
1163
- // correct timing for ref synchronization than useLayoutEffect on React 18.
1164
- // See: https://github.com/facebook/react/pull/25881#issuecomment-1356244360
1165
- useInsertionEffect(function () {
1166
- ref[0] = fn;
1167
- });
1168
- return ref[1];
1169
- };
1170
-
1171
- /**
1172
- * History API docs @see https://developer.mozilla.org/en-US/docs/Web/API/History
1173
- */
1174
- var eventPopstate = "popstate";
1175
- var eventPushState = "pushState";
1176
- var eventReplaceState = "replaceState";
1177
- var eventHashchange = "hashchange";
1178
- var events = [eventPopstate, eventPushState, eventReplaceState, eventHashchange];
1179
- var subscribeToLocationUpdates = function subscribeToLocationUpdates(callback) {
1180
- for (var _i = 0, _events = events; _i < _events.length; _i++) {
1181
- var event = _events[_i];
1182
- addEventListener(event, callback);
1183
- }
1184
- return function () {
1185
- for (var _i2 = 0, _events2 = events; _i2 < _events2.length; _i2++) {
1186
- var _event = _events2[_i2];
1187
- removeEventListener(_event, callback);
1188
- }
1189
- };
1190
- };
1191
- var useLocationProperty = function useLocationProperty(fn, ssrFn) {
1192
- return index_js.useSyncExternalStore(subscribeToLocationUpdates, fn, ssrFn);
1193
- };
1194
- var currentSearch = function currentSearch() {
1195
- return location.search;
1196
- };
1197
- var useSearch = function useSearch() {
1198
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1199
- _ref$ssrSearch = _ref.ssrSearch,
1200
- ssrSearch = _ref$ssrSearch === void 0 ? "" : _ref$ssrSearch;
1201
- return useLocationProperty(currentSearch, function () {
1202
- return ssrSearch;
1203
- });
1204
- };
1205
- var currentPathname = function currentPathname() {
1206
- return location.pathname;
1207
- };
1208
- var usePathname = function usePathname() {
1209
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1210
- ssrPath = _ref2.ssrPath;
1211
- return useLocationProperty(currentPathname, ssrPath ? function () {
1212
- return ssrPath;
1213
- } : currentPathname);
1214
- };
1215
- var navigate = function navigate(to) {
1216
- var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1217
- _ref3$replace = _ref3.replace,
1218
- replace = _ref3$replace === void 0 ? false : _ref3$replace,
1219
- _ref3$state = _ref3.state,
1220
- state = _ref3$state === void 0 ? null : _ref3$state;
1221
- return history[replace ? eventReplaceState : eventPushState](state, "", to);
1222
- };
1223
-
1224
- // the 2nd argument of the `useBrowserLocation` return value is a function
1225
- // that allows to perform a navigation.
1226
- var useBrowserLocation = function useBrowserLocation() {
1227
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1228
- return [usePathname(opts), navigate];
1229
- };
1230
- var patchKey = Symbol["for"]("wouter_v3");
1231
-
1232
- // While History API does have `popstate` event, the only
1233
- // proper way to listen to changes via `push/replaceState`
1234
- // is to monkey-patch these methods.
1235
- //
1236
- // See https://stackoverflow.com/a/4585031
1237
- if (typeof history !== "undefined" && typeof window[patchKey] === "undefined") {
1238
- var _loop = function _loop() {
1239
- var type = _arr[_i3];
1240
- var original = history[type];
1241
- // TODO: we should be using unstable_batchedUpdates to avoid multiple re-renders,
1242
- // however that will require an additional peer dependency on react-dom.
1243
- // See: https://github.com/reactwg/react-18/discussions/86#discussioncomment-1567149
1244
- history[type] = function () {
1245
- var result = original.apply(this, arguments);
1246
- var event = new Event(type);
1247
- event.arguments = arguments;
1248
- dispatchEvent(event);
1249
- return result;
1250
- };
1251
- };
1252
- for (var _i3 = 0, _arr = [eventPushState, eventReplaceState]; _i3 < _arr.length; _i3++) {
1253
- _loop();
1254
- }
1255
-
1256
- // patch history object only once
1257
- // See: https://github.com/molefrog/wouter/issues/167
1258
- Object.defineProperty(window, patchKey, {
1259
- value: true
1260
- });
1261
- }
1262
-
1263
- var _excluded3 = ["to", "href", "onClick", "asChild", "children", "className", "replace", "state"];
1264
-
1265
- /*
1266
- * Transforms `path` into its relative `base` version
1267
- * If base isn't part of the path provided returns absolute path e.g. `~/app`
1268
- */
1269
- var relativePath = function relativePath() {
1270
- var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
1271
- var path = arguments.length > 1 ? arguments[1] : undefined;
1272
- return !path.toLowerCase().indexOf(base.toLowerCase()) ? path.slice(base.length) || "/" : "~" + path;
1273
- };
1274
- var absolutePath = function absolutePath(to) {
1275
- var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
1276
- return to[0] === "~" ? to.slice(1) : base + to;
1277
- };
1278
-
1279
- /*
1280
- * decodes escape sequences such as %20
1281
- */
1282
- var unescape = function unescape(str) {
1283
- try {
1284
- return decodeURI(str);
1285
- } catch (_e) {
1286
- // fail-safe mode: if string can't be decoded do nothing
1287
- return str;
1288
- }
1289
- };
1290
-
1291
- /*
1292
- * Router and router context. Router is a lightweight object that represents the current
1293
- * routing options: how location is managed, base path etc.
1294
- *
1295
- * There is a default router present for most of the use cases, however it can be overridden
1296
- * via the <Router /> component.
1297
- */
1298
-
1299
- var defaultRouter = {
1300
- hook: useBrowserLocation,
1301
- searchHook: useSearch,
1302
- parser: regexparam.parse,
1303
- base: "",
1304
- // this option is used to override the current location during SSR
1305
- ssrPath: undefined,
1306
- ssrSearch: undefined,
1307
- // customizes how `href` props are transformed for <Link />
1308
- hrefs: function hrefs(x) {
1309
- return x;
1310
- }
1311
- };
1312
- var RouterCtx = React.createContext(defaultRouter);
1313
-
1314
- // gets the closest parent router from the context
1315
- var useRouter = function useRouter() {
1316
- return React.useContext(RouterCtx);
1317
- };
1318
-
1319
- /**
1320
- * Parameters context. Used by `useParams()` to get the
1321
- * matched params from the innermost `Route` component.
1322
- */
1323
-
1324
- React.createContext({});
1325
-
1326
- /*
1327
- * Part 1, Hooks API: useRoute and useLocation
1328
- */
1329
-
1330
- // Internal version of useLocation to avoid redundant useRouter calls
1331
-
1332
- var useLocationFromRouter = function useLocationFromRouter(router) {
1333
- var _router$hook = router.hook(router),
1334
- _router$hook2 = _slicedToArray(_router$hook, 2),
1335
- location = _router$hook2[0],
1336
- navigate = _router$hook2[1];
1337
-
1338
- // the function reference should stay the same between re-renders, so that
1339
- // it can be passed down as an element prop without any performance concerns.
1340
- // (This is achieved via `useEvent`.)
1341
- return [unescape(relativePath(router.base, location)), useEvent(function (to, navOpts) {
1342
- return navigate(absolutePath(to, router.base), navOpts);
1343
- })];
1344
- };
1345
- var useLocation = function useLocation() {
1346
- return useLocationFromRouter(useRouter());
1347
- };
1348
- React.forwardRef(function (props, ref) {
1349
- var router = useRouter();
1350
- var _useLocationFromRoute3 = useLocationFromRouter(router),
1351
- _useLocationFromRoute4 = _slicedToArray(_useLocationFromRoute3, 2),
1352
- path = _useLocationFromRoute4[0],
1353
- navigate = _useLocationFromRoute4[1];
1354
- var to = props.to,
1355
- _props$href = props.href,
1356
- _href = _props$href === void 0 ? to : _props$href,
1357
- _onClick = props.onClick,
1358
- asChild = props.asChild,
1359
- children = props.children,
1360
- cls = props.className;
1361
- props.replace;
1362
- props.state;
1363
- var restProps = _objectWithoutProperties(props, _excluded3);
1364
- var onClick = useEvent(function (event) {
1365
- // ignores the navigation when clicked using right mouse button or
1366
- // by holding a special modifier key: ctrl, command, win, alt, shift
1367
- if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || event.button !== 0) return;
1368
- _onClick === null || _onClick === void 0 || _onClick(event);
1369
- if (!event.defaultPrevented) {
1370
- event.preventDefault();
1371
- navigate(_href, props);
1372
- }
1373
- });
1374
-
1375
- // handle nested routers and absolute paths
1376
- var href = router.hrefs(_href[0] === "~" ? _href.slice(1) : router.base + _href, router // pass router as a second argument for convinience
1377
- );
1378
- return asChild && React.isValidElement(children) ? React.cloneElement(children, {
1379
- onClick: onClick,
1380
- href: href
1381
- }) : React.createElement("a", _objectSpread(_objectSpread({}, restProps), {}, {
1382
- onClick: onClick,
1383
- href: href,
1384
- // `className` can be a function to apply the class if this link is active
1385
- className: cls !== null && cls !== void 0 && cls.call ? cls(path === href) : cls,
1386
- children: children,
1387
- ref: ref
1388
- }));
1389
- });
1390
-
1391
- /* eslint-disable react/jsx-props-no-spreading */
1392
- var RoutesContext = /*#__PURE__*/React.createContext(null);
1393
- var useRoutesContext = function useRoutesContext() {
1394
- return React.useContext(RoutesContext);
1395
- };
1396
- var propTypes$1 = {
1397
- children: PropTypes.node.isRequired,
1398
- routes: PropTypes.objectOf(PropTypes.string).isRequired,
1399
- basePath: PropTypes.string
1400
- };
1401
- var defaultProps$1 = {
1402
- basePath: null
1403
- };
1404
- function RoutesProvider(_ref) {
1405
- var routes = _ref.routes,
1406
- basePath = _ref.basePath,
1407
- children = _ref.children;
1408
- var value = React.useMemo(function () {
1409
- return {
1410
- routes: routes,
1411
- basePath: basePath
1412
- };
1413
- }, [routes, basePath]);
1414
- return /*#__PURE__*/jsxRuntime.jsx(RoutesContext.Provider, {
1415
- value: value,
1416
- children: children
1417
- });
1418
- }
1419
- RoutesProvider.propTypes = propTypes$1;
1420
- RoutesProvider.defaultProps = defaultProps$1;
1421
- var compilers = {};
1422
- function generatePath(fullPath, data) {
1423
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1424
- var fullUrlMatches = fullPath.match(/^(https?:\/\/)/);
1425
- if (typeof compilers[fullPath] === 'undefined') {
1426
- compilers[fullPath] = pathToRegexp.compile(fullPath.replace(/^(https?:\/\/)/, ''), opts);
1427
- }
1428
- var compiler = compilers[fullPath];
1429
- return fullUrlMatches !== null ? "".concat(fullUrlMatches[1]).concat(compiler(data)) : compiler(data);
1430
- }
1431
- var useUrlGeneratorPathToRepexp = function useUrlGeneratorPathToRepexp() {
1432
- var _ref2 = useRoutesContext() || {},
1433
- _ref2$routes = _ref2.routes,
1434
- routes = _ref2$routes === void 0 ? null : _ref2$routes,
1435
- _ref2$basePath = _ref2.basePath,
1436
- basePath = _ref2$basePath === void 0 ? null : _ref2$basePath;
1437
- var urlGenerator = React.useCallback(function (key, data, opts) {
1438
- var path = routes !== null ? routes[key] || null : null;
1439
- if (path === null) {
1440
- return null;
1441
- }
1442
- var url = generatePath(path, data, opts);
1443
- return basePath !== null ? "".concat(basePath.replace(/\/$/, ''), "/").concat(url.replace(/^\//, '')) : url;
1444
- }, [routes, basePath]);
1445
- return urlGenerator;
1446
- };
1447
- var useUrlGeneratorPathToRegexp = useUrlGeneratorPathToRepexp;
1448
- var useRoutes = function useRoutes() {
1449
- var _useRoutesContext = useRoutesContext(),
1450
- routes = _useRoutesContext.routes;
1451
- return routes;
1452
- };
1453
- var useRoutes$1 = useRoutes;
1454
-
1455
- var useRoutePush = function useRoutePush() {
1456
- var url = useUrlGeneratorPathToRegexp();
1457
- var _useLocation = useLocation(),
1458
- _useLocation2 = _slicedToArray(_useLocation, 2),
1459
- navigate = _useLocation2[1];
1460
- var push = React.useCallback(function (route, data) {
1461
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1462
- args[_key - 2] = arguments[_key];
1463
- }
1464
- if (isString(route)) {
1465
- navigate.apply(void 0, [url(route, data)].concat(args));
1466
- } else {
1467
- var _ref = route || {},
1468
- _ref$pathname = _ref.pathname,
1469
- pathname = _ref$pathname === void 0 ? null : _ref$pathname,
1470
- _ref$search = _ref.search,
1471
- search = _ref$search === void 0 ? null : _ref$search;
1472
- navigate.apply(void 0, ["".concat(url(pathname, data)).concat(search !== null ? "?".concat(search) : '')].concat(args));
1473
- }
1474
- }, [navigate, url]);
1475
- return push;
1476
- };
1477
- var useRouteBack = function useRouteBack() {
1478
- var url = useUrlGeneratorPathToRegexp();
1479
- var _useLocation3 = useLocation(),
1480
- _useLocation4 = _slicedToArray(_useLocation3, 2),
1481
- navigate = _useLocation4[1];
1482
- var back = React.useCallback(function () {
1483
- return navigate(-1);
1484
- }, [navigate, url]);
1485
- return back;
1486
- };
1487
-
1488
- /* eslint-disable react/jsx-props-no-spreading */
1489
- var useTracking = function useTracking() {
1490
- return React.useContext(tracking.TrackingContext);
1491
- };
1492
- var propTypes = {
1493
- children: PropTypes.node.isRequired,
1494
- variables: core.PropTypes.trackingVariables
1495
- };
1496
- var defaultProps = {
1497
- variables: null
1498
- };
1499
- var TrackingProvider = function TrackingProvider(_ref) {
1500
- var variables = _ref.variables,
1501
- children = _ref.children;
1502
- var contextTracking = useTracking() || null;
1503
- var tracking$1 = React.useMemo(function () {
1504
- if (contextTracking !== null) {
1505
- contextTracking.setVariables(variables);
1506
- return contextTracking;
1507
- }
1508
- return new core.Tracking({
1509
- variables: variables
1510
- });
1511
- }, [contextTracking, variables]);
1512
- return /*#__PURE__*/React.createElement(tracking.TrackingContainer, {
1513
- tracking: tracking$1
1514
- }, children);
1515
- };
1516
- TrackingProvider.propTypes = propTypes;
1517
- TrackingProvider.defaultProps = defaultProps;
1518
-
1519
- Object.defineProperty(exports, "TrackingContext", {
1520
- enumerable: true,
1521
- get: function () { return tracking.TrackingContext; }
1522
- });
1523
- exports.ACTIONS_NAMESPACE = ACTIONS_NAMESPACE;
1524
- exports.APP_NAMESPACE = APP_NAMESPACE;
1525
- exports.BUTTONS_NAMESPACE = BUTTONS_NAMESPACE;
1526
- exports.ComponentsContext = ComponentsContext;
1527
- exports.ComponentsProvider = ComponentsProvider;
1528
- exports.DISPLAYS_NAMESPACE = DISPLAYS_NAMESPACE;
1529
- exports.DefinitionProvider = DefinitionProvider;
1530
- exports.FIELDS_NAMESPACE = FIELDS_NAMESPACE;
1531
- exports.FILTERS_NAMESPACE = FILTERS_NAMESPACE;
1532
- exports.FORMS_NAMESPACE = FORMS_NAMESPACE;
1533
- exports.FieldsContext = FieldsContext;
1534
- exports.FieldsProvider = FieldsProvider;
1535
- exports.FontsContext = FontsContext;
1536
- exports.FontsProvider = FontsProvider;
1537
- exports.FormProvider = FormProvider;
1538
- exports.GoogleApiClientContext = GoogleApiClientContext;
1539
- exports.GoogleApiClientProvider = GoogleApiClientProvider;
1540
- exports.GoogleKeysContext = GoogleKeysContext;
1541
- exports.GoogleKeysProvider = GoogleKeysProvider;
1542
- exports.GoogleMapsClientContext = GoogleMapsClientContext;
1543
- exports.GoogleMapsClientProvider = GoogleMapsClientProvider;
1544
- exports.LISTS_NAMESPACE = LISTS_NAMESPACE;
1545
- exports.LocalesContext = LocalesContext;
1546
- exports.LocalesProvider = LocalesProvider;
1547
- exports.MODALS_NAMESPACE = MODALS_NAMESPACE;
1548
- exports.ModalContext = ModalContext;
1549
- exports.ModalProvider = ModalProvider;
1550
- exports.PAGES_NAMESPACE = PAGES_NAMESPACE;
1551
- exports.PanelsContext = PanelsContext;
1552
- exports.PanelsProvider = PanelsProvider;
1553
- exports.PanneauProvider = PanneauProvider;
1554
- exports.ResourceProvider = ResourceProvider;
1555
- exports.RoutesContext = RoutesContext;
1556
- exports.RoutesProvider = RoutesProvider;
1557
- exports.TrackingProvider = TrackingProvider;
1558
- exports.useActionComponent = useActionComponent;
1559
- exports.useActionsComponents = useActionsComponents;
1560
- exports.useActionsComponentsManager = useActionsComponentsManager;
1561
- exports.useAppComponent = useAppComponent;
1562
- exports.useAppComponents = useAppComponents;
1563
- exports.useAppComponentsManager = useAppComponentsManager;
1564
- exports.useButtonComponent = useButtonComponent;
1565
- exports.useButtonsComponents = useButtonsComponents;
1566
- exports.useButtonsComponentsManager = useButtonsComponentsManager;
1567
- exports.useComponent = useComponent;
1568
- exports.useComponents = useComponents;
1569
- exports.useComponentsManager = useComponentsManager;
1570
- exports.useDefinition = useDefinition;
1571
- exports.useDefinitionContext = useDefinitionContext;
1572
- exports.useDisplayComponent = useDisplayComponent;
1573
- exports.useDisplaysComponents = useDisplaysComponents;
1574
- exports.useDisplaysComponentsManager = useDisplaysComponentsManager;
1575
- exports.useField = useField;
1576
- exports.useFieldComponent = useFieldComponent;
1577
- exports.useFields = useFields;
1578
- exports.useFieldsComponents = useFieldsComponents;
1579
- exports.useFieldsComponentsManager = useFieldsComponentsManager;
1580
- exports.useFieldsManager = useFieldsManager;
1581
- exports.useFilterComponent = useFilterComponent;
1582
- exports.useFiltersComponents = useFiltersComponents;
1583
- exports.useFiltersComponentsManager = useFiltersComponentsManager;
1584
- exports.useFonts = useFonts;
1585
- exports.useForm = useForm;
1586
- exports.useFormComponent = useFormComponent;
1587
- exports.useFormSetValue = useFormSetValue;
1588
- exports.useFormValue = useFormValue;
1589
- exports.useFormsComponents = useFormsComponents;
1590
- exports.useFormsComponentsManager = useFormsComponentsManager;
1591
- exports.useGoogleApiClient = useGoogleApiClient;
1592
- exports.useGoogleFonts = useGoogleFonts;
1593
- exports.useGoogleKeys = useGoogleKeys;
1594
- exports.useGoogleMapsClient = useGoogleMapsClient;
1595
- exports.useListComponent = useListComponent;
1596
- exports.useListsComponents = useListsComponents;
1597
- exports.useListsComponentsManager = useListsComponentsManager;
1598
- exports.useLocales = useLocales;
1599
- exports.useModal = useModal;
1600
- exports.useModalComponent = useModalComponent;
1601
- exports.useModalsComponents = useModalsComponents;
1602
- exports.useModalsComponentsManager = useModalsComponentsManager;
1603
- exports.useOtherLocales = useOtherLocales;
1604
- exports.usePageComponent = usePageComponent;
1605
- exports.usePagesComponents = usePagesComponents;
1606
- exports.usePagesComponentsManager = usePagesComponentsManager;
1607
- exports.usePanels = usePanels;
1608
- exports.usePanneau = usePanneau;
1609
- exports.usePanneauAuth = usePanneauAuth;
1610
- exports.usePanneauColorScheme = usePanneauColorScheme;
1611
- exports.usePanneauComponent = usePanneauComponent;
1612
- exports.usePanneauComponents = usePanneauComponents;
1613
- exports.usePanneauResource = usePanneauResource;
1614
- exports.usePanneauResources = usePanneauResources;
1615
- exports.usePanneauSettings = usePanneauSettings;
1616
- exports.useResource = useResource;
1617
- exports.useRouteBack = useRouteBack;
1618
- exports.useRoutePush = useRoutePush;
1619
- exports.useRoutes = useRoutes$1;
1620
- exports.useTracking = useTracking;
1621
- exports.useUrlGenerator = useUrlGeneratorPathToRegexp;
1622
- exports.withGoogleApiClient = withGoogleApiClient;
1623
- exports.withGoogleMapsClient = withGoogleMapsClient;
1624
- exports.withPanels = withPanels;