@inertiaui/modal-react 0.6.0 → 0.6.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/dist/inertiaui-modal.js +871 -860
- package/dist/inertiaui-modal.umd.cjs +11 -11
- package/package.json +1 -1
- package/src/ModalRoot.jsx +24 -5
package/package.json
CHANGED
package/src/ModalRoot.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createElement, useEffect, useState } from 'react'
|
|
1
|
+
import { createElement, useEffect, useState, useRef } from 'react'
|
|
2
2
|
import { default as Axios } from 'axios'
|
|
3
3
|
import { except, only } from './helpers'
|
|
4
|
-
import { router } from '@inertiajs/react'
|
|
4
|
+
import { router, usePage } from '@inertiajs/react'
|
|
5
5
|
import { mergeDataIntoQueryString } from '@inertiajs/core'
|
|
6
6
|
import { createContext, useContext } from 'react'
|
|
7
7
|
import ModalRenderer from './ModalRenderer'
|
|
@@ -226,10 +226,14 @@ export const ModalStackProvider = ({ children }) => {
|
|
|
226
226
|
'X-InertiaUI-Modal-Use-Router': 0,
|
|
227
227
|
},
|
|
228
228
|
}).then((response) => {
|
|
229
|
-
|
|
230
|
-
updateStack((prevStack) => prevStack) // Trigger re-render
|
|
229
|
+
this.updateProps(response.data.props)
|
|
231
230
|
})
|
|
232
231
|
}
|
|
232
|
+
|
|
233
|
+
updateProps = (props) => {
|
|
234
|
+
Object.assign(this.props, props)
|
|
235
|
+
updateStack((prevStack) => prevStack) // Trigger re-render
|
|
236
|
+
}
|
|
233
237
|
}
|
|
234
238
|
|
|
235
239
|
const pushFromResponseData = (responseData, config = {}, onClose = null, onAfterLeave = null) => {
|
|
@@ -307,6 +311,7 @@ export const ModalStackProvider = ({ children }) => {
|
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
if (useInertiaRouter) {
|
|
314
|
+
newModalOnBase = null
|
|
310
315
|
// Pushing the modal to the stack will be handled by the ModalRoot...
|
|
311
316
|
return router.visit(url, {
|
|
312
317
|
method,
|
|
@@ -333,7 +338,6 @@ export const ModalStackProvider = ({ children }) => {
|
|
|
333
338
|
)
|
|
334
339
|
|
|
335
340
|
resolve(modal)
|
|
336
|
-
newModalOnBase = null
|
|
337
341
|
})
|
|
338
342
|
},
|
|
339
343
|
})
|
|
@@ -494,6 +498,21 @@ export const ModalRoot = ({ children }) => {
|
|
|
494
498
|
return () => Axios.interceptors.request.eject(axiosRequestInterceptor)
|
|
495
499
|
}, [])
|
|
496
500
|
|
|
501
|
+
const $page = usePage()
|
|
502
|
+
const previousModalRef = useRef()
|
|
503
|
+
|
|
504
|
+
useEffect(() => {
|
|
505
|
+
const newModal = $page.props?._inertiaui_modal
|
|
506
|
+
const previousModal = previousModalRef.current
|
|
507
|
+
|
|
508
|
+
// Store the current value for the next render
|
|
509
|
+
previousModalRef.current = newModal
|
|
510
|
+
|
|
511
|
+
if (newModal && previousModal && newModal.component === previousModal.component && newModal.url === previousModal.url) {
|
|
512
|
+
context.stack[0]?.updateProps(newModal.props ?? {})
|
|
513
|
+
}
|
|
514
|
+
}, [$page.props?._inertiaui_modal])
|
|
515
|
+
|
|
497
516
|
return (
|
|
498
517
|
<>
|
|
499
518
|
{children}
|