@expensify/react-native-live-markdown 0.1.115 → 0.1.117
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/lib/commonjs/MarkdownTextInput.js +2 -4
- package/lib/commonjs/MarkdownTextInput.js.map +1 -1
- package/lib/commonjs/MarkdownTextInput.web.js +105 -149
- package/lib/commonjs/MarkdownTextInput.web.js.map +1 -1
- package/lib/commonjs/styleUtils.js.map +1 -1
- package/lib/commonjs/web/utils/blockUtils.js +77 -0
- package/lib/commonjs/web/utils/blockUtils.js.map +1 -0
- package/lib/commonjs/web/utils/browserUtils.js +18 -0
- package/lib/commonjs/web/utils/browserUtils.js.map +1 -0
- package/lib/commonjs/web/utils/cursorUtils.js +111 -0
- package/lib/commonjs/web/utils/cursorUtils.js.map +1 -0
- package/lib/commonjs/web/utils/inputUtils.js +108 -0
- package/lib/commonjs/web/utils/inputUtils.js.map +1 -0
- package/lib/commonjs/web/utils/parserUtils.js +266 -0
- package/lib/commonjs/web/utils/parserUtils.js.map +1 -0
- package/lib/commonjs/web/utils/treeUtils.js +85 -0
- package/lib/commonjs/web/utils/treeUtils.js.map +1 -0
- package/lib/commonjs/web/utils/webStyleUtils.js +51 -0
- package/lib/commonjs/web/utils/webStyleUtils.js.map +1 -0
- package/lib/module/MarkdownTextInput.js +2 -2
- package/lib/module/MarkdownTextInput.js.map +1 -1
- package/lib/module/MarkdownTextInput.web.js +101 -145
- package/lib/module/MarkdownTextInput.web.js.map +1 -1
- package/lib/module/styleUtils.js.map +1 -1
- package/lib/module/web/utils/blockUtils.js +72 -0
- package/lib/module/web/utils/blockUtils.js.map +1 -0
- package/lib/module/web/utils/browserUtils.js +12 -0
- package/lib/module/web/utils/browserUtils.js.map +1 -0
- package/lib/module/web/utils/cursorUtils.js +102 -0
- package/lib/module/web/utils/cursorUtils.js.map +1 -0
- package/lib/module/web/utils/inputUtils.js +99 -0
- package/lib/module/web/utils/inputUtils.js.map +1 -0
- package/lib/module/web/utils/parserUtils.js +260 -0
- package/lib/module/web/utils/parserUtils.js.map +1 -0
- package/lib/module/web/utils/treeUtils.js +78 -0
- package/lib/module/web/utils/treeUtils.js.map +1 -0
- package/lib/module/web/utils/webStyleUtils.js +45 -0
- package/lib/module/web/utils/webStyleUtils.js.map +1 -0
- package/lib/typescript/src/MarkdownTextInput.d.ts +1 -2
- package/lib/typescript/src/MarkdownTextInput.d.ts.map +1 -1
- package/lib/typescript/src/MarkdownTextInput.web.d.ts +9 -3
- package/lib/typescript/src/MarkdownTextInput.web.d.ts.map +1 -1
- package/lib/typescript/src/styleUtils.d.ts +1 -2
- package/lib/typescript/src/styleUtils.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/blockUtils.d.ts +5 -0
- package/lib/typescript/src/web/utils/blockUtils.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/browserUtils.d.ts +12 -0
- package/lib/typescript/src/web/utils/browserUtils.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/cursorUtils.d.ts +12 -0
- package/lib/typescript/src/web/utils/cursorUtils.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/inputUtils.d.ts +9 -0
- package/lib/typescript/src/web/utils/inputUtils.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/parserUtils.d.ts +22 -0
- package/lib/typescript/src/web/utils/parserUtils.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/treeUtils.d.ts +17 -0
- package/lib/typescript/src/web/utils/treeUtils.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/webStyleUtils.d.ts +6 -0
- package/lib/typescript/src/web/utils/webStyleUtils.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/MarkdownTextInput.tsx +4 -7
- package/src/MarkdownTextInput.web.tsx +142 -171
- package/src/styleUtils.ts +1 -3
- package/src/web/utils/blockUtils.ts +72 -0
- package/src/web/utils/browserUtils.ts +13 -0
- package/src/web/utils/cursorUtils.ts +116 -0
- package/src/web/utils/inputUtils.ts +106 -0
- package/src/web/utils/parserUtils.ts +302 -0
- package/src/web/utils/treeUtils.ts +103 -0
- package/src/web/utils/webStyleUtils.ts +54 -0
- package/lib/commonjs/web/browserUtils.js +0 -16
- package/lib/commonjs/web/browserUtils.js.map +0 -1
- package/lib/commonjs/web/cursorUtils.js +0 -156
- package/lib/commonjs/web/cursorUtils.js.map +0 -1
- package/lib/commonjs/web/parserUtils.js +0 -214
- package/lib/commonjs/web/parserUtils.js.map +0 -1
- package/lib/module/web/browserUtils.js +0 -11
- package/lib/module/web/browserUtils.js.map +0 -1
- package/lib/module/web/cursorUtils.js +0 -143
- package/lib/module/web/cursorUtils.js.map +0 -1
- package/lib/module/web/parserUtils.js +0 -206
- package/lib/module/web/parserUtils.js.map +0 -1
- package/lib/typescript/src/web/browserUtils.d.ts +0 -10
- package/lib/typescript/src/web/browserUtils.d.ts.map +0 -1
- package/lib/typescript/src/web/cursorUtils.d.ts +0 -12
- package/lib/typescript/src/web/cursorUtils.d.ts.map +0 -1
- package/lib/typescript/src/web/parserUtils.d.ts +0 -17
- package/lib/typescript/src/web/parserUtils.d.ts.map +0 -1
- package/src/web/browserUtils.ts +0 -11
- package/src/web/cursorUtils.ts +0 -165
- package/src/web/parserUtils.ts +0 -228
|
@@ -8,9 +8,7 @@ var _reactNative = require("react-native");
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _MarkdownTextInputDecoratorViewNativeComponent = _interopRequireDefault(require("./MarkdownTextInputDecoratorViewNativeComponent"));
|
|
10
10
|
var _NativeLiveMarkdownModule = _interopRequireDefault(require("./NativeLiveMarkdownModule"));
|
|
11
|
-
var
|
|
12
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
var _styleUtils = require("./styleUtils");
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
13
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
16
14
|
if (_NativeLiveMarkdownModule.default) {
|
|
@@ -31,7 +29,7 @@ function processColorsInMarkdownStyle(input) {
|
|
|
31
29
|
return output;
|
|
32
30
|
}
|
|
33
31
|
function processMarkdownStyle(input) {
|
|
34
|
-
return processColorsInMarkdownStyle(
|
|
32
|
+
return processColorsInMarkdownStyle((0, _styleUtils.mergeMarkdownStyleWithDefault)(input));
|
|
35
33
|
}
|
|
36
34
|
const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
37
35
|
const IS_FABRIC = ('nativeFabricUIManager' in global);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_react","_interopRequireDefault","_MarkdownTextInputDecoratorViewNativeComponent","_NativeLiveMarkdownModule","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","_interopRequireDefault","_MarkdownTextInputDecoratorViewNativeComponent","_NativeLiveMarkdownModule","_styleUtils","obj","__esModule","default","_extends","Object","assign","bind","target","i","arguments","length","source","key","prototype","hasOwnProperty","call","apply","NativeLiveMarkdownModule","install","processColorsInMarkdownStyle","input","output","JSON","parse","stringify","keys","forEach","prop","endsWith","processColor","processMarkdownStyle","mergeMarkdownStyleWithDefault","MarkdownTextInput","React","forwardRef","props","ref","IS_FABRIC","global","markdownStyle","useMemo","createElement","Fragment","TextInput","style","styles","farAway","displayNone","StyleSheet","create","display","position","top","left","_default","exports"],"sourceRoot":"../../src","sources":["MarkdownTextInput.tsx"],"mappings":"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"}
|
|
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
|
-
var
|
|
10
|
-
var CursorUtils = _interopRequireWildcard(require("./web/cursorUtils"));
|
|
11
|
-
var StyleUtils = _interopRequireWildcard(require("./styleUtils"));
|
|
12
|
-
require("./web/MarkdownTextInput.css");
|
|
9
|
+
var _parserUtils = require("./web/utils/parserUtils");
|
|
13
10
|
var _InputHistory = _interopRequireDefault(require("./web/InputHistory"));
|
|
11
|
+
var _cursorUtils = require("./web/utils/cursorUtils");
|
|
12
|
+
require("./web/MarkdownTextInput.css");
|
|
13
|
+
var _inputUtils = require("./web/utils/inputUtils");
|
|
14
|
+
var _webStyleUtils = require("./web/utils/webStyleUtils");
|
|
14
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -18,81 +19,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
18
19
|
|
|
19
20
|
require('../parser/react-native-live-markdown-parser.js');
|
|
20
21
|
const useClientEffect = typeof window === 'undefined' ? _react.useEffect : _react.useLayoutEffect;
|
|
21
|
-
let createReactDOMStyle;
|
|
22
|
-
try {
|
|
23
|
-
createReactDOMStyle =
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
25
|
-
require('react-native-web/dist/exports/StyleSheet/compiler/createReactDOMStyle').default;
|
|
26
|
-
} catch (e) {
|
|
27
|
-
throw new Error('[react-native-live-markdown] Function `createReactDOMStyle` from react-native-web not found. Please make sure that you are using React Native Web 0.18 or newer.');
|
|
28
|
-
}
|
|
29
|
-
let preprocessStyle;
|
|
30
|
-
try {
|
|
31
|
-
preprocessStyle =
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
33
|
-
require('react-native-web/dist/exports/StyleSheet/preprocess').default;
|
|
34
|
-
} catch (e) {
|
|
35
|
-
throw new Error('[react-native-live-markdown] Function `preprocessStyle` from react-native-web not found.');
|
|
36
|
-
}
|
|
37
|
-
let dangerousStyleValue;
|
|
38
|
-
try {
|
|
39
|
-
dangerousStyleValue =
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
41
|
-
require('react-native-web/dist/modules/setValueForStyles/dangerousStyleValue').default;
|
|
42
|
-
} catch (e) {
|
|
43
|
-
throw new Error('[react-native-live-markdown] Function `dangerousStyleValue` from react-native-web not found.');
|
|
44
|
-
}
|
|
45
22
|
let focusTimeout = null;
|
|
46
|
-
|
|
47
|
-
// Removes one '\n' from the end of the string that were added by contentEditable div
|
|
48
|
-
function normalizeValue(value) {
|
|
49
|
-
return value.replace(/\n$/, '');
|
|
50
|
-
}
|
|
51
|
-
// Adds one '\n' at the end of the string if it's missing
|
|
52
|
-
function denormalizeValue(value) {
|
|
53
|
-
return value.endsWith('\n') ? `${value}\n` : value;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// If an Input Method Editor is processing key input, the 'keyCode' is 229.
|
|
57
|
-
// https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode
|
|
58
|
-
function isEventComposing(nativeEvent) {
|
|
59
|
-
return nativeEvent.isComposing || nativeEvent.keyCode === 229;
|
|
60
|
-
}
|
|
61
|
-
const ZERO_WIDTH_SPACE = '\u200B';
|
|
62
|
-
function getPlaceholderValue(placeholder) {
|
|
63
|
-
if (!placeholder) {
|
|
64
|
-
return ZERO_WIDTH_SPACE;
|
|
65
|
-
}
|
|
66
|
-
return placeholder.length ? placeholder : ZERO_WIDTH_SPACE;
|
|
67
|
-
}
|
|
68
|
-
function processUnitsInMarkdownStyle(input) {
|
|
69
|
-
const output = JSON.parse(JSON.stringify(input));
|
|
70
|
-
Object.keys(output).forEach(key => {
|
|
71
|
-
const obj = output[key];
|
|
72
|
-
Object.keys(obj).forEach(prop => {
|
|
73
|
-
obj[prop] = dangerousStyleValue(prop, obj[prop], false);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
return output;
|
|
77
|
-
}
|
|
78
|
-
function processMarkdownStyle(input) {
|
|
79
|
-
return processUnitsInMarkdownStyle(StyleUtils.mergeMarkdownStyleWithDefault(input));
|
|
80
|
-
}
|
|
81
|
-
function getElementHeight(node, styles, numberOfLines) {
|
|
82
|
-
if (numberOfLines) {
|
|
83
|
-
const tempElement = document.createElement('div');
|
|
84
|
-
tempElement.setAttribute('contenteditable', 'true');
|
|
85
|
-
Object.assign(tempElement.style, styles);
|
|
86
|
-
tempElement.innerText = Array(numberOfLines).fill('A').join('\n');
|
|
87
|
-
if (node.parentElement) {
|
|
88
|
-
node.parentElement.appendChild(tempElement);
|
|
89
|
-
const height = tempElement.clientHeight;
|
|
90
|
-
node.parentElement.removeChild(tempElement);
|
|
91
|
-
return height ? `${height}px` : 'auto';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return styles.height ? `${styles.height}px` : 'auto';
|
|
95
|
-
}
|
|
96
23
|
const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
97
24
|
accessibilityLabel,
|
|
98
25
|
accessibilityLabelledBy,
|
|
@@ -127,23 +54,23 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
127
54
|
inputMode
|
|
128
55
|
}, ref) => {
|
|
129
56
|
const compositionRef = (0, _react.useRef)(false);
|
|
130
|
-
const pasteRef = (0, _react.useRef)(false);
|
|
131
57
|
const divRef = (0, _react.useRef)(null);
|
|
132
58
|
const currentlyFocusedField = (0, _react.useRef)(null);
|
|
133
59
|
const contentSelection = (0, _react.useRef)(null);
|
|
134
60
|
const className = `react-native-live-markdown-input-${multiline ? 'multiline' : 'singleline'}`;
|
|
135
61
|
const history = (0, _react.useRef)();
|
|
136
|
-
const dimensions = _react.
|
|
62
|
+
const dimensions = (0, _react.useRef)(null);
|
|
63
|
+
const pasteContent = (0, _react.useRef)(null);
|
|
137
64
|
if (!history.current) {
|
|
138
65
|
history.current = new _InputHistory.default(100, 150, value || '');
|
|
139
66
|
}
|
|
140
67
|
const flattenedStyle = (0, _react.useMemo)(() => _reactNative.StyleSheet.flatten(style), [style]);
|
|
141
68
|
|
|
142
69
|
// Empty placeholder would collapse the div, so we need to use zero-width space to prevent it
|
|
143
|
-
const heightSafePlaceholder = (0, _react.useMemo)(() => getPlaceholderValue(placeholder), [placeholder]);
|
|
70
|
+
const heightSafePlaceholder = (0, _react.useMemo)(() => (0, _inputUtils.getPlaceholderValue)(placeholder), [placeholder]);
|
|
144
71
|
const setEventProps = (0, _react.useCallback)(e => {
|
|
145
72
|
if (divRef.current) {
|
|
146
|
-
const text =
|
|
73
|
+
const text = divRef.current.value;
|
|
147
74
|
if (e.target) {
|
|
148
75
|
// TODO: change the logic here so every event have value property
|
|
149
76
|
e.target.value = text;
|
|
@@ -154,30 +81,36 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
154
81
|
}
|
|
155
82
|
return e;
|
|
156
83
|
}, []);
|
|
157
|
-
const parseText = (0, _react.useCallback)((target, text, customMarkdownStyles, cursorPosition = null, shouldAddToHistory = true) => {
|
|
84
|
+
const parseText = (0, _react.useCallback)((target, text, customMarkdownStyles, cursorPosition = null, shouldAddToHistory = true, shouldForceDOMUpdate = false) => {
|
|
85
|
+
if (!divRef.current) {
|
|
86
|
+
return {
|
|
87
|
+
text: text || '',
|
|
88
|
+
cursorPosition: null
|
|
89
|
+
};
|
|
90
|
+
}
|
|
158
91
|
if (text === null) {
|
|
159
92
|
return {
|
|
160
|
-
text:
|
|
93
|
+
text: divRef.current.value,
|
|
161
94
|
cursorPosition: null
|
|
162
95
|
};
|
|
163
96
|
}
|
|
164
|
-
const parsedText =
|
|
97
|
+
const parsedText = (0, _parserUtils.updateInputStructure)(target, text, cursorPosition, customMarkdownStyles, !multiline, shouldForceDOMUpdate);
|
|
98
|
+
divRef.current.value = parsedText.text;
|
|
165
99
|
if (history.current && shouldAddToHistory) {
|
|
166
|
-
|
|
167
|
-
history.current.throttledAdd(normalizeValue(parsedText.text), parsedText.cursorPosition);
|
|
100
|
+
history.current.throttledAdd(parsedText.text, parsedText.cursorPosition);
|
|
168
101
|
}
|
|
169
102
|
return parsedText;
|
|
170
103
|
}, [multiline]);
|
|
171
104
|
const processedMarkdownStyle = (0, _react.useMemo)(() => {
|
|
172
|
-
const newMarkdownStyle = processMarkdownStyle(markdownStyle);
|
|
105
|
+
const newMarkdownStyle = (0, _webStyleUtils.processMarkdownStyle)(markdownStyle);
|
|
173
106
|
if (divRef.current) {
|
|
174
|
-
parseText(divRef.current, divRef.current.
|
|
107
|
+
parseText(divRef.current, divRef.current.value, newMarkdownStyle, null, false);
|
|
175
108
|
}
|
|
176
109
|
return newMarkdownStyle;
|
|
177
110
|
}, [markdownStyle, parseText]);
|
|
178
111
|
const inputStyles = (0, _react.useMemo)(() => _reactNative.StyleSheet.flatten([styles.defaultInputStyles, flattenedStyle && {
|
|
179
112
|
caretColor: flattenedStyle.color || 'black'
|
|
180
|
-
}, disabled && styles.disabledInputStyles,
|
|
113
|
+
}, disabled && styles.disabledInputStyles, (0, _webStyleUtils.parseToReactDOMStyle)(flattenedStyle)]), [flattenedStyle, disabled]);
|
|
181
114
|
const undo = (0, _react.useCallback)(target => {
|
|
182
115
|
if (!history.current) {
|
|
183
116
|
return {
|
|
@@ -186,7 +119,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
186
119
|
};
|
|
187
120
|
}
|
|
188
121
|
const item = history.current.undo();
|
|
189
|
-
const undoValue = item ?
|
|
122
|
+
const undoValue = item ? item.text : null;
|
|
190
123
|
return parseText(target, undoValue, processedMarkdownStyle, item ? item.cursorPosition : null, false);
|
|
191
124
|
}, [parseText, processedMarkdownStyle]);
|
|
192
125
|
const redo = (0, _react.useCallback)(target => {
|
|
@@ -197,18 +130,10 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
197
130
|
};
|
|
198
131
|
}
|
|
199
132
|
const item = history.current.redo();
|
|
200
|
-
const redoValue = item ?
|
|
133
|
+
const redoValue = item ? item.text : null;
|
|
201
134
|
return parseText(target, redoValue, processedMarkdownStyle, item ? item.cursorPosition : null, false);
|
|
202
135
|
}, [parseText, processedMarkdownStyle]);
|
|
203
136
|
|
|
204
|
-
// We have to process value property since contentEditable div adds one additional '\n' at the end of the text if we are entering new line
|
|
205
|
-
const processedValue = (0, _react.useMemo)(() => {
|
|
206
|
-
if (value && value[value.length - 1] === '\n') {
|
|
207
|
-
return `${value}\n`;
|
|
208
|
-
}
|
|
209
|
-
return value;
|
|
210
|
-
}, [value]);
|
|
211
|
-
|
|
212
137
|
// Placeholder text color logic
|
|
213
138
|
const updateTextColor = (0, _react.useCallback)((node, text) => {
|
|
214
139
|
// eslint-disable-next-line no-param-reassign -- we need to change the style of the node, so we need to modify it
|
|
@@ -235,7 +160,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
235
160
|
if (!divRef.current) {
|
|
236
161
|
return;
|
|
237
162
|
}
|
|
238
|
-
const newSelection = predefinedSelection ||
|
|
163
|
+
const newSelection = predefinedSelection || (0, _cursorUtils.getCurrentCursorPosition)(divRef.current);
|
|
239
164
|
if (newSelection && (!contentSelection.current || contentSelection.current.start !== newSelection.start || contentSelection.current.end !== newSelection.end)) {
|
|
240
165
|
updateRefSelectionVariables(newSelection);
|
|
241
166
|
contentSelection.current = newSelection;
|
|
@@ -266,22 +191,29 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
266
191
|
}
|
|
267
192
|
}, [multiline, onContentSizeChange]);
|
|
268
193
|
const handleOnChangeText = (0, _react.useCallback)(e => {
|
|
269
|
-
if (!divRef.current || !(e.target instanceof HTMLElement)) {
|
|
194
|
+
if (!divRef.current || !(e.target instanceof HTMLElement) || !contentSelection.current) {
|
|
270
195
|
return;
|
|
271
196
|
}
|
|
197
|
+
const nativeEvent = e.nativeEvent;
|
|
198
|
+
const inputType = nativeEvent.inputType;
|
|
199
|
+
updateTextColor(divRef.current, e.target.textContent ?? '');
|
|
200
|
+
const previousText = divRef.current.value;
|
|
201
|
+
const parsedText = (0, _inputUtils.normalizeValue)(inputType === 'pasteText' ? pasteContent.current || '' : (0, _inputUtils.parseInnerHTMLToText)(e.target));
|
|
202
|
+
if (pasteContent.current) {
|
|
203
|
+
pasteContent.current = null;
|
|
204
|
+
}
|
|
272
205
|
const prevSelection = contentSelection.current ?? {
|
|
273
206
|
start: 0,
|
|
274
207
|
end: 0
|
|
275
208
|
};
|
|
276
|
-
const
|
|
277
|
-
const changedText = e.target.innerText;
|
|
209
|
+
const newCursorPosition = Math.max(Math.max(contentSelection.current.end, 0) + (parsedText.length - previousText.length), 0);
|
|
278
210
|
if (compositionRef.current) {
|
|
279
|
-
|
|
211
|
+
divRef.current.value = parsedText;
|
|
212
|
+
compositionRef.current = false;
|
|
213
|
+
contentSelection.current.end = newCursorPosition;
|
|
280
214
|
return;
|
|
281
215
|
}
|
|
282
216
|
let newInputUpdate;
|
|
283
|
-
const nativeEvent = e.nativeEvent;
|
|
284
|
-
const inputType = nativeEvent.inputType;
|
|
285
217
|
switch (inputType) {
|
|
286
218
|
case 'historyUndo':
|
|
287
219
|
newInputUpdate = undo(divRef.current);
|
|
@@ -289,33 +221,24 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
289
221
|
case 'historyRedo':
|
|
290
222
|
newInputUpdate = redo(divRef.current);
|
|
291
223
|
break;
|
|
292
|
-
case 'insertFromPaste':
|
|
293
|
-
// if there is no newline at the end of the copied text, contentEditable adds invisible <br> tag at the end of the text, so we need to normalize it
|
|
294
|
-
if (changedText.length > 2 && changedText[changedText.length - 2] !== '\n' && changedText[changedText.length - 1] === '\n') {
|
|
295
|
-
newInputUpdate = parseText(divRef.current, normalizeValue(changedText), processedMarkdownStyle);
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
newInputUpdate = parseText(divRef.current, changedText, processedMarkdownStyle);
|
|
299
|
-
break;
|
|
300
224
|
default:
|
|
301
|
-
newInputUpdate = parseText(divRef.current,
|
|
225
|
+
newInputUpdate = parseText(divRef.current, parsedText, processedMarkdownStyle, newCursorPosition, true, !inputType);
|
|
302
226
|
}
|
|
303
227
|
const {
|
|
304
228
|
text,
|
|
305
229
|
cursorPosition
|
|
306
230
|
} = newInputUpdate;
|
|
307
|
-
const normalizedText = normalizeValue(text);
|
|
308
|
-
if (pasteRef !== null && pasteRef !== void 0 && pasteRef.current) {
|
|
309
|
-
pasteRef.current = false;
|
|
310
|
-
updateSelection(e);
|
|
311
|
-
}
|
|
312
231
|
updateTextColor(divRef.current, text);
|
|
232
|
+
updateSelection(e, {
|
|
233
|
+
start: cursorPosition ?? 0,
|
|
234
|
+
end: cursorPosition ?? 0
|
|
235
|
+
});
|
|
313
236
|
if (onChange) {
|
|
314
237
|
const event = e;
|
|
315
238
|
setEventProps(event);
|
|
316
239
|
|
|
317
240
|
// The new text is between the prev start selection and the new end selection, can be empty
|
|
318
|
-
const addedText =
|
|
241
|
+
const addedText = text.slice(prevSelection.start, cursorPosition ?? 0);
|
|
319
242
|
// The length of the text that replaced the before text
|
|
320
243
|
const count = addedText.length;
|
|
321
244
|
// The start index of the replacement operation
|
|
@@ -325,7 +248,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
325
248
|
let before = prevSelectionRange;
|
|
326
249
|
if (prevSelectionRange === 0 && (inputType === 'deleteContentBackward' || inputType === 'deleteContentForward')) {
|
|
327
250
|
// its possible the user pressed a delete key without a selection range, so we need to adjust the before value to have the length of the deleted text
|
|
328
|
-
before =
|
|
251
|
+
before = previousText.length - text.length;
|
|
329
252
|
}
|
|
330
253
|
if (inputType === 'deleteContentBackward') {
|
|
331
254
|
// When the user does a backspace delete he expects the content before the cursor to be removed.
|
|
@@ -340,17 +263,31 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
340
263
|
onChange(event);
|
|
341
264
|
}
|
|
342
265
|
if (onChangeText) {
|
|
343
|
-
onChangeText(
|
|
266
|
+
onChangeText(text);
|
|
344
267
|
}
|
|
345
268
|
handleContentSizeChange();
|
|
346
|
-
}, [updateTextColor,
|
|
269
|
+
}, [updateTextColor, updateSelection, onChange, onChangeText, handleContentSizeChange, undo, redo, parseText, processedMarkdownStyle, setEventProps]);
|
|
270
|
+
const insertText = (0, _react.useCallback)((e, text) => {
|
|
271
|
+
if (!contentSelection.current || !divRef.current) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const previousText = divRef.current.value;
|
|
275
|
+
const newText = `${divRef.current.value.substring(0, contentSelection.current.start)}${text}${divRef.current.value.substring(contentSelection.current.end)}`;
|
|
276
|
+
if (previousText === newText) {
|
|
277
|
+
document.execCommand('delete');
|
|
278
|
+
}
|
|
279
|
+
pasteContent.current = newText;
|
|
280
|
+
e.nativeEvent.inputType = 'pasteText';
|
|
281
|
+
handleOnChangeText(e);
|
|
282
|
+
updateSelection(e);
|
|
283
|
+
}, [handleOnChangeText, updateSelection]);
|
|
347
284
|
const handleKeyPress = (0, _react.useCallback)(e => {
|
|
348
285
|
if (!divRef.current) {
|
|
349
286
|
return;
|
|
350
287
|
}
|
|
351
288
|
const hostNode = e.target;
|
|
352
289
|
e.stopPropagation();
|
|
353
|
-
if (e.key === 'z' && e.metaKey) {
|
|
290
|
+
if (e.key === 'z' && (e.ctrlKey || e.metaKey)) {
|
|
354
291
|
e.preventDefault();
|
|
355
292
|
const nativeEvent = e.nativeEvent;
|
|
356
293
|
if (e.shiftKey) {
|
|
@@ -364,7 +301,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
364
301
|
const blurOnSubmitDefault = !multiline;
|
|
365
302
|
const shouldBlurOnSubmit = blurOnSubmit === null ? blurOnSubmitDefault : blurOnSubmit;
|
|
366
303
|
const nativeEvent = e.nativeEvent;
|
|
367
|
-
const isComposing = isEventComposing(nativeEvent);
|
|
304
|
+
const isComposing = (0, _inputUtils.isEventComposing)(nativeEvent);
|
|
368
305
|
const event = e;
|
|
369
306
|
setEventProps(event);
|
|
370
307
|
if (onKeyPress) {
|
|
@@ -381,14 +318,13 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
381
318
|
} else if (multiline) {
|
|
382
319
|
// We need to change normal behavior of "Enter" key to insert a line breaks, to prevent wrapping contentEditable text in <div> tags.
|
|
383
320
|
// Thanks to that in every situation we have proper amount of new lines in our parsed text. Without it pressing enter in empty lines will add 2 more new lines.
|
|
384
|
-
|
|
385
|
-
CursorUtils.scrollCursorIntoView(divRef.current);
|
|
321
|
+
insertText(e, '\n');
|
|
386
322
|
}
|
|
387
323
|
if (!e.shiftKey && (shouldBlurOnSubmit && hostNode !== null || !multiline)) {
|
|
388
324
|
setTimeout(() => divRef.current && divRef.current.blur(), 0);
|
|
389
325
|
}
|
|
390
326
|
}
|
|
391
|
-
}, [multiline, blurOnSubmit, setEventProps, onKeyPress, updateSelection, handleOnChangeText, onSubmitEditing]);
|
|
327
|
+
}, [multiline, blurOnSubmit, setEventProps, onKeyPress, updateSelection, handleOnChangeText, onSubmitEditing, insertText]);
|
|
392
328
|
const handleFocus = (0, _react.useCallback)(event => {
|
|
393
329
|
const e = event;
|
|
394
330
|
const hostNode = e.target;
|
|
@@ -396,10 +332,10 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
396
332
|
setEventProps(e);
|
|
397
333
|
if (divRef.current) {
|
|
398
334
|
if (contentSelection.current) {
|
|
399
|
-
|
|
335
|
+
(0, _cursorUtils.setCursorPosition)(divRef.current, contentSelection.current.start, contentSelection.current.end);
|
|
400
336
|
} else {
|
|
401
|
-
const valueLength = value ? value.length : divRef.current.
|
|
402
|
-
|
|
337
|
+
const valueLength = value ? value.length : divRef.current.value.length;
|
|
338
|
+
(0, _cursorUtils.setCursorPosition)(divRef.current, valueLength, null);
|
|
403
339
|
}
|
|
404
340
|
updateSelection(event, contentSelection.current);
|
|
405
341
|
}
|
|
@@ -409,7 +345,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
409
345
|
}
|
|
410
346
|
if (hostNode !== null) {
|
|
411
347
|
if (clearTextOnFocus && divRef.current) {
|
|
412
|
-
divRef.current.
|
|
348
|
+
divRef.current.textContent = '';
|
|
413
349
|
}
|
|
414
350
|
if (selectTextOnFocus) {
|
|
415
351
|
// Safari requires selection to occur in a setTimeout
|
|
@@ -427,7 +363,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
427
363
|
}, [clearTextOnFocus, onFocus, selectTextOnFocus, setEventProps, updateSelection, value]);
|
|
428
364
|
const handleBlur = (0, _react.useCallback)(event => {
|
|
429
365
|
const e = event;
|
|
430
|
-
|
|
366
|
+
(0, _cursorUtils.removeSelection)();
|
|
431
367
|
currentlyFocusedField.current = null;
|
|
432
368
|
if (onBlur) {
|
|
433
369
|
setEventProps(e);
|
|
@@ -439,19 +375,36 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
439
375
|
if (!onClick || !divRef.current) {
|
|
440
376
|
return;
|
|
441
377
|
}
|
|
442
|
-
e.target.value =
|
|
378
|
+
e.target.value = divRef.current.value;
|
|
443
379
|
onClick(e);
|
|
444
380
|
}, [onClick, updateSelection]);
|
|
381
|
+
const handleCopy = (0, _react.useCallback)(e => {
|
|
382
|
+
var _divRef$current;
|
|
383
|
+
if (!divRef.current || !contentSelection.current) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
e.preventDefault();
|
|
387
|
+
const text = (_divRef$current = divRef.current) === null || _divRef$current === void 0 ? void 0 : _divRef$current.value.substring(contentSelection.current.start, contentSelection.current.end);
|
|
388
|
+
e.clipboardData.setData('text/plain', text ?? '');
|
|
389
|
+
}, []);
|
|
390
|
+
const handleCut = (0, _react.useCallback)(e => {
|
|
391
|
+
if (!divRef.current || !contentSelection.current) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
handleCopy(e);
|
|
395
|
+
if (contentSelection.current.start !== contentSelection.current.end) {
|
|
396
|
+
document.execCommand('delete');
|
|
397
|
+
}
|
|
398
|
+
}, [handleCopy]);
|
|
445
399
|
const handlePaste = (0, _react.useCallback)(e => {
|
|
446
|
-
|
|
447
|
-
if (e.isDefaultPrevented()) {
|
|
400
|
+
if (e.isDefaultPrevented() || !divRef.current || !contentSelection.current) {
|
|
448
401
|
return;
|
|
449
402
|
}
|
|
450
403
|
e.preventDefault();
|
|
451
404
|
const clipboardData = e.clipboardData;
|
|
452
405
|
const text = clipboardData.getData('text/plain');
|
|
453
|
-
|
|
454
|
-
}, []);
|
|
406
|
+
insertText(e, text);
|
|
407
|
+
}, [insertText]);
|
|
455
408
|
const startComposition = (0, _react.useCallback)(() => {
|
|
456
409
|
compositionRef.current = true;
|
|
457
410
|
}, []);
|
|
@@ -464,12 +417,12 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
464
417
|
if (r) {
|
|
465
418
|
r.isFocused = () => document.activeElement === r;
|
|
466
419
|
r.clear = () => {
|
|
467
|
-
r.
|
|
420
|
+
r.textContent = '';
|
|
468
421
|
updateTextColor(r, '');
|
|
469
422
|
};
|
|
470
423
|
if (value === '' || value === undefined) {
|
|
471
424
|
// update to placeholder color when value is empty
|
|
472
|
-
updateTextColor(r, r.
|
|
425
|
+
updateTextColor(r, r.textContent ?? '');
|
|
473
426
|
}
|
|
474
427
|
}
|
|
475
428
|
if (ref) {
|
|
@@ -483,22 +436,23 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
483
436
|
divRef.current = r;
|
|
484
437
|
};
|
|
485
438
|
useClientEffect(function parseAndStyleValue() {
|
|
486
|
-
if (!divRef.current ||
|
|
439
|
+
if (!divRef.current || value === divRef.current.value) {
|
|
487
440
|
return;
|
|
488
441
|
}
|
|
489
442
|
if (value === undefined) {
|
|
490
|
-
parseText(divRef.current, divRef.current.
|
|
443
|
+
parseText(divRef.current, divRef.current.value, processedMarkdownStyle);
|
|
491
444
|
return;
|
|
492
445
|
}
|
|
493
|
-
const
|
|
494
|
-
|
|
446
|
+
const normalizedValue = (0, _inputUtils.normalizeValue)(value);
|
|
447
|
+
divRef.current.value = normalizedValue;
|
|
448
|
+
parseText(divRef.current, normalizedValue, processedMarkdownStyle);
|
|
495
449
|
updateTextColor(divRef.current, value);
|
|
496
|
-
}, [multiline, processedMarkdownStyle,
|
|
450
|
+
}, [multiline, processedMarkdownStyle, value]);
|
|
497
451
|
useClientEffect(function adjustHeight() {
|
|
498
452
|
if (!divRef.current || !multiline) {
|
|
499
453
|
return;
|
|
500
454
|
}
|
|
501
|
-
const elementHeight = getElementHeight(divRef.current, inputStyles, numberOfLines);
|
|
455
|
+
const elementHeight = (0, _inputUtils.getElementHeight)(divRef.current, inputStyles, numberOfLines);
|
|
502
456
|
divRef.current.style.height = elementHeight;
|
|
503
457
|
divRef.current.style.maxHeight = elementHeight;
|
|
504
458
|
}, [numberOfLines]);
|
|
@@ -526,7 +480,7 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
526
480
|
};
|
|
527
481
|
contentSelection.current = newSelection;
|
|
528
482
|
updateRefSelectionVariables(newSelection);
|
|
529
|
-
|
|
483
|
+
(0, _cursorUtils.setCursorPosition)(divRef.current, newSelection.start, newSelection.end);
|
|
530
484
|
}, [selection, updateRefSelectionVariables]);
|
|
531
485
|
return (
|
|
532
486
|
/*#__PURE__*/
|
|
@@ -552,6 +506,8 @@ const MarkdownTextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
552
506
|
onClick: handleClick,
|
|
553
507
|
onFocus: handleFocus,
|
|
554
508
|
onBlur: handleBlur,
|
|
509
|
+
onCopy: handleCopy,
|
|
510
|
+
onCut: handleCut,
|
|
555
511
|
onPaste: handlePaste,
|
|
556
512
|
placeholder: heightSafePlaceholder,
|
|
557
513
|
spellCheck: spellCheck,
|