@khanacademy/wonder-blocks-tooltip 4.1.11 → 4.1.13

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.js CHANGED
@@ -2,19 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var jsxRuntime = require('react/jsx-runtime');
5
6
  var React = require('react');
6
7
  var ReactDOM = require('react-dom');
7
8
  var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
8
9
  var wonderBlocksModal = require('@khanacademy/wonder-blocks-modal');
9
10
  var aphrodite = require('aphrodite');
10
11
  var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
11
- var _extends = require('@babel/runtime/helpers/extends');
12
12
  var wonderBlocksLayout = require('@khanacademy/wonder-blocks-layout');
13
13
  var wonderBlocksTypography = require('@khanacademy/wonder-blocks-typography');
14
14
  var reactPopper = require('react-popper');
15
15
 
16
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
-
18
16
  function _interopNamespace(e) {
19
17
  if (e && e.__esModule) return e;
20
18
  var n = Object.create(null);
@@ -35,873 +33,26 @@ function _interopNamespace(e) {
35
33
 
36
34
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
37
35
  var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
38
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
39
36
 
40
- class ActiveTracker {
41
- constructor() {
42
- this._subscribers = [];
43
- this._active = false;
44
- }
45
- _getIndex(who) {
46
- return this._subscribers.findIndex(v => v === who);
47
- }
48
- steal(who) {
49
- const wasActive = !!this._active;
50
- this._active = true;
51
- for (const anchor of this._subscribers) {
52
- if (anchor === who) {
53
- continue;
54
- }
55
- anchor.activeStateStolen();
56
- }
57
- return wasActive;
58
- }
59
- giveup() {
60
- this._active = false;
61
- }
62
- subscribe(who) {
63
- if (this._getIndex(who) >= 0) {
64
- throw new Error("Already subscribed.");
65
- }
66
- this._subscribers.push(who);
67
- const unsubscribe = () => {
68
- const index = this._getIndex(who);
69
- this._subscribers.splice(index, 1);
70
- };
71
- return unsubscribe;
72
- }
73
- }
37
+ class ActiveTracker{_getIndex(who){return this._subscribers.findIndex(v=>v===who)}steal(who){const wasActive=!!this._active;this._active=true;for(const anchor of this._subscribers){if(anchor===who){continue}anchor.activeStateStolen();}return wasActive}giveup(){this._active=false;}subscribe(who){if(this._getIndex(who)>=0){throw new Error("Already subscribed.")}this._subscribers.push(who);const unsubscribe=()=>{const index=this._getIndex(who);this._subscribers.splice(index,1);};return unsubscribe}constructor(){this._subscribers=[];this._active=false;}}
74
38
 
75
- const TooltipAppearanceDelay = 100;
76
- const TooltipDisappearanceDelay = 75;
39
+ const TooltipAppearanceDelay=100;const TooltipDisappearanceDelay=75;
77
40
 
78
- const TRACKER = new ActiveTracker();
79
- class TooltipAnchor extends React__namespace.Component {
80
- constructor(props) {
81
- super(props);
82
- this._weSetFocusivity = void 0;
83
- this._anchorNode = void 0;
84
- this._focused = void 0;
85
- this._hovered = void 0;
86
- this._stolenFromUs = void 0;
87
- this._unsubscribeFromTracker = void 0;
88
- this._timeoutID = void 0;
89
- this.activeStateStolen = () => {
90
- this._stolenFromUs = this.state.active || !!this._timeoutID;
91
- this._focused = false;
92
- this._setActiveState(false, true);
93
- };
94
- this._handleFocusIn = () => {
95
- this._updateActiveState(this._hovered, true);
96
- };
97
- this._handleFocusOut = () => {
98
- this._updateActiveState(this._hovered, false);
99
- };
100
- this._handleMouseEnter = () => {
101
- this._updateActiveState(true, this._focused);
102
- };
103
- this._handleMouseLeave = () => {
104
- this._updateActiveState(false, this._focused);
105
- };
106
- this._handleKeyUp = e => {
107
- if (e.key === "Escape" && this.state.active) {
108
- e.preventDefault();
109
- e.stopPropagation();
110
- this._updateActiveState(false, false);
111
- }
112
- };
113
- this._focused = false;
114
- this._hovered = false;
115
- this.state = {
116
- active: false
117
- };
118
- }
119
- componentDidMount() {
120
- const anchorNode = ReactDOM__namespace.findDOMNode(this);
121
- if (anchorNode instanceof Text) {
122
- throw new Error("TooltipAnchor must be applied to an Element. Text content is not supported.");
123
- }
124
- this._unsubscribeFromTracker = TRACKER.subscribe(this);
125
- this._anchorNode = anchorNode;
126
- this._updateFocusivity();
127
- if (anchorNode) {
128
- anchorNode.addEventListener("focusin", this._handleFocusIn);
129
- anchorNode.addEventListener("focusout", this._handleFocusOut);
130
- anchorNode.addEventListener("mouseenter", this._handleMouseEnter);
131
- anchorNode.addEventListener("mouseleave", this._handleMouseLeave);
132
- this.props.anchorRef(this._anchorNode);
133
- }
134
- }
135
- componentDidUpdate(prevProps) {
136
- if (prevProps.forceAnchorFocusivity !== this.props.forceAnchorFocusivity || prevProps.children !== this.props.children) {
137
- this._updateFocusivity();
138
- }
139
- }
140
- componentWillUnmount() {
141
- if (this._unsubscribeFromTracker) {
142
- this._unsubscribeFromTracker();
143
- }
144
- this._clearPendingAction();
145
- const anchorNode = this._anchorNode;
146
- if (anchorNode) {
147
- anchorNode.removeEventListener("focusin", this._handleFocusIn);
148
- anchorNode.removeEventListener("focusout", this._handleFocusOut);
149
- anchorNode.removeEventListener("mouseenter", this._handleMouseEnter);
150
- anchorNode.removeEventListener("mouseleave", this._handleMouseLeave);
151
- }
152
- if (this.state.active) {
153
- document.removeEventListener("keyup", this._handleKeyUp);
154
- }
155
- }
156
- _updateFocusivity() {
157
- const anchorNode = this._anchorNode;
158
- if (!anchorNode) {
159
- return;
160
- }
161
- const {
162
- forceAnchorFocusivity
163
- } = this.props;
164
- const currentTabIndex = anchorNode.getAttribute("tabindex");
165
- if (forceAnchorFocusivity && !currentTabIndex) {
166
- anchorNode.setAttribute("tabindex", "0");
167
- this._weSetFocusivity = true;
168
- } else if (!forceAnchorFocusivity && currentTabIndex) {
169
- if (this._weSetFocusivity) {
170
- anchorNode.removeAttribute("tabindex");
171
- this._weSetFocusivity = false;
172
- }
173
- }
174
- }
175
- _updateActiveState(hovered, focused) {
176
- this._hovered = hovered;
177
- this._focused = focused;
178
- this._setActiveState(hovered || focused);
179
- }
180
- _clearPendingAction() {
181
- if (this._timeoutID) {
182
- clearTimeout(this._timeoutID);
183
- this._timeoutID = null;
184
- }
185
- }
186
- _setActiveState(active, instant) {
187
- if (this._stolenFromUs || active !== this.state.active || !this.state.active && this._timeoutID) {
188
- this._clearPendingAction();
189
- } else if (active === this.state.active) {
190
- if (this._timeoutID) {
191
- this._clearPendingAction();
192
- }
193
- return;
194
- }
195
- instant = instant || active && TRACKER.steal(this);
196
- if (instant) {
197
- if (active) {
198
- document.addEventListener("keyup", this._handleKeyUp);
199
- } else {
200
- document.removeEventListener("keyup", this._handleKeyUp);
201
- }
202
- this.setState({
203
- active
204
- });
205
- this.props.onActiveChanged(active);
206
- if (!this._stolenFromUs && !active) {
207
- TRACKER.giveup();
208
- }
209
- this._stolenFromUs = false;
210
- } else {
211
- const delay = active ? TooltipAppearanceDelay : TooltipDisappearanceDelay;
212
- this._timeoutID = setTimeout(() => {
213
- this._timeoutID = null;
214
- this._setActiveState(active, true);
215
- }, delay);
216
- }
217
- }
218
- _renderAnchorableChildren() {
219
- const {
220
- children
221
- } = this.props;
222
- return typeof children === "string" ? React__namespace.createElement(wonderBlocksCore.Text, null, children) : children;
223
- }
224
- _renderAccessibleChildren(uniqueId) {
225
- const anchorableChildren = this._renderAnchorableChildren();
226
- return React__namespace.cloneElement(anchorableChildren, {
227
- "aria-describedby": `${uniqueId}-${TooltipAnchor.ariaContentId}`
228
- });
229
- }
230
- render() {
231
- if (this.props.id) {
232
- return this._renderAccessibleChildren(this.props.id);
233
- }
234
- return this._renderAnchorableChildren();
235
- }
236
- }
237
- TooltipAnchor.defaultProps = {
238
- forceAnchorFocusivity: true
239
- };
240
- TooltipAnchor.ariaContentId = "aria-content";
41
+ const TRACKER=new ActiveTracker;class TooltipAnchor extends React__namespace.Component{componentDidMount(){const anchorNode=ReactDOM__namespace.findDOMNode(this);if(anchorNode instanceof Text){throw new Error("TooltipAnchor must be applied to an Element. Text content is not supported.")}this._unsubscribeFromTracker=TRACKER.subscribe(this);this._anchorNode=anchorNode;this._updateFocusivity();if(anchorNode){anchorNode.addEventListener("focusin",this._handleFocusIn);anchorNode.addEventListener("focusout",this._handleFocusOut);anchorNode.addEventListener("mouseenter",this._handleMouseEnter);anchorNode.addEventListener("mouseleave",this._handleMouseLeave);this.props.anchorRef(this._anchorNode);}}componentDidUpdate(prevProps){if(prevProps.forceAnchorFocusivity!==this.props.forceAnchorFocusivity||prevProps.children!==this.props.children){this._updateFocusivity();}}componentWillUnmount(){if(this._unsubscribeFromTracker){this._unsubscribeFromTracker();}this._clearPendingAction();const anchorNode=this._anchorNode;if(anchorNode){anchorNode.removeEventListener("focusin",this._handleFocusIn);anchorNode.removeEventListener("focusout",this._handleFocusOut);anchorNode.removeEventListener("mouseenter",this._handleMouseEnter);anchorNode.removeEventListener("mouseleave",this._handleMouseLeave);}if(this.state.active){document.removeEventListener("keyup",this._handleKeyUp);}}_updateFocusivity(){const anchorNode=this._anchorNode;if(!anchorNode){return}const{forceAnchorFocusivity}=this.props;const currentTabIndex=anchorNode.getAttribute("tabindex");if(forceAnchorFocusivity&&!currentTabIndex){anchorNode.setAttribute("tabindex","0");this._weSetFocusivity=true;}else if(!forceAnchorFocusivity&&currentTabIndex){if(this._weSetFocusivity){anchorNode.removeAttribute("tabindex");this._weSetFocusivity=false;}}}_updateActiveState(hovered,focused){this._hovered=hovered;this._focused=focused;this._setActiveState(hovered||focused);}_clearPendingAction(){if(this._timeoutID){clearTimeout(this._timeoutID);this._timeoutID=null;}}_setActiveState(active,instant){if(this._stolenFromUs||active!==this.state.active||!this.state.active&&this._timeoutID){this._clearPendingAction();}else if(active===this.state.active){if(this._timeoutID){this._clearPendingAction();}return}instant=instant||active&&TRACKER.steal(this);if(instant){if(active){document.addEventListener("keyup",this._handleKeyUp);}else {document.removeEventListener("keyup",this._handleKeyUp);}this.setState({active});this.props.onActiveChanged(active);if(!this._stolenFromUs&&!active){TRACKER.giveup();}this._stolenFromUs=false;}else {const delay=active?TooltipAppearanceDelay:TooltipDisappearanceDelay;this._timeoutID=setTimeout(()=>{this._timeoutID=null;this._setActiveState(active,true);},delay);}}_renderAnchorableChildren(){const{children}=this.props;return typeof children==="string"?jsxRuntime.jsx(wonderBlocksCore.Text,{children:children}):children}render(){const{"aria-describedby":ariaDescribedBy}=this.props;const anchorableChildren=this._renderAnchorableChildren();return React__namespace.cloneElement(anchorableChildren,{"aria-describedby":ariaDescribedBy})}constructor(props){super(props),this.activeStateStolen=()=>{this._stolenFromUs=this.state.active||!!this._timeoutID;this._focused=false;this._setActiveState(false,true);},this._handleFocusIn=()=>{this._updateActiveState(this._hovered,true);},this._handleFocusOut=()=>{this._updateActiveState(this._hovered,false);},this._handleMouseEnter=()=>{this._updateActiveState(true,this._focused);},this._handleMouseLeave=()=>{this._updateActiveState(false,this._focused);},this._handleKeyUp=e=>{if(e.key==="Escape"&&this.state.active){e.preventDefault();e.stopPropagation();this._updateActiveState(false,false);}};this._focused=false;this._hovered=false;this.state={active:false};}}TooltipAnchor.defaultProps={forceAnchorFocusivity:true};
241
42
 
242
- let tempIdCounter = 0;
243
- class TooltipTail extends React__namespace.Component {
244
- _calculateDimensionsFromPlacement() {
245
- const {
246
- placement
247
- } = this.props;
248
- const trimlineOffset = 0.5;
249
- switch (placement) {
250
- case "top":
251
- return {
252
- trimlinePoints: [`0,-${trimlineOffset}`, `${ARROW_WIDTH},-${trimlineOffset}`],
253
- points: ["0,0", `${ARROW_WIDTH / 2},${ARROW_HEIGHT}`, `${ARROW_WIDTH},0`],
254
- height: ARROW_HEIGHT,
255
- width: ARROW_WIDTH
256
- };
257
- case "right":
258
- return {
259
- trimlinePoints: [`${ARROW_HEIGHT + trimlineOffset},0`, `${ARROW_HEIGHT + trimlineOffset},${ARROW_WIDTH}`],
260
- points: [`${ARROW_HEIGHT},0`, `0,${ARROW_WIDTH / 2}`, `${ARROW_HEIGHT},${ARROW_WIDTH}`],
261
- width: ARROW_HEIGHT,
262
- height: ARROW_WIDTH
263
- };
264
- case "bottom":
265
- return {
266
- trimlinePoints: [`0, ${ARROW_HEIGHT + trimlineOffset}`, `${ARROW_WIDTH},${ARROW_HEIGHT + trimlineOffset}`],
267
- points: [`0, ${ARROW_HEIGHT}`, `${ARROW_WIDTH / 2},0`, `${ARROW_WIDTH},${ARROW_HEIGHT}`],
268
- width: ARROW_WIDTH,
269
- height: ARROW_HEIGHT
270
- };
271
- case "left":
272
- return {
273
- trimlinePoints: [`-${trimlineOffset},0`, `-${trimlineOffset},${ARROW_WIDTH}`],
274
- points: [`0,0`, `${ARROW_HEIGHT},${ARROW_WIDTH / 2}`, `0,${ARROW_WIDTH}`],
275
- width: ARROW_HEIGHT,
276
- height: ARROW_WIDTH
277
- };
278
- default:
279
- throw new Error(`Unknown placement: ${placement}`);
280
- }
281
- }
282
- _getFilterPositioning() {
283
- const {
284
- placement
285
- } = this.props;
286
- switch (placement) {
287
- case "top":
288
- return {
289
- y: "-50%",
290
- x: "-50%",
291
- offsetShadowX: 0
292
- };
293
- case "bottom":
294
- return null;
295
- case "left":
296
- return {
297
- y: "-50%",
298
- x: "0%",
299
- offsetShadowX: 1
300
- };
301
- case "right":
302
- return {
303
- y: "-50%",
304
- x: "-100%",
305
- offsetShadowX: -1
306
- };
307
- default:
308
- throw new Error(`Unknown placement: ${placement}`);
309
- }
310
- }
311
- _maybeRenderDropshadow(points) {
312
- const position = this._getFilterPositioning();
313
- if (!position) {
314
- return null;
315
- }
316
- const {
317
- placement
318
- } = this.props;
319
- const {
320
- y,
321
- x,
322
- offsetShadowX
323
- } = position;
324
- const dropShadowFilterId = `tooltip-dropshadow-${placement}-${tempIdCounter++}`;
325
- return [React__namespace.createElement("filter", {
326
- key: "filter",
327
- id: dropShadowFilterId,
328
- width: "200%",
329
- height: "200%",
330
- x: x,
331
- y: y
332
- }, React__namespace.createElement("feGaussianBlur", {
333
- in: "SourceAlpha",
334
- stdDeviation: wonderBlocksTokens.spacing.xxSmall_6 / 2
335
- }), React__namespace.createElement("feComponentTransfer", null, React__namespace.createElement("feFuncA", {
336
- type: "linear",
337
- slope: "0.3"
338
- }))), React__namespace.createElement("g", {
339
- key: "dropshadow",
340
- transform: `translate(${offsetShadowX},5.5)`
341
- }, React__namespace.createElement("polyline", {
342
- fill: wonderBlocksTokens.color.offBlack16,
343
- points: points.join(" "),
344
- stroke: wonderBlocksTokens.color.offBlack32,
345
- filter: `url(#${dropShadowFilterId})`
346
- }))];
347
- }
348
- _getFullTailWidth() {
349
- return ARROW_WIDTH + 2 * MIN_DISTANCE_FROM_CORNERS;
350
- }
351
- _getFullTailHeight() {
352
- return ARROW_HEIGHT + DISTANCE_FROM_ANCHOR;
353
- }
354
- _getContainerStyle() {
355
- const {
356
- placement
357
- } = this.props;
358
- const fullTailWidth = this._getFullTailWidth();
359
- const fullTailHeight = this._getFullTailHeight();
360
- switch (placement) {
361
- case "top":
362
- return {
363
- top: -1,
364
- width: fullTailWidth,
365
- height: fullTailHeight
366
- };
367
- case "right":
368
- return {
369
- left: 1,
370
- width: fullTailHeight,
371
- height: fullTailWidth
372
- };
373
- case "bottom":
374
- return {
375
- top: 1,
376
- width: fullTailWidth,
377
- height: fullTailHeight
378
- };
379
- case "left":
380
- return {
381
- left: -1,
382
- width: fullTailHeight,
383
- height: fullTailWidth
384
- };
385
- default:
386
- throw new Error(`Unknown placement: ${placement}`);
387
- }
388
- }
389
- _getArrowStyle() {
390
- const {
391
- placement
392
- } = this.props;
393
- switch (placement) {
394
- case "top":
395
- return {
396
- marginLeft: MIN_DISTANCE_FROM_CORNERS,
397
- marginRight: MIN_DISTANCE_FROM_CORNERS,
398
- paddingBottom: DISTANCE_FROM_ANCHOR
399
- };
400
- case "right":
401
- return {
402
- marginTop: MIN_DISTANCE_FROM_CORNERS,
403
- marginBottom: MIN_DISTANCE_FROM_CORNERS,
404
- paddingLeft: DISTANCE_FROM_ANCHOR
405
- };
406
- case "bottom":
407
- return {
408
- marginLeft: MIN_DISTANCE_FROM_CORNERS,
409
- marginRight: MIN_DISTANCE_FROM_CORNERS,
410
- paddingTop: DISTANCE_FROM_ANCHOR
411
- };
412
- case "left":
413
- return {
414
- marginTop: MIN_DISTANCE_FROM_CORNERS,
415
- marginBottom: MIN_DISTANCE_FROM_CORNERS,
416
- paddingRight: DISTANCE_FROM_ANCHOR
417
- };
418
- default:
419
- throw new Error(`Unknown placement: ${placement}`);
420
- }
421
- }
422
- _renderArrow() {
423
- const {
424
- trimlinePoints,
425
- points,
426
- height,
427
- width
428
- } = this._calculateDimensionsFromPlacement();
429
- const {
430
- color: arrowColor,
431
- show
432
- } = this.props;
433
- if (!show) {
434
- return React__namespace.createElement(wonderBlocksLayout.Strut, {
435
- size: height
436
- });
437
- }
438
- return React__namespace.createElement("svg", {
439
- className: aphrodite.css(styles$2.arrow),
440
- style: this._getArrowStyle(),
441
- width: width,
442
- height: height,
443
- "aria-hidden": true
444
- }, this._maybeRenderDropshadow(points), React__namespace.createElement("polyline", {
445
- fill: wonderBlocksTokens.color[arrowColor],
446
- stroke: wonderBlocksTokens.color[arrowColor],
447
- points: points.join(" ")
448
- }), React__namespace.createElement("polyline", {
449
- fill: wonderBlocksTokens.color[arrowColor],
450
- points: points.join(" "),
451
- stroke: wonderBlocksTokens.color.offBlack16
452
- }), React__namespace.createElement("polyline", {
453
- stroke: wonderBlocksTokens.color[arrowColor],
454
- points: trimlinePoints.join(" ")
455
- }));
456
- }
457
- render() {
458
- const {
459
- offset,
460
- placement,
461
- updateRef
462
- } = this.props;
463
- return React__namespace.createElement(wonderBlocksCore.View, {
464
- style: [styles$2.tailContainer, _extends__default["default"]({}, offset), this._getContainerStyle()],
465
- "data-placement": placement,
466
- ref: updateRef
467
- }, this._renderArrow());
468
- }
469
- }
470
- TooltipTail.defaultProps = {
471
- color: "white",
472
- show: true
473
- };
474
- const DISTANCE_FROM_ANCHOR = wonderBlocksTokens.spacing.xSmall_8;
475
- const MIN_DISTANCE_FROM_CORNERS = wonderBlocksTokens.spacing.xSmall_8;
476
- const ARROW_WIDTH = wonderBlocksTokens.spacing.large_24;
477
- const ARROW_HEIGHT = wonderBlocksTokens.spacing.small_12;
478
- const styles$2 = aphrodite.StyleSheet.create({
479
- tailContainer: {
480
- position: "relative",
481
- pointerEvents: "none"
482
- },
483
- arrow: {
484
- overflow: "visible"
485
- }
486
- });
43
+ let tempIdCounter=0;class TooltipTail extends React__namespace.Component{_calculateDimensionsFromPlacement(){const{placement}=this.props;const trimlineOffset=.5;switch(placement){case"top":return {trimlinePoints:[`0,-${trimlineOffset}`,`${ARROW_WIDTH},-${trimlineOffset}`],points:["0,0",`${ARROW_WIDTH/2},${ARROW_HEIGHT}`,`${ARROW_WIDTH},0`],height:ARROW_HEIGHT,width:ARROW_WIDTH};case"right":return {trimlinePoints:[`${ARROW_HEIGHT+trimlineOffset},0`,`${ARROW_HEIGHT+trimlineOffset},${ARROW_WIDTH}`],points:[`${ARROW_HEIGHT},0`,`0,${ARROW_WIDTH/2}`,`${ARROW_HEIGHT},${ARROW_WIDTH}`],width:ARROW_HEIGHT,height:ARROW_WIDTH};case"bottom":return {trimlinePoints:[`0, ${ARROW_HEIGHT+trimlineOffset}`,`${ARROW_WIDTH},${ARROW_HEIGHT+trimlineOffset}`],points:[`0, ${ARROW_HEIGHT}`,`${ARROW_WIDTH/2},0`,`${ARROW_WIDTH},${ARROW_HEIGHT}`],width:ARROW_WIDTH,height:ARROW_HEIGHT};case"left":return {trimlinePoints:[`-${trimlineOffset},0`,`-${trimlineOffset},${ARROW_WIDTH}`],points:[`0,0`,`${ARROW_HEIGHT},${ARROW_WIDTH/2}`,`0,${ARROW_WIDTH}`],width:ARROW_HEIGHT,height:ARROW_WIDTH};default:throw new Error(`Unknown placement: ${placement}`)}}_getFilterPositioning(){const{placement}=this.props;switch(placement){case"top":return {y:"-50%",x:"-50%",offsetShadowX:0};case"bottom":return null;case"left":return {y:"-50%",x:"0%",offsetShadowX:1};case"right":return {y:"-50%",x:"-100%",offsetShadowX:-1};default:throw new Error(`Unknown placement: ${placement}`)}}_maybeRenderDropshadow(points){const position=this._getFilterPositioning();if(!position){return null}const{placement}=this.props;const{y,x,offsetShadowX}=position;const dropShadowFilterId=`tooltip-dropshadow-${placement}-${tempIdCounter++}`;return [jsxRuntime.jsxs("filter",{id:dropShadowFilterId,width:"200%",height:"200%",x:x,y:y,children:[jsxRuntime.jsx("feGaussianBlur",{in:"SourceAlpha",stdDeviation:wonderBlocksTokens.spacing.xxSmall_6/2}),jsxRuntime.jsx("feComponentTransfer",{children:jsxRuntime.jsx("feFuncA",{type:"linear",slope:"0.3"})})]},"filter"),jsxRuntime.jsx("g",{transform:`translate(${offsetShadowX},5.5)`,children:jsxRuntime.jsx("polyline",{fill:wonderBlocksTokens.color.offBlack16,points:points.join(" "),stroke:wonderBlocksTokens.color.offBlack32,filter:`url(#${dropShadowFilterId})`})},"dropshadow")]}_getFullTailWidth(){return ARROW_WIDTH+2*MIN_DISTANCE_FROM_CORNERS}_getFullTailHeight(){return ARROW_HEIGHT+DISTANCE_FROM_ANCHOR}_getContainerStyle(){const{placement}=this.props;const fullTailWidth=this._getFullTailWidth();const fullTailHeight=this._getFullTailHeight();switch(placement){case"top":return {top:-1,width:fullTailWidth,height:fullTailHeight};case"right":return {left:1,width:fullTailHeight,height:fullTailWidth};case"bottom":return {top:1,width:fullTailWidth,height:fullTailHeight};case"left":return {left:-1,width:fullTailHeight,height:fullTailWidth};default:throw new Error(`Unknown placement: ${placement}`)}}_getArrowStyle(){const{placement}=this.props;switch(placement){case"top":return {marginLeft:MIN_DISTANCE_FROM_CORNERS,marginRight:MIN_DISTANCE_FROM_CORNERS,paddingBottom:DISTANCE_FROM_ANCHOR};case"right":return {marginTop:MIN_DISTANCE_FROM_CORNERS,marginBottom:MIN_DISTANCE_FROM_CORNERS,paddingLeft:DISTANCE_FROM_ANCHOR};case"bottom":return {marginLeft:MIN_DISTANCE_FROM_CORNERS,marginRight:MIN_DISTANCE_FROM_CORNERS,paddingTop:DISTANCE_FROM_ANCHOR};case"left":return {marginTop:MIN_DISTANCE_FROM_CORNERS,marginBottom:MIN_DISTANCE_FROM_CORNERS,paddingRight:DISTANCE_FROM_ANCHOR};default:throw new Error(`Unknown placement: ${placement}`)}}_renderArrow(){const{trimlinePoints,points,height,width}=this._calculateDimensionsFromPlacement();const{color:arrowColor,show}=this.props;if(!show){return jsxRuntime.jsx(wonderBlocksLayout.Strut,{size:height})}return jsxRuntime.jsxs("svg",{className:aphrodite.css(styles$2.arrow),style:this._getArrowStyle(),width:width,height:height,"aria-hidden":true,children:[this._maybeRenderDropshadow(points),jsxRuntime.jsx("polyline",{fill:wonderBlocksTokens.color[arrowColor],stroke:wonderBlocksTokens.color[arrowColor],points:points.join(" ")}),jsxRuntime.jsx("polyline",{fill:wonderBlocksTokens.color[arrowColor],points:points.join(" "),stroke:wonderBlocksTokens.color.offBlack16}),jsxRuntime.jsx("polyline",{stroke:wonderBlocksTokens.color[arrowColor],points:trimlinePoints.join(" ")})]})}render(){const{offset,placement,updateRef}=this.props;return jsxRuntime.jsx(wonderBlocksCore.View,{style:[styles$2.tailContainer,{...offset},this._getContainerStyle()],"data-placement":placement,ref:updateRef,children:this._renderArrow()})}}TooltipTail.defaultProps={color:"white",show:true};const DISTANCE_FROM_ANCHOR=wonderBlocksTokens.spacing.xSmall_8;const MIN_DISTANCE_FROM_CORNERS=wonderBlocksTokens.spacing.xSmall_8;const ARROW_WIDTH=wonderBlocksTokens.spacing.large_24;const ARROW_HEIGHT=wonderBlocksTokens.spacing.small_12;const styles$2=aphrodite.StyleSheet.create({tailContainer:{position:"relative",pointerEvents:"none"},arrow:{overflow:"visible"}});
487
44
 
488
- class TooltipBubble extends React__namespace.Component {
489
- constructor(...args) {
490
- super(...args);
491
- this.state = {
492
- active: false
493
- };
494
- this.handleMouseEnter = () => {
495
- this._setActiveState(true);
496
- };
497
- this.handleMouseLeave = () => {
498
- this.props.onActiveChanged(false);
499
- };
500
- }
501
- _setActiveState(active) {
502
- this.setState({
503
- active
504
- });
505
- this.props.onActiveChanged(active);
506
- }
507
- render() {
508
- const {
509
- id,
510
- children,
511
- updateBubbleRef,
512
- placement,
513
- isReferenceHidden,
514
- style,
515
- updateTailRef,
516
- tailOffset,
517
- backgroundColor
518
- } = this.props;
519
- return React__namespace.createElement(wonderBlocksCore.View, {
520
- id: id,
521
- role: "tooltip",
522
- "data-placement": placement,
523
- onMouseEnter: this.handleMouseEnter,
524
- onMouseLeave: this.handleMouseLeave,
525
- ref: updateBubbleRef,
526
- style: [isReferenceHidden && styles$1.hide, styles$1.bubble, styles$1[`content-${placement}`], style]
527
- }, React__namespace.createElement(wonderBlocksCore.View, {
528
- style: [styles$1.content, backgroundColor && {
529
- backgroundColor: wonderBlocksTokens.color[backgroundColor]
530
- }]
531
- }, children), React__namespace.createElement(TooltipTail, {
532
- updateRef: updateTailRef,
533
- placement: placement,
534
- offset: tailOffset,
535
- color: backgroundColor
536
- }));
537
- }
538
- }
539
- const styles$1 = aphrodite.StyleSheet.create({
540
- bubble: {
541
- position: "absolute"
542
- },
543
- hide: {
544
- pointerEvents: "none",
545
- opacity: 0,
546
- backgroundColor: "transparent",
547
- color: "transparent"
548
- },
549
- "content-top": {
550
- flexDirection: "column"
551
- },
552
- "content-right": {
553
- flexDirection: "row-reverse"
554
- },
555
- "content-bottom": {
556
- flexDirection: "column-reverse"
557
- },
558
- "content-left": {
559
- flexDirection: "row"
560
- },
561
- content: {
562
- maxWidth: 472,
563
- borderRadius: wonderBlocksTokens.border.radius.radius_040,
564
- border: `solid 1px ${wonderBlocksTokens.semanticColor.border.primary}`,
565
- backgroundColor: wonderBlocksTokens.semanticColor.surface.primary,
566
- boxShadow: `0 ${wonderBlocksTokens.spacing.xSmall_8}px ${wonderBlocksTokens.spacing.xSmall_8}px 0 ${wonderBlocksTokens.color.offBlack8}`,
567
- justifyContent: "center"
568
- }
569
- });
45
+ class TooltipBubble extends React__namespace.Component{_setActiveState(active){this.setState({active});this.props.onActiveChanged(active);}render(){const{id,children,updateBubbleRef,placement,isReferenceHidden,style,updateTailRef,tailOffset,backgroundColor}=this.props;return jsxRuntime.jsxs(wonderBlocksCore.View,{id:id,role:"tooltip","data-placement":placement,onMouseEnter:this.handleMouseEnter,onMouseLeave:this.handleMouseLeave,ref:updateBubbleRef,style:[isReferenceHidden&&styles$1.hide,styles$1.bubble,styles$1[`content-${placement}`],style],children:[jsxRuntime.jsx(wonderBlocksCore.View,{style:[styles$1.content,backgroundColor&&{backgroundColor:wonderBlocksTokens.color[backgroundColor]}],children:children}),jsxRuntime.jsx(TooltipTail,{updateRef:updateTailRef,placement:placement,offset:tailOffset,color:backgroundColor})]})}constructor(...args){super(...args),this.state={active:false},this.handleMouseEnter=()=>{this._setActiveState(true);},this.handleMouseLeave=()=>{this.props.onActiveChanged(false);};}}const styles$1=aphrodite.StyleSheet.create({bubble:{position:"absolute"},hide:{pointerEvents:"none",opacity:0,backgroundColor:"transparent",color:"transparent"},"content-top":{flexDirection:"column"},"content-right":{flexDirection:"row-reverse"},"content-bottom":{flexDirection:"column-reverse"},"content-left":{flexDirection:"row"},content:{maxWidth:472,borderRadius:wonderBlocksTokens.border.radius.radius_040,border:`solid 1px ${wonderBlocksTokens.semanticColor.border.primary}`,backgroundColor:wonderBlocksTokens.semanticColor.surface.primary,boxShadow:`0 ${wonderBlocksTokens.spacing.xSmall_8}px ${wonderBlocksTokens.spacing.xSmall_8}px 0 ${wonderBlocksTokens.color.offBlack8}`,justifyContent:"center"}});
570
46
 
571
- class TooltipContent extends React__namespace.Component {
572
- _renderTitle() {
573
- const {
574
- title
575
- } = this.props;
576
- if (title) {
577
- if (typeof title === "string") {
578
- return React__namespace.createElement(wonderBlocksTypography.HeadingSmall, null, title);
579
- } else {
580
- return title;
581
- }
582
- }
583
- return null;
584
- }
585
- _renderChildren() {
586
- const {
587
- children
588
- } = this.props;
589
- if (typeof children === "string") {
590
- return React__namespace.createElement(wonderBlocksTypography.LabelMedium, null, children);
591
- } else {
592
- return children;
593
- }
594
- }
595
- render() {
596
- const title = this._renderTitle();
597
- const children = this._renderChildren();
598
- const containerStyle = title ? styles.withTitle : styles.withoutTitle;
599
- return React__namespace.createElement(wonderBlocksCore.View, {
600
- style: [containerStyle, this.props.contentStyle],
601
- testId: this.props.testId
602
- }, title, title && children && React__namespace.createElement(wonderBlocksLayout.Strut, {
603
- size: wonderBlocksTokens.spacing.xxxSmall_4
604
- }), children);
605
- }
606
- }
607
- const styles = aphrodite.StyleSheet.create({
608
- withoutTitle: {
609
- padding: `10px ${wonderBlocksTokens.spacing.medium_16}px`
610
- },
611
- withTitle: {
612
- padding: wonderBlocksTokens.spacing.medium_16
613
- }
614
- });
47
+ class TooltipContent extends React__namespace.Component{_renderTitle(){const{title}=this.props;if(title){if(typeof title==="string"){return jsxRuntime.jsx(wonderBlocksTypography.HeadingSmall,{children:title})}else {return title}}return null}_renderChildren(){const{children}=this.props;if(typeof children==="string"){return jsxRuntime.jsx(wonderBlocksTypography.LabelMedium,{children:children})}else {return children}}render(){const title=this._renderTitle();const children=this._renderChildren();const containerStyle=title?styles.withTitle:styles.withoutTitle;return jsxRuntime.jsxs(wonderBlocksCore.View,{style:[containerStyle,this.props.contentStyle],testId:this.props.testId,children:[title,title&&children&&jsxRuntime.jsx(wonderBlocksLayout.Strut,{size:wonderBlocksTokens.spacing.xxxSmall_4}),children]})}}const styles=aphrodite.StyleSheet.create({withoutTitle:{padding:`10px ${wonderBlocksTokens.spacing.medium_16}px`},withTitle:{padding:wonderBlocksTokens.spacing.medium_16}});
615
48
 
616
49
  var t=e=>null==e||"object"!=typeof e?e:Array.isArray(e)?e.map(t):Object.keys(e).reduce(((n,r)=>(n[r]=t(e[r]),n)),{}),n=Object.freeze({Unknown:"Unknown",Internal:"Internal",InvalidInput:"InvalidInput",InvalidUse:"InvalidUse",NotFound:"NotFound",NotAllowed:"NotAllowed",Unauthorized:"Unauthorized",NotImplemented:"NotImplemented"});function r(t,e,n){return (e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(t,"string");return "symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}class s{constructor(t,e,n){r(this,"_name",void 0),r(this,"_message",void 0),r(this,"_stackFrames",void 0),this._name=t,this._message=e,this._stackFrames=[...n];}get message(){return this._message}get name(){return this._name}get messageWithName(){return "".concat(this.name,": ").concat(this.message)}get stack(){return [...this._stackFrames]}get standardizedStack(){return "".concat(this.messageWithName,"\n").concat(this._stackFrames.join("\n"))}static fromConsequenceAndCause(t,e){var n;if("production"!==process.env.NODE_ENV){if(!(t instanceof s))throw new Error("consequence must be an instance of ErrorInfo");if(!(e instanceof s))throw new Error("cause must be an instance of ErrorInfo");if(e===t)throw new Error("cause and consequence must be different")}for(var r=[],i=e.stack,a=null!==(n=null==t?void 0:t.stack)&&void 0!==n?n:[],o=i.length-1,c=a.length-1;o>=0&&c>=0&&i[o]===a[c];)r.unshift(i[o]),o--,c--;for(;o>=0;o--)r.unshift(i[o]);for(;c>=0;c--)r.unshift(a[c]);return new s(t.name,((t,e)=>{var n=t=>(null==t?void 0:t.trim())||"(empty message)",r=n(t);return null==e?r:"".concat(r,"\n\tcaused by\n\t\t").concat(n(e))})(t.message,e.messageWithName),r)}static normalize(t){var e,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;if("production"!==process.env.NODE_ENV){if(!(t instanceof Error))throw new Error("Error must be an instance of Error");if(i<0)throw new Error("stripFrames must be >= 0");if(a<0)throw new Error("minimumFrameCount must be >= 0")}var o=null!==(e=t.message.toString().split("\n").find((t=>t.trim().length)))&&void 0!==e?e:"(empty message)",c=t.toString(),u=(null!==(n=t.stack)&&void 0!==n&&n.startsWith(c)&&t.stack!==c?t.stack.substring(c.length):null!==(r=t.stack)&&void 0!==r?r:"").split("\n").filter((t=>t.trim().length)),l=u.length>=i+a?i:0;return new s(t.name,o,u.slice(l))}static from(t){var e,n;if("production"!==process.env.NODE_ENV&&!(t instanceof Error))throw new Error("Error must be an instance of Error");var r=t.toString(),i=(null!==(e=t.stack)&&void 0!==e&&e.startsWith(r)&&t.stack!==r?t.stack.substring(r.length):null!==(n=t.stack)&&void 0!==n?n:"").split("\n").filter((t=>t.trim().length));return new s(t.name,t.message,i)}}class i extends Error{constructor(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.Unknown,{cause:a,prefix:o,name:c,metadata:u,stripStackFrames:l,minimumFrameCount:m,compositeStack:d}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Object.freeze({});if("production"!==process.env.NODE_ENV){if(a&&!(a instanceof Error))throw new Error("cause must be an instance of Error");if(null!=c&&/\s/g.test(c))throw new Error("name must not contain whitespace");if(/\s/g.test(i))throw new Error("kind must not contain whitespace");if(null!=o&&/\s/g.test(o))throw new Error("prefix must not contain whitespace");if(null!=l&&l<0)throw new Error("stripStackFrames must be >= 0");if(null!=m&&m<0)throw new Error("minimumFrameCount must be >= 0")}super(e),r(this,"kind",void 0),r(this,"originalMessage",void 0),r(this,"originalStack",void 0),r(this,"metadata",void 0),r(this,"cause",void 0),this.originalMessage=e,this.metadata=(e=>{if(null==e)return e;var n=t(e);return Object.freeze(n)})(u),this.name="".concat(null!=o?o:"").concat(i).concat(null!=c?c:"","Error"),this.kind=i,this.originalStack=this.stack,this.cause=a;var f=s.normalize(this,null!=l?l:0,null!=m?m:1);if(delete this.stack,this.stack=f.standardizedStack,null!=a){var h=s.from(a),v=s.fromConsequenceAndCause(f,h);this.message=v.message,!0===d&&(this.stack=v.standardizedStack);}}}Object.freeze({ConsequenceFirst:"consequence-first",CauseFirst:"cause-first"});class w extends i{constructor(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.InvalidInput,r=arguments.length>2?arguments[2]:void 0;super("Unhandled case for '".concat(t,"'"),e,r);}}
617
50
 
618
- class RefTracker {
619
- constructor() {
620
- this._lastRef = void 0;
621
- this._targetFn = void 0;
622
- this.updateRef = ref => {
623
- if (ref) {
624
- const domNode = ReactDOM__namespace.findDOMNode(ref);
625
- if (domNode instanceof HTMLElement && domNode !== this._lastRef) {
626
- var _this$_targetFn;
627
- this._lastRef = domNode;
628
- (_this$_targetFn = this._targetFn) == null || _this$_targetFn.call(this, domNode);
629
- }
630
- }
631
- };
632
- this.setCallback = targetFn => {
633
- if (this._targetFn !== targetFn) {
634
- if (targetFn && typeof targetFn !== "function") {
635
- throw new Error("targetFn must be a function");
636
- }
637
- this._targetFn = targetFn || undefined;
638
- if (this._lastRef && this._targetFn) {
639
- this._targetFn(this._lastRef);
640
- }
641
- }
642
- };
643
- }
644
- }
51
+ class RefTracker{constructor(){this.updateRef=ref=>{if(ref){const domNode=ReactDOM__namespace.findDOMNode(ref);if(domNode instanceof HTMLElement&&domNode!==this._lastRef){this._lastRef=domNode;this._targetFn?.(domNode);}}};this.setCallback=targetFn=>{if(this._targetFn!==targetFn){if(targetFn&&typeof targetFn!=="function"){throw new Error("targetFn must be a function")}this._targetFn=targetFn||undefined;if(this._lastRef&&this._targetFn){this._targetFn(this._lastRef);}}};}}
645
52
 
646
- const filterPopperPlacement = placement => {
647
- switch (placement) {
648
- case "auto":
649
- case "auto-start":
650
- case "auto-end":
651
- case "top":
652
- case "top-start":
653
- case "top-end":
654
- return "top";
655
- case "bottom":
656
- case "bottom-start":
657
- case "bottom-end":
658
- return "bottom";
659
- case "right":
660
- case "right-start":
661
- case "right-end":
662
- return "right";
663
- case "left":
664
- case "left-start":
665
- case "left-end":
666
- return "left";
667
- default:
668
- throw new w(placement);
669
- }
670
- };
671
- function _modifyPosition({
672
- state
673
- }) {
674
- const popperHeight = state.rects.popper.height + state.rects.reference.height;
675
- const minHeight = document.documentElement.clientHeight;
676
- if (minHeight < popperHeight && state.modifiersData.hide) {
677
- state.modifiersData.hide = _extends__default["default"]({}, state.modifiersData.hide, {
678
- isReferenceHidden: false
679
- });
680
- }
681
- }
682
- const smallViewportModifier = {
683
- name: "smallViewport",
684
- enabled: true,
685
- phase: "main",
686
- fn: _modifyPosition
687
- };
688
- class TooltipPopper extends React__namespace.Component {
689
- constructor(props) {
690
- super(props);
691
- this._bubbleRefTracker = new RefTracker();
692
- this._tailRefTracker = new RefTracker();
693
- this._observer = null;
694
- this._popperUpdate = null;
695
- this.handleFirstUpdate = () => {
696
- this.setState({
697
- isReady: true
698
- });
699
- };
700
- this.state = {
701
- isReady: false
702
- };
703
- }
704
- componentDidMount() {
705
- const {
706
- anchorElement,
707
- autoUpdate
708
- } = this.props;
709
- if (!anchorElement || !autoUpdate) {
710
- return;
711
- }
712
- this._observer = new MutationObserver(() => {
713
- var _this$_popperUpdate;
714
- (_this$_popperUpdate = this._popperUpdate) == null || _this$_popperUpdate.call(this);
715
- });
716
- this._observer.observe(anchorElement, {
717
- attributes: true,
718
- childList: true,
719
- subtree: true
720
- });
721
- }
722
- componentWillUnmount() {
723
- var _this$_observer;
724
- (_this$_observer = this._observer) == null || _this$_observer.disconnect();
725
- }
726
- _renderPositionedContent(popperProps) {
727
- const {
728
- children
729
- } = this.props;
730
- const {
731
- isReady
732
- } = this.state;
733
- const placement = filterPopperPlacement(popperProps.placement) || this.props.placement;
734
- this._bubbleRefTracker.setCallback(popperProps.ref);
735
- this._tailRefTracker.setCallback(popperProps.arrowProps.ref);
736
- this._popperUpdate = popperProps.update;
737
- const bubbleProps = {
738
- placement,
739
- style: {
740
- top: popperProps.style.top,
741
- left: popperProps.style.left,
742
- bottom: popperProps.style.bottom,
743
- right: popperProps.style.right,
744
- position: popperProps.style.position,
745
- transform: popperProps.style.transform,
746
- visibility: !isReady ? "hidden" : undefined
747
- },
748
- updateBubbleRef: this._bubbleRefTracker.updateRef,
749
- tailOffset: {
750
- bottom: popperProps.arrowProps.style.bottom,
751
- right: popperProps.arrowProps.style.right,
752
- top: popperProps.arrowProps.style.top,
753
- left: popperProps.arrowProps.style.left,
754
- transform: popperProps.arrowProps.style.transform
755
- },
756
- updateTailRef: this._tailRefTracker.updateRef,
757
- isReferenceHidden: popperProps.isReferenceHidden
758
- };
759
- return children(bubbleProps);
760
- }
761
- render() {
762
- const {
763
- anchorElement,
764
- placement,
765
- rootBoundary,
766
- viewportPadding
767
- } = this.props;
768
- const modifiers = [smallViewportModifier];
769
- if (rootBoundary === "viewport") {
770
- modifiers.push({
771
- name: "preventOverflow",
772
- options: {
773
- rootBoundary: "viewport",
774
- padding: viewportPadding
775
- }
776
- });
777
- } else {
778
- modifiers.push({
779
- name: "flip",
780
- options: {
781
- rootBoundary: "document"
782
- }
783
- });
784
- }
785
- return React__namespace.createElement(reactPopper.Popper, {
786
- referenceElement: anchorElement,
787
- strategy: "fixed",
788
- placement: placement,
789
- modifiers: modifiers,
790
- onFirstUpdate: this.handleFirstUpdate
791
- }, props => this._renderPositionedContent(props));
792
- }
793
- }
794
- TooltipPopper.defaultProps = {
795
- rootBoundary: "viewport",
796
- viewportPadding: wonderBlocksTokens.spacing.small_12
797
- };
53
+ const filterPopperPlacement=placement=>{switch(placement){case"auto":case"auto-start":case"auto-end":case"top":case"top-start":case"top-end":return "top";case"bottom":case"bottom-start":case"bottom-end":return "bottom";case"right":case"right-start":case"right-end":return "right";case"left":case"left-start":case"left-end":return "left";default:throw new w(placement)}};function _modifyPosition({state}){const popperHeight=state.rects.popper.height+state.rects.reference.height;const minHeight=document.documentElement.clientHeight;if(minHeight<popperHeight&&state.modifiersData.hide){state.modifiersData.hide={...state.modifiersData.hide,isReferenceHidden:false};}}const smallViewportModifier={name:"smallViewport",enabled:true,phase:"main",fn:_modifyPosition};class TooltipPopper extends React__namespace.Component{componentDidMount(){const{anchorElement,autoUpdate}=this.props;if(!anchorElement||!autoUpdate){return}this._observer=new MutationObserver(()=>{this._popperUpdate?.();});this._observer.observe(anchorElement,{attributes:true,childList:true,subtree:true});}componentWillUnmount(){this._observer?.disconnect();}_renderPositionedContent(popperProps){const{children}=this.props;const{isReady}=this.state;const placement=filterPopperPlacement(popperProps.placement)||this.props.placement;this._bubbleRefTracker.setCallback(popperProps.ref);this._tailRefTracker.setCallback(popperProps.arrowProps.ref);this._popperUpdate=popperProps.update;const bubbleProps={placement,style:{top:popperProps.style.top,left:popperProps.style.left,bottom:popperProps.style.bottom,right:popperProps.style.right,position:popperProps.style.position,transform:popperProps.style.transform,visibility:!isReady?"hidden":undefined},updateBubbleRef:this._bubbleRefTracker.updateRef,tailOffset:{bottom:popperProps.arrowProps.style.bottom,right:popperProps.arrowProps.style.right,top:popperProps.arrowProps.style.top,left:popperProps.arrowProps.style.left,transform:popperProps.arrowProps.style.transform},updateTailRef:this._tailRefTracker.updateRef,isReferenceHidden:popperProps.isReferenceHidden};return children(bubbleProps)}render(){const{anchorElement,placement,rootBoundary,viewportPadding}=this.props;const modifiers=[smallViewportModifier];if(rootBoundary==="viewport"){modifiers.push({name:"preventOverflow",options:{rootBoundary:"viewport",padding:viewportPadding}});}else {modifiers.push({name:"flip",options:{rootBoundary:"document"}});}return jsxRuntime.jsx(reactPopper.Popper,{referenceElement:anchorElement,strategy:"fixed",placement:placement,modifiers:modifiers,onFirstUpdate:this.handleFirstUpdate,children:props=>this._renderPositionedContent(props)})}constructor(props){super(props),this._bubbleRefTracker=new RefTracker,this._tailRefTracker=new RefTracker,this._observer=null,this._popperUpdate=null,this.handleFirstUpdate=()=>{this.setState({isReady:true});};this.state={isReady:false};}}TooltipPopper.defaultProps={rootBoundary:"viewport",viewportPadding:wonderBlocksTokens.spacing.small_12};
798
54
 
799
- class Tooltip extends React__namespace.Component {
800
- constructor(...args) {
801
- super(...args);
802
- this.state = {
803
- active: false,
804
- activeBubble: false
805
- };
806
- }
807
- static getDerivedStateFromProps(props, state) {
808
- return {
809
- active: typeof props.opened === "boolean" ? props.opened : state.active
810
- };
811
- }
812
- _updateAnchorElement(ref) {
813
- if (ref && ref !== this.state.anchorElement) {
814
- this.setState({
815
- anchorElement: ref
816
- });
817
- }
818
- }
819
- _renderBubbleContent() {
820
- const {
821
- title,
822
- content,
823
- contentStyle,
824
- testId
825
- } = this.props;
826
- if (typeof content === "string") {
827
- return React__namespace.createElement(TooltipContent, {
828
- title: title,
829
- contentStyle: contentStyle,
830
- testId: testId ? `${testId}-content` : undefined
831
- }, content);
832
- } else if (title) {
833
- return React__namespace.cloneElement(content, {
834
- title
835
- });
836
- } else {
837
- return content;
838
- }
839
- }
840
- _renderPopper(bubbleId) {
841
- const {
842
- backgroundColor,
843
- placement
844
- } = this.props;
845
- return React__namespace.createElement(TooltipPopper, {
846
- anchorElement: this.state.anchorElement,
847
- placement: placement,
848
- autoUpdate: this.props.autoUpdate,
849
- viewportPadding: this.props.viewportPadding
850
- }, props => React__namespace.createElement(TooltipBubble, {
851
- id: bubbleId,
852
- style: props.style,
853
- backgroundColor: backgroundColor,
854
- tailOffset: props.tailOffset,
855
- isReferenceHidden: props.isReferenceHidden,
856
- placement: props.placement,
857
- updateTailRef: props.updateTailRef,
858
- updateBubbleRef: props.updateBubbleRef,
859
- onActiveChanged: active => this.setState({
860
- activeBubble: active
861
- })
862
- }, this._renderBubbleContent()));
863
- }
864
- _getHost() {
865
- const {
866
- anchorElement
867
- } = this.state;
868
- return wonderBlocksModal.maybeGetPortalMountedModalHostElement(anchorElement) || document.body;
869
- }
870
- _renderTooltipAnchor(uniqueId) {
871
- const {
872
- autoUpdate,
873
- children,
874
- forceAnchorFocusivity
875
- } = this.props;
876
- const {
877
- active,
878
- activeBubble
879
- } = this.state;
880
- const popperHost = this._getHost();
881
- const shouldAnchorExist = autoUpdate ? this.state.anchorElement : true;
882
- const shouldBeVisible = popperHost && (active || activeBubble) && shouldAnchorExist;
883
- return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(TooltipAnchor, {
884
- forceAnchorFocusivity: forceAnchorFocusivity,
885
- anchorRef: r => this._updateAnchorElement(r),
886
- onActiveChanged: active => this.setState({
887
- active
888
- }),
889
- id: `${uniqueId}-anchor`
890
- }, children), shouldBeVisible && ReactDOM__namespace.createPortal(this._renderPopper(uniqueId), popperHost));
891
- }
892
- render() {
893
- const {
894
- id
895
- } = this.props;
896
- return React__namespace.createElement(wonderBlocksCore.Id, {
897
- id: id
898
- }, uniqueId => this._renderTooltipAnchor(uniqueId));
899
- }
900
- }
901
- Tooltip.defaultProps = {
902
- forceAnchorFocusivity: true,
903
- placement: "top"
904
- };
55
+ class Tooltip extends React__namespace.Component{static getDerivedStateFromProps(props,state){return {active:typeof props.opened==="boolean"?props.opened:state.active}}_updateAnchorElement(ref){if(ref&&ref!==this.state.anchorElement){this.setState({anchorElement:ref});}}_renderBubbleContent(){const{title,content,contentStyle,testId}=this.props;if(typeof content==="string"){return jsxRuntime.jsx(TooltipContent,{title:title,contentStyle:contentStyle,testId:testId?`${testId}-content`:undefined,children:content})}else if(title){return React__namespace.cloneElement(content,{title})}else {return content}}_renderPopper(ariaContentId){const{backgroundColor,placement}=this.props;return jsxRuntime.jsx(TooltipPopper,{anchorElement:this.state.anchorElement,placement:placement,autoUpdate:this.props.autoUpdate,viewportPadding:this.props.viewportPadding,children:props=>jsxRuntime.jsx(TooltipBubble,{id:ariaContentId,style:props.style,backgroundColor:backgroundColor,tailOffset:props.tailOffset,isReferenceHidden:props.isReferenceHidden,placement:props.placement,updateTailRef:props.updateTailRef,updateBubbleRef:props.updateBubbleRef,onActiveChanged:active=>this.setState({activeBubble:active}),children:this._renderBubbleContent()})})}_getHost(){const{anchorElement}=this.state;return wonderBlocksModal.maybeGetPortalMountedModalHostElement(anchorElement)||document.body}_renderTooltipAnchor(uniqueId){const{autoUpdate,children,forceAnchorFocusivity}=this.props;const{active,activeBubble}=this.state;const popperHost=this._getHost();const shouldAnchorExist=autoUpdate?this.state.anchorElement:true;const shouldBeVisible=popperHost&&(active||activeBubble)&&shouldAnchorExist;const ariaContentId=`${uniqueId}-aria-content`;return jsxRuntime.jsxs(React__namespace.Fragment,{children:[jsxRuntime.jsx(TooltipAnchor,{forceAnchorFocusivity:forceAnchorFocusivity,anchorRef:r=>this._updateAnchorElement(r),onActiveChanged:active=>this.setState({active}),"aria-describedby":shouldBeVisible?ariaContentId:undefined,children:children}),shouldBeVisible&&ReactDOM__namespace.createPortal(this._renderPopper(ariaContentId),popperHost)]})}render(){const{id}=this.props;return jsxRuntime.jsx(wonderBlocksCore.Id,{id:id,children:uniqueId=>this._renderTooltipAnchor(uniqueId)})}constructor(...args){super(...args),this.state={active:false,activeBubble:false};}}Tooltip.defaultProps={forceAnchorFocusivity:true,placement:"top"};
905
56
 
906
57
  exports.TooltipContent = TooltipContent;
907
58
  exports.TooltipPopper = TooltipPopper;