Skip to content

Commit 556e1eb

Browse files
authored
Merge pull request wix-incubator#33 from philpettican/release/1.4.2
Release/1.4.2
2 parents 54a53e6 + fa18b7c commit 556e1eb

File tree

7 files changed

+89
-50
lines changed

7 files changed

+89
-50
lines changed

README.md

-16
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,6 @@ This method registers a function that will get called whenver the cursor positio
165165

166166
- `registerToolbar(listener)`
167167

168-
## Testing changes using the example app
169-
170-
- Install `yalc` globally. See https://www.npmjs.com/package/yalc for more details
171-
- `$ yarn`
172-
- `$ cd ios && pod install && cd ..`
173-
- `$ bash build.sh`
174-
- `$ react-native run-ios`
175-
- or
176-
- `$ react-native run-android`
177-
- In order for the example app to refresh with the latest changes, you need to:
178-
- re-run `$ bash build.sh`
179-
- Stop and restart the metro bundler and then run
180-
- `$ react-native run-ios`
181-
- or
182-
- `$ react-native run-android`
183-
184168
### Example Usage:
185169

186170
```javascript

example/App.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default class RichTextExample extends Component {
1919
state = {
2020
mentionListVisible: false,
2121
mentionSearchText: '',
22+
content:
23+
'Hello <b>World</b> <p>this is a new paragraph</p> <p>this is another new paragraph</p>',
2224
};
2325

2426
constructor(props) {
@@ -28,6 +30,7 @@ export default class RichTextExample extends Component {
2830
this.onMentioning = this.onMentioning.bind(this);
2931
this.onFinishMention = this.onFinishMention.bind(this);
3032
this.onListItemPress = this.onListItemPress.bind(this);
33+
this.onContentChange = this.onContentChange.bind(this);
3134
}
3235

3336
onMentioning(text) {
@@ -45,9 +48,9 @@ export default class RichTextExample extends Component {
4548
}
4649

4750
onListItemPress(item, index, items) {
48-
console.log('item', item);
49-
console.log('index', index);
50-
console.log('items', items);
51+
//console.log('item', item);
52+
//console.log('index', index);
53+
//console.log('items', items);
5154

5255
const { name } = item;
5356
this.richtext.insertMention(
@@ -73,6 +76,8 @@ export default class RichTextExample extends Component {
7376
}
7477

7578
render() {
79+
const { content } = this.state;
80+
7681
return (
7782
<View style={styles.container}>
7883
{false && this.renderInsertHTMLTest()}
@@ -82,9 +87,8 @@ export default class RichTextExample extends Component {
8287
ref={r => (this.richtext = r)}
8388
style={styles.richText}
8489
initialTitleHTML={'Title!!'}
85-
initialContentHTML={
86-
'Hello <b>World</b> <p>this is a new paragraph</p> <p>this is another new paragraph</p>'
87-
}
90+
enableOnChange={true}
91+
initialContentHTML={content}
8892
editorInitializedCallback={() => this.onEditorInitialized()}
8993
customCSS={CSS}
9094
onMentioning={this.onMentioning}
@@ -98,6 +102,7 @@ export default class RichTextExample extends Component {
98102

99103
onEditorInitialized() {
100104
this.setFocusHandlers();
105+
this.setContentChangeListener();
101106
this.getHTML();
102107
this.richtext.insertExternalCSS(EXTERNAL_CSS);
103108
}
@@ -137,6 +142,17 @@ export default class RichTextExample extends Component {
137142
});
138143
}
139144

145+
setContentChangeListener() {
146+
this.richtext.registerContentChangeListener(this.onContentChange);
147+
}
148+
149+
onContentChange(value) {
150+
//console.log('onContentChange', value);
151+
this.setState({
152+
content: value,
153+
});
154+
}
155+
140156
renderInsertHTMLTest() {
141157
return (
142158
<Button

example/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Example project
2+
3+
## Install deps
4+
5+
```bash
6+
cd example
7+
yarn install
8+
cd ios
9+
pod install
10+
```
11+
12+
## Running (ios)
13+
14+
```bash
15+
cd example
16+
react-native run-ios
17+
```
18+
19+
## Running (android)
20+
21+
```bash
22+
cd example
23+
react-native run-android
24+
```
25+
26+
## Testing changes
27+
28+
- Install `yalc` globally. See https://www.npmjs.com/package/yalc for more details
29+
30+
```bash
31+
cd example
32+
bash build.sh
33+
```
34+
35+
- In order for the example app to refresh with the latest changes, you need to:
36+
- Run `$ bash build.sh`
37+
- Stop and restart the metro bundler and then run
38+
- `$ react-native run-ios`
39+
- or
40+
- `$ react-native run-android`

example/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cd ..
22
yalc publish
33
cd example/
4-
yalc add react-native-zss-rich-text-editor
4+
yalc link react-native-zss-rich-text-editor

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"react-native": "0.61.5",
1515
"react-native-keyboard-spacer": "^0.4.1",
1616
"react-native-webview": "^8.1.2",
17-
"react-native-zss-rich-text-editor": "file:../"
17+
"react-native-zss-rich-text-editor": "../"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.7.7",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "git",
55
"url": "https://github.com/wix/react-native-zss-rich-text-editor.git"
66
},
7-
"version": "1.4.1",
7+
"version": "1.4.2",
88
"description": "React Native Wrapper for ZSSRichTextEditor",
99
"main": "index.js",
1010
"license": "SEE LICENSE IN LICENSE",

src/assets/editor.html

+24-25
Original file line numberDiff line numberDiff line change
@@ -8426,27 +8426,6 @@
84268426
}
84278427
}
84288428

8429-
zss_editor.replaceMentionWithElement = function(element) {
8430-
if (!element) {
8431-
return;
8432-
}
8433-
8434-
/* zss_editor.log('replaceMentionWithElement()'); */
8435-
var externalMentionSpan = document.getElementById(
8436-
mentionExternalSpanId,
8437-
);
8438-
if (!externalMentionSpan) {
8439-
return;
8440-
}
8441-
8442-
var externalMentionSpanParent = externalMentionSpan.parentNode;
8443-
externalMentionSpanParent.removeChild(externalMentionSpan);
8444-
insertElementAtCursor(element);
8445-
insertElementAtCursor(document.createTextNode('\u00A0'));
8446-
8447-
fireEventDidExitMentionMode();
8448-
};
8449-
84508429
function setupTouchEndEnableEditing(editorId) {
84518430
$('#' + editorId).on('touchend', function(e) {
84528431
zss_editor.enabledEditingItems(e);
@@ -8556,7 +8535,7 @@
85568535
$(document).on('selectionchange', function(e) {
85578536
// add by xukj - fix cannot set bold/italic on android
85588537
if (document.getSelection() != '') {
8559-
zss_editor.log('selectionchange'); // log
8538+
/* zss_editor.log('selectionchange'); */
85608539
zss_editor.calculateEditorHeightWithCaretPosition();
85618540
zss_editor.setScrollPosition();
85628541
zss_editor.enabledEditingItems(e);
@@ -8566,7 +8545,7 @@
85668545

85678546
// Make sure that when we tap anywhere in the document we focus on the editor
85688547
$(window).on('touchmove', function(e) {
8569-
zss_editor.log('touchmove'); // log
8548+
/* zss_editor.log('touchmove'); */
85708549
zss_editor.isDragging = true;
85718550
zss_editor.updateScrollOffset = true;
85728551
zss_editor.setScrollPosition();
@@ -9016,16 +8995,36 @@
90168995
/* zss_editor.log(
90178996
`insertMention('${url}', '${title}', '${className}')`,
90188997
); */
8998+
zss_editor.removeMentionRemains();
90198999
var mentionLinkElement = document.createElement('a');
90209000
mentionLinkElement.className = encodeHtmlEntities(className);
90219001
mentionLinkElement.setAttribute(
90229002
'href',
90239003
encodeHtmlEntities(url),
90249004
);
90259005
mentionLinkElement.textContent = encodeHtmlEntities(title);
9006+
document.execCommand(
9007+
'insertHTML',
9008+
false,
9009+
mentionLinkElement.outerHTML,
9010+
);
90269011
var space = document.createElement('span');
90279012
space.innerHTML = '\xa0';
9028-
zss_editor.replaceMentionWithElement(mentionLinkElement);
9013+
document.execCommand('insertHTML', false, space.outerHTML);
9014+
fireEventDidExitMentionMode();
9015+
};
9016+
9017+
zss_editor.removeMentionRemains = function() {
9018+
/* zss_editor.log('removeMentionRemains()'); */
9019+
var externalMentionSpan = document.getElementById(
9020+
mentionExternalSpanId,
9021+
);
9022+
if (!externalMentionSpan) {
9023+
return;
9024+
}
9025+
9026+
var externalMentionSpanParent = externalMentionSpan.parentNode;
9027+
externalMentionSpanParent.removeChild(externalMentionSpan);
90299028
};
90309029

90319030
function removeNode(previous) {
@@ -9326,7 +9325,7 @@
93269325
// Use jQuery to figure out those that are not supported
93279326
if (typeof e != 'undefined') {
93289327
// The target element
9329-
var s = zss_editor.getSelectedNode();
9328+
var s = zss_editor.getSelectedNode() || e.target;
93309329
var t = $(s);
93319330
var nodeName = e.target.nodeName.toLowerCase();
93329331

0 commit comments

Comments
 (0)