TF-2591 Run js script on paste with HtmlEditor

This commit is contained in:
DatDang
2024-02-29 11:14:57 +07:00
committed by Dat H. Pham
parent 98894b4245
commit 80a32559d9
2 changed files with 19 additions and 0 deletions
+9
View File
@@ -7,6 +7,15 @@ import 'package:flutter/material.dart';
import 'package:universal_html/html.dart' as html;
class HtmlUtils {
static const lineHeight100Percent = (
script: '''
document.querySelectorAll("*")
.forEach((element) => {
if (element.style.lineHeight !== "normal")
element.style.lineHeight = "100%";
});''',
name: 'lineHeight100Percent');
static String customCssStyleHtmlEditor({TextDirection direction = TextDirection.ltr}) {
if (PlatformInfo.isWeb) {
return '''
@@ -1,4 +1,5 @@
import 'package:collection/collection.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/html/html_utils.dart';
import 'package:flutter/material.dart';
@@ -113,6 +114,12 @@ class _WebEditorState extends State<WebEditorWidget> {
initialText: widget.content,
customBodyCssStyle: HtmlUtils.customCssStyleHtmlEditor(direction: widget.direction),
spellCheck: true,
webInitialScripts: UnmodifiableListView([
WebScript(
name: HtmlUtils.lineHeight100Percent.name,
script: HtmlUtils.lineHeight100Percent.script,
)
])
),
htmlToolbarOptions: const HtmlToolbarOptions(
toolbarType: ToolbarType.hide,
@@ -135,6 +142,9 @@ class _WebEditorState extends State<WebEditorWidget> {
onImageUpload: widget.onImageUploadSuccessAction,
onImageUploadError: widget.onImageUploadFailureAction,
onTextFontSizeChanged: widget.onEditorTextSizeChanged,
onPaste: () => _editorController.evaluateJavascriptWeb(
HtmlUtils.lineHeight100Percent.name
),
),
);
}