monaco-editor
monaco-editor copied to clipboard
Bump base-x from 3.0.9 to 3.0.11 in /samples/browser-esm-parcel
Bumps base-x from 3.0.9 to 3.0.11.
Commits
043a8883.0.112705ddd[backport 3.x] Prohibit char codes that would overflow theBASE_MAP3d43c0e3.0.100a35446Improve decoding performance- See full diff in compare view
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebasewill rebase this PR@dependabot recreatewill recreate this PR, overwriting any edits that have been made to it@dependabot mergewill merge this PR after your CI passes on it@dependabot squash and mergewill squash and merge this PR after your CI passes on it@dependabot cancel mergewill cancel a previously requested merge and block automerging@dependabot reopenwill reopen this PR if it is closed@dependabot closewill close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot show <dependency name> ignore conditionswill show all of the ignore conditions of the specified dependency@dependabot ignore this major versionwill close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor versionwill close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependencywill close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the Security Alerts page.
What is the workaround here? Have you found a good way to trigger normalization on the entire document?
Is there any function in the Slate API which can normalize a Slate document programmatically?
I'm working on migrating documents from a C# editor to Slate documents and would like to normalize them in a final step.
I guess a function like that would meet your needs as well @aunger , wouldn't it?
What is the workaround here? Have you found a good way to trigger normalization on the entire document?
I'm currently waiting for the initialization and then make a change in every first-level child node and immediately undo that action.
// The setTimeout might not be necessary in your setup, but it is for mine.
setTimeout(() => {
editor.children.forEach((_child, index) => {
Transforms.insertText(editor, '_', { at: [index] })
editor.undo()
})
}, 1)
This feature would be very welcome.
I'm working on a project where we used to edit content with bbcode (yeah it's waaaay too old-school) and we are now migrating it to slate. I'm parsing the HTML output of our bbcode thus the initialValue doesn't comes form slate so it may require so normalization at initialization.
I actually do some pre-normalization on the generated HTML but it's only for the parser to correctly understand what is going on, then it still could yield an incorrect json tree.
@paullaffitte we're doing the exact same thing except that we migrate from TextControl HTML export to slate. I think migrations like that are a pretty common use case.
We'd also really appreciate this feature.
That's odd, I've just find an issue about disabling normalization at initialization from almost 2 years ago.. Is this feature still existing but maybe not documented? Or has it been remove since then?
I ran into some issues with @JonathanWbn 's workaround where a concurrently run value update collided with the editor.undo() call.
So I ended up triggering the normalization with this workaround:
editor.children.forEach((child, index) => {
Transforms.setNodes(editor, [child], { at: [index] })
})
After running into other issues with the above workarounds I finally ended up with this:
- I have my editor component that receives the value as prop from outside
- I store the "internal" slate value in a react state within my editor component
- I use
useEffecthook to update the internal slate value with the incoming external value
Now here comes the magic part. Instead of just setting the external value on the internal state I use this:
React.useEffect(() => {
// Slate throws an error if the value on the initial render is invalid
// so we directly set the value on the editor in order
// to be able to trigger normalization on the initial value before rendering
editor.children = externalValue
Editor.normalize(editor, { force: true })
// We set the internal value so that the rendering can take over from here
setInternalSlateValue(editor.children)
}, [externalValue])
The solution by @davidruisinger worked great, as I also was running into troubles when building a controlled slate component - when setting the external value to editor.children it skips normalisation.
However I improved it a little, because in his solution the component would always render twice (once with an initial value, and once, when the internal state is set after the useEffect runs).
You can avoid this by doing it in a useMemo.
const slateValue = useMemo(() => {
// Slate throws an error if the value on the initial render is invalid
// so we directly set the value on the editor in order
// to be able to trigger normalization on the initial value before rendering
editor.children = externalValue;
Editor.normalize(editor, { force: true });
// We return the normalized internal value so that the rendering can take over from here
return editor.children;
}, [editor, externalValue]);
Then I use this on my Slate Component.
<Slate
editor={editor}
value={slateValue} // now normalized
onChange={onChange} // set / update external value
>
hope this helps someone else.
Thank @janpaepke, 2025 here and you saved my bacon 👍 (PS: go back, the future isn't bright)