Coder Social home page Coder Social logo

How to build? about rich-text HOT 4 CLOSED

ottypes avatar ottypes commented on July 17, 2024
How to build?

from rich-text.

Comments (4)

jhchen avatar jhchen commented on July 17, 2024

If you want to build for the frontend you'd probably want to use browserify. Otherwise this project is currently packaged as a backend node.js project.

from rich-text.

pollen8 avatar pollen8 commented on July 17, 2024

Thanks for replying
I'd tried that but hadn't had any success so far - I'll keep chipping away at the issue though.

from rich-text.

jhchen avatar jhchen commented on July 17, 2024

What issue did you run into with browserify?

from rich-text.

pollen8 avatar pollen8 commented on July 17, 2024

Hi
My issue was that the rich-text ot type wasn't being assigned to the browser window.ottypes global object.
Using browserify I had to add this to the bottom of rich-text/lib/type.js:

if (typeof(window) !== 'undefined') {
    var _types = window.ottypes = window.ottypes || {};
    var _t = module.exports;
    _types['rich-text'] = _t.type;

    if (_t.uri) _types[_t.uri] = _t.type;
}

I'd hacked that from the 'after.js' script.

Then I browserified type.js and placed it in node_modules/share/webclient/

In my node app script i've

var livedb = require('livedb');
var sharejs = require('share');
var express = require('express');
var Duplex = require('stream').Duplex;
var browserChannel = require('browserchannel').server;
var backend = livedb.client(livedb.memory());
var share = require('share').server.createClient({backend: backend});

var otTypes = require('ottypes');
var richText = require('rich-text');

var app = express();
app.use(express.static('public'));

// Load static share.js file into front end
app.use(express.static(sharejs.scriptsDir));

// Register the share ot custom type!
livedb.ot.registerType(richText.type);

My front end js is currently looking like this:

 var socket = new BCSocket(null, {reconnect: true});
        var sjs = new sharejs.Connection(socket);

        sharejs.registerType(window.ottypes['rich-text']);

        var doc = sjs.get('docs', 'hello');

        // Subscribe to changes
        doc.subscribe();

        // This will be called when we have a live copy of the server's data.
        doc.whenReady(function() {
            console.log('doc ready, data: ', doc, doc.getSnapshot());

            // Create a rich-text doc 
            if (!doc.type) {
                console.log('doc has not type - trying to create a rich-text doc');
                doc.create('rich-text', '');
                console.log('created as ', doc);
            }

            var editor = new Quill('#editor', {
                modules: {
                    'authorship': { authorId: 'galadriel', enabled: true },
                    'multi-cursor': true,
                    'toolbar': { container: '#toolbar' },
                    'link-tooltip': true
                },
                theme: 'snow'
            });

            editor.on('selection-change', function(range) {
                console.log('selection-change', range)
            });
            editor.on('text-change', function(delta, source) {
                console.log('text-change', delta, source)
                doc.submitOp(delta, function (error, appliedOp) {
console.log('submit op done', error, appliedOp);
                });
            });

// This is not currently picking up other clients changes
            doc.on('remoteop', function(op) {
                console.log('remote op received', op);
            })
        });

I'm not yet picking up the ot changes - but Im pretty happy so far as I seem to be on the right path

from rich-text.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.