@brytdesigns/web-component-modal 1.1.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/components/index.js +4 -10
- package/dist/main/components/modal-backdrop.js +50 -76
- package/dist/main/components/modal-backdrop.js.map +1 -1
- package/dist/main/components/modal-context.js +125 -126
- package/dist/main/components/modal-context.js.map +1 -1
- package/dist/main/components/modal-panel.js +63 -70
- package/dist/main/components/modal-panel.js.map +1 -1
- package/dist/main/components/modal-trigger.js +83 -74
- package/dist/main/components/modal-trigger.js.map +1 -1
- package/dist/main/hooks/index.js +2 -3
- package/dist/main/hooks/useModal.js +86 -85
- package/dist/main/hooks/useModal.js.map +1 -1
- package/dist/main/index.d.ts +32 -30
- package/dist/main/index.js +28 -32
- package/dist/main/index.js.map +1 -1
- package/dist/main/utils.js +5 -4
- package/dist/main/utils.js.map +1 -1
- package/package.json +8 -9
- package/dist/esm/index.js +0 -493
- package/dist/esm/index.js.map +0 -1
- package/dist/main/components/index.js.map +0 -1
- package/dist/main/consts.js +0 -10
- package/dist/main/consts.js.map +0 -1
- package/dist/main/hooks/index.js.map +0 -1
package/dist/main/index.js
CHANGED
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { getModalContext, useModal, useModalAt } from "./hooks/useModal.js";
|
|
2
|
+
import "./hooks/index.js";
|
|
3
|
+
import { Component, Name } from "./components/modal-backdrop.js";
|
|
4
|
+
import { Component as Component$1, Name as Name$1 } from "./components/modal-context.js";
|
|
5
|
+
import { Component as Component$2, Name as Name$2 } from "./components/modal-panel.js";
|
|
6
|
+
import { Component as Component$3, Name as Name$3 } from "./components/modal-trigger.js";
|
|
7
|
+
import "./components/index.js";
|
|
8
|
+
import { customShadowlessElement } from "@brytdesigns/web-component-core/utils";
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
customShadowlessElement(Name$1, {
|
|
11
|
+
isOpen: false,
|
|
12
|
+
id: "",
|
|
13
|
+
closeOnEscape: true,
|
|
14
|
+
shouldTrapFocus: true,
|
|
15
|
+
isAnimating: false,
|
|
16
|
+
openAfterDelay: false,
|
|
17
|
+
delay: 0
|
|
18
|
+
}, Component$1);
|
|
19
|
+
customShadowlessElement(Name$3, {
|
|
20
|
+
target: "",
|
|
21
|
+
action: "",
|
|
22
|
+
on: "click",
|
|
23
|
+
preventDefault: true
|
|
24
|
+
}, Component$3);
|
|
25
|
+
customShadowlessElement(Name, {}, Component);
|
|
26
|
+
customShadowlessElement(Name$2, {}, Component$2);
|
|
27
|
+
//#endregion
|
|
28
|
+
export { getModalContext, useModal, useModalAt };
|
|
4
29
|
|
|
5
|
-
customShadowlessElement(
|
|
6
|
-
ModalContext.Name,
|
|
7
|
-
{
|
|
8
|
-
isOpen: false,
|
|
9
|
-
id: "",
|
|
10
|
-
closeOnEscape: false,
|
|
11
|
-
shouldTrapFocus: false,
|
|
12
|
-
isAnimating: false,
|
|
13
|
-
openAfterDelay: false,
|
|
14
|
-
delay: 0
|
|
15
|
-
},
|
|
16
|
-
correctElementType(ModalContext.Component)
|
|
17
|
-
);
|
|
18
|
-
customShadowlessElement(
|
|
19
|
-
ModalTrigger.Name,
|
|
20
|
-
{ target: "", action: "", on: "click", preventDefault: true },
|
|
21
|
-
correctElementType(ModalTrigger.Component)
|
|
22
|
-
);
|
|
23
|
-
customShadowlessElement(
|
|
24
|
-
ModalBackdrop.Name,
|
|
25
|
-
{},
|
|
26
|
-
correctElementType(ModalBackdrop.Component)
|
|
27
|
-
);
|
|
28
|
-
customShadowlessElement(
|
|
29
|
-
ModalPanel.Name,
|
|
30
|
-
{},
|
|
31
|
-
correctElementType(ModalPanel.Component)
|
|
32
|
-
);
|
|
33
|
-
//# sourceMappingURL=index.js.map
|
|
34
30
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { customShadowlessElement } from \"@brytdesigns/web-component-core/utils\";\n\nimport {\n\tModalBackdrop,\n\tModalContext,\n\tModalPanel,\n\tModalTrigger,\n} from \"./components/index.js\";\n\nexport type ModalTriggerProps = ModalTrigger.Props;\nexport type ModalBackdropProps = ModalBackdrop.Props;\nexport type ModalPanelProps = ModalPanel.Props;\nexport type ModalContextProps = ModalContext.Props;\n\ncustomShadowlessElement(\n\tModalContext.Name,\n\t{\n\t\tisOpen: false,\n\t\tid: \"\",\n\t\t// On by default: an overlay that traps nothing and closes on no key is\n\t\t// not a dialog. Set close-on-escape=\"false\" / should-trap-focus=\"false\"\n\t\t// in markup to opt out.\n\t\tcloseOnEscape: true,\n\t\tshouldTrapFocus: true,\n\t\tisAnimating: false,\n\t\topenAfterDelay: false,\n\t\tdelay: 0,\n\t},\n\tModalContext.Component,\n);\n\ncustomShadowlessElement(\n\tModalTrigger.Name,\n\t{ target: \"\", action: \"\", on: \"click\", preventDefault: true },\n\tModalTrigger.Component,\n);\n\ncustomShadowlessElement(ModalBackdrop.Name, {}, ModalBackdrop.Component);\n\ncustomShadowlessElement(ModalPanel.Name, {}, ModalPanel.Component);\n\nexport {\n\tgetModalContext,\n\tuseModal,\n\tuseModalAt,\n} from \"./hooks/index.js\";\n"],"mappings":";;;;;;;;;AAcA,wBACC,QACA;CACC,QAAQ;CACR,IAAI;CAIJ,eAAe;CACf,iBAAiB;CACjB,aAAa;CACb,gBAAgB;CAChB,OAAO;AACR,GACA,WACD;AAEA,wBACC,QACA;CAAE,QAAQ;CAAI,QAAQ;CAAI,IAAI;CAAS,gBAAgB;AAAK,GAC5D,WACD;AAEA,wBAAwB,MAAoB,CAAC,GAAG,SAAuB;AAEvE,wBAAwB,QAAiB,CAAC,GAAG,WAAoB"}
|
package/dist/main/utils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
1
2
|
function hideElement(element) {
|
|
2
|
-
|
|
3
|
+
element.style.display = "none";
|
|
3
4
|
}
|
|
4
5
|
function showElement(element) {
|
|
5
|
-
|
|
6
|
+
element.style.display = "block";
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
//#endregion
|
|
8
9
|
export { hideElement, showElement };
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
//# sourceMappingURL=utils.js.map
|
package/dist/main/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["export function hideElement<T extends HTMLElement>(element: T) {\n\telement.style.display = \"none\";\n}\n\nexport function showElement<T extends HTMLElement>(element: T) {\n\telement.style.display = \"block\";\n}\n"],"mappings":";AAAA,SAAgB,YAAmC,SAAY;CAC9D,QAAQ,MAAM,UAAU;AACzB;AAEA,SAAgB,YAAmC,SAAY;CAC9D,QAAQ,MAAM,UAAU;AACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brytdesigns/web-component-modal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Headless modal web component",
|
|
5
5
|
"main": "./dist/main/index.js",
|
|
6
6
|
"module": "./dist/main/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/main/index.d.ts",
|
|
12
|
-
"
|
|
12
|
+
"default": "./dist/main/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
@@ -19,20 +19,19 @@
|
|
|
19
19
|
"author": "Bryt Designs",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@brytdesigns/web-component-core": "3.0.0",
|
|
22
23
|
"body-scroll-lock-upgrade": "^1.1.0",
|
|
23
24
|
"component-register": "0.8.7",
|
|
24
|
-
"motion": "^12.
|
|
25
|
+
"motion": "^12.43.0",
|
|
25
26
|
"observe-element-in-viewport": "^0.0.15",
|
|
26
|
-
"solid-
|
|
27
|
-
"solid-js": "^1.9.9",
|
|
28
|
-
"@brytdesigns/web-component-core": "1.1.6"
|
|
27
|
+
"solid-js": "2.0.0-rc.14"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"@repo/vite-config": "0.0.0",
|
|
31
|
+
"vite": "^8.2.2"
|
|
33
32
|
},
|
|
34
33
|
"scripts": {
|
|
35
|
-
"build": "
|
|
34
|
+
"build": "vite build",
|
|
36
35
|
"typecheck": "tsc --noEmit"
|
|
37
36
|
}
|
|
38
37
|
}
|
package/dist/esm/index.js
DELETED
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
import { createWithElementContext, customShadowlessElement, correctElementType, toHyphenated, getContextFromProvider, disableBodyScroll, enableBodyScroll } from '@brytdesigns/web-component-core/utils';
|
|
2
|
-
import { splitProps, createEffect, on, batch, onCleanup, untrack, mergeProps, onMount } from 'solid-js';
|
|
3
|
-
import { animate } from 'motion';
|
|
4
|
-
import { awaitAllAnimations, getTransitionConfig } from '@brytdesigns/web-component-core/animation';
|
|
5
|
-
import { createContext, consume, provide } from 'component-register';
|
|
6
|
-
import { createStore } from 'solid-js/store';
|
|
7
|
-
import { abortablePromise } from '@brytdesigns/web-component-core/promise';
|
|
8
|
-
import { observeElementInViewport } from 'observe-element-in-viewport';
|
|
9
|
-
import { createFocusTrap } from '@brytdesigns/web-component-core/focusTrap';
|
|
10
|
-
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __export = (target, all) => {
|
|
13
|
-
for (var name in all)
|
|
14
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// src/components/modal-panel.ts
|
|
18
|
-
var modal_panel_exports = {};
|
|
19
|
-
__export(modal_panel_exports, {
|
|
20
|
-
Component: () => Component,
|
|
21
|
-
Name: () => Name
|
|
22
|
-
});
|
|
23
|
-
function initializeModalContext(props) {
|
|
24
|
-
const [element, stateProps] = splitProps(props, ["root"]);
|
|
25
|
-
const [store, setStore] = createStore({ animationQueue: [] });
|
|
26
|
-
createEffect(
|
|
27
|
-
on(
|
|
28
|
-
() => store.animationQueue,
|
|
29
|
-
(animationQueue) => {
|
|
30
|
-
if (!animationQueue.length) return;
|
|
31
|
-
const controller = new AbortController();
|
|
32
|
-
const animations = awaitAllAnimations(animationQueue);
|
|
33
|
-
const abortableAnimations = abortablePromise(
|
|
34
|
-
animations,
|
|
35
|
-
controller.signal
|
|
36
|
-
);
|
|
37
|
-
setElementState("isAnimating", true);
|
|
38
|
-
abortableAnimations.finally(() => {
|
|
39
|
-
batch(() => {
|
|
40
|
-
setElementState("isAnimating", false);
|
|
41
|
-
setStore("animationQueue", []);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
return onCleanup(() => {
|
|
45
|
-
controller.abort("Aborting modal animations");
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
function setElementState(key, value) {
|
|
51
|
-
const currentValue = untrack(() => props[key]);
|
|
52
|
-
if (typeof value === "function") {
|
|
53
|
-
const currentValue2 = untrack(() => props[key]);
|
|
54
|
-
const result = value(currentValue2 || false);
|
|
55
|
-
if (`${currentValue2}` === `${value}`) return;
|
|
56
|
-
element.root.setAttribute(toHyphenated(key), `${result}`);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (`${currentValue}` === `${value}`) return;
|
|
60
|
-
return element.root.setAttribute(toHyphenated(key), `${value}`);
|
|
61
|
-
}
|
|
62
|
-
return [
|
|
63
|
-
mergeProps(store, stateProps),
|
|
64
|
-
{ setElementState, setStore }
|
|
65
|
-
];
|
|
66
|
-
}
|
|
67
|
-
var ModalContextState = createContext(initializeModalContext);
|
|
68
|
-
var provideModalContext = (initialState, element) => {
|
|
69
|
-
const props = mergeProps(initialState, { root: element });
|
|
70
|
-
return provide(ModalContextState, props, element);
|
|
71
|
-
};
|
|
72
|
-
var useModalContext = (context) => {
|
|
73
|
-
const [state, { setElementState, setStore: setState }] = context;
|
|
74
|
-
function updateAnimationQueue(animation) {
|
|
75
|
-
setState("animationQueue", (state2) => [...state2, animation]);
|
|
76
|
-
}
|
|
77
|
-
function close() {
|
|
78
|
-
setElementState("isOpen", false);
|
|
79
|
-
}
|
|
80
|
-
function open() {
|
|
81
|
-
setElementState("isOpen", true);
|
|
82
|
-
}
|
|
83
|
-
function toggle() {
|
|
84
|
-
setElementState("isOpen", (open2) => !open2);
|
|
85
|
-
}
|
|
86
|
-
return [state, { updateAnimationQueue, close, open, toggle }];
|
|
87
|
-
};
|
|
88
|
-
var useModal = (element) => {
|
|
89
|
-
const context = consume(ModalContextState, element);
|
|
90
|
-
if (!context) {
|
|
91
|
-
throw console.error(
|
|
92
|
-
"ModalContext not found! Please ensure to wrap your custom element with modal-context element."
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return useModalContext(context);
|
|
96
|
-
};
|
|
97
|
-
var withModalElementContext = createWithElementContext(ModalContextState);
|
|
98
|
-
var getModalContext = (element) => {
|
|
99
|
-
const context = getContextFromProvider(
|
|
100
|
-
ModalContextState,
|
|
101
|
-
element
|
|
102
|
-
);
|
|
103
|
-
return useModalContext(context);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// src/components/modal-panel.ts
|
|
107
|
-
var Name = "modal-panel";
|
|
108
|
-
var Component = (_, { element }) => {
|
|
109
|
-
const [state, { updateAnimationQueue }] = useModal(element);
|
|
110
|
-
let isFirstRender = true;
|
|
111
|
-
createEffect(
|
|
112
|
-
on(
|
|
113
|
-
() => state.isOpen,
|
|
114
|
-
(isOpen) => {
|
|
115
|
-
if (!isOpen || isFirstRender) return;
|
|
116
|
-
const animation = enter(element);
|
|
117
|
-
updateAnimationQueue(animation);
|
|
118
|
-
return onCleanup(() => {
|
|
119
|
-
if (animation.state !== "finished") animation.complete();
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
)
|
|
123
|
-
);
|
|
124
|
-
createEffect(
|
|
125
|
-
on(
|
|
126
|
-
() => state.isOpen,
|
|
127
|
-
(isOpen) => {
|
|
128
|
-
if (isOpen || isFirstRender) return;
|
|
129
|
-
const animation = exit(element);
|
|
130
|
-
updateAnimationQueue(animation);
|
|
131
|
-
return onCleanup(() => {
|
|
132
|
-
if (animation.state !== "finished") animation.complete();
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
)
|
|
136
|
-
);
|
|
137
|
-
onMount(() => {
|
|
138
|
-
isFirstRender = false;
|
|
139
|
-
});
|
|
140
|
-
function enter(element2) {
|
|
141
|
-
const style = window.getComputedStyle(element2);
|
|
142
|
-
const transition = getTransitionConfig(style);
|
|
143
|
-
return animate(
|
|
144
|
-
element2,
|
|
145
|
-
{
|
|
146
|
-
x: [`var(--${Name}--slide-x-from)`, `var(--${Name}--slide-x-to)`],
|
|
147
|
-
y: [`var(--${Name}--slide-y-from)`, `var(--${Name}--slide-y-to)`],
|
|
148
|
-
scaleY: [`var(--${Name}--scale-y-from)`, `var(--${Name}--scale-y-to)`],
|
|
149
|
-
scaleX: [`var(--${Name}--scale-x-from)`, `var(--${Name}--scale-x-to)`],
|
|
150
|
-
opacity: [`var(--${Name}--opacity-from)`, `var(--${Name}--opacity-to)`]
|
|
151
|
-
},
|
|
152
|
-
transition
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
function exit(element2) {
|
|
156
|
-
const style = window.getComputedStyle(element2);
|
|
157
|
-
const transition = getTransitionConfig(style);
|
|
158
|
-
return animate(
|
|
159
|
-
element2,
|
|
160
|
-
{
|
|
161
|
-
x: [`var(--${Name}--slide-x-to)`, `var(--${Name}--slide-x-from)`],
|
|
162
|
-
y: [`var(--${Name}--slide-y-to)`, `var(--${Name}--slide-y-from)`],
|
|
163
|
-
scaleY: [`var(--${Name}--scale-y-to)`, `var(--${Name}--scale-y-from)`],
|
|
164
|
-
scaleX: [`var(--${Name}--scale-x-to)`, `var(--${Name}--scale-x-from)`],
|
|
165
|
-
opacity: [`var(--${Name}--opacity-to)`, `var(--${Name}--opacity-from)`]
|
|
166
|
-
},
|
|
167
|
-
transition
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
// src/components/modal-trigger.ts
|
|
173
|
-
var modal_trigger_exports = {};
|
|
174
|
-
__export(modal_trigger_exports, {
|
|
175
|
-
Component: () => Component2,
|
|
176
|
-
Name: () => Name2
|
|
177
|
-
});
|
|
178
|
-
var Name2 = "modal-trigger";
|
|
179
|
-
var Component2 = (props, { element }) => {
|
|
180
|
-
withModalElementContext(
|
|
181
|
-
() => props.target || "",
|
|
182
|
-
() => ({
|
|
183
|
-
on: props.on,
|
|
184
|
-
action: props.action,
|
|
185
|
-
preventDefault: props.preventDefault
|
|
186
|
-
}),
|
|
187
|
-
(context, { on: on5, action, preventDefault }) => {
|
|
188
|
-
const controller = new AbortController();
|
|
189
|
-
const [state, { open, close, toggle }] = useModalContext(context);
|
|
190
|
-
switch (on5) {
|
|
191
|
-
case "enter": {
|
|
192
|
-
let unsubscribe = null;
|
|
193
|
-
if (action === "toggle") {
|
|
194
|
-
unsubscribe = observeElementInViewport(element, open, close);
|
|
195
|
-
}
|
|
196
|
-
if (unsubscribe)
|
|
197
|
-
controller.signal.addEventListener("abort", unsubscribe, {
|
|
198
|
-
once: true
|
|
199
|
-
});
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
case "exit": {
|
|
203
|
-
let unsubscribe = null;
|
|
204
|
-
if (action === "toggle") {
|
|
205
|
-
unsubscribe = observeElementInViewport(element, close, open);
|
|
206
|
-
}
|
|
207
|
-
if (unsubscribe)
|
|
208
|
-
controller.signal.addEventListener("abort", unsubscribe, {
|
|
209
|
-
once: true
|
|
210
|
-
});
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
default: {
|
|
214
|
-
element.addEventListener(
|
|
215
|
-
//@ts-ignore
|
|
216
|
-
on5,
|
|
217
|
-
(event) => {
|
|
218
|
-
if (preventDefault) event.preventDefault();
|
|
219
|
-
if (state.isAnimating) return;
|
|
220
|
-
switch (action) {
|
|
221
|
-
case "close":
|
|
222
|
-
close();
|
|
223
|
-
break;
|
|
224
|
-
case "open":
|
|
225
|
-
open();
|
|
226
|
-
break;
|
|
227
|
-
case "toggle":
|
|
228
|
-
toggle();
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
{ signal: controller.signal }
|
|
233
|
-
);
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
createEffect(() => {
|
|
238
|
-
element.setAttribute("is-open", `${state.isOpen}`);
|
|
239
|
-
element.setAttribute("is-animating", `${state.isAnimating}`);
|
|
240
|
-
});
|
|
241
|
-
onCleanup(() => {
|
|
242
|
-
controller.abort();
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
// src/components/modal-backdrop.ts
|
|
249
|
-
var modal_backdrop_exports = {};
|
|
250
|
-
__export(modal_backdrop_exports, {
|
|
251
|
-
Component: () => Component3,
|
|
252
|
-
Name: () => Name3
|
|
253
|
-
});
|
|
254
|
-
var Name3 = "modal-backdrop";
|
|
255
|
-
var Component3 = (_, { element }) => {
|
|
256
|
-
const [state, { updateAnimationQueue, close }] = useModal(element);
|
|
257
|
-
const controller = new AbortController();
|
|
258
|
-
let isFirstRender = true;
|
|
259
|
-
createEffect(
|
|
260
|
-
on(
|
|
261
|
-
() => state.isOpen,
|
|
262
|
-
(isOpen) => {
|
|
263
|
-
if (!isOpen || isFirstRender) return;
|
|
264
|
-
const animation = enter(element);
|
|
265
|
-
updateAnimationQueue(animation);
|
|
266
|
-
return onCleanup(() => {
|
|
267
|
-
if (animation.state !== "finished") animation.complete();
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
)
|
|
271
|
-
);
|
|
272
|
-
createEffect(
|
|
273
|
-
on(
|
|
274
|
-
() => state.isOpen,
|
|
275
|
-
(isOpen) => {
|
|
276
|
-
if (isOpen || isFirstRender) return;
|
|
277
|
-
const animation = exit(element);
|
|
278
|
-
updateAnimationQueue(animation);
|
|
279
|
-
return onCleanup(() => {
|
|
280
|
-
if (animation.state !== "finished") animation.complete();
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
)
|
|
284
|
-
);
|
|
285
|
-
onMount(() => {
|
|
286
|
-
isFirstRender = false;
|
|
287
|
-
});
|
|
288
|
-
function enter(element2) {
|
|
289
|
-
const style = window.getComputedStyle(element2);
|
|
290
|
-
const options = getTransitionConfig(style);
|
|
291
|
-
return animate(
|
|
292
|
-
element2,
|
|
293
|
-
{
|
|
294
|
-
opacity: [`var(--${Name3}--opacity-from)`, `var(--${Name3}--opacity-to)`]
|
|
295
|
-
},
|
|
296
|
-
options
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
function exit(element2) {
|
|
300
|
-
const style = window.getComputedStyle(element2);
|
|
301
|
-
const options = getTransitionConfig(style);
|
|
302
|
-
return animate(
|
|
303
|
-
element2,
|
|
304
|
-
{
|
|
305
|
-
opacity: [`var(--${Name3}--opacity-to)`, `var(--${Name3}--opacity-from)`]
|
|
306
|
-
},
|
|
307
|
-
options
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
element.addEventListener(
|
|
311
|
-
"click",
|
|
312
|
-
() => {
|
|
313
|
-
if (state.isAnimating) return;
|
|
314
|
-
close();
|
|
315
|
-
},
|
|
316
|
-
{
|
|
317
|
-
signal: controller.signal
|
|
318
|
-
}
|
|
319
|
-
);
|
|
320
|
-
onCleanup(() => {
|
|
321
|
-
controller.abort();
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// src/components/modal-context.ts
|
|
326
|
-
var modal_context_exports = {};
|
|
327
|
-
__export(modal_context_exports, {
|
|
328
|
-
Component: () => Component4,
|
|
329
|
-
Name: () => Name4
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
// src/utils.ts
|
|
333
|
-
function hideElement(element) {
|
|
334
|
-
element.style.display = "none";
|
|
335
|
-
}
|
|
336
|
-
function showElement(element) {
|
|
337
|
-
element.style.display = "block";
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// src/components/modal-context.ts
|
|
341
|
-
var Name4 = "modal-context";
|
|
342
|
-
var Component4 = (props, { element }) => {
|
|
343
|
-
const [contextProps, restProps] = splitProps(props, [
|
|
344
|
-
"isOpen",
|
|
345
|
-
"isAnimating"
|
|
346
|
-
]);
|
|
347
|
-
const context = provideModalContext(contextProps, element);
|
|
348
|
-
const [state, { setElementState }] = context;
|
|
349
|
-
const [_, { updateAnimationQueue, ...events }] = useModalContext(context);
|
|
350
|
-
element.actions = events;
|
|
351
|
-
const focusTrap = createFocusTrap(element, () => ({
|
|
352
|
-
allowOutsideClick: true,
|
|
353
|
-
escapeDeactivates: restProps.closeOnEscape,
|
|
354
|
-
onDeactivate: () => {
|
|
355
|
-
setElementState("isOpen", false);
|
|
356
|
-
}
|
|
357
|
-
}));
|
|
358
|
-
createEffect(
|
|
359
|
-
on(
|
|
360
|
-
() => state.isOpen,
|
|
361
|
-
(isOpen) => {
|
|
362
|
-
const eventName = isOpen ? "modal:open" : "modal:close";
|
|
363
|
-
element.dispatchEvent(
|
|
364
|
-
new CustomEvent(eventName, {
|
|
365
|
-
bubbles: true,
|
|
366
|
-
detail: { isOpen, relatedTarget: element }
|
|
367
|
-
})
|
|
368
|
-
);
|
|
369
|
-
element.dispatchEvent(
|
|
370
|
-
new CustomEvent("drawer:toggle", {
|
|
371
|
-
bubbles: true,
|
|
372
|
-
detail: { isOpen, relatedTarget: element }
|
|
373
|
-
})
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
)
|
|
377
|
-
);
|
|
378
|
-
createEffect(
|
|
379
|
-
on(
|
|
380
|
-
() => ({
|
|
381
|
-
isOpen: state.isOpen,
|
|
382
|
-
focusTrap: focusTrap(),
|
|
383
|
-
shouldTrapFocus: restProps.shouldTrapFocus
|
|
384
|
-
}),
|
|
385
|
-
({ isOpen, focusTrap: focusTrap2, shouldTrapFocus }) => {
|
|
386
|
-
if (!isOpen) return;
|
|
387
|
-
showElement(element);
|
|
388
|
-
if (!shouldTrapFocus) return;
|
|
389
|
-
focusTrap2.activate();
|
|
390
|
-
onCleanup(focusTrap2.deactivate);
|
|
391
|
-
}
|
|
392
|
-
)
|
|
393
|
-
);
|
|
394
|
-
createEffect(
|
|
395
|
-
on(
|
|
396
|
-
() => ({
|
|
397
|
-
isOpen: state.isOpen,
|
|
398
|
-
isAnimating: state.isAnimating,
|
|
399
|
-
shouldTrapFocus: restProps.shouldTrapFocus
|
|
400
|
-
}),
|
|
401
|
-
({ isOpen, isAnimating, shouldTrapFocus }) => {
|
|
402
|
-
if (isOpen && !isAnimating && shouldTrapFocus)
|
|
403
|
-
return disableBodyScroll(element, {
|
|
404
|
-
allowTouchMove: (el) => {
|
|
405
|
-
if (el instanceof HTMLElement) {
|
|
406
|
-
let element2 = el;
|
|
407
|
-
while (element2 && element2 !== document.body) {
|
|
408
|
-
if (element2.tagName === "MODAL-PANEL") {
|
|
409
|
-
return true;
|
|
410
|
-
}
|
|
411
|
-
element2 = element2.parentElement;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
onCleanup(() => {
|
|
418
|
-
enableBodyScroll(element);
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
)
|
|
422
|
-
);
|
|
423
|
-
createEffect(
|
|
424
|
-
on(
|
|
425
|
-
() => ({ isOpen: state.isOpen, animationQueue: state.animationQueue }),
|
|
426
|
-
({ isOpen, animationQueue }) => {
|
|
427
|
-
if (isOpen) return;
|
|
428
|
-
return Promise.all(animationQueue).then(() => hideElement(element));
|
|
429
|
-
}
|
|
430
|
-
)
|
|
431
|
-
);
|
|
432
|
-
let openAfterDelayTimeoutId = null;
|
|
433
|
-
onMount(() => {
|
|
434
|
-
if (!restProps.delay || contextProps.isOpen) return;
|
|
435
|
-
openAfterDelayTimeoutId = setTimeout(() => {
|
|
436
|
-
setElementState("isOpen", true);
|
|
437
|
-
}, props.delay);
|
|
438
|
-
return onCleanup(() => {
|
|
439
|
-
clearTimeout(openAfterDelayTimeoutId);
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
createEffect(
|
|
443
|
-
on(
|
|
444
|
-
() => ({
|
|
445
|
-
isOpen: state.isOpen,
|
|
446
|
-
openAfterDelay: restProps.delay > 0
|
|
447
|
-
}),
|
|
448
|
-
({ isOpen, openAfterDelay }) => {
|
|
449
|
-
if (!openAfterDelay && openAfterDelayTimeoutId)
|
|
450
|
-
clearTimeout(openAfterDelayTimeoutId);
|
|
451
|
-
if (isOpen && openAfterDelayTimeoutId)
|
|
452
|
-
clearTimeout(openAfterDelayTimeoutId);
|
|
453
|
-
}
|
|
454
|
-
)
|
|
455
|
-
);
|
|
456
|
-
onCleanup(() => {
|
|
457
|
-
enableBodyScroll(element);
|
|
458
|
-
});
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
// src/index.ts
|
|
462
|
-
customShadowlessElement(
|
|
463
|
-
modal_context_exports.Name,
|
|
464
|
-
{
|
|
465
|
-
isOpen: false,
|
|
466
|
-
id: "",
|
|
467
|
-
closeOnEscape: false,
|
|
468
|
-
shouldTrapFocus: false,
|
|
469
|
-
isAnimating: false,
|
|
470
|
-
openAfterDelay: false,
|
|
471
|
-
delay: 0
|
|
472
|
-
},
|
|
473
|
-
correctElementType(modal_context_exports.Component)
|
|
474
|
-
);
|
|
475
|
-
customShadowlessElement(
|
|
476
|
-
modal_trigger_exports.Name,
|
|
477
|
-
{ target: "", action: "", on: "click", preventDefault: true },
|
|
478
|
-
correctElementType(modal_trigger_exports.Component)
|
|
479
|
-
);
|
|
480
|
-
customShadowlessElement(
|
|
481
|
-
modal_backdrop_exports.Name,
|
|
482
|
-
{},
|
|
483
|
-
correctElementType(modal_backdrop_exports.Component)
|
|
484
|
-
);
|
|
485
|
-
customShadowlessElement(
|
|
486
|
-
modal_panel_exports.Name,
|
|
487
|
-
{},
|
|
488
|
-
correctElementType(modal_panel_exports.Component)
|
|
489
|
-
);
|
|
490
|
-
|
|
491
|
-
export { getModalContext, useModal, withModalElementContext };
|
|
492
|
-
//# sourceMappingURL=index.js.map
|
|
493
|
-
//# sourceMappingURL=index.js.map
|