fix trigger children ext
This commit is contained in:
parent
1f0a840396
commit
150c87b456
2 changed files with 8 additions and 33 deletions
4
framework/assets/dist/htmgo.js
vendored
4
framework/assets/dist/htmgo.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
||||||
import htmx, {HtmxSettleInfo, HtmxSwapStyle} from "htmx.org";
|
import htmx from "htmx.org";
|
||||||
|
|
||||||
function kebabEventName(str: string) {
|
function kebabEventName(str: string) {
|
||||||
return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
|
return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
|
||||||
|
|
@ -28,7 +28,10 @@ function triggerChildren(target: HTMLElement, name: string, event: CustomEvent,
|
||||||
const eventName = kehab.replace("htmx:", "hx-on::")
|
const eventName = kehab.replace("htmx:", "hx-on::")
|
||||||
if (!triggered.has(e as HTMLElement)) {
|
if (!triggered.has(e as HTMLElement)) {
|
||||||
if(e.hasAttribute(eventName)) {
|
if(e.hasAttribute(eventName)) {
|
||||||
const newEvent = makeEvent(eventName.replace("hx-on::", "htmx:"), event.detail)
|
const newEvent = makeEvent(eventName.replace("hx-on::", "htmx:"), {
|
||||||
|
...event.detail,
|
||||||
|
target: e,
|
||||||
|
})
|
||||||
newEvent.detail.meta = 'trigger-children'
|
newEvent.detail.meta = 'trigger-children'
|
||||||
e.dispatchEvent(newEvent)
|
e.dispatchEvent(newEvent)
|
||||||
triggered.add(e as HTMLElement);
|
triggered.add(e as HTMLElement);
|
||||||
|
|
@ -42,6 +45,7 @@ function triggerChildren(target: HTMLElement, name: string, event: CustomEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
htmx.defineExtension("trigger-children", {
|
htmx.defineExtension("trigger-children", {
|
||||||
onEvent: (name, evt: Event | CustomEvent) => {
|
onEvent: (name, evt: Event | CustomEvent) => {
|
||||||
if (!(evt instanceof CustomEvent)) {
|
if (!(evt instanceof CustomEvent)) {
|
||||||
|
|
@ -55,33 +59,4 @@ htmx.defineExtension("trigger-children", {
|
||||||
triggerChildren(target, name, evt, triggered);
|
triggerChildren(target, name, evt, triggered);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
init: function (api: any): void {
|
|
||||||
},
|
|
||||||
transformResponse: function (
|
|
||||||
text: string,
|
|
||||||
xhr: XMLHttpRequest,
|
|
||||||
elt: Element,
|
|
||||||
): string {
|
|
||||||
return text;
|
|
||||||
},
|
|
||||||
isInlineSwap: function (swapStyle: HtmxSwapStyle): boolean {
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
handleSwap: function (
|
|
||||||
swapStyle: HtmxSwapStyle,
|
|
||||||
target: Node,
|
|
||||||
fragment: Node,
|
|
||||||
settleInfo: HtmxSettleInfo,
|
|
||||||
): boolean | Node[] {
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
encodeParameters: function (
|
|
||||||
xhr: XMLHttpRequest,
|
|
||||||
parameters: FormData,
|
|
||||||
elt: Node,
|
|
||||||
) {
|
|
||||||
},
|
|
||||||
getSelectors: function (): string[] | null {
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue