Skip to content

[6.x] Move CKEditor off jQuery and the Craft globals - #643

Merged
i-just merged 27 commits into
feature/craft-6from
chore/js-modules-jquery
Nov 9, 2026
Merged

i-just merged 27 commits into
feature/craft-6from
chore/js-modules-jquery

Conversation

@brianjhanson

@brianjhanson brianjhanson commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Moves CKEditor's control panel code onto the shared import-map modules, without requiring the Yii2 adapter's globals.

 editor and settings bundles
- jQuery, window.Craft, window.Garnish, Velocity
+ @craftcms/cp, @craftcms/garnish, native DOM and ES classes

 upload
- progress bar below the field
+ shared upload notification
  insert the asset only after upload completes

The toolbar now clones component nodes directly, caches button configuration lookups, and handles canceled animations without running their completion callbacks. Margin animations respect reduced motion. The TypeScript declarations and development re-exports cover only t and actionClient, the APIs that bundle uses.

Upload placeholders and their restoration hooks were removed. Pending uploads do not add temporary image data to the saved field value. User-authored JavaScript config can still use $ when window.jQuery is available. This targets Craft 6, with no Craft 5 fallback.

Depends on craftcms/cms#20359. The base branch also requires craftcms/cms#20328 for HtmlSanitizerManager::config().

Evidence

  • Before: Chromium checks against 0b6eecf failed because canceling a toolbar drag hid its source item, and dropping an image serialized a temporary SVG data URI.
    After: Both checks pass. The same browser run also covers toolbar add/remove configuration updates, reduced-motion restoration with forced colors enabled, completed image insertion, default transforms, and failed/canceled uploads. It uses the real editor and Garnish libraries with a controlled upload boundary, not a live-server upload.
  • Rebuilt all three bundles. npm run typecheck, npm run check-prettier, and git diff --check pass.
  • The original branch reports 48 live control panel checks and a global-read probe. Those were not rerun after the simplifications. Full control panel keyboard, screen-reader, contrast, and reflow checks remain unverified.

Related issues

The control panel's selector hands back plain element info and a meta
object, so the image insert flow reads the asset's alt and transform from
there rather than from a jQuery collection.
Selecting a mode now follows the listbox's change event rather than a
click, so keyboard selection counts, and the generated editor module
keeps $ bound for custom config JS that still uses it.
Replaces the progress bar under the field, which duplicated what the
upload notification already reports. The placeholder goes in at the drop
position and its source is swapped for the asset's once the upload
lands; creating the owner's draft replaces the editor's value, so
pending placeholders are put back after a reload.
Keeps the Craft.* and Garnish.* shape at the call sites, so the diff
stays close to the original and CKEditor's own locale `t` is no longer
shadowed. The generated editor module keeps a named import, since a
namespace called Craft there would shadow the global for a field's
custom config JS.

@brianjhanson brianjhanson left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@i-just this is a fairly straightforward rewrite of the javascript to move away from jQuery. It does rely on craftcms/cms#20359 which exposes a handful of functions necessary for this

Remove upload placeholders and their restoration hooks. Fix canceled toolbar animations, respect reduced motion, cache configuration lookups, and clone toolbar components directly. Repair corrupted strings and trim unused module declarations and dev exports.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brianjhanson brianjhanson changed the title Move CKEditor off jQuery, Garnish and the Craft globals [6.x] Move CKEditor off jQuery and the Craft globals Nov 4, 2026
i-just and others added 9 commits November 5, 2026 13:46
resources/assets/fieldsettings/vite/ held the output of the first Vite
builds, from before outDir was switched to dist/. Nothing loads it, and
it still contained the old jQuery/Velocity ToolbarBuilder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lock file still listed jQuery as a root peer dependency after it was
removed from package.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing reads window.Craft any more, and the global const would hide a
missing `import * as Craft from '@craftcms/cp'` from type-checking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Web Animations API doesn't write in-between values to the inline
style the way Velocity did, so releasing a source item mid-collapse
snapped it back to full width. Read the margin from the computed style
instead, which includes running animations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each modal mounts its own Vue app into a host element on <body>, which
only the handle's destroy() removes, so every image or element link
selection left one behind. Also stop passing closeOtherModals to the
link selector, since the modal ignores it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The element editor panel never triggers beforeClose, so the cursor and
focus weren't restored after creating an entry from the toolbar. Use
the onClose setting instead, and place the cursor after the new card,
adding a paragraph when no text block follows it. Canceling still
returns the cursor to where it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every name used from @craftcms/cp in the TypeScript bundle has to be
declared in craftcms-cp.d.ts and listed in vite.config.mts, and one
missing from the Vite list is only noticed under the dev server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The row relied on Craft 5's .flex for its gap and wrapping, so in Craft 6
its items sat flush against each other and the sites dropdown stayed on
the same line instead of breaking onto its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without one, addActionsToChip() had nowhere to put the Replace and
Remove actions, and its jQuery fallback no longer runs. Request the chip
with its action menu, limited to the View and Edit actions, and add
Replace and Remove to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@i-just

i-just commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thanks, @brianjhanson, looks good!

I pushed a few tweaks:

  • Element selector modals are now cleaned up when they close. Before, each image or link selection left a hidden modal behind on the page.
  • Removed leftovers: the old fieldsettings/vite/ build folder, jQuery in package-lock.json, and the global Craft typing in window.d.ts.
  • Toolbar builder: releasing a dragged button quickly no longer makes it snap back; it animates smoothly again.
  • New entries from the toolbar: after creating one, the cursor now lands after the new card and the editor gets focus back.
  • Link balloon:
    • The spacing and layout match Craft 5 again, with the sites dropdown back on its own line.
    • The selected element's chip has its "…" menu back, with View, Edit (new), Replace and Remove (there on v5 too).
  • A note in each file reminding us that new @craftcms/cp imports need to be added to both craftcms-cp.d.ts and vite.config.mts.

Since it's a draft, I won't merge it into feature/craft-6 just yet, but feel free to do that if you're also happy with this.

@brianjhanson
brianjhanson marked this pull request as ready for review November 5, 2026 15:00
@i-just
i-just merged commit aef4de9 into feature/craft-6 Nov 9, 2026
12 checks passed
@i-just
i-just deleted the chore/js-modules-jquery branch November 9, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants