Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitd1ece95

Browse files
committed
chore(editor): add rich editor playgroud
1 parent84da252 commitd1ece95

File tree

13 files changed

+188
-0
lines changed

13 files changed

+188
-0
lines changed

‎package.docker.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"serve.prod":"cross-env NODE_ENV=production SERVE_PORT=${SERVE_PORT} node server"
1111
},
1212
"dependencies": {
13+
"@editorjs/editorjs":"^2.15.0",
1314
"@sentry/browser":"^4.6.4",
1415
"@sentry/node":"^4.6.4",
1516
"@tippy.js/react":"^2.2.1",

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
}
4141
},
4242
"dependencies": {
43+
"@editorjs/editorjs":"^2.15.0",
4344
"@next/bundle-analyzer":"^9.0.0",
4445
"@sentry/browser":"^4.6.4",
4546
"@sentry/node":"^4.6.4",

‎pages/editor.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
importReactfrom'react'
22

3+
importRichEditorfrom'@containers/RichEditor'
4+
// import EditorJS from '@editorjs/editorjs'
5+
36
consthtml=
47
'<div class="cps-viewer"><h2>Editor.js</h2><p>Hey. Meet the new Editor. On this page you can see it in action — try to edit this text.</p><h3>Key features</h3><ul><li>It is a block-styled editor</li><li>It returns clean data output in JSON</li><li>Designed to be extendable and pluggable with a simple API</li></ul><h3>Key features</h3><ol><li>It is a block-styled editor</li><li>It returns clean data output in JSON</li><li>Designed to be extendable and pluggable with a simple API</li></ol><h3>What does it mean «block-styled editor»</h3><div class="cps-viewer-checklist"><div>This is a block-styled editor</div><div>Clean output data</div><div>Simple and powerful API</div></div><p>Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class="cdx-marker">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.</p><p>There are dozens of <a href="https://github.com/editor-js">ready-to-use Blocks</a> and the <a href="https://editorjs.io/creating-a-block-tool">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.</p><h3>What does it mean clean data output</h3><p>Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below</p><p>Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.</p><p>Clean data is useful to sanitize, validate and process on the backend.</p><div class="cps-viewer-delimiter"></div><p>We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it\'s core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏</p><div class="cps-viewer-image"><img src="https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg" /></div><div class="cps-viewer-linker"><a href="https://www.github.com">https://www.github.com</a></div><div class="cps-viewer-quote">quote demo text</div><div>'
58

@@ -17,6 +20,9 @@ const Editor = () => {
1720
__html:html,
1821
}}
1922
/>
23+
<hr/>
24+
<br/>
25+
<RichEditor/>
2026
</div>
2127
)
2228
}

‎src/containers/RichEditor/index.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* RichEditor
4+
*
5+
*/
6+
7+
importReactfrom'react'
8+
9+
import{connectStore,buildLog}from'@utils'
10+
import{useScript}from'@hooks'
11+
12+
import{useInit}from'./logic'
13+
// import * as logic from './logic'
14+
15+
/* eslint-disable-next-line */
16+
constlog=buildLog('C:RichEditor')
17+
18+
constRichEditorContainer=({ richEditor})=>{
19+
const[loaded]=useScript(
20+
'https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest'
21+
)
22+
23+
useInit(richEditor,loaded)
24+
25+
return(
26+
<div>
27+
<h2>RichEditor container!</h2>
28+
<div>impress me!</div>
29+
<divid="codex-editor"/>
30+
</div>
31+
)
32+
}
33+
34+
exportdefaultconnectStore(RichEditorContainer)

‎src/containers/RichEditor/logic.js‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// import R from 'ramda'
2+
import{useEffect}from'react'
3+
4+
// import { TYPE, EVENT, ERR } from '@constant'
5+
import{buildLog}from'@utils'
6+
7+
letstore=null
8+
/* eslint-disable-next-line */
9+
constlog=buildLog('L:RichEditor')
10+
11+
exportconstsomeMethod=()=>{}
12+
13+
// const const cancleLoading = () => {}
14+
15+
// ###############################
16+
// Data & Error handlers
17+
// ###############################
18+
19+
// ###############################
20+
// init & uninit
21+
// ###############################
22+
23+
exportconstuseInit=(_store,loaded)=>{
24+
useEffect(()=>{
25+
store=_store
26+
log('effect init: ',store)
27+
28+
if(loaded){
29+
// eslint-disable-next-line
30+
newEditorJS({
31+
/**
32+
* Id of Element that should contain Editor instance
33+
*/
34+
holderId:'codex-editor',
35+
data:{
36+
time:1552744582955,
37+
blocks:[
38+
{
39+
type:'paragraph',
40+
data:{
41+
text:'this is @',
42+
},
43+
},
44+
],
45+
version:'2.11.10',
46+
},
47+
})
48+
}
49+
50+
return()=>{
51+
// log('effect uninit')
52+
}
53+
},[_store,loaded])
54+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
importgqlfrom'graphql-tag'
2+
3+
constsimpleMutation=gql`
4+
mutation($id: ID!) {
5+
post(id: $id) {
6+
id
7+
}
8+
}
9+
`
10+
constsimpleQuery=gql`
11+
query($filter: filter!) {
12+
post(id: $id) {
13+
id
14+
}
15+
}
16+
`
17+
18+
constschema={
19+
simpleMutation,
20+
simpleQuery,
21+
}
22+
23+
exportdefaultschema

‎src/containers/RichEditor/store.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* RichEditor store
3+
*
4+
*/
5+
6+
import{typesast,getParent}from'mobx-state-tree'
7+
// import R from 'ramda'
8+
9+
import{markStates,buildLog}from'@utils'
10+
/* eslint-disable-next-line */
11+
constlog=buildLog('S:RichEditor')
12+
13+
// NOTE: add me to stores/index && stores/RootStore/index
14+
constRichEditor=t
15+
.model('RichEditor',{})
16+
.views(self=>({
17+
getroot(){
18+
returngetParent(self)
19+
},
20+
}))
21+
.actions(self=>({
22+
mark(sobj){
23+
markStates(sobj,self)
24+
},
25+
}))
26+
27+
exportdefaultRichEditor
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
importstyledfrom'styled-components'
2+
3+
// import Img from '@components/Img'
4+
// import { theme } from '@utils'
5+
6+
exportconstWrapper=styled.div``
7+
exportconstTitle=styled.div``
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import RichEditor from '../index'
5+
6+
describe('TODO <RichEditor />',()=>{
7+
it('Expect to have unit tests specified',()=>{
8+
expect(true).toEqual(true)
9+
})
10+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* RichEditor store test
3+
*
4+
*/
5+
6+
// import R from 'ramda'
7+
8+
// import RichEditor from '../index'
9+
10+
it('TODO: store test RichEditor',()=>{
11+
expect(1+1).toBe(2)
12+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp