@moda/om 20.2.0 → 21.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,310 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { useState, createContext, PureComponent, useRef, useEffect, Children, isValidElement, cloneElement, useContext, useCallback, forwardRef, useMemo, useReducer } from 'react';
3
- import { Link, Prompt } from 'react-router-dom';
3
+ import Link from 'next/link';
4
4
  import require$$1, { createPortal } from 'react-dom';
5
5
 
6
6
  function getDefaultExportFromCjs (x) {
7
7
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
8
8
  }
9
9
 
10
- var focusVisible$1 = {exports: {}};
11
-
12
- var focusVisible = focusVisible$1.exports;
13
- var hasRequiredFocusVisible;
14
- function requireFocusVisible() {
15
- if (hasRequiredFocusVisible) return focusVisible$1.exports;
16
- hasRequiredFocusVisible = 1;
17
- (function (module, exports) {
18
- (function (global, factory) {
19
- factory() ;
20
- })(focusVisible, function () {
21
-
22
- /**
23
- * Applies the :focus-visible polyfill at the given scope.
24
- * A scope in this case is either the top-level Document or a Shadow Root.
25
- *
26
- * @param {(Document|ShadowRoot)} scope
27
- * @see https://github.com/WICG/focus-visible
28
- */
29
- function applyFocusVisiblePolyfill(scope) {
30
- var hadKeyboardEvent = true;
31
- var hadFocusVisibleRecently = false;
32
- var hadFocusVisibleRecentlyTimeout = null;
33
- var inputTypesAllowlist = {
34
- text: true,
35
- search: true,
36
- url: true,
37
- tel: true,
38
- email: true,
39
- password: true,
40
- number: true,
41
- date: true,
42
- month: true,
43
- week: true,
44
- time: true,
45
- datetime: true,
46
- 'datetime-local': true
47
- };
48
-
49
- /**
50
- * Helper function for legacy browsers and iframes which sometimes focus
51
- * elements like document, body, and non-interactive SVG.
52
- * @param {Element} el
53
- */
54
- function isValidFocusTarget(el) {
55
- if (el && el !== document && el.nodeName !== 'HTML' && el.nodeName !== 'BODY' && 'classList' in el && 'contains' in el.classList) {
56
- return true;
57
- }
58
- return false;
59
- }
60
-
61
- /**
62
- * Computes whether the given element should automatically trigger the
63
- * `focus-visible` class being added, i.e. whether it should always match
64
- * `:focus-visible` when focused.
65
- * @param {Element} el
66
- * @return {boolean}
67
- */
68
- function focusTriggersKeyboardModality(el) {
69
- var type = el.type;
70
- var tagName = el.tagName;
71
- if (tagName === 'INPUT' && inputTypesAllowlist[type] && !el.readOnly) {
72
- return true;
73
- }
74
- if (tagName === 'TEXTAREA' && !el.readOnly) {
75
- return true;
76
- }
77
- if (el.isContentEditable) {
78
- return true;
79
- }
80
- return false;
81
- }
82
-
83
- /**
84
- * Add the `focus-visible` class to the given element if it was not added by
85
- * the author.
86
- * @param {Element} el
87
- */
88
- function addFocusVisibleClass(el) {
89
- if (el.classList.contains('focus-visible')) {
90
- return;
91
- }
92
- el.classList.add('focus-visible');
93
- el.setAttribute('data-focus-visible-added', '');
94
- }
95
-
96
- /**
97
- * Remove the `focus-visible` class from the given element if it was not
98
- * originally added by the author.
99
- * @param {Element} el
100
- */
101
- function removeFocusVisibleClass(el) {
102
- if (!el.hasAttribute('data-focus-visible-added')) {
103
- return;
104
- }
105
- el.classList.remove('focus-visible');
106
- el.removeAttribute('data-focus-visible-added');
107
- }
108
-
109
- /**
110
- * If the most recent user interaction was via the keyboard;
111
- * and the key press did not include a meta, alt/option, or control key;
112
- * then the modality is keyboard. Otherwise, the modality is not keyboard.
113
- * Apply `focus-visible` to any current active element and keep track
114
- * of our keyboard modality state with `hadKeyboardEvent`.
115
- * @param {KeyboardEvent} e
116
- */
117
- function onKeyDown(e) {
118
- if (e.metaKey || e.altKey || e.ctrlKey) {
119
- return;
120
- }
121
- if (isValidFocusTarget(scope.activeElement)) {
122
- addFocusVisibleClass(scope.activeElement);
123
- }
124
- hadKeyboardEvent = true;
125
- }
126
-
127
- /**
128
- * If at any point a user clicks with a pointing device, ensure that we change
129
- * the modality away from keyboard.
130
- * This avoids the situation where a user presses a key on an already focused
131
- * element, and then clicks on a different element, focusing it with a
132
- * pointing device, while we still think we're in keyboard modality.
133
- * @param {Event} e
134
- */
135
- function onPointerDown(e) {
136
- hadKeyboardEvent = false;
137
- }
138
-
139
- /**
140
- * On `focus`, add the `focus-visible` class to the target if:
141
- * - the target received focus as a result of keyboard navigation, or
142
- * - the event target is an element that will likely require interaction
143
- * via the keyboard (e.g. a text box)
144
- * @param {Event} e
145
- */
146
- function onFocus(e) {
147
- // Prevent IE from focusing the document or HTML element.
148
- if (!isValidFocusTarget(e.target)) {
149
- return;
150
- }
151
- if (hadKeyboardEvent || focusTriggersKeyboardModality(e.target)) {
152
- addFocusVisibleClass(e.target);
153
- }
154
- }
155
-
156
- /**
157
- * On `blur`, remove the `focus-visible` class from the target.
158
- * @param {Event} e
159
- */
160
- function onBlur(e) {
161
- if (!isValidFocusTarget(e.target)) {
162
- return;
163
- }
164
- if (e.target.classList.contains('focus-visible') || e.target.hasAttribute('data-focus-visible-added')) {
165
- // To detect a tab/window switch, we look for a blur event followed
166
- // rapidly by a visibility change.
167
- // If we don't see a visibility change within 100ms, it's probably a
168
- // regular focus change.
169
- hadFocusVisibleRecently = true;
170
- window.clearTimeout(hadFocusVisibleRecentlyTimeout);
171
- hadFocusVisibleRecentlyTimeout = window.setTimeout(function () {
172
- hadFocusVisibleRecently = false;
173
- }, 100);
174
- removeFocusVisibleClass(e.target);
175
- }
176
- }
177
-
178
- /**
179
- * If the user changes tabs, keep track of whether or not the previously
180
- * focused element had .focus-visible.
181
- * @param {Event} e
182
- */
183
- function onVisibilityChange(e) {
184
- if (document.visibilityState === 'hidden') {
185
- // If the tab becomes active again, the browser will handle calling focus
186
- // on the element (Safari actually calls it twice).
187
- // If this tab change caused a blur on an element with focus-visible,
188
- // re-apply the class when the user switches back to the tab.
189
- if (hadFocusVisibleRecently) {
190
- hadKeyboardEvent = true;
191
- }
192
- addInitialPointerMoveListeners();
193
- }
194
- }
195
-
196
- /**
197
- * Add a group of listeners to detect usage of any pointing devices.
198
- * These listeners will be added when the polyfill first loads, and anytime
199
- * the window is blurred, so that they are active when the window regains
200
- * focus.
201
- */
202
- function addInitialPointerMoveListeners() {
203
- document.addEventListener('mousemove', onInitialPointerMove);
204
- document.addEventListener('mousedown', onInitialPointerMove);
205
- document.addEventListener('mouseup', onInitialPointerMove);
206
- document.addEventListener('pointermove', onInitialPointerMove);
207
- document.addEventListener('pointerdown', onInitialPointerMove);
208
- document.addEventListener('pointerup', onInitialPointerMove);
209
- document.addEventListener('touchmove', onInitialPointerMove);
210
- document.addEventListener('touchstart', onInitialPointerMove);
211
- document.addEventListener('touchend', onInitialPointerMove);
212
- }
213
- function removeInitialPointerMoveListeners() {
214
- document.removeEventListener('mousemove', onInitialPointerMove);
215
- document.removeEventListener('mousedown', onInitialPointerMove);
216
- document.removeEventListener('mouseup', onInitialPointerMove);
217
- document.removeEventListener('pointermove', onInitialPointerMove);
218
- document.removeEventListener('pointerdown', onInitialPointerMove);
219
- document.removeEventListener('pointerup', onInitialPointerMove);
220
- document.removeEventListener('touchmove', onInitialPointerMove);
221
- document.removeEventListener('touchstart', onInitialPointerMove);
222
- document.removeEventListener('touchend', onInitialPointerMove);
223
- }
224
-
225
- /**
226
- * When the polfyill first loads, assume the user is in keyboard modality.
227
- * If any event is received from a pointing device (e.g. mouse, pointer,
228
- * touch), turn off keyboard modality.
229
- * This accounts for situations where focus enters the page from the URL bar.
230
- * @param {Event} e
231
- */
232
- function onInitialPointerMove(e) {
233
- // Work around a Safari quirk that fires a mousemove on <html> whenever the
234
- // window blurs, even if you're tabbing out of the page. ¯\_(ツ)_/¯
235
- if (e.target.nodeName && e.target.nodeName.toLowerCase() === 'html') {
236
- return;
237
- }
238
- hadKeyboardEvent = false;
239
- removeInitialPointerMoveListeners();
240
- }
241
-
242
- // For some kinds of state, we are interested in changes at the global scope
243
- // only. For example, global pointer input, global key presses and global
244
- // visibility change should affect the state at every scope:
245
- document.addEventListener('keydown', onKeyDown, true);
246
- document.addEventListener('mousedown', onPointerDown, true);
247
- document.addEventListener('pointerdown', onPointerDown, true);
248
- document.addEventListener('touchstart', onPointerDown, true);
249
- document.addEventListener('visibilitychange', onVisibilityChange, true);
250
- addInitialPointerMoveListeners();
251
-
252
- // For focus and blur, we specifically care about state changes in the local
253
- // scope. This is because focus / blur events that originate from within a
254
- // shadow root are not re-dispatched from the host element if it was already
255
- // the active element in its own scope:
256
- scope.addEventListener('focus', onFocus, true);
257
- scope.addEventListener('blur', onBlur, true);
258
-
259
- // We detect that a node is a ShadowRoot by ensuring that it is a
260
- // DocumentFragment and also has a host property. This check covers native
261
- // implementation and polyfill implementation transparently. If we only cared
262
- // about the native implementation, we could just check if the scope was
263
- // an instance of a ShadowRoot.
264
- if (scope.nodeType === Node.DOCUMENT_FRAGMENT_NODE && scope.host) {
265
- // Since a ShadowRoot is a special kind of DocumentFragment, it does not
266
- // have a root element to add a class to. So, we add this attribute to the
267
- // host element instead:
268
- scope.host.setAttribute('data-js-focus-visible', '');
269
- } else if (scope.nodeType === Node.DOCUMENT_NODE) {
270
- document.documentElement.classList.add('js-focus-visible');
271
- document.documentElement.setAttribute('data-js-focus-visible', '');
272
- }
273
- }
274
-
275
- // It is important to wrap all references to global window and document in
276
- // these checks to support server-side rendering use cases
277
- // @see https://github.com/WICG/focus-visible/issues/199
278
- if (typeof window !== 'undefined' && typeof document !== 'undefined') {
279
- // Make the polyfill helper globally available. This can be used as a signal
280
- // to interested libraries that wish to coordinate with the polyfill for e.g.,
281
- // applying the polyfill to a shadow root:
282
- window.applyFocusVisiblePolyfill = applyFocusVisiblePolyfill;
283
-
284
- // Notify interested libraries of the polyfill's presence, in case the
285
- // polyfill was loaded lazily:
286
- var event;
287
- try {
288
- event = new CustomEvent('focus-visible-polyfill-ready');
289
- } catch (error) {
290
- // IE11 does not support using CustomEvent as a constructor directly:
291
- event = document.createEvent('CustomEvent');
292
- event.initCustomEvent('focus-visible-polyfill-ready', false, false, {});
293
- }
294
- window.dispatchEvent(event);
295
- }
296
- if (typeof document !== 'undefined') {
297
- // Apply the polyfill to the global document, so that no JavaScript
298
- // coordination is required to use the polyfill in the top-level document:
299
- applyFocusVisiblePolyfill(document);
300
- }
301
- });
302
- })();
303
- return focusVisible$1.exports;
304
- }
305
-
306
- requireFocusVisible();
307
-
308
10
  var dist$4 = {};
