chore: fix prettier, eslint

This commit is contained in:
fantasticit 2022-05-20 23:11:48 +08:00
parent 52675d1e75
commit 5c204e1092
13 changed files with 59 additions and 77 deletions

9
.eslintignore Normal file
View File

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

View File

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

View File

@ -60,6 +60,6 @@
"./packages/server/src/*.{ts,js}": [ "./packages/server/src/*.{ts,js}": [
"eslint --fix" "eslint --fix"
], ],
"*.{css,scss,sass}": " stylelint --fix --formatter verbose --allow-empty-input" "*.{css,scss,sass}": "stylelint --fix --formatter verbose --allow-empty-input"
} }
} }

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, 'func-names': 0,
'no-shadow': 0, 'no-shadow': 0,
'@typescript-eslint/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-unused-vars': [0, { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-use-before-define': 0, '@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/ban-ts-ignore': 0, '@typescript-eslint/ban-ts-ignore': 0,
@ -49,9 +48,7 @@ module.exports = {
'@typescript-eslint/ban-types': 0, '@typescript-eslint/ban-types': 0,
'react-hooks/rules-of-hooks': 2, 'react-hooks/rules-of-hooks': 2,
'react-hooks/exhaustive-deps': 2, 'react-hooks/exhaustive-deps': 2,
'react/prop-types': 0,
'testing-library/no-unnecessary-act': 0, 'testing-library/no-unnecessary-act': 0,
'react/react-in-jsx-scope': 0,
'prettier/prettier': ['error', {}, { usePrettierrc: true }], 'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'react/react-in-jsx-scope': 'off', 'react/react-in-jsx-scope': 'off',
'react/prop-types': '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, var c,
l, l,
a, a,

View File

@ -12,7 +12,7 @@ export const PREFERRED_TRIM_SIZE = 500;
* @param {IndexeddbPersistence} idbPersistence * @param {IndexeddbPersistence} idbPersistence
*/ */
export const fetchUpdates = (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 return idb
.getAll(updatesStore, idb.createIDBKeyRangeLowerBound(idbPersistence._dbref, false)) .getAll(updatesStore, idb.createIDBKeyRangeLowerBound(idbPersistence._dbref, false))
.then((updates) => .then((updates) =>
@ -112,7 +112,7 @@ export class IndexeddbPersistence extends Observable {
this._storeUpdate = (update) => this._storeUpdate = (update) =>
this._mux(() => { this._mux(() => {
if (this.db) { 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); idb.addAutoKey(updatesStore, update);
if (++this._dbsize >= PREFERRED_TRIM_SIZE) { if (++this._dbsize >= PREFERRED_TRIM_SIZE) {
// debounce store call // debounce store call

View File

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

View File

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