Works with yarn.

This commit is contained in:
Laur Ivan 2022-06-07 12:02:54 +02:00
parent 7ebe981909
commit 4e700989fa
8 changed files with 53 additions and 56 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
node_modules
/build
/.svelte-kit
/storybook-static
/package
.env
.env.*

View File

@ -14,7 +14,7 @@
"format": "prettier --write --plugin-search-dir=. .",
"tailwind:watch": "cross-env TAILWIND_MODE=watch cross-env NODE_ENV=development postcss src/styles/tailwind.css -o static/app.css -w",
"tailwind:build": "cross-env TAILWIND_MODE=build cross-env NODE_ENV=production postcss src/styles/tailwind.css -o static/app.css",
"storybook": "BROWSER=none start-storybook -p 6006",
"storybook": "BROWSER=none start-storybook -p 6006 --ci",
"build-storybook": "build-storybook"
},
"devDependencies": {
@ -57,9 +57,7 @@
"dependencies": {
"@fontsource/fira-mono": "^4.5.0",
"cookie": "^0.4.1",
"prosemirror-example-setup": "^1.2.0",
"prosemirror-markdown": "^1.9.1",
"prosemirror-menu": "^1.2.0",
"prosemirror-svelte": "^0.2.4"
}
}

1
src/default.d.ts vendored
View File

@ -1,3 +1,4 @@
declare module '@storybook/addon-svelte-csf';
declare module 'prosemirror-svelte/state';
declare module 'prosemirror-svelte/helpers/plugins';
declare module 'daisyui';

View File

@ -0,0 +1,26 @@
import { EditorState, TextSelection } from 'prosemirror-state';
import { schema, defaultMarkdownParser, defaultMarkdownSerializer } from 'prosemirror-markdown';
import { corePlugins } from 'prosemirror-svelte/helpers/plugins';
/**
* Create an empty editor state, for a multi-line editor schema
* @param content {string}
* @param plugins {array<Plugin>}
* @return {EditorState}
*/
export const createMarkdownEditor = (content = '', plugins = []) => {
let doc, selection;
if (content) {
const paragraphs = content.split('\n');
doc = defaultMarkdownParser.parse(content);
//selection = TextSelection.atEnd(doc);
}
return EditorState.create({
schema: schema,
doc: doc as any,
selection,
plugins: [...corePlugins, ...plugins]
});
};

View File

@ -1,21 +1,16 @@
<script lang="ts">
import { onMount } from 'svelte';
import { Plugin, PluginKey } from 'prosemirror-state';
import ProsemirrorEditor from 'prosemirror-svelte';
import { createRichTextEditor, clear, toHTML, toPlainText } from 'prosemirror-svelte/state';
import { schema, defaultMarkdownParser, defaultMarkdownSerializer } from 'prosemirror-markdown';
import { exampleSetup } from 'prosemirror-example-setup';
const html = `
<h3>I am Rich</h3>
<p>Hello there! I am Rich, a rich-text editor. </p>
<p>Go ahead and edit me.</p>
<p>You can change the format using the keyboard. E.g.: </p>
<p><strong>Ctrl/Cmd-b</strong> will toggle text as <strong>bold</strong>.</p>
<p><strong>Ctrl/Cmd-i</strong> will toggle text as <em>italic</em>.</p>
<p><b>Ctrl-Shift-0</b> will set the block type to paragraph.</p>
<p><b>Ctrl-Shift-1,2,3...</b> will set the block type to heading 1,2,3...</p>`;
import { clear, toHTML, toPlainText } from 'prosemirror-svelte/state';
import { createMarkdownEditor } from './MarkdownEditor';
const markdown = `
# This is a H1
* One
* Two
* Three`;
let focusEditor: any;
let editorState = createRichTextEditor(html, exampleSetup(schema as any));
let editorState = createMarkdownEditor(markdown);
function handleChange(event: any) {
editorState = event.detail.editorState;
}
@ -24,7 +19,7 @@
focusEditor();
}
function resetEditor(event: any) {
editorState = createRichTextEditor(html);
editorState = createMarkdownEditor(markdown);
focusEditor();
}
function showHtml(event: any) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

View File

