@yorkjs/hive-ui 2.2.6 → 2.2.7
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/package.json
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
width 100%
|
|
12
12
|
.auto-height
|
|
13
13
|
height auto
|
|
14
|
-
min-height 80PX
|
|
15
14
|
background-color transparent
|
|
16
15
|
|
|
17
16
|
.block
|
|
@@ -41,6 +40,9 @@
|
|
|
41
40
|
.text-block
|
|
42
41
|
padding 15PX 15PX 6PX
|
|
43
42
|
|
|
43
|
+
.textarea-wrap
|
|
44
|
+
min-height 80PX
|
|
45
|
+
|
|
44
46
|
.editor-textarea
|
|
45
47
|
:global(.taro-textarea)
|
|
46
48
|
width 100%
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useMemo } from 'react'
|
|
1
|
+
import React, { useCallback, useMemo, useRef } from 'react'
|
|
2
2
|
import { View, Textarea, Image, BaseEventOrig, ITouchEvent } from '@tarojs/components'
|
|
3
3
|
|
|
4
4
|
import { useTheme } from '../../config'
|
|
@@ -49,6 +49,19 @@ export interface RichTextEditorProps {
|
|
|
49
49
|
|
|
50
50
|
const ALIGN_OPTIONS: RichTextAlign[] = ['left', 'center', 'right']
|
|
51
51
|
|
|
52
|
+
const focusTextarea = (instance: any) => {
|
|
53
|
+
if (!instance) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof instance.focus === 'function') {
|
|
58
|
+
instance.focus()
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
instance.querySelector?.('textarea')?.focus?.()
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
const RichTextEditor: React.FC<RichTextEditorProps> = (props) => {
|
|
53
66
|
const {
|
|
54
67
|
value = [],
|
|
@@ -58,6 +71,7 @@ const RichTextEditor: React.FC<RichTextEditorProps> = (props) => {
|
|
|
58
71
|
} = props
|
|
59
72
|
|
|
60
73
|
const { themeSelect } = useTheme()
|
|
74
|
+
const textareaRefs = useRef<Record<number, any>>({})
|
|
61
75
|
|
|
62
76
|
const deleteBtnStyle = useMemo(() => ({
|
|
63
77
|
backgroundColor: themeSelect('rgba(0, 0, 0, 0.5)', 'rgba(255, 255, 255, 0.5)'),
|
|
@@ -85,6 +99,10 @@ const RichTextEditor: React.FC<RichTextEditorProps> = (props) => {
|
|
|
85
99
|
updateBlock(index, { align })
|
|
86
100
|
}, [updateBlock])
|
|
87
101
|
|
|
102
|
+
const handleTextBlockClick = useCallback((index: number) => {
|
|
103
|
+
focusTextarea(textareaRefs.current[index])
|
|
104
|
+
}, [])
|
|
105
|
+
|
|
88
106
|
return (
|
|
89
107
|
<View className={formatClassNames(styles['rich-text-editor'], className)}>
|
|
90
108
|
{value.map((block, index) => (
|
|
@@ -108,18 +126,27 @@ const RichTextEditor: React.FC<RichTextEditorProps> = (props) => {
|
|
|
108
126
|
{
|
|
109
127
|
block.type === 'text'
|
|
110
128
|
? (
|
|
111
|
-
<View
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
<View
|
|
130
|
+
className={styles['text-block']}
|
|
131
|
+
onClick={() => handleTextBlockClick(index)}
|
|
132
|
+
>
|
|
133
|
+
<View className={styles['textarea-wrap']}>
|
|
134
|
+
<Textarea
|
|
135
|
+
ref={(node) => {
|
|
136
|
+
textareaRefs.current[index] = node
|
|
137
|
+
}}
|
|
138
|
+
className={formatClassNames(
|
|
139
|
+
styles['editor-textarea'],
|
|
140
|
+
styles[`is-align-${block.align || 'left'}`]
|
|
141
|
+
)}
|
|
142
|
+
value={block.content}
|
|
143
|
+
placeholder={block?.placeholder || placeholder}
|
|
144
|
+
maxlength={-1}
|
|
145
|
+
autoHeight
|
|
146
|
+
disableDefaultPadding
|
|
147
|
+
onInput={(e) => handleTextChange(index, e)}
|
|
148
|
+
/>
|
|
149
|
+
</View>
|
|
123
150
|
<View className={styles['align-toolbar']}>
|
|
124
151
|
{ALIGN_OPTIONS.map((align) => {
|
|
125
152
|
const active = (block.align || 'left') === align
|