@godxjp/editor 31.19.0 → 31.20.0

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
@@ -5,7 +5,7 @@ rendered by [`@godxjp/markdown`](../markdown) (the same sanitiser as the publish
5
5
  pasted, dropped or attached through an upload function **the host** provides.
6
6
 
7
7
  ```bash
8
- pnpm add @godxjp/editor @godxjp/markdown @godxjp/ui lucide-react
8
+ pnpm add @godxjp/editor @godxjp/markdown @godxjp/ui
9
9
  ```
10
10
 
11
11
  ```tsx
package/dist/index.js CHANGED
@@ -36,12 +36,29 @@ function wrapSelection(text, { start, end }, before, after, placeholder) {
36
36
  select: { start: outerStart, end: outerStart + selected.length }
37
37
  };
38
38
  }
39
- const body = selected || placeholder;
39
+ if (!selected) {
40
+ return {
41
+ from: start,
42
+ to: end,
43
+ insert: `${before}${placeholder}${after}`,
44
+ select: { start: start + before.length, end: start + before.length + placeholder.length }
45
+ };
46
+ }
47
+ const count = (value) => before === after ? value.split(before).length - 1 : 0;
48
+ let from = start;
49
+ let to = end;
50
+ if (text.slice(start - before.length, start) === before && count(text.slice(0, start)) % 2 === 1) {
51
+ from = start - before.length;
52
+ }
53
+ if (text.slice(end, end + after.length) === after && count(text.slice(0, end)) % 2 === 1) {
54
+ to = end + after.length;
55
+ }
56
+ const body = text.slice(from, to).split(before).join("").split(after).join("");
40
57
  return {
41
- from: start,
42
- to: end,
58
+ from,
59
+ to,
43
60
  insert: `${before}${body}${after}`,
44
- select: { start: start + before.length, end: start + before.length + body.length }
61
+ select: { start: from + before.length, end: from + before.length + body.length }
45
62
  };
46
63
  }
47
64
  function lineRange(text, { start, end }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godxjp/editor",
3
- "version": "31.19.0",
3
+ "version": "31.20.0",
4
4
  "description": "Markdown editor for GoDX apps: formatting toolbar, write / preview / side by side with @godxjp/markdown, paste / drop / attach through a host upload function, IME-safe, ja / en / vi.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,10 +28,12 @@
28
28
  "directory": "packages/editor"
29
29
  },
30
30
  "license": "Apache-2.0",
31
+ "dependencies": {
32
+ "lucide-react": "^1.37.0"
33
+ },
31
34
  "peerDependencies": {
32
- "@godxjp/markdown": "~31.19.0",
33
- "@godxjp/ui": "~31.19.0",
34
- "lucide-react": ">=1.0.0",
35
+ "@godxjp/markdown": "~31.20.0",
36
+ "@godxjp/ui": "~31.20.0",
35
37
  "react": ">=19.0.0"
36
38
  },
37
39
  "keywords": [