From f95b40bb5b3165083ebfc579e1956312cb91e750 Mon Sep 17 00:00:00 2001 From: jideguru Date: Sat, 29 May 2021 20:38:29 +0100 Subject: [PATCH] chore: added features list to readme --- LICENSE | 2 +- README.md | 51 +++++++++++++++++---- lib/src/models/enum.dart | 44 ++++++++++++++++++ lib/src/utils/command_state.dart | 6 +++ lib/src/utils/javascript_executor_base.dart | 23 +++++++++- pubspec.yaml | 2 +- 6 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 lib/src/models/enum.dart create mode 100644 lib/src/utils/command_state.dart diff --git a/LICENSE b/LICENSE index 1c5919c..17ad059 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2021 Festus Olusegun +Copyright 2021 JideGuru Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index a63ae8b..fd6e0f8 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,45 @@ -# rich_editor +# ✨ rich_editor +[![pub package](https://img.shields.io/pub/v/badge.svg)](https://pub.dartlang.org/packages/rich_editor) +[![pub points](https://badges.bar/rich_editor/pub%20points)](https://pub.dev/packages/sentry/rich_editor) -A new Flutter package. +WYSIWYG editor for Android and JavaFX with a rich set of supported formatting options. -## Getting Started +Based on https://github.com/dankito/RichTextEditor, but but for Flutter. -This project is a starting point for a Dart -[package](https://flutter.dev/developing-packages/), -a library module containing code that can be shared easily across -multiple Flutter or Dart projects. +## ✨ Features +- [x] Bold, Italic, Underline, Strike through, Subscript, Superscript +- [x] Heading 1 - 6, Text body, Preformatted, Block quote +- [] Font (reads all system fonts) +- [x] Font Size +- [x] Text Color +- [x] Text Background Color +- [x] Highlight text +- [x] Justify Left, Center, Right, Blockquote +- [x] Indent, Outdent +- [x] Undo, Redo +- [x] Unordered List (Bullets) +- [x] Ordered List (Numbers) +- [x] Insert local or remote Image +- [x] Insert Link +- [x] Insert Checkbox +- [] Search -For help getting started with Flutter, view our -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. +## 📸 Screenshots + + + +## License + + Copyright 2021 JideGuru + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/lib/src/models/enum.dart b/lib/src/models/enum.dart new file mode 100644 index 0000000..5ba1a95 --- /dev/null +++ b/lib/src/models/enum.dart @@ -0,0 +1,44 @@ +enum CommandName { + UNDO, + REDO, + FORECOLOR, + BACKCOLOR, + FONTNAME, + FONTSIZE, + BOLD, + ITALIC, + UNDERLINE, + SUBSCRIPT, + SUPERSCRIPT, + STRIKETHROUGH, + FORMATBLOCK, // passes value for below format + H1, + H2, + H3, + H4, + H5, + H6, + P, + PRE, + BR, // not settable (at least i don't know how) + BLOCKQUOTE, + REMOVEFORMAT, + JUSTIFYCENTER, + JUSTIFYFULL, + JUSTIFYLEFT, + JUSTIFYRIGHT, + INDENT, + OUTDENT, + INSERTUNORDEREDLIST, + INSERTORDEREDLIST, + INSERTHORIZONTALRULE, + INSERTHTML, // determines if the three command below are executable + INSERTLINK, // pseudo commands, there are no corresponding values for execCommand() + INSERTIMAGE, + INSERTCHECKBOX, +// pseudo commands for toggling grouped command views + ENTER_VIEWING_MODE, + EXPANDING_SEARCH_VIEWING, + TOGGLE_GROUPED_TEXT_STYLES_COMMANDS_VIEW, + TOGGLE_GROUPED_INSERT_COMMANDS_COMMANDS_VIEW +} diff --git a/lib/src/utils/command_state.dart b/lib/src/utils/command_state.dart new file mode 100644 index 0000000..e9aab6b --- /dev/null +++ b/lib/src/utils/command_state.dart @@ -0,0 +1,6 @@ +class CommandState { + bool executable = false; + var value = ""; + + CommandState(this.executable, this.value); +} diff --git a/lib/src/utils/javascript_executor_base.dart b/lib/src/utils/javascript_executor_base.dart index da6dd94..17e6235 100644 --- a/lib/src/utils/javascript_executor_base.dart +++ b/lib/src/utils/javascript_executor_base.dart @@ -1,10 +1,22 @@ import 'package:flutter/material.dart'; import 'package:rich_editor/src/extensions/extensions.dart'; +import 'package:rich_editor/src/models/enum.dart'; import 'package:webview_flutter/webview_flutter.dart'; +import 'command_state.dart'; + class JavascriptExecutorBase { WebViewController? _controller; + String defaultHtml = "

\u200B

"; + + String editorStateChangedCallbackScheme = "editor-state-changed-callback://"; + + String defaultEncoding = "UTF-8"; + + String? htmlField = ""; + Map commandStates = {}; + init(WebViewController controller) { _controller = controller; } @@ -13,12 +25,17 @@ class JavascriptExecutorBase { return await _controller!.evaluateJavascript('editor.$command'); } + String getCachedHtml() { + return htmlField!; + } + setHtml(String html) async { String? baseUrl; await executeJavascript("setHtml('" + encodeHtml(html) + "', '$baseUrl');"); + htmlField = html; } - getHtml() async { + getCurrentHtml() async { String? html = await executeJavascript('getEncodedHtml()'); String? decodedHtml = Uri.decodeFull(html!); if (decodedHtml.startsWith('"') && decodedHtml.endsWith('"')) { @@ -27,6 +44,10 @@ class JavascriptExecutorBase { return decodedHtml; } + bool isDefaultRichTextEditorHtml(String html) { + return defaultHtml == html; + } + // Text commands undo() async { await executeJavascript("undo()"); diff --git a/pubspec.yaml b/pubspec.yaml index 1d9cead..5ca06b2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: rich_editor -description: A new Flutter package. +description: WYSIWYG editor for Flutter with a rich set of supported formatting options. version: 0.0.1 homepage: https://github.com/JideGuru/rich_editor