Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const onKeyDown = useKeyListNav({
selected,
onCollapse: collapseNode,
canCollapse: id => {
const node = store.nodes.$.get(id);
return node ? node.children.length > 0 : false;
},
checkCollapsed: id => collapsed.has(id),
onNext: selectNext,
onPrev: selectPrev,
});
const onMouseLeave = useCallback(() => store.actions.highlightNode(null), []);
const ref = useRef(null);
const paneRef = useRef(null);
useEffect(() => {
if (ref.current && paneRef.current) {
const available = ref.current.offsetWidth;
const actual = paneRef.current.offsetWidth;
const diff = actual - available;
if (diff > 0) {
const current = cssToPx(
getComputedStyle(ref.current).getPropertyValue("--indent-depth"),
);
const indent =
current - Math.round((diff / (treeDepth || 1)) * 100) / 100;
// Only change indentation when it's smaller
console.log({ indent, current });
function AnnotationShareControl({
analytics,
flash,
group,
isPrivate,
shareUri,
}) {
const shareRef = useRef();
const inputRef = useRef();
const [isOpen, setOpen] = useState(false);
const wasOpen = useRef(isOpen);
const toggleSharePanel = () => setOpen(!isOpen);
const closePanel = () => setOpen(false);
// Interactions outside of the component when it is open should close it
useElementShouldClose(shareRef, isOpen, closePanel);
useEffect(() => {
if (wasOpen.current !== isOpen) {
wasOpen.current = isOpen;
if (isOpen) {
// Panel was just opened: select and focus the share URI for convenience
inputRef.current.focus();
function AnnotationShareControl({
analytics,
flash,
group,
isPrivate,
shareUri,
}) {
const shareRef = useRef();
const inputRef = useRef();
const [isOpen, setOpen] = useState(false);
const wasOpen = useRef(isOpen);
const toggleSharePanel = () => setOpen(!isOpen);
const closePanel = () => setOpen(false);
// Interactions outside of the component when it is open should close it
useElementShouldClose(shareRef, isOpen, closePanel);
useEffect(() => {
if (wasOpen.current !== isOpen) {
wasOpen.current = isOpen;
if (isOpen) {
// Panel was just opened: select and focus the share URI for convenience
function useStore(callback) {
const store = useService('store');
// Store the last-used callback in a ref so we can access it in the effect
// below without having to re-subscribe to the store when it changes.
const lastCallback = useRef(null);
lastCallback.current = callback;
const lastResult = useRef(null);
lastResult.current = callback(store);
// Check for a performance issue caused by `callback` returning a different
// result on every call, even if the store has not changed.
if (process.env.NODE_ENV !== 'production') {
if (!shallowEqual(lastResult.current, callback(store))) {
warnOnce(
'The output of a callback passed to `useStore` changes every time. ' +
'This will lead to a component updating more often than necessary.'
);
}
}
// Abuse `useReducer` to force updates when the store state changes.
const [, forceUpdate] = useReducer(x => x + 1, 0);
export const AuditDetailPane = props => {
/** @type {import('preact').Ref} */
const paneElementRef = useRef(undefined);
const previouslySelectedAuditId = usePreviousValue(props.selectedAuditId);
// Scroll to the selected audit *when it changes*
useEffect(() => {
const auditId = props.selectedAuditId;
const paneElement = paneElementRef.current;
if (!paneElement || !auditId || auditId === previouslySelectedAuditId) return;
const childElement = paneElement.querySelector(`#audit-detail-pane-audit--${auditId}`);
if (!childElement || !(childElement instanceof HTMLElement)) return;
paneElement.scrollTo(0, childElement.offsetTop);
}, [props.selectedAuditId, previouslySelectedAuditId]);
return (
<div> (paneElementRef.current = el)}></div>
const value = initializer();
if (value && value.then) {
if ('_value' in value) return [value._value];
if ('_error' in value) return [undefined, value._error];
return [undefined, undefined, value];
}
return [value];
} catch (err) {
return [undefined, err];
}
};
const [pair, setValue] = useState(getInitialState);
// only run on changes, not initial mount
const isFirstRun = useRef(true);
useEffect(() => {
if (isFirstRun.current) return (isFirstRun.current = false);
setValue(getInitialState());
}, params || []);
const pending = pair[2];
if (pending) {
if (!pending._processing) {
pending._processing = true;
pending
.then(value => {
pending._value = value;
setValue([value]);
})
.catch(err => {
pending._error = err;
function Menu({
align = 'left',
arrowClass = '',
children,
containerPositioned = true,
contentClass,
defaultOpen = false,
label,
onOpenChanged,
menuIndicator = true,
title,
}) {
const [isOpen, setOpen] = useState(defaultOpen);
// Notify parent when menu is opened or closed.
const wasOpen = useRef(isOpen);
useEffect(() => {
if (typeof onOpenChanged === 'function' && wasOpen.current !== isOpen) {
wasOpen.current = isOpen;
onOpenChanged(isOpen);
}
}, [isOpen, onOpenChanged]);
// Toggle menu when user presses toggle button. The menu is shown on mouse
// press for a more responsive/native feel but also handles a click event for
// activation via other input methods.
const toggleMenu = event => {
// If the menu was opened on press, don't close it again on the subsequent
// mouse up ("click") event.
if (event.type === 'mousedown') {
ignoreNextClick = true;
} else if (event.type === 'click' && ignoreNextClick) {
function SearchInput({ alwaysExpanded, query, onSearch }) {
const isLoading = useStore(store => store.isLoading());
const input = useRef();
// The active filter query from the previous render.
const [prevQuery, setPrevQuery] = useState(query);
// The query that the user is currently typing, but may not yet have applied.
const [pendingQuery, setPendingQuery] = useState(query);
const onSubmit = e => {
e.preventDefault();
onSearch(input.current.value);
};
// When the active query changes outside of this component, update the input
// field to match. This happens when clearing the current filter for example.
if (query !== prevQuery) {
setPendingQuery(query);
export function TreeItem(props: { key: any; id: ID }) {
const { id } = props;
const store = useStore();
const sel = useSelection();
const { collapsed, toggle } = useCollapser();
const filterFragments = useObserver(() => store.filter.filterFragment.$);
const node = useObserver(() => store.nodes.$.get(id) || null);
const onToggle = () => toggle(id);
const ref = useRef();
let isSelected = sel.selected === id;
useEffect(() => {
if (ref.current && isSelected) {
scrollIntoView(ref.current);
}
}, [ref.current, sel.selected, id]);
if (!node) return null;
return (
<div class="{s.item}"> sel.selectById(id)}
onMouseEnter={() => store.actions.highlightNode(id)}</div>
record: {
operator,
attribute,
current,
target,
hidden,
requirements,
},
setOperator,
setAttribute,
setCurrent,
setTarget,
setHidden,
} = useRecord(init_record);
const operatorInputRef = useRef(null);
useEffect(() => {
if (!operator) {
operatorInputRef.current && operatorInputRef.current.focus();
}
}, []);
const options = Object.entries(ATTRIBUTES).map(([k, v]) => ({ key: k, value: v }));
const operator_data = OPERATORS.find(o => o.name === operator);
const unavailable_attributes = [];
const render_map = {};
if (operator_data) {
if (operator_data.meta.max_elite_rank < 2) {
unavailable_attributes.push(ATTRIBUTES.LEVEL_ELITE_2);
}