@teamturing/react-kit 2.12.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/core/Overlay/index.d.ts +18 -0
  2. package/dist/core/OverlayPopper/index.d.ts +16 -0
  3. package/dist/core/Pagination/index.d.ts +327 -0
  4. package/dist/core/Pill/index.d.ts +47 -0
  5. package/dist/hook/useFocusTrap.d.ts +13 -0
  6. package/dist/hook/useFocusZone.d.ts +15 -0
  7. package/dist/index.d.ts +12 -0
  8. package/dist/index.js +3323 -581
  9. package/esm/core/Dialog/index.js +8 -36
  10. package/esm/core/Overlay/index.js +92 -0
  11. package/esm/core/OverlayPopper/index.js +69 -0
  12. package/esm/core/Pagination/index.js +273 -0
  13. package/esm/core/Pill/index.js +129 -0
  14. package/esm/hook/useFocusTrap.js +39 -0
  15. package/esm/hook/useFocusZone.js +35 -0
  16. package/esm/index.js +8 -0
  17. package/esm/node_modules/@floating-ui/core/dist/floating-ui.core.js +475 -0
  18. package/esm/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +599 -0
  19. package/esm/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +229 -0
  20. package/esm/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +121 -0
  21. package/esm/node_modules/@floating-ui/utils/dom/dist/floating-ui.utils.dom.js +128 -0
  22. package/esm/node_modules/@primer/behaviors/dist/esm/focus-trap.js +105 -0
  23. package/esm/node_modules/@primer/behaviors/dist/esm/focus-zone.js +436 -0
  24. package/esm/node_modules/@primer/behaviors/dist/esm/polyfills/event-listener-signal.js +38 -0
  25. package/esm/node_modules/@primer/behaviors/dist/esm/utils/iterate-focusable-elements.js +65 -0
  26. package/esm/node_modules/@primer/behaviors/dist/esm/utils/unique-id.js +6 -0
  27. package/esm/node_modules/@primer/behaviors/dist/esm/utils/user-agent.js +9 -0
  28. package/esm/packages/utils/esm/noop.js +6 -0
  29. package/package.json +5 -2
