0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 05:02:57 +01:00

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)
This commit is contained in:
LB Johnston 2024-04-06 15:48:32 +10:00 committed by LB (Ben Johnston)
parent be5b69078a
commit e6504951c8
2 changed files with 53 additions and 1 deletions

View File

@ -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')

View File

@ -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'), '')
```