@neovici/cosmoz-dropdown 5.3.0 → 6.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/cosmoz-dropdown.d.ts +2 -4
- package/dist/cosmoz-dropdown.js +2 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/use-floating.d.ts +1 -1
- package/package.json +3 -7
- package/dist/use-position.d.ts +0 -15
- package/dist/use-position.js +0 -54
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { UseFocusOpts } from './use-focus';
|
|
2
2
|
import { Content } from './cosmoz-dropdown-content';
|
|
3
|
-
import {
|
|
4
|
-
export interface Props extends UseFocusOpts {
|
|
5
|
-
placement?: Placement;
|
|
6
|
-
strategy?: Strategy;
|
|
3
|
+
import { UseFloating } from './use-floating';
|
|
4
|
+
export interface Props extends UseFocusOpts, UseFloating {
|
|
7
5
|
render: () => unknown;
|
|
8
6
|
}
|
|
9
7
|
declare const Dropdown: (host: HTMLElement & Props) => import("lit-html").TemplateResult<1>;
|
package/dist/cosmoz-dropdown.js
CHANGED
|
@@ -54,11 +54,12 @@ const style = css `
|
|
|
54
54
|
}
|
|
55
55
|
`;
|
|
56
56
|
const Dropdown = (host) => {
|
|
57
|
-
const { placement, strategy, render } = host;
|
|
57
|
+
const { placement, strategy, middleware, render } = host;
|
|
58
58
|
const { active, onToggle } = useHostFocus(host);
|
|
59
59
|
const { styles, setReference, setFloating } = useFloating({
|
|
60
60
|
placement,
|
|
61
61
|
strategy,
|
|
62
|
+
middleware,
|
|
62
63
|
});
|
|
63
64
|
return html ` <div class="anchor" part="anchor" ${ref(setReference)}>
|
|
64
65
|
<button
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/use-floating.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const defaultMiddleware: {
|
|
|
5
5
|
options?: any;
|
|
6
6
|
fn: (state: import("@floating-ui/dom").MiddlewareState) => import("@floating-ui/core").MiddlewareReturn | Promise<import("@floating-ui/core").MiddlewareReturn>;
|
|
7
7
|
}[];
|
|
8
|
-
interface UseFloating extends Pick<ComputePositionConfig, 'placement' | 'strategy' | 'middleware'> {
|
|
8
|
+
export interface UseFloating extends Pick<ComputePositionConfig, 'placement' | 'strategy' | 'middleware'> {
|
|
9
9
|
}
|
|
10
10
|
export declare const useFloating: ({ placement, strategy, middleware, }: UseFloating) => {
|
|
11
11
|
setReference: (el?: Element) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-dropdown",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "A simple dropdown web component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit-html",
|
|
@@ -66,18 +66,15 @@
|
|
|
66
66
|
"exports": {
|
|
67
67
|
".": "./dist/index.js",
|
|
68
68
|
"./use-focus": "./dist/use-focus.js",
|
|
69
|
-
"./use-position": "./dist/use-position.js",
|
|
70
69
|
"./use-floating": "./dist/use-floating.js",
|
|
71
70
|
"./connectable": "./dist/connectable.js",
|
|
72
|
-
"./src/use-focus.js": "./dist/use-focus.js"
|
|
73
|
-
"./src/use-position.js": "./dist/use-position.js"
|
|
71
|
+
"./src/use-focus.js": "./dist/use-focus.js"
|
|
74
72
|
},
|
|
75
73
|
"dependencies": {
|
|
76
74
|
"@floating-ui/dom": "^1.6.12",
|
|
77
75
|
"@neovici/cosmoz-utils": "^6.8.1",
|
|
78
76
|
"@pionjs/pion": "^2.5.2",
|
|
79
|
-
"lit-html": "^3.1.2"
|
|
80
|
-
"position.js": "^1.1.0"
|
|
77
|
+
"lit-html": "^3.1.2"
|
|
81
78
|
},
|
|
82
79
|
"devDependencies": {
|
|
83
80
|
"@commitlint/cli": "^19.2.1",
|
|
@@ -88,7 +85,6 @@
|
|
|
88
85
|
"@semantic-release/git": "^10.0.0",
|
|
89
86
|
"@storybook/addon-essentials": "^7.0.0",
|
|
90
87
|
"@storybook/addon-links": "^7.0.0",
|
|
91
|
-
"@storybook/storybook-deployer": "^2.8.5",
|
|
92
88
|
"@storybook/web-components": "7.6.17",
|
|
93
89
|
"@types/mocha": "^10.0.6",
|
|
94
90
|
"@types/node": "^22.10.2",
|
package/dist/use-position.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Placement } from 'position.js';
|
|
2
|
-
export declare const defaultPlacement: readonly ["bottom-left", "bottom-right", "bottom", "top-left", "top-right", "top"];
|
|
3
|
-
export { Placement };
|
|
4
|
-
export interface PositionOpts {
|
|
5
|
-
host: HTMLElement;
|
|
6
|
-
anchor: HTMLElement;
|
|
7
|
-
placement?: Placement;
|
|
8
|
-
confinement?: HTMLElement;
|
|
9
|
-
limit?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare const position: ({ host, anchor, placement, confinement, limit, }: PositionOpts) => void;
|
|
12
|
-
interface UsePositionOpts extends Omit<PositionOpts, 'anchor'> {
|
|
13
|
-
anchor?: (() => HTMLElement | null) | HTMLElement | null;
|
|
14
|
-
}
|
|
15
|
-
export declare const usePosition: ({ anchor: anchorage, host, ...thru }: UsePositionOpts) => void;
|
package/dist/use-position.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line
|
|
2
|
-
/// <reference path="../types/position.d.ts" />
|
|
3
|
-
import { useEffect } from '@pionjs/pion';
|
|
4
|
-
import getPosition from 'position.js';
|
|
5
|
-
import { onScrolled } from './on-scrolled';
|
|
6
|
-
export const defaultPlacement = [
|
|
7
|
-
'bottom-left',
|
|
8
|
-
'bottom-right',
|
|
9
|
-
'bottom',
|
|
10
|
-
'top-left',
|
|
11
|
-
'top-right',
|
|
12
|
-
'top',
|
|
13
|
-
];
|
|
14
|
-
export const position = ({ host, anchor, placement = defaultPlacement, confinement, limit, }) => {
|
|
15
|
-
const anchorBounds = anchor.getBoundingClientRect(), hostBounds = host.getBoundingClientRect(), { popupOffset: offset } = getPosition(hostBounds, anchorBounds, placement, {
|
|
16
|
-
fixed: true,
|
|
17
|
-
adjustXY: 'both',
|
|
18
|
-
offsetParent: confinement,
|
|
19
|
-
}), { style } = host;
|
|
20
|
-
if (offset.left < 0) {
|
|
21
|
-
style.left = '0px';
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
style.left = offset.left + 'px';
|
|
25
|
-
}
|
|
26
|
-
style.top = offset.top + 'px';
|
|
27
|
-
if (limit) {
|
|
28
|
-
style.minWidth = Math.max(anchorBounds.width, hostBounds.width) + 'px';
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export const usePosition = ({ anchor: anchorage, host, ...thru }) => {
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const anchor = typeof anchorage === 'function' ? anchorage() : anchorage;
|
|
34
|
-
if (anchor == null) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
let rid;
|
|
38
|
-
const reposition = () => position({ host, anchor, ...thru }), ro = new ResizeObserver(reposition);
|
|
39
|
-
ro.observe(host);
|
|
40
|
-
ro.observe(anchor);
|
|
41
|
-
const onReposition = () => {
|
|
42
|
-
cancelAnimationFrame(rid);
|
|
43
|
-
rid = requestAnimationFrame(reposition);
|
|
44
|
-
}, offScroll = onScrolled(anchor, onReposition);
|
|
45
|
-
window.addEventListener('resize', onReposition, true);
|
|
46
|
-
return () => {
|
|
47
|
-
ro.unobserve(host);
|
|
48
|
-
ro.unobserve(anchor);
|
|
49
|
-
offScroll();
|
|
50
|
-
window.removeEventListener('resize', onReposition, true);
|
|
51
|
-
cancelAnimationFrame(rid);
|
|
52
|
-
};
|
|
53
|
-
}, [anchorage, ...Object.values(thru)]);
|
|
54
|
-
};
|