overlastic 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -7
- data/app/assets/javascripts/overlastic.js +13 -3
- data/app/assets/javascripts/overlastic.min.js +1 -1
- data/app/assets/javascripts/overlastic.min.js.map +1 -1
- data/app/controllers/overlastic/concerns/overlay_handling.rb +70 -10
- data/app/helpers/overlastic/navigation_helper.rb +3 -3
- data/app/helpers/overlastic/overlays_helper.rb +22 -7
- data/app/javascript/overlastic/clickInterceptor.js +14 -3
- data/app/views/overlastic/streams/redirect.turbo_stream.erb +10 -0
- data/lib/generators/overlastic/views/views_generator.rb +7 -0
- data/lib/overlastic/configuration.rb +2 -1
- data/lib/overlastic/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f158f1c2b9f600ab39f4ce19eeac6b800c590cedf6160a99082103370b6bd340
|
4
|
+
data.tar.gz: cf10d779b276c11db52ef5656758d2d36a08b76f451852e6bc2f865db4bbc7d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a11a8f21871e01f6a581a0adf8a3d65e7d9552e6c60c7b871af8e4cd3874882c04d4246cf7e5ac5e04137685412e5894aded732ef4344a361011145f21c8dbd
|
7
|
+
data.tar.gz: 905c243532a2f19b3f94fbfe2f87f6984d63675ff749946fef2568076fd7882eebc762422f567b52c089c34266383b52d9fc323ee5e036feb7e09f72e2275d91
|
data/README.md
CHANGED
@@ -49,21 +49,51 @@ A common use case is to render a form inside an overlay. When the form is submit
|
|
49
49
|
|
50
50
|
```rb
|
51
51
|
if @article.save
|
52
|
-
redirect_to article_url(@article)
|
52
|
+
redirect_to article_url(@article), status: :see_other
|
53
53
|
else
|
54
54
|
render :new, status: :unprocessable_entity
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
-
|
58
|
+
In case the form overlay was nested inside another overlay, you could prefer to apply the redirection to the parent overlay:
|
59
|
+
|
60
|
+
```rb
|
61
|
+
redirect_to article_url(@article), overlay: :previous, status: :see_other
|
62
|
+
```
|
63
|
+
|
64
|
+
Sometimes, you may want to alter the content of a view depending on whether it's inside an overlay or not. Overlastic defines a new `:overlay` request variant that you can use to create custom partials like `_form.html+overlay.erb` or inside a controller like so:
|
59
65
|
|
60
66
|
```rb
|
61
67
|
respond_to do |format|
|
62
68
|
format.html.overlay { render :custom_view }
|
63
|
-
format.html
|
69
|
+
format.html.any
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
You can also close overlays from the server if you don't need to render any more content:
|
74
|
+
|
75
|
+
```rb
|
76
|
+
if request.variant.overlay?
|
77
|
+
close_overlay
|
78
|
+
# close_overlay :last
|
79
|
+
# close_overlay :all
|
80
|
+
# close_overlay :overlay2
|
81
|
+
else
|
82
|
+
redirect_to articles_url, status: :see_other
|
64
83
|
end
|
65
84
|
```
|
66
85
|
|
86
|
+
<details>
|
87
|
+
<summary>Advanced: Rendering an overlay without an initiator</summary><br>
|
88
|
+
|
89
|
+
Overlastic extends the `render` method inside a controller to add all the same options as `link_to_overlay`. This allows you to force an action to render an overlay, even if it wasn't requested:
|
90
|
+
|
91
|
+
```rb
|
92
|
+
render :new, overlay: :first, overlay_target: :_self, overlay_args: { title: "New article" }
|
93
|
+
# render :edit, overlay: :last, overlay_type: :pane
|
94
|
+
```
|
95
|
+
</details>
|
96
|
+
|
67
97
|
|
68
98
|
## Configuration
|
69
99
|
|
@@ -74,10 +104,11 @@ Overlastic.configure do |config|
|
|
74
104
|
config.overlay_types = %i[dialog pane]
|
75
105
|
config.default_overlay = :dialog
|
76
106
|
config.default_action = :stack
|
107
|
+
config.default_target = :_top
|
77
108
|
|
78
109
|
# You can define a custom partial for each overlay type
|
79
|
-
config.dialog_overlay_view_path = "
|
80
|
-
config.
|
110
|
+
config.dialog_overlay_view_path = "overlays/dialog"
|
111
|
+
config.pane_overlay_view_path = "overlays/pane"
|
81
112
|
end
|
82
113
|
```
|
83
114
|
|
@@ -111,8 +142,6 @@ Overlastic comes with default views for both the dialog and pane overlays. It al
|
|
111
142
|
<details>
|
112
143
|
<summary>Roadmap</summary><br>
|
113
144
|
|
114
|
-
- Ability to configure the default target
|
115
|
-
- Allow the server to request closing an overlay / all the overlays
|
116
145
|
- Toasts?
|
117
146
|
</details>
|
118
147
|
|
@@ -206,6 +206,10 @@ addEventListener("click", (event => {
|
|
206
206
|
window._overlasticAnchor = event.target.closest("a[data-turbo-frame^=overlay]");
|
207
207
|
}), true);
|
208
208
|
|
209
|
+
addEventListener("turbo:before-fetch-request", (event => {
|
210
|
+
event.detail.fetchOptions.headers["Overlay-Enabled"] = "1";
|
211
|
+
}));
|
212
|
+
|
209
213
|
addEventListener("turbo:before-fetch-request", (event => {
|
210
214
|
if (!window._overlasticAnchor) return;
|
211
215
|
const anchor = window._overlasticAnchor;
|
@@ -230,9 +234,13 @@ addEventListener("turbo:before-fetch-request", (event => {
|
|
230
234
|
const frame = event.target.closest("turbo-frame[id^=overlay]");
|
231
235
|
if (frame) {
|
232
236
|
const target = frame.dataset.overlayTarget;
|
237
|
+
const initiator = frame.dataset?.overlayInitiator;
|
233
238
|
const type = frame.dataset?.overlayType;
|
234
239
|
const args = frame.dataset?.overlayArgs;
|
235
240
|
event.detail.fetchOptions.headers["Overlay-Target"] = target;
|
241
|
+
if (initiator) {
|
242
|
+
event.detail.fetchOptions.headers["Overlay-Initiator"] = initiator;
|
243
|
+
}
|
236
244
|
if (type) {
|
237
245
|
event.detail.fetchOptions.headers["Overlay-Type"] = type;
|
238
246
|
}
|
@@ -244,10 +252,12 @@ addEventListener("turbo:before-fetch-request", (event => {
|
|
244
252
|
|
245
253
|
addEventListener("turbo:before-fetch-response", (async event => {
|
246
254
|
const fetchResponse = event.detail.fetchResponse;
|
247
|
-
|
255
|
+
const visit = fetchResponse.response.headers.get("Overlay-Visit");
|
256
|
+
if (!visit) return;
|
248
257
|
const responseHTML = await fetchResponse.responseHTML;
|
249
|
-
const {
|
250
|
-
return Turbo.session.visit(
|
258
|
+
const {redirected: redirected, statusCode: statusCode} = fetchResponse;
|
259
|
+
return Turbo.session.visit(visit, {
|
260
|
+
shouldCacheSnapshot: false,
|
251
261
|
response: {
|
252
262
|
redirected: redirected,
|
253
263
|
statusCode: statusCode,
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=!1;if("undefined"!=typeof window){var t={get passive(){e=!0}};window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}var o="undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),n=[],i=!1,r=-1,s=void 0,a=void 0,d=void 0,l=function(e){return n.some((function(t){return!(!t.options.allowTouchMove||!t.options.allowTouchMove(e))}))},c=function(e){var t=e||window.event;return!!l(t.target)||(t.touches.length>1||(t.preventDefault&&t.preventDefault(),!1))};addEventListener("click",(e=>{window._overlasticAnchor=e.target.closest("a[data-turbo-frame^=overlay]")}),!0),addEventListener("turbo:before-fetch-request",(e=>{if(!window._overlasticAnchor)return;const t=window._overlasticAnchor,o=t?.dataset?.overlayType,n=t?.dataset?.overlayTarget,i=t?.dataset?.overlayArgs;e.detail.fetchOptions.headers["Overlay-Initiator"]="1",o&&(e.detail.fetchOptions.headers["Overlay-Type"]=o),n&&(e.detail.fetchOptions.headers["Overlay-Target"]=n),i&&(e.detail.fetchOptions.headers["Overlay-Args"]=i),delete window._overlasticTarget})),addEventListener("turbo:before-fetch-request",(e=>{if(window._overlasticAnchor)return;const t=e.target.closest("turbo-frame[id^=overlay]");if(t){const o=t.dataset.overlayTarget,n=t.dataset?.
|
1
|
+
var e=!1;if("undefined"!=typeof window){var t={get passive(){e=!0}};window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}var o="undefined"!=typeof window&&window.navigator&&window.navigator.platform&&(/iP(ad|hone|od)/.test(window.navigator.platform)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1),n=[],i=!1,r=-1,s=void 0,a=void 0,d=void 0,l=function(e){return n.some((function(t){return!(!t.options.allowTouchMove||!t.options.allowTouchMove(e))}))},c=function(e){var t=e||window.event;return!!l(t.target)||(t.touches.length>1||(t.preventDefault&&t.preventDefault(),!1))};addEventListener("click",(e=>{window._overlasticAnchor=e.target.closest("a[data-turbo-frame^=overlay]")}),!0),addEventListener("turbo:before-fetch-request",(e=>{e.detail.fetchOptions.headers["Overlay-Enabled"]="1"})),addEventListener("turbo:before-fetch-request",(e=>{if(!window._overlasticAnchor)return;const t=window._overlasticAnchor,o=t?.dataset?.overlayType,n=t?.dataset?.overlayTarget,i=t?.dataset?.overlayArgs;e.detail.fetchOptions.headers["Overlay-Initiator"]="1",o&&(e.detail.fetchOptions.headers["Overlay-Type"]=o),n&&(e.detail.fetchOptions.headers["Overlay-Target"]=n),i&&(e.detail.fetchOptions.headers["Overlay-Args"]=i),delete window._overlasticTarget})),addEventListener("turbo:before-fetch-request",(e=>{if(window._overlasticAnchor)return;const t=e.target.closest("turbo-frame[id^=overlay]");if(t){const o=t.dataset.overlayTarget,n=t.dataset?.overlayInitiator,i=t.dataset?.overlayType,r=t.dataset?.overlayArgs;e.detail.fetchOptions.headers["Overlay-Target"]=o,n&&(e.detail.fetchOptions.headers["Overlay-Initiator"]=n),i&&(e.detail.fetchOptions.headers["Overlay-Type"]=i),r&&(e.detail.fetchOptions.headers["Overlay-Args"]=r)}})),addEventListener("turbo:before-fetch-response",(async e=>{const t=e.detail.fetchResponse,o=t.response.headers.get("Overlay-Visit");if(!o)return;const n=await t.responseHTML,{redirected:i,statusCode:r}=t;return Turbo.session.visit(o,{shouldCacheSnapshot:!1,response:{redirected:i,statusCode:r,responseHTML:n}})}));class u extends HTMLElement{connectedCallback(){disableBodyScroll(this),this.addEventListener("click",(e=>this.close(e,!0))),this.querySelector(".overlastic-close").addEventListener("click",(e=>this.close(e)))}close(e,t=!1){t&&e.target!==this||(enableBodyScroll(this),setTimeout((()=>{this.remove()}),5))}}customElements.define("overlastic-dialog",u);customElements.define("overlastic-pane",class extends u{connectedCallback(){super.connectedCallback();const e=Turbo.navigator.history.location;window.modalVisitStack||(window.modalVisitStack=[]),window.modalVisitStack.push(e),Turbo.navigator.history.push(new URL(this.parentElement.src))}close(e,t=!1){t&&e.target!==this||(super.close(e,t),window.modalVisitStack.length>0&&Turbo.navigator.history.replace(window.modalVisitStack.pop()))}}),window.disableBodyScroll=function(t,u){if(t){if(!n.some((function(e){return e.targetElement===t}))){var v={targetElement:t,options:u||{}};n=[].concat(function(e){if(Array.isArray(e)){for(var t=0,o=Array(e.length);t<e.length;t++)o[t]=e[t];return o}return Array.from(e)}(n),[v]),o?window.requestAnimationFrame((function(){if(void 0===a){a={position:document.body.style.position,top:document.body.style.top,left:document.body.style.left};var e=window,t=e.scrollY,o=e.scrollX,n=e.innerHeight;document.body.style.position="fixed",document.body.style.top=-t,document.body.style.left=-o,setTimeout((function(){return window.requestAnimationFrame((function(){var e=n-window.innerHeight;e&&t>=n&&(document.body.style.top=-(t+e))}))}),300)}})):function(e){if(void 0===d){var t=!!e&&!0===e.reserveScrollBarGap,o=window.innerWidth-document.documentElement.clientWidth;if(t&&o>0){var n=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"),10);d=document.body.style.paddingRight,document.body.style.paddingRight=n+o+"px"}}void 0===s&&(s=document.body.style.overflow,document.body.style.overflow="hidden")}(u),o&&(t.ontouchstart=function(e){1===e.targetTouches.length&&(r=e.targetTouches[0].clientY)},t.ontouchmove=function(e){1===e.targetTouches.length&&function(e,t){var o=e.targetTouches[0].clientY-r;!l(e.target)&&(t&&0===t.scrollTop&&o>0||function(e){return!!e&&e.scrollHeight-e.scrollTop<=e.clientHeight}(t)&&o<0?c(e):e.stopPropagation())}(e,t)},i||(document.addEventListener("touchmove",c,e?{passive:!1}:void 0),i=!0))}}else console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.")},window.enableBodyScroll=function(t){t?(n=n.filter((function(e){return e.targetElement!==t})),o&&(t.ontouchstart=null,t.ontouchmove=null,i&&0===n.length&&(document.removeEventListener("touchmove",c,e?{passive:!1}:void 0),i=!1)),o?function(){if(void 0!==a){var e=-parseInt(document.body.style.top,10),t=-parseInt(document.body.style.left,10);document.body.style.position=a.position,document.body.style.top=a.top,document.body.style.left=a.left,window.scrollTo(t,e),a=void 0}}():(void 0!==d&&(document.body.style.paddingRight=d,d=void 0),void 0!==s&&(document.body.style.overflow=s,s=void 0))):console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.")};
|
2
2
|
//# sourceMappingURL=overlastic.min.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"overlastic.min.js","sources":["../../../node_modules/body-scroll-lock/lib/bodyScrollLock.esm.js","../../javascript/overlastic/clickInterceptor.js","../../javascript/overlastic/dialogElement.js","../../javascript/overlastic/paneElement.js","../../javascript/overlastic/index.js"],"sourcesContent":["function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\n// Older browsers don't support event options, feature detect it.\n\n// Adopted and modified solution from Bohdan Didukh (2017)\n// https://stackoverflow.com/questions/41594997/ios-10-safari-prevent-scrolling-behind-a-fixed-overlay-and-maintain-scroll-posi\n\nvar hasPassiveEvents = false;\nif (typeof window !== 'undefined') {\n var passiveTestOptions = {\n get passive() {\n hasPassiveEvents = true;\n return undefined;\n }\n };\n window.addEventListener('testPassive', null, passiveTestOptions);\n window.removeEventListener('testPassive', null, passiveTestOptions);\n}\n\nvar isIosDevice = typeof window !== 'undefined' && window.navigator && window.navigator.platform && (/iP(ad|hone|od)/.test(window.navigator.platform) || window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1);\n\n\nvar locks = [];\nvar documentListenerAdded = false;\nvar initialClientY = -1;\nvar previousBodyOverflowSetting = void 0;\nvar previousBodyPosition = void 0;\nvar previousBodyPaddingRight = void 0;\n\n// returns true if `el` should be allowed to receive touchmove events.\nvar allowTouchMove = function allowTouchMove(el) {\n return locks.some(function (lock) {\n if (lock.options.allowTouchMove && lock.options.allowTouchMove(el)) {\n return true;\n }\n\n return false;\n });\n};\n\nvar preventDefault = function preventDefault(rawEvent) {\n var e = rawEvent || window.event;\n\n // For the case whereby consumers adds a touchmove event listener to document.\n // Recall that we do document.addEventListener('touchmove', preventDefault, { passive: false })\n // in disableBodyScroll - so if we provide this opportunity to allowTouchMove, then\n // the touchmove event on document will break.\n if (allowTouchMove(e.target)) {\n return true;\n }\n\n // Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).\n if (e.touches.length > 1) return true;\n\n if (e.preventDefault) e.preventDefault();\n\n return false;\n};\n\nvar setOverflowHidden = function setOverflowHidden(options) {\n // If previousBodyPaddingRight is already set, don't set it again.\n if (previousBodyPaddingRight === undefined) {\n var _reserveScrollBarGap = !!options && options.reserveScrollBarGap === true;\n var scrollBarGap = window.innerWidth - document.documentElement.clientWidth;\n\n if (_reserveScrollBarGap && scrollBarGap > 0) {\n var computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10);\n previousBodyPaddingRight = document.body.style.paddingRight;\n document.body.style.paddingRight = computedBodyPaddingRight + scrollBarGap + 'px';\n }\n }\n\n // If previousBodyOverflowSetting is already set, don't set it again.\n if (previousBodyOverflowSetting === undefined) {\n previousBodyOverflowSetting = document.body.style.overflow;\n document.body.style.overflow = 'hidden';\n }\n};\n\nvar restoreOverflowSetting = function restoreOverflowSetting() {\n if (previousBodyPaddingRight !== undefined) {\n document.body.style.paddingRight = previousBodyPaddingRight;\n\n // Restore previousBodyPaddingRight to undefined so setOverflowHidden knows it\n // can be set again.\n previousBodyPaddingRight = undefined;\n }\n\n if (previousBodyOverflowSetting !== undefined) {\n document.body.style.overflow = previousBodyOverflowSetting;\n\n // Restore previousBodyOverflowSetting to undefined\n // so setOverflowHidden knows it can be set again.\n previousBodyOverflowSetting = undefined;\n }\n};\n\nvar setPositionFixed = function setPositionFixed() {\n return window.requestAnimationFrame(function () {\n // If previousBodyPosition is already set, don't set it again.\n if (previousBodyPosition === undefined) {\n previousBodyPosition = {\n position: document.body.style.position,\n top: document.body.style.top,\n left: document.body.style.left\n };\n\n // Update the dom inside an animation frame \n var _window = window,\n scrollY = _window.scrollY,\n scrollX = _window.scrollX,\n innerHeight = _window.innerHeight;\n\n document.body.style.position = 'fixed';\n document.body.style.top = -scrollY;\n document.body.style.left = -scrollX;\n\n setTimeout(function () {\n return window.requestAnimationFrame(function () {\n // Attempt to check if the bottom bar appeared due to the position change\n var bottomBarHeight = innerHeight - window.innerHeight;\n if (bottomBarHeight && scrollY >= innerHeight) {\n // Move the content further up so that the bottom bar doesn't hide it\n document.body.style.top = -(scrollY + bottomBarHeight);\n }\n });\n }, 300);\n }\n });\n};\n\nvar restorePositionSetting = function restorePositionSetting() {\n if (previousBodyPosition !== undefined) {\n // Convert the position from \"px\" to Int\n var y = -parseInt(document.body.style.top, 10);\n var x = -parseInt(document.body.style.left, 10);\n\n // Restore styles\n document.body.style.position = previousBodyPosition.position;\n document.body.style.top = previousBodyPosition.top;\n document.body.style.left = previousBodyPosition.left;\n\n // Restore scroll\n window.scrollTo(x, y);\n\n previousBodyPosition = undefined;\n }\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions\nvar isTargetElementTotallyScrolled = function isTargetElementTotallyScrolled(targetElement) {\n return targetElement ? targetElement.scrollHeight - targetElement.scrollTop <= targetElement.clientHeight : false;\n};\n\nvar handleScroll = function handleScroll(event, targetElement) {\n var clientY = event.targetTouches[0].clientY - initialClientY;\n\n if (allowTouchMove(event.target)) {\n return false;\n }\n\n if (targetElement && targetElement.scrollTop === 0 && clientY > 0) {\n // element is at the top of its scroll.\n return preventDefault(event);\n }\n\n if (isTargetElementTotallyScrolled(targetElement) && clientY < 0) {\n // element is at the bottom of its scroll.\n return preventDefault(event);\n }\n\n event.stopPropagation();\n return true;\n};\n\nexport var disableBodyScroll = function disableBodyScroll(targetElement, options) {\n // targetElement must be provided\n if (!targetElement) {\n // eslint-disable-next-line no-console\n console.error('disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.');\n return;\n }\n\n // disableBodyScroll must not have been called on this targetElement before\n if (locks.some(function (lock) {\n return lock.targetElement === targetElement;\n })) {\n return;\n }\n\n var lock = {\n targetElement: targetElement,\n options: options || {}\n };\n\n locks = [].concat(_toConsumableArray(locks), [lock]);\n\n if (isIosDevice) {\n setPositionFixed();\n } else {\n setOverflowHidden(options);\n }\n\n if (isIosDevice) {\n targetElement.ontouchstart = function (event) {\n if (event.targetTouches.length === 1) {\n // detect single touch.\n initialClientY = event.targetTouches[0].clientY;\n }\n };\n targetElement.ontouchmove = function (event) {\n if (event.targetTouches.length === 1) {\n // detect single touch.\n handleScroll(event, targetElement);\n }\n };\n\n if (!documentListenerAdded) {\n document.addEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);\n documentListenerAdded = true;\n }\n }\n};\n\nexport var clearAllBodyScrollLocks = function clearAllBodyScrollLocks() {\n if (isIosDevice) {\n // Clear all locks ontouchstart/ontouchmove handlers, and the references.\n locks.forEach(function (lock) {\n lock.targetElement.ontouchstart = null;\n lock.targetElement.ontouchmove = null;\n });\n\n if (documentListenerAdded) {\n document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);\n documentListenerAdded = false;\n }\n\n // Reset initial clientY.\n initialClientY = -1;\n }\n\n if (isIosDevice) {\n restorePositionSetting();\n } else {\n restoreOverflowSetting();\n }\n\n locks = [];\n};\n\nexport var enableBodyScroll = function enableBodyScroll(targetElement) {\n if (!targetElement) {\n // eslint-disable-next-line no-console\n console.error('enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.');\n return;\n }\n\n locks = locks.filter(function (lock) {\n return lock.targetElement !== targetElement;\n });\n\n if (isIosDevice) {\n targetElement.ontouchstart = null;\n targetElement.ontouchmove = null;\n\n if (documentListenerAdded && locks.length === 0) {\n document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);\n documentListenerAdded = false;\n }\n }\n\n if (isIosDevice) {\n restorePositionSetting();\n } else {\n restoreOverflowSetting();\n }\n};\n\n","// Save the clicked overlay link element for use down the line\naddEventListener(\"click\", event => {\n window._overlasticAnchor = event.target.closest(\"a[data-turbo-frame^=overlay]\")\n}, true)\n\n// When an overlay anchor is clicked,\n// send its type, target and args along with the frame request\naddEventListener(\"turbo:before-fetch-request\", event => {\n if (!window._overlasticAnchor) return\n\n const anchor = window._overlasticAnchor\n const type = anchor?.dataset?.overlayType\n const target = anchor?.dataset?.overlayTarget\n const args = anchor?.dataset?.overlayArgs\n\n event.detail.fetchOptions.headers[\"Overlay-Initiator\"] = \"1\"\n\n if (type) {\n event.detail.fetchOptions.headers[\"Overlay-Type\"] = type\n }\n\n if (target) {\n event.detail.fetchOptions.headers[\"Overlay-Target\"] = target\n }\n\n if (args) {\n event.detail.fetchOptions.headers[\"Overlay-Args\"] = args\n }\n\n delete window._overlasticTarget\n})\n\n// When any other element triggers a fetch,\n// send the current overlay's target along with the frame request\naddEventListener(\"turbo:before-fetch-request\", event => {\n if (window._overlasticAnchor) return\n\n const frame = event.target.closest(\"turbo-frame[id^=overlay]\")\n\n if (frame) {\n const target = frame.dataset.overlayTarget\n const type = frame.dataset?.overlayType\n const args = frame.dataset?.overlayArgs\n\n event.detail.fetchOptions.headers[\"Overlay-Target\"] = target\n\n if (type) {\n event.detail.fetchOptions.headers[\"Overlay-Type\"] = type\n }\n\n if (args) {\n event.detail.fetchOptions.headers[\"Overlay-Args\"] = args\n }\n }\n})\n\n// Handle frame-to-visit promotions when the server asks for it\naddEventListener(\"turbo:before-fetch-response\", async event => {\n const fetchResponse = event.detail.fetchResponse\n\n if (!fetchResponse.response.headers.has(\"Overlay-Visit\")) return\n\n const responseHTML = await fetchResponse.responseHTML\n const { location, redirected, statusCode } = fetchResponse\n\n return Turbo.session.visit(location, { response: { redirected, statusCode, responseHTML } })\n})\n","export default class DialogElement extends HTMLElement {\n connectedCallback() {\n disableBodyScroll(this)\n\n this.addEventListener(\"click\", event => this.close(event, true))\n this.querySelector(\".overlastic-close\").addEventListener(\"click\", event => this.close(event))\n }\n\n close(event, self = false) {\n if (self && event.target !== this) return\n\n enableBodyScroll(this)\n\n // Avoid removing before sending dispatching other events (like form submissions)\n setTimeout(() => {\n this.remove()\n }, 5)\n }\n}\n\ncustomElements.define(\"overlastic-dialog\", DialogElement)\n","import DialogElement from \"./dialogElement\"\n\nclass PaneElement extends DialogElement {\n connectedCallback() {\n super.connectedCallback()\n\n const lastVisit = Turbo.navigator.history.location\n\n if (!window.modalVisitStack) {\n window.modalVisitStack = []\n }\n\n window.modalVisitStack.push(lastVisit)\n Turbo.navigator.history.push(new URL(this.parentElement.src))\n }\n\n close(event, self = false) {\n if (self && event.target !== this) return\n\n super.close(event, self)\n\n if (window.modalVisitStack.length > 0) {\n Turbo.navigator.history.replace(window.modalVisitStack.pop())\n }\n }\n}\n\ncustomElements.define(\"overlastic-pane\", PaneElement)\n","import { disableBodyScroll, enableBodyScroll } from \"body-scroll-lock\"\n\nimport \"./clickInterceptor\"\nimport \"./dialogElement\"\nimport \"./paneElement\"\n\nwindow.disableBodyScroll = disableBodyScroll\nwindow.enableBodyScroll = enableBodyScroll\n"],"names":["hasPassiveEvents","window","passiveTestOptions","passive","addEventListener","removeEventListener","isIosDevice","navigator","platform","test","maxTouchPoints","locks","documentListenerAdded","initialClientY","previousBodyOverflowSetting","previousBodyPosition","previousBodyPaddingRight","allowTouchMove","el","some","lock","options","preventDefault","rawEvent","e","event","target","touches","length","_overlasticAnchor","closest","anchor","type","dataset","overlayType","overlayTarget","args","overlayArgs","detail","fetchOptions","headers","_overlasticTarget","frame","async","fetchResponse","response","has","responseHTML","location","redirected","statusCode","Turbo","session","visit","DialogElement","HTMLElement","[object Object]","disableBodyScroll","this","close","querySelector","self","enableBodyScroll","setTimeout","remove","customElements","define","super","connectedCallback","lastVisit","history","modalVisitStack","push","URL","parentElement","src","replace","pop","targetElement","concat","arr","Array","isArray","i","arr2","from","_toConsumableArray","requestAnimationFrame","undefined","position","document","body","style","top","left","_window","scrollY","scrollX","innerHeight","bottomBarHeight","_reserveScrollBarGap","reserveScrollBarGap","scrollBarGap","innerWidth","documentElement","clientWidth","computedBodyPaddingRight","parseInt","getComputedStyle","getPropertyValue","paddingRight","overflow","setOverflowHidden","ontouchstart","targetTouches","clientY","ontouchmove","scrollTop","scrollHeight","clientHeight","isTargetElementTotallyScrolled","stopPropagation","handleScroll","console","error","filter","y","x","scrollTo","restorePositionSetting"],"mappings":"AAOA,IAAIA,GAAmB,EACvB,GAAsB,oBAAXC,OAAwB,CACjC,IAAIC,EAAqB,CACvBC,cACEH,GAAmB,IAIvBC,OAAOG,iBAAiB,cAAe,KAAMF,GAC7CD,OAAOI,oBAAoB,cAAe,KAAMH,GAGlD,IAAII,EAAgC,oBAAXL,QAA0BA,OAAOM,WAAaN,OAAOM,UAAUC,WAAa,iBAAiBC,KAAKR,OAAOM,UAAUC,WAA2C,aAA9BP,OAAOM,UAAUC,UAA2BP,OAAOM,UAAUG,eAAiB,GAGnOC,EAAQ,GACRC,GAAwB,EACxBC,GAAkB,EAClBC,OAA8B,EAC9BC,OAAuB,EACvBC,OAA2B,EAG3BC,EAAiB,SAAwBC,GAC3C,OAAOP,EAAMQ,MAAK,SAAUC,GAC1B,SAAIA,EAAKC,QAAQJ,iBAAkBG,EAAKC,QAAQJ,eAAeC,QAQ/DI,EAAiB,SAAwBC,GAC3C,IAAIC,EAAID,GAAYtB,OAAOwB,MAM3B,QAAIR,EAAeO,EAAEE,UAKjBF,EAAEG,QAAQC,OAAS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esm.js","../../javascript/overlastic/clickInterceptor.js","../../javascript/overlastic/dialogElement.js","../../javascript/overlastic/paneElement.js","../../javascript/overlastic/index.js"],"sourcesContent":["function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\n// Older browsers don't support event options, feature detect it.\n\n// Adopted and modified solution from Bohdan Didukh (2017)\n// https://stackoverflow.com/questions/41594997/ios-10-safari-prevent-scrolling-behind-a-fixed-overlay-and-maintain-scroll-posi\n\nvar hasPassiveEvents = false;\nif (typeof window !== 'undefined') {\n var passiveTestOptions = {\n get passive() {\n hasPassiveEvents = true;\n return undefined;\n }\n };\n window.addEventListener('testPassive', null, passiveTestOptions);\n window.removeEventListener('testPassive', null, passiveTestOptions);\n}\n\nvar isIosDevice = typeof window !== 'undefined' && window.navigator && window.navigator.platform && (/iP(ad|hone|od)/.test(window.navigator.platform) || window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1);\n\n\nvar locks = [];\nvar documentListenerAdded = false;\nvar initialClientY = -1;\nvar previousBodyOverflowSetting = void 0;\nvar previousBodyPosition = void 0;\nvar previousBodyPaddingRight = void 0;\n\n// returns true if `el` should be allowed to receive touchmove events.\nvar allowTouchMove = function allowTouchMove(el) {\n return locks.some(function (lock) {\n if (lock.options.allowTouchMove && lock.options.allowTouchMove(el)) {\n return true;\n }\n\n return false;\n });\n};\n\nvar preventDefault = function preventDefault(rawEvent) {\n var e = rawEvent || window.event;\n\n // For the case whereby consumers adds a touchmove event listener to document.\n // Recall that we do document.addEventListener('touchmove', preventDefault, { passive: false })\n // in disableBodyScroll - so if we provide this opportunity to allowTouchMove, then\n // the touchmove event on document will break.\n if (allowTouchMove(e.target)) {\n return true;\n }\n\n // Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).\n if (e.touches.length > 1) return true;\n\n if (e.preventDefault) e.preventDefault();\n\n return false;\n};\n\nvar setOverflowHidden = function setOverflowHidden(options) {\n // If previousBodyPaddingRight is already set, don't set it again.\n if (previousBodyPaddingRight === undefined) {\n var _reserveScrollBarGap = !!options && options.reserveScrollBarGap === true;\n var scrollBarGap = window.innerWidth - document.documentElement.clientWidth;\n\n if (_reserveScrollBarGap && scrollBarGap > 0) {\n var computedBodyPaddingRight = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'), 10);\n previousBodyPaddingRight = document.body.style.paddingRight;\n document.body.style.paddingRight = computedBodyPaddingRight + scrollBarGap + 'px';\n }\n }\n\n // If previousBodyOverflowSetting is already set, don't set it again.\n if (previousBodyOverflowSetting === undefined) {\n previousBodyOverflowSetting = document.body.style.overflow;\n document.body.style.overflow = 'hidden';\n }\n};\n\nvar restoreOverflowSetting = function restoreOverflowSetting() {\n if (previousBodyPaddingRight !== undefined) {\n document.body.style.paddingRight = previousBodyPaddingRight;\n\n // Restore previousBodyPaddingRight to undefined so setOverflowHidden knows it\n // can be set again.\n previousBodyPaddingRight = undefined;\n }\n\n if (previousBodyOverflowSetting !== undefined) {\n document.body.style.overflow = previousBodyOverflowSetting;\n\n // Restore previousBodyOverflowSetting to undefined\n // so setOverflowHidden knows it can be set again.\n previousBodyOverflowSetting = undefined;\n }\n};\n\nvar setPositionFixed = function setPositionFixed() {\n return window.requestAnimationFrame(function () {\n // If previousBodyPosition is already set, don't set it again.\n if (previousBodyPosition === undefined) {\n previousBodyPosition = {\n position: document.body.style.position,\n top: document.body.style.top,\n left: document.body.style.left\n };\n\n // Update the dom inside an animation frame \n var _window = window,\n scrollY = _window.scrollY,\n scrollX = _window.scrollX,\n innerHeight = _window.innerHeight;\n\n document.body.style.position = 'fixed';\n document.body.style.top = -scrollY;\n document.body.style.left = -scrollX;\n\n setTimeout(function () {\n return window.requestAnimationFrame(function () {\n // Attempt to check if the bottom bar appeared due to the position change\n var bottomBarHeight = innerHeight - window.innerHeight;\n if (bottomBarHeight && scrollY >= innerHeight) {\n // Move the content further up so that the bottom bar doesn't hide it\n document.body.style.top = -(scrollY + bottomBarHeight);\n }\n });\n }, 300);\n }\n });\n};\n\nvar restorePositionSetting = function restorePositionSetting() {\n if (previousBodyPosition !== undefined) {\n // Convert the position from \"px\" to Int\n var y = -parseInt(document.body.style.top, 10);\n var x = -parseInt(document.body.style.left, 10);\n\n // Restore styles\n document.body.style.position = previousBodyPosition.position;\n document.body.style.top = previousBodyPosition.top;\n document.body.style.left = previousBodyPosition.left;\n\n // Restore scroll\n window.scrollTo(x, y);\n\n previousBodyPosition = undefined;\n }\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions\nvar isTargetElementTotallyScrolled = function isTargetElementTotallyScrolled(targetElement) {\n return targetElement ? targetElement.scrollHeight - targetElement.scrollTop <= targetElement.clientHeight : false;\n};\n\nvar handleScroll = function handleScroll(event, targetElement) {\n var clientY = event.targetTouches[0].clientY - initialClientY;\n\n if (allowTouchMove(event.target)) {\n return false;\n }\n\n if (targetElement && targetElement.scrollTop === 0 && clientY > 0) {\n // element is at the top of its scroll.\n return preventDefault(event);\n }\n\n if (isTargetElementTotallyScrolled(targetElement) && clientY < 0) {\n // element is at the bottom of its scroll.\n return preventDefault(event);\n }\n\n event.stopPropagation();\n return true;\n};\n\nexport var disableBodyScroll = function disableBodyScroll(targetElement, options) {\n // targetElement must be provided\n if (!targetElement) {\n // eslint-disable-next-line no-console\n console.error('disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.');\n return;\n }\n\n // disableBodyScroll must not have been called on this targetElement before\n if (locks.some(function (lock) {\n return lock.targetElement === targetElement;\n })) {\n return;\n }\n\n var lock = {\n targetElement: targetElement,\n options: options || {}\n };\n\n locks = [].concat(_toConsumableArray(locks), [lock]);\n\n if (isIosDevice) {\n setPositionFixed();\n } else {\n setOverflowHidden(options);\n }\n\n if (isIosDevice) {\n targetElement.ontouchstart = function (event) {\n if (event.targetTouches.length === 1) {\n // detect single touch.\n initialClientY = event.targetTouches[0].clientY;\n }\n };\n targetElement.ontouchmove = function (event) {\n if (event.targetTouches.length === 1) {\n // detect single touch.\n handleScroll(event, targetElement);\n }\n };\n\n if (!documentListenerAdded) {\n document.addEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);\n documentListenerAdded = true;\n }\n }\n};\n\nexport var clearAllBodyScrollLocks = function clearAllBodyScrollLocks() {\n if (isIosDevice) {\n // Clear all locks ontouchstart/ontouchmove handlers, and the references.\n locks.forEach(function (lock) {\n lock.targetElement.ontouchstart = null;\n lock.targetElement.ontouchmove = null;\n });\n\n if (documentListenerAdded) {\n document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);\n documentListenerAdded = false;\n }\n\n // Reset initial clientY.\n initialClientY = -1;\n }\n\n if (isIosDevice) {\n restorePositionSetting();\n } else {\n restoreOverflowSetting();\n }\n\n locks = [];\n};\n\nexport var enableBodyScroll = function enableBodyScroll(targetElement) {\n if (!targetElement) {\n // eslint-disable-next-line no-console\n console.error('enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.');\n return;\n }\n\n locks = locks.filter(function (lock) {\n return lock.targetElement !== targetElement;\n });\n\n if (isIosDevice) {\n targetElement.ontouchstart = null;\n targetElement.ontouchmove = null;\n\n if (documentListenerAdded && locks.length === 0) {\n document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined);\n documentListenerAdded = false;\n }\n }\n\n if (isIosDevice) {\n restorePositionSetting();\n } else {\n restoreOverflowSetting();\n }\n};\n\n","// Save the clicked overlay link element for use down the line\naddEventListener(\"click\", event => {\n window._overlasticAnchor = event.target.closest(\"a[data-turbo-frame^=overlay]\")\n}, true)\n\n// Allow progressive enhancement by telling the server if a request is handled by Turbo\naddEventListener(\"turbo:before-fetch-request\", event => {\n event.detail.fetchOptions.headers[\"Overlay-Enabled\"] = \"1\"\n})\n\n// When an overlay anchor is clicked,\n// send its type, target and args along with the frame request\naddEventListener(\"turbo:before-fetch-request\", event => {\n if (!window._overlasticAnchor) return\n\n const anchor = window._overlasticAnchor\n const type = anchor?.dataset?.overlayType\n const target = anchor?.dataset?.overlayTarget\n const args = anchor?.dataset?.overlayArgs\n\n event.detail.fetchOptions.headers[\"Overlay-Initiator\"] = \"1\"\n\n if (type) {\n event.detail.fetchOptions.headers[\"Overlay-Type\"] = type\n }\n\n if (target) {\n event.detail.fetchOptions.headers[\"Overlay-Target\"] = target\n }\n\n if (args) {\n event.detail.fetchOptions.headers[\"Overlay-Args\"] = args\n }\n\n delete window._overlasticTarget\n})\n\n// When any other element triggers a fetch,\n// send the current overlay's target along with the frame request\naddEventListener(\"turbo:before-fetch-request\", event => {\n if (window._overlasticAnchor) return\n\n const frame = event.target.closest(\"turbo-frame[id^=overlay]\")\n\n if (frame) {\n const target = frame.dataset.overlayTarget\n const initiator = frame.dataset?.overlayInitiator\n const type = frame.dataset?.overlayType\n const args = frame.dataset?.overlayArgs\n\n event.detail.fetchOptions.headers[\"Overlay-Target\"] = target\n\n if (initiator) {\n event.detail.fetchOptions.headers[\"Overlay-Initiator\"] = initiator\n }\n\n if (type) {\n event.detail.fetchOptions.headers[\"Overlay-Type\"] = type\n }\n\n if (args) {\n event.detail.fetchOptions.headers[\"Overlay-Args\"] = args\n }\n }\n})\n\n// Handle frame-to-visit promotions when the server asks for it\naddEventListener(\"turbo:before-fetch-response\", async event => {\n const fetchResponse = event.detail.fetchResponse\n const visit = fetchResponse.response.headers.get(\"Overlay-Visit\")\n\n if (!visit) return\n\n const responseHTML = await fetchResponse.responseHTML\n const { redirected, statusCode } = fetchResponse\n\n return Turbo.session.visit(visit, { shouldCacheSnapshot: false, response: { redirected, statusCode, responseHTML } })\n})\n","export default class DialogElement extends HTMLElement {\n connectedCallback() {\n disableBodyScroll(this)\n\n this.addEventListener(\"click\", event => this.close(event, true))\n this.querySelector(\".overlastic-close\").addEventListener(\"click\", event => this.close(event))\n }\n\n close(event, self = false) {\n if (self && event.target !== this) return\n\n enableBodyScroll(this)\n\n // Avoid removing before sending dispatching other events (like form submissions)\n setTimeout(() => {\n this.remove()\n }, 5)\n }\n}\n\ncustomElements.define(\"overlastic-dialog\", DialogElement)\n","import DialogElement from \"./dialogElement\"\n\nclass PaneElement extends DialogElement {\n connectedCallback() {\n super.connectedCallback()\n\n const lastVisit = Turbo.navigator.history.location\n\n if (!window.modalVisitStack) {\n window.modalVisitStack = []\n }\n\n window.modalVisitStack.push(lastVisit)\n Turbo.navigator.history.push(new URL(this.parentElement.src))\n }\n\n close(event, self = false) {\n if (self && event.target !== this) return\n\n super.close(event, self)\n\n if (window.modalVisitStack.length > 0) {\n Turbo.navigator.history.replace(window.modalVisitStack.pop())\n }\n }\n}\n\ncustomElements.define(\"overlastic-pane\", PaneElement)\n","import { disableBodyScroll, enableBodyScroll } from \"body-scroll-lock\"\n\nimport \"./clickInterceptor\"\nimport \"./dialogElement\"\nimport \"./paneElement\"\n\nwindow.disableBodyScroll = disableBodyScroll\nwindow.enableBodyScroll = enableBodyScroll\n"],"names":["hasPassiveEvents","window","passiveTestOptions","passive","addEventListener","removeEventListener","isIosDevice","navigator","platform","test","maxTouchPoints","locks","documentListenerAdded","initialClientY","previousBodyOverflowSetting","previousBodyPosition","previousBodyPaddingRight","allowTouchMove","el","some","lock","options","preventDefault","rawEvent","e","event","target","touches","length","_overlasticAnchor","closest","detail","fetchOptions","headers","anchor","type","dataset","overlayType","overlayTarget","args","overlayArgs","_overlasticTarget","frame","initiator","overlayInitiator","async","fetchResponse","visit","response","get","responseHTML","redirected","statusCode","Turbo","session","shouldCacheSnapshot","DialogElement","HTMLElement","[object Object]","disableBodyScroll","this","close","querySelector","self","enableBodyScroll","setTimeout","remove","customElements","define","super","connectedCallback","lastVisit","history","location","modalVisitStack","push","URL","parentElement","src","replace","pop","targetElement","concat","arr","Array","isArray","i","arr2","from","_toConsumableArray","requestAnimationFrame","undefined","position","document","body","style","top","left","_window","scrollY","scrollX","innerHeight","bottomBarHeight","_reserveScrollBarGap","reserveScrollBarGap","scrollBarGap","innerWidth","documentElement","clientWidth","computedBodyPaddingRight","parseInt","getComputedStyle","getPropertyValue","paddingRight","overflow","setOverflowHidden","ontouchstart","targetTouches","clientY","ontouchmove","scrollTop","scrollHeight","clientHeight","isTargetElementTotallyScrolled","stopPropagation","handleScroll","console","error","filter","y","x","scrollTo","restorePositionSetting"],"mappings":"AAOA,IAAIA,GAAmB,EACvB,GAAsB,oBAAXC,OAAwB,CACjC,IAAIC,EAAqB,CACvBC,cACEH,GAAmB,IAIvBC,OAAOG,iBAAiB,cAAe,KAAMF,GAC7CD,OAAOI,oBAAoB,cAAe,KAAMH,GAGlD,IAAII,EAAgC,oBAAXL,QAA0BA,OAAOM,WAAaN,OAAOM,UAAUC,WAAa,iBAAiBC,KAAKR,OAAOM,UAAUC,WAA2C,aAA9BP,OAAOM,UAAUC,UAA2BP,OAAOM,UAAUG,eAAiB,GAGnOC,EAAQ,GACRC,GAAwB,EACxBC,GAAkB,EAClBC,OAA8B,EAC9BC,OAAuB,EACvBC,OAA2B,EAG3BC,EAAiB,SAAwBC,GAC3C,OAAOP,EAAMQ,MAAK,SAAUC,GAC1B,SAAIA,EAAKC,QAAQJ,iBAAkBG,EAAKC,QAAQJ,eAAeC,QAQ/DI,EAAiB,SAAwBC,GAC3C,IAAIC,EAAID,GAAYtB,OAAOwB,MAM3B,QAAIR,EAAeO,EAAEE,UAKjBF,EAAEG,QAAQC,OAAS,IAEnBJ,EAAEF,gBAAgBE,EAAEF,kBAEjB,KCvDTlB,iBAAiB,SAASqB,IACxBxB,OAAO4B,kBAAoBJ,EAAMC,OAAOI,QAAQ,mCAC/C,GAGH1B,iBAAiB,8BAA8BqB,IAC7CA,EAAMM,OAAOC,aAAaC,QAAQ,mBAAqB,OAKzD7B,iBAAiB,8BAA8BqB,IAC7C,IAAKxB,OAAO4B,kBAAmB,OAE/B,MAAMK,EAASjC,OAAO4B,kBAChBM,EAAOD,GAAQE,SAASC,YACxBX,EAASQ,G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AkBqC,EAAU,EAHtDhG,EAAeG,GAQxBA,EAAMmG,mBA0CAC,CAAapG,EAAOwD,IAInBrE,IACHiF,SAASzF,iBAAiB,YAAakB,EAAgBtB,EAAmB,CAAEG,SAAS,QAAUwF,GAC/F/E,GAAwB,UAxC1BkH,QAAQC,MAAM,mHI5KlB9H,OAAO+D,iBJmPuB,SAA0BiB,GACjDA,GAMLtE,EAAQA,EAAMqH,QAAO,SAAU5G,GAC7B,OAAOA,EAAK6D,gBAAkBA,KAG5B3E,IACF2E,EAAcmC,aAAe,KAC7BnC,EAAcsC,YAAc,KAExB3G,GAA0C,IAAjBD,EAAMiB,SACjCiE,SAASxF,oBAAoB,YAAaiB,EAAgBtB,EAAmB,CAAEG,SAAS,QAAUwF,GAClG/E,GAAwB,IAIxBN,EA5IuB,WAC3B,QAA6BqF,IAAzB5E,EAAoC,CAEtC,IAAIkH,GAAKnB,SAASjB,SAASC,KAAKC,MAAMC,IAAK,IACvCkC,GAAKpB,SAASjB,SAASC,KAAKC,MAAME,KAAM,IAG5CJ,SAASC,KAAKC,MAAMH,SAAW7E,EAAqB6E,SACpDC,SAASC,KAAKC,MAAMC,IAAMjF,EAAqBiF,IAC/CH,SAASC,KAAKC,MAAME,KAAOlF,EAAqBkF,KAGhDhG,OAAOkI,SAASD,EAAGD,GAEnBlH,OAAuB4E,GA+HvByC,SAhM+BzC,IAA7B3E,IACF6E,SAASC,KAAKC,MAAMkB,aAAejG,EAInCA,OAA2B2E,QAGOA,IAAhC7E,IACF+E,SAASC,KAAKC,MAAMmB,SAAWpG,EAI/BA,OAA8B6E,KAgK9BmC,QAAQC,MAAM"}
|
@@ -10,25 +10,85 @@ module Overlastic::Concerns::OverlayHandling
|
|
10
10
|
request.variant = :overlay if helpers.current_overlay_name.present?
|
11
11
|
end
|
12
12
|
|
13
|
+
def close_overlay(key = :last)
|
14
|
+
overlay_name = helpers.overlay_name_from key
|
15
|
+
|
16
|
+
render overlay: overlay_name, html: helpers.overlastic_tag(id: helpers.current_overlay_name)
|
17
|
+
end
|
18
|
+
|
13
19
|
def render(*args, &block)
|
14
|
-
|
15
|
-
|
20
|
+
options = args.last || {}
|
21
|
+
|
22
|
+
# Force render of overlays without an initiator
|
23
|
+
request.headers["Overlay-Target"] ||= options.delete(:overlay_target)
|
24
|
+
request.headers["Overlay-Type"] ||= options.delete(:overlay_type)
|
25
|
+
request.headers["Overlay-Args"] ||= options.delete(:overlay_args)&.to_json
|
26
|
+
|
27
|
+
# Force visit to the desired redirection location
|
28
|
+
response.headers["Overlay-Visit"] ||= options.delete(:redirect)
|
16
29
|
|
17
|
-
|
18
|
-
|
30
|
+
# Rendering with an error status should render inside the overlay
|
31
|
+
error = Rack::Utils.status_code(options[:status]).in? 400..499
|
19
32
|
|
20
|
-
|
21
|
-
|
33
|
+
# No enhancements should be made unless the client is using Turbo
|
34
|
+
overlastic_enabled = request.headers["Overlay-Enabled"]
|
22
35
|
|
23
|
-
|
24
|
-
|
36
|
+
# Initiator requests always render inside an overlay
|
37
|
+
initiator = request.headers["Overlay-Initiator"]
|
25
38
|
|
39
|
+
# By default, navigation inside the overlay will break out of it (_top)
|
40
|
+
target = request.headers["Overlay-Target"]
|
41
|
+
|
42
|
+
# Name of the overlay to be used
|
43
|
+
overlay = options.delete :overlay
|
44
|
+
overlay_name = helpers.overlay_name_from(overlay || helpers.current_overlay_name)
|
45
|
+
|
46
|
+
if overlay && overlastic_enabled
|
47
|
+
options[:layout] = false
|
48
|
+
|
49
|
+
if block_given? || options[:html]
|
50
|
+
super turbo_stream: turbo_stream.replace(overlay_name, html: render_to_string(*args, &block))
|
51
|
+
else
|
52
|
+
super turbo_stream: turbo_stream.replace(overlay_name, html: helpers.render_overlay { render_to_string(*args, &block) })
|
53
|
+
end
|
54
|
+
elsif request.variant.overlay?
|
26
55
|
if initiator || error || target != "_top"
|
27
|
-
super turbo_stream: turbo_stream.replace(
|
56
|
+
super turbo_stream: turbo_stream.replace(overlay_name, html: helpers.render_overlay { render_to_string(*args, &block) })
|
28
57
|
else
|
29
58
|
request.headers["Turbo-Frame"] = nil
|
30
|
-
response.headers["Overlay-Visit"] =
|
59
|
+
response.headers["Overlay-Visit"] = request.fullpath
|
60
|
+
|
61
|
+
super
|
62
|
+
end
|
63
|
+
else
|
64
|
+
super
|
65
|
+
end
|
66
|
+
end
|
31
67
|
|
68
|
+
# Based on https://github.com/hotwired/turbo-rails/pull/367
|
69
|
+
# by seanpdoyle
|
70
|
+
def redirect_to(options = {}, response_options = {})
|
71
|
+
location = url_for options
|
72
|
+
overlay = response_options.delete :overlay
|
73
|
+
overlay_name = helpers.overlay_name_from overlay
|
74
|
+
|
75
|
+
if request.variant.overlay?
|
76
|
+
if overlay_name.present?
|
77
|
+
unless helpers.valid_overlay_name? overlay_name
|
78
|
+
return render overlay: helpers.current_overlay_name, redirect: location, html: helpers.overlastic_tag(id: helpers.current_overlay_name)
|
79
|
+
end
|
80
|
+
|
81
|
+
request.variant.delete :overlay
|
82
|
+
flash.merge! response_options.fetch :flash, {}
|
83
|
+
|
84
|
+
case Rack::Utils.status_code(response_options.fetch(:status, :created))
|
85
|
+
when 300..399 then response_options[:status] = :created
|
86
|
+
end
|
87
|
+
|
88
|
+
render "overlastic/streams/redirect", response_options.with_defaults(
|
89
|
+
locals: { location: location, overlay: overlay_name }
|
90
|
+
)
|
91
|
+
else
|
32
92
|
super
|
33
93
|
end
|
34
94
|
else
|
@@ -51,11 +51,11 @@ module Overlastic::NavigationHelper
|
|
51
51
|
def turbo_frame_from_overlastic_action(action)
|
52
52
|
case action
|
53
53
|
when :stack
|
54
|
-
|
54
|
+
overlay_name_from :next
|
55
55
|
when :replace_last
|
56
|
-
|
56
|
+
overlay_name_from :current
|
57
57
|
when :replace_all
|
58
|
-
:
|
58
|
+
overlay_name_from :first
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Overlastic::OverlaysHelper
|
2
|
-
def overlastic_tag
|
2
|
+
def overlastic_tag(id: :overlay1)
|
3
3
|
if block_given?
|
4
4
|
type = request.headers["Overlay-Type"]
|
5
|
-
target = request.headers["Overlay-Target"] ||
|
5
|
+
target = request.headers["Overlay-Target"] || Overlastic.configuration.default_target
|
6
6
|
args = request.headers["Overlay-Args"]
|
7
7
|
|
8
|
-
turbo_frame_tag current_overlay_name, data: { overlay_type: type, overlay_target: target, overlay_args: args } do
|
8
|
+
turbo_frame_tag current_overlay_name || id, data: { overlay_type: type, overlay_target: target, overlay_args: args } do
|
9
9
|
yield
|
10
10
|
|
11
|
-
concat turbo_frame_tag(
|
11
|
+
concat turbo_frame_tag(overlay_name_from(:next), data: { overlay_target: Overlastic.configuration.default_target })
|
12
12
|
end
|
13
13
|
else
|
14
|
-
turbo_frame_tag
|
14
|
+
turbo_frame_tag id, data: { overlay_target: Overlastic.configuration.default_target }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -21,10 +21,25 @@ module Overlastic::OverlaysHelper
|
|
21
21
|
request.headers["Turbo-Frame"].to_sym
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def overlay_name_from(key)
|
25
25
|
current_number = current_overlay_name.to_s.scan(/\d+/)&.first.to_i
|
26
26
|
|
27
|
-
|
27
|
+
case key
|
28
|
+
when :first, :all
|
29
|
+
:overlay1
|
30
|
+
when :last, :current
|
31
|
+
current_overlay_name
|
32
|
+
when :previous
|
33
|
+
:"overlay#{current_number - 1}"
|
34
|
+
when :next
|
35
|
+
:"overlay#{current_number + 1}"
|
36
|
+
else
|
37
|
+
key
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_overlay_name?(name)
|
42
|
+
name.to_s.scan(/\d+/)&.first&.to_i&.positive?
|
28
43
|
end
|
29
44
|
|
30
45
|
def render_overlay(locals = {}, &block)
|
@@ -3,6 +3,11 @@ addEventListener("click", event => {
|
|
3
3
|
window._overlasticAnchor = event.target.closest("a[data-turbo-frame^=overlay]")
|
4
4
|
}, true)
|
5
5
|
|
6
|
+
// Allow progressive enhancement by telling the server if a request is handled by Turbo
|
7
|
+
addEventListener("turbo:before-fetch-request", event => {
|
8
|
+
event.detail.fetchOptions.headers["Overlay-Enabled"] = "1"
|
9
|
+
})
|
10
|
+
|
6
11
|
// When an overlay anchor is clicked,
|
7
12
|
// send its type, target and args along with the frame request
|
8
13
|
addEventListener("turbo:before-fetch-request", event => {
|
@@ -39,11 +44,16 @@ addEventListener("turbo:before-fetch-request", event => {
|
|
39
44
|
|
40
45
|
if (frame) {
|
41
46
|
const target = frame.dataset.overlayTarget
|
47
|
+
const initiator = frame.dataset?.overlayInitiator
|
42
48
|
const type = frame.dataset?.overlayType
|
43
49
|
const args = frame.dataset?.overlayArgs
|
44
50
|
|
45
51
|
event.detail.fetchOptions.headers["Overlay-Target"] = target
|
46
52
|
|
53
|
+
if (initiator) {
|
54
|
+
event.detail.fetchOptions.headers["Overlay-Initiator"] = initiator
|
55
|
+
}
|
56
|
+
|
47
57
|
if (type) {
|
48
58
|
event.detail.fetchOptions.headers["Overlay-Type"] = type
|
49
59
|
}
|
@@ -57,11 +67,12 @@ addEventListener("turbo:before-fetch-request", event => {
|
|
57
67
|
// Handle frame-to-visit promotions when the server asks for it
|
58
68
|
addEventListener("turbo:before-fetch-response", async event => {
|
59
69
|
const fetchResponse = event.detail.fetchResponse
|
70
|
+
const visit = fetchResponse.response.headers.get("Overlay-Visit")
|
60
71
|
|
61
|
-
if (!
|
72
|
+
if (!visit) return
|
62
73
|
|
63
74
|
const responseHTML = await fetchResponse.responseHTML
|
64
|
-
const {
|
75
|
+
const { redirected, statusCode } = fetchResponse
|
65
76
|
|
66
|
-
return Turbo.session.visit(
|
77
|
+
return Turbo.session.visit(visit, { shouldCacheSnapshot: false, response: { redirected, statusCode, responseHTML } })
|
67
78
|
})
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= turbo_stream.append_all "head" do %>
|
2
|
+
<%= javascript_tag nonce: true do %>
|
3
|
+
frame = document.querySelector("turbo-frame[id=<%= escape_javascript overlay %>]")
|
4
|
+
|
5
|
+
frame.dataset.overlayInitiator = "1"
|
6
|
+
frame.src = "<%= escape_javascript location %>"
|
7
|
+
|
8
|
+
document.currentScript.remove()
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
@@ -10,5 +10,12 @@ class Overlastic::ViewsGenerator < Rails::Generators::Base
|
|
10
10
|
def copy_view_files
|
11
11
|
copy_file "#{options[:css]}/_dialog.html.erb", "app/views/overlays/_dialog.html.erb"
|
12
12
|
copy_file "#{options[:css]}/_pane.html.erb", "app/views/overlays/_pane.html.erb"
|
13
|
+
|
14
|
+
create_file "config/initializers/overlastic.rb", <<~RUBY
|
15
|
+
Overlastic.configure do |config|
|
16
|
+
config.dialog_overlay_view_path = "overlays/dialog"
|
17
|
+
config.pane_overlay_view_path = "overlays/pane"
|
18
|
+
end
|
19
|
+
RUBY
|
13
20
|
end
|
14
21
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Overlastic
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :overlay_types, :default_overlay, :default_action
|
3
|
+
attr_accessor :overlay_types, :default_overlay, :default_action, :default_target
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
self.overlay_types = %i[dialog pane]
|
7
7
|
self.default_overlay = :dialog
|
8
8
|
self.default_action = :stack
|
9
|
+
self.default_target = :_top
|
9
10
|
end
|
10
11
|
|
11
12
|
def overlay_types=(types)
|
data/lib/overlastic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overlastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Zamuner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- app/javascript/overlastic/paneElement.js
|
74
74
|
- app/views/overlastic/inline/_dialog.html.erb
|
75
75
|
- app/views/overlastic/inline/_pane.html.erb
|
76
|
+
- app/views/overlastic/streams/redirect.turbo_stream.erb
|
76
77
|
- app/views/overlastic/tailwind/_dialog.html.erb
|
77
78
|
- app/views/overlastic/tailwind/_pane.html.erb
|
78
79
|
- lib/generators/overlastic/views/USAGE
|