@v-c/dialog 1.0.2 → 1.1.0-rc.1

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.
@@ -5,7 +5,8 @@ import pickAttrs from "@v-c/util/dist/pickAttrs";
5
5
  import { useLockFocus } from "@v-c/util/dist/Dom/focus";
6
6
  import { useFocusBoundaryProvider } from "@v-c/util/dist/Dom/focusBoundary";
7
7
  import { getStylePxValue } from "@v-c/util/dist/props-util";
8
- var Panel_default = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
8
+ //#region src/Dialog/Content/Panel.tsx
9
+ var Panel = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
9
10
  const { setPanel } = useGetRefContext();
10
11
  const internalRef = shallowRef();
11
12
  const mergeRefFun = (el) => {
@@ -48,7 +49,8 @@ var Panel_default = /* @__PURE__ */ defineComponent((props, { expose, slots }) =
48
49
  "onClick": onClose,
49
50
  "aria-label": "Close"
50
51
  }, ariaProps, {
51
- "class": `${prefixCls}-close`,
52
+ "class": classNames(`${prefixCls}-close`, modalClassNames?.close),
53
+ "style": modalStyles?.close,
52
54
  "disabled": closeBtnIsDisabled
53
55
  }), [closableObj.closeIcon]) : null;
54
56
  const content = createVNode("div", {
@@ -90,8 +92,7 @@ var Panel_default = /* @__PURE__ */ defineComponent((props, { expose, slots }) =
90
92
  props: {
91
93
  prefixCls: {
92
94
  type: String,
93
- required: true,
94
- default: void 0
95
+ required: true
95
96
  },
96
97
  ariaId: {
97
98
  type: String,
@@ -351,11 +352,11 @@ var Panel_default = /* @__PURE__ */ defineComponent((props, { expose, slots }) =
351
352
  },
352
353
  animationVisible: {
353
354
  type: Boolean,
354
- required: true,
355
- default: void 0
355
+ required: true
356
356
  }
357
357
  },
358
358
  name: "Panel",
359
359
  inheritAttrs: false
360
360
  });
361
- export { Panel_default as default };
361
+ //#endregion
362
+ export { Panel as default };
@@ -1,8 +1,9 @@
1
1
  import { offset } from "../../util.js";
2
- import Panel_default from "./Panel.js";
2
+ import Panel from "./Panel.js";
3
3
  import { Transition, createVNode, defineComponent, mergeProps, nextTick, shallowRef, vShow, watch, withDirectives } from "vue";
4
4
  import { getTransitionProps } from "@v-c/util/dist/utils/transition";
5
- var Content_default = /* @__PURE__ */ defineComponent((props, { slots }) => {
5
+ //#region src/Dialog/Content/index.tsx
6
+ var Content = /* @__PURE__ */ defineComponent((props, { slots }) => {
6
7
  const dialogRef = shallowRef();
7
8
  const transformOrigin = shallowRef("");
8
9
  function onPrepare() {
@@ -29,7 +30,7 @@ var Content_default = /* @__PURE__ */ defineComponent((props, { slots }) => {
29
30
  onVisibleChanged?.(false);
30
31
  animationVisible.value = false;
31
32
  }
32
- }), { default: () => [visible || !destroyOnHidden ? withDirectives(createVNode(Panel_default, mergeProps(props, {
33
+ }), { default: () => [visible || !destroyOnHidden ? withDirectives(createVNode(Panel, mergeProps(props, {
33
34
  "animationVisible": animationVisible.value,
34
35
  "title": title,
35
36
  "ariaId": ariaId,
@@ -58,13 +59,11 @@ var Content_default = /* @__PURE__ */ defineComponent((props, { slots }) => {
58
59
  },
59
60
  onVisibleChanged: {
60
61
  type: Function,
61
- required: true,
62
- default: void 0
62
+ required: true
63
63
  },
64
64
  prefixCls: {
65
65
  type: String,
66
- required: true,
67
- default: void 0
66
+ required: true
68
67
  },
69
68
  onMouseDown: {
70
69
  type: Function,
@@ -320,4 +319,5 @@ var Content_default = /* @__PURE__ */ defineComponent((props, { slots }) => {
320
319
  },
321
320
  name: "Content"
322
321
  });
323
- export { Content_default as default };
322
+ //#endregion
323
+ export { Content as default };
@@ -1,7 +1,8 @@
1
1
  import { Transition, createVNode, defineComponent, mergeProps } from "vue";
2
2
  import { classNames } from "@v-c/util";
3
3
  import { getTransitionProps } from "@v-c/util/dist/utils/transition";
4
- var Mask_default = /* @__PURE__ */ defineComponent((props) => {
4
+ //#region src/Dialog/Mask.tsx
5
+ var Mask = /* @__PURE__ */ defineComponent((props) => {
5
6
  return () => {
6
7
  const { maskProps, prefixCls, className, style, visible, motionName } = props;
7
8
  return createVNode(Transition, mergeProps(getTransitionProps(motionName), { "key": "mask" }), { default: () => [visible && createVNode("div", mergeProps({
@@ -13,13 +14,11 @@ var Mask_default = /* @__PURE__ */ defineComponent((props) => {
13
14
  props: {
14
15
  prefixCls: {
15
16
  type: String,
16
- required: true,
17
- default: void 0
17
+ required: true
18
18
  },
19
19
  visible: {
20
20
  type: Boolean,
21
- required: true,
22
- default: void 0
21
+ required: true
23
22
  },
24
23
  motionName: {
25
24
  type: String,
@@ -44,4 +43,5 @@ var Mask_default = /* @__PURE__ */ defineComponent((props) => {
44
43
  },
45
44
  name: "Mask"
46
45
  });
47
- export { Mask_default as default };
46
+ //#endregion
47
+ export { Mask as default };
@@ -1,11 +1,12 @@
1
1
  import { getMotionName } from "../util.js";
2
- import Content_default from "./Content/index.js";
3
- import Mask_default from "./Mask.js";
4
- import { createVNode, defineComponent, mergeDefaults, mergeProps, nextTick, onUnmounted, shallowRef, useId, watch } from "vue";
2
+ import Content from "./Content/index.js";
3
+ import Mask from "./Mask.js";
4
+ import { createVNode, defineComponent, mergeDefaults, mergeProps, nextTick, shallowRef, useId, watch } from "vue";
5
5
  import { warning } from "@v-c/util";
6
6
  import contains from "@v-c/util/dist/Dom/contains";
7
7
  import pickAttrs from "@v-c/util/dist/pickAttrs";
8
- var Dialog_default = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
8
+ //#region src/Dialog/index.tsx
9
+ var Dialog = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
9
10
  if (process.env.NODE_ENV !== "production") {
10
11
  [
11
12
  "wrapStyle",
@@ -40,53 +41,50 @@ var Dialog_default = /* @__PURE__ */ defineComponent((props, { expose, slots })
40
41
  lastOutSideActiveElementRef.value = null;
41
42
  }
42
43
  if (_animatedVisible) props?.afterClose?.();
43
- props?.afterOpenChange?.(newVisible);
44
44
  }
45
+ props?.afterOpenChange?.(newVisible);
45
46
  }
46
47
  function onInternalClose(e) {
47
48
  props?.onClose?.(e);
48
49
  }
49
- const contentClickRef = shallowRef(false);
50
- const contentTimeoutRef = shallowRef();
51
- const onContentMouseDown = () => {
52
- clearTimeout(contentTimeoutRef.value);
53
- contentClickRef.value = true;
54
- };
55
- const onContentMouseUp = () => {
56
- contentTimeoutRef.value = setTimeout(() => {
57
- contentClickRef.value = false;
58
- });
59
- };
50
+ const mouseDownOnMaskRef = shallowRef(false);
60
51
  let onWrapperClick = null;
61
52
  watch(() => props.maskClosable, () => {
62
53
  if (props.maskClosable) onWrapperClick = (e) => {
63
- if (contentClickRef.value) contentClickRef.value = false;
64
- else if (wrapperRef.value === e.target) onInternalClose(e);
54
+ if (wrapperRef.value === e.target && mouseDownOnMaskRef.value) onInternalClose(e);
65
55
  };
56
+ else onWrapperClick = null;
66
57
  }, { immediate: true });
58
+ function onWrapperMouseDown(e) {
59
+ mouseDownOnMaskRef.value = e.target === wrapperRef.value;
60
+ }
67
61
  watch(() => props.visible, () => {
68
62
  if (props.visible) {
63
+ mouseDownOnMaskRef.value = false;
69
64
  animatedVisible.value = true;
70
65
  saveLastOutSideActiveElementRef();
71
66
  nextTick(() => {
72
67
  const wrapEl = wrapperRef.value;
73
68
  if (wrapEl) isFixedPos.value = getComputedStyle(wrapEl).position === "fixed";
74
69
  });
75
- }
70
+ if (!getMotionName(props.prefixCls, props.transitionName, props.animation)) nextTick(() => {
71
+ onDialogVisibleChanged(true);
72
+ });
73
+ } else if (animatedVisible.value && !getMotionName(props.prefixCls, props.transitionName, props.animation)) onDialogVisibleChanged(false);
76
74
  }, { immediate: true });
77
- onUnmounted(() => {
78
- clearTimeout(contentTimeoutRef.value);
79
- });
80
75
  expose({});
81
76
  return () => {
82
- const { zIndex, wrapStyle, wrapProps, wrapClassName, closable, transitionName, animation, styles: modalStyles, prefixCls, rootClassName, visible, mask, maskAnimation, maskTransitionName, maskStyle, maskProps, classNames: modalClassNames } = props;
77
+ const { zIndex, wrapStyle, wrapProps, wrapClassName, closable, transitionName, animation, styles: modalStyles, prefixCls, rootClassName, visible, mask, maskAnimation, maskTransitionName, maskStyle, maskProps, classNames: modalClassNames, rootStyle } = props;
83
78
  const mergedStyle = {
84
79
  zIndex,
85
80
  ...wrapStyle,
86
81
  ...modalStyles?.wrapper,
87
82
  display: !animatedVisible.value ? "none" : void 0
88
83
  };
89
- return createVNode("div", mergeProps({ "class": [`${prefixCls}-root`, rootClassName] }, pickAttrs(props, { data: true })), [createVNode(Mask_default, {
84
+ return createVNode("div", mergeProps({
85
+ "class": [`${prefixCls}-root`, rootClassName],
86
+ "style": rootStyle
87
+ }, pickAttrs(props, { data: true })), [createVNode(Mask, {
90
88
  "prefixCls": prefixCls,
91
89
  "visible": !!(mask && visible),
92
90
  "motionName": getMotionName(prefixCls, maskTransitionName, maskAnimation),
@@ -105,11 +103,10 @@ var Dialog_default = /* @__PURE__ */ defineComponent((props, { expose, slots })
105
103
  ],
106
104
  "ref": wrapperRef,
107
105
  "onClick": onWrapperClick,
106
+ "onMousedown": onWrapperMouseDown,
108
107
  "style": mergedStyle
109
- }, wrapProps), [createVNode(Content_default, mergeProps({
108
+ }, wrapProps), [createVNode(Content, mergeProps({
110
109
  ...props,
111
- onMouseDown: onContentMouseDown,
112
- onMouseUp: onContentMouseUp,
113
110
  onClose: onInternalClose,
114
111
  onVisibleChanged: onDialogVisibleChanged
115
112
  }, {
@@ -371,4 +368,5 @@ var Dialog_default = /* @__PURE__ */ defineComponent((props, { expose, slots })
371
368
  }),
372
369
  name: "Dialog"
373
370
  });
374
- export { Dialog_default as default };
371
+ //#endregion
372
+ export { Dialog as default };
@@ -1,8 +1,9 @@
1
1
  import { useRefProvide } from "./context.js";
2
- import Dialog_default from "./Dialog/index.js";
2
+ import Dialog from "./Dialog/index.js";
3
3
  import { createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, watch } from "vue";
4
4
  import Portal from "@v-c/portal";
5
- var DialogWrap_default = /* @__PURE__ */ defineComponent((props, { slots }) => {
5
+ //#region src/DialogWrap.tsx
6
+ var DialogWrap = /* @__PURE__ */ defineComponent((props, { slots }) => {
6
7
  const animatedVisible = shallowRef(false);
7
8
  useRefProvide(props);
8
9
  const onEsc = ({ top, event }) => {
@@ -24,9 +25,10 @@ var DialogWrap_default = /* @__PURE__ */ defineComponent((props, { slots }) => {
24
25
  "onEsc": onEsc,
25
26
  "getContainer": getContainer,
26
27
  "autoLock": visible || animatedVisible.value
27
- }, { default: () => [createVNode(Dialog_default, mergeProps(props, {
28
+ }, { default: () => [createVNode(Dialog, mergeProps(props, {
28
29
  "destroyOnHidden": destroyOnHidden,
29
30
  "afterClose": () => {
31
+ (props.closable && typeof props.closable === "object" ? props.closable : {}).afterClose?.();
30
32
  afterClose?.();
31
33
  animatedVisible.value = false;
32
34
  }
@@ -284,4 +286,5 @@ var DialogWrap_default = /* @__PURE__ */ defineComponent((props, { slots }) => {
284
286
  }),
285
287
  name: "Dialog"
286
288
  });
287
- export { DialogWrap_default as default };
289
+ //#endregion
290
+ export { DialogWrap as default };
@@ -1,9 +1,14 @@
1
1
  import { GetContainer } from '@v-c/util/dist/PortalWrapper';
2
2
  import { VueNode } from '@v-c/util/dist/type';
3
3
  import { CSSProperties } from 'vue';
4
- export type SemanticName = 'header' | 'body' | 'footer' | 'container' | 'title' | 'wrapper' | 'mask';
4
+ export type SemanticName = 'header' | 'body' | 'footer' | 'container' | 'title' | 'wrapper' | 'mask' | 'close';
5
5
  export type ModalClassNames = Partial<Record<SemanticName, string>>;
6
6
  export type ModalStyles = Partial<Record<SemanticName, CSSProperties>>;
7
+ export type ClosableType = {
8
+ closeIcon?: VueNode;
9
+ disabled?: boolean;
10
+ afterClose?: () => any;
11
+ };
7
12
  export interface IDialogPropTypes {
8
13
  className?: string;
9
14
  keyboard?: boolean;
@@ -14,10 +19,7 @@ export interface IDialogPropTypes {
14
19
  afterClose?: () => any;
15
20
  afterOpenChange?: (open: boolean) => void;
16
21
  onClose?: (e: any) => any;
17
- closable?: boolean | ({
18
- closeIcon?: VueNode;
19
- disabled?: boolean;
20
- } & Record<string, any>);
22
+ closable?: boolean | (ClosableType & Record<string, any>);
21
23
  maskClosable?: boolean;
22
24
  visible?: boolean;
23
25
  destroyOnHidden?: boolean;
package/dist/context.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { inject, provide, shallowRef } from "vue";
2
+ //#region src/context.ts
2
3
  var RefContext = Symbol("RefContext");
3
4
  function useRefProvide(props) {
4
5
  const panel = shallowRef();
@@ -8,8 +9,8 @@ function useRefProvide(props) {
8
9
  };
9
10
  provide(RefContext, {
10
11
  panel,
11
- setPanel(panel$1) {
12
- setPanelRef(panel$1);
12
+ setPanel(panel) {
13
+ setPanelRef(panel);
13
14
  }
14
15
  });
15
16
  return {
@@ -20,4 +21,5 @@ function useRefProvide(props) {
20
21
  function useGetRefContext() {
21
22
  return inject(RefContext, {});
22
23
  }
24
+ //#endregion
23
25
  export { useGetRefContext, useRefProvide };
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- import Panel_default from "./Dialog/Content/Panel.js";
2
- import DialogWrap_default from "./DialogWrap.js";
3
- var src_default = DialogWrap_default;
4
- export { Panel_default as Panel, src_default as default };
1
+ import Panel from "./Dialog/Content/Panel.js";
2
+ import DialogWrap from "./DialogWrap.js";
3
+ //#region src/index.ts
4
+ var src_default = DialogWrap;
5
+ //#endregion
6
+ export { Panel, src_default as default };
package/dist/util.js CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/util.ts
1
2
  function getMotionName(prefixCls, transitionName, animationName) {
2
3
  let motionName = transitionName;
3
4
  if (!motionName && animationName) motionName = `${prefixCls}-${animationName}`;
@@ -27,4 +28,5 @@ function offset(el) {
27
28
  }
28
29
  return pos;
29
30
  }
31
+ //#endregion
30
32
  export { getMotionName, offset };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/dialog",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.1.0-rc.1",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",