Skip to content

Commit 8a42a72

Browse files
authored
Merge pull request #172 from WizTeam/2.1.3
2.1.3
2 parents 87fa2cb + a9c6998 commit 8a42a72

13 files changed

+333
-104
lines changed

package-lock.json

+105-91
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wiznotelite",
33
"description": "WizNote Lite - An instant rendering markdown note tool.",
4-
"version": "2.1.2",
4+
"version": "2.1.3",
55
"private": true,
66
"homepage": ".",
77
"productName": "WizNote Lite",
@@ -44,7 +44,7 @@
4444
},
4545
"build": {
4646
"appId": "cn.wiz.note.lite",
47-
"buildVersion": "62",
47+
"buildVersion": "73",
4848
"asar": false,
4949
"extraMetadata": {
5050
"main": "src/start.js"
@@ -185,6 +185,7 @@
185185
"eslint-plugin-import": "^2.20.2",
186186
"eslint-plugin-jsx-a11y": "^6.2.3",
187187
"eslint-plugin-react": "^7.19.0",
188+
"live-editor": "^0.0.322",
188189
"moment": "^2.26.0",
189190
"node-sass": "^4.14.1",
190191
"notistack": "^0.9.17",
@@ -200,8 +201,7 @@
200201
"react-scripts": "3.4.1",
201202
"react-style-proptype": "^3.2.2",
202203
"run-script-os": "^1.0.7",
203-
"timer.js": "^1.0.4",
204-
"live-editor": "^0.0.302"
204+
"timer.js": "^1.0.4"
205205
},
206206
"__npminstall_done": false
207207
}

src/main/resources/editor_theme/beiges.dark.css

+4
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
--editor-checkbox-layer-bg-color: #333333;
1818
--editor-border-color: #bfbfbf;
1919
--editor-table-bg-color: #2a2a2a;
20+
--editor-color: #f0f0f0;
21+
--editor-code-title-bg-color: #000000;
22+
--editor-code-bg-color: rgb(39, 40, 34);
23+
--editor-code-title-color: #ffffff;
2024
}

src/main/resources/editor_theme/beiges.lite.css

+4
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
--editor-checkbox-layer-bg-color: #ffffff;
2323
--editor-border-color: #b9bfc8;
2424
--editor-table-bg-color: transparent;
25+
--editor-color: #333333;
26+
--editor-code-title-bg-color: rgb(220, 223, 227);
27+
--editor-code-bg-color: #f0f2f4;
28+
--editor-code-title-color: #121212;
2529
}
2630

src/main/resources/editor_theme/coffee.dark.css

+4
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
--editor-checkbox-layer-bg-color: #333333;
1818
--editor-border-color: #bfbfbf;
1919
--editor-table-bg-color: #2a2a2a;
20+
--editor-color: #f0f0f0;
21+
--editor-code-title-bg-color: #000000;
22+
--editor-code-bg-color: rgb(39, 40, 34);
23+
--editor-code-title-color: #ffffff;
2024
}

src/main/resources/editor_theme/coffee.lite.css

+4
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
--editor-checkbox-layer-bg-color: #ffffff;
2323
--editor-border-color: #b9bfc8;
2424
--editor-table-bg-color: transparent;
25+
--editor-color: #333333;
26+
--editor-code-title-bg-color: rgb(220, 223, 227);
27+
--editor-code-bg-color: #f0f2f4;
28+
--editor-code-title-color: #121212;
2529
}

src/main/resources/editor_theme/default.dark.css

+4
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
--editor-checkbox-layer-bg-color: #333333;
1818
--editor-border-color: #bfbfbf;
1919
--editor-table-bg-color: #2a2a2a;
20+
--editor-color: #f0f0f0;
21+
--editor-code-title-bg-color: #000000;
22+
--editor-code-bg-color: rgb(39, 40, 34);
23+
--editor-code-title-color: #ffffff;
2024
}

src/main/resources/editor_theme/default.lite.css

+4
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
--editor-checkbox-layer-bg-color: #ffffff;
2323
--editor-border-color: #b9bfc8;
2424
--editor-table-bg-color: transparent;
25+
--editor-color: #333333;
26+
--editor-code-title-bg-color: rgb(220, 223, 227);
27+
--editor-code-bg-color: #f0f2f4;
28+
--editor-code-title-color: #121212;
2529
}

