@atlaskit/top-layer 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/top-layer
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`2857e277050c6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2857e277050c6) -
8
+ Behind the `platform-dst-top-layer` feature gate, `@atlaskit/popper/unsafe-imperative`'s
9
+ `createPopper` now renders and positions in the browser top layer via `@atlaskit/top-layer`
10
+ instead of running the Popper.js engine. Positioning and teardown are applied asynchronously, as
11
+ Popper.js' own first update is. Flag-off behaviour is unchanged.
12
+
13
+ `@atlaskit/top-layer`: the JavaScript positioning fallback no longer clears a consumer's own
14
+ inline positioning and visibility styles.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+
3
20
  ## 3.1.0
4
21
 
5
22
  ### Minor Changes
@@ -344,6 +344,38 @@ function useAnchorPosition(_ref3) {
344
344
  value: 'auto'
345
345
  }]
346
346
  });
347
+
348
+ // The popover can be consumer-owned (`@atlaskit/popper`'s `createPopper`),
349
+ // so restore prior inline values rather than removing ours.
350
+ var undoPosition;
351
+ var undoHide;
352
+
353
+ // `opacity: 0` not `visibility: hidden`: Firefox skips visibility-hidden
354
+ // elements during `<dialog>` initial-focus traversal.
355
+ function hideUntilPositioned() {
356
+ // Keep the first snapshot, else we capture our own `opacity: 0`.
357
+ // (`!popover` is for TS: narrowing does not reach nested functions.)
358
+ if (!popover || undoHide) {
359
+ return;
360
+ }
361
+ undoHide = (0, _setStyle.setStyle)({
362
+ element: popover,
363
+ styles: [{
364
+ property: 'opacity',
365
+ value: '0'
366
+ }]
367
+ });
368
+ }
369
+ function reveal() {
370
+ var _undoHide;
371
+ (_undoHide = undoHide) === null || _undoHide === void 0 || _undoHide();
372
+ undoHide = undefined;
373
+ }
374
+ function restorePosition() {
375
+ var _undoPosition;
376
+ (_undoPosition = undoPosition) === null || _undoPosition === void 0 || _undoPosition();
377
+ undoPosition = undefined;
378
+ }
347
379
  function update() {
348
380
  if (!trigger || !popover) {
349
381
  return;
@@ -382,11 +414,20 @@ function useAnchorPosition(_ref3) {
382
414
  }),
383
415
  top = _computeFallbackPosit.top,
384
416
  left = _computeFallbackPosit.left;
385
- popover.style.setProperty('top', "".concat(top, "px"));
386
- popover.style.setProperty('left', "".concat(left, "px"));
387
- // Reveal the popover only after it has been positioned.
388
- // See the toggle listener below for why we hide on open.
389
- popover.style.removeProperty('opacity');
417
+
418
+ // Restore first so the snapshot stays the consumer's value.
419
+ restorePosition();
420
+ undoPosition = (0, _setStyle.setStyle)({
421
+ element: popover,
422
+ styles: [{
423
+ property: 'top',
424
+ value: "".concat(top, "px")
425
+ }, {
426
+ property: 'left',
427
+ value: "".concat(left, "px")
428
+ }]
429
+ });
430
+ reveal();
390
431
  }
391
432
 
392
433
  // Throttle scroll/resize updates to one per animation frame
@@ -420,22 +461,17 @@ function useAnchorPosition(_ref3) {
420
461
  // event has already fired and our listener below would miss it. Start
421
462
  // observing immediately so the first measurement still happens.
422
463
  if (isPopoverOpen(popover)) {
423
- popover.style.setProperty('opacity', '0');
464
+ hideUntilPositioned();
424
465
  resizeObserver.observe(popover);
425
466
  }
426
467
  var undoPositioning = (0, _combine.combine)(cleanupBaseStyles,
427
- // On every open: hide synchronously so the user never sees
428
- // the UA-default position, then re-observe for a fresh
429
- // measurement. We use `opacity: 0` rather than
430
- // `visibility: hidden` because Firefox skips visibility-hidden
431
- // elements during `<dialog>` initial-focus traversal. See
432
- // `form-in-popup.spec.tsx` on `desktop-firefox`.
468
+ // Each open needs a fresh measurement, so hide and re-observe.
433
469
  (0, _bindEventListener.bind)(popover, {
434
470
  type: 'toggle',
435
471
  listener: function listener(event) {
436
472
  var toggleEvent = event;
437
473
  if (toggleEvent.newState === 'open') {
438
- popover.style.setProperty('opacity', '0');
474
+ hideUntilPositioned();
439
475
  resizeObserver.observe(popover);
440
476
  }
441
477
  }
@@ -456,9 +492,8 @@ function useAnchorPosition(_ref3) {
456
492
  }
457
493
  }), function () {
458
494
  scheduledUpdate.cancel();
459
- popover.style.removeProperty('top');
460
- popover.style.removeProperty('left');
461
- popover.style.removeProperty('opacity');
495
+ restorePosition();
496
+ reveal();
462
497
  });
463
498
  return undoPositioning;
464
499
  }, [anchorRef, popoverRef, stablePlacement, forceFallbackPositioning, isEnabled, id, isOpen]);
@@ -327,6 +327,38 @@ export function useAnchorPosition({
327
327
  value: 'auto'
328
328
  }]
329
329
  });
330
+
331
+ // The popover can be consumer-owned (`@atlaskit/popper`'s `createPopper`),
332
+ // so restore prior inline values rather than removing ours.
333
+ let undoPosition;
334
+ let undoHide;
335
+
336
+ // `opacity: 0` not `visibility: hidden`: Firefox skips visibility-hidden
337
+ // elements during `<dialog>` initial-focus traversal.
338
+ function hideUntilPositioned() {
339
+ // Keep the first snapshot, else we capture our own `opacity: 0`.
340
+ // (`!popover` is for TS: narrowing does not reach nested functions.)
341
+ if (!popover || undoHide) {
342
+ return;
343
+ }
344
+ undoHide = setStyle({
345
+ element: popover,
346
+ styles: [{
347
+ property: 'opacity',
348
+ value: '0'
349
+ }]
350
+ });
351
+ }
352
+ function reveal() {
353
+ var _undoHide;
354
+ (_undoHide = undoHide) === null || _undoHide === void 0 ? void 0 : _undoHide();
355
+ undoHide = undefined;
356
+ }
357
+ function restorePosition() {
358
+ var _undoPosition;
359
+ (_undoPosition = undoPosition) === null || _undoPosition === void 0 ? void 0 : _undoPosition();
360
+ undoPosition = undefined;
361
+ }
330
362
  function update() {
331
363
  if (!trigger || !popover) {
332
364
  return;
@@ -366,11 +398,20 @@ export function useAnchorPosition({
366
398
  direction: stablePlacement.offset.crossAxisShift.direction
367
399
  }
368
400
  });
369
- popover.style.setProperty('top', `${top}px`);
370
- popover.style.setProperty('left', `${left}px`);
371
- // Reveal the popover only after it has been positioned.
372
- // See the toggle listener below for why we hide on open.
373
- popover.style.removeProperty('opacity');
401
+
402
+ // Restore first so the snapshot stays the consumer's value.
403
+ restorePosition();
404
+ undoPosition = setStyle({
405
+ element: popover,
406
+ styles: [{
407
+ property: 'top',
408
+ value: `${top}px`
409
+ }, {
410
+ property: 'left',
411
+ value: `${left}px`
412
+ }]
413
+ });
414
+ reveal();
374
415
  }
375
416
 
376
417
  // Throttle scroll/resize updates to one per animation frame
@@ -404,22 +445,17 @@ export function useAnchorPosition({
404
445
  // event has already fired and our listener below would miss it. Start
405
446
  // observing immediately so the first measurement still happens.
406
447
  if (isPopoverOpen(popover)) {
407
- popover.style.setProperty('opacity', '0');
448
+ hideUntilPositioned();
408
449
  resizeObserver.observe(popover);
409
450
  }
410
451
  const undoPositioning = combine(cleanupBaseStyles,
411
- // On every open: hide synchronously so the user never sees
412
- // the UA-default position, then re-observe for a fresh
413
- // measurement. We use `opacity: 0` rather than
414
- // `visibility: hidden` because Firefox skips visibility-hidden
415
- // elements during `<dialog>` initial-focus traversal. See
416
- // `form-in-popup.spec.tsx` on `desktop-firefox`.
452
+ // Each open needs a fresh measurement, so hide and re-observe.
417
453
  bind(popover, {
418
454
  type: 'toggle',
419
455
  listener: event => {
420
456
  const toggleEvent = event;
421
457
  if (toggleEvent.newState === 'open') {
422
- popover.style.setProperty('opacity', '0');
458
+ hideUntilPositioned();
423
459
  resizeObserver.observe(popover);
424
460
  }
425
461
  }
@@ -438,9 +474,8 @@ export function useAnchorPosition({
438
474
  }
439
475
  }), () => {
440
476
  scheduledUpdate.cancel();
441
- popover.style.removeProperty('top');
442
- popover.style.removeProperty('left');
443
- popover.style.removeProperty('opacity');
477
+ restorePosition();
478
+ reveal();
444
479
  });
445
480
  return undoPositioning;
446
481
  }, [anchorRef, popoverRef, stablePlacement, forceFallbackPositioning, isEnabled, id, isOpen]);
@@ -337,6 +337,38 @@ export function useAnchorPosition(_ref3) {
337
337
  value: 'auto'
338
338
  }]
339
339
  });
340
+
341
+ // The popover can be consumer-owned (`@atlaskit/popper`'s `createPopper`),
342
+ // so restore prior inline values rather than removing ours.
343
+ var undoPosition;
344
+ var undoHide;
345
+
346
+ // `opacity: 0` not `visibility: hidden`: Firefox skips visibility-hidden
347
+ // elements during `<dialog>` initial-focus traversal.
348
+ function hideUntilPositioned() {
349
+ // Keep the first snapshot, else we capture our own `opacity: 0`.
350
+ // (`!popover` is for TS: narrowing does not reach nested functions.)
351
+ if (!popover || undoHide) {
352
+ return;
353
+ }
354
+ undoHide = setStyle({
355
+ element: popover,
356
+ styles: [{
357
+ property: 'opacity',
358
+ value: '0'
359
+ }]
360
+ });
361
+ }
362
+ function reveal() {
363
+ var _undoHide;
364
+ (_undoHide = undoHide) === null || _undoHide === void 0 || _undoHide();
365
+ undoHide = undefined;
366
+ }
367
+ function restorePosition() {
368
+ var _undoPosition;
369
+ (_undoPosition = undoPosition) === null || _undoPosition === void 0 || _undoPosition();
370
+ undoPosition = undefined;
371
+ }
340
372
  function update() {
341
373
  if (!trigger || !popover) {
342
374
  return;
@@ -375,11 +407,20 @@ export function useAnchorPosition(_ref3) {
375
407
  }),
376
408
  top = _computeFallbackPosit.top,
377
409
  left = _computeFallbackPosit.left;
378
- popover.style.setProperty('top', "".concat(top, "px"));
379
- popover.style.setProperty('left', "".concat(left, "px"));
380
- // Reveal the popover only after it has been positioned.
381
- // See the toggle listener below for why we hide on open.
382
- popover.style.removeProperty('opacity');
410
+
411
+ // Restore first so the snapshot stays the consumer's value.
412
+ restorePosition();
413
+ undoPosition = setStyle({
414
+ element: popover,
415
+ styles: [{
416
+ property: 'top',
417
+ value: "".concat(top, "px")
418
+ }, {
419
+ property: 'left',
420
+ value: "".concat(left, "px")
421
+ }]
422
+ });
423
+ reveal();
383
424
  }
384
425
 
385
426
  // Throttle scroll/resize updates to one per animation frame
@@ -413,22 +454,17 @@ export function useAnchorPosition(_ref3) {
413
454
  // event has already fired and our listener below would miss it. Start
414
455
  // observing immediately so the first measurement still happens.
415
456
  if (isPopoverOpen(popover)) {
416
- popover.style.setProperty('opacity', '0');
457
+ hideUntilPositioned();
417
458
  resizeObserver.observe(popover);
418
459
  }
419
460
  var undoPositioning = combine(cleanupBaseStyles,
420
- // On every open: hide synchronously so the user never sees
421
- // the UA-default position, then re-observe for a fresh
422
- // measurement. We use `opacity: 0` rather than
423
- // `visibility: hidden` because Firefox skips visibility-hidden
424
- // elements during `<dialog>` initial-focus traversal. See
425
- // `form-in-popup.spec.tsx` on `desktop-firefox`.
461
+ // Each open needs a fresh measurement, so hide and re-observe.
426
462
  bind(popover, {
427
463
  type: 'toggle',
428
464
  listener: function listener(event) {
429
465
  var toggleEvent = event;
430
466
  if (toggleEvent.newState === 'open') {
431
- popover.style.setProperty('opacity', '0');
467
+ hideUntilPositioned();
432
468
  resizeObserver.observe(popover);
433
469
  }
434
470
  }
@@ -449,9 +485,8 @@ export function useAnchorPosition(_ref3) {
449
485
  }
450
486
  }), function () {
451
487
  scheduledUpdate.cancel();
452
- popover.style.removeProperty('top');
453
- popover.style.removeProperty('left');
454
- popover.style.removeProperty('opacity');
488
+ restorePosition();
489
+ reveal();
455
490
  });
456
491
  return undoPositioning;
457
492
  }, [anchorRef, popoverRef, stablePlacement, forceFallbackPositioning, isEnabled, id, isOpen]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/top-layer",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Low-level layering primitives based on popover and dialog",
5
5
  "homepage": "https://atlassian.design/components/top-layer",
6
6
  "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
@@ -40,7 +40,7 @@
40
40
  "@atlaskit/ds-lib": "^8.0.0",
41
41
  "@atlaskit/layering": "^5.0.0",
42
42
  "@atlaskit/react-compiler-gating": "^0.2.0",
43
- "@atlaskit/tokens": "^16.3.0",
43
+ "@atlaskit/tokens": "^16.4.0",
44
44
  "@babel/runtime": "^7.0.0",
45
45
  "@compiled/react": "^1.0.0",
46
46
  "bind-event-listener": "^3.0.0",