@alien6-studio/elea-content-editor 0.0.0-stage → 0.1.1
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 +202 -0
- package/README.md +220 -2
- package/dist/AddBlockButton.d.ts +16 -0
- package/dist/AddBlockButton.d.ts.map +1 -0
- package/dist/AddBlockButton.js +103 -0
- package/dist/AddBlockButton.js.map +1 -0
- package/dist/BlockEditor.d.ts +46 -0
- package/dist/BlockEditor.d.ts.map +1 -0
- package/dist/BlockEditor.js +397 -0
- package/dist/BlockEditor.js.map +1 -0
- package/dist/ContentEditor.d.ts +59 -0
- package/dist/ContentEditor.d.ts.map +1 -0
- package/dist/ContentEditor.js +460 -0
- package/dist/ContentEditor.js.map +1 -0
- package/dist/EditorPreview.d.ts +12 -0
- package/dist/EditorPreview.d.ts.map +1 -0
- package/dist/EditorPreview.js +10 -0
- package/dist/EditorPreview.js.map +1 -0
- package/dist/MarkdownEditor.d.ts +14 -0
- package/dist/MarkdownEditor.d.ts.map +1 -0
- package/dist/MarkdownEditor.js +30 -0
- package/dist/MarkdownEditor.js.map +1 -0
- package/dist/QuickAddButtons.d.ts +10 -0
- package/dist/QuickAddButtons.d.ts.map +1 -0
- package/dist/QuickAddButtons.js +19 -0
- package/dist/QuickAddButtons.js.map +1 -0
- package/dist/RichTextField.d.ts +72 -0
- package/dist/RichTextField.d.ts.map +1 -0
- package/dist/RichTextField.js +1008 -0
- package/dist/RichTextField.js.map +1 -0
- package/dist/RichTextInput.d.ts +12 -0
- package/dist/RichTextInput.d.ts.map +1 -0
- package/dist/RichTextInput.js +148 -0
- package/dist/RichTextInput.js.map +1 -0
- package/dist/SlashMenu.d.ts +27 -0
- package/dist/SlashMenu.d.ts.map +1 -0
- package/dist/SlashMenu.js +59 -0
- package/dist/SlashMenu.js.map +1 -0
- package/dist/Toolbar.d.ts +15 -0
- package/dist/Toolbar.d.ts.map +1 -0
- package/dist/Toolbar.js +27 -0
- package/dist/Toolbar.js.map +1 -0
- package/dist/VirtualizedBlockList.d.ts +40 -0
- package/dist/VirtualizedBlockList.d.ts.map +1 -0
- package/dist/VirtualizedBlockList.js +51 -0
- package/dist/VirtualizedBlockList.js.map +1 -0
- package/dist/blockPaste.d.ts +17 -0
- package/dist/blockPaste.d.ts.map +1 -0
- package/dist/blockPaste.js +50 -0
- package/dist/blockPaste.js.map +1 -0
- package/dist/blocks/AttachmentBlock.d.ts +3 -0
- package/dist/blocks/AttachmentBlock.d.ts.map +1 -0
- package/dist/blocks/AttachmentBlock.js +55 -0
- package/dist/blocks/AttachmentBlock.js.map +1 -0
- package/dist/blocks/ImageBlock.d.ts +14 -0
- package/dist/blocks/ImageBlock.d.ts.map +1 -0
- package/dist/blocks/ImageBlock.js +153 -0
- package/dist/blocks/ImageBlock.js.map +1 -0
- package/dist/blocks/MediaActions.d.ts +15 -0
- package/dist/blocks/MediaActions.d.ts.map +1 -0
- package/dist/blocks/MediaActions.js +7 -0
- package/dist/blocks/MediaActions.js.map +1 -0
- package/dist/blocks/VideoBlock.d.ts +3 -0
- package/dist/blocks/VideoBlock.d.ts.map +1 -0
- package/dist/blocks/VideoBlock.js +47 -0
- package/dist/blocks/VideoBlock.js.map +1 -0
- package/dist/blocks/cropper.d.ts +16 -0
- package/dist/blocks/cropper.d.ts.map +1 -0
- package/dist/blocks/cropper.js +28 -0
- package/dist/blocks/cropper.js.map +1 -0
- package/dist/bundle.css +7 -0
- package/dist/caret.d.ts +13 -0
- package/dist/caret.d.ts.map +1 -0
- package/dist/caret.js +52 -0
- package/dist/caret.js.map +1 -0
- package/dist/clipboardHtml.d.ts +4 -0
- package/dist/clipboardHtml.d.ts.map +1 -0
- package/dist/clipboardHtml.js +18 -0
- package/dist/clipboardHtml.js.map +1 -0
- package/dist/editorChrome.d.ts +53 -0
- package/dist/editorChrome.d.ts.map +1 -0
- package/dist/editorChrome.js +35 -0
- package/dist/editorChrome.js.map +1 -0
- package/dist/hooks/useBlockDrag.d.ts +26 -0
- package/dist/hooks/useBlockDrag.d.ts.map +1 -0
- package/dist/hooks/useBlockDrag.js +57 -0
- package/dist/hooks/useBlockDrag.js.map +1 -0
- package/dist/hooks/useBlockFocus.d.ts +13 -0
- package/dist/hooks/useBlockFocus.d.ts.map +1 -0
- package/dist/hooks/useBlockFocus.js +95 -0
- package/dist/hooks/useBlockFocus.js.map +1 -0
- package/dist/hooks/useBlockManagement.d.ts +27 -0
- package/dist/hooks/useBlockManagement.d.ts.map +1 -0
- package/dist/hooks/useBlockManagement.js +120 -0
- package/dist/hooks/useBlockManagement.js.map +1 -0
- package/dist/hooks/useBlockSelection.d.ts +30 -0
- package/dist/hooks/useBlockSelection.d.ts.map +1 -0
- package/dist/hooks/useBlockSelection.js +166 -0
- package/dist/hooks/useBlockSelection.js.map +1 -0
- package/dist/hooks/useBlockVisibility.d.ts +10 -0
- package/dist/hooks/useBlockVisibility.d.ts.map +1 -0
- package/dist/hooks/useBlockVisibility.js +48 -0
- package/dist/hooks/useBlockVisibility.js.map +1 -0
- package/dist/hooks/useDocumentHistory.d.ts +29 -0
- package/dist/hooks/useDocumentHistory.d.ts.map +1 -0
- package/dist/hooks/useDocumentHistory.js +75 -0
- package/dist/hooks/useDocumentHistory.js.map +1 -0
- package/dist/hooks/useTextareaResize.d.ts +6 -0
- package/dist/hooks/useTextareaResize.d.ts.map +1 -0
- package/dist/hooks/useTextareaResize.js +30 -0
- package/dist/hooks/useTextareaResize.js.map +1 -0
- package/dist/icons.d.ts +29 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +38 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/listCommands.d.ts +11 -0
- package/dist/listCommands.d.ts.map +1 -0
- package/dist/listCommands.js +190 -0
- package/dist/listCommands.js.map +1 -0
- package/dist/listHtml.d.ts +20 -0
- package/dist/listHtml.d.ts.map +1 -0
- package/dist/listHtml.js +108 -0
- package/dist/listHtml.js.map +1 -0
- package/dist/markdownSource.d.ts +40 -0
- package/dist/markdownSource.d.ts.map +1 -0
- package/dist/markdownSource.js +205 -0
- package/dist/markdownSource.js.map +1 -0
- package/dist/parts.d.ts +34 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +68 -0
- package/dist/parts.js.map +1 -0
- package/dist/paste.d.ts +21 -0
- package/dist/paste.d.ts.map +1 -0
- package/dist/paste.js +273 -0
- package/dist/paste.js.map +1 -0
- package/dist/provider.d.ts +84 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +16 -0
- package/dist/provider.js.map +1 -0
- package/dist/selection.d.ts +17 -0
- package/dist/selection.d.ts.map +1 -0
- package/dist/selection.js +88 -0
- package/dist/selection.js.map +1 -0
- package/dist/styles.css +668 -0
- package/package.json +64 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,221 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @alien6-studio/elea-content-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The React block editor of Elea: paragraphs with rich text, headings, lists, quotes, images,
|
|
4
|
+
videos and attachments, a preview through the viewer, and virtualization for long documents.
|
|
5
|
+
Every host-specific service is injected; the editor itself knows nothing about where images go
|
|
6
|
+
or where attachments come from.
|
|
7
|
+
|
|
8
|
+
## Use
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
"use client";
|
|
12
|
+
import { ContentEditor, ContentProvider } from "@alien6-studio/elea-content-editor";
|
|
13
|
+
import { fr } from "@alien6-studio/elea-content";
|
|
14
|
+
import "@alien6-studio/elea-content-editor/bundle.css";
|
|
15
|
+
|
|
16
|
+
<ContentProvider
|
|
17
|
+
messages={fr}
|
|
18
|
+
siteHostnames={["members.example.org"]}
|
|
19
|
+
resolveAssetUrl={(file) => file.id ? `/assets/${file.id}` : file.url}
|
|
20
|
+
uploadImage={async (file, context) => api.upload(file, context.kind)}
|
|
21
|
+
renderAttachmentPicker={({ onSelect, context }) => <MyLibrary ownerId={context.ownerId} onPick={onSelect} />}
|
|
22
|
+
>
|
|
23
|
+
<ContentEditor key={articleId} blocks={blocks} onBlocksChange={setBlocks} title={title} onTitleChange={setTitle} context={{ kind: "article", ownerId }} />
|
|
24
|
+
</ContentProvider>;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Give the editor a `key` that names the document it edits. Its undo history belongs to one
|
|
28
|
+
document: without the key, an editor that stays mounted while the host moves to another article
|
|
29
|
+
would undo into what the previous one held.
|
|
30
|
+
|
|
31
|
+
`bundle.css` loads the tokens, viewer styles, media styles and crop adjustments, UI styles,
|
|
32
|
+
then the editor styles. When importing styles individually, include
|
|
33
|
+
`@alien6-studio/elea-media/crop-adjustments.css` for the movable crop area.
|
|
34
|
+
Every rule sits in a cascade layer. A host rule outside any layer overrides it.
|
|
35
|
+
With Tailwind v4, declare
|
|
36
|
+
`@layer theme, base, elea, components, utilities;` before its imports.
|
|
37
|
+
|
|
38
|
+
The slash menu, the selection bubble and the link field are rendered at the end of the body. They
|
|
39
|
+
copy the `data-elea-theme` and the `data-elea-motion` of the container the editor is in, so a
|
|
40
|
+
theme set on that container reaches them.
|
|
41
|
+
|
|
42
|
+
`blocks` is the controlled block array. Use `createDocument(blocks)` to create a
|
|
43
|
+
document in Elea's schema, or use the host's save adapter for existing records.
|
|
44
|
+
`showPreview` renders the blocks with the viewer. Pass the same `siteHostnames`
|
|
45
|
+
to the provider and the viewer to keep the default link policy consistent, and the `renderers`
|
|
46
|
+
the published page gives to `ContentView`, so a block of your own previews as it will be read.
|
|
47
|
+
|
|
48
|
+
## Jest in Next.js
|
|
49
|
+
|
|
50
|
+
This package ships ES modules only. For Jest with `next/jest`, include the editor and the Elea packages it loads in your Next.js config. Browser tests can use the viewer’s [Jest setup for the sanitizer](../content-viewer/README.md#jest-in-nextjs).
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
// next.config.mjs
|
|
54
|
+
export default {
|
|
55
|
+
transpilePackages: [
|
|
56
|
+
"@alien6-studio/elea-content-editor",
|
|
57
|
+
"@alien6-studio/elea-content-viewer",
|
|
58
|
+
"@alien6-studio/elea-content",
|
|
59
|
+
"@alien6-studio/elea-media",
|
|
60
|
+
"@alien6-studio/elea-ui",
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Writing modes
|
|
66
|
+
|
|
67
|
+
Use `mode="default"` for writing with margin controls and a floating formatting bar,
|
|
68
|
+
`mode="toolbar"` to add a fixed toolbar, or `mode="classic"` for a continuous visual document
|
|
69
|
+
with its own scrollable canvas and a formatting toolbar across the top. `mode="markdown"` opens a source area with line numbers and updates the
|
|
70
|
+
same block document as you type. Pass `onModeChange` and the current `mode` to enable the pencil menu.
|
|
71
|
+
The pencil selects the writing mode. The adjacent buttons undo and redo edits. A host with its own
|
|
72
|
+
version history can place its actions here with `historyControls` and retain draft shortcuts with
|
|
73
|
+
`history="keyboard"`. In Toolbar mode, choose a block type directly from the **Insert** group.
|
|
74
|
+
It goes after the focused block, or at the end if no block has focus. Writing and Classic offer the + menu.
|
|
75
|
+
With mode switching enabled, adding a block from Markdown opens the visual editor for that block.
|
|
76
|
+
|
|
77
|
+
In paragraph text, Enter inserts a visible line break. A second Enter on the empty line
|
|
78
|
+
starts a new paragraph. In lists, Enter continues the list.
|
|
79
|
+
|
|
80
|
+
In the visual modes, Shift-click to select a range of blocks. Ctrl-click (Command-click on Mac)
|
|
81
|
+
adds or removes individual blocks. Copy and paste the selection in place to duplicate it, or
|
|
82
|
+
click a destination before pasting. Pasting on a picture inserts the copied blocks after it.
|
|
83
|
+
|
|
84
|
+
Markdown shows images with image syntax and uses ordinary links for videos and files with
|
|
85
|
+
URLs. The editor keeps the original block data alongside the source while editing. This
|
|
86
|
+
preserves media identifiers, list styles and extension data when you edit surrounding text.
|
|
87
|
+
Use a visual mode for settings that Markdown cannot express.
|
|
88
|
+
|
|
89
|
+
For images, insert an image block in a visual mode or open **Add an image** in Markdown.
|
|
90
|
+
Both paths accept a dropped file or a file from the picker and use the same cropper and host
|
|
91
|
+
upload service. Set `imageCrop` on the provider to customize the frame and export options.
|
|
92
|
+
|
|
93
|
+
To let authors move and resize the crop area, set `imageCrop={{ formats: true }}`.
|
|
94
|
+
The picker starts at the original ratio. This example opens it in portrait format.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
<ContentProvider messages={fr} uploadImage={uploadImage}
|
|
98
|
+
imageCrop={{ formats: { defaultValue: "portrait" } }}>
|
|
99
|
+
<ContentEditor blocks={blocks} onBlocksChange={setBlocks} />
|
|
100
|
+
</ContentProvider>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The available formats are `original`, `free`, `square`, `landscape`, `portrait` and `custom`.
|
|
104
|
+
For editable dimensions, use `imageCrop={{ formats: true, outputSize: { width: 1200, height: 800 } }}`.
|
|
105
|
+
This opens the custom format at 1200 × 800 pixels. Set `outputSize` alone for a fixed export size.
|
|
106
|
+
The picker loads on demand and uses `messages.cropFormats` from the editor’s English or French locale.
|
|
107
|
+
|
|
108
|
+
Supply `formats.presets` to offer your own publishing formats. A preset can specify an
|
|
109
|
+
exact export size or an aspect ratio that keeps the selected pixels at source resolution.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
const imageCrop: ImageCropOptions = {
|
|
113
|
+
formats: {
|
|
114
|
+
defaultValue: "cover",
|
|
115
|
+
presets: [
|
|
116
|
+
{ value: "cover", label: "Article cover", outputSize: { width: 1600, height: 900 } },
|
|
117
|
+
{ value: "portrait-card", label: "Portrait card", aspect: 4 / 5 },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
resolveOriginal: file => originals.get(file.id),
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
To offer **Adjust crop** on an existing image, have `resolveOriginal` return its source
|
|
125
|
+
file or a same-origin image URL and its saved `recipe`. In the example, `originals` is
|
|
126
|
+
a host-owned `Map<string, ImageCropSource>`. When `uploadImage` receives `options.crop`,
|
|
127
|
+
save it with the ID of the resulting asset. To support later sessions, store the original
|
|
128
|
+
in your media library and persist the recipe with it. Each edit exports from that original.
|
|
129
|
+
Cancelling keeps the current image. The document still stores its usual file reference.
|
|
130
|
+
|
|
131
|
+
An SVG file can carry scripts, which run when the file is opened as a page from the origin
|
|
132
|
+
that serves it. The editor therefore sends an SVG only as the raster picture the cropper
|
|
133
|
+
exports, and refuses one that would go up as picked. Set `allowSvgUpload` on the provider
|
|
134
|
+
when your upload service serves these files safely, from another origin or as downloads.
|
|
135
|
+
|
|
136
|
+
### Report what an upload is doing
|
|
137
|
+
|
|
138
|
+
`uploadImage` receives a third argument with `report` and `signal`. Each call to `report`
|
|
139
|
+
replaces the default "Uploading..." label, and a `progress` between 0 and 1 adds a bar. The
|
|
140
|
+
label is announced whenever it changes, so keep one label per phase and put the numbers in
|
|
141
|
+
`progress`. An `Error` you reject with shows its message beside the block; the generic
|
|
142
|
+
message stays the fallback for an empty one. `signal` aborts when the block is removed or its
|
|
143
|
+
picture changes before the upload settles.
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
const uploadImage: ContentEditorServices["uploadImage"] = async (file, context, { report, signal }) => {
|
|
147
|
+
report({ label: "Uploading", progress: 0 });
|
|
148
|
+
const upload = await api.upload(file, { signal, onProgress: (done) => report({ label: "Uploading", progress: done }) });
|
|
149
|
+
report({ label: "Scanning for viruses…" });
|
|
150
|
+
const scan = await api.scan(upload.id, { signal });
|
|
151
|
+
if (!scan.clean) throw new Error("This file did not pass the virus scan.");
|
|
152
|
+
return { id: upload.id, url: "" };
|
|
153
|
+
};
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Select text in a list to choose the marker for its list level and move the selected items
|
|
157
|
+
together with the indent and outdent buttons. Tab and Shift+Tab offer the same movement.
|
|
158
|
+
Outdenting first-level items turns them into paragraphs.
|
|
159
|
+
|
|
160
|
+
A checklist (`style: "checklist"`, as EditorJS writes it) opens with its boxes and keeps the
|
|
161
|
+
state of every task while its text is edited. Press a box, or Ctrl+Enter (Command+Enter on Mac)
|
|
162
|
+
in a task, to tick it; in Markdown a task is `- [x]` or `- [ ]`. Choosing a marker turns the
|
|
163
|
+
checklist into that list. The add menu does not offer a new checklist yet. Every task is saved
|
|
164
|
+
with its `items`, empty when it has no sub-task, as the EditorJS list tool reads them.
|
|
165
|
+
|
|
166
|
+
A heading is one line of rich text: its emphasis and links show as they read and are kept when
|
|
167
|
+
it is saved, and Enter starts a paragraph with what follows the caret. Its selector goes from H1
|
|
168
|
+
to H6 and shows the level the heading came with.
|
|
169
|
+
|
|
170
|
+
## What loads when
|
|
171
|
+
|
|
172
|
+
Three parts of the editor stay out of its first load and come the first time they are asked
|
|
173
|
+
for: the Markdown source area, the preview, and the cropper that frames a picked picture. A
|
|
174
|
+
bundler that splits on dynamic imports gives each one its own chunk; built with Vite, they weigh
|
|
175
|
+
about 2 KB gzip each, some 10% of the editor. Nothing changes in the host's code.
|
|
176
|
+
|
|
177
|
+
While a part is on its way the editor keeps what it shows and marks itself `aria-busy`: the
|
|
178
|
+
blocks stay until the source area or the preview is there, and the drop zone waits for the
|
|
179
|
+
cropper. A part that cannot load is reported through `reportError` and asked for again the next
|
|
180
|
+
time; a picture whose cropper cannot load goes up as picked.
|
|
181
|
+
|
|
182
|
+
A host that knows a part is about to be needed can ask for it ahead:
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { loadEditorParts } from "@alien6-studio/elea-content-editor";
|
|
186
|
+
|
|
187
|
+
<button onPointerEnter={() => void loadEditorParts("preview")} onClick={() => setPreview(true)}>Preview</button>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`loadEditorParts()` without a name loads all three. A page rendered on the server with
|
|
191
|
+
`mode="markdown"` or `showPreview` must await it before rendering, on the server and again in the
|
|
192
|
+
browser before hydrating, so that both sides show the same view.
|
|
193
|
+
|
|
194
|
+
Sanitizing and pasting stay in the first load: every stored value is sanitized as it renders, and
|
|
195
|
+
a paste has to be answered within its own event. To keep the whole editor off a page until
|
|
196
|
+
someone writes, load it from the host:
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
const ContentEditor = lazy(() => import("@alien6-studio/elea-content-editor").then((editor) => ({ default: editor.ContentEditor })));
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Pieces
|
|
203
|
+
|
|
204
|
+
- `ContentEditor`: title and summary fields, the block list, the add menu; `editors` and `blockTypes`
|
|
205
|
+
extend it with custom blocks.
|
|
206
|
+
- `RichTextField`: the contentEditable engine with its imperative handle (inline, list and block
|
|
207
|
+
formats, link prompt, clear), keyboard shortcuts, Enter and Backspace rules.
|
|
208
|
+
- `RichTextInput`: one field with bold, italic, underline and lists, with an optional length limit.
|
|
209
|
+
- `BlockEditor`, `Toolbar`, `AddBlockButton`, `QuickAddButtons`, `VirtualizedBlockList`, the
|
|
210
|
+
media blocks and the hooks, for hosts that compose their own layout.
|
|
211
|
+
|
|
212
|
+
## DOM contract
|
|
213
|
+
|
|
214
|
+
Each block renders with `data-elea-block-id` and `data-elea-block-type`; rich text fields are
|
|
215
|
+
`[contenteditable="true"]` with `role="textbox"`. Extensions and end-to-end tests can rely on
|
|
216
|
+
these, not on class names.
|
|
217
|
+
|
|
218
|
+
## Security
|
|
219
|
+
|
|
220
|
+
Stored HTML and rich paste pass through the provider's sanitizer. The default
|
|
221
|
+
link policy validates URLs and adds opener protection to external links.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EditorMode } from "./ContentEditor.js";
|
|
2
|
+
export interface AddBlockButtonProps {
|
|
3
|
+
onAdd: (type: string) => void;
|
|
4
|
+
types?: readonly string[] | undefined;
|
|
5
|
+
mode?: EditorMode | undefined;
|
|
6
|
+
onModeChange?: ((mode: EditorMode) => void) | undefined;
|
|
7
|
+
}
|
|
8
|
+
interface ModeButtonProps {
|
|
9
|
+
mode: EditorMode;
|
|
10
|
+
onModeChange: (mode: EditorMode) => void;
|
|
11
|
+
onAdd?: never;
|
|
12
|
+
types?: never;
|
|
13
|
+
}
|
|
14
|
+
export declare function AddBlockButton({ onAdd, types, mode, onModeChange }: AddBlockButtonProps | ModeButtonProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=AddBlockButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddBlockButton.d.ts","sourceRoot":"","sources":["../src/AddBlockButton.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKrD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACtC,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAC9B,YAAY,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACzD;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACzC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAID,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,mBAAmB,GAAG,eAAe,+BA8HzG"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { en } from "@alien6-studio/elea-content";
|
|
4
|
+
import { IconButton } from "@alien6-studio/elea-ui";
|
|
5
|
+
import { useId, useLayoutEffect, useRef, useState } from "react";
|
|
6
|
+
import { CheckIcon, CloseIcon, PencilIcon, PlusIcon } from "./icons.js";
|
|
7
|
+
import { useContentServices } from "./provider.js";
|
|
8
|
+
import { QuickAddButtons } from "./QuickAddButtons.js";
|
|
9
|
+
const modes = ["default", "toolbar", "classic", "markdown"];
|
|
10
|
+
export function AddBlockButton({ onAdd, types, mode, onModeChange }) {
|
|
11
|
+
const { messages } = useContentServices();
|
|
12
|
+
const labels = messages.source ?? en.source;
|
|
13
|
+
const modeLabel = (value) => value === "default" ? labels.writing : labels[value];
|
|
14
|
+
const withModes = mode !== undefined && onModeChange !== undefined;
|
|
15
|
+
// Keep a visited menu mounted so its surface can fold back into the trigger.
|
|
16
|
+
const [open, setOpen] = useState(null);
|
|
17
|
+
const root = useRef(null);
|
|
18
|
+
const trigger = useRef(null);
|
|
19
|
+
const menu = useRef(null);
|
|
20
|
+
const id = useId();
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
const container = root.current;
|
|
23
|
+
const panel = menu.current;
|
|
24
|
+
const button = trigger.current;
|
|
25
|
+
if (!open || !container || !panel || !button)
|
|
26
|
+
return;
|
|
27
|
+
const position = () => {
|
|
28
|
+
const rect = button.getBoundingClientRect();
|
|
29
|
+
const edge = (button.closest(".elea-content-editor") ?? document.documentElement).getBoundingClientRect();
|
|
30
|
+
const right = edge.right - rect.left - 8;
|
|
31
|
+
const left = rect.right - edge.left - 8;
|
|
32
|
+
const below = window.innerHeight - rect.top - 8;
|
|
33
|
+
const above = rect.bottom - 8;
|
|
34
|
+
container.toggleAttribute("data-left", left > right);
|
|
35
|
+
container.style.setProperty("--elea-menu-room", `${Math.max(left, right)}px`);
|
|
36
|
+
const height = panel.offsetHeight;
|
|
37
|
+
container.toggleAttribute("data-above", height > below && above > below);
|
|
38
|
+
};
|
|
39
|
+
const dismiss = (event) => {
|
|
40
|
+
if (!container.contains(event.target))
|
|
41
|
+
setOpen(false);
|
|
42
|
+
};
|
|
43
|
+
position();
|
|
44
|
+
const observer = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(position);
|
|
45
|
+
observer?.observe(panel);
|
|
46
|
+
const choice = panel.querySelector('[aria-checked="true"]') ?? panel.querySelector("button");
|
|
47
|
+
choice?.focus({ preventScroll: panel.scrollWidth <= panel.clientWidth });
|
|
48
|
+
document.addEventListener("pointerdown", dismiss);
|
|
49
|
+
window.addEventListener("resize", position);
|
|
50
|
+
window.addEventListener("scroll", position, true);
|
|
51
|
+
return () => {
|
|
52
|
+
observer?.disconnect();
|
|
53
|
+
document.removeEventListener("pointerdown", dismiss);
|
|
54
|
+
window.removeEventListener("resize", position);
|
|
55
|
+
window.removeEventListener("scroll", position, true);
|
|
56
|
+
};
|
|
57
|
+
}, [open]);
|
|
58
|
+
function close() {
|
|
59
|
+
trigger.current?.focus({ preventScroll: true });
|
|
60
|
+
setOpen(false);
|
|
61
|
+
}
|
|
62
|
+
function navigate(event) {
|
|
63
|
+
if (event.key === "Escape" && open) {
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
event.stopPropagation();
|
|
66
|
+
close();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (event.key === "Tab" && open) {
|
|
70
|
+
close();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const first = event.key === "Home";
|
|
74
|
+
const last = event.key === "End";
|
|
75
|
+
const forward = event.key === "ArrowDown" || event.key === "ArrowRight";
|
|
76
|
+
const backward = event.key === "ArrowUp" || event.key === "ArrowLeft";
|
|
77
|
+
if (!first && !last && !forward && !backward)
|
|
78
|
+
return;
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
if (!open) {
|
|
81
|
+
setOpen(true);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const items = Array.from(menu.current?.querySelectorAll("button") ?? []);
|
|
85
|
+
if (!items.length)
|
|
86
|
+
return;
|
|
87
|
+
const current = items.indexOf(document.activeElement);
|
|
88
|
+
let next = (current + (forward ? 1 : -1) + items.length) % items.length;
|
|
89
|
+
if (last)
|
|
90
|
+
next = items.length - 1;
|
|
91
|
+
if (first)
|
|
92
|
+
next = 0;
|
|
93
|
+
items[next]?.focus();
|
|
94
|
+
}
|
|
95
|
+
let triggerIcon = _jsx(PlusIcon, {});
|
|
96
|
+
if (withModes)
|
|
97
|
+
triggerIcon = _jsx(PencilIcon, {});
|
|
98
|
+
if (open)
|
|
99
|
+
triggerIcon = _jsx(CloseIcon, {});
|
|
100
|
+
return (_jsxs("div", { ref: root, className: "elea-add-block", "data-mode-picker": withModes ? "" : undefined, "data-open": open ?? undefined, onKeyDown: navigate, onBlur: (event) => { if (open && !event.currentTarget.contains(event.relatedTarget))
|
|
101
|
+
setOpen(false); }, children: [_jsx("span", { "aria-hidden": "true", className: "elea-add-block__surface" }), open !== null && (_jsxs("svg", { className: "elea-add-block__drops", viewBox: "0 0 104 44", "aria-hidden": "true", focusable: "false", children: [_jsx("defs", { children: _jsxs("filter", { id: `${id}-neck`, filterUnits: "userSpaceOnUse", x: "-6", y: "-6", width: "116", height: "56", children: [_jsx("feGaussianBlur", { stdDeviation: "3.2" }), _jsx("feColorMatrix", { type: "matrix", values: "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -8" })] }) }), _jsxs("g", { fill: "currentColor", filter: `url(#${id}-neck)`, children: [_jsx("circle", { cx: "22", cy: "22", r: "22" }), _jsx("circle", { className: "elea-add-block__drop", cx: "22", cy: "22", r: "22" })] })] })), _jsx(IconButton, { ref: trigger, variant: "disc", className: "elea-add-block__trigger", onClick: () => setOpen(!open), label: withModes ? `${labels.mode} · ${modeLabel(mode)}` : messages.actions.addBlock, "aria-haspopup": "menu", "aria-controls": open === null ? undefined : id, "aria-expanded": !!open, children: triggerIcon }), open !== null && (_jsx("div", { ref: menu, id: id, role: "menu", "aria-orientation": "horizontal", className: "elea-add-block__menu", "aria-label": withModes ? labels.mode : messages.actions.blockTypesMenu, inert: !open, "aria-hidden": !open, children: withModes ? modes.map((value) => (_jsxs("button", { type: "button", tabIndex: -1, role: "menuitemradio", "aria-checked": mode === value, onClick: () => { close(); onModeChange(value); }, children: [modeLabel(value), mode === value && _jsx(CheckIcon, {})] }, value))) : onAdd && (_jsx(QuickAddButtons, { types: types, onAdd: (type) => { close(); onAdd(type); } })) }))] }));
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=AddBlockButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddBlockButton.js","sourceRoot":"","sources":["../src/AddBlockButton.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,EAAE,EAAE,MAAM,6BAA6B,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAgBvD,MAAM,KAAK,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AAErE,MAAM,UAAU,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAyC;IACxG,MAAM,EAAE,QAAQ,EAAE,GAAG,kBAAkB,EAAE,CAAC;IAC1C,MAA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,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,mBAAiB,CAAC,CAAC,IAAI,YACxF,WAAW,GACD,EACZ,IAAI,KAAK,IAAI,IAAI,CAChB,cAAK,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAC,MAAM,sBAAkB,YAAY,EAAC,SAAS,EAAC,sBAAsB,gBACpF,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,KAAK,EAAE,CAAC,IAAI,iBAAe,CAAC,IAAI,YACtG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAChC,kBAAoB,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAC,eAAe,kBAAe,IAAI,KAAK,KAAK,EAC/F,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,aAC/C,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,KAAK,KAAK,IAAI,KAAC,SAAS,KAAG,KAFvC,KAAK,CAGT,CACV,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CACZ,KAAC,eAAe,IAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAI,CAC9E,GACG,CACP,IACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type BlockData, type BlockLike, type EleaBlock } from "@alien6-studio/elea-content";
|
|
2
|
+
import { type ComponentType, type FocusEvent } from "react";
|
|
3
|
+
import { type ListCommand } from "./listCommands.js";
|
|
4
|
+
import { type MediaBlockProps } from "./blocks/ImageBlock.js";
|
|
5
|
+
import { type EditorContextInfo } from "./provider.js";
|
|
6
|
+
import { type ActiveFormats, type RichTextFieldHandle } from "./RichTextField.js";
|
|
7
|
+
export type BlockEditorComponent = ComponentType<MediaBlockProps>;
|
|
8
|
+
export type BlockEditorMap = Readonly<Record<string, BlockEditorComponent>>;
|
|
9
|
+
export interface BlockEditorProps {
|
|
10
|
+
block: EleaBlock;
|
|
11
|
+
isFocused: boolean;
|
|
12
|
+
/** Part of a multi-block selection. */
|
|
13
|
+
isSelected?: boolean | undefined;
|
|
14
|
+
onFocus: () => void;
|
|
15
|
+
onBlur: (event?: FocusEvent) => void;
|
|
16
|
+
onUpdate: (data: BlockData) => void;
|
|
17
|
+
onRemove: () => void;
|
|
18
|
+
/** A new block of a type goes right after this one, with text carried over from a split. */
|
|
19
|
+
onAddBlockAfter?: ((type: string, initialText?: string) => void) | undefined;
|
|
20
|
+
/** Pasted blocks go right after this one, then a paragraph with the text that followed the caret. */
|
|
21
|
+
onInsertBlocksAfter?: ((blocks: BlockLike[], after: string) => void) | undefined;
|
|
22
|
+
/** The caret leaves this block upwards or downwards. */
|
|
23
|
+
onNavigate?: ((direction: "up" | "down") => void) | undefined;
|
|
24
|
+
/** Backspace at the start of this block: its text (if any) joins the previous block. */
|
|
25
|
+
onMergeBackward?: ((html: string) => void) | undefined;
|
|
26
|
+
/** Delete at the end of this block: the next block joins it. */
|
|
27
|
+
onMergeForward?: (() => void) | undefined;
|
|
28
|
+
/** This block becomes another type (typing shortcut, slash menu), with the given data. */
|
|
29
|
+
onConvert?: ((type: string, data?: Record<string, unknown>) => void) | undefined;
|
|
30
|
+
/** This block gives way to several, the one at `focus` taking the caret at its start or end. */
|
|
31
|
+
onReplaceWith?: ((blocks: BlockLike[], focus: number, position?: "start" | "end") => void) | undefined;
|
|
32
|
+
/** Block types offered by the slash menu. */
|
|
33
|
+
blockTypes?: readonly string[] | undefined;
|
|
34
|
+
/** Props of the drag grip; absent means the block cannot be dragged. */
|
|
35
|
+
dragHandleProps?: React.HTMLAttributes<HTMLElement> | undefined;
|
|
36
|
+
context?: EditorContextInfo | undefined;
|
|
37
|
+
/** Editing components by block type, for custom blocks; built-in types have their own. */
|
|
38
|
+
editors?: BlockEditorMap | undefined;
|
|
39
|
+
/** `default`: margin controls and a floating bar; `toolbar`: a fixed bar above the document too; `classic`: the fixed bar only, nothing around the block. */
|
|
40
|
+
mode?: "default" | "toolbar" | "classic" | undefined;
|
|
41
|
+
/** Reports the focused rich text field and its commands to the document toolbar. */
|
|
42
|
+
onActiveField?: ((handle: RichTextFieldHandle | null, formats: ActiveFormats, listCommand?: (command: ListCommand) => void) => void) | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** One block with its delete button, type indicator, toolbar when it is a focused paragraph, and editing field. */
|
|
45
|
+
export declare const BlockEditor: import("react").MemoExoticComponent<({ block, isFocused, isSelected, onFocus, onBlur, onUpdate, onRemove, onAddBlockAfter, onInsertBlocksAfter, onNavigate, onMergeBackward, onMergeForward, onConvert, onReplaceWith, blockTypes, dragHandleProps, context, editors, mode, onActiveField }: BlockEditorProps) => import("react").JSX.Element>;
|
|
46
|
+
//# sourceMappingURL=BlockEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockEditor.d.ts","sourceRoot":"","sources":["../src/BlockEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA6D,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAiE,MAAM,6BAA6B,CAAC;AACvN,OAAO,EAAuE,KAAK,aAAa,EAAE,KAAK,UAAU,EAA2D,MAAM,OAAO,CAAC;AAG1L,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAItG,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI1E,OAAO,EAAsB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAgC,KA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