Skip to content

Commit

Permalink
Adds prettier + applies formatting 🧟‍♀️
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeJab committed May 27, 2020
1 parent 1c4e21a commit 2a3472a
Show file tree
Hide file tree
Showing 87 changed files with 4,664 additions and 4,703 deletions.
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"scripts": {
"start": "rollup -c --watch",
"test:ci": "yarn build:docs && yarn build && testem ci -f testem-ci.js",
"test": "yarn build && testem ci -f testem.js",
"test": "yarn format && yarn build && testem ci -f testem.js",
"format": "prettier src --write",
"build": "rollup -c",
"build:docs": "jsdoc -c ./.jsdoc",
"build:website": "yarn build:docs && yarn build && ./bin/build-website.sh",
Expand Down Expand Up @@ -52,6 +53,7 @@
"conventional-changelog-cli": "^2.0.34",
"jquery": "^3.5.1",
"jsdoc": "^3.6.4",
"prettier": "^2.0.5",
"qunit": "^2.10.0",
"rollup": "^2.10.3",
"rollup-plugin-copy": "^3.3.0",
Expand All @@ -60,6 +62,12 @@
"saucie": "^3.3.3",
"testem": "^3.1.0"
},
"prettier": {
"arrowParens": "avoid",
"printWidth": 120,
"semi": false,
"singleQuote": true
},
"volta": {
"node": "12.14.1",
"yarn": "1.22.1"
Expand Down
28 changes: 18 additions & 10 deletions src/css/mobiledoc-kit.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,34 @@
*/

@-webkit-keyframes fade-in {
0% { opacity: 0; }
100% { opacity: 1; }
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes fade-in {
0% { opacity: 0; }
100% { opacity: 1; }
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}

.__mobiledoc-tooltip {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 0.7em;
white-space: nowrap;
position: absolute;
background-color: rgba(43,43,43,0.9);
background-color: rgba(43, 43, 43, 0.9);
border-radius: 3px;
line-height: 1em;
padding: 0.7em 0.9em;
color: #FFF;
color: #fff;
-webkit-animation: fade-in 0.2s;
animation: fade-in 0.2s;
animation: fade-in 0.2s;
}

.__mobiledoc-tooltip:before {
Expand All @@ -126,7 +134,7 @@
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid rgba(43,43,43,0.9);
border-bottom: 5px solid rgba(43, 43, 43, 0.9);
top: -5px;
margin-left: -5px;
}
Expand All @@ -142,7 +150,7 @@
}

.__mobiledoc-tooltip a {
color: #FFF;
color: #fff;
text-decoration: none;
}

Expand Down
14 changes: 7 additions & 7 deletions src/js/cards/image.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import placeholderImageSrc from 'mobiledoc-kit/utils/placeholder-image-src';
import placeholderImageSrc from 'mobiledoc-kit/utils/placeholder-image-src'

export default {
name: 'image',
type: 'dom',

render({payload}) {
let img = document.createElement('img');
img.src = payload.src || placeholderImageSrc;
return img;
}
};
render({ payload }) {
let img = document.createElement('img')
img.src = payload.src || placeholderImageSrc
return img
},
}
110 changes: 53 additions & 57 deletions src/js/editor/edit-history.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,122 @@
import mobiledocParsers from 'mobiledoc-kit/parsers/mobiledoc';
import FixedQueue from 'mobiledoc-kit/utils/fixed-queue';
import mobiledocParsers from 'mobiledoc-kit/parsers/mobiledoc'
import FixedQueue from 'mobiledoc-kit/utils/fixed-queue'

function findLeafSectionAtIndex(post, index) {
let section;
let section
post.walkAllLeafSections((_section, _index) => {
if (index === _index) {
section = _section;
section = _section
}
});
return section;
})
return section
}

