Skip to content

Commit 4616b67

Browse files
feat(editor): DP-130987 insert inline image through editor (#692)
1 parent e162f6f commit 4616b67

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

packages/dialtone-vue2/recipes/conversation_view/editor/editor.stories.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export const argTypesData = {
4444
disable: true,
4545
},
4646
},
47+
48+
onInlineImageClick: {
49+
table: {
50+
disable: true,
51+
},
52+
},
4753
};
4854

4955
// Set default values at the story level here.
@@ -56,6 +62,7 @@ export const argsData = {
5662
onBlur: action('blur'),
5763
onInput: action('input'),
5864
onQuickRepliesClick: action('quick-replies-click'),
65+
onInlineImageClick: action('inline-image-click'),
5966
};
6067

6168
// Story Collection

packages/dialtone-vue2/recipes/conversation_view/editor/editor.vue

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ import {
202202
DtIconAlignRight,
203203
DtIconBold,
204204
DtIconCodeBlock,
205+
DtIconImage,
205206
DtIconItalic,
206207
DtIconLightningBolt,
207208
DtIconLink2,
@@ -236,6 +237,7 @@ export default {
236237
DtIconQuote,
237238
DtIconCodeBlock,
238239
DtIconLink2,
240+
DtIconImage,
239241
},
240242
241243
inheritAttrs: false,
@@ -452,6 +454,14 @@ export default {
452454
default: true,
453455
},
454456
457+
/**
458+
* Show button to add an inline image
459+
*/
460+
showInlineImageButton: {
461+
type: Boolean,
462+
default: false,
463+
},
464+
455465
/**
456466
* Show add link default config.
457467
*/
@@ -501,6 +511,12 @@ export default {
501511
* @event quick-replies-click
502512
*/
503513
'quick-replies-click',
514+
515+
/**
516+
* Emit when inline image button is clicked
517+
* @event inline-image-click
518+
*/
519+
'inline-image-click',
504520
],
505521
506522
data () {
@@ -680,6 +696,14 @@ export default {
680696
tooltipMessage: 'Code',
681697
onClick: this.onCodeBlockToggle,
682698
},
699+
{
700+
showBtn: this.showInlineImageButton,
701+
selector: 'image',
702+
icon: DtIconImage,
703+
dataQA: 'dt-recipe-editor-inline-image-btn',
704+
tooltipMessage: 'Image',
705+
onClick: this.onInsertInlineImageClick,
706+
},
683707
].filter(button => button.showBtn);
684708
},
685709
@@ -815,6 +839,14 @@ export default {
815839
this.$emit('quick-replies-click');
816840
},
817841
842+
onInsertInlineImageClick () {
843+
this.$emit('inline-image-click');
844+
},
845+
846+
insertInlineImage (imageUrl) {
847+
this.$refs.richTextEditor?.editor.chain().focus().setImage({ src: imageUrl }).run();
848+
},
849+
818850
onBlockquoteToggle () {
819851
this.$refs.richTextEditor?.editor.chain().focus().toggleBlockquote().run();
820852
},

packages/dialtone-vue2/recipes/conversation_view/editor/editor_default.story.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
:show-align-justify-button="$attrs.showAlignJustifyButton"
2929
:show-quote-button="$attrs.showQuoteButton"
3030
:show-quick-replies-button="$attrs.showQuickRepliesButton"
31+
:show-inline-image-button="$attrs.showInlineImageButton"
3132
:show-code-block-button="$attrs.showCodeBlockButton"
3233
@focus="$attrs.onFocus"
3334
@blur="$attrs.onBlur"
3435
@input="$attrs.onInput"
3536
@quick-replies-click="$attrs.onQuickRepliesClick"
37+
@inline-image-click="$attrs.onInlineImageClick"
3638
/>
3739
<p><strong>Editor content is:</strong></p>
3840
<span>{{ value }}</span>

packages/dialtone-vue3/recipes/conversation_view/editor/editor.stories.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export const argTypesData = {
4444
disable: true,
4545
},
4646
},
47+
48+
onInlineImageClick: {
49+
table: {
50+
disable: true,
51+
},
52+
},
4753
};
4854

4955
// Set default values at the story level here.
@@ -56,6 +62,7 @@ export const argsData = {
5662
onBlur: action('blur'),
5763
onInput: action('input'),
5864
onQuickRepliesClick: action('quick-replies-click'),
65+
onInlineImageClick: action('inline-image-click'),
5966
};
6067

6168
// Story Collection

packages/dialtone-vue3/recipes/conversation_view/editor/editor.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ import {
203203
DtIconAlignRight,
204204
DtIconBold,
205205
DtIconCodeBlock,
206+
DtIconImage,
206207
DtIconItalic,
207208
DtIconLightningBolt,
208209
DtIconLink2,
@@ -238,6 +239,7 @@ export default {
238239
DtIconQuote,
239240
DtIconCodeBlock,
240241
DtIconLink2,
242+
DtIconImage,
241243
},
242244
243245
mixins: [],
@@ -456,6 +458,14 @@ export default {
456458
default: true,
457459
},
458460
461+
/**
462+
* Show button to add an inline image
463+
*/
464+
showInlineImageButton: {
465+
type: Boolean,
466+
default: false,
467+
},
468+
459469
/**
460470
* Show add link default config.
461471
*/
@@ -505,6 +515,12 @@ export default {
505515
* @event quick-replies-click
506516
*/
507517
'quick-replies-click',
518+
519+
/**
520+
* Emit when inline image button is clicked
521+
* @event inline-image-click
522+
*/
523+
'inline-image-click',
508524
],
509525
510526
data () {
@@ -684,6 +700,15 @@ export default {
684700
tooltipMessage: 'Code',
685701
onClick: this.onCodeBlockToggle,
686702
},
703+
{
704+
showBtn: this.showInlineImageButton,
705+
selector: 'image',
706+
icon: DtIconImage,
707+
dataQA: 'dt-recipe-editor-inline-image-btn',
708+
tooltipMessage: 'Image',
709+
// Handle getting image
710+
onClick: this.onInsertInlineImageClick,
711+
},
687712
].filter(button => button.showBtn);
688713
},
689714
@@ -822,6 +847,14 @@ export default {
822847
this.$emit('quick-replies-click');
823848
},
824849
850+
onInsertInlineImageClick () {
851+
this.$emit('inline-image-click');
852+
},
853+
854+
insertInlineImage (imageUrl) {
855+
this.$refs.richTextEditor?.editor.chain().focus().setImage({ src: imageUrl }).run();
856+
},
857+
825858
insertInMessageBody (messageContent) {
826859
this.$refs.richTextEditor?.editor.chain().focus().insertContent(messageContent).run();
827860
},

packages/dialtone-vue3/recipes/conversation_view/editor/editor_default.story.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
:show-quote-button="$attrs.showQuoteButton"
3030
:show-quick-replies-button="$attrs.showQuickRepliesButton"
3131
:show-code-block-button="$attrs.showCodeBlockButton"
32+
:show-inline-image-button="$attrs.showInlineImageButton"
3233
@focus="$attrs.onFocus"
3334
@blur="$attrs.onBlur"
3435
@input="$attrs.onInput"
3536
@quick-replies-click="$attrs.onQuickRepliesClick"
37+
@inline-image-click="$attrs.onInlineImageClick"
3638
/>
3739
<p><strong>Editor content is:</strong></p>
3840
<span>{{ value }}</span>

0 commit comments

Comments
 (0)