2021-10-28 17:47:16 +02:00
|
|
|
export function filterOutModifiersFromData(dataList: any[]): { modifiers: string[]; data: any[] } {
|
2021-10-26 11:01:57 +02:00
|
|
|
dataList = dataList.slice();
|
|
|
|
|
const modifiers = [];
|
|
|
|
|
let elm;
|
|
|
|
|
while ((elm = dataList[0]) && typeof elm === "string") {
|
|
|
|
|
modifiers.push(dataList.shift());
|
|
|
|
|
}
|
|
|
|
|
return { modifiers, data: dataList };
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 16:45:25 +01:00
|
|
|
export const config = {
|
|
|
|
|
// whether or not blockdom should normalize DOM whenever a block is created.
|
|
|
|
|
// Normalizing dom mean removing empty text nodes (or containing only spaces)
|
|
|
|
|
shouldNormalizeDom: true,
|
|
|
|
|
|
|
|
|
|
// this is the main event handler. Every event handler registered with blockdom
|
|
|
|
|
// will go through this function, giving it the data registered in the block
|
|
|
|
|
// and the event
|
2021-10-27 14:45:29 +02:00
|
|
|
mainEventHandler: (data: any, ev: Event, currentTarget?: EventTarget | null): boolean => {
|
2020-11-26 16:45:25 +01:00
|
|
|
if (typeof data === "function") {
|
|
|
|
|
data(ev);
|
|
|
|
|
} else if (Array.isArray(data)) {
|
2021-10-26 11:01:57 +02:00
|
|
|
data = filterOutModifiersFromData(data).data;
|
2020-11-26 16:45:25 +01:00
|
|
|
data[0](data[1], ev);
|
|
|
|
|
}
|
2021-10-27 14:45:29 +02:00
|
|
|
return false;
|
2020-11-26 16:45:25 +01:00
|
|
|
},
|
|
|
|
|
};
|