Little things made by me:
Milkdown | PMAdapter |
---|---|
VPB | Homura |
π« How to reach me:
- π§E-mail: [email protected]
- π¦Twitter: Mirone
βοΈ Mastodon: Mirone
Universal adapter to create prosemirror nodeview from modern UI frameworks.
License: MIT License
Little things made by me:
Milkdown | PMAdapter |
---|---|
VPB | Homura |
π« How to reach me:
Is there any chance you could support angular? I love milkdown and your work around it. As I am forced to use angular for my project, I would love to see this adapter for angular.
Thank you!
When using the code in examples/svelte
I get error in this code (Editor.svelte, lines 32, 27, etc.):
// line 29:
function editor(element: HTMLElement) {
editorView = createEditorView(element, {
paragraph: nodeViewFactory({
component: Paragraph,
as: 'div',
contentAs: 'p'
}),
heading: nodeViewFactory({
component: Heading
})
}, [
new Plugin({
view: pluginViewFactory({
component: Size
})
}),
...
The error reads:
Type 'typeof Paragraph__SvelteComponent_' is not assignable to type 'SvelteNodeViewComponent'.
Types of parameters 'options' and 'options' are incompatible.
Type 'ComponentConstructorOptions' is not assignable to type 'ComponentConstructorOptions<Record<string, never>>'.
Type 'EmptyProps' is not assignable to type 'Record<string, never>'.
Index signature for type 'string' is missing in type 'EmptyProps'.ts(2322)
Not sure how exactly approach a fix... My guess is that changing type in the adapter code should suffice, but did not have the courage to look inside, yet.
"@sveltejs/kit": "^1.5.0",
"@sveltejs/adapter-auto": "^2.0.0",
"svelte": "^3.54.0",
"svelte-check": "^3.0.1",
"@prosemirror-adapter/svelte": "^0.2.4",
Basic collaboration is working. Adding text to the document is sent to collaborators. However, I'm having trouble with a custom node view.
A custom node view calls setAttrs({value: ...})
to modify the value (Mermaid code) of a diagram node, similar to the way the Milkdown Playground does it.
It gets setAttrs via const setAttrs = useNodeViewContext("setAttrs");
I don't see any errors in the JavaScript console or elsewhere. Collaborators connected to the same document don't seem to be receiving the changes. Is there something else that I need to do to modify the Y doc?
I can also guess that if I'm able to get that working, the custom nodeview won't know its node was changed. Can the store returned by useNodeViewContext("node")
be used to re-render the component or does Prosemirror handle that?
Here's my code
Thank you for creating this repo. I was trying to build a custom editor I discovered that useWidgetViewFactory
seems to work in React, but always seem to return an undefined value in Vue.
I've created a test environment which demonstrate this edgecase:
https://stackblitz.com/edit/github-rdvuhn?file=createEditorView.ts
Am I mis-using or misunderstanding how useWidgetViewFactory
works?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
This repository currently has no open or pending branches.
.github/workflows/ci.yml
actions/checkout v4
actions/setup-node v4
pnpm/action-setup v3.0.0
actions/cache v4
cypress-io/github-action v4
cypress-io/github-action v4
changesets/action v1
actions/upload-artifact v4.3.1
actions/upload-artifact v4.3.1
e2e/package.json
@lit-labs/context ^0.5.0
@sveltejs/vite-plugin-svelte ^3.0.0
@types/react ^18.0.30
@types/react-dom ^18.0.11
@vitejs/plugin-react ^4.0.0
@vitejs/plugin-vue ^5.0.0
cypress ^13.0.0
lit ^3.0.0
prosemirror-example-setup ^1.2.1
prosemirror-menu ^1.2.1
prosemirror-schema-basic ^1.2.1
react ^18.2.0
react-dom ^18.2.0
start-server-and-test ^2.0.0
svelte ^4.0.0
vue ^3.2.47
package.json
@antfu/eslint-config ^2.0.0
@changesets/cli ^2.26.1
@commitlint/cli ^19.0.0
@commitlint/config-conventional ^19.0.0
@type-config/strict ^1.2.1
@types/rollup-plugin-auto-external ^2.0.2
concurrently ^8.0.0
cross-env ^7.0.3
eslint ^8.46.0
eslint-plugin-header ^3.1.1
eslint-plugin-react ^7.32.2
eslint-plugin-react-hooks ^4.6.0
git-cz ^4.9.0
husky ^9.0.0
lint-staged ^15.0.0
prosemirror-keymap ^1.2.1
prosemirror-model ^1.19.0
prosemirror-state ^1.4.2
prosemirror-view ^1.30.2
tslib ^2.5.0
typescript ^5.0.2
vite ^5.0.0
node >=16
pnpm >=7
packages/core/package.json
tslib ^2.5.0
packages/lit/package.json
nanoid ^5.0.0
tslib ^2.5.0
@lit-labs/context ^0.5.0
lit ^3.0.0
@lit-labs/context ^0.5.0
lit ^3.0.0
packages/react/package.json
nanoid ^5.0.0
tslib ^2.5.0
@types/react ^18.0.30
@types/react-dom ^18.0.11
react ^18.2.0
react-dom ^18.2.0
react *
react-dom *
packages/svelte/package.json
nanoid ^5.0.0
tslib ^2.5.0
@sveltejs/vite-plugin-svelte ^3.0.0
svelte ^4.0.0
svelte ^4.0.0
packages/vue/package.json
nanoid ^5.0.0
tslib ^2.5.0
@vitejs/plugin-vue-jsx ^3.0.1
vue ^3.2.47
vue ^3.0.0
npm install @prosemirror-adapter/svelte
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/svelte
npm ERR! dev svelte@"^4.0.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer svelte@"^3.57.0" from @prosemirror-adapter/[email protected]
npm ERR! node_modules/@prosemirror-adapter/svelte
npm ERR! @prosemirror-adapter/svelte@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! /Users/rchrdnsh/.npm/_logs/2023-07-15T23_53_13_299Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rchrdnsh/.npm/_logs/2023-07-15T23_53_13_299Z-debug-0.log
when installing...
When combining Milkdown and prosemirror-adapter/svelte, setAttrs({ value: 5 })
causes the Svelte component (declared via $view) to be removed and a new component takes its place. In my case, the Svelte component consists of a textarea. setAtrrs()
moves the cursor out of the textarea to the top of the Milkdown editor. I guess I could capture the cursor location in update() but I'm not sure what I could do to find it later when the new Svelte component is created. I think I'm supposed to use a Svelte store for this. Is that correct? I realize that a better solution is to use a Prosemirror Editor instead of textarea and use transactions (which has better support for undo/redo and collaboration), but that's what the Milkdown Playground does eg with the diagram plugin.
const { view } = usePluginViewContext()
const somePropDeep = computed(()=>view.value.state.select)//or other things
Vue can't track the effect of somePropDeep
when view was shallowRef
, we should use triggerRef
manually after assigned
I just found one place, I think there might be such other things like this in this library
@prosemirror-adapter/svelte 0.2.5
svelte 3.58.0
Milkdown 7.2
I created a Milkdown editor with the diagram plugin. The editor content defaults to a string starting with ```mermaid
This works fine. Milkdown displays the Mermaid diagram text (Mermaid code).
<div data-type="diagram" data-id="gfceeaae" data-value=" graph TD;
A-->B;
A-->C;
B-->D;
C-->D;" contenteditable="false"> graph TD;
A-->B;
A-->C;
B-->D;
C-->D;</div>
I want to implement something similar to the way the Milkdown playground behaves (edit diagram / display diagram as svg), but using Svelte. I added a nodeview plugin:
use( [diagram, $view(diagramSchema.node, () =>
nodeViewFactory({
component: MyComponent,
}))]);
MyComponent.svelte looks like:
<script>
const contentRef = useNodeViewContext('contentRef');
</script>
<div class='text-red-500' use:contentRef/>
The produced HTML looks like the following. The Mermaid diagram code does not appear. I have tried:
<div class="milkdown">
<div contenteditable="true" translate="no" class="ProseMirror editor" role="textbox">
<div data-node-view-root="true">
<div class="text-red-500">
<div data-node-view-content="true" style="white-space: inherit;">
<br class="ProseMirror-trailingBreak"></div></div></div></div></div>
contentRef is a Svelte action that acts on the div that I provided.
(t4) => {
t4 && t4 instanceof HTMLElement &&
this.contentDOM && t4.firstChild !== this.contentDOM &&
t4.appendChild(this.contentDOM);
}
this.contentDOM appears to be:
<div data-node-view-content="true" style="white-space: inherit;">
<br class="ProseMirror-trailingBreak"></div>
Apparently I need to call useNodeViewContext('node') instead and interact with the prose mirror node.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.