@v-c/dialog 1.1.0 → 1.2.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.
@@ -12,9 +12,5 @@ export interface PanelProps extends Omit<IDialogPropTypes, 'getOpenCount'> {
12
12
  export interface ContentRef {
13
13
  focus: () => void;
14
14
  }
15
- declare const Panel: import('vue').DefineSetupFnComponent<PanelProps & {
16
- animationVisible: boolean;
17
- }, {}, {}, PanelProps & {
18
- animationVisible: boolean;
19
- } & {}, import('vue').PublicProps>;
15
+ declare const Panel: import('vue').DefineSetupFnComponent<PanelProps, {}, {}, PanelProps & {}, import('vue').PublicProps>;
20
16
  export default Panel;
@@ -20,7 +20,7 @@ var Panel = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
20
20
  internalRef.value?.focus?.({ preventScroll: true });
21
21
  } });
22
22
  return () => {
23
- const { width, height, footer, prefixCls, classNames: modalClassNames, styles: modalStyles, title, closable, closeIcon, bodyProps, bodyStyle, ariaId, style, className, forceRender, onClose, onMouseDown, onMouseUp, modalRender, animationVisible } = props;
23
+ const { width, height, footer, prefixCls, classNames: modalClassNames, styles: modalStyles, title, closable, closeIcon, bodyProps, bodyStyle, ariaId, style, className, forceRender, onClose, onMouseDown, onMouseUp, modalRender } = props;
24
24
  const contentStyle = {};
25
25
  if (width !== void 0) contentStyle.width = getStylePxValue(width);
26
26
  if (height !== void 0) contentStyle.height = getStylePxValue(height);
@@ -69,7 +69,6 @@ var Panel = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
69
69
  footerNode
70
70
  ]);
71
71
  const renderContent = () => {
72
- if (!animationVisible && forceRender) return null;
73
72
  return modalRender ? modalRender(content) : content;
74
73
  };
