Skip to content

Commit 7d5f9bc

Browse files
authored
Editor update (#185)
* remove gitmodules * remove submodule * use editor from npm * bump version * bump version
1 parent 415dd15 commit 7d5f9bc

File tree

9 files changed

+256
-157
lines changed

9 files changed

+256
-157
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codex.notes",
3-
"version": "2.1.2",
3+
"version": "2.2.0",
44
"productName": "CodeX Notes",
55
"description": "Simple, fast and useful crossplatform notes application based on CodeX Editor and Electron.",
66
"main": "./src/codex-notes.js",
@@ -44,6 +44,16 @@
4444
"babel-core": "^6.25.0",
4545
"babel-loader": "^7.1.4",
4646
"babel-preset-env": "^1.6.1",
47+
"codex.editor": "^2.4.2",
48+
"codex.editor.code": "^2.1.0",
49+
"codex.editor.delimiter": "^1.0.1",
50+
"codex.editor.header": "^2.0.5",
51+
"codex.editor.inline-code": "^1.1.0",
52+
"codex.editor.list": "^1.0.2",
53+
"codex.editor.marker": "^1.0.1",
54+
"codex.editor.quote": "^2.1.0",
55+
"codex.editor.raw": "^2.0.0",
56+
"codex.editor.simple-image": "^1.0.1",
4757
"css-loader": "^0.28.11",
4858
"electron": "^2.0.0-beta.7",
4959
"electron-builder": "^20.14.3",

public/build/bundle.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/bundle.js

Lines changed: 104 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/codex.editor

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/javascripts/editor.js

Lines changed: 65 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
1-
const $ = require('./dom').default;
21
const common = require('./utils/common').default;
32

3+
/**
4+
* CodeX Editor core
5+
*/
6+
const CodexEditor = require('codex.editor');
7+
8+
/**
9+
* Tools for the Editor
10+
*/
11+
const Header = require('codex.editor.header');
12+
const Quote = require('codex.editor.quote');
13+
const Marker = require('codex.editor.marker');
14+
const CodeTool = require('codex.editor.code');
15+
const Delimiter = require('codex.editor.delimiter');
16+
const InlineCode = require('codex.editor.inline-code');
17+
const List = require('codex.editor.list');
18+
const RawTool = require('codex.editor.raw');
19+
const SimpleImageTool = require('codex.editor.simple-image');
420

521
/**
622
* CodeX Editor module
723
*/
824
export default class Editor {
925
/**
1026
* @constructor
11-
* @property {String} path - CodeX Editor library path
12-
* @property {Array} plugins - plugins names
13-
* @property {TimerId} autosaveTimer - autosave debounce timer
1427
*/
1528
constructor() {
16-
/**
17-
* Path to Editor sources dir
18-
*/
19-
this.path = '../../public/codex.editor/';
20-
21-
/**
22-
* List of plugins
23-
*/
24-
this.plugins = [
25-
'text',
26-
'header'
27-
];
28-
29-
/**
30-
* List of inline-tools
31-
*/
32-
this.inlineTools = [
33-
'term'
34-
];
35-
3629
/**
3730
* Element to be wrapper for an Editor
3831
*/
@@ -43,113 +36,72 @@ export default class Editor {
4336
*/
4437
this.instance = null;
4538

46-
this.loadEditor()
47-
.then(() => this.loadPlugins())
48-
.then(() => this.init());
49-
}
50-
51-
52-
53-
/**
54-
* Loads CodeX Editor sources
55-
* @return {Promise}
56-
*/
57-
loadEditor() {
58-
return $.loadResource('JS', this.path + 'build/codex-editor.js', 'codex-editor');
59-
}
60-
61-
/**
62-
* Loads CodeX Editor plugins
63-
* @return {Promise}
64-
*/
65-
loadPlugins() {
66-
let pluginsQuery = [];
67-
6839
/**
69-
* Load plugins
40+
* Wrapper with a debounce to save note
7041
*/
71-
this.plugins.forEach( name => {
72-
pluginsQuery.push(...[
73-
$.loadResource('JS', this.path + 'example/plugins/' + name + '/' + name + '.js', name),
74-
$.loadResource('CSS', this.path + 'example/plugins/' + name + '/' + name + '.css', name)
75-
]);
76-
});
42+
this.saveNoteDebouncedFunction = common.debounce(() => {
43+
codex.notes.note.save();
44+
}, 500);
7745

7846
/**
79-
* Load inline-tools
47+
* Listen title changes and save note
8048
*/
81-
this.inlineTools.forEach( name => {
82-
pluginsQuery.push(...[
83-
$.loadResource('JS', this.path + 'example/tools-inline/' + name + '/' + name + '.js', name),
84-
$.loadResource('CSS', this.path + 'example/tools-inline/' + name + '/' + name + '.css', name)
85-
]);
86-
});
49+
let noteTitle = document.getElementById('note-title');
50+
51+
noteTitle.addEventListener('keyup', this.saveNoteDebouncedFunction);
8752

88-
return Promise.all(pluginsQuery)
89-
.catch( err => console.warn('Cannot load plugin: ', err))
90-
.then( () => console.log('Plugins loaded') );
53+
/**
54+
* Start Editor
55+
*/
56+
this.init();
9157
}
9258

9359
/**
9460
* Init CodeX Editor
95-
* @return {[type]} [description]
9661
*/
9762
init() {
9863
this.instance = new CodexEditor({
9964
holderId : this.editorZoneId,
100-
initialBlock : 'paragraph',
101-
placeholder: 'Your story',
10265
tools: {
103-
paragraph: Text,
104-
header: Header,
105-
term: Term
106-
},
107-
toolsConfig: {
108-
paragraph: {
109-
inlineToolbar : true,
110-
}
66+
header: {
67+
class: Header,
68+
inlineToolbar: ['link', 'marker'],
69+
},
70+
image: {
71+
class: SimpleImageTool,
72+
inlineToolbar: true,
73+
},
74+
list: {
75+
class: List,
76+
inlineToolbar: true
77+
},
78+
quote: {
79+
class: Quote,
80+
inlineToolbar: true,
81+
},
82+
code: {
83+
class: CodeTool,
84+
shortcut: 'CMD+SHIFT+D'
85+
},
86+
inlineCode: {
87+
class: InlineCode,
88+
shortcut: 'CMD+SHIFT+C'
89+
},
90+
rawTool: {
91+
class: RawTool,
92+
shortcut: 'CMD+SHIFT+R'
93+
},
94+
marker: {
95+
class: Marker,
96+
shortcut: 'CMD+SHIFT+M'
97+
},
98+
delimiter: Delimiter,
11199
},
112100
data: {
113101
items: []
114-
}
115-
});
116-
117-
/**
118-
* Wait some time and init autosave function
119-
*/
120-
window.setTimeout(() => {
121-
/**
122-
* Create a wrapper with debouncing for codex.notes.note.save()
123-
*
124-
* @type {Function|*}
125-
*/
126-
this.saveNoteDebouncedFunction = common.debounce(() => {
127-
codex.notes.note.save();
128-
}, 500);
129-
130-
this.enableAutosave();
131-
}, 500);
132-
}
133-
134-
/**
135-
* Add keyup listener to editor zone
136-
*/
137-
enableAutosave() {
138-
let noteTitle = document.getElementById('note-title'),
139-
editorZone = document.getElementById(this.editorZoneId);
140-
141-
noteTitle.addEventListener('keyup', this.saveNoteDebouncedFunction);
142-
editorZone.addEventListener('keyup', this.saveNoteDebouncedFunction);
143-
}
144-
145-
/**
146-
* Remove keyup listener to editor zone
147-
*/
148-
disableAutosave() {
149-
let noteTitle = document.getElementById('note-title'),
150-
editorZone = document.getElementById(this.editorZoneId);
102+
},
151103

152-
noteTitle.removeEventListener('keyup', this.saveNoteDebouncedFunction);
153-
editorZone.removeEventListener('keyup', this.saveNoteDebouncedFunction);
104+
onChange: this.saveNoteDebouncedFunction,
105+
});
154106
}
155107
}

