]> BookStack Code Mirror - bookstack/commitdiff
Merge pull request #4921 from BookStackApp/v24-02
authorDan Brown <redacted>
Fri, 5 Apr 2024 14:21:05 +0000 (15:21 +0100)
committerGitHub <redacted>
Fri, 5 Apr 2024 14:21:05 +0000 (15:21 +0100)
v23.02.3 changes

app/References/ReferenceFetcher.php
app/Util/HtmlDescriptionFilter.php
resources/js/code/index.mjs
resources/js/wysiwyg/config.js
resources/sass/_forms.scss
resources/sass/_tinymce.scss
tests/Entity/BookTest.php
tests/References/ReferencesTest.php

index 655ea7c09eb2bf8b0c21b7c30f0345b7ab0e3ea7..1c9664f45a9979d8c5e88627b4bb6eaa7547dd1a 100644 (file)
@@ -41,7 +41,8 @@ class ReferenceFetcher
     {
         $baseQuery = Reference::query()
             ->where('to_type', '=', $entity->getMorphClass())
-            ->where('to_id', '=', $entity->id);
+            ->where('to_id', '=', $entity->id)
+            ->whereHas('from');
 
         return $this->permissions->restrictEntityRelationQuery(
             $baseQuery,
index 7287586d16fadff29740760599051630edf5e927..cb091b869f8fc9a2ec5d4a9ba644387612f82c95 100644 (file)
@@ -20,7 +20,7 @@ class HtmlDescriptionFilter
      */
     protected static array $allowedAttrsByElements = [
         'p' => [],
-        'a' => ['href', 'title'],
+        'a' => ['href', 'title', 'target'],
         'ol' => [],
         'ul' => [],
         'li' => [],
index d252f8f41013810f357f732a80ab27971ce0be4f..ab31e3f74e43d9ddf2334a9f5f7e183d906d1851 100644 (file)
@@ -48,14 +48,16 @@ function highlightElem(elem) {
     const content = elem.textContent.trimEnd();
 
     let langName = '';
+    let innerCodeDirection = '';
     if (innerCodeElem !== null) {
         langName = innerCodeElem.className.replace('language-', '');
+        innerCodeDirection = innerCodeElem.getAttribute('dir');
     }
 
     const wrapper = document.createElement('div');
     elem.parentNode.insertBefore(wrapper, elem);
 
-    const direction = innerCodeElem.getAttribute('dir') || elem.getAttribute('dir') || '';
+    const direction = innerCodeDirection || elem.getAttribute('dir') || '';
     if (direction) {
         wrapper.setAttribute('dir', direction);
     }
index e5a780d18e9ee9e2bfd052829bc0adb762da7fd9..1666aa50066af25f3ab38b12a996cce2148672bb 100644 (file)
@@ -348,7 +348,7 @@ export function buildForInput(options) {
         toolbar: 'bold italic link bullist numlist',
         content_style: getContentStyle(options),
         file_picker_types: 'file',
-        valid_elements: 'p,a[href|title],ol,ul,li,strong,em,br',
+        valid_elements: 'p,a[href|title|target],ol,ul,li,strong,em,br',
         file_picker_callback: filePickerCallback,
         init_instance_callback(editor) {
             addCustomHeadContent(editor.getDoc());
index 8c277c2b5010c755eede2124fa88d59cc45a259c..e480531fc52afda159342407c80acff847f413e0 100644 (file)
   body {
     display: block;
     background-color: #fff;
-    padding-inline-start: 16px;
-    padding-inline-end: 16px;
+    padding-inline-start: 12px;
+    padding-inline-end: 12px;
+    max-width: 864px;
   }
   [drawio-diagram]:hover {
     outline: 2px solid var(--color-primary);
index 7e443ff5a6bb11ece01a9fe411839a34de6f94bf..29843e4246fdfe49aa3c2c46e82a7d22504138d6 100644 (file)
@@ -21,6 +21,7 @@
   padding-block-end: 1rem;
   outline: 0;
   display: block;
+  max-width: 870px;
 }
 
 .wysiwyg-input.mce-content-body {
index 04dff293facd20805e1281b4264f8808470c902e..51bf65d10bb29d92668fd80bfb1614688cf73c83 100644 (file)
@@ -266,8 +266,8 @@ class BookTest extends TestCase
     {
         $book = $this->entities->book();
 
-        $input = '<h1>Test</h1><p id="abc" href="beans">Content<a href="#cat" data-a="b">a</a><section>Hello</section></p>';
-        $expected = '<p>Content<a href="#cat">a</a></p>';
+        $input = '<h1>Test</h1><p id="abc" href="beans">Content<a href="#cat" target="_blank" data-a="b">a</a><section>Hello</section></p>';
+        $expected = '<p>Content<a href="#cat" target="_blank">a</a></p>';
 
         $this->asEditor()->put($book->getUrl(), [
             'name' => $book->name,
index 715f7143534b09ddcf179bd2517c5a11c6461462..f8698d028858145deba511a35784839d5d7de9df 100644 (file)
@@ -271,7 +271,31 @@ class ReferencesTest extends TestCase
         }
     }
 
-    protected function createReference(Model $from, Model $to)
+    public function test_reference_from_deleted_item_does_not_count_or_show_in_references_page()
+    {
+        $page = $this->entities->page();
+        $referencingPageA = $this->entities->page();
+        $referencingPageB = $this->entities->page();
+
+        $this->asEditor();
+        $this->createReference($referencingPageA, $page);
+        $this->createReference($referencingPageB, $page);
+
+        $resp = $this->get($page->getUrl());
+        $resp->assertSee('Referenced by 2 items');
+
+        $this->delete($referencingPageA->getUrl());
+
+        $resp = $this->get($page->getUrl());
+        $resp->assertSee('Referenced by 1 item');
+
+        $resp = $this->get($page->getUrl('/references'));
+        $resp->assertOk();
+        $resp->assertSee($referencingPageB->getUrl());
+        $resp->assertDontSee($referencingPageA->getUrl());
+    }
+
+    protected function createReference(Model $from, Model $to): void
     {
         (new Reference())->forceFill([
             'from_type' => $from->getMorphClass(),