@ckeditor/ckeditor5-ckbox 36.0.1 → 37.0.0-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,282 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module ckbox/ckboxconfig
7
+ */
8
+ import type { TokenUrl } from '@ckeditor/ckeditor5-cloud-services';
9
+ /**
10
+ * The configuration of the {@link module:ckbox/ckbox~CKBox CKBox feature}.
11
+ *
12
+ * The minimal configuration for the CKBox feature requires providing the
13
+ * {@link module:ckbox/ckboxconfig~CKBoxConfig#tokenUrl `config.ckbox.tokenUrl`}:
14
+ *
15
+ * ```ts
16
+ * ClassicEditor
17
+ * .create( editorElement, {
18
+ * ckbox: {
19
+ * tokenUrl: 'https://example.com/cs-token-endpoint'
20
+ * }
21
+ * } )
22
+ * .then( ... )
23
+ * .catch( ... );
24
+ * ```
25
+ *
26
+ * Hovewer, you can also adjust the feature to fit your needs:
27
+ *
28
+ * ```ts
29
+ * ClassicEditor
30
+ * .create( editorElement, {
31
+ * ckbox: {
32
+ * defaultUploadCategories: {
33
+ * Bitmaps: [ 'bmp' ],
34
+ * Pictures: [ 'jpg', 'jpeg' ],
35
+ * Scans: [ 'png', 'tiff' ]
36
+ * },
37
+ * ignoreDataId: true,
38
+ * serviceOrigin: 'https://example.com/',
39
+ * assetsOrigin: 'https://example.cloud/',
40
+ * tokenUrl: 'https://example.com/cs-token-endpoint'
41
+ * }
42
+ * } )
43
+ * .then( ... )
44
+ * .catch( ... );
45
+ * ```
46
+ *
47
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
48
+ */
49
+ export interface CKBoxConfig {
50
+ /**
51
+ * The authentication token URL for CKBox feature.
52
+ *
53
+ * Defaults to {@link module:cloud-services/cloudservicesconfig~CloudServicesConfig#tokenUrl `config.cloudServices.tokenUrl`}
54
+ */
55
+ tokenUrl?: TokenUrl;
56
+ /**
57
+ * The theme for CKBox dialog.
58
+ */
59
+ theme?: string;
60
+ /**
61
+ * Defines the categories to which the uploaded images will be assigned.
62
+ * If configured, it overrides the category mappings defined on the cloud service.
63
+ * The value of this option should be an object, where the keys define categories and their values are the types of images
64
+ * that will be uploaded to these categories. The categories might be referenced by their name or ID.
65
+ *
66
+ * Example:
67
+ *
68
+ * ```ts
69
+ * const ckboxConfig = {
70
+ * defaultUploadCategories: {
71
+ * Bitmaps: [ 'bmp' ],
72
+ * Pictures: [ 'jpg', 'jpeg' ],
73
+ * Scans: [ 'png', 'tiff' ],
74
+ * // The category below is referenced by its ID.
75
+ * 'fdf2a647-b67f-4a6c-b692-5ba1dc1ed87b': [ 'gif' ]
76
+ * }
77
+ * };
78
+ * ```
79
+ *
80
+ * @default null
81
+ */
82
+ defaultUploadCategories?: Record<string, Array<string>> | null;
83
+ /**
84
+ * Inserts the unique asset ID as the `data-ckbox-resource-id` attribute. To disable this behavior, set it to `true`.
85
+ *
86
+ * @default false
87
+ */
88
+ ignoreDataId?: boolean;
89
+ /**
90
+ * Configures the base URL of the API service. Required only in on-premises installations.
91
+ *
92
+ * @default 'https://api.ckbox.io'
93
+ */
94
+ serviceOrigin?: string;
95
+ /**
96
+ * Configures the base URL for assets inserted into the editor. Required only in on-premises installations.
97
+ *
98
+ * @default 'https://ckbox.cloud'
99
+ */
100
+ assetsOrigin?: string;
101
+ /**
102
+ * Configures the language for the CKBox dialog.
103
+ *
104
+ * Defaults to {@link module:utils/locale~Locale#uiLanguage `Locale#uiLanguage`}
105
+ */
106
+ language?: string;
107
+ }
108
+ declare module '@ckeditor/ckeditor5-core' {
109
+ interface EditorConfig {
110
+ /**
111
+ * The configuration of the {@link module:ckbox/ckbox~CKBox CKBox feature}.
112
+ *
113
+ * Read more in {@link module:ckbox/ckboxconfig~CKBoxConfig}.
114
+ */
115
+ ckbox?: CKBoxConfig;
116
+ }
117
+ }
118
+ /**
119
+ * Asset definition.
120
+ *
121
+ * The definition contains the unique `id`, asset `type` and an `attributes` definition.
122
+ */
123
+ export type CKBoxAssetDefinition = CKBoxAssetImageDefinition | CKBoxAssetLinkDefinition;
124
+ /**
125
+ * Image asset definition.
126
+ *
127
+ * The definition contains the unique `id`, asset `type` and an `attributes` definition.
128
+ */
129
+ export interface CKBoxAssetImageDefinition {
130
+ /**
131
+ * An unique asset id.
132
+ */
133
+ id: string;
134
+ /**
135
+ * Asset type.
136
+ */
137
+ type: 'image';
138
+ /**
139
+ * Asset attributes.
140
+ */
141
+ attributes: CKBoxAssetImageAttributesDefinition;
142
+ }
143
+ /**
144
+ * Link asset definition.
145
+ *
146
+ * The definition contains the unique `id`, asset `type` and an `attributes` definition.
147
+ */
148
+ export interface CKBoxAssetLinkDefinition {
149
+ /**
150
+ * An unique asset id.
151
+ */
152
+ id: string;
153
+ /**
154
+ * Asset type.
155
+ */
156
+ type: 'link';
157
+ /**
158
+ * Asset attributes.
159
+ */
160
+ attributes: CKBoxAssetLinkAttributesDefinition;
161
+ }
162
+ /**
163
+ * Asset attributes definition for an image.
164
+ *
165
+ * The definition contains the `imageFallbackUrl`, an `imageSources` array with one image source definition object and the
166
+ * `imageTextAlternative`.
167
+ *
168
+ * ```ts
169
+ * {
170
+ * imageFallbackUrl: 'https://example.com/assets/asset-id/images/1000.png',
171
+ * imageSources: [
172
+ * {
173
+ * sizes: '1000px',
174
+ * srcset:
175
+ * 'https://example.com/assets/asset-id/images/100.webp 100w,' +
176
+ * 'https://example.com/assets/asset-id/images/200.webp 200w,' +
177
+ * 'https://example.com/assets/asset-id/images/300.webp 300w,' +
178
+ * 'https://example.com/assets/asset-id/images/400.webp 400w,' +
179
+ * 'https://example.com/assets/asset-id/images/500.webp 500w,' +
180
+ * 'https://example.com/assets/asset-id/images/600.webp 600w,' +
181
+ * 'https://example.com/assets/asset-id/images/700.webp 700w,' +
182
+ * 'https://example.com/assets/asset-id/images/800.webp 800w,' +
183
+ * 'https://example.com/assets/asset-id/images/900.webp 900w,' +
184
+ * 'https://example.com/assets/asset-id/images/1000.webp 1000w',
185
+ * type: 'image/webp'
186
+ * }
187
+ * ],
188
+ * imageTextAlternative: 'An alternative text for the image'
189
+ * }
190
+ * ```
191
+ */
192
+ export interface CKBoxAssetImageAttributesDefinition {
193
+ /**
194
+ * A fallback URL for browsers that do not support the "webp" format.
195
+ */
196
+ imageFallbackUrl: string;
197
+ /**
198
+ * An array containing one image source definition object.
199
+ */
200
+ imageSources: Array<{
201
+ srcset: string;
202
+ sizes: string;
203
+ type: string;
204
+ }>;
205
+ /**
206
+ * An alternative text for an image.
207
+ */
208
+ imageTextAlternative: string;
209
+ }
210
+ /**
211
+ * Asset attributes definition for a link.
212
+ *
213
+ * The definition contains the `linkName` and `linkHref` strings.
214
+ *
215
+ * ```ts
216
+ * {
217
+ * linkName: 'File name',
218
+ * linkHref: 'https://example.com/assets/asset-id/file.pdf'
219
+ * }
220
+ * ```
221
+ */
222
+ export interface CKBoxAssetLinkAttributesDefinition {
223
+ /**
224
+ * A link name.
225
+ */
226
+ linkName: string;
227
+ /**
228
+ * An URL for the asset.
229
+ */
230
+ linkHref: string;
231
+ }
232
+ /**
233
+ * Raw asset definition that is received from the CKBox feature.
234
+ */
235
+ export interface CKBoxRawAssetDefinition {
236
+ /**
237
+ * A raw asset data definition.
238
+ */
239
+ data: CKBoxRawAssetDataDefinition;
240
+ /**
241
+ * An asset origin URL.
242
+ */
243
+ origin: string;
244
+ }
245
+ /**
246
+ * Part of raw asset data that is received from the CKBox feature.
247
+ */
248
+ export interface CKBoxRawAssetDataDefinition {
249
+ /**
250
+ * An unique asset id.
251
+ */
252
+ id: string;
253
+ /**
254
+ * An asset extension.
255
+ */
256
+ extension: string;
257
+ /**
258
+ * An asset name.
259
+ */
260
+ name: string;
261
+ /**
262
+ * A raw asset metadata definition.
263
+ */
264
+ metadata?: CKBoxRawAssetMetadataDefinition;
265
+ }
266
+ /**
267
+ * Part of raw asset data that is received from the CKBox feature. Properties are set only if the chosen asset is an image.
268
+ */
269
+ export interface CKBoxRawAssetMetadataDefinition {
270
+ /**
271
+ * Image description.
272
+ */
273
+ description?: string;
274
+ /**
275
+ * Image width.
276
+ */
277
+ width?: number;
278
+ /**
279
+ * Image height.
280
+ */
281
+ height?: number;
282
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ export {};
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module ckbox/ckboxediting
7
+ */
8
+ import type { InitializedToken } from '@ckeditor/ckeditor5-cloud-services';
9
+ import { Plugin, type PluginDependencies } from 'ckeditor5/src/core';
10
+ /**
11
+ * The CKBox editing feature. It introduces the {@link module:ckbox/ckboxcommand~CKBoxCommand CKBox command} and
12
+ * {@link module:ckbox/ckboxuploadadapter~CKBoxUploadAdapter CKBox upload adapter}.
13
+ */
14
+ export default class CKBoxEditing extends Plugin {
15
+ /**
16
+ * CKEditor Cloud Services access token.
17
+ */
18
+ private _token;
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get pluginName(): 'CKBoxEditing';
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ static get requires(): PluginDependencies;
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ init(): Promise<void>;
31
+ /**
32
+ * Returns a token used by the CKBox plugin for communication with the CKBox service.
33
+ */
34
+ getToken(): InitializedToken;
35
+ /**
36
+ * Initializes the `ckbox` editor configuration.
37
+ */
38
+ private _initConfig;
39
+ /**
40
+ * Extends the schema to allow the `ckboxImageId` and `ckboxLinkId` attributes for links and images.
41
+ */
42
+ private _initSchema;
43
+ /**
44
+ * Configures the upcast and downcast conversions for the `ckboxImageId` and `ckboxLinkId` attributes.
45
+ */
46
+ private _initConversion;
47
+ /**
48
+ * Registers post-fixers that add or remove the `ckboxLinkId` and `ckboxImageId` attributes.
49
+ */
50
+ private _initFixers;
51
+ }
52
+ declare module '@ckeditor/ckeditor5-core' {
53
+ interface PluginsMap {
54
+ [CKBoxEditing.pluginName]: CKBoxEditing;
55
+ }
56
+ }