@mdzip/editor-ng 1.2.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.
- package/ng-package.json +8 -0
- package/package.json +21 -0
- package/src/public-api.ts +2 -0
- package/src/workspace.component.css +2 -0
- package/src/workspace.component.html +1 -0
- package/src/workspace.component.ts +177 -0
- package/tsconfig.lib.json +18 -0
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdzip/editor-ng",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Angular UI components for the MDZip workspace engine.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@angular/common": "^20.0.0",
|
|
9
|
+
"@angular/core": "^20.0.0",
|
|
10
|
+
"mdzip-editor": "1.2.0"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"tslib": "^2.8.1"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "ng build @mdzip/editor-ng"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div #host></div>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AfterViewInit,
|
|
3
|
+
ChangeDetectionStrategy,
|
|
4
|
+
Component,
|
|
5
|
+
ElementRef,
|
|
6
|
+
EventEmitter,
|
|
7
|
+
Input,
|
|
8
|
+
OnChanges,
|
|
9
|
+
OnDestroy,
|
|
10
|
+
Output,
|
|
11
|
+
SimpleChanges,
|
|
12
|
+
ViewChild,
|
|
13
|
+
} from '@angular/core';
|
|
14
|
+
import { MdzipWorkspaceView } from 'mdzip-editor';
|
|
15
|
+
import type {
|
|
16
|
+
MdzipControlPolicy,
|
|
17
|
+
MdzipControlPreset,
|
|
18
|
+
MdzipColorScheme,
|
|
19
|
+
MdzipEditorCommand,
|
|
20
|
+
MdzipDocumentChangeEvent,
|
|
21
|
+
MdzipEditorSnapshot,
|
|
22
|
+
MdzipNavigationMode,
|
|
23
|
+
MdzipRemoveAssetOptions,
|
|
24
|
+
MdzipSourceFormat,
|
|
25
|
+
MdzWorkspace,
|
|
26
|
+
MdzWorkspaceAsset,
|
|
27
|
+
MdzipWorkspaceChange,
|
|
28
|
+
MdzipWorkspaceLayout,
|
|
29
|
+
MdzipWorkspaceMode,
|
|
30
|
+
MdzipWorkspaceSave,
|
|
31
|
+
MdzipWorkspaceSnapshot,
|
|
32
|
+
} from 'mdzip-editor';
|
|
33
|
+
|
|
34
|
+
@Component({
|
|
35
|
+
selector: 'mdzip-workspace',
|
|
36
|
+
standalone: true,
|
|
37
|
+
template: '<div #host></div>',
|
|
38
|
+
styles: [':host { display: block; height: 100%; } div { height: 100%; }'],
|
|
39
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
40
|
+
})
|
|
41
|
+
export class MdzipWorkspaceComponent implements AfterViewInit, OnChanges, OnDestroy {
|
|
42
|
+
@Input() bytes: Uint8Array | null = null;
|
|
43
|
+
@Input() workspace: MdzWorkspace | null = null;
|
|
44
|
+
@Input() fileName = 'document.mdz';
|
|
45
|
+
@Input() mode: MdzipWorkspaceMode = 'read-only';
|
|
46
|
+
@Input() sourceFormat?: MdzipSourceFormat;
|
|
47
|
+
@Input() controls: MdzipControlPreset | MdzipControlPolicy = 'viewer';
|
|
48
|
+
@Input() initialLayout?: MdzipWorkspaceLayout;
|
|
49
|
+
@Input() initialColorScheme?: MdzipColorScheme;
|
|
50
|
+
@Input() navigationMode: MdzipNavigationMode = 'editor';
|
|
51
|
+
@Input() navigationButtonActive = true;
|
|
52
|
+
@Output() readonly changed = new EventEmitter<MdzipWorkspaceChange>();
|
|
53
|
+
@Output() readonly saved = new EventEmitter<MdzipWorkspaceSave>();
|
|
54
|
+
@Output() readonly workspaceChanged = new EventEmitter<MdzipDocumentChangeEvent>();
|
|
55
|
+
@Output() readonly documentChanged = new EventEmitter<MdzipDocumentChangeEvent>();
|
|
56
|
+
@Output() readonly assetChanged = new EventEmitter<MdzipDocumentChangeEvent>();
|
|
57
|
+
@Output() readonly manifestChanged = new EventEmitter<MdzipDocumentChangeEvent>();
|
|
58
|
+
@Output() readonly snapshotChanged = new EventEmitter<MdzipWorkspaceSnapshot>();
|
|
59
|
+
@Output() readonly selectionChanged = new EventEmitter<MdzipWorkspaceSnapshot>();
|
|
60
|
+
@Output() readonly dirtyChanged = new EventEmitter<MdzipWorkspaceSnapshot>();
|
|
61
|
+
@Output() readonly validationChanged = new EventEmitter<MdzipWorkspaceSnapshot>();
|
|
62
|
+
@Output() readonly colorSchemeChanged = new EventEmitter<MdzipColorScheme>();
|
|
63
|
+
@Output() readonly failed = new EventEmitter<unknown>();
|
|
64
|
+
|
|
65
|
+
@ViewChild('host') private readonly hostRef!: ElementRef<HTMLDivElement>;
|
|
66
|
+
private view: MdzipWorkspaceView | null = null;
|
|
67
|
+
|
|
68
|
+
ngAfterViewInit(): void {
|
|
69
|
+
this.createView();
|
|
70
|
+
this.syncView();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
ngOnChanges(changes: SimpleChanges): void {
|
|
74
|
+
if (this.view && (changes['controls'] || changes['initialLayout']
|
|
75
|
+
|| changes['initialColorScheme'] || changes['navigationMode']
|
|
76
|
+
|| changes['navigationButtonActive'])) {
|
|
77
|
+
this.createView();
|
|
78
|
+
this.syncView();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (this.view && (changes['bytes'] || changes['workspace'] || changes['mode']
|
|
82
|
+
|| changes['sourceFormat'] || changes['fileName'])) {
|
|
83
|
+
this.syncView();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
ngOnDestroy(): void {
|
|
88
|
+
this.view?.destroy();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
canExecuteCommand(command: MdzipEditorCommand): boolean {
|
|
92
|
+
return this.view?.canExecuteCommand(command) ?? false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
executeCommand(command: MdzipEditorCommand, file?: File): Promise<boolean> {
|
|
96
|
+
return this.view?.executeCommand(command, file) ?? Promise.resolve(false);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
convertToMdz(): Promise<boolean> {
|
|
100
|
+
return this.view?.convertToMdz() ?? Promise.resolve(false);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
focus(): void {
|
|
104
|
+
this.view?.focus();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
flush(): Promise<MdzipEditorSnapshot | null> {
|
|
108
|
+
return this.view?.flush() ?? Promise.resolve(null);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
serialize(): Promise<Blob | null> {
|
|
112
|
+
return this.view?.serialize() ?? Promise.resolve(null);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getCurrentSnapshot(): Promise<MdzipEditorSnapshot | null> {
|
|
116
|
+
return this.view?.getCurrentSnapshot() ?? Promise.resolve(null);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
markPersisted(): void {
|
|
120
|
+
this.view?.markPersisted();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addAsset(archivePath: string, fileBytes: Uint8Array): Promise<void> {
|
|
124
|
+
return this.view?.addAsset(archivePath, fileBytes) ?? Promise.resolve();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
replaceAsset(archivePath: string, fileBytes: Uint8Array): Promise<boolean> {
|
|
128
|
+
return this.view?.replaceAsset(archivePath, fileBytes) ?? Promise.resolve(false);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
removeAsset(archivePath: string, options?: MdzipRemoveAssetOptions): Promise<boolean> {
|
|
132
|
+
return this.view?.removeAsset(archivePath, options) ?? Promise.resolve(false);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
listAssets(): MdzWorkspaceAsset[] {
|
|
136
|
+
return this.view?.listAssets() ?? [];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private syncView(): void {
|
|
140
|
+
if (this.view && this.workspace) {
|
|
141
|
+
void this.view.openWorkspace(this.workspace, {
|
|
142
|
+
mode: this.mode,
|
|
143
|
+
sourceFormat: this.sourceFormat,
|
|
144
|
+
fileName: this.fileName
|
|
145
|
+
});
|
|
146
|
+
} else if (this.view && this.bytes) {
|
|
147
|
+
void this.view.open(this.bytes, {
|
|
148
|
+
mode: this.mode,
|
|
149
|
+
sourceFormat: this.sourceFormat,
|
|
150
|
+
fileName: this.fileName
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private createView(): void {
|
|
156
|
+
this.view?.destroy();
|
|
157
|
+
this.view = new MdzipWorkspaceView(this.hostRef.nativeElement, {
|
|
158
|
+
controls: this.controls,
|
|
159
|
+
initialLayout: this.initialLayout,
|
|
160
|
+
initialColorScheme: this.initialColorScheme,
|
|
161
|
+
navigationMode: this.navigationMode,
|
|
162
|
+
navigationButtonActive: this.navigationButtonActive,
|
|
163
|
+
onChanged: (bytes, snapshot) => this.changed.emit({ bytes, snapshot }),
|
|
164
|
+
onSaved: (bytes, snapshot) => this.saved.emit({ bytes, snapshot }),
|
|
165
|
+
onWorkspaceChanged: (event) => this.workspaceChanged.emit(event),
|
|
166
|
+
onDocumentChanged: (event) => this.documentChanged.emit(event),
|
|
167
|
+
onAssetChanged: (event) => this.assetChanged.emit(event),
|
|
168
|
+
onManifestChanged: (event) => this.manifestChanged.emit(event),
|
|
169
|
+
onSnapshotChanged: (snapshot) => this.snapshotChanged.emit(snapshot),
|
|
170
|
+
onSelectionChanged: (snapshot) => this.selectionChanged.emit(snapshot),
|
|
171
|
+
onDirtyChanged: (snapshot) => this.dirtyChanged.emit(snapshot),
|
|
172
|
+
onValidationChanged: (snapshot) => this.validationChanged.emit(snapshot),
|
|
173
|
+
onColorSchemeChanged: (colorScheme) => this.colorSchemeChanged.emit(colorScheme),
|
|
174
|
+
onFailed: (e) => this.failed.emit(e),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../out-tsc/lib",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"declarationMap": true,
|
|
7
|
+
"inlineSources": true,
|
|
8
|
+
"paths": {
|
|
9
|
+
"mdzip-editor": ["../editor/dist/index.d.ts"]
|
|
10
|
+
},
|
|
11
|
+
"types": []
|
|
12
|
+
},
|
|
13
|
+
"angularCompilerOptions": {
|
|
14
|
+
"strictTemplates": true
|
|
15
|
+
},
|
|
16
|
+
"exclude": ["**/*.spec.ts"],
|
|
17
|
+
"include": ["src/**/*.ts"]
|
|
18
|
+
}
|