diff --git a/.eslintrc.js b/.eslintrc.js index 677f234..3b97b8c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,19 +1,19 @@ module.exports = { - 'env': { - 'browser': true, - 'es6': true, - 'node': true - }, - 'extends': 'eslint:recommended', - 'globals': { - 'Atomics': 'readonly', - 'SharedArrayBuffer': 'readonly' - }, - 'parserOptions': { - 'ecmaVersion': 2018, - 'sourceType': 'module' - }, - 'rules': { - 'no-undef': 'off' - } + env: { + browser: true, + es6: true, + node: true, + }, + extends: 'eslint:recommended', + globals: { + Atomics: 'readonly', + SharedArrayBuffer: 'readonly', + }, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + }, + rules: { + 'no-undef': 'off', + }, }; diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +dist diff --git a/src/integration.js b/src/integration.js index 677b4b7..22930ee 100644 --- a/src/integration.js +++ b/src/integration.js @@ -7,7 +7,13 @@ import { canOpAffectPath } from './canOpAffectPath'; // https://codemirror.net/6/examples/collab/ // https://github.com/yjs/y-codemirror.next/blob/main/src/y-sync.js#L107 // https://github.com/vizhub-core/vizhub/blob/main/vizhub-v2/packages/neoFrontend/src/pages/VizPage/Body/Editor/CodeEditor/CodeArea/CodeAreaCodeMirror5/index.js -export const json1Sync = ({ shareDBDoc, path = [], debug = false }) => +export const json1Sync = ({ + shareDBDoc, + path = [], + json1, + textUnicode, + debug = false, +}) => ViewPlugin.fromClass( class { // ShareDB --> CodeMirror @@ -57,12 +63,24 @@ export const json1Sync = ({ shareDBDoc, path = [], debug = false }) => console.log( ' generated json1 op: ' + JSON.stringify( - changesToOpJSON1(path, update.changes, update.startState.doc) + changesToOpJSON1( + path, + update.changes, + update.startState.doc, + json1, + textUnicode + ) ) ); } shareDBDoc.submitOp( - changesToOpJSON1(path, update.changes, update.startState.doc) + changesToOpJSON1( + path, + update.changes, + update.startState.doc, + json1, + textUnicode + ) ); this.lock = false; } diff --git a/src/translation.js b/src/translation.js index 37d1eb5..82ae47f 100644 --- a/src/translation.js +++ b/src/translation.js @@ -1,6 +1,3 @@ -import json1 from 'ot-json1'; -import textUnicode from 'ot-text-unicode'; - // This module is able to translate from CodeMirror ChangeSet to OT ops // and back, for both json0 and json1 OT types. // @@ -37,7 +34,7 @@ export const changesToOpJSON0 = (path, changeSet, doc) => { }; // Converts a CodeMirror ChangeSet to a json1 OT op. -export const changesToOpJSON1 = (path, changeSet, doc) => { +export const changesToOpJSON1 = (path, changeSet, doc, json1, textUnicode) => { const unicodeOp = []; // Iterate over all changes in the ChangeSet. diff --git a/test/testIntegration.js b/test/testIntegration.js index 62a604e..2476eea 100644 --- a/test/testIntegration.js +++ b/test/testIntegration.js @@ -1,11 +1,11 @@ import * as assert from 'assert'; -import { json1Sync, canOpAffectPath } from '../src/index'; +import json1 from 'ot-json1'; +import textUnicode from 'ot-text-unicode'; import { EditorState, ChangeSet } from '@codemirror/state'; import { EditorView, ViewPlugin } from '@codemirror/view'; import { JSDOM } from 'jsdom'; - -import json1 from 'ot-json1'; import ShareDB from 'sharedb'; +import { json1Sync, canOpAffectPath } from '../src/index'; ShareDB.types.register(json1.type); @@ -34,7 +34,10 @@ const createEditor = ({ shareDBDoc, path, additionalExtensions = [] }) => { const view = new EditorView({ state: EditorState.create({ doc: getAtPath(shareDBDoc, path), - extensions: [json1Sync({ shareDBDoc, path }), ...additionalExtensions], + extensions: [ + json1Sync({ shareDBDoc, path, json1, textUnicode }), + ...additionalExtensions, + ], }), }); return view; diff --git a/test/verify.js b/test/verify.js index bb88fd3..bd09675 100644 --- a/test/verify.js +++ b/test/verify.js @@ -92,7 +92,10 @@ export const verify = (options) => { it('changesToOpJSON1', () => { const state = EditorState.create({ doc: atPath(before, path) }); const changeSet = ChangeSet.of(changes, before.length); - assert.deepEqual(changesToOpJSON1(path, changeSet, state.doc), opJSON1); + assert.deepEqual( + changesToOpJSON1(path, changeSet, state.doc, json1, textUnicode), + opJSON1 + ); }); it('applied changes should match expected text', () => {