Skip to content

Instantly share code, notes, and snippets.

@ladifire
Created April 21, 2024 02:52
Show Gist options
  • Save ladifire/21fb3e774cf62ac50d0700fd50d1ccb2 to your computer and use it in GitHub Desktop.
Save ladifire/21fb3e774cf62ac50d0700fd50d1ccb2 to your computer and use it in GitHub Desktop.
Original code for PressableText from Facebook frontend
__d("PressableText.react", ["Pressability", "PressableGroupContext", "RecoverableViolationWithComponentStack.react", "gkx", "joinClasses", "justknobx", "react", "stylex", "useCometErrorProject", "useMergeRefs", "useWebPressableTouchStartHandler"], (function(a, b, c, d, e, f, g) {
"use strict";
var h, i, j = i || (i = d("react"));
b = i;
var k = b.useCallback
, l = b.useContext
, m = b.useRef
, n = b.useState
, o = ["menuitem", "tab", "none"]
, p = {
article: "article",
banner: "header",
complementary: "aside",
contentinfo: "footer",
figure: "figure",
form: "form",
heading: "h1",
label: "label",
link: "a",
list: "ul",
listitem: "li",
main: "main",
navigation: "nav",
none: "div",
region: "section"
};
function q(a, b) {
var c = "div";
if ((b == null ? void 0 : b.url) != null && (b == null ? void 0 : b.url) !== "#" || o.includes(a) && (b == null ? void 0 : b.url) != null)
c = "a";
else if (a != null) {
b = p[a];
b != null && (c = b)
}
return c
}
var r = function(a) {
var b = a.target
, c = b.tagName;
c = b.isContentEditable || c === "A" && b.href != null || c === "BUTTON" || c === "INPUT" || c === "SELECT" || c === "TEXTAREA";
if (b.tabIndex === 0 && !c) {
c = a.key;
if (c === "Enter")
return !0;
a = b.getAttribute("role");
if ((c === " " || c === "Spacebar") && (a === "button" || a === "combobox" || a === "menuitem" || a === "menuitemradio" || a === "option"))
return !0
}
return !1
};
function s(a) {
return typeof document !== "undefined" && typeof document.contains === "function" ? document.contains(a) : !1
}
function t(a) {
a = a;
while (a != null) {
if (a.tagName === "A" && a.href != null)
return !0;
a = a.parentNode
}
return !1
}
function u(a, b) {
var d = a.altKey
, e = a.ctrlKey
, f = a.currentTarget
, g = a.metaKey
, h = a.shiftKey;
a = a.target;
var i = a;
c("justknobx")._("450") && (i = s(a) ? a : f);
a = t(i);
f = d || e || g || h;
return b !== !1 && a && !f
}
function a(a) {
var b = m(null)
, e = n(!1)
, f = e[0];
e = e[1];
var g = n(!1)
, i = g[0];
g = g[1];
var o = n(!1)
, p = o[0];
o = o[1];
var s = n(!1)
, t = s[0];
s = s[1];
var x = l(c("PressableGroupContext"))
, y = a.accessibilityLabel
, z = a.accessibilityRelationship
, A = a.accessibilityRole
, B = a.accessibilityState
, C = a.children
, D = a.className_DEPRECATED
, E = a.direction
, F = a.disabled
, G = a.focusable
, H = a.forwardedRef
, I = a.link
, J = a.nativeID
, K = a.onBlur
, L = a.onContextMenu
, M = a.onFocus
, N = a.onFocusChange
, O = a.onFocusVisibleChange
, P = a.onHoverChange
, aa = a.onHoverEnd
, ba = a.onHoverMove
, ca = a.onHoverStart
, Q = a.onPress
, da = a.onPressChange
, ea = a.onPressEnd
, fa = a.onPressMove
, ga = a.onPressStart
, ha = a.preventContextMenu
, R = a.preventDefault
, ia = a.selectable
, S = a.style
, T = a.suppressFocusRing
, U = a.testID;
U = a.testOnly_state;
var V = a.xstyle;
a = babelHelpers.objectWithoutPropertiesLoose(a, ["accessibilityLabel", "accessibilityRelationship", "accessibilityRole", "accessibilityState", "children", "className_DEPRECATED", "direction", "disabled", "focusable", "forwardedRef", "link", "nativeID", "onBlur", "onContextMenu", "onFocus", "onFocusChange", "onFocusVisibleChange", "onHoverChange", "onHoverEnd", "onHoverMove", "onHoverStart", "onPress", "onPressChange", "onPressEnd", "onPressMove", "onPressStart", "preventContextMenu", "preventDefault", "selectable", "style", "suppressFocusRing", "testID", "testOnly_state", "xstyle"]);
var W = q(A, I);
F = F === !0 || (B == null ? void 0 : B.disabled) === !0;
var X = B == null ? void 0 : B.hidden
, Y = W === "a" && F !== !0;
f = {
disabled: F === !0 || (U == null ? void 0 : U.disabled) === !0 || !1,
focused: f || (U == null ? void 0 : U.focused) === !0,
focusVisible: i && T !== !0 || (U == null ? void 0 : U.focusVisible) === !0,
hovered: p || (U == null ? void 0 : U.hovered) === !0,
pressed: t || (U == null ? void 0 : U.pressed) === !0
};
i = typeof C === "function" ? C(f) : C;
T = typeof D === "function" ? D(f) : D;
p = typeof S === "function" ? S(f) : S;
t = typeof V === "function" ? V(f) : V;
d("Pressability").usePressability(b, {
disabled: F,
onBlur: K,
onContextMenu: L,
onFocus: M,
onFocusChange: v(e, N),
onFocusVisibleChange: v(g, O),
onHoverChange: v(o, P),
onHoverEnd: aa,
onHoverMove: ba,
onHoverStart: ca,
onPressChange: v(s, da),
onPressEnd: ea,
onPressMove: fa,
onPressStart: ga,
preventContextMenu: ha,
preventDefault: R == null ? !0 : R
});
U = k(function(a) {
Q && Q(a),
(Q || I != null) && a.stopPropagation(),
u(a, R) && a.nativeEvent.preventDefault()
}, [I, Q, R]);
C = k(function(a) {
if (r(a)) {
var b = a.key;
(b === " " || b === "Spacebar") && a.preventDefault();
Q && (Q(a),
a.stopPropagation())
}
}, [Q]);
var ja, Z;
switch (E) {
case "none":
break;
default:
E != null && (Z = E);
break
}
D = c("useMergeRefs")(b, H);
c("useWebPressableTouchStartHandler")(b, x, U);
var $;
S = W === "a" || A === "button";
S ? X === !0 || G === !1 || !c("gkx")("21059") && F === !0 ? $ = -1 : $ = 0 : c("gkx")("21059") ? X !== !0 && G !== !1 && A !== "none" && ($ = 0) : F !== !0 && X !== !0 && G !== !1 && A !== "none" && ($ = 0);
V = I == null ? void 0 : I.download;
K = (V === !0 || typeof V === "string") && Y;
L = A === "none" ? "presentation" : A;
M = j.jsx(W, babelHelpers["extends"]({}, a, {
"aria-activedescendant": z == null ? void 0 : z.activedescendant,
"aria-busy": B == null ? void 0 : B.busy,
"aria-checked": B == null ? void 0 : B.checked,
"aria-controls": z == null ? void 0 : z.controls,
"aria-current": z == null ? void 0 : z.current,
"aria-describedby": z == null ? void 0 : z.describedby,
"aria-details": z == null ? void 0 : z.details,
"aria-disabled": F === !0 && L !== "presentation" ? F : void 0,
"aria-expanded": B == null ? void 0 : B.expanded,
"aria-haspopup": z == null ? void 0 : z.haspopup,
"aria-hidden": X,
"aria-invalid": B == null ? void 0 : B.invalid,
"aria-label": y,
"aria-labelledby": z == null ? void 0 : z.labelledby,
"aria-owns": z == null ? void 0 : z.owns,
"aria-pressed": B == null ? void 0 : B.pressed,
"aria-readonly": B == null ? void 0 : B.readonly,
"aria-required": B == null ? void 0 : B.required,
"aria-selected": B == null ? void 0 : B.selected,
attributionsrc: Y ? I == null ? void 0 : I.attributionsrc : void 0,
children: i,
className: c("joinClasses")((h || (h = c("stylex")))(w.root, ia === !1 && w.notSelectable, f.disabled && w.disabled, !f.focusVisible && w.focusNotVisible, f.focusVisible && S && w.linkFocusRing, t, x && w.rootInGroup), T),
"data-testid": void 0,
dir: Z,
download: K ? V : void 0,
href: Y ? I == null ? void 0 : I.url : void 0,
id: J,
onClick: F ? void 0 : U,
onKeyDown: F ? void 0 : C,
ref: D,
rel: Y ? I == null ? void 0 : I.rel : void 0,
role: L,
style: p,
tabIndex: $,
target: Y ? I == null ? void 0 : I.target : void 0
}));
return M
}
a.displayName = a.name + " [from " + f.id + "]";
function v(a, b) {
return k(function(c) {
a(c),
b && b(c)
}, [b, a])
}
var w = {
disabled: {
cursor: "x1h6gzvc",
$$css: !0
},
focusNotVisible: {
outline: "x1a2a7pz",
$$css: !0
},
linkFocusRing: {
outline: "x1gje4rg",
$$css: !0
},
notSelectable: {
userSelect: "x87ps6o",
$$css: !0
},
root: {
WebkitTapHighlightColor: "x1i10hfl",
backgroundColor: "xjbqb8w",
borderTopStyle: "x1ejq31n",
borderEndStyle: "xd10rxx",
borderBottomStyle: "x1sy0etr",
borderStartStyle: "x17r0tee",
borderTopWidth: "x972fbf",
borderEndWidth: "xcfux6l",
borderBottomWidth: "x1qhh985",
borderStartWidth: "xm0m39n",
boxSizing: "x9f619",
cursor: "x1ypdohk",
display: "xt0psk2",
listStyle: "xe8uvvx",
marginTop: "xdj266r",
marginEnd: "x11i5rnm",
marginBottom: "xat24cr",
marginStart: "x1mh8g0r",
paddingTop: "xexx8yu",
paddingEnd: "x4uap5",
paddingBottom: "x18d9i69",
paddingStart: "xkhd6sd",
textAlign: "x16tdsg8",
textDecoration: "x1hl2dhg",
touchAction: "xggy1nq",
$$css: !0
},
rootInGroup: {
touchAction: "x5ve5x3",
$$css: !0
}
};
g["default"] = a
}
), 98);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment