dragon-editor 3.8.2 → 3.8.3

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/README.md CHANGED
@@ -13,6 +13,8 @@
13
13
  [license-src]: https://img.shields.io/npm/l/dragon-editor
14
14
  [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
15
15
  [nuxt-href]: https://nuxt.com
16
+ [sponsors-src]: https://img.shields.io/github/sponsors/lovefields
17
+ [sponsors-href]: https://github.com/sponsors/lovefields
16
18
 
17
19
  [![stars-src]][stars-href]
18
20
  [![forks-src]][forks-href]
@@ -21,6 +23,7 @@
21
23
  [![npm-version-src]][npm-version-href]
22
24
  [![npm-downloads-src]][npm-downloads-href]
23
25
  ![NPM][license-src]
26
+ [![sponsors-src]][sponsors-href]
24
27
  [![Nuxt][nuxt-src]][nuxt-href]
25
28
 
26
29
  # DragonEditor
@@ -84,3 +87,13 @@ Done!
84
87
  ```
85
88
 
86
89
  More information is [here](https://lovefields.github.io/dragonEditor-doc/)
90
+
91
+ # Sponsors
92
+
93
+ Support this project by becoming a sponsor. [GitHub Sponsors](https://github.com/sponsors/lovefields)
94
+
95
+ <div align="center">
96
+ <a href="https://github.com/kyu91">
97
+ <img src="https://github.com/kyu91.png" width="50" title="kyu91" />
98
+ </a>
99
+ </div>
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "nuxt": ">=3.0.0"
5
5
  },
6
6
  "configKey": "dragon-editor",
7
- "version": "3.8.2",
7
+ "version": "3.8.3",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineNuxtModule, createResolver, addComponent, addTypeTemplate } from '@nuxt/kit';
2
2
 
3
- const module = defineNuxtModule({
3
+ const module$1 = defineNuxtModule({
4
4
  meta: {
5
5
  name: "dragon-editor",
6
6
  compatibility: {
@@ -40,4 +40,4 @@ async function readFile(path) {
40
40
  }
41
41
  }
42
42
 
43
- export { module as default };
43
+ export { module$1 as default };
@@ -45,6 +45,7 @@ const editorStore = ref({
45
45
  },
46
46
  controlStatus: {
47
47
  isMobile: false,
48
+ hasTransformParent: false,
48
49
  currentBlockType: "text",
49
50
  codeBlockTheme: "github-light",
50
51
  codeBlockLang: "text",
@@ -55,7 +56,8 @@ const editorStore = ref({
55
56
  anchorValidation: false,
56
57
  previousCorsorData: null,
57
58
  $anchorInput: null,
58
- $currentBlock: null
59
+ $currentBlock: null,
60
+ $transformElement: null
59
61
  },
60
62
  codeBlockTheme: [
61
63
  {
@@ -548,6 +550,9 @@ defineExpose({
548
550
  height: 100%;
549
551
  border: 0;
550
552
  }
553
+ .dragon-editor .de-controlbar .de-col .de-name {
554
+ width: 70px;
555
+ }
551
556
  .dragon-editor .de-block {
552
557
  width: 100%;
553
558
  padding: 2px 0;
@@ -339,6 +339,9 @@
339
339
  height: 100%;
340
340
  border: 0;
341
341
  }
342
+ .dragon-editor .de-controlbar .de-col .de-name {
343
+ width: 70px;
344
+ }
342
345
  .dragon-editor .de-block {
343
346
  width: 100%;
344
347
  padding: 2px 0;
@@ -51,6 +51,7 @@ interface DragonEditorStore {
51
51
  };
52
52
  controlStatus: {
53
53
  isMobile: boolean;
54
+ hasTransformParent: boolean;
54
55
  anchorValidation: boolean;
55
56
  currentBlockType: DEBlock;
56
57
  codeBlockTheme: DECodeblockTheme;
@@ -62,6 +63,7 @@ interface DragonEditorStore {
62
63
  previousCorsorData: DEditorCursor | null;
63
64
  $anchorInput: HTMLInputElement | null;
64
65
  $currentBlock: HTMLDivElement | null;
66
+ $transformElement: HTMLElement | null;
65
67
  };
66
68
  codeToHtml: codeToHtml;
67
69
  codeBlockTheme: DECodeItem<DECodeblockTheme>[];
@@ -72,180 +72,201 @@ function __pasteToMarkDownFormat(value, store) {
72
72
  const codeBlockReg = new RegExp("^```");
73
73
  let tempData = null;
74
74
  let isCodeBlock = false;
75
- lineList.forEach((text, lineIndex) => {
76
- switch (true) {
77
- case new RegExp("^(---|___|\\*\\*\\*)").test(text):
78
- blockList.push({
79
- type: "divider"
80
- });
81
- break;
82
- case (codeBlockReg.test(text) || isCodeBlock === true):
83
- if (isCodeBlock === false) {
84
- const startLineText = text.split("```");
85
- let codeBlockLang = "text";
86
- if (["text", "csharp", "c", "cpp", "css", "django", "dockerfile", "go", "html", "json", "java", "javascript", "typescript", "kotlin", "lua", "markdown", "nginx", "php", "python", "ruby", "scss", "sql", "shellscript", "swift", "yaml"].includes(startLineText[1]) === true) {
87
- codeBlockLang = startLineText[1];
88
- }
89
- isCodeBlock = true;
90
- tempData = {
91
- type: "code",
92
- filename: "",
93
- theme: "github-light",
94
- language: codeBlockLang,
95
- textContent: ""
96
- };
97
- } else {
98
- if (tempData !== null) {
99
- if (codeBlockReg.test(text) !== true) {
100
- if (tempData.type === "code") {
101
- tempData.textContent += `${text}
75
+ if (lineList.length === 1) {
76
+ const selection = window.getSelection();
77
+ const textNode = document.createTextNode(lineList[0]);
78
+ selection.deleteFromDocument();
79
+ selection.getRangeAt(0).insertNode(textNode);
80
+ _setCursor(textNode, textNode.length);
81
+ } else {
82
+ let isDelete = false;
83
+ let $target = null;
84
+ lineList.forEach((text, lineIndex) => {
85
+ switch (true) {
86
+ case new RegExp("^(---|___|\\*\\*\\*)").test(text):
87
+ blockList.push({
88
+ type: "divider"
89
+ });
90
+ break;
91
+ case (codeBlockReg.test(text) || isCodeBlock === true):
92
+ if (isCodeBlock === false) {
93
+ const startLineText = text.split("```");
94
+ let codeBlockLang = "text";
95
+ if (["text", "csharp", "c", "cpp", "css", "django", "dockerfile", "go", "html", "json", "java", "javascript", "typescript", "kotlin", "lua", "markdown", "nginx", "php", "python", "ruby", "scss", "sql", "shellscript", "swift", "yaml"].includes(startLineText[1]) === true) {
96
+ codeBlockLang = startLineText[1];
97
+ }
98
+ isCodeBlock = true;
99
+ tempData = {
100
+ type: "code",
101
+ filename: "",
102
+ theme: "github-light",
103
+ language: codeBlockLang,
104
+ textContent: ""
105
+ };
106
+ } else {
107
+ if (tempData !== null) {
108
+ if (codeBlockReg.test(text) !== true) {
109
+ if (tempData.type === "code") {
110
+ tempData.textContent += `${text}
102
111
  `;
112
+ }
113
+ } else {
114
+ blockList.push(tempData);
115
+ isCodeBlock = false;
116
+ tempData = null;
103
117
  }
104
- } else {
105
- blockList.push(tempData);
106
- isCodeBlock = false;
107
- tempData = null;
108
118
  }
109
119
  }
110
- }
111
- break;
112
- case orderListReg.test(text):
113
- const olSplitText = text.split(new RegExp("\\d+.(?= )"));
114
- const olDepth = Math.floor(olSplitText[0].length / 4);
115
- if (tempData === null) {
116
- tempData = {
117
- type: "list",
118
- style: ["decimal", "lower-alpha", "upper-alpha", "lower-roman", "upper-roman"][olDepth],
119
- depth: olDepth,
120
- element: "ol",
121
- child: []
122
- };
123
- tempData.child.push({
124
- classList: [],
125
- textContent: ___replaceTextData(olSplitText[1].trim())
126
- });
127
- } else {
128
- if (tempData.type === "list") {
129
- const nextLine = lineList[lineIndex + 1];
120
+ break;
121
+ case orderListReg.test(text):
122
+ const olSplitText = text.split(new RegExp("\\d+.(?= )"));
123
+ const olDepth = Math.floor(olSplitText[0].length / 4);
124
+ if (tempData === null) {
125
+ tempData = {
126
+ type: "list",
127
+ style: ["decimal", "lower-alpha", "upper-alpha", "lower-roman", "upper-roman"][olDepth],
128
+ depth: olDepth,
129
+ element: "ol",
130
+ child: []
131
+ };
130
132
  tempData.child.push({
131
133
  classList: [],
132
134
  textContent: ___replaceTextData(olSplitText[1].trim())
133
135
  });
134
- if (nextLine !== void 0) {
135
- const nextOlSplitText = nextLine.split(new RegExp("\\d+.(?= )"));
136
- const nextOlDepth = Math.floor(nextOlSplitText[0].length / 4);
137
- if (orderListReg.test(nextLine) === false) {
138
- blockList.push(tempData);
139
- tempData = null;
140
- } else {
141
- if (tempData.depth !== nextOlDepth) {
136
+ } else {
137
+ if (tempData.type === "list") {
138
+ const nextLine = lineList[lineIndex + 1];
139
+ tempData.child.push({
140
+ classList: [],
141
+ textContent: ___replaceTextData(olSplitText[1].trim())
142
+ });
143
+ if (nextLine !== void 0) {
144
+ const nextOlSplitText = nextLine.split(new RegExp("\\d+.(?= )"));
145
+ const nextOlDepth = Math.floor(nextOlSplitText[0].length / 4);
146
+ if (orderListReg.test(nextLine) === false) {
142
147
  blockList.push(tempData);
143
148
  tempData = null;
149
+ } else {
150
+ if (tempData.depth !== nextOlDepth) {
151
+ blockList.push(tempData);
152
+ tempData = null;
153
+ }
144
154
  }
155
+ } else {
156
+ blockList.push(tempData);
157
+ tempData = null;
145
158
  }
146
- } else {
147
- blockList.push(tempData);
148
- tempData = null;
149
159
  }
150
160
  }
151
- }
152
- break;
153
- case unorderListReg.test(text):
154
- const ulSplitText = text.split(new RegExp("\\+|\\*|-"));
155
- const ulDepth = Math.floor(ulSplitText[0].length / 4);
156
- if (tempData === null) {
157
- tempData = {
158
- type: "list",
159
- style: ulDepth % 2 === 0 ? "disc" : "square",
160
- depth: ulDepth,
161
- element: "ul",
162
- child: []
163
- };
164
- tempData.child.push({
165
- classList: [],
166
- textContent: ___replaceTextData(ulSplitText[1].trim())
167
- });
168
- } else {
169
- if (tempData.type === "list") {
170
- const nextLine = lineList[lineIndex + 1];
161
+ break;
162
+ case unorderListReg.test(text):
163
+ const ulSplitText = text.split(new RegExp("\\+|\\*|-"));
164
+ const ulDepth = Math.floor(ulSplitText[0].length / 4);
165
+ if (tempData === null) {
166
+ tempData = {
167
+ type: "list",
168
+ style: ulDepth % 2 === 0 ? "disc" : "square",
169
+ depth: ulDepth,
170
+ element: "ul",
171
+ child: []
172
+ };
171
173
  tempData.child.push({
172
174
  classList: [],
173
175
  textContent: ___replaceTextData(ulSplitText[1].trim())
174
176
  });
175
- if (nextLine !== void 0) {
176
- const nextUlSplitText = nextLine.split(new RegExp("\\+|\\*|-"));
177
- const nextUlDepth = Math.floor(nextUlSplitText[0].length / 4);
178
- if (unorderListReg.test(nextLine) === false) {
179
- blockList.push(tempData);
180
- tempData = null;
181
- } else {
182
- if (tempData.depth !== nextUlDepth) {
177
+ } else {
178
+ if (tempData.type === "list") {
179
+ const nextLine = lineList[lineIndex + 1];
180
+ tempData.child.push({
181
+ classList: [],
182
+ textContent: ___replaceTextData(ulSplitText[1].trim())
183
+ });
184
+ if (nextLine !== void 0) {
185
+ const nextUlSplitText = nextLine.split(new RegExp("\\+|\\*|-"));
186
+ const nextUlDepth = Math.floor(nextUlSplitText[0].length / 4);
187
+ if (unorderListReg.test(nextLine) === false) {
183
188
  blockList.push(tempData);
184
189
  tempData = null;
190
+ } else {
191
+ if (tempData.depth !== nextUlDepth) {
192
+ blockList.push(tempData);
193
+ tempData = null;
194
+ }
185
195
  }
196
+ } else {
197
+ blockList.push(tempData);
198
+ tempData = null;
186
199
  }
187
- } else {
188
- blockList.push(tempData);
189
- tempData = null;
190
200
  }
191
201
  }
202
+ break;
203
+ case new RegExp("^###(?= )").test(text):
204
+ blockList.push({
205
+ type: "heading",
206
+ level: 3,
207
+ id: _generateId(),
208
+ classList: [],
209
+ textContent: ___replaceTextData(text.substring(4))
210
+ });
211
+ break;
212
+ case new RegExp("^##(?= )").test(text):
213
+ blockList.push({
214
+ type: "heading",
215
+ level: 2,
216
+ id: _generateId(),
217
+ classList: [],
218
+ textContent: ___replaceTextData(text.substring(3))
219
+ });
220
+ break;
221
+ case new RegExp("^#(?= )").test(text):
222
+ blockList.push({
223
+ type: "heading",
224
+ level: 1,
225
+ id: _generateId(),
226
+ classList: [],
227
+ textContent: ___replaceTextData(text.substring(2))
228
+ });
229
+ break;
230
+ default:
231
+ blockList.push({
232
+ type: "text",
233
+ classList: [],
234
+ textContent: ___replaceTextData(text)
235
+ });
236
+ }
237
+ });
238
+ if (store.value.controlStatus.currentBlockType === "heading" || store.value.controlStatus.currentBlockType === "text") {
239
+ if (store.value.controlStatus.$currentBlock !== null) {
240
+ if (store.value.controlStatus.$currentBlock.textContent === "") {
241
+ isDelete = true;
242
+ $target = store.value.controlStatus.$currentBlock;
192
243
  }
193
- break;
194
- case new RegExp("^###(?= )").test(text):
195
- blockList.push({
196
- type: "heading",
197
- level: 3,
198
- id: _generateId(),
199
- classList: [],
200
- textContent: ___replaceTextData(text.substring(4))
201
- });
202
- break;
203
- case new RegExp("^##(?= )").test(text):
204
- blockList.push({
205
- type: "heading",
206
- level: 2,
207
- id: _generateId(),
208
- classList: [],
209
- textContent: ___replaceTextData(text.substring(3))
210
- });
211
- break;
212
- case new RegExp("^#(?= )").test(text):
213
- blockList.push({
214
- type: "heading",
215
- level: 1,
216
- id: _generateId(),
217
- classList: [],
218
- textContent: ___replaceTextData(text.substring(2))
219
- });
220
- break;
221
- default:
222
- blockList.push({
223
- type: "text",
224
- classList: [],
225
- textContent: ___replaceTextData(text)
226
- });
244
+ }
227
245
  }
228
- });
229
- blockList.forEach((data) => {
230
- switch (data.type) {
231
- case "heading":
232
- if (data.level === 1) {
233
- _addBlock("heading1", store, data);
234
- }
235
- if (data.level === 2) {
236
- _addBlock("heading2", store, data);
237
- }
238
- if (data.level === 3) {
239
- _addBlock("heading3", store, data);
240
- }
241
- break;
242
- case "list":
243
- _addBlock(data.element, store, data);
244
- break;
245
- default:
246
- _addBlock(data.type, store, data);
246
+ blockList.forEach((data) => {
247
+ switch (data.type) {
248
+ case "heading":
249
+ if (data.level === 1) {
250
+ _addBlock("heading1", store, data);
251
+ }
252
+ if (data.level === 2) {
253
+ _addBlock("heading2", store, data);
254
+ }
255
+ if (data.level === 3) {
256
+ _addBlock("heading3", store, data);
257
+ }
258
+ break;
259
+ case "list":
260
+ _addBlock(data.element, store, data);
261
+ break;
262
+ default:
263
+ _addBlock(data.type, store, data);
264
+ }
265
+ });
266
+ if (isDelete === true) {
267
+ $target?.remove();
247
268
  }
248
- });
269
+ }
249
270
  }
250
271
  }
251
272
  function ___replaceTextData(text) {
@@ -56,8 +56,22 @@ export function _decideWhetherOpenControlBar(store) {
56
56
  const allowTypeList = ["code", "ol", "ul"];
57
57
  if (allowTypeList.includes(type) === true && $element !== null) {
58
58
  const targetRect = $element.getBoundingClientRect();
59
- store.value.controlBar.x = Math.floor(targetRect.left + targetRect.width / 2);
60
- store.value.controlBar.y = Math.floor(targetRect.top - 8 - 32);
59
+ let x = Math.floor(targetRect.left + targetRect.width / 2);
60
+ let y = Math.floor(targetRect.top - 8 - 32);
61
+ if (store.value.controlStatus.hasTransformParent === true && store.value.controlStatus.$transformElement !== null) {
62
+ const transformRect = store.value.controlStatus.$transformElement.getBoundingClientRect();
63
+ x -= transformRect.left;
64
+ y -= transformRect.top;
65
+ if (store.value.$parentWrap !== null) {
66
+ if (store.value.$parentWrap === window) {
67
+ y += store.value.$parentWrap.scrollY;
68
+ } else {
69
+ y += store.value.$parentWrap.scrollTop;
70
+ }
71
+ }
72
+ }
73
+ store.value.controlBar.x = x;
74
+ store.value.controlBar.y = y;
61
75
  store.value.controlBar.$element = $element;
62
76
  store.value.controlBar.active = true;
63
77
  } else {
@@ -1,13 +1,21 @@
1
- import { _findScrollingElement } from "../node/index.js";
1
+ import { _findScrollingElement, _findTransformElement } from "../node/index.js";
2
2
  export function _eidtorMountEvent(store) {
3
3
  const $editor = document.querySelector(".js-dragon-editor");
4
4
  const $body = document.querySelector(".js-de-body");
5
5
  const $controlBar = document.querySelector(".js-de-controlbar");
6
6
  const $parentWrap = _findScrollingElement($editor);
7
+ const $transformWrap = _findTransformElement($editor);
7
8
  store.value.$editor = $editor;
8
9
  store.value.$body = $body;
9
10
  store.value.$controlBar = $controlBar;
10
11
  store.value.$parentWrap = $parentWrap;
12
+ if ($transformWrap === null) {
13
+ store.value.controlStatus.hasTransformParent = false;
14
+ store.value.controlStatus.$transformElement = null;
15
+ } else {
16
+ store.value.controlStatus.hasTransformParent = true;
17
+ store.value.controlStatus.$transformElement = $transformWrap;
18
+ }
11
19
  __checkAndSetUpMobile(store);
12
20
  window.addEventListener("click", store.value.windowClickEvent);
13
21
  window.addEventListener("resize", store.value.windowResizeEvent);
@@ -1,4 +1,5 @@
1
1
  export declare function _findScrollingElement($target: HTMLElement): HTMLElement | Window;
2
+ export declare function _findTransformElement($target: HTMLElement): HTMLElement | null;
2
3
  export declare function _getParentElementIfNodeIsText($target: Node, $block: HTMLElement): Node;
3
4
  export declare function _findContentEditableElement($target: Node): HTMLElement | null;
4
5
  export declare function _findPoverTextNode(node: Element, idx: number): number;
@@ -1,18 +1,37 @@
1
1
  export function _findScrollingElement($target) {
2
- if ($target.parentElement !== null) {
3
- if ($target.scrollHeight > $target.clientHeight) {
4
- return $target;
2
+ const $wrap = $target.parentElement;
3
+ if ($wrap !== null) {
4
+ const style = window.getComputedStyle($wrap);
5
+ if (style.overflow !== "visible") {
6
+ return $wrap;
5
7
  } else {
6
- if ($target.parentElement.tagName === "BODY") {
8
+ if ($wrap.tagName === "BODY") {
7
9
  return window;
8
10
  } else {
9
- return _findScrollingElement($target.parentElement);
11
+ return _findScrollingElement($wrap);
10
12
  }
11
13
  }
12
14
  } else {
13
15
  return window;
14
16
  }
15
17
  }
18
+ export function _findTransformElement($target) {
19
+ const $wrap = $target.parentElement;
20
+ if ($wrap !== null) {
21
+ const style = window.getComputedStyle($wrap);
22
+ if (style.transform !== "none") {
23
+ return $wrap;
24
+ } else {
25
+ if ($wrap.tagName === "BODY") {
26
+ return null;
27
+ } else {
28
+ return _findTransformElement($wrap);
29
+ }
30
+ }
31
+ } else {
32
+ return null;
33
+ }
34
+ }
16
35
  export function _getParentElementIfNodeIsText($target, $block) {
17
36
  if ($target.constructor.name === "Text") {
18
37
  const $parent = $target.parentElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dragon-editor",
3
- "version": "3.8.2",
3
+ "version": "3.8.3",
4
4
  "description": "Javascript WYSIWYG editor in Nuxt!",
5
5
  "repository": {
6
6
  "type": "git",