The current Field Widget Action works very well but it has been discussed in the latest AI Initiative Sprint Review that it will be a better UX if the triggering could be done directly on the MDX editor.
So the task is to create a custom button on the MDX Toolbar. The button should open a window to aid with uploading a file or entering a web address which will be used by the Document Loader to fetch the content.
Think of one or more fields in that form to be used in case the user requires an authenticated call to an API endpoint.
Look into whether this functionality should live inside the Document Loader module or a separate submodule (not all use cases of Document Loader might include MDX).
Issue fork document_loader-3580850
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ahmad khader commentedI think this ticket should be to provide a function in a
DocumentLoaderManagerservice to convertgetToolInputSchemainto Drupal fields, similar to how AI tool + explorer works.I think all the logic is on the explorer form; we could move it into the service.
Comment #3
ahmad khader commentedComment #4
ahmad khader commentedThis way, we could fix both of the issues in one singular code logic, and other integrations in the future will be bulletproof as well.
Comment #5
ahmad khader commentedAlso, I think the best approach is to have MDX logic in a sub-module similar to fwa and tool modules. We could also include ck-editor integration as well
Comment #6
unqunqGood points. I have a version of the MDX integration in progress in a submodule.
Here is the first working version:

We've had a chat in Slack on #document_loader about improving this by updating the modal form and using a different icon.
The CKEditor should be a separate ticket - needs to go in its own submodule as well.
Comment #7
unqunqComment #9
unqunqAn updated demo:
Comment #10
unqunqComment #11
unqunqComment #12
bbruno commentedI really like this feature, super useful! I've left some comments regarding the JS/MDXEditor part of the implementation :)
Comment #13
ahmad khader commentedTys, bbruno and nick for the work.
I fixed all issues mentioned by bbruno. Additionally, I fixed;
1. Button stays visible in diff/source mode
Because the "Load document" button is imperatively injected into the DOM (outside React), it was not removed when the MDX editor switches to diff or source mode — the
DiffSourceToggleWrapperonly manages its own React children. Fixed by adding a secondMutationObserveron the toolbar that detects mode changes (by checking for thetoolbarTitleModeclass) and hides the button withdisplay: nonewhen in an alternate mode. Uses a disconnect/reconnect pattern to avoid infinite loops when mutating the DOM inside the observer callback.2. Button appears first instead of last when switching back to rich-text mode
When switching from diff/source back to rich-text mode, React re-renders all toolbar children as new DOM nodes. Our imperatively injected button was still at its old position, which put it before the newly rendered buttons — making it appear first in the toolbar. Fixed by re-positioning the button with
toolbar.insertBefore(button, toolbar.lastElementChild)each time rich-text mode is restored, so it always sits just before the diff/source toggle group at the end.3. Tooltip styling doesn't match native toolbar tooltips
The native MDX editor toolbar buttons use
@radix-ui/react-tooltip(via aTooltipWrapcomponent) which renders styled floating tooltips via React portals. Since our button is injected imperatively outside React, it cannot use the Radix tooltip component. A plaintitleattribute produces a browser-native tooltip that looks completely different. Fixed by creating a custom DOM-based tooltip (.dl-mdx-tooltip) that appears onmouseenterwith a 100ms delay (matching Radix'sdelayDuration), positioned 10px above the button (matching Radix'ssideOffset), using the same CSS custom properties as the native_tooltipContentclass:--baseTextfor background,--baseBasefor text color,--radius-mediumfor border-radius,--text-xsfor font-size. The tooltip is dismissed onmouseleaveand on click.Comment #14
ahmad khader commentedComment #16
ahmad khader commentedI created a separate branch that dynamically loads the loaders, meaning you can load context from anywhere you want, not only files, and it includes the media widget, which I think is more user-friendly than what we currently have.
Comment #17
kristen polAdded this as a related issue to the ccc meta: #3569310: [META] Context source plugin feature (context from PDF/MD/Word/URL/etc)