@wangeditor-next/yjs-for-vue 3.0.0 → 3.0.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.
@@ -2,13 +2,41 @@
2
2
  * @description config interface
3
3
  * @author wangfupeng
4
4
  */
5
- import type { ImageElement } from 'packages/basic-modules/src/modules/image/custom-types';
6
- import type { VideoElement } from 'packages/video-module/src/module/custom-types';
7
5
  import type { Descendant, Node, NodeEntry, Range } from 'slate';
8
6
  import type { IDomEditor } from '../editor/interface';
9
7
  import type { IMenuGroup } from '../menus/interface';
10
8
  import type { IUploadConfig } from '../upload/interface';
11
9
  import type { DOMElement } from '../utils/dom';
10
+ type EmptyText = {
11
+ text: '';
12
+ };
13
+ type ImageElement = {
14
+ type: 'image';
15
+ src: string;
16
+ alt?: string;
17
+ href?: string;
18
+ width?: string;
19
+ height?: string;
20
+ style?: {
21
+ width?: string;
22
+ height?: string;
23
+ };
24
+ children: EmptyText[];
25
+ };
26
+ type VideoElement = {
27
+ type: 'video';
28
+ key?: string;
29
+ src: string;
30
+ poster?: string;
31
+ align?: 'left' | 'center' | 'right';
32
+ width?: string;
33
+ height?: string;
34
+ style?: {
35
+ width?: string;
36
+ height?: string;
37
+ };
38
+ children: EmptyText[];
39
+ };
12
40
  interface IHoverbarConf {
13
41
  [key: string]: {
14
42
  match?: (editor: IDomEditor, n: Node) => boolean;
@@ -2,15 +2,28 @@
2
2
  * @description editor interface
3
3
  * @author wangfupeng
4
4
  */
5
- import { NodeEntryWithContext } from '@wangeditor-next/table-module/src/utils';
6
5
  import ee from 'event-emitter';
7
- import { Ancestor, Editor, Element, Location, Node } from 'slate';
6
+ import { Ancestor, Editor, Element, Location, Node, NodeEntry } from 'slate';
8
7
  import { AlertType, IEditorConfig, IMenuConfig, ISingleMenuConfig } from '../config/interface';
9
8
  import { IPositionStyle } from '../menus/interface';
10
9
  import { DOMElement } from '../utils/dom';
11
10
  export type ElementWithId = Element & {
12
11
  id: string;
13
12
  };
13
+ export type TableSelectionEntry = [
14
+ NodeEntry<Element & {
15
+ type: unknown;
16
+ rowSpan?: number;
17
+ colSpan?: number;
18
+ hidden?: boolean;
19
+ }>,
20
+ {
21
+ rtl: number;
22
+ ltr: number;
23
+ ttb: number;
24
+ btt: number;
25
+ }
26
+ ];
14
27
  type MoveOptions = Parameters<Editor['move']>[0];
15
28
  export type getMenuConfigReturnType<K> = K extends keyof IMenuConfig ? IMenuConfig[K] : ISingleMenuConfig;
16
29
  /**
@@ -59,7 +72,7 @@ export interface IDomEditor extends Editor {
59
72
  move(distance: number, reverse?: boolean): void;
60
73
  moveReverse: (distance: number) => void;
61
74
  restoreSelection: () => void;
62
- getTableSelection?: () => NodeEntryWithContext[][] | null;
75
+ getTableSelection?: () => TableSelectionEntry[][] | null;
63
76
  getSelectionPosition: () => Partial<IPositionStyle>;
64
77
  getNodePosition: (node: Node) => Partial<IPositionStyle>;
65
78
  isSelectedAll: () => boolean;
@@ -11,7 +11,7 @@ import type { IElemToHtmlConf, styleToHtmlFnType } from './to-html/index';
11
11
  import createUploaderRuntime from './upload/createUploader';
12
12
  import type { IUploadConfig } from './upload/interface';
13
13
  export * from './create/index';
14
- export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
14
+ export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, ISingleMenuConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
15
15
  export * from './config/style-mode';
16
16
  export * from './editor/dom-editor';
17
17
  export * from './editor/interface';
@@ -2,6 +2,5 @@
2
2
  * @description formats helper
3
3
  * @author wangfupeng
4
4
  */
5
- import { ElementType } from 'packages/custom-types';
6
- export declare function genElemId(type: ElementType, id: string): string;
5
+ export declare function genElemId(type: string, id: string): string;
7
6
  export declare function genTextId(id: string): string;
@@ -2,9 +2,8 @@
2
2
  * @description Editor View class
3
3
  * @author wangfupeng
4
4
  */
5
- import type { IEditorConfig, IElemToHtmlConf, IModuleConf, IParseElemHtmlConf, IPreParseHtmlConf, IRegisterMenuConf, IRenderElemConf, IToolbarConfig, ParseStyleHtmlFnType, RenderStyleFnType, styleToHtmlFnType } from '@wangeditor-next/core';
5
+ import type { IEditorConfig, IElemToHtmlConf, IModuleConf, IParseElemHtmlConf, IPreParseHtmlConf, IRegisterMenuConf, IRenderElemConf, ISingleMenuConfig, IToolbarConfig, ParseStyleHtmlFnType, RenderStyleFnType, styleToHtmlFnType } from '@wangeditor-next/core';
6
6
  import { IDomEditor } from '@wangeditor-next/core';
7
- import type { ISingleMenuConfig } from 'packages/core/src/config/interface';
8
7
  type PluginType = <T extends IDomEditor>(editor: T) => T;
9
8
  declare class Boot {
10
9
  constructor();
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("@wangeditor-next/yjs"),require("@wangeditor-next/editor"),require("slate")):"function"==typeof define&&define.amd?define(["exports","vue","@wangeditor-next/yjs","@wangeditor-next/editor","slate"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WangEditorYjsForVue={},e.vue,e.yjs,e.editor,e.slate)}(this,function(e,t,n,r,o){"use strict";var i=Symbol("editorContext");var a=function(){var e=t.inject(i);if(!e)throw new Error("[useEditorStatic] editor context not provided.Call provideEditor() in a parent component before using useEditorStatic().");return e.editor},u=function(){return u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},u.apply(this,arguments)};function l(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}"function"==typeof SuppressedError&&SuppressedError;var c=new WeakMap;function f(e,t){if(!t.relativeSelection)return null;var r=c.get(e.children);r||(r=new WeakMap,c.set(e.children,r));var o=r.get(t);if(void 0===o)try{o=n.relativeRangeToSlateRange(e.sharedRoot,e,t.relativeSelection),r.set(t,o)}catch(e){return null}return void 0===o?null:o}function s(e,t,n){var i,a,u=n.yOffset,c=n.xOffset,f=n.shouldGenerateOverlay,s=l(o.Range.edges(t),2),v=s[0],d=s[1],h=function(e,t){try{return r.DomEditor.toDOMRange(e,t)}catch(e){return null}}(e,t);if(!h)return{caretPosition:null,selectionRects:[]};var p=[],y=o.Editor.nodes(e,{at:t,match:function(e,t){return o.Text.isText(e)&&(!f||f(e,t))}}),g=null,m=o.Range.isBackward(t);try{for(var w=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(y),O=w.next();!O.done;O=w.next()){var b=l(O.value,2),R=b[0],E=b[1],S=r.DomEditor.toDOMNode(e,R),x=o.Path.equals(E,v.path),j=o.Path.equals(E,d.path),C=null;if(x||j){var P=document.createRange();P.selectNode(S),x&&P.setStart(h.startContainer,h.startOffset),j&&P.setEnd(h.endContainer,h.endOffset),C=P.getClientRects()}else C=S.getClientRects();for(var k=m?x:j,q=0;q<C.length;q+=1){var M=C.item(q);if(M){var W=k&&(m?0===q:q===C.length-1),F=M.top-u,T=M.left-c;W&&(g={height:M.height,top:F,left:T+(m||o.Range.isCollapsed(t)?0:M.width)}),p.push({width:M.width,height:M.height,top:F,left:T})}}}}catch(e){i={error:e}}finally{try{O&&!O.done&&(a=w.return)&&a.call(w)}finally{if(i)throw i.error}}return{selectionRects:p,caretPosition:g}}var v=function(e){var r=t.ref({}),o=function(o){var i=t.toRaw(e.value);if(i){var a=n.CursorEditor.cursorState(i,o);null!==a?r.value[o.toString()]=a:delete r.value[o.toString()]}},i=function(e){e.added.forEach(function(e){o(e)}),e.removed.forEach(function(e){o(e)}),e.updated.forEach(function(e){o(e)})};return t.watch(function(){return e.value},function(e,r){r&&n.CursorEditor.off(t.toRaw(r),"change",i),e&&n.CursorEditor.on(t.toRaw(e),"change",i)},{immediate:!0}),t.onUnmounted(function(){e.value&&n.CursorEditor.off(t.toRaw(e.value),"change",i)}),{cursors:r}},d=Object.freeze([]);e.getCursorRange=f,e.provideEditor=function(e){t.provide(i,{editor:e})},e.useEditorStatic=a,e.useRemoteCursorOverlayPositions=function(e){var n,r=e.containerRef,o=e.shouldGenerateOverlay,i=e.editorRef,c=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(e,["containerRef","shouldGenerateOverlay","editorRef"]);null==i&&(i=a());var h=new WeakMap,p=v(i).cursors,y=t.ref({}),g=function(e){var n,a,u;if(i.value){var c=null===(n=null==r?void 0:r.value)||void 0===n?void 0:n.getBoundingClientRect(),v=null!==(a=null==c?void 0:c.x)&&void 0!==a?a:0,p=null!==(u=null==c?void 0:c.y)&&void 0!==u?u:0,g=t.toRaw(i.value),m=Object.keys(y.value).length!==Object.keys(e).length,w=Object.fromEntries(Object.entries(e).map(function(e){var t=l(e,2),n=t[0],r=t[1],i=r.relativeSelection&&f(g,r);if(!i)return[n,d];if(h.get(i))return[n,h.get(i)];var a=s(g,i,{xOffset:v,yOffset:p,shouldGenerateOverlay:o});return h.set(i,a),m=!0,[n,a]}));m&&(y.value=w)}},m=!!r&&(null===(n=c.refreshOnResize)||void 0===n||n),w=null,O=new ResizeObserver(function(){h=new WeakMap,"debounced"===m?(w&&cancelAnimationFrame(w),w=requestAnimationFrame(function(){g(p.value)})):g(p.value)});t.watchEffect(function(e){if(m&&r.value){var t=r.value;O.observe(t)}e(function(){if(w&&(cancelAnimationFrame(w),w=null),m&&r.value){var e=r.value;O.unobserve(e)}})});var b=function(){h=new WeakMap,w&&cancelAnimationFrame(w),w=requestAnimationFrame(function(){g(p.value)})};t.watch(function(){return i.value},function(e,t){t&&t.off("scroll",b),e&&e.on("scroll",b)},{immediate:!0}),t.onUnmounted(function(){i.value&&i.value.off("scroll",b)}),t.watch(function(){return[p.value,null==r?void 0:r.value,i.value]},function(){i.value&&g(p.value)},{immediate:!0,flush:"sync",deep:!0});var R=t.computed(function(){if(!i.value)return[];var e=i.value;return Object.entries(p.value).map(function(t){var n,r,o=l(t,2),i=o[0],a=o[1],c=a.relativeSelection?f(e,a):null,s=y.value[i];return u(u({},a),{range:c,caretPosition:null!==(n=null==s?void 0:s.caretPosition)&&void 0!==n?n:null,selectionRects:null!==(r=null==s?void 0:s.selectionRects)&&void 0!==r?r:d})})});return{cursors:R,refresh:function(){h=new WeakMap,g(p.value)}}},e.useRemoteCursorStates=v});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("@wangeditor-next/yjs"),require("@wangeditor-next/editor"),require("slate")):"function"==typeof define&&define.amd?define(["exports","vue","@wangeditor-next/yjs","@wangeditor-next/editor","slate"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WangEditorYjsForVue={},e.Vue,e.WangEditorYjsModule,e.wangEditor,e.Slate)}(this,function(e,t,n,r,o){"use strict";var i=Symbol("editorContext");var a=function(){var e=t.inject(i);if(!e)throw new Error("[useEditorStatic] editor context not provided.Call provideEditor() in a parent component before using useEditorStatic().");return e.editor},u=function(){return u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},u.apply(this,arguments)};function l(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}"function"==typeof SuppressedError&&SuppressedError;var c=new WeakMap;function f(e,t){if(!t.relativeSelection)return null;var r=c.get(e.children);r||(r=new WeakMap,c.set(e.children,r));var o=r.get(t);if(void 0===o)try{o=n.relativeRangeToSlateRange(e.sharedRoot,e,t.relativeSelection),r.set(t,o)}catch(e){return null}return void 0===o?null:o}function s(e,t,n){var i,a,u=n.yOffset,c=n.xOffset,f=n.shouldGenerateOverlay,s=l(o.Range.edges(t),2),v=s[0],d=s[1],h=function(e,t){try{return r.DomEditor.toDOMRange(e,t)}catch(e){return null}}(e,t);if(!h)return{caretPosition:null,selectionRects:[]};var p=[],y=o.Editor.nodes(e,{at:t,match:function(e,t){return o.Text.isText(e)&&(!f||f(e,t))}}),g=null,m=o.Range.isBackward(t);try{for(var w=function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(y),O=w.next();!O.done;O=w.next()){var b=l(O.value,2),R=b[0],E=b[1],S=r.DomEditor.toDOMNode(e,R),x=o.Path.equals(E,v.path),j=o.Path.equals(E,d.path),C=null;if(x||j){var P=document.createRange();P.selectNode(S),x&&P.setStart(h.startContainer,h.startOffset),j&&P.setEnd(h.endContainer,h.endOffset),C=P.getClientRects()}else C=S.getClientRects();for(var k=m?x:j,M=0;M<C.length;M+=1){var q=C.item(M);if(q){var W=k&&(m?0===M:M===C.length-1),F=q.top-u,T=q.left-c;W&&(g={height:q.height,top:F,left:T+(m||o.Range.isCollapsed(t)?0:q.width)}),p.push({width:q.width,height:q.height,top:F,left:T})}}}}catch(e){i={error:e}}finally{try{O&&!O.done&&(a=w.return)&&a.call(w)}finally{if(i)throw i.error}}return{selectionRects:p,caretPosition:g}}var v=function(e){var r=t.ref({}),o=function(o){var i=t.toRaw(e.value);if(i){var a=n.CursorEditor.cursorState(i,o);null!==a?r.value[o.toString()]=a:delete r.value[o.toString()]}},i=function(e){e.added.forEach(function(e){o(e)}),e.removed.forEach(function(e){o(e)}),e.updated.forEach(function(e){o(e)})};return t.watch(function(){return e.value},function(e,r){r&&n.CursorEditor.off(t.toRaw(r),"change",i),e&&n.CursorEditor.on(t.toRaw(e),"change",i)},{immediate:!0}),t.onUnmounted(function(){e.value&&n.CursorEditor.off(t.toRaw(e.value),"change",i)}),{cursors:r}},d=Object.freeze([]);e.getCursorRange=f,e.provideEditor=function(e){t.provide(i,{editor:e})},e.useEditorStatic=a,e.useRemoteCursorOverlayPositions=function(e){var n,r=e.containerRef,o=e.shouldGenerateOverlay,i=e.editorRef,c=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(e,["containerRef","shouldGenerateOverlay","editorRef"]);null==i&&(i=a());var h=new WeakMap,p=v(i).cursors,y=t.ref({}),g=function(e){var n,a,u;if(i.value){var c=null===(n=null==r?void 0:r.value)||void 0===n?void 0:n.getBoundingClientRect(),v=null!==(a=null==c?void 0:c.x)&&void 0!==a?a:0,p=null!==(u=null==c?void 0:c.y)&&void 0!==u?u:0,g=t.toRaw(i.value),m=Object.keys(y.value).length!==Object.keys(e).length,w=Object.fromEntries(Object.entries(e).map(function(e){var t=l(e,2),n=t[0],r=t[1],i=r.relativeSelection&&f(g,r);if(!i)return[n,d];if(h.get(i))return[n,h.get(i)];var a=s(g,i,{xOffset:v,yOffset:p,shouldGenerateOverlay:o});return h.set(i,a),m=!0,[n,a]}));m&&(y.value=w)}},m=!!r&&(null===(n=c.refreshOnResize)||void 0===n||n),w=null,O=new ResizeObserver(function(){h=new WeakMap,"debounced"===m?(w&&cancelAnimationFrame(w),w=requestAnimationFrame(function(){g(p.value)})):g(p.value)});t.watchEffect(function(e){if(m&&r.value){var t=r.value;O.observe(t)}e(function(){if(w&&(cancelAnimationFrame(w),w=null),m&&r.value){var e=r.value;O.unobserve(e)}})});var b=function(){h=new WeakMap,w&&cancelAnimationFrame(w),w=requestAnimationFrame(function(){g(p.value)})};t.watch(function(){return i.value},function(e,t){t&&t.off("scroll",b),e&&e.on("scroll",b)},{immediate:!0}),t.onUnmounted(function(){i.value&&i.value.off("scroll",b)}),t.watch(function(){return[p.value,null==r?void 0:r.value,i.value]},function(){i.value&&g(p.value)},{immediate:!0,flush:"sync",deep:!0});var R=t.computed(function(){if(!i.value)return[];var e=i.value;return Object.entries(p.value).map(function(t){var n,r,o=l(t,2),i=o[0],a=o[1],c=a.relativeSelection?f(e,a):null,s=y.value[i];return u(u({},a),{range:c,caretPosition:null!==(n=null==s?void 0:s.caretPosition)&&void 0!==n?n:null,selectionRects:null!==(r=null==s?void 0:s.selectionRects)&&void 0!==r?r:d})})});return{cursors:R,refresh:function(){h=new WeakMap,g(p.value)}}},e.useRemoteCursorStates=v});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/hooks/use-editor-static.ts","../src/utils/getCursorRange.ts","../src/utils/getOverlayPosition.ts","../src/hooks/useRemoteCursorStates.ts","../src/hooks/useRemoteCursorOverlayPositions.ts"],"sourcesContent":["import type { IDomEditor } from '@wangeditor-next/editor'\nimport { inject, provide, type ShallowRef } from 'vue'\n\nexport interface EditorContext {\n editor: ShallowRef<IDomEditor | undefined>\n}\n\nconst EDITOR_CONTEXT_KEY = Symbol('editorContext')\n\nexport function provideEditor(editorRef: ShallowRef<IDomEditor | undefined>) {\n provide(EDITOR_CONTEXT_KEY, {\n editor: editorRef,\n })\n}\n\nexport const useEditorStatic = (): ShallowRef<IDomEditor | undefined> => {\n const context = inject<EditorContext>(EDITOR_CONTEXT_KEY)\n\n if (!context) {\n // 如果外部没有provide(ShallowRef),则报错\n throw new Error(\n '[useEditorStatic] editor context not provided.Call provideEditor() in a parent component before using useEditorStatic().',\n )\n }\n return context.editor\n}\n","import type { CursorState } from '@wangeditor-next/yjs'\nimport { CursorEditor, relativeRangeToSlateRange } from '@wangeditor-next/yjs'\nimport type { BaseRange, Descendant } from 'slate'\nimport { Range } from 'slate'\n\nconst CHILDREN_TO_CURSOR_STATE_TO_RANGE: WeakMap<Descendant[], WeakMap<CursorState, Range | null>> = new WeakMap()\n\nexport function getCursorRange<TCursorData extends Record<string, unknown> = Record<string, unknown>>(\n editor: CursorEditor<TCursorData>,\n cursorState: CursorState<TCursorData>,\n): BaseRange | null {\n if (!cursorState.relativeSelection) {\n return null\n }\n\n let cursorStates = CHILDREN_TO_CURSOR_STATE_TO_RANGE.get(editor.children)\n\n if (!cursorStates) {\n cursorStates = new WeakMap()\n CHILDREN_TO_CURSOR_STATE_TO_RANGE.set(editor.children, cursorStates)\n }\n\n let range = cursorStates.get(cursorState)\n\n if (range === undefined) {\n try {\n range = relativeRangeToSlateRange(editor.sharedRoot, editor, cursorState.relativeSelection)\n\n cursorStates.set(cursorState, range!)\n } catch (e) {\n return null\n }\n }\n\n return range === undefined ? null : range\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport { DomEditor } from '@wangeditor-next/editor'\nimport type { BaseRange } from 'slate'\nimport {\n Editor, Path, Range as SlateRange, Text,\n} from 'slate'\n\nfunction reactEditorToDomRangeSafe(editor: IDomEditor, range: BaseRange): Range | null {\n try {\n return DomEditor.toDOMRange(editor, range)\n } catch (e) {\n return null\n }\n}\nexport type SelectionRect = {\n width: number;\n height: number;\n top: number;\n left: number;\n};\n\nexport type CaretPosition = {\n height: number;\n top: number;\n left: number;\n};\n\nexport type OverlayPosition = {\n caretPosition: CaretPosition | null;\n selectionRects: SelectionRect[];\n};\n\nexport type GetSelectionRectsOptions = {\n xOffset: number;\n yOffset: number;\n shouldGenerateOverlay?: (node: Text, path: Path) => boolean;\n};\n\nexport function getOverlayPosition(\n editor: IDomEditor,\n range: SlateRange,\n { yOffset, xOffset, shouldGenerateOverlay }: GetSelectionRectsOptions,\n): OverlayPosition {\n const [start, end] = SlateRange.edges(range)\n const domRange = reactEditorToDomRangeSafe(editor, range)\n\n if (!domRange) {\n return {\n caretPosition: null,\n selectionRects: [],\n }\n }\n\n const selectionRects: SelectionRect[] = []\n const nodeIterator = Editor.nodes(editor, {\n at: range,\n match: (n, p) => Text.isText(n) && (!shouldGenerateOverlay || shouldGenerateOverlay(n, p)),\n })\n\n let caretPosition: CaretPosition | null = null\n const isBackward = SlateRange.isBackward(range)\n\n for (const [node, path] of nodeIterator) {\n const domNode = DomEditor.toDOMNode(editor, node)\n\n const isStartNode = Path.equals(path, start.path)\n const isEndNode = Path.equals(path, end.path)\n\n let clientRects: DOMRectList | null = null\n\n if (isStartNode || isEndNode) {\n const nodeRange = document.createRange()\n\n nodeRange.selectNode(domNode)\n\n if (isStartNode) {\n nodeRange.setStart(domRange!.startContainer, domRange!.startOffset)\n }\n if (isEndNode) {\n nodeRange.setEnd(domRange.endContainer, domRange.endOffset)\n }\n\n clientRects = nodeRange.getClientRects()\n } else {\n clientRects = domNode.getClientRects()\n }\n\n const isCaret = isBackward ? isStartNode : isEndNode\n\n for (let i = 0; i < clientRects.length; i += 1) {\n const clientRect = clientRects.item(i)\n\n if (!clientRect) {\n continue\n }\n\n const isCaretRect = isCaret && (isBackward ? i === 0 : i === clientRects.length - 1)\n\n const top = clientRect.top - yOffset\n const left = clientRect.left - xOffset\n\n if (isCaretRect) {\n caretPosition = {\n height: clientRect.height,\n top,\n left: left + (isBackward || SlateRange.isCollapsed(range) ? 0 : clientRect.width),\n }\n }\n\n selectionRects.push({\n width: clientRect.width,\n height: clientRect.height,\n top,\n left,\n })\n }\n }\n\n return {\n selectionRects,\n caretPosition,\n }\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport type {\n CursorState,\n CursorStateChangeEvent,\n} from '@wangeditor-next/yjs'\nimport { CursorEditor } from '@wangeditor-next/yjs'\nimport {\n onUnmounted, ref, type ShallowRef, toRaw, watch,\n} from 'vue'\n\nexport const useRemoteCursorStates = <TCursorData extends Record<string, unknown>>(\n editorRef: ShallowRef<IDomEditor | undefined>,\n) => {\n const cursors = ref<Record<string, CursorState<TCursorData>>>({})\n\n // ===============监听Y.js的改变从而自动改变cursors===============\n const updateCursor = (clientId: number) => {\n const editor = toRaw(editorRef.value) as CursorEditor & IDomEditor\n\n if (!editor) { return }\n const state = CursorEditor.cursorState(editor, clientId)\n\n if (state === null) {\n delete cursors.value[clientId.toString()]\n return\n }\n cursors.value[clientId.toString()] = state as CursorState<TCursorData>\n }\n const changeHandler = (event: CursorStateChangeEvent) => {\n event.added.forEach((clientId: number) => {\n updateCursor(clientId)\n })\n event.removed.forEach((clientId: number) => {\n updateCursor(clientId)\n })\n event.updated.forEach((clientId: number) => {\n updateCursor(clientId)\n })\n }\n\n watch(\n () => editorRef.value,\n (newEditor, oldEditor) => {\n if (oldEditor) {\n CursorEditor.off(toRaw(oldEditor) as CursorEditor & IDomEditor, 'change', changeHandler)\n }\n if (newEditor) {\n // 拿到的是Vue3中的Proxy对象,跟原始对象是不同的映射\n CursorEditor.on(toRaw(newEditor) as CursorEditor & IDomEditor, 'change', changeHandler)\n }\n },\n {\n immediate: true,\n },\n )\n\n onUnmounted(() => {\n if (editorRef.value) {\n CursorEditor.off(toRaw(editorRef.value) as CursorEditor & IDomEditor, 'change', changeHandler)\n }\n })\n // ===============监听Y.js的改变从而自动改变cursors===============\n\n return {\n cursors,\n }\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport { CursorEditor, CursorState } from '@wangeditor-next/yjs'\nimport type {\n BaseRange, NodeMatch, Range as SlateRange, Text,\n} from 'slate'\nimport {\n onUnmounted, type Ref, type ShallowRef, toRaw, watchEffect,\n} from 'vue'\nimport { computed, ref, watch } from 'vue'\n\nimport { getCursorRange } from '../utils/getCursorRange'\nimport type { CaretPosition, OverlayPosition, SelectionRect } from '../utils/getOverlayPosition'\nimport { getOverlayPosition } from '../utils/getOverlayPosition'\nimport { useEditorStatic } from './use-editor-static'\nimport { useRemoteCursorStates } from './useRemoteCursorStates'\n\nconst FROZEN_EMPTY_ARRAY = Object.freeze([])\n\nexport type CursorOverlayData<TCursorData extends Record<string, unknown>> =\n CursorState<TCursorData> & {\n range: BaseRange | null\n caretPosition: CaretPosition | null\n selectionRects: SelectionRect[]\n }\n\nexport type UseRemoteCursorOverlayPositionsOptions<T extends HTMLElement> = {\n shouldGenerateOverlay?: NodeMatch<Text>\n editorRef?: ShallowRef<IDomEditor | undefined>\n} & {\n containerRef?: Ref<T | undefined>\n // Whether to refresh the cursor overlay positions on container resize. Defaults\n // to true. If set to 'debounced', the remote cursor positions will be updated\n // each animation frame.\n refreshOnResize?: boolean | 'debounced'\n}\n\nexport function useRemoteCursorOverlayPositions<\n TCursorData extends Record<string, unknown>,\n TContainer extends HTMLElement = HTMLDivElement,\n>({\n containerRef,\n shouldGenerateOverlay,\n editorRef,\n ...opts\n}: UseRemoteCursorOverlayPositionsOptions<TContainer>) {\n // 1. 监听Y.js的change事件,从而改变cursorStates数据\n // 2. 监听cursorState数据 => 合并Y.js拿到的数据 => 形成最终的数据返回\n\n // 只有完全未传 editorRef 时,才从 context 获取\n // undefined == null 或者 null == null 都为true\n if (editorRef == null) {\n editorRef = useEditorStatic() // eslint-disable-line react-hooks/rules-of-hooks\n }\n\n let overlayPositionCache: WeakMap<SlateRange, OverlayPosition> = new WeakMap()\n\n // ===============监听Y.js的改变从而自动改变cursors===============\n const { cursors } = useRemoteCursorStates<TCursorData>(editorRef)\n\n // ===============cursors改变从而触发overlayPositions的重新计算===============\n const overlayPositions = ref<Record<string, OverlayPosition>>({})\n const computeOverlayPosition = (newCursorsValue: Record<string, CursorState<TCursorData>>) => {\n if (!editorRef.value) { return }\n // 监听containerRef.value挂载再触发一次computeOverlayPosition()\n // if (containerRef && !containerRef.value) {\n // return;\n // }\n // 跟React版本一致,支持【containerRef.value】为空,代表还没初始化完成dom\n const containerRect = containerRef?.value?.getBoundingClientRect()\n const xOffset = containerRect?.x ?? 0\n const yOffset = containerRect?.y ?? 0\n\n const editor = toRaw(editorRef.value!) as CursorEditor & IDomEditor\n\n let overlayPositionsChanged = Object.keys(overlayPositions.value).length !== Object.keys(newCursorsValue).length\n // 每次都更新位置\n const newOverlayPositions = Object.fromEntries(\n Object.entries(newCursorsValue).map(([key, state]) => {\n const range: SlateRange | null = state.relativeSelection && getCursorRange(editor, state)\n\n if (!range) {\n return [key, FROZEN_EMPTY_ARRAY]\n }\n\n if (overlayPositionCache.get(range)) {\n return [key, overlayPositionCache.get(range)]\n }\n\n const overlayPosition = getOverlayPosition(editor, range, {\n xOffset,\n yOffset,\n shouldGenerateOverlay,\n })\n\n overlayPositionCache.set(range, overlayPosition)\n overlayPositionsChanged = true\n\n return [key, overlayPosition]\n }),\n )\n\n if (overlayPositionsChanged) {\n overlayPositions.value = newOverlayPositions\n }\n }\n\n // ===============监听containerRef的变化===============\n const refreshOnResize = containerRef ? (opts.refreshOnResize ?? true) : false\n let rafId: number | null = null\n const observer = new ResizeObserver(() => {\n // 重新进行界面的渲染刷新\n overlayPositionCache = new WeakMap()\n if (refreshOnResize === 'debounced') {\n if (rafId) {\n cancelAnimationFrame(rafId)\n }\n\n rafId = requestAnimationFrame(() => {\n computeOverlayPosition(cursors.value)\n })\n } else {\n computeOverlayPosition(cursors.value)\n }\n })\n\n watchEffect(onCleanup => {\n if (refreshOnResize && containerRef!.value) {\n const element = containerRef!.value\n\n observer.observe(element)\n }\n\n onCleanup(() => {\n if (rafId) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n if (refreshOnResize && containerRef!.value) {\n const element = containerRef!.value\n\n observer.unobserve(element)\n }\n })\n })\n // ===============监听containerRef的变化===============\n\n // ===============监听editor滚动,实时更新cursors的计算===============\n const handleScroll = () => {\n overlayPositionCache = new WeakMap()\n if (rafId) {\n cancelAnimationFrame(rafId)\n }\n rafId = requestAnimationFrame(() => {\n computeOverlayPosition(cursors.value)\n })\n }\n\n watch(\n () => editorRef.value,\n (newEditor, oldEditor) => {\n if (oldEditor) {\n oldEditor.off('scroll', handleScroll)\n }\n if (newEditor) {\n newEditor.on('scroll', handleScroll)\n }\n },\n {\n immediate: true,\n },\n )\n\n onUnmounted(() => {\n if (editorRef.value) {\n editorRef.value.off('scroll', handleScroll)\n }\n })\n // ===============监听editor滚动,实时更新cursors的计算===============\n\n // 跟React的useLayoutEffect相同逻辑,只是Vue不需要重新渲染,只需要监听依赖的数据\n // containerRef可能为空,Vue支持监听null/undefined,不会进行响应式收集\n // overlayPosition的计算依赖于:当前传入的DOM-containerRef(需要一开始没挂载,需要一段时间才挂载),cursors的值变化\n // computeOverlayPosition()有使用缓存overlayPositionCache,即使跟observer.observe(element)重复触发,也不会重复赋值overlayPositions.value\n watch(\n () => [cursors.value, containerRef?.value, editorRef.value],\n () => {\n if (!editorRef.value) {\n return\n }\n // 重新计算overlayPosition\n computeOverlayPosition(cursors.value)\n },\n {\n immediate: true,\n flush: 'sync',\n deep: true,\n },\n )\n // ===============cursors改变从而触发overlayPositions的重新计算===============\n\n // ------------------------根据cursors和overlayPositions进行overlayData的计算------------------------\n type OverlayDataType = CursorState<TCursorData> & {\n range: BaseRange | null\n } & OverlayPosition\n const overlayData = computed(() => {\n if (!editorRef.value) {\n return []\n }\n const editor = editorRef.value as CursorEditor & IDomEditor\n\n return Object.entries(cursors.value).map(([clientId, state]) => {\n const range = state.relativeSelection ? getCursorRange(editor, state) : null\n const overlayPosition = overlayPositions.value[clientId]\n\n return {\n ...state,\n range,\n caretPosition: overlayPosition?.caretPosition ?? null,\n selectionRects: overlayPosition?.selectionRects ?? FROZEN_EMPTY_ARRAY,\n }\n }) as Array<OverlayDataType>\n })\n // ------------------------根据cursors和overlayPositions进行overlayData的计算------------------------\n\n const refresh = () => {\n overlayPositionCache = new WeakMap()\n computeOverlayPosition(cursors.value)\n }\n\n return {\n cursors: overlayData,\n refresh,\n }\n}\n"],"names":["EDITOR_CONTEXT_KEY","Symbol","useEditorStatic","context","inject","Error","editor","CHILDREN_TO_CURSOR_STATE_TO_RANGE","WeakMap","getCursorRange","cursorState","relativeSelection","cursorStates","get","children","set","range","undefined","relativeRangeToSlateRange","sharedRoot","e","getOverlayPosition","_a","yOffset","xOffset","shouldGenerateOverlay","_c","__read","SlateRange","edges","start","end","domRange","DomEditor","toDOMRange","reactEditorToDomRangeSafe","caretPosition","selectionRects","nodeIterator","Editor","nodes","at","match","n","p","Text","isText","isBackward","nodeIterator_1","__values","nodeIterator_1_1","next","_d","value","node","path","domNode","toDOMNode","isStartNode","Path","equals","isEndNode","clientRects","nodeRange","document","createRange","selectNode","setStart","startContainer","startOffset","setEnd","endContainer","endOffset","getClientRects","isCaret","i","length","clientRect","item","isCaretRect","top_1","top","left","height","isCollapsed","width","push","useRemoteCursorStates","editorRef","cursors","ref","updateCursor","clientId","toRaw","state","CursorEditor","toString","changeHandler","event","added","forEach","removed","updated","watch","newEditor","oldEditor","off","on","immediate","onUnmounted","FROZEN_EMPTY_ARRAY","Object","freeze","provide","containerRef","opts","__rest","overlayPositionCache","overlayPositions","computeOverlayPosition","newCursorsValue","containerRect","getBoundingClientRect","_b","x","y","overlayPositionsChanged","keys","newOverlayPositions","fromEntries","entries","map","key","overlayPosition","refreshOnResize","rafId","observer","ResizeObserver","cancelAnimationFrame","requestAnimationFrame","watchEffect","onCleanup","element","observe","unobserve","handleScroll","flush","deep","overlayData","computed","__assign","refresh"],"mappings":"icAOA,IAAMA,EAAqBC,OAAO,iBAQ3B,IAAMC,EAAkB,WAC7B,IAAMC,EAAUC,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version":3,"file":"index.js","sources":["../src/hooks/use-editor-static.ts","../src/utils/getCursorRange.ts","../src/utils/getOverlayPosition.ts","../src/hooks/useRemoteCursorStates.ts","../src/hooks/useRemoteCursorOverlayPositions.ts"],"sourcesContent":["import type { IDomEditor } from '@wangeditor-next/editor'\nimport { inject, provide, type ShallowRef } from 'vue'\n\nexport interface EditorContext {\n editor: ShallowRef<IDomEditor | undefined>\n}\n\nconst EDITOR_CONTEXT_KEY = Symbol('editorContext')\n\nexport function provideEditor(editorRef: ShallowRef<IDomEditor | undefined>) {\n provide(EDITOR_CONTEXT_KEY, {\n editor: editorRef,\n })\n}\n\nexport const useEditorStatic = (): ShallowRef<IDomEditor | undefined> => {\n const context = inject<EditorContext>(EDITOR_CONTEXT_KEY)\n\n if (!context) {\n // 如果外部没有provide(ShallowRef),则报错\n throw new Error(\n '[useEditorStatic] editor context not provided.Call provideEditor() in a parent component before using useEditorStatic().',\n )\n }\n return context.editor\n}\n","import type { CursorState } from '@wangeditor-next/yjs'\nimport { CursorEditor, relativeRangeToSlateRange } from '@wangeditor-next/yjs'\nimport type { BaseRange, Descendant } from 'slate'\nimport { Range } from 'slate'\n\nconst CHILDREN_TO_CURSOR_STATE_TO_RANGE: WeakMap<Descendant[], WeakMap<CursorState, Range | null>> = new WeakMap()\n\nexport function getCursorRange<TCursorData extends Record<string, unknown> = Record<string, unknown>>(\n editor: CursorEditor<TCursorData>,\n cursorState: CursorState<TCursorData>,\n): BaseRange | null {\n if (!cursorState.relativeSelection) {\n return null\n }\n\n let cursorStates = CHILDREN_TO_CURSOR_STATE_TO_RANGE.get(editor.children)\n\n if (!cursorStates) {\n cursorStates = new WeakMap()\n CHILDREN_TO_CURSOR_STATE_TO_RANGE.set(editor.children, cursorStates)\n }\n\n let range = cursorStates.get(cursorState)\n\n if (range === undefined) {\n try {\n range = relativeRangeToSlateRange(editor.sharedRoot, editor, cursorState.relativeSelection)\n\n cursorStates.set(cursorState, range!)\n } catch (e) {\n return null\n }\n }\n\n return range === undefined ? null : range\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport { DomEditor } from '@wangeditor-next/editor'\nimport type { BaseRange } from 'slate'\nimport {\n Editor, Path, Range as SlateRange, Text,\n} from 'slate'\n\nfunction reactEditorToDomRangeSafe(editor: IDomEditor, range: BaseRange): Range | null {\n try {\n return DomEditor.toDOMRange(editor, range)\n } catch (e) {\n return null\n }\n}\nexport type SelectionRect = {\n width: number;\n height: number;\n top: number;\n left: number;\n};\n\nexport type CaretPosition = {\n height: number;\n top: number;\n left: number;\n};\n\nexport type OverlayPosition = {\n caretPosition: CaretPosition | null;\n selectionRects: SelectionRect[];\n};\n\nexport type GetSelectionRectsOptions = {\n xOffset: number;\n yOffset: number;\n shouldGenerateOverlay?: (node: Text, path: Path) => boolean;\n};\n\nexport function getOverlayPosition(\n editor: IDomEditor,\n range: SlateRange,\n { yOffset, xOffset, shouldGenerateOverlay }: GetSelectionRectsOptions,\n): OverlayPosition {\n const [start, end] = SlateRange.edges(range)\n const domRange = reactEditorToDomRangeSafe(editor, range)\n\n if (!domRange) {\n return {\n caretPosition: null,\n selectionRects: [],\n }\n }\n\n const selectionRects: SelectionRect[] = []\n const nodeIterator = Editor.nodes(editor, {\n at: range,\n match: (n, p) => Text.isText(n) && (!shouldGenerateOverlay || shouldGenerateOverlay(n, p)),\n })\n\n let caretPosition: CaretPosition | null = null\n const isBackward = SlateRange.isBackward(range)\n\n for (const [node, path] of nodeIterator) {\n const domNode = DomEditor.toDOMNode(editor, node)\n\n const isStartNode = Path.equals(path, start.path)\n const isEndNode = Path.equals(path, end.path)\n\n let clientRects: DOMRectList | null = null\n\n if (isStartNode || isEndNode) {\n const nodeRange = document.createRange()\n\n nodeRange.selectNode(domNode)\n\n if (isStartNode) {\n nodeRange.setStart(domRange!.startContainer, domRange!.startOffset)\n }\n if (isEndNode) {\n nodeRange.setEnd(domRange.endContainer, domRange.endOffset)\n }\n\n clientRects = nodeRange.getClientRects()\n } else {\n clientRects = domNode.getClientRects()\n }\n\n const isCaret = isBackward ? isStartNode : isEndNode\n\n for (let i = 0; i < clientRects.length; i += 1) {\n const clientRect = clientRects.item(i)\n\n if (!clientRect) {\n continue\n }\n\n const isCaretRect = isCaret && (isBackward ? i === 0 : i === clientRects.length - 1)\n\n const top = clientRect.top - yOffset\n const left = clientRect.left - xOffset\n\n if (isCaretRect) {\n caretPosition = {\n height: clientRect.height,\n top,\n left: left + (isBackward || SlateRange.isCollapsed(range) ? 0 : clientRect.width),\n }\n }\n\n selectionRects.push({\n width: clientRect.width,\n height: clientRect.height,\n top,\n left,\n })\n }\n }\n\n return {\n selectionRects,\n caretPosition,\n }\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport type {\n CursorState,\n CursorStateChangeEvent,\n} from '@wangeditor-next/yjs'\nimport { CursorEditor } from '@wangeditor-next/yjs'\nimport {\n onUnmounted, ref, type ShallowRef, toRaw, watch,\n} from 'vue'\n\nexport const useRemoteCursorStates = <TCursorData extends Record<string, unknown>>(\n editorRef: ShallowRef<IDomEditor | undefined>,\n) => {\n const cursors = ref<Record<string, CursorState<TCursorData>>>({})\n\n // ===============监听Y.js的改变从而自动改变cursors===============\n const updateCursor = (clientId: number) => {\n const editor = toRaw(editorRef.value) as CursorEditor & IDomEditor\n\n if (!editor) { return }\n const state = CursorEditor.cursorState(editor, clientId)\n\n if (state === null) {\n delete cursors.value[clientId.toString()]\n return\n }\n cursors.value[clientId.toString()] = state as CursorState<TCursorData>\n }\n const changeHandler = (event: CursorStateChangeEvent) => {\n event.added.forEach((clientId: number) => {\n updateCursor(clientId)\n })\n event.removed.forEach((clientId: number) => {\n updateCursor(clientId)\n })\n event.updated.forEach((clientId: number) => {\n updateCursor(clientId)\n })\n }\n\n watch(\n () => editorRef.value,\n (newEditor, oldEditor) => {\n if (oldEditor) {\n CursorEditor.off(toRaw(oldEditor) as CursorEditor & IDomEditor, 'change', changeHandler)\n }\n if (newEditor) {\n // 拿到的是Vue3中的Proxy对象,跟原始对象是不同的映射\n CursorEditor.on(toRaw(newEditor) as CursorEditor & IDomEditor, 'change', changeHandler)\n }\n },\n {\n immediate: true,\n },\n )\n\n onUnmounted(() => {\n if (editorRef.value) {\n CursorEditor.off(toRaw(editorRef.value) as CursorEditor & IDomEditor, 'change', changeHandler)\n }\n })\n // ===============监听Y.js的改变从而自动改变cursors===============\n\n return {\n cursors,\n }\n}\n","import type { IDomEditor } from '@wangeditor-next/editor'\nimport { CursorEditor, CursorState } from '@wangeditor-next/yjs'\nimport type {\n BaseRange, NodeMatch, Range as SlateRange, Text,\n} from 'slate'\nimport {\n onUnmounted, type Ref, type ShallowRef, toRaw, watchEffect,\n} from 'vue'\nimport { computed, ref, watch } from 'vue'\n\nimport { getCursorRange } from '../utils/getCursorRange'\nimport type { CaretPosition, OverlayPosition, SelectionRect } from '../utils/getOverlayPosition'\nimport { getOverlayPosition } from '../utils/getOverlayPosition'\nimport { useEditorStatic } from './use-editor-static'\nimport { useRemoteCursorStates } from './useRemoteCursorStates'\n\nconst FROZEN_EMPTY_ARRAY = Object.freeze([])\n\nexport type CursorOverlayData<TCursorData extends Record<string, unknown>> =\n CursorState<TCursorData> & {\n range: BaseRange | null\n caretPosition: CaretPosition | null\n selectionRects: SelectionRect[]\n }\n\nexport type UseRemoteCursorOverlayPositionsOptions<T extends HTMLElement> = {\n shouldGenerateOverlay?: NodeMatch<Text>\n editorRef?: ShallowRef<IDomEditor | undefined>\n} & {\n containerRef?: Ref<T | undefined>\n // Whether to refresh the cursor overlay positions on container resize. Defaults\n // to true. If set to 'debounced', the remote cursor positions will be updated\n // each animation frame.\n refreshOnResize?: boolean | 'debounced'\n}\n\nexport function useRemoteCursorOverlayPositions<\n TCursorData extends Record<string, unknown>,\n TContainer extends HTMLElement = HTMLDivElement,\n>({\n containerRef,\n shouldGenerateOverlay,\n editorRef,\n ...opts\n}: UseRemoteCursorOverlayPositionsOptions<TContainer>) {\n // 1. 监听Y.js的change事件,从而改变cursorStates数据\n // 2. 监听cursorState数据 => 合并Y.js拿到的数据 => 形成最终的数据返回\n\n // 只有完全未传 editorRef 时,才从 context 获取\n // undefined == null 或者 null == null 都为true\n if (editorRef == null) {\n editorRef = useEditorStatic() // eslint-disable-line react-hooks/rules-of-hooks\n }\n\n let overlayPositionCache: WeakMap<SlateRange, OverlayPosition> = new WeakMap()\n\n // ===============监听Y.js的改变从而自动改变cursors===============\n const { cursors } = useRemoteCursorStates<TCursorData>(editorRef)\n\n // ===============cursors改变从而触发overlayPositions的重新计算===============\n const overlayPositions = ref<Record<string, OverlayPosition>>({})\n const computeOverlayPosition = (newCursorsValue: Record<string, CursorState<TCursorData>>) => {\n if (!editorRef.value) { return }\n // 监听containerRef.value挂载再触发一次computeOverlayPosition()\n // if (containerRef && !containerRef.value) {\n // return;\n // }\n // 跟React版本一致,支持【containerRef.value】为空,代表还没初始化完成dom\n const containerRect = containerRef?.value?.getBoundingClientRect()\n const xOffset = containerRect?.x ?? 0\n const yOffset = containerRect?.y ?? 0\n\n const editor = toRaw(editorRef.value!) as CursorEditor & IDomEditor\n\n let overlayPositionsChanged = Object.keys(overlayPositions.value).length !== Object.keys(newCursorsValue).length\n // 每次都更新位置\n const newOverlayPositions = Object.fromEntries(\n Object.entries(newCursorsValue).map(([key, state]) => {\n const range: SlateRange | null = state.relativeSelection && getCursorRange(editor, state)\n\n if (!range) {\n return [key, FROZEN_EMPTY_ARRAY]\n }\n\n if (overlayPositionCache.get(range)) {\n return [key, overlayPositionCache.get(range)]\n }\n\n const overlayPosition = getOverlayPosition(editor, range, {\n xOffset,\n yOffset,\n shouldGenerateOverlay,\n })\n\n overlayPositionCache.set(range, overlayPosition)\n overlayPositionsChanged = true\n\n return [key, overlayPosition]\n }),\n )\n\n if (overlayPositionsChanged) {\n overlayPositions.value = newOverlayPositions\n }\n }\n\n // ===============监听containerRef的变化===============\n const refreshOnResize = containerRef ? (opts.refreshOnResize ?? true) : false\n let rafId: number | null = null\n const observer = new ResizeObserver(() => {\n // 重新进行界面的渲染刷新\n overlayPositionCache = new WeakMap()\n if (refreshOnResize === 'debounced') {\n if (rafId) {\n cancelAnimationFrame(rafId)\n }\n\n rafId = requestAnimationFrame(() => {\n computeOverlayPosition(cursors.value)\n })\n } else {\n computeOverlayPosition(cursors.value)\n }\n })\n\n watchEffect(onCleanup => {\n if (refreshOnResize && containerRef!.value) {\n const element = containerRef!.value\n\n observer.observe(element)\n }\n\n onCleanup(() => {\n if (rafId) {\n cancelAnimationFrame(rafId)\n rafId = null\n }\n if (refreshOnResize && containerRef!.value) {\n const element = containerRef!.value\n\n observer.unobserve(element)\n }\n })\n })\n // ===============监听containerRef的变化===============\n\n // ===============监听editor滚动,实时更新cursors的计算===============\n const handleScroll = () => {\n overlayPositionCache = new WeakMap()\n if (rafId) {\n cancelAnimationFrame(rafId)\n }\n rafId = requestAnimationFrame(() => {\n computeOverlayPosition(cursors.value)\n })\n }\n\n watch(\n () => editorRef.value,\n (newEditor, oldEditor) => {\n if (oldEditor) {\n oldEditor.off('scroll', handleScroll)\n }\n if (newEditor) {\n newEditor.on('scroll', handleScroll)\n }\n },\n {\n immediate: true,\n },\n )\n\n onUnmounted(() => {\n if (editorRef.value) {\n editorRef.value.off('scroll', handleScroll)\n }\n })\n // ===============监听editor滚动,实时更新cursors的计算===============\n\n // 跟React的useLayoutEffect相同逻辑,只是Vue不需要重新渲染,只需要监听依赖的数据\n // containerRef可能为空,Vue支持监听null/undefined,不会进行响应式收集\n // overlayPosition的计算依赖于:当前传入的DOM-containerRef(需要一开始没挂载,需要一段时间才挂载),cursors的值变化\n // computeOverlayPosition()有使用缓存overlayPositionCache,即使跟observer.observe(element)重复触发,也不会重复赋值overlayPositions.value\n watch(\n () => [cursors.value, containerRef?.value, editorRef.value],\n () => {\n if (!editorRef.value) {\n return\n }\n // 重新计算overlayPosition\n computeOverlayPosition(cursors.value)\n },\n {\n immediate: true,\n flush: 'sync',\n deep: true,\n },\n )\n // ===============cursors改变从而触发overlayPositions的重新计算===============\n\n // ------------------------根据cursors和overlayPositions进行overlayData的计算------------------------\n type OverlayDataType = CursorState<TCursorData> & {\n range: BaseRange | null\n } & OverlayPosition\n const overlayData = computed(() => {\n if (!editorRef.value) {\n return []\n }\n const editor = editorRef.value as CursorEditor & IDomEditor\n\n return Object.entries(cursors.value).map(([clientId, state]) => {\n const range = state.relativeSelection ? getCursorRange(editor, state) : null\n const overlayPosition = overlayPositions.value[clientId]\n\n return {\n ...state,\n range,\n caretPosition: overlayPosition?.caretPosition ?? null,\n selectionRects: overlayPosition?.selectionRects ?? FROZEN_EMPTY_ARRAY,\n }\n }) as Array<OverlayDataType>\n })\n // ------------------------根据cursors和overlayPositions进行overlayData的计算------------------------\n\n const refresh = () => {\n overlayPositionCache = new WeakMap()\n computeOverlayPosition(cursors.value)\n }\n\n return {\n cursors: overlayData,\n refresh,\n }\n}\n"],"names":["EDITOR_CONTEXT_KEY","Symbol","useEditorStatic","context","inject","Error","editor","CHILDREN_TO_CURSOR_STATE_TO_RANGE","WeakMap","getCursorRange","cursorState","relativeSelection","cursorStates","get","children","set","range","undefined","relativeRangeToSlateRange","sharedRoot","e","getOverlayPosition","_a","yOffset","xOffset","shouldGenerateOverlay","_c","__read","SlateRange","edges","start","end","domRange","DomEditor","toDOMRange","reactEditorToDomRangeSafe","caretPosition","selectionRects","nodeIterator","Editor","nodes","at","match","n","p","Text","isText","isBackward","nodeIterator_1","__values","nodeIterator_1_1","next","_d","value","node","path","domNode","toDOMNode","isStartNode","Path","equals","isEndNode","clientRects","nodeRange","document","createRange","selectNode","setStart","startContainer","startOffset","setEnd","endContainer","endOffset","getClientRects","isCaret","i","length","clientRect","item","isCaretRect","top_1","top","left","height","isCollapsed","width","push","useRemoteCursorStates","editorRef","cursors","ref","updateCursor","clientId","toRaw","state","CursorEditor","toString","changeHandler","event","added","forEach","removed","updated","watch","newEditor","oldEditor","off","on","immediate","onUnmounted","FROZEN_EMPTY_ARRAY","Object","freeze","provide","containerRef","opts","__rest","overlayPositionCache","overlayPositions","computeOverlayPosition","newCursorsValue","containerRect","getBoundingClientRect","_b","x","y","overlayPositionsChanged","keys","newOverlayPositions","fromEntries","entries","map","key","overlayPosition","refreshOnResize","rafId","observer","ResizeObserver","cancelAnimationFrame","requestAnimationFrame","watchEffect","onCleanup","element","observe","unobserve","handleScroll","flush","deep","overlayData","computed","__assign","refresh"],"mappings":"qdAOA,IAAMA,EAAqBC,OAAO,iBAQ3B,IAAMC,EAAkB,WAC7B,IAAMC,EAAUC,EAAAA,OAAsBJ,GAEtC,IAAKG,EAEH,MAAM,IAAIE,MACR,4HAGJ,OAAOF,EAAQG,MACjB,+hBCpBA,IAAMC,EAA+F,IAAIC,QAEnG,SAAUC,EACdH,EACAI,GAEA,IAAKA,EAAYC,kBACf,OAAO,KAGT,IAAIC,EAAeL,EAAkCM,IAAIP,EAAOQ,UAE3DF,IACHA,EAAe,IAAIJ,QACnBD,EAAkCQ,IAAIT,EAAOQ,SAAUF,IAGzD,IAAII,EAAQJ,EAAaC,IAAIH,GAE7B,QAAcO,IAAVD,EACF,IACEA,EAAQE,EAAAA,0BAA0BZ,EAAOa,WAAYb,EAAQI,EAAYC,mBAEzEC,EAAaG,IAAIL,EAAaM,EAChC,CAAE,MAAOI,GACP,OAAO,IACT,CAGF,YAAiBH,IAAVD,EAAsB,KAAOA,CACtC,UCGgBK,EACdf,EACAU,EACAM,WAAEC,YAASC,EAAOF,EAAAE,QAAEC,EAAqBH,EAAAG,sBAEnCC,EAAAC,EAAeC,EAAAA,MAAWC,MAAMb,GAAM,GAArCc,EAAKJ,EAAA,GAAEK,OACRC,EArCR,SAAmC1B,EAAoBU,GACrD,IACE,OAAOiB,YAAUC,WAAW5B,EAAQU,EACtC,CAAE,MAAOI,GACP,OAAO,IACT,CACF,CA+BmBe,CAA0B7B,EAAQU,GAEnD,IAAKgB,EACH,MAAO,CACLI,cAAe,KACfC,eAAgB,IAIpB,IAAMA,EAAkC,GAClCC,EAAeC,EAAAA,OAAOC,MAAMlC,EAAQ,CACxCmC,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ACLoB,cAA6C,QAA9BuF,EAAAU,aAAe,EAAfA,EAAiBjG,qBAAa,IAAAuF,EAAAA,EAAI,KACjDtF,eAA+C,QAA/BX,EAAA2G,aAAe,EAAfA,EAAiBhG,sBAAc,IAAAX,EAAAA,EAAIoF,GAEvD,EACF,GAQA,MAAO,CACLrB,QAAS2D,EACTG,QAPc,WACdlC,EAAuB,IAAI7G,QAC3B+G,EAAuB9B,EAAQpC,MACjC,EAMF"}
@@ -3,4 +3,5 @@
3
3
  * @author wangfupeng
4
4
  */
5
5
  import { IDomEditor } from '@wangeditor-next/core';
6
- export declare const ELEM_TO_EDITOR: WeakMap<import("packages/custom-types").CustomElement, IDomEditor>;
6
+ import { BaseElement } from 'slate';
7
+ export declare const ELEM_TO_EDITOR: WeakMap<BaseElement, IDomEditor>;
@@ -1,4 +1,5 @@
1
1
  import { IButtonMenu, IDomEditor } from '@wangeditor-next/core';
2
+ import { NodeEntry } from 'slate';
2
3
  import TableProperty, { FieldName } from './TableProperty';
3
4
  declare class CellProperty extends TableProperty implements IButtonMenu {
4
5
  readonly title: string;
@@ -8,6 +9,6 @@ declare class CellProperty extends TableProperty implements IButtonMenu {
8
9
  readonly modalWidth = 360;
9
10
  readonly menu = "cell";
10
11
  readonly propertyFields: FieldName[];
11
- getModalContentNode(editor: IDomEditor): import("slate").NodeEntry<import("../../utils").WithType<import("packages/custom-types").CustomElement>>;
12
+ getModalContentNode(editor: IDomEditor): NodeEntry;
12
13
  }
13
14
  export default CellProperty;
@@ -3,6 +3,7 @@
3
3
  * @author hsuna
4
4
  */
5
5
  import { IButtonMenu, IDomEditor } from '@wangeditor-next/core';
6
+ import { NodeEntry } from 'slate';
6
7
  export type FieldName = 'borderStyle' | 'borderColor' | 'borderWidth' | 'backgroundColor' | 'textAlign' | 'verticalAlign';
7
8
  type SelectOption = {
8
9
  value: string;
@@ -35,7 +36,7 @@ declare class TableProperty implements IButtonMenu {
35
36
  isActive(_editor: IDomEditor): boolean;
36
37
  isDisabled(editor: IDomEditor): boolean;
37
38
  exec(_editor: IDomEditor, _value: string | boolean): void;
38
- getModalContentNode(editor: IDomEditor): import("slate").NodeEntry<import("../../utils").WithType<import("packages/custom-types").CustomElement>>;
39
+ getModalContentNode(editor: IDomEditor): NodeEntry;
39
40
  getModalPositionNode(_editor: IDomEditor): null;
40
41
  getModalContentElem(editor: IDomEditor): Element | null;
41
42
  getPanelContentElem(editor: any, { mark, selectedColor, callback }: {
@@ -1,5 +1,6 @@
1
+ import { BaseEditor, BaseElement } from 'slate';
1
2
  import { NodeEntryWithContext } from '../utils';
2
3
  /** Weak reference between the `Editor` and the selected elements */
3
- export declare const EDITOR_TO_SELECTION: WeakMap<import("slate").BaseEditor, NodeEntryWithContext[][]>;
4
+ export declare const EDITOR_TO_SELECTION: WeakMap<BaseEditor, NodeEntryWithContext[][]>;
4
5
  /** Weak reference between the `Editor` and a set of the selected elements */
5
- export declare const EDITOR_TO_SELECTION_SET: WeakMap<import("slate").BaseEditor, WeakSet<import("packages/custom-types").CustomElement>>;
6
+ export declare const EDITOR_TO_SELECTION_SET: WeakMap<BaseEditor, WeakSet<BaseElement>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wangeditor-next/yjs-for-vue",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Vue specific components/utils for wangeditor-next-yjs.",
5
5
  "author": "wbccb",
6
6
  "type": "module",
@@ -48,8 +48,8 @@
48
48
  "y-protocols": "^1.0.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "@wangeditor-next/editor": ">=6.0.0",
52
- "@wangeditor-next/yjs": "^2.0.2",
51
+ "@wangeditor-next/editor": ">=6.0.1",
52
+ "@wangeditor-next/yjs": "^2.0.3",
53
53
  "vue": ">=3.5.18",
54
54
  "slate": "^0.124.0",
55
55
  "yjs": "^13.5.29"