monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

Bump base-x from 3.0.9 to 3.0.11 in /samples/browser-esm-parcel

Open dependabot[bot] opened this issue 6 months ago • 0 comments

Bumps base-x from 3.0.9 to 3.0.11.

Commits

Dependabot compatibility score

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 rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
  • @dependabot ignore this major version will 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 version will 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 dependency will 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.

dependabot[bot] avatar May 16 '25 20:05 dependabot[bot]

What is the workaround here? Have you found a good way to trigger normalization on the entire document?

aunger avatar Mar 08 '20 02:03 aunger

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?

alfechner avatar Mar 08 '20 09:03 alfechner

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)

JonathanWbn avatar Mar 08 '20 09:03 JonathanWbn

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.

plaffitt avatar Mar 26 '20 05:03 plaffitt

@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.

alfechner avatar Mar 26 '20 10:03 alfechner

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?

plaffitt avatar Apr 01 '20 03:04 plaffitt

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] })
})

davidruisinger avatar May 04 '20 17:05 davidruisinger

After running into other issues with the above workarounds I finally ended up with this:

  1. I have my editor component that receives the value as prop from outside
  2. I store the "internal" slate value in a react state within my editor component
  3. I use useEffect hook 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])

davidruisinger avatar Jul 08 '20 15:07 davidruisinger

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.

janpaepke avatar Mar 01 '22 12:03 janpaepke

Thank @janpaepke, 2025 here and you saved my bacon 👍 (PS: go back, the future isn't bright)

pchr-srf avatar Feb 24 '25 15:02 pchr-srf