@editora/plugins 1.1.0 → 1.2.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/index.d.ts CHANGED
@@ -1116,7 +1116,69 @@ export function getTemplateCategories(): string[];
1116
1116
  export function searchTemplates(query: string): Template[];
1117
1117
  export function sanitizeTemplate(html: string): string;
1118
1118
  export function validateTemplate(template: Template): boolean;
1119
- export function CommentsPlugin(): Plugin;
1119
+ export interface CommentUser {
1120
+ /** Your own id for the person. When it is set on both the user and a comment's author, only that person can edit or delete the comment. */
1121
+ id?: string;
1122
+ name: string;
1123
+ /** URL of a picture (http, https, a data:image URL or a path on the page). Without one, or if it fails to load, the initials are shown. */
1124
+ avatar?: string;
1125
+ }
1126
+ export interface CommentReplyData {
1127
+ id: string;
1128
+ author: CommentUser;
1129
+ text: string;
1130
+ createdAt: string;
1131
+ editedAt?: string;
1132
+ }
1133
+ /** One discussion. Store it as it is and give it back with `setCommentThreads` or `initialThreads`. */
1134
+ export interface CommentThread {
1135
+ id: string;
1136
+ /** The `id` of the highlighted span in the document. Missing for a note about the whole document. */
1137
+ anchorId?: string;
1138
+ /** The text that was selected when the thread was started. */
1139
+ quote?: string;
1140
+ author: CommentUser;
1141
+ text: string;
1142
+ createdAt: string;
1143
+ editedAt?: string;
1144
+ resolved: boolean;
1145
+ resolvedAt?: string;
1146
+ resolvedBy?: CommentUser;
1147
+ replies: CommentReplyData[];
1148
+ }
1149
+ export type CommentsChangeReason = 'create' | 'reply' | 'edit' | 'resolve' | 'reopen' | 'delete' | 'document';
1150
+ export interface CommentsChange {
1151
+ reason: CommentsChangeReason;
1152
+ threadId?: string;
1153
+ }
1154
+ export interface CommentsOptions {
1155
+ /** Who is commenting. New comments, replies and resolutions are signed with this. Default: `{ name: 'User' }`. */
1156
+ currentUser?: CommentUser | string;
1157
+ /** Threads to show when the editor starts, for example the ones you saved with the document. */
1158
+ initialThreads?: CommentThread[];
1159
+ /**
1160
+ * Keep the comments in the browser's localStorage under this key: they are saved after every change and loaded
1161
+ * when the editor starts (they win over `initialThreads` when something is stored). The key must be yours alone,
1162
+ * one per document: editors that share a key share their comments. Only the comments are kept: save the
1163
+ * document's HTML as well (for example with the editor's `autosave`), or the highlights they belong to are gone.
1164
+ */
1165
+ storageKey?: string;
1166
+ /** Called after every change to the comments, with all of them. Store them here. */
1167
+ onChange?: (threads: CommentThread[], change: CommentsChange) => void;
1168
+ /** Whether `user` may edit or delete something `author` wrote. By default people can change their own comments when both have an id, and anyone can change anything when there are no ids. */
1169
+ canModify?: (author: CommentUser, user: CommentUser) => boolean;
1170
+ }
1171
+ export function CommentsPlugin(options?: CommentsOptions): Plugin;
1172
+ /** The comments of one editor as plain data to store. `target` is the editor element or anything inside it. */
1173
+ export function getCommentThreads(target: Element): CommentThread[];
1174
+ /** Show these threads in an editor in place of the ones it has. Does not call `onChange`. */
1175
+ export function setCommentThreads(target: Element, threads: CommentThread[]): void;
1176
+ /** Add or replace a single thread that arrived while the editor is open, without disturbing what the person is typing. Returns false when `thread` cannot be used. Does not call `onChange`. */
1177
+ export function upsertCommentThread(target: Element, thread: CommentThread): boolean;
1178
+ /** Take away a single thread that was deleted elsewhere. Returns false when the editor has no such thread. Does not call `onChange`. */
1179
+ export function removeCommentThread(target: Element, threadId: string): boolean;
1180
+ /** Give an editor the options `CommentsPlugin(options)` takes, when the plugin cannot know which editor is its own. */
1181
+ export function configureComments(target: Element, options: CommentsOptions): void;
1120
1182
  export function SpellCheckPlugin(): Plugin;
1121
1183
  export function A11yCheckerPlugin(): Plugin;
1122
1184
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@editora/plugins",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Enterprise plugin suite for Editora rich text editor in React and web apps, including tables, media, workflow, and compliance tooling.",
5
5
  "author": "Ajay Kumar <ajaykr089@gmail.com>",
6
6
  "license": "MIT",