首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在角8中实现多个游标?

如何在角8中实现多个游标?
EN

Stack Overflow用户
提问于 2019-11-07 04:08:53
回答 2查看 957关注 0票数 0

我正试图在Quill中实现协作编辑,为此,我在后端使用了角作为前端和节点。我已经设置了蒙戈适配器和ngx模块在前端的共享。但是,我很困惑如何在角8中实现毛刺游标模块?

我的插座服务

代码语言:javascript
复制
import { Injectable } from '@angular/core';

@Injectable({
 providedIn: 'root'
})
export class SocketsService {
 connection: any;
 sharedb: any;
 socket:any;
 doc: any;

 constructor() {
   this.sharedb = require('sharedb/lib/client');
   this.sharedb.types.register(require('rich-text').type);
   // Open WebSocket connection to ShareDB server
   this.socket = new WebSocket('ws://localhost:8080/sharedb');
   this.connection = new this.sharedb.Connection(this.socket);
   this.doc = this.connection.get('examples', 'richtext');
 }
}

我的编辑器组件

代码语言:javascript
复制
import {ViewChild, Component, OnInit} from '@angular/core';
import { QuillEditorComponent } from 'ngx-quill';
import QuillCursors from 'quill-cursors';
import {SocketsService} from '../sockets.service';
import {HttpClient} from '@angular/common/http';
import Quill from 'quill';
import 'quill-mention';
import jsondecoder from 'jsonwebtoken/decode.js'
Quill.register('modules/cursors', QuillCursors);
const Tooltip = Quill.import('ui/tooltip'); 

@Component({
  selector: 'app-editor',
  templateUrl: './editor.component.html',
  styleUrls: ['./editor.component.css']
})

export class EditorComponent implements OnInit{
  @ViewChild(QuillEditorComponent, { static: true })
  editor: QuillEditorComponent;
  content = '';
  myTooltip:any;
  public modules: any;
  private socket: any;
  private http: HttpClient;
  ngOnInit(){
  }

  constructor()
  {
    this.socket = new SocketsService();

    this.modules = {
      cursors: {
        transformOnTextChange: true
      },
      mention: {
        allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
        onSelect: (item, insertItem) => {
          const editor = this.editor.quillEditor as Quill
          insertItem(item) // necessary because quill-mention triggers changes as 'api' instead of 'user'
          editor.insertText(editor.getLength() - 1, '', 'user')
        },
        source: (searchTerm, renderList) => {
          const values = [
            { id: 1, value: 'Alec'},
            { id: 2, value: 'Irshad'},
            { id: 3, value: 'Anmol'},
            { id: 4, value: 'MunMun'},
            { id: 5, value:'Zoya'}
          ]
          if (searchTerm.length === 0) {
            renderList(values, searchTerm)
          } else {
            const matches = []
            values.forEach((entry) => {
              if (entry.value.toLowerCase().indexOf(searchTerm.toLowerCase()) !== -1) {
                matches.push(entry)
              }
            })
            renderList(matches, searchTerm)
          }
        }
      }
    }
  }

  editorCreated($event){
    this.socket.doc.subscribe((err)=>{ // Get initial value of document and subscribe to changes
      if(err) throw err;
       $event.setContents(this.socket.doc.data);
      this.socket.doc.on('op', (op, source)=>{
        if (source === 'quill') return;
        $event.updateContents(op);
      });
    });
  }

  logChanged($event)
  { 
    if ($event.source !== 'user') return;
    this.socket.doc.submitOp($event.delta, {source: 'quill'});
  }
}

我的节点后端代码

代码语言:javascript
复制
var ShareDB = require('@teamwork/sharedb');
var richText = require('rich-text');
ShareDB.types.register(richText.type);
const mongodb = require('mongodb');
const db = require('@teamwork/sharedb-mongo')({mongo: function(callback) {
  mongodb.connect('mongodb://localhost:27017/test',{useUnifiedTopology: true},callback);
}});
const shareDBServer= new ShareDB({db, disableDocAction: true, disableSpaceDelimitedActions: true});
var connection = shareDBServer.connect();
var doc = connection.get('examples', 'richtext');
doc.fetch(function(err) {
  if (err) throw err;
  if (doc.type === null) {
    doc.create([{insert: 'Document Ready'}], 'rich-text', callback);
    return;
  }
});
 var wss = new WebSocket.Server({
    noServer: true
  });

  wss.on('connection', function(ws, req) {
    ws.isAlive = true;

    var stream = new WebSocketJSONStream(ws);
    shareDBServer.listen(stream);

    ws.on('pong', function(data, flags) {
      ws.isAlive = true;
    });

    ws.on('error', function(error) {
        console.log('Error');
    });
 });

我的问题是在导入编辑器组件中的笔游标模块之后,如何实现它?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-11-07 05:18:40

首先,您必须将quill安装到您的角项目中。

代码语言:javascript
复制
npm install ngx-quill

对于使用角< v5.0.0的项目,请安装npm install ngx-quill@1.6.0

in app.module.ts从ngx导入QuillModule:

代码语言:javascript
复制
import { QuillModule } from 'ngx-quill';

将QuillModule添加到导入NgModule:

代码语言:javascript
复制
@NgModule({
  imports: [
    ...,

    QuillModule.forRoot()
  ],
  ...
})
class YourModule { ... }

在模板中使用<quill-editor></quill-editor>添加默认的查询编辑器

参考ngx-quill

票数 0
EN

Stack Overflow用户

发布于 2020-10-01 17:14:02

如果您指的是协作编辑,请尝试使用Quill的Yjs。他们已经整合了CRDT的全面合作编辑。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58741861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档