react-text-range 1.0.13 → 1.0.15
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/dist/cjs/index.js +27 -15
- package/dist/esm/index.js +27 -15
- package/package.json +1 -1
- package/dist/cjs/esm/rect.d.ts +0 -6
- package/dist/cjs/index.html +0 -17
- package/dist/cjs/server.js +0 -6
- package/dist/esm/rect.d.ts +0 -6
package/dist/cjs/index.js
CHANGED
|
@@ -22,12 +22,12 @@ function _interopNamespaceDefault(e) {
|
|
|
22
22
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
23
23
|
|
|
24
24
|
const getHandlerRect = (node, left) => {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f;
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
26
26
|
if (!node || !node.childNodes || node.childNodes.length != 6)
|
|
27
27
|
return null;
|
|
28
|
-
const headLength = (_b = (_a = node.childNodes[1].firstChild) === null || _a === void 0 ? void 0 : _a.nodeValue) === null || _b === void 0 ? void 0 : _b.length;
|
|
29
|
-
const selLength = (
|
|
30
|
-
const tailLength = (
|
|
28
|
+
const headLength = (_c = (_b = (_a = node.childNodes[1].firstChild) === null || _a === void 0 ? void 0 : _a.nodeValue) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
29
|
+
const selLength = (_f = (_e = (_d = node.childNodes[3].firstChild) === null || _d === void 0 ? void 0 : _d.nodeValue) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0;
|
|
30
|
+
const tailLength = (_j = (_h = (_g = node.childNodes[5].firstChild) === null || _g === void 0 ? void 0 : _g.nodeValue) === null || _h === void 0 ? void 0 : _h.length) !== null && _j !== void 0 ? _j : 0;
|
|
31
31
|
if (left) {
|
|
32
32
|
const range = document.createRange();
|
|
33
33
|
if (selLength > 0) {
|
|
@@ -147,7 +147,7 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
147
147
|
tailSpan.classList.value = tailClass;
|
|
148
148
|
tail.surroundContents(tailSpan);
|
|
149
149
|
return () => {
|
|
150
|
-
if (textDiv.current) {
|
|
150
|
+
if (textDiv.current && textDiv.current.childNodes[0]) {
|
|
151
151
|
textDiv.current.childNodes[0].nodeValue = textDiv.current.textContent;
|
|
152
152
|
while (textDiv.current.childNodes.length > 1 && textDiv.current.lastChild) {
|
|
153
153
|
textDiv.current.removeChild(textDiv.current.lastChild);
|
|
@@ -158,7 +158,7 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
158
158
|
// mouse move handler
|
|
159
159
|
// left handler
|
|
160
160
|
const leftMoveHandler = React.useCallback((e) => {
|
|
161
|
-
var _a, _b;
|
|
161
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
162
162
|
const sm = getNodeAndOffsetFromPoint(e.clientX, e.clientY);
|
|
163
163
|
if (!sm)
|
|
164
164
|
return;
|
|
@@ -170,11 +170,17 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
170
170
|
posToSet = currentLeftPos + sm.offset;
|
|
171
171
|
}
|
|
172
172
|
if (posToSet !== currentLeftPos) {
|
|
173
|
-
const headText = textDiv.current.childNodes[1].firstChild.nodeValue;
|
|
174
|
-
const selText = textDiv.current.childNodes[3].firstChild.nodeValue;
|
|
173
|
+
const headText = (_f = (_e = (_d = (_c = textDiv.current) === null || _c === void 0 ? void 0 : _c.childNodes[1]) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.nodeValue) !== null && _f !== void 0 ? _f : '';
|
|
174
|
+
const selText = (_k = (_j = (_h = (_g = textDiv.current) === null || _g === void 0 ? void 0 : _g.childNodes[3]) === null || _h === void 0 ? void 0 : _h.firstChild) === null || _j === void 0 ? void 0 : _j.nodeValue) !== null && _k !== void 0 ? _k : '';
|
|
175
175
|
const full = headText + selText;
|
|
176
|
-
textDiv.current.childNodes[1]
|
|
177
|
-
|
|
176
|
+
const nodeChild1 = (_m = (_l = textDiv.current) === null || _l === void 0 ? void 0 : _l.childNodes[1]) === null || _m === void 0 ? void 0 : _m.firstChild;
|
|
177
|
+
if (nodeChild1) {
|
|
178
|
+
nodeChild1.nodeValue = full.substring(0, posToSet);
|
|
179
|
+
}
|
|
180
|
+
const nodeChild3 = (_p = (_o = textDiv.current) === null || _o === void 0 ? void 0 : _o.childNodes[3]) === null || _p === void 0 ? void 0 : _p.firstChild;
|
|
181
|
+
if (nodeChild3) {
|
|
182
|
+
nodeChild3.nodeValue = full.substring(posToSet);
|
|
183
|
+
}
|
|
178
184
|
setCurrentLeftPos(posToSet);
|
|
179
185
|
}
|
|
180
186
|
}, [currentLeftPos, textDiv.current]);
|
|
@@ -194,7 +200,7 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
194
200
|
}, [initLeftPos]);
|
|
195
201
|
// right handler
|
|
196
202
|
const rightMoveHandler = React.useCallback((e) => {
|
|
197
|
-
var _a, _b;
|
|
203
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
198
204
|
const sm = getNodeAndOffsetFromPoint(e.clientX, e.clientY);
|
|
199
205
|
if (!sm)
|
|
200
206
|
return;
|
|
@@ -206,11 +212,17 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
206
212
|
posToSet = currentRightPos + sm.offset;
|
|
207
213
|
}
|
|
208
214
|
if (posToSet !== currentRightPos) {
|
|
209
|
-
const selText = textDiv.current.childNodes[3].firstChild.nodeValue;
|
|
210
|
-
const tailText = textDiv.current.childNodes[5].firstChild.nodeValue;
|
|
215
|
+
const selText = (_f = (_e = (_d = (_c = textDiv.current) === null || _c === void 0 ? void 0 : _c.childNodes[3]) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.nodeValue) !== null && _f !== void 0 ? _f : '';
|
|
216
|
+
const tailText = (_k = (_j = (_h = (_g = textDiv.current) === null || _g === void 0 ? void 0 : _g.childNodes[5]) === null || _h === void 0 ? void 0 : _h.firstChild) === null || _j === void 0 ? void 0 : _j.nodeValue) !== null && _k !== void 0 ? _k : '';
|
|
211
217
|
const full = selText + tailText;
|
|
212
|
-
textDiv.current.childNodes[3]
|
|
213
|
-
|
|
218
|
+
const nodeChild3 = (_m = (_l = textDiv.current) === null || _l === void 0 ? void 0 : _l.childNodes[3]) === null || _m === void 0 ? void 0 : _m.firstChild;
|
|
219
|
+
if (nodeChild3) {
|
|
220
|
+
nodeChild3.nodeValue = full.substring(0, posToSet - currentLeftPos);
|
|
221
|
+
}
|
|
222
|
+
const nodeChild5 = (_p = (_o = textDiv.current) === null || _o === void 0 ? void 0 : _o.childNodes[5]) === null || _p === void 0 ? void 0 : _p.firstChild;
|
|
223
|
+
if (nodeChild5) {
|
|
224
|
+
nodeChild5.nodeValue = full.substring(posToSet - currentLeftPos);
|
|
225
|
+
}
|
|
214
226
|
setCurrentRightPos(posToSet);
|
|
215
227
|
}
|
|
216
228
|
}, [currentLeftPos, currentRightPos, textDiv.current]);
|
package/dist/esm/index.js
CHANGED
|
@@ -2,12 +2,12 @@ import * as React from 'react';
|
|
|
2
2
|
import React__default, { useState, useRef, useLayoutEffect, useCallback, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
const getHandlerRect = (node, left) => {
|
|
5
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
6
6
|
if (!node || !node.childNodes || node.childNodes.length != 6)
|
|
7
7
|
return null;
|
|
8
|
-
const headLength = (_b = (_a = node.childNodes[1].firstChild) === null || _a === void 0 ? void 0 : _a.nodeValue) === null || _b === void 0 ? void 0 : _b.length;
|
|
9
|
-
const selLength = (
|
|
10
|
-
const tailLength = (
|
|
8
|
+
const headLength = (_c = (_b = (_a = node.childNodes[1].firstChild) === null || _a === void 0 ? void 0 : _a.nodeValue) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
9
|
+
const selLength = (_f = (_e = (_d = node.childNodes[3].firstChild) === null || _d === void 0 ? void 0 : _d.nodeValue) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0;
|
|
10
|
+
const tailLength = (_j = (_h = (_g = node.childNodes[5].firstChild) === null || _g === void 0 ? void 0 : _g.nodeValue) === null || _h === void 0 ? void 0 : _h.length) !== null && _j !== void 0 ? _j : 0;
|
|
11
11
|
if (left) {
|
|
12
12
|
const range = document.createRange();
|
|
13
13
|
if (selLength > 0) {
|
|
@@ -127,7 +127,7 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
127
127
|
tailSpan.classList.value = tailClass;
|
|
128
128
|
tail.surroundContents(tailSpan);
|
|
129
129
|
return () => {
|
|
130
|
-
if (textDiv.current) {
|
|
130
|
+
if (textDiv.current && textDiv.current.childNodes[0]) {
|
|
131
131
|
textDiv.current.childNodes[0].nodeValue = textDiv.current.textContent;
|
|
132
132
|
while (textDiv.current.childNodes.length > 1 && textDiv.current.lastChild) {
|
|
133
133
|
textDiv.current.removeChild(textDiv.current.lastChild);
|
|
@@ -138,7 +138,7 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
138
138
|
// mouse move handler
|
|
139
139
|
// left handler
|
|
140
140
|
const leftMoveHandler = useCallback((e) => {
|
|
141
|
-
var _a, _b;
|
|
141
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
142
142
|
const sm = getNodeAndOffsetFromPoint(e.clientX, e.clientY);
|
|
143
143
|
if (!sm)
|
|
144
144
|
return;
|
|
@@ -150,11 +150,17 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
150
150
|
posToSet = currentLeftPos + sm.offset;
|
|
151
151
|
}
|
|
152
152
|
if (posToSet !== currentLeftPos) {
|
|
153
|
-
const headText = textDiv.current.childNodes[1].firstChild.nodeValue;
|
|
154
|
-
const selText = textDiv.current.childNodes[3].firstChild.nodeValue;
|
|
153
|
+
const headText = (_f = (_e = (_d = (_c = textDiv.current) === null || _c === void 0 ? void 0 : _c.childNodes[1]) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.nodeValue) !== null && _f !== void 0 ? _f : '';
|
|
154
|
+
const selText = (_k = (_j = (_h = (_g = textDiv.current) === null || _g === void 0 ? void 0 : _g.childNodes[3]) === null || _h === void 0 ? void 0 : _h.firstChild) === null || _j === void 0 ? void 0 : _j.nodeValue) !== null && _k !== void 0 ? _k : '';
|
|
155
155
|
const full = headText + selText;
|
|
156
|
-
textDiv.current.childNodes[1]
|
|
157
|
-
|
|
156
|
+
const nodeChild1 = (_m = (_l = textDiv.current) === null || _l === void 0 ? void 0 : _l.childNodes[1]) === null || _m === void 0 ? void 0 : _m.firstChild;
|
|
157
|
+
if (nodeChild1) {
|
|
158
|
+
nodeChild1.nodeValue = full.substring(0, posToSet);
|
|
159
|
+
}
|
|
160
|
+
const nodeChild3 = (_p = (_o = textDiv.current) === null || _o === void 0 ? void 0 : _o.childNodes[3]) === null || _p === void 0 ? void 0 : _p.firstChild;
|
|
161
|
+
if (nodeChild3) {
|
|
162
|
+
nodeChild3.nodeValue = full.substring(posToSet);
|
|
163
|
+
}
|
|
158
164
|
setCurrentLeftPos(posToSet);
|
|
159
165
|
}
|
|
160
166
|
}, [currentLeftPos, textDiv.current]);
|
|
@@ -174,7 +180,7 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
174
180
|
}, [initLeftPos]);
|
|
175
181
|
// right handler
|
|
176
182
|
const rightMoveHandler = useCallback((e) => {
|
|
177
|
-
var _a, _b;
|
|
183
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
178
184
|
const sm = getNodeAndOffsetFromPoint(e.clientX, e.clientY);
|
|
179
185
|
if (!sm)
|
|
180
186
|
return;
|
|
@@ -186,11 +192,17 @@ const useTextSelectionEditor = (initLeftPos, initRightPos, leftDrag, rightDrag,
|
|
|
186
192
|
posToSet = currentRightPos + sm.offset;
|
|
187
193
|
}
|
|
188
194
|
if (posToSet !== currentRightPos) {
|
|
189
|
-
const selText = textDiv.current.childNodes[3].firstChild.nodeValue;
|
|
190
|
-
const tailText = textDiv.current.childNodes[5].firstChild.nodeValue;
|
|
195
|
+
const selText = (_f = (_e = (_d = (_c = textDiv.current) === null || _c === void 0 ? void 0 : _c.childNodes[3]) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.nodeValue) !== null && _f !== void 0 ? _f : '';
|
|
196
|
+
const tailText = (_k = (_j = (_h = (_g = textDiv.current) === null || _g === void 0 ? void 0 : _g.childNodes[5]) === null || _h === void 0 ? void 0 : _h.firstChild) === null || _j === void 0 ? void 0 : _j.nodeValue) !== null && _k !== void 0 ? _k : '';
|
|
191
197
|
const full = selText + tailText;
|
|
192
|
-
textDiv.current.childNodes[3]
|
|
193
|
-
|
|
198
|
+
const nodeChild3 = (_m = (_l = textDiv.current) === null || _l === void 0 ? void 0 : _l.childNodes[3]) === null || _m === void 0 ? void 0 : _m.firstChild;
|
|
199
|
+
if (nodeChild3) {
|
|
200
|
+
nodeChild3.nodeValue = full.substring(0, posToSet - currentLeftPos);
|
|
201
|
+
}
|
|
202
|
+
const nodeChild5 = (_p = (_o = textDiv.current) === null || _o === void 0 ? void 0 : _o.childNodes[5]) === null || _p === void 0 ? void 0 : _p.firstChild;
|
|
203
|
+
if (nodeChild5) {
|
|
204
|
+
nodeChild5.nodeValue = full.substring(posToSet - currentLeftPos);
|
|
205
|
+
}
|
|
194
206
|
setCurrentRightPos(posToSet);
|
|
195
207
|
}
|
|
196
208
|
}, [currentLeftPos, currentRightPos, textDiv.current]);
|
package/package.json
CHANGED
package/dist/cjs/esm/rect.d.ts
DELETED
package/dist/cjs/index.html
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<title>Document</title>
|
|
8
|
-
</head>
|
|
9
|
-
|
|
10
|
-
<body>
|
|
11
|
-
<div id="root"></div>
|
|
12
|
-
<script defer src="/index.js"></script>
|
|
13
|
-
</body>
|
|
14
|
-
|
|
15
|
-
</body>
|
|
16
|
-
|
|
17
|
-
</html>
|
package/dist/cjs/server.js
DELETED