@@ -0,0 +1,436 @@
1
+ import { polyfill } from './polyfills/event-listener-signal.js';
2
+ import { isMacOS } from './utils/user-agent.js';
3
+ import { iterateFocusableElements } from './utils/iterate-focusable-elements.js';
4
+ import { uniqueId } from './utils/unique-id.js';
5
+
6
+ polyfill();
7
+ var FocusKeys;
8
+ (function (FocusKeys) {
9
+ FocusKeys[FocusKeys["ArrowHorizontal"] = 1] = "ArrowHorizontal";
10
+ FocusKeys[FocusKeys["ArrowVertical"] = 2] = "ArrowVertical";
11
+ FocusKeys[FocusKeys["JK"] = 4] = "JK";
12
+ FocusKeys[FocusKeys["HL"] = 8] = "HL";
13
+ FocusKeys[FocusKeys["HomeAndEnd"] = 16] = "HomeAndEnd";
14
+ FocusKeys[FocusKeys["PageUpDown"] = 256] = "PageUpDown";
15
+ FocusKeys[FocusKeys["WS"] = 32] = "WS";
16
+ FocusKeys[FocusKeys["AD"] = 64] = "AD";
17
+ FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
18
+ FocusKeys[FocusKeys["Backspace"] = 512] = "Backspace";
19
+ FocusKeys[FocusKeys["ArrowAll"] = 3] = "ArrowAll";
20
+ FocusKeys[FocusKeys["HJKL"] = 12] = "HJKL";
21
+ FocusKeys[FocusKeys["WASD"] = 96] = "WASD";
22
+ FocusKeys[FocusKeys["All"] = 511] = "All";
23
+ })(FocusKeys || (FocusKeys = {}));
24
+ const KEY_TO_BIT = {
25
+ ArrowLeft: FocusKeys.ArrowHorizontal,
26
+ ArrowDown: FocusKeys.ArrowVertical,
27
+ ArrowUp: FocusKeys.ArrowVertical,
28
+ ArrowRight: FocusKeys.ArrowHorizontal,
29
+ h: FocusKeys.HL,
30
+ j: FocusKeys.JK,
31
+ k: FocusKeys.JK,
32
+ l: FocusKeys.HL,
33
+ a: FocusKeys.AD,
34
+ s: FocusKeys.WS,
35
+ w: FocusKeys.WS,
36
+ d: FocusKeys.AD,
37
+ Tab: FocusKeys.Tab,
38
+ Home: FocusKeys.HomeAndEnd,
39
+ End: FocusKeys.HomeAndEnd,
40
+ PageUp: FocusKeys.PageUpDown,
41
+ PageDown: FocusKeys.PageUpDown,
42
+ Backspace: FocusKeys.Backspace
43
+ };
44
+ const KEY_TO_DIRECTION = {
45
+ ArrowLeft: 'previous',
46
+ ArrowDown: 'next',
47
+ ArrowUp: 'previous',
48
+ ArrowRight: 'next',
49
+ h: 'previous',
50
+ j: 'next',
51
+ k: 'previous',
52
+ l: 'next',
53
+ a: 'previous',
54
+ s: 'next',
55
+ w: 'previous',
56
+ d: 'next',
57
+ Tab: 'next',
58
+ Home: 'start',
59
+ End: 'end',
60
+ PageUp: 'start',
61
+ PageDown: 'end',
62
+ Backspace: 'previous'
63
+ };
64
+ function getDirection(keyboardEvent) {
65
+ const direction = KEY_TO_DIRECTION[keyboardEvent.key];
66
+ if (keyboardEvent.key === 'Tab' && keyboardEvent.shiftKey) {
67
+ return 'previous';
68
+ }
69
+ const isMac = isMacOS();
70
+ if (isMac && keyboardEvent.metaKey || !isMac && keyboardEvent.ctrlKey) {
71
+ if (keyboardEvent.key === 'ArrowLeft' || keyboardEvent.key === 'ArrowUp') {
72
+ return 'start';
73
+ } else if (keyboardEvent.key === 'ArrowRight' || keyboardEvent.key === 'ArrowDown') {
74
+ return 'end';
75
+ }
76
+ }
77
+ return direction;
78
+ }
79
+ function shouldIgnoreFocusHandling(keyboardEvent, activeElement) {
80
+ const key = keyboardEvent.key;
81
+ const keyLength = [...key].length;
82
+ const isTextInput = activeElement instanceof HTMLInputElement && activeElement.type === 'text' || activeElement instanceof HTMLTextAreaElement;
83
+ if (isTextInput && (keyLength === 1 || key === 'Home' || key === 'End')) {
84
+ return true;
85
+ }
86
+ if (activeElement instanceof HTMLSelectElement) {
87
+ if (keyLength === 1) {
88
+ return true;
89
+ }
90
+ if (key === 'ArrowDown' && isMacOS() && !keyboardEvent.metaKey) {
91
+ return true;
92
+ }
93
+ if (key === 'ArrowDown' && !isMacOS() && keyboardEvent.altKey) {
94
+ return true;
95
+ }
96
+ }
97
+ if (activeElement instanceof HTMLTextAreaElement && (key === 'PageUp' || key === 'PageDown')) {
98
+ return true;
99
+ }
100
+ if (isTextInput) {
101
+ const textInput = activeElement;
102
+ const cursorAtStart = textInput.selectionStart === 0 && textInput.selectionEnd === 0;
103
+ const cursorAtEnd = textInput.selectionStart === textInput.value.length && textInput.selectionEnd === textInput.value.length;
104
+ if (key === 'ArrowLeft' && !cursorAtStart) {
105
+ return true;
106
+ }
107
+ if (key === 'ArrowRight' && !cursorAtEnd) {
108
+ return true;
109
+ }
110
+ if (textInput instanceof HTMLTextAreaElement) {
111
+ if (key === 'ArrowUp' && !cursorAtStart) {
112
+ return true;
113
+ }
114
+ if (key === 'ArrowDown' && !cursorAtEnd) {
115
+ return true;
116
+ }
117
+ }
118
+ }
119
+ return false;
120
+ }
121
+ const isActiveDescendantAttribute = 'data-is-active-descendant';
122
+ const activeDescendantActivatedDirectly = 'activated-directly';
123
+ const activeDescendantActivatedIndirectly = 'activated-indirectly';
124
+ const hasActiveDescendantAttribute = 'data-has-active-descendant';
125
+ function focusZone(container, settings) {
126
+ var _a, _b, _c, _d, _e;
127
+ const focusableElements = [];
128
+ const savedTabIndex = new WeakMap();
129
+ const bindKeys = (_a = settings === null || settings === void 0 ? void 0 : settings.bindKeys) !== null && _a !== void 0 ? _a : ((settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
130
+ const focusOutBehavior = (_b = settings === null || settings === void 0 ? void 0 : settings.focusOutBehavior) !== null && _b !== void 0 ? _b : 'stop';
131
+ const focusInStrategy = (_c = settings === null || settings === void 0 ? void 0 : settings.focusInStrategy) !== null && _c !== void 0 ? _c : 'previous';
132
+ const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
133
+ const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
134
+ let currentFocusedElement;
135
+ const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
136
+ function getFirstFocusableElement() {
137
+ return focusableElements[0];
138
+ }
139
+ function isActiveDescendantInputFocused() {
140
+ return document.activeElement === activeDescendantControl;
141
+ }
142
+ function updateFocusedElement(to, directlyActivated = false) {
143
+ const from = currentFocusedElement;
144
+ currentFocusedElement = to;
145
+ if (activeDescendantControl) {
146
+ if (to && isActiveDescendantInputFocused()) {
147
+ setActiveDescendant(from, to, directlyActivated);
148
+ } else {
149
+ clearActiveDescendant();
150
+ }
151
+ return;
152
+ }
153
+ if (from && from !== to && savedTabIndex.has(from)) {
154
+ from.setAttribute('tabindex', '-1');
155
+ }
156
+ to === null || to === void 0 ? void 0 : to.setAttribute('tabindex', '0');
157
+ }
158
+ function setActiveDescendant(from, to, directlyActivated = false) {
159
+ if (!to.id) {
160
+ to.setAttribute('id', uniqueId());
161
+ }
162
+ if (from && from !== to) {
163
+ from.removeAttribute(isActiveDescendantAttribute);
164
+ }
165
+ if (!activeDescendantControl || !directlyActivated && activeDescendantControl.getAttribute('aria-activedescendant') === to.id) {
166
+ return;
167
+ }
168
+ activeDescendantControl.setAttribute('aria-activedescendant', to.id);
169
+ container.setAttribute(hasActiveDescendantAttribute, to.id);
170
+ to.setAttribute(isActiveDescendantAttribute, directlyActivated ? activeDescendantActivatedDirectly : activeDescendantActivatedIndirectly);
171
+ activeDescendantCallback === null || activeDescendantCallback === void 0 ? void 0 : activeDescendantCallback(to, from, directlyActivated);
172
+ }
173
+ function clearActiveDescendant(previouslyActiveElement = currentFocusedElement) {
174
+ if (focusInStrategy === 'first') {
175
+ currentFocusedElement = undefined;
176
+ }
177
+ activeDescendantControl === null || activeDescendantControl === void 0 ? void 0 : activeDescendantControl.removeAttribute('aria-activedescendant');
178
+ container.removeAttribute(hasActiveDescendantAttribute);
179
+ previouslyActiveElement === null || previouslyActiveElement === void 0 ? void 0 : previouslyActiveElement.removeAttribute(isActiveDescendantAttribute);
180
+ activeDescendantCallback === null || activeDescendantCallback === void 0 ? void 0 : activeDescendantCallback(undefined, previouslyActiveElement, false);
181
+ }
182
+ function beginFocusManagement(...elements) {
183
+ const filteredElements = elements.filter(e => {
184
+ var _a, _b;
185
+ return (_b = (_a = settings === null || settings === void 0 ? void 0 : settings.focusableElementFilter) === null || _a === void 0 ? void 0 : _a.call(settings, e)) !== null && _b !== void 0 ? _b : true;
186
+ });
187
+ if (filteredElements.length === 0) {
188
+ return;
189
+ }
190
+ focusableElements.splice(findInsertionIndex(filteredElements), 0, ...filteredElements);
191
+ for (const element of filteredElements) {
192
+ if (!savedTabIndex.has(element)) {
193
+ savedTabIndex.set(element, element.getAttribute('tabindex'));
194
+ }
195
+ element.setAttribute('tabindex', '-1');
196
+ }
197
+ if (!currentFocusedElement) {
198
+ updateFocusedElement(getFirstFocusableElement());
199
+ }
200
+ }
201
+ function findInsertionIndex(elementsToInsert) {
202
+ const firstElementToInsert = elementsToInsert[0];
203
+ if (focusableElements.length === 0) return 0;
204
+ let iMin = 0;
205
+ let iMax = focusableElements.length - 1;
206
+ while (iMin <= iMax) {
207
+ const i = Math.floor((iMin + iMax) / 2);
208
+ const element = focusableElements[i];
209
+ if (followsInDocument(firstElementToInsert, element)) {
210
+ iMax = i - 1;
211
+ } else {
212
+ iMin = i + 1;
213
+ }
214
+ }
215
+ return iMin;
216
+ }
217
+ function followsInDocument(first, second) {
218
+ return (second.compareDocumentPosition(first) & Node.DOCUMENT_POSITION_PRECEDING) > 0;
219
+ }
220
+ function endFocusManagement(...elements) {
221
+ for (const element of elements) {
222
+ const focusableElementIndex = focusableElements.indexOf(element);
223
+ if (focusableElementIndex >= 0) {
224
+ focusableElements.splice(focusableElementIndex, 1);
225
+ }
226
+ const savedIndex = savedTabIndex.get(element);
227
+ if (savedIndex !== undefined) {
228
+ if (savedIndex === null) {
229
+ element.removeAttribute('tabindex');
230
+ } else {
231
+ element.setAttribute('tabindex', savedIndex);
232
+ }
233
+ savedTabIndex.delete(element);
234
+ }
235
+ if (element === currentFocusedElement) {
236
+ const nextElementToFocus = getFirstFocusableElement();
237
+ updateFocusedElement(nextElementToFocus);
238
+ }
239
+ }
240
+ }
241
+ beginFocusManagement(...iterateFocusableElements(container));
242
+ const initialElement = typeof focusInStrategy === 'function' ? focusInStrategy(document.body) : getFirstFocusableElement();
243
+ updateFocusedElement(initialElement);
244
+ const observer = new MutationObserver(mutations => {
245
+ for (const mutation of mutations) {
246
+ for (const removedNode of mutation.removedNodes) {
247
+ if (removedNode instanceof HTMLElement) {
248
+ endFocusManagement(...iterateFocusableElements(removedNode));
249
+ }
250
+ }
251
+ }
252
+ for (const mutation of mutations) {
253
+ for (const addedNode of mutation.addedNodes) {
254
+ if (addedNode instanceof HTMLElement) {
255
+ beginFocusManagement(...iterateFocusableElements(addedNode));
256
+ }
257
+ }
258
+ }
259
+ });
260
+ observer.observe(container, {
261
+ subtree: true,
262
+ childList: true
263
+ });
264
+ const controller = new AbortController();
265
+ const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
266
+ signal.addEventListener('abort', () => {
267
+ endFocusManagement(...focusableElements);
268
+ });
269
+ let elementIndexFocusedByClick = undefined;
270
+ container.addEventListener('mousedown', event => {
271
+ if (event.target instanceof HTMLElement && event.target !== document.activeElement) {
272
+ elementIndexFocusedByClick = focusableElements.indexOf(event.target);
273
+ }
274
+ }, {
275
+ signal
276
+ });
277
+ if (activeDescendantControl) {
278
+ container.addEventListener('focusin', event => {
279
+ if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
280
+ activeDescendantControl.focus({
281
+ preventScroll
282
+ });
283
+ updateFocusedElement(event.target);
284
+ }
285
+ });
286
+ container.addEventListener('mousemove', ({
287
+ target
288
+ }) => {
289
+ if (!(target instanceof Node)) {
290
+ return;
291
+ }
292
+ const focusableElement = focusableElements.find(element => element.contains(target));
293
+ if (focusableElement) {
294
+ updateFocusedElement(focusableElement);
295
+ }
296
+ }, {
297
+ signal,
298
+ capture: true
299
+ });
300
+ activeDescendantControl.addEventListener('focusin', () => {
301
+ if (!currentFocusedElement) {
302
+ updateFocusedElement(getFirstFocusableElement());
303
+ } else {
304
+ setActiveDescendant(undefined, currentFocusedElement);
305
+ }
306
+ });
307
+ activeDescendantControl.addEventListener('focusout', () => {
308
+ clearActiveDescendant();
309
+ });
310
+ } else {
311
+ container.addEventListener('focusin', event => {
312
+ if (event.target instanceof HTMLElement) {
313
+ if (elementIndexFocusedByClick !== undefined) {
314
+ if (elementIndexFocusedByClick >= 0) {
315
+ if (focusableElements[elementIndexFocusedByClick] !== currentFocusedElement) {
316
+ updateFocusedElement(focusableElements[elementIndexFocusedByClick]);
317
+ }
318
+ }
319
+ elementIndexFocusedByClick = undefined;
320
+ } else {
321
+ if (focusInStrategy === 'previous') {
322
+ updateFocusedElement(event.target);
323
+ } else if (focusInStrategy === 'closest' || focusInStrategy === 'first') {
324
+ if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
325
+ const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
326
+ const targetElement = focusableElements[targetElementIndex];
327
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus({
328
+ preventScroll
329
+ });
330
+ return;
331
+ } else {
332
+ updateFocusedElement(event.target);
333
+ }
334
+ } else if (typeof focusInStrategy === 'function') {
335
+ if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
336
+ const elementToFocus = focusInStrategy(event.relatedTarget);
337
+ const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
338
+ if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
339
+ elementToFocus.focus({
340
+ preventScroll
341
+ });
342
+ return;
343
+ } else {
344
+ console.warn('Element requested is not a known focusable element.');
345
+ }
346
+ } else {
347
+ updateFocusedElement(event.target);
348
+ }
349
+ }
350
+ }
351
+ }
352
+ lastKeyboardFocusDirection = undefined;
353
+ }, {
354
+ signal
355
+ });
356
+ }
357
+ const keyboardEventRecipient = activeDescendantControl !== null && activeDescendantControl !== void 0 ? activeDescendantControl : container;
358
+ let lastKeyboardFocusDirection = undefined;
359
+ if (focusInStrategy === 'closest') {
360
+ document.addEventListener('keydown', event => {
361
+ if (event.key === 'Tab') {
362
+ lastKeyboardFocusDirection = getDirection(event);
363
+ }
364
+ }, {
365
+ signal,
366
+ capture: true
367
+ });
368
+ }
369
+ function getCurrentFocusedIndex() {
370
+ if (!currentFocusedElement) {
371
+ return 0;
372
+ }
373
+ const focusedIndex = focusableElements.indexOf(currentFocusedElement);
374
+ const fallbackIndex = currentFocusedElement === container ? -1 : 0;
375
+ return focusedIndex !== -1 ? focusedIndex : fallbackIndex;
376
+ }
377
+ keyboardEventRecipient.addEventListener('keydown', event => {
378
+ var _a;
379
+ if (event.key in KEY_TO_DIRECTION) {
380
+ const keyBit = KEY_TO_BIT[event.key];
381
+ if (!event.defaultPrevented && (keyBit & bindKeys) > 0 && !shouldIgnoreFocusHandling(event, document.activeElement)) {
382
+ const direction = getDirection(event);
383
+ let nextElementToFocus = undefined;
384
+ if (settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) {
385
+ nextElementToFocus = settings.getNextFocusable(direction, (_a = document.activeElement) !== null && _a !== void 0 ? _a : undefined, event);
386
+ }
387
+ if (!nextElementToFocus) {
388
+ const lastFocusedIndex = getCurrentFocusedIndex();
389
+ let nextFocusedIndex = lastFocusedIndex;
390
+ if (direction === 'previous') {
391
+ nextFocusedIndex -= 1;
392
+ } else if (direction === 'start') {
393
+ nextFocusedIndex = 0;
394
+ } else if (direction === 'next') {
395
+ nextFocusedIndex += 1;
396
+ } else {
397
+ nextFocusedIndex = focusableElements.length - 1;
398
+ }
399
+ if (nextFocusedIndex < 0) {
400
+ if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
401
+ nextFocusedIndex = focusableElements.length - 1;
402
+ } else {
403
+ nextFocusedIndex = 0;
404
+ }
405
+ }
406
+ if (nextFocusedIndex >= focusableElements.length) {
407
+ if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
408
+ nextFocusedIndex = 0;
409
+ } else {
410
+ nextFocusedIndex = focusableElements.length - 1;
411
+ }
412
+ }
413
+ if (lastFocusedIndex !== nextFocusedIndex) {
414
+ nextElementToFocus = focusableElements[nextFocusedIndex];
415
+ }
416
+ }
417
+ if (activeDescendantControl) {
418
+ updateFocusedElement(nextElementToFocus || currentFocusedElement, true);
419
+ } else if (nextElementToFocus) {
420
+ lastKeyboardFocusDirection = direction;
421
+ nextElementToFocus.focus({
422
+ preventScroll
423
+ });
424
+ }
425
+ if (event.key !== 'Tab' || nextElementToFocus) {
426
+ event.preventDefault();
427
+ }
428
+ }
429
+ }
430
+ }, {
431
+ signal
432
+ });
433
+ return controller;
434
+ }
435
+
436
+ export { FocusKeys, activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, focusZone, hasActiveDescendantAttribute, isActiveDescendantAttribute };
@@ -0,0 +1,38 @@
1
+ let signalSupported = false;
2
+ function noop() {}
3
+ try {
4
+ const options = Object.create({}, {
5
+ signal: {
6
+ get() {
7
+ signalSupported = true;
8
+ }
9
+ }
10
+ });
11
+ window.addEventListener('test', noop, options);
12
+ window.removeEventListener('test', noop, options);
13
+ } catch (e) {}
14
+ function featureSupported() {
15
+ return signalSupported;
16
+ }
17
+ function monkeyPatch() {
18
+ if (typeof window === 'undefined') {
19
+ return;
20
+ }
21
+ const originalAddEventListener = EventTarget.prototype.addEventListener;
22
+ EventTarget.prototype.addEventListener = function (name, originalCallback, optionsOrCapture) {
23
+ if (typeof optionsOrCapture === 'object' && 'signal' in optionsOrCapture && optionsOrCapture.signal instanceof AbortSignal) {
24
+ originalAddEventListener.call(optionsOrCapture.signal, 'abort', () => {
25
+ this.removeEventListener(name, originalCallback, optionsOrCapture);
26
+ });
27
+ }
28
+ return originalAddEventListener.call(this, name, originalCallback, optionsOrCapture);
29
+ };
30
+ }
31
+ function polyfill() {
32
+ if (!featureSupported()) {
33
+ monkeyPatch();
34
+ signalSupported = true;
35
+ }
36
+ }
37
+
38
+ export { polyfill };
@@ -0,0 +1,65 @@
1
+ function* iterateFocusableElements(container, options = {}) {
2
+ var _a, _b;
3
+ const strict = (_a = options.strict) !== null && _a !== void 0 ? _a : false;
4
+ const acceptFn = ((_b = options.onlyTabbable) !== null && _b !== void 0 ? _b : false) ? isTabbable : isFocusable;
5
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
6
+ acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
7
+ });
8
+ let nextNode = null;
9
+ if (!options.reverse && acceptFn(container, strict)) {
10
+ yield container;
11
+ }
12
+ if (options.reverse) {
13
+ let lastChild = walker.lastChild();
14
+ while (lastChild) {
15
+ nextNode = lastChild;
16
+ lastChild = walker.lastChild();
17
+ }
18
+ } else {
19
+ nextNode = walker.firstChild();
20
+ }
21
+ while (nextNode instanceof HTMLElement) {
22
+ yield nextNode;
23
+ nextNode = options.reverse ? walker.previousNode() : walker.nextNode();
24
+ }
25
+ if (options.reverse && acceptFn(container, strict)) {
26
+ yield container;
27
+ }
28
+ return undefined;
29
+ }
30
+ function getFocusableChild(container, lastChild = false) {
31
+ return iterateFocusableElements(container, {
32
+ reverse: lastChild,
33
+ strict: true,
34
+ onlyTabbable: true
35
+ }).next().value;
36
+ }
37
+ function isFocusable(elem, strict = false) {
38
+ const disabledAttrInert = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(elem.tagName) && elem.disabled;
39
+ const hiddenInert = elem.hidden;
40
+ const hiddenInputInert = elem instanceof HTMLInputElement && elem.type === 'hidden';
41
+ const sentinelInert = elem.classList.contains('sentinel');
42
+ if (disabledAttrInert || hiddenInert || hiddenInputInert || sentinelInert) {
43
+ return false;
44
+ }
45
+ if (strict) {
46
+ const sizeInert = elem.offsetWidth === 0 || elem.offsetHeight === 0;
47
+ const visibilityInert = ['hidden', 'collapse'].includes(getComputedStyle(elem).visibility);
48
+ const clientRectsInert = elem.getClientRects().length === 0;
49
+ if (sizeInert || visibilityInert || clientRectsInert) {
50
+ return false;
51
+ }
52
+ }
53
+ if (elem.getAttribute('tabindex') != null) {
54
+ return true;
55
+ }
56
+ if (elem instanceof HTMLAnchorElement && elem.getAttribute('href') == null) {
57
+ return false;
58
+ }
59
+ return elem.tabIndex !== -1;
60
+ }
61
+ function isTabbable(elem, strict = false) {
62
+ return isFocusable(elem, strict) && elem.getAttribute('tabindex') !== '-1';
63
+ }
64
+
65
+ export { getFocusableChild, isFocusable, isTabbable, iterateFocusableElements };
@@ -0,0 +1,6 @@
1
+ let idSeed = 10000;
2
+ function uniqueId() {
3
+ return `__primer_id_${idSeed++}`;
4
+ }
5
+
6
+ export { uniqueId };
@@ -0,0 +1,9 @@
1
+ let isMac = undefined;
2
+ function isMacOS() {
3
+ if (isMac === undefined) {
4
+ isMac = /^mac/i.test(window.navigator.platform);
5
+ }
6
+ return isMac;
7
+ }
8
+
9
+ export { isMacOS };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 아무 행위도 하지 않는 함수입니다.
3
+ */
4
+ function noop() {}
5
+
6
+ export { noop };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamturing/react-kit",
3
- "version": "2.12.0",
3
+ "version": "2.14.0",
4
4
  "description": "React components, hooks for create teamturing web application",
5
5
  "author": "Sungchang Park <psch300@gmail.com> (https://github.com/psch300)",
6
6
  "homepage": "https://github.com/weareteamturing/bombe#readme",
@@ -48,9 +48,12 @@
48
48
  "@types/styled-system": "^5.1.17",
49
49
  "@types/styled-system__css": "^5.0.17",
50
50
  "react": "*",
51
+ "react-dom": "*",
51
52
  "styled-components": "*"
52
53
  },
53
54
  "dependencies": {
55
+ "@floating-ui/react-dom": "^2.0.2",
56
+ "@primer/behaviors": "^1.3.6",
54
57
  "@teamturing/icons": "^1.19.0",
55
58
  "@teamturing/token-studio": "^1.1.7",
56
59
  "framer-motion": "^10.16.4",
@@ -59,5 +62,5 @@
59
62
  "react-is": "^18.2.0",
60
63
  "styled-system": "^5.1.5"
61
64
  },
62
- "gitHead": "141b9cffa82d978cf6ac2723e69a7ef7d8220f78"
65
+ "gitHead": "544bb0398781216f2425c6e23d897d0eaa029c95"
63
66
  }