UNPKG

4.44 kBJavaScriptView Raw
1var $20aJV$reactariautils = require("@react-aria/utils");
2
3
4function $parcel$export(e, n, v, s) {
5 Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6}
7
8$parcel$export(module.exports, "disableTextSelection", () => $f7e14e656343df57$export$16a4697467175487);
9$parcel$export(module.exports, "restoreTextSelection", () => $f7e14e656343df57$export$b0d6fa1ab32e3295);
10/*
11 * Copyright 2020 Adobe. All rights reserved.
12 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License. You may obtain a copy
14 * of the License at http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software distributed under
17 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18 * OF ANY KIND, either express or implied. See the License for the specific language
19 * governing permissions and limitations under the License.
20 */
21// Note that state only matters here for iOS. Non-iOS gets user-select: none applied to the target element
22// rather than at the document level so we just need to apply/remove user-select: none for each pressed element individually
23let $f7e14e656343df57$var$state = 'default';
24let $f7e14e656343df57$var$savedUserSelect = '';
25let $f7e14e656343df57$var$modifiedElementMap = new WeakMap();
26function $f7e14e656343df57$export$16a4697467175487(target) {
27 if ((0, $20aJV$reactariautils.isIOS)()) {
28 if ($f7e14e656343df57$var$state === 'default') {
29 // eslint-disable-next-line no-restricted-globals
30 const documentObject = (0, $20aJV$reactariautils.getOwnerDocument)(target);
31 $f7e14e656343df57$var$savedUserSelect = documentObject.documentElement.style.webkitUserSelect;
32 documentObject.documentElement.style.webkitUserSelect = 'none';
33 }
34 $f7e14e656343df57$var$state = 'disabled';
35 } else if (target instanceof HTMLElement || target instanceof SVGElement) {
36 // If not iOS, store the target's original user-select and change to user-select: none
37 // Ignore state since it doesn't apply for non iOS
38 $f7e14e656343df57$var$modifiedElementMap.set(target, target.style.userSelect);
39 target.style.userSelect = 'none';
40 }
41}
42function $f7e14e656343df57$export$b0d6fa1ab32e3295(target) {
43 if ((0, $20aJV$reactariautils.isIOS)()) {
44 // If the state is already default, there's nothing to do.
45 // If it is restoring, then there's no need to queue a second restore.
46 if ($f7e14e656343df57$var$state !== 'disabled') return;
47 $f7e14e656343df57$var$state = 'restoring';
48 // There appears to be a delay on iOS where selection still might occur
49 // after pointer up, so wait a bit before removing user-select.
50 setTimeout(()=>{
51 // Wait for any CSS transitions to complete so we don't recompute style
52 // for the whole page in the middle of the animation and cause jank.
53 (0, $20aJV$reactariautils.runAfterTransition)(()=>{
54 // Avoid race conditions
55 if ($f7e14e656343df57$var$state === 'restoring') {
56 // eslint-disable-next-line no-restricted-globals
57 const documentObject = (0, $20aJV$reactariautils.getOwnerDocument)(target);
58 if (documentObject.documentElement.style.webkitUserSelect === 'none') documentObject.documentElement.style.webkitUserSelect = $f7e14e656343df57$var$savedUserSelect || '';
59 $f7e14e656343df57$var$savedUserSelect = '';
60 $f7e14e656343df57$var$state = 'default';
61 }
62 });
63 }, 300);
64 } else if (target instanceof HTMLElement || target instanceof SVGElement) // If not iOS, restore the target's original user-select if any
65 // Ignore state since it doesn't apply for non iOS
66 {
67 if (target && $f7e14e656343df57$var$modifiedElementMap.has(target)) {
68 let targetOldUserSelect = $f7e14e656343df57$var$modifiedElementMap.get(target);
69 if (target.style.userSelect === 'none') target.style.userSelect = targetOldUserSelect;
70 if (target.getAttribute('style') === '') target.removeAttribute('style');
71 $f7e14e656343df57$var$modifiedElementMap.delete(target);
72 }
73 }
74}
75
76
77//# sourceMappingURL=textSelection.main.js.map