@ithinkdt/page 4.2.1 → 4.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ithinkdt/page",
3
- "version": "4.2.1",
3
+ "version": "4.2.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "iThinkDT Page",
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "sideEffects": false,
41
41
  "dependencies": {
42
- "@vueuse/core": "^14.3.0",
43
- "nanoid": "^6.0.0",
42
+ "@vueuse/core": "^14.4.0",
43
+ "nanoid": "^6.0.1",
44
44
  "@ithinkdt/common": "~4.2.1"
45
45
  },
46
46
  "peerDependencies": {
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "typescript": "~6.0.3",
52
- "vite": "^8.1.5",
53
- "vue": "^3.5.40",
52
+ "vite": "^8.2.1",
53
+ "vue": "^3.5.41",
54
54
  "vue-router": "^5.2.0"
55
55
  },
56
56
  "scripts": {
package/src/crud.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { MaybeRef, VNodeChild } from 'vue'
2
2
 
3
- import { Awaitable, Falsely, MaybeArray } from '@ithinkdt/common/typed'
3
+ import { Awaitable, Falsely, MaybeArray, MaybePromise } from '@ithinkdt/common/typed'
4
4
 
5
5
  import { PresetKeyField, _DataWithPresetKeyField } from './data-source.js'
6
6
  import { FormItemHelper, FormItemOptions, FormModalOptionsBase } from './form.js'
7
+ import { ModalRenderParam } from './modal.js'
7
8
 
8
9
  export interface CrudConfirmParams {
9
10
  title: () => VNodeChild
@@ -71,13 +72,18 @@ type SimpleCrudOptions<
71
72
  submitText?: VNodeChild | (() => VNodeChild)
72
73
  cancelText?: VNodeChild | (() => VNodeChild)
73
74
  action?: (
74
- params: {
75
- onSubmit(this: void): Promise<boolean>
76
- onCancel(this: void): void
77
- onClose(this: void): void
78
- } & ({ model: CreateParams, type: 'create' }
79
- | { model: UpdateParams, type: 'edit' }
80
- | { model: DetailEntity, type: 'view' }),
75
+ params: Omit<ModalRenderParam, 'onConfirm'> & {
76
+ onSubmit(this: void): MaybePromise<boolean | void>
77
+ } & ({ /** @reactively */ model: CreateParams, type: 'create' }
78
+ | { /** @reactively */ model: UpdateParams, type: 'edit' }
79
+ | { /** @reactively */ model: DetailEntity, type: 'view' }),
80
+ ) => VNodeChild
81
+ actionExtra?: (
82
+ params: Omit<ModalRenderParam, 'onConfirm'> & {
83
+ onSubmit(this: void): MaybePromise<boolean | void>
84
+ } & ({ /** @reactively */ model: CreateParams, type: 'create' }
85
+ | { /** @reactively */ model: UpdateParams, type: 'edit' }
86
+ | { /** @reactively */ model: DetailEntity, type: 'view' }),
81
87
  ) => VNodeChild
82
88
  resizable?: MaybeRef<boolean | undefined>
83
89
  draggable?: MaybeRef<boolean | undefined>
package/src/crud.js CHANGED
@@ -100,6 +100,12 @@ function _useSimpleCrudModal(crudType, getItems, request, options) {
100
100
  type: crudType,
101
101
  })
102
102
  : undefined,
103
+ actionExtra: options.actionExtra
104
+ ? params => options.actionExtra({
105
+ ...params,
106
+ type: crudType,
107
+ })
108
+ : undefined,
103
109
  })
104
110
 
105
111
  return {
package/src/form.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ComputedRef, MaybeRef, MaybeRefOrGetter, VNodeChild } from 'vue'
2
2
 
3
3
  import { Awaitable, MaybeArray, MaybePromise } from '@ithinkdt/common'
4
4
 
5
- import { ModalDialogOptions, ModalDrawerOptions, ModalReturns } from './modal.js'
5
+ import { ModalDialogOptions, ModalDrawerOptions, ModalRenderParam, ModalReturns } from './modal.js'
6
6
 
7
7
  export type ValidationTrigger = MaybeArray<'input' | 'blur' | (string & {})>
8
8
 
@@ -248,10 +248,18 @@ export type FormModalOptions<Model extends {}> = FormModalOptionsBase & FormHelp
248
248
  submitText?: VNodeChild | (() => VNodeChild)
249
249
  readonly?: MaybeRefOrGetter<boolean>