75
74
  return createVNode("div", mergeProps({
@@ -346,13 +345,14 @@ var Panel = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
346
345
  required: false,
347
346
  default: void 0
348
347
  },
349
- panelRef: {
348
+ scrollLock: {
349
+ type: Boolean,
350
350
  required: false,
351
351
  default: void 0
352
352
  },
353
- animationVisible: {
354
- type: Boolean,
355
- required: true
353
+ panelRef: {
354
+ required: false,
355
+ default: void 0
356
356
  }
357
357
  },
358
358
  name: "Panel",
@@ -1,6 +1,6 @@
1
1
  import { offset } from "../../util.js";
2
2
  import Panel from "./Panel.js";
3
- import { Transition, createVNode, defineComponent, mergeProps, nextTick, shallowRef, vShow, watch, withDirectives } from "vue";
3
+ import { Transition, createVNode, defineComponent, mergeProps, nextTick, shallowRef, vShow, withDirectives } from "vue";
4
4
  import { getTransitionProps } from "@v-c/util/dist/utils/transition";
5
5
  //#region src/Dialog/Content/index.tsx
6
6
  var Content = /* @__PURE__ */ defineComponent((props, { slots }) => {
@@ -15,12 +15,8 @@ var Content = /* @__PURE__ */ defineComponent((props, { slots }) => {
15
15
  }
16
16
  });
17
17
  }
18
- const animationVisible = shallowRef(props.visible);
19
- watch(() => props.visible, () => {
20
- if (props.visible) animationVisible.value = true;
21
- });
22
18
  return () => {
23
- const { prefixCls, className, style, visible, destroyOnHidden, onVisibleChanged, ariaId, title, motionName } = props;
19
+ const { prefixCls, className, style, visible, destroyOnHidden, onVisibleChanged, ariaId, title, motionName, forceRender } = props;
24
20
  const contentStyle = {};
25
21
  if (transformOrigin.value) contentStyle.transformOrigin = transformOrigin.value;
26
22
  return createVNode(Transition, mergeProps(getTransitionProps(motionName), {
@@ -28,10 +24,8 @@ var Content = /* @__PURE__ */ defineComponent((props, { slots }) => {
28
24
  "onAfterEnter": () => onVisibleChanged?.(true),
29
25
  "onAfterLeave": () => {
30
26
  onVisibleChanged?.(false);
31
- animationVisible.value = false;
32
27
  }
33
- }), { default: () => [visible || !destroyOnHidden ? withDirectives(createVNode(Panel, mergeProps(props, {
34
- "animationVisible": animationVisible.value,
28
+ }), { default: () => [visible || !destroyOnHidden || forceRender ? withDirectives(createVNode(Panel, mergeProps(props, {
35
29
  "title": title,
36
30
  "ariaId": ariaId,
37
31
  "prefixCls": prefixCls,
@@ -312,6 +306,11 @@ var Content = /* @__PURE__ */ defineComponent((props, { slots }) => {
312
306
  required: false,
313
307
  default: void 0
314
308
  },
309
+ scrollLock: {
310
+ type: Boolean,
311
+ required: false,
312
+ default: void 0
313
+ },
315
314
  panelRef: {
316
315
  required: false,
317
316
  default: void 0
@@ -353,6 +353,11 @@ var Dialog = /* @__PURE__ */ defineComponent((props, { expose, slots }) => {
353
353
  required: false,
354
354
  default: void 0
355
355
  },
356
+ scrollLock: {
357
+ type: Boolean,
358
+ required: false,
359
+ default: void 0
360
+ },
356
361
  panelRef: {
357
362
  required: false,
358
363
  default: void 0
@@ -17,15 +17,16 @@ var DialogWrap = /* @__PURE__ */ defineComponent((props, { slots }) => {
17
17
  if (props.visible) animatedVisible.value = true;
18
18
  }, { immediate: true });
19
19
  return () => {
20
- const { visible, getContainer, forceRender, destroyOnHidden = false, afterClose } = props;
20
+ const { visible, getContainer, forceRender, destroyOnHidden = false, scrollLock = true, afterClose } = props;
21
+ const { scrollLock: _, ...restProps } = props;
21
22
  if (!forceRender && destroyOnHidden && !animatedVisible.value) return null;
22
23
  return createVNode(Portal, {
23
24
  "open": visible || forceRender || animatedVisible.value,
24
25
  "autoDestroy": false,
25
26
  "onEsc": onEsc,
26
27
  "getContainer": getContainer,
27
- "autoLock": visible || animatedVisible.value
28
- }, { default: () => [createVNode(Dialog, mergeProps(props, {
28
+ "autoLock": scrollLock && (visible || animatedVisible.value)
29
+ }, { default: () => [createVNode(Dialog, mergeProps(restProps, {
29
30
  "destroyOnHidden": destroyOnHidden,
30
31
  "afterClose": () => {
31
32
  (props.closable && typeof props.closable === "object" ? props.closable : {}).afterClose?.();
@@ -268,6 +269,11 @@ var DialogWrap = /* @__PURE__ */ defineComponent((props, { slots }) => {
268
269
  required: false,
269
270
  default: void 0
270
271
  },
272
+ scrollLock: {
273
+ type: Boolean,
274
+ required: false,
275
+ default: void 0
276
+ },
271
277
  panelRef: {
272
278
  required: false,
273
279
  default: void 0
@@ -4,11 +4,11 @@ import { CSSProperties } from 'vue';
4
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 = {
7
+ export interface ClosableType {
8
8
  closeIcon?: VueNode;
9
9
  disabled?: boolean;
10
10
  afterClose?: () => any;
11
- };
11
+ }
12
12
  export interface IDialogPropTypes {
13
13
  className?: string;
14
14
  keyboard?: boolean;
@@ -53,5 +53,7 @@ export interface IDialogPropTypes {
53
53
  forceRender?: boolean;
54
54
  focusTriggerAfterClose?: boolean;
55
55
  focusTrap?: boolean;
56
+ /** Control whether to lock body scroll when modal opens. Default is true. */
57
+ scrollLock?: boolean;
56
58
  panelRef?: any;
57
59
  }
package/dist/util.js CHANGED
@@ -5,6 +5,7 @@ function getMotionName(prefixCls, transitionName, animationName) {
5
5
  return motionName;
6
6
  }
7
7
  function getScroll(w, top) {
8
+ if (!w) return 0;
8
9
  let ret = w[`page${top ? "Y" : "X"}Offset`];
9
10
  const method = `scroll${top ? "Top" : "Left"}`;
10
11
  if (typeof ret !== "number") {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/dialog",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",