| 20 | >, |
| 21 | ): void |
| 22 | export function handler(options: any, map?: any) { |
| 23 | if (!currentTemplate) return |
| 24 | const draft = currentTemplate.draft |
| 25 | assert( |
| 26 | draft.type === 'element', |
| 27 | `"handler" extension can be used only with element nodes, got "${draft.type}"`, |
| 28 | ) |
| 29 | if (map === undefined) { |
| 30 | map = options |
| 31 | options = {} |
| 32 | } |
| 33 | for (const key in map) { |
| 34 | assert(is.unit(map[key]), `handler for "${key}" should be event`) |
| 35 | } |
| 36 | const { |
| 37 | passive = false, |
| 38 | capture = false, |
| 39 | prevent = false, |
| 40 | stop = false, |
| 41 | } = options |
| 42 | draft.handler.push({ |
| 43 | options: { |
| 44 | prevent, |
| 45 | stop, |
| 46 | }, |
| 47 | domConfig: { |
| 48 | passive: prevent ? false : passive, |
| 49 | capture, |
| 50 | }, |
| 51 | map, |
| 52 | }) |
| 53 | } |