From 70d2f93b170534eb964a0cfc56703bcf47ed2b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marker=20dao=20=C2=AE?= Date: Fri, 15 Nov 2024 12:13:32 +0100 Subject: [PATCH] feat(htmleditor): Add react demo && Add deps in script module for vue --- .../HtmlEditor/MarkdownSupport/React/App.tsx | 97 ++++++++----------- .../HtmlEditor/MarkdownSupport/React/data.ts | 5 +- .../MarkdownSupport/React/index.html | 18 ++++ .../MarkdownSupport/React/styles.css | 6 +- .../HtmlEditor/MarkdownSupport/Vue/App.vue | 19 ++-- .../HtmlEditor/MarkdownSupport/Vue/index.html | 14 +++ 6 files changed, 88 insertions(+), 71 deletions(-) diff --git a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/App.tsx b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/App.tsx index ffac78dc8f29..942f6e195d3f 100644 --- a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/App.tsx +++ b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/App.tsx @@ -1,95 +1,80 @@ import React, { useCallback, useState } from 'react'; import HtmlEditor, { Toolbar, Item } from 'devextreme-react/html-editor'; -import ButtonGroup, { Item as ButtonItem } from 'devextreme-react/button-group'; -import prettier from 'prettier/standalone'; -import parserHtml from 'prettier/parser-html'; import { markup } from './data.ts'; -const sizeValues = ['8pt', '10pt', '12pt', '14pt', '18pt', '24pt', '36pt']; -const fontValues = ['Arial', 'Courier New', 'Georgia', 'Impact', 'Lucida Console', 'Tahoma', 'Times New Roman', 'Verdana']; -const defaultSelectedItemKeys = ['Html']; -const fontSizeOptions = { +const headerValues = [false, 1, 2, 3, 4, 5]; +const headerOptions = { inputAttr: { - 'aria-label': 'Font size', + 'aria-label': 'Font family', }, }; -const fontFamilyOptions = { - inputAttr: { - 'aria-label': 'Font family', +const converter = { + toHtml(value) { + // @ts-expect-error + const result = unified() + // @ts-expect-error + .use(remarkParse) + // @ts-expect-error + // eslint-disable-next-line spellcheck/spell-checker + .use(remarkRehype) + // @ts-expect-error + // eslint-disable-next-line spellcheck/spell-checker + .use(rehypeStringify) + .processSync(value) + .toString(); + + return result; + }, + fromHtml(value) { + // @ts-expect-error + const result = unified() + // @ts-expect-error + // eslint-disable-next-line spellcheck/spell-checker + .use(rehypeParse) + // eslint-disable-next-line spellcheck/spell-checker + // @ts-expect-error + .use(rehypeRemark) + // @ts-expect-error + .use(remarkStringify) + .processSync(value) + .toString(); + + return result; }, }; export default function App() { const [valueContent, setValueContent] = useState(markup); - const [editorValueType, setEditorValueType] = useState<'html' | 'markdown'>('html'); const valueChanged = useCallback((e: { value?: string; }) => { setValueContent(e.value); }, [setValueContent]); - const valueTypeChanged = useCallback((e: { addedItems: { text: string; }[]; }) => { - const newEditorValue = e.addedItems[0].text.toLowerCase() as 'html' | 'markdown'; - setEditorValueType(newEditorValue); - }, [setEditorValueType]); - - const prettierFormat = useCallback((text) => { - if (editorValueType === 'html') { - return prettier.format(text, { - parser: 'html', - plugins: [parserHtml], - }); - } - return text; - }, [editorValueType]); - return (
- - - - - - - - - - - - +
- - - - +
+ Contents of the value option +
- {prettierFormat(valueContent)} + {valueContent}
diff --git a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/data.ts b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/data.ts index f13c82e36465..d282c8183d21 100644 --- a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/data.ts +++ b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/data.ts @@ -1 +1,4 @@ -export const markup = '

HtmlEditor Formatted Text Editor (HTML Editor)


DevExtreme JavaScript HTML Editor is a client-side WYSIWYG text editor that allows its users to format textual and visual content and store it as HTML or Markdown.

'; +export const markup = `## Formatted Text Editor (HTML Editor) + +DevExtreme JavaScript HTML Editor is a client-side WYSIWYG text editor that allows its users to format textual and visual content and store it as HTML. +`; diff --git a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/index.html b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/index.html index ee451f8288ff..411b034d6e45 100644 --- a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/index.html +++ b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/index.html @@ -8,6 +8,24 @@ + + diff --git a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/styles.css b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/styles.css index f87e2bc9a025..c31e37305a8b 100644 --- a/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/styles.css +++ b/apps/demos/Demos/HtmlEditor/MarkdownSupport/React/styles.css @@ -1,6 +1,6 @@ -.dx-htmleditor-content img { - vertical-align: middle; - padding-right: 10px; +.value-title { + font-size: 18px; + font-weight: 500; } .value-content { diff --git a/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/App.vue b/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/App.vue index a477f40d0abd..40ac2bb28085 100644 --- a/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/App.vue +++ b/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/App.vue @@ -40,17 +40,6 @@ import { DxToolbar, DxItem, } from 'devextreme-vue/html-editor'; -import { unified } from 'unified'; -import remarkParse from 'remark-parse'; -// eslint-disable-next-line spellcheck/spell-checker -import remarkRehype from 'remark-rehype'; -// eslint-disable-next-line spellcheck/spell-checker -import rehypeStringify from 'rehype-stringify'; -// eslint-disable-next-line spellcheck/spell-checker -import rehypeParse from 'rehype-parse'; -// eslint-disable-next-line spellcheck/spell-checker -import rehypeRemark from 'rehype-remark'; -import remarkStringify from 'remark-stringify'; import { markup } from './data.ts'; const valueContent = ref(markup); @@ -58,10 +47,14 @@ const headerValues = [false, 1, 2, 3, 4, 5]; const headerOptions = { inputAttr: { 'aria-label': 'Font family' } }; const converter = { toHtml(value) { + // @ts-expect-error const result = unified() + // @ts-expect-error .use(remarkParse) + // @ts-expect-error // eslint-disable-next-line spellcheck/spell-checker .use(remarkRehype) + // @ts-expect-error // eslint-disable-next-line spellcheck/spell-checker .use(rehypeStringify) .processSync(value) @@ -70,11 +63,15 @@ const converter = { return result; }, fromHtml(value) { + // @ts-expect-error const result = unified() + // @ts-expect-error // eslint-disable-next-line spellcheck/spell-checker .use(rehypeParse) // eslint-disable-next-line spellcheck/spell-checker + // @ts-expect-error .use(rehypeRemark) + // @ts-expect-error .use(remarkStringify) .processSync(value) .toString(); diff --git a/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/index.html b/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/index.html index c3ac7d2ffbef..d12401eac205 100644 --- a/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/index.html +++ b/apps/demos/Demos/HtmlEditor/MarkdownSupport/Vue/index.html @@ -10,8 +10,22 @@