easy-richtextarea 4.0.199 → 4.0.201

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.
@@ -5,65 +5,105 @@ import { Element, document, eventTypes } from "easy";
5
5
  import Selection from "./selection"
6
6
  import customEventMixins from "./mixins/customEvent";
7
7
 
8
- import { BLUR_CUSTOM_EVENT_TYPE, FOCUS_CUSTOM_EVENT_TYPE, SCROLL_CUSTOM_EVENT_TYPE, CHANGE_CUSTOM_EVENT_TYPE } from "./customEventTypes";
8
+ import { BLUR_CUSTOM_EVENT_TYPE,
9
+ FOCUS_CUSTOM_EVENT_TYPE,
10
+ SCROLL_CUSTOM_EVENT_TYPE,
11
+ CHANGE_CUSTOM_EVENT_TYPE,
12
+ ACTIVATE_CUSTOM_EVENT_TYPE,
13
+ DEACTIVATE_CUSTOM_EVENT_TYPE } from "./customEventTypes";
9
14
 
10
- const { BLUR_EVENT_TYPE,
11
- FOCUS_EVENT_TYPE,
12
- INPUT_EVENT_TYPE,
13
- SCROLL_EVENT_TYPE,
14
- SELECTIONCHANGE_EVENT_TYPE } = eventTypes;
15
+ const { BLUR_EVENT_TYPE, FOCUS_EVENT_TYPE, INPUT_EVENT_TYPE, SCROLL_EVENT_TYPE } = eventTypes;
15
16
 
