/
injector.ts
102 lines (92 loc) · 2.16 KB
/
injector.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { InjectionToken } from '@angular/core';
import EditorJS, { EditorConfig, OutputData } from '@editorjs/editorjs';
import { Block } from './blocks';
/**
* Configuration for creating an EditorJS instance
*/
export interface EditorJSInstanceConfig {
/**
* The editor configuration, this is required with at least the `holder` property
*/
editorConfig: EditorConfig;
/**
* The method to call when the editor makes a change
*/
onChange?: (holder?: string) => void;
/**
* The method to call with an editor is ready
*/
onReady?: (holder?: string) => void;
}
/**
* Default values for each internal map
*/
export const MAP_DEFAULTS = [
['lastChangeMap', { time: 0, blocks: [], version: typeof EditorJS !== 'undefined' && EditorJS.version || ''}],
['isReadyMap', false],
['hasSavedMap', false]
];
/**
* Injection token for the EditorJS class
*/
export const EDITORJS_MODULE_IMPORT = new InjectionToken<any>('EDITORJS_MODULE_IMPORT');
/**
* The EditorJS class injector
*/
export const EditorJSInstance = new InjectionToken<EditorJSClass>('EditorJSInstance');
/**
* Options for a Injector method
*/
export interface InjectorMethodOption {
/**
* The holder for the option
*/
holder: string;
/**
* Optional blocks
*/
data?: OutputData;
/**
* Optional editor
*/
editor?: EditorJS;
/**
* Don't call save
*/
skipSave?: boolean;
}
/**
* Options to pass when calling the EditorJS instance API
*/
export interface InjectorApiCallOptions {
/**
* Holder for the EditorJS instance
*/
holder: string;
/**
* The method to call
*/
method: string;
/**
* The optional namespace for the API call
*/
namespace?: string;
}
/**
* A response from the EditorJS api
*/
export interface InjectorApiCallResponse<T = any> extends InjectorApiCallOptions {
result: T;
}
/**
* Interface for the injected EditorJS class, returns the static
* class of EditorJS with the version and that creates the instance and provides
* the Typescript parse with type information
*/
export interface EditorJSClass<T = EditorJS> extends Function {
new (...args: any[]): T;
/**
* EditorJS version
*/
version: string;
}