src/main/resources/editor_theme/mintGreen.dark.css

+4
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
--editor-checkbox-layer-bg-color: #333333;
1818
--editor-border-color: #bfbfbf;
1919
--editor-table-bg-color: #2a2a2a;
20+
--editor-color: #f0f0f0;
21+
--editor-code-title-bg-color: #000000;
22+
--editor-code-bg-color: rgb(39, 40, 34);
23+
--editor-code-title-color: #ffffff;
2024
}

src/main/resources/editor_theme/mintGreen.lite.css

+4
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@
2222
--editor-checkbox-layer-bg-color: #ffffff;
2323
--editor-border-color: #b9bfc8;
2424
--editor-table-bg-color: transparent;
25+
--editor-color: #333333;
26+
--editor-code-title-bg-color: rgb(220, 223, 227);
27+
--editor-code-bg-color: #f0f2f4;
28+
--editor-code-title-color: #121212;
2529
}

src/web/components/editor/markdown/MarkdownEditor.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { filter } from 'fuzzaldrin';
1515
// import { getTagSpanFromRange } from '../libs/dom_utils';
1616
// import { getLocale } from '../../../utils/lang';
1717
import './live-editor.scss';
18+
import { setInsertMenuList } from './QuickInsert';
1819

1920
const {
2021
extractLinksFromMarkdown,
@@ -264,7 +265,7 @@ class MarkdownEditorComponent extends React.PureComponent {
264265

265266
componentDidUpdate(prevProps) {
266267
const { note: currentNote } = this.state;
267-
const { note: propsNote } = this.props;
268+
const { note: propsNote, intl } = this.props;
268269
if (propsNote?.guid !== currentNote?.guid) {
269270
// note changed
270271
this.saveAndLoadNote();
@@ -283,6 +284,37 @@ class MarkdownEditorComponent extends React.PureComponent {
283284
title: item,
284285
}));
285286
}
287+
setInsertMenuList([{
288+
data: null,
289+
iconUrl: '',
290+
id: 'link',
291+
text: intl.formatMessage({ id: 'editorMenuLink' }),
292+
},
293+
{
294+
id: 'checkBox',
295+
data: null,
296+
iconUrl: '',
297+
text: intl.formatMessage({ id: 'editorMenuTodoList' }),
298+
},
299+
{
300+
id: 'table',
301+
data: null,
302+
iconUrl: '',
303+
text: intl.formatMessage({ id: 'editorMenuTable' }),
304+
},
305+
{
306+
id: 'image',
307+
data: null,
308+
iconUrl: '',
309+
text: intl.formatMessage({ id: 'editorMenuImage' }),
310+
},
311+
{
312+
id: 'codeBlock',
313+
data: null,
314+
iconUrl: '',
315+
text: intl.formatMessage({ id: 'editorMenuBlockCode' }),
316+
},
317+
]);
286318
}
287319