export class Snapshot {
constructor(takenAt, editor, editAction=null) {
this.mobiledoc = editor.serialize();
this.editor = editor;
this.editAction = editAction;
this.takenAt = takenAt;
constructor(takenAt, editor, editAction = null) {
this.mobiledoc = editor.serialize()
this.editor = editor
this.editAction = editAction
this.takenAt = takenAt

this.snapshotRange();
this.snapshotRange()
}

snapshotRange() {
let { range, cursor } = this.editor;
let { range, cursor } = this.editor
if (cursor.hasCursor() && !range.isBlank) {
let { head, tail } = range;
let { head, tail } = range
this.range = {
head: [head.leafSectionIndex, head.offset],
tail: [tail.leafSectionIndex, tail.offset]
};
tail: [tail.leafSectionIndex, tail.offset],
}
}
}

getRange(post) {
if (this.range) {
let { head, tail } = this.range;
let [headLeafSectionIndex, headOffset] = head;
let [tailLeafSectionIndex, tailOffset] = tail;
let headSection = findLeafSectionAtIndex(post, headLeafSectionIndex);
let tailSection = findLeafSectionAtIndex(post, tailLeafSectionIndex);
let { head, tail } = this.range
let [headLeafSectionIndex, headOffset] = head
let [tailLeafSectionIndex, tailOffset] = tail
let headSection = findLeafSectionAtIndex(post, headLeafSectionIndex)
let tailSection = findLeafSectionAtIndex(post, tailLeafSectionIndex)

head = headSection.toPosition(headOffset);
tail = tailSection.toPosition(tailOffset);
head = headSection.toPosition(headOffset)
tail = tailSection.toPosition(tailOffset)

return head.toRange(tail);
return head.toRange(tail)
}
}

groupsWith(groupingTimeout, editAction, takenAt) {
return (
editAction !== null &&
this.editAction === editAction &&
this.takenAt + groupingTimeout > takenAt
);
return editAction !== null && this.editAction === editAction && this.takenAt + groupingTimeout > takenAt
}
}

export default class EditHistory {
constructor(editor, queueLength, groupingTimeout) {
this.editor = editor;
this._undoStack = new FixedQueue(queueLength);
this._redoStack = new FixedQueue(queueLength);
this.editor = editor
this._undoStack = new FixedQueue(queueLength)
this._redoStack = new FixedQueue(queueLength)

this._pendingSnapshot = null;
this._groupingTimeout = groupingTimeout;
this._pendingSnapshot = null
this._groupingTimeout = groupingTimeout
}

snapshot() {
// update the current snapshot with the range read from DOM
if (this._pendingSnapshot) {
this._pendingSnapshot.snapshotRange();
this._pendingSnapshot.snapshotRange()
}
}

storeSnapshot(editAction=null) {
let now = Date.now();
storeSnapshot(editAction = null) {
let now = Date.now()
// store pending snapshot
let pendingSnapshot = this._pendingSnapshot;
let pendingSnapshot = this._pendingSnapshot
if (pendingSnapshot) {
if (!pendingSnapshot.groupsWith(this._groupingTimeout, editAction, now)) {
this._undoStack.push(pendingSnapshot);
this._undoStack.push(pendingSnapshot)
}
this._redoStack.clear();
this._redoStack.clear()
}

// take new pending snapshot to store next time `storeSnapshot` is called
this._pendingSnapshot = new Snapshot(now, this.editor, editAction);
this._pendingSnapshot = new Snapshot(now, this.editor, editAction)
}

stepBackward(postEditor) {
// Throw away the pending snapshot
this._pendingSnapshot = null;
this._pendingSnapshot = null

let snapshot = this._undoStack.pop();
let snapshot = this._undoStack.pop()
if (snapshot) {
this._redoStack.push(new Snapshot(Date.now(), this.editor));
this._restoreFromSnapshot(snapshot, postEditor);
this._redoStack.push(new Snapshot(Date.now(), this.editor))
this._restoreFromSnapshot(snapshot, postEditor)
}
}

stepForward(postEditor) {
let snapshot = this._redoStack.pop();
let snapshot = this._redoStack.pop()
if (snapshot) {
this._undoStack.push(new Snapshot(Date.now(), this.editor));
this._restoreFromSnapshot(snapshot, postEditor);
this._undoStack.push(new Snapshot(Date.now(), this.editor))
this._restoreFromSnapshot(snapshot, postEditor)
}
postEditor.cancelSnapshot();
postEditor.cancelSnapshot()
}

_restoreFromSnapshot(snapshot, postEditor) {
let { mobiledoc } = snapshot;
let { editor } = this;
let { builder, post } = editor;
let restoredPost = mobiledocParsers.parse(builder, mobiledoc);
let { mobiledoc } = snapshot
let { editor } = this
let { builder, post } = editor
let restoredPost = mobiledocParsers.parse(builder, mobiledoc)

postEditor.removeAllSections();
postEditor.migrateSectionsFromPost(restoredPost);
postEditor.removeAllSections()
postEditor.migrateSectionsFromPost(restoredPost)

// resurrect snapshotted range if it exists
let newRange = snapshot.getRange(post);
let newRange = snapshot.getRange(post)
if (newRange) {
postEditor.setRange(newRange);
postEditor.setRange(newRange)
}
}
}
Loading

0 comments on commit 2a3472a

Please sign in to comment.