Skip to content

Commit

Permalink
Support update body direction on web
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Jun 15, 2023
1 parent e056608 commit 11343c5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/html_editor_controller_unsupported.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,7 @@ class HtmlEditorController {

/// Remove signature from compose email
void removeSignature() {}

/// Update body direction on web
void updateBodyDirection(String direction) {}
}
5 changes: 5 additions & 0 deletions lib/src/html_editor_controller_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,9 @@ class HtmlEditorController extends unsupported.HtmlEditorController {
void removeSignature() {
_evaluateJavascriptWeb(data: {'type': 'toIframe: removeSignature'});
}

@override
void updateBodyDirection(String direction) {
_evaluateJavascriptWeb(data: {'type': 'toIframe: updateBodyDirection', 'direction': direction});
}
}
7 changes: 7 additions & 0 deletions lib/src/widgets/html_editor_widget_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ class _HtmlEditorWidgetWebState extends State<HtmlEditorWidget> {
const contentsEditor = document.getElementsByClassName('note-editable')[0].innerHTML;
window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onChangeContent", "contents": contentsEditor}), "*");
}
if (data["type"].includes("updateBodyDirection")) {
${JavascriptUtils.jsHandleUpdateBodyDirection}
const contentsEditor = document.getElementsByClassName('note-editable')[0].innerHTML;
window.parent.postMessage(JSON.stringify({"view": "$createdViewId", "type": "toDart: onChangeContent", "contents": contentsEditor}), "*");
}
$userScripts
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/javascript_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ class JavascriptUtils {
nodeSignature[0].remove();
}
''';

static const String jsHandleUpdateBodyDirection = '''
const nodeEditor = document.getElementsByClassName('note-editable')[0];
const currentDirection = data['direction'];
console.log('currentDirection: ' + currentDirection);
nodeEditor.style.direction = currentDirection.toString();
''';
}

0 comments on commit 11343c5

Please sign in to comment.