@panneau/display-link 3.0.223 → 3.0.228
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/package.json +8 -5
- package/lib/index.js +0 -343
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/display-link",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.228",
|
|
4
4
|
"description": "Link item value in list",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -25,8 +25,11 @@
|
|
|
25
25
|
}
|
|
26
26
|
],
|
|
27
27
|
"license": "ISC",
|
|
28
|
-
"
|
|
28
|
+
"type": "module",
|
|
29
29
|
"module": "es/index.js",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./es/index.js"
|
|
32
|
+
},
|
|
30
33
|
"files": [
|
|
31
34
|
"lib",
|
|
32
35
|
"es",
|
|
@@ -46,8 +49,8 @@
|
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"@babel/runtime": "^7.12.5",
|
|
49
|
-
"@panneau/core": "^3.0.
|
|
50
|
-
"@panneau/themes": "^3.0.
|
|
52
|
+
"@panneau/core": "^3.0.228",
|
|
53
|
+
"@panneau/themes": "^3.0.228",
|
|
51
54
|
"lodash": "^4.17.21",
|
|
52
55
|
"prop-types": "^15.7.2",
|
|
53
56
|
"react-intl": "^5.15.8||^6.0.0",
|
|
@@ -56,5 +59,5 @@
|
|
|
56
59
|
"publishConfig": {
|
|
57
60
|
"access": "public"
|
|
58
61
|
},
|
|
59
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "2adf72884fb88052c6a6822e6f32169bb1dfe18b"
|
|
60
63
|
}
|
package/lib/index.js
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var get = require('lodash/get');
|
|
6
|
-
var isString = require('lodash/isString');
|
|
7
|
-
var PropTypes = require('prop-types');
|
|
8
|
-
var React = require('react');
|
|
9
|
-
var reactIntl = require('react-intl');
|
|
10
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
11
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
12
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
13
|
-
var regexparam = require('regexparam');
|
|
14
|
-
var index_js = require('use-sync-external-store/shim/index.js');
|
|
15
|
-
|
|
16
|
-
function _interopNamespaceDefault(e) {
|
|
17
|
-
var n = Object.create(null);
|
|
18
|
-
if (e) {
|
|
19
|
-
Object.keys(e).forEach(function (k) {
|
|
20
|
-
if (k !== 'default') {
|
|
21
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () { return e[k]; }
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
n.default = e;
|
|
30
|
-
return Object.freeze(n);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
34
|
-
|
|
35
|
-
var useEffect = React__namespace.useEffect,
|
|
36
|
-
useLayoutEffect = React__namespace.useLayoutEffect,
|
|
37
|
-
useRef = React__namespace.useRef;
|
|
38
|
-
|
|
39
|
-
// React.useInsertionEffect is not available in React <18
|
|
40
|
-
// This hack fixes a transpilation issue on some apps
|
|
41
|
-
var useBuiltinInsertionEffect = React__namespace['useInsertion' + 'Effect'];
|
|
42
|
-
|
|
43
|
-
// Copied from:
|
|
44
|
-
// https://github.com/facebook/react/blob/main/packages/shared/ExecutionEnvironment.js
|
|
45
|
-
var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
|
46
|
-
|
|
47
|
-
// Copied from:
|
|
48
|
-
// https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.ts
|
|
49
|
-
// "React currently throws a warning when using useLayoutEffect on the server.
|
|
50
|
-
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
51
|
-
// useLayoutEffect in the browser."
|
|
52
|
-
var useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
|
|
53
|
-
|
|
54
|
-
// useInsertionEffect is already a noop on the server.
|
|
55
|
-
// See: https://github.com/facebook/react/blob/main/packages/react-server/src/ReactFizzHooks.js
|
|
56
|
-
var useInsertionEffect = useBuiltinInsertionEffect || useIsomorphicLayoutEffect;
|
|
57
|
-
|
|
58
|
-
// Userland polyfill while we wait for the forthcoming
|
|
59
|
-
// https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
|
|
60
|
-
// Note: "A high-fidelity polyfill for useEvent is not possible because
|
|
61
|
-
// there is no lifecycle or Hook in React that we can use to switch
|
|
62
|
-
// .current at the right timing."
|
|
63
|
-
// So we will have to make do with this "close enough" approach for now.
|
|
64
|
-
var useEvent = function useEvent(fn) {
|
|
65
|
-
var ref = useRef([fn, function () {
|
|
66
|
-
return ref[0].apply(ref, arguments);
|
|
67
|
-
}]).current;
|
|
68
|
-
// Per Dan Abramov: useInsertionEffect executes marginally closer to the
|
|
69
|
-
// correct timing for ref synchronization than useLayoutEffect on React 18.
|
|
70
|
-
// See: https://github.com/facebook/react/pull/25881#issuecomment-1356244360
|
|
71
|
-
useInsertionEffect(function () {
|
|
72
|
-
ref[0] = fn;
|
|
73
|
-
});
|
|
74
|
-
return ref[1];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* History API docs @see https://developer.mozilla.org/en-US/docs/Web/API/History
|
|
79
|
-
*/
|
|
80
|
-
var eventPopstate = "popstate";
|
|
81
|
-
var eventPushState = "pushState";
|
|
82
|
-
var eventReplaceState = "replaceState";
|
|
83
|
-
var eventHashchange = "hashchange";
|
|
84
|
-
var events = [eventPopstate, eventPushState, eventReplaceState, eventHashchange];
|
|
85
|
-
var subscribeToLocationUpdates = function subscribeToLocationUpdates(callback) {
|
|
86
|
-
for (var _i = 0, _events = events; _i < _events.length; _i++) {
|
|
87
|
-
var event = _events[_i];
|
|
88
|
-
addEventListener(event, callback);
|
|
89
|
-
}
|
|
90
|
-
return function () {
|
|
91
|
-
for (var _i2 = 0, _events2 = events; _i2 < _events2.length; _i2++) {
|
|
92
|
-
var _event = _events2[_i2];
|
|
93
|
-
removeEventListener(_event, callback);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
var useLocationProperty = function useLocationProperty(fn, ssrFn) {
|
|
98
|
-
return index_js.useSyncExternalStore(subscribeToLocationUpdates, fn, ssrFn);
|
|
99
|
-
};
|
|
100
|
-
var currentSearch = function currentSearch() {
|
|
101
|
-
return location.search;
|
|
102
|
-
};
|
|
103
|
-
var useSearch = function useSearch() {
|
|
104
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
105
|
-
_ref$ssrSearch = _ref.ssrSearch,
|
|
106
|
-
ssrSearch = _ref$ssrSearch === void 0 ? "" : _ref$ssrSearch;
|
|
107
|
-
return useLocationProperty(currentSearch, function () {
|
|
108
|
-
return ssrSearch;
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
var currentPathname = function currentPathname() {
|
|
112
|
-
return location.pathname;
|
|
113
|
-
};
|
|
114
|
-
var usePathname = function usePathname() {
|
|
115
|
-
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
116
|
-
ssrPath = _ref2.ssrPath;
|
|
117
|
-
return useLocationProperty(currentPathname, ssrPath ? function () {
|
|
118
|
-
return ssrPath;
|
|
119
|
-
} : currentPathname);
|
|
120
|
-
};
|
|
121
|
-
var navigate = function navigate(to) {
|
|
122
|
-
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
123
|
-
_ref3$replace = _ref3.replace,
|
|
124
|
-
replace = _ref3$replace === void 0 ? false : _ref3$replace,
|
|
125
|
-
_ref3$state = _ref3.state,
|
|
126
|
-
state = _ref3$state === void 0 ? null : _ref3$state;
|
|
127
|
-
return history[replace ? eventReplaceState : eventPushState](state, "", to);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// the 2nd argument of the `useBrowserLocation` return value is a function
|
|
131
|
-
// that allows to perform a navigation.
|
|
132
|
-
var useBrowserLocation = function useBrowserLocation() {
|
|
133
|
-
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
134
|
-
return [usePathname(opts), navigate];
|
|
135
|
-
};
|
|
136
|
-
var patchKey = Symbol["for"]("wouter_v3");
|
|
137
|
-
|
|
138
|
-
// While History API does have `popstate` event, the only
|
|
139
|
-
// proper way to listen to changes via `push/replaceState`
|
|
140
|
-
// is to monkey-patch these methods.
|
|
141
|
-
//
|
|
142
|
-
// See https://stackoverflow.com/a/4585031
|
|
143
|
-
if (typeof history !== "undefined" && typeof window[patchKey] === "undefined") {
|
|
144
|
-
var _loop = function _loop() {
|
|
145
|
-
var type = _arr[_i3];
|
|
146
|
-
var original = history[type];
|
|
147
|
-
// TODO: we should be using unstable_batchedUpdates to avoid multiple re-renders,
|
|
148
|
-
// however that will require an additional peer dependency on react-dom.
|
|
149
|
-
// See: https://github.com/reactwg/react-18/discussions/86#discussioncomment-1567149
|
|
150
|
-
history[type] = function () {
|
|
151
|
-
var result = original.apply(this, arguments);
|
|
152
|
-
var event = new Event(type);
|
|
153
|
-
event.arguments = arguments;
|
|
154
|
-
dispatchEvent(event);
|
|
155
|
-
return result;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
for (var _i3 = 0, _arr = [eventPushState, eventReplaceState]; _i3 < _arr.length; _i3++) {
|
|
159
|
-
_loop();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// patch history object only once
|
|
163
|
-
// See: https://github.com/molefrog/wouter/issues/167
|
|
164
|
-
Object.defineProperty(window, patchKey, {
|
|
165
|
-
value: true
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
var _excluded3 = ["to", "href", "onClick", "asChild", "children", "className", "replace", "state"];
|
|
170
|
-
|
|
171
|
-
/*
|
|
172
|
-
* Transforms `path` into its relative `base` version
|
|
173
|
-
* If base isn't part of the path provided returns absolute path e.g. `~/app`
|
|
174
|
-
*/
|
|
175
|
-
var relativePath = function relativePath() {
|
|
176
|
-
var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
177
|
-
var path = arguments.length > 1 ? arguments[1] : undefined;
|
|
178
|
-
return !path.toLowerCase().indexOf(base.toLowerCase()) ? path.slice(base.length) || "/" : "~" + path;
|
|
179
|
-
};
|
|
180
|
-
var absolutePath = function absolutePath(to) {
|
|
181
|
-
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
|
|
182
|
-
return to[0] === "~" ? to.slice(1) : base + to;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
/*
|
|
186
|
-
* decodes escape sequences such as %20
|
|
187
|
-
*/
|
|
188
|
-
var unescape = function unescape(str) {
|
|
189
|
-
try {
|
|
190
|
-
return decodeURI(str);
|
|
191
|
-
} catch (_e) {
|
|
192
|
-
// fail-safe mode: if string can't be decoded do nothing
|
|
193
|
-
return str;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
/*
|
|
198
|
-
* Router and router context. Router is a lightweight object that represents the current
|
|
199
|
-
* routing options: how location is managed, base path etc.
|
|
200
|
-
*
|
|
201
|
-
* There is a default router present for most of the use cases, however it can be overridden
|
|
202
|
-
* via the <Router /> component.
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
var defaultRouter = {
|
|
206
|
-
hook: useBrowserLocation,
|
|
207
|
-
searchHook: useSearch,
|
|
208
|
-
parser: regexparam.parse,
|
|
209
|
-
base: "",
|
|
210
|
-
// this option is used to override the current location during SSR
|
|
211
|
-
ssrPath: undefined,
|
|
212
|
-
ssrSearch: undefined,
|
|
213
|
-
// customizes how `href` props are transformed for <Link />
|
|
214
|
-
hrefs: function hrefs(x) {
|
|
215
|
-
return x;
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
var RouterCtx = React.createContext(defaultRouter);
|
|
219
|
-
|
|
220
|
-
// gets the closest parent router from the context
|
|
221
|
-
var useRouter = function useRouter() {
|
|
222
|
-
return React.useContext(RouterCtx);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Parameters context. Used by `useParams()` to get the
|
|
227
|
-
* matched params from the innermost `Route` component.
|
|
228
|
-
*/
|
|
229
|
-
|
|
230
|
-
React.createContext({});
|
|
231
|
-
|
|
232
|
-
/*
|
|
233
|
-
* Part 1, Hooks API: useRoute and useLocation
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
// Internal version of useLocation to avoid redundant useRouter calls
|
|
237
|
-
|
|
238
|
-
var useLocationFromRouter = function useLocationFromRouter(router) {
|
|
239
|
-
var _router$hook = router.hook(router),
|
|
240
|
-
_router$hook2 = _slicedToArray(_router$hook, 2),
|
|
241
|
-
location = _router$hook2[0],
|
|
242
|
-
navigate = _router$hook2[1];
|
|
243
|
-
|
|
244
|
-
// the function reference should stay the same between re-renders, so that
|
|
245
|
-
// it can be passed down as an element prop without any performance concerns.
|
|
246
|
-
// (This is achieved via `useEvent`.)
|
|
247
|
-
return [unescape(relativePath(router.base, location)), useEvent(function (to, navOpts) {
|
|
248
|
-
return navigate(absolutePath(to, router.base), navOpts);
|
|
249
|
-
})];
|
|
250
|
-
};
|
|
251
|
-
var Link$2 = React.forwardRef(function (props, ref) {
|
|
252
|
-
var router = useRouter();
|
|
253
|
-
var _useLocationFromRoute3 = useLocationFromRouter(router),
|
|
254
|
-
_useLocationFromRoute4 = _slicedToArray(_useLocationFromRoute3, 2),
|
|
255
|
-
path = _useLocationFromRoute4[0],
|
|
256
|
-
navigate = _useLocationFromRoute4[1];
|
|
257
|
-
var to = props.to,
|
|
258
|
-
_props$href = props.href,
|
|
259
|
-
_href = _props$href === void 0 ? to : _props$href,
|
|
260
|
-
_onClick = props.onClick,
|
|
261
|
-
asChild = props.asChild,
|
|
262
|
-
children = props.children,
|
|
263
|
-
cls = props.className;
|
|
264
|
-
props.replace;
|
|
265
|
-
props.state;
|
|
266
|
-
var restProps = _objectWithoutProperties(props, _excluded3);
|
|
267
|
-
var onClick = useEvent(function (event) {
|
|
268
|
-
// ignores the navigation when clicked using right mouse button or
|
|
269
|
-
// by holding a special modifier key: ctrl, command, win, alt, shift
|
|
270
|
-
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || event.button !== 0) return;
|
|
271
|
-
_onClick === null || _onClick === void 0 || _onClick(event);
|
|
272
|
-
if (!event.defaultPrevented) {
|
|
273
|
-
event.preventDefault();
|
|
274
|
-
navigate(_href, props);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
// handle nested routers and absolute paths
|
|
279
|
-
var href = router.hrefs(_href[0] === "~" ? _href.slice(1) : router.base + _href, router // pass router as a second argument for convinience
|
|
280
|
-
);
|
|
281
|
-
return asChild && React.isValidElement(children) ? React.cloneElement(children, {
|
|
282
|
-
onClick: onClick,
|
|
283
|
-
href: href
|
|
284
|
-
}) : React.createElement("a", _objectSpread(_objectSpread({}, restProps), {}, {
|
|
285
|
-
onClick: onClick,
|
|
286
|
-
href: href,
|
|
287
|
-
// `className` can be a function to apply the class if this link is active
|
|
288
|
-
className: cls !== null && cls !== void 0 && cls.call ? cls(path === href) : cls,
|
|
289
|
-
children: children,
|
|
290
|
-
ref: ref
|
|
291
|
-
}));
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
var propTypes = {
|
|
295
|
-
item: PropTypes.shape({
|
|
296
|
-
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
297
|
-
}),
|
|
298
|
-
value: PropTypes.string,
|
|
299
|
-
label: PropTypes.string,
|
|
300
|
-
labelPath: PropTypes.string,
|
|
301
|
-
external: PropTypes.bool,
|
|
302
|
-
target: PropTypes.string,
|
|
303
|
-
placeholder: PropTypes.oneOfType([PropTypes.node, PropTypes.string])
|
|
304
|
-
};
|
|
305
|
-
var defaultProps = {
|
|
306
|
-
item: null,
|
|
307
|
-
value: null,
|
|
308
|
-
label: null,
|
|
309
|
-
labelPath: null,
|
|
310
|
-
external: false,
|
|
311
|
-
target: null,
|
|
312
|
-
placeholder: null
|
|
313
|
-
};
|
|
314
|
-
var Link = function Link(_ref) {
|
|
315
|
-
var item = _ref.item,
|
|
316
|
-
label = _ref.label,
|
|
317
|
-
labelPath = _ref.labelPath,
|
|
318
|
-
value = _ref.value,
|
|
319
|
-
external = _ref.external,
|
|
320
|
-
target = _ref.target,
|
|
321
|
-
placeholder = _ref.placeholder;
|
|
322
|
-
var itemLabel = get(item, labelPath);
|
|
323
|
-
var finalValue = itemLabel || label || placeholder || /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
|
|
324
|
-
id: "e0xuLo",
|
|
325
|
-
defaultMessage: [{
|
|
326
|
-
"type": 0,
|
|
327
|
-
"value": "Link"
|
|
328
|
-
}]
|
|
329
|
-
});
|
|
330
|
-
var isExternal = value !== null && isString(value) ? value.indexOf('http') === 0 : false;
|
|
331
|
-
return external || isExternal ? /*#__PURE__*/React.createElement("a", {
|
|
332
|
-
href: value,
|
|
333
|
-
target: target || '_blank',
|
|
334
|
-
rel: "noopener noreferrer"
|
|
335
|
-
}, finalValue) : /*#__PURE__*/React.createElement(Link$2, {
|
|
336
|
-
href: value
|
|
337
|
-
}, finalValue);
|
|
338
|
-
};
|
|
339
|
-
Link.propTypes = propTypes;
|
|
340
|
-
Link.defaultProps = defaultProps;
|
|
341
|
-
var Link$1 = Link;
|
|
342
|
-
|
|
343
|
-
exports.default = Link$1;
|