250
250
  action?: (
251
- params: {
252
- onSubmit(this: void): Promise<boolean>
253
- onCancel(this: void): void
254
- onClose(this: void): void
251
+ params: Omit<ModalRenderParam, 'onConfirm'> & {
252
+ onSubmit(this: void): MaybePromise<boolean | void>
253
+ /**
254
+ * 数据
255
+ * @reactively
256
+ */
257
+ model: Partial<Model>
258
+ },
259
+ ) => VNodeChild
260
+ actionExtra?: (
261
+ params: Omit<ModalRenderParam, 'onConfirm'> & {
262
+ onSubmit(this: void): MaybePromise<boolean | void>
255
263
  /**
256
264
  * 数据
257
265
  * @reactively
package/src/form.js CHANGED
@@ -502,7 +502,7 @@ export class ValidationError extends Error {
502
502
  }
503
503
  }
504
504
 
505
- export function useFormModal({ initial, items, rules, onSubmit, submitText, cancelText, action, readonly = false, ...options }) {
505
+ export function useFormModal({ initial, items, rules, onSubmit, submitText, cancelText, action, actionExtra, readonly = false, ...options }) {
506
506
  const { i18n: useI18n, getFormRenderer } = (hasInjectionContext() ? inject(PAGE_INJECTION, pageInjection) : pageInjection) ?? {}
507
507
  if (!getFormRenderer) {
508
508
  throw new Error('`useFormModal` not found `getFormRenderer` in injection, please install the page plugin.')
@@ -583,7 +583,10 @@ export function useFormModal({ initial, items, rules, onSubmit, submitText, canc
583
583
  validation2.value = {}
584
584
  },
585
585
  footer: action
586
- ? params => action({ ...params, model: form.model })
586
+ ? params => action({ ...params, onSubmit: params.onConfirm, model: form.model })
587
+ : undefined,
588
+ footerExtra: actionExtra
589
+ ? params => actionExtra({ ...params, onSubmit: params.onConfirm, model: form.model })
587
590
  : undefined,
588
591
  })
589
592
 
package/src/modal.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface ModalOptionsBase {
12
12
  cancelDisabled?: MaybeRef<boolean | undefined>
13
13
  cancelLoading?: MaybeRef<boolean | undefined>
14
14
  footer?: VNodeChild | ((params: ModalRenderParam) => VNodeChild)
15
+ footerExtra?: VNodeChild | ((params: ModalRenderParam) => VNodeChild)
15
16
  closable?: MaybeRef<boolean | undefined>
16
17
  closeOnEsc?: MaybeRef<boolean | undefined>
17
18
  showMask?: MaybeRef<boolean | undefined>
@@ -41,6 +42,7 @@ export interface ModalRenderParam {
41
42
  title: VNodeChild
42
43
  content: VNodeChild
43
44
  footer: VNodeChild
45
+ footerExtra: VNodeChild
44
46
  visible: boolean
45
47
  loading: boolean | undefined
46
48
  resizable: boolean | undefined
package/src/modal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { tryOnScopeDispose } from '@vueuse/core'
2
2
  import { nanoid } from 'nanoid'
3
- import { computed, defineComponent, h, hasInjectionContext, inject, isVNode, provide, reactive, ref, toValue, unref } from 'vue'
3
+ import { computed, defineComponent, h, hasInjectionContext, inject, isVNode, onActivated, onDeactivated, provide, reactive, ref, toValue, unref } from 'vue'
4
4
 
5
5
  import { IgnoreRejectionError, PAGE_INJECTION, pageInjection } from './plugin.js'
6
6
 
@@ -14,7 +14,7 @@ export const ModalProvider = defineComponent({
14
14
 
15
15
  const ModalInjectionKey = Symbol('__MODAL__')
16
16
 
17
- export function useModal({ content, confirmText, confirmLoading, cancelText, cancelLoading, footer, onConfirm, onCancel, onClose, title, ...options }) {
17
+ export function useModal({ content, confirmText, confirmLoading, cancelText, cancelLoading, footer, footerExtra, onConfirm, onCancel, onClose, title, ...options }) {
18
18
  const { i18n: useI18n, getModalRenderer, addModal } = (hasInjectionContext() ? inject(PAGE_INJECTION, pageInjection) : pageInjection) ?? {}
19
19
  if (!getModalRenderer) {
20
20
  throw new Error('`useModal` not found `getModalRenderer` in injection, please install the page plugin.')
@@ -24,6 +24,14 @@ export function useModal({ content, confirmText, confirmLoading, cancelText, can
24
24
 
25
25
  const title2 = ref()
26
26
  const visible = ref(false)
27
+ let visibleSaved = visible.value
28
+ onActivated(() => {
29
+ visible.value = visibleSaved
30
+ })
31
+ onDeactivated(() => {
32
+ visibleSaved = visible.value
33
+ visible.value = false
34
+ })
27
35
  let resolve0, reject0
28
36
  const open = (title0) => {
29
37
  if (visible.value) {
@@ -112,6 +120,7 @@ export function useModal({ content, confirmText, confirmLoading, cancelText, can
112
120
  title: toValue(title2.value ?? title),
113
121
  content: toValue(content),
114
122
  footer: isVNode(footer) ? footer : footer === null ? null : footer?.(renderParam),
123
+ footerExtra: isVNode(footerExtra) ? footerExtra : footerExtra?.(renderParam),
115
124
  confirmText: toValue(confirmText ?? (confirmText === null ? null : t('common.confirm.defaultOk'))),
116
125
  cancelText: toValue(cancelText ?? (cancelText === null ? null : t('common.page.form.cancelText'))),
117
126
  })