Skip to content

Commit

Permalink
refactor: typings again, avoid peer deps
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerCodeMonkey committed Apr 18, 2020
1 parent 685d7e5 commit f2a2586
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 226 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ XLM Wallet Address:
- `npm install ngx-quill`
- for projects using Angular < v5.0.0 install `npm install ngx-quill@1.6.0`
- install `@angular/core`, `@angular/common`, `@angular/forms`, `@angular/platform-browser`, `quill`, and `rxjs` - peer dependencies of ngx-quill
- install `parchment` and `quill-delta` as peer dependencies for custom typings of `Quill` instances, `Range` and `Delta`
- include theme stylings: bubble.css, snow.css of quilljs in your index.html, or add them in your css/scss files with `@import` statements, or add them external stylings in your build process.

### For standard webpack, angular-cli and tsc builds
Expand Down
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './src/quill-editor.component'
export * from './src/quill-view.component'
export * from './src/quill-view-html.component'
export * from './src/quill-editor.interfaces'
export * from './src/quill.interfaces'
33 changes: 1 addition & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-quill",
"license": "MIT",
"version": "8.1.6",
"version": "8.1.7",
"author": {
"name": "Bengt Weiße"
},
Expand Down Expand Up @@ -54,9 +54,7 @@
"@angular/core": "^7.0.0 || ^8.0.0 || ^9.0.0",
"@angular/forms": "^7.0.0 || ^8.0.0 || ^9.0.0",
"@angular/platform-browser": "^7.0.0 || ^8.0.0 || ^9.0.0",
"parchment": "^1.1.4",
"quill": "^1.3.7",
"quill-delta": "^4.2.2",
"rxjs": "^6.4.0 || ^6.5.0"
},
"devDependencies": {
Expand All @@ -83,9 +81,7 @@
"jest-preset-angular": "^8.1.3",
"loader-utils": "^2.0.0",
"ng-packagr": "^9.1.1",
"parchment": "^1.1.4",
"quill": "^1.3.7",
"quill-delta": "^4.2.2",
"reflect-metadata": "^0.1.13",
"rollup": "^1.20.0",
"rxjs": "^6.5.5",
Expand Down
27 changes: 14 additions & 13 deletions src/quill-editor.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {DOCUMENT, isPlatformServer} from '@angular/common'
import {DomSanitizer} from '@angular/platform-browser'

import {QUILL_CONFIG_TOKEN, QuillConfig, QuillModules, Quill, Delta} from './quill-editor.interfaces'
import {QUILL_CONFIG_TOKEN, QuillConfig, QuillModules} from './quill-editor.interfaces'

import {
AfterViewInit,
Expand All @@ -26,6 +26,7 @@ import {ControlValueAccessor, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validator} from
import {defaultModules} from './quill-defaults'

import {getFormat} from './helpers'
import { QuillDelta, QuillEditor } from './quill.interfaces'

// Because quill uses `document` directly, we cannot `import` during SSR
// instead, we load dynamically via `require('quill')` in `ngAfterViewInit()`
Expand All @@ -44,28 +45,28 @@ export interface Range {

export interface ContentChange {
content: any
delta: Delta
editor: Quill
delta: QuillDelta
editor: QuillEditor
html: string | null
oldDelta: Delta
oldDelta: QuillDelta
source: string
text: string
}

export interface SelectionChange {
editor: Quill
editor: QuillEditor
oldRange: Range | null
range: Range | null
source: string
}

export interface Blur {
editor: Quill
editor: QuillEditor
source: string
}

export interface Focus {
editor: Quill
editor: QuillEditor
source: string
}

Expand Down Expand Up @@ -107,7 +108,7 @@ export class QuillEditorComponent implements AfterViewInit, ControlValueAccessor
}, [])
}

quillEditor!: Quill
quillEditor!: QuillEditor
editorElem: HTMLElement | undefined
content: any

Expand All @@ -133,7 +134,7 @@ export class QuillEditorComponent implements AfterViewInit, ControlValueAccessor
@Input() classes?: string
@Input() trimOnValidation = false

