Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
condenser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
condenser
Commits
014c4fbf
Commit
014c4fbf
authored
8 years ago
by
Tim
Browse files
Options
Downloads
Patches
Plain Diff
insert image as inline, add shortcuts
#185
parent
d85f3b89
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/components/elements/SlateEditor.jsx
+31
-3
31 additions, 3 deletions
app/components/elements/SlateEditor.jsx
app/components/elements/SlateEditor.scss
+1
-0
1 addition, 0 deletions
app/components/elements/SlateEditor.scss
app/utils/SlateEditor/Schema.js
+6
-1
6 additions, 1 deletion
app/utils/SlateEditor/Schema.js
with
38 additions
and
4 deletions
app/components/elements/SlateEditor.jsx
+
31
−
3
View file @
014c4fbf
...
@@ -28,7 +28,7 @@ if(process.env.BROWSER) {
...
@@ -28,7 +28,7 @@ if(process.env.BROWSER) {
InsertImages
({
InsertImages
({
extensions
:
[
'
jpeg
'
],
extensions
:
[
'
jpeg
'
],
applyTransform
:
(
transform
,
file
)
=>
{
applyTransform
:
(
transform
,
file
)
=>
{
return
transform
.
insert
Block
({
return
transform
.
insert
Inline
({
type
:
'
image
'
,
type
:
'
image
'
,
isVoid
:
true
,
isVoid
:
true
,
data
:
{
file
}
data
:
{
file
}
...
@@ -160,7 +160,7 @@ export default class SlateEditor extends React.Component {
...
@@ -160,7 +160,7 @@ export default class SlateEditor extends React.Component {
const
hasLinks
=
this
.
hasInline
(
'
link
'
)
const
hasLinks
=
this
.
hasInline
(
'
link
'
)
if
(
hasLinks
)
{
if
(
hasLinks
)
{
console
.
log
(
JSON
.
stringify
(
Raw
.
serialize
(
state
,
{
terse
:
false
})))
console
.
log
(
JSON
.
stringify
(
Raw
.
serialize
(
state
,
{
terse
:
false
})
,
null
,
2
))
state
=
state
state
=
state
.
transform
()
.
transform
()
.
unwrapInline
(
'
link
'
)
.
unwrapInline
(
'
link
'
)
...
@@ -195,13 +195,14 @@ console.log(JSON.stringify(Raw.serialize(state, {terse: false})))
...
@@ -195,13 +195,14 @@ console.log(JSON.stringify(Raw.serialize(state, {terse: false})))
.
collapseToEnd
()
.
collapseToEnd
()
.
apply
()
.
apply
()
}
}
console
.
log
(
JSON
.
stringify
(
Raw
.
serialize
(
state
,
{
terse
:
false
})))
console
.
log
(
JSON
.
stringify
(
Raw
.
serialize
(
state
,
{
terse
:
false
})
,
null
,
2
))
this
.
setState
({
state
})
this
.
setState
({
state
})
}
}
// Markdown-style quick formatting
// Markdown-style quick formatting
onKeyDown
=
(
e
,
data
,
state
)
=>
{
onKeyDown
=
(
e
,
data
,
state
)
=>
{
if
(
data
.
isMod
)
return
this
.
onModKeyDown
(
e
,
data
,
state
);
switch
(
data
.
key
)
{
switch
(
data
.
key
)
{
case
'
space
'
:
return
this
.
onSpace
(
e
,
state
)
case
'
space
'
:
return
this
.
onSpace
(
e
,
state
)
case
'
backspace
'
:
return
this
.
onBackspace
(
e
,
state
)
case
'
backspace
'
:
return
this
.
onBackspace
(
e
,
state
)
...
@@ -209,6 +210,33 @@ console.log(JSON.stringify(Raw.serialize(state, {terse: false})))
...
@@ -209,6 +210,33 @@ console.log(JSON.stringify(Raw.serialize(state, {terse: false})))
}
}
}
}
onModKeyDown
=
(
e
,
data
,
state
)
=>
{
let
mark
switch
(
data
.
key
)
{
case
'
b
'
:
mark
=
'
bold
'
break
case
'
i
'
:
mark
=
'
italic
'
break
case
'
u
'
:
mark
=
'
underline
'
break
case
'
k
'
:
return
this
.
onClickLink
(
e
);
}
if
(
!
mark
)
return
;
state
=
state
.
transform
()
.
toggleMark
(
mark
)
.
apply
()
e
.
preventDefault
()
return
state
}
// If space was entered, check if it was a markdown sequence
// If space was entered, check if it was a markdown sequence
onSpace
=
(
e
,
state
)
=>
{
onSpace
=
(
e
,
state
)
=>
{
if
(
state
.
isExpanded
)
return
if
(
state
.
isExpanded
)
return
...
...
This diff is collapsed.
Click to expand it.
app/components/elements/SlateEditor.scss
+
1
−
0
View file @
014c4fbf
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
a
{
a
{
border-bottom
:
1px
dotted
#00f
;
border-bottom
:
1px
dotted
#00f
;
position
:
relative
;
position
:
relative
;
img
{
border
:
1px
dotted
#00f
}
}
}
.active
{
.active
{
box-shadow
:
0
0
0
2px
blue
;
box-shadow
:
0
0
0
2px
blue
;
...
...
This diff is collapsed.
Click to expand it.
app/utils/SlateEditor/Schema.js
+
6
−
1
View file @
014c4fbf
...
@@ -51,11 +51,16 @@ export const HtmlRules = [
...
@@ -51,11 +51,16 @@ export const HtmlRules = [
deserialize
:
(
el
,
next
)
=>
{
deserialize
:
(
el
,
next
)
=>
{
const
type
=
BLOCK_TAGS
[
el
.
tagName
]
const
type
=
BLOCK_TAGS
[
el
.
tagName
]
if
(
!
type
)
return
if
(
!
type
)
return
// Special case for <pre>: ignore its inner <code> element.
const
code
=
el
.
tagName
==
'
pre
'
?
el
.
children
[
0
]
:
null
const
children
=
code
&&
code
.
tagName
==
'
code
'
?
code
.
children
:
el
.
children
return
{
return
{
kind
:
'
block
'
,
kind
:
'
block
'
,
type
:
type
,
type
:
type
,
isVoid
:
(
type
==
'
hr
'
),
isVoid
:
(
type
==
'
hr
'
),
nodes
:
next
(
el
.
children
)
nodes
:
next
(
children
)
}
}
},
},
serialize
:
(
object
,
children
)
=>
{
serialize
:
(
object
,
children
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment