@brytdesigns/web-component-drawer 1.1.11 → 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.
@@ -1,74 +1,93 @@
1
- import { onCleanup, createEffect } from 'solid-js';
2
- import { observeElementInViewport } from 'observe-element-in-viewport';
3
- import { withDrawerElementContext, useDrawerContext } from '../hooks/index.js';
4
-
5
- const Name = "drawer-trigger";
6
- const Component = (props, { element }) => {
7
- withDrawerElementContext(
8
- () => props.target || "",
9
- () => {
10
- return {
11
- action: props.action,
12
- on: props.on,
13
- preventDefault: props.preventDefault
14
- };
15
- },
16
- (context, props2) => {
17
- const controller = new AbortController();
18
- const { action, on, preventDefault } = props2;
19
- const [state, { open, close, toggle }] = useDrawerContext(context);
20
- switch (on) {
21
- case "enter": {
22
- let unsubscribe = null;
23
- if (action === "toggle") {
24
- unsubscribe = observeElementInViewport(element, open, close);
25
- }
26
- if (unsubscribe) onCleanup(unsubscribe);
27
- break;
28
- }
29
- case "exit": {
30
- let unsubscribe = null;
31
- if (action === "toggle") {
32
- unsubscribe = observeElementInViewport(element, close, open);
33
- }
34
- if (unsubscribe) onCleanup(unsubscribe);
35
- break;
36
- }
37
- default: {
38
- element.addEventListener(
39
- //@ts-ignore
40
- on,
41
- (event) => {
42
- if (preventDefault) event.preventDefault();
43
- if (state.isAnimating) return;
44
- switch (action) {
45
- case "close":
46
- close();
47
- break;
48
- case "open":
49
- open();
50
- break;
51
- case "toggle":
52
- toggle();
53
- break;
54
- }
55
- },
56
- { signal: controller.signal }
57
- );
58
- break;
59
- }
60
- }
61
- createEffect(() => {
62
- element.setAttribute("is-open", `${state.isOpen}`);
63
- element.setAttribute("is-animating", `${state.isAnimating}`);
64
- });
65
- onCleanup(() => {
66
- controller.abort();
67
- });
68
- }
69
- );
1
+ import { useDrawerAt, useDrawerContext } from "../hooks/useDrawer.js";
2
+ import "../hooks/index.js";
3
+ import { createGuardedEffect, ensureId, findDisclosureControl } from "@brytdesigns/web-component-core/utils";
4
+ import { observeElementInViewport } from "observe-element-in-viewport";
5
+ //#region src/components/drawer-trigger.ts
6
+ var Name = "drawer-trigger";
7
+ var Component = (props, { element }) => {
8
+ const drawer = useDrawerAt(() => props.target, element);
9
+ createGuardedEffect(() => ({
10
+ context: drawer(),
11
+ action: props.action,
12
+ on: props.on,
13
+ preventDefault: props.preventDefault
14
+ }), ({ context, action, on, preventDefault }) => {
15
+ const controller = new AbortController();
16
+ const [state, { open, close, toggle }] = useDrawerContext(context);
17
+ switch (on) {
18
+ case "enter":
19
+ if (action === "toggle") {
20
+ const unsubscribe = observeElementInViewport(element, open, close);
21
+ return () => {
22
+ unsubscribe();
23
+ controller.abort();
24
+ };
25
+ }
26
+ break;
27
+ case "exit":
28
+ if (action === "toggle") {
29
+ const unsubscribe = observeElementInViewport(element, close, open);
30
+ return () => {
31
+ unsubscribe();
32
+ controller.abort();
33
+ };
34
+ }
35
+ break;
36
+ default: element.addEventListener(on, (event) => {
37
+ if (preventDefault) event.preventDefault();
38
+ if (state.isAnimating) return;
39
+ switch (action) {
40
+ case "close":
41
+ close();
42
+ break;
43
+ case "open":
44
+ open();
45
+ break;
46
+ case "toggle": toggle();
47
+ }
48
+ }, { signal: controller.signal });
49
+ }
50
+ return () => {
51
+ controller.abort();
52
+ };
53
+ });
54
+ /**
55
+ * ARIA for the control that opens the overlay.
56
+ *
57
+ * `aria-haspopup="dialog"` rather than `aria-expanded`: this opens an
58
+ * overlay and moves focus into it, which is not the disclosure pattern
59
+ * `aria-expanded` describes. None of this was published before.
60
+ *
61
+ * A trigger with no button inside warns and sets nothing, matching
62
+ * `dialog-trigger` — ARIA on a non-interactive wrapper would claim a
63
+ * control that assistive tech cannot operate.
64
+ */
65
+ createGuardedEffect(() => ({
66
+ context: drawer(),
67
+ selector: props.target
68
+ }), ({ selector }) => {
69
+ const control = findDisclosureControl(element);
70
+ if (!control) {
71
+ console.warn("drawer-trigger: no <button> inside it, so no ARIA was applied. Wrap the trigger content in a <button type=\"button\">.", element);
72
+ return;
73
+ }
74
+ control.setAttribute("aria-haspopup", "dialog");
75
+ const root = selector ? document.querySelector(selector) : null;
76
+ if (root && !control.hasAttribute("aria-controls")) control.setAttribute("aria-controls", ensureId(root, "drawer"));
77
+ });
78
+ createGuardedEffect(() => {
79
+ const context = drawer();
80
+ const [state] = useDrawerContext(context);
81
+ return {
82
+ isOpen: state.isOpen,
83
+ isAnimating: state.isAnimating
84
+ };
85
+ }, ({ isOpen, isAnimating }) => {
86
+ element.setAttribute("is-open", `${isOpen}`);
87
+ element.setAttribute("is-animating", `${isAnimating}`);
88
+ });
70
89
  };
71
-
90
+ //#endregion
72
91
  export { Component, Name };
73
- //# sourceMappingURL=drawer-trigger.js.map
92
+
74
93
  //# sourceMappingURL=drawer-trigger.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/drawer-trigger.ts"],"names":["props"],"mappings":";;;;AAeO,MAAM,IAAO,GAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC5E,EAAA,wBAAA;AAAA,IACE,MAAM,MAAM,MAAU,IAAA,EAAA;AAAA,IACtB,MAAM;AACJ,MAAO,OAAA;AAAA,QACL,QAAQ,KAAM,CAAA,MAAA;AAAA,QACd,IAAI,KAAM,CAAA,EAAA;AAAA,QACV,gBAAgB,KAAM,CAAA;AAAA,OACxB;AAAA,KACF;AAAA,IACA,CAAC,SAASA,MAAU,KAAA;AAClB,MAAM,MAAA,UAAA,GAAa,IAAI,eAAgB,EAAA;AACvC,MAAA,MAAM,EAAE,MAAA,EAAQ,EAAI,EAAA,cAAA,EAAmBA,GAAAA,MAAAA;AACvC,MAAM,MAAA,CAAC,OAAO,EAAE,IAAA,EAAM,OAAO,MAAO,EAAC,CAAI,GAAA,gBAAA,CAAiB,OAAO,CAAA;AAEjE,MAAA,QAAQ,EAAI;AAAA,QACV,KAAK,OAAS,EAAA;AACZ,UAAA,IAAI,WAAc,GAAA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AClB,CAAA;AAAA;AACH,GACF;AACF","file":"drawer-trigger.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport type { Action } from \"../consts\";\n\nimport { createEffect, onCleanup } from \"solid-js\";\nimport { observeElementInViewport } from \"observe-element-in-viewport\";\n\nimport { withDrawerElementContext, useDrawerContext } from \"../hooks/index.js\";\n\nexport type Props = {\n target?: string;\n action?: Action | \"\";\n on?: keyof HTMLElementEventMap | \"enter\" | \"exit\";\n preventDefault: boolean;\n};\n\nexport const Name = \"drawer-trigger\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n withDrawerElementContext(\n () => props.target || \"\",\n () => {\n return {\n action: props.action,\n on: props.on,\n preventDefault: props.preventDefault,\n };\n },\n (context, props) => {\n const controller = new AbortController();\n const { action, on, preventDefault } = props;\n const [state, { open, close, toggle }] = useDrawerContext(context);\n\n switch (on) {\n case \"enter\": {\n let unsubscribe = null;\n if (action === \"toggle\") {\n unsubscribe = observeElementInViewport(element, open, close);\n }\n\n if (unsubscribe) onCleanup(unsubscribe);\n break;\n }\n case \"exit\": {\n let unsubscribe = null;\n if (action === \"toggle\") {\n unsubscribe = observeElementInViewport(element, close, open);\n }\n\n if (unsubscribe) onCleanup(unsubscribe);\n break;\n }\n\n default: {\n element.addEventListener(\n //@ts-ignore\n on,\n (event) => {\n if (preventDefault) event.preventDefault();\n if (state.isAnimating) return;\n switch (action) {\n case \"close\":\n close();\n break;\n case \"open\":\n open();\n break;\n case \"toggle\":\n toggle();\n break;\n }\n },\n { signal: controller.signal },\n );\n break;\n }\n }\n\n createEffect(() => {\n element.setAttribute(\"is-open\", `${state.isOpen}`);\n element.setAttribute(\"is-animating\", `${state.isAnimating}`);\n });\n\n onCleanup(() => {\n controller.abort();\n });\n },\n );\n};\n"]}
1
+ {"version":3,"file":"drawer-trigger.js","names":[],"sources":["../../../src/components/drawer-trigger.ts"],"sourcesContent":["import {\n\ttype CorrectComponentType,\n\tcreateGuardedEffect,\n\tensureId,\n\tfindDisclosureControl,\n} from \"@brytdesigns/web-component-core/utils\";\nimport { observeElementInViewport } from \"observe-element-in-viewport\";\n\nimport type { Action } from \"../consts\";\n\nimport { useDrawerAt, useDrawerContext } from \"../hooks/index.js\";\n\nexport type Props = {\n\ttarget?: string;\n\taction?: Action | \"\";\n\ton?: keyof HTMLElementEventMap | \"enter\" | \"exit\";\n\tpreventDefault: boolean;\n};\n\nexport const Name = \"drawer-trigger\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n\t// The drawer is not an ancestor, so this is a lateral lookup. It resolves\n\t// asynchronously — waiting for a provider that may mount later, and\n\t// re-resolving if one replaces it — and reading it in an effect's compute\n\t// phase simply defers the apply until it is ready. No boundary needed.\n\tconst drawer = useDrawerAt(() => props.target, element);\n\n\tcreateGuardedEffect(\n\t\t() => ({\n\t\t\tcontext: drawer(),\n\t\t\taction: props.action,\n\t\t\ton: props.on,\n\t\t\tpreventDefault: props.preventDefault,\n\t\t}),\n\t\t({ context, action, on, preventDefault }) => {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst [state, { open, close, toggle }] = useDrawerContext(context);\n\n\t\t\tswitch (on) {\n\t\t\t\tcase \"enter\": {\n\t\t\t\t\tif (action === \"toggle\") {\n\t\t\t\t\t\tconst unsubscribe = observeElementInViewport(element, open, close);\n\t\t\t\t\t\treturn () => {\n\t\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"exit\": {\n\t\t\t\t\tif (action === \"toggle\") {\n\t\t\t\t\t\tconst unsubscribe = observeElementInViewport(element, close, open);\n\t\t\t\t\t\treturn () => {\n\t\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\telement.addEventListener(\n\t\t\t\t\t\t//@ts-expect-error `on` is a free-form attribute\n\t\t\t\t\t\ton,\n\t\t\t\t\t\t(event) => {\n\t\t\t\t\t\t\tif (preventDefault) event.preventDefault();\n\t\t\t\t\t\t\tif (state.isAnimating) return;\n\t\t\t\t\t\t\tswitch (action) {\n\t\t\t\t\t\t\t\tcase \"close\":\n\t\t\t\t\t\t\t\t\tclose();\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"open\":\n\t\t\t\t\t\t\t\t\topen();\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase \"toggle\":\n\t\t\t\t\t\t\t\t\ttoggle();\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ signal: controller.signal },\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn () => {\n\t\t\t\tcontroller.abort();\n\t\t\t};\n\t\t},\n\t);\n\n\t/**\n\t * ARIA for the control that opens the overlay.\n\t *\n\t * `aria-haspopup=\"dialog\"` rather than `aria-expanded`: this opens an\n\t * overlay and moves focus into it, which is not the disclosure pattern\n\t * `aria-expanded` describes. None of this was published before.\n\t *\n\t * A trigger with no button inside warns and sets nothing, matching\n\t * `dialog-trigger` — ARIA on a non-interactive wrapper would claim a\n\t * control that assistive tech cannot operate.\n\t */\n\tcreateGuardedEffect(\n\t\t// `target` belongs in the dependency list. It was read from the apply\n\t\t// phase, which does not track, so a trigger whose `target` changed kept\n\t\t// publishing `aria-controls` for the element it used to point at — the\n\t\t// same shape of defect as `product-variant-input` writing a stale\n\t\t// variant id, and just as quiet.\n\t\t() => ({ context: drawer(), selector: props.target }),\n\t\t({ selector }) => {\n\t\t\tconst control = findDisclosureControl(element);\n\t\t\tif (!control) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'drawer-trigger: no <button> inside it, so no ARIA was applied. Wrap the trigger content in a <button type=\"button\">.',\n\t\t\t\t\telement,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcontrol.setAttribute(\"aria-haspopup\", \"dialog\");\n\t\t\tconst root = selector\n\t\t\t\t? document.querySelector<HTMLElement>(selector)\n\t\t\t\t: null;\n\t\t\t// An authored aria-controls is left alone.\n\t\t\tif (root && !control.hasAttribute(\"aria-controls\")) {\n\t\t\t\tcontrol.setAttribute(\"aria-controls\", ensureId(root, \"drawer\"));\n\t\t\t}\n\t\t},\n\t);\n\n\t// Mirroring drawer state onto the trigger is independent of which listener\n\t// is wired, so it is its own effect rather than nested inside the one above.\n\tcreateGuardedEffect(\n\t\t() => {\n\t\t\tconst context = drawer();\n\t\t\tconst [state] = useDrawerContext(context);\n\t\t\treturn { isOpen: state.isOpen, isAnimating: state.isAnimating };\n\t\t},\n\t\t({ isOpen, isAnimating }) => {\n\t\t\telement.setAttribute(\"is-open\", `${isOpen}`);\n\t\t\telement.setAttribute(\"is-animating\", `${isAnimating}`);\n\t\t},\n\t);\n};\n"],"mappings":";;;;;AAmBA,IAAa,OAAO;AAEpB,IAAa,aAA0C,OAAO,EAAE,cAAc;CAK7E,MAAM,SAAS,kBAAkB,MAAM,QAAQ,OAAO;CAEtD,2BACQ;EACN,SAAS,OAAO;EAChB,QAAQ,MAAM;EACd,IAAI,MAAM;EACV,gBAAgB,MAAM;CACvB,KACC,EAAE,SAAS,QAAQ,IAAI,qBAAqB;EAC5C,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,CAAC,OAAO,EAAE,MAAM,OAAO,YAAY,iBAAiB,OAAO;EAEjE,QAAQ,IAAR;GACC,KAAK;IACJ,IAAI,WAAW,UAAU;KACxB,MAAM,cAAc,yBAAyB,SAAS,MAAM,KAAK;KACjE,aAAa;MACZ,YAAY;MACZ,WAAW,MAAM;KAClB;IACD;IACA;GAED,KAAK;IACJ,IAAI,WAAW,UAAU;KACxB,MAAM,cAAc,yBAAyB,SAAS,OAAO,IAAI;KACjE,aAAa;MACZ,YAAY;MACZ,WAAW,MAAM;KAClB;IACD;IACA;GAGD,SACC,QAAQ,iBAEP,KACC,UAAU;IACV,IAAI,gBAAgB,MAAM,eAAe;IACzC,IAAI,MAAM,aAAa;IACvB,QAAQ,QAAR;KACC,KAAK;MACJ,MAAM;MACN;KACD,KAAK;MACJ,KAAK;MACL;KACD,KAAK,UACJ,OAAO;IAET;GACD,GACA,EAAE,QAAQ,WAAW,OAAO,CAC7B;EAGF;EAEA,aAAa;GACZ,WAAW,MAAM;EAClB;CACD,CACD;;;;;;;;;;;;CAaA,2BAMQ;EAAE,SAAS,OAAO;EAAG,UAAU,MAAM;CAAO,KAClD,EAAE,eAAe;EACjB,MAAM,UAAU,sBAAsB,OAAO;EAC7C,IAAI,CAAC,SAAS;GACb,QAAQ,KACP,0HACA,OACD;GACA;EACD;EACA,QAAQ,aAAa,iBAAiB,QAAQ;EAC9C,MAAM,OAAO,WACV,SAAS,cAA2B,QAAQ,IAC5C;EAEH,IAAI,QAAQ,CAAC,QAAQ,aAAa,eAAe,GAChD,QAAQ,aAAa,iBAAiB,SAAS,MAAM,QAAQ,CAAC;CAEhE,CACD;CAIA,0BACO;EACL,MAAM,UAAU,OAAO;EACvB,MAAM,CAAC,SAAS,iBAAiB,OAAO;EACxC,OAAO;GAAE,QAAQ,MAAM;GAAQ,aAAa,MAAM;EAAY;CAC/D,IACC,EAAE,QAAQ,kBAAkB;EAC5B,QAAQ,aAAa,WAAW,GAAG,QAAQ;EAC3C,QAAQ,aAAa,gBAAgB,GAAG,aAAa;CACtD,CACD;AACD"}
@@ -1,10 +1,4 @@
1
- import * as drawerContent_js from './drawer-content.js';
2
- export { drawerContent_js as DrawerContent };
3
- import * as drawerTrigger_js from './drawer-trigger.js';
4
- export { drawerTrigger_js as DrawerTrigger };
5
- import * as drawerBackdrop_js from './drawer-backdrop.js';
6
- export { drawerBackdrop_js as DrawerBackdrop };
7
- import * as drawerContext_js from './drawer-context.js';
8
- export { drawerContext_js as DrawerContext };
9
- //# sourceMappingURL=index.js.map
10
- //# sourceMappingURL=index.js.map
1
+ import "./drawer-backdrop.js";
2
+ import "./drawer-content.js";
3
+ import "./drawer-context.js";
4
+ import "./drawer-trigger.js";
@@ -1,16 +1,11 @@
1
- const POSITION = {
2
- TOP: "top",
3
- BOTTOM: "bottom",
4
- LEFT: "left",
5
- RIGHT: "right"
1
+ //#region src/consts.ts
2
+ var POSITION = {
3
+ TOP: "top",
4
+ BOTTOM: "bottom",
5
+ LEFT: "left",
6
+ RIGHT: "right"
6
7
  };
7
- const ACTION = {
8
- OPEN: "open",
9
- CLOSE: "close",
10
- TOGGLE: "toggle"
11
- };
12
- const EVENT_NAMESPACE = `bryt:drawer`;
8
+ //#endregion
9
+ export { POSITION };
13
10
 
14
- export { ACTION, EVENT_NAMESPACE, POSITION };
15
- //# sourceMappingURL=consts.js.map
16
11
  //# sourceMappingURL=consts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/consts.ts"],"names":[],"mappings":"AAGO,MAAM,QAAW,GAAA;AAAA,EACtB,GAAK,EAAA,KAAA;AAAA,EACL,MAAQ,EAAA,QAAA;AAAA,EACR,IAAM,EAAA,MAAA;AAAA,EACN,KAAO,EAAA;AACT;AAEO,MAAM,MAAS,GAAA;AAAA,EACpB,IAAM,EAAA,MAAA;AAAA,EACN,KAAO,EAAA,OAAA;AAAA,EACP,MAAQ,EAAA;AACV;AAEO,MAAM,eAAkB,GAAA,CAAA,WAAA","file":"consts.js","sourcesContent":["export type Position = (typeof POSITION)[keyof typeof POSITION];\nexport type Action = (typeof ACTION)[keyof typeof ACTION];\n\nexport const POSITION = {\n TOP: \"top\",\n BOTTOM: \"bottom\",\n LEFT: \"left\",\n RIGHT: \"right\",\n} as const;\n\nexport const ACTION = {\n OPEN: \"open\",\n CLOSE: \"close\",\n TOGGLE: \"toggle\",\n};\n\nexport const EVENT_NAMESPACE = `bryt:drawer` as const;\n"]}
1
+ {"version":3,"file":"consts.js","names":[],"sources":["../../src/consts.ts"],"sourcesContent":["export type Position = (typeof POSITION)[keyof typeof POSITION];\nexport type Action = (typeof ACTION)[keyof typeof ACTION];\n\nexport const POSITION = {\n\tTOP: \"top\",\n\tBOTTOM: \"bottom\",\n\tLEFT: \"left\",\n\tRIGHT: \"right\",\n} as const;\n\nexport const ACTION = {\n\tOPEN: \"open\",\n\tCLOSE: \"close\",\n\tTOGGLE: \"toggle\",\n};\n\nexport const EVENT_NAMESPACE = `bryt:drawer` as const;\n"],"mappings":";AAGA,IAAa,WAAW;CACvB,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;AACR"}
@@ -1,3 +1,2 @@
1
- export * from './useDrawer.js';
2
- //# sourceMappingURL=index.js.map
3
- //# sourceMappingURL=index.js.map
1
+ import { getDrawerContext, provideDrawerContext, useDrawer, useDrawerAt, useDrawerContext } from "./useDrawer.js";
2
+ export { getDrawerContext, provideDrawerContext, useDrawer, useDrawerAt, useDrawerContext };
@@ -1,89 +1,93 @@
1
- import { createContext, provide, consume } from 'component-register';
2
- import { splitProps, createEffect, on, batch, onCleanup, untrack, mergeProps } from 'solid-js';
3
- import { createStore } from 'solid-js/store';
4
- import { abortablePromise } from '@brytdesigns/web-component-core/promise';
5
- import { awaitAllAnimations } from '@brytdesigns/web-component-core/animation';
6
- import { createWithElementContext, toHyphenated, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
7
-
1
+ import { createGuardedEffect, createRemoteContext, getContextFromProvider, toHyphenated } from "@brytdesigns/web-component-core/utils";
2
+ import { awaitAllAnimations } from "@brytdesigns/web-component-core/animation";
3
+ import { createSignal, merge, omit, untrack } from "solid-js";
4
+ import { abortablePromise } from "@brytdesigns/web-component-core/promise";
5
+ import { consume, createContext, provide } from "component-register";
6
+ //#region src/hooks/useDrawer.ts
8
7
  function initializeDrawerContext(props) {
9
- const [_internal, _state] = splitProps(props, ["root"]);
10
- const [store, setStore] = createStore({ animationQueue: [] });
11
- createEffect(
12
- on(
13
- () => store.animationQueue,
14
- (animationQueue) => {
15
- if (!animationQueue.length) return;
16
- const controller = new AbortController();
17
- const animations = awaitAllAnimations(animationQueue);
18
- const abortableAnimations = abortablePromise(
19
- animations,
20
- controller.signal
21
- );
22
- setElementState("isAnimating", true);
23
- abortableAnimations.finally(() => {
24
- batch(() => {
25
- setElementState("isAnimating", false);
26
- setStore("animationQueue", []);
27
- });
28
- });
29
- return onCleanup(() => {
30
- controller.abort("Aborting drawer animations");
31
- });
32
- }
33
- )
34
- );
35
- function setElementState(key, value) {
36
- const currentValue = untrack(() => props[key]);
37
- if (typeof value === "function") {
38
- const result = value(currentValue || false);
39
- if (`${currentValue}` === `${result}`) return;
40
- _internal.root.setAttribute(toHyphenated(key), `${result}`);
41
- return;
42
- }
43
- if (`${currentValue}` === `${value}`) return;
44
- return _internal.root.setAttribute(toHyphenated(key), `${value}`);
45
- }
46
- return [mergeProps(_state, store), { setElementState, setStore }];
8
+ const _state = omit(props, "root");
9
+ /**
10
+ * The animation queue is a SIGNAL, not a store.
11
+ *
12
+ * A store deep-proxies what you put in it, and what goes in here is a list of
13
+ * live Motion playback controls. Proxied, every `.finished`, `.state` and
14
+ * `.then` on them became a reactive read from a non-tracking scope — hundreds
15
+ * of STRICT_READ_UNTRACKED reports under any interaction, and a proxy hop on
16
+ * every property access of an object that is not state at all.
17
+ *
18
+ * Nothing here needs per-property reactivity: the queue is replaced wholesale
19
+ * and read wholesale. A signal is the right primitive, and it hands the
20
+ * controls back exactly as they went in.
21
+ */
22
+ const [animationQueue, setAnimationQueue] = createSignal([]);
23
+ createGuardedEffect(animationQueue, (queue) => {
24
+ if (!queue.length) return;
25
+ const controller = new AbortController();
26
+ const animations = awaitAllAnimations(queue);
27
+ const abortableAnimations = abortablePromise(animations, controller.signal);
28
+ setElementState("isAnimating", true);
29
+ abortableAnimations.finally(() => {
30
+ setElementState("isAnimating", false);
31
+ setAnimationQueue([]);
32
+ });
33
+ return () => {
34
+ controller.abort("Aborting drawer animations");
35
+ };
36
+ });
37
+ function setElementState(key, value) {
38
+ const currentValue = untrack(() => props[key]);
39
+ if (typeof value === "function") {
40
+ const result = value(currentValue || false);
41
+ if (`${currentValue}` === `${result}`) return;
42
+ props.root.setAttribute(toHyphenated(key), `${result}`);
43
+ return;
44
+ }
45
+ if (`${currentValue}` === `${value}`) return;
46
+ return props.root.setAttribute(toHyphenated(key), `${value}`);
47
+ }
48
+ return [merge(_state, { get animationQueue() {
49
+ return animationQueue();
50
+ } }), {
51
+ setElementState,
52
+ setAnimationQueue
53
+ }];
47
54
  }
48
- const DrawerContextState = createContext(initializeDrawerContext);
49
- const provideDrawerContext = (initialState, element) => {
50
- const props = mergeProps(initialState, { root: element });
51
- return provide(DrawerContextState, props, element);
55
+ var DrawerContextState = createContext(initializeDrawerContext);
56
+ var provideDrawerContext = (initialState, element) => {
57
+ const props = merge(initialState, { root: element });
58
+ return provide(DrawerContextState, props, element);
52
59
  };
53
- const useDrawerContext = (context) => {
54
- const [state, { setElementState, setStore: setState }] = context;
55
- function updateAnimationQueue(animation) {
56
- setState("animationQueue", (state2) => [...state2, animation]);
57
- }
58
- function close() {
59
- setElementState("isOpen", false);
60
- }
61
- function open() {
62
- setElementState("isOpen", true);
63
- }
64
- function toggle() {
65
- setElementState("isOpen", (open2) => !open2);
66
- }
67
- return [state, { updateAnimationQueue, close, open, toggle }];
60
+ var useDrawerContext = (context) => {
61
+ const [state, { setElementState, setAnimationQueue }] = context;
62
+ function updateAnimationQueue(animation) {
63
+ setAnimationQueue((queue) => [...queue, animation]);
64
+ }
65
+ function close() {
66
+ setElementState("isOpen", false);
67
+ }
68
+ function open() {
69
+ setElementState("isOpen", true);
70
+ }
71
+ function toggle() {
72
+ setElementState("isOpen", (open) => !open);
73
+ }
74
+ return [state, {
75
+ updateAnimationQueue,
76
+ close,
77
+ open,
78
+ toggle
79
+ }];
68
80
  };
69
- const useDrawer = (element) => {
70
- const context = consume(DrawerContextState, element);
71
- if (!context) {
72
- throw console.error(
73
- "DrawerContext not found! Please ensure to wrap your custom element with drawer-context element."
74
- );
75
- }
76
- return useDrawerContext(context);
81
+ var useDrawer = (element) => {
82
+ const context = consume(DrawerContextState, element);
83
+ if (!context) throw new Error("DrawerContext not found! Please ensure to wrap your custom element with drawer-context element.");
84
+ return useDrawerContext(context);
77
85
  };
78
- const withDrawerElementContext = createWithElementContext(DrawerContextState);
79
- const getDrawerContext = (element) => {
80
- const context = getContextFromProvider(
81
- DrawerContextState,
82
- element
83
- );
84
- return useDrawerContext(context);
86
+ var useDrawerAt = createRemoteContext(DrawerContextState);
87
+ var getDrawerContext = (element) => {
88
+ return useDrawerContext(getContextFromProvider(DrawerContextState, element));
85
89
  };
90
+ //#endregion
91
+ export { getDrawerContext, provideDrawerContext, useDrawer, useDrawerAt, useDrawerContext };
86
92
 
87
- export { getDrawerContext, provideDrawerContext, useDrawer, useDrawerContext, withDrawerElementContext };
88
- //# sourceMappingURL=useDrawer.js.map
89
93
  //# sourceMappingURL=useDrawer.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useDrawer.ts"],"names":["state","open"],"mappings":";;;;;;;AAwCA,SAAS,wBAAwB,KAA6B,EAAA;AAC5D,EAAM,MAAA,CAAC,WAAW,MAAM,CAAA,GAAI,WAAW,KAAO,EAAA,CAAC,MAAM,CAAC,CAAA;AACtD,EAAM,MAAA,CAAC,OAAO,QAAQ,CAAA,GAAI,YAA0B,EAAE,cAAA,EAAgB,EAAC,EAAG,CAAA;AAE1E,EAAA,YAAA;AAAA,IACE,EAAA;AAAA,MACE,MAAM,KAAM,CAAA,cAAA;AAAA,MACZ,CAAC,cAAmB,KAAA;AAClB,QAAI,IAAA,CAAC,eAAe,MAAQ,EAAA;AAC5B,QAAM,MAAA,UAAA,GAAa,IAAI,eAAgB,EAAA;AACvC,QAAM,MAAA,UAAA,GAAa,mBAAmB,cAAc,CAAA;AACpD,QAAA,MAAM,mBAAsB,GAAA,gBAAA;AAAA,U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,kBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,iBAAiB,OAAO,CAAA;AACjC","file":"useDrawer.js","sourcesContent":["import {\n type ICustomElement,\n createContext,\n provide,\n consume,\n} from \"component-register\";\nimport {\n createEffect,\n on,\n batch,\n splitProps,\n untrack,\n mergeProps,\n onCleanup,\n} from \"solid-js\";\nimport { createStore } from \"solid-js/store\";\n\nimport type { AnimationPlaybackControlsWithThen } from \"motion\";\nimport { abortablePromise } from \"@brytdesigns/web-component-core/promise\";\nimport { awaitAllAnimations } from \"@brytdesigns/web-component-core/animation\";\nimport {\n createWithElementContext,\n toHyphenated,\n getContextFromProvider,\n} from \"@brytdesigns/web-component-core/utils\";\n\ntype StoreContext = {\n animationQueue: AnimationPlaybackControlsWithThen[];\n};\n\ntype CreateContextOptions = {\n root: HTMLElement & ICustomElement;\n isOpen: boolean;\n isAnimating: boolean;\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype DrawerContext = ReturnType<typeof initializeDrawerContext>;\n\nfunction initializeDrawerContext(props: CreateContextOptions) {\n const [_internal, _state] = splitProps(props, [\"root\"]);\n const [store, setStore] = createStore<StoreContext>({ animationQueue: [] });\n\n createEffect(\n on(\n () => store.animationQueue,\n (animationQueue) => {\n if (!animationQueue.length) return;\n const controller = new AbortController();\n const animations = awaitAllAnimations(animationQueue);\n const abortableAnimations = abortablePromise(\n animations,\n controller.signal,\n );\n setElementState(\"isAnimating\", true);\n abortableAnimations.finally(() => {\n batch(() => {\n setElementState(\"isAnimating\", false);\n setStore(\"animationQueue\", []);\n });\n });\n\n return onCleanup(() => {\n controller.abort(\"Aborting drawer animations\");\n });\n },\n ),\n );\n\n function setElementState(\n key: keyof Omit<CreateContextOptions, \"root\">,\n value: boolean | ((v: boolean) => boolean),\n ) {\n const currentValue = untrack(() => props[key]);\n if (typeof value === \"function\") {\n const result = value(currentValue || false);\n if (`${currentValue}` === `${result}`) return;\n _internal.root.setAttribute(toHyphenated(key), `${result}`);\n return;\n }\n if (`${currentValue}` === `${value}`) return;\n return _internal.root.setAttribute(toHyphenated(key), `${value}`);\n }\n\n return [mergeProps(_state, store), { setElementState, setStore }] as const;\n}\n\nconst DrawerContextState = createContext(initializeDrawerContext);\n\nexport const provideDrawerContext = (\n initialState: Omit<CreateContextOptions, \"root\">,\n element: WalkableNode,\n): DrawerContext => {\n const props = mergeProps(initialState, { root: element });\n return provide(DrawerContextState, props, element);\n};\n\nexport const useDrawerContext = (context: DrawerContext) => {\n const [state, { setElementState, setStore: setState }] = context;\n\n function updateAnimationQueue(animation: AnimationPlaybackControlsWithThen) {\n setState(\"animationQueue\", (state) => [...state, animation]);\n }\n\n function close() {\n setElementState(\"isOpen\", false);\n }\n\n function open() {\n setElementState(\"isOpen\", true);\n }\n\n function toggle() {\n setElementState(\"isOpen\", (open) => !open);\n }\n\n return [state, { updateAnimationQueue, close, open, toggle }] as const;\n};\n\nexport const useDrawer = (element: HTMLElement & ICustomElement) => {\n const context: DrawerContext = consume(DrawerContextState, element);\n\n if (!context) {\n throw console.error(\n \"DrawerContext not found! Please ensure to wrap your custom element with drawer-context element.\",\n );\n }\n\n return useDrawerContext(context);\n};\n\nexport const withDrawerElementContext = createWithElementContext<\n typeof DrawerContextState,\n DrawerContext\n>(DrawerContextState);\n\nexport const getDrawerContext = (element: Element) => {\n const context = getContextFromProvider<DrawerContext>(\n DrawerContextState,\n element,\n );\n return useDrawerContext(context);\n};\n"]}
1
+ {"version":3,"file":"useDrawer.js","names":[],"sources":["../../../src/hooks/useDrawer.ts"],"sourcesContent":["import { awaitAllAnimations } from \"@brytdesigns/web-component-core/animation\";\nimport { abortablePromise } from \"@brytdesigns/web-component-core/promise\";\nimport {\n\tcreateGuardedEffect,\n\tcreateRemoteContext,\n\tgetContextFromProvider,\n\ttoHyphenated,\n} from \"@brytdesigns/web-component-core/utils\";\nimport {\n\tconsume,\n\tcreateContext,\n\ttype ICustomElement,\n\tprovide,\n} from \"component-register\";\nimport type { AnimationPlaybackControlsWithThen } from \"motion\";\nimport { createSignal, merge, omit, untrack } from \"solid-js\";\n\ntype StoreContext = {\n\tanimationQueue: AnimationPlaybackControlsWithThen[];\n};\n\ntype CreateContextOptions = {\n\troot: HTMLElement & ICustomElement;\n\tisOpen: boolean;\n\tisAnimating: boolean;\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype DrawerContext = ReturnType<typeof initializeDrawerContext>;\n\nfunction initializeDrawerContext(props: CreateContextOptions) {\n\t// `omit` returns only the rest; `root` is read straight off `props`.\n\tconst _state = omit(props, \"root\");\n\t/**\n\t * The animation queue is a SIGNAL, not a store.\n\t *\n\t * A store deep-proxies what you put in it, and what goes in here is a list of\n\t * live Motion playback controls. Proxied, every `.finished`, `.state` and\n\t * `.then` on them became a reactive read from a non-tracking scope — hundreds\n\t * of STRICT_READ_UNTRACKED reports under any interaction, and a proxy hop on\n\t * every property access of an object that is not state at all.\n\t *\n\t * Nothing here needs per-property reactivity: the queue is replaced wholesale\n\t * and read wholesale. A signal is the right primitive, and it hands the\n\t * controls back exactly as they went in.\n\t */\n\tconst [animationQueue, setAnimationQueue] = createSignal<\n\t\tAnimationPlaybackControlsWithThen[]\n\t>([]);\n\n\tcreateGuardedEffect(animationQueue, (queue) => {\n\t\tif (!queue.length) return;\n\t\tconst controller = new AbortController();\n\t\tconst animations = awaitAllAnimations(queue);\n\t\tconst abortableAnimations = abortablePromise(animations, controller.signal);\n\t\tsetElementState(\"isAnimating\", true);\n\t\tabortableAnimations.finally(() => {\n\t\t\t// No `batch` in v2 — writes stage and flush together by default.\n\t\t\tsetElementState(\"isAnimating\", false);\n\t\t\tsetAnimationQueue([]);\n\t\t});\n\n\t\t// v2 treats the apply phase's return value as the cleanup.\n\t\treturn () => {\n\t\t\tcontroller.abort(\"Aborting drawer animations\");\n\t\t};\n\t});\n\n\tfunction setElementState(\n\t\tkey: keyof Omit<CreateContextOptions, \"root\">,\n\t\tvalue: boolean | ((v: boolean) => boolean),\n\t) {\n\t\tconst currentValue = untrack(() => props[key]);\n\t\tif (typeof value === \"function\") {\n\t\t\tconst result = value(currentValue || false);\n\t\t\tif (`${currentValue}` === `${result}`) return;\n\t\t\tprops.root.setAttribute(toHyphenated(key), `${result}`);\n\t\t\treturn;\n\t\t}\n\t\tif (`${currentValue}` === `${value}`) return;\n\t\treturn props.root.setAttribute(toHyphenated(key), `${value}`);\n\t}\n\n\treturn [\n\t\tmerge(_state, {\n\t\t\tget animationQueue() {\n\t\t\t\treturn animationQueue();\n\t\t\t},\n\t\t}),\n\t\t{ setElementState, setAnimationQueue },\n\t] as const;\n}\n\nconst DrawerContextState = createContext(initializeDrawerContext);\n\nexport const provideDrawerContext = (\n\tinitialState: Omit<CreateContextOptions, \"root\">,\n\telement: WalkableNode,\n): DrawerContext => {\n\tconst props = merge(initialState, { root: element });\n\treturn provide(DrawerContextState, props, element);\n};\n\nexport const useDrawerContext = (context: DrawerContext) => {\n\tconst [state, { setElementState, setAnimationQueue }] = context;\n\n\tfunction updateAnimationQueue(animation: AnimationPlaybackControlsWithThen) {\n\t\t// v2 store setters are draft-first, but this one REPLACES the array\n\t\t// rather than pushing into it. The effect above tracks\n\t\t// `store.animationQueue` — the property, not its contents — and an\n\t\t// in-place `push` leaves that property pointing at the same array, so\n\t\t// the effect never re-ran and `is-animating` was never published at\n\t\t// any point, open or closed.\n\t\tsetAnimationQueue((queue) => [...queue, animation]);\n\t}\n\n\tfunction close() {\n\t\tsetElementState(\"isOpen\", false);\n\t}\n\n\tfunction open() {\n\t\tsetElementState(\"isOpen\", true);\n\t}\n\n\tfunction toggle() {\n\t\tsetElementState(\"isOpen\", (open) => !open);\n\t}\n\n\treturn [state, { updateAnimationQueue, close, open, toggle }] as const;\n};\n\nexport const useDrawer = (element: HTMLElement & ICustomElement) => {\n\tconst context: DrawerContext = consume(DrawerContextState, element);\n\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"DrawerContext not found! Please ensure to wrap your custom element with drawer-context element.\",\n\t\t);\n\t}\n\n\treturn useDrawerContext(context);\n};\n\nexport const useDrawerAt =\n\tcreateRemoteContext<DrawerContext>(DrawerContextState);\n\nexport const getDrawerContext = (element: Element) => {\n\tconst context = getContextFromProvider<DrawerContext>(\n\t\tDrawerContextState,\n\t\telement,\n\t);\n\treturn useDrawerContext(context);\n};\n"],"mappings":";;;;;;AA+BA,SAAS,wBAAwB,OAA6B;CAE7D,MAAM,SAAS,KAAK,OAAO,MAAM;;;;;;;;;;;;;;CAcjC,MAAM,CAAC,gBAAgB,qBAAqB,aAE1C,CAAC,CAAC;CAEJ,oBAAoB,iBAAiB,UAAU;EAC9C,IAAI,CAAC,MAAM,QAAQ;EACnB,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,aAAa,mBAAmB,KAAK;EAC3C,MAAM,sBAAsB,iBAAiB,YAAY,WAAW,MAAM;EAC1E,gBAAgB,eAAe,IAAI;EACnC,oBAAoB,cAAc;GAEjC,gBAAgB,eAAe,KAAK;GACpC,kBAAkB,CAAC,CAAC;EACrB,CAAC;EAGD,aAAa;GACZ,WAAW,MAAM,4BAA4B;EAC9C;CACD,CAAC;CAED,SAAS,gBACR,KACA,OACC;EACD,MAAM,eAAe,cAAc,MAAM,IAAI;EAC7C,IAAI,OAAO,UAAU,YAAY;GAChC,MAAM,SAAS,MAAM,gBAAgB,KAAK;GAC1C,IAAI,GAAG,mBAAmB,GAAG,UAAU;GACvC,MAAM,KAAK,aAAa,aAAa,GAAG,GAAG,GAAG,QAAQ;GACtD;EACD;EACA,IAAI,GAAG,mBAAmB,GAAG,SAAS;EACtC,OAAO,MAAM,KAAK,aAAa,aAAa,GAAG,GAAG,GAAG,OAAO;CAC7D;CAEA,OAAO,CACN,MAAM,QAAQ,EACb,IAAI,iBAAiB;EACpB,OAAO,eAAe;CACvB,EACD,CAAC,GACD;EAAE;EAAiB;CAAkB,CACtC;AACD;AAEA,IAAM,qBAAqB,cAAc,uBAAuB;AAEhE,IAAa,wBACZ,cACA,YACmB;CACnB,MAAM,QAAQ,MAAM,cAAc,EAAE,MAAM,QAAQ,CAAC;CACnD,OAAO,QAAQ,oBAAoB,OAAO,OAAO;AAClD;AAEA,IAAa,oBAAoB,YAA2B;CAC3D,MAAM,CAAC,OAAO,EAAE,iBAAiB,uBAAuB;CAExD,SAAS,qBAAqB,WAA8C;EAO3E,mBAAmB,UAAU,CAAC,GAAG,OAAO,SAAS,CAAC;CACnD;CAEA,SAAS,QAAQ;EAChB,gBAAgB,UAAU,KAAK;CAChC;CAEA,SAAS,OAAO;EACf,gBAAgB,UAAU,IAAI;CAC/B;CAEA,SAAS,SAAS;EACjB,gBAAgB,WAAW,SAAS,CAAC,IAAI;CAC1C;CAEA,OAAO,CAAC,OAAO;EAAE;EAAsB;EAAO;EAAM;CAAO,CAAC;AAC7D;AAEA,IAAa,aAAa,YAA0C;CACnE,MAAM,UAAyB,QAAQ,oBAAoB,OAAO;CAElE,IAAI,CAAC,SACJ,MAAM,IAAI,MACT,iGACD;CAGD,OAAO,iBAAiB,OAAO;AAChC;AAEA,IAAa,cACZ,oBAAmC,kBAAkB;AAEtD,IAAa,oBAAoB,YAAqB;CAKrD,OAAO,iBAJS,uBACf,oBACA,OAEuB,CAAO;AAChC"}
@@ -3,43 +3,45 @@
3
3
  import { ICustomElement } from 'component-register';
4
4
  import { AnimationPlaybackControlsWithThen } from 'motion';
5
5
 
6
+ /**
7
+ * `component-register` types `options.element` as a bare `ICustomElement`, but
8
+ * at runtime it is always also an `HTMLElement`. Every component in this repo
9
+ * needs the DOM half.
10
+ */
6
11
  export type CorrectComponentOptions = {
7
12
  element: HTMLElement & ICustomElement;
8
13
  };
9
14
  export type CorrectComponentType<T> = (props: T, options: CorrectComponentOptions) => unknown;
10
15
  export type Props = {};
11
- declare const Name = "drawer-content";
16
+ declare const Name = "drawer-backdrop";
12
17
  declare const Component: CorrectComponentType<Props>;
18
+ type Props$1 = {};
19
+ declare const Name$1 = "drawer-content";
20
+ declare const Component$1: CorrectComponentType<Props$1>;
21
+ type Props$2 = {
22
+ isOpen: boolean;
23
+ id: string;
24
+ closeOnEscape: boolean;
25
+ shouldTrapFocus: boolean;
26
+ isAnimating: boolean;
27
+ debug?: boolean;
28
+ };
29
+ declare const Name$2 = "drawer-context";
30
+ declare const Component$2: CorrectComponentType<Props$2>;
13
31
  export type Action = (typeof ACTION)[keyof typeof ACTION];
14
32
  declare const ACTION: {
15
33
  OPEN: string;
16
34
  CLOSE: string;
17
35
  TOGGLE: string;
18
36
  };
19
- type Props$1 = {
37
+ type Props$3 = {
20
38
  target?: string;
21
39
  action?: Action | "";
22
40
  on?: keyof HTMLElementEventMap | "enter" | "exit";
23
41
  preventDefault: boolean;
24
42
  };
25
- declare const Name$1 = "drawer-trigger";
26
- declare const Component$1: CorrectComponentType<Props$1>;
27
- type Props$2 = {};
28
- declare const Name$2 = "drawer-backdrop";
29
- declare const Component$2: CorrectComponentType<Props$2>;
30
- type Props$3 = {
31
- isOpen: boolean;
32
- id: string;
33
- closeOnEscape: boolean;
34
- shouldTrapFocus: boolean;
35
- isAnimating: boolean;
36
- debug?: boolean;
37
- };
38
- declare const Name$3 = "drawer-context";
43
+ declare const Name$3 = "drawer-trigger";
39
44
  declare const Component$3: CorrectComponentType<Props$3>;
40
- export type StoreContext = {
41
- animationQueue: AnimationPlaybackControlsWithThen[];
42
- };
43
45
  export type CreateContextOptions = {
44
46
  root: HTMLElement & ICustomElement;
45
47
  isOpen: boolean;
@@ -49,7 +51,7 @@ export declare const useDrawer: (element: HTMLElement & ICustomElement) => reado
49
51
  {
50
52
  isOpen: boolean;
51
53
  isAnimating: boolean;
52
- animationQueue: AnimationPlaybackControlsWithThen[];
54
+ readonly animationQueue: AnimationPlaybackControlsWithThen[];
53
55
  },
54
56
  {
55
57
  readonly updateAnimationQueue: (animation: AnimationPlaybackControlsWithThen) => void;
@@ -58,22 +60,22 @@ export declare const useDrawer: (element: HTMLElement & ICustomElement) => reado
58
60
  readonly toggle: () => void;
59
61
  }
60
62
  ];
61
- export declare const withDrawerElementContext: <D extends unknown>(target: string | import("solid-js").Accessor<string> | import("solid-js").Accessor<() => Element>, dependencies: import("solid-js").Accessor<D> | undefined, cb: (context: readonly [
63
+ export declare const useDrawerAt: (target: () => string | undefined, host: HTMLElement) => import("solid-js").SourceAccessor<readonly [
62
64
  {
63
65
  isOpen: boolean;
64
66
  isAnimating: boolean;
65
- animationQueue: AnimationPlaybackControlsWithThen[];
67
+ readonly animationQueue: AnimationPlaybackControlsWithThen[];
66
68
  },
67
69
  {
68
70
  readonly setElementState: (key: keyof Omit<CreateContextOptions, "root">, value: boolean | ((v: boolean) => boolean)) => void;
69
- readonly setStore: import("solid-js/store").SetStoreFunction<StoreContext>;
71
+ readonly setAnimationQueue: import("solid-js").Setter<AnimationPlaybackControlsWithThen[]>;
70
72
  }
71
- ], dependencies: D) => void | (() => void)) => void;
73
+ ]>;
72
74
  export declare const getDrawerContext: (element: Element) => readonly [
73
75
  {
74
76
  isOpen: boolean;
75
77
  isAnimating: boolean;
76
- animationQueue: AnimationPlaybackControlsWithThen[];
78
+ readonly animationQueue: AnimationPlaybackControlsWithThen[];
77
79
  },
78
80
  {
79
81
  readonly updateAnimationQueue: (animation: AnimationPlaybackControlsWithThen) => void;
@@ -82,12 +84,12 @@ export declare const getDrawerContext: (element: Element) => readonly [
82
84
  readonly toggle: () => void;
83
85
  }
84
86
  ];
85
- export type DrawerContentProps = Props;
86
- export type DrawerContextProps = DrawerContext.Props;
87
- export type DrawerTriggerProps = Props$1;
88
- export type DrawerBackdropProps = Props$2;
87
+ export type DrawerContentProps = Props$1;
88
+ export type DrawerContextProps = Props$2;
89
+ export type DrawerTriggerProps = DrawerTrigger.Props;
90
+ export type DrawerBackdropProps = Props;
89
91
 
90
- declare namespace DrawerContext {
92
+ declare namespace DrawerTrigger {
91
93
  export { Component$3 as Component, Name$3 as Name, Props$3 as Props };
92
94
  }
93
95