@ -1 +0,0 @@
{"generatedAt":1654589143881,"builder":{"name":"storybook-builder-vite"},"hasCustomBabel":false,"hasCustomWebpack":true,"hasStaticDirs":false,"hasStorybookEslint":false,"refCount":0,"metaFramework":{"name":"svelte-kit","packageName":"@sveltejs/kit","version":"1.0.0-next.348"},"packageManager":{"type":"npm","version":"8.11.0"},"storybookVersion":"6.5.7","language":"typescript","storybookPackages":{"@storybook/addon-actions":{"version":"6.5.7"},"@storybook/addon-docs":{"version":"6.5.7"},"@storybook/svelte":{"version":"6.5.7"},"storybook-builder-vite":{"version":"0.1.23"}},"framework":{"name":"svelte","options":{"preprocess":{"defaultLanguages":{"markup":"html","style":"css","script":"javascript"}}}},"addons":{"@storybook/addon-links":{"version":"6.5.7"},"@storybook/addon-essentials":{"version":"6.5.7"},"@storybook/addon-svelte-csf":{"version":"2.0.4"}}}

View File

@ -4259,11 +4259,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
safe-buffer "^5.0.1"
sha.js "^2.4.8"
crelt@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/crelt/-/crelt-1.0.5.tgz#57c0d52af8c859e354bace1883eb2e1eb182bb94"
integrity sha512-+BO9wPPi+DWTDcNYhr/W90myha8ptzftZT+LwcmUbbok0rcP/fequmFYCw8NMoH7pkAZQzU78b3kYrlua5a9eA==
cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
@ -8775,7 +8770,7 @@ property-information@^5.0.0, property-information@^5.3.0:
dependencies:
xtend "^4.0.0"
prosemirror-commands@^1.0.0, prosemirror-commands@^1.1.2:
prosemirror-commands@^1.1.2:
version "1.3.0"
resolved "https://registry.yarnpkg.com/prosemirror-commands/-/prosemirror-commands-1.3.0.tgz#361b2e2b2a347ce7453386459f97c3f549a1113b"
integrity sha512-BwBbZ5OAScPcm0x7H8SPbqjuEJnCU2RJT9LDyOiiIl/3NbL1nJZI4SFNHwU2e/tRr2Xe7JsptpzseqvZvToLBQ==
@ -8784,7 +8779,7 @@ prosemirror-commands@^1.0.0, prosemirror-commands@^1.1.2:
prosemirror-state "^1.0.0"
prosemirror-transform "^1.0.0"
prosemirror-dropcursor@^1.0.0, prosemirror-dropcursor@^1.3.2:
prosemirror-dropcursor@^1.3.2:
version "1.5.0"
resolved "https://registry.yarnpkg.com/prosemirror-dropcursor/-/prosemirror-dropcursor-1.5.0.tgz#edbc61d6f71f9f924130eec8e85b0861357957c9"
integrity sha512-vy7i77ddKyXlu8kKBB3nlxLBnsWyKUmQIPB5x8RkYNh01QNp/qqGmdd5yZefJs0s3rtv5r7Izfu2qbtr+tYAMQ==
@ -8793,22 +8788,7 @@ prosemirror-dropcursor@^1.0.0, prosemirror-dropcursor@^1.3.2:
prosemirror-transform "^1.1.0"
prosemirror-view "^1.1.0"
prosemirror-example-setup@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/prosemirror-example-setup/-/prosemirror-example-setup-1.2.0.tgz#417a9b87e4c26baa5e8a55feaf06c38bdf74d4a1"
integrity sha512-Op7V8HZ60iqbPoTuGxHmfPvplInpU0tqlXsSk1BCyHrlWB0g2hWiTp/qWJSkq6tmiujUNjIex3jvOXBBRdFZYw==
dependencies:
prosemirror-commands "^1.0.0"
prosemirror-dropcursor "^1.0.0"
prosemirror-gapcursor "^1.0.0"
prosemirror-history "^1.0.0"
prosemirror-inputrules "^1.0.0"
prosemirror-keymap "^1.0.0"
prosemirror-menu "^1.0.0"
prosemirror-schema-list "^1.0.0"
prosemirror-state "^1.0.0"
prosemirror-gapcursor@^1.0.0, prosemirror-gapcursor@^1.1.2:
prosemirror-gapcursor@^1.1.2:
version "1.3.1"
resolved "https://registry.yarnpkg.com/prosemirror-gapcursor/-/prosemirror-gapcursor-1.3.1.tgz#8cfd874592e4504d63720e14ed680c7866e64554"
integrity sha512-GKTeE7ZoMsx5uVfc51/ouwMFPq0o8YrZ7Hx4jTF4EeGbXxBveUV8CGv46mSHuBBeXGmvu50guoV2kSnOeZZnUA==
@ -8818,7 +8798,7 @@ prosemirror-gapcursor@^1.0.0, prosemirror-gapcursor@^1.1.2:
prosemirror-state "^1.0.0"
prosemirror-view "^1.0.0"
prosemirror-history@^1.0.0, prosemirror-history@^1.1.3:
prosemirror-history@^1.1.3:
version "1.3.0"
resolved "https://registry.yarnpkg.com/prosemirror-history/-/prosemirror-history-1.3.0.tgz#bf5a1ff7759aca759ddf0c722c2fa5b14fb0ddc1"
integrity sha512-qo/9Wn4B/Bq89/YD+eNWFbAytu6dmIM85EhID+fz9Jcl9+DfGEo8TTSrRhP15+fFEoaPqpHSxlvSzSEbmlxlUA==
@ -8827,7 +8807,7 @@ prosemirror-history@^1.0.0, prosemirror-history@^1.1.3:
prosemirror-transform "^1.0.0"
rope-sequence "^1.3.0"
prosemirror-inputrules@^1.0.0, prosemirror-inputrules@^1.1.2:
prosemirror-inputrules@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/prosemirror-inputrules/-/prosemirror-inputrules-1.2.0.tgz#476dde2dc244050b3aca00cf58a82adfad6749e7"
integrity sha512-eAW/M/NTSSzpCOxfR8Abw6OagdG0MiDAiWHQMQveIsZtoKVYzm0AflSPq/ymqJd56/Su1YPbwy9lM13wgHOFmQ==
@ -8851,23 +8831,20 @@ prosemirror-markdown@^1.9.1:
markdown-it "^13.0.1"
prosemirror-model "^1.0.0"
prosemirror-menu@^1.0.0, prosemirror-menu@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/prosemirror-menu/-/prosemirror-menu-1.2.0.tgz#5c5db7506572d0cd1d06a4df91dfbc23ba782971"
integrity sha512-MignsYhlvuY3suwvJjG05JKyVPPKXDZLMMLd6vSqkRTo6gnK+t012z1yC42bZacom3iX/5C/FaLtvTzWBzQNBQ==
dependencies:
crelt "^1.0.0"
prosemirror-commands "^1.0.0"
prosemirror-history "^1.0.0"
prosemirror-state "^1.0.0"
prosemirror-model@^1.0.0, prosemirror-model@^1.16.0, prosemirror-model@^1.2.0, prosemirror-model@^1.8.2:
prosemirror-model@^1.0.0, prosemirror-model@^1.16.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/prosemirror-model/-/prosemirror-model-1.17.0.tgz#f99fe93e9b45e48559ebf0f50262ef900a6246b7"
integrity sha512-RJBDgZs/W26yyx1itrk5b3H9FxIro3K7Xjc2QWJI99Gu1nxYAnIggqI3fIOD8Jd/6QZfM+t6elZFJPycVexMTA==
dependencies:
orderedmap "^1.1.0"
prosemirror-model@^1.2.0, prosemirror-model@^1.8.2:
version "1.18.0"
resolved "https://registry.yarnpkg.com/prosemirror-model/-/prosemirror-model-1.18.0.tgz#8c360ed65a6ec9dd2fb899b5f5ceeb5f5f689ee0"
integrity sha512-EZLl0mvVIixEL1V538GsPP4Iw+D83gBRdLcjL7VouzoPPWlhhv/0Y0V9ttT5lUhF7jieIrNHOa3XNFs1FwgrOw==
dependencies:
orderedmap "^1.1.0"
prosemirror-schema-basic@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/prosemirror-schema-basic/-/prosemirror-schema-basic-1.2.0.tgz#c33ad74426efae1d41e2260371866f623e8eb10e"
@ -8875,7 +8852,7 @@ prosemirror-schema-basic@^1.1.2:
dependencies:
prosemirror-model "^1.2.0"
prosemirror-schema-list@^1.0.0, prosemirror-schema-list@^1.1.2:
prosemirror-schema-list@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/prosemirror-schema-list/-/prosemirror-schema-list-1.2.0.tgz#1932268593a7396c0ac168cbe31f28187406ce24"
integrity sha512-8PT/9xOx1HHdC7fDNNfhQ50Z8Mzu7nKyA1KCDltSpcZVZIbB0k7KtsHrnXyuIhbLlScoymBiLZ00c5MH6wdFsA==