@laser-ui/components 2.0.3 → 2.0.5

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/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
+ ## [2.0.5](https://github.com/laser-ui/laser-ui/compare/v2.0.4...v2.0.5) (2025-01-13)
6
+
7
+ ### Features
8
+
9
+ - **components:** add `Dialogs` ([eca6d58](https://github.com/laser-ui/laser-ui/commit/eca6d580b7ea94990f8b80e1672f6eaec601550e))
10
+
11
+ ## [2.0.4](https://github.com/laser-ui/laser-ui/compare/v2.0.3...v2.0.4) (2025-01-06)
12
+
13
+ ### Bug Fixes
14
+
15
+ - **components:** fix `useMaxIndex` ([c09e8b9](https://github.com/laser-ui/laser-ui/commit/c09e8b93409f72f3b0ff45564c0228139302905c))
16
+
5
17
  ## [2.0.3](https://github.com/laser-ui/laser-ui/compare/v2.0.2...v2.0.3) (2024-12-25)
6
18
 
7
19
  ### Bug Fixes
@@ -1,32 +1,24 @@
1
1
  import { useUnmount } from '@laser-ui/hooks';
2
- import { useId, useMemo, useRef } from 'react';
3
- const MAX_INDEX_MANAGER = {
4
- record: [],
5
- add(id) {
6
- let n = 1;
7
- if (this.record.length > 0) {
8
- n = this.record[this.record.length - 1].n + 1;
9
- }
10
- this.record.push({ id, n });
11
- return n;
12
- },
13
- delete(id) {
14
- this.record = this.record.filter((item) => item.id !== id);
15
- },
16
- };
2
+ import { nth } from 'lodash';
3
+ import { useMemo, useRef } from 'react';
4
+ let ZINDEX = [];
17
5
  export function useMaxIndex(visible) {
18
- const id = useId();
19
- const prevMaxZIndex = useRef(0);
6
+ const zIndex = useRef(0);
20
7
  const maxZIndex = useMemo(() => {
8
+ var _a;
21
9
  if (visible) {
22
- return MAX_INDEX_MANAGER.add(id);
10
+ const z = ((_a = nth(ZINDEX, -1)) !== null && _a !== void 0 ? _a : 0) + 1;
11
+ zIndex.current = z;
12
+ ZINDEX.push(z);
13
+ return z;
14
+ }
15
+ else {
16
+ ZINDEX = ZINDEX.filter((z) => z !== zIndex.current);
17
+ return zIndex.current;
23
18
  }
24
- MAX_INDEX_MANAGER.delete(id);
25
- return prevMaxZIndex.current;
26
- }, [id, visible]);
27
- prevMaxZIndex.current = maxZIndex;
19
+ }, [visible]);
28
20
  useUnmount(() => {
29
- MAX_INDEX_MANAGER.delete(id);
21
+ ZINDEX = ZINDEX.filter((z) => z !== zIndex.current);
30
22
  });
31
23
  return maxZIndex;
32
24
  }
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { useDialogService } from './hooks';
2
- export { Root, DialogService } from './root';
2
+ export { Root, DialogService, Dialogs } from './root';
3
3
  export { ConfigProvider } from './config-provider';
4
4
  export { Accordion } from './accordion';
5
5
  export { Affix } from './affix';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { useDialogService } from './hooks';
2
- export { Root, DialogService } from './root';
2
+ export { Root, DialogService, Dialogs } from './root';
3
3
  export { ConfigProvider } from './config-provider';
4
4
  export { Accordion } from './accordion';
5
5
  export { Affix } from './affix';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laser-ui/components",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "React components.",
5
5
  "keywords": [
6
6
  "ui",
@@ -37,5 +37,5 @@
37
37
  "access": "public",
38
38
  "directory": "../../dist/libs/components"
39
39
  },
40
- "gitHead": "c7123f02baa424b48320c60861b29c7a55312ced"
40
+ "gitHead": "fb803f4dd41dc2ce86f4aa34aefa67255424942e"
41
41
  }
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { DialogInstance } from '../dialog-service';
3
+ export declare const Dialogs: import("react").NamedExoticComponent<{
4
+ dialogs: DialogInstance<any>[];
5
+ }>;
@@ -0,0 +1,4 @@
1
+ import { memo } from 'react';
2
+ export const Dialogs = memo(function (props) {
3
+ return props.dialogs.map((dialog) => dialog.node);
4
+ });
package/root/Root.js CHANGED
@@ -1,7 +1,8 @@
1
- import { jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEvent, useRefExtra } from '@laser-ui/hooks';
3
3
  import { isString, set } from 'lodash';
4
4
  import { useEffect, useMemo } from 'react';
5
+ import { Dialogs } from './Dialogs';
5
6
  import { useDialogs } from './dialog-service';
6
7
  import { ROOT_DATA, RootContext } from './vars';
7
8
  import dayjs from '../dayjs';
@@ -69,5 +70,5 @@ export function Root(props) {
69
70
  default:
70
71
  break;
71
72
  }
72
- return (_jsxs(RootContext, { value: context, children: [children, dialogs.map(({ node }) => node)] }));
73
+ return (_jsxs(RootContext, { value: context, children: [children, _jsx(Dialogs, { dialogs: dialogs })] }));
73
74
  }
package/root/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export type { RootProps } from './types';
2
2
  export { Root } from './Root';
3
3
  export { DialogService } from './dialog-service';
4
+ export { Dialogs } from './Dialogs';
package/root/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Root } from './Root';
2
2
  export { DialogService } from './dialog-service';
3
+ export { Dialogs } from './Dialogs';