| 20 | } |
| 21 | |
| 22 | export function liveEditingRule(target: EditingTarget) { |
| 23 | // for vision components specific |
| 24 | const { node, event } = target; |
| 25 | |
| 26 | const targetElement = event.target as HTMLElement; |
| 27 | |
| 28 | if (!Array.from(targetElement.childNodes).every((item) => item.nodeType === Node.TEXT_NODE)) { |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | const { innerText } = targetElement; |
| 33 | const propTarget = ['title', 'label', 'text', 'content', 'children'].find((prop) => { |
| 34 | return equalText(getText(node, prop), innerText); |
| 35 | }); |
| 36 | |
| 37 | if (propTarget) { |
| 38 | return { |
| 39 | propElement: targetElement, |
| 40 | propTarget, |
| 41 | }; |
| 42 | } |
| 43 | return null; |
| 44 | } |
| 45 | |
| 46 | function equalText(v: any, innerText: string) { |
| 47 | // TODO: enhance compare text logic |