@khanacademy/wonder-blocks-floating 0.2.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/dist/es/index.css +29 -0
- package/dist/es/index.css.map +1 -0
- package/dist/es/index.js +7 -6
- package/dist/index.css +29 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +6 -4
- package/package.json +19 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-floating
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- f52e4cd: Add an `exports` map (`.` and `./css`) and `"sideEffects": ["**/*.css"]` to the package.json. `./css` is the component stylesheet. It's conditional: `import` resolves to `dist/es/index.css` and `require` to `dist/index.css`, the same copy each JS entry already loads, so importing `./css` too doesn't duplicate the CSS.
|
|
8
|
+
|
|
9
|
+
**Breaking:** the new `exports` map blocks deep imports such as `@khanacademy/wonder-blocks-core/dist/...`. Import from the package root instead. No deep imports of these packages were found in Khan/frontend or Khan/perseus.
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 1611067: Migrate `Floating` from Aphrodite to CSS Modules (WB-2335, CSS Modules Phase 5
|
|
14
|
+
/ Wave G). The public component API is unchanged: same props, DOM structure,
|
|
15
|
+
and `styles.root` override.
|
|
16
|
+
|
|
17
|
+
- The floating element's surface styles (background, border, radius, shadow,
|
|
18
|
+
minimum size, outline reset) now live in `floating.module.css`. The
|
|
19
|
+
floating-ui position styles and the `visibility` toggle are still applied
|
|
20
|
+
inline.
|
|
21
|
+
- `@khanacademy/wonder-blocks-core` is now declared as a dependency. `Floating`
|
|
22
|
+
already imported it, but because it wasn't declared, the build inlined a
|
|
23
|
+
private copy of core into this package's bundle. Core is now an external
|
|
24
|
+
import, like in every other package.
|
|
25
|
+
- The package now ships `dist/index.css` (auto side-effect import) and marks
|
|
26
|
+
`**/*.css` as `sideEffects`. `aphrodite` is dropped from `peerDependencies`
|
|
27
|
+
(the package no longer imports it).
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 9652f57: Load each package's CSS after the CSS of the Wonder Blocks packages it depends
|
|
32
|
+
on. The published JS imported its own `index.css` before its dependencies, so
|
|
33
|
+
bundlers emitted, for example, Button's CSS before Typography's. Both sit in
|
|
34
|
+
`@layer shared` with single-class selectors, so the later `BodyText` rule won and
|
|
35
|
+
Button labels lost their own `font-weight`, `line-height` and `font-size`. The CSS
|
|
36
|
+
import now comes after the dependency imports, matching the source order that
|
|
37
|
+
Storybook already uses.
|
|
38
|
+
- c7b0d66: Hide `Floating` (while its reference element is out of view) and `Tooltip`'s bubble (until it's positioned) with a CSS class instead of an inline `visibility` style. Since plain style objects now render as the `style` attribute, the inline style made content inaccessible to Testing Library queries in consumer tests: jsdom has no layout, so floating-ui always reports the reference element as hidden there.
|
|
39
|
+
- Updated dependencies [0c6d97d]
|
|
40
|
+
- Updated dependencies [185dbbc]
|
|
41
|
+
- Updated dependencies [0b6c478]
|
|
42
|
+
- Updated dependencies [9652f57]
|
|
43
|
+
- Updated dependencies [f52e4cd]
|
|
44
|
+
- Updated dependencies [b66b7b7]
|
|
45
|
+
- Updated dependencies [dbb8f0f]
|
|
46
|
+
- Updated dependencies [ad52f4b]
|
|
47
|
+
- @khanacademy/wonder-blocks-tokens@18.3.0
|
|
48
|
+
- @khanacademy/wonder-blocks-core@13.0.0
|
|
49
|
+
|
|
50
|
+
## 0.2.3
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- Updated dependencies [d4df210]
|
|
55
|
+
- @khanacademy/wonder-blocks-tokens@18.2.1
|
|
56
|
+
|
|
3
57
|
## 0.2.2
|
|
4
58
|
|
|
5
59
|
### Patch Changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@layer shared {/* Styles for `Floating`. The build wraps these rules in `@layer shared { … }`
|
|
2
|
+
* via the wrap-in-layer plugin in `postcss.config.cjs`. */.wb-floating-floating-1d1144e4 {
|
|
3
|
+
background: var(--wb-semanticColor-core-background-base-default);
|
|
4
|
+
border: solid var(--wb-border-width-thin)
|
|
5
|
+
var(--wb-semanticColor-core-border-neutral-subtle);
|
|
6
|
+
border-radius: var(--wb-border-radius-radius_040);
|
|
7
|
+
|
|
8
|
+
/* Allow the floating element to be at least as tall as the arrow. We set
|
|
9
|
+
* inline size to ensure that it works with inline placements. Keep in sync
|
|
10
|
+
* with `ARROW_SIZE_INLINE` in `util/constants.ts`. */
|
|
11
|
+
min-block-size: 20px;
|
|
12
|
+
box-shadow: var(--wb-boxShadow-mid);
|
|
13
|
+
justify-content: center;
|
|
14
|
+
|
|
15
|
+
/* Prevent the floating element from receiving focus when it is clicked. */
|
|
16
|
+
outline: none;
|
|
17
|
+
}.wb-floating-constrained-1d1144e4 {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
}/* Applied while the reference element is out of view (see `isHidden` in
|
|
21
|
+
* `floating.tsx`). This is a class rather than an inline style on purpose:
|
|
22
|
+
* jsdom has no layout, so floating-ui always reports the reference as hidden
|
|
23
|
+
* in tests. Consumer test setups mock CSS, so a class keeps the content
|
|
24
|
+
* visible there, while an inline `visibility: hidden` would hide it from
|
|
25
|
+
* Testing Library queries. */.wb-floating-hidden-1d1144e4 {
|
|
26
|
+
visibility: hidden;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../../src/components/floating.module.css"],"names":[],"mappings":"AAAA,eCAA;0DAC0D,CAE1D;IACI,gEAAgE;IAChE;0DACsD;IACtD,iDAAiD;;IAEjD;;yDAEqD;IACrD,oBAAoB;IACpB,mCAAmC;IACnC,uBAAuB;;IAEvB,0EAA0E;IAC1E,aAAa;AACjB,CAEA;IACI,aAAa;IACb,sBAAsB;AAC1B,CAEA;;;;;6BAK6B,CAC7B;IACI,kBAAkB;AACtB;CDjCA","file":"index.css","sourcesContent":[null,"/* Styles for `Floating`. The build wraps these rules in `@layer shared { … }`\n * via the wrap-in-layer plugin in `postcss.config.cjs`. */\n\n.floating {\n background: var(--wb-semanticColor-core-background-base-default);\n border: solid var(--wb-border-width-thin)\n var(--wb-semanticColor-core-border-neutral-subtle);\n border-radius: var(--wb-border-radius-radius_040);\n\n /* Allow the floating element to be at least as tall as the arrow. We set\n * inline size to ensure that it works with inline placements. Keep in sync\n * with `ARROW_SIZE_INLINE` in `util/constants.ts`. */\n min-block-size: 20px;\n box-shadow: var(--wb-boxShadow-mid);\n justify-content: center;\n\n /* Prevent the floating element from receiving focus when it is clicked. */\n outline: none;\n}\n\n.constrained {\n display: flex;\n flex-direction: column;\n}\n\n/* Applied while the reference element is out of view (see `isHidden` in\n * `floating.tsx`). This is a class rather than an inline style on purpose:\n * jsdom has no layout, so floating-ui always reports the reference as hidden\n * in tests. Consumer test setups mock CSS, so a class keeps the content\n * visible there, while an inline `visibility: hidden` would hide it from\n * Testing Library queries. */\n.hidden {\n visibility: hidden;\n}"]}
|
package/dist/es/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
3
|
import { FloatingArrow, FloatingPortal, useFloating, autoUpdate, offset, flip, shift, size, arrow, hide, useDismiss, useInteractions, useMergeRefs, FloatingFocusManager } from '@floating-ui/react';
|
|
5
4
|
export { useMergeRefs } from '@floating-ui/react';
|
|
6
|
-
import {
|
|
7
|
-
import { semanticColor
|
|
8
|
-
|
|
9
|
-
function flatten(list){const result=[];if(!list){return result}else if(Array.isArray(list)){for(const item of list){result.push(...flatten(item));}}else {result.push(list);}return result}function processStyleList(style){const stylesheetStyles=[];const inlineStyles=[];if(!style){return {style:{},className:""}}const shouldInlineStyles=typeof global!=="undefined"&&global.SNAPSHOT_INLINE_APHRODITE;flatten(style).forEach(child=>{const _definition=child._definition;if(_definition!=null){if(shouldInlineStyles){const def={};for(const[key,value]of Object.entries(_definition)){def[key.replace(/-[a-z]/g,match=>match[1].toUpperCase())]=value;}inlineStyles.push(def);}else {stylesheetStyles.push(child);}}else {inlineStyles.push(child);}});const inlineStylesObject=Object.assign({},...inlineStyles);if(inlineStyles.length>0&&!shouldInlineStyles){const inlineStylesStyleSheet=StyleSheet.create({inlineStyles:inlineStylesObject});stylesheetStyles.push(inlineStylesStyleSheet.inlineStyles);}return {style:shouldInlineStyles?inlineStylesObject:{},className:css(...stylesheetStyles)}}const isHeaderRegex=/^h[1-6]$/;const styles$1=StyleSheet.create({text:{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale"},header:{marginBlockStart:0,marginBlockEnd:0}});React.forwardRef(function Text({children,style,tag="span",testId,...otherProps},ref){const Tag=tag;const isHeader=isHeaderRegex.test(tag);const styleAttributes=processStyleList([styles$1.text,isHeader&&styles$1.header,style]);const classNames=otherProps.className?[otherProps.className,styleAttributes.className].join(" "):styleAttributes.className;return jsx(Tag,{...otherProps,style:styleAttributes.style,className:classNames,"data-testid":testId,ref:ref,children:children})});function addStyle(Component,defaultStyle){return React.forwardRef((props,ref)=>{const{className,style,...otherProps}=props;const reset=typeof Component==="string"?overrides[Component]:null;const{className:aphroditeClassName,style:inlineStyles}=processStyleList([reset,defaultStyle,style]);return jsx(Component,{...otherProps,ref:ref,className:[aphroditeClassName,className].filter(Boolean).join(" "),style:inlineStyles})})}const overrides=StyleSheet.create({button:{margin:0,"::-moz-focus-inner":{border:0}}});const styles$2=StyleSheet.create({default:{alignItems:"stretch",borderWidth:0,borderStyle:"solid",boxSizing:"border-box",display:"flex",flexDirection:"column",margin:0,padding:0,position:"relative",zIndex:0,minBlockSize:0,minInlineSize:0}});React.forwardRef(function View(props,ref){const{testId,tag="div",...restProps}=props;const commonProps={...restProps,"data-testid":testId};const StyledTag=useMemo(()=>addStyle(tag,styles$2.default),[tag]);return jsx(StyledTag,{...commonProps,ref:ref})});(function(RenderState){RenderState["Initial"]="initial";RenderState["Standard"]="standard";return RenderState})({});(function(RenderStateInternal){RenderStateInternal["Root"]="root";RenderStateInternal["Initial"]="initial";RenderStateInternal["Standard"]="standard";return RenderStateInternal})({});const RenderStateContext=React.createContext("root");RenderStateContext.displayName="RenderStateContext";
|
|
5
|
+
import { addStyle } from '@khanacademy/wonder-blocks-core';
|
|
6
|
+
import { semanticColor } from '@khanacademy/wonder-blocks-tokens';
|
|
10
7
|
|
|
11
8
|
const ARROW_SIZE_INLINE=20;const ARROW_SIZE_BLOCK=10;const FloatingReferenceAttributeName="data-wb-floating-reference";const ModalLauncherPortalAttributeName="data-modal-launcher-portal";
|
|
12
9
|
|
|
@@ -20,6 +17,10 @@ const rtlMirror=()=>{return {name:"rtlMirror",fn(state){const{placement,elements
|
|
|
20
17
|
|
|
21
18
|
function canAcceptRef(element){const type=element.type;if(typeof type==="string"){return true}if(typeof type==="object"&&type!==null){if(type.$$typeof===Symbol.for("react.forward_ref")){return true}if(type.$$typeof===Symbol.for("react.memo")){return canAcceptRef({...element,type:type.type})}}return false}function getElementRef(element){if(parseInt(React.version,10)>=19){return element.props?.ref??undefined}return element.ref??undefined}
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
var modules_b1e1135d={"floating":"wb-floating-floating-1d1144e4","constrained":"wb-floating-constrained-1d1144e4","hidden":"wb-floating-hidden-1d1144e4"};var styles = modules_b1e1135d;
|
|
21
|
+
|
|
22
|
+
const StyledDiv=addStyle("div");const SHIFT_PADDING=12;const NON_TEXT_INPUT_TYPES=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]);function opensVirtualKeyboard(element){if(element instanceof HTMLTextAreaElement||element instanceof HTMLInputElement){if(element.readOnly||element.disabled||element.getAttribute("aria-disabled")==="true"){return false}return element instanceof HTMLTextAreaElement||!NON_TEXT_INPUT_TYPES.has(element.type)}return element instanceof HTMLElement&&element.isContentEditable}function Floating({content,children,placement="top",open=false,onOpenChange,portal=true,strategy="absolute",testId,focusManagerEnabled=true,initialFocusRef,returnFocus=true,closeOnFocusOut=false,dismissEnabled=false,onPlacementChange,hide:hideProp=true,offset:offsetProp=20,flip:flipProp=true,shift:shiftProp=true,shiftPadding=SHIFT_PADDING,constrainSize=false,rootBoundary="viewport",showArrow=true,styles:stylesProp}){const arrowRef=React.useRef(null);const prevOpenRef=React.useRef(open??false);const[focusedField,setFocusedField]=React.useState(null);const{elements,refs,floatingStyles,context,middlewareData,placement:resolvedPlacement}=useFloating({open,onOpenChange,placement,strategy,whileElementsMounted:autoUpdate,middleware:[offset({mainAxis:offsetProp}),flipProp?flip({rootBoundary}):undefined,shiftProp?shift({padding:shiftPadding,crossAxis:true,rootBoundary}):undefined,constrainSize?size({padding:shiftPadding,rootBoundary,apply({availableWidth,availableHeight,elements}){Object.assign(elements.floating.style,{maxInlineSize:`${Math.max(0,availableWidth)}px`,maxBlockSize:`${Math.max(0,availableHeight)}px`});}}):undefined,showArrow?arrow({element:arrowRef}):undefined,hideProp?hide():undefined,rtlMirror()]});const dismiss=useDismiss(context,{enabled:dismissEnabled});const{getReferenceProps,getFloatingProps}=useInteractions([dismiss]);React.useEffect(()=>{if(prevOpenRef.current!==open){onOpenChange?.(open);prevOpenRef.current=open;}},[onOpenChange,open]);React.useEffect(()=>{if(!open){setFocusedField(null);}},[open]);const isPressingInsideRef=React.useRef(false);const handleFocus=React.useCallback(event=>{if(event.currentTarget.contains(event.target)&&opensVirtualKeyboard(event.target)){setFocusedField(event.target);}},[]);const handleBlur=React.useCallback(event=>{const{relatedTarget,currentTarget}=event;const movesInside=relatedTarget instanceof Node?currentTarget.contains(relatedTarget):isPressingInsideRef.current;isPressingInsideRef.current=false;if(!movesInside){setFocusedField(null);}},[]);const handlePointerDown=React.useCallback(()=>{isPressingInsideRef.current=true;},[]);const handlePointerUp=React.useCallback(()=>{isPressingInsideRef.current=false;},[]);React.useEffect(()=>{const floating=elements.floating;if(!focusedField||!floating){return}const observer=new MutationObserver(()=>{if(!focusedField.isConnected){setFocusedField(null);}});observer.observe(floating,{childList:true,subtree:true});return ()=>observer.disconnect()},[elements.floating,focusedField]);const isHidden=!!middlewareData.hide?.referenceHidden&&!focusedField;React.useEffect(()=>{onPlacementChange?.(resolvedPlacement);},[onPlacementChange,resolvedPlacement]);const{setReference}=refs;const referenceId=React.useId();const referenceFromRef=React.useRef(null);const setReferenceFromTrigger=React.useCallback(node=>{const element=node instanceof Element?node:null;referenceFromRef.current=element;setReference(element);},[setReference]);const triggerRef=useMergeRefs([setReferenceFromTrigger,getElementRef(children)]);const trigger=React.useMemo(()=>{return React.cloneElement(children,{[FloatingReferenceAttributeName]:referenceId,...canAcceptRef(children)?{ref:triggerRef}:undefined,...getReferenceProps()})},[children,getReferenceProps,referenceId,triggerRef]);React.useLayoutEffect(()=>{if(referenceFromRef.current){return}const node=document.querySelector(`[${FloatingReferenceAttributeName}="${referenceId}"]`);if(node!==elements.reference){setReference(node);}if(process.env.NODE_ENV!=="production"&&open&&!node){console.warn("Floating: could not find the trigger's element in the DOM, "+"so the floating element can't be positioned. Make sure "+"the trigger either attaches the ref it is given or "+"spreads the props it is given onto the element the "+"floating element should be anchored to.");}});return jsxs(Fragment,{children:[trigger,open&&elements.reference&&jsx(Portal,{portal:portal,reference:elements.reference,children:jsx(FloatingFocusManager,{disabled:!focusManagerEnabled,context:context,modal:false,initialFocus:initialFocusRef,returnFocus:returnFocus,closeOnFocusOut:closeOnFocusOut,visuallyHiddenDismiss:dismissEnabled,children:jsxs(StyledDiv,{"data-testid":testId,"data-placement":placement,ref:refs.setFloating,style:[styles.floating,constrainSize&&styles.constrained,floatingStyles,stylesProp?.root,isHidden&&styles.hidden],...getFloatingProps({onFocus:handleFocus,onBlur:handleBlur,onPointerDown:handlePointerDown,onPointerUp:handlePointerUp,onPointerCancel:handlePointerUp}),children:[content,showArrow&&jsx(Arrow,{ref:arrowRef,context:context,style:stylesProp?.arrow})]})})})]})}
|
|
24
23
|
|
|
25
24
|
export { Floating, FloatingReferenceAttributeName, canAcceptRef, getElementRef };
|
|
25
|
+
|
|
26
|
+
import "./index.css";
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@layer shared {/* Styles for `Floating`. The build wraps these rules in `@layer shared { … }`
|
|
2
|
+
* via the wrap-in-layer plugin in `postcss.config.cjs`. */.wb-floating-floating-1d1144e4 {
|
|
3
|
+
background: var(--wb-semanticColor-core-background-base-default);
|
|
4
|
+
border: solid var(--wb-border-width-thin)
|
|
5
|
+
var(--wb-semanticColor-core-border-neutral-subtle);
|
|
6
|
+
border-radius: var(--wb-border-radius-radius_040);
|
|
7
|
+
|
|
8
|
+
/* Allow the floating element to be at least as tall as the arrow. We set
|
|
9
|
+
* inline size to ensure that it works with inline placements. Keep in sync
|
|
10
|
+
* with `ARROW_SIZE_INLINE` in `util/constants.ts`. */
|
|
11
|
+
min-block-size: 20px;
|
|
12
|
+
box-shadow: var(--wb-boxShadow-mid);
|
|
13
|
+
justify-content: center;
|
|
14
|
+
|
|
15
|
+
/* Prevent the floating element from receiving focus when it is clicked. */
|
|
16
|
+
outline: none;
|
|
17
|
+
}.wb-floating-constrained-1d1144e4 {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
}/* Applied while the reference element is out of view (see `isHidden` in
|
|
21
|
+
* `floating.tsx`). This is a class rather than an inline style on purpose:
|
|
22
|
+
* jsdom has no layout, so floating-ui always reports the reference as hidden
|
|
23
|
+
* in tests. Consumer test setups mock CSS, so a class keeps the content
|
|
24
|
+
* visible there, while an inline `visibility: hidden` would hide it from
|
|
25
|
+
* Testing Library queries. */.wb-floating-hidden-1d1144e4 {
|
|
26
|
+
visibility: hidden;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["<no source>","../src/components/floating.module.css"],"names":[],"mappings":"AAAA,eCAA;0DAC0D,CAE1D;IACI,gEAAgE;IAChE;0DACsD;IACtD,iDAAiD;;IAEjD;;yDAEqD;IACrD,oBAAoB;IACpB,mCAAmC;IACnC,uBAAuB;;IAEvB,0EAA0E;IAC1E,aAAa;AACjB,CAEA;IACI,aAAa;IACb,sBAAsB;AAC1B,CAEA;;;;;6BAK6B,CAC7B;IACI,kBAAkB;AACtB;CDjCA","file":"index.css","sourcesContent":[null,"/* Styles for `Floating`. The build wraps these rules in `@layer shared { … }`\n * via the wrap-in-layer plugin in `postcss.config.cjs`. */\n\n.floating {\n background: var(--wb-semanticColor-core-background-base-default);\n border: solid var(--wb-border-width-thin)\n var(--wb-semanticColor-core-border-neutral-subtle);\n border-radius: var(--wb-border-radius-radius_040);\n\n /* Allow the floating element to be at least as tall as the arrow. We set\n * inline size to ensure that it works with inline placements. Keep in sync\n * with `ARROW_SIZE_INLINE` in `util/constants.ts`. */\n min-block-size: 20px;\n box-shadow: var(--wb-boxShadow-mid);\n justify-content: center;\n\n /* Prevent the floating element from receiving focus when it is clicked. */\n outline: none;\n}\n\n.constrained {\n display: flex;\n flex-direction: column;\n}\n\n/* Applied while the reference element is out of view (see `isHidden` in\n * `floating.tsx`). This is a class rather than an inline style on purpose:\n * jsdom has no layout, so floating-ui always reports the reference as hidden\n * in tests. Consumer test setups mock CSS, so a class keeps the content\n * visible there, while an inline `visibility: hidden` would hide it from\n * Testing Library queries. */\n.hidden {\n visibility: hidden;\n}"]}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var react = require('@floating-ui/react');
|
|
8
|
-
var
|
|
8
|
+
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
9
9
|
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
10
10
|
|
|
11
11
|
function _interopNamespace(e) {
|
|
@@ -28,8 +28,6 @@ function _interopNamespace(e) {
|
|
|
28
28
|
|
|
29
29
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
30
|
|
|
31
|
-
function flatten(list){const result=[];if(!list){return result}else if(Array.isArray(list)){for(const item of list){result.push(...flatten(item));}}else {result.push(list);}return result}function processStyleList(style){const stylesheetStyles=[];const inlineStyles=[];if(!style){return {style:{},className:""}}const shouldInlineStyles=typeof global!=="undefined"&&global.SNAPSHOT_INLINE_APHRODITE;flatten(style).forEach(child=>{const _definition=child._definition;if(_definition!=null){if(shouldInlineStyles){const def={};for(const[key,value]of Object.entries(_definition)){def[key.replace(/-[a-z]/g,match=>match[1].toUpperCase())]=value;}inlineStyles.push(def);}else {stylesheetStyles.push(child);}}else {inlineStyles.push(child);}});const inlineStylesObject=Object.assign({},...inlineStyles);if(inlineStyles.length>0&&!shouldInlineStyles){const inlineStylesStyleSheet=aphrodite.StyleSheet.create({inlineStyles:inlineStylesObject});stylesheetStyles.push(inlineStylesStyleSheet.inlineStyles);}return {style:shouldInlineStyles?inlineStylesObject:{},className:aphrodite.css(...stylesheetStyles)}}const isHeaderRegex=/^h[1-6]$/;const styles$1=aphrodite.StyleSheet.create({text:{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale"},header:{marginBlockStart:0,marginBlockEnd:0}});React__namespace.forwardRef(function Text({children,style,tag="span",testId,...otherProps},ref){const Tag=tag;const isHeader=isHeaderRegex.test(tag);const styleAttributes=processStyleList([styles$1.text,isHeader&&styles$1.header,style]);const classNames=otherProps.className?[otherProps.className,styleAttributes.className].join(" "):styleAttributes.className;return jsxRuntime.jsx(Tag,{...otherProps,style:styleAttributes.style,className:classNames,"data-testid":testId,ref:ref,children:children})});function addStyle(Component,defaultStyle){return React__namespace.forwardRef((props,ref)=>{const{className,style,...otherProps}=props;const reset=typeof Component==="string"?overrides[Component]:null;const{className:aphroditeClassName,style:inlineStyles}=processStyleList([reset,defaultStyle,style]);return jsxRuntime.jsx(Component,{...otherProps,ref:ref,className:[aphroditeClassName,className].filter(Boolean).join(" "),style:inlineStyles})})}const overrides=aphrodite.StyleSheet.create({button:{margin:0,"::-moz-focus-inner":{border:0}}});const styles$2=aphrodite.StyleSheet.create({default:{alignItems:"stretch",borderWidth:0,borderStyle:"solid",boxSizing:"border-box",display:"flex",flexDirection:"column",margin:0,padding:0,position:"relative",zIndex:0,minBlockSize:0,minInlineSize:0}});React__namespace.forwardRef(function View(props,ref){const{testId,tag="div",...restProps}=props;const commonProps={...restProps,"data-testid":testId};const StyledTag=React.useMemo(()=>addStyle(tag,styles$2.default),[tag]);return jsxRuntime.jsx(StyledTag,{...commonProps,ref:ref})});(function(RenderState){RenderState["Initial"]="initial";RenderState["Standard"]="standard";return RenderState})({});(function(RenderStateInternal){RenderStateInternal["Root"]="root";RenderStateInternal["Initial"]="initial";RenderStateInternal["Standard"]="standard";return RenderStateInternal})({});const RenderStateContext=React__namespace.createContext("root");RenderStateContext.displayName="RenderStateContext";
|
|
32
|
-
|
|
33
31
|
const ARROW_SIZE_INLINE=20;const ARROW_SIZE_BLOCK=10;const FloatingReferenceAttributeName="data-wb-floating-reference";const ModalLauncherPortalAttributeName="data-modal-launcher-portal";
|
|
34
32
|
|
|
35
33
|
const Arrow=React__namespace.forwardRef(function Arrow({context,style},ref){const shadowStyle=context.placement.endsWith("top")?{filter:`drop-shadow(0 4px 2px ${wonderBlocksTokens.semanticColor.core.shadow.transparent.mid})`}:undefined;return jsxRuntime.jsx(react.FloatingArrow,{ref:ref,context:context,fill:style?.fill??wonderBlocksTokens.semanticColor.core.background.base.default,stroke:style?.stroke??wonderBlocksTokens.semanticColor.core.border.neutral.subtle,strokeWidth:style?.strokeWidth??1,width:style?.width??ARROW_SIZE_INLINE,height:style?.height??ARROW_SIZE_BLOCK,style:shadowStyle})});
|
|
@@ -42,7 +40,9 @@ const rtlMirror=()=>{return {name:"rtlMirror",fn(state){const{placement,elements
|
|
|
42
40
|
|
|
43
41
|
function canAcceptRef(element){const type=element.type;if(typeof type==="string"){return true}if(typeof type==="object"&&type!==null){if(type.$$typeof===Symbol.for("react.forward_ref")){return true}if(type.$$typeof===Symbol.for("react.memo")){return canAcceptRef({...element,type:type.type})}}return false}function getElementRef(element){if(parseInt(React__namespace.version,10)>=19){return element.props?.ref??undefined}return element.ref??undefined}
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
var modules_b1e1135d={"floating":"wb-floating-floating-1d1144e4","constrained":"wb-floating-constrained-1d1144e4","hidden":"wb-floating-hidden-1d1144e4"};var styles = modules_b1e1135d;
|
|
44
|
+
|
|
45
|
+
const StyledDiv=wonderBlocksCore.addStyle("div");const SHIFT_PADDING=12;const NON_TEXT_INPUT_TYPES=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]);function opensVirtualKeyboard(element){if(element instanceof HTMLTextAreaElement||element instanceof HTMLInputElement){if(element.readOnly||element.disabled||element.getAttribute("aria-disabled")==="true"){return false}return element instanceof HTMLTextAreaElement||!NON_TEXT_INPUT_TYPES.has(element.type)}return element instanceof HTMLElement&&element.isContentEditable}function Floating({content,children,placement="top",open=false,onOpenChange,portal=true,strategy="absolute",testId,focusManagerEnabled=true,initialFocusRef,returnFocus=true,closeOnFocusOut=false,dismissEnabled=false,onPlacementChange,hide:hideProp=true,offset:offsetProp=20,flip:flipProp=true,shift:shiftProp=true,shiftPadding=SHIFT_PADDING,constrainSize=false,rootBoundary="viewport",showArrow=true,styles:stylesProp}){const arrowRef=React__namespace.useRef(null);const prevOpenRef=React__namespace.useRef(open??false);const[focusedField,setFocusedField]=React__namespace.useState(null);const{elements,refs,floatingStyles,context,middlewareData,placement:resolvedPlacement}=react.useFloating({open,onOpenChange,placement,strategy,whileElementsMounted:react.autoUpdate,middleware:[react.offset({mainAxis:offsetProp}),flipProp?react.flip({rootBoundary}):undefined,shiftProp?react.shift({padding:shiftPadding,crossAxis:true,rootBoundary}):undefined,constrainSize?react.size({padding:shiftPadding,rootBoundary,apply({availableWidth,availableHeight,elements}){Object.assign(elements.floating.style,{maxInlineSize:`${Math.max(0,availableWidth)}px`,maxBlockSize:`${Math.max(0,availableHeight)}px`});}}):undefined,showArrow?react.arrow({element:arrowRef}):undefined,hideProp?react.hide():undefined,rtlMirror()]});const dismiss=react.useDismiss(context,{enabled:dismissEnabled});const{getReferenceProps,getFloatingProps}=react.useInteractions([dismiss]);React__namespace.useEffect(()=>{if(prevOpenRef.current!==open){onOpenChange?.(open);prevOpenRef.current=open;}},[onOpenChange,open]);React__namespace.useEffect(()=>{if(!open){setFocusedField(null);}},[open]);const isPressingInsideRef=React__namespace.useRef(false);const handleFocus=React__namespace.useCallback(event=>{if(event.currentTarget.contains(event.target)&&opensVirtualKeyboard(event.target)){setFocusedField(event.target);}},[]);const handleBlur=React__namespace.useCallback(event=>{const{relatedTarget,currentTarget}=event;const movesInside=relatedTarget instanceof Node?currentTarget.contains(relatedTarget):isPressingInsideRef.current;isPressingInsideRef.current=false;if(!movesInside){setFocusedField(null);}},[]);const handlePointerDown=React__namespace.useCallback(()=>{isPressingInsideRef.current=true;},[]);const handlePointerUp=React__namespace.useCallback(()=>{isPressingInsideRef.current=false;},[]);React__namespace.useEffect(()=>{const floating=elements.floating;if(!focusedField||!floating){return}const observer=new MutationObserver(()=>{if(!focusedField.isConnected){setFocusedField(null);}});observer.observe(floating,{childList:true,subtree:true});return ()=>observer.disconnect()},[elements.floating,focusedField]);const isHidden=!!middlewareData.hide?.referenceHidden&&!focusedField;React__namespace.useEffect(()=>{onPlacementChange?.(resolvedPlacement);},[onPlacementChange,resolvedPlacement]);const{setReference}=refs;const referenceId=React__namespace.useId();const referenceFromRef=React__namespace.useRef(null);const setReferenceFromTrigger=React__namespace.useCallback(node=>{const element=node instanceof Element?node:null;referenceFromRef.current=element;setReference(element);},[setReference]);const triggerRef=react.useMergeRefs([setReferenceFromTrigger,getElementRef(children)]);const trigger=React__namespace.useMemo(()=>{return React__namespace.cloneElement(children,{[FloatingReferenceAttributeName]:referenceId,...canAcceptRef(children)?{ref:triggerRef}:undefined,...getReferenceProps()})},[children,getReferenceProps,referenceId,triggerRef]);React__namespace.useLayoutEffect(()=>{if(referenceFromRef.current){return}const node=document.querySelector(`[${FloatingReferenceAttributeName}="${referenceId}"]`);if(node!==elements.reference){setReference(node);}if(process.env.NODE_ENV!=="production"&&open&&!node){console.warn("Floating: could not find the trigger's element in the DOM, "+"so the floating element can't be positioned. Make sure "+"the trigger either attaches the ref it is given or "+"spreads the props it is given onto the element the "+"floating element should be anchored to.");}});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[trigger,open&&elements.reference&&jsxRuntime.jsx(Portal,{portal:portal,reference:elements.reference,children:jsxRuntime.jsx(react.FloatingFocusManager,{disabled:!focusManagerEnabled,context:context,modal:false,initialFocus:initialFocusRef,returnFocus:returnFocus,closeOnFocusOut:closeOnFocusOut,visuallyHiddenDismiss:dismissEnabled,children:jsxRuntime.jsxs(StyledDiv,{"data-testid":testId,"data-placement":placement,ref:refs.setFloating,style:[styles.floating,constrainSize&&styles.constrained,floatingStyles,stylesProp?.root,isHidden&&styles.hidden],...getFloatingProps({onFocus:handleFocus,onBlur:handleBlur,onPointerDown:handlePointerDown,onPointerUp:handlePointerUp,onPointerCancel:handlePointerUp}),children:[content,showArrow&&jsxRuntime.jsx(Arrow,{ref:arrowRef,context:context,style:stylesProp?.arrow})]})})})]})}
|
|
46
46
|
|
|
47
47
|
Object.defineProperty(exports, 'useMergeRefs', {
|
|
48
48
|
enumerable: true,
|
|
@@ -52,3 +52,5 @@ exports.Floating = Floating;
|
|
|
52
52
|
exports.FloatingReferenceAttributeName = FloatingReferenceAttributeName;
|
|
53
53
|
exports.canAcceptRef = canAcceptRef;
|
|
54
54
|
exports.getElementRef = getElementRef;
|
|
55
|
+
|
|
56
|
+
require("./index.css");
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A package that provides support for floating UI components in our UIs, including portal and focus management support.",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "1.0.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -18,17 +18,32 @@
|
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"module": "dist/es/index.js",
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"**/*.css"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/es/index.js",
|
|
28
|
+
"require": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./css": {
|
|
31
|
+
"import": "./dist/es/index.css",
|
|
32
|
+
"require": "./dist/index.css",
|
|
33
|
+
"default": "./dist/index.css"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
21
36
|
"dependencies": {
|
|
22
37
|
"@floating-ui/react": "^0.27.16",
|
|
23
|
-
"@khanacademy/wonder-blocks-
|
|
38
|
+
"@khanacademy/wonder-blocks-core": "13.0.0",
|
|
39
|
+
"@khanacademy/wonder-blocks-tokens": "18.3.0"
|
|
24
40
|
},
|
|
25
41
|
"peerDependencies": {
|
|
26
|
-
"aphrodite": "^1.2.5",
|
|
27
42
|
"react": "18.2.0"
|
|
28
43
|
},
|
|
29
44
|
"devDependencies": {
|
|
30
45
|
"@khanacademy/wb-dev-build-settings": "3.3.0",
|
|
31
|
-
"@khanacademy/wonder-blocks-modal": "
|
|
46
|
+
"@khanacademy/wonder-blocks-modal": "9.0.0"
|
|
32
47
|
},
|
|
33
48
|
"scripts": {
|
|
34
49
|
"test": "echo \"Error: no test specified\" && exit 1"
|