@bayou/doc-common
Advanced tools
Comparing version 1.0.1 to 1.0.6
@@ -5,5 +5,5 @@ // Copyright 2016-2018 the Bayou Authors (Dan Bornstein et alia). | ||
import Delta from 'quill-delta'; | ||
import { Text } from '@bayou/config-common'; | ||
import { BaseDelta } from '@bayou/ot-common'; | ||
import { Logger } from '@bayou/see-all'; | ||
import { TBoolean, TObject } from '@bayou/typecheck'; | ||
@@ -37,21 +37,3 @@ import { Errors } from '@bayou/util-common'; | ||
} else { | ||
try { | ||
TObject.check(quillDelta, Delta); | ||
ops = quillDelta.ops; | ||
} catch (e) { | ||
if ((typeof quillDelta === 'object') && (quillDelta.constructor.name === 'Delta')) { | ||
// The version of `Delta` used by Quill is different than the one we | ||
// specified in our `package.json`. Even though it will often happen | ||
// to work if we just let it slide (e.g. by snarfing `ops` out of the | ||
// object and running with it), we don't want to end up shipping two | ||
// versions of `Delta` to the client; so, instead of just blithely | ||
// accepting this possibility, we reject it here and report an error | ||
// which makes it easy to figure out what happened. Should you find | ||
// yourself looking at this error, the right thing to do is look at | ||
// Quill's `package.json` and update the `quill-delta` dependency in | ||
// this module to what you find there. | ||
throw Errors.badUse('Divergent versions of `quill-delta` package.'); | ||
} | ||
throw e; | ||
} | ||
ops = BodyDelta._opsOfQuillDelta(quillDelta); | ||
} | ||
@@ -100,3 +82,3 @@ | ||
const ops = this.ops.map(op => op.toQuillForm()); | ||
return new Delta(ops); | ||
return new Text.Delta(ops); | ||
} | ||
@@ -204,2 +186,45 @@ | ||
} | ||
/** | ||
* Checks that the argument is a Quill delta, and if so returns the `ops` | ||
* array inside it. Throws an error if not. | ||
* | ||
* @param {Delta} quillDelta Quill delta instance. | ||
* @returns {array} Array of Quill operations that `delta` contains. | ||
*/ | ||
static _opsOfQuillDelta(quillDelta) { | ||
try { | ||
TObject.check(quillDelta, Text.Delta); | ||
} catch (e) { | ||
if ((typeof quillDelta === 'object') && (quillDelta.constructor.name === 'Delta')) { | ||
// The version of `Delta` used by Quill is different than the one we | ||
// specified in our `package.json`. Even though it will often happen | ||
// to work if we just let it slide (e.g. by snarfing `ops` out of the | ||
// object and running with it), we don't want to end up shipping two | ||
// versions of `Delta` to the client; so, instead of just blithely | ||
// accepting this possibility, we reject it here and report an error | ||
// which makes it easy to figure out what happened. Should you find | ||
// yourself looking at this error, the likely right thing to do is | ||
// look at `package.json` in the version of Quill you are using, and | ||
// update what is returned from | ||
// {@link @bayou/config-common/Text#Delta} to match what Quill has as | ||
// its `quill-delta` dependency. | ||
// **TODO:** Because reasons, this complaint has been demoted to | ||
// from "actual error" to "stern warning," for the time being. The | ||
// `throw` should be restored at the earliest opportunity, along with | ||
// removing the surrounding bits that let this case fall through. | ||
//throw Errors.badUse('Divergent versions of `quill-delta` package.'); | ||
if (!BodyDelta._divergentComplaintMade) { | ||
// NB: This is the only code in this module that uses `see-all`. | ||
BodyDelta._divergentComplaintMade = true; | ||
new Logger('doc-common').warn('Divergent versions of `quill-delta` package!'); | ||
} | ||
} else { | ||
throw e; | ||
} | ||
} | ||
return quillDelta.ops; | ||
} | ||
} |
@@ -7,11 +7,11 @@ { | ||
"dependencies": { | ||
"@bayou/codec": "1.0.1", | ||
"@bayou/config-common": "1.0.1", | ||
"@bayou/deps-quill-common": "1.0.1", | ||
"@bayou/ot-common": "1.0.1", | ||
"@bayou/typecheck": "1.0.1", | ||
"@bayou/util-common": "1.0.1" | ||
"@bayou/codec": "1.0.6", | ||
"@bayou/config-common": "1.0.6", | ||
"@bayou/ot-common": "1.0.6", | ||
"@bayou/see-all": "1.0.6", | ||
"@bayou/typecheck": "1.0.6", | ||
"@bayou/util-common": "1.0.6" | ||
}, | ||
"name": "@bayou/doc-common", | ||
"version": "1.0.1" | ||
"version": "1.0.6" | ||
} |
@@ -7,4 +7,4 @@ // Copyright 2016-2018 the Bayou Authors (Dan Bornstein et alia). | ||
import { describe, it } from 'mocha'; | ||
import Delta from 'quill-delta'; | ||
import { Text } from '@bayou/config-common'; | ||
import { BodyChange, BodyDelta, BodyOp } from '@bayou/doc-common'; | ||
@@ -83,3 +83,3 @@ import { Timestamp } from '@bayou/ot-common'; | ||
test(0, { ops: [] }); | ||
test(0, new Delta()); // Needs to be a `BodyDelta`. | ||
test(0, new Text.Delta()); // Needs to be a `BodyDelta`. | ||
@@ -86,0 +86,0 @@ // Invalid `timestamp`. |
@@ -7,5 +7,5 @@ // Copyright 2016-2018 the Bayou Authors (Dan Bornstein et alia). | ||
import { describe, it } from 'mocha'; | ||
import Delta from 'quill-delta'; | ||
import { inspect } from 'util'; | ||
import { Text } from '@bayou/config-common'; | ||
import { BodyDelta, BodyOp } from '@bayou/doc-common'; | ||
@@ -43,3 +43,3 @@ | ||
const ops = [{ insert: 'foo' }, { retain: 10 }, { insert: 'bar', attributes: { bold: true } }]; | ||
const quillDelta = new Delta(ops); | ||
const quillDelta = new Text.Delta(ops); | ||
const result = BodyDelta.fromQuillForm(quillDelta); | ||
@@ -371,3 +371,3 @@ | ||
const result = delta.toQuillForm(); | ||
assert.instanceOf(result, Delta); | ||
assert.instanceOf(result, Text.Delta); | ||
@@ -374,0 +374,0 @@ const origOps = delta.ops; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162236
4255
+ Added@bayou/see-all@1.0.6
+ Added@bayou/codec@1.0.6(transitive)
+ Added@bayou/config-common@1.0.6(transitive)
+ Added@bayou/injecty@1.0.6(transitive)
+ Added@bayou/ot-common@1.0.6(transitive)
+ Added@bayou/see-all@1.0.6(transitive)
+ Added@bayou/typecheck@1.0.6(transitive)
+ Added@bayou/util-common@1.0.6(transitive)
+ Added@bayou/util-core@1.0.6(transitive)
- Removed@bayou/deps-quill-common@1.0.1
- Removed@bayou/codec@1.0.1(transitive)
- Removed@bayou/config-common@1.0.1(transitive)
- Removed@bayou/deps-quill-common@1.0.1(transitive)
- Removed@bayou/injecty@1.0.1(transitive)
- Removed@bayou/ot-common@1.0.1(transitive)
- Removed@bayou/typecheck@1.0.1(transitive)
- Removed@bayou/util-common@1.0.1(transitive)
- Removed@bayou/util-core@1.0.1(transitive)
- Removedcall-bind@1.0.8(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removeddeep-equal@1.1.2(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedextend@3.0.2(transitive)
- Removedfast-diff@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis-arguments@1.2.0(transitive)
- Removedis-date-object@1.1.0(transitive)
- Removedis-regex@1.2.1(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedobject-is@1.1.6(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedquill-delta@3.6.3(transitive)
- Removedregexp.prototype.flags@1.5.4(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
Updated@bayou/codec@1.0.6
Updated@bayou/config-common@1.0.6
Updated@bayou/ot-common@1.0.6
Updated@bayou/typecheck@1.0.6
Updated@bayou/util-common@1.0.6