TF-2591 Run js script on paste with HtmlEditor
This commit is contained in:
@@ -7,6 +7,15 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:universal_html/html.dart' as html;
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
|
||||||
class HtmlUtils {
|
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}) {
|
static String customCssStyleHtmlEditor({TextDirection direction = TextDirection.ltr}) {
|
||||||
if (PlatformInfo.isWeb) {
|
if (PlatformInfo.isWeb) {
|
||||||
return '''
|
return '''
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:core/utils/html/html_utils.dart';
|
import 'package:core/utils/html/html_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -113,6 +114,12 @@ class _WebEditorState extends State<WebEditorWidget> {
|
|||||||
initialText: widget.content,
|
initialText: widget.content,
|
||||||
customBodyCssStyle: HtmlUtils.customCssStyleHtmlEditor(direction: widget.direction),
|
customBodyCssStyle: HtmlUtils.customCssStyleHtmlEditor(direction: widget.direction),
|
||||||
spellCheck: true,
|
spellCheck: true,
|
||||||
|
webInitialScripts: UnmodifiableListView([
|
||||||
|
WebScript(
|
||||||
|
name: HtmlUtils.lineHeight100Percent.name,
|
||||||
|
script: HtmlUtils.lineHeight100Percent.script,
|
||||||
|
)
|
||||||
|
])
|
||||||
),
|
),
|
||||||
htmlToolbarOptions: const HtmlToolbarOptions(
|
htmlToolbarOptions: const HtmlToolbarOptions(
|
||||||
toolbarType: ToolbarType.hide,
|
toolbarType: ToolbarType.hide,
|
||||||
@@ -135,6 +142,9 @@ class _WebEditorState extends State<WebEditorWidget> {
|
|||||||
onImageUpload: widget.onImageUploadSuccessAction,
|
onImageUpload: widget.onImageUploadSuccessAction,
|
||||||
onImageUploadError: widget.onImageUploadFailureAction,
|
onImageUploadError: widget.onImageUploadFailureAction,
|
||||||
onTextFontSizeChanged: widget.onEditorTextSizeChanged,
|
onTextFontSizeChanged: widget.onEditorTextSizeChanged,
|
||||||
|
onPaste: () => _editorController.evaluateJavascriptWeb(
|
||||||
|
HtmlUtils.lineHeight100Percent.name
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user