Skip to content

Commit

Permalink
style: stylistic objects
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerCodeMonkey committed Sep 13, 2024
1 parent 292a119 commit ffb19a9
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 35 deletions.
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

8 changes: 7 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export default tseslint.config(
multilineDetection: 'brackets'
}
],
'@stylistic/object-property-newline': ['error'],
'@stylistic/object-curly-newline': ['error'],
'@stylistic/object-curly-spacing': ['error', 'always'],

'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
Expand Down Expand Up @@ -131,7 +134,10 @@ export default tseslint.config(
multilineDetection: 'brackets'
}
],
'@stylistic/comma-dangle': ['error', 'never']
'@stylistic/comma-dangle': ['error', 'never'],
'@stylistic/object-property-newline': ['error'],
'@stylistic/object-curly-newline': ['error'],
'@stylistic/object-curly-spacing': ['error', 'always']
}
},

Expand Down
3 changes: 2 additions & 1 deletion projects/ngx-quill/config/src/provide-quill-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import { QUILL_CONFIG_TOKEN, QuillConfig } from './quill-editor.interfaces'
* ```
*/
export const provideQuillConfig = (config: QuillConfig): EnvironmentProviders =>
makeEnvironmentProviders([{ provide: QUILL_CONFIG_TOKEN, useValue: config }])
makeEnvironmentProviders([{ provide: QUILL_CONFIG_TOKEN,
useValue: config }])
3 changes: 2 additions & 1 deletion projects/ngx-quill/config/src/quill-config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export class QuillConfigModule {
static forRoot(config: QuillConfig): ModuleWithProviders<QuillConfigModule> {
return {
ngModule: QuillConfigModule,
providers: [{ provide: QUILL_CONFIG_TOKEN, useValue: config }],
providers: [{ provide: QUILL_CONFIG_TOKEN,
useValue: config }],
}
}
}
11 changes: 8 additions & 3 deletions projects/ngx-quill/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ module.exports = function (config) {
coverageReporter: {
dir: require('path').join(__dirname, '../../coverage/ngx-quill'),
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' },
{ type: 'text-summary', subdir: '.', file: 'text-summary.txt' }
{ type: 'html',
subdir: 'report-html' },
{ type: 'lcovonly',
subdir: '.',
file: 'report-lcovonly.txt' },
{ type: 'text-summary',
subdir: '.',
file: 'text-summary.txt' }
],
check: {
global: {
Expand Down
36 changes: 20 additions & 16 deletions projects/ngx-quill/src/lib/quill-editor.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Component, Renderer2, ViewChild} from '@angular/core'
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'
import {defer} from 'rxjs'
import { Component, Renderer2, ViewChild } from '@angular/core'
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'
import { defer } from 'rxjs'

import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms'
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'

import {QuillEditorComponent} from './quill-editor.component'
import { QuillEditorComponent } from './quill-editor.component'

import Quill from 'quill'
import {QuillModule} from './quill.module'
import { QuillModule } from './quill.module'

window.setTimeout = ((cb) => {
cb()
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('Formats', () => {

await fixture.whenStable()
await fixture.whenStable()
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hello\n'}]}))
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hello\n' }] }))
})

it('should update text', async () => {
Expand All @@ -286,7 +286,7 @@ describe('Formats', () => {
fixture.detectChanges()

await fixture.whenStable()
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: '1234\n'}]}))
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: '1234\n' }] }))
})

it('should update model if editor text changes', async () => {
Expand All @@ -297,7 +297,7 @@ describe('Formats', () => {
fixture.detectChanges()

await fixture.whenStable()
expect(JSON.stringify(component.title)).toEqual(JSON.stringify({ops: [{insert: '123\n'}]}))
expect(JSON.stringify(component.title)).toEqual(JSON.stringify({ ops: [{ insert: '123\n' }] }))
})
})

Expand Down Expand Up @@ -373,13 +373,13 @@ unordered`)
const incomponent = sanfixture.componentInstance

expect(JSON.stringify(incomponent.editor.getContents()))
.toEqual(JSON.stringify({ops: [{insert: 'Hallo ' }, {insert: {image: 'wroooong.jpg'}}, {insert: '\n'}]}))
.toEqual(JSON.stringify({ ops: [{ insert: 'Hallo ' }, { insert: { image: 'wroooong.jpg' } }, { insert: '\n' }] }))

incomponent.title = '<p><img src="xxxx" onerror="window.alert()"></p>'
sanfixture.detectChanges()

