react-text-range 1.0.8 → 1.0.9
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 +10 -4
- package/dist/cjs/esm/ReactTextRange.d.ts +2 -0
- package/dist/cjs/esm/SelectionHandler.d.ts +2 -0
- package/dist/cjs/index.js +24 -18
- package/dist/cjs/server.js +6 -0
- package/dist/esm/ReactTextRange.d.ts +2 -0
- package/dist/esm/SelectionHandler.d.ts +2 -0
- package/dist/esm/index.js +24 -18
- package/dist/index.d.ts +2 -0
- package/package.json +2 -2
- package/dist/cjs/esm/FullWindow.d.ts +0 -6
- package/dist/cjs/esm/TextContainer.d.ts +0 -4
- package/dist/cjs/esm/TextSelectionZone.d.ts +0 -12
- package/dist/esm/FullWindow.d.ts +0 -6
- package/dist/esm/TextContainer.d.ts +0 -4
- package/dist/esm/TextSelectionZone.d.ts +0 -12
- package/dist/esm/index.html +0 -17
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# react-text-range
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
## using
|
|
4
6
|
|
|
5
7
|
```js
|
|
@@ -8,11 +10,12 @@ import { TextContainer, RangeState, ReactTextRange } from "./ReactTextRange";
|
|
|
8
10
|
|
|
9
11
|
const MyTextContainer: TextContainer = React.forwardRef(({ children }, ref) =>
|
|
10
12
|
<div ref={ref} style={{
|
|
11
|
-
fontSize:
|
|
13
|
+
fontSize: 24,
|
|
12
14
|
width: '320px',
|
|
13
15
|
backgroundColor: 'rgba(253, 224, 71, .2)',
|
|
14
16
|
userSelect: 'none',
|
|
15
17
|
padding: '20px',
|
|
18
|
+
whiteSpace: 'pre-wrap',
|
|
16
19
|
}}>
|
|
17
20
|
{children}
|
|
18
21
|
</div>
|
|
@@ -22,9 +25,12 @@ const App: FunctionComponent = () => {
|
|
|
22
25
|
const [myPos, setMyPos] = useState<RangeState>({ left: 23, right: 37 })
|
|
23
26
|
return (
|
|
24
27
|
<div style={{ margin: 20 }}>
|
|
25
|
-
<ReactTextRange initLeftPos={23} initRightPos={
|
|
26
|
-
Container={MyTextContainer} onChange={setMyPos}
|
|
27
|
-
|
|
28
|
+
<ReactTextRange initLeftPos={23} initRightPos={47}
|
|
29
|
+
Container={MyTextContainer} onChange={setMyPos}
|
|
30
|
+
selectionColor='yellow' handlerWidth={18}>{
|
|
31
|
+
`Some text
|
|
32
|
+
or even some real good multiline text
|
|
33
|
+
here and there`}
|
|
28
34
|
</ReactTextRange>
|
|
29
35
|
<div>
|
|
30
36
|
<span>{myPos?.left}</span>
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const getHandlerRect = (index, node) => {
|
|
|
27
27
|
range.setEnd(node, index);
|
|
28
28
|
if (range.getClientRects) {
|
|
29
29
|
const rects = range.getClientRects();
|
|
30
|
-
if (rects.length
|
|
30
|
+
if (rects.length >= 1) {
|
|
31
31
|
return rects[0];
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -203,8 +203,7 @@ function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : func
|
|
|
203
203
|
var SvgQuoteLeft = function SvgQuoteLeft(props) {
|
|
204
204
|
return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({
|
|
205
205
|
xmlns: "http://www.w3.org/2000/svg",
|
|
206
|
-
|
|
207
|
-
height: 24
|
|
206
|
+
viewBox: "0 0 24 24"
|
|
208
207
|
}, props), _path$1 || (_path$1 = /*#__PURE__*/React__namespace.createElement("path", {
|
|
209
208
|
d: "M13 14.725C13 9.584 16.892 4.206 23 3l.984 2.126c-2.215.835-4.163 3.742-4.38 5.746A5.213 5.213 0 0 1 24 16.021C24 19.203 21.416 21 18.801 21 15.786 21 13 18.695 13 14.725zm-13 0C0 9.584 3.892 4.206 10 3l.984 2.126c-2.215.835-4.163 3.742-4.38 5.746A5.213 5.213 0 0 1 11 16.021C11 19.203 8.416 21 5.801 21 2.786 21 0 18.695 0 14.725z"
|
|
210
209
|
})));
|
|
@@ -215,8 +214,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
215
214
|
var SvgQuoteRight = function SvgQuoteRight(props) {
|
|
216
215
|
return /*#__PURE__*/React__namespace.createElement("svg", _extends({
|
|
217
216
|
xmlns: "http://www.w3.org/2000/svg",
|
|
218
|
-
|
|
219
|
-
height: 24
|
|
217
|
+
viewBox: "0 0 24 24"
|
|
220
218
|
}, props), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
|
|
221
219
|
d: "M11 9.275C11 14.416 7.108 19.794 1 21l-.984-2.126c2.215-.835 4.163-3.742 4.38-5.746A5.213 5.213 0 0 1 0 7.979C0 4.797 2.584 3 5.199 3 8.214 3 11 5.305 11 9.275zm13 0C24 14.416 20.108 19.794 14 21l-.984-2.126c2.215-.835 4.163-3.742 4.38-5.746A5.213 5.213 0 0 1 13 7.979C13 4.797 15.584 3 18.199 3 21.214 3 24 5.305 24 9.275z"
|
|
222
220
|
})));
|
|
@@ -249,20 +247,25 @@ function styleInject(css, ref) {
|
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
249
|
|
|
252
|
-
var css_248z = "/*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}html{-webkit-text-size-adjust:100%;font-feature-settings:normal;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]{display:none}*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.absolute{position:absolute}.relative{position:relative}.flex{display:flex}.rounded-l-md{border-bottom-left-radius:.375rem;border-top-left-radius:.375rem}.rounded-r-md{border-bottom-right-radius:.375rem;border-top-right-radius:.375rem}
|
|
250
|
+
var css_248z = "/*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}html{-webkit-text-size-adjust:100%;font-feature-settings:normal;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]{display:none}*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.absolute{position:absolute}.relative{position:relative}.flex{display:flex}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rounded-l-md{border-bottom-left-radius:.375rem;border-top-left-radius:.375rem}.rounded-r-md{border-bottom-right-radius:.375rem;border-top-right-radius:.375rem}";
|
|
253
251
|
styleInject(css_248z,{"insertAt":"top"});
|
|
254
252
|
|
|
255
|
-
const SelectionHandler = ({ pos, grab, setGrab, left }) => {
|
|
253
|
+
const SelectionHandler = ({ pos, grab, setGrab, left, bgColor, width }) => {
|
|
254
|
+
const bgColorDef = bgColor !== null && bgColor !== void 0 ? bgColor : 'rgb(253 224 71)';
|
|
255
|
+
const widthDef = width !== null && width !== void 0 ? width : 25;
|
|
256
256
|
return (pos &&
|
|
257
|
-
React.createElement("div", { draggable: false, className:
|
|
257
|
+
React.createElement("div", { draggable: false, className: `${left ? 'rounded-l-md' : 'rounded-r-md'}`, style: {
|
|
258
258
|
position: 'absolute',
|
|
259
259
|
display: 'flex',
|
|
260
|
-
left: left ? pos.left -
|
|
260
|
+
left: left ? pos.left - (widthDef - 1) : pos.left - 1,
|
|
261
261
|
top: pos.top,
|
|
262
|
-
width:
|
|
262
|
+
width: `${widthDef}px`,
|
|
263
263
|
height: pos.height,
|
|
264
264
|
cursor: grab ? 'grabbing' : 'grab',
|
|
265
265
|
alignItems: left ? 'flex-start' : 'flex-end',
|
|
266
|
+
backgroundColor: bgColorDef,
|
|
267
|
+
opacity: .8,
|
|
268
|
+
// transform: 'scale(.5)'
|
|
266
269
|
}, onMouseDown: () => {
|
|
267
270
|
setGrab(true);
|
|
268
271
|
const handler = () => {
|
|
@@ -277,7 +280,7 @@ const SelectionHandler = ({ pos, grab, setGrab, left }) => {
|
|
|
277
280
|
: React.createElement(SvgQuoteRight, null)));
|
|
278
281
|
};
|
|
279
282
|
|
|
280
|
-
const ReactTextRange = ({ initLeftPos, initRightPos, Container, children, onChange, props, }) => {
|
|
283
|
+
const ReactTextRange = ({ initLeftPos, initRightPos, Container, children, onChange, props, selectionColor, handlerWidth, }) => {
|
|
281
284
|
const [mouseOnLeft, setMouseOnLeft] = React.useState(false);
|
|
282
285
|
const [mouseOnRight, setMouseOnRight] = React.useState(false);
|
|
283
286
|
const [textDiv, leftHandler, rightHandler, rects] = useTextSelectionEditor(initLeftPos, initRightPos, mouseOnLeft, mouseOnRight);
|
|
@@ -289,25 +292,28 @@ const ReactTextRange = ({ initLeftPos, initRightPos, Container, children, onChan
|
|
|
289
292
|
});
|
|
290
293
|
}
|
|
291
294
|
}, [leftHandler, rightHandler]);
|
|
295
|
+
const bgColor = selectionColor;
|
|
292
296
|
return (React.createElement("div", { draggable: false, style: Object.assign({ position: 'relative' }, props) },
|
|
293
|
-
React.createElement(SelectionRects, { rects: rects }),
|
|
297
|
+
React.createElement(SelectionRects, { rects: rects, bgColor: bgColor }),
|
|
294
298
|
React.createElement(Container, { ref: textDiv }, children),
|
|
295
|
-
React.createElement(SelectionHandler, { grab: mouseOnLeft, left: true, pos: leftHandler, setGrab: (v) => setMouseOnLeft(v) }),
|
|
296
|
-
React.createElement(SelectionHandler, { grab: mouseOnRight, left: false, pos: rightHandler, setGrab: (v) => setMouseOnRight(v) })));
|
|
299
|
+
React.createElement(SelectionHandler, { bgColor: bgColor, width: handlerWidth, grab: mouseOnLeft, left: true, pos: leftHandler, setGrab: (v) => setMouseOnLeft(v) }),
|
|
300
|
+
React.createElement(SelectionHandler, { bgColor: bgColor, width: handlerWidth, grab: mouseOnRight, left: false, pos: rightHandler, setGrab: (v) => setMouseOnRight(v) })));
|
|
297
301
|
};
|
|
298
|
-
const SelectionRects = ({ rects }) => {
|
|
302
|
+
const SelectionRects = ({ rects, bgColor }) => {
|
|
299
303
|
if (!rects)
|
|
300
304
|
return null;
|
|
301
|
-
return (React.createElement(React.Fragment, null, rects.map((d, i) => React.createElement(SelectionRect, { key: i, rect: d }))));
|
|
305
|
+
return (React.createElement(React.Fragment, null, rects.map((d, i) => React.createElement(SelectionRect, { key: i, rect: d, bgColor: bgColor }))));
|
|
302
306
|
};
|
|
303
|
-
const SelectionRect = ({ rect }) => {
|
|
304
|
-
|
|
307
|
+
const SelectionRect = ({ rect, bgColor }) => {
|
|
308
|
+
const bgColorDef = bgColor !== null && bgColor !== void 0 ? bgColor : 'rgb(253 224 71)';
|
|
309
|
+
return (React.createElement("div", { style: {
|
|
305
310
|
userSelect: 'none',
|
|
306
311
|
position: 'absolute',
|
|
307
312
|
top: `${rect.top}px`,
|
|
308
313
|
left: `${rect.left}px`,
|
|
309
314
|
width: `${rect.width}px`,
|
|
310
315
|
height: `${rect.height}px`,
|
|
316
|
+
backgroundColor: bgColorDef,
|
|
311
317
|
} }, "\u00A0"));
|
|
312
318
|
};
|
|
313
319
|
|
package/dist/esm/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const getHandlerRect = (index, node) => {
|
|
|
7
7
|
range.setEnd(node, index);
|
|
8
8
|
if (range.getClientRects) {
|
|
9
9
|
const rects = range.getClientRects();
|
|
10
|
-
if (rects.length
|
|
10
|
+
if (rects.length >= 1) {
|
|
11
11
|
return rects[0];
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -183,8 +183,7 @@ function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : func
|
|
|
183
183
|
var SvgQuoteLeft = function SvgQuoteLeft(props) {
|
|
184
184
|
return /*#__PURE__*/React.createElement("svg", _extends$1({
|
|
185
185
|
xmlns: "http://www.w3.org/2000/svg",
|
|
186
|
-
|
|
187
|
-
height: 24
|
|
186
|
+
viewBox: "0 0 24 24"
|
|
188
187
|
}, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
|
|
189
188
|
d: "M13 14.725C13 9.584 16.892 4.206 23 3l.984 2.126c-2.215.835-4.163 3.742-4.38 5.746A5.213 5.213 0 0 1 24 16.021C24 19.203 21.416 21 18.801 21 15.786 21 13 18.695 13 14.725zm-13 0C0 9.584 3.892 4.206 10 3l.984 2.126c-2.215.835-4.163 3.742-4.38 5.746A5.213 5.213 0 0 1 11 16.021C11 19.203 8.416 21 5.801 21 2.786 21 0 18.695 0 14.725z"
|
|
190
189
|
})));
|
|
@@ -195,8 +194,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
195
194
|
var SvgQuoteRight = function SvgQuoteRight(props) {
|
|
196
195
|
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
197
196
|
xmlns: "http://www.w3.org/2000/svg",
|
|
198
|
-
|
|
199
|
-
height: 24
|
|
197
|
+
viewBox: "0 0 24 24"
|
|
200
198
|
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
201
199
|
d: "M11 9.275C11 14.416 7.108 19.794 1 21l-.984-2.126c2.215-.835 4.163-3.742 4.38-5.746A5.213 5.213 0 0 1 0 7.979C0 4.797 2.584 3 5.199 3 8.214 3 11 5.305 11 9.275zm13 0C24 14.416 20.108 19.794 14 21l-.984-2.126c2.215-.835 4.163-3.742 4.38-5.746A5.213 5.213 0 0 1 13 7.979C13 4.797 15.584 3 18.199 3 21.214 3 24 5.305 24 9.275z"
|
|
202
200
|
})));
|
|
@@ -229,20 +227,25 @@ function styleInject(css, ref) {
|
|
|
229
227
|
}
|
|
230
228
|
}
|
|
231
229
|
|
|
232
|
-
var css_248z = "/*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}html{-webkit-text-size-adjust:100%;font-feature-settings:normal;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]{display:none}*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.absolute{position:absolute}.relative{position:relative}.flex{display:flex}.rounded-l-md{border-bottom-left-radius:.375rem;border-top-left-radius:.375rem}.rounded-r-md{border-bottom-right-radius:.375rem;border-top-right-radius:.375rem}
|
|
230
|
+
var css_248z = "/*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:\"\"}html{-webkit-text-size-adjust:100%;font-feature-settings:normal;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]{display:none}*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.absolute{position:absolute}.relative{position:relative}.flex{display:flex}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rounded-l-md{border-bottom-left-radius:.375rem;border-top-left-radius:.375rem}.rounded-r-md{border-bottom-right-radius:.375rem;border-top-right-radius:.375rem}";
|
|
233
231
|
styleInject(css_248z,{"insertAt":"top"});
|
|
234
232
|
|
|
235
|
-
const SelectionHandler = ({ pos, grab, setGrab, left }) => {
|
|
233
|
+
const SelectionHandler = ({ pos, grab, setGrab, left, bgColor, width }) => {
|
|
234
|
+
const bgColorDef = bgColor !== null && bgColor !== void 0 ? bgColor : 'rgb(253 224 71)';
|
|
235
|
+
const widthDef = width !== null && width !== void 0 ? width : 25;
|
|
236
236
|
return (pos &&
|
|
237
|
-
React__default.createElement("div", { draggable: false, className:
|
|
237
|
+
React__default.createElement("div", { draggable: false, className: `${left ? 'rounded-l-md' : 'rounded-r-md'}`, style: {
|
|
238
238
|
position: 'absolute',
|
|
239
239
|
display: 'flex',
|
|
240
|
-
left: left ? pos.left -
|
|
240
|
+
left: left ? pos.left - (widthDef - 1) : pos.left - 1,
|
|
241
241
|
top: pos.top,
|
|
242
|
-
width:
|
|
242
|
+
width: `${widthDef}px`,
|
|
243
243
|
height: pos.height,
|
|
244
244
|
cursor: grab ? 'grabbing' : 'grab',
|
|
245
245
|
alignItems: left ? 'flex-start' : 'flex-end',
|
|
246
|
+
backgroundColor: bgColorDef,
|
|
247
|
+
opacity: .8,
|
|
248
|
+
// transform: 'scale(.5)'
|
|
246
249
|
}, onMouseDown: () => {
|
|
247
250
|
setGrab(true);
|
|
248
251
|
const handler = () => {
|
|
@@ -257,7 +260,7 @@ const SelectionHandler = ({ pos, grab, setGrab, left }) => {
|
|
|
257
260
|
: React__default.createElement(SvgQuoteRight, null)));
|
|
258
261
|
};
|
|
259
262
|
|
|
260
|
-
const ReactTextRange = ({ initLeftPos, initRightPos, Container, children, onChange, props, }) => {
|
|
263
|
+
const ReactTextRange = ({ initLeftPos, initRightPos, Container, children, onChange, props, selectionColor, handlerWidth, }) => {
|
|
261
264
|
const [mouseOnLeft, setMouseOnLeft] = useState(false);
|
|
262
265
|
const [mouseOnRight, setMouseOnRight] = useState(false);
|
|
263
266
|
const [textDiv, leftHandler, rightHandler, rects] = useTextSelectionEditor(initLeftPos, initRightPos, mouseOnLeft, mouseOnRight);
|
|
@@ -269,25 +272,28 @@ const ReactTextRange = ({ initLeftPos, initRightPos, Container, children, onChan
|
|
|
269
272
|
});
|
|
270
273
|
}
|
|
271
274
|
}, [leftHandler, rightHandler]);
|
|
275
|
+
const bgColor = selectionColor;
|
|
272
276
|
return (React__default.createElement("div", { draggable: false, style: Object.assign({ position: 'relative' }, props) },
|
|
273
|
-
React__default.createElement(SelectionRects, { rects: rects }),
|
|
277
|
+
React__default.createElement(SelectionRects, { rects: rects, bgColor: bgColor }),
|
|
274
278
|
React__default.createElement(Container, { ref: textDiv }, children),
|
|
275
|
-
React__default.createElement(SelectionHandler, { grab: mouseOnLeft, left: true, pos: leftHandler, setGrab: (v) => setMouseOnLeft(v) }),
|
|
276
|
-
React__default.createElement(SelectionHandler, { grab: mouseOnRight, left: false, pos: rightHandler, setGrab: (v) => setMouseOnRight(v) })));
|
|
279
|
+
React__default.createElement(SelectionHandler, { bgColor: bgColor, width: handlerWidth, grab: mouseOnLeft, left: true, pos: leftHandler, setGrab: (v) => setMouseOnLeft(v) }),
|
|
280
|
+
React__default.createElement(SelectionHandler, { bgColor: bgColor, width: handlerWidth, grab: mouseOnRight, left: false, pos: rightHandler, setGrab: (v) => setMouseOnRight(v) })));
|
|
277
281
|
};
|
|
278
|
-
const SelectionRects = ({ rects }) => {
|
|
282
|
+
const SelectionRects = ({ rects, bgColor }) => {
|
|
279
283
|
if (!rects)
|
|
280
284
|
return null;
|
|
281
|
-
return (React__default.createElement(React__default.Fragment, null, rects.map((d, i) => React__default.createElement(SelectionRect, { key: i, rect: d }))));
|
|
285
|
+
return (React__default.createElement(React__default.Fragment, null, rects.map((d, i) => React__default.createElement(SelectionRect, { key: i, rect: d, bgColor: bgColor }))));
|
|
282
286
|
};
|
|
283
|
-
const SelectionRect = ({ rect }) => {
|
|
284
|
-
|
|
287
|
+
const SelectionRect = ({ rect, bgColor }) => {
|
|
288
|
+
const bgColorDef = bgColor !== null && bgColor !== void 0 ? bgColor : 'rgb(253 224 71)';
|
|
289
|
+
return (React__default.createElement("div", { style: {
|
|
285
290
|
userSelect: 'none',
|
|
286
291
|
position: 'absolute',
|
|
287
292
|
top: `${rect.top}px`,
|
|
288
293
|
left: `${rect.left}px`,
|
|
289
294
|
width: `${rect.width}px`,
|
|
290
295
|
height: `${rect.height}px`,
|
|
296
|
+
backgroundColor: bgColorDef,
|
|
291
297
|
} }, "\u00A0"));
|
|
292
298
|
};
|
|
293
299
|
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ declare const ReactTextRange: FC<{
|
|
|
14
14
|
children: string;
|
|
15
15
|
onChange: (state: RangeState) => void;
|
|
16
16
|
props?: React.CSSProperties;
|
|
17
|
+
selectionColor?: string;
|
|
18
|
+
handlerWidth?: number;
|
|
17
19
|
}>;
|
|
18
20
|
|
|
19
21
|
export { type RangeState, ReactTextRange, type TextContainer };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-text-range",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "text selection editor for React",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
7
7
|
"types": "./dist/esm/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build:sample": "rollup -
|
|
9
|
+
"build:sample": "rollup --config rollup-sample.config.mjs && cp ./src/server.js ./dist/cjs && cp ./src/index.html ./dist/cjs",
|
|
10
10
|
"build": "rollup -c",
|
|
11
11
|
"test": "jest --config jestconfig.json",
|
|
12
12
|
"prepare": "npm run build",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export type TextContainer = React.ForwardRefExoticComponent<{
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
} & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
-
export declare const ReactTextRange: FC<{
|
|
7
|
-
initLeftPos: number;
|
|
8
|
-
initRightPos: number;
|
|
9
|
-
Container: TextContainer;
|
|
10
|
-
children: string;
|
|
11
|
-
}>;
|
|
12
|
-
export default ReactTextRange;
|
package/dist/esm/FullWindow.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export type TextContainer = React.ForwardRefExoticComponent<{
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
} & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
-
export declare const ReactTextRange: FC<{
|
|
7
|
-
initLeftPos: number;
|
|
8
|
-
initRightPos: number;
|
|
9
|
-
Container: TextContainer;
|
|
10
|
-
children: string;
|
|
11
|
-
}>;
|
|
12
|
-
export default ReactTextRange;
|
package/dist/esm/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 type="module" src="/index.js"></script>
|
|
13
|
-
</body>
|
|
14
|
-
|
|
15
|
-
</body>
|
|
16
|
-
|
|
17
|
-
</html>
|