frappe-ui 0.0.72 → 0.0.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frappe-ui",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "description": "A set of components and utilities for rapid UI development",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -39,6 +39,7 @@
39
39
  "feather-icons": "^4.28.0",
40
40
  "idb-keyval": "^6.2.0",
41
41
  "postcss": "^8.4.5",
42
+ "showdown": "^2.1.0",
42
43
  "socket.io-client": "^4.5.1",
43
44
  "tailwindcss": "^3.0.12",
44
45
  "tippy.js": "^6.3.7"
@@ -29,6 +29,8 @@ import configureMention from './mention'
29
29
  import TextEditorFixedMenu from './TextEditorFixedMenu.vue'
30
30
  import TextEditorBubbleMenu from './TextEditorBubbleMenu.vue'
31
31
  import TextEditorFloatingMenu from './TextEditorFloatingMenu.vue'
32
+ import { detectMarkdown, markdownToHTML } from '../../utils/markdown'
33
+ import { DOMParser } from 'prosemirror-model'
32
34
 
33
35
  export default {
34
36
  name: 'TextEditor',
@@ -161,6 +163,26 @@ export default {
161
163
  this.editorClass,
162
164
  ]),
163
165
  },
166
+ clipboardTextParser: (text, $context) => {
167
+ if (!detectMarkdown(text)) return
168
+ if (
169
+ !confirm(
170
+ 'Do you want to convert markdown content to HTML before pasting?'
171
+ )
172
+ )
173
+ return
174
+
175
+ let dom = document.createElement('div')
176
+ dom.innerHTML = markdownToHTML(text)
177
+ let parser =
178
+ this.editor.view.someProp('clipboardParser') ||
179
+ this.editor.view.someProp('domParser') ||
180
+ DOMParser.fromSchema(this.editor.schema)
181
+ return parser.parseSlice(dom, {
182
+ preserveWhitespace: true,
183
+ context: $context,
184
+ })
185
+ },
164
186
  }
165
187
  },
166
188
  },
@@ -197,8 +197,16 @@ export function createListResource(options, vm, getResource) {
197
197
  }
198
198
 
199
199
  function reload() {
200
- out.start = 0
201
- return out.list.fetch()
200
+ let _start = out.start
201
+ let _limit = out.limit
202
+ if (out.start > 0) {
203
+ out.start = 0
204
+ out.limit = out.originalData.length
205
+ }
206
+ return out.list.fetch().finally(() => {
207
+ out.start = _start
208
+ out.limit = _limit
209
+ })
202
210
  }
203
211
 
204
212
  function setData(data) {
@@ -0,0 +1,29 @@
1
+ import showdown from 'showdown'
2
+
3
+ export function markdownToHTML(text) {
4
+ const converter = new showdown.Converter()
5
+ return converter.makeHtml(text)
6
+ }
7
+
8
+ export function htmlToMarkdown(text) {
9
+ const converter = new showdown.Converter()
10
+ return converter.makeMarkdown(text)
11
+ }
12
+
13
+ export function detectMarkdown(text) {
14
+ const lines = text.split('\n')
15
+ const markdown = lines.filter(
16
+ (line) =>
17
+ line.startsWith('![') ||
18
+ line.startsWith('#') ||
19
+ line.startsWith('> ') ||
20
+ line.startsWith('*') ||
21
+ line.startsWith('- ') ||
22
+ line.startsWith('1. ') ||
23
+ line.startsWith('```') ||
24
+ line.startsWith('`') ||
25
+ line.startsWith('[') ||
26
+ line.startsWith('---')
27
+ )
28
+ return markdown.length > 0
29
+ }