(
plugin: TaskNotesPlugin,
options: { force?: boolean } = {}
)
| 639 | } |
| 640 | |
| 641 | export function injectCanvasTaskCardWidgets( |
| 642 | plugin: TaskNotesPlugin, |
| 643 | options: { force?: boolean } = {} |
| 644 | ): void { |
| 645 | if (!plugin.settings.showTaskCardInNote) { |
| 646 | return; |
| 647 | } |
| 648 | |
| 649 | for (const leaf of plugin.app.workspace.getLeavesOfType("canvas")) { |
| 650 | for (const node of getCanvasNodes(leaf)) { |
| 651 | const filePath = getCanvasNodeFilePath(node); |
| 652 | const contentEl = node.contentEl; |
| 653 | if (!filePath || !contentEl) { |
| 654 | continue; |
| 655 | } |
| 656 | |
| 657 | const isEditing = isCanvasNodeEditing(node, contentEl); |
| 658 | const sourceEditor = contentEl.querySelector<HTMLElement>( |
| 659 | ".markdown-source-view, .cm-editor" |
| 660 | ); |
| 661 | if (sourceEditor?.querySelector(`.${CSS_TASK_CARD_WIDGET}`)) { |
| 662 | continue; |
| 663 | } |
| 664 | |
| 665 | const targetContainer = findCanvasEmbedTaskCardContainer(contentEl); |
| 666 | if (!isEditing && !targetContainer) { |
| 667 | continue; |
| 668 | } |
| 669 | |
| 670 | if (!options.force && !canvasNodeNeedsWidgetRefresh(node, contentEl)) { |
| 671 | continue; |
| 672 | } |
| 673 | |
| 674 | const task = plugin.cacheManager.getCachedTaskInfoSync(filePath); |
| 675 | removeTaskCardWidgets(contentEl); |
| 676 | |
| 677 | if (!task) { |
| 678 | continue; |
| 679 | } |
| 680 | |
| 681 | const widget = createTaskCardWidget(plugin, task); |
| 682 | if (isEditing) { |
| 683 | contentEl.insertBefore(widget, contentEl.firstChild); |
| 684 | } else if (targetContainer) { |
| 685 | insertAfterMetadataOrHeader(targetContainer, widget); |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Setup reading mode handlers for task card widget |
no test coverage detected