fix(submit): show body placeholder on first load and restore caret on blank clicks
两个前台投稿编辑器的缺陷,根因都在占位符的实现方式: 1. 首次加载不显示占位符,输入一个再删掉才出现。 旧实现往正文插了一个 data-mce-bogus 占位段落,而 TinyMCE 在 setContent(studio 初始化时必调)与清理 bogus 元素时会把它移除。 2. 光标在块级结构里时,点击正文空白处无法落回正文。 占位段落占着首行、且 pointer-events:none,点击落不到可编辑元素上; 正文以表格 / 代码块这类结构块结尾时也没有可承载光标的段落。 改为 front-submit-editor-basics.js(替换 front-submit-placeholder.js): - 占位符改成 body 属性 + content CSS 的 ::before,正文 DOM 不含占位节点; - 点击空白处(事件目标是 body)且光标不在普通文本里时,补一个可编辑尾段 并把光标放进去; - 两份 content CSS 让 html/body 撑满编辑区,studio 的 syncEditorHeight 以编辑器声明高度为下限,空正文时 iframe 不会缩成一行。 新增 tests/widget-system/submit-placeholder-behavior.test.cjs(jsdom 跑真实插件)。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c2733017fd
commit
5afa7ab9df
10 files changed
+428
-172
No files matched your search
@@ -55,7 +55,7 @@ $is_can_new = !empty($ctx['is_can_new']);
|
||||
$toolbar1[] = 'jio_hide';
|
||||
}
|
||||
$toolbar1 = implode(',', array_merge($toolbar1, ['jio_quote', 'jio_precode', 'fullscreen', 'wp_adv']));
|
||||
// jio_placeholder 通过 external_plugins 注册:WordPress 会丢弃
|
||||
// jio_editor_basics 通过 external_plugins 注册:WordPress 会丢弃
|
||||
// 名字已出现在 plugins 列表里的外部插件,写在这里反而加载不到。
|
||||
$plugins = 'paste,link,lists,fullscreen,wordpress,wplink,charmap,colorpicker,textcolor';
|
||||
$editor_plugin_path = get_template_directory() . '/assets/js/front-submit-editor.js';
|
||||
@@ -63,20 +63,20 @@ $is_can_new = !empty($ctx['is_can_new']);
|
||||
if (file_exists($editor_plugin_path)) {
|
||||
$editor_plugin_url = add_query_arg('ver', (string) filemtime($editor_plugin_path), $editor_plugin_url);
|
||||
}
|
||||
$placeholder_plugin_path = get_template_directory() . '/assets/js/front-submit-placeholder.js';
|
||||
$placeholder_plugin_url = get_template_directory_uri() . '/assets/js/front-submit-placeholder.js';
|
||||
if (file_exists($placeholder_plugin_path)) {
|
||||
$placeholder_plugin_url = add_query_arg('ver', (string) filemtime($placeholder_plugin_path), $placeholder_plugin_url);
|
||||
$editor_basics_plugin_path = get_template_directory() . '/assets/js/front-submit-editor-basics.js';
|
||||
$editor_basics_plugin_url = get_template_directory_uri() . '/assets/js/front-submit-editor-basics.js';
|
||||
if (file_exists($editor_basics_plugin_path)) {
|
||||
$editor_basics_plugin_url = add_query_arg('ver', (string) filemtime($editor_basics_plugin_path), $editor_basics_plugin_url);
|
||||
}
|
||||
$editor_css_path = get_template_directory() . '/assets/css/frontend/pages/submit-editor.css';
|
||||
$editor_css_url = get_template_directory_uri() . '/assets/css/frontend/pages/submit-editor.css';
|
||||
if (file_exists($editor_css_path)) {
|
||||
$editor_css_url = add_query_arg('ver', (string) filemtime($editor_css_path), $editor_css_url);
|
||||
}
|
||||
$external_plugins = static function (array $external, string $editor_id) use ($editor_plugin_url, $placeholder_plugin_url): array {
|
||||
$external_plugins = static function (array $external, string $editor_id) use ($editor_plugin_url, $editor_basics_plugin_url): array {
|
||||
if ($editor_id === 'post_content') {
|
||||
$external['jio_editor_tools'] = $editor_plugin_url;
|
||||
$external['jio_placeholder'] = $placeholder_plugin_url;
|
||||
$external['jio_editor_basics'] = $editor_basics_plugin_url;
|
||||
}
|
||||
return $external;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user