(event: Event, imageWrapper: HTMLElement)
| 519 | |
| 520 | // Handle click inline image. |
| 521 | private _handleClickInlineImage(event: Event, imageWrapper: HTMLElement) { |
| 522 | event.preventDefault(); |
| 523 | event.stopPropagation(); |
| 524 | const { eventCenter } = this.muya; |
| 525 | const imageInfo = getImageInfo(imageWrapper); |
| 526 | const { target } = event; |
| 527 | if (!(target instanceof Node)) |
| 528 | return; |
| 529 | const deleteContainer = isHTMLElement(target) |
| 530 | ? target.closest('.mu-image-icon-close') |
| 531 | : null; |
| 532 | const contentDom = findContentDOM(target); |
| 533 | |
| 534 | if (!contentDom) |
| 535 | return; |
| 536 | |
| 537 | const contentBlock = contentDom[BLOCK_DOM_PROPERTY] as Format; |
| 538 | |
| 539 | if (deleteContainer) { |
| 540 | contentBlock.deleteImage(imageInfo); |
| 541 | |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | // Handle image click, to select the current image |
| 546 | if (isHTMLElement(target) && target.tagName === 'IMG') { |
| 547 | // Handle show image toolbar |
| 548 | const rect = imageWrapper |
| 549 | .querySelector(`.${CLASS_NAMES.MU_IMAGE_CONTAINER}`) |
| 550 | ?.getBoundingClientRect(); |
| 551 | const reference = { |
| 552 | getBoundingClientRect: () => rect, |
| 553 | width: imageWrapper.offsetWidth, |
| 554 | height: imageWrapper.offsetHeight, |
| 555 | }; |
| 556 | |
| 557 | // Show image edit tool bar. |
| 558 | eventCenter.emit('muya-image-toolbar', { |
| 559 | block: contentBlock, |
| 560 | reference, |
| 561 | imageInfo, |
| 562 | }); |
| 563 | |
| 564 | // Handle show image transformer. |
| 565 | // marktext d26f5092 (#1335): the resize bar should only appear for |
| 566 | // block-aligned images. Inline images flow with surrounding text |
| 567 | // and dragging their edges has no meaningful resize semantics. |
| 568 | if (shouldShowImageResizeBar(imageInfo.token)) { |
| 569 | const imageSelector = `#${imageInfo.imageId}`; |
| 570 | |
| 571 | const imageContainer = document.querySelector( |
| 572 | `${imageSelector} .${CLASS_NAMES.MU_IMAGE_CONTAINER}`, |
| 573 | ); |
| 574 | |
| 575 | eventCenter.emit('muya-transformer', { |
| 576 | block: contentBlock, |
| 577 | reference: imageContainer, |
| 578 | imageInfo, |
no test coverage detected