@tiptap/extension-collaboration-caret 3.20.3 → 3.20.4
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/dist/index.cjs +120 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/package.json +13 -13
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CollaborationCaret: () => CollaborationCaret,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/collaboration-caret.ts
|
|
29
|
+
var import_core = require("@tiptap/core");
|
|
30
|
+
var import_y_tiptap = require("@tiptap/y-tiptap");
|
|
31
|
+
var awarenessStatesToArray = (states) => {
|
|
32
|
+
return Array.from(states.entries()).map(([key, value]) => {
|
|
33
|
+
return {
|
|
34
|
+
clientId: key,
|
|
35
|
+
...value.user
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var defaultOnUpdate = () => null;
|
|
40
|
+
var CollaborationCaret = import_core.Extension.create({
|
|
41
|
+
name: "collaborationCaret",
|
|
42
|
+
priority: 999,
|
|
43
|
+
addOptions() {
|
|
44
|
+
return {
|
|
45
|
+
provider: null,
|
|
46
|
+
user: {
|
|
47
|
+
name: null,
|
|
48
|
+
color: null
|
|
49
|
+
},
|
|
50
|
+
render: (user) => {
|
|
51
|
+
const cursor = document.createElement("span");
|
|
52
|
+
cursor.classList.add("collaboration-carets__caret");
|
|
53
|
+
cursor.setAttribute("style", `border-color: ${user.color}`);
|
|
54
|
+
const label = document.createElement("div");
|
|
55
|
+
label.classList.add("collaboration-carets__label");
|
|
56
|
+
label.setAttribute("style", `background-color: ${user.color}`);
|
|
57
|
+
label.insertBefore(document.createTextNode(user.name), null);
|
|
58
|
+
cursor.insertBefore(label, null);
|
|
59
|
+
return cursor;
|
|
60
|
+
},
|
|
61
|
+
selectionRender: import_y_tiptap.defaultSelectionBuilder,
|
|
62
|
+
onUpdate: defaultOnUpdate
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
onCreate() {
|
|
66
|
+
if (this.options.onUpdate !== defaultOnUpdate) {
|
|
67
|
+
console.warn(
|
|
68
|
+
'[tiptap warn]: DEPRECATED: The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (!this.options.provider) {
|
|
72
|
+
throw new Error('The "provider" option is required for the CollaborationCaret extension');
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
addStorage() {
|
|
76
|
+
return {
|
|
77
|
+
users: []
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
addCommands() {
|
|
81
|
+
return {
|
|
82
|
+
updateUser: (attributes) => () => {
|
|
83
|
+
this.options.provider.awareness.setLocalStateField("user", attributes);
|
|
84
|
+
return true;
|
|
85
|
+
},
|
|
86
|
+
user: (attributes) => ({ editor }) => {
|
|
87
|
+
console.warn(
|
|
88
|
+
'[tiptap warn]: DEPRECATED: The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'
|
|
89
|
+
);
|
|
90
|
+
return editor.commands.updateUser(attributes);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
addProseMirrorPlugins() {
|
|
95
|
+
return [
|
|
96
|
+
(0, import_y_tiptap.yCursorPlugin)(
|
|
97
|
+
(() => {
|
|
98
|
+
this.options.provider.awareness.setLocalStateField("user", this.options.user);
|
|
99
|
+
this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states);
|
|
100
|
+
this.options.provider.awareness.on("update", () => {
|
|
101
|
+
this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states);
|
|
102
|
+
});
|
|
103
|
+
return this.options.provider.awareness;
|
|
104
|
+
})(),
|
|
105
|
+
{
|
|
106
|
+
cursorBuilder: this.options.render,
|
|
107
|
+
selectionBuilder: this.options.selectionRender
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// src/index.ts
|
|
115
|
+
var index_default = CollaborationCaret;
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
CollaborationCaret
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/collaboration-caret.ts"],"sourcesContent":["import { CollaborationCaret } from './collaboration-caret.js'\n\nexport * from './collaboration-caret.js'\n\nexport default CollaborationCaret\n","import { Extension } from '@tiptap/core'\nimport type { DecorationAttrs } from '@tiptap/pm/view'\nimport { defaultSelectionBuilder, yCursorPlugin } from '@tiptap/y-tiptap'\n\ntype CollaborationCaretStorage = {\n users: { clientId: number; [key: string]: any }[]\n}\n\nexport interface CollaborationCaretOptions {\n /**\n * The Hocuspocus provider instance. This can also be a TiptapCloudProvider instance.\n * @type {HocuspocusProvider | TiptapCloudProvider}\n * @example new HocuspocusProvider()\n */\n provider: any\n\n /**\n * The user details object – feel free to add properties to this object as needed\n * @example { name: 'John Doe', color: '#305500' }\n */\n user: Record<string, any>\n\n /**\n * A function that returns a DOM element for the cursor.\n * @param user The user details object\n * @example\n * render: user => {\n * const cursor = document.createElement('span')\n * cursor.classList.add('collaboration-carets__caret')\n * cursor.setAttribute('style', `border-color: ${user.color}`)\n *\n * const label = document.createElement('div')\n * label.classList.add('collaboration-carets__label')\n * label.setAttribute('style', `background-color: ${user.color}`)\n * label.insertBefore(document.createTextNode(user.name), null)\n *\n * cursor.insertBefore(label, null)\n * return cursor\n * }\n */\n render(user: Record<string, any>): HTMLElement\n\n /**\n * A function that returns a ProseMirror DecorationAttrs object for the selection.\n * @param user The user details object\n * @example\n * selectionRender: user => {\n * return {\n * nodeName: 'span',\n * class: 'collaboration-carets__selection',\n * style: `background-color: ${user.color}`,\n * 'data-user': user.name,\n * }\n */\n selectionRender(user: Record<string, any>): DecorationAttrs\n\n /**\n * @deprecated The \"onUpdate\" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret\n */\n onUpdate: (users: { clientId: number; [key: string]: any }[]) => null\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n collaborationCaret: {\n /**\n * Update details of the current user\n * @example editor.commands.updateUser({ name: 'John Doe', color: '#305500' })\n */\n updateUser: (attributes: Record<string, any>) => ReturnType\n /**\n * Update details of the current user\n *\n * @deprecated The \"user\" command is deprecated. Please use \"updateUser\" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret\n */\n user: (attributes: Record<string, any>) => ReturnType\n }\n }\n\n interface Storage {\n collaborationCaret: CollaborationCaretStorage\n }\n}\n\nconst awarenessStatesToArray = (states: Map<number, Record<string, any>>) => {\n return Array.from(states.entries()).map(([key, value]) => {\n return {\n clientId: key,\n ...value.user,\n }\n })\n}\n\nconst defaultOnUpdate = () => null\n\n/**\n * This extension allows you to add collaboration carets to your editor.\n * @see https://tiptap.dev/api/extensions/collaboration-caret\n */\nexport const CollaborationCaret = Extension.create<CollaborationCaretOptions, CollaborationCaretStorage>({\n name: 'collaborationCaret',\n\n priority: 999,\n\n addOptions() {\n return {\n provider: null,\n user: {\n name: null,\n color: null,\n },\n render: user => {\n const cursor = document.createElement('span')\n\n cursor.classList.add('collaboration-carets__caret')\n cursor.setAttribute('style', `border-color: ${user.color}`)\n\n const label = document.createElement('div')\n\n label.classList.add('collaboration-carets__label')\n label.setAttribute('style', `background-color: ${user.color}`)\n label.insertBefore(document.createTextNode(user.name), null)\n cursor.insertBefore(label, null)\n\n return cursor\n },\n selectionRender: defaultSelectionBuilder,\n onUpdate: defaultOnUpdate,\n }\n },\n\n onCreate() {\n if (this.options.onUpdate !== defaultOnUpdate) {\n console.warn(\n '[tiptap warn]: DEPRECATED: The \"onUpdate\" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret',\n )\n }\n if (!this.options.provider) {\n throw new Error('The \"provider\" option is required for the CollaborationCaret extension')\n }\n },\n\n addStorage() {\n return {\n users: [],\n }\n },\n\n addCommands() {\n return {\n updateUser: attributes => () => {\n this.options.provider.awareness.setLocalStateField('user', attributes)\n return true\n },\n user:\n attributes =>\n ({ editor }) => {\n console.warn(\n '[tiptap warn]: DEPRECATED: The \"user\" command is deprecated. Please use \"updateUser\" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret',\n )\n\n return editor.commands.updateUser(attributes)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [\n yCursorPlugin(\n (() => {\n this.options.provider.awareness.setLocalStateField('user', this.options.user)\n\n this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states)\n\n this.options.provider.awareness.on('update', () => {\n this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states)\n })\n\n return this.options.provider.awareness\n })(),\n {\n cursorBuilder: this.options.render,\n selectionBuilder: this.options.selectionRender,\n },\n ),\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAE1B,sBAAuD;AAkFvD,IAAM,yBAAyB,CAAC,WAA6C;AAC3E,SAAO,MAAM,KAAK,OAAO,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACxD,WAAO;AAAA,MACL,UAAU;AAAA,MACV,GAAG,MAAM;AAAA,IACX;AAAA,EACF,CAAC;AACH;AAEA,IAAM,kBAAkB,MAAM;AAMvB,IAAM,qBAAqB,sBAAU,OAA6D;AAAA,EACvG,MAAM;AAAA,EAEN,UAAU;AAAA,EAEV,aAAa;AACX,WAAO;AAAA,MACL,UAAU;AAAA,MACV,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA,QAAQ,UAAQ;AACd,cAAM,SAAS,SAAS,cAAc,MAAM;AAE5C,eAAO,UAAU,IAAI,6BAA6B;AAClD,eAAO,aAAa,SAAS,iBAAiB,KAAK,KAAK,EAAE;AAE1D,cAAM,QAAQ,SAAS,cAAc,KAAK;AAE1C,cAAM,UAAU,IAAI,6BAA6B;AACjD,cAAM,aAAa,SAAS,qBAAqB,KAAK,KAAK,EAAE;AAC7D,cAAM,aAAa,SAAS,eAAe,KAAK,IAAI,GAAG,IAAI;AAC3D,eAAO,aAAa,OAAO,IAAI;AAE/B,eAAO;AAAA,MACT;AAAA,MACA,iBAAiB;AAAA,MACjB,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EAEA,WAAW;AACT,QAAI,KAAK,QAAQ,aAAa,iBAAiB;AAC7C,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AACA,QAAI,CAAC,KAAK,QAAQ,UAAU;AAC1B,YAAM,IAAI,MAAM,wEAAwE;AAAA,IAC1F;AAAA,EACF;AAAA,EAEA,aAAa;AACX,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,IACV;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,YAAY,gBAAc,MAAM;AAC9B,aAAK,QAAQ,SAAS,UAAU,mBAAmB,QAAQ,UAAU;AACrE,eAAO;AAAA,MACT;AAAA,MACA,MACE,gBACA,CAAC,EAAE,OAAO,MAAM;AACd,gBAAQ;AAAA,UACN;AAAA,QACF;AAEA,eAAO,OAAO,SAAS,WAAW,UAAU;AAAA,MAC9C;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,UACL;AAAA,SACG,MAAM;AACL,eAAK,QAAQ,SAAS,UAAU,mBAAmB,QAAQ,KAAK,QAAQ,IAAI;AAE5E,eAAK,QAAQ,QAAQ,uBAAuB,KAAK,QAAQ,SAAS,UAAU,MAAM;AAElF,eAAK,QAAQ,SAAS,UAAU,GAAG,UAAU,MAAM;AACjD,iBAAK,QAAQ,QAAQ,uBAAuB,KAAK,QAAQ,SAAS,UAAU,MAAM;AAAA,UACpF,CAAC;AAED,iBAAO,KAAK,QAAQ,SAAS;AAAA,QAC/B,GAAG;AAAA,QACH;AAAA,UACE,eAAe,KAAK,QAAQ;AAAA,UAC5B,kBAAkB,KAAK,QAAQ;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;ADvLD,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { DecorationAttrs } from '@tiptap/pm/view';
|
|
3
|
+
|
|
4
|
+
type CollaborationCaretStorage = {
|
|
5
|
+
users: {
|
|
6
|
+
clientId: number;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
interface CollaborationCaretOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The Hocuspocus provider instance. This can also be a TiptapCloudProvider instance.
|
|
13
|
+
* @type {HocuspocusProvider | TiptapCloudProvider}
|
|
14
|
+
* @example new HocuspocusProvider()
|
|
15
|
+
*/
|
|
16
|
+
provider: any;
|
|
17
|
+
/**
|
|
18
|
+
* The user details object – feel free to add properties to this object as needed
|
|
19
|
+
* @example { name: 'John Doe', color: '#305500' }
|
|
20
|
+
*/
|
|
21
|
+
user: Record<string, any>;
|
|
22
|
+
/**
|
|
23
|
+
* A function that returns a DOM element for the cursor.
|
|
24
|
+
* @param user The user details object
|
|
25
|
+
* @example
|
|
26
|
+
* render: user => {
|
|
27
|
+
* const cursor = document.createElement('span')
|
|
28
|
+
* cursor.classList.add('collaboration-carets__caret')
|
|
29
|
+
* cursor.setAttribute('style', `border-color: ${user.color}`)
|
|
30
|
+
*
|
|
31
|
+
* const label = document.createElement('div')
|
|
32
|
+
* label.classList.add('collaboration-carets__label')
|
|
33
|
+
* label.setAttribute('style', `background-color: ${user.color}`)
|
|
34
|
+
* label.insertBefore(document.createTextNode(user.name), null)
|
|
35
|
+
*
|
|
36
|
+
* cursor.insertBefore(label, null)
|
|
37
|
+
* return cursor
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
render(user: Record<string, any>): HTMLElement;
|
|
41
|
+
/**
|
|
42
|
+
* A function that returns a ProseMirror DecorationAttrs object for the selection.
|
|
43
|
+
* @param user The user details object
|
|
44
|
+
* @example
|
|
45
|
+
* selectionRender: user => {
|
|
46
|
+
* return {
|
|
47
|
+
* nodeName: 'span',
|
|
48
|
+
* class: 'collaboration-carets__selection',
|
|
49
|
+
* style: `background-color: ${user.color}`,
|
|
50
|
+
* 'data-user': user.name,
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
selectionRender(user: Record<string, any>): DecorationAttrs;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret
|
|
56
|
+
*/
|
|
57
|
+
onUpdate: (users: {
|
|
58
|
+
clientId: number;
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
}[]) => null;
|
|
61
|
+
}
|
|
62
|
+
declare module '@tiptap/core' {
|
|
63
|
+
interface Commands<ReturnType> {
|
|
64
|
+
collaborationCaret: {
|
|
65
|
+
/**
|
|
66
|
+
* Update details of the current user
|
|
67
|
+
* @example editor.commands.updateUser({ name: 'John Doe', color: '#305500' })
|
|
68
|
+
*/
|
|
69
|
+
updateUser: (attributes: Record<string, any>) => ReturnType;
|
|
70
|
+
/**
|
|
71
|
+
* Update details of the current user
|
|
72
|
+
*
|
|
73
|
+
* @deprecated The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret
|
|
74
|
+
*/
|
|
75
|
+
user: (attributes: Record<string, any>) => ReturnType;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
interface Storage {
|
|
79
|
+
collaborationCaret: CollaborationCaretStorage;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* This extension allows you to add collaboration carets to your editor.
|
|
84
|
+
* @see https://tiptap.dev/api/extensions/collaboration-caret
|
|
85
|
+
*/
|
|
86
|
+
declare const CollaborationCaret: Extension<CollaborationCaretOptions, CollaborationCaretStorage>;
|
|
87
|
+
|
|
88
|
+
export { CollaborationCaret, type CollaborationCaretOptions, CollaborationCaret as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { DecorationAttrs } from '@tiptap/pm/view';
|
|
3
|
+
|
|
4
|
+
type CollaborationCaretStorage = {
|
|
5
|
+
users: {
|
|
6
|
+
clientId: number;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
interface CollaborationCaretOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The Hocuspocus provider instance. This can also be a TiptapCloudProvider instance.
|
|
13
|
+
* @type {HocuspocusProvider | TiptapCloudProvider}
|
|
14
|
+
* @example new HocuspocusProvider()
|
|
15
|
+
*/
|
|
16
|
+
provider: any;
|
|
17
|
+
/**
|
|
18
|
+
* The user details object – feel free to add properties to this object as needed
|
|
19
|
+
* @example { name: 'John Doe', color: '#305500' }
|
|
20
|
+
*/
|
|
21
|
+
user: Record<string, any>;
|
|
22
|
+
/**
|
|
23
|
+
* A function that returns a DOM element for the cursor.
|
|
24
|
+
* @param user The user details object
|
|
25
|
+
* @example
|
|
26
|
+
* render: user => {
|
|
27
|
+
* const cursor = document.createElement('span')
|
|
28
|
+
* cursor.classList.add('collaboration-carets__caret')
|
|
29
|
+
* cursor.setAttribute('style', `border-color: ${user.color}`)
|
|
30
|
+
*
|
|
31
|
+
* const label = document.createElement('div')
|
|
32
|
+
* label.classList.add('collaboration-carets__label')
|
|
33
|
+
* label.setAttribute('style', `background-color: ${user.color}`)
|
|
34
|
+
* label.insertBefore(document.createTextNode(user.name), null)
|
|
35
|
+
*
|
|
36
|
+
* cursor.insertBefore(label, null)
|
|
37
|
+
* return cursor
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
render(user: Record<string, any>): HTMLElement;
|
|
41
|
+
/**
|
|
42
|
+
* A function that returns a ProseMirror DecorationAttrs object for the selection.
|
|
43
|
+
* @param user The user details object
|
|
44
|
+
* @example
|
|
45
|
+
* selectionRender: user => {
|
|
46
|
+
* return {
|
|
47
|
+
* nodeName: 'span',
|
|
48
|
+
* class: 'collaboration-carets__selection',
|
|
49
|
+
* style: `background-color: ${user.color}`,
|
|
50
|
+
* 'data-user': user.name,
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
selectionRender(user: Record<string, any>): DecorationAttrs;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret
|
|
56
|
+
*/
|
|
57
|
+
onUpdate: (users: {
|
|
58
|
+
clientId: number;
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
}[]) => null;
|
|
61
|
+
}
|
|
62
|
+
declare module '@tiptap/core' {
|
|
63
|
+
interface Commands<ReturnType> {
|
|
64
|
+
collaborationCaret: {
|
|
65
|
+
/**
|
|
66
|
+
* Update details of the current user
|
|
67
|
+
* @example editor.commands.updateUser({ name: 'John Doe', color: '#305500' })
|
|
68
|
+
*/
|
|
69
|
+
updateUser: (attributes: Record<string, any>) => ReturnType;
|
|
70
|
+
/**
|
|
71
|
+
* Update details of the current user
|
|
72
|
+
*
|
|
73
|
+
* @deprecated The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret
|
|
74
|
+
*/
|
|
75
|
+
user: (attributes: Record<string, any>) => ReturnType;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
interface Storage {
|
|
79
|
+
collaborationCaret: CollaborationCaretStorage;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* This extension allows you to add collaboration carets to your editor.
|
|
84
|
+
* @see https://tiptap.dev/api/extensions/collaboration-caret
|
|
85
|
+
*/
|
|
86
|
+
declare const CollaborationCaret: Extension<CollaborationCaretOptions, CollaborationCaretStorage>;
|
|
87
|
+
|
|
88
|
+
export { CollaborationCaret, type CollaborationCaretOptions, CollaborationCaret as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/collaboration-caret.ts
|
|
2
|
+
import { Extension } from "@tiptap/core";
|
|
3
|
+
import { defaultSelectionBuilder, yCursorPlugin } from "@tiptap/y-tiptap";
|
|
4
|
+
var awarenessStatesToArray = (states) => {
|
|
5
|
+
return Array.from(states.entries()).map(([key, value]) => {
|
|
6
|
+
return {
|
|
7
|
+
clientId: key,
|
|
8
|
+
...value.user
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var defaultOnUpdate = () => null;
|
|
13
|
+
var CollaborationCaret = Extension.create({
|
|
14
|
+
name: "collaborationCaret",
|
|
15
|
+
priority: 999,
|
|
16
|
+
addOptions() {
|
|
17
|
+
return {
|
|
18
|
+
provider: null,
|
|
19
|
+
user: {
|
|
20
|
+
name: null,
|
|
21
|
+
color: null
|
|
22
|
+
},
|
|
23
|
+
render: (user) => {
|
|
24
|
+
const cursor = document.createElement("span");
|
|
25
|
+
cursor.classList.add("collaboration-carets__caret");
|
|
26
|
+
cursor.setAttribute("style", `border-color: ${user.color}`);
|
|
27
|
+
const label = document.createElement("div");
|
|
28
|
+
label.classList.add("collaboration-carets__label");
|
|
29
|
+
label.setAttribute("style", `background-color: ${user.color}`);
|
|
30
|
+
label.insertBefore(document.createTextNode(user.name), null);
|
|
31
|
+
cursor.insertBefore(label, null);
|
|
32
|
+
return cursor;
|
|
33
|
+
},
|
|
34
|
+
selectionRender: defaultSelectionBuilder,
|
|
35
|
+
onUpdate: defaultOnUpdate
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
onCreate() {
|
|
39
|
+
if (this.options.onUpdate !== defaultOnUpdate) {
|
|
40
|
+
console.warn(
|
|
41
|
+
'[tiptap warn]: DEPRECATED: The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (!this.options.provider) {
|
|
45
|
+
throw new Error('The "provider" option is required for the CollaborationCaret extension');
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
addStorage() {
|
|
49
|
+
return {
|
|
50
|
+
users: []
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
addCommands() {
|
|
54
|
+
return {
|
|
55
|
+
updateUser: (attributes) => () => {
|
|
56
|
+
this.options.provider.awareness.setLocalStateField("user", attributes);
|
|
57
|
+
return true;
|
|
58
|
+
},
|
|
59
|
+
user: (attributes) => ({ editor }) => {
|
|
60
|
+
console.warn(
|
|
61
|
+
'[tiptap warn]: DEPRECATED: The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'
|
|
62
|
+
);
|
|
63
|
+
return editor.commands.updateUser(attributes);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
addProseMirrorPlugins() {
|
|
68
|
+
return [
|
|
69
|
+
yCursorPlugin(
|
|
70
|
+
(() => {
|
|
71
|
+
this.options.provider.awareness.setLocalStateField("user", this.options.user);
|
|
72
|
+
this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states);
|
|
73
|
+
this.options.provider.awareness.on("update", () => {
|
|
74
|
+
this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states);
|
|
75
|
+
});
|
|
76
|
+
return this.options.provider.awareness;
|
|
77
|
+
})(),
|
|
78
|
+
{
|
|
79
|
+
cursorBuilder: this.options.render,
|
|
80
|
+
selectionBuilder: this.options.selectionRender
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// src/index.ts
|
|
88
|
+
var index_default = CollaborationCaret;
|
|
89
|
+
export {
|
|
90
|
+
CollaborationCaret,
|
|
91
|
+
index_default as default
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/collaboration-caret.ts","../src/index.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { DecorationAttrs } from '@tiptap/pm/view'\nimport { defaultSelectionBuilder, yCursorPlugin } from '@tiptap/y-tiptap'\n\ntype CollaborationCaretStorage = {\n users: { clientId: number; [key: string]: any }[]\n}\n\nexport interface CollaborationCaretOptions {\n /**\n * The Hocuspocus provider instance. This can also be a TiptapCloudProvider instance.\n * @type {HocuspocusProvider | TiptapCloudProvider}\n * @example new HocuspocusProvider()\n */\n provider: any\n\n /**\n * The user details object – feel free to add properties to this object as needed\n * @example { name: 'John Doe', color: '#305500' }\n */\n user: Record<string, any>\n\n /**\n * A function that returns a DOM element for the cursor.\n * @param user The user details object\n * @example\n * render: user => {\n * const cursor = document.createElement('span')\n * cursor.classList.add('collaboration-carets__caret')\n * cursor.setAttribute('style', `border-color: ${user.color}`)\n *\n * const label = document.createElement('div')\n * label.classList.add('collaboration-carets__label')\n * label.setAttribute('style', `background-color: ${user.color}`)\n * label.insertBefore(document.createTextNode(user.name), null)\n *\n * cursor.insertBefore(label, null)\n * return cursor\n * }\n */\n render(user: Record<string, any>): HTMLElement\n\n /**\n * A function that returns a ProseMirror DecorationAttrs object for the selection.\n * @param user The user details object\n * @example\n * selectionRender: user => {\n * return {\n * nodeName: 'span',\n * class: 'collaboration-carets__selection',\n * style: `background-color: ${user.color}`,\n * 'data-user': user.name,\n * }\n */\n selectionRender(user: Record<string, any>): DecorationAttrs\n\n /**\n * @deprecated The \"onUpdate\" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret\n */\n onUpdate: (users: { clientId: number; [key: string]: any }[]) => null\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n collaborationCaret: {\n /**\n * Update details of the current user\n * @example editor.commands.updateUser({ name: 'John Doe', color: '#305500' })\n */\n updateUser: (attributes: Record<string, any>) => ReturnType\n /**\n * Update details of the current user\n *\n * @deprecated The \"user\" command is deprecated. Please use \"updateUser\" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret\n */\n user: (attributes: Record<string, any>) => ReturnType\n }\n }\n\n interface Storage {\n collaborationCaret: CollaborationCaretStorage\n }\n}\n\nconst awarenessStatesToArray = (states: Map<number, Record<string, any>>) => {\n return Array.from(states.entries()).map(([key, value]) => {\n return {\n clientId: key,\n ...value.user,\n }\n })\n}\n\nconst defaultOnUpdate = () => null\n\n/**\n * This extension allows you to add collaboration carets to your editor.\n * @see https://tiptap.dev/api/extensions/collaboration-caret\n */\nexport const CollaborationCaret = Extension.create<CollaborationCaretOptions, CollaborationCaretStorage>({\n name: 'collaborationCaret',\n\n priority: 999,\n\n addOptions() {\n return {\n provider: null,\n user: {\n name: null,\n color: null,\n },\n render: user => {\n const cursor = document.createElement('span')\n\n cursor.classList.add('collaboration-carets__caret')\n cursor.setAttribute('style', `border-color: ${user.color}`)\n\n const label = document.createElement('div')\n\n label.classList.add('collaboration-carets__label')\n label.setAttribute('style', `background-color: ${user.color}`)\n label.insertBefore(document.createTextNode(user.name), null)\n cursor.insertBefore(label, null)\n\n return cursor\n },\n selectionRender: defaultSelectionBuilder,\n onUpdate: defaultOnUpdate,\n }\n },\n\n onCreate() {\n if (this.options.onUpdate !== defaultOnUpdate) {\n console.warn(\n '[tiptap warn]: DEPRECATED: The \"onUpdate\" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret',\n )\n }\n if (!this.options.provider) {\n throw new Error('The \"provider\" option is required for the CollaborationCaret extension')\n }\n },\n\n addStorage() {\n return {\n users: [],\n }\n },\n\n addCommands() {\n return {\n updateUser: attributes => () => {\n this.options.provider.awareness.setLocalStateField('user', attributes)\n return true\n },\n user:\n attributes =>\n ({ editor }) => {\n console.warn(\n '[tiptap warn]: DEPRECATED: The \"user\" command is deprecated. Please use \"updateUser\" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret',\n )\n\n return editor.commands.updateUser(attributes)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [\n yCursorPlugin(\n (() => {\n this.options.provider.awareness.setLocalStateField('user', this.options.user)\n\n this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states)\n\n this.options.provider.awareness.on('update', () => {\n this.storage.users = awarenessStatesToArray(this.options.provider.awareness.states)\n })\n\n return this.options.provider.awareness\n })(),\n {\n cursorBuilder: this.options.render,\n selectionBuilder: this.options.selectionRender,\n },\n ),\n ]\n },\n})\n","import { CollaborationCaret } from './collaboration-caret.js'\n\nexport * from './collaboration-caret.js'\n\nexport default CollaborationCaret\n"],"mappings":";AAAA,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB,qBAAqB;AAkFvD,IAAM,yBAAyB,CAAC,WAA6C;AAC3E,SAAO,MAAM,KAAK,OAAO,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACxD,WAAO;AAAA,MACL,UAAU;AAAA,MACV,GAAG,MAAM;AAAA,IACX;AAAA,EACF,CAAC;AACH;AAEA,IAAM,kBAAkB,MAAM;AAMvB,IAAM,qBAAqB,UAAU,OAA6D;AAAA,EACvG,MAAM;AAAA,EAEN,UAAU;AAAA,EAEV,aAAa;AACX,WAAO;AAAA,MACL,UAAU;AAAA,MACV,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA,QAAQ,UAAQ;AACd,cAAM,SAAS,SAAS,cAAc,MAAM;AAE5C,eAAO,UAAU,IAAI,6BAA6B;AAClD,eAAO,aAAa,SAAS,iBAAiB,KAAK,KAAK,EAAE;AAE1D,cAAM,QAAQ,SAAS,cAAc,KAAK;AAE1C,cAAM,UAAU,IAAI,6BAA6B;AACjD,cAAM,aAAa,SAAS,qBAAqB,KAAK,KAAK,EAAE;AAC7D,cAAM,aAAa,SAAS,eAAe,KAAK,IAAI,GAAG,IAAI;AAC3D,eAAO,aAAa,OAAO,IAAI;AAE/B,eAAO;AAAA,MACT;AAAA,MACA,iBAAiB;AAAA,MACjB,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EAEA,WAAW;AACT,QAAI,KAAK,QAAQ,aAAa,iBAAiB;AAC7C,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AACA,QAAI,CAAC,KAAK,QAAQ,UAAU;AAC1B,YAAM,IAAI,MAAM,wEAAwE;AAAA,IAC1F;AAAA,EACF;AAAA,EAEA,aAAa;AACX,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,IACV;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,YAAY,gBAAc,MAAM;AAC9B,aAAK,QAAQ,SAAS,UAAU,mBAAmB,QAAQ,UAAU;AACrE,eAAO;AAAA,MACT;AAAA,MACA,MACE,gBACA,CAAC,EAAE,OAAO,MAAM;AACd,gBAAQ;AAAA,UACN;AAAA,QACF;AAEA,eAAO,OAAO,SAAS,WAAW,UAAU;AAAA,MAC9C;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,MACL;AAAA,SACG,MAAM;AACL,eAAK,QAAQ,SAAS,UAAU,mBAAmB,QAAQ,KAAK,QAAQ,IAAI;AAE5E,eAAK,QAAQ,QAAQ,uBAAuB,KAAK,QAAQ,SAAS,UAAU,MAAM;AAElF,eAAK,QAAQ,SAAS,UAAU,GAAG,UAAU,MAAM;AACjD,iBAAK,QAAQ,QAAQ,uBAAuB,KAAK,QAAQ,SAAS,UAAU,MAAM;AAAA,UACpF,CAAC;AAED,iBAAO,KAAK,QAAQ,SAAS;AAAA,QAC/B,GAAG;AAAA,QACH;AAAA,UACE,eAAe,KAAK,QAAQ;AAAA,UAC5B,kBAAkB,KAAK,QAAQ;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;ACvLD,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-collaboration-caret",
|
|
3
3
|
"description": "collaboration caret extension for tiptap",
|
|
4
|
-
"version": "3.20.
|
|
4
|
+
"version": "3.20.4",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@tiptap/y-tiptap": "^3.0.2",
|
|
35
35
|
"yjs": "^13.6.23",
|
|
36
|
-
"@tiptap/core": "^3.20.
|
|
37
|
-
"@tiptap/extension-collaboration": "^3.20.
|
|
38
|
-
"@tiptap/extension-
|
|
39
|
-
"@tiptap/extension-
|
|
40
|
-
"@tiptap/extension-table": "^3.20.
|
|
41
|
-
"@tiptap/extension-table-
|
|
42
|
-
"@tiptap/extension-
|
|
43
|
-
"@tiptap/extension-table-row": "^3.20.
|
|
44
|
-
"@tiptap/extension-text": "^3.20.
|
|
45
|
-
"@tiptap/pm": "^3.20.
|
|
36
|
+
"@tiptap/core": "^3.20.4",
|
|
37
|
+
"@tiptap/extension-collaboration": "^3.20.4",
|
|
38
|
+
"@tiptap/extension-paragraph": "^3.20.4",
|
|
39
|
+
"@tiptap/extension-table-cell": "^3.20.4",
|
|
40
|
+
"@tiptap/extension-table": "^3.20.4",
|
|
41
|
+
"@tiptap/extension-table-header": "^3.20.4",
|
|
42
|
+
"@tiptap/extension-document": "^3.20.4",
|
|
43
|
+
"@tiptap/extension-table-row": "^3.20.4",
|
|
44
|
+
"@tiptap/extension-text": "^3.20.4",
|
|
45
|
+
"@tiptap/pm": "^3.20.4"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@tiptap/y-tiptap": "^3.0.2",
|
|
49
|
-
"@tiptap/
|
|
50
|
-
"@tiptap/
|
|
49
|
+
"@tiptap/core": "^3.20.4",
|
|
50
|
+
"@tiptap/pm": "^3.20.4"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
|
53
53
|
"type": "git",
|