public/javascripts/note.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const $ = require('./dom').default;
22
const AutoResizer = require('./autoresizer').default;
33
const Dialog = require('./dialog').default;
4-
const Shortcut = require('@codexteam/shortcuts').default;
4+
// const Shortcut = require('@codexteam/shortcuts').default;
55
const clipboardUtil = require('./utils/clipboard').default;
66
const HashCoder = require('./utils/hashCoder').default;
77

@@ -83,31 +83,31 @@ export default class Note {
8383
this.editor.removeEventListener('copy', preventDefaultExecution);
8484
}, false);
8585

86-
/**
87-
* Select all document by CMD+A
88-
*/
89-
let selectAllShortcut = new Shortcut({
90-
name: 'CMD+A',
91-
on: this.editor,
92-
callback: event => {
93-
this.cmdA(event);
94-
this.editor.addEventListener('copy', preventDefaultExecution);
95-
}
96-
});
97-
98-
/**
99-
* Copy selected document by CMD+C
100-
*/
101-
let copySelectedShortcut = new Shortcut({
102-
name: 'CMD+C',
103-
on: this.editor,
104-
callback: () => {
105-
this.cmdC();
106-
}
107-
});
108-
109-
this.shortcuts.push(selectAllShortcut);
110-
this.shortcuts.push(copySelectedShortcut);
86+
// /**
87+
// * Select all document by CMD+A
88+
// */
89+
// let selectAllShortcut = new Shortcut({
90+
// name: 'CMD+A',
91+
// on: this.editor,
92+
// callback: event => {
93+
// this.cmdA(event);
94+
// this.editor.addEventListener('copy', preventDefaultExecution);
95+
// }
96+
// });
97+
//
98+
// /**
99+
// * Copy selected document by CMD+C
100+
// */
101+
// let copySelectedShortcut = new Shortcut({
102+
// name: 'CMD+C',
103+
// on: this.editor,
104+
// callback: () => {
105+
// this.cmdC();
106+
// }
107+
// });
108+
//
109+
// this.shortcuts.push(selectAllShortcut);
110+
// this.shortcuts.push(copySelectedShortcut);
111111
}
112112

