@radix-ui/react-tooltip 0.1.1-rc.6 → 0.1.1
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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +11 -12
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import * as Radix from "@radix-ui/react-primitive";
|
|
3
3
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
4
4
|
import * as PopperPrimitive from "@radix-ui/react-popper";
|
|
5
|
+
export const createTooltipScope: import("@radix-ui/react-context").CreateScope;
|
|
5
6
|
export interface TooltipProps {
|
|
6
7
|
open?: boolean;
|
|
7
8
|
defaultOpen?: boolean;
|
|
@@ -16,6 +17,7 @@ export interface TooltipProps {
|
|
|
16
17
|
* (default: 300)
|
|
17
18
|
*/
|
|
18
19
|
skipDelayDuration?: number;
|
|
20
|
+
children?: React.ReactNode;
|
|
19
21
|
}
|
|
20
22
|
export const Tooltip: React.FC<TooltipProps>;
|
|
21
23
|
type PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"A;A;A;A;
|
|
1
|
+
{"mappings":"A;A;A;A;AEqCA,OAAA,yFAEE,CAAC;AAiBH;IACE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAEvC;A;A;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;A;A;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;CAC5B;AAED,OAAA,MAAM,SAAS,MAAM,EAAE,CAAC,YAAY,CA6FnC,CAAC;AAWF,4BAA4B,MAAM,wBAAwB,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC;AACpF,oCAA8B,SAAQ,oBAAoB;CAAG;AAE7D,OAAA,MAAM,6GA4BL,CAAC;AAWF,oCAA8B,SAAQ,uBAAuB;IAC3D;A;A;OAGG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB;AAED,OAAA,MAAM,0GAUL,CAAC;AAGF,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,gBAAgB,OAAO,CAAC,CAAC;AACzF,iCAAkC,SAAQ,kBAAkB;IAC1D;A;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;A;A;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAmDD,wBAAwB,MAAM,wBAAwB,CAAC,OAAO,gBAAgB,KAAK,CAAC,CAAC;AACrF,kCAA4B,SAAQ,gBAAgB;CAAG;AAEvD,OAAA,MAAM,qGAML,CAAC;AA+BF,OAAA,MAAM,4BAAc,CAAC;AACrB,OAAA,MAAM,sGAAwB,CAAC;AAC/B,OAAA,MAAM,mGAAwB,CAAC;AAC/B,OAAA,MAAM,8FAAoB,CAAC","sources":["./packages/react/tooltip/src/packages/react/tooltip/src/createStateMachine.tsx","./packages/react/tooltip/src/packages/react/tooltip/src/tooltipStateChart.tsx","./packages/react/tooltip/src/packages/react/tooltip/src/Tooltip.tsx","./packages/react/tooltip/src/packages/react/tooltip/src/index.ts"],"sourcesContent":[null,null,null,null],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e,t=require("@radix-ui/react-id").useId,o=
|
|
1
|
+
var e,t=require("@radix-ui/react-id").useId,o=v({},require("@radix-ui/react-visually-hidden")),n=require("@radix-ui/react-slot").Slottable,r=require("@radix-ui/react-portal").Portal,i=require("@radix-ui/react-popper"),s=v({},i),a=i.createPopperScope,c=require("@radix-ui/react-primitive").Primitive,l=require("@radix-ui/react-presence").Presence,u=require("@radix-ui/react-use-rect").useRect,d=require("@radix-ui/react-use-previous").usePrevious,p=require("@radix-ui/react-use-layout-effect").useLayoutEffect,f=require("@radix-ui/react-use-escape-keydown").useEscapeKeydown,g=require("@radix-ui/react-use-controllable-state").useControllableState,E=require("@radix-ui/react-context").createContextScope,y=require("@radix-ui/react-compose-refs").useComposedRefs,x=require("@radix-ui/primitive").composeEventHandlers,T=v({},require("react")),m=(e=require("@babel/runtime/helpers/extends"))&&e.__esModule?e.default:e;function v(e,t){return Object.keys(t).forEach((function(o){"default"!==o&&"__esModule"!==o&&Object.defineProperty(e,o,{enumerable:!0,get:function(){return t[o]}})})),e}function C(e){return{type:"machine.actions.assign",assign:e}}let _,b;const D=C(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),w=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n=e.initial,r=e.context;const i=[],s=a=>{var c,l;const u=e.states[n],d=a.type,p=null===(c=e.on)||void 0===c?void 0:c[d],f=null===(l=u.on)||void 0===l?void 0:l[d],g=null!=p?p:f;if(void 0===g)o&&console.warn(`From state: "${n}", event "${d}" has no transition to any state`);else{const{target:o,actions:c=[],cond:l=(()=>!0)}=g,d=o?e.states[o]:{};if(l(r,a)){const e=(u.exit||[]).concat(c,d.entry||[]);r=function(e,t,o){let n=o;return null==e||e.forEach((e=>{"function"==typeof e?e(n,t,s):"machine.actions.assign"===e.type&&(n=e.assign(n,t))})),n}(e,a,r),o&&(n=o,t&&(console.group("event:",a),console.log("state:",n),console.log("context:",r),console.groupEnd()),i.forEach((e=>e({state:n,context:r}))))}}};return{subscribe:function(e){return i.push(e),()=>{i.splice(i.indexOf(e),1)}},send:s,getContext:function(){return r}}}({initial:"closed",context:{id:null,delayed:!1},on:{FOCUS:{target:"open"}},states:{closed:{entry:[C((e=>({...e,id:null})))],on:{OPEN:{target:"opening"}}},opening:{entry:[(e,t,o)=>{const n=t.delayDuration,r=()=>o({type:"DELAY_TIMER_END"});void 0===n?r():_=window.setTimeout(r,n)},D,C((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(_)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[D],exit:[C((e=>({...e,delayed:!1})))],on:{OPEN:{target:"open"},CLOSE:{target:"closing",cond:(e,t)=>e.id===t.id}}},closing:{entry:[(e,t,o)=>{var n;const r=null!==(n=t.skipDelayDuration)&&void 0!==n?n:300;b=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(b)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[h,O]=E("Tooltip",[a]);exports.createTooltipScope=O;const q=a(),[M,P]=h("Tooltip"),S=e=>{const{__scopeTooltip:o,children:n,open:r,defaultOpen:i=!1,onOpenChange:a,delayDuration:c=700,skipDelayDuration:l=300}=e,u=q(o),[d,f]=T.useState(null),E=t(),[y=!1,x]=g({prop:r,defaultProp:i,onChange:a}),[m,v]=T.useState(r?"instant-open":"closed");T.useEffect((()=>w.subscribe((({state:e,context:t})=>{"open"===e&&t.id===E?x(!0):x(!1)}))),[E,x]),T.useEffect((()=>w.subscribe((({state:e,context:t})=>{t.id===E?v("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):v("closed")}))),[E]);const C=T.useCallback((()=>w.send({type:"FOCUS",id:E})),[E]),_=T.useCallback((()=>w.send({type:"OPEN",id:E,delayDuration:c})),[E,c]),b=T.useCallback((()=>w.send({type:"CLOSE",id:E,skipDelayDuration:l})),[l,E]);return T.useEffect((()=>()=>b()),[b]),p((()=>{!0===r&&w.send({type:"OPEN",id:E})}),[E,r]),/*#__PURE__*/T.createElement(s.Root,u,/*#__PURE__*/T.createElement(M,{scope:o,contentId:E,open:y,stateAttribute:m,trigger:d,onTriggerChange:f,onFocus:C,onOpen:_,onClose:b},n))};exports.Tooltip=S;const R=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=P("TooltipTrigger",o),i=q(o),a=y(t,r.onTriggerChange);/*#__PURE__*/return T.createElement(s.Anchor,m({asChild:!0},i),/*#__PURE__*/T.createElement(c.button,m({type:"button","aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute},n,{ref:a,onMouseEnter:x(e.onMouseEnter,r.onOpen),onMouseLeave:x(e.onMouseLeave,r.onClose),onMouseDown:x(e.onMouseDown,r.onClose),onFocus:x(e.onFocus,r.onFocus),onBlur:x(e.onBlur,r.onClose),onKeyDown:x(e.onKeyDown,(e=>{"Enter"!==e.key&&" "!==e.key||r.onClose()}))})))}));exports.TooltipTrigger=R;const k=/*#__PURE__*/T.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=P("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return T.createElement(l,{present:o||r.open},/*#__PURE__*/T.createElement(A,m({ref:t},n)))}));exports.TooltipContent=k;const A=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:i,children:a,"aria-label":c,portalled:l=!0,...u}=e,d=P("TooltipContent",i),p=q(i),g=l?r:T.Fragment;return f((()=>d.onClose())),/*#__PURE__*/T.createElement(g,null,/*#__PURE__*/T.createElement(L,{__scopeTooltip:i}),/*#__PURE__*/T.createElement(s.Content,m({"data-state":d.stateAttribute},p,u,{ref:t,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"}}),/*#__PURE__*/T.createElement(n,null,a),/*#__PURE__*/T.createElement(o.Root,{id:d.contentId,role:"tooltip"},c||a)))})),I=/*#__PURE__*/T.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,r=q(o);/*#__PURE__*/return T.createElement(s.Arrow,m({},r,n,{ref:t}))}));/*#__PURE__*/function L(e){const{__scopeTooltip:t}=e,o=P("CheckTriggerMoved",t),n=u(o.trigger),r=null==n?void 0:n.left,i=d(r),s=null==n?void 0:n.top,a=d(s),c=o.onClose;return T.useEffect((()=>{(void 0!==i&&i!==r||void 0!==a&&a!==s)&&c()}),[c,i,a,r,s]),null}exports.TooltipArrow=I;const N=S;exports.Root=N;const F=R;exports.Trigger=F;const K=k;exports.Content=K;const Y=I;exports.Arrow=Y;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"IAAgCA,wyBAAAA,8CAClBA,EAAEC,WAAaD,EAAEE,QAAUF,EAWzC,SAASG,EAAuBC,EAAMC,GAcpC,OAbAC,OAAOC,KAAKF,GAAQG,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeN,EAAMK,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOP,EAAOI,SAKbL,ECoGT,SAASS,EACPC,GAEA,MAAO,CAAEC,KAjIgB,yBAiIUF,OAAQC,GC9G7C,IAAIE,EACAC,EAEJ,MAsBMC,EAAuBC,GAAO,CAACC,EAASC,KAAV,IAAAC,EAAA,MAAqB,IACpDF,EACHG,GAAE,QAAAD,EAAGD,EAAcE,UAAjB,IAAAD,EAAAA,EAAuBF,EAAQG,OCpB7BC,EFSN,SACEC,GACAC,MAAEA,GAAQ,EAAVC,yBAAiBA,GAA2B,GAAkB,IAE9D,IAAIC,EAAeH,EAAWI,QAC1BC,EAAiBL,EAAWL,QAGhC,MAAMW,EAAmC,GAanCC,EAAQX,IAAiB,IAAAY,EAAAC,EAC7B,MAAMC,EAAkBV,EAAWW,OAAOR,GACpCb,EAAkCM,EAAMN,KACxCsB,EAAiE,QAAAJ,EAAGR,EAAWa,UAAd,IAAAL,OAAA,EAAGA,EAAgBlB,GACpFwB,EAA8D,QAAAL,EAClEC,EAAgBG,UADkD,IAAAJ,OAAA,EAClEA,EAAqBnB,GACjByB,EAAaH,MAAAA,EAAAA,EAAsBE,EAEzC,QAAm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,GAAIH,EAAQ6E,UAAW2D,KAAK,WACvDX,GAAaxD,QAoBpBoE,eAAe9D,EAAM2B,YACzB,CAAClC,EAAOmC,iBAAiBX,EAAAC,cAACC,EAAgB4C,MAAjB5B,EAAA,GAA2B1C,EAA3B,CAAkC2C,IAAKR,oBAOlE,SAASoC,IACP,MAAM3I,EAAUiE,EAAkB,qBAE5B2E,EAAcC,EAAQ7I,EAAQyE,SAC9BqE,EAAcF,MAAAA,OAAH,EAAGA,EAAaG,KAC3BC,EAAsBC,EAAYH,GAClCI,EAAaN,MAAAA,OAAH,EAAGA,EAAaO,IAC1BC,EAAqBH,EAAYC,GACjCxD,EAAc1F,EAAQoG,QAa5B,OAXAzB,EAAMW,WAAU,WAGajE,IAAxB2H,GAAqCA,IAAwBF,QACtCzH,IAAvB+H,GAAoCA,IAAuBF,IAG5DxD,MAED,CAACA,EAAasD,EAAqBI,EAAoBN,EAAaI,IAEhE,4BAGT,MAAMnD,EAAO5B,iBACb,MAAMkF,EAAUhD,oBAChB,MAAM+B,EAAUd,oBAChB,MAAMoB,EAAQD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/tooltip/src/createStateMachine.tsx","./packages/react/tooltip/src/tooltipStateChart.tsx","./packages/react/tooltip/src/Tooltip.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","const ASSIGN_ACTION_TYPE = 'machine.actions.assign' as const;\n\nconst isProduction = process.env.NODE_ENV === 'production';\n\ntype StateChart<State extends string, Context, Event extends { type: string }> = {\n initial: State;\n context: Context;\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n states: {\n [stateValue in State]: {\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n entry?: Array<Action<Context, Event>>;\n exit?: Array<Action<Context, Event>>;\n };\n };\n};\n\ntype Transition<State extends string, Context, Event> = {\n target?: State;\n actions?: Array<Action<Context, Event>>;\n cond?: (context: Context, Event: Event) => boolean;\n};\n\ntype Action<Context, Event> = ActionFunction<Context, Event> | AssignAction<Context, Event>;\n\ntype ActionFunction<Context, Event> = (\n context: Context,\n event: Event,\n send: (event: Event) => void\n) => void;\n\nfunction createStateMachine<State extends string, Context, Event extends { type: string }>(\n stateChart: StateChart<State, Context, Event>,\n { debug = false, warnOnUnknownTransitions = !isProduction } = {}\n) {\n let currentState = stateChart.initial;\n let currentContext = stateChart.context;\n\n type CallbackFn = (args: { state: State; context: Context }) => void;\n const subscriptions: Array<CallbackFn> = [];\n\n function subscribe(callback: CallbackFn) {\n subscriptions.push(callback);\n return () => {\n subscriptions.splice(subscriptions.indexOf(callback), 1);\n };\n }\n\n function notify() {\n subscriptions.forEach((callback) => callback({ state: currentState, context: currentContext }));\n }\n\n const send = (event: Event) => {\n const stateDefinition = stateChart.states[currentState];\n const type: Event['type'] | undefined = event.type;\n const topLevelTransition: Transition<State, Context, Event> | undefined = stateChart.on?.[type];\n const stateTransition: Transition<State, Context, Event> | undefined =\n stateDefinition.on?.[type];\n const transition = topLevelTransition ?? stateTransition;\n\n if (transition === undefined) {\n if (warnOnUnknownTransitions) {\n console.warn(\n `From state: \"${currentState}\", event \"${type}\" has no transition to any state`\n );\n }\n } else {\n const { target: nextState, actions = [], cond = () => true } = transition;\n const nextStateDefinition = nextState ? stateChart.states[nextState] : {};\n\n if (cond(currentContext, event)) {\n // execute actions\n const allActions = (stateDefinition.exit || []).concat(\n actions,\n nextStateDefinition.entry || []\n );\n currentContext = executeActions(allActions, event, currentContext);\n\n if (nextState) {\n currentState = nextState;\n\n if (debug) {\n console.group('event:', event);\n console.log('state:', currentState);\n console.log('context:', currentContext);\n console.groupEnd();\n }\n\n notify();\n }\n }\n }\n };\n\n function getContext() {\n return currentContext;\n }\n\n function executeActions(\n actions: Array<Action<Context, Event>>,\n event: Event,\n context: Context\n ): Context {\n let nextContext = context;\n actions?.forEach((action) => {\n if (typeof action === 'function') {\n action(nextContext, event, send);\n } else if (action.type === ASSIGN_ACTION_TYPE) {\n nextContext = action.assign(nextContext, event);\n }\n });\n return nextContext;\n }\n\n return { subscribe, send, getContext };\n}\n\ntype AssignAction<Context, Event> = {\n type: typeof ASSIGN_ACTION_TYPE;\n assign(context: Context, event: Event): Context;\n};\n\nfunction assign<Context, Event>(\n assignFn: AssignAction<Context, Event>['assign']\n): AssignAction<Context, Event> {\n return { type: ASSIGN_ACTION_TYPE, assign: assignFn };\n}\n\nexport { createStateMachine, assign };\nexport type { StateChart, Action };\n","import { assign } from './createStateMachine';\n\nimport type { StateChart, Action } from './createStateMachine';\n\ntype TooltipState = 'closed' | 'opening' | 'open' | 'closing';\n\ntype TooltipEvent =\n | { type: 'OPEN'; id: string; delayDuration?: number }\n | { type: 'CLOSE'; id: string; skipDelayDuration: number }\n | { type: 'FOCUS'; id: string }\n | { type: 'DELAY_TIMER_END' }\n | { type: 'SKIP_DELAY_TIMER_END' };\n\ntype TooltipContext = { id: string | null; delayed: boolean };\n\ntype TooltipStateChart = StateChart<TooltipState, TooltipContext, TooltipEvent>;\ntype TooltipAction = Action<TooltipContext, TooltipEvent>;\n\n// actions\nlet delayTimerId: number;\nlet skipDelayTimerId: number;\n\nconst startDelayTimer: TooltipAction = (context, event, send) => {\n const delayDuration: number | undefined = (event as any).delayDuration;\n const sendTimerEnd = () => send({ type: 'DELAY_TIMER_END' });\n if (delayDuration === undefined) {\n sendTimerEnd();\n } else {\n delayTimerId = window.setTimeout(sendTimerEnd, delayDuration);\n }\n};\n\nconst cancelDelayTimer: TooltipAction = () => clearTimeout(delayTimerId);\n\nconst startSkipDelayTimer: TooltipAction = (context, event, send) => {\n const skipDelayDuration: number = (event as any).skipDelayDuration ?? 300;\n skipDelayTimerId = window.setTimeout(\n () => send({ type: 'SKIP_DELAY_TIMER_END' }),\n skipDelayDuration\n );\n};\n\nconst cancelSkipDelayTimer: TooltipAction = () => clearTimeout(skipDelayTimerId);\n\nconst setId: TooltipAction = assign((context, event) => ({\n ...context,\n id: (event as any).id ?? context.id,\n}));\nconst resetId: TooltipAction = assign((context) => ({ ...context, id: null }));\nconst setDelayed: TooltipAction = assign((context) => ({ ...context, delayed: true }));\nconst resetDelayed: TooltipAction = assign((context) => ({ ...context, delayed: false }));\n\nconst tooltipStateChart: TooltipStateChart = {\n initial: 'closed',\n context: { id: null, delayed: false },\n on: {\n FOCUS: { target: 'open' },\n },\n states: {\n closed: {\n entry: [resetId],\n on: {\n OPEN: { target: 'opening' },\n },\n },\n\n opening: {\n entry: [startDelayTimer, setId, setDelayed],\n exit: [cancelDelayTimer],\n on: {\n DELAY_TIMER_END: { target: 'open' },\n CLOSE: { target: 'closed' },\n },\n },\n\n open: {\n entry: [setId],\n exit: [resetDelayed],\n on: {\n OPEN: { target: 'open' },\n CLOSE: {\n target: 'closing',\n cond: (context, event) => context.id === (event as any).id,\n },\n },\n },\n\n closing: {\n entry: [startSkipDelayTimer],\n exit: [cancelSkipDelayTimer],\n on: {\n OPEN: { target: 'open' },\n SKIP_DELAY_TIMER_END: { target: 'closed' },\n },\n },\n },\n};\n\nexport { tooltipStateChart };\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContext } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useRect } from '@radix-ui/react-use-rect';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport * as PopperPrimitive from '@radix-ui/react-popper';\nimport { Portal } from '@radix-ui/react-portal';\nimport { Slottable } from '@radix-ui/react-slot';\nimport * as VisuallyHiddenPrimitive from '@radix-ui/react-visually-hidden';\nimport { useId } from '@radix-ui/react-id';\nimport { createStateMachine } from './createStateMachine';\nimport { tooltipStateChart } from './tooltipStateChart';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * State machine\n * -----------------------------------------------------------------------------------------------*/\n\ntype StateAttribute = 'closed' | 'delayed-open' | 'instant-open';\nconst stateMachine = createStateMachine(tooltipStateChart);\n\n/* -------------------------------------------------------------------------------------------------\n * Tooltip\n * -----------------------------------------------------------------------------------------------*/\n\nconst TOOLTIP_NAME = 'Tooltip';\n\ntype TooltipContextValue = {\n contentId: string;\n open: boolean;\n stateAttribute: StateAttribute;\n trigger: TooltipTriggerElement | null;\n onTriggerChange(trigger: TooltipTriggerElement | null): void;\n onFocus(): void;\n onOpen(): void;\n onClose(): void;\n};\n\nconst [TooltipProvider, useTooltipContext] = createContext<TooltipContextValue>(TOOLTIP_NAME);\n\ninterface TooltipProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n\n /**\n * The duration from when the mouse enters the trigger until the tooltip gets opened.\n * (default: 700)\n */\n delayDuration?: number;\n\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * (default: 300)\n */\n skipDelayDuration?: number;\n}\n\nconst Tooltip: React.FC<TooltipProps> = (props) => {\n const {\n children,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n delayDuration = 700,\n skipDelayDuration = 300,\n } = props;\n const [trigger, setTrigger] = React.useState<HTMLButtonElement | null>(null);\n const contentId = useId();\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n const [stateAttribute, setStateAttribute] = React.useState<StateAttribute>(\n openProp ? 'instant-open' : 'closed'\n );\n\n // control open state using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (state === 'open' && context.id === contentId) {\n setOpen(true);\n } else {\n setOpen(false);\n }\n });\n\n return unsubscribe;\n }, [contentId, setOpen]);\n\n // sync state attribute with using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (context.id === contentId) {\n if (state === 'open') {\n setStateAttribute(context.delayed ? 'delayed-open' : 'instant-open');\n } else {\n setStateAttribute('closed');\n }\n } else {\n setStateAttribute('closed');\n }\n });\n\n return unsubscribe;\n }, [contentId]);\n\n const handleFocus = React.useCallback(\n () => stateMachine.send({ type: 'FOCUS', id: contentId }),\n [contentId]\n );\n const handleOpen = React.useCallback(\n () => stateMachine.send({ type: 'OPEN', id: contentId, delayDuration }),\n [contentId, delayDuration]\n );\n const handleClose = React.useCallback(\n () => stateMachine.send({ type: 'CLOSE', id: contentId, skipDelayDuration }),\n [skipDelayDuration, contentId]\n );\n\n // send transition if the component unmounts\n React.useEffect(() => () => handleClose(), [handleClose]);\n\n // if we're controlling the component\n // put the state machine in the appropriate state\n useLayoutEffect(() => {\n if (openProp === true) {\n stateMachine.send({ type: 'OPEN', id: contentId });\n }\n }, [contentId, openProp]);\n\n return (\n <PopperPrimitive.Root>\n <TooltipProvider\n contentId={contentId}\n open={open}\n stateAttribute={stateAttribute}\n trigger={trigger}\n onTriggerChange={setTrigger}\n onFocus={handleFocus}\n onOpen={handleOpen}\n onClose={handleClose}\n >\n {children}\n </TooltipProvider>\n </PopperPrimitive.Root>\n );\n};\n\nTooltip.displayName = TOOLTIP_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'TooltipTrigger';\n\ntype TooltipTriggerElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface TooltipTriggerProps extends PrimitiveButtonProps {}\n\nconst TooltipTrigger = React.forwardRef<TooltipTriggerElement, TooltipTriggerProps>(\n (props, forwardedRef) => {\n const context = useTooltipContext(TRIGGER_NAME);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.onTriggerChange);\n return (\n <PopperPrimitive.Anchor asChild>\n <Primitive.button\n type=\"button\"\n aria-describedby={context.open ? context.contentId : undefined}\n data-state={context.stateAttribute}\n {...props}\n ref={composedTriggerRef}\n onMouseEnter={composeEventHandlers(props.onMouseEnter, context.onOpen)}\n onMouseLeave={composeEventHandlers(props.onMouseLeave, context.onClose)}\n onMouseDown={composeEventHandlers(props.onMouseDown, context.onClose)}\n onFocus={composeEventHandlers(props.onFocus, context.onFocus)}\n onBlur={composeEventHandlers(props.onBlur, context.onClose)}\n onKeyDown={composeEventHandlers(props.onKeyDown, (event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n context.onClose();\n }\n })}\n />\n </PopperPrimitive.Anchor>\n );\n }\n);\n\nTooltipTrigger.displayName = TRIGGER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'TooltipContent';\n\ntype TooltipContentElement = TooltipContentImplElement;\ninterface TooltipContentProps extends TooltipContentImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst TooltipContent = React.forwardRef<TooltipContentElement, TooltipContentProps>(\n (props, forwardedRef) => {\n const { forceMount, ...contentProps } = props;\n const context = useTooltipContext(CONTENT_NAME);\n return (\n <Presence present={forceMount || context.open}>\n <TooltipContentImpl ref={forwardedRef} {...contentProps} />\n </Presence>\n );\n }\n);\n\ntype TooltipContentImplElement = React.ElementRef<typeof PopperPrimitive.Content>;\ntype PopperContentProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Content>;\ninterface TooltipContentImplProps extends PopperContentProps {\n /**\n * A more descriptive label for accessibility purpose\n */\n 'aria-label'?: string;\n\n /**\n * Whether the Tooltip should render in a Portal\n * (default: `true`)\n */\n portalled?: boolean;\n}\n\nconst TooltipContentImpl = React.forwardRef<TooltipContentImplElement, TooltipContentImplProps>(\n (props, forwardedRef) => {\n const { children, 'aria-label': ariaLabel, portalled = true, ...contentProps } = props;\n const context = useTooltipContext(CONTENT_NAME);\n const PortalWrapper = portalled ? Portal : React.Fragment;\n\n useEscapeKeydown(() => context.onClose());\n\n return (\n <PortalWrapper>\n <CheckTriggerMoved />\n <PopperPrimitive.Content\n data-state={context.stateAttribute}\n {...contentProps}\n ref={forwardedRef}\n style={{\n ...contentProps.style,\n // re-namespace exposed content custom property\n ['--radix-tooltip-content-transform-origin' as any]:\n 'var(--radix-popper-transform-origin)',\n }}\n >\n <Slottable>{children}</Slottable>\n <VisuallyHiddenPrimitive.Root id={context.contentId} role=\"tooltip\">\n {ariaLabel || children}\n </VisuallyHiddenPrimitive.Root>\n </PopperPrimitive.Content>\n </PortalWrapper>\n );\n }\n);\n\nTooltipContent.displayName = CONTENT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'TooltipArrow';\n\ntype TooltipArrowElement = React.ElementRef<typeof PopperPrimitive.Arrow>;\ntype PopperArrowProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Arrow>;\ninterface TooltipArrowProps extends PopperArrowProps {}\n\nconst TooltipArrow = React.forwardRef<TooltipArrowElement, TooltipArrowProps>(\n (props, forwardedRef) => <PopperPrimitive.Arrow {...props} ref={forwardedRef} />\n);\n\nTooltipArrow.displayName = ARROW_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction CheckTriggerMoved() {\n const context = useTooltipContext('CheckTriggerMoved');\n\n const triggerRect = useRect(context.trigger);\n const triggerLeft = triggerRect?.left;\n const previousTriggerLeft = usePrevious(triggerLeft);\n const triggerTop = triggerRect?.top;\n const previousTriggerTop = usePrevious(triggerTop);\n const handleClose = context.onClose;\n\n React.useEffect(() => {\n // checking if the user has scrolled…\n const hasTriggerMoved =\n (previousTriggerLeft !== undefined && previousTriggerLeft !== triggerLeft) ||\n (previousTriggerTop !== undefined && previousTriggerTop !== triggerTop);\n\n if (hasTriggerMoved) {\n handleClose();\n }\n }, [handleClose, previousTriggerLeft, previousTriggerTop, triggerLeft, triggerTop]);\n\n return null;\n}\n\nconst Root = Tooltip;\nconst Trigger = TooltipTrigger;\nconst Content = TooltipContent;\nconst Arrow = TooltipArrow;\n\nexport {\n Tooltip,\n TooltipTrigger,\n TooltipContent,\n TooltipArrow,\n //\n Root,\n Trigger,\n Content,\n Arrow,\n};\nexport type { TooltipProps, TooltipTriggerProps, TooltipContentProps, TooltipArrowProps };\n"],"names":["a","__esModule","default","$parcel$exportWildcard","dest","source","Object","keys","forEach","key","defineProperty","enumerable","get","assign","assignFn","type","delayTimerId","skipDelayTimerId","setId","$fb910db130fc9c6f19b2800f728d3b10$export$assign","context","event","_id","id","stateMachine","stateChart","debug","warnOnUnknownTransitions","currentState","initial","currentContext","subscriptions","send","_stateChart$on","_stateDefinition$on","stateDefinition","states","topLevelTransition","on","stateTransition","transition","undefined","console","warn","target","nextState","actions","cond","nextStateDefinition","allActions","exit","concat","entry","nextContext","action","executeActions","group","log","groupEnd","callback","state","subscribe","push","splice","indexOf","getContext","$fb910db130fc9c6f19b2800f728d3b10$export$createStateMachine","delayed","FOCUS","closed","OPEN","opening","delayDuration","sendTimerEnd","window","setTimeout","clearTimeout","DELAY_TIMER_END","CLOSE","open","closing","_skipDelayDuration","skipDelayDuration","SKIP_DELAY_TIMER_END","TooltipProvider","useTooltipContext","createContext","Tooltip","props","children","openProp","defaultOpen","onOpenChange","trigger","setTrigger","React","useState","contentId","useId","setOpen","useControllableState","prop","defaultProp","onChange","stateAttribute","setStateAttribute","useEffect","handleFocus","useCallback","handleOpen","handleClose","useLayoutEffect","_react","createElement","_radixUiReactPopper","Root","$bfd2ef98f93cfd0786881e49eeb6a4$var$TooltipProvider","onTriggerChange","onFocus","onOpen","onClose","TooltipTrigger","forwardRef","forwardedRef","composedTriggerRef","useComposedRefs","Anchor","asChild","Primitive","button","_babelRuntimeHelpersExtends","ref","onMouseEnter","composeEventHandlers","onMouseLeave","onMouseDown","onBlur","onKeyDown","TooltipContent","forceMount","contentProps","Presence","present","$bfd2ef98f93cfd0786881e49eeb6a4$var$TooltipContentImpl","TooltipContentImpl","ariaLabel","portalled","PortalWrapper","Portal","Fragment","useEscapeKeydown","$bfd2ef98f93cfd0786881e49eeb6a4$var$CheckTriggerMoved","Content","style","Slottable","_radixUiReactVisuallyHidden","role","TooltipArrow","Arrow","CheckTriggerMoved","triggerRect","useRect","triggerLeft","left","previousTriggerLeft","usePrevious","triggerTop","top","previousTriggerTop","Trigger"],"version":3,"file":"index.js.map"}
|
|
1
|
+
{"mappings":"IAAgCA,u0BAAAA,8CAClBA,EAAEC,WAAaD,EAAEE,QAAUF,EAWzC,SAASG,EAAuBC,EAAMC,GAcpC,OAbAC,OAAOC,KAAKF,GAAQG,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeN,EAAMK,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOP,EAAOI,SAKbL,ECoGT,SAASS,EACPC,GAEA,MAAO,CAAEC,KAjIgB,yBAiIUF,OAAQC,GC9G7C,IAAIE,EACAC,EAEJ,MAsBMC,EAAuBC,GAAO,CAACC,EAASC,KAAV,IAAAC,EAAA,MAAqB,IACpDF,EACHG,GAAE,QAAAD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AC3BC,EAAsBC,EAAYH,GAClCI,EAAaN,MAAAA,OAAH,EAAGA,EAAaO,IAC1BC,EAAqBH,EAAYC,GACjC3D,EAAchG,EAAQ2G,QAa5B,OAXA1B,EAAMW,WAAU,WAGavE,IAAxBoI,GAAqCA,IAAwBF,QACtClI,IAAvBwI,GAAoCA,IAAuBF,IAG5D3D,MAED,CAACA,EAAayD,EAAqBI,EAAoBN,EAAaI,IAEhE,4BAGT,MAAMtD,EAAO9B,iBACb,MAAMuF,EAAUlD,oBAChB,MAAMgC,EAAUd,oBAChB,MAAMqB,EAAQF","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/tooltip/src/createStateMachine.tsx","./packages/react/tooltip/src/tooltipStateChart.tsx","./packages/react/tooltip/src/Tooltip.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","const ASSIGN_ACTION_TYPE = 'machine.actions.assign' as const;\n\nconst isProduction = process.env.NODE_ENV === 'production';\n\ntype StateChart<State extends string, Context, Event extends { type: string }> = {\n initial: State;\n context: Context;\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n states: {\n [stateValue in State]: {\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n entry?: Array<Action<Context, Event>>;\n exit?: Array<Action<Context, Event>>;\n };\n };\n};\n\ntype Transition<State extends string, Context, Event> = {\n target?: State;\n actions?: Array<Action<Context, Event>>;\n cond?: (context: Context, Event: Event) => boolean;\n};\n\ntype Action<Context, Event> = ActionFunction<Context, Event> | AssignAction<Context, Event>;\n\ntype ActionFunction<Context, Event> = (\n context: Context,\n event: Event,\n send: (event: Event) => void\n) => void;\n\nfunction createStateMachine<State extends string, Context, Event extends { type: string }>(\n stateChart: StateChart<State, Context, Event>,\n { debug = false, warnOnUnknownTransitions = !isProduction } = {}\n) {\n let currentState = stateChart.initial;\n let currentContext = stateChart.context;\n\n type CallbackFn = (args: { state: State; context: Context }) => void;\n const subscriptions: Array<CallbackFn> = [];\n\n function subscribe(callback: CallbackFn) {\n subscriptions.push(callback);\n return () => {\n subscriptions.splice(subscriptions.indexOf(callback), 1);\n };\n }\n\n function notify() {\n subscriptions.forEach((callback) => callback({ state: currentState, context: currentContext }));\n }\n\n const send = (event: Event) => {\n const stateDefinition = stateChart.states[currentState];\n const type: Event['type'] | undefined = event.type;\n const topLevelTransition: Transition<State, Context, Event> | undefined = stateChart.on?.[type];\n const stateTransition: Transition<State, Context, Event> | undefined =\n stateDefinition.on?.[type];\n const transition = topLevelTransition ?? stateTransition;\n\n if (transition === undefined) {\n if (warnOnUnknownTransitions) {\n console.warn(\n `From state: \"${currentState}\", event \"${type}\" has no transition to any state`\n );\n }\n } else {\n const { target: nextState, actions = [], cond = () => true } = transition;\n const nextStateDefinition = nextState ? stateChart.states[nextState] : {};\n\n if (cond(currentContext, event)) {\n // execute actions\n const allActions = (stateDefinition.exit || []).concat(\n actions,\n nextStateDefinition.entry || []\n );\n currentContext = executeActions(allActions, event, currentContext);\n\n if (nextState) {\n currentState = nextState;\n\n if (debug) {\n console.group('event:', event);\n console.log('state:', currentState);\n console.log('context:', currentContext);\n console.groupEnd();\n }\n\n notify();\n }\n }\n }\n };\n\n function getContext() {\n return currentContext;\n }\n\n function executeActions(\n actions: Array<Action<Context, Event>>,\n event: Event,\n context: Context\n ): Context {\n let nextContext = context;\n actions?.forEach((action) => {\n if (typeof action === 'function') {\n action(nextContext, event, send);\n } else if (action.type === ASSIGN_ACTION_TYPE) {\n nextContext = action.assign(nextContext, event);\n }\n });\n return nextContext;\n }\n\n return { subscribe, send, getContext };\n}\n\ntype AssignAction<Context, Event> = {\n type: typeof ASSIGN_ACTION_TYPE;\n assign(context: Context, event: Event): Context;\n};\n\nfunction assign<Context, Event>(\n assignFn: AssignAction<Context, Event>['assign']\n): AssignAction<Context, Event> {\n return { type: ASSIGN_ACTION_TYPE, assign: assignFn };\n}\n\nexport { createStateMachine, assign };\nexport type { StateChart, Action };\n","import { assign } from './createStateMachine';\n\nimport type { StateChart, Action } from './createStateMachine';\n\ntype TooltipState = 'closed' | 'opening' | 'open' | 'closing';\n\ntype TooltipEvent =\n | { type: 'OPEN'; id: string; delayDuration?: number }\n | { type: 'CLOSE'; id: string; skipDelayDuration: number }\n | { type: 'FOCUS'; id: string }\n | { type: 'DELAY_TIMER_END' }\n | { type: 'SKIP_DELAY_TIMER_END' };\n\ntype TooltipContext = { id: string | null; delayed: boolean };\n\ntype TooltipStateChart = StateChart<TooltipState, TooltipContext, TooltipEvent>;\ntype TooltipAction = Action<TooltipContext, TooltipEvent>;\n\n// actions\nlet delayTimerId: number;\nlet skipDelayTimerId: number;\n\nconst startDelayTimer: TooltipAction = (context, event, send) => {\n const delayDuration: number | undefined = (event as any).delayDuration;\n const sendTimerEnd = () => send({ type: 'DELAY_TIMER_END' });\n if (delayDuration === undefined) {\n sendTimerEnd();\n } else {\n delayTimerId = window.setTimeout(sendTimerEnd, delayDuration);\n }\n};\n\nconst cancelDelayTimer: TooltipAction = () => clearTimeout(delayTimerId);\n\nconst startSkipDelayTimer: TooltipAction = (context, event, send) => {\n const skipDelayDuration: number = (event as any).skipDelayDuration ?? 300;\n skipDelayTimerId = window.setTimeout(\n () => send({ type: 'SKIP_DELAY_TIMER_END' }),\n skipDelayDuration\n );\n};\n\nconst cancelSkipDelayTimer: TooltipAction = () => clearTimeout(skipDelayTimerId);\n\nconst setId: TooltipAction = assign((context, event) => ({\n ...context,\n id: (event as any).id ?? context.id,\n}));\nconst resetId: TooltipAction = assign((context) => ({ ...context, id: null }));\nconst setDelayed: TooltipAction = assign((context) => ({ ...context, delayed: true }));\nconst resetDelayed: TooltipAction = assign((context) => ({ ...context, delayed: false }));\n\nconst tooltipStateChart: TooltipStateChart = {\n initial: 'closed',\n context: { id: null, delayed: false },\n on: {\n FOCUS: { target: 'open' },\n },\n states: {\n closed: {\n entry: [resetId],\n on: {\n OPEN: { target: 'opening' },\n },\n },\n\n opening: {\n entry: [startDelayTimer, setId, setDelayed],\n exit: [cancelDelayTimer],\n on: {\n DELAY_TIMER_END: { target: 'open' },\n CLOSE: { target: 'closed' },\n },\n },\n\n open: {\n entry: [setId],\n exit: [resetDelayed],\n on: {\n OPEN: { target: 'open' },\n CLOSE: {\n target: 'closing',\n cond: (context, event) => context.id === (event as any).id,\n },\n },\n },\n\n closing: {\n entry: [startSkipDelayTimer],\n exit: [cancelSkipDelayTimer],\n on: {\n OPEN: { target: 'open' },\n SKIP_DELAY_TIMER_END: { target: 'closed' },\n },\n },\n },\n};\n\nexport { tooltipStateChart };\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useRect } from '@radix-ui/react-use-rect';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport * as PopperPrimitive from '@radix-ui/react-popper';\nimport { createPopperScope } from '@radix-ui/react-popper';\nimport { Portal } from '@radix-ui/react-portal';\nimport { Slottable } from '@radix-ui/react-slot';\nimport * as VisuallyHiddenPrimitive from '@radix-ui/react-visually-hidden';\nimport { useId } from '@radix-ui/react-id';\nimport { createStateMachine } from './createStateMachine';\nimport { tooltipStateChart } from './tooltipStateChart';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * State machine\n * -----------------------------------------------------------------------------------------------*/\n\ntype StateAttribute = 'closed' | 'delayed-open' | 'instant-open';\nconst stateMachine = createStateMachine(tooltipStateChart);\n\n/* -------------------------------------------------------------------------------------------------\n * Tooltip\n * -----------------------------------------------------------------------------------------------*/\n\nconst TOOLTIP_NAME = 'Tooltip';\n\ntype ScopedProps<P> = P & { __scopeTooltip?: Scope };\nconst [createTooltipContext, createTooltipScope] = createContextScope(TOOLTIP_NAME, [\n createPopperScope,\n]);\nconst usePopperScope = createPopperScope();\n\ntype TooltipContextValue = {\n contentId: string;\n open: boolean;\n stateAttribute: StateAttribute;\n trigger: TooltipTriggerElement | null;\n onTriggerChange(trigger: TooltipTriggerElement | null): void;\n onFocus(): void;\n onOpen(): void;\n onClose(): void;\n};\n\nconst [TooltipProvider, useTooltipContext] =\n createTooltipContext<TooltipContextValue>(TOOLTIP_NAME);\n\ninterface TooltipProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n\n /**\n * The duration from when the mouse enters the trigger until the tooltip gets opened.\n * (default: 700)\n */\n delayDuration?: number;\n\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * (default: 300)\n */\n skipDelayDuration?: number;\n children?: React.ReactNode;\n}\n\nconst Tooltip: React.FC<TooltipProps> = (props: ScopedProps<TooltipProps>) => {\n const {\n __scopeTooltip,\n children,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n delayDuration = 700,\n skipDelayDuration = 300,\n } = props;\n const popperScope = usePopperScope(__scopeTooltip);\n const [trigger, setTrigger] = React.useState<HTMLButtonElement | null>(null);\n const contentId = useId();\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n const [stateAttribute, setStateAttribute] = React.useState<StateAttribute>(\n openProp ? 'instant-open' : 'closed'\n );\n\n // control open state using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (state === 'open' && context.id === contentId) {\n setOpen(true);\n } else {\n setOpen(false);\n }\n });\n\n return unsubscribe;\n }, [contentId, setOpen]);\n\n // sync state attribute with using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (context.id === contentId) {\n if (state === 'open') {\n setStateAttribute(context.delayed ? 'delayed-open' : 'instant-open');\n } else {\n setStateAttribute('closed');\n }\n } else {\n setStateAttribute('closed');\n }\n });\n\n return unsubscribe;\n }, [contentId]);\n\n const handleFocus = React.useCallback(\n () => stateMachine.send({ type: 'FOCUS', id: contentId }),\n [contentId]\n );\n const handleOpen = React.useCallback(\n () => stateMachine.send({ type: 'OPEN', id: contentId, delayDuration }),\n [contentId, delayDuration]\n );\n const handleClose = React.useCallback(\n () => stateMachine.send({ type: 'CLOSE', id: contentId, skipDelayDuration }),\n [skipDelayDuration, contentId]\n );\n\n // send transition if the component unmounts\n React.useEffect(() => () => handleClose(), [handleClose]);\n\n // if we're controlling the component\n // put the state machine in the appropriate state\n useLayoutEffect(() => {\n if (openProp === true) {\n stateMachine.send({ type: 'OPEN', id: contentId });\n }\n }, [contentId, openProp]);\n\n return (\n <PopperPrimitive.Root {...popperScope}>\n <TooltipProvider\n scope={__scopeTooltip}\n contentId={contentId}\n open={open}\n stateAttribute={stateAttribute}\n trigger={trigger}\n onTriggerChange={setTrigger}\n onFocus={handleFocus}\n onOpen={handleOpen}\n onClose={handleClose}\n >\n {children}\n </TooltipProvider>\n </PopperPrimitive.Root>\n );\n};\n\nTooltip.displayName = TOOLTIP_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'TooltipTrigger';\n\ntype TooltipTriggerElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface TooltipTriggerProps extends PrimitiveButtonProps {}\n\nconst TooltipTrigger = React.forwardRef<TooltipTriggerElement, TooltipTriggerProps>(\n (props: ScopedProps<TooltipTriggerProps>, forwardedRef) => {\n const { __scopeTooltip, ...triggerProps } = props;\n const context = useTooltipContext(TRIGGER_NAME, __scopeTooltip);\n const popperScope = usePopperScope(__scopeTooltip);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.onTriggerChange);\n return (\n <PopperPrimitive.Anchor asChild {...popperScope}>\n <Primitive.button\n type=\"button\"\n aria-describedby={context.open ? context.contentId : undefined}\n data-state={context.stateAttribute}\n {...triggerProps}\n ref={composedTriggerRef}\n onMouseEnter={composeEventHandlers(props.onMouseEnter, context.onOpen)}\n onMouseLeave={composeEventHandlers(props.onMouseLeave, context.onClose)}\n onMouseDown={composeEventHandlers(props.onMouseDown, context.onClose)}\n onFocus={composeEventHandlers(props.onFocus, context.onFocus)}\n onBlur={composeEventHandlers(props.onBlur, context.onClose)}\n onKeyDown={composeEventHandlers(props.onKeyDown, (event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n context.onClose();\n }\n })}\n />\n </PopperPrimitive.Anchor>\n );\n }\n);\n\nTooltipTrigger.displayName = TRIGGER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'TooltipContent';\n\ntype TooltipContentElement = TooltipContentImplElement;\ninterface TooltipContentProps extends TooltipContentImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst TooltipContent = React.forwardRef<TooltipContentElement, TooltipContentProps>(\n (props: ScopedProps<TooltipContentProps>, forwardedRef) => {\n const { forceMount, ...contentProps } = props;\n const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);\n return (\n <Presence present={forceMount || context.open}>\n <TooltipContentImpl ref={forwardedRef} {...contentProps} />\n </Presence>\n );\n }\n);\n\ntype TooltipContentImplElement = React.ElementRef<typeof PopperPrimitive.Content>;\ntype PopperContentProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Content>;\ninterface TooltipContentImplProps extends PopperContentProps {\n /**\n * A more descriptive label for accessibility purpose\n */\n 'aria-label'?: string;\n\n /**\n * Whether the Tooltip should render in a Portal\n * (default: `true`)\n */\n portalled?: boolean;\n}\n\nconst TooltipContentImpl = React.forwardRef<TooltipContentImplElement, TooltipContentImplProps>(\n (props: ScopedProps<TooltipContentImplProps>, forwardedRef) => {\n const {\n __scopeTooltip,\n children,\n 'aria-label': ariaLabel,\n portalled = true,\n ...contentProps\n } = props;\n const context = useTooltipContext(CONTENT_NAME, __scopeTooltip);\n const popperScope = usePopperScope(__scopeTooltip);\n const PortalWrapper = portalled ? Portal : React.Fragment;\n\n useEscapeKeydown(() => context.onClose());\n\n return (\n <PortalWrapper>\n <CheckTriggerMoved __scopeTooltip={__scopeTooltip} />\n <PopperPrimitive.Content\n data-state={context.stateAttribute}\n {...popperScope}\n {...contentProps}\n ref={forwardedRef}\n style={{\n ...contentProps.style,\n // re-namespace exposed content custom property\n ['--radix-tooltip-content-transform-origin' as any]:\n 'var(--radix-popper-transform-origin)',\n }}\n >\n <Slottable>{children}</Slottable>\n <VisuallyHiddenPrimitive.Root id={context.contentId} role=\"tooltip\">\n {ariaLabel || children}\n </VisuallyHiddenPrimitive.Root>\n </PopperPrimitive.Content>\n </PortalWrapper>\n );\n }\n);\n\nTooltipContent.displayName = CONTENT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'TooltipArrow';\n\ntype TooltipArrowElement = React.ElementRef<typeof PopperPrimitive.Arrow>;\ntype PopperArrowProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Arrow>;\ninterface TooltipArrowProps extends PopperArrowProps {}\n\nconst TooltipArrow = React.forwardRef<TooltipArrowElement, TooltipArrowProps>(\n (props: ScopedProps<TooltipArrowProps>, forwardedRef) => {\n const { __scopeTooltip, ...arrowProps } = props;\n const popperScope = usePopperScope(__scopeTooltip);\n return <PopperPrimitive.Arrow {...popperScope} {...arrowProps} ref={forwardedRef} />;\n }\n);\n\nTooltipArrow.displayName = ARROW_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction CheckTriggerMoved(props: ScopedProps<{}>) {\n const { __scopeTooltip } = props;\n const context = useTooltipContext('CheckTriggerMoved', __scopeTooltip);\n\n const triggerRect = useRect(context.trigger);\n const triggerLeft = triggerRect?.left;\n const previousTriggerLeft = usePrevious(triggerLeft);\n const triggerTop = triggerRect?.top;\n const previousTriggerTop = usePrevious(triggerTop);\n const handleClose = context.onClose;\n\n React.useEffect(() => {\n // checking if the user has scrolled…\n const hasTriggerMoved =\n (previousTriggerLeft !== undefined && previousTriggerLeft !== triggerLeft) ||\n (previousTriggerTop !== undefined && previousTriggerTop !== triggerTop);\n\n if (hasTriggerMoved) {\n handleClose();\n }\n }, [handleClose, previousTriggerLeft, previousTriggerTop, triggerLeft, triggerTop]);\n\n return null;\n}\n\nconst Root = Tooltip;\nconst Trigger = TooltipTrigger;\nconst Content = TooltipContent;\nconst Arrow = TooltipArrow;\n\nexport {\n createTooltipScope,\n //\n Tooltip,\n TooltipTrigger,\n TooltipContent,\n TooltipArrow,\n //\n Root,\n Trigger,\n Content,\n Arrow,\n};\nexport type { TooltipProps, TooltipTriggerProps, TooltipContentProps, TooltipArrowProps };\n"],"names":["a","__esModule","default","$parcel$exportWildcard","dest","source","Object","keys","forEach","key","defineProperty","enumerable","get","assign","assignFn","type","delayTimerId","skipDelayTimerId","setId","$fb910db130fc9c6f19b2800f728d3b10$export$assign","context","event","_id","id","stateMachine","stateChart","debug","warnOnUnknownTransitions","currentState","initial","currentContext","subscriptions","send","_stateChart$on","_stateDefinition$on","stateDefinition","states","topLevelTransition","on","stateTransition","transition","undefined","console","warn","target","nextState","actions","cond","nextStateDefinition","allActions","exit","concat","entry","nextContext","action","executeActions","group","log","groupEnd","callback","state","subscribe","push","splice","indexOf","getContext","$fb910db130fc9c6f19b2800f728d3b10$export$createStateMachine","delayed","FOCUS","closed","OPEN","opening","delayDuration","sendTimerEnd","window","setTimeout","clearTimeout","DELAY_TIMER_END","CLOSE","open","closing","_skipDelayDuration","skipDelayDuration","SKIP_DELAY_TIMER_END","createTooltipContext","createTooltipScope","createContextScope","createPopperScope","usePopperScope","TooltipProvider","useTooltipContext","Tooltip","props","__scopeTooltip","children","openProp","defaultOpen","onOpenChange","popperScope","trigger","setTrigger","React","useState","contentId","useId","setOpen","useControllableState","prop","defaultProp","onChange","stateAttribute","setStateAttribute","useEffect","handleFocus","useCallback","handleOpen","handleClose","useLayoutEffect","_react","createElement","_radixUiReactPopper","Root","$bfd2ef98f93cfd0786881e49eeb6a4$var$TooltipProvider","scope","onTriggerChange","onFocus","onOpen","onClose","TooltipTrigger","forwardRef","forwardedRef","triggerProps","composedTriggerRef","useComposedRefs","Anchor","_babelRuntimeHelpersExtends","asChild","Primitive","button","ref","onMouseEnter","composeEventHandlers","onMouseLeave","onMouseDown","onBlur","onKeyDown","TooltipContent","forceMount","contentProps","Presence","present","$bfd2ef98f93cfd0786881e49eeb6a4$var$TooltipContentImpl","TooltipContentImpl","ariaLabel","portalled","PortalWrapper","Portal","Fragment","useEscapeKeydown","$bfd2ef98f93cfd0786881e49eeb6a4$var$CheckTriggerMoved","Content","style","Slottable","_radixUiReactVisuallyHidden","role","TooltipArrow","arrowProps","Arrow","CheckTriggerMoved","triggerRect","useRect","triggerLeft","left","previousTriggerLeft","usePrevious","triggerTop","top","previousTriggerTop","Trigger"],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useId as e}from"@radix-ui/react-id";import*as t from"@radix-ui/react-visually-hidden";import{Slottable as o}from"@radix-ui/react-slot";import{Portal as n}from"@radix-ui/react-portal";import*as r from"@radix-ui/react-popper";import{
|
|
1
|
+
import{useId as e}from"@radix-ui/react-id";import*as t from"@radix-ui/react-visually-hidden";import{Slottable as o}from"@radix-ui/react-slot";import{Portal as n}from"@radix-ui/react-portal";import*as r from"@radix-ui/react-popper";import{createPopperScope as i}from"@radix-ui/react-popper";import{Primitive as a}from"@radix-ui/react-primitive";import{Presence as s}from"@radix-ui/react-presence";import{useRect as l}from"@radix-ui/react-use-rect";import{usePrevious as c}from"@radix-ui/react-use-previous";import{useLayoutEffect as p}from"@radix-ui/react-use-layout-effect";import{useEscapeKeydown as u}from"@radix-ui/react-use-escape-keydown";import{useControllableState as d}from"@radix-ui/react-use-controllable-state";import{createContextScope as m}from"@radix-ui/react-context";import{useComposedRefs as f}from"@radix-ui/react-compose-refs";import{composeEventHandlers as g}from"@radix-ui/primitive";import*as E from"react";import x from"@babel/runtime/helpers/esm/extends";function y(e){return{type:"machine.actions.assign",assign:e}}let T,C;const v=y(((e,t)=>{var o;return{...e,id:null!==(o=t.id)&&void 0!==o?o:e.id}})),_=function(e,{debug:t=!1,warnOnUnknownTransitions:o=!1}={}){let n=e.initial,r=e.context;const i=[],a=s=>{var l,c;const p=e.states[n],u=s.type,d=null===(l=e.on)||void 0===l?void 0:l[u],m=null===(c=p.on)||void 0===c?void 0:c[u],f=null!=d?d:m;if(void 0===f)o&&console.warn(`From state: "${n}", event "${u}" has no transition to any state`);else{const{target:o,actions:l=[],cond:c=(()=>!0)}=f,u=o?e.states[o]:{};if(c(r,s)){const e=(p.exit||[]).concat(l,u.entry||[]);r=function(e,t,o){let n=o;return null==e||e.forEach((e=>{"function"==typeof e?e(n,t,a):"machine.actions.assign"===e.type&&(n=e.assign(n,t))})),n}(e,s,r),o&&(n=o,t&&(console.group("event:",s),console.log("state:",n),console.log("context:",r),console.groupEnd()),i.forEach((e=>e({state:n,context:r}))))}}};return{subscribe:function(e){return i.push(e),()=>{i.splice(i.indexOf(e),1)}},send:a,getContext:function(){return r}}}({initial:"closed",context:{id:null,delayed:!1},on:{FOCUS:{target:"open"}},states:{closed:{entry:[y((e=>({...e,id:null})))],on:{OPEN:{target:"opening"}}},opening:{entry:[(e,t,o)=>{const n=t.delayDuration,r=()=>o({type:"DELAY_TIMER_END"});void 0===n?r():T=window.setTimeout(r,n)},v,y((e=>({...e,delayed:!0})))],exit:[()=>clearTimeout(T)],on:{DELAY_TIMER_END:{target:"open"},CLOSE:{target:"closed"}}},open:{entry:[v],exit:[y((e=>({...e,delayed:!1})))],on:{OPEN:{target:"open"},CLOSE:{target:"closing",cond:(e,t)=>e.id===t.id}}},closing:{entry:[(e,t,o)=>{var n;const r=null!==(n=t.skipDelayDuration)&&void 0!==n?n:300;C=window.setTimeout((()=>o({type:"SKIP_DELAY_TIMER_END"})),r)}],exit:[()=>clearTimeout(C)],on:{OPEN:{target:"open"},SKIP_DELAY_TIMER_END:{target:"closed"}}}}}),[b,D]=m("Tooltip",[i]);export{D as createTooltipScope};const w=i(),[h,O]=b("Tooltip");export const Tooltip=t=>{const{__scopeTooltip:o,children:n,open:i,defaultOpen:a=!1,onOpenChange:s,delayDuration:l=700,skipDelayDuration:c=300}=t,u=w(o),[m,f]=E.useState(null),g=e(),[x=!1,y]=d({prop:i,defaultProp:a,onChange:s}),[T,C]=E.useState(i?"instant-open":"closed");E.useEffect((()=>_.subscribe((({state:e,context:t})=>{"open"===e&&t.id===g?y(!0):y(!1)}))),[g,y]),E.useEffect((()=>_.subscribe((({state:e,context:t})=>{t.id===g?C("open"===e?t.delayed?"delayed-open":"instant-open":"closed"):C("closed")}))),[g]);const v=E.useCallback((()=>_.send({type:"FOCUS",id:g})),[g]),b=E.useCallback((()=>_.send({type:"OPEN",id:g,delayDuration:l})),[g,l]),D=E.useCallback((()=>_.send({type:"CLOSE",id:g,skipDelayDuration:c})),[c,g]);return E.useEffect((()=>()=>D()),[D]),p((()=>{!0===i&&_.send({type:"OPEN",id:g})}),[g,i]),/*#__PURE__*/E.createElement(r.Root,u,/*#__PURE__*/E.createElement(h,{scope:o,contentId:g,open:x,stateAttribute:T,trigger:m,onTriggerChange:f,onFocus:v,onOpen:b,onClose:D},n))};/*#__PURE__*/export const TooltipTrigger=/*#__PURE__*/E.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,i=O("TooltipTrigger",o),s=w(o),l=f(t,i.onTriggerChange);/*#__PURE__*/return E.createElement(r.Anchor,x({asChild:!0},s),/*#__PURE__*/E.createElement(a.button,x({type:"button","aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute},n,{ref:l,onMouseEnter:g(e.onMouseEnter,i.onOpen),onMouseLeave:g(e.onMouseLeave,i.onClose),onMouseDown:g(e.onMouseDown,i.onClose),onFocus:g(e.onFocus,i.onFocus),onBlur:g(e.onBlur,i.onClose),onKeyDown:g(e.onKeyDown,(e=>{"Enter"!==e.key&&" "!==e.key||i.onClose()}))})))}));/*#__PURE__*/export const TooltipContent=/*#__PURE__*/E.forwardRef(((e,t)=>{const{forceMount:o,...n}=e,r=O("TooltipContent",e.__scopeTooltip);/*#__PURE__*/return E.createElement(s,{present:o||r.open},/*#__PURE__*/E.createElement(A,x({ref:t},n)))}));const A=/*#__PURE__*/E.forwardRef(((e,i)=>{const{__scopeTooltip:a,children:s,"aria-label":l,portalled:c=!0,...p}=e,d=O("TooltipContent",a),m=w(a),f=c?n:E.Fragment;return u((()=>d.onClose())),/*#__PURE__*/E.createElement(f,null,/*#__PURE__*/E.createElement(M,{__scopeTooltip:a}),/*#__PURE__*/E.createElement(r.Content,x({"data-state":d.stateAttribute},m,p,{ref:i,style:{...p.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)"}}),/*#__PURE__*/E.createElement(o,null,s),/*#__PURE__*/E.createElement(t.Root,{id:d.contentId,role:"tooltip"},l||s)))}));/*#__PURE__*/export const TooltipArrow=/*#__PURE__*/E.forwardRef(((e,t)=>{const{__scopeTooltip:o,...n}=e,i=w(o);/*#__PURE__*/return E.createElement(r.Arrow,x({},i,n,{ref:t}))}));/*#__PURE__*/function M(e){const{__scopeTooltip:t}=e,o=O("CheckTriggerMoved",t),n=l(o.trigger),r=null==n?void 0:n.left,i=c(r),a=null==n?void 0:n.top,s=c(a),p=o.onClose;return E.useEffect((()=>{(void 0!==i&&i!==r||void 0!==s&&s!==a)&&p()}),[p,i,s,r,a]),null}export const Root=Tooltip;export const Trigger=TooltipTrigger;export const Content=TooltipContent;export const Arrow=TooltipArrow;
|
|
2
2
|
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"m5BA8HA,SAASA,EACPC,GAEA,MAAO,CAAEC,KAjIgB,yBAiIUF,OAAQC,GC9G7C,IAAIE,EACAC,EAEJ,MAsBMC,EAAuBC,GAAO,CAACC,EAASC,KAAV,IAAAC,EAAA,MAAqB,IACpDF,EACHG,GAAE,QAAAD,EAAGD,EAAcE,UAAjB,IAAAD,EAAAA,EAAuBF,EAAQG,OCpB7BC,EFSN,SACEC,GACAC,MAAEA,GAAQ,EAAVC,yBAAiBA,GAA2B,GAAkB,IAE9D,IAAIC,EAAeH,EAAWI,QAC1BC,EAAiBL,EAAWL,QAGhC,MAAMW,EAAmC,GAanCC,EAAQX,IAAiB,IAAAY,EAAAC,EAC7B,MAAMC,EAAkBV,EAAWW,OAAOR,GACpCb,EAAkCM,EAAMN,KACxCsB,EAAiE,QAAAJ,EAAGR,EAAWa,UAAd,IAAAL,OAAA,EAAGA,EAAgBlB,GACpFwB,EAA8D,QAAAL,EAClEC,EAAgBG,UADkD,IAAAJ,OAAA,EAClEA,EAAqBnB,GACjByB,EAAaH,MAAAA,EAAAA,EA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C2C,EAAwBzC,KAAzB,CAA8B7F,GAAIH,EAAQ8E,UAAW4D,KAAK,WACvDX,GAAazD,4BAoB1B,MAAMqE,0BAAe/D,EAAM2B,YACzB,CAAClC,EAAOmC,iBAAiBX,EAAAC,cAACC,EAAgB6C,MAAjB7B,EAAA,GAA2B1C,EAA3B,CAAkC2C,IAAKR,oBAOlE,SAASqC,IACP,MAAM7I,EAAUkE,EAAkB,qBAE5B4E,EAAcC,EAAQ/I,EAAQ0E,SAC9BsE,EAAcF,MAAAA,OAAH,EAAGA,EAAaG,KAC3BC,EAAsBC,EAAYH,GAClCI,EAAaN,MAAAA,OAAH,EAAGA,EAAaO,IAC1BC,EAAqBH,EAAYC,GACjCzD,EAAc3F,EAAQqG,QAa5B,OAXAzB,EAAMW,WAAU,WAGalE,IAAxB6H,GAAqCA,IAAwBF,QACtC3H,IAAvBiI,GAAoCA,IAAuBF,IAG5DzD,MAED,CAACA,EAAauD,EAAqBI,EAAoBN,EAAaI,IAEhE,YAGT,MAAMpD,KAAO5B,eACb,MAAMmF,QAAUjD,sBAChB,MAAMgC,QAAUd,sBAChB,MAAMoB,MAAQD","sources":["./packages/react/tooltip/src/createStateMachine.tsx","./packages/react/tooltip/src/tooltipStateChart.tsx","./packages/react/tooltip/src/Tooltip.tsx"],"sourcesContent":["const ASSIGN_ACTION_TYPE = 'machine.actions.assign' as const;\n\nconst isProduction = process.env.NODE_ENV === 'production';\n\ntype StateChart<State extends string, Context, Event extends { type: string }> = {\n initial: State;\n context: Context;\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n states: {\n [stateValue in State]: {\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n entry?: Array<Action<Context, Event>>;\n exit?: Array<Action<Context, Event>>;\n };\n };\n};\n\ntype Transition<State extends string, Context, Event> = {\n target?: State;\n actions?: Array<Action<Context, Event>>;\n cond?: (context: Context, Event: Event) => boolean;\n};\n\ntype Action<Context, Event> = ActionFunction<Context, Event> | AssignAction<Context, Event>;\n\ntype ActionFunction<Context, Event> = (\n context: Context,\n event: Event,\n send: (event: Event) => void\n) => void;\n\nfunction createStateMachine<State extends string, Context, Event extends { type: string }>(\n stateChart: StateChart<State, Context, Event>,\n { debug = false, warnOnUnknownTransitions = !isProduction } = {}\n) {\n let currentState = stateChart.initial;\n let currentContext = stateChart.context;\n\n type CallbackFn = (args: { state: State; context: Context }) => void;\n const subscriptions: Array<CallbackFn> = [];\n\n function subscribe(callback: CallbackFn) {\n subscriptions.push(callback);\n return () => {\n subscriptions.splice(subscriptions.indexOf(callback), 1);\n };\n }\n\n function notify() {\n subscriptions.forEach((callback) => callback({ state: currentState, context: currentContext }));\n }\n\n const send = (event: Event) => {\n const stateDefinition = stateChart.states[currentState];\n const type: Event['type'] | undefined = event.type;\n const topLevelTransition: Transition<State, Context, Event> | undefined = stateChart.on?.[type];\n const stateTransition: Transition<State, Context, Event> | undefined =\n stateDefinition.on?.[type];\n const transition = topLevelTransition ?? stateTransition;\n\n if (transition === undefined) {\n if (warnOnUnknownTransitions) {\n console.warn(\n `From state: \"${currentState}\", event \"${type}\" has no transition to any state`\n );\n }\n } else {\n const { target: nextState, actions = [], cond = () => true } = transition;\n const nextStateDefinition = nextState ? stateChart.states[nextState] : {};\n\n if (cond(currentContext, event)) {\n // execute actions\n const allActions = (stateDefinition.exit || []).concat(\n actions,\n nextStateDefinition.entry || []\n );\n currentContext = executeActions(allActions, event, currentContext);\n\n if (nextState) {\n currentState = nextState;\n\n if (debug) {\n console.group('event:', event);\n console.log('state:', currentState);\n console.log('context:', currentContext);\n console.groupEnd();\n }\n\n notify();\n }\n }\n }\n };\n\n function getContext() {\n return currentContext;\n }\n\n function executeActions(\n actions: Array<Action<Context, Event>>,\n event: Event,\n context: Context\n ): Context {\n let nextContext = context;\n actions?.forEach((action) => {\n if (typeof action === 'function') {\n action(nextContext, event, send);\n } else if (action.type === ASSIGN_ACTION_TYPE) {\n nextContext = action.assign(nextContext, event);\n }\n });\n return nextContext;\n }\n\n return { subscribe, send, getContext };\n}\n\ntype AssignAction<Context, Event> = {\n type: typeof ASSIGN_ACTION_TYPE;\n assign(context: Context, event: Event): Context;\n};\n\nfunction assign<Context, Event>(\n assignFn: AssignAction<Context, Event>['assign']\n): AssignAction<Context, Event> {\n return { type: ASSIGN_ACTION_TYPE, assign: assignFn };\n}\n\nexport { createStateMachine, assign };\nexport type { StateChart, Action };\n","import { assign } from './createStateMachine';\n\nimport type { StateChart, Action } from './createStateMachine';\n\ntype TooltipState = 'closed' | 'opening' | 'open' | 'closing';\n\ntype TooltipEvent =\n | { type: 'OPEN'; id: string; delayDuration?: number }\n | { type: 'CLOSE'; id: string; skipDelayDuration: number }\n | { type: 'FOCUS'; id: string }\n | { type: 'DELAY_TIMER_END' }\n | { type: 'SKIP_DELAY_TIMER_END' };\n\ntype TooltipContext = { id: string | null; delayed: boolean };\n\ntype TooltipStateChart = StateChart<TooltipState, TooltipContext, TooltipEvent>;\ntype TooltipAction = Action<TooltipContext, TooltipEvent>;\n\n// actions\nlet delayTimerId: number;\nlet skipDelayTimerId: number;\n\nconst startDelayTimer: TooltipAction = (context, event, send) => {\n const delayDuration: number | undefined = (event as any).delayDuration;\n const sendTimerEnd = () => send({ type: 'DELAY_TIMER_END' });\n if (delayDuration === undefined) {\n sendTimerEnd();\n } else {\n delayTimerId = window.setTimeout(sendTimerEnd, delayDuration);\n }\n};\n\nconst cancelDelayTimer: TooltipAction = () => clearTimeout(delayTimerId);\n\nconst startSkipDelayTimer: TooltipAction = (context, event, send) => {\n const skipDelayDuration: number = (event as any).skipDelayDuration ?? 300;\n skipDelayTimerId = window.setTimeout(\n () => send({ type: 'SKIP_DELAY_TIMER_END' }),\n skipDelayDuration\n );\n};\n\nconst cancelSkipDelayTimer: TooltipAction = () => clearTimeout(skipDelayTimerId);\n\nconst setId: TooltipAction = assign((context, event) => ({\n ...context,\n id: (event as any).id ?? context.id,\n}));\nconst resetId: TooltipAction = assign((context) => ({ ...context, id: null }));\nconst setDelayed: TooltipAction = assign((context) => ({ ...context, delayed: true }));\nconst resetDelayed: TooltipAction = assign((context) => ({ ...context, delayed: false }));\n\nconst tooltipStateChart: TooltipStateChart = {\n initial: 'closed',\n context: { id: null, delayed: false },\n on: {\n FOCUS: { target: 'open' },\n },\n states: {\n closed: {\n entry: [resetId],\n on: {\n OPEN: { target: 'opening' },\n },\n },\n\n opening: {\n entry: [startDelayTimer, setId, setDelayed],\n exit: [cancelDelayTimer],\n on: {\n DELAY_TIMER_END: { target: 'open' },\n CLOSE: { target: 'closed' },\n },\n },\n\n open: {\n entry: [setId],\n exit: [resetDelayed],\n on: {\n OPEN: { target: 'open' },\n CLOSE: {\n target: 'closing',\n cond: (context, event) => context.id === (event as any).id,\n },\n },\n },\n\n closing: {\n entry: [startSkipDelayTimer],\n exit: [cancelSkipDelayTimer],\n on: {\n OPEN: { target: 'open' },\n SKIP_DELAY_TIMER_END: { target: 'closed' },\n },\n },\n },\n};\n\nexport { tooltipStateChart };\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContext } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useRect } from '@radix-ui/react-use-rect';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport * as PopperPrimitive from '@radix-ui/react-popper';\nimport { Portal } from '@radix-ui/react-portal';\nimport { Slottable } from '@radix-ui/react-slot';\nimport * as VisuallyHiddenPrimitive from '@radix-ui/react-visually-hidden';\nimport { useId } from '@radix-ui/react-id';\nimport { createStateMachine } from './createStateMachine';\nimport { tooltipStateChart } from './tooltipStateChart';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * State machine\n * -----------------------------------------------------------------------------------------------*/\n\ntype StateAttribute = 'closed' | 'delayed-open' | 'instant-open';\nconst stateMachine = createStateMachine(tooltipStateChart);\n\n/* -------------------------------------------------------------------------------------------------\n * Tooltip\n * -----------------------------------------------------------------------------------------------*/\n\nconst TOOLTIP_NAME = 'Tooltip';\n\ntype TooltipContextValue = {\n contentId: string;\n open: boolean;\n stateAttribute: StateAttribute;\n trigger: TooltipTriggerElement | null;\n onTriggerChange(trigger: TooltipTriggerElement | null): void;\n onFocus(): void;\n onOpen(): void;\n onClose(): void;\n};\n\nconst [TooltipProvider, useTooltipContext] = createContext<TooltipContextValue>(TOOLTIP_NAME);\n\ninterface TooltipProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n\n /**\n * The duration from when the mouse enters the trigger until the tooltip gets opened.\n * (default: 700)\n */\n delayDuration?: number;\n\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * (default: 300)\n */\n skipDelayDuration?: number;\n}\n\nconst Tooltip: React.FC<TooltipProps> = (props) => {\n const {\n children,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n delayDuration = 700,\n skipDelayDuration = 300,\n } = props;\n const [trigger, setTrigger] = React.useState<HTMLButtonElement | null>(null);\n const contentId = useId();\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n const [stateAttribute, setStateAttribute] = React.useState<StateAttribute>(\n openProp ? 'instant-open' : 'closed'\n );\n\n // control open state using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (state === 'open' && context.id === contentId) {\n setOpen(true);\n } else {\n setOpen(false);\n }\n });\n\n return unsubscribe;\n }, [contentId, setOpen]);\n\n // sync state attribute with using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (context.id === contentId) {\n if (state === 'open') {\n setStateAttribute(context.delayed ? 'delayed-open' : 'instant-open');\n } else {\n setStateAttribute('closed');\n }\n } else {\n setStateAttribute('closed');\n }\n });\n\n return unsubscribe;\n }, [contentId]);\n\n const handleFocus = React.useCallback(\n () => stateMachine.send({ type: 'FOCUS', id: contentId }),\n [contentId]\n );\n const handleOpen = React.useCallback(\n () => stateMachine.send({ type: 'OPEN', id: contentId, delayDuration }),\n [contentId, delayDuration]\n );\n const handleClose = React.useCallback(\n () => stateMachine.send({ type: 'CLOSE', id: contentId, skipDelayDuration }),\n [skipDelayDuration, contentId]\n );\n\n // send transition if the component unmounts\n React.useEffect(() => () => handleClose(), [handleClose]);\n\n // if we're controlling the component\n // put the state machine in the appropriate state\n useLayoutEffect(() => {\n if (openProp === true) {\n stateMachine.send({ type: 'OPEN', id: contentId });\n }\n }, [contentId, openProp]);\n\n return (\n <PopperPrimitive.Root>\n <TooltipProvider\n contentId={contentId}\n open={open}\n stateAttribute={stateAttribute}\n trigger={trigger}\n onTriggerChange={setTrigger}\n onFocus={handleFocus}\n onOpen={handleOpen}\n onClose={handleClose}\n >\n {children}\n </TooltipProvider>\n </PopperPrimitive.Root>\n );\n};\n\nTooltip.displayName = TOOLTIP_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'TooltipTrigger';\n\ntype TooltipTriggerElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface TooltipTriggerProps extends PrimitiveButtonProps {}\n\nconst TooltipTrigger = React.forwardRef<TooltipTriggerElement, TooltipTriggerProps>(\n (props, forwardedRef) => {\n const context = useTooltipContext(TRIGGER_NAME);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.onTriggerChange);\n return (\n <PopperPrimitive.Anchor asChild>\n <Primitive.button\n type=\"button\"\n aria-describedby={context.open ? context.contentId : undefined}\n data-state={context.stateAttribute}\n {...props}\n ref={composedTriggerRef}\n onMouseEnter={composeEventHandlers(props.onMouseEnter, context.onOpen)}\n onMouseLeave={composeEventHandlers(props.onMouseLeave, context.onClose)}\n onMouseDown={composeEventHandlers(props.onMouseDown, context.onClose)}\n onFocus={composeEventHandlers(props.onFocus, context.onFocus)}\n onBlur={composeEventHandlers(props.onBlur, context.onClose)}\n onKeyDown={composeEventHandlers(props.onKeyDown, (event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n context.onClose();\n }\n })}\n />\n </PopperPrimitive.Anchor>\n );\n }\n);\n\nTooltipTrigger.displayName = TRIGGER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'TooltipContent';\n\ntype TooltipContentElement = TooltipContentImplElement;\ninterface TooltipContentProps extends TooltipContentImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst TooltipContent = React.forwardRef<TooltipContentElement, TooltipContentProps>(\n (props, forwardedRef) => {\n const { forceMount, ...contentProps } = props;\n const context = useTooltipContext(CONTENT_NAME);\n return (\n <Presence present={forceMount || context.open}>\n <TooltipContentImpl ref={forwardedRef} {...contentProps} />\n </Presence>\n );\n }\n);\n\ntype TooltipContentImplElement = React.ElementRef<typeof PopperPrimitive.Content>;\ntype PopperContentProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Content>;\ninterface TooltipContentImplProps extends PopperContentProps {\n /**\n * A more descriptive label for accessibility purpose\n */\n 'aria-label'?: string;\n\n /**\n * Whether the Tooltip should render in a Portal\n * (default: `true`)\n */\n portalled?: boolean;\n}\n\nconst TooltipContentImpl = React.forwardRef<TooltipContentImplElement, TooltipContentImplProps>(\n (props, forwardedRef) => {\n const { children, 'aria-label': ariaLabel, portalled = true, ...contentProps } = props;\n const context = useTooltipContext(CONTENT_NAME);\n const PortalWrapper = portalled ? Portal : React.Fragment;\n\n useEscapeKeydown(() => context.onClose());\n\n return (\n <PortalWrapper>\n <CheckTriggerMoved />\n <PopperPrimitive.Content\n data-state={context.stateAttribute}\n {...contentProps}\n ref={forwardedRef}\n style={{\n ...contentProps.style,\n // re-namespace exposed content custom property\n ['--radix-tooltip-content-transform-origin' as any]:\n 'var(--radix-popper-transform-origin)',\n }}\n >\n <Slottable>{children}</Slottable>\n <VisuallyHiddenPrimitive.Root id={context.contentId} role=\"tooltip\">\n {ariaLabel || children}\n </VisuallyHiddenPrimitive.Root>\n </PopperPrimitive.Content>\n </PortalWrapper>\n );\n }\n);\n\nTooltipContent.displayName = CONTENT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'TooltipArrow';\n\ntype TooltipArrowElement = React.ElementRef<typeof PopperPrimitive.Arrow>;\ntype PopperArrowProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Arrow>;\ninterface TooltipArrowProps extends PopperArrowProps {}\n\nconst TooltipArrow = React.forwardRef<TooltipArrowElement, TooltipArrowProps>(\n (props, forwardedRef) => <PopperPrimitive.Arrow {...props} ref={forwardedRef} />\n);\n\nTooltipArrow.displayName = ARROW_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction CheckTriggerMoved() {\n const context = useTooltipContext('CheckTriggerMoved');\n\n const triggerRect = useRect(context.trigger);\n const triggerLeft = triggerRect?.left;\n const previousTriggerLeft = usePrevious(triggerLeft);\n const triggerTop = triggerRect?.top;\n const previousTriggerTop = usePrevious(triggerTop);\n const handleClose = context.onClose;\n\n React.useEffect(() => {\n // checking if the user has scrolled…\n const hasTriggerMoved =\n (previousTriggerLeft !== undefined && previousTriggerLeft !== triggerLeft) ||\n (previousTriggerTop !== undefined && previousTriggerTop !== triggerTop);\n\n if (hasTriggerMoved) {\n handleClose();\n }\n }, [handleClose, previousTriggerLeft, previousTriggerTop, triggerLeft, triggerTop]);\n\n return null;\n}\n\nconst Root = Tooltip;\nconst Trigger = TooltipTrigger;\nconst Content = TooltipContent;\nconst Arrow = TooltipArrow;\n\nexport {\n Tooltip,\n TooltipTrigger,\n TooltipContent,\n TooltipArrow,\n //\n Root,\n Trigger,\n Content,\n Arrow,\n};\nexport type { TooltipProps, TooltipTriggerProps, TooltipContentProps, TooltipArrowProps };\n"],"names":["assign","assignFn","type","delayTimerId","skipDelayTimerId","setId","$ef54466d8a95ecaa234e3ec978fbe68$export$assign","context","event","_id","id","stateMachine","stateChart","debug","warnOnUnknownTransitions","currentState","initial","currentContext","subscriptions","send","_stateChart$on","_stateDefinition$on","stateDefinition","states","topLevelTransition","on","stateTransition","transition","undefined","console","warn","target","nextState","actions","cond","nextStateDefinition","allActions","exit","concat","entry","nextContext","forEach","action","executeActions","group","log","groupEnd","callback","state","subscribe","push","splice","indexOf","getContext","$ef54466d8a95ecaa234e3ec978fbe68$export$createStateMachine","delayed","FOCUS","closed","OPEN","opening","delayDuration","sendTimerEnd","window","setTimeout","clearTimeout","DELAY_TIMER_END","CLOSE","open","closing","_skipDelayDuration","skipDelayDuration","SKIP_DELAY_TIMER_END","TooltipProvider","useTooltipContext","createContext","Tooltip","props","children","openProp","defaultOpen","onOpenChange","trigger","setTrigger","React","useState","contentId","useId","setOpen","useControllableState","prop","defaultProp","onChange","stateAttribute","setStateAttribute","useEffect","handleFocus","useCallback","handleOpen","handleClose","useLayoutEffect","_react","createElement","_radixUiReactPopper","Root","$badf5d6f88b7e9fa4e0bb85d71c0396a$var$TooltipProvider","onTriggerChange","onFocus","onOpen","onClose","TooltipTrigger","forwardRef","forwardedRef","composedTriggerRef","useComposedRefs","Anchor","asChild","Primitive","button","_babelRuntimeHelpersEsmExtends","ref","onMouseEnter","composeEventHandlers","onMouseLeave","onMouseDown","onBlur","onKeyDown","key","TooltipContent","forceMount","contentProps","Presence","present","$badf5d6f88b7e9fa4e0bb85d71c0396a$var$TooltipContentImpl","TooltipContentImpl","ariaLabel","portalled","PortalWrapper","Portal","Fragment","useEscapeKeydown","$badf5d6f88b7e9fa4e0bb85d71c0396a$var$CheckTriggerMoved","Content","style","Slottable","_radixUiReactVisuallyHidden","role","TooltipArrow","Arrow","CheckTriggerMoved","triggerRect","useRect","triggerLeft","left","previousTriggerLeft","usePrevious","triggerTop","top","previousTriggerTop","Trigger"],"version":3,"file":"index.module.js.map"}
|
|
1
|
+
{"mappings":"m9BA8HA,SAASA,EACPC,GAEA,MAAO,CAAEC,KAjIgB,yBAiIUF,OAAQC,GC9G7C,IAAIE,EACAC,EAEJ,MAsBMC,EAAuBC,GAAO,CAACC,EAASC,KAAV,IAAAC,EAAA,MAAqB,IACpDF,EACHG,GAAE,QAAAD,EAAGD,EAAcE,UAAjB,IAAAD,EAAAA,EAAuBF,EAAQG,OClB7BC,EFON,SACEC,GACAC,MAAEA,GAAQ,EAAVC,yBAAiBA,GAA2B,GAAkB,IAE9D,IAAIC,EAAeH,EAAWI,QAC1BC,EAAiBL,EAAWL,QAGhC,MAAMW,EAAmC,GAanCC,EAAQX,IAAiB,IAAAY,EAAAC,EAC7B,MAAMC,EAAkBV,EAAWW,OAAOR,GACpCb,EAAkCM,EAAMN,KACxCsB,EAAiE,QAAAJ,EAAGR,EAAWa,UAAd,IAAAL,OAAA,EAAGA,EAAgBlB,GACpFwB,EAA8D,QAAAL,EAClEC,EAAgBG,UADkD,IAAAJ,OAAA,EAClEA,EAAqBnB,GACjByB,EAAaH,MAAAA,EAAAA,EAAsBE,EAEzC,QAAmBE,IAAfD,EACEb,GACFe,QAAQC,KACL,gBAAef,cAAyBb,yCAGxC,CACL,MAAQ6B,OAAQC,EAAVC,QAAqBA,EAAU,GAA/BC,KAAmCA,EAAO,MAAM,IAASP,EACzDQ,EAAsBH,EAAYpB,EAAWW,OAAOS,GAAa,GAEvE,GAAIE,EAAKjB,EAAgBT,GAAQ,CAE/B,MAAM4B,GAAcd,EAAgBe,MAAQ,IAAIC,OAC9CL,EACAE,EAAoBI,OAAS,IAE/BtB,EAsBN,SACEgB,EACAzB,EACAD,GAEA,I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F,UAAW8D,KAAK,WACvDX,GAAa5D,4BAoB1B,MAAMwE,0BAAejE,EAAM4B,YACzB,CAACrC,EAAuCsC,KACtC,MAAMrC,eAAEA,KAAmB0E,GAAe3E,EACpCM,EAAcV,EAAeK,gBACnC,OAAOyB,EAAAC,cAACC,EAAgBgD,MAAjBjC,EAAA,GAA2BrC,EAAiBqE,EAA5C,CAAwD5B,IAAKT,qBAQxE,SAASuC,EAAkB7E,GACzB,MAAMC,eAAEA,GAAmBD,EACrBzE,EAAUuE,EAAkB,oBAAqBG,GAEjD6E,EAAcC,EAAQxJ,EAAQgF,SAC9ByE,EAAcF,MAAAA,OAAH,EAAGA,EAAaG,KAC3BC,EAAsBC,EAAYH,GAClCI,EAAaN,MAAAA,OAAH,EAAGA,EAAaO,IAC1BC,EAAqBH,EAAYC,GACjC5D,EAAcjG,EAAQ4G,QAa5B,OAXA1B,EAAMW,WAAU,WAGaxE,IAAxBsI,GAAqCA,IAAwBF,QACtCpI,IAAvB0I,GAAoCA,IAAuBF,IAG5D5D,MAED,CAACA,EAAa0D,EAAqBI,EAAoBN,EAAaI,IAEhE,YAGT,MAAMvD,KAAO9B,eACb,MAAMwF,QAAUnD,sBAChB,MAAMiC,QAAUd,sBAChB,MAAMqB,MAAQF","sources":["./packages/react/tooltip/src/createStateMachine.tsx","./packages/react/tooltip/src/tooltipStateChart.tsx","./packages/react/tooltip/src/Tooltip.tsx"],"sourcesContent":["const ASSIGN_ACTION_TYPE = 'machine.actions.assign' as const;\n\nconst isProduction = process.env.NODE_ENV === 'production';\n\ntype StateChart<State extends string, Context, Event extends { type: string }> = {\n initial: State;\n context: Context;\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n states: {\n [stateValue in State]: {\n on?: {\n [eventType in Event['type']]?: Transition<State, Context, Event>;\n };\n entry?: Array<Action<Context, Event>>;\n exit?: Array<Action<Context, Event>>;\n };\n };\n};\n\ntype Transition<State extends string, Context, Event> = {\n target?: State;\n actions?: Array<Action<Context, Event>>;\n cond?: (context: Context, Event: Event) => boolean;\n};\n\ntype Action<Context, Event> = ActionFunction<Context, Event> | AssignAction<Context, Event>;\n\ntype ActionFunction<Context, Event> = (\n context: Context,\n event: Event,\n send: (event: Event) => void\n) => void;\n\nfunction createStateMachine<State extends string, Context, Event extends { type: string }>(\n stateChart: StateChart<State, Context, Event>,\n { debug = false, warnOnUnknownTransitions = !isProduction } = {}\n) {\n let currentState = stateChart.initial;\n let currentContext = stateChart.context;\n\n type CallbackFn = (args: { state: State; context: Context }) => void;\n const subscriptions: Array<CallbackFn> = [];\n\n function subscribe(callback: CallbackFn) {\n subscriptions.push(callback);\n return () => {\n subscriptions.splice(subscriptions.indexOf(callback), 1);\n };\n }\n\n function notify() {\n subscriptions.forEach((callback) => callback({ state: currentState, context: currentContext }));\n }\n\n const send = (event: Event) => {\n const stateDefinition = stateChart.states[currentState];\n const type: Event['type'] | undefined = event.type;\n const topLevelTransition: Transition<State, Context, Event> | undefined = stateChart.on?.[type];\n const stateTransition: Transition<State, Context, Event> | undefined =\n stateDefinition.on?.[type];\n const transition = topLevelTransition ?? stateTransition;\n\n if (transition === undefined) {\n if (warnOnUnknownTransitions) {\n console.warn(\n `From state: \"${currentState}\", event \"${type}\" has no transition to any state`\n );\n }\n } else {\n const { target: nextState, actions = [], cond = () => true } = transition;\n const nextStateDefinition = nextState ? stateChart.states[nextState] : {};\n\n if (cond(currentContext, event)) {\n // execute actions\n const allActions = (stateDefinition.exit || []).concat(\n actions,\n nextStateDefinition.entry || []\n );\n currentContext = executeActions(allActions, event, currentContext);\n\n if (nextState) {\n currentState = nextState;\n\n if (debug) {\n console.group('event:', event);\n console.log('state:', currentState);\n console.log('context:', currentContext);\n console.groupEnd();\n }\n\n notify();\n }\n }\n }\n };\n\n function getContext() {\n return currentContext;\n }\n\n function executeActions(\n actions: Array<Action<Context, Event>>,\n event: Event,\n context: Context\n ): Context {\n let nextContext = context;\n actions?.forEach((action) => {\n if (typeof action === 'function') {\n action(nextContext, event, send);\n } else if (action.type === ASSIGN_ACTION_TYPE) {\n nextContext = action.assign(nextContext, event);\n }\n });\n return nextContext;\n }\n\n return { subscribe, send, getContext };\n}\n\ntype AssignAction<Context, Event> = {\n type: typeof ASSIGN_ACTION_TYPE;\n assign(context: Context, event: Event): Context;\n};\n\nfunction assign<Context, Event>(\n assignFn: AssignAction<Context, Event>['assign']\n): AssignAction<Context, Event> {\n return { type: ASSIGN_ACTION_TYPE, assign: assignFn };\n}\n\nexport { createStateMachine, assign };\nexport type { StateChart, Action };\n","import { assign } from './createStateMachine';\n\nimport type { StateChart, Action } from './createStateMachine';\n\ntype TooltipState = 'closed' | 'opening' | 'open' | 'closing';\n\ntype TooltipEvent =\n | { type: 'OPEN'; id: string; delayDuration?: number }\n | { type: 'CLOSE'; id: string; skipDelayDuration: number }\n | { type: 'FOCUS'; id: string }\n | { type: 'DELAY_TIMER_END' }\n | { type: 'SKIP_DELAY_TIMER_END' };\n\ntype TooltipContext = { id: string | null; delayed: boolean };\n\ntype TooltipStateChart = StateChart<TooltipState, TooltipContext, TooltipEvent>;\ntype TooltipAction = Action<TooltipContext, TooltipEvent>;\n\n// actions\nlet delayTimerId: number;\nlet skipDelayTimerId: number;\n\nconst startDelayTimer: TooltipAction = (context, event, send) => {\n const delayDuration: number | undefined = (event as any).delayDuration;\n const sendTimerEnd = () => send({ type: 'DELAY_TIMER_END' });\n if (delayDuration === undefined) {\n sendTimerEnd();\n } else {\n delayTimerId = window.setTimeout(sendTimerEnd, delayDuration);\n }\n};\n\nconst cancelDelayTimer: TooltipAction = () => clearTimeout(delayTimerId);\n\nconst startSkipDelayTimer: TooltipAction = (context, event, send) => {\n const skipDelayDuration: number = (event as any).skipDelayDuration ?? 300;\n skipDelayTimerId = window.setTimeout(\n () => send({ type: 'SKIP_DELAY_TIMER_END' }),\n skipDelayDuration\n );\n};\n\nconst cancelSkipDelayTimer: TooltipAction = () => clearTimeout(skipDelayTimerId);\n\nconst setId: TooltipAction = assign((context, event) => ({\n ...context,\n id: (event as any).id ?? context.id,\n}));\nconst resetId: TooltipAction = assign((context) => ({ ...context, id: null }));\nconst setDelayed: TooltipAction = assign((context) => ({ ...context, delayed: true }));\nconst resetDelayed: TooltipAction = assign((context) => ({ ...context, delayed: false }));\n\nconst tooltipStateChart: TooltipStateChart = {\n initial: 'closed',\n context: { id: null, delayed: false },\n on: {\n FOCUS: { target: 'open' },\n },\n states: {\n closed: {\n entry: [resetId],\n on: {\n OPEN: { target: 'opening' },\n },\n },\n\n opening: {\n entry: [startDelayTimer, setId, setDelayed],\n exit: [cancelDelayTimer],\n on: {\n DELAY_TIMER_END: { target: 'open' },\n CLOSE: { target: 'closed' },\n },\n },\n\n open: {\n entry: [setId],\n exit: [resetDelayed],\n on: {\n OPEN: { target: 'open' },\n CLOSE: {\n target: 'closing',\n cond: (context, event) => context.id === (event as any).id,\n },\n },\n },\n\n closing: {\n entry: [startSkipDelayTimer],\n exit: [cancelSkipDelayTimer],\n on: {\n OPEN: { target: 'open' },\n SKIP_DELAY_TIMER_END: { target: 'closed' },\n },\n },\n },\n};\n\nexport { tooltipStateChart };\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useRect } from '@radix-ui/react-use-rect';\nimport { Presence } from '@radix-ui/react-presence';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport * as PopperPrimitive from '@radix-ui/react-popper';\nimport { createPopperScope } from '@radix-ui/react-popper';\nimport { Portal } from '@radix-ui/react-portal';\nimport { Slottable } from '@radix-ui/react-slot';\nimport * as VisuallyHiddenPrimitive from '@radix-ui/react-visually-hidden';\nimport { useId } from '@radix-ui/react-id';\nimport { createStateMachine } from './createStateMachine';\nimport { tooltipStateChart } from './tooltipStateChart';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * State machine\n * -----------------------------------------------------------------------------------------------*/\n\ntype StateAttribute = 'closed' | 'delayed-open' | 'instant-open';\nconst stateMachine = createStateMachine(tooltipStateChart);\n\n/* -------------------------------------------------------------------------------------------------\n * Tooltip\n * -----------------------------------------------------------------------------------------------*/\n\nconst TOOLTIP_NAME = 'Tooltip';\n\ntype ScopedProps<P> = P & { __scopeTooltip?: Scope };\nconst [createTooltipContext, createTooltipScope] = createContextScope(TOOLTIP_NAME, [\n createPopperScope,\n]);\nconst usePopperScope = createPopperScope();\n\ntype TooltipContextValue = {\n contentId: string;\n open: boolean;\n stateAttribute: StateAttribute;\n trigger: TooltipTriggerElement | null;\n onTriggerChange(trigger: TooltipTriggerElement | null): void;\n onFocus(): void;\n onOpen(): void;\n onClose(): void;\n};\n\nconst [TooltipProvider, useTooltipContext] =\n createTooltipContext<TooltipContextValue>(TOOLTIP_NAME);\n\ninterface TooltipProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n\n /**\n * The duration from when the mouse enters the trigger until the tooltip gets opened.\n * (default: 700)\n */\n delayDuration?: number;\n\n /**\n * How much time a user has to enter another trigger without incurring a delay again.\n * (default: 300)\n */\n skipDelayDuration?: number;\n children?: React.ReactNode;\n}\n\nconst Tooltip: React.FC<TooltipProps> = (props: ScopedProps<TooltipProps>) => {\n const {\n __scopeTooltip,\n children,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n delayDuration = 700,\n skipDelayDuration = 300,\n } = props;\n const popperScope = usePopperScope(__scopeTooltip);\n const [trigger, setTrigger] = React.useState<HTMLButtonElement | null>(null);\n const contentId = useId();\n const [open = false, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n const [stateAttribute, setStateAttribute] = React.useState<StateAttribute>(\n openProp ? 'instant-open' : 'closed'\n );\n\n // control open state using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (state === 'open' && context.id === contentId) {\n setOpen(true);\n } else {\n setOpen(false);\n }\n });\n\n return unsubscribe;\n }, [contentId, setOpen]);\n\n // sync state attribute with using state machine subscription\n React.useEffect(() => {\n const unsubscribe = stateMachine.subscribe(({ state, context }) => {\n if (context.id === contentId) {\n if (state === 'open') {\n setStateAttribute(context.delayed ? 'delayed-open' : 'instant-open');\n } else {\n setStateAttribute('closed');\n }\n } else {\n setStateAttribute('closed');\n }\n });\n\n return unsubscribe;\n }, [contentId]);\n\n const handleFocus = React.useCallback(\n () => stateMachine.send({ type: 'FOCUS', id: contentId }),\n [contentId]\n );\n const handleOpen = React.useCallback(\n () => stateMachine.send({ type: 'OPEN', id: contentId, delayDuration }),\n [contentId, delayDuration]\n );\n const handleClose = React.useCallback(\n () => stateMachine.send({ type: 'CLOSE', id: contentId, skipDelayDuration }),\n [skipDelayDuration, contentId]\n );\n\n // send transition if the component unmounts\n React.useEffect(() => () => handleClose(), [handleClose]);\n\n // if we're controlling the component\n // put the state machine in the appropriate state\n useLayoutEffect(() => {\n if (openProp === true) {\n stateMachine.send({ type: 'OPEN', id: contentId });\n }\n }, [contentId, openProp]);\n\n return (\n <PopperPrimitive.Root {...popperScope}>\n <TooltipProvider\n scope={__scopeTooltip}\n contentId={contentId}\n open={open}\n stateAttribute={stateAttribute}\n trigger={trigger}\n onTriggerChange={setTrigger}\n onFocus={handleFocus}\n onOpen={handleOpen}\n onClose={handleClose}\n >\n {children}\n </TooltipProvider>\n </PopperPrimitive.Root>\n );\n};\n\nTooltip.displayName = TOOLTIP_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipTrigger\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRIGGER_NAME = 'TooltipTrigger';\n\ntype TooltipTriggerElement = React.ElementRef<typeof Primitive.button>;\ntype PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;\ninterface TooltipTriggerProps extends PrimitiveButtonProps {}\n\nconst TooltipTrigger = React.forwardRef<TooltipTriggerElement, TooltipTriggerProps>(\n (props: ScopedProps<TooltipTriggerProps>, forwardedRef) => {\n const { __scopeTooltip, ...triggerProps } = props;\n const context = useTooltipContext(TRIGGER_NAME, __scopeTooltip);\n const popperScope = usePopperScope(__scopeTooltip);\n const composedTriggerRef = useComposedRefs(forwardedRef, context.onTriggerChange);\n return (\n <PopperPrimitive.Anchor asChild {...popperScope}>\n <Primitive.button\n type=\"button\"\n aria-describedby={context.open ? context.contentId : undefined}\n data-state={context.stateAttribute}\n {...triggerProps}\n ref={composedTriggerRef}\n onMouseEnter={composeEventHandlers(props.onMouseEnter, context.onOpen)}\n onMouseLeave={composeEventHandlers(props.onMouseLeave, context.onClose)}\n onMouseDown={composeEventHandlers(props.onMouseDown, context.onClose)}\n onFocus={composeEventHandlers(props.onFocus, context.onFocus)}\n onBlur={composeEventHandlers(props.onBlur, context.onClose)}\n onKeyDown={composeEventHandlers(props.onKeyDown, (event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n context.onClose();\n }\n })}\n />\n </PopperPrimitive.Anchor>\n );\n }\n);\n\nTooltipTrigger.displayName = TRIGGER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipContent\n * -----------------------------------------------------------------------------------------------*/\n\nconst CONTENT_NAME = 'TooltipContent';\n\ntype TooltipContentElement = TooltipContentImplElement;\ninterface TooltipContentProps extends TooltipContentImplProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true;\n}\n\nconst TooltipContent = React.forwardRef<TooltipContentElement, TooltipContentProps>(\n (props: ScopedProps<TooltipContentProps>, forwardedRef) => {\n const { forceMount, ...contentProps } = props;\n const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);\n return (\n <Presence present={forceMount || context.open}>\n <TooltipContentImpl ref={forwardedRef} {...contentProps} />\n </Presence>\n );\n }\n);\n\ntype TooltipContentImplElement = React.ElementRef<typeof PopperPrimitive.Content>;\ntype PopperContentProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Content>;\ninterface TooltipContentImplProps extends PopperContentProps {\n /**\n * A more descriptive label for accessibility purpose\n */\n 'aria-label'?: string;\n\n /**\n * Whether the Tooltip should render in a Portal\n * (default: `true`)\n */\n portalled?: boolean;\n}\n\nconst TooltipContentImpl = React.forwardRef<TooltipContentImplElement, TooltipContentImplProps>(\n (props: ScopedProps<TooltipContentImplProps>, forwardedRef) => {\n const {\n __scopeTooltip,\n children,\n 'aria-label': ariaLabel,\n portalled = true,\n ...contentProps\n } = props;\n const context = useTooltipContext(CONTENT_NAME, __scopeTooltip);\n const popperScope = usePopperScope(__scopeTooltip);\n const PortalWrapper = portalled ? Portal : React.Fragment;\n\n useEscapeKeydown(() => context.onClose());\n\n return (\n <PortalWrapper>\n <CheckTriggerMoved __scopeTooltip={__scopeTooltip} />\n <PopperPrimitive.Content\n data-state={context.stateAttribute}\n {...popperScope}\n {...contentProps}\n ref={forwardedRef}\n style={{\n ...contentProps.style,\n // re-namespace exposed content custom property\n ['--radix-tooltip-content-transform-origin' as any]:\n 'var(--radix-popper-transform-origin)',\n }}\n >\n <Slottable>{children}</Slottable>\n <VisuallyHiddenPrimitive.Root id={context.contentId} role=\"tooltip\">\n {ariaLabel || children}\n </VisuallyHiddenPrimitive.Root>\n </PopperPrimitive.Content>\n </PortalWrapper>\n );\n }\n);\n\nTooltipContent.displayName = CONTENT_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * TooltipArrow\n * -----------------------------------------------------------------------------------------------*/\n\nconst ARROW_NAME = 'TooltipArrow';\n\ntype TooltipArrowElement = React.ElementRef<typeof PopperPrimitive.Arrow>;\ntype PopperArrowProps = Radix.ComponentPropsWithoutRef<typeof PopperPrimitive.Arrow>;\ninterface TooltipArrowProps extends PopperArrowProps {}\n\nconst TooltipArrow = React.forwardRef<TooltipArrowElement, TooltipArrowProps>(\n (props: ScopedProps<TooltipArrowProps>, forwardedRef) => {\n const { __scopeTooltip, ...arrowProps } = props;\n const popperScope = usePopperScope(__scopeTooltip);\n return <PopperPrimitive.Arrow {...popperScope} {...arrowProps} ref={forwardedRef} />;\n }\n);\n\nTooltipArrow.displayName = ARROW_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction CheckTriggerMoved(props: ScopedProps<{}>) {\n const { __scopeTooltip } = props;\n const context = useTooltipContext('CheckTriggerMoved', __scopeTooltip);\n\n const triggerRect = useRect(context.trigger);\n const triggerLeft = triggerRect?.left;\n const previousTriggerLeft = usePrevious(triggerLeft);\n const triggerTop = triggerRect?.top;\n const previousTriggerTop = usePrevious(triggerTop);\n const handleClose = context.onClose;\n\n React.useEffect(() => {\n // checking if the user has scrolled…\n const hasTriggerMoved =\n (previousTriggerLeft !== undefined && previousTriggerLeft !== triggerLeft) ||\n (previousTriggerTop !== undefined && previousTriggerTop !== triggerTop);\n\n if (hasTriggerMoved) {\n handleClose();\n }\n }, [handleClose, previousTriggerLeft, previousTriggerTop, triggerLeft, triggerTop]);\n\n return null;\n}\n\nconst Root = Tooltip;\nconst Trigger = TooltipTrigger;\nconst Content = TooltipContent;\nconst Arrow = TooltipArrow;\n\nexport {\n createTooltipScope,\n //\n Tooltip,\n TooltipTrigger,\n TooltipContent,\n TooltipArrow,\n //\n Root,\n Trigger,\n Content,\n Arrow,\n};\nexport type { TooltipProps, TooltipTriggerProps, TooltipContentProps, TooltipArrowProps };\n"],"names":["assign","assignFn","type","delayTimerId","skipDelayTimerId","setId","$ef54466d8a95ecaa234e3ec978fbe68$export$assign","context","event","_id","id","stateMachine","stateChart","debug","warnOnUnknownTransitions","currentState","initial","currentContext","subscriptions","send","_stateChart$on","_stateDefinition$on","stateDefinition","states","topLevelTransition","on","stateTransition","transition","undefined","console","warn","target","nextState","actions","cond","nextStateDefinition","allActions","exit","concat","entry","nextContext","forEach","action","executeActions","group","log","groupEnd","callback","state","subscribe","push","splice","indexOf","getContext","$ef54466d8a95ecaa234e3ec978fbe68$export$createStateMachine","delayed","FOCUS","closed","OPEN","opening","delayDuration","sendTimerEnd","window","setTimeout","clearTimeout","DELAY_TIMER_END","CLOSE","open","closing","_skipDelayDuration","skipDelayDuration","SKIP_DELAY_TIMER_END","createTooltipContext","createTooltipScope","createContextScope","createPopperScope","usePopperScope","TooltipProvider","useTooltipContext","Tooltip","props","__scopeTooltip","children","openProp","defaultOpen","onOpenChange","popperScope","trigger","setTrigger","React","useState","contentId","useId","setOpen","useControllableState","prop","defaultProp","onChange","stateAttribute","setStateAttribute","useEffect","handleFocus","useCallback","handleOpen","handleClose","useLayoutEffect","_react","createElement","_radixUiReactPopper","Root","$badf5d6f88b7e9fa4e0bb85d71c0396a$var$TooltipProvider","scope","onTriggerChange","onFocus","onOpen","onClose","TooltipTrigger","forwardRef","forwardedRef","triggerProps","composedTriggerRef","useComposedRefs","Anchor","_babelRuntimeHelpersEsmExtends","asChild","Primitive","button","ref","onMouseEnter","composeEventHandlers","onMouseLeave","onMouseDown","onBlur","onKeyDown","key","TooltipContent","forceMount","contentProps","Presence","present","$badf5d6f88b7e9fa4e0bb85d71c0396a$var$TooltipContentImpl","TooltipContentImpl","ariaLabel","portalled","PortalWrapper","Portal","Fragment","useEscapeKeydown","$badf5d6f88b7e9fa4e0bb85d71c0396a$var$CheckTriggerMoved","Content","style","Slottable","_radixUiReactVisuallyHidden","role","TooltipArrow","arrowProps","Arrow","CheckTriggerMoved","triggerRect","useRect","triggerLeft","left","previousTriggerLeft","usePrevious","triggerTop","top","previousTriggerTop","Trigger"],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-tooltip",
|
|
3
|
-
"version": "0.1.1
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
"@babel/runtime": "^7.13.10",
|
|
20
20
|
"@radix-ui/primitive": "0.1.0",
|
|
21
21
|
"@radix-ui/react-compose-refs": "0.1.0",
|
|
22
|
-
"@radix-ui/react-context": "0.1.
|
|
23
|
-
"@radix-ui/react-id": "0.1.
|
|
24
|
-
"@radix-ui/react-popper": "0.1.1
|
|
25
|
-
"@radix-ui/react-portal": "0.1.1
|
|
26
|
-
"@radix-ui/react-presence": "0.1.1
|
|
27
|
-
"@radix-ui/react-primitive": "0.1.1
|
|
28
|
-
"@radix-ui/react-slot": "0.1.1
|
|
22
|
+
"@radix-ui/react-context": "0.1.1",
|
|
23
|
+
"@radix-ui/react-id": "0.1.1",
|
|
24
|
+
"@radix-ui/react-popper": "0.1.1",
|
|
25
|
+
"@radix-ui/react-portal": "0.1.1",
|
|
26
|
+
"@radix-ui/react-presence": "0.1.1",
|
|
27
|
+
"@radix-ui/react-primitive": "0.1.1",
|
|
28
|
+
"@radix-ui/react-slot": "0.1.1",
|
|
29
29
|
"@radix-ui/react-use-controllable-state": "0.1.0",
|
|
30
30
|
"@radix-ui/react-use-escape-keydown": "0.1.0",
|
|
31
31
|
"@radix-ui/react-use-layout-effect": "0.1.0",
|
|
32
32
|
"@radix-ui/react-use-previous": "0.1.0",
|
|
33
|
-
"@radix-ui/react-use-rect": "0.1.
|
|
34
|
-
"@radix-ui/react-visually-hidden": "0.1.1
|
|
33
|
+
"@radix-ui/react-use-rect": "0.1.1",
|
|
34
|
+
"@radix-ui/react-visually-hidden": "0.1.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": "^16.8 || ^17.0",
|
|
@@ -44,6 +44,5 @@
|
|
|
44
44
|
},
|
|
45
45
|
"bugs": {
|
|
46
46
|
"url": "https://github.com/radix-ui/primitives/issues"
|
|
47
|
-
}
|
|
48
|
-
"stableVersion": "0.1.0"
|
|
47
|
+
}
|
|
49
48
|
}
|