(
element: HTMLElement,
note: NoteInfo,
plugin: TaskNotesPlugin,
options: Partial<NoteCardOptions> = {}
)
| 166 | * Update an existing note card with new data |
| 167 | */ |
| 168 | export function updateNoteCard( |
| 169 | element: HTMLElement, |
| 170 | note: NoteInfo, |
| 171 | plugin: TaskNotesPlugin, |
| 172 | options: Partial<NoteCardOptions> = {} |
| 173 | ): void { |
| 174 | const opts = { ...DEFAULT_NOTE_CARD_OPTIONS, ...options }; |
| 175 | |
| 176 | // Update main element classes using BEM structure |
| 177 | // Check if this is a daily note using the core plugin |
| 178 | let isDailyNote = false; |
| 179 | try { |
| 180 | const allDailyNotes = getAllDailyNotes(); |
| 181 | isDailyNote = Object.values(allDailyNotes).some((file) => file.path === note.path); |
| 182 | } catch { |
| 183 | // Daily Notes interface not available, fallback to false |
| 184 | isDailyNote = false; |
| 185 | } |
| 186 | |
| 187 | // Build BEM class names for update |
| 188 | const cardClasses = ["note-card"]; |
| 189 | |
| 190 | // Add modifiers |
| 191 | if (isDailyNote) cardClasses.push("note-card--daily-note"); |
| 192 | cardClasses.push("note-card--compact", "note-card--shadow-light"); |
| 193 | |
| 194 | element.className = cardClasses.join(" "); |
| 195 | |
| 196 | // Ensure icon exists (for cards created before this update) |
| 197 | let iconWrap = element.querySelector(".note-card__icon") as HTMLElement; |
| 198 | if (!iconWrap) { |
| 199 | const mainRow = |
| 200 | element.querySelector(".note-card__main-row") || |
| 201 | element.createDiv({ cls: "note-card__main-row" }); |
| 202 | iconWrap = mainRow.createEl("span", { cls: "note-card__icon" }); |
| 203 | const leftIcon = iconWrap.createEl("span"); |
| 204 | setIcon(leftIcon, "file-text"); |
| 205 | |
| 206 | // Move existing content into the main row structure if needed |
| 207 | const existingContent = element.querySelector(".note-card__content"); |
| 208 | if ( |
| 209 | existingContent && |
| 210 | !existingContent.parentElement?.classList.contains("note-card__main-row") |
| 211 | ) { |
| 212 | mainRow.appendChild(existingContent); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // Update title |
| 217 | const titleEl = element.querySelector(".note-card__title") as HTMLElement; |
| 218 | if (titleEl) { |
| 219 | titleEl.textContent = note.title; |
| 220 | } |
| 221 | |
| 222 | // Update created date |
| 223 | const dateEl = element.querySelector(".note-card__metadata") as HTMLElement; |
| 224 | if (dateEl && opts.showCreatedDate && note.createdDate) { |
| 225 | const timeFormat = plugin.settings.calendarViewSettings.timeFormat; |
nothing calls this directly
no test coverage detected