jodit 4.19.6 → 4.19.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/es2015/jodit.css +1 -1
  3. package/es2015/jodit.fat.min.js +10 -10
  4. package/es2015/jodit.js +787 -200
  5. package/es2015/jodit.min.js +10 -10
  6. package/es2015/plugins/debug/debug.css +1 -1
  7. package/es2015/plugins/debug/debug.js +1 -1
  8. package/es2015/plugins/debug/debug.min.js +1 -1
  9. package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
  10. package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
  11. package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
  12. package/es2018/jodit.fat.min.js +10 -10
  13. package/es2018/jodit.min.js +10 -10
  14. package/es2018/plugins/debug/debug.min.js +1 -1
  15. package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
  16. package/es2021/jodit.css +1 -1
  17. package/es2021/jodit.fat.min.js +12 -12
  18. package/es2021/jodit.js +709 -143
  19. package/es2021/jodit.min.js +12 -12
  20. package/es2021/plugins/debug/debug.css +1 -1
  21. package/es2021/plugins/debug/debug.js +1 -1
  22. package/es2021/plugins/debug/debug.min.js +1 -1
  23. package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
  24. package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
  25. package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
  26. package/es2021.en/jodit.css +1 -1
  27. package/es2021.en/jodit.fat.min.js +18 -18
  28. package/es2021.en/jodit.js +709 -143
  29. package/es2021.en/jodit.min.js +18 -18
  30. package/es2021.en/plugins/debug/debug.css +1 -1
  31. package/es2021.en/plugins/debug/debug.js +1 -1
  32. package/es2021.en/plugins/debug/debug.min.js +1 -1
  33. package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
  34. package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
  35. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
  36. package/es5/jodit.css +2 -2
  37. package/es5/jodit.fat.min.js +2 -2
  38. package/es5/jodit.js +947 -208
  39. package/es5/jodit.min.css +2 -2
  40. package/es5/jodit.min.js +2 -2
  41. package/es5/plugins/debug/debug.css +1 -1
  42. package/es5/plugins/debug/debug.js +1 -1
  43. package/es5/plugins/debug/debug.min.js +1 -1
  44. package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
  45. package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
  46. package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
  47. package/es5/polyfills.fat.min.js +1 -1
  48. package/es5/polyfills.js +1 -1
  49. package/es5/polyfills.min.js +1 -1
  50. package/esm/core/constants.d.ts +1 -0
  51. package/esm/core/constants.js +3 -1
  52. package/esm/core/helpers/utils/error/error.d.ts +1 -0
  53. package/esm/core/helpers/utils/error/error.js +4 -1
  54. package/esm/core/helpers/utils/error/errors/answer-error.d.ts +13 -0
  55. package/esm/core/helpers/utils/error/errors/answer-error.js +17 -0
  56. package/esm/core/helpers/utils/error/errors/index.d.ts +1 -0
  57. package/esm/core/helpers/utils/error/errors/index.js +1 -0
  58. package/esm/core/request/ajax.d.ts +1 -0
  59. package/esm/core/request/ajax.js +20 -1
  60. package/esm/core/selection/style/apply-style.js +31 -2
  61. package/esm/jodit.js +14 -2
  62. package/esm/modules/file-browser/data-provider.js +5 -3
  63. package/esm/modules/uploader/config.js +4 -0
  64. package/esm/modules/uploader/helpers/send-files.d.ts +2 -2
  65. package/esm/modules/uploader/helpers/send-files.js +76 -9
  66. package/esm/modules/uploader/helpers/upload-error.d.ts +15 -0
  67. package/esm/modules/uploader/helpers/upload-error.js +16 -0
  68. package/esm/modules/uploader/uploader.js +15 -3
  69. package/esm/plugins/backspace/cases/check-join-neighbors.js +36 -7
  70. package/esm/plugins/backspace/cases/check-remove-empty-parent.js +3 -1
  71. package/esm/plugins/bold/bold.js +4 -1
  72. package/esm/plugins/delete/delete.d.ts +12 -0
  73. package/esm/plugins/delete/delete.js +50 -1
  74. package/esm/plugins/resize-cells/resize-cells.d.ts +25 -1
  75. package/esm/plugins/resize-cells/resize-cells.js +84 -15
  76. package/esm/plugins/select/select.d.ts +35 -0
  77. package/esm/plugins/select/select.js +153 -1
  78. package/esm/plugins/select-cells/select-cells.d.ts +24 -0
  79. package/esm/plugins/select-cells/select-cells.js +81 -18
  80. package/esm/types/style.d.ts +5 -0
  81. package/esm/types/uploader.d.ts +117 -11
  82. package/package.json +2 -2
  83. package/types/core/constants.d.ts +1 -0
  84. package/types/core/helpers/utils/error/error.d.ts +1 -0
  85. package/types/core/helpers/utils/error/errors/answer-error.d.ts +13 -0
  86. package/types/core/helpers/utils/error/errors/index.d.ts +1 -0
  87. package/types/core/request/ajax.d.ts +1 -0
  88. package/types/modules/uploader/helpers/send-files.d.ts +2 -2
  89. package/types/modules/uploader/helpers/upload-error.d.ts +15 -0
  90. package/types/plugins/delete/delete.d.ts +12 -0
  91. package/types/plugins/resize-cells/resize-cells.d.ts +25 -1
  92. package/types/plugins/select/select.d.ts +35 -0
  93. package/types/plugins/select-cells/select-cells.d.ts +24 -0
  94. package/types/types/style.d.ts +5 -0
  95. package/types/types/uploader.d.ts +117 -11