288320
componentWillUnmount() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import assert from 'assert';
2+
3+
import {
4+
boxUtils, blockUtils,
5+
} from 'live-editor/client';
6+
7+
function getPrefixInfo(detail, prefix) {
8+
const block = detail.startBlock;
9+
if (!block || !prefix) {
10+
return {
11+
index: -1,
12+
keywords: '',
13+
count: 0,
14+
maxCount: 0,
15+
};
16+
}
17+
//
18+
assert(block);
19+
//
20+
const data = blockUtils.saveData(block).text;
21+
assert(data);
22+
assert(detail.startOffset !== undefined);
23+
const left = data.split(detail.startOffset)[0].toPlainText();
24+
if (left.endsWith(' ')) { // 3 spaces
25+
return {
26+
index: -1,
27+
keywords: '',
28+
count: 0,
29+
maxCount: 0,
30+
};
31+
}
32+
const index = left.lastIndexOf(prefix);
33+
if (index === -1) {
34+
return {
35+
index: -1,
36+
keywords: '',
37+
count: 0,
38+
maxCount: 0,
39+
};
40+
}
41+
const keywords = left.substr(index + 1);
42+
const count = detail.startOffset - index;
43+
const afterPrefix = data.split(index)[1];
44+
let endIndex = afterPrefix.toPlainText().indexOf(' ');
45+
if (endIndex === -1) {
46+
endIndex = afterPrefix.toPlainText().length;
47+
}
48+
//
49+
return {
50+
index,
51+
keywords,
52+
count,
53+
maxCount: endIndex,
54+
};
55+
}
56+
57+
function insertImage(editor) {
58+
const input = document.createElement('input');
59+
input.type = 'file';
60+
input.accept = 'image/*';
61+
input.onchange = () => {
62+
if (input.files && input.files.length > 0) {
63+
Array.from(input.files).forEach((file) => {
64+
editor.insertImage(null, file, -2);
65+
});
66+
input.files = null;
67+
input.value = '';
68+
}
69+
input.remove();
70+
};
71+
input.click();
72+
}
73+
74+
let insertMenuList = [];
75+
76+
// eslint-disable-next-line import/prefer-default-export
77+
export function setInsertMenuList(list) {
78+
insertMenuList = list;
79+
}
80+
81+
const quickInsertBlock = {
82+
createNode: (editor, data) => ({
83+
classes: ['box-quick-insert'],
84+
children: [
85+
{
86+
type: 'text',
87+
text: data.text,
88+
},
89+
],
90+
}),
91+
getItems: async (editor, keywords) => {
92+
assert(editor);
93+
//
94+
if (!keywords) {
95+
return insertMenuList;
96+
}
97+
return insertMenuList.filter((menu) => menu.id.toLowerCase().indexOf(keywords.toLowerCase()) !== -1);
98+
},
99+
supportMarkdown: true,
100+
prefix: '+',
101+
handleBoxItemSelected(editor, item) {
102+
let detail = editor.getSelectionDetail();
103+
if (!detail.startBlock) {
104+
const lastSelectionState = editor.saveSelectionState();
105+
if (lastSelectionState) {
106+
editor.restoreSelectionState(lastSelectionState);
107+
detail = editor.getSelectionDetail();
108+
}
109+
}
110+
assert(detail.startBlock);
111+
assert(detail.startBlock === detail.endBlock);
112+
const { index, maxCount } = getPrefixInfo(detail, '+');
113+
if (index !== -1) {
114+
editor.deleteBlockText(detail.startBlock, index, index + maxCount);
115+
switch (item.id) {
116+
case 'link':
117+
editor.executeTextCommand('link');
118+
break;
119+
case 'checkBox':
120+
editor.executeBlockCommand('toCheckbox');
121+
break;
122+
case 'table':
123+
editor.insertTable(-2, 4, 4);
124+
break;
125+
case 'image':
126+
insertImage(editor);
127+
break;
128+
case 'codeBlock':
129+
editor.insertCode(-2);
130+
break;
131+
default:
132+
break;
133+
}
134+
}
135+
},
136+
};
137+
138+
boxUtils.registerBoxType('quick-insert', quickInsertBlock);

yarn.lock

+21-8
Original file line numberDiff line numberDiff line change
@@ -6319,6 +6319,11 @@ [email protected], fast-safe-stringify@^2.0.7:
63196319
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz#124aa885899261f68aedb42a7c080de9da608743"
63206320
integrity sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==
63216321

6322+
fast-xml-parser@^3.19.0:
6323+
version "3.19.0"
6324+
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-3.19.0.tgz#cb637ec3f3999f51406dd8ff0e6fc4d83e520d01"
6325+
integrity sha512-4pXwmBplsCPv8FOY1WRakF970TjNGnGnfbOnLqjlYvMiF1SR3yOHyxMR/YCXpPTOspNF5gwudqktIP4VsWkvBg==
6326+
63226327
fastify-cookie@^5.1.0:
63236328
version "5.3.1"
63246329
resolved "https://registry.yarnpkg.com/fastify-cookie/-/fastify-cookie-5.3.1.tgz#97b17f3f297b06ffc8e27fe7a0398aefa9df74f0"
@@ -8218,6 +8223,13 @@ is-string@^1.0.5, is-string@^1.0.6:
82188223
resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.6.tgz#3fe5d5992fb0d93404f32584d4b0179a71b54a5f"
82198224
integrity sha512-2gdzbKUuqtQ3lYNrUTQYoClPhm7oQu4UdpSZMp1/DGgkHBT8E2Z1l0yMdb6D4zNAxwDiMv8MdulKROJGNl0Q0w==
82208225

