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

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,272 @@
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
+ /**
109
+ * Asset definition.
110
+ *
111
+ * The definition contains the unique `id`, asset `type` and an `attributes` definition.
112
+ */
113
+ export type CKBoxAssetDefinition = CKBoxAssetImageDefinition | CKBoxAssetLinkDefinition;
114
+ /**
115
+ * Image asset definition.
116
+ *
117
+ * The definition contains the unique `id`, asset `type` and an `attributes` definition.
118
+ */
119
+ export interface CKBoxAssetImageDefinition {
120
+ /**
121
+ * An unique asset id.
122
+ */
123
+ id: string;
124
+ /**
125
+ * Asset type.
126
+ */
127
+ type: 'image';
128
+ /**
129
+ * Asset attributes.
130
+ */
131
+ attributes: CKBoxAssetImageAttributesDefinition;
132
+ }
133
+ /**
134
+ * Link asset definition.
135
+ *
136
+ * The definition contains the unique `id`, asset `type` and an `attributes` definition.
137
+ */
138
+ export interface CKBoxAssetLinkDefinition {
139
+ /**
140
+ * An unique asset id.
141
+ */
142
+ id: string;
143
+ /**
144
+ * Asset type.
145
+ */
146
+ type: 'link';
147
+ /**
148
+ * Asset attributes.
149
+ */
150
+ attributes: CKBoxAssetLinkAttributesDefinition;
151
+ }
152
+ /**
153
+ * Asset attributes definition for an image.
154
+ *
155
+ * The definition contains the `imageFallbackUrl`, an `imageSources` array with one image source definition object and the
156
+ * `imageTextAlternative`.
157
+ *
158
+ * ```ts
159
+ * {
160
+ * imageFallbackUrl: 'https://example.com/assets/asset-id/images/1000.png',
161
+ * imageSources: [
162
+ * {
163
+ * sizes: '1000px',
164
+ * srcset:
165
+ * 'https://example.com/assets/asset-id/images/100.webp 100w,' +
166
+ * 'https://example.com/assets/asset-id/images/200.webp 200w,' +
167
+ * 'https://example.com/assets/asset-id/images/300.webp 300w,' +
168
+ * 'https://example.com/assets/asset-id/images/400.webp 400w,' +
169
+ * 'https://example.com/assets/asset-id/images/500.webp 500w,' +
170
+ * 'https://example.com/assets/asset-id/images/600.webp 600w,' +
171
+ * 'https://example.com/assets/asset-id/images/700.webp 700w,' +
172
+ * 'https://example.com/assets/asset-id/images/800.webp 800w,' +
173
+ * 'https://example.com/assets/asset-id/images/900.webp 900w,' +
174
+ * 'https://example.com/assets/asset-id/images/1000.webp 1000w',
175
+ * type: 'image/webp'
176
+ * }
177
+ * ],
178
+ * imageTextAlternative: 'An alternative text for the image'
179
+ * }
180
+ * ```
181
+ */
182
+ export interface CKBoxAssetImageAttributesDefinition {
183
+ /**
184
+ * A fallback URL for browsers that do not support the "webp" format.
185
+ */
186
+ imageFallbackUrl: string;
187
+ /**
188
+ * An array containing one image source definition object.
189
+ */
190
+ imageSources: Array<{
191
+ srcset: string;
192
+ sizes: string;
193
+ type: string;
194
+ }>;
195
+ /**
196
+ * An alternative text for an image.
197
+ */
198
+ imageTextAlternative: string;
199
+ }
200
+ /**
201
+ * Asset attributes definition for a link.
202
+ *
203
+ * The definition contains the `linkName` and `linkHref` strings.
204
+ *
205
+ * ```ts
206
+ * {
207
+ * linkName: 'File name',
208
+ * linkHref: 'https://example.com/assets/asset-id/file.pdf'
209
+ * }
210
+ * ```
211
+ */
212
+ export interface CKBoxAssetLinkAttributesDefinition {
213
+ /**
214
+ * A link name.
215
+ */
216
+ linkName: string;
217
+ /**
218
+ * An URL for the asset.
219
+ */
220
+ linkHref: string;
221
+ }
222
+ /**
223
+ * Raw asset definition that is received from the CKBox feature.
224
+ */
225
+ export interface CKBoxRawAssetDefinition {
226
+ /**
227
+ * A raw asset data definition.
228
+ */
229
+ data: CKBoxRawAssetDataDefinition;
230
+ /**
231
+ * An asset origin URL.
232
+ */
233
+ origin: string;
234
+ }
235
+ /**
236
+ * Part of raw asset data that is received from the CKBox feature.
237
+ */
238
+ export interface CKBoxRawAssetDataDefinition {
239
+ /**
240
+ * An unique asset id.
241
+ */
242
+ id: string;
243
+ /**
244
+ * An asset extension.
245
+ */
246
+ extension: string;
247
+ /**
248
+ * An asset name.
249
+ */
250
+ name: string;
251
+ /**
252
+ * A raw asset metadata definition.
253
+ */
254
+ metadata?: CKBoxRawAssetMetadataDefinition;
255
+ }
256
+ /**
257
+ * Part of raw asset data that is received from the CKBox feature. Properties are set only if the chosen asset is an image.
258
+ */
259
+ export interface CKBoxRawAssetMetadataDefinition {
260
+ /**
261
+ * Image description.
262
+ */
263
+ description?: string;
264
+ /**
265
+ * Image width.
266
+ */
267
+ width?: number;
268
+ /**
269
+ * Image height.
270
+ */
271
+ height?: number;
272
+ }
@@ -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,51 @@
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
+ }