@chaitrabhairappa/react-native-rich-text-editor 3.3.0 → 3.4.1
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/android/src/main/java/com/richtext/editor/MediaAttachmentSpan.kt +5 -0
- package/android/src/main/java/com/richtext/editor/MediaAttachmentSupport.kt +94 -8
- package/android/src/main/java/com/richtext/editor/RichTextEditorView.kt +55 -5
- package/android/src/main/java/com/richtext/editor/RichTextEditorViewManager.kt +20 -4
- package/ios/RichTextEditorView.swift +237 -19
- package/lib/commonjs/index.js +11 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/index.js +11 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +7 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +23 -11
- package/src/types.ts +7 -1
|
@@ -11,6 +11,11 @@ import kotlin.math.ceil
|
|
|
11
11
|
data class MediaAttachmentData(
|
|
12
12
|
val kind: String,
|
|
13
13
|
val uri: String,
|
|
14
|
+
val sourceUri: String? = null,
|
|
15
|
+
val fileName: String? = null,
|
|
16
|
+
val extension: String? = null,
|
|
17
|
+
val contentType: String? = null,
|
|
18
|
+
val fileSize: Long? = null,
|
|
14
19
|
val widthDp: Int,
|
|
15
20
|
val heightDp: Int,
|
|
16
21
|
val alt: String
|
|
@@ -4,9 +4,11 @@ import android.content.Context
|
|
|
4
4
|
import android.graphics.Bitmap
|
|
5
5
|
import android.graphics.BitmapFactory
|
|
6
6
|
import android.net.Uri
|
|
7
|
+
import android.provider.OpenableColumns
|
|
7
8
|
import android.text.Editable
|
|
8
9
|
import android.text.SpannableStringBuilder
|
|
9
10
|
import android.text.Spanned
|
|
11
|
+
import android.webkit.MimeTypeMap
|
|
10
12
|
import com.facebook.react.bridge.Arguments
|
|
11
13
|
import com.facebook.react.bridge.WritableMap
|
|
12
14
|
import org.json.JSONObject
|
|
@@ -32,9 +34,16 @@ class MediaAttachmentSupport(
|
|
|
32
34
|
if (blockType != "mediaAttachment") return null
|
|
33
35
|
|
|
34
36
|
val mediaInfo = block["mediaAttachment"] as? Map<*, *>
|
|
37
|
+
val uri = mediaInfo?.get("uri") as? String ?: ""
|
|
38
|
+
val sourceUri = mediaInfo?.get("sourceUri") as? String ?: uri
|
|
35
39
|
return MediaAttachmentData(
|
|
36
40
|
kind = mediaInfo?.get("kind") as? String ?: "image",
|
|
37
|
-
uri =
|
|
41
|
+
uri = uri,
|
|
42
|
+
sourceUri = sourceUri,
|
|
43
|
+
fileName = mediaInfo?.get("fileName") as? String,
|
|
44
|
+
extension = mediaInfo?.get("extension") as? String,
|
|
45
|
+
contentType = mediaInfo?.get("contentType") as? String,
|
|
46
|
+
fileSize = (mediaInfo?.get("fileSize") as? Number)?.toLong(),
|
|
38
47
|
widthDp = (mediaInfo?.get("width") as? Number)?.toInt() ?: 100,
|
|
39
48
|
heightDp = (mediaInfo?.get("height") as? Number)?.toInt() ?: 100,
|
|
40
49
|
alt = mediaInfo?.get("alt") as? String ?: ""
|
|
@@ -76,6 +85,11 @@ class MediaAttachmentSupport(
|
|
|
76
85
|
val mediaMap = Arguments.createMap()
|
|
77
86
|
mediaMap.putString("kind", mediaData.kind)
|
|
78
87
|
mediaMap.putString("uri", mediaData.uri)
|
|
88
|
+
mediaMap.putString("sourceUri", mediaData.sourceUri ?: mediaData.uri)
|
|
89
|
+
mediaData.fileName?.let { mediaMap.putString("fileName", it) }
|
|
90
|
+
mediaData.extension?.let { mediaMap.putString("extension", it) }
|
|
91
|
+
mediaData.contentType?.let { mediaMap.putString("contentType", it) }
|
|
92
|
+
mediaData.fileSize?.let { mediaMap.putDouble("fileSize", it.toDouble()) }
|
|
79
93
|
mediaMap.putInt("width", mediaData.widthDp)
|
|
80
94
|
mediaMap.putInt("height", mediaData.heightDp)
|
|
81
95
|
mediaMap.putString("alt", mediaData.alt)
|
|
@@ -93,6 +107,11 @@ class MediaAttachmentSupport(
|
|
|
93
107
|
val mediaObj = JSONObject()
|
|
94
108
|
mediaObj.put("kind", mediaData.kind)
|
|
95
109
|
mediaObj.put("uri", mediaData.uri)
|
|
110
|
+
mediaObj.put("sourceUri", mediaData.sourceUri ?: mediaData.uri)
|
|
111
|
+
mediaData.fileName?.let { mediaObj.put("fileName", it) }
|
|
112
|
+
mediaData.extension?.let { mediaObj.put("extension", it) }
|
|
113
|
+
mediaData.contentType?.let { mediaObj.put("contentType", it) }
|
|
114
|
+
mediaData.fileSize?.let { mediaObj.put("fileSize", it) }
|
|
96
115
|
mediaObj.put("width", mediaData.widthDp)
|
|
97
116
|
mediaObj.put("height", mediaData.heightDp)
|
|
98
117
|
mediaObj.put("alt", mediaData.alt)
|
|
@@ -127,14 +146,12 @@ class MediaAttachmentSupport(
|
|
|
127
146
|
}
|
|
128
147
|
|
|
129
148
|
fun insertMediaAttachmentBlock(editable: Editable, insertPos: Int, uri: String): Int {
|
|
149
|
+
val mediaData = createMediaDataForUri(uri)
|
|
150
|
+
return insertMediaAttachmentBlock(editable, insertPos, mediaData)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fun insertMediaAttachmentBlock(editable: Editable, insertPos: Int, mediaData: MediaAttachmentData): Int {
|
|
130
154
|
var mutableInsertPos = insertPos.coerceIn(0, editable.length)
|
|
131
|
-
val mediaData = MediaAttachmentData(
|
|
132
|
-
kind = "image",
|
|
133
|
-
uri = uri,
|
|
134
|
-
widthDp = 100,
|
|
135
|
-
heightDp = 100,
|
|
136
|
-
alt = "Selected image"
|
|
137
|
-
)
|
|
138
155
|
|
|
139
156
|
if (mutableInsertPos > 0 && editable[mutableInsertPos - 1] != '\n') {
|
|
140
157
|
editable.insert(mutableInsertPos, "\n")
|
|
@@ -160,6 +177,75 @@ class MediaAttachmentSupport(
|
|
|
160
177
|
return nextPos.coerceAtMost(editable.length)
|
|
161
178
|
}
|
|
162
179
|
|
|
180
|
+
fun createMediaDataForUri(uri: String): MediaAttachmentData {
|
|
181
|
+
val inferredMeta = inferMediaMetadata(uri)
|
|
182
|
+
return MediaAttachmentData(
|
|
183
|
+
kind = "image",
|
|
184
|
+
uri = uri,
|
|
185
|
+
sourceUri = uri,
|
|
186
|
+
fileName = inferredMeta.fileName,
|
|
187
|
+
extension = inferredMeta.extension,
|
|
188
|
+
contentType = inferredMeta.contentType,
|
|
189
|
+
fileSize = inferredMeta.fileSize,
|
|
190
|
+
widthDp = 100,
|
|
191
|
+
heightDp = 100,
|
|
192
|
+
alt = "Selected image"
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private data class InferredMediaMetadata(
|
|
197
|
+
val fileName: String?,
|
|
198
|
+
val extension: String?,
|
|
199
|
+
val contentType: String?,
|
|
200
|
+
val fileSize: Long?
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
private fun inferMediaMetadata(uriString: String): InferredMediaMetadata {
|
|
204
|
+
val parsed = runCatching { Uri.parse(uriString) }.getOrNull()
|
|
205
|
+
?: return InferredMediaMetadata(null, null, null, null)
|
|
206
|
+
|
|
207
|
+
val extension = runCatching {
|
|
208
|
+
MimeTypeMap.getFileExtensionFromUrl(parsed.toString())
|
|
209
|
+
}.getOrNull()?.takeIf { it.isNotBlank() }?.lowercase()
|
|
210
|
+
|
|
211
|
+
val contentType = runCatching {
|
|
212
|
+
context.contentResolver.getType(parsed)
|
|
213
|
+
}.getOrNull() ?: extension?.let {
|
|
214
|
+
MimeTypeMap.getSingleton().getMimeTypeFromExtension(it)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
var fileName: String? = null
|
|
218
|
+
var fileSize: Long? = null
|
|
219
|
+
|
|
220
|
+
if (parsed.scheme == "content") {
|
|
221
|
+
runCatching {
|
|
222
|
+
context.contentResolver.query(parsed, null, null, null, null)
|
|
223
|
+
}.getOrNull()?.use { cursor ->
|
|
224
|
+
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
|
225
|
+
val sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE)
|
|
226
|
+
if (cursor.moveToFirst()) {
|
|
227
|
+
if (nameIndex >= 0) {
|
|
228
|
+
fileName = cursor.getString(nameIndex)
|
|
229
|
+
}
|
|
230
|
+
if (sizeIndex >= 0 && !cursor.isNull(sizeIndex)) {
|
|
231
|
+
fileSize = cursor.getLong(sizeIndex)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (fileName.isNullOrBlank()) {
|
|
238
|
+
fileName = parsed.lastPathSegment
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
val resolvedExtension = extension ?: fileName
|
|
242
|
+
?.substringAfterLast('.', "")
|
|
243
|
+
?.takeIf { it.isNotBlank() }
|
|
244
|
+
?.lowercase()
|
|
245
|
+
|
|
246
|
+
return InferredMediaMetadata(fileName, resolvedExtension, contentType, fileSize)
|
|
247
|
+
}
|
|
248
|
+
|
|
163
249
|
private fun normalizeMediaDimensions(mediaData: MediaAttachmentData, targetWidthPx: Int): MediaAttachmentData {
|
|
164
250
|
val targetWidthDp = (targetWidthPx / density).toInt().coerceAtLeast(1)
|
|
165
251
|
val fallbackHeightDp = if (mediaData.widthDp > 0 && mediaData.heightDp > 0) {
|
|
@@ -1943,12 +1943,12 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
1943
1943
|
imagePickerLauncher?.launch("image/*")
|
|
1944
1944
|
}
|
|
1945
1945
|
|
|
1946
|
-
private fun insertMediaAttachmentBlock(
|
|
1946
|
+
private fun insertMediaAttachmentBlock(mediaData: MediaAttachmentData) {
|
|
1947
1947
|
val editable = text ?: return
|
|
1948
1948
|
var insertPos = selectionStart.coerceIn(0, editable.length)
|
|
1949
1949
|
|
|
1950
1950
|
isInternalChange = true
|
|
1951
|
-
val nextPos = mediaAttachmentSupport.insertMediaAttachmentBlock(editable, insertPos,
|
|
1951
|
+
val nextPos = mediaAttachmentSupport.insertMediaAttachmentBlock(editable, insertPos, mediaData)
|
|
1952
1952
|
setSelection(nextPos.coerceAtMost(editable.length))
|
|
1953
1953
|
|
|
1954
1954
|
isInternalChange = false
|
|
@@ -1957,10 +1957,60 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
1957
1957
|
post { updateContentSize() }
|
|
1958
1958
|
}
|
|
1959
1959
|
|
|
1960
|
-
fun
|
|
1961
|
-
val safeUri = uri
|
|
1960
|
+
private fun insertMediaAttachmentBlock(uri: String) {
|
|
1961
|
+
val safeUri = uri.trim()
|
|
1962
1962
|
if (safeUri.isEmpty()) return
|
|
1963
|
-
|
|
1963
|
+
val mediaData = mediaAttachmentSupport.createMediaDataForUri(safeUri)
|
|
1964
|
+
insertMediaAttachmentBlock(mediaData)
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
private fun parseMediaAttachmentPayload(payload: String): MediaAttachmentData? {
|
|
1968
|
+
val trimmed = payload.trim()
|
|
1969
|
+
if (trimmed.isEmpty()) return null
|
|
1970
|
+
|
|
1971
|
+
return try {
|
|
1972
|
+
if (trimmed.startsWith("{")) {
|
|
1973
|
+
val obj = org.json.JSONObject(trimmed)
|
|
1974
|
+
val uri = obj.optString("uri", "").trim()
|
|
1975
|
+
if (uri.isEmpty()) {
|
|
1976
|
+
null
|
|
1977
|
+
} else {
|
|
1978
|
+
val sourceUri = obj.optString("sourceUri", uri).ifBlank { uri }
|
|
1979
|
+
val kind = obj.optString("kind", "image")
|
|
1980
|
+
val fileName = obj.optString("fileName", "").ifBlank { null }
|
|
1981
|
+
val extension = obj.optString("extension", "").ifBlank { null }
|
|
1982
|
+
val contentType = obj.optString("contentType", "").ifBlank { null }
|
|
1983
|
+
val fileSize = if (obj.has("fileSize")) obj.optLong("fileSize", -1L) else -1L
|
|
1984
|
+
val width = obj.optInt("width", 100).coerceAtLeast(1)
|
|
1985
|
+
val height = obj.optInt("height", 100).coerceAtLeast(1)
|
|
1986
|
+
val alt = obj.optString("alt", "Selected image")
|
|
1987
|
+
|
|
1988
|
+
MediaAttachmentData(
|
|
1989
|
+
kind = kind,
|
|
1990
|
+
uri = uri,
|
|
1991
|
+
sourceUri = sourceUri,
|
|
1992
|
+
fileName = fileName,
|
|
1993
|
+
extension = extension,
|
|
1994
|
+
contentType = contentType,
|
|
1995
|
+
fileSize = fileSize.takeIf { it >= 0L },
|
|
1996
|
+
widthDp = width,
|
|
1997
|
+
heightDp = height,
|
|
1998
|
+
alt = alt
|
|
1999
|
+
)
|
|
2000
|
+
}
|
|
2001
|
+
} else {
|
|
2002
|
+
mediaAttachmentSupport.createMediaDataForUri(trimmed)
|
|
2003
|
+
}
|
|
2004
|
+
} catch (_: Exception) {
|
|
2005
|
+
mediaAttachmentSupport.createMediaDataForUri(trimmed)
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
fun insertMediaAttachment(payload: String?) {
|
|
2010
|
+
val safePayload = payload?.trim().orEmpty()
|
|
2011
|
+
if (safePayload.isEmpty()) return
|
|
2012
|
+
val mediaData = parseMediaAttachmentPayload(safePayload) ?: return
|
|
2013
|
+
insertMediaAttachmentBlock(mediaData)
|
|
1964
2014
|
}
|
|
1965
2015
|
|
|
1966
2016
|
private fun promptInsertLink() {
|
|
@@ -29,8 +29,8 @@ class RichTextEditorViewManager : SimpleViewManager<RichTextEditorView>() {
|
|
|
29
29
|
override fun receiveCommand(view: RichTextEditorView, commandId: String?, args: ReadableArray?) {
|
|
30
30
|
when (commandId) {
|
|
31
31
|
"insertMediaAttachment" -> {
|
|
32
|
-
val
|
|
33
|
-
view.insertMediaAttachment(
|
|
32
|
+
val payload = args?.getString(0)
|
|
33
|
+
view.insertMediaAttachment(payload)
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -38,8 +38,8 @@ class RichTextEditorViewManager : SimpleViewManager<RichTextEditorView>() {
|
|
|
38
38
|
override fun receiveCommand(view: RichTextEditorView, commandId: Int, args: ReadableArray?) {
|
|
39
39
|
when (commandId) {
|
|
40
40
|
COMMAND_INSERT_MEDIA_ATTACHMENT -> {
|
|
41
|
-
val
|
|
42
|
-
view.insertMediaAttachment(
|
|
41
|
+
val payload = args?.getString(0)
|
|
42
|
+
view.insertMediaAttachment(payload)
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -174,6 +174,22 @@ class RichTextEditorViewManager : SimpleViewManager<RichTextEditorView>() {
|
|
|
174
174
|
val mediaMap = mutableMapOf<String, Any>()
|
|
175
175
|
mediaMap["kind"] = mediaAttachment.optString("kind", "image")
|
|
176
176
|
mediaMap["uri"] = mediaAttachment.optString("uri", "")
|
|
177
|
+
mediaMap["sourceUri"] = mediaAttachment.optString(
|
|
178
|
+
"sourceUri",
|
|
179
|
+
mediaAttachment.optString("uri", "")
|
|
180
|
+
)
|
|
181
|
+
if (mediaAttachment.has("fileName")) {
|
|
182
|
+
mediaMap["fileName"] = mediaAttachment.optString("fileName", "")
|
|
183
|
+
}
|
|
184
|
+
if (mediaAttachment.has("extension")) {
|
|
185
|
+
mediaMap["extension"] = mediaAttachment.optString("extension", "")
|
|
186
|
+
}
|
|
187
|
+
if (mediaAttachment.has("contentType")) {
|
|
188
|
+
mediaMap["contentType"] = mediaAttachment.optString("contentType", "")
|
|
189
|
+
}
|
|
190
|
+
if (mediaAttachment.has("fileSize")) {
|
|
191
|
+
mediaMap["fileSize"] = mediaAttachment.optLong("fileSize", 0)
|
|
192
|
+
}
|
|
177
193
|
mediaMap["width"] = mediaAttachment.optInt("width", 100)
|
|
178
194
|
mediaMap["height"] = mediaAttachment.optInt("height", 100)
|
|
179
195
|
mediaMap["alt"] = mediaAttachment.optString("alt", "")
|
|
@@ -2035,7 +2035,12 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2035
2035
|
|
|
2036
2036
|
private func insertPickedImage(_ image: UIImage) {
|
|
2037
2037
|
guard let imageUrl = writeImageToTemporaryURL(image) else { return }
|
|
2038
|
-
|
|
2038
|
+
let mediaAttachment = createMediaAttachmentInfoFromUri(
|
|
2039
|
+
imageUrl.absoluteString,
|
|
2040
|
+
kind: "image",
|
|
2041
|
+
alt: "Selected image"
|
|
2042
|
+
)
|
|
2043
|
+
insertMediaAttachmentBlock(mediaAttachment: mediaAttachment, image: image)
|
|
2039
2044
|
}
|
|
2040
2045
|
|
|
2041
2046
|
private func writeImageToTemporaryURL(_ image: UIImage) -> URL? {
|
|
@@ -2051,7 +2056,12 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2051
2056
|
}
|
|
2052
2057
|
}
|
|
2053
2058
|
|
|
2054
|
-
private func insertMediaAttachmentBlock(
|
|
2059
|
+
private func insertMediaAttachmentBlock(mediaAttachment: [String: Any], image: UIImage?) {
|
|
2060
|
+
guard let uri = mediaAttachment["uri"] as? String,
|
|
2061
|
+
!uri.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
|
2062
|
+
return
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2055
2065
|
let mutable = NSMutableAttributedString(attributedString: textView.attributedText)
|
|
2056
2066
|
var insertPos = textView.selectedRange.location
|
|
2057
2067
|
insertPos = max(0, min(insertPos, mutable.length))
|
|
@@ -2066,7 +2076,12 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2066
2076
|
}
|
|
2067
2077
|
}
|
|
2068
2078
|
|
|
2069
|
-
let attachmentString = createMediaAttachmentAttributedString(
|
|
2079
|
+
let attachmentString = createMediaAttachmentAttributedString(
|
|
2080
|
+
mediaAttachment: mediaAttachment,
|
|
2081
|
+
image: image,
|
|
2082
|
+
width: nil,
|
|
2083
|
+
height: nil
|
|
2084
|
+
)
|
|
2070
2085
|
mutable.insert(attachmentString, at: insertPos)
|
|
2071
2086
|
|
|
2072
2087
|
var nextPos = insertPos + attachmentString.length
|
|
@@ -2090,13 +2105,33 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2090
2105
|
updateContentSize()
|
|
2091
2106
|
}
|
|
2092
2107
|
|
|
2093
|
-
private func
|
|
2108
|
+
private func insertMediaAttachmentBlock(uri: String, image: UIImage?) {
|
|
2109
|
+
let safeUri = uri.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
2110
|
+
guard !safeUri.isEmpty else { return }
|
|
2111
|
+
let mediaAttachment = createMediaAttachmentInfoFromUri(safeUri, kind: "image", alt: "Selected image")
|
|
2112
|
+
insertMediaAttachmentBlock(mediaAttachment: mediaAttachment, image: image)
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
private func createMediaAttachmentAttributedString(mediaAttachment: [String: Any], image: UIImage?, width: CGFloat?, height: CGFloat?) -> NSAttributedString {
|
|
2116
|
+
let uri = (mediaAttachment["uri"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
|
2117
|
+
let sourceUri = (mediaAttachment["sourceUri"] as? String)
|
|
2118
|
+
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
|
|
2119
|
+
.flatMap { $0.isEmpty ? nil : $0 } ?? uri
|
|
2120
|
+
let kind = (mediaAttachment["kind"] as? String)
|
|
2121
|
+
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
|
|
2122
|
+
.flatMap { $0.isEmpty ? nil : $0 } ?? "image"
|
|
2123
|
+
let alt = (mediaAttachment["alt"] as? String)
|
|
2124
|
+
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
|
|
2125
|
+
.flatMap { $0.isEmpty ? nil : $0 } ?? "Selected image"
|
|
2126
|
+
|
|
2127
|
+
let widthFromPayload = numberValue(mediaAttachment["width"]).map { CGFloat(truncating: $0) }
|
|
2128
|
+
let heightFromPayload = numberValue(mediaAttachment["height"]).map { CGFloat(truncating: $0) }
|
|
2094
2129
|
let textContainerWidth = max(
|
|
2095
2130
|
120,
|
|
2096
2131
|
textView.bounds.width - textView.textContainerInset.left - textView.textContainerInset.right - textView.textContainer.lineFragmentPadding * 2
|
|
2097
2132
|
)
|
|
2098
2133
|
|
|
2099
|
-
let fallbackWidth = width ?? textContainerWidth
|
|
2134
|
+
let fallbackWidth = width ?? widthFromPayload ?? textContainerWidth
|
|
2100
2135
|
let normalizedWidth = max(1, min(textContainerWidth, fallbackWidth))
|
|
2101
2136
|
|
|
2102
2137
|
let sourceImage = image ?? loadImageFromUri(uri)
|
|
@@ -2104,7 +2139,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2104
2139
|
if let sourceImage = sourceImage, sourceImage.size.width > 0 {
|
|
2105
2140
|
normalizedHeight = max(1, normalizedWidth * (sourceImage.size.height / sourceImage.size.width))
|
|
2106
2141
|
} else {
|
|
2107
|
-
normalizedHeight = max(1, height ?? normalizedWidth)
|
|
2142
|
+
normalizedHeight = max(1, height ?? heightFromPayload ?? normalizedWidth)
|
|
2108
2143
|
}
|
|
2109
2144
|
|
|
2110
2145
|
let targetSize = CGSize(width: normalizedWidth, height: normalizedHeight)
|
|
@@ -2113,15 +2148,32 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2113
2148
|
attachment.image = renderMediaImage(sourceImage, targetSize: targetSize)
|
|
2114
2149
|
|
|
2115
2150
|
let attributed = NSMutableAttributedString(attachment: attachment)
|
|
2151
|
+
|
|
2152
|
+
var normalizedAttachment: [String: Any] = [
|
|
2153
|
+
"kind": kind,
|
|
2154
|
+
"uri": uri,
|
|
2155
|
+
"sourceUri": sourceUri,
|
|
2156
|
+
"width": Int(normalizedWidth.rounded()),
|
|
2157
|
+
"height": Int(normalizedHeight.rounded()),
|
|
2158
|
+
"alt": alt
|
|
2159
|
+
]
|
|
2160
|
+
|
|
2161
|
+
if let fileName = (mediaAttachment["fileName"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !fileName.isEmpty {
|
|
2162
|
+
normalizedAttachment["fileName"] = fileName
|
|
2163
|
+
}
|
|
2164
|
+
if let fileExtension = (mediaAttachment["extension"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !fileExtension.isEmpty {
|
|
2165
|
+
normalizedAttachment["extension"] = fileExtension
|
|
2166
|
+
}
|
|
2167
|
+
if let contentType = (mediaAttachment["contentType"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !contentType.isEmpty {
|
|
2168
|
+
normalizedAttachment["contentType"] = contentType
|
|
2169
|
+
}
|
|
2170
|
+
if let fileSize = numberValue(mediaAttachment["fileSize"]) {
|
|
2171
|
+
normalizedAttachment["fileSize"] = fileSize
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2116
2174
|
attributed.addAttribute(
|
|
2117
2175
|
RichTextEditorView.mediaAttachmentAttributeKey,
|
|
2118
|
-
value:
|
|
2119
|
-
"kind": "image",
|
|
2120
|
-
"uri": uri,
|
|
2121
|
-
"width": Int(normalizedWidth.rounded()),
|
|
2122
|
-
"height": Int(normalizedHeight.rounded()),
|
|
2123
|
-
"alt": alt
|
|
2124
|
-
],
|
|
2176
|
+
value: normalizedAttachment,
|
|
2125
2177
|
range: NSRange(location: 0, length: attributed.length)
|
|
2126
2178
|
)
|
|
2127
2179
|
|
|
@@ -2172,6 +2224,137 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2172
2224
|
return UIImage(data: data)
|
|
2173
2225
|
}
|
|
2174
2226
|
|
|
2227
|
+
private func createMediaAttachmentInfoFromUri(_ uri: String, kind: String = "image", alt: String = "Selected image") -> [String: Any] {
|
|
2228
|
+
let normalizedUri = uri.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
2229
|
+
var mediaAttachment: [String: Any] = [
|
|
2230
|
+
"kind": kind,
|
|
2231
|
+
"uri": normalizedUri,
|
|
2232
|
+
"sourceUri": normalizedUri,
|
|
2233
|
+
"alt": alt
|
|
2234
|
+
]
|
|
2235
|
+
|
|
2236
|
+
let inferred = inferMediaMetadata(from: normalizedUri)
|
|
2237
|
+
if let fileName = inferred.fileName {
|
|
2238
|
+
mediaAttachment["fileName"] = fileName
|
|
2239
|
+
}
|
|
2240
|
+
if let fileExtension = inferred.fileExtension {
|
|
2241
|
+
mediaAttachment["extension"] = fileExtension
|
|
2242
|
+
}
|
|
2243
|
+
if let contentType = inferred.contentType {
|
|
2244
|
+
mediaAttachment["contentType"] = contentType
|
|
2245
|
+
}
|
|
2246
|
+
if let fileSize = inferred.fileSize {
|
|
2247
|
+
mediaAttachment["fileSize"] = fileSize
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
return mediaAttachment
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
private func numberValue(_ value: Any?) -> NSNumber? {
|
|
2254
|
+
if let number = value as? NSNumber {
|
|
2255
|
+
return number
|
|
2256
|
+
}
|
|
2257
|
+
if let intValue = value as? Int {
|
|
2258
|
+
return NSNumber(value: intValue)
|
|
2259
|
+
}
|
|
2260
|
+
if let int64Value = value as? Int64 {
|
|
2261
|
+
return NSNumber(value: int64Value)
|
|
2262
|
+
}
|
|
2263
|
+
if let doubleValue = value as? Double {
|
|
2264
|
+
return NSNumber(value: doubleValue)
|
|
2265
|
+
}
|
|
2266
|
+
if let floatValue = value as? Float {
|
|
2267
|
+
return NSNumber(value: floatValue)
|
|
2268
|
+
}
|
|
2269
|
+
return nil
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
private func parseMediaAttachmentPayload(_ payload: String) -> [String: Any]? {
|
|
2273
|
+
let trimmed = payload.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
2274
|
+
guard !trimmed.isEmpty else { return nil }
|
|
2275
|
+
|
|
2276
|
+
if trimmed.first == "{" {
|
|
2277
|
+
guard let data = trimmed.data(using: .utf8),
|
|
2278
|
+
let raw = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
|
2279
|
+
let uriValue = raw["uri"] as? String else {
|
|
2280
|
+
return nil
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
let uri = uriValue.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
2284
|
+
guard !uri.isEmpty else { return nil }
|
|
2285
|
+
|
|
2286
|
+
var normalized = createMediaAttachmentInfoFromUri(uri)
|
|
2287
|
+
|
|
2288
|
+
if let kind = (raw["kind"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !kind.isEmpty {
|
|
2289
|
+
normalized["kind"] = kind
|
|
2290
|
+
}
|
|
2291
|
+
if let sourceUri = (raw["sourceUri"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !sourceUri.isEmpty {
|
|
2292
|
+
normalized["sourceUri"] = sourceUri
|
|
2293
|
+
}
|
|
2294
|
+
if let alt = (raw["alt"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !alt.isEmpty {
|
|
2295
|
+
normalized["alt"] = alt
|
|
2296
|
+
}
|
|
2297
|
+
if let fileName = (raw["fileName"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !fileName.isEmpty {
|
|
2298
|
+
normalized["fileName"] = fileName
|
|
2299
|
+
}
|
|
2300
|
+
if let fileExtension = (raw["extension"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !fileExtension.isEmpty {
|
|
2301
|
+
normalized["extension"] = fileExtension
|
|
2302
|
+
}
|
|
2303
|
+
if let contentType = (raw["contentType"] as? String)?.trimmingCharacters(in: .whitespacesAndNewlines), !contentType.isEmpty {
|
|
2304
|
+
normalized["contentType"] = contentType
|
|
2305
|
+
}
|
|
2306
|
+
if let fileSize = numberValue(raw["fileSize"]) {
|
|
2307
|
+
normalized["fileSize"] = fileSize
|
|
2308
|
+
}
|
|
2309
|
+
if let width = numberValue(raw["width"]) {
|
|
2310
|
+
normalized["width"] = max(1, width.intValue)
|
|
2311
|
+
}
|
|
2312
|
+
if let height = numberValue(raw["height"]) {
|
|
2313
|
+
normalized["height"] = max(1, height.intValue)
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
return normalized
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
return createMediaAttachmentInfoFromUri(trimmed)
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
private func inferMediaMetadata(from uri: String) -> (fileName: String?, fileExtension: String?, contentType: String?, fileSize: NSNumber?) {
|
|
2323
|
+
guard let url = URL(string: uri) else {
|
|
2324
|
+
return (nil, nil, nil, nil)
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
let fileName = url.lastPathComponent.isEmpty ? nil : url.lastPathComponent
|
|
2328
|
+
let fileExtension = url.pathExtension.isEmpty ? nil : url.pathExtension.lowercased()
|
|
2329
|
+
|
|
2330
|
+
var fileSize: NSNumber?
|
|
2331
|
+
if url.isFileURL,
|
|
2332
|
+
let attributes = try? FileManager.default.attributesOfItem(atPath: url.path),
|
|
2333
|
+
let size = attributes[.size] as? NSNumber {
|
|
2334
|
+
fileSize = size
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
let contentType = fileExtension.flatMap { mimeType(forExtension: $0) }
|
|
2338
|
+
|
|
2339
|
+
return (fileName, fileExtension, contentType, fileSize)
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
private func mimeType(forExtension fileExtension: String) -> String? {
|
|
2343
|
+
let lower = fileExtension.lowercased()
|
|
2344
|
+
switch lower {
|
|
2345
|
+
case "jpg", "jpeg": return "image/jpeg"
|
|
2346
|
+
case "png": return "image/png"
|
|
2347
|
+
case "gif": return "image/gif"
|
|
2348
|
+
case "webp": return "image/webp"
|
|
2349
|
+
case "bmp": return "image/bmp"
|
|
2350
|
+
case "heic": return "image/heic"
|
|
2351
|
+
case "heif": return "image/heif"
|
|
2352
|
+
case "mp4": return "video/mp4"
|
|
2353
|
+
case "mov": return "video/quicktime"
|
|
2354
|
+
default: return nil
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2175
2358
|
private func isImageURL(_ url: URL) -> Bool {
|
|
2176
2359
|
let lowercasedPath = url.path.lowercased()
|
|
2177
2360
|
return lowercasedPath.hasSuffix(".png") ||
|
|
@@ -2365,9 +2548,38 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2365
2548
|
let uri = mediaAttachment["uri"] as? String {
|
|
2366
2549
|
let width = (mediaAttachment["width"] as? NSNumber).map { CGFloat(truncating: $0) }
|
|
2367
2550
|
let height = (mediaAttachment["height"] as? NSNumber).map { CGFloat(truncating: $0) }
|
|
2368
|
-
|
|
2551
|
+
var normalizedMediaAttachment = createMediaAttachmentInfoFromUri(uri)
|
|
2369
2552
|
|
|
2370
|
-
|
|
2553
|
+
if let kind = mediaAttachment["kind"] as? String {
|
|
2554
|
+
normalizedMediaAttachment["kind"] = kind
|
|
2555
|
+
}
|
|
2556
|
+
if let sourceUri = mediaAttachment["sourceUri"] as? String, !sourceUri.isEmpty {
|
|
2557
|
+
normalizedMediaAttachment["sourceUri"] = sourceUri
|
|
2558
|
+
}
|
|
2559
|
+
if let alt = mediaAttachment["alt"] as? String, !alt.isEmpty {
|
|
2560
|
+
normalizedMediaAttachment["alt"] = alt
|
|
2561
|
+
}
|
|
2562
|
+
if let fileName = mediaAttachment["fileName"] as? String, !fileName.isEmpty {
|
|
2563
|
+
normalizedMediaAttachment["fileName"] = fileName
|
|
2564
|
+
}
|
|
2565
|
+
if let fileExtension = mediaAttachment["extension"] as? String, !fileExtension.isEmpty {
|
|
2566
|
+
normalizedMediaAttachment["extension"] = fileExtension
|
|
2567
|
+
}
|
|
2568
|
+
if let contentType = mediaAttachment["contentType"] as? String, !contentType.isEmpty {
|
|
2569
|
+
normalizedMediaAttachment["contentType"] = contentType
|
|
2570
|
+
}
|
|
2571
|
+
if let fileSize = numberValue(mediaAttachment["fileSize"]) {
|
|
2572
|
+
normalizedMediaAttachment["fileSize"] = fileSize
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
attributedString.append(
|
|
2576
|
+
createMediaAttachmentAttributedString(
|
|
2577
|
+
mediaAttachment: normalizedMediaAttachment,
|
|
2578
|
+
image: nil,
|
|
2579
|
+
width: width,
|
|
2580
|
+
height: height
|
|
2581
|
+
)
|
|
2582
|
+
)
|
|
2371
2583
|
|
|
2372
2584
|
if blockIndex < blocks.count - 1 {
|
|
2373
2585
|
attributedString.append(NSAttributedString(string: "\n", attributes: [
|
|
@@ -2589,10 +2801,16 @@ class RichTextEditorView: UIView, UITextViewDelegate, PHPickerViewControllerDele
|
|
|
2589
2801
|
}
|
|
2590
2802
|
|
|
2591
2803
|
func insertMediaAttachment(uri: String) {
|
|
2592
|
-
let
|
|
2593
|
-
guard !
|
|
2594
|
-
|
|
2595
|
-
|
|
2804
|
+
let safePayload = uri.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
2805
|
+
guard !safePayload.isEmpty,
|
|
2806
|
+
let mediaAttachment = parseMediaAttachmentPayload(safePayload),
|
|
2807
|
+
let mediaUri = mediaAttachment["uri"] as? String,
|
|
2808
|
+
!mediaUri.isEmpty else {
|
|
2809
|
+
return
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2812
|
+
let image = loadImageFromUri(mediaUri)
|
|
2813
|
+
insertMediaAttachmentBlock(mediaAttachment: mediaAttachment, image: image)
|
|
2596
2814
|
}
|
|
2597
2815
|
|
|
2598
2816
|
func undo() {
|
package/lib/commonjs/index.js
CHANGED
|
@@ -33,10 +33,16 @@ const RichTextEditor = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
33
33
|
if (commandId == null) return;
|
|
34
34
|
_reactNative.UIManager.dispatchViewManagerCommand(nativeTag, commandId, args);
|
|
35
35
|
}, []);
|
|
36
|
-
const dispatchInsertMediaAttachment = _react.default.useCallback(
|
|
37
|
-
if (typeof uri !== "string" || uri.trim().length === 0)
|
|
36
|
+
const dispatchInsertMediaAttachment = _react.default.useCallback(mediaAttachment => {
|
|
37
|
+
if (!mediaAttachment || typeof mediaAttachment !== "object" || typeof mediaAttachment.uri !== "string" || mediaAttachment.uri.trim().length === 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const normalizedMediaAttachment = {
|
|
41
|
+
...mediaAttachment,
|
|
42
|
+
sourceUri: mediaAttachment.sourceUri ?? mediaAttachment.uri
|
|
43
|
+
};
|
|
38
44
|
if (_reactNative.Platform.OS === "android") {
|
|
39
|
-
dispatchAndroidCommand("insertMediaAttachment", [
|
|
45
|
+
dispatchAndroidCommand("insertMediaAttachment", [JSON.stringify(normalizedMediaAttachment)]);
|
|
40
46
|
return;
|
|
41
47
|
}
|
|
42
48
|
if (_reactNative.Platform.OS === "ios") {
|
|
@@ -44,7 +50,7 @@ const RichTextEditor = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
44
50
|
if (nativeTag == null) return;
|
|
45
51
|
const manager = _reactNative.NativeModules ? _reactNative.NativeModules["RichTextEditorViewManager"] : null;
|
|
46
52
|
if (manager && typeof manager === "object" && typeof manager.insertMediaAttachment === "function") {
|
|
47
|
-
manager.insertMediaAttachment(nativeTag,
|
|
53
|
+
manager.insertMediaAttachment(nativeTag, JSON.stringify(normalizedMediaAttachment));
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
}, [dispatchAndroidCommand]);
|
|
@@ -105,9 +111,7 @@ const RichTextEditor = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
105
111
|
/* Native toolbar handles this */
|
|
106
112
|
},
|
|
107
113
|
insertMediaAttachment: mediaAttachment => {
|
|
108
|
-
|
|
109
|
-
dispatchInsertMediaAttachment(mediaAttachment.uri);
|
|
110
|
-
}
|
|
114
|
+
dispatchInsertMediaAttachment(mediaAttachment);
|
|
111
115
|
},
|
|
112
116
|
undo: () => {
|
|
113
117
|
/* Native toolbar handles this */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_RichTextEditorViewNativeComponent","_types","e","__esModule","default","RichTextEditor","React","forwardRef","props","ref","nativeRef","useRef","height","setHeight","useState","handleSizeChange","useCallback","event","newHeight","nativeEvent","dispatchAndroidCommand","commandName","args","Platform","OS","nativeTag","findNodeHandle","current","commandConfig","UIManager","getViewManagerConfig","Commands","commandId","dispatchViewManagerCommand","dispatchInsertMediaAttachment","uri","trim","length","manager","NativeModules","insertMediaAttachment","useImperativeHandle","setContent","_blocks","getText","getBlocks","clear","focus","blur","toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","toggleCode","toggleHighlight","_color","setHeading","setBulletList","setNumberedList","setQuote","setChecklist","setParagraph","insertLink","_url","_text","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_RichTextEditorViewNativeComponent","_types","e","__esModule","default","RichTextEditor","React","forwardRef","props","ref","nativeRef","useRef","height","setHeight","useState","handleSizeChange","useCallback","event","newHeight","nativeEvent","dispatchAndroidCommand","commandName","args","Platform","OS","nativeTag","findNodeHandle","current","commandConfig","UIManager","getViewManagerConfig","Commands","commandId","dispatchViewManagerCommand","dispatchInsertMediaAttachment","mediaAttachment","uri","trim","length","normalizedMediaAttachment","sourceUri","JSON","stringify","manager","NativeModules","insertMediaAttachment","useImperativeHandle","setContent","_blocks","getText","getBlocks","clear","focus","blur","toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","toggleCode","toggleHighlight","_color","setHeading","setBulletList","setNumberedList","setQuote","setChecklist","setParagraph","insertLink","_url","_text","undo","redo","clearFormatting","indent","outdent","setAlignment","_alignment","toggleChecklistItem","handleContentChange","blocks","blocksJson","parse","contentEvent","text","delta","onContentChange","handleSelectionChange","selectionEvent","start","end","onSelectionChange","handleFocus","onFocus","handleBlur","onBlur","handleActiveStylesChange","onActiveStylesChange","combinedStyle","StyleSheet","flatten","style","createElement","placeholder","initialContentJson","initialContent","undefined","editable","readOnly","selectable","maxHeight","numberOfLines","showToolbar","toolbarOptions","variant","fontFamily","fontSize","onEditorFocus","onEditorBlur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,CAACuG,WAAW,IAAI,IAAM;IAClEC,cAAc,EAAExG,KAAK,CAACwG,cAAe;IACrCC,OAAO,EAAEzG,KAAK,CAACyG,OAAO,IAAI,UAAW;IACrCC,UAAU,EAAE1G,KAAK,CAAC0G,UAAW;IAC7BC,QAAQ,EAAE3G,KAAK,CAAC2G,QAAS;IACzB9B,eAAe,EAAEP,mBAAoB;IACrCY,iBAAiB,EAAEJ,qBAAsB;IACzC8B,aAAa,EAAEzB,WAAY;IAC3B0B,YAAY,EAAExB,UAAW;IACzByB,YAAY,EAAEvG,gBAAiB;IAC/BiF,oBAAoB,EAAED;EAAyB,CAChD,CAAC;AAEN,CAAC,CAAC;AAEF1F,cAAc,CAACkH,WAAW,GAAG,gBAAgB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAArH,OAAA,GAE/BC,cAAc","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_TOOLBAR_OPTIONS","exports"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"names":["DEFAULT_TOOLBAR_OPTIONS","exports"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;;;;;AAqGO,MAAMA,uBAAwC,GAAAC,OAAA,CAAAD,uBAAA,GAAG,CACtD,MAAM,EACN,QAAQ,EACR,WAAW,EACX,eAAe,EACf,MAAM,EACN,WAAW,EACX,SAAS,EACT,QAAQ,EACR,UAAU,EACV,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,MAAM,EACN,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,WAAW,EACX,aAAa,EACb,YAAY,CACb","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -19,10 +19,16 @@ const RichTextEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
19
19
|
if (commandId == null) return;
|
|
20
20
|
UIManager.dispatchViewManagerCommand(nativeTag, commandId, args);
|
|
21
21
|
}, []);
|
|
22
|
-
const dispatchInsertMediaAttachment = React.useCallback(
|
|
23
|
-
if (typeof uri !== "string" || uri.trim().length === 0)
|
|
22
|
+
const dispatchInsertMediaAttachment = React.useCallback(mediaAttachment => {
|
|
23
|
+
if (!mediaAttachment || typeof mediaAttachment !== "object" || typeof mediaAttachment.uri !== "string" || mediaAttachment.uri.trim().length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const normalizedMediaAttachment = {
|
|
27
|
+
...mediaAttachment,
|
|
28
|
+
sourceUri: mediaAttachment.sourceUri ?? mediaAttachment.uri
|
|
29
|
+
};
|
|
24
30
|
if (Platform.OS === "android") {
|
|
25
|
-
dispatchAndroidCommand("insertMediaAttachment", [
|
|
31
|
+
dispatchAndroidCommand("insertMediaAttachment", [JSON.stringify(normalizedMediaAttachment)]);
|
|
26
32
|
return;
|
|
27
33
|
}
|
|
28
34
|
if (Platform.OS === "ios") {
|
|
@@ -30,7 +36,7 @@ const RichTextEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
30
36
|
if (nativeTag == null) return;
|
|
31
37
|
const manager = NativeModules ? NativeModules["RichTextEditorViewManager"] : null;
|
|
32
38
|
if (manager && typeof manager === "object" && typeof manager.insertMediaAttachment === "function") {
|
|
33
|
-
manager.insertMediaAttachment(nativeTag,
|
|
39
|
+
manager.insertMediaAttachment(nativeTag, JSON.stringify(normalizedMediaAttachment));
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
42
|
}, [dispatchAndroidCommand]);
|
|
@@ -91,9 +97,7 @@ const RichTextEditor = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
91
97
|
/* Native toolbar handles this */
|
|
92
98
|
},
|
|
93
99
|
insertMediaAttachment: mediaAttachment => {
|
|
94
|
-
|
|
95
|
-
dispatchInsertMediaAttachment(mediaAttachment.uri);
|
|
96
|
-
}
|
|
100
|
+
dispatchInsertMediaAttachment(mediaAttachment);
|
|
97
101
|
},
|
|
98
102
|
undo: () => {
|
|
99
103
|
/* Native toolbar handles this */
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","findNodeHandle","NativeModules","Platform","StyleSheet","UIManager","RichTextEditorViewNative","RichTextEditor","forwardRef","props","ref","nativeRef","useRef","height","setHeight","useState","handleSizeChange","useCallback","event","newHeight","nativeEvent","dispatchAndroidCommand","commandName","args","OS","nativeTag","current","commandConfig","getViewManagerConfig","Commands","commandId","dispatchViewManagerCommand","dispatchInsertMediaAttachment","uri","trim","length","manager","insertMediaAttachment","useImperativeHandle","setContent","_blocks","getText","getBlocks","clear","focus","blur","toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","toggleCode","toggleHighlight","_color","setHeading","setBulletList","setNumberedList","setQuote","setChecklist","setParagraph","insertLink","_url","_text","
|
|
1
|
+
{"version":3,"names":["React","findNodeHandle","NativeModules","Platform","StyleSheet","UIManager","RichTextEditorViewNative","RichTextEditor","forwardRef","props","ref","nativeRef","useRef","height","setHeight","useState","handleSizeChange","useCallback","event","newHeight","nativeEvent","dispatchAndroidCommand","commandName","args","OS","nativeTag","current","commandConfig","getViewManagerConfig","Commands","commandId","dispatchViewManagerCommand","dispatchInsertMediaAttachment","mediaAttachment","uri","trim","length","normalizedMediaAttachment","sourceUri","JSON","stringify","manager","insertMediaAttachment","useImperativeHandle","setContent","_blocks","getText","getBlocks","clear","focus","blur","toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","toggleCode","toggleHighlight","_color","setHeading","setBulletList","setNumberedList","setQuote","setChecklist","setParagraph","insertLink","_url","_text","undo","redo","clearFormatting","indent","outdent","setAlignment","_alignment","toggleChecklistItem","handleContentChange","blocks","blocksJson","parse","contentEvent","text","delta","onContentChange","handleSelectionChange","selectionEvent","start","end","onSelectionChange","handleFocus","onFocus","handleBlur","onBlur","handleActiveStylesChange","onActiveStylesChange","combinedStyle","flatten","style","createElement","placeholder","initialContentJson","initialContent","undefined","editable","readOnly","selectable","maxHeight","numberOfLines","showToolbar","toolbarOptions","variant","fontFamily","fontSize","onEditorFocus","onEditorBlur","onSizeChange","displayName","DEFAULT_TOOLBAR_OPTIONS"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,cAAc,EACdC,aAAa,EACbC,QAAQ,EACRC,UAAU,EACVC,SAAS,QACJ,cAAc;AAUrB,OAAOC,wBAAwB,MAAM,qCAAqC;AA2B1E,MAAMC,cAAc,gBAAGP,KAAK,CAACQ,UAAU,CAGrC,CAACC,KAAK,EAAEC,GAAG,KAAK;EAChB,MAAMC,SAAS,GACbX,KAAK,CAACY,MAAM,CAAoD,IAAI,CAAC;EACvE,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAGd,KAAK,CAACe,QAAQ,CAAS,EAAE,CAAC;EAEtD,MAAMC,gBAAgB,GAAGhB,KAAK,CAACiB,WAAW,CAAEC,KAAsB,IAAK;IACrE,MAAMC,SAAS,GAAGD,KAAK,CAACE,WAAW,EAAEP,MAAM;IAC3C,IAAIM,SAAS,IAAIA,SAAS,GAAG,CAAC,EAAE;MAC9BL,SAAS,CAACK,SAAS,CAAC;IACtB;EACF,CAAC,EAAE,EAAE,CAAC;EAEN,MAAME,sBAAsB,GAAGrB,KAAK,CAACiB,WAAW,CAC9C,CAACK,WAAmB,EAAEC,IAAmC,GAAG,EAAE,KAAK;IACjE,IAAIpB,QAAQ,CAACqB,EAAE,KAAK,SAAS,EAAE;IAE/B,MAAMC,SAAS,GAAGxB,cAAc,CAACU,SAAS,CAACe,OAAO,CAAC;IACnD,IAAID,SAAS,IAAI,IAAI,EAAE;IAEvB,MAAME,aAAa,GACjBtB,SAAS,CAACuB,oBAAoB,CAAC,oBAAoB,CAAC,EAAEC,QAAQ;IAChE,MAAMC,SAAS,GAAGH,aAAa,GAAGL,WAAW,CAAC;IAE9C,IAAIQ,SAAS,IAAI,IAAI,EAAE;IAEvBzB,SAAS,CAAC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;IACrCC,OAAO,EAAEpG,KAAK,CAACoG,OAAO,IAAI,UAAW;IACrCC,UAAU,EAAErG,KAAK,CAACqG,UAAW;IAC7BC,QAAQ,EAAEtG,KAAK,CAACsG,QAAS;IACzB7B,eAAe,EAAEP,mBAAoB;IACrCY,iBAAiB,EAAEJ,qBAAsB;IACzC6B,aAAa,EAAExB,WAAY;IAC3ByB,YAAY,EAAEvB,UAAW;IACzBwB,YAAY,EAAElG,gBAAiB;IAC/B6E,oBAAoB,EAAED;EAAyB,CAChD,CAAC;AAEN,CAAC,CAAC;AAEFrF,cAAc,CAAC4G,WAAW,GAAG,gBAAgB;AAE7C,eAAe5G,cAAc;AAC7B,SAAS6G,uBAAuB,QAAQ,SAAS","ignoreList":[]}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_TOOLBAR_OPTIONS"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["DEFAULT_TOOLBAR_OPTIONS"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"AAqGA,OAAO,MAAMA,uBAAwC,GAAG,CACtD,MAAM,EACN,QAAQ,EACR,WAAW,EACX,eAAe,EACf,MAAM,EACN,WAAW,EACX,SAAS,EACT,QAAQ,EACR,UAAU,EACV,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,MAAM,EACN,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,WAAW,EACX,aAAa,EACb,YAAY,CACb","ignoreList":[]}
|
|
@@ -16,5 +16,5 @@ export interface RichTextEditorPropsExtended extends RichTextEditorProps {
|
|
|
16
16
|
declare const RichTextEditor: React.ForwardRefExoticComponent<RichTextEditorPropsExtended & React.RefAttributes<RichTextEditorRef>>;
|
|
17
17
|
export default RichTextEditor;
|
|
18
18
|
export { DEFAULT_TOOLBAR_OPTIONS } from "./types";
|
|
19
|
-
export type { Block, BlockType, StyleRange, MediaAttachment, TextAlignment, EditorVariant, ContentChangeEvent, SelectionChangeEvent, RichTextEditorRef, RichTextEditorProps, ToolbarOption, ContentDelta, DeltaType, } from "./types";
|
|
19
|
+
export type { Block, BlockType, StyleRange, MediaKind, MediaAttachment, TextAlignment, EditorVariant, ContentChangeEvent, SelectionChangeEvent, RichTextEditorRef, RichTextEditorProps, ToolbarOption, ContentDelta, DeltaType, } from "./types";
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,KAAK,EAMV,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AASjB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC5D;AAED,QAAA,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,KAAK,EAMV,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AASjB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,MAAM,WAAW,2BAA4B,SAAQ,mBAAmB;IACtE,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC5D;AAED,QAAA,MAAM,cAAc,uGAgQlB,CAAC;AAIH,eAAe,cAAc,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,YAAY,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,SAAS,GACV,MAAM,SAAS,CAAC"}
|
|
@@ -9,9 +9,15 @@ export interface StyleRange {
|
|
|
9
9
|
export type BlockType = "paragraph" | "bullet" | "numbered" | "heading" | "quote" | "checklist" | "mediaAttachment";
|
|
10
10
|
export type TextAlignment = "left" | "center" | "right";
|
|
11
11
|
export type EditorVariant = "outlined" | "flat" | "plain";
|
|
12
|
+
export type MediaKind = "image" | "video";
|
|
12
13
|
export interface MediaAttachment {
|
|
13
|
-
kind:
|
|
14
|
+
kind: MediaKind;
|
|
14
15
|
uri: string;
|
|
16
|
+
sourceUri?: string;
|
|
17
|
+
fileName?: string;
|
|
18
|
+
extension?: string;
|
|
19
|
+
contentType?: string;
|
|
20
|
+
fileSize?: number;
|
|
15
21
|
width?: number;
|
|
16
22
|
height?: number;
|
|
17
23
|
alt?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,W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E,MAAM,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,qBAAqB,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,IAAI,CAAC;IAClE,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chaitrabhairappa/react-native-rich-text-editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "A high-performance native rich text editor for React Native (New Architecture / Fabric only)",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
package/src/index.tsx
CHANGED
|
@@ -76,11 +76,25 @@ const RichTextEditor = React.forwardRef<
|
|
|
76
76
|
);
|
|
77
77
|
|
|
78
78
|
const dispatchInsertMediaAttachment = React.useCallback(
|
|
79
|
-
(
|
|
80
|
-
if (
|
|
79
|
+
(mediaAttachment: MediaAttachment) => {
|
|
80
|
+
if (
|
|
81
|
+
!mediaAttachment ||
|
|
82
|
+
typeof mediaAttachment !== "object" ||
|
|
83
|
+
typeof mediaAttachment.uri !== "string" ||
|
|
84
|
+
mediaAttachment.uri.trim().length === 0
|
|
85
|
+
) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const normalizedMediaAttachment: MediaAttachment = {
|
|
90
|
+
...mediaAttachment,
|
|
91
|
+
sourceUri: mediaAttachment.sourceUri ?? mediaAttachment.uri,
|
|
92
|
+
};
|
|
81
93
|
|
|
82
94
|
if (Platform.OS === "android") {
|
|
83
|
-
dispatchAndroidCommand("insertMediaAttachment", [
|
|
95
|
+
dispatchAndroidCommand("insertMediaAttachment", [
|
|
96
|
+
JSON.stringify(normalizedMediaAttachment),
|
|
97
|
+
]);
|
|
84
98
|
return;
|
|
85
99
|
}
|
|
86
100
|
|
|
@@ -104,7 +118,10 @@ const RichTextEditor = React.forwardRef<
|
|
|
104
118
|
manager as {
|
|
105
119
|
insertMediaAttachment: (tag: number, value: string) => void;
|
|
106
120
|
}
|
|
107
|
-
).insertMediaAttachment(
|
|
121
|
+
).insertMediaAttachment(
|
|
122
|
+
nativeTag,
|
|
123
|
+
JSON.stringify(normalizedMediaAttachment),
|
|
124
|
+
);
|
|
108
125
|
}
|
|
109
126
|
}
|
|
110
127
|
},
|
|
@@ -169,13 +186,7 @@ const RichTextEditor = React.forwardRef<
|
|
|
169
186
|
/* Native toolbar handles this */
|
|
170
187
|
},
|
|
171
188
|
insertMediaAttachment: (mediaAttachment: MediaAttachment) => {
|
|
172
|
-
|
|
173
|
-
mediaAttachment &&
|
|
174
|
-
typeof mediaAttachment === "object" &&
|
|
175
|
-
typeof mediaAttachment.uri === "string"
|
|
176
|
-
) {
|
|
177
|
-
dispatchInsertMediaAttachment(mediaAttachment.uri);
|
|
178
|
-
}
|
|
189
|
+
dispatchInsertMediaAttachment(mediaAttachment);
|
|
179
190
|
},
|
|
180
191
|
undo: () => {
|
|
181
192
|
/* Native toolbar handles this */
|
|
@@ -297,6 +308,7 @@ export type {
|
|
|
297
308
|
Block,
|
|
298
309
|
BlockType,
|
|
299
310
|
StyleRange,
|
|
311
|
+
MediaKind,
|
|
300
312
|
MediaAttachment,
|
|
301
313
|
TextAlignment,
|
|
302
314
|
EditorVariant,
|
package/src/types.ts
CHANGED
|
@@ -25,10 +25,16 @@ export type BlockType =
|
|
|
25
25
|
| "mediaAttachment";
|
|
26
26
|
export type TextAlignment = "left" | "center" | "right";
|
|
27
27
|
export type EditorVariant = "outlined" | "flat" | "plain";
|
|
28
|
+
export type MediaKind = "image" | "video";
|
|
28
29
|
|
|
29
30
|
export interface MediaAttachment {
|
|
30
|
-
kind:
|
|
31
|
+
kind: MediaKind;
|
|
31
32
|
uri: string;
|
|
33
|
+
sourceUri?: string;
|
|
34
|
+
fileName?: string;
|
|
35
|
+
extension?: string;
|
|
36
|
+
contentType?: string;
|
|
37
|
+
fileSize?: number;
|
|
32
38
|
width?: number;
|
|
33
39
|
height?: number;
|
|
34
40
|
alt?: string;
|