1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import { LabeledFieldView, createLabeledInputText } from 'ckeditor5/src/ui';
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export function prepareIntegrations( editor ) {
|
21 | const panelItems = editor.config.get( 'image.insert.integrations' );
|
22 | const imageInsertUIPlugin = editor.plugins.get( 'ImageInsertUI' );
|
23 |
|
24 | const PREDEFINED_INTEGRATIONS = {
|
25 | 'insertImageViaUrl': createLabeledInputView( editor.locale )
|
26 | };
|
27 |
|
28 | if ( !panelItems ) {
|
29 | return PREDEFINED_INTEGRATIONS;
|
30 | }
|
31 |
|
32 |
|
33 | if ( panelItems.find( item => item === 'openCKFinder' ) && editor.ui.componentFactory.has( 'ckfinder' ) ) {
|
34 | const ckFinderButton = editor.ui.componentFactory.create( 'ckfinder' );
|
35 | ckFinderButton.set( {
|
36 | withText: true,
|
37 | class: 'ck-image-insert__ck-finder-button'
|
38 | } );
|
39 |
|
40 |
|
41 | ckFinderButton.delegate( 'execute' ).to( imageInsertUIPlugin, 'cancel' );
|
42 |
|
43 | PREDEFINED_INTEGRATIONS.openCKFinder = ckFinderButton;
|
44 | }
|
45 |
|
46 |
|
47 | return panelItems.reduce( ( object, key ) => {
|
48 | if ( PREDEFINED_INTEGRATIONS[ key ] ) {
|
49 | object[ key ] = PREDEFINED_INTEGRATIONS[ key ];
|
50 | } else if ( editor.ui.componentFactory.has( key ) ) {
|
51 | object[ key ] = editor.ui.componentFactory.create( key );
|
52 | }
|
53 |
|
54 | return object;
|
55 | }, {} );
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | export function createLabeledInputView( locale ) {
|
66 | const t = locale.t;
|
67 | const labeledInputView = new LabeledFieldView( locale, createLabeledInputText );
|
68 |
|
69 | labeledInputView.set( {
|
70 | label: t( 'Insert image via URL' )
|
71 | } );
|
72 | labeledInputView.fieldView.placeholder = 'https://example.com/image.png';
|
73 |
|
74 | return labeledInputView;
|
75 | }
|