From 12a5244c8f8f86d0de6659ca1b5751e807ca0704 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Tue, 2 Dec 2025 23:25:13 +0000 Subject: [PATCH 01/29] Amend composer for Symfony 6 and 7, with PHP 8.1+ --- composer.json | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 7994137..07cb304 100644 --- a/composer.json +++ b/composer.json @@ -14,21 +14,21 @@ } ], "require": { - "php": "^7.1", + "php": "^8.1", "ext-zip": "*", - "symfony/asset": "^3.4 || ^4.0", - "symfony/config": "^3.4 || ^4.0", - "symfony/dependency-injection": "^3.4 || ^4.0", - "symfony/expression-language": "^3.4 || ^4.0", - "symfony/form": "^3.4 || ^4.0", - "symfony/framework-bundle": "^3.4 || ^4.0", - "symfony/http-foundation": "^3.4 || ^4.0", - "symfony/http-kernel": "^3.4 || ^4.0", - "symfony/options-resolver": "^3.4 || ^4.0", - "symfony/property-access": "^3.4 || ^4.0", - "symfony/routing": "^3.4 || ^4.0", - "symfony/twig-bundle": "^3.4 || ^4.0", - "twig/twig": "^2.0" + "symfony/asset": "^6.4 || ^7.4", + "symfony/config": "^6.4 || ^7.4", + "symfony/dependency-injection": "^6.4 || ^7.4", + "symfony/expression-language": "^6.4 || ^7.4", + "symfony/form": "^6.4 || ^7.4", + "symfony/framework-bundle": "^6.4 || ^7.4", + "symfony/http-foundation": "^6.4 || ^7.4", + "symfony/http-kernel": "^6.4 || ^7.4", + "symfony/options-resolver": "^6.4 || ^7.4", + "symfony/property-access": "^6.4 || ^7.4", + "symfony/routing": "^6.4 || ^7.4", + "symfony/twig-bundle": "^6.4 || ^7.4", + "twig/twig": "^2.12|^3.0" }, "autoload": { "psr-4": { From 2a38a6064594eabfea8c0eb91709122f6ec96b0c Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 3 Dec 2025 01:53:33 +0000 Subject: [PATCH 02/29] Fix type for twig template filename --- src/DependencyInjection/Compile/TwigFormThemeCompilePass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/Compile/TwigFormThemeCompilePass.php b/src/DependencyInjection/Compile/TwigFormThemeCompilePass.php index 98521e2..84e2796 100644 --- a/src/DependencyInjection/Compile/TwigFormThemeCompilePass.php +++ b/src/DependencyInjection/Compile/TwigFormThemeCompilePass.php @@ -14,7 +14,7 @@ public function process(ContainerBuilder $container) { //add tuieditor_widget.html.twig to form_theme $form_theme_old = $container->getParameter('twig.form.resources'); - $form_theme = array_merge($form_theme_old, ['@TeebbTuiEditor/Form/tuieditor_widget.html.Twig']); + $form_theme = array_merge($form_theme_old, ['@TeebbTuiEditor/Form/tuieditor_widget.html.twig']); $container->getDefinition('twig.form.engine')->replaceArgument(0, $form_theme); } From baf887ad822ade57b94f4bce08fa6df65584b116 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 3 Dec 2025 01:56:26 +0000 Subject: [PATCH 03/29] Fix command for Symfony 7 --- src/Command/TuiEditorDownloadCommand.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Command/TuiEditorDownloadCommand.php b/src/Command/TuiEditorDownloadCommand.php index 8d53d1e..9b0a227 100644 --- a/src/Command/TuiEditorDownloadCommand.php +++ b/src/Command/TuiEditorDownloadCommand.php @@ -13,6 +13,10 @@ use Symfony\Component\Console\Question\ChoiceQuestion; use Teebb\TuiEditorBundle\Installer\TuiEditorInstaller; +#[AsCommand( + name: TuiEditorDownloadCommand::defaultName, + description: 'Download the lastest tui.editor with all the required libraries.', +)] class TuiEditorDownloadCommand extends Command { protected static $defaultName = 'tuieditor:install'; @@ -26,7 +30,7 @@ public function __construct(TuiEditorInstaller $installer) $this->installer = $installer; } - protected function configure() + protected function configure(): void { $this ->setDescription('Download the lastest tui.editor with all the required libraries.') @@ -54,7 +58,7 @@ protected function configure() ); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->title($output); @@ -65,8 +69,10 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($success) { $this->success('tui.editor has been successfully installed...', $output); + return Command::SUCCESS; } else { $this->info('tui.editor installation has been skipped...', $output); + return Command::INVALID; } } From 671f5ea751b585730f1ce296b79cb7b146dde469 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 3 Dec 2025 16:59:04 +0000 Subject: [PATCH 04/29] Redo asset loader --- src/DependencyInjection/Configuration.php | 112 +++++++++++----------- src/Renderer/TuiEditorRenderer.php | 112 +++++++++++----------- 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 65fa851..517cb9a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -25,11 +25,11 @@ public function getConfigTreeBuilder(): TreeBuilder ->booleanNode('enable')->defaultTrue()->end() ->booleanNode('jquery')->defaultTrue()->info("If you want use jquery.js set true.")->end() ->scalarNode('base_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/')->end() - ->scalarNode('editor_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-Editor.min.js')->end() - ->scalarNode('viewer_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-Viewer.min.js')->end() - ->scalarNode('editor_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor.min.css')->end() - ->scalarNode('editor_contents_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-contents.min.css')->end() - ->scalarNode('jquery_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/jquery/dist/jquery.min.js')->end() + ->scalarNode('editor_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor.js')->end() + ->scalarNode('viewer_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor-viewer.js')->end() + ->scalarNode('editor_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor.css')->end() + ->scalarNode('editor_contents_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor-viewer.css')->end() + ->scalarNode('jquery_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/jquery/dist/jquery.min.js')->end() ->scalarNode('default_config')->defaultValue(null)->end() ->append($this->createExtensions()) ->append($this->createDependencies()) @@ -44,60 +44,41 @@ private function createExtensions() return $this->createNode('extensions') ->addDefaultsIfNotSet() ->children() - ->arrayNode('scrollSync') + ->arrayNode('editor_plugin_color_syntax') ->addDefaultsIfNotSet() ->children() - ->scalarNode('extScrollSync_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-extScrollSync.min.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() - - ->arrayNode('colorSyntax') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('tui_color_picker_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/tui-color-picker/dist/tui-color-picker.min.js')->end() - ->scalarNode('extColorSyntax_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-extColorSyntax.min.js')->end() - ->scalarNode('tui_color_picker_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/tui-color-picker/dist/tui-color-picker.min.css')->end() + ->scalarNode('tui_code_color_syntax_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.js')->end() + ->scalarNode('tui_code_color_syntax_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.css')->end() ->end() ->end() - - ->arrayNode('uml') + ->arrayNode('editor_plugin_chart') ->addDefaultsIfNotSet() ->children() - ->scalarNode('plantuml_encoder_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/plantuml-encoder/dist/plantuml-encoder.min.js')->end() - ->scalarNode('extUML_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-extUML.min.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() + ->scalarNode('tui_chart_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/dist/toastui-chart.min.js')->end() + ->scalarNode('tui_chart_plugin_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-chart/dist/toastui-editor-plugin-chart.js')->end() + ->scalarNode('tui_chart_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/dist/toastui-chart.min.css')->end() ->end() ->end() - - ->arrayNode('chart') + ->arrayNode('editor_plugin_code_syntax_highlight') ->addDefaultsIfNotSet() ->children() - ->scalarNode('raphael_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/raphael/raphael.min.js')->end() - ->scalarNode('tui_chart_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/tui-chart/dist/tui-chart.min.js')->end() - ->scalarNode('extChart_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-extChart.min.js')->end() - ->scalarNode('tui_chart_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/tui-chart/dist/tui-chart.min.css')->end() + ->scalarNode('tui_code_syntax_highlight_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight.js')->end() + ->scalarNode('tui_code_syntax_highlight_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight.css')->end() ->end() ->end() - - ->arrayNode('table') + ->arrayNode('editor_plugin_table_merged_cell') ->addDefaultsIfNotSet() ->children() - ->scalarNode('extTable_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/tui-editor/dist/tui-editor-extTable.min.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() + ->scalarNode('tui_table_merged_cell_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-table-merged-cell/dist/toastui-editor-plugin-table-merged-cell.js')->end() + ->scalarNode('tui_table_merged_cell_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-table-merged-cell/dist/toastui-editor-plugin-table-merged-cell.css')->end() ->end() ->end() - - ->arrayNode('mark') + ->arrayNode('editor_plugin_uml') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue(null)->end() + ->scalarNode('tui_uml_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-uml/dist/toastui-editor-plugin-uml.js')->end() ->end() ->end() - - - ->end(); } @@ -106,47 +87,68 @@ private function createDependencies() return $this->createNode('dependencies') ->addDefaultsIfNotSet() ->children() - ->arrayNode('markdown-it') + ->arrayNode('dompurify') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/markdown-it/dist/markdown-it.min.js')->end() + ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/dompurify/dist/purify.min.js')->end() + ->scalarNode('module_js_path')->defaultValue(null)->end() ->scalarNode('css_path')->defaultValue(null)->end() ->end() ->end() - ->arrayNode('tui-code-snippet') + ->arrayNode('orderedmap') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/tui-code-snippet/dist/tui-code-snippet.min.js')->end() + ->scalarNode('js_path')->defaultValue(null)->end() + ->scalarNode('module_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/orderedmap/dist/index.js')->end() ->scalarNode('css_path')->defaultValue(null)->end() ->end() ->end() - ->arrayNode('codemirror') + ->arrayNode('plantuml_encoder') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/codemirror/lib/codemirror.js')->end() - ->scalarNode('css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/codemirror/lib/codemirror.css')->end() + ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/plantuml-encoder/dist/plantuml-encoder.min.js')->end() + ->scalarNode('module_js_path')->defaultValue(null)->end() + ->scalarNode('css_path')->defaultValue(null)->end() ->end() ->end() - ->arrayNode('highlight') + ->arrayNode('plantuml_decoder') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/highlight/highlight.pack.js')->end() - ->scalarNode('css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/highlight/styles/github.css')->end() + ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/plantuml-encoder/dist/plantuml-decoder.min.js')->end() + ->scalarNode('module_js_path')->defaultValue(null)->end() + ->scalarNode('css_path')->defaultValue(null)->end() ->end() ->end() - ->arrayNode('squire-rte') + ->arrayNode('prismjs') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/squire-rte/build/squire-raw.js')->end() + ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/prismjs/prism.js')->end() + ->scalarNode('module_js_path')->defaultValue(null)->end() ->scalarNode('css_path')->defaultValue(null)->end() ->end() ->end() - - ->arrayNode('to-mark') + ->arrayNode('prosemirror_bundle') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('js_path')->defaultValue(null)->end() + ->scalarNode('module_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/prosemirror-bundle.js')->end() + ->scalarNode('css_path')->defaultValue(null)->end() + ->end() + ->end() + ->arrayNode('tui_color_picker') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/tui-color-picker/dist/tui-color-picker.min.js')->end() + ->scalarNode('module_js_path')->defaultValue(null)->end() + ->scalarNode('css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/tui-color-picker/dist/tui-color-picker.min.css')->end() + ->end() + ->end() + ->arrayNode('w3c-keyname') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/to-mark/dist/to-mark.min.js')->end() + ->scalarNode('js_path')->defaultValue(null)->end() + ->scalarNode('module_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/w3c-keyname/index.js')->end() ->scalarNode('css_path')->defaultValue(null)->end() ->end() ->end() @@ -186,4 +188,4 @@ private function createNode(string $name): ArrayNodeDefinition return $node; } -} +} \ No newline at end of file diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 86dd921..11b89b0 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -113,57 +113,84 @@ public function renderDependencies(array $dependencies = null): string $dependenciesCssHtml = ""; if ($this->options['jquery']) { - $dependenciesJsHtml .= sprintf('', $this->fixPath($this->options['jquery_path'])); + $dependenciesJsHtml .= $this->renderScriptBlock($this->options['jquery_path']); } foreach ($dependencies as $dependency) { + if ($dependency['module_js_path'] !== null) { + $dependenciesJsHtml .= $this->renderScriptModuleBlock($dependency['module_js_path']); + } if ($dependency['js_path'] !== null) { - $dependenciesJsHtml .= sprintf('', $this->fixPath($dependency['js_path'])); + $dependenciesJsHtml .= $this->renderScriptBlock($dependency['js_path']); } if ($dependency['css_path'] !== null) { - $dependenciesCssHtml .= sprintf('', $this->fixPath($dependency['css_path'])); + $dependenciesCssHtml .= $this->renderStyleBlock($dependency['css_path']); } } return $dependenciesJsHtml . $dependenciesCssHtml; } - public function renderViewer(string $id, string $content, string $viewerJsPath = null): string + public function renderScriptBlock(string $path): string { + return sprintf('', $this->fixPath($path)); + } + + public function renderScriptModuleBlock(string $path): string + { + return sprintf('', $this->fixPath($path)); + } - if (null === $viewerJsPath) { - $viewerJsPath = $this->options['viewer_js_path']; - } - $extensions = $this->options['configs'][$this->options['default_config']]['exts']; - $viewerJsCode = sprintf('', $this->fixPath($viewerJsPath)); - $viewerCssCode = sprintf('', $this->fixPath($this->options['editor_contents_css_path'])); + public function renderStyleBlock(string $path): string + { + return sprintf('', $this->fixPath($path)); + } + public function renderExtensions($extensions): string + { $extsJsHtml = ""; $extsCssHtml = ""; if (null !== $extensions) { foreach ($extensions as $extKey => $extValue) { switch ($extValue) { - case 'colorSyntax': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['colorSyntax']['tui_color_picker_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['colorSyntax']['extColorSyntax_js_path'])); - $extsCssHtml .= sprintf('', $this->fixPath($this->options['extensions']['colorSyntax']['tui_color_picker_css_path'])); + case 'editor_plugin_color_syntax': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_color_syntax']['tui_code_color_syntax_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_color_syntax']['tui_code_color_syntax_css_path']); break; - case 'uml': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['uml']['plantuml_encoder_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['uml']['extUML_js_path'])); + case 'editor_plugin_chart': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_chart']['tui_chart_js_path']); + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_chart']['tui_chart_plugin_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_chart']['tui_chart_css_path']); break; - case 'chart': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['raphael_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['tui_chart_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['extChart_js_path'])); - $extsCssHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['tui_chart_css_path'])); + case 'editor_plugin_code_syntax_highlight': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_code_syntax_highlight']['tui_code_syntax_highlight_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_code_syntax_highlight']['tui_code_syntax_highlight_css_path']); break; - case 'table': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['table']['extTable_js_path'])); + case 'editor_plugin_table_merged_cell': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_table_merged_cell']['tui_table_merged_cell_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_table_merged_cell']['tui_table_merged_cell_css_path']); + break; + case 'editor_plugin_uml': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_uml']['tui_uml_js_path']); break; } } } + return $extsJsHtml.$extsCssHtml; + } + + public function renderViewer(string $id, string $content, string $viewerJsPath = null): string + { + + if (null === $viewerJsPath) { + $viewerJsPath = $this->options['viewer_js_path']; + } + $extensions = $this->options['configs'][$this->options['default_config']]['exts']; + + $viewerJsCode = $this->renderScriptBlock($viewerJsPath); + $viewerCssCode = $this->renderStyleBlock($this->options['editor_contents_css_path']); + + $extsHtml = $this->renderExtensions($extensions); $viewerJsScript = sprintf( '', $this->fixPath($this->options['extensions']['scrollSync']['extScrollSync_js_path'])); - break; - case 'colorSyntax': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['colorSyntax']['tui_color_picker_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['colorSyntax']['extColorSyntax_js_path'])); - $extsCssHtml .= sprintf('', $this->fixPath($this->options['extensions']['colorSyntax']['tui_color_picker_css_path'])); - break; - case 'uml': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['uml']['plantuml_encoder_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['uml']['extUML_js_path'])); - break; - case 'chart': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['raphael_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['tui_chart_js_path'])); - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['extChart_js_path'])); - $extsCssHtml .= sprintf('', $this->fixPath($this->options['extensions']['chart']['tui_chart_css_path'])); - break; - case 'table': - $extsJsHtml .= sprintf('', $this->fixPath($this->options['extensions']['table']['extTable_js_path'])); - break; - } - } - } + $extsHtml = $this->renderExtensions($extensions); $editorJsScript = sprintf( ' - - - - - - - - + + + + + + + + + ``` Second, use the `TuiEditorType` in your form field: ```php +use Teebb\TuiEditorBundle\Form\Type\TuiEditorType; + class ArticleType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/README_zh.md b/README_zh.md index ffcb5c1..088e713 100644 --- a/README_zh.md +++ b/README_zh.md @@ -75,29 +75,33 @@ $ php bin/console assets:install --symlink ```yaml #config/packages/teebb_tuieditor.yaml teebb_tui_editor: - #enable: true # 是否启用tui.editor - #jquery: true # 是否使用jquery, 如果您的项目中使用过jquery,可以设置为false,避免重复引入jquery - #jquery_path: ~ # 自定义jquery路径. - #editor_js_path: ~ # 自定义editor js 路径 - # ... # 更多配置使用命令: bin/console debug:config teebb_tui_editor 查看 + #enable: true # 是否启用tui.editor + #jquery: true # 是否使用jquery, 如果您的项目中使用过jquery,可以设置为false,避免重复引入jquery + #jquery_path: ~ # 自定义jquery路径. + #editor_js_path: ~ # 自定义editor js 路径 + #asset_repository: 'teebbstudios/tui.editor-bundles' # Public assets installer repository + # ... # 更多配置使用命令: bin/console debug:config teebb_tui_editor 查看 default_config: basic_config configs: basic_config: - to_html: false # Save to database use html syntax? - #previewStyle: 'vertical' # Markdown editor's preview style (tab, vertical) - #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) - exts: # exts must defined as array - - scrollSync - - colorSyntax - - uml - - chart - - mark - - table + to_html: false # Save to database use html syntax? + #previewStyle: 'vertical' # Markdown editor's preview style (tab, vertical) + #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) + exts: # exts must defined as array + - editor_plugin_color_syntax + - editor_plugin_chart + - editor_plugin_code_syntax_highlight + - editor_plugin_table_merged_cell + - editor_plugin_uml ``` + +> [!CAUTION] +> asset_repository config is the GitHub repository that will be used for the `php bin/console tuieditor:install` command, the script will look for the latest release and download all files into the TeebbTuiEditorBundle `src/Resources/public` folder. Use only trusted repository for this bundle. + 您可以修改tui.editor的语言显示。 ```yaml #config/services.yaml @@ -117,19 +121,21 @@ parameters: 这一步会把tui.editor所有的依赖js库添加到页面, 最终的html代码如下: ```html - - - - - - - - - + + + + + + + + + ``` 再在您的表单对应字段中使用TeebbTuiEditorBundle预先定义好的类型`TuiEditorType`, 如下: ```php +use Teebb\TuiEditorBundle\Form\Type\TuiEditorType; + class ArticleType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/src/Config/TuiEditorConfiguration.php b/src/Config/TuiEditorConfiguration.php index e812d60..47e5326 100644 --- a/src/Config/TuiEditorConfiguration.php +++ b/src/Config/TuiEditorConfiguration.php @@ -72,6 +72,11 @@ final class TuiEditorConfiguration implements TuiEditorConfigurationInterface */ private $dependencies; + /** + * @var string + */ + private $assetRepository; + public function __construct(array $config) { if ($config['enable']) { @@ -90,6 +95,7 @@ public function __construct(array $config) $this->configs = $config['configs']; $this->extensions = $config['extensions']; $this->dependencies = $config['dependencies']; + $this->assetRepository = $config['asset_repository']; } @@ -177,6 +183,11 @@ public function getDependencies(): array return $this->dependencies; } + public function getAssetRepository(): string + { + return $this->assetRepository; + } + public function getConfig(string $name): array { if (!isset($this->configs[$name])) { diff --git a/src/Config/TuiEditorConfigurationInterface.php b/src/Config/TuiEditorConfigurationInterface.php index eb16470..d867acd 100644 --- a/src/Config/TuiEditorConfigurationInterface.php +++ b/src/Config/TuiEditorConfigurationInterface.php @@ -34,6 +34,8 @@ public function getExtensions(): array; public function getDependencies(): array; + public function getAssetRepository(): string; + /** * @throws ConfigException */ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 517cb9a..d158420 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -31,6 +31,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('editor_contents_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor-viewer.css')->end() ->scalarNode('jquery_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/jquery/dist/jquery.min.js')->end() ->scalarNode('default_config')->defaultValue(null)->end() + ->scalarNode('asset_repository')->defaultValue('teebbstudios/tui.editor-bundles')->end() ->append($this->createExtensions()) ->append($this->createDependencies()) ->append($this->createConfigsNode()) @@ -188,4 +189,4 @@ private function createNode(string $name): ArrayNodeDefinition return $node; } -} \ No newline at end of file +} diff --git a/src/Installer/TuiEditorInstaller.php b/src/Installer/TuiEditorInstaller.php index 96765de..fcf7088 100644 --- a/src/Installer/TuiEditorInstaller.php +++ b/src/Installer/TuiEditorInstaller.php @@ -7,6 +7,7 @@ use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; use Teebb\TuiEditorBundle\Exception\BadProxyUrlException; +use Teebb\TuiEditorBundle\Config\TuiEditorConfigurationInterface; final class TuiEditorInstaller { @@ -62,8 +63,6 @@ final class TuiEditorInstaller */ private static $archive = 'https://github.com/%s/archive/%s.zip'; - private $repository = 'teebbstudios/tui.editor-bundles'; - private $version; /** @@ -71,8 +70,12 @@ final class TuiEditorInstaller */ private $resolver; + /** + * @var TuiEditorConfigurationInterface + */ + private $configuration; - public function __construct(array $options = []) + public function __construct(TuiEditorConfigurationInterface $configuration, array $options = []) { $this->resolver = (new OptionsResolver()) ->setDefaults(array_merge([ @@ -86,6 +89,7 @@ public function __construct(array $options = []) ->setNormalizer('path', function (Options $options, $path) { return rtrim($path, '/'); }); + $this->configuration = $configuration; } public function install(array $options = []): bool @@ -180,13 +184,13 @@ private function getDownloadUrl(array $options): string $this->notify(self::NOTIFY_GET_DOWNLOAD_URL, null, $options['notifier']); - $repoApiUrl = sprintf(self::$archiveApi, $this->repository); + $repoApiUrl = sprintf(self::$archiveApi, $this->configuration->getAssetRepository()); $apiResponseJson = json_decode(file_get_contents($repoApiUrl, false, $this->createHttpGetContext()), true); $this->version = $apiResponseJson['tag_name']; - $downloadUrl = sprintf(self::$archive, $this->repository, $this->version); + $downloadUrl = sprintf(self::$archive, $this->configuration->getAssetRepository(), $this->version); $this->notify(self::NOTIFY_DOWNLOAD_URL, $downloadUrl, $options['notifier']); diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 11b89b0..cafe15b 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -206,7 +206,7 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = $id, $id, "300px", - $this->fixArrayToJs($extensions, "scrollSync") + $this->fixArrayToJs($extensions) ); return $viewerJsCode . $viewerCssCode . $extsHtml . $viewerJsScript; diff --git a/src/Resources/config/installer.xml b/src/Resources/config/installer.xml index 132a25d..5bf3c0b 100644 --- a/src/Resources/config/installer.xml +++ b/src/Resources/config/installer.xml @@ -5,6 +5,8 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > - + + + diff --git a/src/Twig/TuiEditorExtension.php b/src/Twig/TuiEditorExtension.php index 18a89b0..0887670 100644 --- a/src/Twig/TuiEditorExtension.php +++ b/src/Twig/TuiEditorExtension.php @@ -30,7 +30,7 @@ public function getFunctions(): array new TwigFunction('tuieditor_viewer_widget', [$this, 'renderViewer'], $options), new TwigFunction('tuieditor_editor_widget', [$this, 'renderEditor'], $options), new TwigFunction('tuieditor_editor_css_path', [$this, 'renderEditorCssPath'], $options), - new TwigFunction('tuieditor_editor_contents_csss_path', [$this, 'renderEditorContentsCssPath'], $options), + new TwigFunction('tuieditor_editor_contents_css_path', [$this, 'renderEditorContentsCssPath'], $options), new TwigFunction('tuieditor_dependencies', [$this, 'renderDependencies'], $options), ]; } From a0a1445efbda5fd98ba8fd0e03f8980e8d528be6 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 3 Dec 2025 23:56:09 +0000 Subject: [PATCH 06/29] Fix detection for existing TUI Editor in new asset folder structure --- src/Installer/TuiEditorInstaller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Installer/TuiEditorInstaller.php b/src/Installer/TuiEditorInstaller.php index fcf7088..2b37b9c 100644 --- a/src/Installer/TuiEditorInstaller.php +++ b/src/Installer/TuiEditorInstaller.php @@ -110,7 +110,7 @@ public function install(array $options = []): bool private function clear(array $options): string { - if (!file_exists($options['path'].'/tui.editor-bundles/tui-editor/dist/tui-editor-Editor.js')) { + if (!file_exists($options['path'].'/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor.js')) { return self::CLEAR_DROP; } From 88bc23b108130ad00122d04f9785e1530dc9d603 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 4 Dec 2025 00:00:54 +0000 Subject: [PATCH 07/29] Add missing options argument --- src/Resources/config/installer.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Resources/config/installer.xml b/src/Resources/config/installer.xml index 5bf3c0b..8cc8b6c 100644 --- a/src/Resources/config/installer.xml +++ b/src/Resources/config/installer.xml @@ -7,6 +7,7 @@ + From c51e76133b0679f333f6c78525d1edb99b77710f Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 4 Dec 2025 00:08:32 +0000 Subject: [PATCH 08/29] Fix incorrect path for toastui-editor-plugin-color-syntax --- src/DependencyInjection/Configuration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d158420..2b2a34e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -48,8 +48,8 @@ private function createExtensions() ->arrayNode('editor_plugin_color_syntax') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_code_color_syntax_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.js')->end() - ->scalarNode('tui_code_color_syntax_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.css')->end() + ->scalarNode('tui_code_color_syntax_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.js')->end() + ->scalarNode('tui_code_color_syntax_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.css')->end() ->end() ->end() ->arrayNode('editor_plugin_chart') From 8143844966e7705a7bb9a0bdfae121fa7c87a6bf Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 4 Dec 2025 09:43:37 +0000 Subject: [PATCH 09/29] Keep plugin/extension name the same, for editor/viewer parameter --- README.md | 10 +++++----- README_zh.md | 10 +++++----- src/DependencyInjection/Configuration.php | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6436937..abbe0cb 100644 --- a/README.md +++ b/README.md @@ -95,11 +95,11 @@ teebb_tui_editor: #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) exts: # exts must defined as array - - editor_plugin_color_syntax - - editor_plugin_chart - - editor_plugin_code_syntax_highlight - - editor_plugin_table_merged_cell - - editor_plugin_uml + - chart + - code-syntax-highlight + - color-syntax + - table-merged-cell + - uml ``` diff --git a/README_zh.md b/README_zh.md index 088e713..08d9c57 100644 --- a/README_zh.md +++ b/README_zh.md @@ -91,11 +91,11 @@ teebb_tui_editor: #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) exts: # exts must defined as array - - editor_plugin_color_syntax - - editor_plugin_chart - - editor_plugin_code_syntax_highlight - - editor_plugin_table_merged_cell - - editor_plugin_uml + - chart + - code-syntax-highlight + - color-syntax + - table-merged-cell + - uml ``` diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2b2a34e..50fcff3 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -45,14 +45,14 @@ private function createExtensions() return $this->createNode('extensions') ->addDefaultsIfNotSet() ->children() - ->arrayNode('editor_plugin_color_syntax') + ->arrayNode('color-syntax') ->addDefaultsIfNotSet() ->children() ->scalarNode('tui_code_color_syntax_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.js')->end() ->scalarNode('tui_code_color_syntax_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.css')->end() ->end() ->end() - ->arrayNode('editor_plugin_chart') + ->arrayNode('chart') ->addDefaultsIfNotSet() ->children() ->scalarNode('tui_chart_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/dist/toastui-chart.min.js')->end() @@ -60,21 +60,21 @@ private function createExtensions() ->scalarNode('tui_chart_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/dist/toastui-chart.min.css')->end() ->end() ->end() - ->arrayNode('editor_plugin_code_syntax_highlight') + ->arrayNode('code-syntax-highlight') ->addDefaultsIfNotSet() ->children() ->scalarNode('tui_code_syntax_highlight_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight.js')->end() ->scalarNode('tui_code_syntax_highlight_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight.css')->end() ->end() ->end() - ->arrayNode('editor_plugin_table_merged_cell') + ->arrayNode('table-merged-cell') ->addDefaultsIfNotSet() ->children() ->scalarNode('tui_table_merged_cell_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-table-merged-cell/dist/toastui-editor-plugin-table-merged-cell.js')->end() ->scalarNode('tui_table_merged_cell_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-table-merged-cell/dist/toastui-editor-plugin-table-merged-cell.css')->end() ->end() ->end() - ->arrayNode('editor_plugin_uml') + ->arrayNode('uml') ->addDefaultsIfNotSet() ->children() ->scalarNode('tui_uml_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-uml/dist/toastui-editor-plugin-uml.js')->end() From 39c3ff7f908d9bb6b44a2192136011efa40414c0 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Fri, 5 Dec 2025 12:07:03 +0000 Subject: [PATCH 10/29] Use generated bundle, remove dependencies --- README.md | 6 +- README_zh.md | 6 +- src/Config/TuiEditorConfiguration.php | 6 ++ src/DependencyInjection/Configuration.php | 87 +++-------------------- src/Form/Type/TuiEditorType.php | 4 ++ src/Renderer/TuiEditorRenderer.php | 74 +++++++++---------- src/Twig/TuiEditorExtension.php | 6 ++ 7 files changed, 71 insertions(+), 118 deletions(-) diff --git a/README.md b/README.md index abbe0cb..4ed4ba5 100644 --- a/README.md +++ b/README.md @@ -96,9 +96,9 @@ teebb_tui_editor: #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) exts: # exts must defined as array - chart - - code-syntax-highlight - - color-syntax - - table-merged-cell + - codeSyntaxHighlight + - colorSyntax + - tableMergedCell - uml ``` diff --git a/README_zh.md b/README_zh.md index 08d9c57..68c1c49 100644 --- a/README_zh.md +++ b/README_zh.md @@ -92,9 +92,9 @@ teebb_tui_editor: #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) exts: # exts must defined as array - chart - - code-syntax-highlight - - color-syntax - - table-merged-cell + - codeSyntaxHighlight + - colorSyntax + - tableMergedCell - uml ``` diff --git a/src/Config/TuiEditorConfiguration.php b/src/Config/TuiEditorConfiguration.php index 47e5326..e5c8b7d 100644 --- a/src/Config/TuiEditorConfiguration.php +++ b/src/Config/TuiEditorConfiguration.php @@ -89,6 +89,7 @@ public function __construct(array $config) $this->editorJsPath = $config['editor_js_path']; $this->viewerJsPath = $config['viewer_js_path']; $this->editorCssPath = $config['editor_css_path']; + $this->viewerCssPath = $config['viewer_css_path']; $this->editorContentsCssPath = $config['editor_contents_css_path']; $this->jqueryPath = $config['jquery_path']; $this->defaultConfig = $config['default_config']; @@ -152,6 +153,11 @@ public function getEditorCssPath(): string return $this->editorCssPath; } + public function getViewerCssPath(): string + { + return $this->viewerCssPath; + } + public function getEditorContentsCssPath(): string { return $this->editorContentsCssPath; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 50fcff3..3e0e37e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -25,9 +25,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->booleanNode('enable')->defaultTrue()->end() ->booleanNode('jquery')->defaultTrue()->info("If you want use jquery.js set true.")->end() ->scalarNode('base_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/')->end() - ->scalarNode('editor_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor.js')->end() - ->scalarNode('viewer_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor-viewer.js')->end() + ->scalarNode('editor_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-editor-bundle.js')->end() + ->scalarNode('viewer_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-viewer-bundle.js')->end() ->scalarNode('editor_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor.css')->end() + ->scalarNode('viewer_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor-viewer.css')->end() ->scalarNode('editor_contents_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor/dist/toastui-editor-viewer.css')->end() ->scalarNode('jquery_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/jquery/dist/jquery.min.js')->end() ->scalarNode('default_config')->defaultValue(null)->end() @@ -45,39 +46,38 @@ private function createExtensions() return $this->createNode('extensions') ->addDefaultsIfNotSet() ->children() - ->arrayNode('color-syntax') + ->arrayNode('colorSyntax') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_code_color_syntax_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.js')->end() + ->scalarNode('tui_code_color_syntax_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-color-syntax-bundle.js')->end() ->scalarNode('tui_code_color_syntax_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-color-syntax/dist/toastui-editor-plugin-color-syntax.css')->end() ->end() ->end() ->arrayNode('chart') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_chart_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/dist/toastui-chart.min.js')->end() - ->scalarNode('tui_chart_plugin_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-chart/dist/toastui-editor-plugin-chart.js')->end() + ->scalarNode('tui_chart_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-chart-bundle.js')->end() ->scalarNode('tui_chart_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/chart/dist/toastui-chart.min.css')->end() ->end() ->end() - ->arrayNode('code-syntax-highlight') + ->arrayNode('codeSyntaxHighlight') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_code_syntax_highlight_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight.js')->end() + ->scalarNode('tui_code_syntax_highlight_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-code-syntax-highlight-bundle.js')->end() ->scalarNode('tui_code_syntax_highlight_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-code-syntax-highlight/dist/toastui-editor-plugin-code-syntax-highlight.css')->end() ->end() ->end() - ->arrayNode('table-merged-cell') + ->arrayNode('tableMergedCell') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_table_merged_cell_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-table-merged-cell/dist/toastui-editor-plugin-table-merged-cell.js')->end() + ->scalarNode('tui_table_merged_cell_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-table-merged-cell-bundle.js')->end() ->scalarNode('tui_table_merged_cell_css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-table-merged-cell/dist/toastui-editor-plugin-table-merged-cell.css')->end() ->end() ->end() ->arrayNode('uml') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_uml_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/@toast-ui/editor-plugin-uml/dist/toastui-editor-plugin-uml.js')->end() + ->scalarNode('tui_uml_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-viewer-bundle.js')->end() ->end() ->end() ->end(); @@ -88,71 +88,6 @@ private function createDependencies() return $this->createNode('dependencies') ->addDefaultsIfNotSet() ->children() - ->arrayNode('dompurify') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/dompurify/dist/purify.min.js')->end() - ->scalarNode('module_js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() - - ->arrayNode('orderedmap') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue(null)->end() - ->scalarNode('module_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/orderedmap/dist/index.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() - ->arrayNode('plantuml_encoder') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/plantuml-encoder/dist/plantuml-encoder.min.js')->end() - ->scalarNode('module_js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() - ->arrayNode('plantuml_decoder') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/plantuml-encoder/dist/plantuml-decoder.min.js')->end() - ->scalarNode('module_js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() - ->arrayNode('prismjs') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/prismjs/prism.js')->end() - ->scalarNode('module_js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() - ->arrayNode('prosemirror_bundle') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue(null)->end() - ->scalarNode('module_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/prosemirror-bundle.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() - ->arrayNode('tui_color_picker') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/tui-color-picker/dist/tui-color-picker.min.js')->end() - ->scalarNode('module_js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/tui-color-picker/dist/tui-color-picker.min.css')->end() - ->end() - ->end() - ->arrayNode('w3c-keyname') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('js_path')->defaultValue(null)->end() - ->scalarNode('module_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/node_modules/w3c-keyname/index.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() - ->end() - ->end() ->end(); } diff --git a/src/Form/Type/TuiEditorType.php b/src/Form/Type/TuiEditorType.php index 0a28d96..3713d03 100644 --- a/src/Form/Type/TuiEditorType.php +++ b/src/Form/Type/TuiEditorType.php @@ -46,6 +46,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->setAttribute('editor_js_path', $options['editor_js_path']); $builder->setAttribute('viewer_js_path', $options['viewer_js_path']); $builder->setAttribute('editor_css_path', $options['editor_css_path']); + $builder->setAttribute('viewer_css_path', $options['viewer_css_path']); $builder->setAttribute('editor_contents_css_path', $options['editor_contents_css_path']); $builder->setAttribute('jquery_path', $options['jquery_path']); $builder->setAttribute('config', $this->resolveConfig($options)); @@ -82,6 +83,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): $view->vars['editor_js_path'] = $config->getAttribute('editor_js_path'); $view->vars['viewer_js_path'] = $config->getAttribute('viewer_js_path'); $view->vars['editor_css_path'] = $config->getAttribute('editor_css_path'); + $view->vars['viewer_css_path'] = $config->getAttribute('viewer_css_path'); $view->vars['editor_contents_css_path'] = $config->getAttribute('editor_contents_css_path'); $view->vars['jquery_path'] = $config->getAttribute('jquery_path'); $view->vars['config'] = $config->getAttribute('config'); @@ -102,6 +104,7 @@ public function configureOptions(OptionsResolver $resolver): void 'editor_js_path' => $this->configuration->getEditorJsPath(), 'viewer_js_path' => $this->configuration->getViewerJsPath(), 'editor_css_path' => $this->configuration->getEditorCssPath(), + 'viewer_css_path' => $this->configuration->getViewerCssPath(), 'editor_contents_css_path' => $this->configuration->getEditorContentsCssPath(), 'jquery_path' => $this->configuration->getJqueryPath(), 'config_name' => $this->configuration->getDefaultConfig(), @@ -117,6 +120,7 @@ public function configureOptions(OptionsResolver $resolver): void ->addAllowedTypes('editor_js_path', 'string') ->addAllowedTypes('viewer_js_path', 'string') ->addAllowedTypes('editor_css_path', 'string') + ->addAllowedTypes('viewer_css_path', 'string') ->addAllowedTypes('editor_contents_css_path', 'string') ->addAllowedTypes('jquery_path', 'string') ->addAllowedTypes('config', 'array') diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index cafe15b..4d7dfaa 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -95,6 +95,15 @@ public function renderEditorCssPath(string $editorCssPath = null): string return $this->fixPath($editorCssPath); } + public function renderViewerCssPath(string $viewerCssPath = null): string + { + if ($viewerCssPath === null) { + return $this->fixPath($this->options['viewer_css_path']); + } + return $this->fixPath($viewerCssPath); + } + + public function renderEditorContentsCssPath(string $editorContentsCssPath = null): string { if ($editorContentsCssPath === null) { @@ -116,9 +125,6 @@ public function renderDependencies(array $dependencies = null): string $dependenciesJsHtml .= $this->renderScriptBlock($this->options['jquery_path']); } foreach ($dependencies as $dependency) { - if ($dependency['module_js_path'] !== null) { - $dependenciesJsHtml .= $this->renderScriptModuleBlock($dependency['module_js_path']); - } if ($dependency['js_path'] !== null) { $dependenciesJsHtml .= $this->renderScriptBlock($dependency['js_path']); } @@ -134,12 +140,6 @@ public function renderScriptBlock(string $path): string return sprintf('', $this->fixPath($path)); } - public function renderScriptModuleBlock(string $path): string - { - return sprintf('', $this->fixPath($path)); - } - - public function renderStyleBlock(string $path): string { return sprintf('', $this->fixPath($path)); @@ -188,20 +188,22 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = $extensions = $this->options['configs'][$this->options['default_config']]['exts']; $viewerJsCode = $this->renderScriptBlock($viewerJsPath); - $viewerCssCode = $this->renderStyleBlock($this->options['editor_contents_css_path']); + $editorContentsCssCode = $this->renderStyleBlock($this->options['editor_contents_css_path']); + $viewerCssCode = $this->renderStyleBlock($this->options['viewer_css_path']); $extsHtml = $this->renderExtensions($extensions); $viewerJsScript = sprintf( - '', + '', $this->fixContentToJs($content), $id, $id, @@ -209,7 +211,7 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = $this->fixArrayToJs($extensions) ); - return $viewerJsCode . $viewerCssCode . $extsHtml . $viewerJsScript; + return $viewerJsCode . $viewerCssCode. $editorContentsCssCode . $extsHtml . $viewerJsScript; } private function fixArrayToJs(array $array, ?string $exclude = null): string @@ -291,25 +293,25 @@ public function renderEditor(string $id, array $config, string $content = null): $config = $this->fixConfigLanguage($config); $extensions = $config['exts']; - $editorJsCode = sprintf('', $this->fixPath($this->options['editor_js_path'])); - $editorCssCode = sprintf('', $this->fixPath($this->options['editor_css_path'])); - $editorContentsCssCode = sprintf('', $this->fixPath($this->options['editor_contents_css_path'])); + $editorJsCode = $this->renderScriptBlock($this->options['editor_js_path']); + $editorCssCode = $this->renderStyleBlock($this->options['editor_css_path']); + $editorContentsCssCode = $this->renderStyleBlock($this->options['editor_contents_css_path']); $extsHtml = $this->renderExtensions($extensions); $editorJsScript = sprintf( - '', + '', $this->fixContentToJs($content), $id, $id, @@ -320,6 +322,6 @@ public function renderEditor(string $id, array $config, string $content = null): $this->fixArrayToJs($extensions) ); - return $editorJsCode . $editorCssCode . $editorContentsCssCode . $extsHtml . $editorJsScript; + return $extsHtml . $editorJsCode . $editorCssCode . $editorContentsCssCode . $editorJsScript; } } \ No newline at end of file diff --git a/src/Twig/TuiEditorExtension.php b/src/Twig/TuiEditorExtension.php index 0887670..0b1e323 100644 --- a/src/Twig/TuiEditorExtension.php +++ b/src/Twig/TuiEditorExtension.php @@ -30,6 +30,7 @@ public function getFunctions(): array new TwigFunction('tuieditor_viewer_widget', [$this, 'renderViewer'], $options), new TwigFunction('tuieditor_editor_widget', [$this, 'renderEditor'], $options), new TwigFunction('tuieditor_editor_css_path', [$this, 'renderEditorCssPath'], $options), + new TwigFunction('tuieditor_viewer_css_path', [$this, 'renderViewerCssPath'], $options), new TwigFunction('tuieditor_editor_contents_css_path', [$this, 'renderEditorContentsCssPath'], $options), new TwigFunction('tuieditor_dependencies', [$this, 'renderDependencies'], $options), ]; @@ -40,6 +41,11 @@ public function renderEditorCssPath(string $editorCssPath = null): string return $this->renderer->renderEditorCssPath($editorCssPath); } + public function renderViewerCssPath(string $viewerCssPath = null): string + { + return $this->renderer->renderViewerCssPath($viewerCssPath); + } + public function renderEditorContentsCssPath(string $editorContentsCssPath = null): string { return $this->renderer->renderEditorContentsCssPath($editorContentsCssPath); From 102beb58e198ebb0d84186aa004d362d8bc7e129 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Sat, 6 Dec 2025 02:16:27 +0000 Subject: [PATCH 11/29] Display Editor and Viewer with essential plugins --- README.md | 17 +----- README_zh.md | 14 +---- src/DependencyInjection/Configuration.php | 2 +- src/Installer/TuiEditorInstaller.php | 2 - src/Renderer/TuiEditorRenderer.php | 65 +++++++++-------------- 5 files changed, 28 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 4ed4ba5..0c8e3eb 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ teebb_tui_editor: #jquery: true # Whether to enable jquery in dependencies. #jquery_path: ~ # Custom jquery path. #editor_js_path: ~ # Custom tui.editor js path. + #viewer_js_path: ~ # Custom tui.viewer js path. + #editor_contents_css_path: ~ # Custom content css path. #asset_repository: 'teebbstudios/tui.editor-bundles' # Public assets installer repository # ... # more config options, you can see: bin/console debug:config teebb_tui_editor @@ -121,21 +123,6 @@ Add the tui.editor dependencies in your page top. For example: ```twig {{ tuieditor_dependencies() }} -``` -This will add the tui.editor dependencies JS and CSS libs like: - -```html - - - - - - - - - - - ``` Second, use the `TuiEditorType` in your form field: diff --git a/README_zh.md b/README_zh.md index 68c1c49..03dfc6d 100644 --- a/README_zh.md +++ b/README_zh.md @@ -118,19 +118,7 @@ parameters: ```twig {{ tuieditor_dependencies() }} ``` -这一步会把tui.editor所有的依赖js库添加到页面, 最终的html代码如下: - -```html - - - - - - - - - -``` + 再在您的表单对应字段中使用TeebbTuiEditorBundle预先定义好的类型`TuiEditorType`, 如下: ```php diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3e0e37e..1eb3925 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -77,7 +77,7 @@ private function createExtensions() ->arrayNode('uml') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_uml_js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/toast-ui-viewer-bundle.js')->end() + ->scalarNode('tui_uml_js_path')->defaultValue('https://uicdn.toast.com/editor-plugin-uml/latest/toastui-editor-plugin-uml.min.js')->end() ->end() ->end() ->end(); diff --git a/src/Installer/TuiEditorInstaller.php b/src/Installer/TuiEditorInstaller.php index 2b37b9c..bef1433 100644 --- a/src/Installer/TuiEditorInstaller.php +++ b/src/Installer/TuiEditorInstaller.php @@ -307,10 +307,8 @@ private function extractFile(string $file, string $rewrite, string $origin, arra if (!@copy($from, $to)) { throw $this->createException(sprintf('Unable to extract the file "%s" to "%s".', $file, $to)); } - } - private function notify(string $type, $data = null, callable $notifier = null) { if (null !== $notifier) { diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 4d7dfaa..79b7bcd 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -153,25 +153,24 @@ public function renderExtensions($extensions): string if (null !== $extensions) { foreach ($extensions as $extKey => $extValue) { switch ($extValue) { - case 'editor_plugin_color_syntax': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_color_syntax']['tui_code_color_syntax_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_color_syntax']['tui_code_color_syntax_css_path']); + case 'colorSyntax': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['colorSyntax']['tui_code_color_syntax_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['colorSyntax']['tui_code_color_syntax_css_path']); break; - case 'editor_plugin_chart': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_chart']['tui_chart_js_path']); - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_chart']['tui_chart_plugin_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_chart']['tui_chart_css_path']); + case 'chart': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['chart']['tui_chart_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['chart']['tui_chart_css_path']); break; - case 'editor_plugin_code_syntax_highlight': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_code_syntax_highlight']['tui_code_syntax_highlight_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_code_syntax_highlight']['tui_code_syntax_highlight_css_path']); + case 'codeSyntaxHighlight': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['codeSyntaxHighlight']['tui_code_syntax_highlight_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['codeSyntaxHighlight']['tui_code_syntax_highlight_css_path']); break; - case 'editor_plugin_table_merged_cell': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_table_merged_cell']['tui_table_merged_cell_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['editor_plugin_table_merged_cell']['tui_table_merged_cell_css_path']); + case 'tableMergedCell': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['tableMergedCell']['tui_table_merged_cell_js_path']); + $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['tableMergedCell']['tui_table_merged_cell_css_path']); break; - case 'editor_plugin_uml': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['editor_plugin_uml']['tui_uml_js_path']); + case 'uml': + $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['uml']['tui_uml_js_path']); break; } } @@ -195,13 +194,11 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = $viewerJsScript = sprintf( '', $this->fixContentToJs($content), @@ -214,40 +211,26 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = return $viewerJsCode . $viewerCssCode. $editorContentsCssCode . $extsHtml . $viewerJsScript; } - private function fixArrayToJs(array $array, ?string $exclude = null): string + private function fixArrayToJs(array $array, array $excludeList = []): string { if (null == $array) { return ""; } - $jsArray = ""; + $jsArray = []; foreach ($array as $key => $item) { - if ($item == $exclude) continue; - if ($key !== sizeof($array) - 1) { - $jsArray .= "'" . $item . "',"; - } else { - $jsArray .= "'" . $item . "'"; - } + if (in_array($item, $excludeList)) continue; + array_push($jsArray, $item); } - return $jsArray; + return implode(",", $jsArray); } private function fixContentToJs(string $content): string { if (null == $content) { - return ""; - } - $rows = explode("\r\n", $content); - - $jsArray = ""; - foreach ($rows as $index => $row) { - if ($index !== sizeof($rows) - 1) { - $jsArray .= "'" . $row . "',"; - } else { - $jsArray .= "'" . $row . "'"; - } + $content = ""; } - return $jsArray; + return json_encode($content); } private function fixPath(string $path): string @@ -301,7 +284,7 @@ public function renderEditor(string $id, array $config, string $content = null): $editorJsScript = sprintf( ' From 51b9db9fb3627f7318dff34ea6a3c5341e34964e Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Tue, 9 Dec 2025 16:57:12 +0000 Subject: [PATCH 16/29] Add theme option --- README.md | 13 ++++++- README_zh.md | 6 +++- src/Config/TuiEditorConfiguration.php | 10 ++++++ .../TuiEditorConfigurationInterface.php | 2 ++ src/DependencyInjection/Configuration.php | 13 +++++-- src/Renderer/TuiEditorRenderer.php | 34 +++++++++++++++---- 6 files changed, 67 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 09524ac..d883988 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ teebb_tui_editor: #previewStyle: 'vertical' # Markdown editor's preview style (tab, vertical) #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) - #theme_css: 'dark' # override editor color scheme with dark theme + #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' exts: # exts must defined as array - chart - codeSyntaxHighlight @@ -106,6 +106,11 @@ teebb_tui_editor: - tableMergedCell - uml toolbar_items: [] + dependencies: + editor_dark_theme: # Must include if using 'dark' theme + js_path: + css_path: /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css + ``` @@ -129,6 +134,12 @@ Add the tui.editor dependencies in your page top. For example: {{ tuieditor_dependencies() }} ``` +This will add the tui.editor dependencies JS and CSS libs like: + +```html + +``` + Second, use the `TuiEditorType` in your form field: ```php diff --git a/README_zh.md b/README_zh.md index 229c970..04d022a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -94,7 +94,7 @@ teebb_tui_editor: #previewStyle: 'vertical' # Markdown editor's preview style (tab, vertical) #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) - #theme_css: 'dark' # override editor color scheme with dark theme + #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' exts: # exts must defined as array - chart - codeSyntaxHighlight @@ -102,6 +102,10 @@ teebb_tui_editor: - tableMergedCell - uml toolbar_items: [] + dependencies: + editor_dark_theme: # Must include if using 'dark' theme + js_path: + css_path: /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css ``` diff --git a/src/Config/TuiEditorConfiguration.php b/src/Config/TuiEditorConfiguration.php index 170a503..57b9d8c 100644 --- a/src/Config/TuiEditorConfiguration.php +++ b/src/Config/TuiEditorConfiguration.php @@ -47,6 +47,11 @@ final class TuiEditorConfiguration implements TuiEditorConfigurationInterface */ private $editorContentsCssPath; + /** + * @var string + */ + private $editorThemeName; + /** * @var string */ @@ -96,6 +101,7 @@ public function __construct(array $config) $this->editorCssPath = $config['editor_css_path']; $this->viewerCssPath = $config['viewer_css_path']; $this->editorContentsCssPath = $config['editor_contents_css_path']; + $this->editorThemeName = $config['editor_theme_name']; $this->jqueryPath = $config['jquery_path']; $this->defaultConfig = $config['default_config']; $this->configs = $config['configs']; @@ -169,6 +175,10 @@ public function getEditorContentsCssPath(): ?string return $this->editorContentsCssPath; } + public function getEditorThemeName(): string + { + return $this->editorThemeName; + } public function getJqueryPath(): string { diff --git a/src/Config/TuiEditorConfigurationInterface.php b/src/Config/TuiEditorConfigurationInterface.php index cfe094e..3f251f7 100644 --- a/src/Config/TuiEditorConfigurationInterface.php +++ b/src/Config/TuiEditorConfigurationInterface.php @@ -24,6 +24,8 @@ public function getEditorCssPath(): string; public function getEditorContentsCssPath(): ?string; + public function getEditorThemeName(): string; + public function getJqueryPath(): string; public function getDefaultConfig(): ?string; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2c73dd8..a38e92e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -30,12 +30,13 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('editor_css_path')->defaultValue($bundleBasePath.'css/toastui-editor.css')->end() ->scalarNode('viewer_css_path')->defaultValue($bundleBasePath.'css/toastui-editor-viewer.css')->end() ->scalarNode('editor_contents_css_path')->defaultValue(null)->end() + ->scalarNode('editor_theme_name')->defaultValue('light')->end() ->scalarNode('jquery_path')->defaultValue($bundleBasePath.'js/jquery.min.js')->end() ->scalarNode('default_config')->defaultValue(null)->end() ->scalarNode('asset_repository')->defaultValue('teebbstudios/tui.editor-bundles')->end() ->append($this->createToolbarItems()) ->append($this->createExtensions($bundleBasePath)) - ->append($this->createDependencies()) + ->append($this->createDependencies($bundleBasePath)) ->append($this->createConfigsNode()) ->end(); @@ -93,12 +94,18 @@ private function createExtensions(string $bundleBasePath) ->end(); } - private function createDependencies() + private function createDependencies($bundleBasePath) { return $this->createNode('dependencies') ->addDefaultsIfNotSet() ->children() - + ->arrayNode('editor_dark_theme') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('js_path')->defaultValue(null)->end() + ->scalarNode('css_path')->defaultValue($bundleBasePath.'css/toastui-editor-dark.css')->end() + ->end() + ->end() ->end(); } diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 4f4c0bd..38fe8c2 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -115,7 +115,12 @@ public function renderEditorContentsCssPath(string $editorContentsCssPath = null public function renderDependencies(array $dependencies = null): string { if ($dependencies === null) { - $dependencies = $this->options['dependencies']; + if ($this->options['default_config']) { + $dependencies = $this->options['configs'][$this->options['default_config']]['dependencies']; + } + if ($dependencies === null) { + $dependencies = $this->options['dependencies']; + } } $dependenciesJsHtml = ""; @@ -145,13 +150,14 @@ public function renderStyleBlock(string $path): string return sprintf('', $this->fixPath($path)); } - public function renderExtensions($extensions): string + public function renderExtensions($extensions, array $excludeList = []): string { $extsJsHtml = ""; $extsCssHtml = ""; if (null !== $extensions) { foreach ($extensions as $extKey => $extValue) { + if (in_array($extKey, $excludeList)) continue; switch ($extValue) { case 'colorSyntax': $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['colorSyntax']['tui_code_color_syntax_js_path']); @@ -185,13 +191,22 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = if (null === $viewerJsPath) { $viewerJsPath = $this->options['viewer_js_path']; } + $extensions = $this->options['configs'][$this->options['default_config']]['exts']; + + $editorThemeName = null; + if ($this->options['default_config']) { + $editorThemeName = $this->options['configs'][$this->options['default_config']]['editor_theme_name']; + } + if ($editorThemeName === null) { + $editorThemeName = $this->options['editor_theme_name']; + } $viewerJsCode = $this->renderScriptBlock($viewerJsPath); $editorContentsCssCode = isset($this->options['editor_contents_css_path']) && null !== $this->options['editor_contents_css_path']? $this->renderStyleBlock($this->options['editor_contents_css_path']) : ''; $viewerCssCode = $this->renderStyleBlock($this->options['viewer_css_path']); - $extsHtml = $this->renderExtensions($extensions); + $extsHtml = $this->renderExtensions($extensions, ["uml", "colorSyntax"]); $viewerJsScript = sprintf( '', $this->fixContentToJs($content), $id, $id, "300px", - $this->fixArrayToJs($extensions) + $this->fixArrayToJs($extensions, ["uml", "colorSyntax"]), + $editorThemeName ); return $viewerJsCode . $viewerCssCode. $editorContentsCssCode . $extsHtml . $viewerJsScript; @@ -274,8 +292,10 @@ private function getLanguage(): ?string public function renderEditor(string $id, array $config, string $content = null): string { + return $this->renderViewer($id, $content); $config = $this->fixConfigLanguage($config); $extensions = $config['exts']; + $editorThemeName = $config['editor_theme_name']; $editorJsCode = $this->renderScriptBlock($this->options['editor_js_path']); $editorCssCode = $this->renderStyleBlock($this->options['editor_css_path']); @@ -293,7 +313,8 @@ public function renderEditor(string $id, array $config, string $content = null): height: "%s", language: "%s", initialValue: content, - plugins: [%s] + plugins: [%s], + theme: "%s" }); ', $this->fixContentToJs($content), @@ -303,7 +324,8 @@ public function renderEditor(string $id, array $config, string $content = null): array_key_exists('previewStyle', $config) ? $config['previewStyle'] : "vertical", array_key_exists('height', $config) ? $config['height'] : "300px", array_key_exists('language', $config) ? $config['language'] : $config['locale'], - $this->fixArrayToJs($extensions) + $this->fixArrayToJs($extensions), + $editorThemeName ); return $extsHtml . $editorJsCode . $editorCssCode . $editorContentsCssCode . $editorJsScript; From abc8dc9deef64095db33b05339f5ffbff18a19c3 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Tue, 9 Dec 2025 17:37:02 +0000 Subject: [PATCH 17/29] Fix config detection --- src/Form/Type/TuiEditorType.php | 3 +++ src/Renderer/TuiEditorRenderer.php | 17 +++++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Form/Type/TuiEditorType.php b/src/Form/Type/TuiEditorType.php index 9a387d6..e858493 100644 --- a/src/Form/Type/TuiEditorType.php +++ b/src/Form/Type/TuiEditorType.php @@ -85,6 +85,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): $view->vars['editor_css_path'] = $config->getAttribute('editor_css_path'); $view->vars['viewer_css_path'] = $config->getAttribute('viewer_css_path'); $view->vars['editor_contents_css_path'] = $config->getAttribute('editor_contents_css_path'); + $view->vars['editor_theme_name'] = $config->getAttribute('editor_theme_name'); $view->vars['jquery_path'] = $config->getAttribute('jquery_path'); $view->vars['config'] = $config->getAttribute('config'); $view->vars['extensions'] = $config->getAttribute('extensions'); @@ -106,6 +107,7 @@ public function configureOptions(OptionsResolver $resolver): void 'editor_css_path' => $this->configuration->getEditorCssPath(), 'viewer_css_path' => $this->configuration->getViewerCssPath(), 'editor_contents_css_path' => $this->configuration->getEditorContentsCssPath(), + 'editor_theme_name' => $this->configuration->getEditorThemeName(), 'jquery_path' => $this->configuration->getJqueryPath(), 'config_name' => $this->configuration->getDefaultConfig(), 'config' => $this->configuration->getConfigs(), @@ -122,6 +124,7 @@ public function configureOptions(OptionsResolver $resolver): void ->addAllowedTypes('editor_css_path', 'string') ->addAllowedTypes('viewer_css_path', 'string') ->addAllowedTypes('editor_contents_css_path', ['string', 'null']) + ->addAllowedTypes('editor_theme_name', 'string') ->addAllowedTypes('jquery_path', 'string') ->addAllowedTypes('config', 'array') ->addAllowedTypes('extensions', 'array') diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 38fe8c2..9870528 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -187,20 +187,14 @@ public function renderExtensions($extensions, array $excludeList = []): string public function renderViewer(string $id, string $content, string $viewerJsPath = null): string { - if (null === $viewerJsPath) { $viewerJsPath = $this->options['viewer_js_path']; } - $extensions = $this->options['configs'][$this->options['default_config']]['exts']; + $defaultConfig = $this->options['default_config']; + $extensions = $defaultConfig && array_key_exists('editor_theme_name', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['extensions']: $this->options['extensions']; - $editorThemeName = null; - if ($this->options['default_config']) { - $editorThemeName = $this->options['configs'][$this->options['default_config']]['editor_theme_name']; - } - if ($editorThemeName === null) { - $editorThemeName = $this->options['editor_theme_name']; - } + $editorThemeName = $defaultConfig && array_key_exists('editor_theme_name', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['editor_theme_name']: $this->options['editor_theme_name']; $viewerJsCode = $this->renderScriptBlock($viewerJsPath); $editorContentsCssCode = isset($this->options['editor_contents_css_path']) && null !== $this->options['editor_contents_css_path']? $this->renderStyleBlock($this->options['editor_contents_css_path']) : ''; @@ -292,10 +286,9 @@ private function getLanguage(): ?string public function renderEditor(string $id, array $config, string $content = null): string { - return $this->renderViewer($id, $content); $config = $this->fixConfigLanguage($config); - $extensions = $config['exts']; - $editorThemeName = $config['editor_theme_name']; + $extensions = array_key_exists('extensions', $config) ? $config['extensions']: $this->options['extensions']; + $editorThemeName = array_key_exists('editor_theme_name', $config) ? $config['editor_theme_name']: $this->options['editor_theme_name']; $editorJsCode = $this->renderScriptBlock($this->options['editor_js_path']); $editorCssCode = $this->renderStyleBlock($this->options['editor_css_path']); From ccbe4eaaff70f6362cb1549af9e2e72368b2eece Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Tue, 9 Dec 2025 23:00:33 +0000 Subject: [PATCH 18/29] Provide better support for plugin options, amended the README to display the optional options for the extensions --- README.md | 16 ++++++++++++---- README_zh.md | 16 ++++++++++++---- src/Renderer/TuiEditorRenderer.php | 23 ++++++++++++++++------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d883988..bc3006d 100644 --- a/README.md +++ b/README.md @@ -99,12 +99,20 @@ teebb_tui_editor: #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' - exts: # exts must defined as array - - chart + extensions: # extensions must defined as array of plugin_name variable or {plugin_name, [plugin_options}} + - chart: # chart options + #width: 'auto' # number|string 'auto' Default width value + #height: 'auto' # number|string 'auto' Default height value + #minWidth: 0 # number 0 Minimum width value + #maxWidth: 0 # number 0 Minimum height value + #minHeight: Infinity # number Infinity Maximum width value + #maxHeight: Infinity # number Infinity Maximum height value - codeSyntaxHighlight - - colorSyntax + - colorSyntax: # colorSyntax options + #preset: ['#181818', '#292929'] # preset Array. Preset for color palette - tableMergedCell - - uml + - uml: # uml options + #rendererURL: ~ # string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer toolbar_items: [] dependencies: editor_dark_theme: # Must include if using 'dark' theme diff --git a/README_zh.md b/README_zh.md index 04d022a..1fcebe4 100644 --- a/README_zh.md +++ b/README_zh.md @@ -95,12 +95,20 @@ teebb_tui_editor: #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' - exts: # exts must defined as array - - chart + extensions: # extensions must defined as array of plugin_name variable or {plugin_name, {plugin_options}} + - chart: # chart options + #width: 'auto' # number|string 'auto' Default width value + #height: 'auto' # number|string 'auto' Default height value + #minWidth: 0 # number 0 Minimum width value + #maxWidth: 0 # number 0 Minimum height value + #minHeight: Infinity # number Infinity Maximum width value + #maxHeight: Infinity # number Infinity Maximum height value - codeSyntaxHighlight - - colorSyntax + - colorSyntax: # colorSyntax options + #preset: ['#181818', '#292929'] # preset Array. Preset for color palette - tableMergedCell - - uml + - uml: # uml options + #rendererURL: ~ # string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer toolbar_items: [] dependencies: editor_dark_theme: # Must include if using 'dark' theme diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 9870528..8607fc0 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -154,11 +154,14 @@ public function renderExtensions($extensions, array $excludeList = []): string { $extsJsHtml = ""; $extsCssHtml = ""; - if (null !== $extensions) { - foreach ($extensions as $extKey => $extValue) { - if (in_array($extKey, $excludeList)) continue; - switch ($extValue) { + foreach ($extensions as $key => $extensionName) { + if (is_array($extensionName)) { + $extensionName = array_key_first($extensionName); + if (in_array($extensionName, $excludeList)) continue; + } + if (in_array($extensionName, $excludeList)) continue; + switch ($extensionName) { case 'colorSyntax': $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['colorSyntax']['tui_code_color_syntax_js_path']); $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['colorSyntax']['tui_code_color_syntax_css_path']); @@ -230,9 +233,15 @@ private function fixArrayToJs(array $array, array $excludeList = []): string return ""; } $jsArray = []; - foreach ($array as $key => $item) { - if (in_array($item, $excludeList)) continue; - array_push($jsArray, $item); + foreach ($array as $item) { + if (is_array($item)) { + $key = array_key_first($item); + if (in_array($key, $excludeList)) continue; + array_push($jsArray, '['.$key.','.json_encode($item[$key]).']'); + } else { + if (in_array($item, $excludeList)) continue; + array_push($jsArray, $item); + } } return implode(",", $jsArray); From 87114137d4a4dfa0d36d2c4b73468ec4a70e8dd4 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Tue, 9 Dec 2025 23:08:21 +0000 Subject: [PATCH 19/29] Update README, colorSyntax custom option for preset must be required, uml custom option for rendererURL must be required. Display example with default and custom options --- README.md | 13 ++++++++----- README_zh.md | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bc3006d..cc33fe8 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,8 @@ teebb_tui_editor: #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' extensions: # extensions must defined as array of plugin_name variable or {plugin_name, [plugin_options}} - - chart: # chart options + - chart # chart default + #- chart: # chart custom options #width: 'auto' # number|string 'auto' Default width value #height: 'auto' # number|string 'auto' Default height value #minWidth: 0 # number 0 Minimum width value @@ -108,11 +109,13 @@ teebb_tui_editor: #minHeight: Infinity # number Infinity Maximum width value #maxHeight: Infinity # number Infinity Maximum height value - codeSyntaxHighlight - - colorSyntax: # colorSyntax options - #preset: ['#181818', '#292929'] # preset Array. Preset for color palette + - colorSyntax # colorSyntax default + #- colorSyntax: # colorSyntax custom options + #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette - tableMergedCell - - uml: # uml options - #rendererURL: ~ # string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer + - uml # uml default + #- uml: # uml custom options + #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer toolbar_items: [] dependencies: editor_dark_theme: # Must include if using 'dark' theme diff --git a/README_zh.md b/README_zh.md index 1fcebe4..8d71901 100644 --- a/README_zh.md +++ b/README_zh.md @@ -96,7 +96,8 @@ teebb_tui_editor: #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' extensions: # extensions must defined as array of plugin_name variable or {plugin_name, {plugin_options}} - - chart: # chart options + - chart # chart default + #- chart: # chart custom options #width: 'auto' # number|string 'auto' Default width value #height: 'auto' # number|string 'auto' Default height value #minWidth: 0 # number 0 Minimum width value @@ -104,11 +105,13 @@ teebb_tui_editor: #minHeight: Infinity # number Infinity Maximum width value #maxHeight: Infinity # number Infinity Maximum height value - codeSyntaxHighlight - - colorSyntax: # colorSyntax options - #preset: ['#181818', '#292929'] # preset Array. Preset for color palette + - colorSyntax # colorSyntax default + #- colorSyntax: # colorSyntax custom options + #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette - tableMergedCell - - uml: # uml options - #rendererURL: ~ # string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer + - uml # uml default + #- uml: # uml custom options + #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer toolbar_items: [] dependencies: editor_dark_theme: # Must include if using 'dark' theme From 44fddc562f6bc87f4eab140f97295bcb61875b05 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Wed, 10 Dec 2025 16:49:40 +0000 Subject: [PATCH 20/29] Implement editor_options and viewer_options for configuration --- README.md | 22 +++++++++-- README_zh.md | 21 +++++++--- src/Config/TuiEditorConfiguration.php | 32 ++++++++-------- .../TuiEditorConfigurationInterface.php | 6 ++- src/DependencyInjection/Configuration.php | 27 ++++++++++--- src/Form/Type/TuiEditorType.php | 11 ++++-- src/Renderer/TuiEditorRenderer.php | 38 +++++++++---------- 7 files changed, 103 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index cc33fe8..59aff4a 100644 --- a/README.md +++ b/README.md @@ -91,14 +91,28 @@ teebb_tui_editor: # ... # more config options, you can see: bin/console debug:config teebb_tui_editor default_config: basic_config + #editor_options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ["heading"] + #viewer_options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' configs: basic_config: to_html: false # Save to database use html syntax? - #previewStyle: 'vertical' # Markdown editor's preview style (tab, vertical) - #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) - #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' + editor_options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ["heading"] + #viewer_options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' extensions: # extensions must defined as array of plugin_name variable or {plugin_name, [plugin_options}} - chart # chart default #- chart: # chart custom options diff --git a/README_zh.md b/README_zh.md index 8d71901..60ccfca 100644 --- a/README_zh.md +++ b/README_zh.md @@ -87,14 +87,26 @@ teebb_tui_editor: # ... # 更多配置使用命令: bin/console debug:config teebb_tui_editor 查看 default_config: basic_config + #editor_options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ["heading"] + #viewer_options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' configs: basic_config: to_html: false # Save to database use html syntax? - #previewStyle: 'vertical' # Markdown editor's preview style (tab, vertical) - #height: '400px' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - #initialEditType: 'markdown' # Initial editor type (markdown, wysiwyg) - #editor_theme_name: 'dark' # override editor color scheme with dark theme, default is 'light' + editor_options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ["heading"] extensions: # extensions must defined as array of plugin_name variable or {plugin_name, {plugin_options}} - chart # chart default #- chart: # chart custom options @@ -112,7 +124,6 @@ teebb_tui_editor: - uml # uml default #- uml: # uml custom options #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer - toolbar_items: [] dependencies: editor_dark_theme: # Must include if using 'dark' theme js_path: diff --git a/src/Config/TuiEditorConfiguration.php b/src/Config/TuiEditorConfiguration.php index 57b9d8c..bdda786 100644 --- a/src/Config/TuiEditorConfiguration.php +++ b/src/Config/TuiEditorConfiguration.php @@ -47,11 +47,6 @@ final class TuiEditorConfiguration implements TuiEditorConfigurationInterface */ private $editorContentsCssPath; - /** - * @var string - */ - private $editorThemeName; - /** * @var string */ @@ -70,7 +65,12 @@ final class TuiEditorConfiguration implements TuiEditorConfigurationInterface /** * @var array */ - private $toolbarItems; + private $editorOptions; + + /** + * @var array + */ + private $viewerOptions; /** * @var array @@ -101,11 +101,11 @@ public function __construct(array $config) $this->editorCssPath = $config['editor_css_path']; $this->viewerCssPath = $config['viewer_css_path']; $this->editorContentsCssPath = $config['editor_contents_css_path']; - $this->editorThemeName = $config['editor_theme_name']; $this->jqueryPath = $config['jquery_path']; $this->defaultConfig = $config['default_config']; $this->configs = $config['configs']; - $this->toolbarItems = $config['toolbar_items']; + $this->editorOptions = $config['editor_options']; + $this->viewerOptions = $config['viewer_options']; $this->extensions = $config['extensions']; $this->dependencies = $config['dependencies']; $this->assetRepository = $config['asset_repository']; @@ -175,11 +175,6 @@ public function getEditorContentsCssPath(): ?string return $this->editorContentsCssPath; } - public function getEditorThemeName(): string - { - return $this->editorThemeName; - } - public function getJqueryPath(): string { return $this->jqueryPath; @@ -195,9 +190,14 @@ public function getConfigs(): array return $this->configs; } - public function getToolbarItems(): array + public function getEditorOptions(): array + { + return $this->editorOptions; + } + + public function getViewerOptions(): array { - return $this->toolbarItems; + return $this->viewerOptions; } public function getExtensions(): array @@ -223,4 +223,4 @@ public function getConfig(string $name): array return $this->configs[$name]; } -} +} \ No newline at end of file diff --git a/src/Config/TuiEditorConfigurationInterface.php b/src/Config/TuiEditorConfigurationInterface.php index 3f251f7..75e5722 100644 --- a/src/Config/TuiEditorConfigurationInterface.php +++ b/src/Config/TuiEditorConfigurationInterface.php @@ -24,8 +24,6 @@ public function getEditorCssPath(): string; public function getEditorContentsCssPath(): ?string; - public function getEditorThemeName(): string; - public function getJqueryPath(): string; public function getDefaultConfig(): ?string; @@ -36,6 +34,10 @@ public function getExtensions(): array; public function getDependencies(): array; + public function getEditorOptions(): array; + + public function getViewerOptions(): array; + public function getAssetRepository(): string; /** diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index a38e92e..8bdcb5c 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -30,11 +30,11 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('editor_css_path')->defaultValue($bundleBasePath.'css/toastui-editor.css')->end() ->scalarNode('viewer_css_path')->defaultValue($bundleBasePath.'css/toastui-editor-viewer.css')->end() ->scalarNode('editor_contents_css_path')->defaultValue(null)->end() - ->scalarNode('editor_theme_name')->defaultValue('light')->end() ->scalarNode('jquery_path')->defaultValue($bundleBasePath.'js/jquery.min.js')->end() ->scalarNode('default_config')->defaultValue(null)->end() ->scalarNode('asset_repository')->defaultValue('teebbstudios/tui.editor-bundles')->end() - ->append($this->createToolbarItems()) + ->append($this->createEditorOptions()) + ->append($this->createViewerOptions()) ->append($this->createExtensions($bundleBasePath)) ->append($this->createDependencies($bundleBasePath)) ->append($this->createConfigsNode()) @@ -43,14 +43,31 @@ public function getConfigTreeBuilder(): TreeBuilder return $treeBuilder; } - private function createToolbarItems() + private function createEditorOptions() { - return $this->createNode("toolbar_items") + return $this->createNode('editor_options') ->addDefaultsIfNotSet() ->children() + ->arrayNode('toolbar_items') + ->prototype('scalar')->end() + ->defaultValue([['heading', 'bold', 'italic', 'strike'],['hr', 'quote'],['ul', 'ol', 'task', 'indent', 'outdent'],['table', 'image', 'link'],['code', 'codeblock']]) + ->end() + ->scalarNode('theme')->defaultValue('light')->end() + ->scalarNode('initial_edit_type')->defaultValue('markdown')->end() + ->scalarNode('preview_style')->defaultValue('vertical')->end() + ->scalarNode('height')->defaultValue('auto')->end() + ->end(); + } - ->end(); + private function createViewerOptions() + { + return $this->createNode('viewer_options') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('height')->defaultValue('auto')->end() + ->end(); } + private function createExtensions(string $bundleBasePath) { return $this->createNode('extensions') diff --git a/src/Form/Type/TuiEditorType.php b/src/Form/Type/TuiEditorType.php index e858493..45c5fbd 100644 --- a/src/Form/Type/TuiEditorType.php +++ b/src/Form/Type/TuiEditorType.php @@ -48,6 +48,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->setAttribute('editor_css_path', $options['editor_css_path']); $builder->setAttribute('viewer_css_path', $options['viewer_css_path']); $builder->setAttribute('editor_contents_css_path', $options['editor_contents_css_path']); + $builder->setAttribute('editor_options', $options['editor_options']); + $builder->setAttribute('viewer_options', $options['viewer_options']); $builder->setAttribute('jquery_path', $options['jquery_path']); $builder->setAttribute('config', $this->resolveConfig($options)); $builder->setAttribute('config_name', $options['config_name']); @@ -85,7 +87,8 @@ public function buildView(FormView $view, FormInterface $form, array $options): $view->vars['editor_css_path'] = $config->getAttribute('editor_css_path'); $view->vars['viewer_css_path'] = $config->getAttribute('viewer_css_path'); $view->vars['editor_contents_css_path'] = $config->getAttribute('editor_contents_css_path'); - $view->vars['editor_theme_name'] = $config->getAttribute('editor_theme_name'); + $view->vars['editor_options'] = $config->getAttribute('editor_options'); + $view->vars['viewer_options'] = $config->getAttribute('viewer_options'); $view->vars['jquery_path'] = $config->getAttribute('jquery_path'); $view->vars['config'] = $config->getAttribute('config'); $view->vars['extensions'] = $config->getAttribute('extensions'); @@ -107,7 +110,8 @@ public function configureOptions(OptionsResolver $resolver): void 'editor_css_path' => $this->configuration->getEditorCssPath(), 'viewer_css_path' => $this->configuration->getViewerCssPath(), 'editor_contents_css_path' => $this->configuration->getEditorContentsCssPath(), - 'editor_theme_name' => $this->configuration->getEditorThemeName(), + 'editor_options' => $this->configuration->getEditorOptions(), + 'viewer_options' => $this->configuration->getViewerOptions(), 'jquery_path' => $this->configuration->getJqueryPath(), 'config_name' => $this->configuration->getDefaultConfig(), 'config' => $this->configuration->getConfigs(), @@ -124,7 +128,8 @@ public function configureOptions(OptionsResolver $resolver): void ->addAllowedTypes('editor_css_path', 'string') ->addAllowedTypes('viewer_css_path', 'string') ->addAllowedTypes('editor_contents_css_path', ['string', 'null']) - ->addAllowedTypes('editor_theme_name', 'string') + ->addAllowedTypes('editor_options', 'array') + ->addAllowedTypes('viewer_options', 'array') ->addAllowedTypes('jquery_path', 'string') ->addAllowedTypes('config', 'array') ->addAllowedTypes('extensions', 'array') diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 8607fc0..7ed9386 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -195,9 +195,8 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = } $defaultConfig = $this->options['default_config']; - $extensions = $defaultConfig && array_key_exists('editor_theme_name', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['extensions']: $this->options['extensions']; - - $editorThemeName = $defaultConfig && array_key_exists('editor_theme_name', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['editor_theme_name']: $this->options['editor_theme_name']; + $extensions = $defaultConfig && array_key_exists('extensions', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['extensions']: $this->options['extensions']; + $viewerOptions = $defaultConfig && array_key_exists('viewer_options', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['viewer_options']: $this->options['viewer_options']; $viewerJsCode = $this->renderScriptBlock($viewerJsPath); $editorContentsCssCode = isset($this->options['editor_contents_css_path']) && null !== $this->options['editor_contents_css_path']? $this->renderStyleBlock($this->options['editor_contents_css_path']) : ''; @@ -210,18 +209,16 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = var content = %s; const viewer_%s = new Viewer({ el: document.querySelector("#%s"), - height: "%s", + height: %s, initialValue: content, - plugins: [%s], - theme: "%s" + plugins: [%s] }); ', $this->fixContentToJs($content), $id, $id, - "300px", - $this->fixArrayToJs($extensions, ["uml", "colorSyntax"]), - $editorThemeName + json_encode($viewerOptions['height']), + $this->fixArrayToJs($extensions, ["uml", "colorSyntax"]) ); return $viewerJsCode . $viewerCssCode. $editorContentsCssCode . $extsHtml . $viewerJsScript; @@ -296,8 +293,9 @@ private function getLanguage(): ?string public function renderEditor(string $id, array $config, string $content = null): string { $config = $this->fixConfigLanguage($config); + $extensions = array_key_exists('extensions', $config) ? $config['extensions']: $this->options['extensions']; - $editorThemeName = array_key_exists('editor_theme_name', $config) ? $config['editor_theme_name']: $this->options['editor_theme_name']; + $editorOptions = array_key_exists('editor_options', $config) ? $config['editor_options']: $this->options['editor_options']; $editorJsCode = $this->renderScriptBlock($this->options['editor_js_path']); $editorCssCode = $this->renderStyleBlock($this->options['editor_css_path']); @@ -310,24 +308,26 @@ public function renderEditor(string $id, array $config, string $content = null): var content = %s; const %s = new Editor({ el: document.querySelector("#%s"), - initialEditType: "%s", - previewStyle: "%s", - height: "%s", - language: "%s", + initialEditType: %s, + previewStyle: %s, + height: %s, + language: %s, initialValue: content, plugins: [%s], - theme: "%s" + theme: %s, + toolbarItems: %s }); ', $this->fixContentToJs($content), $id, $id, - array_key_exists('initialEditType', $config) ? $config['initialEditType'] : "markdown", - array_key_exists('previewStyle', $config) ? $config['previewStyle'] : "vertical", - array_key_exists('height', $config) ? $config['height'] : "300px", + json_encode($editorOptions['initial_edit_type']), + json_encode($editorOptions['preview_style']), + json_encode($editorOptions['height']), array_key_exists('language', $config) ? $config['language'] : $config['locale'], $this->fixArrayToJs($extensions), - $editorThemeName + json_encode($editorOptions['theme']), + json_encode($editorOptions['toolbar_items']) ); return $extsHtml . $editorJsCode . $editorCssCode . $editorContentsCssCode . $editorJsScript; From 9e271f708964634c4ed9b4df35dad20f02002fc3 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 11 Dec 2025 13:18:18 +0000 Subject: [PATCH 21/29] Overhaul js and css path loader, use array in Configuration --- README.md | 118 +++++++++++--- README_zh.md | 120 +++++++++++--- src/DependencyInjection/Configuration.php | 102 ++++++++++-- src/Renderer/TuiEditorRenderer.php | 184 +++++++++++++++------- 4 files changed, 402 insertions(+), 122 deletions(-) diff --git a/README.md b/README.md index 59aff4a..a0006fc 100644 --- a/README.md +++ b/README.md @@ -89,18 +89,62 @@ teebb_tui_editor: #editor_contents_css_path: ~ # Custom content css path. #asset_repository: 'teebbstudios/tui.editor-bundles' # Public assets installer repository # ... # more config options, you can see: bin/console debug:config teebb_tui_editor - - default_config: basic_config + #editor_options: #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) #theme: 'dark' # override editor color scheme with dark theme #toolbar_items: - #- ["heading"] + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] #viewer_options: #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] + #chart: # chart custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-chart-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-chart.min.css + #options: + #width: 'auto' # number|string 'auto' Default width value + #height: 'auto' # number|string 'auto' Default height value + #minWidth: 0 # number 0 Minimum width value + #maxWidth: 0 # number 0 Minimum height value + #minHeight: Infinity # number Infinity Maximum width value + #maxHeight: Infinity # number Infinity Maximum height value + #codeSyntaxHighlight: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-code-syntax-highlight-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-code-syntax-highlight.css + #colorSyntax: # colorSyntax custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-color-syntax-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-color-syntax.css + #- /bundles/teebbtuieditor/tui.editor-bundles/css/tui-color-picker.css + #options: + #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette + #tableMergedCell: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-table-merged-cell-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-table-merged-cell.css + #uml: # uml custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-uml-bundle.js + #options: + #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer + #dependencies: # You may add any dependancy that you need here + #editor_dark_theme: + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css + default_config: basic_config configs: basic_config: to_html: false # Save to database use html syntax? @@ -110,31 +154,53 @@ teebb_tui_editor: #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) #theme: 'dark' # override editor color scheme with dark theme #toolbar_items: - #- ["heading"] + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] #viewer_options: #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - extensions: # extensions must defined as array of plugin_name variable or {plugin_name, [plugin_options}} - - chart # chart default - #- chart: # chart custom options - #width: 'auto' # number|string 'auto' Default width value - #height: 'auto' # number|string 'auto' Default height value - #minWidth: 0 # number 0 Minimum width value - #maxWidth: 0 # number 0 Minimum height value - #minHeight: Infinity # number Infinity Maximum width value - #maxHeight: Infinity # number Infinity Maximum height value - - codeSyntaxHighlight - - colorSyntax # colorSyntax default - #- colorSyntax: # colorSyntax custom options - #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette - - tableMergedCell - - uml # uml default - #- uml: # uml custom options - #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer - toolbar_items: [] - dependencies: - editor_dark_theme: # Must include if using 'dark' theme - js_path: - css_path: /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css + extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] + chart: # chart custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-chart-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-chart.min.css + #options: + #width: 'auto' # number|string 'auto' Default width value + #height: 'auto' # number|string 'auto' Default height value + #minWidth: 0 # number 0 Minimum width value + #maxWidth: 0 # number 0 Minimum height value + #minHeight: Infinity # number Infinity Maximum width value + #maxHeight: Infinity # number Infinity Maximum height value + codeSyntaxHighlight: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-code-syntax-highlight-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-code-syntax-highlight.css + colorSyntax: # colorSyntax custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-color-syntax-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-color-syntax.css + #- /bundles/teebbtuieditor/tui.editor-bundles/css/tui-color-picker.css + #options: + #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette + tableMergedCell: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-table-merged-cell-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-table-merged-cell.css + uml: # uml custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-uml-bundle.js + #options: + #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer + #dependencies: # You may add any dependancy that you need here + #editor_dark_theme: # Must include if using 'dark' theme + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css ``` diff --git a/README_zh.md b/README_zh.md index 60ccfca..f2ebb99 100644 --- a/README_zh.md +++ b/README_zh.md @@ -85,18 +85,61 @@ teebb_tui_editor: #editor_contents_css_path: ~ # Custom content css path. #asset_repository: 'teebbstudios/tui.editor-bundles' # Public assets installer repository # ... # 更多配置使用命令: bin/console debug:config teebb_tui_editor 查看 - - default_config: basic_config + #editor_options: #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) #theme: 'dark' # override editor color scheme with dark theme #toolbar_items: - #- ["heading"] + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] #viewer_options: #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - + #extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] + #chart: # chart custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-chart-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-chart.min.css + #options: + #width: 'auto' # number|string 'auto' Default width value + #height: 'auto' # number|string 'auto' Default height value + #minWidth: 0 # number 0 Minimum width value + #maxWidth: 0 # number 0 Minimum height value + #minHeight: Infinity # number Infinity Maximum width value + #maxHeight: Infinity # number Infinity Maximum height value + #codeSyntaxHighlight: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-code-syntax-highlight-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-code-syntax-highlight.css + #colorSyntax: # colorSyntax custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-color-syntax-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-color-syntax.css + #- /bundles/teebbtuieditor/tui.editor-bundles/css/tui-color-picker.css + #options: + #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette + #tableMergedCell: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-table-merged-cell-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-table-merged-cell.css + #uml: # uml custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-uml-bundle.js + #options: + #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer + #dependencies: # You may add any dependancy that you need here + #editor_dark_theme: + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css + default_config: basic_config configs: basic_config: to_html: false # Save to database use html syntax? @@ -106,28 +149,53 @@ teebb_tui_editor: #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) #theme: 'dark' # override editor color scheme with dark theme #toolbar_items: - #- ["heading"] - extensions: # extensions must defined as array of plugin_name variable or {plugin_name, {plugin_options}} - - chart # chart default - #- chart: # chart custom options - #width: 'auto' # number|string 'auto' Default width value - #height: 'auto' # number|string 'auto' Default height value - #minWidth: 0 # number 0 Minimum width value - #maxWidth: 0 # number 0 Minimum height value - #minHeight: Infinity # number Infinity Maximum width value - #maxHeight: Infinity # number Infinity Maximum height value - - codeSyntaxHighlight - - colorSyntax # colorSyntax default - #- colorSyntax: # colorSyntax custom options - #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette - - tableMergedCell - - uml # uml default - #- uml: # uml custom options - #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer - dependencies: - editor_dark_theme: # Must include if using 'dark' theme - js_path: - css_path: /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] + #viewer_options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] + chart: # chart custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-chart-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-chart.min.css + #options: + #width: 'auto' # number|string 'auto' Default width value + #height: 'auto' # number|string 'auto' Default height value + #minWidth: 0 # number 0 Minimum width value + #maxWidth: 0 # number 0 Minimum height value + #minHeight: Infinity # number Infinity Maximum width value + #maxHeight: Infinity # number Infinity Maximum height value + codeSyntaxHighlight: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-code-syntax-highlight-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-code-syntax-highlight.css + colorSyntax: # colorSyntax custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-color-syntax-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-color-syntax.css + #- /bundles/teebbtuieditor/tui.editor-bundles/css/tui-color-picker.css + #options: + #preset: ['#181818', '#292929'] # [required] preset Array. Preset for color palette + tableMergedCell: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-table-merged-cell-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-plugin-table-merged-cell.css + uml: # uml custom options + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-uml-bundle.js + #options: + #rendererURL: ~ # [required]string 'http://www.plantuml.com/plantuml/png/' URL of plant uml renderer + #dependencies: # You may add any dependancy that you need here + #editor_dark_theme: # Must include if using 'dark' theme + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-dark.css ``` diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8bdcb5c..fcb0bcb 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -49,8 +49,11 @@ private function createEditorOptions() ->addDefaultsIfNotSet() ->children() ->arrayNode('toolbar_items') - ->prototype('scalar')->end() ->defaultValue([['heading', 'bold', 'italic', 'strike'],['hr', 'quote'],['ul', 'ol', 'task', 'indent', 'outdent'],['table', 'image', 'link'],['code', 'codeblock']]) + ->arrayPrototype() + ->scalarPrototype() + ->end() + ->end() ->end() ->scalarNode('theme')->defaultValue('light')->end() ->scalarNode('initial_edit_type')->defaultValue('markdown')->end() @@ -76,36 +79,101 @@ private function createExtensions(string $bundleBasePath) ->arrayNode('colorSyntax') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_code_color_syntax_js_path')->defaultValue($bundleBasePath.'js/toast-ui-color-syntax-bundle.js')->end() - ->scalarNode('tui_code_color_syntax_css_path')->defaultValue($bundleBasePath.'css/toastui-editor-plugin-color-syntax.css')->end() - ->scalarNode('tui_code_color_picker_css_path')->defaultValue($bundleBasePath.'css/tui-color-picker.css')->end() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-color-syntax-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor-plugin-color-syntax.css',$bundleBasePath.'css/tui-color-picker.css']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->defaultValue(null) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() ->arrayNode('chart') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_chart_js_path')->defaultValue($bundleBasePath.'js/toast-ui-chart-bundle.js')->end() - ->scalarNode('tui_chart_css_path')->defaultValue($bundleBasePath.'css/toastui-chart.min.css')->end() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-chart-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-chart.min.css']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->defaultValue(null) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() ->arrayNode('codeSyntaxHighlight') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_code_syntax_highlight_js_path')->defaultValue($bundleBasePath.'js/toast-ui-code-syntax-highlight-bundle.js')->end() - ->scalarNode('tui_code_syntax_highlight_css_path')->defaultValue($bundleBasePath.'css/toastui-editor-plugin-code-syntax-highlight.css')->end() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-code-syntax-highlight-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor-plugin-code-syntax-highlight.css']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->defaultValue(null) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() ->arrayNode('tableMergedCell') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_table_merged_cell_js_path')->defaultValue($bundleBasePath.'js/toast-ui-table-merged-cell-bundle.js')->end() - ->scalarNode('tui_table_merged_cell_css_path')->defaultValue($bundleBasePath.'css/toastui-editor-plugin-table-merged-cell.css')->end() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-table-merged-cell-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor-plugin-table-merged-cell.css']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->defaultValue(null) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() ->arrayNode('uml') ->addDefaultsIfNotSet() ->children() - ->scalarNode('tui_uml_js_path')->defaultValue($bundleBasePath.'js/toast-ui-uml-bundle.js')->end() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-uml-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue(null) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->defaultValue(null) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() ->end(); @@ -119,8 +187,16 @@ private function createDependencies($bundleBasePath) ->arrayNode('editor_dark_theme') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue($bundleBasePath.'css/toastui-editor-dark.css')->end() + ->arrayNode('js_paths') + ->defaultValue(null) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor-dark.css']) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() ->end(); diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 7ed9386..11fdff4 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -114,14 +114,7 @@ public function renderEditorContentsCssPath(string $editorContentsCssPath = null public function renderDependencies(array $dependencies = null): string { - if ($dependencies === null) { - if ($this->options['default_config']) { - $dependencies = $this->options['configs'][$this->options['default_config']]['dependencies']; - } - if ($dependencies === null) { - $dependencies = $this->options['dependencies']; - } - } + $dependencies = $this->getOption(null, 'dependencies', $dependencies, $this->options, true); $dependenciesJsHtml = ""; $dependenciesCssHtml = ""; @@ -129,12 +122,20 @@ public function renderDependencies(array $dependencies = null): string if ($this->options['jquery']) { $dependenciesJsHtml .= $this->renderScriptBlock($this->options['jquery_path']); } - foreach ($dependencies as $dependency) { - if ($dependency['js_path'] !== null) { - $dependenciesJsHtml .= $this->renderScriptBlock($dependency['js_path']); + foreach ($dependencies as $dependencyName => $dependencyConfigs) { + if (is_array($dependencyConfigs) && array_key_exists('js_paths',$dependencyConfigs)) { + $dependenciesJsHtml .= $this->retrieveJsPathToHtml($dependencyConfigs['js_paths']); + } else { + // Find default + $dependencyFindDefault = $this->getOptionForParent('js_paths', $dependencyName, 'dependencies', $dependencies, $this->options, true); + $dependenciesJsHtml .= $this->retrieveJsPathToHtml($dependencyFindDefault); } - if ($dependency['css_path'] !== null) { - $dependenciesCssHtml .= $this->renderStyleBlock($dependency['css_path']); + if (is_array($dependencyConfigs) && array_key_exists('css_paths',$dependencyConfigs)) { + $dependenciesCssHtml .= $this->retrieveCssPathToHtml($dependencyConfigs['css_paths']); + } else { + // Find default + $dependencyFindDefault = $this->getOptionForParent('css_paths', $dependencyName, 'dependencies', $dependencies, $this->options, true); + $dependenciesCssHtml .= $this->retrieveCssPathToHtml($dependencyFindDefault); } } return $dependenciesJsHtml . $dependenciesCssHtml; @@ -150,38 +151,51 @@ public function renderStyleBlock(string $path): string return sprintf('', $this->fixPath($path)); } + private function retrieveJsPathToHtml(?array $paths) { + $html = ''; + if ($paths && is_array($paths)) { + foreach ($paths as $path) { + if ($path) { + $html .= $this->renderScriptBlock($path); + } + } + } + return $html; + } + + private function retrieveCssPathToHtml(?array $paths) { + $html = ''; + if ($paths && is_array($paths)) { + foreach ($paths as $path) { + if ($path) { + $html .= $this->renderStyleBlock($path); + } + } + } + return $html; + } + public function renderExtensions($extensions, array $excludeList = []): string { $extsJsHtml = ""; $extsCssHtml = ""; if (null !== $extensions) { - foreach ($extensions as $key => $extensionName) { - if (is_array($extensionName)) { - $extensionName = array_key_first($extensionName); - if (in_array($extensionName, $excludeList)) continue; - } + foreach ($extensions as $extensionName => $extensionConfigs) { if (in_array($extensionName, $excludeList)) continue; - switch ($extensionName) { - case 'colorSyntax': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['colorSyntax']['tui_code_color_syntax_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['colorSyntax']['tui_code_color_syntax_css_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['colorSyntax']['tui_code_color_picker_css_path']); - break; - case 'chart': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['chart']['tui_chart_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['chart']['tui_chart_css_path']); - break; - case 'codeSyntaxHighlight': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['codeSyntaxHighlight']['tui_code_syntax_highlight_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['codeSyntaxHighlight']['tui_code_syntax_highlight_css_path']); - break; - case 'tableMergedCell': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['tableMergedCell']['tui_table_merged_cell_js_path']); - $extsCssHtml .= $this->renderStyleBlock($this->options['extensions']['tableMergedCell']['tui_table_merged_cell_css_path']); - break; - case 'uml': - $extsJsHtml .= $this->renderScriptBlock($this->options['extensions']['uml']['tui_uml_js_path']); - break; + + if (is_array($extensionConfigs) && array_key_exists('js_paths',$extensionConfigs)) { + $extsJsHtml .= $this->retrieveJsPathToHtml($extensionConfigs['js_paths']); + } else { + // Find default + $extensionFindDefault = $this->getOptionForParent('js_paths', $extensionName, 'extensions', $extensionConfigs, $this->options, true); + $extsJsHtml .= $this->retrieveJsPathToHtml($extensionFindDefault); + } + if (is_array($extensionConfigs) && array_key_exists('css_paths',$extensionConfigs)) { + $extsCssHtml .= $this->retrieveCssPathToHtml($extensionConfigs['css_paths']); + } else { + // Find default + $extensionFindDefault = $this->getOptionForParent('css_paths', $extensionName, 'extensions', $extensionConfigs, $this->options, true); + $extsCssHtml .= $this->retrieveCssPathToHtml($extensionFindDefault); } } } @@ -195,9 +209,7 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = } $defaultConfig = $this->options['default_config']; - $extensions = $defaultConfig && array_key_exists('extensions', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['extensions']: $this->options['extensions']; - $viewerOptions = $defaultConfig && array_key_exists('viewer_options', $this->options['configs'][$defaultConfig]) ? $this->options['configs'][$defaultConfig]['viewer_options']: $this->options['viewer_options']; - + $extensions = $this->getOption(null, 'extensions', null, $this->options, true); $viewerJsCode = $this->renderScriptBlock($viewerJsPath); $editorContentsCssCode = isset($this->options['editor_contents_css_path']) && null !== $this->options['editor_contents_css_path']? $this->renderStyleBlock($this->options['editor_contents_css_path']) : ''; $viewerCssCode = $this->renderStyleBlock($this->options['viewer_css_path']); @@ -217,7 +229,7 @@ public function renderViewer(string $id, string $content, string $viewerJsPath = $this->fixContentToJs($content), $id, $id, - json_encode($viewerOptions['height']), + $this->getOptionAsJson('height', 'viewer_options', false, $this->options, true), $this->fixArrayToJs($extensions, ["uml", "colorSyntax"]) ); @@ -230,14 +242,18 @@ private function fixArrayToJs(array $array, array $excludeList = []): string return ""; } $jsArray = []; - foreach ($array as $item) { + foreach ($array as $key=>$item) { + if (in_array($key, $excludeList)) continue; + $options = null; if (is_array($item)) { - $key = array_key_first($item); - if (in_array($key, $excludeList)) continue; - array_push($jsArray, '['.$key.','.json_encode($item[$key]).']'); + if (array_key_exists('options', $item)) { + $options = $item['options']; + } + } + if ($options) { + array_push($jsArray, '['.$key.','.json_encode($item['options']).']'); } else { - if (in_array($item, $excludeList)) continue; - array_push($jsArray, $item); + array_push($jsArray, $key); } } @@ -290,12 +306,66 @@ private function getLanguage(): ?string return $this->locale; } + private function getOptionAsJson($key, $keyOption, $userPreferenceConfig, $config, $checkDefaultConfig = false): ?string + { + return json_encode($this->getOption($key, $keyOption, $userPreferenceConfig, $config, $checkDefaultConfig)); + } + + private function getOption($key, $keyOption, $userPreferenceConfig, $config, $checkDefaultConfig = false) + { + if (empty($key)) { + if (is_array($userPreferenceConfig) && array_key_exists($keyOption, $userPreferenceConfig)) { + return $userPreferenceConfig[$keyOption]; + } else { + if ($checkDefaultConfig) { + $defaultConfig = $config['default_config']; + return $this->getOption($key, $keyOption,$defaultConfig && array_key_exists($defaultConfig, $config['configs']) ? $config['configs'][$defaultConfig]: null, $config); + } else { + return $config[$keyOption]; + } + } + } else if (is_array($userPreferenceConfig) && array_key_exists($keyOption, $userPreferenceConfig) && is_array($userPreferenceConfig[$keyOption]) && array_key_exists($key, $userPreferenceConfig[$keyOption])) { + return $userPreferenceConfig[$keyOption][$key]; + } else { + if ($checkDefaultConfig) { + $defaultConfig = $config['default_config']; + return $this->getOption($key, $keyOption,$defaultConfig && array_key_exists($defaultConfig, $config['configs']) ? $config['configs'][$defaultConfig]: null, $config); + } else { + return $config[$keyOption][$key]; + } + } + } + + private function getOptionForParent($key, $keyOption, $keyParent, $userPreferenceConfig, $config, $checkDefaultConfig = false) + { + if (empty($key)) { + if (is_array($userPreferenceConfig) && array_key_exists($keyOption, $userPreferenceConfig)) { + return $userPreferenceConfig[$keyOption]; + } else { + if ($checkDefaultConfig) { + $defaultConfig = $config['default_config']; + return $this->getOption($key, $keyOption,$defaultConfig && array_key_exists($defaultConfig, $config['configs']) ? $config['configs'][$defaultConfig][$keyParent]: null, $config[$keyParent]); + } else { + return $config[$keyParent][$keyOption]; + } + } + } else if (is_array($userPreferenceConfig) && array_key_exists($keyOption, $userPreferenceConfig) && is_array($userPreferenceConfig[$keyOption]) && array_key_exists($key, $userPreferenceConfig[$keyOption])) { + return $userPreferenceConfig[$keyOption][$key]; + } else { + if ($checkDefaultConfig) { + $defaultConfig = $config['default_config']; + return $this->getOption($key, $keyOption,$defaultConfig && array_key_exists($defaultConfig, $config['configs']) ? $config['configs'][$defaultConfig][$keyParent]: null, $config[$keyParent]); + } else { + return $config[$keyParent][$keyOption][$key]; + } + } + } + public function renderEditor(string $id, array $config, string $content = null): string { $config = $this->fixConfigLanguage($config); - $extensions = array_key_exists('extensions', $config) ? $config['extensions']: $this->options['extensions']; - $editorOptions = array_key_exists('editor_options', $config) ? $config['editor_options']: $this->options['editor_options']; + $extensions = $this->getOption(null, 'extensions', $config, $this->options, true); $editorJsCode = $this->renderScriptBlock($this->options['editor_js_path']); $editorCssCode = $this->renderStyleBlock($this->options['editor_css_path']); @@ -311,7 +381,7 @@ public function renderEditor(string $id, array $config, string $content = null): initialEditType: %s, previewStyle: %s, height: %s, - language: %s, + language: "%s", initialValue: content, plugins: [%s], theme: %s, @@ -321,13 +391,13 @@ public function renderEditor(string $id, array $config, string $content = null): $this->fixContentToJs($content), $id, $id, - json_encode($editorOptions['initial_edit_type']), - json_encode($editorOptions['preview_style']), - json_encode($editorOptions['height']), + $this->getOptionAsJson('initial_edit_type', 'editor_options', $config, $this->options, true), + $this->getOptionAsJson('preview_style', 'editor_options', $config, $this->options, true), + $this->getOptionAsJson('height', 'editor_options', $config, $this->options, true), array_key_exists('language', $config) ? $config['language'] : $config['locale'], $this->fixArrayToJs($extensions), - json_encode($editorOptions['theme']), - json_encode($editorOptions['toolbar_items']) + $this->getOptionAsJson('theme', 'editor_options', $config, $this->options, true), + $this->getOptionAsJson('toolbar_items', 'editor_options', $config, $this->options, true) ); return $extsHtml . $editorJsCode . $editorCssCode . $editorContentsCssCode . $editorJsScript; From 9b390ef4530fb382eeb7aa702b1699917c717c45 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 11 Dec 2025 13:47:18 +0000 Subject: [PATCH 22/29] Allow support for backwards compatibility for PHP 7 and 8, and Symfony 3.4 to 7 --- composer.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 07cb304..2fb3d43 100644 --- a/composer.json +++ b/composer.json @@ -14,20 +14,20 @@ } ], "require": { - "php": "^8.1", + "php": "^7.1 || ^8.0", "ext-zip": "*", - "symfony/asset": "^6.4 || ^7.4", - "symfony/config": "^6.4 || ^7.4", - "symfony/dependency-injection": "^6.4 || ^7.4", - "symfony/expression-language": "^6.4 || ^7.4", - "symfony/form": "^6.4 || ^7.4", - "symfony/framework-bundle": "^6.4 || ^7.4", - "symfony/http-foundation": "^6.4 || ^7.4", - "symfony/http-kernel": "^6.4 || ^7.4", - "symfony/options-resolver": "^6.4 || ^7.4", - "symfony/property-access": "^6.4 || ^7.4", - "symfony/routing": "^6.4 || ^7.4", - "symfony/twig-bundle": "^6.4 || ^7.4", + "symfony/asset": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/config": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/expression-language": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/form": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/http-foundation": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/http-kernel": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/options-resolver": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/property-access": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/routing": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", "twig/twig": "^2.12|^3.0" }, "autoload": { From a27c83212abed43d7e7495791714c52e411da3c7 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 11 Dec 2025 13:55:48 +0000 Subject: [PATCH 23/29] Provide empty Array for expected Array type --- src/DependencyInjection/Configuration.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index fcb0bcb..2ab00b0 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -90,7 +90,7 @@ private function createExtensions(string $bundleBasePath) ->end() ->end() ->arrayNode('options') - ->defaultValue(null) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() @@ -110,7 +110,7 @@ private function createExtensions(string $bundleBasePath) ->end() ->end() ->arrayNode('options') - ->defaultValue(null) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() @@ -130,7 +130,7 @@ private function createExtensions(string $bundleBasePath) ->end() ->end() ->arrayNode('options') - ->defaultValue(null) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() @@ -150,7 +150,7 @@ private function createExtensions(string $bundleBasePath) ->end() ->end() ->arrayNode('options') - ->defaultValue(null) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() @@ -165,12 +165,12 @@ private function createExtensions(string $bundleBasePath) ->end() ->end() ->arrayNode('css_paths') - ->defaultValue(null) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() ->arrayNode('options') - ->defaultValue(null) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() @@ -188,7 +188,7 @@ private function createDependencies($bundleBasePath) ->addDefaultsIfNotSet() ->children() ->arrayNode('js_paths') - ->defaultValue(null) + ->defaultValue([]) ->scalarPrototype() ->end() ->end() From ce760f0576b658acf5be9713f63e76212a1069ae Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 11 Dec 2025 14:03:52 +0000 Subject: [PATCH 24/29] Support up to Symfony 6 --- composer.json | 24 ++++++++++++------------ src/Command/TuiEditorDownloadCommand.php | 8 +------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 2fb3d43..62ae96b 100644 --- a/composer.json +++ b/composer.json @@ -16,18 +16,18 @@ "require": { "php": "^7.1 || ^8.0", "ext-zip": "*", - "symfony/asset": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/config": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/expression-language": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/form": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/http-foundation": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/http-kernel": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/options-resolver": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/property-access": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/routing": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", - "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/asset": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/config": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/expression-language": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/form": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/http-foundation": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/http-kernel": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/options-resolver": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/property-access": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/routing": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0", "twig/twig": "^2.12|^3.0" }, "autoload": { diff --git a/src/Command/TuiEditorDownloadCommand.php b/src/Command/TuiEditorDownloadCommand.php index 9b0a227..7fba669 100644 --- a/src/Command/TuiEditorDownloadCommand.php +++ b/src/Command/TuiEditorDownloadCommand.php @@ -13,10 +13,6 @@ use Symfony\Component\Console\Question\ChoiceQuestion; use Teebb\TuiEditorBundle\Installer\TuiEditorInstaller; -#[AsCommand( - name: TuiEditorDownloadCommand::defaultName, - description: 'Download the lastest tui.editor with all the required libraries.', -)] class TuiEditorDownloadCommand extends Command { protected static $defaultName = 'tuieditor:install'; @@ -58,7 +54,7 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function execute(InputInterface $input, OutputInterface $output) { $this->title($output); @@ -69,10 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($success) { $this->success('tui.editor has been successfully installed...', $output); - return Command::SUCCESS; } else { $this->info('tui.editor installation has been skipped...', $output); - return Command::INVALID; } } From 1077d3df13cacaa42fcc685dd7d128d68985ce2c Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Thu, 11 Dec 2025 14:08:31 +0000 Subject: [PATCH 25/29] Support Symfony 7 --- composer.json | 24 ++++++++++++------------ src/Command/TuiEditorDownloadCommand.php | 8 +++++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 62ae96b..88653fb 100644 --- a/composer.json +++ b/composer.json @@ -16,18 +16,18 @@ "require": { "php": "^7.1 || ^8.0", "ext-zip": "*", - "symfony/asset": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/config": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/expression-language": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/form": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/http-foundation": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/http-kernel": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/options-resolver": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/property-access": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/routing": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/asset": "^7.0", + "symfony/config": "^7.0", + "symfony/dependency-injection": "^7.0", + "symfony/expression-language": "^7.0", + "symfony/form": "^7.0", + "symfony/framework-bundle": "^7.0", + "symfony/http-foundation": "^7.0", + "symfony/http-kernel": "^7.0", + "symfony/options-resolver": "^7.0", + "symfony/property-access": "^7.0", + "symfony/routing": "^7.0", + "symfony/twig-bundle": "^7.0", "twig/twig": "^2.12|^3.0" }, "autoload": { diff --git a/src/Command/TuiEditorDownloadCommand.php b/src/Command/TuiEditorDownloadCommand.php index 7fba669..9b0a227 100644 --- a/src/Command/TuiEditorDownloadCommand.php +++ b/src/Command/TuiEditorDownloadCommand.php @@ -13,6 +13,10 @@ use Symfony\Component\Console\Question\ChoiceQuestion; use Teebb\TuiEditorBundle\Installer\TuiEditorInstaller; +#[AsCommand( + name: TuiEditorDownloadCommand::defaultName, + description: 'Download the lastest tui.editor with all the required libraries.', +)] class TuiEditorDownloadCommand extends Command { protected static $defaultName = 'tuieditor:install'; @@ -54,7 +58,7 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->title($output); @@ -65,8 +69,10 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($success) { $this->success('tui.editor has been successfully installed...', $output); + return Command::SUCCESS; } else { $this->info('tui.editor installation has been skipped...', $output); + return Command::INVALID; } } From 28c0796379b40946d625e6bef76b0cf1f50abb6f Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Fri, 12 Dec 2025 14:36:00 +0000 Subject: [PATCH 26/29] Remove unnecessary functions --- README.md | 83 ++++--- README_zh.md | 87 +++++--- src/Config/TuiEditorConfiguration.php | 97 ++------ .../TuiEditorConfigurationInterface.php | 18 +- src/DependencyInjection/Configuration.php | 94 ++++++-- src/Form/Type/TuiEditorType.php | 49 +---- src/Renderer/TuiEditorRenderer.php | 208 ++++++++---------- src/Renderer/TuiEditorRendererInterface.php | 17 +- .../views/Form/tuieditor_widget.html.twig | 4 +- src/Twig/TuiEditorExtension.php | 43 +--- 10 files changed, 301 insertions(+), 399 deletions(-) diff --git a/README.md b/README.md index a0006fc..0efbe3a 100644 --- a/README.md +++ b/README.md @@ -80,29 +80,36 @@ You can add a config file in `config/packages` folder.(Just a simple config, B #config/packages/teebb_tuieditor.yaml teebb_tui_editor: #enable: true # Whether to enable tui.editor. - #jquery: true # Whether to enable jquery in dependencies. - #jquery_path: ~ # Custom jquery path. - #editor_js_path: ~ # Custom tui.editor js path. - #viewer_js_path: ~ # Custom tui.viewer js path. - #editor_css_path: ~ # Custom tui.editor css path. - #viewer_css_path: ~ # Custom tui.viewer css path. - #editor_contents_css_path: ~ # Custom content css path. + #jquery: + #enable: false # Whether to enable jquery. + #js_paths: # Custom jquery path. + #- /bundles/teebbtuieditor/tui.editor-bundles/js/jquery.min.js #asset_repository: 'teebbstudios/tui.editor-bundles' # Public assets installer repository # ... # more config options, you can see: bin/console debug:config teebb_tui_editor - #editor_options: - #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) - #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) - #theme: 'dark' # override editor color scheme with dark theme - #toolbar_items: - #- ['heading', 'bold', 'italic', 'strike'] - #- ['hr', 'quote'] - #- ['ul', 'ol', 'task', 'indent', 'outdent'] - #- ['table', 'image', 'link'] - #- ['code', 'codeblock'] - #viewer_options: - #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #editor: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-editor-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor.css + #options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] + #viewer: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-viewer-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-viewer.css + #options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] #chart: # chart custom options #js_paths: @@ -148,19 +155,29 @@ teebb_tui_editor: configs: basic_config: to_html: false # Save to database use html syntax? - editor_options: - #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) - #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) - #theme: 'dark' # override editor color scheme with dark theme - #toolbar_items: - #- ['heading', 'bold', 'italic', 'strike'] - #- ['hr', 'quote'] - #- ['ul', 'ol', 'task', 'indent', 'outdent'] - #- ['table', 'image', 'link'] - #- ['code', 'codeblock'] - #viewer_options: - #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #editor: + #js_paths: + - /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-editor-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor.css + #options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] + #viewer: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-viewer-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-viewer.css + #options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] chart: # chart custom options #js_paths: diff --git a/README_zh.md b/README_zh.md index f2ebb99..420d606 100644 --- a/README_zh.md +++ b/README_zh.md @@ -76,29 +76,36 @@ $ php bin/console assets:install --symlink #config/packages/teebb_tuieditor.yaml teebb_tui_editor: #enable: true # 是否启用tui.editor - #jquery: true # 是否使用jquery, 如果您的项目中使用过jquery,可以设置为false,避免重复引入jquery - #jquery_path: ~ # 自定义jquery路径. - #editor_js_path: ~ # 自定义editor js 路径 - #viewer_js_path: ~ # Custom tui.viewer js path. - #editor_css_path: ~ # Custom tui.editor css path. - #viewer_css_path: ~ # Custom tui.viewer css path. - #editor_contents_css_path: ~ # Custom content css path. + #jquery: + #enable: true # 是否使用jquery, 如果您的项目中使用过jquery,可以设置为false,避免重复引入jquery + #js_paths: # 自定义jquery路径. + #- /bundles/teebbtuieditor/tui.editor-bundles/js/jquery.min.js #asset_repository: 'teebbstudios/tui.editor-bundles' # Public assets installer repository # ... # 更多配置使用命令: bin/console debug:config teebb_tui_editor 查看 - #editor_options: - #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) - #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) - #theme: 'dark' # override editor color scheme with dark theme - #toolbar_items: - #- ['heading', 'bold', 'italic', 'strike'] - #- ['hr', 'quote'] - #- ['ul', 'ol', 'task', 'indent', 'outdent'] - #- ['table', 'image', 'link'] - #- ['code', 'codeblock'] - #viewer_options: - #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #editor: + #js_paths: # 自定义editor js 路径 + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-editor-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor.css + #options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] + #viewer: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-viewer-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-viewer.css + #options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' #extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] #chart: # chart custom options #js_paths: @@ -143,21 +150,31 @@ teebb_tui_editor: configs: basic_config: to_html: false # Save to database use html syntax? - editor_options: - #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) - #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) - #theme: 'dark' # override editor color scheme with dark theme - #toolbar_items: - #- ['heading', 'bold', 'italic', 'strike'] - #- ['hr', 'quote'] - #- ['ul', 'ol', 'task', 'indent', 'outdent'] - #- ['table', 'image', 'link'] - #- ['code', 'codeblock'] - #viewer_options: - #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' - extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] - chart: # chart custom options + editor: + #js_paths: # 自定义editor js 路径 + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-editor-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor.css + #options: + #height: 'auto' # Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + #initial_edit_type: 'wysiwyg' # Initial editor type (markdown, wysiwyg) + #preview_style: 'vertical' # Markdown editor's preview style (tab, vertical) + #theme: 'dark' # override editor color scheme with dark theme + #toolbar_items: + #- ['heading', 'bold', 'italic', 'strike'] + #- ['hr', 'quote'] + #- ['ul', 'ol', 'task', 'indent', 'outdent'] + #- ['table', 'image', 'link'] + #- ['code', 'codeblock'] + #viewer: + #js_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-viewer-bundle.js + #css_paths: + #- /bundles/teebbtuieditor/tui.editor-bundles/css/toastui-editor-viewer.css + #options: + #height: 'auto' # Viewer's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' + extensions: # extensions must defined as array of plugin_name variable or [plugin_name, [plugin_options]] + chart: # chart custom options #js_paths: #- /bundles/teebbtuieditor/tui.editor-bundles/js/toast-ui-chart-bundle.js #css_paths: diff --git a/src/Config/TuiEditorConfiguration.php b/src/Config/TuiEditorConfiguration.php index bdda786..548c642 100644 --- a/src/Config/TuiEditorConfiguration.php +++ b/src/Config/TuiEditorConfiguration.php @@ -17,60 +17,35 @@ final class TuiEditorConfiguration implements TuiEditorConfigurationInterface */ private $toHtml; - /** - * @var boolean - */ - private $jquery; - /** * @var string */ private $basePath; - /** - * @var string - */ - private $editorJsPath; - - /** - * @var string - */ - private $viewerJsPath; - - /** - * @var string - */ - private $editorCssPath; - /** * @var string|null */ - private $editorContentsCssPath; - - /** - * @var string - */ - private $jqueryPath; + private $defaultConfig; /** - * @var string|null + * @var array */ - private $defaultConfig; + private $configs; /** * @var array */ - private $configs; + private $jquery; /** * @var array */ - private $editorOptions; + private $editor; /** * @var array */ - private $viewerOptions; + private $viewer; /** * @var array @@ -94,18 +69,12 @@ public function __construct(array $config) } $this->enable = $config['enable']; - $this->jquery = $config['jquery']; $this->basePath = $config['base_path']; - $this->editorJsPath = $config['editor_js_path']; - $this->viewerJsPath = $config['viewer_js_path']; - $this->editorCssPath = $config['editor_css_path']; - $this->viewerCssPath = $config['viewer_css_path']; - $this->editorContentsCssPath = $config['editor_contents_css_path']; - $this->jqueryPath = $config['jquery_path']; $this->defaultConfig = $config['default_config']; $this->configs = $config['configs']; - $this->editorOptions = $config['editor_options']; - $this->viewerOptions = $config['viewer_options']; + $this->jquery = $config['jquery']; + $this->editor = $config['editor']; + $this->viewer = $config['viewer']; $this->extensions = $config['extensions']; $this->dependencies = $config['dependencies']; $this->assetRepository = $config['asset_repository']; @@ -140,46 +109,11 @@ public function isToHtml(): bool return $this->toHtml; } - public function isJquery(): bool - { - return $this->jquery; - } - public function getBasePath(): string { return $this->basePath; } - public function getEditorJsPath(): string - { - return $this->editorJsPath; - } - - public function getViewerJsPath(): string - { - return $this->viewerJsPath; - } - - public function getEditorCssPath(): string - { - return $this->editorCssPath; - } - - public function getViewerCssPath(): string - { - return $this->viewerCssPath; - } - - public function getEditorContentsCssPath(): ?string - { - return $this->editorContentsCssPath; - } - - public function getJqueryPath(): string - { - return $this->jqueryPath; - } - public function getDefaultConfig(): ?string { return $this->defaultConfig; @@ -190,14 +124,19 @@ public function getConfigs(): array return $this->configs; } - public function getEditorOptions(): array + public function getJquery(): array + { + return $this->jquery; + } + + public function getEditor(): array { - return $this->editorOptions; + return $this->editor; } - public function getViewerOptions(): array + public function getViewer(): array { - return $this->viewerOptions; + return $this->viewer; } public function getExtensions(): array diff --git a/src/Config/TuiEditorConfigurationInterface.php b/src/Config/TuiEditorConfigurationInterface.php index 75e5722..bbbd819 100644 --- a/src/Config/TuiEditorConfigurationInterface.php +++ b/src/Config/TuiEditorConfigurationInterface.php @@ -12,20 +12,8 @@ public function isEnable(): bool; public function isToHtml(): bool; - public function isJquery(): bool; - public function getBasePath(): string; - public function getEditorJsPath(): string; - - public function getViewerJsPath(): string; - - public function getEditorCssPath(): string; - - public function getEditorContentsCssPath(): ?string; - - public function getJqueryPath(): string; - public function getDefaultConfig(): ?string; public function getConfigs(): array; @@ -34,9 +22,11 @@ public function getExtensions(): array; public function getDependencies(): array; - public function getEditorOptions(): array; + public function getJquery(): array; + + public function getEditor(): array; - public function getViewerOptions(): array; + public function getViewer(): array; public function getAssetRepository(): string; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2ab00b0..a27b26a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -23,18 +23,12 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode ->children() ->booleanNode('enable')->defaultTrue()->end() - ->booleanNode('jquery')->defaultTrue()->info("If you want use jquery.js set true.")->end() ->scalarNode('base_path')->defaultValue($bundleBasePath)->end() - ->scalarNode('editor_js_path')->defaultValue($bundleBasePath.'js/toast-ui-editor-bundle.js')->end() - ->scalarNode('viewer_js_path')->defaultValue($bundleBasePath.'js/toast-ui-viewer-bundle.js')->end() - ->scalarNode('editor_css_path')->defaultValue($bundleBasePath.'css/toastui-editor.css')->end() - ->scalarNode('viewer_css_path')->defaultValue($bundleBasePath.'css/toastui-editor-viewer.css')->end() - ->scalarNode('editor_contents_css_path')->defaultValue(null)->end() - ->scalarNode('jquery_path')->defaultValue($bundleBasePath.'js/jquery.min.js')->end() ->scalarNode('default_config')->defaultValue(null)->end() ->scalarNode('asset_repository')->defaultValue('teebbstudios/tui.editor-bundles')->end() - ->append($this->createEditorOptions()) - ->append($this->createViewerOptions()) + ->append($this->createJquery($bundleBasePath)) + ->append($this->createEditor($bundleBasePath)) + ->append($this->createViewer($bundleBasePath)) ->append($this->createExtensions($bundleBasePath)) ->append($this->createDependencies($bundleBasePath)) ->append($this->createConfigsNode()) @@ -43,32 +37,84 @@ public function getConfigTreeBuilder(): TreeBuilder return $treeBuilder; } - private function createEditorOptions() + private function createJquery($bundleBasePath) { - return $this->createNode('editor_options') + return $this->createNode('jquery') ->addDefaultsIfNotSet() ->children() - ->arrayNode('toolbar_items') - ->defaultValue([['heading', 'bold', 'italic', 'strike'],['hr', 'quote'],['ul', 'ol', 'task', 'indent', 'outdent'],['table', 'image', 'link'],['code', 'codeblock']]) - ->arrayPrototype() - ->scalarPrototype() + ->booleanNode('enable')->defaultTrue()->info("If you want use jquery.js set true.")->end() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/jquery.min.js']) + ->scalarPrototype() + ->end() + ->end() + ->end(); + } + + + private function createEditor($bundleBasePath) + { + return $this->createNode('editor') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-editor-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor.css']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('toolbar_items') + ->defaultValue([['heading', 'bold', 'italic', 'strike'],['hr', 'quote'],['ul', 'ol', 'task', 'indent', 'outdent'],['table', 'image', 'link'],['code', 'codeblock']]) + ->arrayPrototype() + ->scalarPrototype() + ->end() + ->end() ->end() + ->arrayNode('widget_rules') + ->defaultValue([]) + ->arrayPrototype() + ->scalarPrototype() + ->end() + ->end() + ->end() + ->scalarNode('theme')->defaultValue('light')->end() + ->scalarNode('initial_edit_type')->defaultValue('markdown')->end() + ->scalarNode('preview_style')->defaultValue('vertical')->end() + ->scalarNode('height')->defaultValue('auto')->end() ->end() ->end() - ->scalarNode('theme')->defaultValue('light')->end() - ->scalarNode('initial_edit_type')->defaultValue('markdown')->end() - ->scalarNode('preview_style')->defaultValue('vertical')->end() - ->scalarNode('height')->defaultValue('auto')->end() - ->end(); + ->end(); } - private function createViewerOptions() + private function createViewer($bundleBasePath) { - return $this->createNode('viewer_options') + return $this->createNode('viewer') ->addDefaultsIfNotSet() ->children() - ->scalarNode('height')->defaultValue('auto')->end() - ->end(); + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-viewer-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor-viewer.css']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('height')->defaultValue('auto')->end() + ->end() + ->end() + ->end(); } private function createExtensions(string $bundleBasePath) diff --git a/src/Form/Type/TuiEditorType.php b/src/Form/Type/TuiEditorType.php index 45c5fbd..7d28140 100644 --- a/src/Form/Type/TuiEditorType.php +++ b/src/Form/Type/TuiEditorType.php @@ -39,18 +39,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void if (!$options['enable']) { return; } - - $builder->setAttribute('jquery', $options['jquery']); $builder->setAttribute('base_path', $options['base_path']); $builder->setAttribute('locale', $options['locale']); - $builder->setAttribute('editor_js_path', $options['editor_js_path']); - $builder->setAttribute('viewer_js_path', $options['viewer_js_path']); - $builder->setAttribute('editor_css_path', $options['editor_css_path']); - $builder->setAttribute('viewer_css_path', $options['viewer_css_path']); - $builder->setAttribute('editor_contents_css_path', $options['editor_contents_css_path']); - $builder->setAttribute('editor_options', $options['editor_options']); - $builder->setAttribute('viewer_options', $options['viewer_options']); - $builder->setAttribute('jquery_path', $options['jquery_path']); + $builder->setAttribute('jquery', $options['jquery']); + $builder->setAttribute('editor', $options['editor']); + $builder->setAttribute('viewer', $options['viewer']); $builder->setAttribute('config', $this->resolveConfig($options)); $builder->setAttribute('config_name', $options['config_name']); $builder->setAttribute('extensions', $options['extensions']); @@ -79,17 +72,11 @@ public function buildView(FormView $view, FormInterface $form, array $options): return; } - $view->vars['jquery'] = $config->getAttribute('jquery'); $view->vars['locale'] = $config->getAttribute('locale'); $view->vars['base_path'] = $config->getAttribute('base_path'); - $view->vars['editor_js_path'] = $config->getAttribute('editor_js_path'); - $view->vars['viewer_js_path'] = $config->getAttribute('viewer_js_path'); - $view->vars['editor_css_path'] = $config->getAttribute('editor_css_path'); - $view->vars['viewer_css_path'] = $config->getAttribute('viewer_css_path'); - $view->vars['editor_contents_css_path'] = $config->getAttribute('editor_contents_css_path'); - $view->vars['editor_options'] = $config->getAttribute('editor_options'); - $view->vars['viewer_options'] = $config->getAttribute('viewer_options'); - $view->vars['jquery_path'] = $config->getAttribute('jquery_path'); + $view->vars['jquery'] = $config->getAttribute('jquery'); + $view->vars['editor'] = $config->getAttribute('editor'); + $view->vars['viewer'] = $config->getAttribute('viewer'); $view->vars['config'] = $config->getAttribute('config'); $view->vars['extensions'] = $config->getAttribute('extensions'); $view->vars['dependencies'] = $config->getAttribute('dependencies'); @@ -102,35 +89,23 @@ public function configureOptions(OptionsResolver $resolver): void $resolver ->setDefaults([ 'enable' => $this->configuration->isEnable(), - 'jquery' => $this->configuration->isJquery(), 'locale' => $this->locale, 'base_path' => $this->configuration->getBasePath(), - 'editor_js_path' => $this->configuration->getEditorJsPath(), - 'viewer_js_path' => $this->configuration->getViewerJsPath(), - 'editor_css_path' => $this->configuration->getEditorCssPath(), - 'viewer_css_path' => $this->configuration->getViewerCssPath(), - 'editor_contents_css_path' => $this->configuration->getEditorContentsCssPath(), - 'editor_options' => $this->configuration->getEditorOptions(), - 'viewer_options' => $this->configuration->getViewerOptions(), - 'jquery_path' => $this->configuration->getJqueryPath(), + 'jquery' => $this->configuration->getJquery(), + 'editor' => $this->configuration->getEditor(), + 'viewer' => $this->configuration->getViewer(), 'config_name' => $this->configuration->getDefaultConfig(), 'config' => $this->configuration->getConfigs(), 'extensions' => $this->configuration->getExtensions(), 'dependencies' => $this->configuration->getDependencies(), ]) ->addAllowedTypes('enable', 'bool') - ->addAllowedTypes('jquery', 'bool') ->addAllowedTypes('locale', ['string', 'null']) ->addAllowedTypes('config_name', ['string', 'null']) ->addAllowedTypes('base_path', 'string') - ->addAllowedTypes('editor_js_path', 'string') - ->addAllowedTypes('viewer_js_path', 'string') - ->addAllowedTypes('editor_css_path', 'string') - ->addAllowedTypes('viewer_css_path', 'string') - ->addAllowedTypes('editor_contents_css_path', ['string', 'null']) - ->addAllowedTypes('editor_options', 'array') - ->addAllowedTypes('viewer_options', 'array') - ->addAllowedTypes('jquery_path', 'string') + ->addAllowedTypes('jquery', 'array') + ->addAllowedTypes('editor', 'array') + ->addAllowedTypes('viewer', 'array') ->addAllowedTypes('config', 'array') ->addAllowedTypes('extensions', 'array') ->addAllowedTypes('dependencies', 'array') diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 11fdff4..ecbb4d4 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -66,50 +66,38 @@ public function __construct( $this->locale = $locale; } - public function renderBasePath(string $basePath): string - { - return $this->fixPath($basePath); - } - - public function renderEditorJsPath(string $editorJsPath = null): string - { - if ($editorJsPath === null) { - return $this->fixPath($this->options['editor_js_path']); - } - return $this->fixPath($editorJsPath); - } - - public function renderJqueryPath(string $jqueryPath = null): string + public function renderScriptBlock(string $path): string { - if ($jqueryPath === null) { - return $this->fixPath($this->options['jquery_path']); - } - return $this->fixPath($jqueryPath); + return sprintf('', $this->fixPath($path)); } - public function renderEditorCssPath(string $editorCssPath = null): string + public function renderStyleBlock(string $path): string { - if ($editorCssPath === null) { - return $this->fixPath($this->options['editor_css_path']); - } - return $this->fixPath($editorCssPath); + return sprintf('', $this->fixPath($path)); } - public function renderViewerCssPath(string $viewerCssPath = null): string - { - if ($viewerCssPath === null) { - return $this->fixPath($this->options['viewer_css_path']); + private function retrieveJsPathToHtml(?array $paths) { + $html = ''; + if ($paths && is_array($paths)) { + foreach ($paths as $path) { + if ($path) { + $html .= $this->renderScriptBlock($path); + } + } } - return $this->fixPath($viewerCssPath); + return $html; } - - public function renderEditorContentsCssPath(string $editorContentsCssPath = null): string - { - if ($editorContentsCssPath === null) { - return $this->fixPath($this->options['editor_contents_css_path']); + private function retrieveCssPathToHtml(?array $paths) { + $html = ''; + if ($paths && is_array($paths)) { + foreach ($paths as $path) { + if ($path) { + $html .= $this->renderStyleBlock($path); + } + } } - return $this->fixPath($editorContentsCssPath); + return $html; } public function renderDependencies(array $dependencies = null): string @@ -119,9 +107,6 @@ public function renderDependencies(array $dependencies = null): string $dependenciesJsHtml = ""; $dependenciesCssHtml = ""; - if ($this->options['jquery']) { - $dependenciesJsHtml .= $this->renderScriptBlock($this->options['jquery_path']); - } foreach ($dependencies as $dependencyName => $dependencyConfigs) { if (is_array($dependencyConfigs) && array_key_exists('js_paths',$dependencyConfigs)) { $dependenciesJsHtml .= $this->retrieveJsPathToHtml($dependencyConfigs['js_paths']); @@ -141,40 +126,6 @@ public function renderDependencies(array $dependencies = null): string return $dependenciesJsHtml . $dependenciesCssHtml; } - public function renderScriptBlock(string $path): string - { - return sprintf('', $this->fixPath($path)); - } - - public function renderStyleBlock(string $path): string - { - return sprintf('', $this->fixPath($path)); - } - - private function retrieveJsPathToHtml(?array $paths) { - $html = ''; - if ($paths && is_array($paths)) { - foreach ($paths as $path) { - if ($path) { - $html .= $this->renderScriptBlock($path); - } - } - } - return $html; - } - - private function retrieveCssPathToHtml(?array $paths) { - $html = ''; - if ($paths && is_array($paths)) { - foreach ($paths as $path) { - if ($path) { - $html .= $this->renderStyleBlock($path); - } - } - } - return $html; - } - public function renderExtensions($extensions, array $excludeList = []): string { $extsJsHtml = ""; @@ -202,40 +153,6 @@ public function renderExtensions($extensions, array $excludeList = []): string return $extsJsHtml.$extsCssHtml; } - public function renderViewer(string $id, string $content, string $viewerJsPath = null): string - { - if (null === $viewerJsPath) { - $viewerJsPath = $this->options['viewer_js_path']; - } - - $defaultConfig = $this->options['default_config']; - $extensions = $this->getOption(null, 'extensions', null, $this->options, true); - $viewerJsCode = $this->renderScriptBlock($viewerJsPath); - $editorContentsCssCode = isset($this->options['editor_contents_css_path']) && null !== $this->options['editor_contents_css_path']? $this->renderStyleBlock($this->options['editor_contents_css_path']) : ''; - $viewerCssCode = $this->renderStyleBlock($this->options['viewer_css_path']); - - $extsHtml = $this->renderExtensions($extensions, ["uml", "colorSyntax"]); - - $viewerJsScript = sprintf( - '', - $this->fixContentToJs($content), - $id, - $id, - $this->getOptionAsJson('height', 'viewer_options', false, $this->options, true), - $this->fixArrayToJs($extensions, ["uml", "colorSyntax"]) - ); - - return $viewerJsCode . $viewerCssCode. $editorContentsCssCode . $extsHtml . $viewerJsScript; - } - private function fixArrayToJs(array $array, array $excludeList = []): string { if (null == $array) { @@ -260,7 +177,7 @@ private function fixArrayToJs(array $array, array $excludeList = []): string return implode(",", $jsArray); } - private function fixContentToJs(string $content): string + private function getContentToJson(string $content): string { if (null == $content) { $content = ""; @@ -336,6 +253,11 @@ private function getOption($key, $keyOption, $userPreferenceConfig, $config, $ch } } + private function getOptionForParentAsJson($key, $keyOption, $keyParent, $userPreferenceConfig, $config, $checkDefaultConfig = false): ?string + { + return json_encode($this->getOptionForParent($key, $keyOption, $keyParent, $userPreferenceConfig, $config, $checkDefaultConfig)); + } + private function getOptionForParent($key, $keyOption, $keyParent, $userPreferenceConfig, $config, $checkDefaultConfig = false) { if (empty($key)) { @@ -361,22 +283,23 @@ private function getOptionForParent($key, $keyOption, $keyParent, $userPreferenc } } - public function renderEditor(string $id, array $config, string $content = null): string + public function renderEditor(string $id, array $config, string $content = null, ?array $formConfig): string { $config = $this->fixConfigLanguage($config); + $jqueryEnable = $this->getOption('enable', 'jquery', $formConfig, $this->options, true); + $jqueryJsCode = ''; + if ($jqueryEnable) { + $jqueryJsPaths = $this->getOption('js_paths', 'jquery', $formConfig, $this->options, true); + $jqueryJsCode = $this->retrieveJsPathToHtml($jqueryJsPaths); + } $extensions = $this->getOption(null, 'extensions', $config, $this->options, true); - - $editorJsCode = $this->renderScriptBlock($this->options['editor_js_path']); - $editorCssCode = $this->renderStyleBlock($this->options['editor_css_path']); - $editorContentsCssCode = isset($this->options['editor_contents_css_path']) && null !== $this->options['editor_contents_css_path']? $this->renderStyleBlock($this->options['editor_contents_css_path']) : ''; - - $extsHtml = $this->renderExtensions($extensions); + $extensionsnHtml = $this->renderExtensions($extensions); $editorJsScript = sprintf( '', - $this->fixContentToJs($content), + $this->getContentToJson($content), $id, $id, - $this->getOptionAsJson('initial_edit_type', 'editor_options', $config, $this->options, true), - $this->getOptionAsJson('preview_style', 'editor_options', $config, $this->options, true), - $this->getOptionAsJson('height', 'editor_options', $config, $this->options, true), + $this->getOptionForParentAsJson('initial_edit_type', 'options', 'editor', $formConfig, $this->options, true), + $this->getOptionForParentAsJson('preview_style', 'options', 'editor', $formConfig, $this->options, true), + $this->getOptionForParentAsJson('height', 'options', 'editor', $formConfig, $this->options, true), array_key_exists('language', $config) ? $config['language'] : $config['locale'], $this->fixArrayToJs($extensions), - $this->getOptionAsJson('theme', 'editor_options', $config, $this->options, true), - $this->getOptionAsJson('toolbar_items', 'editor_options', $config, $this->options, true) + $this->getOptionForParentAsJson('theme', 'options', 'editor', $formConfig, $this->options, true), + $this->getOptionForParentAsJson('toolbar_items', 'options', 'editor', $formConfig, $this->options, true) + ); + + $editorJsPaths = $this->getOption('js_paths', 'editor', $formConfig, $this->options, true); + $editorJsCode = $this->retrieveJsPathToHtml($editorJsPaths); + + $editorCssPaths = $this->getOption('css_paths', 'editor', $formConfig, $this->options, true); + $editorCssCode = $this->retrieveCssPathToHtml($editorCssPaths); + + return $extensionsnHtml . $jqueryJsCode . $editorJsCode . $editorCssCode . $editorJsScript; + } + + public function renderViewer(string $id, string $content, ?array $formConfig = null): string + { + $jqueryEnable = $this->getOption('enable', 'jquery', $formConfig, $this->options, true); + $jqueryJsCode = ''; + if ($jqueryEnable) { + $jqueryJsPaths = $this->getOption('js_paths', 'jquery', $formConfig, $this->options, true); + $jqueryJsCode = $this->retrieveJsPathToHtml($jqueryJsPaths); + } + $extensions = $this->getOption(null, 'extensions', $formConfig, $this->options, true); + $extensionsnHtml = $this->renderExtensions($extensions, ["uml", "colorSyntax"]); + + $viewerJsScript = sprintf( + '', + $this->getContentToJson($content), + $id, + $id, + $this->getOptionForParentAsJson('height', 'options', 'viewer', $formConfig, $this->options, true), + $this->fixArrayToJs($extensions, ["uml", "colorSyntax"]) ); - return $extsHtml . $editorJsCode . $editorCssCode . $editorContentsCssCode . $editorJsScript; + $viewerJsPaths = $this->getOption('js_paths', 'viewer', $formConfig, $this->options, true); + $viewerJsCode = $this->retrieveJsPathToHtml($viewerJsPaths); + + $viewerCssPaths = $this->getOption('css_paths', 'viewer', $formConfig, $this->options, true); + $viewerCssCode = $this->retrieveCssPathToHtml($viewerCssPaths); + + return $viewerJsCode . $jqueryJsCode. $viewerCssCode . $extensionsnHtml . $viewerJsScript; } } \ No newline at end of file diff --git a/src/Renderer/TuiEditorRendererInterface.php b/src/Renderer/TuiEditorRendererInterface.php index c0ad610..01889b0 100644 --- a/src/Renderer/TuiEditorRendererInterface.php +++ b/src/Renderer/TuiEditorRendererInterface.php @@ -6,20 +6,9 @@ interface TuiEditorRendererInterface { - public function renderBasePath(string $basePath): string; + public function renderViewer(string $id, string $content, ?array $formConfig): string; - public function renderJqueryPath(string $jqueryPath = null): string; - - public function renderEditorJsPath(string $editorJsPath = null): string; - - public function renderViewer(string $id, string $content, string $viewerJsPath = null): string; - - public function renderEditor(string $id, array $config, string $content = null): string; - - public function renderEditorCssPath(string $editorCssPath = null): string; - - public function renderEditorContentsCssPath(string $editorContentsCssPath = null): string; + public function renderEditor(string $id, array $config, string $content = null, ?array $formConfig): string; public function renderDependencies(array $dependencies = null): string; - -} +} \ No newline at end of file diff --git a/src/Resources/views/Form/tuieditor_widget.html.twig b/src/Resources/views/Form/tuieditor_widget.html.twig index 5e8dca7..1018206 100644 --- a/src/Resources/views/Form/tuieditor_widget.html.twig +++ b/src/Resources/views/Form/tuieditor_widget.html.twig @@ -13,10 +13,8 @@ {% endblock %} {% block _tuieditor_javascript %} - - {{ tuieditor_editor_widget('editor_'~id, config, value) }} + {{ tuieditor_editor_widget('editor_'~id, config, value, { "editor": {editor}} ) }} {{ block('_tuieditor_events_hooks') }} - {% endblock %} {% block _tuieditor_events_hooks %} diff --git a/src/Twig/TuiEditorExtension.php b/src/Twig/TuiEditorExtension.php index 0b1e323..30fe92b 100644 --- a/src/Twig/TuiEditorExtension.php +++ b/src/Twig/TuiEditorExtension.php @@ -24,51 +24,20 @@ public function getFunctions(): array $options = ['is_safe' => ['html']]; return [ - new TwigFunction('tuieditor_base_path', [$this, 'renderBasePath'], $options), - new TwigFunction('tuieditor_jquery_path', [$this, 'renderJqueryPath'], $options), - new TwigFunction('tuieditor_editor_js_path', [$this, 'renderEditorJsPath'], $options), new TwigFunction('tuieditor_viewer_widget', [$this, 'renderViewer'], $options), new TwigFunction('tuieditor_editor_widget', [$this, 'renderEditor'], $options), - new TwigFunction('tuieditor_editor_css_path', [$this, 'renderEditorCssPath'], $options), - new TwigFunction('tuieditor_viewer_css_path', [$this, 'renderViewerCssPath'], $options), - new TwigFunction('tuieditor_editor_contents_css_path', [$this, 'renderEditorContentsCssPath'], $options), new TwigFunction('tuieditor_dependencies', [$this, 'renderDependencies'], $options), ]; } - public function renderEditorCssPath(string $editorCssPath = null): string + public function renderViewer(string $id, string $content, ?array $formConfig): string { - return $this->renderer->renderEditorCssPath($editorCssPath); + return $this->renderer->renderViewer($id, $content, $formConfig); } - public function renderViewerCssPath(string $viewerCssPath = null): string + public function renderEditor(string $id, array $config, string $content = null, ?array $formConfig): string { - return $this->renderer->renderViewerCssPath($viewerCssPath); - } - - public function renderEditorContentsCssPath(string $editorContentsCssPath = null): string - { - return $this->renderer->renderEditorContentsCssPath($editorContentsCssPath); - } - - public function renderBasePath(string $basePath): string - { - return $this->renderer->renderBasePath($basePath); - } - - public function renderEditorJsPath(string $editorJsPath = null): string - { - return $this->renderer->renderEditorJsPath($editorJsPath); - } - - public function renderViewer(string $id, string $content, string $viewerJsPath = null): string - { - return $this->renderer->renderViewer($id, $content, $viewerJsPath); - } - - public function renderJqueryPath(string $jqueryPath = null): string - { - return $this->renderer->renderJqueryPath($jqueryPath); + return $this->renderer->renderEditor($id, $config, $content, $formConfig); } public function renderDependencies(array $dependencies = null): string @@ -76,8 +45,4 @@ public function renderDependencies(array $dependencies = null): string return $this->renderer->renderDependencies($dependencies); } - public function renderEditor(string $id, array $config, string $content = null): string - { - return $this->renderer->renderEditor($id, $config, $content); - } } From 78d05ec5094181569ba26d350bdd91bc500d6e0d Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Fri, 12 Dec 2025 14:41:18 +0000 Subject: [PATCH 27/29] Support Symfony <6 --- composer.json | 26 ++++++++++++------------ src/Command/TuiEditorDownloadCommand.php | 8 +------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 88653fb..aeae009 100644 --- a/composer.json +++ b/composer.json @@ -16,19 +16,19 @@ "require": { "php": "^7.1 || ^8.0", "ext-zip": "*", - "symfony/asset": "^7.0", - "symfony/config": "^7.0", - "symfony/dependency-injection": "^7.0", - "symfony/expression-language": "^7.0", - "symfony/form": "^7.0", - "symfony/framework-bundle": "^7.0", - "symfony/http-foundation": "^7.0", - "symfony/http-kernel": "^7.0", - "symfony/options-resolver": "^7.0", - "symfony/property-access": "^7.0", - "symfony/routing": "^7.0", - "symfony/twig-bundle": "^7.0", - "twig/twig": "^2.12|^3.0" + "symfony/asset": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/config": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/expression-language": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/form": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/http-foundation": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/http-kernel": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/options-resolver": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/property-access": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/routing": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0", + "twig/twig": "^2.12 || ^3.0" }, "autoload": { "psr-4": { diff --git a/src/Command/TuiEditorDownloadCommand.php b/src/Command/TuiEditorDownloadCommand.php index 9b0a227..7fba669 100644 --- a/src/Command/TuiEditorDownloadCommand.php +++ b/src/Command/TuiEditorDownloadCommand.php @@ -13,10 +13,6 @@ use Symfony\Component\Console\Question\ChoiceQuestion; use Teebb\TuiEditorBundle\Installer\TuiEditorInstaller; -#[AsCommand( - name: TuiEditorDownloadCommand::defaultName, - description: 'Download the lastest tui.editor with all the required libraries.', -)] class TuiEditorDownloadCommand extends Command { protected static $defaultName = 'tuieditor:install'; @@ -58,7 +54,7 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output): int + protected function execute(InputInterface $input, OutputInterface $output) { $this->title($output); @@ -69,10 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($success) { $this->success('tui.editor has been successfully installed...', $output); - return Command::SUCCESS; } else { $this->info('tui.editor installation has been skipped...', $output); - return Command::INVALID; } } From edcc89efabb8590dfe8f2a7e589118191e1e2086 Mon Sep 17 00:00:00 2001 From: Michael Yip Date: Mon, 15 Dec 2025 09:30:15 +0000 Subject: [PATCH 28/29] Fix on change edit --- src/Renderer/TuiEditorRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index ecbb4d4..a613fc5 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -299,7 +299,7 @@ public function renderEditor(string $id, array $config, string $content = null, $editorJsScript = sprintf( '