@workday/canvas-kit-popup-stack
Advanced tools
Comparing version 12.0.0-alpha.846-next.0 to 12.0.0-alpha.852-next.0
@@ -37,3 +37,6 @@ /** | ||
items: PopupStackItem[]; | ||
container?: () => HTMLElement; | ||
/** | ||
* Returns the container of a stack given an optional element. | ||
*/ | ||
container?: (element?: HTMLElement) => HTMLElement; | ||
zIndex: { | ||
@@ -40,0 +43,0 @@ min: number; |
@@ -126,2 +126,16 @@ "use strict"; | ||
}; | ||
/** | ||
* TODO: Remove this after v12 and use `stack.container(el)` directly. This is temporary to make | ||
* sure Popups can open in new windows while supporting older versions of Canvas Kit AND full screen | ||
* mode. | ||
*/ | ||
const getContainer = (stack, element) => { | ||
var _a; | ||
let stackContainer = (_a = stack.container) === null || _a === void 0 ? void 0 : _a.call(stack); | ||
if (stackContainer === document.body) { | ||
// Here's the transitory code | ||
stackContainer = element === null || element === void 0 ? void 0 : element.ownerDocument.body; | ||
} | ||
return stackContainer || document.body; | ||
}; | ||
// We need to make sure only one stack is ever in use on the page - ever. If a stack is already | ||
@@ -132,3 +146,3 @@ // defined on the page, we need to use that one. Never, ever, ever change this variable name on | ||
description: 'Global popup stack from @workday/canvas-kit/popup-stack', | ||
container: () => document.body, | ||
container: el => (el === null || el === void 0 ? void 0 : el.ownerDocument.body) || document.body, | ||
items: [], | ||
@@ -187,3 +201,3 @@ zIndex: { min: 30, max: 50, getValue: getValue }, | ||
add(item) { | ||
var _a, _b; | ||
var _a; | ||
const stack = getTopStack(); | ||
@@ -195,3 +209,3 @@ if ((_a = stack._adapter) === null || _a === void 0 ? void 0 : _a.add) { | ||
stack.items.push(item); | ||
(((_b = stack.container) === null || _b === void 0 ? void 0 : _b.call(stack)) || document.body).appendChild(item.element); | ||
getContainer(stack, item.owner).appendChild(item.element); | ||
setZIndexOfElements(exports.PopupStack.getElements()); | ||
@@ -207,3 +221,3 @@ }, | ||
remove(element) { | ||
var _a, _b; | ||
var _a; | ||
// Find the stack the popup belongs to. | ||
@@ -216,4 +230,5 @@ const stack = stacks.find(stack => !!exports.PopupStack.getElements(stack).find(el => el === element)); | ||
} | ||
const item = stack.items.find(item => item.element === element); | ||
stack.items = stack.items.filter(item => item.element !== element); | ||
(((_b = stack.container) === null || _b === void 0 ? void 0 : _b.call(stack)) || document.body).removeChild(element); | ||
getContainer(stack, item === null || item === void 0 ? void 0 : item.owner).removeChild(element); | ||
setZIndexOfElements(exports.PopupStack.getElements(stack)); | ||
@@ -220,0 +235,0 @@ } |
@@ -37,3 +37,6 @@ /** | ||
items: PopupStackItem[]; | ||
container?: () => HTMLElement; | ||
/** | ||
* Returns the container of a stack given an optional element. | ||
*/ | ||
container?: (element?: HTMLElement) => HTMLElement; | ||
zIndex: { | ||
@@ -40,0 +43,0 @@ min: number; |
@@ -119,2 +119,16 @@ import screenfull from 'screenfull'; | ||
}; | ||
/** | ||
* TODO: Remove this after v12 and use `stack.container(el)` directly. This is temporary to make | ||
* sure Popups can open in new windows while supporting older versions of Canvas Kit AND full screen | ||
* mode. | ||
*/ | ||
const getContainer = (stack, element) => { | ||
var _a; | ||
let stackContainer = (_a = stack.container) === null || _a === void 0 ? void 0 : _a.call(stack); | ||
if (stackContainer === document.body) { | ||
// Here's the transitory code | ||
stackContainer = element === null || element === void 0 ? void 0 : element.ownerDocument.body; | ||
} | ||
return stackContainer || document.body; | ||
}; | ||
// We need to make sure only one stack is ever in use on the page - ever. If a stack is already | ||
@@ -125,3 +139,3 @@ // defined on the page, we need to use that one. Never, ever, ever change this variable name on | ||
description: 'Global popup stack from @workday/canvas-kit/popup-stack', | ||
container: () => document.body, | ||
container: el => (el === null || el === void 0 ? void 0 : el.ownerDocument.body) || document.body, | ||
items: [], | ||
@@ -180,3 +194,3 @@ zIndex: { min: 30, max: 50, getValue: getValue }, | ||
add(item) { | ||
var _a, _b; | ||
var _a; | ||
const stack = getTopStack(); | ||
@@ -188,3 +202,3 @@ if ((_a = stack._adapter) === null || _a === void 0 ? void 0 : _a.add) { | ||
stack.items.push(item); | ||
(((_b = stack.container) === null || _b === void 0 ? void 0 : _b.call(stack)) || document.body).appendChild(item.element); | ||
getContainer(stack, item.owner).appendChild(item.element); | ||
setZIndexOfElements(PopupStack.getElements()); | ||
@@ -200,3 +214,3 @@ }, | ||
remove(element) { | ||
var _a, _b; | ||
var _a; | ||
// Find the stack the popup belongs to. | ||
@@ -209,4 +223,5 @@ const stack = stacks.find(stack => !!PopupStack.getElements(stack).find(el => el === element)); | ||
} | ||
const item = stack.items.find(item => item.element === element); | ||
stack.items = stack.items.filter(item => item.element !== element); | ||
(((_b = stack.container) === null || _b === void 0 ? void 0 : _b.call(stack)) || document.body).removeChild(element); | ||
getContainer(stack, item === null || item === void 0 ? void 0 : item.owner).removeChild(element); | ||
setZIndexOfElements(PopupStack.getElements(stack)); | ||
@@ -213,0 +228,0 @@ } |
@@ -96,3 +96,6 @@ import screenfull from 'screenfull'; | ||
items: PopupStackItem[]; | ||
container?: () => HTMLElement; | ||
/** | ||
* Returns the container of a stack given an optional element. | ||
*/ | ||
container?: (element?: HTMLElement) => HTMLElement; | ||
zIndex: { | ||
@@ -171,2 +174,17 @@ min: number; | ||
/** | ||
* TODO: Remove this after v12 and use `stack.container(el)` directly. This is temporary to make | ||
* sure Popups can open in new windows while supporting older versions of Canvas Kit AND full screen | ||
* mode. | ||
*/ | ||
const getContainer = (stack: Stack, element?: HTMLElement): HTMLElement => { | ||
let stackContainer = stack.container?.(); | ||
if (stackContainer === document.body) { | ||
// Here's the transitory code | ||
stackContainer = element?.ownerDocument.body; | ||
} | ||
return stackContainer || document.body; | ||
}; | ||
// We need to make sure only one stack is ever in use on the page - ever. If a stack is already | ||
@@ -177,3 +195,3 @@ // defined on the page, we need to use that one. Never, ever, ever change this variable name on | ||
description: 'Global popup stack from @workday/canvas-kit/popup-stack', | ||
container: () => document.body, | ||
container: el => el?.ownerDocument.body || document.body, | ||
items: [], | ||
@@ -241,3 +259,3 @@ zIndex: {min: 30, max: 50, getValue: getValue}, | ||
stack.items.push(item); | ||
(stack.container?.() || document.body).appendChild(item.element); | ||
getContainer(stack, item.owner).appendChild(item.element); | ||
@@ -262,4 +280,5 @@ setZIndexOfElements(PopupStack.getElements()); | ||
} | ||
const item = stack.items.find(item => item.element === element); | ||
stack.items = stack.items.filter(item => item.element !== element); | ||
(stack.container?.() || document.body).removeChild(element); | ||
getContainer(stack, item?.owner).removeChild(element); | ||
@@ -266,0 +285,0 @@ setZIndexOfElements(PopupStack.getElements(stack)); |
{ | ||
"name": "@workday/canvas-kit-popup-stack", | ||
"version": "12.0.0-alpha.846-next.0", | ||
"version": "12.0.0-alpha.852-next.0", | ||
"description": "Stack for managing popup UIs to coordinate global concerns like escape key handling and rendering order", | ||
@@ -40,3 +40,3 @@ "author": "Workday, Inc. (https://www.workday.com)", | ||
}, | ||
"gitHead": "92573a5cb42a250072618c814c0bc78edaf0480a" | ||
"gitHead": "bbd7343aec2a6657b8eff4981a7aa4a6e47af161" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
102950
1704