Skip to content

Commit

Permalink
Merge pull request #8 from Meruem5/imnapo-master
Browse files Browse the repository at this point in the history
Imnapo master
  • Loading branch information
Meruem5 authored Jul 7, 2023
2 parents a74a2c6 + 39c05f2 commit 8eb526e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,18 @@ _editor.current.setText('Hello\n');

---

### `setPlaceholder(text: string)`

Overwrites placeholder with given text.

#### Example:

```
_editor.current.setPlaceholder('Hello World');
```

---

### `updateContents(delta: any)`

Applies Delta to editor contents.
Expand Down
32 changes: 29 additions & 3 deletions src/constants/editor/editor_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,37 @@ export const editor_js = `
quill.insertText(index, text, formats);
}
var setContents = function (delta) {
quill.setContents(delta);
var setContents = function (key, delta) {
try {
var setContentsData = quill.setContents(delta);
var setContentsDataJson = JSON.stringify({
type: 'set-contents',
key: key,
data: setContentsData });
sendMessage(setContentsDataJson);
} catch (error) {
var errorJson = JSON.stringify({
type: 'set-contents-error',
key: key,
data: { message: error.message, stack: error.stack } });
sendMessage(errorJson);
var setContentsDataJson = JSON.stringify({
type: 'set-contents',
key: key,
data: {} });
sendMessage(setContentsDataJson);
}
}
var setText = function (text) {
quill.setText(text);
}
var setPlaceholder = function (text) {
quill.root.dataset.placeholder = text;
}
var updateContents = function (delta) {
quill.updateContents(delta);
}
Expand Down Expand Up @@ -241,11 +264,14 @@ export const editor_js = `
insertText(msg.index, msg.text, msg.formats);
break;
case 'setContents':
setContents(msg.delta);
setContents(msg.key, msg.delta);
break;
case 'setText':
setText(msg.text);
break;
case 'setPlaceholder':
setPlaceholder(msg.text);
break;
case 'updateContents':
updateContents(msg.delta);
break;
Expand Down
9 changes: 7 additions & 2 deletions src/editor/quill-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export default class QuillEditor extends React.Component<
break;
case 'has-focus':
case 'get-contents':
case 'set-contents':
case 'get-text':
case 'get-length':
case 'get-bounds':
Expand Down Expand Up @@ -325,14 +326,18 @@ export default class QuillEditor extends React.Component<
this.post({ command: 'insertText', index, text, formats });
};

setContents = (delta: any) => {
this.post({ command: 'setContents', delta });
setContents = (delta: any): Promise<any> => {
return this.postAwait<any>({ command: 'setContents', delta });
};

setText = (text: string) => {
this.post({ command: 'setText', text });
};

setPlaceholder = (text: string) => {
this.post({ command: 'setPlaceholder', text });
};

updateContents = (delta: any) => {
this.post({ command: 'updateContents', delta });
};
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import QuillEditor from './editor/quill-editor';
import QuillEditor, { EditorProps } from './editor/quill-editor';
import { QuillToolbar } from './toolbar/quill-toolbar';
import type {
EditorEventHandler,
Expand All @@ -12,6 +12,7 @@ import type {
export default QuillEditor;
export { QuillToolbar };
export type {
EditorProps,
EditorEventHandler,
SelectionChangeData,
EditorChangeData,
Expand Down
2 changes: 1 addition & 1 deletion src/toolbar/components/selection-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const SelectionBar: React.FC<Props> = ({}) => {
</ScrollView>
<TouchableOpacity onPress={() => hide()}>
<View style={closeViewStyle}>
<Text style={closeTextStyle}>X</Text>
<Text style={closeTextStyle}>×</Text>
</View>
</TouchableOpacity>
</View>
Expand Down

0 comments on commit 8eb526e

Please sign in to comment.