{"version":3,"file":"taiga-ui-editor-extensions-iframe-editor.mjs","sources":["../../../projects/editor/extensions/iframe-editor/iframe-editor.options.ts","../../../projects/editor/extensions/iframe-editor/iframe-editor.component.ts","../../../projects/editor/extensions/iframe-editor/iframe-editor.component.html","../../../projects/editor/extensions/iframe-editor/iframe-editor.extension.ts","../../../projects/editor/extensions/iframe-editor/taiga-ui-editor-extensions-iframe-editor.ts"],"sourcesContent":["/// <reference types=\"@taiga-ui/tsconfig/ng-dev-mode\" />\nimport {InjectionToken} from '@angular/core';\nimport {type TuiEditableIframeOptions} from '@taiga-ui/editor/common';\n\n/**\n * Size of resizable iframe inside editor\n */\nexport const TUI_IFRAME_EDITOR_OPTIONS = new InjectionToken<TuiEditableIframeOptions>(\n    ngDevMode ? 'TUI_IFRAME_EDITOR_OPTIONS' : '',\n    {\n        factory: () => ({\n            minWidth: 100,\n            maxWidth: Infinity,\n            minHeight: 100,\n            maxHeight: Infinity,\n        }),\n    },\n);\n","import {\n    ChangeDetectionStrategy,\n    ChangeDetectorRef,\n    Component,\n    ElementRef,\n    inject,\n} from '@angular/core';\nimport {DomSanitizer, type SafeResourceUrl} from '@angular/platform-browser';\nimport {tuiPure} from '@taiga-ui/cdk';\nimport {TUI_EDITOR_RESIZE_EVENT, type TuiEditableIframe} from '@taiga-ui/editor/common';\nimport {\n    AbstractTuiEditorResizable,\n    TuiEditorResizable,\n} from '@taiga-ui/editor/components/editor-resizable';\n\nimport {TUI_IFRAME_EDITOR_OPTIONS} from './iframe-editor.options';\n\n@Component({\n    standalone: true,\n    selector: 'tui-iframe-editor',\n    imports: [TuiEditorResizable],\n    templateUrl: './iframe-editor.component.html',\n    styleUrls: ['./iframe-editor.component.less'],\n    changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class TuiIframeEditor extends AbstractTuiEditorResizable<TuiEditableIframe> {\n    private readonly sanitizer = inject(DomSanitizer);\n    private readonly el: ElementRef<HTMLDivElement> = inject(ElementRef);\n    protected readonly options = inject(TUI_IFRAME_EDITOR_OPTIONS);\n    protected readonly changeDetector = inject(ChangeDetectorRef);\n\n    public updateSize([width, height]: readonly [width: number, height: number]): void {\n        this.currentWidth = Math.max(\n            this.options.minWidth,\n            Math.min(this.options.maxWidth, width),\n        );\n\n        this.currentHeight = Math.max(\n            this.options.minHeight,\n            Math.min(this.options.maxHeight, height),\n        );\n\n        this.attrs.width = this.currentWidth;\n        this.attrs.height = this.currentHeight;\n\n        this.el.nativeElement.dispatchEvent(\n            new CustomEvent(TUI_EDITOR_RESIZE_EVENT, {bubbles: true}),\n        );\n    }\n\n    @tuiPure\n    protected get src(): SafeResourceUrl {\n        return this.sanitizer.bypassSecurityTrustResourceUrl(this.attrs.src ?? '');\n    }\n}\n","<tui-editor-resizable\n    [height]=\"height\"\n    [isEditable]=\"editor.isEditable\"\n    [width]=\"width\"\n    (sizeChange)=\"updateSize($event)\"\n>\n    <iframe\n        alt=\"\"\n        [height]=\"height\"\n        [src]=\"src\"\n        [style.max-height]=\"options.maxHeight\"\n        [style.max-width]=\"options.maxWidth\"\n        [style.min-height]=\"options.minHeight\"\n        [style.min-width]=\"options.minWidth\"\n        [width]=\"width\"\n    ></iframe>\n</tui-editor-resizable>\n","import {type Injector} from '@angular/core';\nimport {type TuiEditableIframe} from '@taiga-ui/editor/common';\nimport {TuiNodeView} from '@taiga-ui/editor/extensions/tiptap-node-view';\nimport {\n    type Attribute,\n    mergeAttributes,\n    Node,\n    type NodeViewRenderer,\n    type NodeViewRendererProps,\n    type RawCommands,\n} from '@tiptap/core';\nimport {type DOMOutputSpec, type NodeSpec} from '@tiptap/pm/model';\nimport {type NodeView} from '@tiptap/pm/view';\n\nimport {TuiIframeEditor} from './iframe-editor.component';\n\ndeclare module '@tiptap/core' {\n    interface Commands<ReturnType> {\n        iframe: {\n            setIframe(options: TuiEditableIframe): ReturnType;\n        };\n    }\n}\n\nexport const tuiCreateIframeEditorExtension = ({injector}: {injector: Injector}): Node =>\n    Node.create({\n        name: 'iframe',\n        group: 'block',\n        atom: true,\n        draggable: false,\n\n        parseHTML(): NodeSpec['parseDOM'] {\n            return [{tag: 'iframe'}];\n        },\n\n        addAttributes(): Record<keyof TuiEditableIframe, Attribute> {\n            return {\n                src: {\n                    default: null,\n                    keepOnSplit: false,\n                    parseHTML: (element) => element.getAttribute('src'),\n                },\n                frameborder: {\n                    default: 0,\n                    keepOnSplit: false,\n                    parseHTML: (element) => element.getAttribute('frameborder'),\n                },\n                width: {\n                    default: '100%',\n                    keepOnSplit: false,\n                    parseHTML: (element) => element.getAttribute('width'),\n                },\n                height: {\n                    default: null,\n                    keepOnSplit: false,\n                    parseHTML: (element) => element.getAttribute('height'),\n                },\n                allowfullscreen: {\n                    keepOnSplit: false,\n                    default: this.options.allowFullscreen,\n                    parseHTML: (element) => element.getAttribute('allowfullscreen'),\n                },\n            };\n        },\n\n        renderHTML({HTMLAttributes}: Record<string, any>): DOMOutputSpec {\n            return [\n                'iframe',\n                mergeAttributes(HTMLAttributes, {'data-type': 'iframe-editor'}),\n            ];\n        },\n\n        addNodeView(): NodeViewRenderer {\n            return (props: NodeViewRendererProps): NodeView =>\n                new TuiNodeView(TuiIframeEditor, props, {\n                    injector,\n                    ...props,\n                }) as unknown as NodeView;\n        },\n\n        addCommands(): Partial<RawCommands> {\n            return {\n                setIframe:\n                    (attrs) =>\n                    ({commands, state}) => {\n                        const prevLine = state.selection.anchor;\n\n                        commands.enter();\n                        commands.setTextSelection(prevLine);\n\n                        commands.insertContent({\n                            type: this.name,\n                            attrs,\n                        });\n\n                        commands.setTextSelection(state.selection.anchor);\n\n                        return true;\n                    },\n            };\n        },\n    });\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AAIA;;AAEG;AACU,MAAA,yBAAyB,GAAG,IAAI,cAAc,CACvD,SAAS,GAAG,2BAA2B,GAAG,EAAE,EAC5C;AACI,IAAA,OAAO,EAAE,OAAO;AACZ,QAAA,QAAQ,EAAE,GA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