Repository: wagtail-nest/wagtail-hallo (language: python)

Issue:
Updated responses to match Wagtail 4 chooser names
Fixes #33 

However, changing these 2 lines means at this point, the code is no longer agnostic between Wagtail 3 and 4. @lb- I don't know a trick like the try/catch for python imports that would allow this to work on both sets. Should we create a pypi release with the previous code (and stating Wagtail <= 3) and then merge this and declare this Wagtail 4+? If so, should we go ahead and remove the ifs in the imports? 

(I have tested this fix and it works on Wagtail 4.0 and 4.1)


Discussion / hints:
Hey @cnk  - it probably makes sense to try to do a 3.0 compatible release and then do this change as a different one that is 4.0 compatible but drops < 3.0.


https://github.com/wagtail-nest/wagtail-hallo/blob/main/wagtail_hallo/test/tests/hallo.test.js

Wagtail uses Jest - but here are the docs https://jestjs.io/

```
npm ci
npm run test # run all tests
```

```
npm run test -- --watch
```

https://jestjs.io/docs/cli - to pass in cli arguments to npm scripts remember to use the `--` before these

@cnk FYI I just submitted https://github.com/wagtail-nest/wagtail-hallo/pull/38 for the wagtail 4.2 upgrade. It might mean that this change isn't required. 🤞 
This change is very much required in that it related to the JS callbacks for the choosers

