generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent fetch resources in contenteditable
- Loading branch information
Showing
17 changed files
with
240 additions
and
18 deletions.
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
12 changes: 12 additions & 0 deletions
12
projects/demo/src/app/pages/embed/pdf/examples/1/index.html
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,12 @@ | ||
<tui-editor | ||
class="editor" | ||
[formControl]="control" | ||
[tools]="builtInTools" | ||
(fileAttached)="attach($event)" | ||
/> | ||
|
||
<h4>HTML:</h4> | ||
<div [innerHTML]="safe(control.value)"></div> | ||
|
||
<h4>Text:</h4> | ||
<p>{{ control.value }}</p> |
19 changes: 19 additions & 0 deletions
19
projects/demo/src/app/pages/embed/pdf/examples/1/index.less
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,19 @@ | ||
.editor { | ||
min-height: 700px; | ||
} | ||
|
||
:host { | ||
&._e2e ::ng-deep { | ||
//noinspection CssInvalidPseudoSelector | ||
video::-webkit-media-controls-current-time-display, | ||
video::-webkit-media-controls-time-remaining-display, | ||
audio::-webkit-media-controls-current-time-display, | ||
audio::-webkit-media-controls-time-remaining-display { | ||
display: none; | ||
} | ||
} | ||
|
||
::ng-deep iframe { | ||
border: 1px solid var(--tui-background-accent-1); | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
projects/demo/src/app/pages/embed/pdf/examples/1/index.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,137 @@ | ||
import type {Injector} from '@angular/core'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
inject, | ||
INJECTOR, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import {FormControl, ReactiveFormsModule, Validators} from '@angular/forms'; | ||
import type {SafeHtml} from '@angular/platform-browser'; | ||
import {DomSanitizer} from '@angular/platform-browser'; | ||
import {TUI_IS_E2E, tuiPure, tuiTypedFromEvent} from '@taiga-ui/cdk'; | ||
import type {TuiEditorAttachedFile} from '@taiga-ui/editor'; | ||
import { | ||
TUI_ATTACH_FILES_LOADER, | ||
TUI_ATTACH_FILES_OPTIONS, | ||
TUI_EDITOR_EXTENSIONS, | ||
TuiEditor, | ||
TuiEditorTool, | ||
} from '@taiga-ui/editor'; | ||
import type {Observable} from 'rxjs'; | ||
import {map} from 'rxjs'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [ReactiveFormsModule, TuiEditor], | ||
templateUrl: './index.html', | ||
styleUrls: ['./index.less'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
providers: [ | ||
{ | ||
provide: TUI_EDITOR_EXTENSIONS, | ||
deps: [INJECTOR], | ||
useFactory: (injector: Injector) => [ | ||
import('@taiga-ui/editor').then(({TuiStarterKit}) => TuiStarterKit), | ||
import('@tiptap/extension-text-style').then(({TextStyle}) => TextStyle), | ||
import('@taiga-ui/editor').then(({TuiLink}) => TuiLink), | ||
import('@taiga-ui/editor').then(({TuiFileLink}) => TuiFileLink), | ||
import('@taiga-ui/editor').then(({tuiCreateIframeEditorExtension}) => | ||
tuiCreateIframeEditorExtension({injector}), | ||
), | ||
], | ||
}, | ||
{ | ||
provide: TUI_ATTACH_FILES_LOADER, | ||
useFactory: | ||
() => | ||
([file]: File[]): Observable< | ||
Array<TuiEditorAttachedFile<{type: string}>> | ||
> => { | ||
const fileReader = new FileReader(); | ||
|
||
// For example, instead of uploading to a file server, | ||
// we convert the result immediately into content to base64 | ||
fileReader.readAsDataURL(file); | ||
|
||
return tuiTypedFromEvent(fileReader, 'load').pipe( | ||
map(() => [ | ||
{ | ||
name: file.name, | ||
|
||
/* base64 or link to the file on your server */ | ||
link: String(fileReader.result), | ||
|
||
attrs: { | ||
type: file.type, | ||
}, | ||
}, | ||
]), | ||
); | ||
}, | ||
}, | ||
{ | ||
provide: TUI_ATTACH_FILES_OPTIONS, | ||
useValue: { | ||
accept: 'application/pdf', | ||
multiple: false, | ||
}, | ||
}, | ||
], | ||
host: { | ||
class: 'html5-editor-example', | ||
'[class._e2e]': 'isE2E', | ||
}, | ||
}) | ||
export default class Example { | ||
@ViewChild(TuiEditor) | ||
private readonly editor?: TuiEditor; | ||
|
||
private readonly sanitizer = inject(DomSanitizer); | ||
|
||
protected readonly isE2E = inject(TUI_IS_E2E); | ||
|
||
protected readonly builtInTools = [ | ||
TuiEditorTool.Undo, | ||
TuiEditorTool.Link, | ||
TuiEditorTool.Attach, | ||
]; | ||
|
||
protected readonly control = new FormControl( | ||
` | ||
<p>sample.pdf</p> | ||
<iframe | ||
data-type="iframe-editor" | ||
src="https://mozilla.github.io/pdf.js/web/viewer.html?url=https://pdfobject.com/pdf/sample.pdf" | ||
width="100%" | ||
height="300" | ||
></iframe> | ||
<p>Hello world</p> | ||
`, | ||
Validators.required, | ||
); | ||
|
||
@tuiPure | ||
protected safe(content: string | null): SafeHtml { | ||
return this.sanitizer.bypassSecurityTrustHtml(content ?? ''); | ||
} | ||
|
||
protected attach([file]: Array<TuiEditorAttachedFile<{type: string}>>): void { | ||
this.editor?.editorService | ||
?.getOriginTiptapEditor() | ||
?.chain() | ||
.focus('end') | ||
.createParagraphNear() | ||
.insertContent(file.name) | ||
.run(); | ||
|
||
this.editor?.editorService?.setIframe({ | ||
allowfullscreen: false, | ||
frameborder: null, | ||
// For example, src: `https://mozilla.github.io/pdf.js/web/viewer.html?url${file.link}`, | ||
src: `data:application/pdf;base64${file.link}`, | ||
width: '100%', | ||
height: 300, | ||
}); | ||
} | ||
} |
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,11 @@ | ||
<tui-doc-page | ||
header="Editor" | ||
type="components" | ||
> | ||
<tui-doc-example | ||
id="pdf" | ||
heading="PDF" | ||
[component]="component1" | ||
[content]="example1" | ||
/> | ||
</tui-doc-page> |
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,25 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {RouterLink} from '@angular/router'; | ||
import {TuiAddonDoc} from '@taiga-ui/addon-doc'; | ||
import {TuiLink} from '@taiga-ui/core'; | ||
import {TUI_EDITOR_DEFAULT_EXTENSIONS, TUI_EDITOR_EXTENSIONS} from '@taiga-ui/editor'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [TuiAddonDoc, TuiLink, RouterLink], | ||
templateUrl: './index.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
providers: [ | ||
{ | ||
provide: TUI_EDITOR_EXTENSIONS, | ||
useValue: TUI_EDITOR_DEFAULT_EXTENSIONS, | ||
}, | ||
], | ||
}) | ||
export default class Example { | ||
protected readonly component1 = import('./examples/1'); | ||
protected readonly example1 = { | ||
HTML: import('./examples/1/index.html?raw'), | ||
TypeScript: import('./examples/1/index.ts?raw'), | ||
}; | ||
} |
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
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
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