├── .npmrc ├── .travis.yml ├── src ├── favicon.ico ├── styles.css ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── tsconfig.app.json ├── tsconfig.spec.json ├── index.html ├── app │ ├── app.component.css │ ├── app.component.html │ ├── app.component.ts │ └── app.module.ts ├── tslint.json ├── main.ts ├── .browserslistrc ├── test.ts ├── karma.conf.js └── polyfills.ts ├── projects └── ngx-wig │ ├── package-lock.json │ ├── ng-package.json │ ├── tsconfig.lib.prod.json │ ├── tsconfig.spec.json │ ├── src │ ├── public_api.ts │ ├── test.ts │ └── lib │ │ ├── ngx-wig-filter-styles.service.ts │ │ ├── ngx-wig-filter-styles.service.spec.ts │ │ ├── ngx-wig.module.ts │ │ ├── config.ts │ │ ├── ngx-wig-toolbar.service.ts │ │ ├── ngx-wig-filter.service.spec.ts │ │ ├── ngx-wig-toolbar.service.spec.ts │ │ ├── ngx-wig-component.html │ │ ├── ngx-wig-filter.service.ts │ │ ├── ngx-wig-component.css │ │ ├── ngx-wig.component.ts │ │ └── ngx-wig.component.spec.ts │ ├── package.json │ ├── tsconfig.lib.json │ ├── karma.conf.js │ └── .eslintrc.json ├── .editorconfig ├── .github └── workflows │ ├── main.yml │ └── npm_publish.yml ├── tsconfig.json ├── .gitignore ├── .eslintrc.json ├── package.json ├── tslint.json ├── README.md ├── angular.json └── LICENSE /.npmrc: -------------------------------------------------------------------------------- 1 | always-auth = true -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: required 3 | node_js: 4 | - 18 5 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stevermeister/ngx-wig/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /projects/ngx-wig/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngx-wig", 3 | "version": "2.0.0", 4 | "lockfileVersion": 1 5 | } 6 | -------------------------------------------------------------------------------- /projects/ngx-wig/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "../../dist/ngx-wig", 4 | "lib": { 5 | "entryFile": "src/public_api.ts" 6 | } 7 | } -------------------------------------------------------------------------------- /projects/ngx-wig/tsconfig.lib.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.lib.json", 3 | "compilerOptions": { 4 | "declarationMap": false 5 | }, 6 | "angularCompilerOptions": { 7 | "compilationMode": "partial" 8 | } 9 | } -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "main.ts", 9 | "polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /projects/ngx-wig/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts" 12 | ], 13 | "include": [ 14 | "**/*.spec.ts", 15 | "**/*.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /projects/ngx-wig/src/public_api.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Public API Surface of ngx-wig 3 | */ 4 | 5 | export * from './lib/ngx-wig-toolbar.service'; 6 | export * from './lib/ngx-wig-filter.service'; 7 | export * from './lib/ngx-wig-filter-styles.service'; 8 | export * from './lib/ngx-wig.component'; 9 | export * from './lib/ngx-wig.module'; 10 | export * from './lib/config'; 11 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NgxWigApp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .font-arial, 2 | .font-courier, 3 | .font-times { 4 | width: fit-content !important; 5 | } 6 | 7 | .font-arial { 8 | font-family: Arial, Helvetica, sans-serif; 9 | } 10 | 11 | .font-courier { 12 | font-family: 'Courier New', Courier, monospace; 13 | } 14 | 15 | .font-times { 16 | font-family: 'Times New Roman', Times, serif; 17 | } -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | on: 3 | pull_request: 4 | branches: [ master ] 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | node-version: [20.x] 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Use Node.js ${{ matrix.node-version }} 14 | uses: actions/setup-node@v1 15 | with: 16 | node-version: ${{ matrix.node-version }} 17 | - run: npm install 18 | - run: npm test 19 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | // First, initialize the Angular testing environment. 11 | getTestBed().initTestEnvironment( 12 | BrowserDynamicTestingModule, 13 | platformBrowserDynamicTesting() 14 | ); 15 | -------------------------------------------------------------------------------- /projects/ngx-wig/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | //import 'core-js/es7/reflect'; 4 | import 'zone.js'; 5 | import 'zone.js/testing'; 6 | import { getTestBed } from '@angular/core/testing'; 7 | import { 8 | BrowserDynamicTestingModule, 9 | platformBrowserDynamicTesting 10 | } from '@angular/platform-browser-dynamic/testing'; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

Examples for ngx-wig

2 | 3 | 4 |

Quick start

5 | 6 | 7 | 8 |

Placeholder

9 | 10 | 11 | 12 | 13 |

Set buttons

14 | 15 | 16 | 17 |

onContentChange Hook

18 | 19 |
20 | 21 | 22 |

Reactive FormControl

23 | 24 | -------------------------------------------------------------------------------- /projects/ngx-wig/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngx-wig", 3 | "version": "20.0.0", 4 | "description": "Light-weight WYSIWYG Editor for Angular", 5 | "keywords": [ 6 | "Angular", 7 | "Library", 8 | "WYSIWYG", 9 | "Editor" 10 | ], 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/stevermeister/ngx-wig" 14 | }, 15 | "homepage": "https://github.com/stevermeister/ngx-wig", 16 | "peerDependencies": { 17 | "@angular/common": "^20.0.0", 18 | "@angular/core": "^20.0.0", 19 | "@angular/forms": "^20.0.0" 20 | }, 21 | "dependencies": { 22 | "tslib": "^2.2.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "esModuleInterop": true, 7 | "sourceMap": true, 8 | "declaration": false, 9 | "module": "es2020", 10 | "moduleResolution": "bundler", 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "strictNullChecks": true, 14 | "target": "ES2022", 15 | "typeRoots": [ 16 | "node_modules/@types" 17 | ], 18 | "lib": [ 19 | "es2018", 20 | "dom" 21 | ], 22 | "paths": { 23 | "ngx-wig": [ 24 | "dist/ngx-wig" 25 | ], 26 | "ngx-wig/*": [ 27 | "dist/ngx-wig/*" 28 | ] 29 | }, 30 | "useDefineForClassFields": false 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | .angular 8 | 9 | # dependencies 10 | /node_modules 11 | 12 | # profiling files 13 | chrome-profiler-events.json 14 | speed-measure-plugin.json 15 | 16 | # IDEs and editors 17 | /.idea 18 | .project 19 | .classpath 20 | .c9/ 21 | *.launch 22 | .settings/ 23 | *.sublime-workspace 24 | 25 | # IDE - VSCode 26 | .vscode/* 27 | !.vscode/settings.json 28 | !.vscode/tasks.json 29 | !.vscode/launch.json 30 | !.vscode/extensions.json 31 | 32 | # misc 33 | /.sass-cache 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | npm-debug.log 38 | yarn-error.log 39 | testem.log 40 | /typings 41 | 42 | # System Files 43 | .DS_Store 44 | Thumbs.db 45 | -------------------------------------------------------------------------------- /projects/ngx-wig/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/lib", 5 | "declarationMap": true, 6 | "module": "es2015", 7 | "moduleResolution": "bundler", 8 | "declaration": true, 9 | "sourceMap": true, 10 | "inlineSources": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "types": [], 14 | "lib": [ 15 | "dom", 16 | "es2018" 17 | ] 18 | }, 19 | "angularCompilerOptions": { 20 | "skipTemplateCodegen": true, 21 | "strictMetadataEmit": true, 22 | "fullTemplateTypeCheck": true, 23 | "strictInjectionParameters": true, 24 | "enableResourceInlining": true 25 | }, 26 | "exclude": [ 27 | "src/test.ts", 28 | "**/*.spec.ts" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/npm_publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to NPM 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 # Updated to use v2 13 | - uses: actions/setup-node@v4 # Updated to use v3 14 | with: 15 | node-version: 20 16 | registry-url: 'https://registry.npmjs.org/' # Added for npm to configure auth 17 | - name: Install Angular CLI 18 | run: npm install -g @angular/cli @angular/core 19 | - name: Install NPM Dependencies 20 | run: npm ci 21 | - name: Build project 22 | run: npm run build 23 | - name: Publish to NPM 24 | uses: JS-DevTools/npm-publish@v3 25 | with: 26 | token: ${{ secrets.NPM_TOKEN }} 27 | package: dist/ngx-wig/package.json 28 | access: public 29 | env: 30 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Ensure npm can authenticate with your token 31 | -------------------------------------------------------------------------------- /projects/ngx-wig/src/lib/ngx-wig-filter-styles.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | 3 | @Injectable({ 4 | providedIn: "root", 5 | }) 6 | export class NgxWigFilterStylesService { 7 | constructor() {} 8 | public filter(htmlString: string): string { 9 | // Parse the HTML string into a DOM object 10 | const parser: DOMParser = new DOMParser(); 11 | const doc: Document = parser.parseFromString(htmlString, "text/html"); 12 | 13 | // Remove all style attributes from all elements 14 | const elementsWithStyle: NodeListOf = 15 | doc.querySelectorAll("[style]"); 16 | elementsWithStyle.forEach((el: Element) => el.removeAttribute("style")); 17 | 18 | // Remove all
Hello, world!
'; 22 | const expectedOutput = '
Hello, world!
'; 23 | expect(service.filter(htmlString)).toEqual(expectedOutput); 24 | }); 25 | 26 | it('should handle empty HTML string', () => { 27 | const htmlString = ''; 28 | const expectedOutput = ''; 29 | expect(service.filter(htmlString)).toEqual(expectedOutput); 30 | }); 31 | }); -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "ignorePatterns": [ 4 | "projects/**/*" 5 | ], 6 | "overrides": [ 7 | { 8 | "files": [ 9 | "*.ts" 10 | ], 11 | "parserOptions": { 12 | "project": [ 13 | "tsconfig.json", 14 | "e2e/tsconfig.json" 15 | ], 16 | "createDefaultProgram": true 17 | }, 18 | "extends": [ 19 | "plugin:@angular-eslint/ng-cli-compat", 20 | "plugin:@angular-eslint/ng-cli-compat--formatting-add-on", 21 | "plugin:@angular-eslint/template/process-inline-templates" 22 | ], 23 | "rules": { 24 | "@typescript-eslint/consistent-type-definitions": "error", 25 | "@typescript-eslint/dot-notation": "off", 26 | "@typescript-eslint/explicit-member-accessibility": [ 27 | "off", 28 | { 29 | "accessibility": "explicit" 30 | } 31 | ], 32 | "brace-style": [ 33 | "error", 34 | "1tbs" 35 | ], 36 | "id-blacklist": "off", 37 | "id-match": "off", 38 | "no-underscore-dangle": "off" 39 | } 40 | }, 41 | { 42 | "files": [ 43 | "*.html" 44 | ], 45 | "extends": [ 46 | "plugin:@angular-eslint/template/recommended" 47 | ], 48 | "rules": {} 49 | } 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /projects/ngx-wig/src/lib/ngx-wig.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule, ModuleWithProviders } from '@angular/core'; 3 | import { NgxWigComponent } from './ngx-wig.component'; 4 | import { FormsModule } from '@angular/forms'; 5 | import { TButtonLibrary, DEFAULT_LIBRARY_BUTTONS, BUTTONS, CUSTOM_LIBRARY_BUTTONS } from './config'; 6 | 7 | 8 | export const getWindowObject = (): Window => window; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | NgxWigComponent 13 | ], 14 | imports: [ 15 | CommonModule, 16 | FormsModule, 17 | ], 18 | exports: [NgxWigComponent], 19 | providers: [ 20 | { provide: BUTTONS, multi: true, useValue: DEFAULT_LIBRARY_BUTTONS }, 21 | { provide: 'WINDOW', useFactory: getWindowObject }, 22 | ] 23 | }) 24 | export class NgxWigModule { 25 | 26 | static forRoot(config?: { buttonsConfig: TButtonLibrary } ): ModuleWithProviders { 27 | return { 28 | ngModule: NgxWigModule, 29 | providers: [ 30 | { 31 | provide: BUTTONS, 32 | multi: true, useValue: ((!config || !config?.buttonsConfig) ? DEFAULT_LIBRARY_BUTTONS : config?.buttonsConfig) 33 | }, 34 | { provide: 'WINDOW', useFactory: getWindowObject }, 35 | ], 36 | }; 37 | } 38 | 39 | static forChild(): ModuleWithProviders { 40 | return {ngModule: NgxWigModule }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /projects/ngx-wig/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../.eslintrc.json", 3 | "ignorePatterns": [ 4 | "!**/*" 5 | ], 6 | "overrides": [ 7 | { 8 | "files": [ 9 | "*.ts" 10 | ], 11 | "parserOptions": { 12 | "project": [ 13 | "projects/ngx-wig/tsconfig.lib.json", 14 | "projects/ngx-wig/tsconfig.spec.json" 15 | ], 16 | "createDefaultProgram": true 17 | }, 18 | "rules": { 19 | "@angular-eslint/component-selector": [ 20 | "error", 21 | { 22 | "type": "element", 23 | "prefix": "ngx-wig", 24 | "style": "kebab-case" 25 | } 26 | ], 27 | "@angular-eslint/directive-selector": [ 28 | "error", 29 | { 30 | "type": "attribute", 31 | "prefix": "ngx-wig", 32 | "style": "camelCase" 33 | } 34 | ], 35 | "@typescript-eslint/consistent-type-definitions": "error", 36 | "@typescript-eslint/dot-notation": "off", 37 | "@typescript-eslint/explicit-member-accessibility": [ 38 | "off", 39 | { 40 | "accessibility": "explicit" 41 | } 42 | ], 43 | "brace-style": [ 44 | "error", 45 | "1tbs" 46 | ], 47 | "id-blacklist": "off", 48 | "id-match": "off", 49 | "no-underscore-dangle": "off" 50 | } 51 | }, 52 | { 53 | "files": [ 54 | "*.html" 55 | ], 56 | "rules": {} 57 | } 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ViewEncapsulation } from '@angular/core'; 2 | import { FormControl } from '@angular/forms'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'], 8 | encapsulation: ViewEncapsulation.None, 9 | standalone: false 10 | }) 11 | export class AppComponent { 12 | 13 | public result: any; 14 | 15 | // tslint:disable:max-line-length 16 | public text = `There are a few options for making a WYSIWYG editor that works in the browser. 17 | 18 | Pure DHTML/JavaScript. Capture mouse input, buttons, keystrokes, etc., and actually edit the HTML of the current document. It's not trivial, but possible. 19 | Create a custom browser plug-in, Java applet, ActiveX control. This would probably be workable, but would take quite a bit of hackery, and may or may not work. Requiring users to install any sort of plugin is very undesirable. 20 | Imho, limited approach. Only Java applet is (possibly) cross-browser compatible. But not all users have Java on their machines and JavaScript is supported by all popular browsers (well, maybe except text-based, but I think that Java wouldn't work there too)... --Shtriter 07:20, 26 July 2006 (UTC) 21 | Users using text based browsers don't matter for WYSIWIG. They are going to be happier editing in Creole --Kevin Holzer (see hlzr.net for contact) 12:38, g29 December 2010 (PST) 22 | Both Mozilla and Internet Explorer have included ways to make sections of a page editable. IE 5.5 had the MSHTML Editing Platform (archive.org), and Mozilla has its Rich Text Editing API. Both technologies allow Web developers to make parts of a page editable -- in slightly different ways, of course. 23 | Most current in-browser WYSIWYG editors use the third option.`; 24 | // tslint:enable:max-line-length 25 | public name = new FormControl('some text'); 26 | } 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngx-wig-app", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "lib-build": "ng build ngx-wig", 6 | "start": "(ng build ngx-wig --watch ) & sleep 10 && ng serve", 7 | "build": "ng build ngx-wig --configuration production", 8 | "test": "ng test ngx-wig --browsers=ChromeHeadless --watch=false", 9 | "lint": "ng lint ngx-wig", 10 | "e2e": "ng e2e ngx-wig", 11 | "package": "ng build ngx-wig --configuration production && cp ./README.md ./dist/ngx-wig && cd dist/ngx-wig && npm pack" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^20.0.0", 16 | "@angular/common": "^20.0.0", 17 | "@angular/compiler": "^20.0.0", 18 | "@angular/core": "^20.0.0", 19 | "@angular/forms": "^20.0.0", 20 | "@angular/platform-browser": "^20.0.0", 21 | "@angular/platform-browser-dynamic": "^20.0.0", 22 | "@angular/router": "^20.0.0", 23 | "core-js": "^3.19.3", 24 | "rxjs": "^6.5.5", 25 | "tslib": "^2.2.0", 26 | "zone.js": "^0.15.0" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "^20.1.1", 30 | "@angular/cli": "^20.0.0", 31 | "@angular/compiler-cli": "^20.0.0", 32 | "@types/jasmine": "^5.1.4", 33 | "@types/node": "^20.10.5", 34 | "@typescript-eslint/eslint-plugin": "5.36.2", 35 | "@typescript-eslint/parser": "5.36.2", 36 | "eslint": "^8.56.0", 37 | "eslint-plugin-import": "latest", 38 | "eslint-plugin-jsdoc": "latest", 39 | "eslint-plugin-prefer-arrow": "latest", 40 | "jasmine-core": "^5.1.1", 41 | "jasmine-spec-reporter": "^7.0.0", 42 | "karma": "^6.4.2", 43 | "karma-chrome-launcher": "^3.2.0", 44 | "karma-coverage-istanbul-reporter": "^3.0.3", 45 | "karma-jasmine": "^5.1.0", 46 | "karma-jasmine-html-reporter": "^2.1.0", 47 | "ng-packagr": "^20.1.0", 48 | "ts-node": "~7.0.0", 49 | "typescript": "^5.8.3" 50 | } 51 | } -------------------------------------------------------------------------------- /projects/ngx-wig/src/lib/config.ts: -------------------------------------------------------------------------------- 1 | import { InjectionToken } from '@angular/core'; 2 | import { NgxWigComponent } from './ngx-wig.component'; 3 | 4 | export type CommandFunction = (ctx: NgxWigComponent) => void; 5 | 6 | export interface TButton { 7 | label?: string; 8 | icon?: string; 9 | title?: string; 10 | ariaLabel?: string; 11 | children?: TButton[]; 12 | command?: string | CommandFunction; 13 | styleClass?: string; 14 | visibleDropdown?: boolean; 15 | isOpenOnMouseOver?: boolean; 16 | /** 17 | * Tracks the currently focusable child button when the toolbar button has a dropdown. 18 | * Implements a roving tabindex pattern for dropdown items. 19 | */ 20 | dropdownButtonIndex?: number; 21 | } 22 | 23 | export interface TButtonLibrary { 24 | [name: string]: TButton; 25 | } 26 | 27 | export const DEFAULT_LIBRARY_BUTTONS: TButtonLibrary = { 28 | list1: { 29 | label: 'UL', 30 | title: 'Unordered List', 31 | command: 'insertunorderedlist', 32 | styleClass: 'nw-list-ul', 33 | icon: 'nwe-icon-list-ul' 34 | }, 35 | list2: { 36 | label: 'OL', 37 | title: 'Ordered List', 38 | command: 'insertorderedlist', 39 | styleClass: 'nw-list-ol', 40 | icon: 'nwe-icon-list-ol' 41 | }, 42 | bold: { 43 | label: 'B', 44 | title: 'Bold', 45 | command: 'bold', 46 | styleClass: 'nw-bold', 47 | icon: 'nwe-icon-bold' 48 | }, 49 | italic: { 50 | label: 'I', 51 | title: 'Italic', 52 | command: 'italic', 53 | styleClass: 'nw-italic', 54 | icon: 'nwe-icon-italic' 55 | }, 56 | link: { 57 | label: 'Link', 58 | title: 'Add or remove link', 59 | command: 'createlink', 60 | styleClass: 'nw-link', 61 | icon: 'nwe-icon-link' 62 | }, 63 | underline: { 64 | label: 'U', 65 | title: 'Underline', 66 | command: 'underline', 67 | styleClass: 'nw-format-underlined', 68 | icon: 'nwe-icon-underline' 69 | } 70 | }; 71 | 72 | export const CUSTOM_LIBRARY_BUTTONS: TButtonLibrary = { 73 | edithtml: { 74 | label: 'Edit HTML', 75 | title: 'Edit HTML', 76 | command: (ctx: NgxWigComponent) => { 77 | ctx.editMode = !ctx.editMode; 78 | }, 79 | styleClass: 'nw-button--source', 80 | icon: '', 81 | } 82 | }; 83 | 84 | 85 | export const BUTTONS = new InjectionToken('BUTTONS'); 86 | -------------------------------------------------------------------------------- /projects/ngx-wig/src/lib/ngx-wig-toolbar.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject } from '@angular/core'; 2 | import { TButtonLibrary, TButton, BUTTONS } from './config'; 3 | 4 | @Injectable({ 5 | providedIn: 'root' 6 | }) 7 | export class NgxWigToolbarService { 8 | private _defaultButtonsList: string[] = []; 9 | private _buttonLibrary: TButtonLibrary; 10 | 11 | constructor(@Inject(BUTTONS) buttonLibraryConfig: TButtonLibrary[]) { 12 | this._buttonLibrary = buttonLibraryConfig.reduce((acc: TButtonLibrary, val: TButtonLibrary) => ({ ...acc, ...val }), {}); 13 | this._defaultButtonsList = Object.keys(this._buttonLibrary); 14 | } 15 | 16 | public setButtons(buttons: string[]): void { 17 | if (!Array.isArray(buttons)) { 18 | throw new Error('Argument "buttons" should be an array'); 19 | } 20 | 21 | this._defaultButtonsList = buttons; 22 | } 23 | 24 | public addStandardButton( 25 | name: string, 26 | title: string, 27 | command: string, 28 | styleClass: string, 29 | icon: string 30 | ) { 31 | if (!name || !title || !command) { 32 | throw new Error('Arguments "name", "title" and "command" are required'); 33 | } 34 | 35 | styleClass = styleClass || ''; 36 | this._buttonLibrary[name] = { title, command, styleClass, icon }; 37 | this._defaultButtonsList.push(name); 38 | } 39 | 40 | public getToolbarButtons(buttonsList?: string): TButton[] { 41 | let buttons = this._defaultButtonsList; 42 | const toolbarButtons: TButton[] = []; 43 | 44 | if (typeof buttonsList !== 'undefined') { 45 | buttons = string2array(buttonsList); 46 | } 47 | 48 | buttons.forEach(buttonKey => { 49 | if (!buttonKey) { 50 | return; 51 | } 52 | 53 | if (!this._buttonLibrary[buttonKey]) { 54 | throw new Error( 55 | `There is no "${buttonKey}" in your library. Possible variants: ${Object.keys(this._buttonLibrary)}` 56 | ); 57 | } 58 | 59 | const button = Object.assign({}, this._buttonLibrary[buttonKey]); 60 | // button.isActive = () => {return !!this.command && document.queryCommandState(this.command);} 61 | toolbarButtons.push(button); 62 | }); 63 | 64 | return toolbarButtons; 65 | } 66 | } 67 | 68 | const string2array = (keysString: string) => 69 | keysString 70 | .split(',') 71 | .map(Function.prototype.call, String.prototype.trim); 72 | -------------------------------------------------------------------------------- /projects/ngx-wig/src/lib/ngx-wig-filter.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { NgxWigFilterService } from './ngx-wig-filter.service'; 2 | 3 | describe('NgxWigFilterService', () => { 4 | let service: NgxWigFilterService; 5 | 6 | beforeEach(() => { 7 | service = new NgxWigFilterService(); 8 | }); 9 | 10 | it('should create an instance', () => { 11 | expect(service).toBeTruthy(); 12 | }); 13 | 14 | it('should return the same content when filtering', () => { 15 | const content = 'Hello, world!'; 16 | expect(service.filter(content)).toEqual(content); 17 | }); 18 | 19 | describe('_cleanWordHtml', () => { 20 | it('should clean Word HTML and convert underline spans to ', () => { 21 | const html = `Underlined text`; 22 | const result = service['_cleanWordHtml'](html); 23 | expect(result).toContain('Underlined text'); 24 | }); 25 | 26 | it('should remove unwanted tags like 29 | 30 | 31 |

Content

32 | `; 33 | const result = service['_cleanWordHtml'](html); 34 | expect(result).toContain('

Content

'); 35 | expect(result).not.toContain('