jodit 4.2.21 → 4.2.24

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 (70) hide show
  1. package/CHANGELOG.md +9 -5
  2. package/es2015/jodit.css +1 -1
  3. package/es2015/jodit.fat.min.css +1 -1
  4. package/es2015/jodit.fat.min.js +2 -2
  5. package/es2015/jodit.js +2 -2
  6. package/es2015/jodit.min.js +2 -2
  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 +3 -2
  10. package/es2015/plugins/speech-recognize/speech-recognize.js +125 -95
  11. package/es2015/plugins/speech-recognize/speech-recognize.min.css +1 -1
  12. package/es2015/plugins/speech-recognize/speech-recognize.min.js +2 -2
  13. package/es2018/jodit.css +1 -1
  14. package/es2018/jodit.fat.min.css +1 -1
  15. package/es2018/jodit.fat.min.js +2 -2
  16. package/es2018/jodit.js +2 -2
  17. package/es2018/jodit.min.js +2 -2
  18. package/es2018/plugins/debug/debug.js +1 -1
  19. package/es2018/plugins/debug/debug.min.js +1 -1
  20. package/es2018/plugins/speech-recognize/speech-recognize.css +3 -2
  21. package/es2018/plugins/speech-recognize/speech-recognize.js +125 -95
  22. package/es2018/plugins/speech-recognize/speech-recognize.min.css +1 -1
  23. package/es2018/plugins/speech-recognize/speech-recognize.min.js +2 -2
  24. package/es2021/jodit.css +1 -1
  25. package/es2021/jodit.fat.min.css +1 -1
  26. package/es2021/jodit.fat.min.js +2 -2
  27. package/es2021/jodit.js +2 -2
  28. package/es2021/jodit.min.js +2 -2
  29. package/es2021/plugins/debug/debug.js +1 -1
  30. package/es2021/plugins/debug/debug.min.js +1 -1
  31. package/es2021/plugins/speech-recognize/speech-recognize.css +3 -2
  32. package/es2021/plugins/speech-recognize/speech-recognize.js +124 -95
  33. package/es2021/plugins/speech-recognize/speech-recognize.min.css +1 -1
  34. package/es2021/plugins/speech-recognize/speech-recognize.min.js +2 -2
  35. package/es2021.en/jodit.css +1 -1
  36. package/es2021.en/jodit.fat.min.css +1 -1
  37. package/es2021.en/jodit.fat.min.js +2 -2
  38. package/es2021.en/jodit.js +2 -2
  39. package/es2021.en/jodit.min.js +2 -2
  40. package/es2021.en/plugins/debug/debug.js +1 -1
  41. package/es2021.en/plugins/debug/debug.min.js +1 -1
  42. package/es2021.en/plugins/speech-recognize/speech-recognize.css +3 -2
  43. package/es2021.en/plugins/speech-recognize/speech-recognize.js +124 -95
  44. package/es2021.en/plugins/speech-recognize/speech-recognize.min.css +1 -1
  45. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +2 -2
  46. package/es5/jodit.css +2 -2
  47. package/es5/jodit.fat.min.css +1 -1
  48. package/es5/jodit.fat.min.js +2 -2
  49. package/es5/jodit.js +2 -2
  50. package/es5/jodit.min.css +2 -2
  51. package/es5/jodit.min.js +2 -2
  52. package/es5/plugins/debug/debug.js +1 -1
  53. package/es5/plugins/debug/debug.min.js +1 -1
  54. package/es5/plugins/speech-recognize/speech-recognize.css +3 -2
  55. package/es5/plugins/speech-recognize/speech-recognize.js +126 -97
  56. package/es5/plugins/speech-recognize/speech-recognize.min.css +1 -1
  57. package/es5/plugins/speech-recognize/speech-recognize.min.js +2 -2
  58. package/esm/core/constants.js +1 -1
  59. package/esm/plugins/speech-recognize/config.d.ts +1 -1
  60. package/esm/plugins/speech-recognize/config.js +18 -6
  61. package/esm/plugins/speech-recognize/helpers/recognize-manager.d.ts +3 -2
  62. package/esm/plugins/speech-recognize/helpers/recognize-manager.js +47 -31
  63. package/esm/plugins/speech-recognize/interface.d.ts +2 -0
  64. package/esm/plugins/speech-recognize/speech-recognize.d.ts +5 -1
  65. package/esm/plugins/speech-recognize/speech-recognize.js +17 -17
  66. package/package.json +1 -1
  67. package/types/plugins/speech-recognize/config.d.ts +1 -1
  68. package/types/plugins/speech-recognize/helpers/recognize-manager.d.ts +3 -2
  69. package/types/plugins/speech-recognize/interface.d.ts +2 -0
  70. package/types/plugins/speech-recognize/speech-recognize.d.ts +5 -1
