@inertiaui/modal-react 0.6.4 → 0.7.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.
- package/dist/inertiaui-modal.js +1018 -1009
- package/dist/inertiaui-modal.umd.cjs +13 -13
- package/package.json +1 -1
- package/src/ModalRoot.jsx +18 -11
- package/src/helpers.js +2 -2
package/package.json
CHANGED
package/src/ModalRoot.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createElement, useEffect, useState, useRef } from 'react'
|
|
2
2
|
import { default as Axios } from 'axios'
|
|
3
|
-
import { except, only } from './helpers'
|
|
3
|
+
import { except, only, kebabCase } from './helpers'
|
|
4
4
|
import { router, usePage } from '@inertiajs/react'
|
|
5
5
|
import { mergeDataIntoQueryString } from '@inertiajs/core'
|
|
6
6
|
import { createContext, useContext } from 'react'
|
|
@@ -164,11 +164,13 @@ export const ModalStackProvider = ({ children }) => {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
on = (event, callback) => {
|
|
167
|
+
event = kebabCase(event)
|
|
167
168
|
this.listeners[event] = this.listeners[event] ?? []
|
|
168
169
|
this.listeners[event].push(callback)
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
off = (event, callback) => {
|
|
173
|
+
event = kebabCase(event)
|
|
172
174
|
if (callback) {
|
|
173
175
|
this.listeners[event] = this.listeners[event]?.filter((cb) => cb !== callback) ?? []
|
|
174
176
|
} else {
|
|
@@ -177,7 +179,7 @@ export const ModalStackProvider = ({ children }) => {
|
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
emit = (event, ...args) => {
|
|
180
|
-
this.listeners[event]?.forEach((callback) => callback(...args))
|
|
182
|
+
this.listeners[kebabCase(event)]?.forEach((callback) => callback(...args))
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
registerEventListenersFromProps = (props) => {
|
|
@@ -187,14 +189,9 @@ export const ModalStackProvider = ({ children }) => {
|
|
|
187
189
|
.filter((key) => key.startsWith('on'))
|
|
188
190
|
.forEach((key) => {
|
|
189
191
|
// e.g. onRefreshKey -> refresh-key
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
.replace(/([A-Z])/g, '-$1')
|
|
194
|
-
.toLowerCase()
|
|
195
|
-
|
|
196
|
-
this.on(snakeCaseKey, props[key])
|
|
197
|
-
unsubscribers.push(() => this.off(snakeCaseKey, props[key]))
|
|
192
|
+
const eventName = kebabCase(key).replace(/^on-/, '')
|
|
193
|
+
this.on(eventName, props[key])
|
|
194
|
+
unsubscribers.push(() => this.off(eventName, props[key]))
|
|
198
195
|
})
|
|
199
196
|
|
|
200
197
|
return () => unsubscribers.forEach((unsub) => unsub())
|
|
@@ -274,7 +271,17 @@ export const ModalStackProvider = ({ children }) => {
|
|
|
274
271
|
options.onAfterLeave,
|
|
275
272
|
options.queryStringArrayFormat ?? 'brackets',
|
|
276
273
|
options.navigate ?? getConfig('navigate'),
|
|
277
|
-
)
|
|
274
|
+
).then((modal) => {
|
|
275
|
+
const listeners = options.listeners ?? {}
|
|
276
|
+
|
|
277
|
+
Object.keys(listeners).forEach((event) => {
|
|
278
|
+
// e.g. refreshKey -> refresh-key
|
|
279
|
+
const eventName = kebabCase(event)
|
|
280
|
+
modal.on(eventName, listeners[event])
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
return modal
|
|
284
|
+
})
|
|
278
285
|
|
|
279
286
|
const visit = (
|
|
280
287
|
href,
|
package/src/helpers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { except, only, rejectNullValues, waitFor } from './../../vue/src/helpers.js'
|
|
2
|
-
export { except, only, rejectNullValues, waitFor }
|
|
1
|
+
import { except, only, rejectNullValues, waitFor, kebabCase } from './../../vue/src/helpers.js'
|
|
2
|
+
export { except, only, rejectNullValues, waitFor, kebabCase }
|