roosterjs-editor-adapter 0.26.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/LICENSE +25 -0
- package/README.md +262 -0
- package/lib/corePlugins/BridgePlugin.d.ts +73 -0
- package/lib/corePlugins/BridgePlugin.js +124 -0
- package/lib/corePlugins/BridgePlugin.js.map +1 -0
- package/lib/corePlugins/EditPlugin.d.ts +6 -0
- package/lib/corePlugins/EditPlugin.js +89 -0
- package/lib/corePlugins/EditPlugin.js.map +1 -0
- package/lib/editor/DarkColorHandlerImpl.d.ts +6 -0
- package/lib/editor/DarkColorHandlerImpl.js +134 -0
- package/lib/editor/DarkColorHandlerImpl.js.map +1 -0
- package/lib/editor/EditorAdapter.d.ts +341 -0
- package/lib/editor/EditorAdapter.js +843 -0
- package/lib/editor/EditorAdapter.js.map +1 -0
- package/lib/editor/utils/buildRangeEx.d.ts +5 -0
- package/lib/editor/utils/buildRangeEx.js +81 -0
- package/lib/editor/utils/buildRangeEx.js.map +1 -0
- package/lib/editor/utils/eventConverter.d.ts +15 -0
- package/lib/editor/utils/eventConverter.js +463 -0
- package/lib/editor/utils/eventConverter.js.map +1 -0
- package/lib/editor/utils/insertNode.d.ts +7 -0
- package/lib/editor/utils/insertNode.js +147 -0
- package/lib/editor/utils/insertNode.js.map +1 -0
- package/lib/editor/utils/selectionConverter.d.ts +10 -0
- package/lib/editor/utils/selectionConverter.js +79 -0
- package/lib/editor/utils/selectionConverter.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/publicTypes/BeforePasteAdapterEvent.d.ts +15 -0
- package/lib/publicTypes/BeforePasteAdapterEvent.js +3 -0
- package/lib/publicTypes/BeforePasteAdapterEvent.js.map +1 -0
- package/lib/publicTypes/EditorAdapterOptions.d.ts +20 -0
- package/lib/publicTypes/EditorAdapterOptions.js +3 -0
- package/lib/publicTypes/EditorAdapterOptions.js.map +1 -0
- package/lib-amd/corePlugins/BridgePlugin.d.ts +73 -0
- package/lib-amd/corePlugins/BridgePlugin.js +122 -0
- package/lib-amd/corePlugins/BridgePlugin.js.map +1 -0
- package/lib-amd/corePlugins/EditPlugin.d.ts +6 -0
- package/lib-amd/corePlugins/EditPlugin.js +90 -0
- package/lib-amd/corePlugins/EditPlugin.js.map +1 -0
- package/lib-amd/editor/DarkColorHandlerImpl.d.ts +6 -0
- package/lib-amd/editor/DarkColorHandlerImpl.js +135 -0
- package/lib-amd/editor/DarkColorHandlerImpl.js.map +1 -0
- package/lib-amd/editor/EditorAdapter.d.ts +341 -0
- package/lib-amd/editor/EditorAdapter.js +836 -0
- package/lib-amd/editor/EditorAdapter.js.map +1 -0
- package/lib-amd/editor/utils/buildRangeEx.d.ts +5 -0
- package/lib-amd/editor/utils/buildRangeEx.js +82 -0
- package/lib-amd/editor/utils/buildRangeEx.js.map +1 -0
- package/lib-amd/editor/utils/eventConverter.d.ts +15 -0
- package/lib-amd/editor/utils/eventConverter.js +463 -0
- package/lib-amd/editor/utils/eventConverter.js.map +1 -0
- package/lib-amd/editor/utils/insertNode.d.ts +7 -0
- package/lib-amd/editor/utils/insertNode.js +148 -0
- package/lib-amd/editor/utils/insertNode.js.map +1 -0
- package/lib-amd/editor/utils/selectionConverter.d.ts +10 -0
- package/lib-amd/editor/utils/selectionConverter.js +79 -0
- package/lib-amd/editor/utils/selectionConverter.js.map +1 -0
- package/lib-amd/index.d.ts +3 -0
- package/lib-amd/index.js +7 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/publicTypes/BeforePasteAdapterEvent.d.ts +15 -0
- package/lib-amd/publicTypes/BeforePasteAdapterEvent.js +5 -0
- package/lib-amd/publicTypes/BeforePasteAdapterEvent.js.map +1 -0
- package/lib-amd/publicTypes/EditorAdapterOptions.d.ts +20 -0
- package/lib-amd/publicTypes/EditorAdapterOptions.js +5 -0
- package/lib-amd/publicTypes/EditorAdapterOptions.js.map +1 -0
- package/lib-mjs/corePlugins/BridgePlugin.d.ts +73 -0
- package/lib-mjs/corePlugins/BridgePlugin.js +120 -0
- package/lib-mjs/corePlugins/BridgePlugin.js.map +1 -0
- package/lib-mjs/corePlugins/EditPlugin.d.ts +6 -0
- package/lib-mjs/corePlugins/EditPlugin.js +85 -0
- package/lib-mjs/corePlugins/EditPlugin.js.map +1 -0
- package/lib-mjs/editor/DarkColorHandlerImpl.d.ts +6 -0
- package/lib-mjs/editor/DarkColorHandlerImpl.js +130 -0
- package/lib-mjs/editor/DarkColorHandlerImpl.js.map +1 -0
- package/lib-mjs/editor/EditorAdapter.d.ts +341 -0
- package/lib-mjs/editor/EditorAdapter.js +840 -0
- package/lib-mjs/editor/EditorAdapter.js.map +1 -0
- package/lib-mjs/editor/utils/buildRangeEx.d.ts +5 -0
- package/lib-mjs/editor/utils/buildRangeEx.js +77 -0
- package/lib-mjs/editor/utils/buildRangeEx.js.map +1 -0
- package/lib-mjs/editor/utils/eventConverter.d.ts +15 -0
- package/lib-mjs/editor/utils/eventConverter.js +458 -0
- package/lib-mjs/editor/utils/eventConverter.js.map +1 -0
- package/lib-mjs/editor/utils/insertNode.d.ts +7 -0
- package/lib-mjs/editor/utils/insertNode.js +143 -0
- package/lib-mjs/editor/utils/insertNode.js.map +1 -0
- package/lib-mjs/editor/utils/selectionConverter.d.ts +10 -0
- package/lib-mjs/editor/utils/selectionConverter.js +74 -0
- package/lib-mjs/editor/utils/selectionConverter.js.map +1 -0
- package/lib-mjs/index.d.ts +3 -0
- package/lib-mjs/index.js +2 -0
- package/lib-mjs/index.js.map +1 -0
- package/lib-mjs/publicTypes/BeforePasteAdapterEvent.d.ts +15 -0
- package/lib-mjs/publicTypes/BeforePasteAdapterEvent.js +2 -0
- package/lib-mjs/publicTypes/BeforePasteAdapterEvent.js.map +1 -0
- package/lib-mjs/publicTypes/EditorAdapterOptions.d.ts +20 -0
- package/lib-mjs/publicTypes/EditorAdapterOptions.js +2 -0
- package/lib-mjs/publicTypes/EditorAdapterOptions.js.map +1 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
RoosterJS
|
|
2
|
+
Copyright (c) Microsoft Corporation
|
|
3
|
+
All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
[](https://github.com/microsoft/roosterjs/actions/workflows/build-and-deploy.yml)
|
|
2
|
+
|
|
3
|
+
# Rooster
|
|
4
|
+
|
|
5
|
+
Rooster is a framework-independent JavaScript rich-text editor neatly nested
|
|
6
|
+
inside one HTML `<div>` element. Editing operations performed by end users are
|
|
7
|
+
handled in simple ways to generate the final HTML.
|
|
8
|
+
|
|
9
|
+
To view the sample site, please click the link below:
|
|
10
|
+
|
|
11
|
+
[RoosterJs Sample Site](https://microsoft.github.io/roosterjs/index.html).
|
|
12
|
+
|
|
13
|
+
## Upgrade from RoosterJs 7.\*
|
|
14
|
+
|
|
15
|
+
Please see [here](https://github.com/microsoft/roosterjs/wiki/RoosterJs-8).
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
### Packages
|
|
20
|
+
|
|
21
|
+
Rooster contains 6 basic packages.
|
|
22
|
+
|
|
23
|
+
1. [roosterjs](https://microsoft.github.io/roosterjs/docs/modules/roosterjs.html):
|
|
24
|
+
A facade of all Rooster code for those who want a quick start. Use the
|
|
25
|
+
`createEditor()` function in roosterjs to create an editor with default
|
|
26
|
+
configurations.
|
|
27
|
+
|
|
28
|
+
2. [roosterjs-editor-core](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_editor_core.html):
|
|
29
|
+
Defines the core editor and plugin infrastructure. Use `roosterjs-editor-core`
|
|
30
|
+
instead of `roosterjs` to build and customize your own editor.
|
|
31
|
+
|
|
32
|
+
3. [roosterjs-editor-api](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_editor_api.html):
|
|
33
|
+
Defines APIs for editor operations. Use these APIs to modify content and
|
|
34
|
+
formatting in the editor you built using `roosterjs-editor-core`.
|
|
35
|
+
|
|
36
|
+
4. [roosterjs-editor-dom](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_editor_dom.html):
|
|
37
|
+
Defines APIs for DOM operations. Use `roosterjs-editor-api` instead unless
|
|
38
|
+
you want to access DOM API directly.
|
|
39
|
+
|
|
40
|
+
5. [roosterjs-editor-plugins](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_editor_plugins.html):
|
|
41
|
+
Defines basic plugins for common features. Examples: making hyperlinks,
|
|
42
|
+
pasting HTML content, inserting inline images.
|
|
43
|
+
|
|
44
|
+
6. [roosterjs-editor-types](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_editor_types.html):
|
|
45
|
+
Defines public interfaces and enumerations.
|
|
46
|
+
|
|
47
|
+
There are also some extension packages to provide additional functionalities.
|
|
48
|
+
|
|
49
|
+
1. [roosterjs-color-utils](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_color_utils.html):
|
|
50
|
+
Provide color transformation utility to make editor work under dark mode.
|
|
51
|
+
|
|
52
|
+
2. [roosterjs-react](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_react.html):
|
|
53
|
+
Provide a React wrapper of roosterjs so it can be easily used with React.
|
|
54
|
+
|
|
55
|
+
3. [roosterjs-editor-types-compatible](https://microsoft.github.io/roosterjs/docs/modules/roosterjs_editor_types_compatible.html):
|
|
56
|
+
Provide types that are compatible with isolatedModules mode. When using isolatedModules mode,
|
|
57
|
+
"const enum" will not work correctly, this package provides enums with prefix "Compatible" in
|
|
58
|
+
their names and they have the same value with const enums in roosterjs-editor-types package
|
|
59
|
+
|
|
60
|
+
### APIs
|
|
61
|
+
|
|
62
|
+
Rooster provides DOM level APIs (in `roosterjs-editor-dom`), core APIs (in `roosterjs-editor-core`), and formatting APIs
|
|
63
|
+
(in `roosterjs-editor-api`) to perform editing operations.
|
|
64
|
+
|
|
65
|
+
`roosterjs-editor-dom` provides several levels of DOM operations:
|
|
66
|
+
|
|
67
|
+
- Perform basic DOM operations such as `wrap()`, `unwrap()`, ...
|
|
68
|
+
- Wrap a given DOM node with `InlineElement` or `BlockElement` and perform
|
|
69
|
+
operations with DOM Walker API.
|
|
70
|
+
- Perform DOM operations on a given scope using scopers.
|
|
71
|
+
- Travel among `InlineElements` and `BlockElements` with scope using
|
|
72
|
+
ContentTraverser API.
|
|
73
|
+
|
|
74
|
+
`roosterjs-editor-core` provides APIs for editor core. Editor class will call such
|
|
75
|
+
APIs to perform basic editor operations. These APIs are overridable by specifying
|
|
76
|
+
API overrides in Editor options when creating the editor.
|
|
77
|
+
|
|
78
|
+
`roosterjs-editor-api` provides APIs for scenario-based operations triggered by
|
|
79
|
+
user interaction.
|
|
80
|
+
|
|
81
|
+
## Plugins
|
|
82
|
+
|
|
83
|
+
Rooster supports plugins. You can use built-in plugins or build your own.
|
|
84
|
+
Plugins call APIs to communicate with the editor. When an operation is
|
|
85
|
+
performed by the user or when content is changed by code, the editor will
|
|
86
|
+
trigger events for the plugins to handle.
|
|
87
|
+
|
|
88
|
+
Here's a sample plugin which will show a dialog containing "Hello Rooster" when
|
|
89
|
+
an "a" is typed in the editor:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
class HelloRooster implements EditorPlugin {
|
|
93
|
+
getName() {
|
|
94
|
+
return 'HelloRooster';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
initialize(editor: IEditor) {}
|
|
98
|
+
|
|
99
|
+
dispose() {}
|
|
100
|
+
|
|
101
|
+
onPluginEvent(e: PluginEvent) {
|
|
102
|
+
if (e.eventType == PluginEventType.KeyPress && e.rawEvent.which == 65) {
|
|
103
|
+
alert('Hello Rooster');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Installation
|
|
110
|
+
|
|
111
|
+
Install via NPM or Yarn:
|
|
112
|
+
|
|
113
|
+
`yarn add roosterjs`
|
|
114
|
+
|
|
115
|
+
You can also install sub packages separately:
|
|
116
|
+
|
|
117
|
+
`yarn add roosterjs-editor-core`
|
|
118
|
+
|
|
119
|
+
`yarn add roosterjs-editor-api`
|
|
120
|
+
|
|
121
|
+
`...`
|
|
122
|
+
|
|
123
|
+
In order to run the code below, you may also need to install [webpack](https://webpack.js.org/):
|
|
124
|
+
|
|
125
|
+
`yarn add webpack -g`
|
|
126
|
+
|
|
127
|
+
## Usage
|
|
128
|
+
|
|
129
|
+
### A quick start
|
|
130
|
+
|
|
131
|
+
1. Create `editor.htm` which contains a DIV with some styles, buttons to handle some click events and a reference to rooster.js (update with the path to your rooster.js file):
|
|
132
|
+
|
|
133
|
+
```html
|
|
134
|
+
<html>
|
|
135
|
+
<body>
|
|
136
|
+
<div style="width: 500px; height: 400px; border: solid 1px black" id="contentDiv"></div>
|
|
137
|
+
<button id="buttonB">B</button> <button id="buttonI">I</button>
|
|
138
|
+
<button id="buttonU">U</button>
|
|
139
|
+
<script src="rooster.js"></script>
|
|
140
|
+
<script>
|
|
141
|
+
var contentDiv = document.getElementById('contentDiv');
|
|
142
|
+
var editor = roosterjs.createEditor(contentDiv);
|
|
143
|
+
|
|
144
|
+
editor.setContent('Welcome to <b>RoosterJs</b>!');
|
|
145
|
+
document.getElementById('buttonB').addEventListener('click', function () {
|
|
146
|
+
roosterjs.toggleBold(editor);
|
|
147
|
+
});
|
|
148
|
+
document.getElementById('buttonI').addEventListener('click', function () {
|
|
149
|
+
roosterjs.toggleItalic(editor);
|
|
150
|
+
});
|
|
151
|
+
document.getElementById('buttonU').addEventListener('click', function () {
|
|
152
|
+
roosterjs.toggleUnderline(editor);
|
|
153
|
+
});
|
|
154
|
+
</script>
|
|
155
|
+
</body>
|
|
156
|
+
</html>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
2. Navigate to editor.htm, you will see a editor shown in the page which includes buttons with bold, italic, underline
|
|
160
|
+
actions.
|
|
161
|
+
|
|
162
|
+
## Sample code
|
|
163
|
+
|
|
164
|
+
To view the sample site, please click [here](https://microsoft.github.io/roosterjs/index.html).
|
|
165
|
+
|
|
166
|
+
To build the sample site code yourself, follow these instructions:
|
|
167
|
+
|
|
168
|
+
1. Get dependencies using [yarn](https://yarnpkg.com) or [npm](https://www.npmjs.com/):
|
|
169
|
+
|
|
170
|
+
```cmd
|
|
171
|
+
yarn
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
2. Build the source code, and start the sample editor:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
yarn start
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
or
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
npm start
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Debugging
|
|
187
|
+
|
|
188
|
+
There are two options for debugging:
|
|
189
|
+
|
|
190
|
+
1. Debugging from VSCode
|
|
191
|
+
|
|
192
|
+
- Ensure the sample editor is running
|
|
193
|
+
- Set the breakpoints within VSCode
|
|
194
|
+
- Select "Debug app in Chrome" from the VSCode debugging configuration dropdown
|
|
195
|
+
<img src="/assets/readme-images/debug-in-VSCode.png" width="411" height="278"><br>
|
|
196
|
+
- Run the scenario that needs to be debugged
|
|
197
|
+
|
|
198
|
+
2. Debugging directly from the development tools within the web browser
|
|
199
|
+
- The directions for how to do this are specific to each web browser. By opening the developer
|
|
200
|
+
tools for the web browser that Rooster is running on, you will be able to set breakpoints in
|
|
201
|
+
the code and debug accordingly.
|
|
202
|
+
|
|
203
|
+
## Running tests
|
|
204
|
+
|
|
205
|
+
There are two ways that tests can be run:
|
|
206
|
+
|
|
207
|
+
1. Run all tests or a single test from VSCode<br>
|
|
208
|
+
- (Skip if running all tests) Ensure the file that you want to test is selected (ie: toggleBold.ts
|
|
209
|
+
or toggleBoldTest.ts)
|
|
210
|
+
- Select "Test all files" or "Test current file" from the VSCode debugging configuration dropdown
|
|
211
|
+
<img src="/assets/readme-images/test-in-VSCode.png" width="402" height="268">
|
|
212
|
+
2. Run all tests from command line
|
|
213
|
+
```
|
|
214
|
+
yarn test
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Dependencies
|
|
218
|
+
|
|
219
|
+
As a NodeJs package, RoosterJs has dependencies for runtime (specified in package.json under each sub
|
|
220
|
+
packages in "dependencies" section) and dependencies for build time (specified in package.json under
|
|
221
|
+
root path in "devDependencies" section).
|
|
222
|
+
|
|
223
|
+
For runtime dependencies, there are two parts:
|
|
224
|
+
|
|
225
|
+
- Internal dependencies (a RoosterJs package depends on other RoosterJs packages)
|
|
226
|
+
- External dependencies (RoosterJs depends on other NPM packages)
|
|
227
|
+
|
|
228
|
+
Currently we have very few external dependencies. Before adding any new dependency, we need to check:
|
|
229
|
+
|
|
230
|
+
1. What's the value of the new dependency and the code using the dependency bring into roosterjs?
|
|
231
|
+
If we add a new dependency and create our new API to just call into the dependency, that new API
|
|
232
|
+
doesn't actually bring too much value, and people who uses roosterjs in their project can do this
|
|
233
|
+
themselves in their code, and we should not add such dependency to people who don't really need it.
|
|
234
|
+
|
|
235
|
+
2. What's the dependency tree of the dependency?
|
|
236
|
+
If we introduce a new dependency which has a deep dependency tree, we need to be careful since it
|
|
237
|
+
means we are actually adding a lot of new dependencies and our code size may be increased a lot.
|
|
238
|
+
|
|
239
|
+
3. How much functionalities do we need from the dependency?
|
|
240
|
+
If the dependency provides a lot of functionalities but we actually only need a small piece of them,
|
|
241
|
+
we may need to consider other solutions, such as find another smaller one, or do it ourselves.
|
|
242
|
+
|
|
243
|
+
4. What's the license of the dependency?
|
|
244
|
+
A dependency package under MIT license is good to be used for RoosterJs. For other licenses, we need
|
|
245
|
+
to review and see if we can take it as a dependency.
|
|
246
|
+
|
|
247
|
+
If you still feel a new dependency is required after checking these questions, we can review it and
|
|
248
|
+
finally decide whether we should add the new dependency.
|
|
249
|
+
|
|
250
|
+
For build time dependencies, it is more flexible to add new dependencies since it won't increase runtime
|
|
251
|
+
code size or dependencies.
|
|
252
|
+
|
|
253
|
+
## More documentation
|
|
254
|
+
|
|
255
|
+
We are still working on more documentation in [roosterjs wiki](https://github.com/Microsoft/roosterjs/wiki) and [API reference](https://microsoft.github.io/roosterjs/docs/index.html).
|
|
256
|
+
|
|
257
|
+
## License - MIT
|
|
258
|
+
|
|
259
|
+
License
|
|
260
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
261
|
+
|
|
262
|
+
Licensed under the [MIT](LICENSE) License.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { EditorPlugin as LegacyEditorPlugin, ContextMenuProvider as LegacyContextMenuProvider, IEditor as ILegacyEditor, ExperimentalFeatures, SizeTransformer, EditPluginState, CustomData, DarkColorHandler } from 'roosterjs-editor-types';
|
|
2
|
+
import type { ContextMenuProvider, IStandaloneEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
* Represents the core data structure of a editor adapter
|
|
6
|
+
*/
|
|
7
|
+
export interface EditorAdapterCore {
|
|
8
|
+
/**
|
|
9
|
+
* Custom data of this editor
|
|
10
|
+
*/
|
|
11
|
+
readonly customData: Record<string, CustomData>;
|
|
12
|
+
/**
|
|
13
|
+
* Enabled experimental features
|
|
14
|
+
*/
|
|
15
|
+
readonly experimentalFeatures: ExperimentalFeatures[];
|
|
16
|
+
/**
|
|
17
|
+
* Dark model handler for the editor, used for variable-based solution.
|
|
18
|
+
* If keep it null, editor will still use original dataset-based dark mode solution.
|
|
19
|
+
*/
|
|
20
|
+
readonly darkColorHandler: DarkColorHandler;
|
|
21
|
+
/**
|
|
22
|
+
* Plugin state of EditPlugin
|
|
23
|
+
*/
|
|
24
|
+
readonly edit: EditPluginState;
|
|
25
|
+
/**
|
|
26
|
+
* Context Menu providers
|
|
27
|
+
*/
|
|
28
|
+
readonly contextMenuProviders: LegacyContextMenuProvider<any>[];
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use zoomScale instead
|
|
31
|
+
*/
|
|
32
|
+
readonly sizeTransformer: SizeTransformer;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
* Act as a bridge between Standalone editor and Content Model editor, translate Standalone editor event type to legacy event type
|
|
37
|
+
*/
|
|
38
|
+
export declare class BridgePlugin implements ContextMenuProvider<any> {
|
|
39
|
+
private onInitialize;
|
|
40
|
+
private experimentalFeatures;
|
|
41
|
+
private legacyPlugins;
|
|
42
|
+
private edit;
|
|
43
|
+
private contextMenuProviders;
|
|
44
|
+
private checkExclusivelyHandling;
|
|
45
|
+
constructor(onInitialize: (core: EditorAdapterCore) => ILegacyEditor, legacyPlugins?: LegacyEditorPlugin[], experimentalFeatures?: ExperimentalFeatures[]);
|
|
46
|
+
/**
|
|
47
|
+
* Get a friendly name of this plugin
|
|
48
|
+
*/
|
|
49
|
+
getName(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Initialize this plugin. This should only be called from Editor
|
|
52
|
+
* @param editor Editor instance
|
|
53
|
+
*/
|
|
54
|
+
initialize(editor: IStandaloneEditor): void;
|
|
55
|
+
/**
|
|
56
|
+
* Dispose this plugin
|
|
57
|
+
*/
|
|
58
|
+
dispose(): void;
|
|
59
|
+
willHandleEventExclusively(event: PluginEvent): boolean;
|
|
60
|
+
onPluginEvent(event: PluginEvent): void;
|
|
61
|
+
/**
|
|
62
|
+
* A callback to return context menu items
|
|
63
|
+
* @param target Target node that triggered a ContextMenu event
|
|
64
|
+
* @returns An array of context menu items, or null means no items needed
|
|
65
|
+
*/
|
|
66
|
+
getContextMenuItems(target: Node): any[];
|
|
67
|
+
private createEditorCore;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @internal Export for test only. This function is only used for compatibility from older build
|
|
71
|
+
|
|
72
|
+
*/
|
|
73
|
+
export declare function createSizeTransformer(editor: IStandaloneEditor): SizeTransformer;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSizeTransformer = exports.BridgePlugin = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var DarkColorHandlerImpl_1 = require("../editor/DarkColorHandlerImpl");
|
|
6
|
+
var EditPlugin_1 = require("./EditPlugin");
|
|
7
|
+
var eventConverter_1 = require("../editor/utils/eventConverter");
|
|
8
|
+
var ExclusivelyHandleEventPluginKey = '__ExclusivelyHandleEventPlugin';
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
* Act as a bridge between Standalone editor and Content Model editor, translate Standalone editor event type to legacy event type
|
|
12
|
+
*/
|
|
13
|
+
var BridgePlugin = /** @class */ (function () {
|
|
14
|
+
function BridgePlugin(onInitialize, legacyPlugins, experimentalFeatures) {
|
|
15
|
+
if (legacyPlugins === void 0) { legacyPlugins = []; }
|
|
16
|
+
if (experimentalFeatures === void 0) { experimentalFeatures = []; }
|
|
17
|
+
this.onInitialize = onInitialize;
|
|
18
|
+
this.experimentalFeatures = experimentalFeatures;
|
|
19
|
+
var editPlugin = (0, EditPlugin_1.createEditPlugin)();
|
|
20
|
+
this.legacyPlugins = (0, tslib_1.__spreadArray)([editPlugin], (0, tslib_1.__read)(legacyPlugins.filter(function (x) { return !!x; })), false);
|
|
21
|
+
this.edit = editPlugin.getState();
|
|
22
|
+
this.contextMenuProviders = this.legacyPlugins.filter(isContextMenuProvider);
|
|
23
|
+
this.checkExclusivelyHandling = this.legacyPlugins.some(function (plugin) { return plugin.willHandleEventExclusively; });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get a friendly name of this plugin
|
|
27
|
+
*/
|
|
28
|
+
BridgePlugin.prototype.getName = function () {
|
|
29
|
+
return 'Bridge';
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Initialize this plugin. This should only be called from Editor
|
|
33
|
+
* @param editor Editor instance
|
|
34
|
+
*/
|
|
35
|
+
BridgePlugin.prototype.initialize = function (editor) {
|
|
36
|
+
var outerEditor = this.onInitialize(this.createEditorCore(editor));
|
|
37
|
+
this.legacyPlugins.forEach(function (plugin) { return plugin.initialize(outerEditor); });
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Dispose this plugin
|
|
41
|
+
*/
|
|
42
|
+
BridgePlugin.prototype.dispose = function () {
|
|
43
|
+
for (var i = this.legacyPlugins.length - 1; i >= 0; i--) {
|
|
44
|
+
var plugin = this.legacyPlugins[i];
|
|
45
|
+
plugin.dispose();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
BridgePlugin.prototype.willHandleEventExclusively = function (event) {
|
|
49
|
+
var _a;
|
|
50
|
+
var oldEvent;
|
|
51
|
+
if (this.checkExclusivelyHandling && (oldEvent = (0, eventConverter_1.newEventToOldEvent)(event))) {
|
|
52
|
+
for (var i = 0; i < this.legacyPlugins.length; i++) {
|
|
53
|
+
var plugin = this.legacyPlugins[i];
|
|
54
|
+
if ((_a = plugin.willHandleEventExclusively) === null || _a === void 0 ? void 0 : _a.call(plugin, oldEvent)) {
|
|
55
|
+
if (!event.eventDataCache) {
|
|
56
|
+
event.eventDataCache = {};
|
|
57
|
+
}
|
|
58
|
+
event.eventDataCache[ExclusivelyHandleEventPluginKey] = plugin;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
65
|
+
BridgePlugin.prototype.onPluginEvent = function (event) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
var oldEvent = (0, eventConverter_1.newEventToOldEvent)(event);
|
|
68
|
+
if (oldEvent) {
|
|
69
|
+
var exclusivelyHandleEventPlugin = (_a = event.eventDataCache) === null || _a === void 0 ? void 0 : _a[ExclusivelyHandleEventPluginKey];
|
|
70
|
+
if (exclusivelyHandleEventPlugin) {
|
|
71
|
+
(_b = exclusivelyHandleEventPlugin.onPluginEvent) === null || _b === void 0 ? void 0 : _b.call(exclusivelyHandleEventPlugin, oldEvent);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.legacyPlugins.forEach(function (plugin) { var _a; return (_a = plugin.onPluginEvent) === null || _a === void 0 ? void 0 : _a.call(plugin, oldEvent); });
|
|
75
|
+
}
|
|
76
|
+
Object.assign(event, (0, eventConverter_1.oldEventToNewEvent)(oldEvent, event));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* A callback to return context menu items
|
|
81
|
+
* @param target Target node that triggered a ContextMenu event
|
|
82
|
+
* @returns An array of context menu items, or null means no items needed
|
|
83
|
+
*/
|
|
84
|
+
BridgePlugin.prototype.getContextMenuItems = function (target) {
|
|
85
|
+
var allItems = [];
|
|
86
|
+
this.contextMenuProviders.forEach(function (provider) {
|
|
87
|
+
var _a;
|
|
88
|
+
var items = (_a = provider.getContextMenuItems(target)) !== null && _a !== void 0 ? _a : [];
|
|
89
|
+
if ((items === null || items === void 0 ? void 0 : items.length) > 0) {
|
|
90
|
+
if (allItems.length > 0) {
|
|
91
|
+
allItems.push(null);
|
|
92
|
+
}
|
|
93
|
+
allItems.push.apply(allItems, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(items), false));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return allItems;
|
|
97
|
+
};
|
|
98
|
+
BridgePlugin.prototype.createEditorCore = function (editor) {
|
|
99
|
+
var _a;
|
|
100
|
+
return {
|
|
101
|
+
customData: {},
|
|
102
|
+
experimentalFeatures: (_a = this.experimentalFeatures) !== null && _a !== void 0 ? _a : [],
|
|
103
|
+
sizeTransformer: createSizeTransformer(editor),
|
|
104
|
+
darkColorHandler: (0, DarkColorHandlerImpl_1.createDarkColorHandler)(editor.getColorManager()),
|
|
105
|
+
edit: this.edit,
|
|
106
|
+
contextMenuProviders: this.contextMenuProviders,
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
return BridgePlugin;
|
|
110
|
+
}());
|
|
111
|
+
exports.BridgePlugin = BridgePlugin;
|
|
112
|
+
/**
|
|
113
|
+
* @internal Export for test only. This function is only used for compatibility from older build
|
|
114
|
+
|
|
115
|
+
*/
|
|
116
|
+
function createSizeTransformer(editor) {
|
|
117
|
+
return function (size) { return size / editor.getDOMHelper().calculateZoomScale(); };
|
|
118
|
+
}
|
|
119
|
+
exports.createSizeTransformer = createSizeTransformer;
|
|
120
|
+
function isContextMenuProvider(source) {
|
|
121
|
+
var _a;
|
|
122
|
+
return !!((_a = source) === null || _a === void 0 ? void 0 : _a.getContextMenuItems);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=BridgePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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A0HzB;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,MAAyB;IAC3D,OAAO,UAAA,IAAI,IAAI,OAAA,IAAI,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,kBAAkB,EAAE,EAAjD,CAAiD,CAAC;AACrE,CAAC;AAFD,sDAEC;AAED,SAAS,qBAAqB,CAC1B,MAA0B;;IAE1B,OAAO,CAAC,CAAC,CAAA,MAAiC,MAAO,0CAAE,mBAAmB,CAAA,CAAC;AAC3E,CAAC","sourcesContent":["import { createDarkColorHandler } from '../editor/DarkColorHandlerImpl';\r\nimport { createEditPlugin } from './EditPlugin';\r\nimport { newEventToOldEvent, oldEventToNewEvent } from '../editor/utils/eventConverter';\r\nimport type {\r\n EditorPlugin as LegacyEditorPlugin,\r\n PluginEvent as LegacyPluginEvent,\r\n ContextMenuProvider as LegacyContextMenuProvider,\r\n IEditor as ILegacyEditor,\r\n ExperimentalFeatures,\r\n SizeTransformer,\r\n EditPluginState,\r\n CustomData,\r\n DarkColorHandler,\r\n} from 'roosterjs-editor-types';\r\nimport type {\r\n ContextMenuProvider,\r\n IStandaloneEditor,\r\n PluginEvent,\r\n} from 'roosterjs-content-model-types';\r\n\r\nconst ExclusivelyHandleEventPluginKey = '__ExclusivelyHandleEventPlugin';\r\n\r\n/**\r\n * @internal\r\n * Represents the core data structure of a editor adapter\r\n */\r\nexport interface EditorAdapterCore {\r\n /**\r\n * Custom data of this editor\r\n */\r\n readonly customData: Record<string, CustomData>;\r\n\r\n /**\r\n * Enabled experimental features\r\n */\r\n readonly experimentalFeatures: ExperimentalFeatures[];\r\n\r\n /**\r\n * Dark model handler for the editor, used for variable-based solution.\r\n * If keep it null, editor will still use original dataset-based dark mode solution.\r\n */\r\n readonly darkColorHandler: DarkColorHandler;\r\n\r\n /**\r\n * Plugin state of EditPlugin\r\n */\r\n readonly edit: EditPluginState;\r\n\r\n /**\r\n * Context Menu providers\r\n */\r\n readonly contextMenuProviders: LegacyContextMenuProvider<any>[];\r\n\r\n /**\r\n * @deprecated Use zoomScale instead\r\n */\r\n readonly sizeTransformer: SizeTransformer;\r\n}\r\n\r\n/**\r\n * @internal\r\n * Act as a bridge between Standalone editor and Content Model editor, translate Standalone editor event type to legacy event type\r\n */\r\nexport class BridgePlugin implements ContextMenuProvider<any> {\r\n private legacyPlugins: LegacyEditorPlugin[];\r\n private edit: EditPluginState;\r\n private contextMenuProviders: LegacyContextMenuProvider<any>[];\r\n private checkExclusivelyHandling: boolean;\r\n\r\n constructor(\r\n private onInitialize: (core: EditorAdapterCore) => ILegacyEditor,\r\n legacyPlugins: LegacyEditorPlugin[] = [],\r\n private experimentalFeatures: ExperimentalFeatures[] = []\r\n ) {\r\n const editPlugin = createEditPlugin();\r\n\r\n this.legacyPlugins = [editPlugin, ...legacyPlugins.filter(x => !!x)];\r\n this.edit = editPlugin.getState();\r\n this.contextMenuProviders = this.legacyPlugins.filter(isContextMenuProvider);\r\n this.checkExclusivelyHandling = this.legacyPlugins.some(\r\n plugin => plugin.willHandleEventExclusively\r\n );\r\n }\r\n\r\n /**\r\n * Get a friendly name of this plugin\r\n */\r\n getName() {\r\n return 'Bridge';\r\n }\r\n\r\n /**\r\n * Initialize this plugin. This should only be called from Editor\r\n * @param editor Editor instance\r\n */\r\n initialize(editor: IStandaloneEditor) {\r\n const outerEditor = this.onInitialize(this.createEditorCore(editor));\r\n\r\n this.legacyPlugins.forEach(plugin => plugin.initialize(outerEditor));\r\n }\r\n\r\n /**\r\n * Dispose this plugin\r\n */\r\n dispose() {\r\n for (let i = this.legacyPlugins.length - 1; i >= 0; i--) {\r\n const plugin = this.legacyPlugins[i];\r\n\r\n plugin.dispose();\r\n }\r\n }\r\n\r\n willHandleEventExclusively(event: PluginEvent) {\r\n let oldEvent: LegacyPluginEvent | undefined;\r\n\r\n if (this.checkExclusivelyHandling && (oldEvent = newEventToOldEvent(event))) {\r\n for (let i = 0; i < this.legacyPlugins.length; i++) {\r\n const plugin = this.legacyPlugins[i];\r\n\r\n if (plugin.willHandleEventExclusively?.(oldEvent)) {\r\n if (!event.eventDataCache) {\r\n event.eventDataCache = {};\r\n }\r\n\r\n event.eventDataCache[ExclusivelyHandleEventPluginKey] = plugin;\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n onPluginEvent(event: PluginEvent) {\r\n const oldEvent = newEventToOldEvent(event);\r\n\r\n if (oldEvent) {\r\n const exclusivelyHandleEventPlugin = event.eventDataCache?.[\r\n ExclusivelyHandleEventPluginKey\r\n ] as LegacyEditorPlugin | undefined;\r\n\r\n if (exclusivelyHandleEventPlugin) {\r\n exclusivelyHandleEventPlugin.onPluginEvent?.(oldEvent);\r\n } else {\r\n this.legacyPlugins.forEach(plugin => plugin.onPluginEvent?.(oldEvent));\r\n }\r\n\r\n Object.assign(event, oldEventToNewEvent(oldEvent, event));\r\n }\r\n }\r\n\r\n /**\r\n * A callback to return context menu items\r\n * @param target Target node that triggered a ContextMenu event\r\n * @returns An array of context menu items, or null means no items needed\r\n */\r\n getContextMenuItems(target: Node): any[] {\r\n const allItems: any[] = [];\r\n\r\n this.contextMenuProviders.forEach(provider => {\r\n const items = provider.getContextMenuItems(target) ?? [];\r\n if (items?.length > 0) {\r\n if (allItems.length > 0) {\r\n allItems.push(null);\r\n }\r\n\r\n allItems.push(...items);\r\n }\r\n });\r\n\r\n return allItems;\r\n }\r\n\r\n private createEditorCore(editor: IStandaloneEditor): EditorAdapterCore {\r\n return {\r\n customData: {},\r\n experimentalFeatures: this.experimentalFeatures ?? [],\r\n sizeTransformer: createSizeTransformer(editor),\r\n darkColorHandler: createDarkColorHandler(editor.getColorManager()),\r\n edit: this.edit,\r\n contextMenuProviders: this.contextMenuProviders,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * @internal Export for test only. This function is only used for compatibility from older build\r\n\r\n */\r\nexport function createSizeTransformer(editor: IStandaloneEditor): SizeTransformer {\r\n return size => size / editor.getDOMHelper().calculateZoomScale();\r\n}\r\n\r\nfunction isContextMenuProvider(\r\n source: LegacyEditorPlugin\r\n): source is LegacyContextMenuProvider<any> {\r\n return !!(<LegacyContextMenuProvider<any>>source)?.getContextMenuItems;\r\n}\r\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEditPlugin = void 0;
|
|
4
|
+
var roosterjs_editor_dom_1 = require("roosterjs-editor-dom");
|
|
5
|
+
/**
|
|
6
|
+
* Edit Component helps handle Content edit features
|
|
7
|
+
*/
|
|
8
|
+
var EditPlugin = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* Construct a new instance of EditPlugin
|
|
11
|
+
* @param options The editor options
|
|
12
|
+
*/
|
|
13
|
+
function EditPlugin() {
|
|
14
|
+
this.editor = null;
|
|
15
|
+
this.state = {
|
|
16
|
+
features: {},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get a friendly name of this plugin
|
|
21
|
+
*/
|
|
22
|
+
EditPlugin.prototype.getName = function () {
|
|
23
|
+
return 'Edit';
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Initialize this plugin. This should only be called from Editor
|
|
27
|
+
* @param editor Editor instance
|
|
28
|
+
*/
|
|
29
|
+
EditPlugin.prototype.initialize = function (editor) {
|
|
30
|
+
this.editor = editor;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Dispose this plugin
|
|
34
|
+
*/
|
|
35
|
+
EditPlugin.prototype.dispose = function () {
|
|
36
|
+
this.editor = null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Get plugin state object
|
|
40
|
+
*/
|
|
41
|
+
EditPlugin.prototype.getState = function () {
|
|
42
|
+
return this.state;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Handle events triggered from editor
|
|
46
|
+
* @param event PluginEvent object
|
|
47
|
+
*/
|
|
48
|
+
EditPlugin.prototype.onPluginEvent = function (event) {
|
|
49
|
+
var _a;
|
|
50
|
+
var hasFunctionKey = false;
|
|
51
|
+
var features = null;
|
|
52
|
+
var ctrlOrMeta = false;
|
|
53
|
+
var isKeyDownEvent = event.eventType == 0 /* KeyDown */;
|
|
54
|
+
if (isKeyDownEvent) {
|
|
55
|
+
var rawEvent = event.rawEvent;
|
|
56
|
+
var range = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getSelectionRange();
|
|
57
|
+
ctrlOrMeta = (0, roosterjs_editor_dom_1.isCtrlOrMetaPressed)(rawEvent);
|
|
58
|
+
hasFunctionKey = ctrlOrMeta || rawEvent.altKey;
|
|
59
|
+
features =
|
|
60
|
+
this.state.features[rawEvent.which] ||
|
|
61
|
+
(range && !range.collapsed && this.state.features[258 /* RANGE */]);
|
|
62
|
+
}
|
|
63
|
+
else if (event.eventType == 7 /* ContentChanged */) {
|
|
64
|
+
features = this.state.features[257 /* CONTENTCHANGED */];
|
|
65
|
+
}
|
|
66
|
+
for (var i = 0; features && i < (features === null || features === void 0 ? void 0 : features.length); i++) {
|
|
67
|
+
var feature = features[i];
|
|
68
|
+
if ((feature.allowFunctionKeys || !hasFunctionKey) &&
|
|
69
|
+
this.editor &&
|
|
70
|
+
feature.shouldHandleEvent(event, this.editor, ctrlOrMeta)) {
|
|
71
|
+
feature.handleEvent(event, this.editor);
|
|
72
|
+
if (isKeyDownEvent) {
|
|
73
|
+
event.handledByEditFeature = true;
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return EditPlugin;
|
|
80
|
+
}());
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
* Create a new instance of EditPlugin.
|
|
84
|
+
*/
|
|
85
|
+
function createEditPlugin() {
|
|
86
|
+
return new EditPlugin();
|
|
87
|
+
}
|
|
88
|
+
exports.createEditPlugin = createEditPlugin;
|
|
89
|
+
//# sourceMappingURL=EditPlugin.js.map
|
|
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,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,iBAAY,CAAC,CAAC;SACtE;aAAM,IAAI,KAAK,CAAC,SAAS,0BAAkC,EAAE;YAC1D,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,0BAAqB,CAAC;SACvD;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,IAAI,CAAC,IAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAA,EAAE,CAAC,EAAE,EAAE;YACnD,IAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC5B,IACI,CAAC,OAAO,CAAC,iBAAiB,IAAI,CAAC,cAAc,CAAC;gBAC9C,IAAI,CAAC,MAAM;gBACX,OAAO,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,EAC3D;gBACE,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;gBACxC,IAAI,cAAc,EAAE;oBAChB,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC;iBACrC;gBACD,MAAM;aACT;SACJ;IACL,CAAC;IACL,iBAAC;AAAD,CAAC,AAjFD,IAiFC;AAED;;;GAGG;AACH,SAAgB,gBAAgB;IAC5B,OAAO,IAAI,UAAU,EAAE,CAAC;AAC5B,CAAC;AAFD,4CAEC","sourcesContent":["import { isCtrlOrMetaPressed } from 'roosterjs-editor-dom';\r\nimport { Keys, PluginEventType } from 'roosterjs-editor-types';\r\nimport type {\r\n EditPluginState,\r\n GenericContentEditFeature,\r\n IEditor,\r\n PluginEvent,\r\n PluginWithState,\r\n} from 'roosterjs-editor-types';\r\n\r\n/**\r\n * Edit Component helps handle Content edit features\r\n */\r\nclass EditPlugin implements PluginWithState<EditPluginState> {\r\n private editor: IEditor | null = null;\r\n private state: EditPluginState;\r\n\r\n /**\r\n * Construct a new instance of EditPlugin\r\n * @param options The editor options\r\n */\r\n constructor() {\r\n this.state = {\r\n features: {},\r\n };\r\n }\r\n\r\n /**\r\n * Get a friendly name of this plugin\r\n */\r\n getName() {\r\n return 'Edit';\r\n }\r\n\r\n /**\r\n * Initialize this plugin. This should only be called from Editor\r\n * @param editor Editor instance\r\n */\r\n initialize(editor: IEditor) {\r\n this.editor = editor;\r\n }\r\n\r\n /**\r\n * Dispose this plugin\r\n */\r\n dispose() {\r\n this.editor = null;\r\n }\r\n\r\n /**\r\n * Get plugin state object\r\n */\r\n getState() {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Handle events triggered from editor\r\n * @param event PluginEvent object\r\n */\r\n onPluginEvent(event: PluginEvent) {\r\n let hasFunctionKey = false;\r\n let features: GenericContentEditFeature<PluginEvent>[] | null = null;\r\n let ctrlOrMeta = false;\r\n const isKeyDownEvent = event.eventType == PluginEventType.KeyDown;\r\n\r\n if (isKeyDownEvent) {\r\n const rawEvent = event.rawEvent;\r\n const range = this.editor?.getSelectionRange();\r\n\r\n ctrlOrMeta = isCtrlOrMetaPressed(rawEvent);\r\n hasFunctionKey = ctrlOrMeta || rawEvent.altKey;\r\n features =\r\n this.state.features[rawEvent.which] ||\r\n (range && !range.collapsed && this.state.features[Keys.RANGE]);\r\n } else if (event.eventType == PluginEventType.ContentChanged) {\r\n features = this.state.features[Keys.CONTENTCHANGED];\r\n }\r\n\r\n for (let i = 0; features && i < features?.length; i++) {\r\n const feature = features[i];\r\n if (\r\n (feature.allowFunctionKeys || !hasFunctionKey) &&\r\n this.editor &&\r\n feature.shouldHandleEvent(event, this.editor, ctrlOrMeta)\r\n ) {\r\n feature.handleEvent(event, this.editor);\r\n if (isKeyDownEvent) {\r\n event.handledByEditFeature = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n * Create a new instance of EditPlugin.\r\n */\r\nexport function createEditPlugin(): PluginWithState<EditPluginState> {\r\n return new EditPlugin();\r\n}\r\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DarkColorHandler } from 'roosterjs-editor-types';
|
|
2
|
+
import type { DarkColorHandler as StandaloneDarkColorHandler } from 'roosterjs-content-model-types';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare function createDarkColorHandler(innerHandler: StandaloneDarkColorHandler): DarkColorHandler;
|