chore: fix prettier, eslint

pull/47/head
fantasticit 2022-05-20 23:11:48 +08:00
parent 52675d1e75
commit 5c204e1092
13 changed files with 59 additions and 77 deletions

9
.eslintignore 100644
View File

@ -0,0 +1,9 @@
node_modules
.next
dist
lib
**/.next/**
**/dist/**
**/build/**
**/public/**

View File

@ -2,5 +2,8 @@ node_modules
.next
dist
lib
./packages/client/public/diagram.js
./packages/client/public/diagram.min.js
**/.next/**
**/dist/**
**/build/**
**/public/**

View File

@ -1,9 +0,0 @@
node_modules
**/.next/**
**/_next/**
**/dist/**
.eslintrc.js
./src/tiptap/core/wrappers/mind/mind-elixir/iconfont/iconfont.js
./public/diagram.js
./public/diagram.min.js

View File

@ -36,7 +36,6 @@ module.exports = {
'func-names': 0,
'no-shadow': 0,
'@typescript-eslint/no-shadow': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-unused-vars': [0, { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/ban-ts-ignore': 0,
@ -49,9 +48,7 @@ module.exports = {
'@typescript-eslint/ban-types': 0,
'react-hooks/rules-of-hooks': 2,
'react-hooks/exhaustive-deps': 2,
'react/prop-types': 0,
'testing-library/no-unnecessary-act': 0,
'react/react-in-jsx-scope': 0,
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',

View File

@ -1,6 +0,0 @@
node_modules
.next
dist
lib
./public/diagram.js
./public/diagram.min.js

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
!(function (t) {
/* eslint-disable */
(function (t) {
var c,
l,
a,

View File

@ -12,7 +12,7 @@ export const PREFERRED_TRIM_SIZE = 500;
* @param {IndexeddbPersistence} idbPersistence
*/
export const fetchUpdates = (idbPersistence) => {
const [updatesStore] = idb.transact(/** @type {IDBDatabase} */ (idbPersistence.db), [updatesStoreName]); // , 'readonly')
const [updatesStore] = idb.transact(/** @type {IDBDatabase} */ idbPersistence.db, [updatesStoreName]); // , 'readonly')
return idb
.getAll(updatesStore, idb.createIDBKeyRangeLowerBound(idbPersistence._dbref, false))
.then((updates) =>
@ -112,7 +112,7 @@ export class IndexeddbPersistence extends Observable {
this._storeUpdate = (update) =>
this._mux(() => {
if (this.db) {
const [updatesStore] = idb.transact(/** @type {IDBDatabase} */ (this.db), [updatesStoreName]);
const [updatesStore] = idb.transact(/** @type {IDBDatabase} */ this.db, [updatesStoreName]);
idb.addAutoKey(updatesStore, update);
if (++this._dbsize >= PREFERRED_TRIM_SIZE) {
// debounce store call

View File

@ -20,7 +20,7 @@ import * as eventloop from 'lib0/eventloop';
let viewsToUpdate = null;
const updateMetas = () => {
const ups = /** @type {Map<EditorView, Map<any, any>>} */ (viewsToUpdate);
const ups = /** @type {Map<EditorView, Map<any, any>>} */ viewsToUpdate;
viewsToUpdate = null;
ups.forEach((metas, view) => {
const tr = view.state.tr;
@ -54,7 +54,7 @@ export const absolutePositionToRelativePosition = (pos, type, mapping) => {
/**
* @type {any}
*/
let n = type._first === null ? null : /** @type {Y.ContentType} */ (type._first.content).type;
let n = type._first === null ? null : /** @type {Y.ContentType} */ type._first.content.type;
while (n !== null && type !== n) {
if (n instanceof Y.XmlText) {
if (n._length >= pos) {
@ -63,7 +63,7 @@ export const absolutePositionToRelativePosition = (pos, type, mapping) => {
pos -= n._length;
}
if (n._item !== null && n._item.next !== null) {
n = /** @type {Y.ContentType} */ (n._item.next.content).type;
n = /** @type {Y.ContentType} */ n._item.next.content.type;
} else {
do {
n = n._item === null ? null : n._item.parent;
@ -71,13 +71,13 @@ export const absolutePositionToRelativePosition = (pos, type, mapping) => {
} while (n !== type && n !== null && n._item !== null && n._item.next === null);
if (n !== null && n !== type) {
// @ts-gnore we know that n.next !== null because of above loop conditition
n = n._item === null ? null : /** @type {Y.ContentType} */ (/** @type Y.Item */ (n._item.next).content).type;
n = n._item === null ? null : /** @type {Y.ContentType} */ /** @type Y.Item */ n._item.next.content.type;
}
}
} else {
const pNodeSize = /** @type {any} */ (mapping.get(n) || { nodeSize: 0 }).nodeSize;
if (n._first !== null && pos < pNodeSize) {
n = /** @type {Y.ContentType} */ (n._first.content).type;
n = /** @type {Y.ContentType} */ n._first.content.type;
pos--;
} else {
if (pos === 1 && n._length === 0 && pNodeSize > 1) {
@ -90,7 +90,7 @@ export const absolutePositionToRelativePosition = (pos, type, mapping) => {
}
pos -= pNodeSize;
if (n._item !== null && n._item.next !== null) {
n = /** @type {Y.ContentType} */ (n._item.next.content).type;
n = /** @type {Y.ContentType} */ n._item.next.content.type;
} else {
if (pos === 0) {
// set to end of n.parent
@ -102,14 +102,13 @@ export const absolutePositionToRelativePosition = (pos, type, mapping) => {
);
}
do {
n = /** @type {Y.Item} */ (n._item).parent;
n = /** @type {Y.Item} */ n._item.parent;
pos--;
} while (n !== type && /** @type {Y.Item} */ (n._item).next === null);
} while (n !== type && /** @type {Y.Item} */ n._item.next === null);
// if n is null at this point, we have an unexpected case
if (n !== type) {
// We know that n._item.next is defined because of above loop condition
n = /** @type {Y.ContentType} */ (/** @type {Y.Item} */ (/** @type {Y.Item} */ (n._item).next).content)
.type;
n = /** @type {Y.ContentType} */ /** @type {Y.Item} */ /** @type {Y.Item} */ n._item.next.content.type;
}
}
}
@ -157,15 +156,15 @@ export const relativePositionToAbsolutePosition = (y, documentType, relPos, mapp
let i = 0;
while (i < type._length && i < decodedPos.index && n !== null) {
if (!n.deleted) {
const t = /** @type {Y.ContentType} */ (n.content).type;
const t = /** @type {Y.ContentType} */ n.content.type;
i++;
if (t instanceof Y.XmlText) {
pos += t._length;
} else {
pos += /** @type {any} */ (mapping.get(t)).nodeSize;
pos += /** @type {any} */ mapping.get(t).nodeSize;
}
}
n = /** @type {Y.Item} */ (n.right);
n = /** @type {Y.Item} */ n.right;
}
pos += 1; // increase because we go out of n
}
@ -175,10 +174,10 @@ export const relativePositionToAbsolutePosition = (y, documentType, relPos, mapp
// @ts-ignore
if (parent._item === null || !parent._item.deleted) {
pos += 1; // the start tag
let n = /** @type {Y.AbstractType} */ (parent)._first;
let n = /** @type {Y.AbstractType} */ parent._first;
// now iterate until we found type
while (n !== null) {
const contentType = /** @type {Y.ContentType} */ (n.content).type;
const contentType = /** @type {Y.ContentType} */ n.content.type;
if (contentType === type) {
break;
}
@ -186,13 +185,13 @@ export const relativePositionToAbsolutePosition = (y, documentType, relPos, mapp
if (contentType instanceof Y.XmlText) {
pos += contentType._length;
} else {
pos += /** @type {any} */ (mapping.get(contentType)).nodeSize;
pos += /** @type {any} */ mapping.get(contentType).nodeSize;
}
}
n = n.right;
}
}
type = /** @type {Y.AbstractType} */ (parent);
type = /** @type {Y.AbstractType} */ parent;
}
return pos - 1; // we don't count the most outer tag, because it is a fragment
};
@ -210,7 +209,7 @@ export const relativePositionToAbsolutePosition = (y, documentType, relPos, mapp
*/
export function prosemirrorToYDoc(doc, xmlFragment = 'prosemirror') {
const ydoc = new Y.Doc();
const type = /** @type {Y.XmlFragment} */ (ydoc.get(xmlFragment, Y.XmlFragment));
const type = /** @type {Y.XmlFragment} */ ydoc.get(xmlFragment, Y.XmlFragment);
if (!type.doc) {
return ydoc;
}

View File

@ -26,7 +26,7 @@ export const isVisible = (item, snapshot) =>
snapshot === undefined
? !item.deleted
: snapshot.sv.has(item.id.client) &&
/** @type {number} */ (snapshot.sv.get(item.id.client)) > item.id.clock &&
/** @type {number} */ snapshot.sv.get(item.id.client) > item.id.clock &&
!Y.isDeleted(snapshot.ds, item.id);
/**
@ -68,7 +68,7 @@ const getUserColor = (colorMapping, colors, user) => {
}
colorMapping.set(user, random.oneOf(colors));
}
return /** @type {ColorDef} */ (colorMapping.get(user));
return /** @type {ColorDef} */ colorMapping.get(user);
};
/**
@ -283,7 +283,7 @@ export class ProsemirrorBinding {
const fragmentContent = this.type
.toArray()
.map((t) =>
createNodeFromYElement(/** @type {Y.XmlElement} */ (t), this.prosemirrorView.state.schema, this.mapping)
createNodeFromYElement(/** @type {Y.XmlElement} */ t, this.prosemirrorView.state.schema, this.mapping)
)
.filter((n) => n !== null);
// @ts-ignore
@ -303,7 +303,7 @@ export class ProsemirrorBinding {
const fragmentContent = this.type
.toArray()
.map((t) =>
createNodeFromYElement(/** @type {Y.XmlElement} */ (t), this.prosemirrorView.state.schema, this.mapping)
createNodeFromYElement(/** @type {Y.XmlElement} */ t, this.prosemirrorView.state.schema, this.mapping)
)
.filter((n) => n !== null);
// @ts-ignore
@ -397,7 +397,7 @@ export class ProsemirrorBinding {
transaction.deleteSet,
(struct) =>
struct.constructor === Y.Item &&
this.mapping.delete(/** @type {Y.ContentType} */ (/** @type {Y.Item} */ (struct).content).type)
this.mapping.delete(/** @type {Y.ContentType} */ /** @type {Y.Item} */ struct.content.type)
);
transaction.changed.forEach(delType);
transaction.changedParentTypes.forEach(delType);
@ -405,7 +405,7 @@ export class ProsemirrorBinding {
.toArray()
.map((t) =>
createNodeIfNotExists(
/** @type {Y.XmlElement | Y.XmlHook} */ (t),
/** @type {Y.XmlElement | Y.XmlHook} */ t,
this.prosemirrorView.state.schema,
this.mapping
)
@ -453,7 +453,7 @@ export class ProsemirrorBinding {
* @return {PModel.Node | null}
*/
const createNodeIfNotExists = (el, schema, mapping, snapshot, prevSnapshot, computeYChange) => {
const node = /** @type {PModel.Node} */ (mapping.get(el));
const node = /** @type {PModel.Node} */ mapping.get(el);
if (node === undefined) {
if (el instanceof Y.XmlElement) {
return createNodeFromYElement(el, schema, mapping, snapshot, prevSnapshot, computeYChange);
@ -501,14 +501,12 @@ const createNodeFromYElement = (el, schema, mapping, snapshot, prevSnapshot, com
try {
const attrs = el.getAttributes(snapshot);
if (snapshot !== undefined) {
if (!isVisible(/** @type {Y.Item} */ (el._item), snapshot)) {
if (!isVisible(/** @type {Y.Item} */ el._item, snapshot)) {
attrs.ychange = computeYChange
? computeYChange('removed', /** @type {Y.Item} */ (el._item).id)
? computeYChange('removed', /** @type {Y.Item} */ el._item.id)
: { type: 'removed' };
} else if (!isVisible(/** @type {Y.Item} */ (el._item), prevSnapshot)) {
attrs.ychange = computeYChange
? computeYChange('added', /** @type {Y.Item} */ (el._item).id)
: { type: 'added' };
} else if (!isVisible(/** @type {Y.Item} */ el._item, prevSnapshot)) {
attrs.ychange = computeYChange ? computeYChange('added', /** @type {Y.Item} */ el._item.id) : { type: 'added' };
}
}
const node = schema.node(el.nodeName, attrs, children);
@ -516,8 +514,8 @@ const createNodeFromYElement = (el, schema, mapping, snapshot, prevSnapshot, com
return node;
} catch (e) {
// an error occured while creating the node. This is probably a result of a concurrent action.
/** @type {Y.Doc} */ (el.doc).transact((transaction) => {
/** @type {Y.Item} */ (el._item).delete(transaction);
/** @type {Y.Doc} */ el.doc.transact((transaction) => {
/** @type {Y.Item} */ el._item.delete(transaction);
}, ySyncPluginKey);
mapping.delete(el);
return null;
@ -548,8 +546,8 @@ const createTextNodesFromYText = (text, schema, mapping, snapshot, prevSnapshot,
}
} catch (e) {
// an error occured while creating the node. This is probably a result of a concurrent action.
/** @type {Y.Doc} */ (text.doc).transact((transaction) => {
/** @type {Y.Item} */ (text._item).delete(transaction);
/** @type {Y.Doc} */ text.doc.transact((transaction) => {
/** @type {Y.Item} */ text._item.delete(transaction);
}, ySyncPluginKey);
return null;
}
@ -657,7 +655,7 @@ const equalYTextPText = (ytext, ptexts) => {
delta.length === ptexts.length &&
delta.every(
(d, i) =>
d.insert === /** @type {any} */ (ptexts[i]).text &&
d.insert === /** @type {any} */ ptexts[i].text &&
object.keys(d.attributes || {}).length === ptexts[i].marks.length &&
ptexts[i].marks.every((mark) => equalAttrs(d.attributes[mark.type.name] || {}, mark.attrs))
)
@ -764,7 +762,7 @@ const updateYText = (ytext, ptexts, mapping) => {
mapping.set(ytext, ptexts);
const { nAttrs, str } = ytextTrans(ytext);
const content = ptexts.map((p) => ({
insert: /** @type {any} */ (p).text,
insert: /** @type {any} */ p.text,
attributes: Object.assign({}, nAttrs, marksToAttributes(p.marks)),
}));
const { insert, remove, index } = simpleDiff(str, content.map((c) => c.insert).join(''));
@ -867,13 +865,13 @@ export const updateYFragment = (y, yDomFragment, pNode, mapping) => {
if (updateLeft && updateRight) {
// decide which which element to update
const equalityLeft = computeChildEqualityFactor(
/** @type {Y.XmlElement} */ (leftY),
/** @type {PModel.Node} */ (leftP),
/** @type {Y.XmlElement} */ leftY,
/** @type {PModel.Node} */ leftP,
mapping
);
const equalityRight = computeChildEqualityFactor(
/** @type {Y.XmlElement} */ (rightY),
/** @type {PModel.Node} */ (rightP),
/** @type {Y.XmlElement} */ rightY,
/** @type {PModel.Node} */ rightP,
mapping
);
if (equalityLeft.foundMappedChild && !equalityRight.foundMappedChild) {
@ -887,10 +885,10 @@ export const updateYFragment = (y, yDomFragment, pNode, mapping) => {
}
}
if (updateLeft) {
updateYFragment(y, /** @type {Y.XmlFragment} */ (leftY), /** @type {PModel.Node} */ (leftP), mapping);
updateYFragment(y, /** @type {Y.XmlFragment} */ leftY, /** @type {PModel.Node} */ leftP, mapping);
left += 1;
} else if (updateRight) {
updateYFragment(y, /** @type {Y.XmlFragment} */ (rightY), /** @type {PModel.Node} */ (rightP), mapping);
updateYFragment(y, /** @type {Y.XmlFragment} */ rightY, /** @type {PModel.Node} */ rightP, mapping);
right += 1;
} else {
yDomFragment.delete(left, 1);

View File

@ -1,5 +0,0 @@
node_modules
**/.next/**
**/_next/**
**/dist/**
.eslintrc.js

View File

@ -1,4 +0,0 @@
node_modules
.next
dist
lib