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.

Commit41d74b6

Browse files
committed
Merge branch 'editor-js' ofhttps://github.com/coderplanets/coderplanets_web into editor-js
2 parents1ed3007 +1ca2030 commit41d74b6

File tree

7 files changed

+290
-110
lines changed

7 files changed

+290
-110
lines changed

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@
4343
"@editorjs/checklist":"^1.1.0",
4444
"@editorjs/code":"^2.4.1",
4545
"@editorjs/delimiter":"^1.1.0",
46-
"@editorjs/editorjs":"^2.15.0",
46+
"@editorjs/editorjs":"^2.15.1",
4747
"@editorjs/header":"^2.3.0",
4848
"@editorjs/inline-code":"^1.3.0",
4949
"@editorjs/list":"^1.4.0",
5050
"@editorjs/marker":"^1.2.1",
51+
"@groupher/editor-code":"^1.0.0",
5152
"@groupher/editor-header":"^2.3.0",
53+
"@groupher/editor-image":"^1.0.0",
5254
"@groupher/editor-link":"^2.1.3",
5355
"@groupher/editor-quote":"^2.3.0",
5456
"@next/bundle-analyzer":"^9.0.0",

‎src/containers/RichEditor/index.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { Wrapper } from './styles'
1818
constlog=buildLog('C:RichEditor')
1919