Fix patch:
diff --git a/.github/report_nightly_build_failure.py b/.github/report_nightly_build_failure.py
index 29ceca9..4b7e11f 100644
--- a/.github/report_nightly_build_failure.py
+++ b/.github/report_nightly_build_failure.py
@@ -2,6 +2,7 @@
 Called by GitHub Actions when the nightly build fails.
 This reports an error to the #nightly-build-failures Slack channel.
 """
+
 import os
 import requests
 
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9065e30..bdd8cca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,11 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ## [unreleased] - YYYY-MM-DD
 
-- Add Wagtail 3 classifier for PyPI _Paarth Agarwal_
 - Add Django 4.1 and Python 3.10 classifier to PyPI _Joren Hammudoglu_
 - Add Django 4.1 support to CI _Joren Hammudoglu_
 - Add support for Wagtail 4 _Katherine Domingo_
 
+## [0.2.0] - 2024-12-02
+
+- Add Wagtail 3 classifier for PyPI _Paarth Agarwal_
+- Fix toolbar scrolling out of the editor textarea _RobertRollins_
+
 ## [0.1.0] - 2022-05-05
 
 - First non-alpha release
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index f47733a..1f6d974 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -10,3 +10,4 @@ A special thanks to the 100s of developers who, over the course of 2014 to 2022
 - Paarth Agarwal
 - Joren Hammudoglu
 - Katherine Domingo
+- Robert Rollins
diff --git a/README.md b/README.md
index 576f0b2..8b9dd58 100644
--- a/README.md
+++ b/README.md
@@ -22,8 +22,8 @@ This is the legacy rich text editor for the Wagtail CMS. Based on [Hallo.js](htt
 ## Supported Versions
 
 - Python 3.7, 3.8, 3.9 3.10
-- Django 3.2. 4.0 4.1
-- Wagtail 2.15, 2.16, 3.0, 4.0
+- Django 3.2. 4.0
+- Wagtail 2.15, 2.16, 3.0
 
 ## Installing the Hallo Editor
 
@@ -148,7 +148,7 @@ When writing the front-end code for the plugin, Wagtail’s Hallo implementation
 
 After extending the editor to support a new HTML element, you'll need to add it to the whitelist of permitted elements - Wagtail's standard behaviour is to strip out unrecognised elements, to prevent editors from inserting styles and scripts (either deliberately, or inadvertently through copy-and-paste) that the developer didn't account for.
 
-Elements can be added to the whitelist through the feature registry's `register_converter_rule(converter, feature_name, ruleset)` method. When the `hallo.js` editor is in use, the `converter` parameter should always be `'editorhtml'`.
+Elements can be added to the whitelist through the feature registry's `register_converter_rule(converter, feature_name, ruleset)` method. When the `hallo.js` editor is in use, the `converter` parameter should always be `'editorhtml'`. The `feature_name` is the name of your plugin.
 
 The following code will add the `<blockquote>` element to the whitelist whenever the `block-quote` feature is active:
 
diff --git a/wagtail_hallo/static/css/hallo.css b/wagtail_hallo/static/css/hallo.css
index 5ddc46f..81b1668 100644
--- a/wagtail_hallo/static/css/hallo.css
+++ b/wagtail_hallo/static/css/hallo.css
@@ -201,7 +201,7 @@
   display: block;
 }
 
-/* 
+/*
   These styles correspond to the image formats defined in wagtailimages/formats.py,
   so that images displayed in the rich text field receive more or less the same
   styling that they would receive on the site front-end.
@@ -231,27 +231,27 @@
 }
 
 /* Page Editor */
-.object .halloeditor {
+.halloeditor {
   padding-top: 1em;
   padding-bottom: 1em;
 }
 
-.object .halloeditor.expanded {
-  padding-top: 5em;
+.halloeditor.expanded {
+  padding-top: 7em;
   padding-bottom: 2em;
 }
 
-.object.full .halloeditor {
+.full .halloeditor {
   padding-top: 3em;
   padding-bottom: 3em;
 }
 
-.object.full .halloeditor.expanded {
+.full .halloeditor.expanded {
   padding-top: 5em;
   padding-bottom: 5em;
 }
 
-.object.full .error .halloeditor {
+.full .error .halloeditor {
   background-color: #ffe6e6;
 }
 
@@ -273,7 +273,7 @@
   font-family: Roboto Slab, Georgia, serif;
 }
 @media screen and (min-width: breakpoint-min(sm)) {
-  .object.full .halloeditor {
+  .full .halloeditor {
     border-width: 0 1px;
   }
 }
diff --git a/wagtail_hallo/static/js/hallo-editor.js b/wagtail_hallo/static/js/hallo-editor.js
index d6d1d32..3da43ca 100644
--- a/wagtail_hallo/static/js/hallo-editor.js
+++ b/wagtail_hallo/static/js/hallo-editor.js
@@ -88,12 +88,14 @@
           /* Hallo's toolbar will reposition itself on the scroll event.
         This is useful since animating the fields can cause it to be
         positioned badly initially. */
-          $(window).trigger('scroll');
+          // Adding .content-wrapper as a triggered element makes this work
+          // in Wagtail 4.
+          $(window).add('.content-wrapper').trigger('scroll');
         });
       })
       .on('hallodeactivated', function (event) {
         $(event.target).removeClass('expanded', 200, function () {
-          $(window).trigger('scroll');
+          $(window).add('.content-wrapper').trigger('scroll');
         });
       });
     setupLinkTooltips(editor);
diff --git a/wagtail_hallo/static/js/vendor/hallo.js b/wagtail_hallo/static/js/vendor/hallo.js
index 6c4bb84..1f1678e 100644
--- a/wagtail_hallo/static/js/vendor/hallo.js
+++ b/wagtail_hallo/static/js/vendor/hallo.js
@@ -3184,12 +3184,18 @@
         this.toolbar.show();
         jQuery(this.options.parentElement).append(this.toolbar);
         this._bindEvents();
-        jQuery(window).on('resize', function (event) {
-          return _this.setPosition();
-        });
-        jQuery(window).on('scroll', function (event) {
-          return _this.setPosition();
-        });
+        // Adding .content-wrapper as a triggering element makes these work
+        // in Wagtail 4.
+        jQuery(window)
+          .add('.content-wrapper')
+          .on('resize', function (event) {
+            return _this.setPosition();
+          });
+        jQuery(window)
+          .add('.content-wrapper')
+          .on('scroll', function (event) {
+            return _this.setPosition();
+          });
         if (this.options.parentElement === 'body') {
           el = jQuery(this.element);
           widthToAdd = parseFloat(el.css('padding-left'));
@@ -3232,6 +3238,8 @@
           return;
         }
         this.toolbar.css('position', 'absolute');
+        // The 44 is to account for the changes to the Page Editor UI in
+        // Wagtail 4.
         this.toolbar.css(
           'top',
           this.element.offset().top - this.toolbar.outerHeight(),
@@ -3249,7 +3257,6 @@
             this.toolbar.css('position', 'fixed');
             this.toolbar.css('top', this.options.affixTopOffset);
           }
-        } else {
         }
 
         return this.toolbar.css('left', this.element.offset().left - 2);


Test patch:
diff --git a/wagtail_hallo/test/migrations/0001_initial.py b/wagtail_hallo/test/migrations/0001_initial.py
index cecea09..1ab7304 100644
--- a/wagtail_hallo/test/migrations/0001_initial.py
+++ b/wagtail_hallo/test/migrations/0001_initial.py
@@ -36,31 +36,33 @@ class Migration(migrations.Migration):
                 ("body", fields.RichTextField(blank=True)),
                 (
                     "body_stream",
-                    fields.StreamField(
-                        [
-                            (
-                                "heading",
-                                blocks.CharBlock(form_classname="full title"),
-                            ),
-                            (
-                                "paragraph",
-                                blocks.RichTextBlock(editor="hallo"),
-                            ),
-                        ],
-                        use_json_field=True,
-                    )
-                    if WAGTAIL_VERSION >= (3, 0)
-                    else fields.StreamField(
-                        [
-                            (
-                                "heading",
-                                blocks.CharBlock(form_classname="full title"),
-                            ),
-                            (
-                                "paragraph",
-                                blocks.RichTextBlock(editor="hallo"),
-                            ),
-                        ],
+                    (
+                        fields.StreamField(
+                            [
+                                (
+                                    "heading",
+                                    blocks.CharBlock(form_classname="full title"),
+                                ),
+                                (
+                                    "paragraph",
+                                    blocks.RichTextBlock(editor="hallo"),
+                                ),
+                            ],
+                            use_json_field=True,
+                        )
+                        if WAGTAIL_VERSION >= (3, 0)
+                        else fields.StreamField(
+                            [
+                                (
+                                    "heading",
+                                    blocks.CharBlock(form_classname="full title"),
+                                ),
+                                (
+                                    "paragraph",
+                                    blocks.RichTextBlock(editor="hallo"),
+                                ),
+                            ],
+                        )
                     ),
                 ),
             ],