309
11
 
310
12
  var colors = {};
@@ -5539,6 +5241,7 @@ var Clickable = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
5539
5241
  disabled: disabled
5540
5242
  });
5541
5243
  if (isLink(props)) return /*#__PURE__*/React__default.createElement(Link, _extends$1({}, props, {
5244
+ href: props.to,
5542
5245
  ref: ref
5543
5246
  }));
5544
5247
  if (isAnchor(props)) return /*#__PURE__*/React__default.createElement("a", _extends$1({}, props, {
@@ -12053,14 +11756,11 @@ var usePreventNavigation = function usePreventNavigation() {
12053
11756
 
12054
11757
  var NavigationPreventer = function NavigationPreventer(_ref) {
12055
11758
  var _ref$enabled = _ref.enabled,
12056
- enabled = _ref$enabled === void 0 ? false : _ref$enabled,
12057
- _ref$message = _ref.message,
12058
- message = _ref$message === void 0 ? 'Changes that you made may not be saved.' : _ref$message;
11759
+ enabled = _ref$enabled === void 0 ? false : _ref$enabled;
12059
11760
  usePreventNavigation(enabled);
12060
- return /*#__PURE__*/React__default.createElement(Prompt, {
12061
- when: enabled,
12062
- message: message
12063
- });
11761
+
11762
+ // TODO: implement this with next.js https://github.com/vercel/next.js/discussions/32231
11763
+ return null;
12064
11764
  };
12065
11765
 
12066
11766
  var __assign$1 = undefined && undefined.__assign || function () {