@fluentui/react-positioning 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.11
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +494 -10
- package/CHANGELOG.md +221 -71
- package/dist/index.d.ts +247 -0
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/createArrowStyles.js +87 -0
- package/lib/createArrowStyles.js.map +1 -0
- package/lib/createVirtualElementFromClick.js +19 -15
- package/lib/createVirtualElementFromClick.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/isIntersectingModifier.js +26 -0
- package/lib/isIntersectingModifier.js.map +1 -0
- package/lib/types.js.map +1 -1
- package/lib/usePositioning.js +408 -0
- package/lib/usePositioning.js.map +1 -0
- package/lib/usePositioningMouseTarget.js +40 -0
- package/lib/usePositioningMouseTarget.js.map +1 -0
- package/lib/utils/fromPopperPlacement.js +40 -0
- package/lib/utils/fromPopperPlacement.js.map +1 -0
- package/lib/utils/getBoundary.js +15 -10
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/getPopperOffset.js +44 -0
- package/lib/utils/getPopperOffset.js.map +1 -0
- package/lib/utils/getReactFiberFromNode.js +39 -35
- package/lib/utils/getReactFiberFromNode.js.map +1 -1
- package/lib/utils/getScrollParent.js +46 -32
- package/lib/utils/getScrollParent.js.map +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeArrowOffset.js +31 -25
- package/lib/utils/mergeArrowOffset.js.map +1 -1
- package/lib/utils/parsePopperPlacement.js +14 -0
- package/lib/utils/parsePopperPlacement.js.map +1 -0
- package/lib/utils/positioningHelper.js +42 -34
- package/lib/utils/positioningHelper.js.map +1 -1
- package/lib/utils/resolvePositioningShorthand.js +58 -20
- package/lib/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib/utils/useCallbackRef.js +35 -29
- package/lib/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/createArrowStyles.js +100 -0
- package/lib-commonjs/createArrowStyles.js.map +1 -0
- package/lib-commonjs/createVirtualElementFromClick.js +25 -16
- package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
- package/lib-commonjs/index.js +62 -10
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/isIntersectingModifier.js +34 -0
- package/lib-commonjs/isIntersectingModifier.js.map +1 -0
- package/lib-commonjs/types.js +4 -1
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/usePositioning.js +424 -0
- package/lib-commonjs/usePositioning.js.map +1 -0
- package/lib-commonjs/usePositioningMouseTarget.js +51 -0
- package/lib-commonjs/usePositioningMouseTarget.js.map +1 -0
- package/lib-commonjs/utils/fromPopperPlacement.js +50 -0
- package/lib-commonjs/utils/fromPopperPlacement.js.map +1 -0
- package/lib-commonjs/utils/getBoundary.js +23 -12
- package/lib-commonjs/utils/getBoundary.js.map +1 -1
- package/lib-commonjs/utils/getPopperOffset.js +54 -0
- package/lib-commonjs/utils/getPopperOffset.js.map +1 -0
- package/lib-commonjs/utils/getReactFiberFromNode.js +44 -36
- package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
- package/lib-commonjs/utils/getScrollParent.js +53 -33
- package/lib-commonjs/utils/getScrollParent.js.map +1 -1
- package/lib-commonjs/utils/index.js +15 -3
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeArrowOffset.js +37 -26
- package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
- package/lib-commonjs/utils/parsePopperPlacement.js +23 -0
- package/lib-commonjs/utils/parsePopperPlacement.js.map +1 -0
- package/lib-commonjs/utils/positioningHelper.js +50 -35
- package/lib-commonjs/utils/positioningHelper.js.map +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.js +66 -23
- package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib-commonjs/utils/useCallbackRef.js +45 -32
- package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
- package/package.json +17 -14
- package/dist/react-positioning.d.ts +0 -143
- package/lib/createVirtualElementFromClick.d.ts +0 -6
- package/lib/index.d.ts +0 -5
- package/lib/types.d.ts +0 -68
- package/lib/usePopper.d.ts +0 -35
- package/lib/usePopper.js +0 -357
- package/lib/usePopper.js.map +0 -1
- package/lib/usePopperMouseTarget.d.ts +0 -11
- package/lib/usePopperMouseTarget.js +0 -34
- package/lib/usePopperMouseTarget.js.map +0 -1
- package/lib/utils/getBasePlacement.d.ts +0 -8
- package/lib/utils/getBasePlacement.js +0 -10
- package/lib/utils/getBasePlacement.js.map +0 -1
- package/lib/utils/getBoundary.d.ts +0 -6
- package/lib/utils/getReactFiberFromNode.d.ts +0 -109
- package/lib/utils/getScrollParent.d.ts +0 -12
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/mergeArrowOffset.d.ts +0 -10
- package/lib/utils/positioningHelper.d.ts +0 -7
- package/lib/utils/resolvePositioningShorthand.d.ts +0 -2
- package/lib/utils/useCallbackRef.d.ts +0 -19
- package/lib-commonjs/createVirtualElementFromClick.d.ts +0 -6
- package/lib-commonjs/index.d.ts +0 -5
- package/lib-commonjs/types.d.ts +0 -68
- package/lib-commonjs/usePopper.d.ts +0 -35
- package/lib-commonjs/usePopper.js +0 -361
- package/lib-commonjs/usePopper.js.map +0 -1
- package/lib-commonjs/usePopperMouseTarget.d.ts +0 -11
- package/lib-commonjs/usePopperMouseTarget.js +0 -38
- package/lib-commonjs/usePopperMouseTarget.js.map +0 -1
- package/lib-commonjs/utils/getBasePlacement.d.ts +0 -8
- package/lib-commonjs/utils/getBasePlacement.js +0 -14
- package/lib-commonjs/utils/getBasePlacement.js.map +0 -1
- package/lib-commonjs/utils/getBoundary.d.ts +0 -6
- package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -109
- package/lib-commonjs/utils/getScrollParent.d.ts +0 -12
- package/lib-commonjs/utils/index.d.ts +0 -8
- package/lib-commonjs/utils/mergeArrowOffset.d.ts +0 -10
- package/lib-commonjs/utils/positioningHelper.d.ts +0 -7
- package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +0 -2
- package/lib-commonjs/utils/useCallbackRef.d.ts +0 -19
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils/getPopperOffset.ts"],"names":[],"mappings":"AAEA,SAAS,mBAAT,QAAoC,uBAApC;AAyBA;;;;AAIG;;AACH,OAAM,SAAU,eAAV,CAA0B,SAA1B,EAAuD;AAC3D,MAAI,SAAS,KAAK,SAAd,IAA2B,SAAS,KAAK,IAA7C,EAAmD;AACjD,WAAO,SAAP;AACD;;AAED,MAAI,OAAO,SAAP,KAAqB,QAAzB,EAAmC;AACjC,WAAO,CAAC,CAAD,EAAI,SAAJ,CAAP;AACD;;AAED,MAAI,OAAO,SAAP,KAAqB,QAAzB,EAAmC;AACjC,WAAO,CAAC,SAAS,CAAC,SAAX,EAAsB,SAAS,CAAC,QAAhC,CAAP;AACD;;AAED,SAAO,CAAC;AAAE,IAAA,MAAF;AAAU,IAAA,SAAV;AAAqB,IAAA;AAArB,GAAD,KAAqC;AAC1C,UAAM;AAAE,MAAA,QAAF;AAAY,MAAA;AAAZ,QAA0B,mBAAmB,CAAC,SAAD,CAAnD;AACA,UAAM,cAAc,GAAG,SAAS,CAAC;AAAE,MAAA,cAAc,EAAE,MAAlB;AAA0B,MAAA,UAAU,EAAE,SAAtC;AAAiD,MAAA,QAAjD;AAA2D,MAAA;AAA3D,KAAD,CAAhC;;AACA,QAAI,OAAO,cAAP,KAA0B,QAA9B,EAAwC;AACtC,aAAO,CAAC,CAAD,EAAI,cAAJ,CAAP;AACD;;AAED,WAAO,CAAC,cAAc,CAAC,SAAhB,EAA2B,cAAc,CAAC,QAA1C,CAAP;AACD,GARD;AASD","sourcesContent":["import type { Offset } from '../types';\nimport type { Rect, Placement } from '@popperjs/core';\nimport { fromPopperPlacement } from './fromPopperPlacement';\n/**\n * Type taken from Popper since it is not exported\n */\nexport type PopperOffsetValue = [number | null | undefined, number | null | undefined];\n\n/**\n * Type taken from Popper since it is not exported\n */\nexport type PopperOffset = PopperOffsetValue | PopperOffsetFunction;\n\n/**\n * Type taken from Popper.js since it is not exported\n */\nexport type PopperOffsetFunctionParam = {\n popper: Rect;\n reference: Rect;\n placement: Placement;\n};\n\n/**\n * Type taken from Popper.js since it is not exported\n */\nexport type PopperOffsetFunction = (args: { popper: Rect; reference: Rect; placement: Placement }) => PopperOffsetValue;\n\n/**\n * Shim to transform offset values from this library to Popper.js\n * @param rawOffset Offset from this library\n * @returns An offset value compatible with Popper.js\n */\nexport function getPopperOffset(rawOffset: Offset | undefined): PopperOffsetValue | PopperOffsetFunction | undefined {\n if (rawOffset === undefined || rawOffset === null) {\n return rawOffset;\n }\n\n if (typeof rawOffset === 'number') {\n return [0, rawOffset];\n }\n\n if (typeof rawOffset === 'object') {\n return [rawOffset.crossAxis, rawOffset.mainAxis];\n }\n\n return ({ popper, reference, placement }) => {\n const { position, alignment } = fromPopperPlacement(placement);\n const computedOffset = rawOffset({ positionedRect: popper, targetRect: reference, position, alignment });\n if (typeof computedOffset === 'number') {\n return [0, computedOffset];\n }\n\n return [computedOffset.crossAxis, computedOffset.mainAxis];\n };\n}\n"],"sourceRoot":"../src/"}
|
@@ -1,42 +1,46 @@
|
|
1
1
|
var WorkTag;
|
2
|
+
|
2
3
|
(function (WorkTag) {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
4
|
+
WorkTag[WorkTag["FunctionComponent"] = 0] = "FunctionComponent";
|
5
|
+
WorkTag[WorkTag["ClassComponent"] = 1] = "ClassComponent";
|
6
|
+
WorkTag[WorkTag["IndeterminateComponent"] = 2] = "IndeterminateComponent";
|
7
|
+
WorkTag[WorkTag["HostRoot"] = 3] = "HostRoot";
|
8
|
+
WorkTag[WorkTag["HostPortal"] = 4] = "HostPortal";
|
9
|
+
WorkTag[WorkTag["HostComponent"] = 5] = "HostComponent";
|
10
|
+
WorkTag[WorkTag["HostText"] = 6] = "HostText";
|
11
|
+
WorkTag[WorkTag["Fragment"] = 7] = "Fragment";
|
12
|
+
WorkTag[WorkTag["Mode"] = 8] = "Mode";
|
13
|
+
WorkTag[WorkTag["ContextConsumer"] = 9] = "ContextConsumer";
|
14
|
+
WorkTag[WorkTag["ContextProvider"] = 10] = "ContextProvider";
|
15
|
+
WorkTag[WorkTag["ForwardRef"] = 11] = "ForwardRef";
|
16
|
+
WorkTag[WorkTag["Profiler"] = 12] = "Profiler";
|
17
|
+
WorkTag[WorkTag["SuspenseComponent"] = 13] = "SuspenseComponent";
|
18
|
+
WorkTag[WorkTag["MemoComponent"] = 14] = "MemoComponent";
|
19
|
+
WorkTag[WorkTag["SimpleMemoComponent"] = 15] = "SimpleMemoComponent";
|
20
|
+
WorkTag[WorkTag["LazyComponent"] = 16] = "LazyComponent";
|
21
|
+
WorkTag[WorkTag["IncompleteClassComponent"] = 17] = "IncompleteClassComponent";
|
22
|
+
WorkTag[WorkTag["DehydratedFragment"] = 18] = "DehydratedFragment";
|
23
|
+
WorkTag[WorkTag["SuspenseListComponent"] = 19] = "SuspenseListComponent";
|
24
|
+
WorkTag[WorkTag["FundamentalComponent"] = 20] = "FundamentalComponent";
|
25
|
+
WorkTag[WorkTag["ScopeComponent"] = 21] = "ScopeComponent";
|
25
26
|
})(WorkTag || (WorkTag = {}));
|
27
|
+
|
26
28
|
export function getReactFiberFromNode(elm) {
|
27
|
-
|
28
|
-
|
29
|
+
if (!elm) {
|
30
|
+
return null;
|
31
|
+
}
|
32
|
+
|
33
|
+
for (const k in elm) {
|
34
|
+
// React 16 uses "__reactInternalInstance$" prefix
|
35
|
+
// React 17 uses "__reactFiber$" prefix
|
36
|
+
// https://github.com/facebook/react/pull/18377
|
37
|
+
if (k.indexOf('__reactInternalInstance$') === 0 || k.indexOf('__reactFiber$') === 0) {
|
38
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
39
|
+
// @ts-ignore
|
40
|
+
return elm[k];
|
29
41
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
// https://github.com/facebook/react/pull/18377
|
34
|
-
if (k.indexOf('__reactInternalInstance$') === 0 || k.indexOf('__reactFiber$') === 0) {
|
35
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
36
|
-
// @ts-ignore
|
37
|
-
return elm[k];
|
38
|
-
}
|
39
|
-
}
|
40
|
-
throw new Error('getReactFiber(): Failed to find a React Fiber on a node');
|
42
|
+
}
|
43
|
+
|
44
|
+
throw new Error('getReactFiber(): Failed to find a React Fiber on a node');
|
41
45
|
}
|
42
46
|
//# sourceMappingURL=getReactFiberFromNode.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getReactFiberFromNode.js","sourceRoot":"","sources":["../../src/utils/getReactFiberFromNode.ts"],"names":[],"mappings":"AAuEA,IAAK,OAuBJ;AAvBD,WAAK,OAAO;IACV,+DAAqB,CAAA;IACrB,yDAAkB,CAAA;IAClB,yEAA0B,CAAA;IAC1B,6CAAY,CAAA;IACZ,iDAAc,CAAA;IACd,uDAAiB,CAAA;IACjB,6CAAY,CAAA;IACZ,6CAAY,CAAA;IACZ,qCAAQ,CAAA;IACR,2DAAmB,CAAA;IACnB,4DAAoB,CAAA;IACpB,kDAAe,CAAA;IACf,8CAAa,CAAA;IACb,gEAAsB,CAAA;IACtB,wDAAkB,CAAA;IAClB,oEAAwB,CAAA;IACxB,wDAAkB,CAAA;IAClB,8EAA6B,CAAA;IAC7B,kEAAuB,CAAA;IACvB,wEAA0B,CAAA;IAC1B,sEAAyB,CAAA;IACzB,0DAAmB,CAAA;AACrB,CAAC,EAvBI,OAAO,KAAP,OAAO,QAuBX;AA+JD,MAAM,UAAU,qBAAqB,CAAC,GAAqB;IACzD,IAAI,CAAC,GAAG,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AAU,0BAAV,MAA0C,CAA1C,IAA+C,CAAC,CAAC,OAAF,CAAU,eAAV,MAA+B,CAAlF,EAAqF;AACnF;AACA;AACA,aAAO,GAAG,CAAC,CAAD,CAAV;AACD;AACF;;AAED,QAAM,IAAI,KAAJ,CAAU,yDAAV,CAAN;AACD","sourcesContent":["import * as React from 'react';\n\n// ========================================================\n// react/packages/shared/ReactTypes.js\n// ========================================================\n\ntype ReactEventResponder<E, C> = {\n $$typeof: Symbol | number;\n displayName: string;\n targetEventTypes: null | string[];\n rootEventTypes: null | string[];\n getInitialState: null | ((props: Object) => Object);\n onEvent: null | ((event: E, context: C, props: Object, state: Object) => void);\n onRootEvent: null | ((event: E, context: C, props: Object, state: Object) => void);\n onMount: null | ((context: C, props: Object, state: Object) => void);\n onUnmount: null | ((context: C, props: Object, state: Object) => void);\n};\n\ntype ReactEventResponderInstance<E, C> = {\n fiber: Object;\n props: Object;\n responder: ReactEventResponder<E, C>;\n rootEventTypes: null | Set<string>;\n state: Object;\n};\n\n// ========================================================\n// react/packages/react-reconciler/src/ReactFiberHooks.js\n// ========================================================\n\nexport type HookType =\n | 'useState'\n | 'useReducer'\n | 'useContext'\n | 'useRef'\n | 'useEffect'\n | 'useLayoutEffect'\n | 'useCallback'\n | 'useMemo'\n | 'useImperativeHandle'\n | 'useDebugValue'\n | 'useResponder';\n\ntype ReactProviderType<T> = {\n $$typeof: Symbol | number;\n _context: ReactContext<T>;\n};\n\ntype ReactContext<T> = {\n $$typeof: Symbol | number;\n Consumer: ReactContext<T>;\n Provider: ReactProviderType<T>;\n\n _calculateChangedBits: ((a: T, b: T) => number) | null;\n\n _currentValue: T;\n _currentValue2: T;\n _threadCount: number;\n\n // DEV only\n _currentRenderer?: Object | null;\n _currentRenderer2?: Object | null;\n};\n\ntype ContextDependency<T> = {\n context: ReactContext<T>;\n observedBits: number;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n next: ContextDependency<any> | null;\n};\n\nenum WorkTag {\n FunctionComponent = 0,\n ClassComponent = 1,\n IndeterminateComponent = 2, // Before we know whether it is function or class\n HostRoot = 3, // Root of a host tree. Could be nested inside another node.\n HostPortal = 4, // A subtree. Could be an entry point to a different renderer.\n HostComponent = 5,\n HostText = 6,\n Fragment = 7,\n Mode = 8,\n ContextConsumer = 9,\n ContextProvider = 10,\n ForwardRef = 11,\n Profiler = 12,\n SuspenseComponent = 13,\n MemoComponent = 14,\n SimpleMemoComponent = 15,\n LazyComponent = 16,\n IncompleteClassComponent = 17,\n DehydratedFragment = 18,\n SuspenseListComponent = 19,\n FundamentalComponent = 20,\n ScopeComponent = 21,\n}\n\ntype Source = {\n fileName: string;\n lineNumber: number;\n};\n\ntype ExpirationTime = number;\n\ntype Dependencies = {\n expirationTime: ExpirationTime;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n firstContext: ContextDependency<any> | null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n responders: Map<ReactEventResponder<any, any>, ReactEventResponderInstance<any, any>> | null;\n};\n\n// ========================================================\n// react/packages/react-reconciler/src/ReactFiber.js\n// ========================================================\n\n// A Fiber is work on a Component that needs to be done or was done. There can\n// be more than one per component.\n\nexport type Fiber = {\n // These first fields are conceptually members of an Instance. This used to\n // be split into a separate type and intersected with the other Fiber fields,\n // but until Flow fixes its intersection bugs, we've merged them into a\n // single type.\n\n // An Instance is shared between all versions of a component. We can easily\n // break this out into a separate object to avoid copying so much to the\n // alternate versions of the tree. We put this on a single object for now to\n // minimize the number of objects created during the initial render.\n\n // Tag identifying the type of fiber.\n tag: WorkTag;\n\n // Unique identifier of this child.\n key: null | string;\n\n // The value of element.type which is used to preserve the identity during\n // reconciliation of this child.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n elementType: any;\n\n // The resolved function/class/ associated with this fiber.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n type: any;\n\n // The local state associated with this fiber.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stateNode: any;\n\n // Conceptual aliases\n // parent : Instance -> return The parent happens to be the same as the\n // return fiber since we've merged the fiber and instance.\n\n // Remaining fields belong to Fiber\n\n // The Fiber to return to after finishing processing this one.\n // This is effectively the parent, but there can be multiple parents (two)\n // so this is only the parent of the thing we're currently processing.\n // It is conceptually the same as the return address of a stack frame.\n return: Fiber | null;\n\n // Singly Linked List Tree Structure.\n child: Fiber | null;\n sibling: Fiber | null;\n index: number;\n\n // The ref last used to attach this node.\n // I'll avoid adding an owner field for prod and model that as functions.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref: React.Ref<any>;\n\n // Input is the data coming into process this fiber. Arguments. Props.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pendingProps: any; // This type will be more specific once we overload the tag.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n memoizedProps: any; // The props used to create the output.\n\n // A queue of state updates and callbacks.\n // updateQueue: UpdateQueue<any> | null,\n\n // The state used to create the output\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n memoizedState: any;\n\n // Dependencies (contexts, events) for this fiber, if it has any\n dependencies: Dependencies | null;\n\n // // Bitfield that describes properties about the fiber and its subtree. E.g.\n // // the ConcurrentMode flag indicates whether the subtree should be async-by-\n // // default. When a fiber is created, it inherits the mode of its\n // // parent. Additional flags can be set at creation time, but after that the\n // // value should remain unchanged throughout the fiber's lifetime, particularly\n // // before its child fibers are created.\n // mode: TypeOfMode\n //\n // // Effect\n // effectTag: SideEffectTag\n\n // Singly linked list fast path to the next fiber with side-effects.\n nextEffect: Fiber | null;\n\n // The first and last fiber with side-effect within this subtree. This allows\n // us to reuse a slice of the linked list when we reuse the work done within\n // this fiber.\n firstEffect: Fiber | null;\n lastEffect: Fiber | null;\n\n // Represents a time in the future by which this work should be completed.\n // Does not include work found in its subtree.\n expirationTime: ExpirationTime;\n\n // This is used to quickly determine if a subtree has no pending changes.\n childExpirationTime: ExpirationTime;\n\n // This is a pooled version of a Fiber. Every fiber that gets updated will\n // eventually have a pair. There are cases when we can clean up pairs to save\n // memory if we need to.\n alternate: Fiber | null;\n\n // Time spent rendering this Fiber and its descendants for the current update.\n // This tells us how well the tree makes use of sCU for memoization.\n // It is reset to 0 each time we render and only updated when we don't bailout.\n // This field is only set when the enableProfilerTimer flag is enabled.\n actualDuration?: number;\n\n // If the Fiber is currently active in the \"render\" phase,\n // This marks the time at which the work began.\n // This field is only set when the enableProfilerTimer flag is enabled.\n actualStartTime?: number;\n\n // Duration of the most recent render time for this Fiber.\n // This value is not updated when we bailout for memoization purposes.\n // This field is only set when the enableProfilerTimer flag is enabled.\n selfBaseDuration?: number;\n\n // Sum of base times for all descendants of this Fiber.\n // This value bubbles up during the \"complete\" phase.\n // This field is only set when the enableProfilerTimer flag is enabled.\n treeBaseDuration?: number;\n\n // Conceptual aliases\n // workInProgress : Fiber -> alternate The alternate used for reuse happens\n // to be the same as work in progress.\n // __DEV__ only\n _debugID?: number;\n _debugSource?: Source | null;\n _debugOwner?: Fiber | null;\n _debugIsCurrentlyTiming?: boolean;\n _debugNeedsRemount?: boolean;\n\n // Used to verify that the order of hooks does not change between renders.\n _debugHookTypes?: HookType[] | null;\n};\n\nexport function getReactFiberFromNode(elm: Node | undefined): Fiber | null {\n if (!elm) {\n return null;\n }\n\n for (const k in elm) {\n // React 16 uses \"__reactInternalInstance$\" prefix\n // React 17 uses \"__reactFiber$\" prefix\n // https://github.com/facebook/react/pull/18377\n if (k.indexOf('__reactInternalInstance$') === 0 || k.indexOf('__reactFiber$') === 0) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return elm[k];\n }\n }\n\n throw new Error('getReactFiber(): Failed to find a React Fiber on a node');\n}\n"],"sourceRoot":"../src/"}
|
@@ -3,49 +3,63 @@
|
|
3
3
|
* @param node - DOM node.
|
4
4
|
* @returns - parent DOM node.
|
5
5
|
*/
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
export const getParentNode = node => {
|
7
|
+
if (node.nodeName === 'HTML') {
|
8
|
+
return node;
|
9
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
|
+
|
11
|
+
|
12
|
+
return node.parentNode || node.host;
|
12
13
|
};
|
13
14
|
/**
|
14
15
|
* Returns CSS styles of the given node.
|
15
16
|
* @param node - DOM node.
|
16
17
|
* @returns - CSS styles.
|
17
18
|
*/
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
|
20
|
+
const getStyleComputedProperty = node => {
|
21
|
+
var _a;
|
22
|
+
|
23
|
+
if (node.nodeType !== 1) {
|
24
|
+
return {};
|
25
|
+
}
|
26
|
+
|
27
|
+
const window = (_a = node.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
|
28
|
+
return window.getComputedStyle(node, null);
|
25
29
|
};
|
26
30
|
/**
|
27
31
|
* Returns the first scrollable parent of the given element.
|
28
32
|
* @param node - DOM node.
|
29
33
|
* @returns - the first scrollable parent.
|
30
34
|
*/
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
35
|
+
|
36
|
+
|
37
|
+
export const getScrollParent = node => {
|
38
|
+
// Return body, `getScroll` will take care to get the correct `scrollTop` from it
|
39
|
+
const parentNode = node && getParentNode(node); // eslint-disable-next-line
|
40
|
+
|
41
|
+
if (!parentNode) return document.body;
|
42
|
+
|
43
|
+
switch (parentNode.nodeName) {
|
44
|
+
case 'HTML':
|
45
|
+
case 'BODY':
|
46
|
+
return parentNode.ownerDocument.body;
|
47
|
+
|
48
|
+
case '#document':
|
49
|
+
return parentNode.body;
|
50
|
+
} // If any of the overflow props is defined for the node then we return it as the parent
|
51
|
+
|
52
|
+
|
53
|
+
const {
|
54
|
+
overflow,
|
55
|
+
overflowX,
|
56
|
+
overflowY
|
57
|
+
} = getStyleComputedProperty(parentNode);
|
58
|
+
|
59
|
+
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
|
60
|
+
return parentNode;
|
61
|
+
}
|
62
|
+
|
63
|
+
return getScrollParent(parentNode);
|
50
64
|
};
|
51
65
|
//# sourceMappingURL=getScrollParent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["utils/getScrollParent.ts"],"names":[],"mappings":"AAAA;;;;AAIG;AACH,OAAO,MAAM,aAAa,GAAI,IAAD,IAAmC;AAC9D,MAAI,IAAI,CAAC,QAAL,KAAkB,MAAtB,EAA8B;AAC5B,WAAO,IAAP;AACD,GAH6D,CAI9D;;;AACA,SAAO,IAAI,CAAC,UAAL,IAAoB,IAAY,CAAC,IAAxC;AACD,CANM;AAQP;;;;AAIG;;AACH,MAAM,wBAAwB,GAAI,IAAD,IAAoD;;;AACnF,MAAI,IAAI,CAAC,QAAL,KAAkB,CAAtB,EAAyB;AACvB,WAAO,EAAP;AACD;;AAED,QAAM,MAAM,GAAG,CAAA,EAAA,GAAA,IAAI,CAAC,aAAL,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,KAAA,CAAlB,GAAkB,EAAA,CAAE,WAAnC;AACA,SAAO,MAAO,CAAC,gBAAR,CAAyB,IAAzB,EAA+B,IAA/B,CAAP;AACD,CAPD;AASA;;;;AAIG;;;AACH,OAAO,MAAM,eAAe,GAAI,IAAD,IAAqD;AAClF;AACA,QAAM,UAAU,GAAG,IAAI,IAAI,aAAa,CAAC,IAAD,CAAxC,CAFkF,CAGlF;;AACA,MAAI,CAAC,UAAL,EAAiB,OAAO,QAAQ,CAAC,IAAhB;;AAEjB,UAAQ,UAAU,CAAC,QAAnB;AACE,SAAK,MAAL;AACA,SAAK,MAAL;AACE,aAAO,UAAU,CAAC,aAAX,CAA0B,IAAjC;;AACF,SAAK,WAAL;AACE,aAAS,UAAmC,CAAC,IAA7C;AALJ,GANkF,CAclF;;;AACA,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,SAAZ;AAAuB,IAAA;AAAvB,MAAqC,wBAAwB,CAAC,UAAD,CAAnE;;AACA,MAAI,wBAAwB,IAAxB,CAA6B,QAAS,GAAG,SAAZ,GAAyB,SAAtD,CAAJ,EAAsE;AACpE,WAAO,UAAP;AACD;;AAED,SAAO,eAAe,CAAC,UAAD,CAAtB;AACD,CArBM","sourcesContent":["/**\n * Returns the parent node or the host of the node argument.\n * @param node - DOM node.\n * @returns - parent DOM node.\n */\nexport const getParentNode = (node: HTMLElement): HTMLElement => {\n if (node.nodeName === 'HTML') {\n return node;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return node.parentNode || (node as any).host;\n};\n\n/**\n * Returns CSS styles of the given node.\n * @param node - DOM node.\n * @returns - CSS styles.\n */\nconst getStyleComputedProperty = (node: HTMLElement): Partial<CSSStyleDeclaration> => {\n if (node.nodeType !== 1) {\n return {};\n }\n\n const window = node.ownerDocument?.defaultView;\n return window!.getComputedStyle(node, null);\n};\n\n/**\n * Returns the first scrollable parent of the given element.\n * @param node - DOM node.\n * @returns - the first scrollable parent.\n */\nexport const getScrollParent = (node: Document | HTMLElement | null): HTMLElement => {\n // Return body, `getScroll` will take care to get the correct `scrollTop` from it\n const parentNode = node && getParentNode(node as HTMLElement);\n // eslint-disable-next-line\n if (!parentNode) return document.body;\n\n switch (parentNode.nodeName) {\n case 'HTML':\n case 'BODY':\n return parentNode.ownerDocument!.body;\n case '#document':\n return ((parentNode as unknown) as Document).body;\n }\n\n // If any of the overflow props is defined for the node then we return it as the parent\n const { overflow, overflowX, overflowY } = getStyleComputedProperty(parentNode);\n if (/(auto|scroll|overlay)/.test(overflow! + overflowY! + overflowX)) {\n return parentNode;\n }\n\n return getScrollParent(parentNode);\n};\n"],"sourceRoot":"../src/"}
|
package/lib/utils/index.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
export * from './getBasePlacement';
|
2
1
|
export * from './getBoundary';
|
3
2
|
export * from './getReactFiberFromNode';
|
4
3
|
export * from './getScrollParent';
|
@@ -6,4 +5,5 @@ export * from './mergeArrowOffset';
|
|
6
5
|
export * from './positioningHelper';
|
7
6
|
export * from './resolvePositioningShorthand';
|
8
7
|
export * from './useCallbackRef';
|
8
|
+
export * from './parsePopperPlacement';
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from './getBoundary';\nexport * from './getReactFiberFromNode';\nexport * from './getScrollParent';\nexport * from './mergeArrowOffset';\nexport * from './positioningHelper';\nexport * from './resolvePositioningShorthand';\nexport * from './useCallbackRef';\nexport * from './parsePopperPlacement';\n"]}
|
@@ -7,31 +7,37 @@
|
|
7
7
|
* @returns User offset augmented with arrow height
|
8
8
|
*/
|
9
9
|
export function mergeArrowOffset(userOffset, arrowHeight) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
10
|
+
if (typeof userOffset === 'number') {
|
11
|
+
return addArrowOffset(userOffset, arrowHeight);
|
12
|
+
}
|
13
|
+
|
14
|
+
if (typeof userOffset === 'object' && userOffset !== null) {
|
15
|
+
return addArrowOffset(userOffset, arrowHeight);
|
16
|
+
}
|
17
|
+
|
18
|
+
if (typeof userOffset === 'function') {
|
19
|
+
return offsetParams => {
|
20
|
+
const offset = userOffset(offsetParams);
|
21
|
+
return addArrowOffset(offset, arrowHeight);
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
return {
|
26
|
+
mainAxis: arrowHeight
|
27
|
+
};
|
28
28
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
|
30
|
+
const addArrowOffset = (offset, arrowHeight) => {
|
31
|
+
var _a;
|
32
|
+
|
33
|
+
if (typeof offset === 'number') {
|
34
|
+
return {
|
35
|
+
mainAxis: offset + arrowHeight
|
36
|
+
};
|
37
|
+
}
|
38
|
+
|
39
|
+
return { ...offset,
|
40
|
+
mainAxis: ((_a = offset.mainAxis) !== null && _a !== void 0 ? _a : 0) + arrowHeight
|
41
|
+
};
|
36
42
|
};
|
37
43
|
//# sourceMappingURL=mergeArrowOffset.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["utils/mergeArrowOffset.ts"],"names":[],"mappings":"AAEA;;;;;;;AAOG;AACH,OAAM,SAAU,gBAAV,CAA2B,UAA3B,EAAkE,WAAlE,EAAqF;AACzF,MAAI,OAAO,UAAP,KAAsB,QAA1B,EAAoC;AAClC,WAAO,cAAc,CAAC,UAAD,EAAa,WAAb,CAArB;AACD;;AAED,MAAI,OAAO,UAAP,KAAsB,QAAtB,IAAkC,UAAU,KAAK,IAArD,EAA2D;AACzD,WAAO,cAAc,CAAC,UAAD,EAAa,WAAb,CAArB;AACD;;AAED,MAAI,OAAO,UAAP,KAAsB,UAA1B,EAAsC;AACpC,WAAO,YAAY,IAAG;AACpB,YAAM,MAAM,GAAG,UAAU,CAAC,YAAD,CAAzB;AACA,aAAO,cAAc,CAAC,MAAD,EAAS,WAAT,CAArB;AACD,KAHD;AAID;;AAED,SAAO;AAAE,IAAA,QAAQ,EAAE;AAAZ,GAAP;AACD;;AAED,MAAM,cAAc,GAAG,CAAC,MAAD,EAAgC,WAAhC,KAAqE;;;AAC1F,MAAI,OAAO,MAAP,KAAkB,QAAtB,EAAgC;AAC9B,WAAO;AAAE,MAAA,QAAQ,EAAE,MAAM,GAAG;AAArB,KAAP;AACD;;AAED,SAAO,EAAE,GAAG,MAAL;AAAa,IAAA,QAAQ,EAAE,CAAC,CAAA,EAAA,GAAA,MAAM,CAAC,QAAP,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,EAAf,GAAmB,CAApB,IAAyB;AAAhD,GAAP;AACD,CAND","sourcesContent":["import type { Offset, OffsetObject } from '../types';\n\n/**\n * Generally when adding an arrow to popper, it's necessary to offset the position of the popper by the\n * height of the arrow. A simple utility to merge a provided offset with an arrow height to return the final offset\n *\n * @param userOffset - The offset provided by the user\n * @param arrowHeight - The height of the arrow in px\n * @returns User offset augmented with arrow height\n */\nexport function mergeArrowOffset(userOffset: Offset | undefined | null, arrowHeight: number): Offset {\n if (typeof userOffset === 'number') {\n return addArrowOffset(userOffset, arrowHeight);\n }\n\n if (typeof userOffset === 'object' && userOffset !== null) {\n return addArrowOffset(userOffset, arrowHeight);\n }\n\n if (typeof userOffset === 'function') {\n return offsetParams => {\n const offset = userOffset(offsetParams);\n return addArrowOffset(offset, arrowHeight);\n };\n }\n\n return { mainAxis: arrowHeight };\n}\n\nconst addArrowOffset = (offset: OffsetObject | number, arrowHeight: number): OffsetObject => {\n if (typeof offset === 'number') {\n return { mainAxis: offset + arrowHeight };\n }\n\n return { ...offset, mainAxis: (offset.mainAxis ?? 0) + arrowHeight };\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* Parses Popper placement and returns the different components
|
3
|
+
* @param placement - the Popper.js placement (i.e. bottom-start)
|
4
|
+
*
|
5
|
+
* @returns side and alignment components of the placement
|
6
|
+
*/
|
7
|
+
export function parsePopperPlacement(placement) {
|
8
|
+
const tokens = placement.split('-');
|
9
|
+
return {
|
10
|
+
basePlacement: tokens[0],
|
11
|
+
alignment: tokens[1]
|
12
|
+
};
|
13
|
+
}
|
14
|
+
//# sourceMappingURL=parsePopperPlacement.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils/parsePopperPlacement.ts"],"names":[],"mappings":"AAEA;;;;;AAKG;AACH,OAAM,SAAU,oBAAV,CAA+B,SAA/B,EAAmD;AACvD,QAAM,MAAM,GAAG,SAAS,CAAC,KAAV,CAAgB,GAAhB,CAAf;AACA,SAAO;AACL,IAAA,aAAa,EAAE,MAAM,CAAC,CAAD,CADhB;AAEL,IAAA,SAAS,EAAE,MAAM,CAAC,CAAD;AAFZ,GAAP;AAID","sourcesContent":["import type { BasePlacement, Placement, Variation } from '@popperjs/core';\n\n/**\n * Parses Popper placement and returns the different components\n * @param placement - the Popper.js placement (i.e. bottom-start)\n *\n * @returns side and alignment components of the placement\n */\nexport function parsePopperPlacement(placement: Placement): { basePlacement: BasePlacement; alignment: Variation } {\n const tokens = placement.split('-');\n return {\n basePlacement: tokens[0] as BasePlacement,\n alignment: tokens[1] as Variation,\n };\n}\n"],"sourceRoot":"../src/"}
|
@@ -1,41 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
});
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
const getPositionMap = rtl => ({
|
2
|
+
above: 'top',
|
3
|
+
below: 'bottom',
|
4
|
+
before: rtl ? 'right' : 'left',
|
5
|
+
after: rtl ? 'left' : 'right'
|
6
|
+
});
|
7
|
+
|
8
|
+
const getAlignmentMap = rtl => ({
|
9
|
+
start: rtl ? 'end' : 'start',
|
10
|
+
end: rtl ? 'start' : 'end',
|
11
|
+
top: 'start',
|
12
|
+
bottom: 'end',
|
13
|
+
center: ''
|
14
|
+
});
|
15
|
+
|
16
|
+
const shouldAlignToCenter = (p, a) => {
|
17
|
+
const positionedVertically = p === 'above' || p === 'below';
|
18
|
+
const alignedVertically = a === 'top' || a === 'bottom';
|
19
|
+
return positionedVertically && alignedVertically || !positionedVertically && !alignedVertically;
|
18
20
|
};
|
19
21
|
/**
|
20
22
|
* @see positioninHelper.test.ts for expected placement values
|
21
23
|
*/
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
|
25
|
+
|
26
|
+
export const getPlacement = (align, position, rtl) => {
|
27
|
+
const alignment = shouldAlignToCenter(position, align) ? 'center' : align;
|
28
|
+
const computedPosition = position && getPositionMap(rtl)[position];
|
29
|
+
const computedAlignmnent = alignment && getAlignmentMap(rtl)[alignment];
|
30
|
+
|
31
|
+
if (computedPosition && computedAlignmnent) {
|
32
|
+
return `${computedPosition}-${computedAlignmnent}`;
|
33
|
+
}
|
34
|
+
|
35
|
+
return computedPosition || 'auto';
|
30
36
|
};
|
31
|
-
export
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
export const applyRtlToOffset = offset => {
|
38
|
+
if (typeof offset === 'undefined') {
|
39
|
+
return undefined;
|
40
|
+
}
|
41
|
+
|
42
|
+
if (Array.isArray(offset)) {
|
43
|
+
offset[0] = offset[0] * -1;
|
44
|
+
return offset;
|
45
|
+
}
|
46
|
+
|
47
|
+
return param => applyRtlToOffset(offset(param));
|
40
48
|
};
|
41
49
|
//# sourceMappingURL=positioningHelper.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["utils/positioningHelper.ts"],"names":[],"mappings":"AAOA,MAAM,cAAc,GAAI,GAAD,KAAyD;AAC9E,EAAA,KAAK,EAAE,KADuE;AAE9E,EAAA,KAAK,EAAE,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AO,MAAP,KAAkB,WAAtB,EAAmC;AACjC,WAAO,SAAP;AACD;;AAED,MAAI,KAAK,CAAC,OAAN,CAAc,MAAd,CAAJ,EAA2B;AACzB,IAAA,MAAM,CAAC,CAAD,CAAN,GAAY,MAAM,CAAC,CAAD,CAAN,GAAa,CAAC,CAA1B;AAEA,WAAO,MAAP;AACD;;AAED,SAAS,KAAD,IAAsC,gBAAgB,CAAC,MAAM,CAAC,KAAD,CAAP,CAA9D;AACD,CAZM","sourcesContent":["import * as PopperJs from '@popperjs/core';\nimport type { Alignment, Position } from '../types';\nimport { PopperOffset, PopperOffsetFunction, PopperOffsetFunctionParam } from './getPopperOffset';\n\ntype PlacementPosition = 'top' | 'bottom' | 'left' | 'right';\ntype PlacementAlign = 'start' | 'end' | ''; // '' represents center\n\nconst getPositionMap = (rtl?: boolean): Record<Position, PlacementPosition> => ({\n above: 'top',\n below: 'bottom',\n before: rtl ? 'right' : 'left',\n after: rtl ? 'left' : 'right',\n});\n\nconst getAlignmentMap = (rtl?: boolean): Record<Alignment, PlacementAlign> => ({\n start: rtl ? 'end' : 'start',\n end: rtl ? 'start' : 'end',\n top: 'start',\n bottom: 'end',\n center: '',\n});\n\nconst shouldAlignToCenter = (p?: Position, a?: Alignment): boolean => {\n const positionedVertically = p === 'above' || p === 'below';\n const alignedVertically = a === 'top' || a === 'bottom';\n\n return (positionedVertically && alignedVertically) || (!positionedVertically && !alignedVertically);\n};\n\n/**\n * @see positioninHelper.test.ts for expected placement values\n */\nexport const getPlacement = (align?: Alignment, position?: Position, rtl?: boolean): PopperJs.Placement => {\n const alignment = shouldAlignToCenter(position, align) ? 'center' : align;\n\n const computedPosition = position && getPositionMap(rtl)[position];\n const computedAlignmnent = alignment && getAlignmentMap(rtl)[alignment];\n\n if (computedPosition && computedAlignmnent) {\n return `${computedPosition}-${computedAlignmnent}` as PopperJs.Placement;\n }\n\n return computedPosition || ('auto' as PopperJs.Placement);\n};\n\nexport const applyRtlToOffset = (offset: PopperOffset | undefined): PopperOffset | undefined => {\n if (typeof offset === 'undefined') {\n return undefined;\n }\n\n if (Array.isArray(offset)) {\n offset[0] = offset[0]! * -1;\n\n return offset;\n }\n\n return ((param: PopperOffsetFunctionParam) => applyRtlToOffset(offset(param))) as PopperOffsetFunction;\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,25 +1,63 @@
|
|
1
1
|
// Look up table for shorthand to avoid parsing strings
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
2
|
+
const shorthandLookup = {
|
3
|
+
above: {
|
4
|
+
position: 'above',
|
5
|
+
align: 'center'
|
6
|
+
},
|
7
|
+
'above-start': {
|
8
|
+
position: 'above',
|
9
|
+
align: 'start'
|
10
|
+
},
|
11
|
+
'above-end': {
|
12
|
+
position: 'above',
|
13
|
+
align: 'end'
|
14
|
+
},
|
15
|
+
below: {
|
16
|
+
position: 'below',
|
17
|
+
align: 'center'
|
18
|
+
},
|
19
|
+
'below-start': {
|
20
|
+
position: 'below',
|
21
|
+
align: 'start'
|
22
|
+
},
|
23
|
+
'below-end': {
|
24
|
+
position: 'below',
|
25
|
+
align: 'end'
|
26
|
+
},
|
27
|
+
before: {
|
28
|
+
position: 'before',
|
29
|
+
align: 'center'
|
30
|
+
},
|
31
|
+
'before-top': {
|
32
|
+
position: 'before',
|
33
|
+
align: 'top'
|
34
|
+
},
|
35
|
+
'before-bottom': {
|
36
|
+
position: 'before',
|
37
|
+
align: 'bottom'
|
38
|
+
},
|
39
|
+
after: {
|
40
|
+
position: 'after',
|
41
|
+
align: 'center'
|
42
|
+
},
|
43
|
+
'after-top': {
|
44
|
+
position: 'after',
|
45
|
+
align: 'top'
|
46
|
+
},
|
47
|
+
'after-bottom': {
|
48
|
+
position: 'after',
|
49
|
+
align: 'bottom'
|
50
|
+
}
|
15
51
|
};
|
16
52
|
export function resolvePositioningShorthand(shorthand) {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
53
|
+
if (shorthand === undefined || shorthand === null) {
|
54
|
+
return {};
|
55
|
+
}
|
56
|
+
|
57
|
+
if (typeof shorthand === 'string') {
|
58
|
+
return shorthandLookup[shorthand];
|
59
|
+
}
|
60
|
+
|
61
|
+
return shorthand;
|
24
62
|
}
|
25
63
|
//# sourceMappingURL=resolvePositioningShorthand.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["utils/resolvePositioningShorthand.ts"],"names":[],"mappings":"AAEA;AACA,MAAM,eAAe,GAAoF;AACvG,EAAA,KAAK,EAAE;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GADgG;AAEvG,iBAAe;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAFwF;AAGvG,eAAa;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAH0F;AAIvG,EAAA,KAAK,EAAE;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAJgG;AAKvG,iBAAe;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GALwF;AAMvG,eAAa;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAN0F;AAOvG,EAAA,MAAM,EAAE;AAAE,IAAA,QAAQ,EAAE,QAAZ;AAAsB,IAAA,KAAK,EAAE;AAA7B,GAP+F;AAQvG,gBAAc;AAAE,IAAA,QAAQ,EAAE,QAAZ;AAAsB,IAAA,KAAK,EAAE;AAA7B,GARyF;AASvG,mBAAiB;AAAE,IAAA,QAAQ,EAAE,QAAZ;AAAsB,IAAA,KAAK,EAAE;AAA7B,GATsF;AAUvG,EAAA,KAAK,EAAE;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAVgG;AAWvG,eAAa;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B,GAX0F;AAYvG,kBAAgB;AAAE,IAAA,QAAQ,EAAE,OAAZ;AAAqB,IAAA,KAAK,EAAE;AAA5B;AAZuF,CAAzG;AAeA,OAAM,SAAU,2BAAV,CACJ,SADI,EAC8C;AAElD,MAAI,SAAS,KAAK,SAAd,IAA2B,SAAS,KAAK,IAA7C,EAAmD;AACjD,WAAO,EAAP;AACD;;AAED,MAAI,OAAO,SAAP,KAAqB,QAAzB,EAAmC;AACjC,WAAO,eAAe,CAAC,SAAD,CAAtB;AACD;;AAED,SAAO,SAAP;AACD","sourcesContent":["import type { PositioningShorthand, PositioningShorthandValue, PositioningProps } from '../types';\n\n// Look up table for shorthand to avoid parsing strings\nconst shorthandLookup: Record<PositioningShorthandValue, Pick<PositioningProps, 'position' | 'align'>> = {\n above: { position: 'above', align: 'center' },\n 'above-start': { position: 'above', align: 'start' },\n 'above-end': { position: 'above', align: 'end' },\n below: { position: 'below', align: 'center' },\n 'below-start': { position: 'below', align: 'start' },\n 'below-end': { position: 'below', align: 'end' },\n before: { position: 'before', align: 'center' },\n 'before-top': { position: 'before', align: 'top' },\n 'before-bottom': { position: 'before', align: 'bottom' },\n after: { position: 'after', align: 'center' },\n 'after-top': { position: 'after', align: 'top' },\n 'after-bottom': { position: 'after', align: 'bottom' },\n};\n\nexport function resolvePositioningShorthand(\n shorthand: PositioningShorthand | undefined | null,\n): Readonly<PositioningProps> {\n if (shorthand === undefined || shorthand === null) {\n return {};\n }\n\n if (typeof shorthand === 'string') {\n return shorthandLookup[shorthand];\n }\n\n return shorthand as Readonly<PositioningProps>;\n}\n"],"sourceRoot":"../src/"}
|