await sanfixture.whenStable()
expect(JSON.stringify(incomponent.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: {image: 'xxxx'}}, {insert: '\n'}]}))
expect(JSON.stringify(incomponent.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: { image: 'xxxx' } }, { insert: '\n' }] }))
})
})

Expand Down Expand Up @@ -495,7 +495,7 @@ unordered`)
})

it('should set json string', async () => {
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo\n'}]}))
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo\n' }] }))
})

it('should update json string', async () => {
Expand All @@ -504,7 +504,7 @@ unordered`)
}])
fixture.detectChanges()
await fixture.whenStable()
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo 123\n'}]}))
expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo 123\n' }] }))
})

it('should update model if editor changes', async () => {
Expand All @@ -514,7 +514,7 @@ unordered`)
fixture.detectChanges()
await fixture.whenStable()

expect(component.title).toEqual(JSON.stringify({ops: [{insert: 'Hallo 123\n'}]}))
expect(component.title).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo 123\n' }] }))
})

it('should set as text if invalid JSON', async () => {
Expand Down Expand Up @@ -1343,10 +1343,14 @@ describe('QuillEditor - base config', () => {
fixture.detectChanges()

expect(JSON.stringify(fixture.componentInstance.title))
.toEqual(JSON.stringify({ ops: [{ attributes: { bold: true }, insert: 'content'}, {insert: '\n'}] }))
.toEqual(JSON.stringify({ ops: [{ attributes: { bold: true },
insert: 'content' }, { insert: '\n' }] }))
expect(editor.root.dataset.placeholder).toEqual('placeholder')
expect(registerSpy).toHaveBeenCalledWith(
jasmine.objectContaining({attrName: 'size', keyName: 'font-size', scope: 5, whitelist: ['14']}), true, true
jasmine.objectContaining({ attrName: 'size',
keyName: 'font-size',
scope: 5,
whitelist: ['14'] }), true, true
)

expect(fixture.componentInstance.editorComponent.quillEditor['options'].modules.toolbar)
Expand Down
10 changes: 5 additions & 5 deletions projects/ngx-quill/src/lib/quill-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Formats', () => {
const component = fixture.componentInstance

await fixture.whenStable()
expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hello\n'}]}))
expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hello\n' }] }))
})

it('should update object content', async () => {
Expand All @@ -98,7 +98,7 @@ describe('Formats', () => {
fixture.detectChanges()

await fixture.whenStable()
expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: '1234\n'}]}))
expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: '1234\n' }] }))
})
})

Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Formats', () => {
await fixture.whenStable()
await fixture.whenStable()

expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo\n'}]}))
expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo\n' }] }))
})

it('should update json string', async () => {
Expand All @@ -233,7 +233,7 @@ describe('Formats', () => {
fixture.detectChanges()
await fixture.whenStable()

expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo 123\n'}]}))
expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo 123\n' }] }))
})
})
})
Expand All @@ -246,7 +246,7 @@ describe('Advanced QuillViewComponent', () => {
`
})
class AdvancedComponent {
@ViewChild(QuillViewComponent, {static: true}) view: QuillViewComponent | undefined
@ViewChild(QuillViewComponent, { static: true }) view: QuillViewComponent | undefined
content = '<p>Hallo</p>'
quillEditor: any

Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-quill/src/lib/quill-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class QuillViewComponent implements AfterViewInit, OnChanges, OnDestroy {
if (sanitize) {
value = this.domSanitizer.sanitize(SecurityContext.HTML, value)
}
content = quillEditor.clipboard.convert({html: value})
content = quillEditor.clipboard.convert({ html: value })
} else if (format === 'json') {
try {
content = JSON.parse(value)
Expand Down
7 changes: 4 additions & 3 deletions projects/ngx-quill/src/lib/quill.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DOCUMENT } from '@angular/common'
import { Injectable, Inject, Injector, Optional } from '@angular/core'
import { Inject, Injectable, Injector, Optional } from '@angular/core'
import { defer, firstValueFrom, isObservable, Observable } from 'rxjs'
import { shareReplay } from 'rxjs/operators'

import {
CustomModule,
defaultModules,
QUILL_CONFIG_TOKEN,
QuillConfig,
CustomModule,
} from 'ngx-quill/config'

@Injectable({
Expand Down Expand Up @@ -59,7 +59,8 @@ export class QuillService {
this.config.customModules,
this.config.suppressGlobalRegisterWarning
)
}).pipe(shareReplay({ bufferSize: 1, refCount: true }))
}).pipe(shareReplay({ bufferSize: 1,
refCount: true }))

constructor(
injector: Injector,
Expand Down

0 comments on commit ffb19a9

Please sign in to comment.