This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { type ReactNode, type ComponentType } from 'react';
export type NavbarSecondaryMenuComponent<Props> = ComponentType<Props>;
/** @internal */
export type Content = {
component: NavbarSecondaryMenuComponent<object>;
props: object;
} | {
component: null;
props: null;
};
/** @internal */
export declare function NavbarSecondaryMenuContentProvider({ children, }: {
children: ReactNode;
}): JSX.Element;
/** @internal */
export declare function useNavbarSecondaryMenuContent(): Content;
/**
* This component renders nothing by itself, but it fills the placeholder in the
* generic secondary menu layout. This reduces coupling between the main layout
* and the specific page.
*
* This kind of feature is often called portal/teleport/gateway/outlet...
* Various unmaintained React libs exist. Most up-to-date one:
* https://github.com/gregberge/react-teleporter
* Not sure any of those is safe regarding concurrent mode.
*/
export declare function NavbarSecondaryMenuFiller<P extends object>({ component, props, }: {
component: NavbarSecondaryMenuComponent<P>;
props: P;
}): JSX.Element | null;
//# sourceMappingURL=content.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/content.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAIZ,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AAUf,MAAM,MAAM,4BAA4B,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;AAEvE,gBAAgB;AAChB,MAAM,MAAM,OAAO,GACf;IACE,SAAS,EAAE,4BAA4B,CAAC,MAAM,CAAC,CAAC;IAChD,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IAAC,SAAS,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAC,CAAC;AASnC,gBAAgB;AAChB,wBAAgB,kCAAkC,CAAC,EACjD,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAMd;AAED,gBAAgB;AAChB,wBAAgB,6BAA6B,IAAI,OAAO,CAMvD;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,MAAM,EAAE,EAC1D,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,EAAE,4BAA4B,CAAC,CAAC,CAAC,CAAC;IAC3C,KAAK,EAAE,CAAC,CAAC;CACV,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAqBrB"}

View File

@@ -0,0 +1,50 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { useState, useContext, useEffect, } from 'react';
import { ReactContextError, useShallowMemoObject } from '../../utils/reactUtils';
const Context = React.createContext(null);
/** @internal */
export function NavbarSecondaryMenuContentProvider({ children, }) {
const value = useState({ component: null, props: null });
return (
// @ts-expect-error: this context is hard to type
<Context.Provider value={value}>{children}</Context.Provider>);
}
/** @internal */
export function useNavbarSecondaryMenuContent() {
const value = useContext(Context);
if (!value) {
throw new ReactContextError('NavbarSecondaryMenuContentProvider');
}
return value[0];
}
/**
* This component renders nothing by itself, but it fills the placeholder in the
* generic secondary menu layout. This reduces coupling between the main layout
* and the specific page.
*
* This kind of feature is often called portal/teleport/gateway/outlet...
* Various unmaintained React libs exist. Most up-to-date one:
* https://github.com/gregberge/react-teleporter
* Not sure any of those is safe regarding concurrent mode.
*/
export function NavbarSecondaryMenuFiller({ component, props, }) {
const context = useContext(Context);
if (!context) {
throw new ReactContextError('NavbarSecondaryMenuContentProvider');
}
const [, setContent] = context;
// To avoid useless context re-renders, props are memoized shallowly
const memoizedProps = useShallowMemoObject(props);
useEffect(() => {
// @ts-expect-error: this context is hard to type
setContent({ component, props: memoizedProps });
}, [setContent, component, memoizedProps]);
useEffect(() => () => setContent({ component: null, props: null }), [setContent]);
return null;
}
//# sourceMappingURL=content.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/content.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,GAGV,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,iBAAiB,EAAE,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAwB/E,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAsB,IAAI,CAAC,CAAC;AAE/D,gBAAgB;AAChB,MAAM,UAAU,kCAAkC,CAAC,EACjD,QAAQ,GAGT;IACC,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC;IACvD,OAAO;IACL,iDAAiD;IACjD,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAC9D,CAAC;AACJ,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,6BAA6B;IAC3C,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,iBAAiB,CAAC,oCAAoC,CAAC,CAAC;KACnE;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CAAmB,EAC1D,SAAS,EACT,KAAK,GAIN;IACC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,iBAAiB,CAAC,oCAAoC,CAAC,CAAC;KACnE;IACD,MAAM,CAAC,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC;IAE/B,oEAAoE;IACpE,MAAM,aAAa,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAElD,SAAS,CAAC,GAAG,EAAE;QACb,iDAAiD;QACjD,UAAU,CAAC,EAAC,SAAS,EAAE,KAAK,EAAE,aAAa,EAAC,CAAC,CAAC;IAChD,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC;IAE3C,SAAS,CACP,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,EACtD,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC"}

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { type ReactNode } from 'react';
/** @internal */
export declare function NavbarSecondaryMenuDisplayProvider({ children, }: {
children: ReactNode;
}): JSX.Element;
/** Wires the logic for rendering the mobile navbar secondary menu. */
export declare function useNavbarSecondaryMenu(): {
/** Whether secondary menu is displayed. */
shown: boolean;
/**
* Hide the secondary menu; fired either when hiding the entire sidebar, or
* when going back to the primary menu.
*/
hide: () => void;
/** The content returned from the current secondary menu filler. */
content: JSX.Element | undefined;
};
//# sourceMappingURL=display.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/display.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAMZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AA6Cf,gBAAgB;AAChB,wBAAgB,kCAAkC,CAAC,EACjD,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAGd;AAUD,sEAAsE;AACtE,wBAAgB,sBAAsB,IAAI;IACxC,2CAA2C;IAC3C,KAAK,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,mEAAmE;IACnE,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC;CAClC,CAaA"}

