-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create starter kit package #217
Merged
Merged
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5d9793f
starer kit is ready
Darginec05 991cdfd
fixes export in plain text
Darginec05 9b945d0
added example template
Darginec05 600e0cf
Publish
Darginec05 2f25120
publish rc
Darginec05 2a330ff
Publish
Darginec05 c3b58f8
Publish
Darginec05 ddc035b
publish -rc versions
Darginec05 7aa6b9c
update example
Darginec05 41c576b
Fix bugs with blur
Darginec05 fe401b1
Publish
Darginec05 dbd1e81
update example packages
Darginec05 7dafc8c
oopsie voopsie
Darginec05 40f9657
fix types for plugin
Darginec05 4e6fc72
small review fixes
Darginec05 29190e2
Publish
Darginec05 1e2efd6
update example packaages
Darginec05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { SlateElement, YooEditor, YooptaBlockData, YooptaContentValue } from '@yoopta/editor'; | ||
|
||
export function serialize(editor: YooEditor, blocksData: YooptaBlockData[]) { | ||
const blocks = blocksData.sort((a, b) => (a.meta.order > b.meta.order ? 1 : -1)); | ||
|
||
const markdown = blocks.map((blockData) => { | ||
const plugin = editor.plugins[blockData.type]; | ||
|
||
if (plugin) { | ||
const element = blockData.value[0] as SlateElement; | ||
|
||
if (plugin.parsers?.markdown?.serialize) { | ||
const serialized = plugin.parsers.markdown.serialize( | ||
element, | ||
element.children.map((child) => child.text).join(''), | ||
); | ||
if (serialized) return serialized; | ||
} | ||
} | ||
|
||
return ''; | ||
}); | ||
|
||
return markdown.join('\n'); | ||
} | ||
|
||
export function getMarkdown(editor: YooEditor, content: YooptaContentValue) { | ||
const selectedBlocks = Object.values(content); | ||
return serialize(editor, selectedBlocks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { YooEditor, YooptaContentValue } from '@yoopta/editor'; | ||
import { getHTML } from './getHTML'; | ||
|
||
export function getPlainText(editor: YooEditor, content: YooptaContentValue) { | ||
const htmlString = getHTML(editor, content); | ||
|
||
const div = document.createElement('div'); | ||
div.innerHTML = htmlString; | ||
return div.innerText; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# StarterKit plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add docs |
||
|
||
StarterKit is plugin for Yoopta-Editor | ||
|
||
### Installation | ||
|
||
```bash | ||
yarn add @yoopta/starter-kit | ||
``` | ||
|
||
### Usage | ||
|
||
```jsx | ||
import StarterKit from '@yoopta/starter-kit'; | ||
|
||
const plugins = [StarterKit]; | ||
|
||
const Editor = () => { | ||
return <YooptaEditor plugins={plugins} />; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "@yoopta/starter-kit", | ||
"version": "4.6.4", | ||
"description": "StarterKit for Yoopta Editor", | ||
"author": "Darginec05 <[email protected]>", | ||
"homepage": "https://github.com/Darginec05/Editor-Yoopta#readme", | ||
"license": "MIT", | ||
"private": false, | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"module": "dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist/" | ||
], | ||
"dependencies": { | ||
"@yoopta/accordion": "^4.6.4", | ||
"@yoopta/action-menu-list": "^4.6.4", | ||
"@yoopta/blockquote": "^4.6.4", | ||
"@yoopta/callout": "^4.6.4", | ||
"@yoopta/code": "^4.6.4", | ||
"@yoopta/editor": "^4.6.4", | ||
"@yoopta/embed": "^4.6.4", | ||
"@yoopta/exports": "^4.6.4", | ||
"@yoopta/file": "^4.6.4", | ||
"@yoopta/headings": "^4.6.4", | ||
"@yoopta/image": "^4.6.4", | ||
"@yoopta/link": "^4.6.4", | ||
"@yoopta/link-tool": "^4.6.4", | ||
"@yoopta/lists": "^4.6.4", | ||
"@yoopta/marks": "^4.6.4", | ||
"@yoopta/paragraph": "^4.6.4", | ||
"@yoopta/toolbar": "^4.6.4", | ||
"@yoopta/video": "^4.6.4", | ||
"slate": "^0.102.0", | ||
"slate-react": "^0.102.0" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=17.0.2", | ||
"react-dom": ">=17.0.2" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.yarnpkg.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Darginec05/Editor-Yoopta.git" | ||
}, | ||
"scripts": { | ||
"test": "node ./__tests__/yoopta-starter-kit.test.js", | ||
"start": "rollup --config rollup.config.js --watch --bundleConfigAsCjs --environment NODE_ENV:development", | ||
"prepublishOnly": "yarn build", | ||
"build": "rollup --config rollup.config.js --bundleConfigAsCjs --environment NODE_ENV:production" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Darginec05/Editor-Yoopta/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createRollupConfig } from '../../../config/rollup'; | ||
|
||
const pkg = require('./package.json'); | ||
export default createRollupConfig({ | ||
pkg, | ||
tailwindConfig: { content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'], prefix: 'yoo-starter-' }, | ||
}); |
72 changes: 72 additions & 0 deletions
72
packages/core/starter-kit/src/components/StarterKit/StarterKit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { CSSProperties, useEffect, useMemo, useRef } from 'react'; | ||
import YooptaEditor, { createYooptaEditor, YooptaContentValue } from '@yoopta/editor'; | ||
|
||
import { TOOLS } from '../../utilts/tools'; | ||
import { MARKS } from '../../utilts/marks'; | ||
import { getPlugins } from '../../utilts/plugins'; | ||
import { ImageUploadResponse } from '@yoopta/image'; | ||
import { VideoUploadResponse } from '@yoopta/video'; | ||
import { FileUploadResponse } from '@yoopta/file'; | ||
|
||
export type StarterKitProps = { | ||
id?: string; | ||
value?: YooptaContentValue; | ||
onChange?: (value: YooptaContentValue) => void; | ||
readOnly?: boolean; | ||
autoFocus?: boolean; | ||
className?: string; | ||
placeholder?: string; | ||
style?: CSSProperties; | ||
selectionRef?: React.RefObject<HTMLDivElement> | false; | ||
media?: MediaUploadsFn; | ||
}; | ||
|
||
export type MediaUploadsFn = { | ||
imageUpload?: (file: File) => Promise<ImageUploadResponse>; | ||
videoUpload?: (file: File) => Promise<VideoUploadResponse>; | ||
fileUpload?: (file: File) => Promise<FileUploadResponse>; | ||
}; | ||
|
||
function StarterKit({ | ||
id, | ||
value, | ||
style, | ||
onChange, | ||
readOnly, | ||
autoFocus, | ||
className, | ||
placeholder, | ||
media, | ||
selectionRef = false, | ||
}: StarterKitProps) { | ||
const editor = useMemo(() => createYooptaEditor(), []); | ||
|
||
useEffect(() => { | ||
if (typeof onChange === 'function') { | ||
editor.on('change', onChange); | ||
return () => { | ||
editor.off('change', onChange); | ||
}; | ||
} | ||
}, [editor]); | ||
|
||
return ( | ||
<YooptaEditor | ||
key={id} | ||
id={id} | ||
selectionBoxRoot={selectionRef} | ||
editor={editor} | ||
plugins={getPlugins({ media })} | ||
tools={TOOLS} | ||
marks={MARKS} | ||
value={value} | ||
readOnly={readOnly} | ||
autoFocus={autoFocus} | ||
className={className} | ||
style={style} | ||
placeholder={placeholder} | ||
/> | ||
); | ||
} | ||
|
||
export { StarterKit }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { StarterKit, type MediaUploadsFn, type StarterKitProps } from './components/StarterKit/StarterKit'; | ||
|
||
export default StarterKit; | ||
export type { MediaUploadsFn, StarterKitProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Bold, Italic, CodeMark, Underline, Strike, Highlight } from '@yoopta/marks'; | ||
|
||
export const MARKS = [Bold, Italic, CodeMark, Underline, Strike, Highlight]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove