Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bb412bac
Commit
bb412bac
authored
May 25, 2020
by
jerasmus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to insert an image via SSE
Added the ability to insert an image via SSE
parent
dfbf879e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
32 deletions
+98
-32
app/assets/javascripts/vue_shared/components/rich_content_editor/constants.js
...ts/vue_shared/components/rich_content_editor/constants.js
+5
-1
app/assets/javascripts/vue_shared/components/rich_content_editor/editor_service.js
...e_shared/components/rich_content_editor/editor_service.js
+5
-1
app/assets/javascripts/vue_shared/components/rich_content_editor/rich_content_editor.vue
...ed/components/rich_content_editor/rich_content_editor.vue
+20
-1
spec/frontend/vue_shared/components/rich_content_editor/editor_service_spec.js
...red/components/rich_content_editor/editor_service_spec.js
+47
-0
spec/frontend/vue_shared/components/rich_content_editor/rich_content_editor_spec.js
...omponents/rich_content_editor/rich_content_editor_spec.js
+21
-0
spec/frontend/vue_shared/components/rich_content_editor/toolbar_service_spec.js
...ed/components/rich_content_editor/toolbar_service_spec.js
+0
-29
No files found.
app/assets/javascripts/vue_shared/components/rich_content_editor/constants.js
View file @
bb412bac
import
{
__
}
from
'
~/locale
'
;
import
{
generateToolbarItem
}
from
'
./toolbar_service
'
;
import
{
generateToolbarItem
}
from
'
./editor_service
'
;
export
const
CUSTOM_EVENTS
=
{
openAddImageModal
:
'
gl_openAddImageModal
'
,
};
/* eslint-disable @gitlab/require-i18n-strings */
const
TOOLBAR_ITEM_CONFIGS
=
[
...
...
app/assets/javascripts/vue_shared/components/rich_content_editor/
toolba
r_service.js
→
app/assets/javascripts/vue_shared/components/rich_content_editor/
edito
r_service.js
View file @
bb412bac
...
...
@@ -12,7 +12,6 @@ const buildWrapper = propsData => {
return
instance
.
$el
;
};
// eslint-disable-next-line import/prefer-default-export
export
const
generateToolbarItem
=
config
=>
{
const
{
icon
,
classes
,
event
,
command
,
tooltip
,
isDivider
}
=
config
;
...
...
@@ -30,3 +29,8 @@ export const generateToolbarItem = config => {
},
};
};
export
const
addCustomEventListener
=
(
editorInstance
,
event
,
handler
)
=>
{
editorInstance
.
eventManager
.
addEventType
(
event
);
editorInstance
.
eventManager
.
listen
(
event
,
handler
);
};
app/assets/javascripts/vue_shared/components/rich_content_editor/rich_content_editor.vue
View file @
bb412bac
...
...
@@ -2,7 +2,15 @@
import
'
codemirror/lib/codemirror.css
'
;
import
'
@toast-ui/editor/dist/toastui-editor.css
'
;
import
{
EDITOR_OPTIONS
,
EDITOR_TYPES
,
EDITOR_HEIGHT
,
EDITOR_PREVIEW_STYLE
}
from
'
./constants
'
;
import
{
EDITOR_OPTIONS
,
EDITOR_TYPES
,
EDITOR_HEIGHT
,
EDITOR_PREVIEW_STYLE
,
CUSTOM_EVENTS
,
}
from
'
./constants
'
;
import
{
addCustomEventListener
}
from
'
./editor_service
'
;
export
default
{
components
:
{
...
...
@@ -49,6 +57,16 @@ export default {
getMarkdown
()
{
return
this
.
$refs
.
editor
.
invoke
(
'
getMarkdown
'
);
},
onLoad
(
editorInstance
)
{
addCustomEventListener
(
editorInstance
,
CUSTOM_EVENTS
.
openAddImageModal
,
this
.
onOpenAddImageModal
,
);
},
onOpenAddImageModal
()
{
// TODO - add image modal (next MR)
},
},
};
</
script
>
...
...
@@ -61,5 +79,6 @@ export default {
:initial-edit-type=
"initialEditType"
:height=
"height"
@
change=
"onContentChanged"
@
load=
"onLoad"
/>
</
template
>
spec/frontend/vue_shared/components/rich_content_editor/editor_service_spec.js
0 → 100644
View file @
bb412bac
import
{
generateToolbarItem
,
addCustomEventListener
,
}
from
'
~/vue_shared/components/rich_content_editor/editor_service
'
;
describe
(
'
Editor Service
'
,
()
=>
{
describe
(
'
generateToolbarItem
'
,
()
=>
{
const
config
=
{
icon
:
'
bold
'
,
command
:
'
some-command
'
,
tooltip
:
'
Some Tooltip
'
,
event
:
'
some-event
'
,
};
const
generatedItem
=
generateToolbarItem
(
config
);
it
(
'
generates the correct command
'
,
()
=>
{
expect
(
generatedItem
.
options
.
command
).
toBe
(
config
.
command
);
});
it
(
'
generates the correct tooltip
'
,
()
=>
{
expect
(
generatedItem
.
options
.
tooltip
).
toBe
(
config
.
tooltip
);
});
it
(
'
generates the correct event
'
,
()
=>
{
expect
(
generatedItem
.
options
.
event
).
toBe
(
config
.
event
);
});
it
(
'
generates a divider when isDivider is set to true
'
,
()
=>
{
const
isDivider
=
true
;
expect
(
generateToolbarItem
({
isDivider
})).
toBe
(
'
divider
'
);
});
});
describe
(
'
addCustomEventListener
'
,
()
=>
{
const
mockInstance
=
{
eventManager
:
{
addEventType
:
jest
.
fn
(),
listen
:
jest
.
fn
()
}
};
const
event
=
'
someCustomEvent
'
;
const
handler
=
jest
.
fn
();
it
(
'
registers an event type on the instance and adds an event handler
'
,
()
=>
{
addCustomEventListener
(
mockInstance
,
event
,
handler
);
expect
(
mockInstance
.
eventManager
.
addEventType
).
toHaveBeenCalledWith
(
event
);
expect
(
mockInstance
.
eventManager
.
listen
).
toHaveBeenCalledWith
(
event
,
handler
);
});
});
});
spec/frontend/vue_shared/components/rich_content_editor/rich_content_editor_spec.js
View file @
bb412bac
...
...
@@ -5,8 +5,16 @@ import {
EDITOR_TYPES
,
EDITOR_HEIGHT
,
EDITOR_PREVIEW_STYLE
,
CUSTOM_EVENTS
,
}
from
'
~/vue_shared/components/rich_content_editor/constants
'
;
import
{
addCustomEventListener
}
from
'
~/vue_shared/components/rich_content_editor/editor_service
'
;
jest
.
mock
(
'
~/vue_shared/components/rich_content_editor/editor_service
'
,
()
=>
({
...
jest
.
requireActual
(
'
~/vue_shared/components/rich_content_editor/editor_service
'
),
addCustomEventListener
:
jest
.
fn
(),
}));
describe
(
'
Rich Content Editor
'
,
()
=>
{
let
wrapper
;
...
...
@@ -56,4 +64,17 @@ describe('Rich Content Editor', () => {
expect
(
wrapper
.
emitted
().
input
[
0
][
0
]).
toBe
(
changedMarkdown
);
});
});
describe
(
'
when editor is loaded
'
,
()
=>
{
it
(
'
adds the CUSTOM_EVENTS.openAddImageModal custom event listener
'
,
()
=>
{
const
mockInstance
=
{
eventManager
:
{
addEventType
:
jest
.
fn
(),
listen
:
jest
.
fn
()
}
};
findEditor
().
vm
.
$emit
(
'
load
'
,
mockInstance
);
expect
(
addCustomEventListener
).
toHaveBeenCalledWith
(
mockInstance
,
CUSTOM_EVENTS
.
openAddImageModal
,
wrapper
.
vm
.
onOpenAddImageModal
,
);
});
});
});
spec/frontend/vue_shared/components/rich_content_editor/toolbar_service_spec.js
deleted
100644 → 0
View file @
dfbf879e
import
{
generateToolbarItem
}
from
'
~/vue_shared/components/rich_content_editor/toolbar_service
'
;
describe
(
'
Toolbar Service
'
,
()
=>
{
const
config
=
{
icon
:
'
bold
'
,
command
:
'
some-command
'
,
tooltip
:
'
Some Tooltip
'
,
event
:
'
some-event
'
,
};
const
generatedItem
=
generateToolbarItem
(
config
);
it
(
'
generates the correct command
'
,
()
=>
{
expect
(
generatedItem
.
options
.
command
).
toBe
(
config
.
command
);
});
it
(
'
generates the correct tooltip
'
,
()
=>
{
expect
(
generatedItem
.
options
.
tooltip
).
toBe
(
config
.
tooltip
);
});
it
(
'
generates the correct event
'
,
()
=>
{
expect
(
generatedItem
.
options
.
event
).
toBe
(
config
.
event
);
});
it
(
'
generates a divider when isDivider is set to true
'
,
()
=>
{
const
isDivider
=
true
;
expect
(
generateToolbarItem
({
isDivider
})).
toBe
(
'
divider
'
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment