Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 5164x 5164x 5164x 5164x 5164x 5164x 2x 4657x 4657x 430x 264x 430x 430x 430x 4227x 5642x 1656x 264x 264x 264x 772x 532x 532x 24x 532x 240x 264x 24x 24x 24x 24x 1543x 1543x 1249x 1249x 1168x 294x 294x 80x 294x 10x 10x 10x 8x 8x 8x 18x 8x 8x 31335x 2601x 2601x 2547x 2547x 19148x 19148x 4554x 4554x 4518x 4554x 4554x 45540x 4554x 40986x 4554x 36432x 4554x 31878x 4554x 4554x 4554x 4524x 30x 30x 30x 28x 4554x 4554x 4554x 1892x 4560x 4560x 4560x 4560x 1048x 1007x 1007x 4560x 4560x 34139x 8888x 8888x 8888x 8888x 7950x 5080x 7950x 2216x 4x 2x 2x 2x 4x 2x 2x 2x 12x 8x 8x 8x 8x 8x 4558x 2x 2x 4758x 16x 16x 4556x 2380x 2380x 5132x 4658x 4658x 4658x 4538x 8x 8x 8x 4560x 1930x 1930x 1930x 1930x 13666x 4x 4x 4x 4x 2604x 1000x 1000x 432x 3934x 3934x 40840x 723x 385x 723x 723x 31339x 31339x 26633x 4706x 4706x 1802x 574x 1228x 6x 1222x 4706x 234x 18x 8x 288x | /**
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {BaseComponent} from '../../../coral-base-component';
import {BaseOverlay} from '../../../coral-base-overlay';
import PopperJS from 'popper.js';
import {transform, validate, commons} from '../../../coral-utils';
import {Decorator} from '../../../coral-decorator';
const DEPRECATED_ALIGN = 'Coral.Overlay: alignAt and alignMy have been deprecated. Please use the offset, inner and placement properties instead.';
const DEPRECATED_FLIP_FIT = 'Coral.Overlay.collision.FLIP_FIT has been deprecated. Please use Coral.Overlay.collision.FLIP instead.';
/**
Enumeration for {@link Overlay} alignment pairs.
@deprecated
@typedef {Object} OverlayAlignEnum
@property {String} LEFT_TOP
Use the top of the left side as an anchor point.
@property {String} LEFT_CENTER
Use the center of the left side as an anchor point.
@property {String} LEFT_BOTTOM
Use the bottom of the left side as an anchor point.
@property {String} CENTER_TOP
Use the center of the top side as an anchor point.
@property {String} CENTER_CENTER
Use the center as an anchor point.
@property {String} CENTER_BOTTOM
Use the center of the bottom side as an anchor point.
@property {String} RIGHT_TOP
Use the top of the right side as an anchor point.
@property {String} RIGHT_CENTER
Use the center of the right side as an anchor point.
@property {String} RIGHT_BOTTOM
Use the bottom of the right side as an anchor point.
*/
const align = {
LEFT_TOP: 'left top',
LEFT_CENTER: 'left center',
LEFT_BOTTOM: 'left bottom',
CENTER_TOP: 'center top',
CENTER_CENTER: 'center center',
CENTER_BOTTOM: 'center bottom',
RIGHT_TOP: 'right top',
RIGHT_CENTER: 'right center',
RIGHT_BOTTOM: 'right bottom'
};
/**
Enumeration for {@link Overlay} collision detection strategies.
@typedef {Object} OverlayCollisionEnum
@property {String} FLIP
Flips the element to the opposite side of the target and the collision detection is run again to see if it will fit. Whichever side allows more of the element to be visible will be used.
@property {String} FIT
Shift the element away from the edge of the window.
@property {String} FLIP_FIT
Deprecated. First applies the flip logic, placing the element on whichever side allows more of the element to be visible. Then the fit logic is applied to ensure as much of the element is visible as possible.
@property {String} NONE
Does not apply any collision detection.
*/
const collision = {
FLIP: 'flip',
FIT: 'fit',
FLIP_FIT: 'flipfit',
NONE: 'none'
};
/**
Enumeration for {@link Overlay} anchored overlay targets.
@typedef {Object} OverlayTargetEnum
@property {String} PREVIOUS
Use the previous sibling element in the DOM.
@property {String} NEXT
Use the next sibling element in the DOM.
*/
const target = {
PREVIOUS: '_prev',
NEXT: '_next'
};
/**
Enumeration for {@link Overlay} placement values.
@typedef {Object} OverlayPlacementEnum
@property {String} LEFT
An overlay anchored to the left of the target.
@property {String} RIGHT
An overlay anchored to the right of the target.
@property {String} BOTTOM
An overlay anchored at the bottom the target.
@property {String} TOP
An overlay anchored at the top target.
*/
const placement = {
LEFT: 'left',
RIGHT: 'right',
BOTTOM: 'bottom',
TOP: 'top'
};
/**
Enumeration for {@link Overlay} interaction values.
@typedef {Object} OverlayInteractionEnum
@property {String} ON
Keyboard interaction is enabled.
@property {String} OFF
Keyboard interaction is disabled.
*/
const interaction = {
ON: 'on',
OFF: 'off'
};
const CLASSNAME = '_coral-Overlay';
/**
@class Coral.Overlay
@classdesc A generic Overlay component.
@htmltag coral-overlay
@extends {HTMLElement}
@extends {BaseComponent}
@extends {BaseOverlay}
*/
class ExtensibleOverlay extends BaseOverlay(BaseComponent(HTMLElement)) {
/** @ignore */
constructor() {
super();
// Override from BaseOverlay
this._overlayAnimationTime = 0;
// Popper default
this._withinOffset = 5;
// Events
this._delegateEvents({
'global:key:escape': '_handleEscape',
'click [coral-close]': '_handleCloseClick'
});
}
/**
The element the overlay should position relative to. It accepts values from {@link OverlayTargetEnum}, as
well as a DOM element or a CSS selector. If a CSS selector is provided, the first matching element will be used.
@type {?HTMLElement|String}
@default null
*/
get target() {
return this._target || null;
}
set target(value) {
// We don't want to validate that the value must change here
// If a selector is provided, we'll take the first element matching that selector
// If the DOM is modified and the user wants a new target with the same selector,
// They should be able to set target = 'selector' again and get a different element
if (value === null || typeof value === 'string' || value instanceof Node) {
this._target = value;
const targetElement = this._getTarget();
if (targetElement) {
// To make it return focus to the right item, change the target
if (this._returnFocus === this.constructor.returnFocus.ON) {
this.returnFocusTo(targetElement);
}
// update popper if popper already initialised or it is not explicitly avoid.
if(this._popper || !this._avoidPopperInit) {
this._initPopper(false, targetElement);
}
}
}
}
/**
The point on the overlay we should anchor from when positioning. See {@link OverlayAlignEnum}.
@type {String}
@default OverlayAlignEnum.CENTER_CENTER
@htmlattribute alignmy
@deprecated
*/
get alignMy() {
return this._alignMy || align.CENTER_CENTER;
}
set alignMy(value) {
commons._log('warn', DEPRECATED_ALIGN);
value = transform.string(value).toLowerCase();
this._alignMy = validate.enumeration(align)(value) && value || align.CENTER_CENTER;
}
/**
The point on the target we should anchor to when positioning. See {@link OverlayAlignEnum}.
@type {String}
@default Coral.Overlay.align.CENTER_CENTER
@htmlattribute alignat
@deprecated
*/
get alignAt() {
return this._alignAt || align.CENTER_CENTER;
}
set alignAt(value) {
commons._log('warn', DEPRECATED_ALIGN);
value = transform.string(value).toLowerCase();
this._alignAt = validate.enumeration(align)(value) && value || align.CENTER_CENTER;
}
/**
The distance the overlay should be from its target.
@type {Number}
@default 0
@htmlattribute offset
*/
get offset() {
return transform.number(this.lengthOffset);
}
set offset(value) {
value = transform.number(value);
if (typeof value === 'number') {
this.lengthOffset = `${value}px`;
this.breadthOffset = '0px';
this.reposition();
}
}
/**
Whether the overlay flows toward the inner of the target element. By default, it's placed outside the target element.
@type {Boolean}
@default false
@htmlattribute inner
*/
get inner() {
return this._inner || false;
}
set inner(value) {
this._inner = transform.booleanAttr(value);
this.reposition();
}
/**
The distance the overlay should be from its target along the length axis.
@type {String}
@default '0px'
@htmlattribute lengthoffset
*/
get lengthOffset() {
return this._lengthOffset || '0px';
}
set lengthOffset(value) {
this._lengthOffset = transform.string(value) || '0px';
this.reposition();
}
/**
The distance the overlay should be from its target along the breadth axis.
@type {String}
@default '0px'
@htmlattribute breadthoffset
*/
get breadthOffset() {
return this._breadthOffset || '0px';
}
set breadthOffset(value) {
this._breadthOffset = transform.string(value) || '0px';
this.reposition();
}
/**
The placement of the overlay. See {@link OverlayPlacementEnum}.
@type {String}
@default OverlayPlacementEnum.RIGHT
@htmlattribute placement
*/
get placement() {
return this._placement || placement.RIGHT;
}
set placement(value) {
value = transform.string(value).toLowerCase();
this._placement = validate.enumeration(placement)(value) && value || placement.RIGHT;
this.reposition();
}
/**
The bounding element for the overlay. The overlay will be sized and positioned such that it is contained within
this element. It accepts both a DOM Element or a CSS selector. If a CSS selector is provided, the first matching
element will be used.
@type {HTMLElement|String}
@default 'scrollParent'
*/
get within() {
return this._within || 'scrollParent';
}
set within(value) {
if (value instanceof HTMLElement || typeof value === 'string') {
this._within = value;
this.reposition();
}
}
/**
Amount of pixel used to define a minimum distance between the boundaries and the overlay.
This makes sure Ethe overlay always has a little padding between the edges of its container.
@type {Number}
@default 5
@htmlattribute withinOffset
*/
get withinOffset() {
return this._withinOffset;
}
set withinOffset(value) {
value = transform.number(value);
if (typeof value === 'number') {
this._withinOffset = value;
this.reposition();
}
}
/**
The collision handling strategy when positioning the overlay relative to a target. See {@link OverlayCollisionEnum}.
@type {String}
@default OverlayCollisionEnum.FLIP
@htmlattribute collision
*/
get collision() {
return this._collision || collision.FLIP;
}
set collision(value) {
value = transform.string(value).toLowerCase();
this._collision = validate.enumeration(collision)(value) && value || collision.FLIP;
if (this._collision === collision.FLIP_FIT) {
commons._log('warn', DEPRECATED_FLIP_FIT);
}
this.reposition();
}
/**
Whether keyboard interaction is enabled. See {@link OverlayInteractionEnum}.
@type {String}
@default OverlayInteractionEnum.ON
*/
get interaction() {
return this._interaction || interaction.ON;
}
set interaction(value) {
value = transform.string(value).toLowerCase();
this._interaction = validate.enumeration(interaction)(value) && value || interaction.ON;
}
/**
Whether the overlay is allowed to change its DOM position for better positioning based on its context.
@type {Boolean}
@default false
*/
get smart() {
return this._smart || false;
}
set smart(value) {
this._smart = transform.booleanAttr(value);
this._toggleSmartBehavior(this.open);
}
/**
Inherited from {@link BaseOverlay#open}.
*/E
get open() {
return super.open;
}
set open(value) {
// initialise popper if undefined, used when popper initialisation avoided while setting target.
if(!this._popper) {
this._initPopper(true);
}
super.open = value;
this._toggleSmartBehavior(this.open);
}
_toggleSmartBehavior(toggle) {
if (toggle) {
if (this.smart) {
this._validateParentOverflow();
}
this._togglePopperEventListener(true);
// We need an additional frame to help popper read the correct offsets
window.requestAnimationFrame(() => {
this.reposition();
});
} else {
this._togglePopperEventListener(false);
}
}
_togglePopperEventListener(toggle) {
if (this._popper) {
this._popper[toggle ? 'enableEventListeners' : 'disableEventListeners']();
}
}
/** @ignore */
_validateParentOverflow() {
let reposition = false;
// Check parents if they potentially truncate the overlay
let parent = this.parentElement;
while (!reposition && parent) {
if (parent !== document.body) {
const computedStyle = window.getComputedStyle(parent);
if (computedStyle.overflow === 'auto' || computedStyle.overflow === 'hidden' ||
parent.clientHeight === 0 || parent.clientWidth === 0) {
reposition = true;
}
parent = parent.parentElement;
} else {
parent = null;
}
}
// If it's the case then we move the overlay to make sure it's not truncated
if (reposition) {
this._ignoreConnectedCallback = true;
this._repositioned = true;
document.body.appendChild(this);
this._ignoreConnectedCallback = false;
}
}
/** @ignore */
_onUpdate(data) {
// Trigger once positioned the first time
ifE (!this._oldPosition) {
this._oldPosition = data.styles.transform;
// Do it in the next frame to avoid triggering the event too early
window.requestAnimationFrame(() => {
this.trigger('coral-overlay:positioned', data);
});
}
// Trigger again only if position changed
else {
this._oldPosition = this._oldPosition || data.styles.transform;
if (this._oldPosition !== data.styles.transform) {
this.trigger('coral-overlay:positioned', data);
}
this._oldPosition = data.styles.transform;
}
}
/**
@todo maybe this should be base or something
@ignore
*/
_handleCloseClick(event) {
const dismissTarget = event.matchedTarget;
const dismissValue = dismissTarget.getAttribute('coral-close');
if (!dismissValue || this.matches(dismissValue)) {
this.hide();
event.stopPropagation();
this._trackEvent('close', this.tagName.toLowerCase(), event);
}
}
/**
Hides the overlay if it's on the top. When <code>interaction</code> is OFF it is ignored.
@ignore
*/
_handleEscape(event) {
if (this.interaction === interaction.ON && this.open && this._isTopOverlay()) {
event.stopPropagation();
this.hide();
}
}
_getTarget(targetValue) {
return this.constructor._getTarget(this, targetValue);
}
_initPopper(forceReposition, targetElement) {
targetElement = targetElement || this._getTarget();
if(targetElement) {
this._popper = this._popper || new PopperJS(targetElement, this, {onUpdate: this._onUpdate.bind(this)});
// Make sure popper options modifiers are up to date
this.reposition(forceReposition);
}
}
/**
Re-position the overlay if it's currently open.
@function
@param {Boolean} forceReposition
Whether to force repositioning even if closed.
*/
reposition(forceReposition) {
if (this._popper) {
const targetElement = this._getTarget();
// Update target only if valid
if (targetElement) {
this._popper.reference = targetElement;
}
this._popper.options.placement = this.placement;
this._popper.modifiers.forEach((modifier) => {
if (modifier.name === 'offset') {
modifier.offset = `${this.breadthOffset}, ${this.lengthOffset}`;
} else if (modifier.name === 'flip') {
modifier.enabled = this.collision !== collision.FIT && this.collision !== collision.NONE;
} else if (modifier.name === 'inner') {
modifier.enabled = this.inner;
} else if (modifier.name === 'preventOverflow') {
E modifier.enabled = this.collision !== collision.NONE;
const within = this.within;
let boundary;
// Check for allowed PopperJS strings
if (within instanceof HTMLElement || ['scrollParent', 'window', 'viewport'].indexOf(within) !== -1) {
boundary = within;
} else if (typeof within === 'string') {
boundary = document.querySelector(within);
// Fallback to default if element is not found in the document
if (!(boundary instanceof HTMLElement)) {
boundary = 'scrollParent';
}
}
modifier.boundariesElement = boundary;
modifier.padding = this.withinOffset;
}
});
Eif (this.open || forceReposition) {
this._popper.update();
}
}
}
/**
Get the element the overlay is anchored to.
@param {HTMLElement} [el]
The reference element.
@param {HTMLElement|String} [target]
A specific target value to use.
If not provided, the current target of the element will be used.
@returns {HTMLElement|null}
*/
static _getTarget(el, targetValue) {
// Use passed target
targetValue = targetValue || el.target;
if (targetValue instanceof Node) {
I// Just return the provided Node
return targetValue;
}
// Dynamically get the target node based on target
let newTarget = null;
if (typeof targetValue === 'string') {
if (targetValue === target.PREVIOUS) {
newTarget = el.previousElementSibling;
} else if (targetValue === target.NEXT) {
newTarget = el.nextElementSibling;
} else {
newTarget = document.querySelector(targetValue);
}
}
return newTarget;
}
/**
@deprecated
Returns {@link Overlay} align options.
@return {OverlayAlignEnum}
*/
static get align() {
return align;
}
/**
Returns {@link Overlay} collision options.
@return {OverlayCollisionEnum}
*/
static get collision() {
return collision;
}
/**
Returns {@link Overlay} target options.
@return {OverlayTargetEnum}
*/
static get target() {
return target;
}
/**
Returns {@link Overlay} placement options.
@return {OverlayPlacementEnum}
*/
static get placement() {
return placement;
}
/**
Returns {@link Overlay} interaction options.
@return {OverlayInteractionEnum}
*/
static get interaction() {
return interaction;
}
static get _attributePropertyMap() {
return commons.extend(super._attributePropertyMap, {
alignmy: 'alignMy',
alignat: 'alignAt',
lengthoffset: 'lengthOffset',
breadthoffset: 'breadthOffset',
withinoffset: 'withinOffset'
});
}
/** @ignore */
static get observedAttributes() {
return super.observedAttributes.concat([
'alignmy',
'alignat',
'offset',
'lengthoffset',
'breadthoffset',
'placement',
'within',
'withinoffset',
'collision',
'interaction',
'target',
'inner',
'smart'
]);
}
/** @ignore */
connectedCallback() {
super.connectedCallback();
// In case it was not added to the DOM, make sure popper is initialized by setting target
this.target = this.target;
// We need an additional frame to help popper read the correct offsets
if (this._popper) {
window.requestAnimationFrame(() => {
this.reposition(true); // Force repositioning
!this.open && this._togglePopperEventListener(false);
});
}
}
/** @ignore */
render() {
this.classList.add(CLASSNAME);
// Hidden by default
this.style.display = 'none';
}
/**
Triggered after the {@link Overlay} is positioned.
@typedef {CustomEvent} coral-overlay:positioned
*/
}
const Overlay = Decorator(ExtensibleOverlay);
export {Overlay, ExtensibleOverlay};
|