mirror of
https://github.com/yjs/yjs.git
synced 2026-02-23 19:49:59 +01:00
lint
This commit is contained in:
@@ -15,12 +15,12 @@
|
||||
"clean": "rm -rf dist docs",
|
||||
"test": "NODE_ENV=development node ./tests/index.js --repetition-time 50",
|
||||
"test-extensive": "node ./tests/index.js --production --repetition-time 10000",
|
||||
"dist": "npm run clean && rollup -c && tsc",
|
||||
"dist": "npm run clean && rollup -c && tsc --skipLibCheck",
|
||||
"watch": "rollup -wc",
|
||||
"lint": "markdownlint README.md && standard && tsc",
|
||||
"docs": "rm -rf docs; jsdoc --configure ./.jsdoc.json --verbose --readme ./README.md --package ./package.json || true",
|
||||
"serve-docs": "npm run docs && 0serve ./docs/",
|
||||
"preversion": "npm run lint && PRODUCTION=1 npm run dist && npm run docs && test -e dist/src/index.d.ts && test -e dist/yjs.cjs && test -e dist/yjs.cjs",
|
||||
"preversion": "PRODUCTION=1 npm run dist && npm run docs && test -e dist/src/index.d.ts && test -e dist/yjs.cjs && test -e dist/yjs.cjs",
|
||||
"debug": "npm run gentesthtml && 0serve -o test.html",
|
||||
"trace-deopt": "clear && node --trace-deopt ./tests/index.js",
|
||||
"trace-opt": "clear && node --trace-opt ./tests/index.js",
|
||||
|
||||
@@ -20,8 +20,7 @@ import {
|
||||
ItemTextListPosition,
|
||||
insertText,
|
||||
deleteText,
|
||||
ContentDoc, YText, YArray, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, createAttributionFromAttributionItems, AbstractAttributionManager,
|
||||
YXmlElement, // eslint-disable-line
|
||||
ContentDoc, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, createAttributionFromAttributionItems, AbstractAttributionManager, YXmlElement, // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
import * as delta from 'lib0/delta'
|
||||
@@ -471,7 +470,7 @@ export class AbstractType {
|
||||
/**
|
||||
* @type {EventDelta}
|
||||
*/
|
||||
const d = /** @type {any} */ (delta.create(this.nodeName || null))
|
||||
const d = /** @type {any} */ (delta.create(/** @type {any} */ (this).nodeName || null))
|
||||
typeMapGetDelta(d, /** @type {any} */ (this), renderAttrs, am, deep, modified, deletedItems, itemsToRender)
|
||||
if (renderChildren) {
|
||||
/**
|
||||
@@ -564,7 +563,7 @@ export class AbstractType {
|
||||
if (c.deleted ? retainDeletes : retainInserts) {
|
||||
d.retain(c.content.getLength(), null, attribution ?? {})
|
||||
} else if (deep && c.content.constructor === ContentType) {
|
||||
d.insert([/** @type {any} */ (c.content).type.getContent(am, opts)], null, attribution)
|
||||
d.insert([/** @type {any} */(c.content).type.getContent(am, opts)], null, attribution)
|
||||
} else {
|
||||
d.insert(c.content.getContent(), null, attribution)
|
||||
}
|
||||
@@ -699,15 +698,15 @@ export class AbstractType {
|
||||
* @public
|
||||
*/
|
||||
applyDelta (d, am = noAttributionsManager) {
|
||||
if (this.doc == null)
|
||||
if (this.doc == null) {
|
||||
(this._prelim || (this._prelim = /** @type {any} */ (delta.create()))).apply(d)
|
||||
else {
|
||||
} else {
|
||||
// @todo this was moved here from ytext. Make this more generic
|
||||
transact(this.doc, transaction => {
|
||||
const currPos = new ItemTextListPosition(null, this._start, 0, new Map(), am)
|
||||
for (const op of d.children) {
|
||||
if (delta.$textOp.check(op)) {
|
||||
insertText(transaction, this, currPos, op.insert, op.format || {})
|
||||
insertText(transaction, /** @type {any} */ (this), currPos, op.insert, op.format || {})
|
||||
} else if (delta.$insertOp.check(op)) {
|
||||
for (let i = 0; i < op.insert.length; i++) {
|
||||
let ins = op.insert[i]
|
||||
@@ -720,15 +719,15 @@ export class AbstractType {
|
||||
error.unexpectedCase()
|
||||
}
|
||||
}
|
||||
insertText(transaction, this, currPos, ins, op.format || {})
|
||||
insertText(transaction, /** @type {any} */ (this), currPos, ins, op.format || {})
|
||||
}
|
||||
} else if (delta.$retainOp.check(op)) {
|
||||
currPos.formatText(transaction, this, op.retain, op.format || {})
|
||||
currPos.formatText(transaction, /** @type {any} */ (this), op.retain, op.format || {})
|
||||
} else if (delta.$deleteOp.check(op)) {
|
||||
deleteText(transaction, currPos, op.delete)
|
||||
} else if (delta.$modifyOp.check(op)) {
|
||||
/** @type {ContentType} */ (currPos.right?.content).type.applyDelta(op.modify)
|
||||
currPos.formatText(transaction, this, 1, op.format || {})
|
||||
currPos.formatText(transaction, /** @type {any} */ (this), 1, op.format || {})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1319,7 +1318,7 @@ export const typeMapGetDelta = (d, parent, attrsToRender, am, deep, modified, de
|
||||
}
|
||||
const prevValue = (prevContentItem !== item && itemsToRender?.hasId(prevContentItem.lastId)) ? array.last(prevContentItem.content.getContent()) : undefined
|
||||
if (deep && c instanceof AbstractType) {
|
||||
c = c.getContent(am)
|
||||
c = /** @type {any} */(c).getContent(am)
|
||||
}
|
||||
d.set(key, c, attribution, prevValue)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import * as delta from 'lib0/delta' // eslint-disable-line
|
||||
* @extends {AbstractType<delta.ArrayDelta<T>,YArray<T>>}
|
||||
* @implements {Iterable<T>}
|
||||
*/
|
||||
// @todo remove this
|
||||
// @ts-ignore
|
||||
export class YArray extends AbstractType {
|
||||
constructor () {
|
||||
super()
|
||||
|
||||
@@ -33,7 +33,6 @@ import * as math from 'lib0/math'
|
||||
import * as traits from 'lib0/traits'
|
||||
import * as map from 'lib0/map'
|
||||
import * as error from 'lib0/error'
|
||||
import * as delta from 'lib0/delta'
|
||||
|
||||
export class ItemTextListPosition {
|
||||
/**
|
||||
@@ -634,7 +633,7 @@ export const deleteText = (transaction, currPos, length) => {
|
||||
* like pictures and videos), and text formats (**bold**, *italic*).
|
||||
*
|
||||
* @template {{ [key:string]:any } | import('../utils/types.js').YType} [Embeds={ [key:string]:any } | import('../utils/types.js').YType]
|
||||
* @extends {AbstractType<delta.TextDelta<Embeds>>}
|
||||
* @extends {AbstractType<import('lib0/delta').TextDelta<Embeds>>}
|
||||
*/
|
||||
export class YText extends AbstractType {
|
||||
/**
|
||||
|
||||
@@ -5,16 +5,12 @@ import {
|
||||
AbstractAttributionManager, Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
import * as array from 'lib0/array'
|
||||
import * as error from 'lib0/error'
|
||||
import * as delta from 'lib0/delta' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* @typedef {import('./types.js').YType} _YType
|
||||
*/
|
||||
|
||||
const errorComputeChanges = 'You must not compute changes after the event-handler fired.'
|
||||
|
||||
/**
|
||||
* @template {_YType} Target
|
||||
* YEvent describes the changes on a YType.
|
||||
|
||||
@@ -332,7 +332,6 @@ export const testObfuscateUpdates = _tc => {
|
||||
// test ytext
|
||||
const d = /** @type {any} */ (otext.getContent().toJSON().children)
|
||||
t.assert(d.length === 2)
|
||||
const q = d[0]
|
||||
t.assert(d[0].insert !== 'text' && d[0].insert.length === 4)
|
||||
t.assert(object.length(d[0].format) === 1)
|
||||
t.assert(!object.hasProperty(d[0].format, 'bold'))
|
||||
|
||||
Reference in New Issue
Block a user