carbon-components-angular 3.15.2 → 3.15.3
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/dialog/dialog.component.js +5 -29
- package/dialog/dialog.component.js.map +1 -1
- package/dialog/dialog.component.metadata.json +1 -1
- package/docs/documentation/components/Dialog.html +12 -41
- package/docs/documentation/components/Dropdown.html +82 -176
- package/docs/documentation/components/OverflowMenuPane.html +7 -7
- package/docs/documentation/components/Tooltip.html +7 -7
- package/docs/documentation/coverage.html +49 -1
- package/docs/documentation/images/coverage-badge-documentation.svg +1 -1
- package/docs/documentation/js/search/search_index.js +2 -2
- package/docs/documentation/miscellaneous/variables.html +144 -0
- package/docs/storybook/iframe.html +3 -3
- package/docs/storybook/{main.b7f84e1c05f635d7c347.bundle.js → main.d9349fe343a2c719f60b.bundle.js} +84 -54
- package/docs/storybook/main.d9349fe343a2c719f60b.bundle.js.map +1 -0
- package/docs/storybook/{runtime~main.b7f84e1c05f635d7c347.bundle.js → runtime~main.d9349fe343a2c719f60b.bundle.js} +1 -1
- package/docs/storybook/{runtime~main.b7f84e1c05f635d7c347.bundle.js.map → runtime~main.d9349fe343a2c719f60b.bundle.js.map} +1 -1
- package/docs/storybook/{vendors~main.b7f84e1c05f635d7c347.bundle.js → vendors~main.d9349fe343a2c719f60b.bundle.js} +1 -1
- package/docs/storybook/{vendors~main.b7f84e1c05f635d7c347.bundle.js.map → vendors~main.d9349fe343a2c719f60b.bundle.js.map} +1 -1
- package/dropdown/dropdown.component.d.ts +0 -4
- package/dropdown/dropdown.component.js +14 -25
- package/dropdown/dropdown.component.js.map +1 -1
- package/dropdown/dropdown.component.metadata.json +1 -1
- package/dropdown/dropdown.component.ngsummary.json +1 -1
- package/modal/modal.component.d.ts +1 -1
- package/package.json +1 -1
- package/utils/scroll.d.ts +38 -0
- package/utils/scroll.js +66 -0
- package/utils/scroll.js.map +1 -0
- package/utils/scroll.metadata.json +1 -0
- package/utils/scroll.ngsummary.json +1 -0
- package/breadcrumb/breadcrumb.component.spec.d.ts +0 -21
- package/bundle/carbon-angular.umd.js +0 -216
- package/bundle/carbon-angular.umd.js.map +0 -1
- package/checkbox/checkbox.component.spec.d.ts +0 -21
- package/code-snippet/code-snippet.component.spec.d.ts +0 -21
- package/combobox/combobox.component.spec.d.ts +0 -21
- package/common/utils.spec.d.ts +0 -21
- package/dialog/tooltip/tooltip.directive.spec.d.ts +0 -21
- package/docs/storybook/main.b7f84e1c05f635d7c347.bundle.js.map +0 -1
- package/dropdown/dropdown.component.spec.d.ts +0 -21
- package/dropdown/list/dropdown-list.component.spec.d.ts +0 -21
- package/grid/grid.directive.spec.d.ts +0 -21
- package/i18n/i18n.spec.d.ts +0 -21
- package/inline-loading/inline-loading.spec.d.ts +0 -21
- package/input/label.component.spec.d.ts +0 -21
- package/link/link.spec.d.ts +0 -21
- package/loading/loading.component.spec.d.ts +0 -21
- package/modal/modal.component.spec.d.ts +0 -21
- package/notification/notification.component.spec.d.ts +0 -21
- package/number-input/number.component.spec.d.ts +0 -21
- package/radio/radio.component.spec.d.ts +0 -21
- package/sample/sample-base.class.d.ts +0 -35
- package/sample/sample.component.d.ts +0 -48
- package/sample/sample.component.spec.d.ts +0 -21
- package/sample/sample.interface.d.ts +0 -29
- package/sample/sample.module.d.ts +0 -26
- package/sample/subcomponent/sample-sub.component.d.ts +0 -38
- package/sample/subcomponent/sample-sub.component.spec.d.ts +0 -21
- package/search/search.component.spec.d.ts +0 -21
- package/table/table-model.class.spec.d.ts +0 -21
- package/table/table.component.spec.d.ts +0 -21
- package/tabs/tab-headers.component.spec.d.ts +0 -21
- package/tabs/tabs.component.spec.d.ts +0 -22
- package/tiles/clickable-tile.component.spec.d.ts +0 -22
- package/tiles/tile.component.spec.d.ts +0 -22
- package/toggle/toggle.component.spec.d.ts +0 -21
- package/ui-shell/header/header.component.spec.d.ts +0 -21
- package/utils/a11y.d.ts +0 -26
- package/utils/position.d.ts +0 -21
- package/utils/utils.d.ts +0 -21
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
import { Component, Input, Output, EventEmitter, ElementRef, ViewChild, HostListener } from "@angular/core";
|
|
22
|
-
import { Subscription, fromEvent
|
|
22
|
+
import { Subscription, fromEvent } from "rxjs";
|
|
23
23
|
import { throttleTime } from "rxjs/operators";
|
|
24
24
|
// the AbsolutePosition is required to import the declaration correctly
|
|
25
25
|
import Position, { position } from "@carbon/utils-position";
|
|
26
26
|
import { cycleTabs, getFocusElementList } from "./../common/tab.service";
|
|
27
|
+
import { scrollableParentsObservable, isVisibleInContainer } from "./../utils/scroll";
|
|
27
28
|
/**
|
|
28
29
|
* Implements a `Dialog` that can be positioned anywhere on the page.
|
|
29
30
|
* Used to implement a popover or tooltip.
|
|
@@ -93,7 +94,7 @@ var Dialog = /** @class */ (function () {
|
|
|
93
94
|
Dialog.prototype.ngAfterViewInit = function () {
|
|
94
95
|
var _this = this;
|
|
95
96
|
var dialogElement = this.dialog.nativeElement;
|
|
96
|
-
// split the wrapper class list and apply separately to avoid IE
|
|
97
|
+
// split the wrapper class list and apply separately to avoid IE
|
|
97
98
|
// 1. throwing an error due to assigning a readonly property (classList)
|
|
98
99
|
// 2. throwing a SyntaxError due to passing an empty string to `add`
|
|
99
100
|
if (this.dialogConfig.wrapperClass) {
|
|
@@ -106,38 +107,13 @@ var Dialog = /** @class */ (function () {
|
|
|
106
107
|
if (getFocusElementList(this.dialog.nativeElement).length > 0) {
|
|
107
108
|
dialogElement.focus();
|
|
108
109
|
}
|
|
109
|
-
var
|
|
110
|
-
var node = parentEl;
|
|
111
|
-
var observables = [];
|
|
112
|
-
// if the element has an overflow set as part of
|
|
113
|
-
// its computed style it can scroll
|
|
114
|
-
var isScrollableElement = function (element) {
|
|
115
|
-
var computedStyle = getComputedStyle(element);
|
|
116
|
-
return (computedStyle.overflow === "auto" ||
|
|
117
|
-
computedStyle.overflow === "scroll" ||
|
|
118
|
-
computedStyle["overflow-y"] === "auto" ||
|
|
119
|
-
computedStyle["overflow-y"] === "scroll" ||
|
|
120
|
-
computedStyle["overflow-x"] === "auto" ||
|
|
121
|
-
computedStyle["overflow-x"] === "scroll");
|
|
122
|
-
};
|
|
123
|
-
var isVisibleInContainer = function (element, container) {
|
|
124
|
-
var elementRect = element.getBoundingClientRect();
|
|
125
|
-
var containerRect = container.getBoundingClientRect();
|
|
126
|
-
return elementRect.bottom <= containerRect.bottom && elementRect.top >= containerRect.top;
|
|
127
|
-
};
|
|
110
|
+
var parentElement = this.dialogConfig.parentRef.nativeElement;
|
|
128
111
|
var placeDialogInContainer = function () {
|
|
129
112
|
// only do the work to find the scroll containers if we're appended to body
|
|
130
113
|
// or skip this work if we're inline
|
|
131
114
|
if (!_this.dialogConfig.appendInline) {
|
|
132
|
-
// walk the parents and subscribe to all the scroll events we can
|
|
133
|
-
while (node.parentElement && node !== document.body) {
|
|
134
|
-
if (isScrollableElement(node)) {
|
|
135
|
-
observables.push(fromEvent(node, "scroll"));
|
|
136
|
-
}
|
|
137
|
-
node = node.parentElement;
|
|
138
|
-
}
|
|
139
115
|
// subscribe to the observable, and update the position and visibility
|
|
140
|
-
var scrollObservable =
|
|
116
|
+
var scrollObservable = scrollableParentsObservable(parentElement);
|
|
141
117
|
_this.scrollSubscription = scrollObservable.subscribe(function (event) {
|
|
142
118
|
_this.placeDialog();
|
|
143
119
|
if (!isVisibleInContainer(_this.dialogConfig.parentRef.nativeElement, event.target)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.component.js","sourceRoot":"","sources":["../src/dialog/dialog.component.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,KAAK,EACL,MAAM,EACN,YAAY,EACZ,UAAU,EACV,SAAS,EAIT,YAAY,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAEN,YAAY,EACZ,SAAS,EACT,KAAK,EACL,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,gBAA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MAAM,CAAC,EAAG;YACvE,IAAI,CAAC,OAAO,EAAE,CAAC;SACf;IACF,CAAC;IAED;;OAEG;IACI,wBAAO,GAAd;QACC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,4BAAW,GAAX;QACC,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,CAAC;QACtC,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,CAAC;IACvC,CAAC;IAjPD;;OAEG;IACc,uBAAgB,GAAoB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;;gBARzG,SAAS,SAAC;oBACV,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE,EAAE;iBACZ;;;;gBAjCA,UAAU;;;wBA0CT,MAAM;+BAKN,KAAK;yBAIL,SAAS,SAAC,QAAQ;8BAuLlB,YAAY,SAAC,SAAS,EAAE,CAAC,QAAQ,CAAC;6BAqBlC,YAAY,SAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC;;IAsB3C,aAAC;CAAA,AAvPD,IAuPC;SAnPY,MAAM","sourcesContent":["import {\n\tComponent,\n\tInput,\n\tOutput,\n\tEventEmitter,\n\tElementRef,\n\tViewChild,\n\tOnInit,\n\tAfterViewInit,\n\tOnDestroy,\n\tHostListener\n} from \"@angular/core\";\nimport {\n\tObservable,\n\tSubscription,\n\tfromEvent,\n\tmerge\n} from \"rxjs\";\nimport { throttleTime } from \"rxjs/operators\";\n// the AbsolutePosition is required to import the declaration correctly\nimport Position, { position, AbsolutePosition, Positions } from \"@carbon/utils-position\";\nimport { cycleTabs, getFocusElementList } from \"./../common/tab.service\";\nimport { DialogConfig } from \"./dialog-config.interface\";\n\n\n/**\n * Implements a `Dialog` that can be positioned anywhere on the page.\n * Used to implement a popover or tooltip.\n *\n * @export\n * @class Dialog\n * @implements {OnInit}\n * @implements {AfterViewInit}\n * @implements {OnDestroy}\n */\n@Component({\n\tselector: \"ibm-dialog\",\n\ttemplate: \"\"\n})\nexport class Dialog implements OnInit, AfterViewInit, OnDestroy {\n\t/**\n\t * One static event observable to handle window resizing.\n\t */\n\tprotected static resizeObservable: Observable<any> = fromEvent(window, \"resize\").pipe(throttleTime(100));\n\t/**\n\t * Emits event that handles the closing of a `Dialog` object.\n\t */\n\t@Output() close: EventEmitter<any> = new EventEmitter();\n\t/**\n\t * Receives `DialogConfig` interface object with properties of `Dialog`\n\t * explicitly defined.\n\t */\n\t@Input() dialogConfig: DialogConfig;\n\t/**\n\t * Maintains a reference to the view DOM element of the `Dialog`.\n\t */\n\t@ViewChild(\"dialog\") dialog: ElementRef;\n\n\t/**\n\t * Stores the data received from `dialogConfig`.\n\t */\n\tpublic data = {};\n\n\t/**\n\t * The placement of the `Dialog` is received from the `Position` service.\n\t */\n\tpublic placement: string;\n\n\t/**\n\t * `Subscription` used to update placement in the event of a window resize.\n\t */\n\tprotected resizeSubscription: Subscription;\n\t/**\n\t * Subscription to all the scrollable parents `scroll` event\n\t */\n\t// add a new subscription temporarily so that contexts (such as tests)\n\t// that don't run ngAfterViewInit have something to unsubscribe in ngOnDestroy\n\tprotected scrollSubscription: Subscription = new Subscription();\n\t/**\n\t * Handles offsetting the `Dialog` item based on the defined position\n\t * to not obscure the content beneath.\n\t */\n\tprotected addGap = {\n\t\t\"left\": pos => position.addOffset(pos, 0, -this.dialogConfig.gap),\n\t\t\"right\": pos => position.addOffset(pos, 0, this.dialogConfig.gap),\n\t\t\"top\": pos => position.addOffset(pos, -this.dialogConfig.gap),\n\t\t\"bottom\": pos => position.addOffset(pos, this.dialogConfig.gap),\n\t\t\"left-bottom\": pos => position.addOffset(pos, 0, -this.dialogConfig.gap),\n\t\t\"right-bottom\": pos => position.addOffset(pos, 0, this.dialogConfig.gap)\n\t};\n\n\t/**\n\t * Extra placements. Child classes can add to this for use in `placeDialog`.\n\t */\n\tprotected placements: Positions = {};\n\n\t/**\n\t * Creates an instance of `Dialog`.\n\t * @param {ElementRef} elementRef\n\t */\n\tconstructor(protected elementRef: ElementRef) {\t}\n\n\t/**\n\t * Initialize the `Dialog`, set the placement and gap, and add a `Subscription` to resize events.\n\t */\n\tngOnInit() {\n\t\tthis.placement = this.dialogConfig.placement.split(\",\")[0];\n\t\tthis.data = this.dialogConfig.data;\n\n\t\tthis.resizeSubscription = Dialog.resizeObservable.subscribe(() => {\n\t\t\tthis.placeDialog();\n\t\t});\n\n\t\t// run any additional initialization code that consuming classes may have\n\t\tthis.onDialogInit();\n\t}\n\n\t/**\n\t * After the DOM is ready, focus is set and dialog is placed\n\t * in respect to the parent element.\n\t */\n\tngAfterViewInit() {\n\t\tconst dialogElement = this.dialog.nativeElement;\n\t\t// split the wrapper class list and apply separately to avoid IE from\n\t\t// 1. throwing an error due to assigning a readonly property (classList)\n\t\t// 2. throwing a SyntaxError due to passing an empty string to `add`\n\t\tif (this.dialogConfig.wrapperClass) {\n\t\t\tfor (const extraClass of this.dialogConfig.wrapperClass.split(\" \")) {\n\t\t\t\tdialogElement.classList.add(extraClass);\n\t\t\t}\n\t\t}\n\t\tthis.placeDialog();\n\t\tif (getFocusElementList(this.dialog.nativeElement).length > 0) {\n\t\t\tdialogElement.focus();\n\t\t}\n\t\tconst parentEl: HTMLElement = this.dialogConfig.parentRef.nativeElement;\n\t\tlet node = parentEl;\n\t\tlet observables = [];\n\n\t\t// if the element has an overflow set as part of\n\t\t// its computed style it can scroll\n\t\tconst isScrollableElement = (element: HTMLElement) => {\n\t\t\tconst computedStyle = getComputedStyle(element);\n\t\t\treturn (\n\t\t\t\tcomputedStyle.overflow === \"auto\" ||\n\t\t\t\tcomputedStyle.overflow === \"scroll\" ||\n\t\t\t\tcomputedStyle[\"overflow-y\"] === \"auto\" ||\n\t\t\t\tcomputedStyle[\"overflow-y\"] === \"scroll\" ||\n\t\t\t\tcomputedStyle[\"overflow-x\"] === \"auto\" ||\n\t\t\t\tcomputedStyle[\"overflow-x\"] === \"scroll\"\n\t\t\t);\n\t\t};\n\n\t\tconst isVisibleInContainer = (element, container) => {\n\t\t\tconst elementRect = element.getBoundingClientRect();\n\t\t\tconst containerRect = container.getBoundingClientRect();\n\t\t\treturn elementRect.bottom <= containerRect.bottom && elementRect.top >= containerRect.top;\n\t\t};\n\n\t\tconst placeDialogInContainer = () => {\n\t\t\t// only do the work to find the scroll containers if we're appended to body\n\t\t\t// or skip this work if we're inline\n\t\t\tif (!this.dialogConfig.appendInline) {\n\t\t\t\t// walk the parents and subscribe to all the scroll events we can\n\t\t\t\twhile (node.parentElement && node !== document.body) {\n\t\t\t\t\tif (isScrollableElement(node)) {\n\t\t\t\t\t\tobservables.push(fromEvent(node, \"scroll\"));\n\t\t\t\t\t}\n\t\t\t\t\tnode = node.parentElement;\n\t\t\t\t}\n\t\t\t\t// subscribe to the observable, and update the position and visibility\n\t\t\t\tconst scrollObservable = merge(...observables);\n\t\t\t\tthis.scrollSubscription = scrollObservable.subscribe((event: any) => {\n\t\t\t\t\tthis.placeDialog();\n\t\t\t\t\tif (!isVisibleInContainer(this.dialogConfig.parentRef.nativeElement, event.target)) {\n\t\t\t\t\t\tthis.doClose();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\t\t// settimeout to let the DOM settle before attempting to place the dialog\n\t\t// and before notifying components that the DOM is ready\n\t\tsetTimeout(() => {\n\t\t\tplaceDialogInContainer();\n\t\t\tthis.afterDialogViewInit();\n\t\t});\n\t}\n\n\t/**\n\t * Empty method to be overridden by consuming classes to run any additional initialization code.\n\t */\n\tonDialogInit() {}\n\n\t/**\n\t * Empty method to be overridden by consuming classes to run any additional initialization code after the view is available.\n\t * NOTE: this does _not_ guarantee the dialog will be positioned, simply that it will exist in the DOM\n\t */\n\tafterDialogViewInit() {}\n\n\t/**\n\t * Uses the position service to position the `Dialog` in screen space\n\t */\n\tplaceDialog(): void {\n\t\tconst positionService = new Position(this.placements);\n\t\t// helper to find the position based on the current/given environment\n\t\tconst findPosition = (reference, target, placement) => {\n\t\t\tlet pos;\n\t\t\tif (this.dialogConfig.appendInline) {\n\t\t\t\tpos = this.addGap[placement](positionService.findRelative(reference, target, placement));\n\t\t\t} else {\n\t\t\t\tpos = this.addGap[placement](positionService.findAbsolute(reference, target, placement));\n\t\t\t}\n\t\t\treturn pos;\n\t\t};\n\n\t\tlet parentEl = this.dialogConfig.parentRef.nativeElement;\n\t\tlet el = this.dialog.nativeElement;\n\t\tlet dialogPlacement = this.placement;\n\n\t\t// split always returns an array, so we can just use the auto position logic\n\t\t// for single positions too\n\t\tconst placements = this.dialogConfig.placement.split(\",\");\n\n\t\t// find the best placement\n\t\tdialogPlacement = positionService.findBestPlacement(parentEl, el, placements);\n\n\t\t// calculate the final position\n\t\tconst pos = findPosition(parentEl, el, dialogPlacement);\n\n\t\t// update the element\n\t\tpositionService.setElement(el, pos);\n\t\tsetTimeout(() => { this.placement = dialogPlacement; });\n\t}\n\n\t/**\n\t * Sets up a KeyboardEvent to close `Dialog` with Escape key.\n\t * @param {KeyboardEvent} event\n\t */\n\t@HostListener(\"keydown\", [\"$event\"])\n\tescapeClose(event: KeyboardEvent) {\n\t\tswitch (event.key) {\n\t\t\tcase \"Esc\": // IE specific value\n\t\t\tcase \"Escape\": {\n\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t\tthis.doClose();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"Tab\": {\n\t\t\t\tcycleTabs(event, this.elementRef.nativeElement);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets up a event Listener to close `Dialog` if click event occurs outside\n\t * `Dialog` object.\n\t * @param {any} event\n\t */\n\t@HostListener(\"document:click\", [\"$event\"])\n\tclickClose(event) {\n\t\tif (!this.elementRef.nativeElement.contains(event.target)\n\t\t\t&& !this.dialogConfig.parentRef.nativeElement.contains(event.target) ) {\n\t\t\tthis.doClose();\n\t\t}\n\t}\n\n\t/**\n\t * Closes `Dialog` object by emitting the close event upwards to parents.\n\t */\n\tpublic doClose() {\n\t\tthis.close.emit();\n\t}\n\n\t/**\n\t * At destruction of component, `Dialog` unsubscribes from handling window resizing changes.\n\t */\n\tngOnDestroy() {\n\t\tthis.resizeSubscription.unsubscribe();\n\t\tthis.scrollSubscription.unsubscribe();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialog.component.js","sourceRoot":"","sources":["../src/dialog/dialog.component.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,KAAK,EACL,MAAM,EACN,YAAY,EACZ,UAAU,EACV,SAAS,EAIT,YAAY,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAEN,YAAY,EACZ,SAAS,EAET,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAO,MAAM,gBAAgB,CAAC;AACnD,uEAAuE;AACvE,OAAO,QAAQ,EAAE,EAAE,QAAQ,EAA+B,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEtF;;;;;;;;;GASG;AACH;IA6DC;;;OAGG;IACH,gBAAsB,UAAsB;QAA5C,iBAAiD;QAA3B,eAAU,GAAV,UAAU,CAAY;QAxD5C;;WAEG;QACO,UAAK,GAAsB,IAAI,YAAY,EAAE,CAAC;QAWxD;;WAEG;QACI,SAAI,GAAG,EAAE,CAAC;QAWjB;;WAEG;QACH,sEAAsE;QACtE,8EAA8E;QACpE,uBAAkB,GAAiB,IAAI,YAAY,EAAE,CAAC;QAChE;;;WAGG;QACO,WAAM,GAAG;YAClB,MAAM,EAAE,UAAA,GAAG,IAAI,OAAA,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,KAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAlD,CAAkD;YACjE,OAAO,EAAE,UAAA,GAAG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EAAE;iBACZ;;;;gBAjCA,UAAU;;;wBA0CT,MAAM;+BAKN,KAAK;yBAIL,SAAS,SAAC,QAAQ;8BA0JlB,YAAY,SAAC,SAAS,EAAE,CAAC,QAAQ,CAAC;6BAqBlC,YAAY,SAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC;;IAsB3C,aAAC;CAAA,AA1ND,IA0NC;SAtNY,MAAM","sourcesContent":["import {\n\tComponent,\n\tInput,\n\tOutput,\n\tEventEmitter,\n\tElementRef,\n\tViewChild,\n\tOnInit,\n\tAfterViewInit,\n\tOnDestroy,\n\tHostListener\n} from \"@angular/core\";\nimport {\n\tObservable,\n\tSubscription,\n\tfromEvent,\n\tmerge\n} from \"rxjs\";\nimport { throttleTime, map } from \"rxjs/operators\";\n// the AbsolutePosition is required to import the declaration correctly\nimport Position, { position, AbsolutePosition, Positions } from \"@carbon/utils-position\";\nimport { cycleTabs, getFocusElementList } from \"./../common/tab.service\";\nimport { DialogConfig } from \"./dialog-config.interface\";\nimport { scrollableParentsObservable, isVisibleInContainer } from \"./../utils/scroll\";\n\n/**\n * Implements a `Dialog` that can be positioned anywhere on the page.\n * Used to implement a popover or tooltip.\n *\n * @export\n * @class Dialog\n * @implements {OnInit}\n * @implements {AfterViewInit}\n * @implements {OnDestroy}\n */\n@Component({\n\tselector: \"ibm-dialog\",\n\ttemplate: \"\"\n})\nexport class Dialog implements OnInit, AfterViewInit, OnDestroy {\n\t/**\n\t * One static event observable to handle window resizing.\n\t */\n\tprotected static resizeObservable: Observable<any> = fromEvent(window, \"resize\").pipe(throttleTime(100));\n\t/**\n\t * Emits event that handles the closing of a `Dialog` object.\n\t */\n\t@Output() close: EventEmitter<any> = new EventEmitter();\n\t/**\n\t * Receives `DialogConfig` interface object with properties of `Dialog`\n\t * explicitly defined.\n\t */\n\t@Input() dialogConfig: DialogConfig;\n\t/**\n\t * Maintains a reference to the view DOM element of the `Dialog`.\n\t */\n\t@ViewChild(\"dialog\") dialog: ElementRef;\n\n\t/**\n\t * Stores the data received from `dialogConfig`.\n\t */\n\tpublic data = {};\n\n\t/**\n\t * The placement of the `Dialog` is received from the `Position` service.\n\t */\n\tpublic placement: string;\n\n\t/**\n\t * `Subscription` used to update placement in the event of a window resize.\n\t */\n\tprotected resizeSubscription: Subscription;\n\t/**\n\t * Subscription to all the scrollable parents `scroll` event\n\t */\n\t// add a new subscription temporarily so that contexts (such as tests)\n\t// that don't run ngAfterViewInit have something to unsubscribe in ngOnDestroy\n\tprotected scrollSubscription: Subscription = new Subscription();\n\t/**\n\t * Handles offsetting the `Dialog` item based on the defined position\n\t * to not obscure the content beneath.\n\t */\n\tprotected addGap = {\n\t\t\"left\": pos => position.addOffset(pos, 0, -this.dialogConfig.gap),\n\t\t\"right\": pos => position.addOffset(pos, 0, this.dialogConfig.gap),\n\t\t\"top\": pos => position.addOffset(pos, -this.dialogConfig.gap),\n\t\t\"bottom\": pos => position.addOffset(pos, this.dialogConfig.gap),\n\t\t\"left-bottom\": pos => position.addOffset(pos, 0, -this.dialogConfig.gap),\n\t\t\"right-bottom\": pos => position.addOffset(pos, 0, this.dialogConfig.gap)\n\t};\n\n\t/**\n\t * Extra placements. Child classes can add to this for use in `placeDialog`.\n\t */\n\tprotected placements: Positions = {};\n\n\t/**\n\t * Creates an instance of `Dialog`.\n\t * @param {ElementRef} elementRef\n\t */\n\tconstructor(protected elementRef: ElementRef) {\t}\n\n\t/**\n\t * Initialize the `Dialog`, set the placement and gap, and add a `Subscription` to resize events.\n\t */\n\tngOnInit() {\n\t\tthis.placement = this.dialogConfig.placement.split(\",\")[0];\n\t\tthis.data = this.dialogConfig.data;\n\n\t\tthis.resizeSubscription = Dialog.resizeObservable.subscribe(() => {\n\t\t\tthis.placeDialog();\n\t\t});\n\n\t\t// run any additional initialization code that consuming classes may have\n\t\tthis.onDialogInit();\n\t}\n\n\t/**\n\t * After the DOM is ready, focus is set and dialog is placed\n\t * in respect to the parent element.\n\t */\n\tngAfterViewInit() {\n\t\tconst dialogElement = this.dialog.nativeElement;\n\t\t// split the wrapper class list and apply separately to avoid IE\n\t\t// 1. throwing an error due to assigning a readonly property (classList)\n\t\t// 2. throwing a SyntaxError due to passing an empty string to `add`\n\t\tif (this.dialogConfig.wrapperClass) {\n\t\t\tfor (const extraClass of this.dialogConfig.wrapperClass.split(\" \")) {\n\t\t\t\tdialogElement.classList.add(extraClass);\n\t\t\t}\n\t\t}\n\t\tthis.placeDialog();\n\t\tif (getFocusElementList(this.dialog.nativeElement).length > 0) {\n\t\t\tdialogElement.focus();\n\t\t}\n\t\tconst parentElement = this.dialogConfig.parentRef.nativeElement;\n\n\t\tconst placeDialogInContainer = () => {\n\t\t\t// only do the work to find the scroll containers if we're appended to body\n\t\t\t// or skip this work if we're inline\n\t\t\tif (!this.dialogConfig.appendInline) {\n\t\t\t\t// subscribe to the observable, and update the position and visibility\n\t\t\t\tconst scrollObservable = scrollableParentsObservable(parentElement);\n\t\t\t\tthis.scrollSubscription = scrollObservable.subscribe((event: any) => {\n\t\t\t\t\tthis.placeDialog();\n\t\t\t\t\tif (!isVisibleInContainer(this.dialogConfig.parentRef.nativeElement, event.target)) {\n\t\t\t\t\t\tthis.doClose();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\t\t// settimeout to let the DOM settle before attempting to place the dialog\n\t\t// and before notifying components that the DOM is ready\n\t\tsetTimeout(() => {\n\t\t\tplaceDialogInContainer();\n\t\t\tthis.afterDialogViewInit();\n\t\t});\n\t}\n\n\t/**\n\t * Empty method to be overridden by consuming classes to run any additional initialization code.\n\t */\n\tonDialogInit() {}\n\n\t/**\n\t * Empty method to be overridden by consuming classes to run any additional initialization code after the view is available.\n\t * NOTE: this does _not_ guarantee the dialog will be positioned, simply that it will exist in the DOM\n\t */\n\tafterDialogViewInit() {}\n\n\t/**\n\t * Uses the position service to position the `Dialog` in screen space\n\t */\n\tplaceDialog(): void {\n\t\tconst positionService = new Position(this.placements);\n\t\t// helper to find the position based on the current/given environment\n\t\tconst findPosition = (reference, target, placement) => {\n\t\t\tlet pos;\n\t\t\tif (this.dialogConfig.appendInline) {\n\t\t\t\tpos = this.addGap[placement](positionService.findRelative(reference, target, placement));\n\t\t\t} else {\n\t\t\t\tpos = this.addGap[placement](positionService.findAbsolute(reference, target, placement));\n\t\t\t}\n\t\t\treturn pos;\n\t\t};\n\n\t\tlet parentEl = this.dialogConfig.parentRef.nativeElement;\n\t\tlet el = this.dialog.nativeElement;\n\t\tlet dialogPlacement = this.placement;\n\n\t\t// split always returns an array, so we can just use the auto position logic\n\t\t// for single positions too\n\t\tconst placements = this.dialogConfig.placement.split(\",\");\n\n\t\t// find the best placement\n\t\tdialogPlacement = positionService.findBestPlacement(parentEl, el, placements);\n\n\t\t// calculate the final position\n\t\tconst pos = findPosition(parentEl, el, dialogPlacement);\n\n\t\t// update the element\n\t\tpositionService.setElement(el, pos);\n\t\tsetTimeout(() => { this.placement = dialogPlacement; });\n\t}\n\n\t/**\n\t * Sets up a KeyboardEvent to close `Dialog` with Escape key.\n\t * @param {KeyboardEvent} event\n\t */\n\t@HostListener(\"keydown\", [\"$event\"])\n\tescapeClose(event: KeyboardEvent) {\n\t\tswitch (event.key) {\n\t\t\tcase \"Esc\": // IE specific value\n\t\t\tcase \"Escape\": {\n\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t\tthis.doClose();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"Tab\": {\n\t\t\t\tcycleTabs(event, this.elementRef.nativeElement);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets up a event Listener to close `Dialog` if click event occurs outside\n\t * `Dialog` object.\n\t * @param {any} event\n\t */\n\t@HostListener(\"document:click\", [\"$event\"])\n\tclickClose(event) {\n\t\tif (!this.elementRef.nativeElement.contains(event.target)\n\t\t\t&& !this.dialogConfig.parentRef.nativeElement.contains(event.target) ) {\n\t\t\tthis.doClose();\n\t\t}\n\t}\n\n\t/**\n\t * Closes `Dialog` object by emitting the close event upwards to parents.\n\t */\n\tpublic doClose() {\n\t\tthis.close.emit();\n\t}\n\n\t/**\n\t * At destruction of component, `Dialog` unsubscribes from handling window resizing changes.\n\t */\n\tngOnDestroy() {\n\t\tthis.resizeSubscription.unsubscribe();\n\t\tthis.scrollSubscription.unsubscribe();\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"__symbolic":"module","version":4,"metadata":{"Dialog":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":35,"character":1},"arguments":[{"selector":"ibm-dialog","template":""}]}],"members":{"close":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":47,"character":2}}]}],"dialogConfig":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":52,"character":2}}]}],"dialog":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild","line":56,"character":2},"arguments":["dialog"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef","line":100,"character":35}]}],"ngOnInit":[{"__symbolic":"method"}],"ngAfterViewInit":[{"__symbolic":"method"}],"onDialogInit":[{"__symbolic":"method"}],"afterDialogViewInit":[{"__symbolic":"method"}],"placeDialog":[{"__symbolic":"method"}],"escapeClose":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":
|
|
1
|
+
[{"__symbolic":"module","version":4,"metadata":{"Dialog":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":35,"character":1},"arguments":[{"selector":"ibm-dialog","template":""}]}],"members":{"close":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":47,"character":2}}]}],"dialogConfig":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":52,"character":2}}]}],"dialog":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild","line":56,"character":2},"arguments":["dialog"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef","line":100,"character":35}]}],"ngOnInit":[{"__symbolic":"method"}],"ngAfterViewInit":[{"__symbolic":"method"}],"onDialogInit":[{"__symbolic":"method"}],"afterDialogViewInit":[{"__symbolic":"method"}],"placeDialog":[{"__symbolic":"method"}],"escapeClose":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":210,"character":2},"arguments":["keydown",["$event"]]}]}],"clickClose":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"HostListener","line":231,"character":2},"arguments":["document:click",["$event"]]}]}],"doClose":[{"__symbolic":"method"}],"ngOnDestroy":[{"__symbolic":"method"}]},"statics":{"resizeObservable":{"__symbolic":"call","expression":{"__symbolic":"select","expression":{"__symbolic":"call","expression":{"__symbolic":"reference","module":"rxjs","name":"fromEvent","line":43,"character":54},"arguments":[{"__symbolic":"reference","name":"window"},"resize"]},"member":"pipe"},"arguments":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"rxjs/operators","name":"throttleTime","line":43,"character":87},"arguments":[100]}]}}}}}]
|
|
@@ -384,7 +384,7 @@ explicitly defined.</p>
|
|
|
384
384
|
|
|
385
385
|
<tr>
|
|
386
386
|
<td class="col-md-4">
|
|
387
|
-
<div class="io-line">Defined in <a href="" data-line="
|
|
387
|
+
<div class="io-line">Defined in <a href="" data-line="233" class="link-to-prism">src/dialog/dialog.component.ts:233</a></div>
|
|
388
388
|
</td>
|
|
389
389
|
</tr>
|
|
390
390
|
|
|
@@ -426,7 +426,7 @@ explicitly defined.</p>
|
|
|
426
426
|
|
|
427
427
|
<tr>
|
|
428
428
|
<td class="col-md-4">
|
|
429
|
-
<div class="io-line">Defined in <a href="" data-line="
|
|
429
|
+
<div class="io-line">Defined in <a href="" data-line="212" class="link-to-prism">src/dialog/dialog.component.ts:212</a></div>
|
|
430
430
|
</td>
|
|
431
431
|
</tr>
|
|
432
432
|
|
|
@@ -469,7 +469,7 @@ explicitly defined.</p>
|
|
|
469
469
|
|
|
470
470
|
<tr>
|
|
471
471
|
<td class="col-md-4">
|
|
472
|
-
<div class="io-line">Defined in <a href="" data-line="
|
|
472
|
+
<div class="io-line">Defined in <a href="" data-line="170" class="link-to-prism">src/dialog/dialog.component.ts:170</a></div>
|
|
473
473
|
</td>
|
|
474
474
|
</tr>
|
|
475
475
|
|
|
@@ -512,7 +512,7 @@ NOTE: this does <em>not</em> guarantee the dialog will be positioned, simply tha
|
|
|
512
512
|
|
|
513
513
|
<tr>
|
|
514
514
|
<td class="col-md-4">
|
|
515
|
-
<div class="io-line">Defined in <a href="" data-line="
|
|
515
|
+
<div class="io-line">Defined in <a href="" data-line="243" class="link-to-prism">src/dialog/dialog.component.ts:243</a></div>
|
|
516
516
|
</td>
|
|
517
517
|
</tr>
|
|
518
518
|
|
|
@@ -593,7 +593,7 @@ in respect to the parent element.</p>
|
|
|
593
593
|
|
|
594
594
|
<tr>
|
|
595
595
|
<td class="col-md-4">
|
|
596
|
-
<div class="io-line">Defined in <a href="" data-line="
|
|
596
|
+
<div class="io-line">Defined in <a href="" data-line="250" class="link-to-prism">src/dialog/dialog.component.ts:250</a></div>
|
|
597
597
|
</td>
|
|
598
598
|
</tr>
|
|
599
599
|
|
|
@@ -673,7 +673,7 @@ in respect to the parent element.</p>
|
|
|
673
673
|
|
|
674
674
|
<tr>
|
|
675
675
|
<td class="col-md-4">
|
|
676
|
-
<div class="io-line">Defined in <a href="" data-line="
|
|
676
|
+
<div class="io-line">Defined in <a href="" data-line="164" class="link-to-prism">src/dialog/dialog.component.ts:164</a></div>
|
|
677
677
|
</td>
|
|
678
678
|
</tr>
|
|
679
679
|
|
|
@@ -713,7 +713,7 @@ in respect to the parent element.</p>
|
|
|
713
713
|
|
|
714
714
|
<tr>
|
|
715
715
|
<td class="col-md-4">
|
|
716
|
-
<div class="io-line">Defined in <a href="" data-line="
|
|
716
|
+
<div class="io-line">Defined in <a href="" data-line="175" class="link-to-prism">src/dialog/dialog.component.ts:175</a></div>
|
|
717
717
|
</td>
|
|
718
718
|
</tr>
|
|
719
719
|
|
|
@@ -1132,12 +1132,12 @@ import {
|
|
|
1132
1132
|
fromEvent,
|
|
1133
1133
|
merge
|
|
1134
1134
|
} from "rxjs";
|
|
1135
|
-
import { throttleTime } from "rxjs/operators";
|
|
1135
|
+
import { throttleTime, map } from "rxjs/operators";
|
|
1136
1136
|
// the AbsolutePosition is required to import the declaration correctly
|
|
1137
1137
|
import Position, { position, AbsolutePosition, Positions } from "@carbon/utils-position";
|
|
1138
1138
|
import { cycleTabs, getFocusElementList } from "./../common/tab.service";
|
|
1139
1139
|
import { DialogConfig } from "./dialog-config.interface";
|
|
1140
|
-
|
|
1140
|
+
import { scrollableParentsObservable, isVisibleInContainer } from "./../utils/scroll";
|
|
1141
1141
|
|
|
1142
1142
|
/**
|
|
1143
1143
|
* Implements a `Dialog` that can be positioned anywhere on the page.
|
|
@@ -1237,7 +1237,7 @@ export class Dialog implements OnInit, AfterViewInit, OnDestroy {
|
|
|
1237
1237
|
*/
|
|
1238
1238
|
ngAfterViewInit() {
|
|
1239
1239
|
const dialogElement = this.dialog.nativeElement;
|
|
1240
|
-
// split the wrapper class list and apply separately to avoid IE
|
|
1240
|
+
// split the wrapper class list and apply separately to avoid IE
|
|
1241
1241
|
// 1. throwing an error due to assigning a readonly property (classList)
|
|
1242
1242
|
// 2. throwing a SyntaxError due to passing an empty string to `add`
|
|
1243
1243
|
if (this.dialogConfig.wrapperClass) {
|
|
@@ -1249,43 +1249,14 @@ export class Dialog implements OnInit, AfterViewInit, OnDestroy {
|
|
|
1249
1249
|
if (getFocusElementList(this.dialog.nativeElement).length > 0) {
|
|
1250
1250
|
dialogElement.focus();
|
|
1251
1251
|
}
|
|
1252
|
-
const
|
|
1253
|
-
let node = parentEl;
|
|
1254
|
-
let observables = [];
|
|
1255
|
-
|
|
1256
|
-
// if the element has an overflow set as part of
|
|
1257
|
-
// its computed style it can scroll
|
|
1258
|
-
const isScrollableElement = (element: HTMLElement) => {
|
|
1259
|
-
const computedStyle = getComputedStyle(element);
|
|
1260
|
-
return (
|
|
1261
|
-
computedStyle.overflow === "auto" ||
|
|
1262
|
-
computedStyle.overflow === "scroll" ||
|
|
1263
|
-
computedStyle["overflow-y"] === "auto" ||
|
|
1264
|
-
computedStyle["overflow-y"] === "scroll" ||
|
|
1265
|
-
computedStyle["overflow-x"] === "auto" ||
|
|
1266
|
-
computedStyle["overflow-x"] === "scroll"
|
|
1267
|
-
);
|
|
1268
|
-
};
|
|
1269
|
-
|
|
1270
|
-
const isVisibleInContainer = (element, container) => {
|
|
1271
|
-
const elementRect = element.getBoundingClientRect();
|
|
1272
|
-
const containerRect = container.getBoundingClientRect();
|
|
1273
|
-
return elementRect.bottom <= containerRect.bottom && elementRect.top >= containerRect.top;
|
|
1274
|
-
};
|
|
1252
|
+
const parentElement = this.dialogConfig.parentRef.nativeElement;
|
|
1275
1253
|
|
|
1276
1254
|
const placeDialogInContainer = () => {
|
|
1277
1255
|
// only do the work to find the scroll containers if we're appended to body
|
|
1278
1256
|
// or skip this work if we're inline
|
|
1279
1257
|
if (!this.dialogConfig.appendInline) {
|
|
1280
|
-
// walk the parents and subscribe to all the scroll events we can
|
|
1281
|
-
while (node.parentElement && node !== document.body) {
|
|
1282
|
-
if (isScrollableElement(node)) {
|
|
1283
|
-
observables.push(fromEvent(node, "scroll"));
|
|
1284
|
-
}
|
|
1285
|
-
node = node.parentElement;
|
|
1286
|
-
}
|
|
1287
1258
|
// subscribe to the observable, and update the position and visibility
|
|
1288
|
-
const scrollObservable =
|
|
1259
|
+
const scrollObservable = scrollableParentsObservable(parentElement);
|
|
1289
1260
|
this.scrollSubscription = scrollObservable.subscribe((event: any) => {
|
|
1290
1261
|
this.placeDialog();
|
|
1291
1262
|
if (!isVisibleInContainer(this.dialogConfig.parentRef.nativeElement, event.target)) {
|