share / sharedb

Realtime database backend based on Operational Transformation (OT)
Other
6.24k stars 453 forks source link

Brainstorm to have two or more rich-texts in the same document (and other "basics" types). #232

Open ammontes opened 6 years ago

ammontes commented 6 years ago

Hello,

First of all, I must say that this library is really amazing because it is so powerful and it can be integrated easily with MongoDB or Quill.

Our question is about "hybrid document type". We are developing a website angular-6 application that allows filling in the information about the events. Each event has several rich-texts and other kinds of data such as dates, numbers, arrays of keywords... I did some tests using the counter example and it is easy to put several fields in the same document and carry out the changes. The json-OT documentation is enough to adapt this example.

However, I would like to include several rich-texts in the same documents. The "rich-text" is a kind of sharedb document and the changes are included in "ops" field. I do not mind if I need to include the "ops" field in another field.

{"_id":"richtext","ops":[{"insert":"Hi!"}],"_type":"http://sharejs.org/types/rich-text/v1","_v":1,"_m":{"ctime":1532731794839,"mtime":1532731794839},"_o":{"$oid":"5b5ba19298ddc636ccb906e8"}}

{"_id":"counter","numClicks":4,"description":{ <==== richtext ops and others fields====> },"array":[{"value":-4},{"value":2}],"_type":"http://sharejs.org/types/JSONv0","_v":10,"_m":{"ctime":1532728667948,"mtime":1532729189936},"_o":{"$oid":"5b5b9765d4c9a433aa14b8c8"}}

What part of the project (quill-delta, rich-text...) should I read/understand/modify to carry out my goal? Do you know a more correct way to get my goal? I would like to avoid to have a document per "rich-text area" of the event...

gkubisa commented 6 years ago

Subtypes in json0 should allow you to embed multiple rich-text documents in a json document.

ammontes commented 6 years ago

Thank you for your answer. I carried out more tests and I got a document with a rich-text field and two number fields. So, I guess that the following steps to have many rich-text fields and other kinds of fields in the same document will be easy.

I am going to do more tests and I am going to increment the complexity of the example. Maybe, I will share the example because it would be useful for other people.

However, I have a question about the implementation. To embed other kinds of fields, it is necessary to use the ".registerSubtype(richText.type);" function. Where and How is the correct way to call this function? I modified the json0.ts of ot-json0 library... but I am sure that it is a botched action... (richText is the rich-text library) var richText = require('rich-text');

gkubisa commented 6 years ago

Executing require('json0').type.registerSubtype(require('rich-text').type) at the startup time of your app would work fine.

curran commented 5 years ago

Suggesting to close this due to inactivity. The issue seems to have been resolved.

alecgibson commented 5 years ago

Agreed. @gkubisa is correct - you can have multiple rich-text documents in a json0 document.