8226+
is-svg@^4.3.1:
8227+
version "4.3.1"
8228+
resolved "https://registry.yarnpkg.com/is-svg/-/is-svg-4.3.1.tgz#8c63ec8c67c8c7f0a8de0a71c8c7d58eccf4406b"
8229+
integrity sha512-h2CGs+yPUyvkgTJQS9cJzo9lYK06WgRiXUqBBHtglSzVKAuH4/oWsqk7LGfbSa1hGk9QcZ0SyQtVggvBA8LZXA==
8230+
dependencies:
8231+
fast-xml-parser "^3.19.0"
8232+
82218233
is-symbol@^1.0.2, is-symbol@^1.0.3:
82228234
version "1.0.4"
82238235
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.4.tgz#a6dac93b635b063ca6872236de88910a57af139c"
@@ -9274,10 +9286,10 @@ lines-and-columns@^1.1.6:
92749286
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
92759287
integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=
92769288

9277-
live-editor@^0.0.276:
9278-
version "0.0.276"
9279-
resolved "https://registry.yarnpkg.com/live-editor/-/live-editor-0.0.276.tgz#d564bb27742bf66e2e20dab1906d1de2c1d262f0"
9280-
integrity sha512-TG/5NFZEZ11ge1gy2hClT75RD0qMoMf17EbEDm1kVHXDpUekP31+NgKJITnLigwELmdI6lbzlnPnv9s7ngFjPg==
9289+
live-editor@^0.0.322:
9290+
version "0.0.322"
9291+
resolved "https://registry.yarnpkg.com/live-editor/-/live-editor-0.0.322.tgz#b7ac3d6b3e21f3324358dd5682f6e30f555f7139"
9292+
integrity sha512-dc6JLe+Syb+bFQ9IZ3LPE4jCCVxWXr3TjX0JJu5uwjfmATSd36rhZDMPT8vwTYuuECOoLLUJvpQYgezg9ZGExw==
92819293
dependencies:
92829294
"@lvgithub/ctrip-apollo-client" "^1.0.22"
92839295
"@nestjs/common" "^7.6.3"
@@ -15243,10 +15255,10 @@ wiznote-sdk-js-share@^1.0.6:
1524315255
"@types/assert" "^1.5.4"
1524415256
assert "^2.0.0"
1524515257

15246-
wiznote-sdk-js@^1.2.30:
15247-
version "1.2.30"
15248-
resolved "https://registry.yarnpkg.com/wiznote-sdk-js/-/wiznote-sdk-js-1.2.30.tgz#4fd7ee7ecccef015a7a36afed96cb32a8cf7af35"
15249-
integrity sha512-3Bbk+gjGrs/QadijFeHAtgAhglLDH3KqeuY88RW+P1S+a8vqWFoUFAioRBLToOIl+f5XZdUX73dqCio/FLOqdQ==
15258+
wiznote-sdk-js@^1.2.33:
15259+
version "1.2.33"
15260+
resolved "https://registry.yarnpkg.com/wiznote-sdk-js/-/wiznote-sdk-js-1.2.33.tgz#dce57d7207e7610d652bba488bcf3afd3aeed2bd"
15261+
integrity sha512-0qswzYlhDpAEQK9SKF5vXRJrgi91kQvYHYW5gHZIb8zXujlPLe1f0xDEnTZFn5+nNeu3nKnt16R7ARIxiH9WmA==
1525015262
dependencies:
1525115263
"@types/fs-extra" "^9.0.7"
1525215264
"@types/lodash" "^4.14.168"
@@ -15262,6 +15274,7 @@ wiznote-sdk-js@^1.2.30:
1526215274
events "^3.2.0"
1526315275
i18next "^19.6.3"
1526415276
image-type "^4.1.0"
15277+
is-svg "^4.3.1"
1526515278
lodash "^4.17.19"
1526615279
marked "^2.0.0"
1526715280
md5 "^2.3.0"

0 commit comments

Comments
 (0)