@@ -60,7 +60,7 @@ let RecognizeManager = RecognizeManager_1 = class RecognizeManager extends Event
60
60
  }, 5000);
61
61
  this.emit('pulse', true);
62
62
  };
63
- this._progressTimeout = 0;
63
+ this.__interimResults = '';
64
64
  this._api = api;
65
65
  RecognizeManager_1._instances.add(this);
66
66
  }
@@ -82,23 +82,29 @@ let RecognizeManager = RecognizeManager_1 = class RecognizeManager extends Event
82
82
  instance.stop();
83
83
  }
84
84
  });
85
- this._api.start();
85
+ try {
86
+ this._api.start();
87
+ }
88
+ catch (e) {
89
+ this._onError(e);
90
+ this.stop();
91
+ return;
92
+ }
86
93
  this.__on('speechstart', this._onSpeechStart)
87
94
  .__on('error', this._onError)
88
- .__on('result', this._onResult);
95
+ .__on('result', this._onProgress)
96
+ .__on('end', this._onResults);
89
97
  }
90
98
  stop() {
91
99
  if (!this._isEnabled) {
92
100
  return;
93
101
  }
94
- try {
95
- this._api.abort();
96
- this._api.stop();
97
- }
98
- catch { }
102
+ this._api.abort();
103
+ this._api.stop();
99
104
  this.__off('speechstart', this._onSpeechStart)
100
105
  .__off('error', this._onError)
101
- .__off('result', this._onResult);
106
+ .__off('result', this._onProgress)
107
+ .__off('end', this._onResults);
102
108
  this.async.clearTimeout(this._restartTimeout);
103
109
  this._isEnabled = false;
104
110
  this.emit('pulse', false);
@@ -123,37 +129,47 @@ let RecognizeManager = RecognizeManager_1 = class RecognizeManager extends Event
123
129
  this._api.removeEventListener(event, callback);
124
130
  return this;
125
131
  }