@Output() onEditorCreated: EventEmitter<Quill> = new EventEmitter()
@Output() onEditorCreated: EventEmitter<QuillEditor> = new EventEmitter()
@Output() onEditorChanged: EventEmitter<EditorChangeContent | EditorChangeSelection> = new EventEmitter()
@Output() onContentChanged: EventEmitter<ContentChange> = new EventEmitter()
@Output() onSelectionChanged: EventEmitter<SelectionChange> = new EventEmitter()
Expand All @@ -157,12 +158,12 @@ export class QuillEditorComponent implements AfterViewInit, ControlValueAccessor
onValidatorChanged() {}

@Input()
valueGetter = (quillEditor: Quill, editorElement: HTMLElement): string | any  => {
valueGetter = (quillEditor: QuillEditor, editorElement: HTMLElement): string | any  => {
let html: string | null = editorElement.querySelector('.ql-editor')!.innerHTML
if (html === '<p><br></p>' || html === '<div><br></div>') {
html = null
}
let modelValue: string | Delta | null = html
let modelValue: string | QuillDelta | null = html
const format = getFormat(this.format, this.config.format)

if (format === 'text') {
Expand All @@ -181,7 +182,7 @@ export class QuillEditorComponent implements AfterViewInit, ControlValueAccessor
}

@Input()
valueSetter = (quillEditor: Quill, value: any): any => {
valueSetter = (quillEditor: QuillEditor, value: any): any => {
const format = getFormat(this.format, this.config.format)
if (format === 'html') {
if (this.sanitize) {
Expand Down Expand Up @@ -378,7 +379,7 @@ export class QuillEditorComponent implements AfterViewInit, ControlValueAccessor
})
}

textChangeHandler = (delta: Delta, oldDelta: Delta, source: string): void => {
textChangeHandler = (delta: QuillDelta, oldDelta: QuillDelta, source: string): void => {
// only emit changes emitted by user interactions
const text = this.quillEditor.getText()
const content = this.quillEditor.getContents()
Expand Down
5 changes: 1 addition & 4 deletions src/quill-editor.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InjectionToken } from '@angular/core'
import { Quill as QuillEditor, QuillDelta } from './quill'

export type QuillToolbarConfig = Array<Array< string | {
indent?: string
Expand Down Expand Up @@ -50,11 +49,9 @@ export interface QuillConfig {
readOnly?: boolean
scrollingContainer?: HTMLElement | string | null
theme?: string
strict?: boolean
// Custom Config to track all changes or only changes by 'user'
trackChanges?: 'user' | 'all'
}

export type Quill = QuillEditor
export type Delta = QuillDelta

export const QUILL_CONFIG_TOKEN = new InjectionToken<QuillConfig>('config')
7 changes: 4 additions & 3 deletions src/quill-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isPlatformServer } from '@angular/common'

import { QUILL_CONFIG_TOKEN, QuillConfig, QuillModules, Quill } from './quill-editor.interfaces'
import { QUILL_CONFIG_TOKEN, QuillConfig, QuillModules } from './quill-editor.interfaces'

import {
AfterViewInit,
Expand All @@ -19,6 +19,7 @@ import {
import { defaultModules } from './quill-defaults'
import { CustomOption } from './quill-editor.component'
import {getFormat} from './helpers'
import { QuillEditor } from './quill.interfaces'

// Because quill uses `document` directly, we cannot `import` during SSR
// instead, we load dynamically via `require('quill')` in `ngAfterViewInit()`
Expand All @@ -37,7 +38,7 @@ let Quill: any = null
`
})
export class QuillViewComponent implements AfterViewInit, OnChanges {
quillEditor!: Quill
quillEditor!: QuillEditor
editorElem: HTMLElement | undefined

@Input() format?: 'object' | 'html' | 'text' | 'json'
Expand All @@ -58,7 +59,7 @@ export class QuillViewComponent implements AfterViewInit, OnChanges {
@Inject(NgZone) private zone: NgZone
) {}

valueSetter = (quillEditor: Quill, value: any): any => {
valueSetter = (quillEditor: QuillEditor, value: any): any => {
const format = getFormat(this.format, this.config.format)
let content = value
if (format === 'html' || format === 'text') {
Expand Down
Loading

0 comments on commit f2a2586

Please sign in to comment.