0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-04-18 18:38:44 +00:00

Comments: Added input wysiwyg for creating/updating comments

Not supporting old content, existing HTML or updating yet.
This commit is contained in:
Dan Brown 2024-01-30 14:27:09 +00:00
parent 24e6dc4b37
commit 5c92b72fdd
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
8 changed files with 85 additions and 12 deletions

View file

@ -41,6 +41,17 @@ class CommentTree
return $this->tree; return $this->tree;
} }
public function canUpdateAny(): bool
{
foreach ($this->comments as $comment) {
if (userCan('comment-update', $comment)) {
return true;
}
}
return false;
}
/** /**
* @param Comment[] $comments * @param Comment[] $comments
*/ */

View file

@ -1,5 +1,6 @@
import {Component} from './component'; import {Component} from './component';
import {getLoading, htmlToDom} from '../services/dom'; import {getLoading, htmlToDom} from '../services/dom';
import {buildForInput} from "../wysiwyg/config";
export class PageComment extends Component { export class PageComment extends Component {
@ -11,7 +12,12 @@ export class PageComment extends Component {
this.deletedText = this.$opts.deletedText; this.deletedText = this.$opts.deletedText;
this.updatedText = this.$opts.updatedText; this.updatedText = this.$opts.updatedText;
// Element References // Editor reference and text options
this.wysiwygEditor = null;
this.wysiwygLanguage = this.$opts.wysiwygLanguage;
this.wysiwygTextDirection = this.$opts.wysiwygTextDirection;
// Element references
this.container = this.$el; this.container = this.$el;
this.contentContainer = this.$refs.contentContainer; this.contentContainer = this.$refs.contentContainer;
this.form = this.$refs.form; this.form = this.$refs.form;
@ -50,8 +56,23 @@ export class PageComment extends Component {
startEdit() { startEdit() {
this.toggleEditMode(true); this.toggleEditMode(true);
const lineCount = this.$refs.input.value.split('\n').length;
this.$refs.input.style.height = `${(lineCount * 20) + 40}px`; if (this.wysiwygEditor) {
return;
}
const config = buildForInput({
language: this.wysiwygLanguage,
containerElement: this.input,
darkMode: document.documentElement.classList.contains('dark-mode'),
textDirection: this.wysiwygTextDirection,
translations: {},
translationMap: window.editor_translations,
});
window.tinymce.init(config).then(editors => {
this.wysiwygEditor = editors[0];
});
} }
async update(event) { async update(event) {

View file

@ -1,5 +1,6 @@
import {Component} from './component'; import {Component} from './component';
import {getLoading, htmlToDom} from '../services/dom'; import {getLoading, htmlToDom} from '../services/dom';
import {buildForInput} from "../wysiwyg/config";
export class PageComments extends Component { export class PageComments extends Component {
@ -21,6 +22,11 @@ export class PageComments extends Component {
this.hideFormButton = this.$refs.hideFormButton; this.hideFormButton = this.$refs.hideFormButton;
this.removeReplyToButton = this.$refs.removeReplyToButton; this.removeReplyToButton = this.$refs.removeReplyToButton;
// WYSIWYG options
this.wysiwygLanguage = this.$opts.wysiwygLanguage;
this.wysiwygTextDirection = this.$opts.wysiwygTextDirection;
this.wysiwygEditor = null;
// Translations // Translations
this.createdText = this.$opts.createdText; this.createdText = this.$opts.createdText;
this.countText = this.$opts.countText; this.countText = this.$opts.countText;
@ -96,9 +102,7 @@ export class PageComments extends Component {
this.formContainer.toggleAttribute('hidden', false); this.formContainer.toggleAttribute('hidden', false);
this.addButtonContainer.toggleAttribute('hidden', true); this.addButtonContainer.toggleAttribute('hidden', true);
this.formContainer.scrollIntoView({behavior: 'smooth', block: 'nearest'}); this.formContainer.scrollIntoView({behavior: 'smooth', block: 'nearest'});
setTimeout(() => { this.loadEditor();
this.formInput.focus();
}, 100);
} }
hideForm() { hideForm() {
@ -112,6 +116,26 @@ export class PageComments extends Component {
this.addButtonContainer.toggleAttribute('hidden', false); this.addButtonContainer.toggleAttribute('hidden', false);
} }
loadEditor() {
if (this.wysiwygEditor) {
return;
}
const config = buildForInput({
language: this.wysiwygLanguage,
containerElement: this.formInput,
darkMode: document.documentElement.classList.contains('dark-mode'),
textDirection: this.wysiwygTextDirection,
translations: {},
translationMap: window.editor_translations,
});
window.tinymce.init(config).then(editors => {
this.wysiwygEditor = editors[0];
this.wysiwygEditor.focus();
});
}
getCommentCount() { getCommentCount() {
return this.container.querySelectorAll('[component="page-comment"]').length; return this.container.querySelectorAll('[component="page-comment"]').length;
} }

View file

@ -10,11 +10,8 @@ export class WysiwygInput extends Component {
language: this.$opts.language, language: this.$opts.language,
containerElement: this.elem, containerElement: this.elem,
darkMode: document.documentElement.classList.contains('dark-mode'), darkMode: document.documentElement.classList.contains('dark-mode'),
textDirection: this.textDirection, textDirection: this.$opts.textDirection,
translations: { translations: {},
imageUploadErrorText: this.$opts.imageUploadErrorText,
serverUploadLimitText: this.$opts.serverUploadLimitText,
},
translationMap: window.editor_translations, translationMap: window.editor_translations,
}); });

View file

@ -30,6 +30,13 @@
display: block; display: block;
} }
.wysiwyg-input.mce-content-body:before {
padding: 1rem;
top: 4px;
font-style: italic;
color: rgba(34,47,62,.5)
}
// Default styles for our custom root nodes // Default styles for our custom root nodes
.page-content.mce-content-body doc-root { .page-content.mce-content-body doc-root {
display: block; display: block;

View file

@ -4,6 +4,8 @@
option:page-comment:comment-parent-id="{{ $comment->parent_id }}" option:page-comment:comment-parent-id="{{ $comment->parent_id }}"
option:page-comment:updated-text="{{ trans('entities.comment_updated_success') }}" option:page-comment:updated-text="{{ trans('entities.comment_updated_success') }}"
option:page-comment:deleted-text="{{ trans('entities.comment_deleted_success') }}" option:page-comment:deleted-text="{{ trans('entities.comment_deleted_success') }}"
option:page-comment:wysiwyg-language="{{ $locale->htmlLang() }}"
option:page-comment:wysiwyg-text-direction="{{ $locale->htmlDirection() }}"
id="comment{{$comment->local_id}}" id="comment{{$comment->local_id}}"
class="comment-box"> class="comment-box">
<div class="header"> <div class="header">

View file

@ -2,6 +2,8 @@
option:page-comments:page-id="{{ $page->id }}" option:page-comments:page-id="{{ $page->id }}"
option:page-comments:created-text="{{ trans('entities.comment_created_success') }}" option:page-comments:created-text="{{ trans('entities.comment_created_success') }}"
option:page-comments:count-text="{{ trans('entities.comment_count') }}" option:page-comments:count-text="{{ trans('entities.comment_count') }}"
option:page-comments:wysiwyg-language="{{ $locale->htmlLang() }}"
option:page-comments:wysiwyg-text-direction="{{ $locale->htmlDirection() }}"
class="comments-list" class="comments-list"
aria-label="{{ trans('entities.comments') }}"> aria-label="{{ trans('entities.comments') }}">
@ -24,7 +26,6 @@
@if(userCan('comment-create-all')) @if(userCan('comment-create-all'))
@include('comments.create') @include('comments.create')
@if (!$commentTree->empty()) @if (!$commentTree->empty())
<div refs="page-comments@addButtonContainer" class="text-right"> <div refs="page-comments@addButtonContainer" class="text-right">
<button type="button" <button type="button"
@ -34,4 +35,11 @@
@endif @endif
@endif @endif
@if(userCan('comment-create-all') || $commentTree->canUpdateAny())
@push('post-app-scripts')
<script src="{{ versioned_asset('libs/tinymce/tinymce.min.js') }}" nonce="{{ $cspNonce }}"></script>
@include('form.editor-translations')
@endpush
@endif
</section> </section>

View file

@ -68,10 +68,13 @@
</div> </div>
@yield('bottom') @yield('bottom')
@if($cspNonce ?? false) @if($cspNonce ?? false)
<script src="{{ versioned_asset('dist/app.js') }}" nonce="{{ $cspNonce }}"></script> <script src="{{ versioned_asset('dist/app.js') }}" nonce="{{ $cspNonce }}"></script>
@endif @endif
@yield('scripts') @yield('scripts')
@stack('post-app-scripts')
@include('layouts.parts.base-body-end') @include('layouts.parts.base-body-end')
</body> </body>