@@ -10,6 +10,7 @@ import type { CanPromise, IDictionary, IViewComponent } from "./types";
10
10
  import type { IViewBased } from "./view";
11
11
  import type { IAjax } from "./ajax";
12
12
  interface IUploaderData {
13
+ code?: number;
13
14
  messages?: string[];
14
15
  files: string[];
15
16
  isImages?: boolean[];
@@ -29,6 +30,23 @@ interface IUploaderAnswer {
29
30
  data: IUploaderData;
30
31
  }
31
32
  export type HandlerSuccess = (resp: IUploaderData) => void;
33
+ /**
34
+ * Error the handler gets when the connector refused an upload: the answer,
35
+ * its `code`, the sent `files` and `retry` to send them again, changed
36
+ */
37
+ export interface IUploadError extends Error {
38
+ code?: number;
39
+ answer: IUploaderAnswer;
40
+ files: File[];
41
+ retry(plan?: Partial<IUploadPlan>): Promise<unknown>;
42
+ }
43
+ /**
44
+ * What `beforeUpload` decided: the files to send and extra fields of the request
45
+ */
46
+ export interface IUploadPlan {
47
+ files: File[];
48
+ data?: IDictionary<string>;
49
+ }
32
50
  export type HandlerError = (e: Error) => void;
33
51
  export type BuildDataResult = FormData | IDictionary<string> | Promise<FormData | IDictionary<string>> | string;
34
52
  export interface IUploaderOptions<T> {
@@ -103,28 +121,56 @@ export interface IUploaderOptions<T> {
103
121
  pathVariableName: string;
104
122
  withCredentials: boolean;
105
123
  /**
106
- * Called with the list of files right before they are uploaded (or read as
107
- * base64). Return `false` to abort the whole upload — useful for client
108
- * side validation (size, type, count). Throwing an Error also aborts and
109
- * routes the message through the uploader error handler.
124
+ * Called with the files right before they are sent (or read as base64).
125
+ * What it returns decides what happens:
126
+ *
127
+ * - `false` cancels the upload, the error handler gets `Upload canceled`
128
+ * - `undefined` (or `true`) sends the files as they are
129
+ * - an array of `File` sends those files instead, so files can be renamed
130
+ * with `new File([file], 'other.png', { type: file.type })` or left out
131
+ * - an object `{ files, data }` ({@link IUploadPlan}) sends those files
132
+ * and adds the fields of `data` to the request
133
+ * - a promise of any of the above is awaited, so the user can be asked first
134
+ *
135
+ * Throwing an error cancels the upload and routes the message through
136
+ * the error handler.
137
+ *
138
+ * Client-side validation (size, type, count):
110
139
  *
111
140
  * ```javascript
112
141
  * Jodit.make('#editor', {
113
142
  * uploader: {
114
- * url: '...',
143
+ * url: 'https://example.com/connector/?action=fileUpload',
115
144
  * beforeUpload(files) {
116
- * for (const file of files) {
117
- * if (file.size > 2 * 1024 * 1024) {
118
- * this.jodit.message.error('Max 2MB');
119
- * return false;
120
- * }
145
+ * if (files.some(file => file.size > 2 * 1024 * 1024)) {
146
+ * this.j.message.error('Max 2MB');
147
+ * return false;
121
148
  * }
122
149
  * }
123
150
  * }
124
151
  * });
125
152
  * ```
153
+ *
154
+ * Ask the user, say for a target folder the connector takes as a field:
155
+ *
156
+ * ```javascript
157
+ * Jodit.make('#editor', {
158
+ * uploader: {
159
+ * url: 'https://example.com/connector/?action=fileUpload',
160
+ * beforeUpload(files) {
161
+ * return new Promise(resolve =>
162
+ * this.j.prompt('Folder', 'Upload to', folder =>
163
+ * resolve({ files, data: { path: folder } })
164
+ * )
165
+ * );
166
+ * }
167
+ * }
168
+ * });
169
+ * ```
170
+ *
171
+ * A name that is already taken is not this hook's job: see `promptOnExists`.
126
172
  */
127
- beforeUpload?: (this: T, files: File[]) => boolean | void;
173
+ beforeUpload?: (this: T, files: File[]) => CanPromise<boolean | void | File[] | IUploadPlan>;
128
174
  prepareData: (this: T, formData: FormData) => any;
129
175
  buildData?: (this: T, formData: any) => BuildDataResult;
130
176
  queryBuild?: (obj: string | IDictionary<string | object> | FormData, prefix?: string) => string | FormData;
@@ -133,7 +179,67 @@ export interface IUploaderOptions<T> {
133
179
  process: (this: T, resp: IUploaderAnswer) => IUploaderData;
134
180
  error: (this: T, e: Error) => void;
135
181
  defaultHandlerSuccess: HandlerSuccess;
182
+ /**
183
+ * Shows a failed upload. When the connector refused it, the error is an
184
+ * {@link IUploadError}: `message` is the connector's text (`getMessage`),
185
+ * `answer` the whole answer, `code` its `data.code`, `files` the files
186
+ * that were sent and `retry(plan)` sends them again with other files or
187
+ * extra request fields, without running `beforeUpload` a second time.
188
+ *
189
+ * Connectors answer `409` when an uploaded name is already taken and
190
+ * `saveSameFileNameStrategy` is `error` (jodit-nodejs 2.1.1, PHP 3.0.61,
191
+ * jodit-python). With `promptOnExists` off, ask the user here:
192
+ *
193
+ * ```javascript
194
+ * Jodit.make('#editor', {
195
+ * uploader: {
196
+ * url: 'https://example.com/connector/?action=fileUpload',
197
+ * promptOnExists: false,
198
+ * defaultHandlerError(e) {
199
+ * if (e.code === 409) {
200
+ * this.j.confirm('Replace?', yes => yes && e.retry({ data: { onExists: 'replace' } }));
201
+ * return;
202
+ * }
203
+ *
204
+ * this.j.message.error(e.message);
205
+ * }
206
+ * }
207
+ * });
208
+ * ```
209
+ *
210
+ * Or keep both files under another name:
211
+ *
212
+ * ```javascript
213
+ * e.retry({
214
+ * files: e.files.map(file => new File([file], 'copy-' + file.name, { type: file.type }))
215
+ * });
216
+ * ```
217
+ */
136
218
  defaultHandlerError: HandlerError;
219
+ /**
220
+ * When the connector answers `409` (the name is already taken), ask the
221
+ * user for another name in a prompt and send the file again under it,
222
+ * before the error handler gets a say: this is part of the upload, not a
223
+ * failure. The prompt comes with `promptOnExistsSuggestName(name)` filled
224
+ * in; Cancel drops the file. A refused batch (the connector stores nothing
225
+ * and does not say which name is taken) is sent again one file at a time,
226
+ * so the free ones are stored and only the taken ones ask.
227
+ *
228
+ * ```javascript
229
+ * Jodit.make('#editor', {
230
+ * uploader: {
231
+ * url: 'https://example.com/connector/?action=fileUpload',
232
+ * promptOnExists: true,
233
+ * promptOnExistsSuggestName: name => name.replace(/(\.\w+)?$/, '-copy$1')
234
+ * }
235
+ * });
236
+ * ```
237
+ */
238
+ promptOnExists: boolean;
239
+ /**
240
+ * The name the `promptOnExists` prompt offers for a taken name. Default: the same name
241
+ */
242
+ promptOnExistsSuggestName: (this: T, name: string) => string;
137
243
  contentType: (this: T, requestData: any) => string | false;
138
244
  /**
139
245
  * This method can be used to replace the function of uploading files