From db995addaeb2d19c3aeac9106f96ed18e3a724b8 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Thu, 4 May 2023 15:34:52 -0400 Subject: [PATCH] A super tab idea --- ACKNOWLEDGMENTS.md | 11 --- package.json | 1 - ts/background.ts | 47 ++++++++++ ts/components/CustomColorEditor.tsx | 140 +++++++++++++++------------- ts/components/Preferences.tsx | 2 +- ts/hooks/useTabs.tsx | 2 +- ts/util/focusableSelectors.ts | 30 ++++++ yarn.lock | 5 - 8 files changed, 152 insertions(+), 86 deletions(-) create mode 100644 ts/util/focusableSelectors.ts diff --git a/ACKNOWLEDGMENTS.md b/ACKNOWLEDGMENTS.md index 7c30b678f13a..3b6e30438769 100644 --- a/ACKNOWLEDGMENTS.md +++ b/ACKNOWLEDGMENTS.md @@ -781,17 +781,6 @@ Signal Desktop makes use of the following open source projects. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -## focusable-selectors - - The MIT License (MIT) - Copyright (c) 2021 Kitty Giraudel - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ## form-data Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors diff --git a/package.json b/package.json index 87b31bf9640f..0f8b78eba32f 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,6 @@ "filesize": "3.6.1", "firstline": "1.2.1", "focus-trap-react": "8.8.1", - "focusable-selectors": "0.8.0", "form-data": "4.0.0", "fs-extra": "5.0.0", "fuse.js": "6.5.3", diff --git a/ts/background.ts b/ts/background.ts index d2fce63437ed..5cf5e6001846 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -191,6 +191,7 @@ import { RetryPlaceholders } from './util/retryPlaceholders'; import { setBatchingStrategy } from './util/messageBatcher'; import { parseRemoteClientExpiration } from './util/parseRemoteClientExpiration'; import { makeLookup } from './util/makeLookup'; +import { focusableSelectors } from './util/focusableSelectors'; export function isOverHourIntoPast(timestamp: number): boolean { const HOUR = 1000 * 60 * 60; @@ -1352,6 +1353,52 @@ export async function startApp(): Promise { return; } + // Super tab :) + if (commandOrCtrl && key === 'F6') { + window.enterKeyboardMode(); + const focusedElement = document.activeElement; + const targets: Array = Array.from( + document.querySelectorAll('[data-supertab="true"]') + ); + + const focusedIndex = targets.findIndex(target => { + if (!target || !focusedElement) { + return false; + } + + if (target === focusedElement) { + return true; + } + + if (target.contains(focusedElement)) { + return true; + } + + return false; + }); + + const lastIndex = targets.length - 1; + const increment = shiftKey ? -1 : 1; + + let index; + if (focusedIndex < 0 || focusedIndex >= lastIndex) { + index = 0; + } else { + index = focusedIndex + increment; + } + + while (!targets[index]) { + index += increment; + if (index > lastIndex || index < 0) { + index = 0; + } + } + + targets[index] + .querySelectorAll(focusableSelectors.join(','))[0] + ?.focus(); + } + // Navigate by section if (commandOrCtrl && !shiftKey && (key === 't' || key === 'T')) { window.enterKeyboardMode(); diff --git a/ts/components/CustomColorEditor.tsx b/ts/components/CustomColorEditor.tsx index 0a4efa2e01f5..9e65e7be57e6 100644 --- a/ts/components/CustomColorEditor.tsx +++ b/ts/components/CustomColorEditor.tsx @@ -96,76 +96,82 @@ export function CustomColorEditor({ includeAnotherBubble /> {selectedTab === TabViews.Gradient && ( - { - setColor({ - ...color, - deg, - }); - }} - onClick={knob => setSelectedColorKnob(knob)} - selectedKnob={selectedColorKnob} - /> +
+ { + setColor({ + ...color, + deg, + }); + }} + onClick={knob => setSelectedColorKnob(knob)} + selectedKnob={selectedColorKnob} + /> +
)} -
- {i18n('icu:CustomColorEditor__hue')} - { - setColor({ - ...color, - [selectedColorKnob]: { - ...ULTRAMARINE_ISH_VALUES, - ...color[selectedColorKnob], - hue: getValue(percentage, MAX_HUE), - }, - }); - }} - value={getPercentage(hue, MAX_HUE)} - /> +
+
+ {i18n('icu:CustomColorEditor__hue')} + { + setColor({ + ...color, + [selectedColorKnob]: { + ...ULTRAMARINE_ISH_VALUES, + ...color[selectedColorKnob], + hue: getValue(percentage, MAX_HUE), + }, + }); + }} + value={getPercentage(hue, MAX_HUE)} + /> +
+
+ {i18n('icu:CustomColorEditor__saturation')} + { + setColor({ + ...color, + [selectedColorKnob]: { + ...ULTRAMARINE_ISH_VALUES, + ...color[selectedColorKnob], + saturation: value, + }, + }); + }} + value={saturation} + /> +
-
- {i18n('icu:CustomColorEditor__saturation')} - { - setColor({ - ...color, - [selectedColorKnob]: { - ...ULTRAMARINE_ISH_VALUES, - ...color[selectedColorKnob], - saturation: value, - }, - }); - }} - value={saturation} - /> -
-
+
diff --git a/ts/components/Preferences.tsx b/ts/components/Preferences.tsx index cf9627e4f629..f5bf0e3c6836 100644 --- a/ts/components/Preferences.tsx +++ b/ts/components/Preferences.tsx @@ -3,7 +3,6 @@ import type { AudioDevice } from '@signalapp/ringrtc'; import type { ReactNode } from 'react'; -import focusableSelectors from 'focusable-selectors'; import React, { useCallback, useEffect, @@ -59,6 +58,7 @@ import { DurationInSeconds } from '../util/durations'; import { useEscapeHandling } from '../hooks/useEscapeHandling'; import { useUniqueId } from '../hooks/useUniqueId'; import { useTheme } from '../hooks/useTheme'; +import { focusableSelectors } from '../util/focusableSelectors'; type CheckboxChangeHandlerType = (value: boolean) => unknown; type SelectChangeHandlerType = (value: T) => unknown; diff --git a/ts/hooks/useTabs.tsx b/ts/hooks/useTabs.tsx index 6d8a7d69f41a..0076708cc777 100644 --- a/ts/hooks/useTabs.tsx +++ b/ts/hooks/useTabs.tsx @@ -63,7 +63,7 @@ export function useTabs(options: TabsOptionsType): TabsProps { } const tabsHeaderElement = ( -
+
{options.tabs.map(({ id, label }) => (
summary:first-of-type${not.negTabIndex}`, + // Discard until Firefox supports `:has()` + // See: https://github.com/KittyGiraudel/focusable-selectors/issues/12 + // `details:not(:has(> summary))${not.inert}${not.negTabIndex}`, + `iframe${not.inert}${not.negTabIndex}`, + `audio[controls]${not.inert}${not.negTabIndex}`, + `video[controls]${not.inert}${not.negTabIndex}`, + `[contenteditable]${not.inert}${not.negTabIndex}`, + `[tabindex]${not.inert}${not.negTabIndex}`, +]; diff --git a/yarn.lock b/yarn.lock index 0e8e74b0e66c..b39b508fda2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9488,11 +9488,6 @@ focus-trap@^6.7.1: dependencies: tabbable "^5.2.1" -focusable-selectors@0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/focusable-selectors/-/focusable-selectors-0.8.0.tgz#aecfd7ce2ac369fd808289d4bcf474ac2bf03562" - integrity sha512-lKyq/Cth8mTEzJk2CLHLdMDYl2zmMicQflfrUMs0CZ3Boc5Ca/63d7z+GgKV3nKm79KqrPtCWrwTdoV9RTjVCA== - follow-redirects@^1.0.0: version "1.14.9" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"