From e6504951c879321c7332d24c447038cfd1a0c6f8 Mon Sep 17 00:00:00 2001 From: LB Johnston Date: Sat, 6 Apr 2024 15:48:32 +1000 Subject: [PATCH] Add deprecated backwards compatible window.URLify with release notes - Add legacy support for window.URLify with allowUnicode as a param - Add release notes details for both window.URLify (deprecated) & window.XRegExp (removed) --- client/src/entrypoints/admin/core.js | 19 ++++++++++++++- docs/releases/6.1.md | 35 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/client/src/entrypoints/admin/core.js b/client/src/entrypoints/admin/core.js index 2e4c6ef03a..22733fbc0d 100644 --- a/client/src/entrypoints/admin/core.js +++ b/client/src/entrypoints/admin/core.js @@ -3,11 +3,13 @@ import * as StimulusModule from '@hotwired/stimulus'; import { Icon, Portal } from '../..'; import { coreControllerDefinitions } from '../../controllers'; -import { escapeHtml } from '../../utils/text'; import { InlinePanel } from '../../components/InlinePanel'; import { MultipleChooserPanel } from '../../components/MultipleChooserPanel'; import { initStimulus } from '../../includes/initStimulus'; +import { urlify } from '../../utils/urlify'; +import { escapeHtml } from '../../utils/text'; + /** Expose a global to allow for customisations and packages to build with Stimulus. */ window.StimulusModule = StimulusModule; @@ -38,6 +40,21 @@ window.InlinePanel = InlinePanel; window.MultipleChooserPanel = MultipleChooserPanel; +/** + * Support legacy global URLify which can be called with `allowUnicode` as a third param. + * Was not documented and only used in modeladmin prepopulate JS. + * + * @deprecated RemovedInWagtail70 + * @see https://github.com/django/django/blob/main/django/contrib/admin/static/admin/js/urlify.js#L156 + * + * @param {string} str + * @param {number} numChars + * @param {boolean} allowUnicode + * @returns {string} + */ +window.URLify = (str, numChars = 255, allowUnicode = false) => + urlify(str, { numChars, allowUnicode }); + $(() => { /* Dropzones */ $('.drop-zone') diff --git a/docs/releases/6.1.md b/docs/releases/6.1.md index 3e86f63cae..e7e34cb889 100644 --- a/docs/releases/6.1.md +++ b/docs/releases/6.1.md @@ -281,3 +281,38 @@ In the new approach, we no longer need to attach an inline script but instead us ### Removal of jQuery from base client-side Widget and BoundWidget classes The JavaScript base classes `Widget` and `BoundWidget` that provide client-side access to form widgets (see [](streamfield_widget_api)) no longer use jQuery. The `element` argument passed to the `BoundWidget` constructor, and the `input` property of `BoundWidget`, are now native DOM elements rather than jQuery collections. User code that extends these classes should be updated accordingly. + +### `window.URLify` deprecated + +The undocumented client-side global util `window.URLify` is now deprecated and will be removed in a future release. + +If this was required for slug field behavior, it's recommended that the `SlugInput` widget be used instead. This will automatically convert values entered into a suitable slug in the browser while respecting the global configuration `WAGTAIL_ALLOW_UNICODE_SLUGS`. + +```python +from wagtail.admin.widgets.slug import SlugInput +# ... other imports + +class MyPage(Page): + promote_panels = [ + FieldPanel("slug", widget=SlugInput), + # ... other panels + ] +``` + +If you require this for custom JavaScript functionality, it's recommended you either include your own implementation from the original [Django URLify source](https://raw.githubusercontent.com/wagtail/wagtail/stable/6.0.x/wagtail/admin/static_src/wagtailadmin/js/vendor/urlify.js). Alternatively, the [`slugify`](https://www.npmjs.com/package/slugify) or [`parameterize` (a Django URLify port)](https://www.npmjs.com/package/parameterize) NPM packages might be suitable. + +### `window.XRegExp` polyfill removed + +The legacy `window.XRegExp` global polyfill util has been removed and will throw an error if called. + +Instead, any usage of this should be updated to the well supported [browser native Regex implementation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions). + +```javascript +// old +const newStr = XRegExp.replace(originalStr, XRegExp('[ab+c]', 'g'), '') + +// new (with RegExp) +const newStr = originalStr.replace(new RegExp('[ab+c]', 'g'), '') +// OR +const newStr = originalStr.replace(/[ab+c]/g, 'g'), '') +```