@bjj/nuxt-layer-shadcn-ui 0.11.16 → 0.12.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.
@@ -150,6 +150,66 @@ async function handleDestroy () {
150
150
  }),
151
151
  }
152
152
 
153
+ export const BeforeClose: Story = {
154
+ parameters: {
155
+ ...noControls,
156
+ docs: {
157
+ source: {
158
+ code: `
159
+ <script setup lang="ts">
160
+ const { destroy } = useDialog()
161
+ const result = ref('')
162
+
163
+ async function handleDelete () {
164
+ const ok = await destroy({
165
+ title: 'Delete Item',
166
+ message: 'This will call the API before closing.',
167
+ beforeClose: async (action) => {
168
+ // Only intercept confirm; cancel / close stay instant.
169
+ if (action !== 'confirm') return
170
+ // Returning a Promise keeps the dialog open and shows loading until it settles.
171
+ await new Promise((resolve) => setTimeout(resolve, 1500))
172
+ },
173
+ })
174
+ result.value = \`destroy → \${ok}\`
175
+ }
176
+ </script>
177
+
178
+ <template>
179
+ <Button variant="destructive" @click="handleDelete">Delete with async</Button>
180
+ <div v-if="result">Result: {{ result }}</div>
181
+ </template>
182
+ `.trim(),
183
+ },
184
+ },
185
+ },
186
+ render: () => ({
187
+ components: { Button },
188
+ setup () {
189
+ const { destroy } = useDialog()
190
+ const result = ref('')
191
+ async function handleDelete () {
192
+ const ok = await destroy({
193
+ title: 'Delete Item',
194
+ message: 'This will call the API before closing.',
195
+ beforeClose: async action => {
196
+ if (action !== 'confirm') return
197
+ await new Promise(resolve => setTimeout(resolve, 1500))
198
+ },
199
+ })
200
+ result.value = `destroy → ${ok}`
201
+ }
202
+ return { handleDelete, result }
203
+ },
204
+ template: `
205
+ <div class="space-y-4">
206
+ <Button variant="destructive" @click="handleDelete">Delete with async</Button>
207
+ <div v-if="result" class="rounded-md bg-muted p-4 text-sm">Result: {{ result }}</div>
208
+ </div>
209
+ `,
210
+ }),
211
+ }
212
+
153
213
  export const MultiDialog: Story = {
154
214
  parameters: {
155
215
  ...noControls,
@@ -1,28 +1,53 @@
1
1
  <script setup lang="ts">
2
2
  const { current, isOpen, isActive, close, onClosed } = useDialogState()
3
3
 
4
- const isAlert = computed(() => current.value?.options.rejectLabel === '')
4
+ const modalProps = computed<Record<string, unknown> | undefined>(() => {
5
+ const options = current.value?.options as Record<string, unknown> | undefined
6
+ if (!options) return undefined
7
+ // `content` (string | VNode | HTMLElement) wins over the `message` shorthand;
8
+ // strip `message` so it never leaks onto the DOM as an unknown attribute.
9
+ const { message, ...rest } = options
10
+ return { ...rest, content: rest.content ?? message }
11
+ })
12
+
5
13
  const isDestructive = computed(() => {
6
14
  const type = current.value?.options.type
7
15
  return type === 'danger' || type === 'error'
8
16
  })
17
+ // danger/error dialogs get a destructive confirm button unless overridden
18
+ const confirmVariant = computed(
19
+ () => current.value?.options.confirmVariant ?? (isDestructive.value ? 'destructive' : undefined),
20
+ )
21
+
22
+ // Modal's `@close` fires only after `beforeClose` allows it, but carries no
23
+ // action — so we remember the intent and resolve on the actual close. `@open`
24
+ // resets it per dialog: each one defaults to a cancel (X / Esc / outside click).
25
+ let confirmed = false
26
+ function onOpen () {
27
+ confirmed = false
28
+ }
29
+ function onConfirm () {
30
+ confirmed = true
31
+ }
32
+ function onCancel () {
33
+ confirmed = false
34
+ }
35
+ function onClose () {
36
+ close(confirmed)
37
+ }
9
38
  </script>
10
39
 
11
40
  <template>
12
41
  <Modal
13
42
  v-if="isActive"
43
+ v-bind="modalProps"
14
44
  data-alert-dialog
15
45
  :visible="isOpen"
16
- :title="current?.options.title"
17
- :type="current?.options.type"
18
- :content="current?.options.message"
19
- :showCancel="!isAlert"
20
- :cancelText="current?.options.rejectLabel || undefined"
21
- :confirmText="current?.options.acceptLabel || undefined"
22
- :confirmVariant="isDestructive ? 'destructive' : 'default'"
23
- @confirm="close(true)"
24
- @cancel="close(false)"
25
- @close="close(false)"
46
+ :confirmVariant="confirmVariant"
47
+ @open="onOpen"
48
+ @confirm="onConfirm"
49
+ @cancel="onCancel"
50
+ @close="onClose"
26
51
  @closed="onClosed"
27
52
  />
28
53
  </template>
@@ -168,7 +168,6 @@ function resetPagination (overrides?: Record<string, any>) {
168
168
  // -- Event handlers --
169
169
 
170
170
  function onPageChange (newPage: number) {
171
- if (newPage === pagination.value.page) return
172
171
  pagination.value.page = newPage
173
172
  emit('update:filters', getFilters())
174
173
  fetchData()
@@ -1,14 +1,13 @@
1
- import type { ModalContentProps } from '../components/ui/ModalContent/types'
1
+ import type { ModalProps } from '../components/ui/Modal/types'
2
2
 
3
- export type DialogType = NonNullable<ModalContentProps['type']>
4
- export type DialogMessageContent = NonNullable<ModalContentProps['content']>
5
-
6
- export interface DialogOptions {
7
- type?: DialogType
8
- title?: string
9
- message?: DialogMessageContent
10
- acceptLabel?: string
11
- rejectLabel?: string
3
+ /**
4
+ * Imperative dialog options, aligned with `<Modal>` props (minus `visible`,
5
+ * which the queue manages). Anything Modal accepts — `beforeClose`, `loading`,
6
+ * `confirmVariant`, `class`, … — works here too.
7
+ */
8
+ export interface DialogOptions extends Omit<ModalProps, 'visible'> {
9
+ /** Plain-text body shorthand. Overridden by `content` when both are set. */
10
+ message?: string
12
11
  }
13
12
 
14
13
  interface DialogQueueItem {
@@ -16,7 +15,11 @@ interface DialogQueueItem {
16
15
  resolve: (value: boolean) => void
17
16
  }
18
17
 
19
- const dialogQueue = reactive<DialogQueueItem[]>([])
18
+ // shallowReactive (not reactive): aligning DialogOptions with ModalProps pulls in
19
+ // recursive types (ClassValue) and VNode, which blow past TS's depth limit under
20
+ // deep ref-unwrapping. Queue items are written once and read whole, so array-level
21
+ // reactivity is all we need.
22
+ const dialogQueue = shallowReactive<DialogQueueItem[]>([])
20
23
  const isOpen = ref(false)
21
24
  const mountedInstances = ref<symbol[]>([])
22
25
 
@@ -41,7 +44,7 @@ export function useDialog () {
41
44
  }
42
45
 
43
46
  const alert = (options: DialogOptions): Promise<void> => {
44
- return showDialog({ ...options, rejectLabel: '' }).then(() => {})
47
+ return showDialog({ ...options, showCancel: false }).then(() => {})
45
48
  }
46
49
 
47
50
  const destroy = (options: DialogOptions): Promise<boolean> => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjj/nuxt-layer-shadcn-ui",
3
- "version": "0.11.16",
3
+ "version": "0.12.0",
4
4
  "description": "Nuxt layer providing shadcn-vue based UI components",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -42,5 +42,5 @@
42
42
  "vue-i18n": "^11",
43
43
  "vue-router": "^4 || ^5"
44
44
  },
45
- "gitHead": "ccfa49fc9bf2e8b9da159c560ae6449182131abb"
45
+ "gitHead": "690898135beed9a9a0a5620b27585e0e70e693f8"
46
46
  }