16
17
  export default class RichTextarea extends Element {
17
18
  blurHandler = (event, element) => {
19
+ const active = this.isActive();
20
+
21
+ if (!active) {
22
+ return;
23
+ }
24
+
18
25
  const customEventType = BLUR_CUSTOM_EVENT_TYPE,
19
- selectionChanged = true;
26
+ forced = true;
20
27
 
21
- this.customHandler(customEventType, event, element, selectionChanged);
28
+ this.customHandler(customEventType, event, element, forced);
22
29
  }
23
30
 
24
31
  focusHandler = (event, element) => {
25
32
  defer(() => {
33
+ const active = this.isActive();
34
+
35
+ if (!active) {
36
+ this.addClass("active");
37
+
38
+ const customEventType = ACTIVATE_CUSTOM_EVENT_TYPE,
39
+ event = null,
40
+ element = this,
41
+ forced = true;
42
+
43
+ this.customHandler(customEventType, event, element, forced);
44
+ }
45
+
26
46
  const customEventType = FOCUS_CUSTOM_EVENT_TYPE,
27
- selectionChanged = true;
47
+ forced = true;
28
48
 
29
- this.customHandler(customEventType, event, element, selectionChanged);
49
+ this.customHandler(customEventType, event, element, forced);
30
50
  });
31
51
  }
32
52
 
33
53
  inputHandler = (event, element) => {
34
- const customEventType = CHANGE_CUSTOM_EVENT_TYPE,
35
- selectionChanged = this.hasSelectionChanged();
54
+ const active = this.isActive();
36
55
 
37
- this.customHandler(customEventType, event, element, selectionChanged);
56
+ if (!active) {
57
+ return;
58
+ }
59
+
60
+ const customEventType = CHANGE_CUSTOM_EVENT_TYPE;
61
+
62
+ this.customHandler(customEventType, event, element);
38
63
  }
39
64
 
40
65
  scrollHandler = (event, element) => {
41
- const customEventType = SCROLL_CUSTOM_EVENT_TYPE;
66
+ const active = this.isActive();
67
+
68
+ if (!active) {
69
+ return;
70
+ }
71
+
72
+ const customEventType = SCROLL_CUSTOM_EVENT_TYPE,
73
+ forced = true;
42
74
 
43
- this.callCustomHandlers(customEventType, event, element);
75
+ this.customHandler(customEventType, event, element, forced);
44
76
  }
45
77
 
46
- selectChangeHandler = (event, element) => {
78
+ selectionChangeHandler = (event, element) => {
79
+ const active = this.isActive();
80
+
81
+ if (!active) {
82
+ return;
83
+ }
84
+
47
85
  const { currentTarget } = event,
48
86
  { activeElement } = currentTarget,
49
87
  domElement = this.getDOMElement();
50
88
 
51
- if (activeElement === domElement) {
52
- element = this; ///
89
+ if (activeElement !== domElement) {
90
+ return;
91
+ }
53
92
 
54
- const customEventType = CHANGE_CUSTOM_EVENT_TYPE,
55
- selectionChanged = this.hasSelectionChanged();
93
+ element = this; ///
56
94
 
57
- this.customHandler(customEventType, event, element, selectionChanged);
58
- }
95
+ const customEventType = CHANGE_CUSTOM_EVENT_TYPE;
96
+
97
+ this.customHandler(customEventType, event, element);
59
98
  }
60
99
 
61
- customHandler = (customEventType, event, element, selectionChanged) => {
100
+ customHandler = (customEventType, event, element, forced = false) => {
62
101
  const content = this.getContent(),
63
102
  selection = this.getSelection(),
64
- contentChanged = this.hasContentChanged();
103
+ contentChanged = this.hasContentChanged(),
104
+ selectionChanged = this.hasSelectionChanged();
65
105
 
66
- if (contentChanged || selectionChanged) {
106
+ if (forced || contentChanged || selectionChanged) {
67
107
  this.callCustomHandlers(customEventType, event, element);
68
108
  }
69
109
 
@@ -161,31 +201,30 @@ export default class RichTextarea extends Element {
161
201
  }
162
202
 
163
203
  activate() {
164
- this.onEvent(BLUR_EVENT_TYPE, this.blurHandler);
165
-
166
- this.onEvent(FOCUS_EVENT_TYPE, this.focusHandler);
167
-
168
- this.onEvent(INPUT_EVENT_TYPE, this.inputHandler);
169
-
170
- this.onEvent(SCROLL_EVENT_TYPE, this.scrollHandler);
204
+ const active = this.isActive();
171
205
 
172
- document.onEvent(SELECTIONCHANGE_EVENT_TYPE, this.selectChangeHandler);
206
+ if (active) {
207
+ return;
208
+ }
173
209
 
174
- this.addClass("active");
210
+ this.focus();
175
211
  }
176
212
 
177
213
  deactivate() {
178
- this.offEvent(BLUR_EVENT_TYPE, this.blurHandler);
179
-
180
- this.offEvent(FOCUS_EVENT_TYPE, this.focusHandler);
214
+ const active = this.isActive();
181
215
 
182
- this.offEvent(INPUT_EVENT_TYPE, this.inputHandler);
216
+ if (!active) {
217
+ return;
218
+ }
183
219
 
184
- this.offEvent(SCROLL_EVENT_TYPE, this.scrollHandler);
220
+ this.removeClass("active");
185
221
 
186
- document.offEvent(SELECTIONCHANGE_EVENT_TYPE, this.selectChangeHandler);
222
+ const customEventType = DEACTIVATE_CUSTOM_EVENT_TYPE,
223
+ event = null,
224
+ element = this,
225
+ forced = true;
187
226
 
188
- this.removeClass("active");
227
+ this.customHandler(customEventType, event, element, forced);
189
228
  }
190
229
 
191
230
  getPreviousContent() {
@@ -212,6 +251,16 @@ export default class RichTextarea extends Element {
212
251
  });
213
252
  }
214
253
 
254
+ setInitialState() {
255
+ const previousContent = null,
256
+ previousSelection = null;
257
+
258
+ this.setState({
259
+ previousContent,
260
+ previousSelection
261
+ });
262
+ }
263
+
215
264
  didMount() {
216
265
  const content = this.getContent(),
217
266
  selection = this.getSelection(),
@@ -221,24 +270,28 @@ export default class RichTextarea extends Element {
221
270
  this.setPreviousContent(previousContent);
222
271
 
223
272
  this.setPreviousSelection(previousSelection);
273
+
274
+ this.onEvent(BLUR_EVENT_TYPE, this.blurHandler);
275
+
276
+ this.onEvent(FOCUS_EVENT_TYPE, this.focusHandler);
277
+
278
+ this.onEvent(INPUT_EVENT_TYPE, this.inputHandler);
279
+
280
+ this.onEvent(SCROLL_EVENT_TYPE, this.scrollHandler);
281
+
282
+ document.onSelectionChange(this.selectionChangeHandler, this);
224
283
  }
225
284
 
226
285
  willUnmount() {
227
- const active = this.isActive();
286
+ this.offEvent(BLUR_EVENT_TYPE, this.blurHandler);
228
287
 
229
- if (active) {
230
- this.deactivate();
231
- }
232
- }
288
+ this.offEvent(FOCUS_EVENT_TYPE, this.focusHandler);
233
289
 
234
- setInitialState() {
235
- const previousContent = null,
236
- previousSelection = null;
290
+ this.offEvent(INPUT_EVENT_TYPE, this.inputHandler);
237
291
 
238
- this.setState({
239
- previousContent,
240
- previousSelection
241
- });
292
+ this.offEvent(SCROLL_EVENT_TYPE, this.scrollHandler);
293
+
294
+ document.offSelectionChange(this.selectionChangeHandler, this);
242
295
  }
243
296
 
244
297
  initialise() {
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return _default;
9
- }
10
- });
11
- var _easywithstyle = /*#__PURE__*/ _interop_require_default(require("easy-with-style"));
12
- var _index = require("../index");
13
- function _interop_require_default(obj) {
14
- return obj && obj.__esModule ? obj : {
15
- default: obj
16
- };
17
- }
18
- function _tagged_template_literal(strings, raw) {
19
- if (!raw) {
20
- raw = strings.slice(0);
21
- }
22
- return Object.freeze(Object.defineProperties(strings, {
23
- raw: {
24
- value: Object.freeze(raw)
25
- }
26
- }));
27
- }
28
- function _templateObject() {
29
- var data = _tagged_template_literal([
30
- "\n\n width: 48rem;\n border: solid 1px black;\n resize: none;\n height: 32rem;\n padding: 0.25rem;\n font-family: monospace;\n\n"
31
- ]);
32
- _templateObject = function _templateObject() {
33
- return data;
34
- };
35
- return data;
36
- }
37
- var _default = (0, _easywithstyle.default)(_index.RichTextarea)(_templateObject());
38
-
39
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9leGFtcGxlL3JpY2hUZXh0YXJlYS5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcblxuaW1wb3J0IHdpdGhTdHlsZSBmcm9tIFwiZWFzeS13aXRoLXN0eWxlXCI7XG5cbmltcG9ydCB7IFJpY2hUZXh0YXJlYSB9IGZyb20gXCIuLi9pbmRleFwiOyAgLy8vXG5cbmV4cG9ydCBkZWZhdWx0IHdpdGhTdHlsZShSaWNoVGV4dGFyZWEpYFxuXG4gIHdpZHRoOiA0OHJlbTtcbiAgYm9yZGVyOiBzb2xpZCAxcHggYmxhY2s7XG4gIHJlc2l6ZTogbm9uZTtcbiAgaGVpZ2h0OiAzMnJlbTtcbiAgcGFkZGluZzogMC4yNXJlbTtcbiAgZm9udC1mYW1pbHk6IG1vbm9zcGFjZTtcblxuYDtcbiJdLCJuYW1lcyI6WyJ3aXRoU3R5bGUiLCJSaWNoVGV4dGFyZWEiXSwibWFwcGluZ3MiOiJBQUFBOzs7OytCQU1BOzs7ZUFBQTs7O29FQUpzQjtxQkFFTzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztJQUU3QixXQUFlQSxJQUFBQSxzQkFBUyxFQUFDQyxtQkFBWSJ9