113113
/**
@@ -161,7 +161,7 @@ export default class Note {
161161
return noteData;
162162
})
163163
.then( noteData => {
164-
let currentNoteContent = this.titleEl.value + JSON.stringify(noteData.items),
164+
let currentNoteContent = this.titleEl.value + JSON.stringify(noteData.blocks),
165165
currentHashedNote = HashCoder.simpleHash(currentNoteContent);
166166

167167
/** Note wont be saved because hashes are similar */
@@ -180,7 +180,7 @@ export default class Note {
180180
* because on the server-side it can generate different string
181181
* caused of unmatched order of object properties
182182
*/
183-
noteData.content = JSON.stringify(noteData.items);
183+
noteData.content = JSON.stringify(noteData.blocks);
184184

185185
noteData.id = this.currentNoteId;
186186

@@ -215,7 +215,7 @@ export default class Note {
215215
* @throws {Error}
216216
*/
217217
validate(noteData) {
218-
if (!noteData.items.length) {
218+
if (!noteData.blocks.length) {
219219
throw Error('Article is empty');
220220
}
221221
}
@@ -284,7 +284,7 @@ export default class Note {
284284

285285
const renderData = {
286286
id: note._id,
287-
items: JSON.parse(note.content),
287+
blocks: JSON.parse(note.content),
288288
time: note.dtModify,
289289
created: note.dtCreate,
290290
version: note.editorVersion,

src/controllers/auth.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ class AuthController {
9898
authWindow.webContents.on('did-get-response-details', (event, status, newURL, originalURL, httpResponseCode) => {
9999
if (httpResponseCode !== 200) {
100100
global.logger.debug(`-------------------------------\nAuthorisation failed: code ${httpResponseCode} \n-------------------------------`);
101-
authWindow.close();
101+
102+
// if (!process.env.DEBUG) {
103+
// authWindow.close();
104+
// }
102105
}
103106
});
104107

0 commit comments

Comments
 (0)