@neovici/cosmoz-dropdown 5.4.0 → 6.1.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/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './use-focus';
2
- export * from './use-position';
3
2
  export * from './cosmoz-dropdown-menu';
4
3
  export * from './cosmoz-dropdown';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './use-focus';
2
- export * from './use-position';
3
2
  export * from './cosmoz-dropdown-menu';
4
3
  export * from './cosmoz-dropdown';
@@ -7,9 +7,9 @@ export declare const defaultMiddleware: {
7
7
  }[];
8
8
  export interface UseFloating extends Pick<ComputePositionConfig, 'placement' | 'strategy' | 'middleware'> {
9
9
  }
10
- export declare const useFloating: ({ placement, strategy, middleware, }: UseFloating) => {
11
- setReference: (el?: Element) => void;
12
- setFloating: (el?: Element) => void;
10
+ export declare const useFloating: ({ placement, strategy, middleware, }?: UseFloating | undefined) => {
11
+ setReference: import("@pionjs/pion").StateUpdater<Element | undefined>;
12
+ setFloating: import("@pionjs/pion").StateUpdater<Element | undefined>;
13
13
  styles: {
14
14
  left: string;
15
15
  top: string;
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useMemo, useState } from '@pionjs/pion';
1
+ import { useEffect, useMemo, useState } from '@pionjs/pion';
2
2
  import { autoUpdate, computePosition, flip, shift, } from '@floating-ui/dom';
3
3
  export { flip, shift, size } from '@floating-ui/dom';
4
4
  export const defaultMiddleware = [
@@ -8,8 +8,9 @@ export const defaultMiddleware = [
8
8
  }),
9
9
  shift(),
10
10
  ];
11
- export const useFloating = ({ placement = 'bottom-start', strategy, middleware = defaultMiddleware, }) => {
12
- const [[reference, floating], setRefs] = useState([]);
11
+ export const useFloating = ({ placement = 'bottom-start', strategy, middleware = defaultMiddleware, } = {}) => {
12
+ const [reference, setReference] = useState();
13
+ const [floating, setFloating] = useState();
13
14
  const [position, setPosition] = useState();
14
15
  useEffect(() => {
15
16
  if (!reference || !(floating instanceof HTMLElement)) {
@@ -23,8 +24,8 @@ export const useFloating = ({ placement = 'bottom-start', strategy, middleware =
23
24
  }).then(setPosition));
24
25
  }, [reference, floating, placement, strategy, middleware]);
25
26
  return {
26
- setReference: useCallback((el) => setRefs(([, _]) => [el, _]), []),
27
- setFloating: useCallback((el) => setRefs(([_]) => [_, el]), []),
27
+ setReference,
28
+ setFloating,
28
29
  styles: useMemo(() => position ? { left: `${position.x}px`, top: `${position.y}px` } : {}, [position?.x, position?.y]),
29
30
  };
30
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-dropdown",
3
- "version": "5.4.0",
3
+ "version": "6.1.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",
@@ -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;
@@ -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
- };