@panneau/core 4.0.7 → 4.0.11
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/es/contexts.js +2 -2
- package/es/hooks.js +9 -176
- package/es/types/index.d.ts +4 -23
- package/es/types/panneau.d.ts +1 -0
- package/es/types/resource.d.ts +19 -0
- package/es/utils.js +2 -2
- package/lib/contexts.js +22 -10
- package/lib/hooks.js +7 -176
- package/lib/utils.js +2 -2
- package/package.json +12 -28
- package/contexts.js +0 -1
- package/hooks.js +0 -1
- package/utils.js +0 -1
package/es/contexts.js
CHANGED
|
@@ -15,9 +15,9 @@ import { getDisplayName } from '@panneau/core/utils';
|
|
|
15
15
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
16
16
|
import { useUrlGenerator } from '@folklore/routes';
|
|
17
17
|
export { RoutesContext, RoutesProvider, useRoutes, useUrlGenerator } from '@folklore/routes';
|
|
18
|
-
import {
|
|
19
|
-
import { TrackingContext, TrackingContainer } from '@folklore/tracking';
|
|
18
|
+
import { TrackingContainer, TrackingContext } from '@folklore/tracking';
|
|
20
19
|
export { TrackingContext } from '@folklore/tracking';
|
|
20
|
+
import { useLocation } from 'wouter';
|
|
21
21
|
|
|
22
22
|
var MODALS_NAMESPACE = 'modals';
|
|
23
23
|
var FIELDS_NAMESPACE = 'fields';
|
package/es/hooks.js
CHANGED
|
@@ -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-es/get';
|
|
11
|
+
import isArray from 'lodash-es/isArray';
|
|
12
|
+
import isObject from 'lodash-es/isObject';
|
|
13
|
+
import isString from 'lodash-es/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,
|
|
@@ -274,7 +107,7 @@ var _getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref)
|
|
|
274
107
|
_onChange = _ref.onChange,
|
|
275
108
|
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
276
109
|
var locales = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
277
|
-
return fields.reduce(function (allFields, field) {
|
|
110
|
+
return (fields || []).reduce(function (allFields, field) {
|
|
278
111
|
var _ref2 = isObject(field) ? field : {},
|
|
279
112
|
_ref2$name = _ref2.name,
|
|
280
113
|
name = _ref2$name === void 0 ? isString(field) ? field : null : _ref2$name,
|
|
@@ -310,7 +143,7 @@ var _getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref)
|
|
|
310
143
|
onChange: function onChange(fieldValue) {
|
|
311
144
|
return _onChange(name, fieldValue);
|
|
312
145
|
},
|
|
313
|
-
fields: fieldFields !== null ? _getFieldsPropsFromFields(fieldFields, {
|
|
146
|
+
fields: fieldFields !== null && isArray(fieldFields) ? _getFieldsPropsFromFields(fieldFields, {
|
|
314
147
|
value: value !== null && name !== null && isObject(value[name]) ? value[name] : null,
|
|
315
148
|
errors: subfieldErrors,
|
|
316
149
|
onChange: _onChange
|
|
@@ -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 };
|
package/es/types/index.d.ts
CHANGED
|
@@ -8,32 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
// Core UI Types
|
|
11
|
-
export type
|
|
12
|
-
Message,
|
|
13
|
-
Label,
|
|
14
|
-
StatusCode,
|
|
15
|
-
MenuItem,
|
|
16
|
-
Button,
|
|
17
|
-
ButtonTheme,
|
|
18
|
-
ButtonSize,
|
|
19
|
-
ButtonType,
|
|
20
|
-
DropdownAlign,
|
|
21
|
-
ControlSize,
|
|
22
|
-
FormStatus,
|
|
23
|
-
Feedback,
|
|
24
|
-
FormError,
|
|
25
|
-
Toggle,
|
|
26
|
-
Breadcrumb,
|
|
27
|
-
Font,
|
|
28
|
-
TrackingVariables,
|
|
29
|
-
TriggerUpdate,
|
|
30
|
-
} from './core';
|
|
11
|
+
export type * from './core';
|
|
31
12
|
|
|
32
13
|
// Form Types
|
|
33
|
-
export type
|
|
14
|
+
export type * from './form';
|
|
34
15
|
|
|
35
16
|
// Resource Types
|
|
36
|
-
export type
|
|
17
|
+
export type * from './resource';
|
|
37
18
|
|
|
38
19
|
// Panneau Definition Types
|
|
39
|
-
export type
|
|
20
|
+
export type * from './panneau';
|
package/es/types/panneau.d.ts
CHANGED
package/es/types/resource.d.ts
CHANGED
|
@@ -4,6 +4,25 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Field } from './form';
|
|
6
6
|
|
|
7
|
+
export interface Action {
|
|
8
|
+
id?: string;
|
|
9
|
+
component?: string;
|
|
10
|
+
label?: string | null;
|
|
11
|
+
icon?: string | null;
|
|
12
|
+
href?: string | null;
|
|
13
|
+
external?: boolean;
|
|
14
|
+
theme?: string;
|
|
15
|
+
target?: string;
|
|
16
|
+
onClick?: (() => void) | null;
|
|
17
|
+
endpoint?: string | null;
|
|
18
|
+
withConfirmation?: boolean;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ActionDefinition = string | Action;
|
|
23
|
+
|
|
24
|
+
type ActionValue = Item | Item[] | null;
|
|
25
|
+
|
|
7
26
|
/**
|
|
8
27
|
* Internationalization configuration
|
|
9
28
|
*/
|
package/es/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import isNumber from 'lodash-es/isNumber';
|
|
2
2
|
import { snakeCase } from 'snake-case';
|
|
3
|
-
import isObject from 'lodash-es/isObject';
|
|
4
|
-
import { useEffect, isValidElement } from 'react';
|
|
5
3
|
import _regenerator from '@babel/runtime/helpers/regenerator';
|
|
6
4
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
5
|
+
import isObject from 'lodash-es/isObject';
|
|
6
|
+
import { useEffect, isValidElement } from 'react';
|
|
7
7
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
8
8
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
9
9
|
import ReactIs from 'react-is';
|
package/lib/contexts.js
CHANGED
|
@@ -17,9 +17,9 @@ var utils = require('@panneau/core/utils');
|
|
|
17
17
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
18
18
|
var PropTypes = require('prop-types');
|
|
19
19
|
var pathToRegexp = require('path-to-regexp');
|
|
20
|
+
var tracking = require('@folklore/tracking');
|
|
20
21
|
var regexparam = require('regexparam');
|
|
21
22
|
var index_js = require('use-sync-external-store/shim/index.js');
|
|
22
|
-
var tracking = require('@folklore/tracking');
|
|
23
23
|
|
|
24
24
|
function _interopNamespaceDefault(e) {
|
|
25
25
|
var n = Object.create(null);
|
|
@@ -978,11 +978,14 @@ var currentSearch = function currentSearch() {
|
|
|
978
978
|
};
|
|
979
979
|
var useSearch = function useSearch() {
|
|
980
980
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
981
|
+
ssrSearch = _ref.ssrSearch;
|
|
982
|
+
return useLocationProperty(currentSearch,
|
|
983
|
+
// != null checks for both null and undefined, but allows empty string ""
|
|
984
|
+
// This allows proper hydration: server renders with ssrSearch="?foo",
|
|
985
|
+
// client hydrates with just <Router /> and reads from location.search
|
|
986
|
+
ssrSearch != null ? function () {
|
|
984
987
|
return ssrSearch;
|
|
985
|
-
});
|
|
988
|
+
} : currentSearch);
|
|
986
989
|
};
|
|
987
990
|
var currentPathname = function currentPathname() {
|
|
988
991
|
return location.pathname;
|
|
@@ -990,7 +993,11 @@ var currentPathname = function currentPathname() {
|
|
|
990
993
|
var usePathname = function usePathname() {
|
|
991
994
|
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
992
995
|
ssrPath = _ref2.ssrPath;
|
|
993
|
-
return useLocationProperty(currentPathname,
|
|
996
|
+
return useLocationProperty(currentPathname,
|
|
997
|
+
// != null checks for both null and undefined, but allows empty string ""
|
|
998
|
+
// This allows proper hydration: server renders with ssrPath="/foo",
|
|
999
|
+
// client hydrates with just <Router /> and reads from location.pathname
|
|
1000
|
+
ssrPath != null ? function () {
|
|
994
1001
|
return ssrPath;
|
|
995
1002
|
} : currentPathname);
|
|
996
1003
|
};
|
|
@@ -1042,8 +1049,6 @@ if (typeof history !== "undefined" && typeof window[patchKey] === "undefined") {
|
|
|
1042
1049
|
});
|
|
1043
1050
|
}
|
|
1044
1051
|
|
|
1045
|
-
var _excluded3 = ["to", "href", "onClick", "asChild", "children", "className", "replace", "state"];
|
|
1046
|
-
|
|
1047
1052
|
/*
|
|
1048
1053
|
* Transforms `path` into its relative `base` version
|
|
1049
1054
|
* If base isn't part of the path provided returns absolute path e.g. `~/app`
|
|
@@ -1080,6 +1085,8 @@ var unescape = function unescape(str) {
|
|
|
1080
1085
|
}
|
|
1081
1086
|
};
|
|
1082
1087
|
|
|
1088
|
+
var _excluded3 = ["to", "href", "onClick", "asChild", "children", "className", "replace", "state", "transition"];
|
|
1089
|
+
|
|
1083
1090
|
/*
|
|
1084
1091
|
* Router and router context. Router is a lightweight object that represents the current
|
|
1085
1092
|
* routing options: how location is managed, base path etc.
|
|
@@ -1101,6 +1108,10 @@ var defaultRouter = {
|
|
|
1101
1108
|
// customizes how `href` props are transformed for <Link />
|
|
1102
1109
|
hrefs: function hrefs(x) {
|
|
1103
1110
|
return x;
|
|
1111
|
+
},
|
|
1112
|
+
// wraps navigate calls, useful for view transitions
|
|
1113
|
+
aroundNav: function aroundNav(n, t, o) {
|
|
1114
|
+
return n(t, o);
|
|
1104
1115
|
}
|
|
1105
1116
|
};
|
|
1106
1117
|
var RouterCtx = React.createContext(defaultRouter);
|
|
@@ -1133,8 +1144,8 @@ var useLocationFromRouter = function useLocationFromRouter(router) {
|
|
|
1133
1144
|
// the function reference should stay the same between re-renders, so that
|
|
1134
1145
|
// it can be passed down as an element prop without any performance concerns.
|
|
1135
1146
|
// (This is achieved via `useEvent`.)
|
|
1136
|
-
return [relativePath(router.base, location), useEvent(function (to,
|
|
1137
|
-
return navigate
|
|
1147
|
+
return [relativePath(router.base, location), useEvent(function (to, opts) {
|
|
1148
|
+
return router.aroundNav(navigate, absolutePath(to, router.base), opts);
|
|
1138
1149
|
})];
|
|
1139
1150
|
};
|
|
1140
1151
|
var useLocation = function useLocation() {
|
|
@@ -1156,6 +1167,7 @@ React.forwardRef(function (props, ref) {
|
|
|
1156
1167
|
cls = props.className;
|
|
1157
1168
|
props.replace;
|
|
1158
1169
|
props.state;
|
|
1170
|
+
props.transition;
|
|
1159
1171
|
var restProps = _objectWithoutProperties(props, _excluded3);
|
|
1160
1172
|
var onClick = useEvent(function (event) {
|
|
1161
1173
|
// ignores the navigation when clicked using right mouse button or
|
package/lib/hooks.js
CHANGED
|
@@ -1,190 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var get = require('lodash-es/get');
|
|
4
|
-
var isArray = require('lodash-es/isArray');
|
|
5
3
|
var react = require('react');
|
|
6
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
7
|
-
var isObject = require('lodash-es/isObject');
|
|
8
|
-
var isString = require('lodash-es/isString');
|
|
9
4
|
var core = require('@panneau/core');
|
|
10
5
|
var utils = require('@panneau/core/utils');
|
|
11
6
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
12
7
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
8
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
13
9
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
14
10
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
15
11
|
var fetch = require('@folklore/fetch');
|
|
12
|
+
var get = require('lodash-es/get');
|
|
13
|
+
var isArray = require('lodash-es/isArray');
|
|
14
|
+
var isObject = require('lodash-es/isObject');
|
|
15
|
+
var isString = require('lodash-es/isString');
|
|
16
16
|
var contexts = require('@panneau/core/contexts');
|
|
17
17
|
var dayjs = require('dayjs');
|
|
18
18
|
var reactIntl = require('react-intl');
|
|
19
19
|
var cssMediaquery = require('css-mediaquery');
|
|
20
20
|
|
|
21
|
-
function useActionProps(action, value) {
|
|
22
|
-
var labelPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
23
|
-
var values = react.useMemo(function () {
|
|
24
|
-
if (value === null) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (isArray(value)) {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
return value || null;
|
|
31
|
-
}, [value]);
|
|
32
|
-
var ids = react.useMemo(function () {
|
|
33
|
-
if (value === null) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
if (isArray(value)) {
|
|
37
|
-
return value.map(function () {
|
|
38
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
39
|
-
_ref$id = _ref.id,
|
|
40
|
-
id = _ref$id === void 0 ? null : _ref$id;
|
|
41
|
-
return id;
|
|
42
|
-
}).filter(function (id) {
|
|
43
|
-
return id !== null;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return value !== null && typeof value.id !== 'undefined' ? [value.id] : null;
|
|
47
|
-
}, [value]);
|
|
48
|
-
var idKeys = react.useMemo(function () {
|
|
49
|
-
return (ids || []).map(function (id) {
|
|
50
|
-
return "".concat(id);
|
|
51
|
-
}).join('-');
|
|
52
|
-
}, [ids]);
|
|
53
|
-
var idLabels = react.useMemo(function () {
|
|
54
|
-
return isArray(values) ? values.map(function () {
|
|
55
|
-
var it = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
56
|
-
return "#".concat(get(it, 'id', '')).concat(labelPath !== null ? " ".concat(get(it, labelPath, '')) : '');
|
|
57
|
-
}).join(', ') : get(values, 'id', 'no-value');
|
|
58
|
-
}, [ids]);
|
|
59
|
-
var modalKey = react.useMemo(function () {
|
|
60
|
-
return "".concat(action, "-").concat(idKeys);
|
|
61
|
-
}, [idKeys]);
|
|
62
|
-
return {
|
|
63
|
-
ids: ids,
|
|
64
|
-
idKeys: idKeys,
|
|
65
|
-
idLabels: idLabels,
|
|
66
|
-
modalKey: modalKey
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// For backwards compatibility with the old actions element
|
|
71
|
-
|
|
72
|
-
function useActions() {
|
|
73
|
-
var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
74
|
-
var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
75
|
-
var urlGenerator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
76
|
-
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
77
|
-
_ref$iconsOnly = _ref.iconsOnly,
|
|
78
|
-
iconsOnly = _ref$iconsOnly === void 0 ? true : _ref$iconsOnly,
|
|
79
|
-
_ref$showLabel = _ref.showLabel,
|
|
80
|
-
showLabel = _ref$showLabel === void 0 ? null : _ref$showLabel,
|
|
81
|
-
_ref$editLabel = _ref.editLabel,
|
|
82
|
-
editLabel = _ref$editLabel === void 0 ? null : _ref$editLabel,
|
|
83
|
-
_ref$deleteLabel = _ref.deleteLabel,
|
|
84
|
-
deleteLabel = _ref$deleteLabel === void 0 ? null : _ref$deleteLabel,
|
|
85
|
-
_ref$onClickShow = _ref.onClickShow,
|
|
86
|
-
onClickShow = _ref$onClickShow === void 0 ? null : _ref$onClickShow,
|
|
87
|
-
_ref$onClickEdit = _ref.onClickEdit,
|
|
88
|
-
onClickEdit = _ref$onClickEdit === void 0 ? null : _ref$onClickEdit,
|
|
89
|
-
_ref$onClickDelete = _ref.onClickDelete,
|
|
90
|
-
onClickDelete = _ref$onClickDelete === void 0 ? null : _ref$onClickDelete,
|
|
91
|
-
_ref$getShowPropsFrom = _ref.getShowPropsFromItem,
|
|
92
|
-
getShowPropsFromItem = _ref$getShowPropsFrom === void 0 ? null : _ref$getShowPropsFrom,
|
|
93
|
-
_ref$getEditPropsFrom = _ref.getEditPropsFromItem,
|
|
94
|
-
getEditPropsFromItem = _ref$getEditPropsFrom === void 0 ? null : _ref$getEditPropsFrom,
|
|
95
|
-
_ref$getDeletePropsFr = _ref.getDeletePropsFromItem,
|
|
96
|
-
getDeletePropsFromItem = _ref$getDeletePropsFr === void 0 ? null : _ref$getDeletePropsFr,
|
|
97
|
-
_ref$showUrl = _ref.showUrl,
|
|
98
|
-
showUrl = _ref$showUrl === void 0 ? null : _ref$showUrl,
|
|
99
|
-
_ref$withoutItemShowU = _ref.withoutItemShowUrl,
|
|
100
|
-
withoutItemShowUrl = _ref$withoutItemShowU === void 0 ? null : _ref$withoutItemShowU,
|
|
101
|
-
_ref$preferEditModal = _ref.preferEditModal,
|
|
102
|
-
preferEditModal = _ref$preferEditModal === void 0 ? false : _ref$preferEditModal,
|
|
103
|
-
_ref$preferDeleteModa = _ref.preferDeleteModal,
|
|
104
|
-
preferDeleteModal = _ref$preferDeleteModa === void 0 ? false : _ref$preferDeleteModa,
|
|
105
|
-
_ref$hasDuplicateRout = _ref.hasDuplicateRoute,
|
|
106
|
-
hasDuplicateRoute = _ref$hasDuplicateRout === void 0 ? false : _ref$hasDuplicateRout;
|
|
107
|
-
var _ref2 = item || {},
|
|
108
|
-
id = _ref2.id,
|
|
109
|
-
_ref2$url = _ref2.url,
|
|
110
|
-
url = _ref2$url === void 0 ? null : _ref2$url;
|
|
111
|
-
var hasCustomShowUrl = showUrl !== null || url !== null;
|
|
112
|
-
return (actions || []).map(function (action) {
|
|
113
|
-
if (isString(action)) {
|
|
114
|
-
switch (action) {
|
|
115
|
-
case 'show':
|
|
116
|
-
return _objectSpread({
|
|
117
|
-
id: 'show',
|
|
118
|
-
component: 'show',
|
|
119
|
-
label: iconsOnly ? null : showLabel,
|
|
120
|
-
icon: iconsOnly ? 'eye' : null,
|
|
121
|
-
href: urlGenerator !== null && (!hasCustomShowUrl || withoutItemShowUrl) ? urlGenerator('show', {
|
|
122
|
-
id: id
|
|
123
|
-
}) || null : showUrl || url,
|
|
124
|
-
external: hasCustomShowUrl,
|
|
125
|
-
theme: 'info',
|
|
126
|
-
target: '_blank',
|
|
127
|
-
onClick: onClickShow
|
|
128
|
-
}, getShowPropsFromItem !== null ? getShowPropsFromItem(item) : null);
|
|
129
|
-
case 'edit':
|
|
130
|
-
return _objectSpread({
|
|
131
|
-
id: 'edit',
|
|
132
|
-
component: 'edit',
|
|
133
|
-
label: iconsOnly ? null : editLabel,
|
|
134
|
-
icon: iconsOnly ? 'pencil-square' : null,
|
|
135
|
-
href: urlGenerator !== null && !preferEditModal ? urlGenerator('edit', {
|
|
136
|
-
id: id
|
|
137
|
-
}) || null : null,
|
|
138
|
-
theme: 'primary',
|
|
139
|
-
onClick: onClickEdit
|
|
140
|
-
}, getEditPropsFromItem !== null ? getEditPropsFromItem(item) : null);
|
|
141
|
-
case 'duplicate':
|
|
142
|
-
return {
|
|
143
|
-
id: 'duplicate',
|
|
144
|
-
component: 'duplicate',
|
|
145
|
-
label: null,
|
|
146
|
-
href: urlGenerator !== null && hasDuplicateRoute ? urlGenerator('duplicate', {
|
|
147
|
-
id: id
|
|
148
|
-
}) || null : null
|
|
149
|
-
};
|
|
150
|
-
case 'restore':
|
|
151
|
-
return {
|
|
152
|
-
id: 'restore',
|
|
153
|
-
component: 'restore',
|
|
154
|
-
label: null
|
|
155
|
-
};
|
|
156
|
-
case 'delete':
|
|
157
|
-
return _objectSpread({
|
|
158
|
-
id: 'delete',
|
|
159
|
-
component: 'delete',
|
|
160
|
-
label: iconsOnly ? null : deleteLabel,
|
|
161
|
-
icon: iconsOnly ? 'trash3' : null,
|
|
162
|
-
href: urlGenerator !== null && !preferDeleteModal ? urlGenerator('delete', {
|
|
163
|
-
id: id
|
|
164
|
-
}) || null : null,
|
|
165
|
-
theme: 'danger',
|
|
166
|
-
onClick: onClickDelete,
|
|
167
|
-
endpoint: urlGenerator !== null && preferDeleteModal ? urlGenerator('delete', {
|
|
168
|
-
id: id
|
|
169
|
-
}) || null : null,
|
|
170
|
-
withConfirmation: preferDeleteModal
|
|
171
|
-
}, getDeletePropsFromItem !== null ? getDeletePropsFromItem(item) : null);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (isObject(action)) {
|
|
175
|
-
var _ref3 = action || {},
|
|
176
|
-
_ref3$itemLinkProp = _ref3.itemLinkProp,
|
|
177
|
-
itemLinkProp = _ref3$itemLinkProp === void 0 ? null : _ref3$itemLinkProp;
|
|
178
|
-
return _objectSpread(_objectSpread({}, action), itemLinkProp !== null && isObject(item) && typeof item[itemLinkProp] !== 'undefined' ? {
|
|
179
|
-
href: item[itemLinkProp]
|
|
180
|
-
} : null);
|
|
181
|
-
}
|
|
182
|
-
return action;
|
|
183
|
-
}).filter(function (action) {
|
|
184
|
-
return action !== null;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
21
|
function useAnimationFrame(onFrame) {
|
|
189
22
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
190
23
|
_ref$disabled = _ref.disabled,
|
|
@@ -276,7 +109,7 @@ var _getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref)
|
|
|
276
109
|
_onChange = _ref.onChange,
|
|
277
110
|
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
278
111
|
var locales = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
279
|
-
return fields.reduce(function (allFields, field) {
|
|
112
|
+
return (fields || []).reduce(function (allFields, field) {
|
|
280
113
|
var _ref2 = isObject(field) ? field : {},
|
|
281
114
|
_ref2$name = _ref2.name,
|
|
282
115
|
name = _ref2$name === void 0 ? isString(field) ? field : null : _ref2$name,
|
|
@@ -312,7 +145,7 @@ var _getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref)
|
|
|
312
145
|
onChange: function onChange(fieldValue) {
|
|
313
146
|
return _onChange(name, fieldValue);
|
|
314
147
|
},
|
|
315
|
-
fields: fieldFields !== null ? _getFieldsPropsFromFields(fieldFields, {
|
|
148
|
+
fields: fieldFields !== null && isArray(fieldFields) ? _getFieldsPropsFromFields(fieldFields, {
|
|
316
149
|
value: value !== null && name !== null && isObject(value[name]) ? value[name] : null,
|
|
317
150
|
errors: subfieldErrors,
|
|
318
151
|
onChange: _onChange
|
|
@@ -1314,8 +1147,6 @@ var useWindowEvent = utils.createUseEvent(eventsManager);
|
|
|
1314
1147
|
|
|
1315
1148
|
exports.KEYCODES = KEYCODES;
|
|
1316
1149
|
exports.getObserver = getObserver;
|
|
1317
|
-
exports.useActionProps = useActionProps;
|
|
1318
|
-
exports.useActions = useActions;
|
|
1319
1150
|
exports.useAnimationFrame = useAnimationFrame;
|
|
1320
1151
|
exports.useDocumentEvent = useDocumentEvent;
|
|
1321
1152
|
exports.useForm = useForm;
|
package/lib/utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var isNumber = require('lodash-es/isNumber');
|
|
4
|
-
var isObject = require('lodash-es/isObject');
|
|
5
|
-
var react = require('react');
|
|
6
4
|
var _regenerator = require('@babel/runtime/helpers/regenerator');
|
|
7
5
|
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
6
|
+
var isObject = require('lodash-es/isObject');
|
|
7
|
+
var react = require('react');
|
|
8
8
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
9
9
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
10
10
|
var ReactIs = require('react-is');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -27,36 +27,20 @@
|
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"type": "module",
|
|
29
29
|
"module": "es/index.js",
|
|
30
|
+
"types": "es/types/index.d.ts",
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
33
|
"import": {
|
|
33
34
|
"default": "./es/index.js",
|
|
34
35
|
"types": "./es/types/index.d.ts"
|
|
35
|
-
},
|
|
36
|
-
"require": {
|
|
37
|
-
"types": "./lib/types/index.d.ts",
|
|
38
|
-
"default": "./lib/index.js"
|
|
39
36
|
}
|
|
40
37
|
},
|
|
41
|
-
"./contexts":
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"./hooks": {
|
|
46
|
-
"require": "./lib/hooks.js",
|
|
47
|
-
"import": "./es/hooks.js"
|
|
48
|
-
},
|
|
49
|
-
"./utils": {
|
|
50
|
-
"require": "./lib/utils.js",
|
|
51
|
-
"import": "./es/utils.js"
|
|
52
|
-
},
|
|
53
|
-
"./types": {
|
|
54
|
-
"require": "./lib/types/index.d.ts",
|
|
55
|
-
"import": "./es/types/index.d.ts"
|
|
56
|
-
}
|
|
38
|
+
"./contexts": "./es/contexts.js",
|
|
39
|
+
"./hooks": "./es/hooks.js",
|
|
40
|
+
"./utils": "./es/utils.js",
|
|
41
|
+
"./types": "./es/types/index.d.ts"
|
|
57
42
|
},
|
|
58
43
|
"sideEffects": [
|
|
59
|
-
"./lib/hooks.js",
|
|
60
44
|
"./es/hooks.js"
|
|
61
45
|
],
|
|
62
46
|
"files": [
|
|
@@ -70,15 +54,15 @@
|
|
|
70
54
|
],
|
|
71
55
|
"scripts": {
|
|
72
56
|
"prepublishOnly": "npm run build",
|
|
73
|
-
"build": "../../scripts/prepare-package.sh
|
|
57
|
+
"build": "../../scripts/prepare-package.sh"
|
|
74
58
|
},
|
|
75
59
|
"devDependencies": {
|
|
76
|
-
"react": "^
|
|
77
|
-
"react-dom": "^
|
|
60
|
+
"react": "^19.0.0",
|
|
61
|
+
"react-dom": "^19.0.0"
|
|
78
62
|
},
|
|
79
63
|
"peerDependencies": {
|
|
80
|
-
"react": "^
|
|
81
|
-
"react-dom": "^
|
|
64
|
+
"react": "^19.0.0",
|
|
65
|
+
"react-dom": "^19.0.0"
|
|
82
66
|
},
|
|
83
67
|
"dependencies": {
|
|
84
68
|
"@babel/runtime": "^7.12.5",
|
|
@@ -112,5 +96,5 @@
|
|
|
112
96
|
"publishConfig": {
|
|
113
97
|
"access": "public"
|
|
114
98
|
},
|
|
115
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "fe8264ed2815da0b5a40339dec99999c6fe70751"
|
|
116
100
|
}
|
package/contexts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./lib/contexts');
|
package/hooks.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./lib/hooks');
|
package/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./lib/utils');
|