-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add footnotes functionnality to richtext #2071
Merged
+1,500
−972
Merged
Changes from 43 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
e1b087b
wip: works: loads ckeditor5-custom-build
derschnee68 940534e
wip: tooltip
derschnee68 afd26e7
wip: footnote display tooltip
derschnee68 f358609
wip
derschnee68 7918966
feat: add footnotes to the property value
derschnee68 8c5167a
fix
derschnee68 a2440b9
fix: improve style
derschnee68 3704f8a
fix
derschnee68 8c7250f
fix
derschnee68 59fde3f
fix
derschnee68 2bff43a
fix
derschnee68 d917c44
fix: updating bug
derschnee68 a619ef7
fix: two footnotes updating
derschnee68 76dc506
fix: style
derschnee68 63b9b19
fix: edit animation
derschnee68 8295a03
wip
derschnee68 99db9ce
fix
derschnee68 4b33f51
fix
derschnee68 1e57f28
Merge remote-tracking branch 'origin/main' into julien/footnote-display
derschnee68 e022c2d
fix
derschnee68 dfe67de
fix
derschnee68 4974f49
fix
derschnee68 8bbe2c4
fix
derschnee68 6d67af0
fix
derschnee68 d104624
Merge remote-tracking branch 'origin/main' into julien/footnote-display
derschnee68 4e80bd8
fix: new package lock
derschnee68 225f26e
fix lint
derschnee68 5e72717
fix: lint circular dependency
derschnee68 860079e
Merge remote-tracking branch 'origin/main' into julien/fixfootnotes-i…
derschnee68 6b22e5a
fix
derschnee68 25cce2a
fix
derschnee68 764401d
fix: first setup for footnotes
derschnee68 1838468
fix
derschnee68 ce0f593
review: wip
derschnee68 52d1857
Merge remote-tracking branch 'origin/main' into julien/fixfootnotes-i…
derschnee68 1d67dc0
fix
derschnee68 cb4ceec
Merge remote-tracking branch 'origin/main' into julien/fixfootnotes-i…
derschnee68 a11eff9
fix
derschnee68 149a8dd
fix
derschnee68 8a600c4
wip
derschnee68 dadeef0
wip: better
derschnee68 827562c
wip: better
derschnee68 6173bf8
fix
derschnee68 556e8bf
fix
derschnee68 1b840bf
fix
derschnee68 ff43971
fix
derschnee68 d57dd4d
fix
derschnee68 f133e21
fix
derschnee68 fb0635d
fix
derschnee68 5187cd6
fix
derschnee68 52b6a7d
fix
derschnee68 234ccb7
fix
derschnee68 80f7103
fix
derschnee68 8c17c71
Merge branch 'main' into julien/fixfootnotes-issues
derschnee68 45f3479
Revert "fix"
derschnee68 53d38a5
fix
derschnee68 ccfe100
fix
derschnee68 a7f0464
fix
derschnee68 4097edb
fix
derschnee68 9d89854
fix
derschnee68 2c127c5
fix: scroll to view
derschnee68 ac86f64
fix: scroll to view
derschnee68 8df20c6
fix: ckeditor v2.1.4
derschnee68 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class ResourcePage { | ||
visit(id: string) { | ||
cy.visit(`/project/00FF/ontology/00FF/images/${id}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libs/vre/resource-editor/resource-properties/src/lib/footnote-tooltip.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { animate, state, style, transition, trigger } from '@angular/animations'; | ||
import { Component, Input } from '@angular/core'; | ||
import { SafeHtml } from '@angular/platform-browser'; | ||
|
||
@Component({ | ||
selector: 'app-footnote-tooltip', | ||
template: ` <div class="content" [@fadeIn]="'in'"> | ||
<div [innerHTML]="content"></div> | ||
</div>`, | ||
animations: [ | ||
trigger('fadeIn', [ | ||
state('in', style({ opacity: 1 })), | ||
transition(':enter', [style({ opacity: 0 }), animate(100)]), | ||
]), | ||
], | ||
styles: [ | ||
` | ||
:host { | ||
position: absolute; | ||
z-index: 1000; | ||
} | ||
|
||
.content { | ||
font-size: 0.8em; | ||
background: white; | ||
color: black; | ||
padding: 8px; | ||
min-width: 200px; | ||
border-radius: 4px; | ||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); | ||
} | ||
`, | ||
], | ||
}) | ||
export class FootnoteTooltipComponent { | ||
@Input({ required: true }) content!: SafeHtml; | ||
} |
87 changes: 87 additions & 0 deletions
87
libs/vre/resource-editor/resource-properties/src/lib/footnote.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Overlay, OverlayPositionBuilder, OverlayRef } from '@angular/cdk/overlay'; | ||
import { ComponentPortal } from '@angular/cdk/portal'; | ||
import { Directive, HostListener } from '@angular/core'; | ||
import { DomSanitizer } from '@angular/platform-browser'; | ||
import { AppError } from '@dasch-swiss/vre/core/error-handler'; | ||
import { FootnoteTooltipComponent } from './footnote-tooltip.component'; | ||
|
||
@Directive({ | ||
selector: '[appFootnote]', | ||
}) | ||
export class FootnoteDirective { | ||
private overlayRef: OverlayRef | null = null; | ||
private hideTimeout: any; | ||
derschnee68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
constructor( | ||
private overlay: Overlay, | ||
private positionBuilder: OverlayPositionBuilder, | ||
private sanitizer: DomSanitizer | ||
derschnee68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) {} | ||
|
||
@HostListener('mouseover', ['$event']) | ||
onMouseOver(event: MouseEvent) { | ||
const targetElement = event.target as HTMLElement; | ||
if (targetElement.nodeName.toLowerCase() === 'footnote') { | ||
const content = targetElement.getAttribute('content'); | ||
if (content === null) { | ||
throw new AppError('Footnote content is null'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use translations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intended for the dev
derschnee68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
this.showTooltip(content, event.clientX, event.clientY); | ||
} | ||
} | ||
|
||
@HostListener('mouseout', ['$event.target']) | ||
onMouseOut(targetElement: HTMLElement) { | ||
if (targetElement.nodeName.toLowerCase() === 'footnote') { | ||
this.hideTooltipWithDelay(); | ||
} | ||
} | ||
|
||
private showTooltip(content: string, mouseX: number, mouseY: number) { | ||
if (!this.overlayRef) { | ||
const positionStrategy = this.positionBuilder.flexibleConnectedTo({ x: mouseX, y: mouseY }).withPositions([ | ||
{ | ||
overlayX: 'center', | ||
overlayY: 'top', | ||
originX: 'center', | ||
originY: 'bottom', | ||
offsetY: 10, | ||
}, | ||
]); | ||
|
||
this.overlayRef = this.overlay.create({ | ||
positionStrategy, | ||
scrollStrategy: this.overlay.scrollStrategies.reposition(), | ||
}); | ||
} | ||
|
||
const tooltipPortal = new ComponentPortal(FootnoteTooltipComponent); | ||
if (this.overlayRef.hasAttached()) { | ||
this.overlayRef.detach(); | ||
clearTimeout(this.hideTimeout); | ||
} | ||
|
||
const tooltipRef = this.overlayRef.attach(tooltipPortal); | ||
tooltipRef.instance.content = this.sanitizer.bypassSecurityTrustHtml(content); | ||
|
||
this.overlayRef.overlayElement.addEventListener('mouseenter', () => { | ||
clearTimeout(this.hideTimeout); | ||
}); | ||
|
||
this.overlayRef.overlayElement.addEventListener('mouseleave', () => { | ||
this.hideTooltipWithDelay(); | ||
}); | ||
} | ||
|
||
private hideTooltipWithDelay() { | ||
this.hideTimeout = setTimeout(() => { | ||
this.hideTooltip(); | ||
}, 300); | ||
} | ||
|
||
private hideTooltip() { | ||
if (this.overlayRef) { | ||
this.overlayRef.detach(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
libs/vre/resource-editor/resource-properties/src/lib/footnote.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { SafeHtml } from '@angular/platform-browser'; | ||
|
||
@Injectable() | ||
export class FootnoteService { | ||
footnotes: { uid: string; content: SafeHtml }[] = []; | ||
derschnee68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
addFootnote(uid: string, content: SafeHtml): void { | ||
const property = this.footnotes.find(footnote => footnote.uid === uid); | ||
if (property) { | ||
property.content = content; | ||
} else { | ||
this.footnotes.push({ uid, content }); | ||
} | ||
} | ||
|
||
reset() { | ||
this.footnotes = []; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
libs/vre/resource-editor/resource-properties/src/lib/footnotes.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Component } from '@angular/core'; | ||
import { AppError } from '@dasch-swiss/vre/core/error-handler'; | ||
import { FootnoteService } from './footnote.service'; | ||
|
||
@Component({ | ||
selector: 'app-footnotes', | ||
template: `<h5>Footnotes</h5> | ||
derschnee68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<div | ||
*ngFor="let footnote of footnoteService.footnotes; let index = index" | ||
derschnee68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(click)="goToFootnote(footnote.uid)" | ||
class="footnote" | ||
data-cy="footnote"> | ||
{{ index + 1 }}. <span [innerHTML]="footnote.content"></span> | ||
</div>`, | ||
styles: [ | ||
` | ||
.footnote { | ||
display: flex; | ||
align-items: center; | ||
gap: 5px; | ||
} | ||
`, | ||
], | ||
}) | ||
export class FootnotesComponent { | ||
constructor(public readonly footnoteService: FootnoteService) {} | ||
|
||
goToFootnote(uid: string) { | ||
const element = document.getElementById(uid); | ||
if (!element) { | ||
throw new AppError(`Element with uid ${uid} is not found on page.`); | ||
derschnee68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
element.scrollIntoView(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there might be more tests with footnotes, I suggest moving them to a separate test file