126
- _onResult(e) {
132
+ _onResults(e) {
133
+ this.emit('pulse', false);
134
+ this.emit('result', this.__interimResults);
135
+ this.__interimResults = '';
136
+ this._makeSound(PII);
137
+ this.restart();
138
+ }
139
+ _onProgress(e) {
127
140
  if (!this._isEnabled) {
128
141
  return;
129
142
  }
130
- this.async.clearTimeout(this._progressTimeout);
131
- const resultItem = e.results.item(e.resultIndex);
132
- const { transcript } = resultItem.item(0);
133
- const resultHandler = () => {
134
- try {
135
- this.async.clearTimeout(this._restartTimeout);
136
- this.emit('result', transcript);
137
- }
138
- catch { }
139
- this.restart();
140
- this.emit('pulse', false);
141
- this._makeSound(PII);
142
- };
143
- if (resultItem.isFinal === false) {
144
- this.emit('progress', transcript);
145
- this._progressTimeout = this.async.setTimeout(resultHandler, 500);
143
+ this.__interimResults = '';
144
+ if (!e.results) {
146
145
  return;
147
146
  }
148
- resultHandler();
147
+ for (let i = 0; i < e.results.length; i++) {
148
+ const resultItem = e.results.item(i);
149
+ if (resultItem.length) {
150
+ const { transcript } = resultItem.item(0);
151
+ this.__interimResults += transcript;
152
+ }
153
+ }
154
+ if (this.__interimResults) {
155
+ this.emit('progress', this.__interimResults);
156
+ }
149
157
  }
150
- _onError() {
151
- if (!this._isEnabled) {
152
- return;
158
+ _onError(e) {
159
+ if (e.error === 'voice-unavailable') {
160
+ this.emit('error', 'Voice unavailable');
161
+ }
162
+ if (e.error === 'not-allowed') {
163
+ this.emit('error', 'Not allowed');
164
+ }
165
+ if (e.error === 'language-unavailable' ||
166
+ // @ts-ignore
167
+ e.error === 'language-not-supported') {
168
+ this.emit('error', 'Language unavailable');
153
169
  }
154
170
  this._makeSound(WARN);
155
171
  this.emit('pulse', false);
156
- this.restart();
172
+ this.stop();
157
173
  }
158
174
  _makeSound(frequency) {
159
175
  if (this.sound) {
@@ -14,7 +14,9 @@ export interface ISpeechRecognizeResult {
14
14
  item(subIndex: number): {
15
15
  transcript: string;
16
16
  };
17
+ length: number;
17
18
  };
19
+ length: number;
18
20
  };
19
21
  }
20
22
  export interface ISpeechRecognize {
@@ -13,10 +13,14 @@ import { Plugin } from "../../core/plugin";
13
13
  import "./config";
14
14
 
15
15
  export declare class SpeechRecognizeNative extends Plugin implements IPlugin {
16
- constructor(j: IJodit);
16
+ buttons: {
17
+ group: string;
18
+ name: string;
19
+ }[];
17
20
  protected afterInit(jodit: IJodit): void;
18
21
  protected beforeDestruct(jodit: IJodit): void;
19
22
  private messagePopup;
23
+ private __hidePopupTimeout;
20
24
  protected onSpeechRecognizeProgressResult(text: string): void;
21
25
  protected onSpeechRecognizeResult(text: string): void;
22
26
  private _checkCommand;
@@ -13,7 +13,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
14
  return c > 3 && r && Object.defineProperty(target, key, r), r;
15
15
  };
16
- import { debounce } from "../../core/decorators/debounce/debounce.js";
17
16
  import { watch } from "../../core/decorators/watch/watch.js";
18
17
  import { Dom } from "../../core/dom/dom.js";
19
18
  import { extendLang } from "../../core/global.js";
@@ -24,15 +23,15 @@ import { Jodit } from "../../jodit.js";
24
23
  import { execSpellCommand } from "./helpers/exec-spell-command.js";
25
24
  import * as langs from "./langs/index.js";
26
25
  export class SpeechRecognizeNative extends Plugin {
27
- constructor(j) {
28
- super(j);
29
- this._commandToWord = {};
30
- if (j.o.speechRecognize.api) {
31
- j.registerButton({
26
+ constructor() {
27
+ super(...arguments);
28
+ this.buttons = [
29
+ {
32
30
  group: 'state',
33
31
  name: 'speechRecognize'
34
- });
35
- }
32
+ }
33
+ ];
34
+ this._commandToWord = {};
36
35
  }
37
36
  afterInit(jodit) {
38
37
  const { commands } = jodit.o.speechRecognize;
@@ -53,23 +52,25 @@ export class SpeechRecognizeNative extends Plugin {
53
52
  });
54
53
  }
55
54
  }
56
- beforeDestruct(jodit) { }
55
+ beforeDestruct(jodit) {
56
+ Dom.safeRemove(this.messagePopup);
57
+ }
57
58
  onSpeechRecognizeProgressResult(text) {
58
59
  if (!this.messagePopup) {
59
60
  this.messagePopup = this.j.create.div('jodit-speech-recognize__popup');
60
61
  }
61
62
  this.j.workplace.appendChild(this.messagePopup);
62
- this.j.async.setTimeout(() => {
63
+ this.j.async.clearTimeout(this.__hidePopupTimeout);
64
+ this.__hidePopupTimeout = this.j.async.setTimeout(() => {
63
65
  Dom.safeRemove(this.messagePopup);
64
- }, {
65
- label: 'onSpeechRecognizeProgressResult',
66
- timeout: 1000
67
- });
66
+ }, 1000);
68
67
  this.messagePopup.innerText = text + '|';
69
68
  }
70
69
  onSpeechRecognizeResult(text) {
71
- const { j } = this, { s } = j;
70
+ this.j.async.clearTimeout(this.__hidePopupTimeout);
72
71
  Dom.safeRemove(this.messagePopup);
72
+ const { j } = this;
73
+ const { s } = j;
73
74
  if (!this._checkCommand(text)) {
74
75
  const { range } = s, node = s.current();
75
76
  if (s.isCollapsed() &&
@@ -100,8 +101,7 @@ export class SpeechRecognizeNative extends Plugin {
100
101
  }
101
102
  }
102
103
  __decorate([
103
- watch(':speechRecognizeProgressResult'),
104
- debounce()
104
+ watch(':speechRecognizeProgressResult')
105
105
  ], SpeechRecognizeNative.prototype, "onSpeechRecognizeProgressResult", null);
106
106
  __decorate([
107
107
  watch(':speechRecognizeResult')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jodit",
3
- "version": "4.2.21",
3
+ "version": "4.2.24",
4
4
  "description": "Jodit is an awesome and useful wysiwyg editor with filebrowser",
5
5
  "main": "esm/index.js",
6
6
  "types": "types/index.d.ts",
@@ -11,7 +11,7 @@ import type { ISpeechRecognizeConstructor } from "./interface";
11
11
  declare module 'jodit/config' {
12
12
  interface Config {
13
13
  speechRecognize: {
14
- readonly api: ISpeechRecognizeConstructor;
14
+ readonly api: ISpeechRecognizeConstructor | null;
15
15
  /**
16
16
  * Returns and sets the language of the current SpeechRecognition.
17
17
  * If not specified, this defaults to the HTML lang attribute value, or
@@ -41,8 +41,9 @@ export declare class RecognizeManager extends Eventify<{
41
41
  private readonly _api;
42
42
  private __on;
43
43
  private __off;
44
- private _progressTimeout;
45
- private _onResult;
44
+ private _onResults;
45
+ private __interimResults;
46
+ private _onProgress;
46
47
  private _onError;
47
48
  private _makeSound;
48
49
  }
@@ -14,7 +14,9 @@ export interface ISpeechRecognizeResult {
14
14
  item(subIndex: number): {
15
15
  transcript: string;
16
16
  };
17
+ length: number;
17
18
  };
19
+ length: number;
18
20
  };
19
21
  }
20
22
  export interface ISpeechRecognize {
@@ -13,10 +13,14 @@ import { Plugin } from "../../core/plugin";
13
13
  import "./config";
14
14
 
15
15
  export declare class SpeechRecognizeNative extends Plugin implements IPlugin {
16
- constructor(j: IJodit);
16
+ buttons: {
17
+ group: string;
18
+ name: string;
19
+ }[];
17
20
  protected afterInit(jodit: IJodit): void;
18
21
  protected beforeDestruct(jodit: IJodit): void;
19
22
  private messagePopup;
23
+ private __hidePopupTimeout;
20
24
  protected onSpeechRecognizeProgressResult(text: string): void;
21
25
  protected onSpeechRecognizeResult(text: string): void;
22
26
  private _checkCommand;