View File

@@ -0,0 +1,62 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { useState, useContext, useEffect, useMemo, useCallback, } from 'react';
import { ReactContextError, usePrevious } from '../../utils/reactUtils';
import { useNavbarMobileSidebar } from '../navbarMobileSidebar';
import { useNavbarSecondaryMenuContent } from './content';
const Context = React.createContext(null);
function useContextValue() {
const mobileSidebar = useNavbarMobileSidebar();
const content = useNavbarSecondaryMenuContent();
const [shown, setShown] = useState(false);
const hasContent = content.component !== null;
const previousHasContent = usePrevious(hasContent);
// When content is become available for the first time (set in useEffect)
// we set this content to be shown!
useEffect(() => {
const contentBecameAvailable = hasContent && !previousHasContent;
if (contentBecameAvailable) {
setShown(true);
}
}, [hasContent, previousHasContent]);
// On sidebar close, secondary menu is set to be shown on next re-opening
// (if any secondary menu content available)
useEffect(() => {
if (!hasContent) {
setShown(false);
return;
}
if (!mobileSidebar.shown) {
setShown(true);
}
}, [mobileSidebar.shown, hasContent]);
return useMemo(() => [shown, setShown], [shown]);
}
/** @internal */
export function NavbarSecondaryMenuDisplayProvider({ children, }) {
const value = useContextValue();
return <Context.Provider value={value}>{children}</Context.Provider>;
}
function renderElement(content) {
if (content.component) {
const Comp = content.component;
return <Comp {...content.props}/>;
}
return undefined;
}
/** Wires the logic for rendering the mobile navbar secondary menu. */
export function useNavbarSecondaryMenu() {
const value = useContext(Context);
if (!value) {
throw new ReactContextError('NavbarSecondaryMenuDisplayProvider');
}
const [shown, setShown] = value;
const hide = useCallback(() => setShown(false), [setShown]);
const content = useNavbarSecondaryMenuContent();
return useMemo(() => ({ shown, hide, content: renderElement(content) }), [hide, content, shown]);
}
//# sourceMappingURL=display.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"display.js","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/display.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,OAAO,EACP,WAAW,GAEZ,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,iBAAiB,EAAE,WAAW,EAAC,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAC,sBAAsB,EAAC,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAC,6BAA6B,EAAe,MAAM,WAAW,CAAC;AAOtE,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAsB,IAAI,CAAC,CAAC;AAE/D,SAAS,eAAe;IACtB,MAAM,aAAa,GAAG,sBAAsB,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,6BAA6B,EAAE,CAAC;IAEhD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE1C,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;IAC9C,MAAM,kBAAkB,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IAEnD,yEAAyE;IACzE,mCAAmC;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,sBAAsB,GAAG,UAAU,IAAI,CAAC,kBAAkB,CAAC;QACjE,IAAI,sBAAsB,EAAE;YAC1B,QAAQ,CAAC,IAAI,CAAC,CAAC;SAChB;IACH,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAErC,yEAAyE;IACzE,4CAA4C;IAC5C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,UAAU,EAAE;YACf,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChB,OAAO;SACR;QACD,IAAI,CAAC,aAAa,CAAC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