@ecodev/natural-editor 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ import { EventEmitter, OnDestroy, OnInit } from '@angular/core';
2
+ import { ControlValueAccessor, NgControl } from '@angular/forms';
3
+ import { MatDialog } from '@angular/material/dialog';
4
+ import { Key, MenuItems } from './menu';
5
+ import * as i0 from "@angular/core";
6
+ /**
7
+ * Prosemirror component
8
+ *
9
+ * Usage :
10
+ *
11
+ * ```html
12
+ * <natural-editor [(ngModel)]="htmlString"></natural-editor>
13
+ * ```
14
+ */
15
+ export declare class NaturalEditorComponent implements OnInit, OnDestroy, ControlValueAccessor {
16
+ readonly ngControl: NgControl;
17
+ private readonly document;
18
+ private readonly dialog;
19
+ private view;
20
+ private editor;
21
+ readonly contentChange: EventEmitter<string>;
22
+ /**
23
+ * Interface with ControlValueAccessor
24
+ * Notifies parent model / form controller
25
+ */
26
+ private onChange?;
27
+ /**
28
+ * HTML string
29
+ */
30
+ private content;
31
+ menu: MenuItems | null;
32
+ constructor(ngControl: NgControl, document: Document, dialog: MatDialog);
33
+ ngOnInit(): void;
34
+ writeValue(val: string | undefined): void;
35
+ private createState;
36
+ /**
37
+ * Called by Prosemirror whenever the editor state changes. So we update our menu states.
38
+ */
39
+ update(): void;
40
+ registerOnChange(fn: any): void;
41
+ registerOnTouched(fn: any): void;
42
+ setDisabledState(isDisabled: boolean): void;
43
+ ngOnDestroy(): void;
44
+ run(event: Event, key: Key): void;
45
+ static ɵfac: i0.ɵɵFactoryDeclaration<NaturalEditorComponent, [{ optional: true; self: true; }, null, null]>;
46
+ static ɵcmp: i0.ɵɵComponentDeclaration<NaturalEditorComponent, "natural-editor", never, {}, { "contentChange": "contentChange"; }, never, never>;
47
+ }
@@ -0,0 +1,19 @@
1
+ import * as i0 from "@angular/core";
2
+ import * as i1 from "./editor.component";
3
+ import * as i2 from "./link-dialog/link-dialog.component";
4
+ import * as i3 from "@angular/common";
5
+ import * as i4 from "@angular/material/button";
6
+ import * as i5 from "@angular/material/button-toggle";
7
+ import * as i6 from "@angular/material/dialog";
8
+ import * as i7 from "@angular/material/form-field";
9
+ import * as i8 from "@angular/material/icon";
10
+ import * as i9 from "@angular/material/input";
11
+ import * as i10 from "@angular/material/menu";
12
+ import * as i11 from "@angular/material/toolbar";
13
+ import * as i12 from "@angular/material/tooltip";
14
+ import * as i13 from "@angular/forms";
15
+ export declare class NaturalEditorModule {
16
+ static ɵfac: i0.ɵɵFactoryDeclaration<NaturalEditorModule, never>;
17
+ static ɵmod: i0.ɵɵNgModuleDeclaration<NaturalEditorModule, [typeof i1.NaturalEditorComponent, typeof i2.LinkDialogComponent], [typeof i3.CommonModule, typeof i4.MatButtonModule, typeof i5.MatButtonToggleModule, typeof i6.MatDialogModule, typeof i7.MatFormFieldModule, typeof i8.MatIconModule, typeof i9.MatInputModule, typeof i10.MatMenuModule, typeof i11.MatToolbarModule, typeof i12.MatTooltipModule, typeof i13.ReactiveFormsModule], [typeof i3.CommonModule, typeof i4.MatButtonModule, typeof i5.MatButtonToggleModule, typeof i6.MatDialogModule, typeof i7.MatFormFieldModule, typeof i8.MatIconModule, typeof i9.MatInputModule, typeof i10.MatMenuModule, typeof i11.MatToolbarModule, typeof i12.MatTooltipModule, typeof i13.ReactiveFormsModule, typeof i1.NaturalEditorComponent]>;
18
+ static ɵinj: i0.ɵɵInjectorDeclaration<NaturalEditorModule>;
19
+ }
@@ -0,0 +1,18 @@
1
+ import { MatDialogRef } from '@angular/material/dialog';
2
+ import { FormControl, FormGroup } from '@angular/forms';
3
+ import * as i0 from "@angular/core";
4
+ export interface LinkDialogData {
5
+ href: string;
6
+ title?: string;
7
+ }
8
+ export declare class LinkDialogComponent {
9
+ private dialogRef;
10
+ readonly hrefControl: FormControl;
11
+ readonly titleControl: FormControl;
12
+ readonly form: FormGroup;
13
+ constructor(data: LinkDialogData, dialogRef: MatDialogRef<LinkDialogComponent, LinkDialogData>);
14
+ maybeConfirm(): void;
15
+ private confirm;
16
+ static ɵfac: i0.ɵɵFactoryDeclaration<LinkDialogComponent, never>;
17
+ static ɵcmp: i0.ɵɵComponentDeclaration<LinkDialogComponent, "ng-component", never, {}, {}, never, never>;
18
+ }
package/lib/menu.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { MenuItemSpec } from 'prosemirror-menu';
2
+ import { EditorState } from 'prosemirror-state';
3
+ import { Schema } from 'prosemirror-model';
4
+ import { MatDialog } from '@angular/material/dialog';
5
+ import { EditorView } from 'prosemirror-view';
6
+ /**
7
+ * One item of the menu.
8
+ *
9
+ * This is the equivalent of `MenuItem` but without all the rendering logic since we use Angular
10
+ * templates for rendering. Also it caches the state of the item everytime the editor state changes,
11
+ * so Angular can query the state as often as needed without performance hit.
12
+ */
13
+ export declare class Item {
14
+ readonly spec: MenuItemSpec;
15
+ /**
16
+ * Whether the item is 'active' (for example, the item for toggling the strong mark might be active when the cursor is in strong text).
17
+ */
18
+ active: boolean;
19
+ /**
20
+ * Button is shown but disabled, because the item cannot be (un-)applied
21
+ */
22
+ disabled: boolean;
23
+ /**
24
+ * Whether the item is shown at the moment
25
+ */
26
+ show: boolean;
27
+ constructor(spec: MenuItemSpec);
28
+ /**
29
+ * Update the item state according to the editor state
30
+ */
31
+ update(view: EditorView, state: EditorState): void;
32
+ }
33
+ export declare type Key = 'toggleStrong' | 'toggleEm' | 'toggleCode' | 'toggleLink' | 'insertImage' | 'wrapBulletList' | 'wrapOrderedList' | 'wrapBlockQuote' | 'makeParagraph' | 'makeCodeBlock' | 'makeHead1' | 'makeHead2' | 'makeHead3' | 'makeHead4' | 'makeHead5' | 'makeHead6' | 'insertHorizontalRule' | 'joinUp' | 'lift' | 'selectParentNode' | 'undo' | 'redo';
34
+ export declare type MenuItems = Partial<Record<Key, Item>>;
35
+ /**
36
+ * Given a schema, look for default mark and node types in it and
37
+ * return an object with relevant menu items relating to those marks:
38
+ */
39
+ export declare function buildMenuItems(schema: Schema, dialog: MatDialog): MenuItems;
@@ -0,0 +1,2 @@
1
+ import { Schema } from 'prosemirror-model';
2
+ export declare const schema: Schema<any, "link" | "em" | "strong">;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@ecodev/natural-editor",
3
+ "version": "1.1.0",
4
+ "license": "MIT",
5
+ "repository": "github:Ecodev/natural",
6
+ "sideEffects": false,
7
+ "dependencies": {
8
+ "@types/prosemirror-commands": "^1.0.4",
9
+ "@types/prosemirror-menu": "^1.0.6",
10
+ "@types/prosemirror-model": "^1.13.2",
11
+ "@types/prosemirror-schema-basic": "^1.0.2",
12
+ "@types/prosemirror-schema-list": "^1.0.3",
13
+ "@types/prosemirror-state": "^1.2.7",
14
+ "@types/prosemirror-view": "^1.19.1",
15
+ "prosemirror-commands": "^1.1.12",
16
+ "prosemirror-example-setup": "^1.1.2",
17
+ "prosemirror-keymap": "^1.1.4",
18
+ "prosemirror-menu": "^1.1.4",
19
+ "prosemirror-model": "^1.16.1",
20
+ "prosemirror-schema-basic": "^1.1.2",
21
+ "prosemirror-schema-list": "^1.1.6",
22
+ "prosemirror-state": "^1.3.4",
23
+ "prosemirror-view": "^1.23.5",
24
+ "tslib": "^2.3.0"
25
+ },
26
+ "peerDependencies": {
27
+ "@angular/common": "^12.2.0",
28
+ "@angular/core": "^12.2.0",
29
+ "@ecodev/natural": ">40.0"
30
+ },
31
+ "main": "bundles/ecodev-natural-editor.umd.js",
32
+ "module": "fesm2015/ecodev-natural-editor.js",
33
+ "es2015": "fesm2015/ecodev-natural-editor.js",
34
+ "esm2015": "esm2015/ecodev-natural-editor.js",
35
+ "fesm2015": "fesm2015/ecodev-natural-editor.js",
36
+ "typings": "ecodev-natural-editor.d.ts"
37
+ }
@@ -0,0 +1,3 @@
1
+ import '@angular/localize/init';
2
+ export { NaturalEditorComponent } from './lib/editor.component';
3
+ export { NaturalEditorModule } from './lib/editor.module';