diff --git a/README.md b/README.md index 24f49a0..0efbe3a 100644 --- a/README.md +++ b/README.md @@ -79,29 +79,152 @@ You can add a config file in `config/packages` folder.(Just a simple config, B ```yaml #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. - # ... # more config options, you can see: bin/console debug:config teebb_tui_editor - - default_config: basic_config + #enable: true # Whether to enable tui.editor. + #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: + #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: + #- /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? - #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? + #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: + #- /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 + ``` + +> [!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. + You can config tui.editor language. ```yaml #config/services.yaml @@ -111,7 +234,6 @@ parameters: ``` - ### Step 5: Use the Bundle Add the tui.editor dependencies in your page top. For example: @@ -119,25 +241,18 @@ 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: ```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..420d606 100644 --- a/README_zh.md +++ b/README_zh.md @@ -75,29 +75,150 @@ $ 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: + #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: + #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: + #- /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? - #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? + 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: + #- /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 ``` + +> [!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 @@ -114,22 +235,12 @@ parameters: ```twig {{ tuieditor_dependencies() }} ``` -这一步会把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/composer.json b/composer.json index 7994137..aeae009 100644 --- a/composer.json +++ b/composer.json @@ -14,21 +14,21 @@ } ], "require": { - "php": "^7.1", + "php": "^7.1 || ^8.0", "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": "^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 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; } } diff --git a/src/Config/TuiEditorConfiguration.php b/src/Config/TuiEditorConfiguration.php index e812d60..548c642 100644 --- a/src/Config/TuiEditorConfiguration.php +++ b/src/Config/TuiEditorConfiguration.php @@ -17,50 +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 + * @var string|null */ - private $editorCssPath; + private $defaultConfig; /** - * @var string + * @var array */ - private $editorContentsCssPath; + private $configs; /** - * @var string + * @var array */ - private $jqueryPath; + private $jquery; /** - * @var string|null + * @var array */ - private $defaultConfig; + private $editor; /** * @var array */ - private $configs; + private $viewer; /** * @var array @@ -72,6 +57,11 @@ final class TuiEditorConfiguration implements TuiEditorConfigurationInterface */ private $dependencies; + /** + * @var string + */ + private $assetRepository; + public function __construct(array $config) { if ($config['enable']) { @@ -79,17 +69,15 @@ 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->editorContentsCssPath = $config['editor_contents_css_path']; - $this->jqueryPath = $config['jquery_path']; $this->defaultConfig = $config['default_config']; $this->configs = $config['configs']; + $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']; } @@ -121,50 +109,34 @@ 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 + public function getDefaultConfig(): ?string { - return $this->editorCssPath; + return $this->defaultConfig; } - public function getEditorContentsCssPath(): string + public function getConfigs(): array { - return $this->editorContentsCssPath; + return $this->configs; } - - public function getJqueryPath(): string + public function getJquery(): array { - return $this->jqueryPath; + return $this->jquery; } - public function getDefaultConfig(): ?string + public function getEditor(): array { - return $this->defaultConfig; + return $this->editor; } - public function getConfigs(): array + public function getViewer(): array { - return $this->configs; + return $this->viewer; } public function getExtensions(): array @@ -177,6 +149,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])) { @@ -185,4 +162,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 eb16470..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,6 +22,14 @@ public function getExtensions(): array; public function getDependencies(): array; + public function getJquery(): array; + + public function getEditor(): array; + + public function getViewer(): array; + + public function getAssetRepository(): string; + /** * @throws ConfigException */ 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); } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 65fa851..a27b26a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -19,138 +19,232 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('teebb_tui_editor'); } - + $bundleBasePath = "bundles/teebbtuieditor/tui.editor-bundles/"; $rootNode ->children() ->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('base_path')->defaultValue($bundleBasePath)->end() ->scalarNode('default_config')->defaultValue(null)->end() - ->append($this->createExtensions()) - ->append($this->createDependencies()) + ->scalarNode('asset_repository')->defaultValue('teebbstudios/tui.editor-bundles')->end() + ->append($this->createJquery($bundleBasePath)) + ->append($this->createEditor($bundleBasePath)) + ->append($this->createViewer($bundleBasePath)) + ->append($this->createExtensions($bundleBasePath)) + ->append($this->createDependencies($bundleBasePath)) ->append($this->createConfigsNode()) ->end(); return $treeBuilder; } - private function createExtensions() + private function createJquery($bundleBasePath) { - return $this->createNode('extensions') + return $this->createNode('jquery') ->addDefaultsIfNotSet() ->children() - ->arrayNode('scrollSync') - ->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() + ->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(); + } - ->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() + + 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('uml') - ->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() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor.css']) + ->scalarPrototype() ->end() ->end() - - ->arrayNode('chart') + ->arrayNode('options') ->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() + ->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() + ->end(); + } - ->arrayNode('table') - ->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() + private function createViewer($bundleBasePath) + { + return $this->createNode('viewer') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-viewer-bundle.js']) + ->scalarPrototype() ->end() ->end() - - ->arrayNode('mark') + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor-viewer.css']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue(null)->end() - ->scalarNode('css_path')->defaultValue(null)->end() + ->scalarNode('height')->defaultValue('auto')->end() ->end() ->end() - - - ->end(); } - private function createDependencies() + private function createExtensions(string $bundleBasePath) { - return $this->createNode('dependencies') + return $this->createNode('extensions') ->addDefaultsIfNotSet() ->children() - ->arrayNode('markdown-it') + ->arrayNode('colorSyntax') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/markdown-it/dist/markdown-it.min.js')->end() - ->scalarNode('css_path')->defaultValue(null)->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([]) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() - - ->arrayNode('tui-code-snippet') + ->arrayNode('chart') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/tui-code-snippet/dist/tui-code-snippet.min.js')->end() - ->scalarNode('css_path')->defaultValue(null)->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([]) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() - ->arrayNode('codemirror') + ->arrayNode('codeSyntaxHighlight') ->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() + ->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([]) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() - ->arrayNode('highlight') + ->arrayNode('tableMergedCell') ->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() + ->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([]) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() - ->arrayNode('squire-rte') + ->arrayNode('uml') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/squire-rte/build/squire-raw.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() + ->arrayNode('js_paths') + ->defaultValue([$bundleBasePath.'js/toast-ui-uml-bundle.js']) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([]) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('options') + ->defaultValue([]) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() + ->end(); + } - ->arrayNode('to-mark') + private function createDependencies($bundleBasePath) + { + return $this->createNode('dependencies') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('editor_dark_theme') ->addDefaultsIfNotSet() ->children() - ->scalarNode('js_path')->defaultValue('bundles/teebbtuieditor/tui.editor-bundles/lib/to-mark/dist/to-mark.min.js')->end() - ->scalarNode('css_path')->defaultValue(null)->end() + ->arrayNode('js_paths') + ->defaultValue([]) + ->scalarPrototype() + ->end() + ->end() + ->arrayNode('css_paths') + ->defaultValue([$bundleBasePath.'css/toastui-editor-dark.css']) + ->scalarPrototype() + ->end() + ->end() ->end() ->end() - ->end(); } @@ -186,4 +280,4 @@ private function createNode(string $name): ArrayNodeDefinition return $node; } -} +} \ No newline at end of file diff --git a/src/Form/Type/TuiEditorType.php b/src/Form/Type/TuiEditorType.php index 0a28d96..7d28140 100644 --- a/src/Form/Type/TuiEditorType.php +++ b/src/Form/Type/TuiEditorType.php @@ -39,15 +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('editor_contents_css_path', $options['editor_contents_css_path']); - $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']); @@ -76,14 +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['editor_contents_css_path'] = $config->getAttribute('editor_contents_css_path'); - $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'); @@ -96,29 +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(), - 'editor_contents_css_path' => $this->configuration->getEditorContentsCssPath(), - '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('editor_contents_css_path', 'string') - ->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/Installer/TuiEditorInstaller.php b/src/Installer/TuiEditorInstaller.php index 96765de..cb06305 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 @@ -106,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/js/toast-ui-editor-bundle.js')) { return self::CLEAR_DROP; } @@ -119,36 +123,40 @@ private function clear(array $options): string } if (self::CLEAR_DROP === $options['clear']) { - $files = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($options['path'], \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::CHILD_FIRST - ); + $this->removeDirectory($options['path'], $options['notifier']); - $this->notify(self::NOTIFY_CLEAR_SIZE, iterator_count($files), $options['notifier']); + $this->notify(self::NOTIFY_CLEAR_COMPLETE, null, $options['notifier']); + } - foreach ($files as $file) { - $filePath = $file->getRealPath(); - $this->notify(self::NOTIFY_CLEAR_PROGRESS, $filePath, $options['notifier']); + return $options['clear']; + } - if ($dir = $file->isDir()) { - $success = @rmdir($filePath); - } else { - $success = @unlink($filePath); - } + private function removeDirectory($path, $notifier) { + $files = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), + \RecursiveIteratorIterator::CHILD_FIRST + ); - if (!$success) { - throw $this->createException(sprintf( - 'Unable to remove the %s "%s".', - $dir ? 'directory' : 'file', - $filePath - )); - } + $this->notify(self::NOTIFY_CLEAR_SIZE, iterator_count($files), $notifier); + + foreach ($files as $file) { + $filePath = $file->getRealPath(); + $this->notify(self::NOTIFY_CLEAR_PROGRESS, $filePath, $notifier); + + if ($dir = $file->isDir()) { + $success = @rmdir($filePath); + } else { + $success = @unlink($filePath); } - $this->notify(self::NOTIFY_CLEAR_COMPLETE, null, $options['notifier']); + if (!$success) { + throw $this->createException(sprintf( + 'Unable to remove the %s "%s".', + $dir ? 'directory' : 'file', + $filePath + )); + } } - - return $options['clear']; } private function download(array $options): string @@ -180,13 +188,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']); @@ -275,9 +283,16 @@ private function extract(string $path, array $options): void $zip->close(); $originExtractFolderName = $options['path'] . '/tui.editor-bundles-' . substr($this->version, 1); + $publicAssets = $options['path'] . '/tui.editor-bundles'; + if (!is_dir($publicAssets) && !@mkdir($publicAssets, 0777, true)) { + throw $this->createException(sprintf('Unable to create the directory "%s".', $publicAssets)); + } - rename($originExtractFolderName, $options['path'] . '/tui.editor-bundles'); - + $this->extractPublicFolder($originExtractFolderName.'/public', $publicAssets); + if (is_dir($originExtractFolderName)) { + $this->removeDirectory($originExtractFolderName, $options['notifier']); + rmdir($originExtractFolderName); + } $this->notify(self::NOTIFY_EXTRACT_COMPLETE, null, $options['notifier']); $this->notify(self::NOTIFY_CLEAR_ARCHIVE, $path, $options['notifier']); @@ -287,6 +302,26 @@ private function extract(string $path, array $options): void } } + public function extractPublicFolder($fromPath, $toPath) + { + $files = scandir($fromPath); + $source = $fromPath."/"; + $destination = $toPath."/"; + foreach ($files as $file) { + if (in_array($file, array(".",".."))) continue; + if (is_dir($source.$file)) { + if (!is_dir($destination.$file) && !@mkdir($destination.$file, 0777, true)) { + throw $this->createException(sprintf('Unable to create the directory "%s".', $destination.$file)); + } + $this->extractPublicFolder($source.$file, $destination.$file); + } else { + if (copy($source.$file, $destination.$file)) { + // copied successfully + } + } + } + } + private function extractFile(string $file, string $rewrite, string $origin, array $options): void { $this->notify(self::NOTIFY_EXTRACT_PROGRESS, $rewrite, $options['notifier']); @@ -303,10 +338,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) { @@ -324,6 +357,4 @@ private function createException(string $message): \RuntimeException return new \RuntimeException($message); } - - } \ No newline at end of file diff --git a/src/Renderer/TuiEditorRenderer.php b/src/Renderer/TuiEditorRenderer.php index 86dd921..a613fc5 100644 --- a/src/Renderer/TuiEditorRenderer.php +++ b/src/Renderer/TuiEditorRenderer.php @@ -66,159 +66,123 @@ public function __construct( $this->locale = $locale; } - public function renderBasePath(string $basePath): string + public function renderScriptBlock(string $path): string { - return $this->fixPath($basePath); + return sprintf('', $this->fixPath($path)); } - public function renderEditorJsPath(string $editorJsPath = null): string + public function renderStyleBlock(string $path): string { - if ($editorJsPath === null) { - return $this->fixPath($this->options['editor_js_path']); - } - return $this->fixPath($editorJsPath); - } - - public function renderJqueryPath(string $jqueryPath = null): 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 - { - if ($editorCssPath === null) { - return $this->fixPath($this->options['editor_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($editorCssPath); + 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 { - if ($dependencies === null) { - $dependencies = $this->options['dependencies']; - } + $dependencies = $this->getOption(null, 'dependencies', $dependencies, $this->options, true); $dependenciesJsHtml = ""; $dependenciesCssHtml = ""; - if ($this->options['jquery']) { - $dependenciesJsHtml .= sprintf('', $this->fixPath($this->options['jquery_path'])); - } - foreach ($dependencies as $dependency) { - if ($dependency['js_path'] !== null) { - $dependenciesJsHtml .= sprintf('', $this->fixPath($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 .= sprintf('', $this->fixPath($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; } - public function renderViewer(string $id, string $content, string $viewerJsPath = null): string + public function renderExtensions($extensions, array $excludeList = []): string { - - 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'])); - $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'])); - 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; + foreach ($extensions as $extensionName => $extensionConfigs) { + if (in_array($extensionName, $excludeList)) continue; + + 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); } } } - - $viewerJsScript = sprintf( - '', - $this->fixContentToJs($content), - $id, - $id, - "300px", - $this->fixArrayToJs($extensions, "scrollSync") - ); - - return $viewerJsCode . $viewerCssCode . $extsJsHtml . $extsCssHtml . $viewerJsScript; + return $extsJsHtml.$extsCssHtml; } - private function fixArrayToJs(array $array, ?string $exclude = null): string + private function fixArrayToJs(array $array, array $excludeList = []): string { if (null == $array) { return ""; } - $jsArray = ""; - foreach ($array as $key => $item) { - if ($item == $exclude) continue; - if ($key !== sizeof($array) - 1) { - $jsArray .= "'" . $item . "',"; + $jsArray = []; + foreach ($array as $key=>$item) { + if (in_array($key, $excludeList)) continue; + $options = null; + if (is_array($item)) { + if (array_key_exists('options', $item)) { + $options = $item['options']; + } + } + if ($options) { + array_push($jsArray, '['.$key.','.json_encode($item['options']).']'); } else { - $jsArray .= "'" . $item . "'"; + array_push($jsArray, $key); } } - return $jsArray; + return implode(",", $jsArray); } - private function fixContentToJs(string $content): string + private function getContentToJson(string $content): string { if (null == $content) { - return ""; + $content = ""; } - $rows = explode("\r\n", $content); - - $jsArray = ""; - foreach ($rows as $index => $row) { - if ($index !== sizeof($rows) - 1) { - $jsArray .= "'" . $row . "',"; - } else { - $jsArray .= "'" . $row . "'"; - } - } - return $jsArray; + return json_encode($content); } private function fixPath(string $path): string @@ -259,69 +223,149 @@ private function getLanguage(): ?string return $this->locale; } - public function renderEditor(string $id, array $config, string $content = null): string + private function getOptionAsJson($key, $keyOption, $userPreferenceConfig, $config, $checkDefaultConfig = false): ?string { - $config = $this->fixConfigLanguage($config); - $extensions = $config['exts']; + return json_encode($this->getOption($key, $keyOption, $userPreferenceConfig, $config, $checkDefaultConfig)); + } - $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'])); + 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]; + } + } + } - $extsJsHtml = ""; - $extsCssHtml = ""; + private function getOptionForParentAsJson($key, $keyOption, $keyParent, $userPreferenceConfig, $config, $checkDefaultConfig = false): ?string + { + return json_encode($this->getOptionForParent($key, $keyOption, $keyParent, $userPreferenceConfig, $config, $checkDefaultConfig)); + } - if (null !== $extensions) { - foreach ($extensions as $extKey => $extValue) { - switch ($extValue) { - case 'scrollSync': - $extsJsHtml .= 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; + 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, ?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); + $extensionsnHtml = $this->renderExtensions($extensions); + $editorJsScript = sprintf( - '', - $this->fixContentToJs($content), + '', + $this->getContentToJson($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", + $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->fixArrayToJs($extensions), + $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 $editorJsCode . $editorCssCode . $editorContentsCssCode . $extsJsHtml . $extsCssHtml . $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/config/installer.xml b/src/Resources/config/installer.xml index 132a25d..8cc8b6c 100644 --- a/src/Resources/config/installer.xml +++ b/src/Resources/config/installer.xml @@ -5,6 +5,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > - + + + + diff --git a/src/Resources/views/Form/tuieditor_widget.html.twig b/src/Resources/views/Form/tuieditor_widget.html.twig index c6a3c2d..1018206 100644 --- a/src/Resources/views/Form/tuieditor_widget.html.twig +++ b/src/Resources/views/Form/tuieditor_widget.html.twig @@ -13,17 +13,15 @@ {% 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 18a89b0..30fe92b 100644 --- a/src/Twig/TuiEditorExtension.php +++ b/src/Twig/TuiEditorExtension.php @@ -24,45 +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_editor_contents_csss_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 renderEditorContentsCssPath(string $editorContentsCssPath = null): string + public function renderEditor(string $id, array $config, string $content = null, ?array $formConfig): 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 @@ -70,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); - } }