2020
constRichEditorContainer=({ richEditor})=>{
21-
const[loaded]=useScript(
22-
'https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest'
21+
const[uploaderLoaded]=useScript(
22+
'https://gosspublic.alicdn.com/aliyun-oss-sdk-5.2.0.min.js'
2323
)
2424

25-
useInit(richEditor,loaded)
25+
useInit(richEditor,uploaderLoaded)
2626

2727
return(
2828
<Wrapper>

‎src/containers/RichEditor/logic.js‎

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// import R from 'ramda'
2+
import{useEffect}from'react'
3+
4+
importEditorJSfrom'@editorjs/editorjs'
5+
importListfrom'@editorjs/list'
6+
importMarkerfrom'@editorjs/marker'
7+
importChecklistfrom'@editorjs/checklist'
8+
importDelimiterfrom'@editorjs/delimiter'
9+
importInlineCodefrom'@editorjs/inline-code'
10+
11+
importHeaderfrom'@groupher/editor-header'
12+
importQuotefrom'@groupher/editor-quote'
13+
importLinkToolfrom'@groupher/editor-link'
14+
importCodefrom'@groupher/editor-code'
15+
importImageToolfrom'@groupher/editor-image'
16+
17+
// import Prism from 'mastani-codehighlight'
18+
19+
// import { TYPE, EVENT, ERR } from '@constant'
20+
import{buildLog}from'@utils'
21+
22+
import{initUploaderClient,uploadFile}from'./uploader'
23+
24+
letstore=null
25+
26+
/* eslint-disable-next-line */
27+
constlog=buildLog('L:RichEditor')
28+
29+
exportconstsomeMethod=()=>{}
30+
31+
// ###############################
32+
// init & uninit
33+
// ###############################
34+
35+
exportconstuseInit=(_store,uploaderLoaded)=>{
36+
useEffect(()=>{
37+
store=_store
38+
log('effect init: ',store)
39+
40+
if(uploaderLoaded){
41+
// eslint-disable-next-line
42+
consteditor=newEditorJS({
43+
/**
44+
* Id of Element that should contain Editor instance
45+
*/
46+
holderId:'codex-editor',
47+
tools:{
48+
header:{
49+
class:Header,
50+
inlineToolbar:false,
51+
},
52+
quote:Quote,
53+
list:{
54+
class:List,
55+
inlineToolbar:true,
56+
},
57+
marker:{
58+
class:Marker,
59+
},
60+
checklist:{
61+
class:Checklist,
62+
inlineToolbar:true,
63+
},
64+
delimiter:Delimiter,
65+
inlineCode:InlineCode,
66+
linkTool:{
67+
class:LinkTool,
68+
config:{
69+
endpoint:'http://localhost:4001/api/og-info',
70+
},
71+
},
72+
code:{
73+
class:Code,
74+
inlineToolbar:false,
75+
},
76+
image:{
77+
class:ImageTool,
78+
config:{
79+
endpoints:{
80+
byFile:'http://localhost:8008/uploadFile',// Your backend file uploader endpoint
81+
byUrl:'http://localhost:8008/fetchUrl',// Your endpoint that provides uploading by Url
82+
},
83+
ossKeys:{
84+
ALI_OSS_RESION:'ALI_OSS_RESION',
85+
// region: process.env.ALI_OSS_RESION,
86+
ALI_ACCESS_KEY:'ALI_ACCESS_KEY',
87+
// accessKeyId: process.env.ALI_ACCESS_KEY,
88+
ALI_ACCESS_SECRET:'ALI_ACCESS_SECRET',
89+
// accessKeySecret: process.env.ALI_ACCESS_SECRET,
90+
ALI_OSS_BUCKET:'ALI_OSS_BUCKET',
91+
// bucket: process.env.ALI_OSS_BUCKET,
92+
93+
// region: process.env.ALI_OSS_RESION,
94+
// accessKeyId: process.env.ALI_ACCESS_KEY,
95+
// accessKeySecret: process.env.ALI_ACCESS_SECRET,
96+
// bucket: process.env.ALI_OSS_BUCKET,
97+
},
98+
uploader:{
99+
/**
100+
* Upload file to the server and return an uploaded image data
101+
*@param {File} file - file selected from the device or pasted by drag-n-drop
102+
*@return {Promise.<{success, file: {url}}>}
103+
*/
104+
uploadByFile(file){
105+
// your own uploading logic here
106+
returnuploadFile(file)
107+
// return MyAjax.upload(file).then(() => {
108+
// return {
109+
// success: 1,
110+
// file: {
111+
// url:
112+
// 'https://codex.so/upload/redactor_images/o_80beea670e49f04931ce9e3b2122ac70.jpg',
113+
// // any other image data you want to store, such as width, height, color, extension, etc
114+
// },
115+
// }
116+
// })
117+
},
118+
},
119+
},
120+
},
121+
},
122+
data:{
123+
time:1552744582955,
124+
blocks:[
125+
{
126+
type:'paragraph',
127+
data:{
128+
text:'this is @',
129+
},
130+
},
131+
{
132+
type:'code',
133+
data:{
134+
lang:'css',
135+
text:
136+
'body {\n color: tomato;\n margin-left: 20px;\n};\n\nconsole.log("hello fuck")',
137+
},
138+
},
139+
],
140+
version:'2.15.1',
141+
},
142+
onChange:()=>{
143+
editor.save().then(data=>{
144+
console.log('onChange data: ',data)
145+
// Prism.highlightAll()
146+
})
147+
},
148+
})
149+
initUploaderClient(store)
150+
}
151+
152+
return()=>{
153+
// log('effect uninit')
154+
}
155+
},[_store,uploaderLoaded])
156+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// eslint-disable-next-line import/named
2+
import{ASSETS_ENDPOINT}from'@config'
3+
4+
letossClient=null
5+
letstore=null
6+
7+
exportconstinitUploaderClient=_store=>{
8+
store=_store
9+
/* eslint-disable */
10+
/* OSS sdk is import in _document from ali cdn */
11+
12+
try{
13+
/* this.state.ossClient = new OSS.Wrapper({ */
14+
ossClient=newOSS.Wrapper({
15+
region:'',
16+
accessKeyId:'',
17+
accessKeySecret:'',
18+
bucket:'',
19+
})
20+
21+
console.log('ossClient init done')
22+
}catch(e){
23+
console.error(e)
24+
// this.props.onUploadError(e)
25+
}
26+
/* eslint-enable */
27+
}
28+
29+
exportconstuploadFile=file=>{
30+
// const { ossScriptLoaded } = this.state
31+
// if (!ossScriptLoaded) return alert('脚本未加载...')
32+
// if (!file || !R.startsWith('image/', file.type)) return false
33+
// const initTimestamp = Date.now() / 1000
34+
35+
constfileSize=file.size/1024/1024
36+
if(fileSize>2)returnalert('资源有限,请不要上传大于 2MB 的文件')
37+
38+
// const curTimeStamp = Date.now() / 1000
39+
// if (curTimeStamp - initTimestamp <= 3) {
40+
// return false
41+
// }
42+
43+
// this.setState({ initTimestamp: curTimeStamp })
44+
45+
// sendEvent('start')
46+
// onUploadStart()
47+
48+
constfilename=file.name
49+
constfullpath=`${getOSSDir()}/${getOSSFileName(filename)}`
50+
51+
returnossClient
52+
.multipartUpload(fullpath,file)
53+
.then(result=>{
54+
console.log('upload done result',result)
55+
consturl=`${ASSETS_ENDPOINT}/${result.name}`
56+
return{
57+
success:1,
58+
file:{ url},
59+
// 'https://camo.githubusercontent.com/678857ab89085c81690b7a4069e266a2b1cc1c30/68747470733a2f2f636170656c6c612e706963732f37396365393436612d643633362d343163642d616139362d6433626335656366646530332e6a7067',
60+
}
61+
// const url = `${ASSETS_ENDPOINT}/${result.name}`
62+
// sendEvent('finish')
63+
// this.onUploadDone(url)
64+
})
65+
.catch(err=>{
66+
console.log(err)
67+
// sendEvent('finish')
68+
// onUploadError(err)
69+
})
70+
}
71+
72+
constgetOSSDir=()=>{
73+
constthread=store.curThread
74+
constdate=newDate()
75+
letday=date.getDate()
76+
if(day<10){
77+
day=`0${day}`
78+
}
79+
80+
return`${thread}/${date.getFullYear()}_${date.getMonth()+1}/${day}`
81+
}
82+
83+
constgetOSSFileName=filename=>{
84+
constcommunity=store.curCommunity.raw
85+
constthread=store.curThread
86+
constuserName=store.accountInfo.nickname
87+
constuserId=store.accountInfo.id
88+
constid=store.viewingData.id||'new'
89+
constcurDate=newDate()
90+
constcurTime=curDate.getTime()
91+
92+
return`${community}-${thread}-${id}-${userName}-${userId}-${curTime}-${filename}`
93+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp