slate-angular 1.9.2 → 13.0.1

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 (64) hide show
  1. package/components/descendant/descendant.component.d.ts +2 -3
  2. package/{esm2015/components/block-card/block-card.component.js → esm2020/components/block-card/block-card.component.mjs} +5 -8
  3. package/{esm2015/components/children/children.component.js → esm2020/components/children/children.component.mjs} +3 -3
  4. package/esm2020/components/descendant/descendant.component.mjs +183 -0
  5. package/esm2020/components/editable/editable.component.mjs +1057 -0
  6. package/{esm2015/components/element/default-element.component.js → esm2020/components/element/default-element.component.mjs} +3 -3
  7. package/{esm2015/components/element/default-element.component.token.js → esm2020/components/element/default-element.component.token.mjs} +0 -0
  8. package/{esm2015/components/element/element.component.js → esm2020/components/element/element.component.mjs} +3 -3
  9. package/{esm2015/components/leaf/default-leaf.component.js → esm2020/components/leaf/default-leaf.component.mjs} +3 -3
  10. package/{esm2015/components/leaf/leaf.component.js → esm2020/components/leaf/leaf.component.mjs} +3 -3
  11. package/{esm2015/components/leaves/leaves.component.js → esm2020/components/leaves/leaves.component.mjs} +3 -3
  12. package/esm2020/components/string/string.component.mjs +73 -0
  13. package/esm2020/components/string/template.component.mjs +26 -0
  14. package/{esm2015/components/text/default-text.component.js → esm2020/components/text/default-text.component.mjs} +3 -3
  15. package/{esm2015/components/text/void-text.component.js → esm2020/components/text/void-text.component.mjs} +3 -3
  16. package/{esm2015/custom-event/BeforeInputEventPlugin.js → esm2020/custom-event/BeforeInputEventPlugin.mjs} +0 -0
  17. package/{esm2015/custom-event/DOMTopLevelEventTypes.js → esm2020/custom-event/DOMTopLevelEventTypes.mjs} +0 -0
  18. package/{esm2015/custom-event/FallbackCompositionState.js → esm2020/custom-event/FallbackCompositionState.mjs} +0 -0
  19. package/{esm2015/custom-event/before-input-polyfill.js → esm2020/custom-event/before-input-polyfill.mjs} +0 -0
  20. package/{esm2015/module.js → esm2020/module.mjs} +5 -6
  21. package/esm2020/plugins/angular-editor.mjs +565 -0
  22. package/{esm2015/plugins/with-angular.js → esm2020/plugins/with-angular.mjs} +0 -0
  23. package/{esm2015/public-api.js → esm2020/public-api.mjs} +0 -0
  24. package/{esm2015/slate-angular.js → esm2020/slate-angular.mjs} +0 -0
  25. package/{esm2015/types/error.js → esm2020/types/error.mjs} +0 -0
  26. package/{esm2015/types/feature.js → esm2020/types/feature.mjs} +0 -0
  27. package/{esm2015/types/index.js → esm2020/types/index.mjs} +1 -1
  28. package/{esm2015/types/view.js → esm2020/types/view.mjs} +0 -0
  29. package/esm2020/utils/block-card.mjs +25 -0
  30. package/{esm2015/utils/dom.js → esm2020/utils/dom.mjs} +0 -0
  31. package/esm2020/utils/environment.mjs +38 -0
  32. package/{esm2015/utils/global-normalize.js → esm2020/utils/global-normalize.mjs} +0 -0
  33. package/{esm2015/utils/hotkeys.js → esm2020/utils/hotkeys.mjs} +0 -0
  34. package/{esm2015/utils/index.js → esm2020/utils/index.mjs} +0 -0
  35. package/{esm2015/utils/key.js → esm2020/utils/key.mjs} +0 -0
  36. package/{esm2015/utils/lines.js → esm2020/utils/lines.mjs} +0 -0
  37. package/esm2020/utils/range-list.mjs +29 -0
  38. package/{esm2015/utils/view.js → esm2020/utils/view.mjs} +0 -0
  39. package/{esm2015/utils/weak-maps.js → esm2020/utils/weak-maps.mjs} +0 -0
  40. package/{esm2015/view/base.js → esm2020/view/base.mjs} +12 -12
  41. package/{esm2015/view/before-context-change.js → esm2020/view/before-context-change.mjs} +0 -0
  42. package/esm2020/view/container-item.mjs +102 -0
  43. package/{esm2015/view/container.js → esm2020/view/container.mjs} +3 -3
  44. package/{esm2015/view/context.js → esm2020/view/context.mjs} +0 -0
  45. package/fesm2015/{slate-angular.js → slate-angular.mjs} +84 -99
  46. package/fesm2015/slate-angular.mjs.map +1 -0
  47. package/fesm2020/slate-angular.mjs +3643 -0
  48. package/fesm2020/slate-angular.mjs.map +1 -0
  49. package/package.json +30 -6
  50. package/styles/index.scss +1 -1
  51. package/types/index.d.ts +1 -0
  52. package/view/container-item.d.ts +2 -3
  53. package/bundles/slate-angular.umd.js +0 -4296
  54. package/bundles/slate-angular.umd.js.map +0 -1
  55. package/esm2015/components/descendant/descendant.component.js +0 -179
  56. package/esm2015/components/editable/editable.component.js +0 -1063
  57. package/esm2015/components/string/string.component.js +0 -73
  58. package/esm2015/components/string/template.component.js +0 -30
  59. package/esm2015/plugins/angular-editor.js +0 -565
  60. package/esm2015/utils/block-card.js +0 -25
  61. package/esm2015/utils/environment.js +0 -36
  62. package/esm2015/utils/range-list.js +0 -30
  63. package/esm2015/view/container-item.js +0 -105
  64. package/fesm2015/slate-angular.js.map +0 -1
@@ -1,4296 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('slate'), require('is-hotkey'), require('@angular/core'), require('direction'), require('rxjs'), require('debug'), require('@angular/forms'), require('slate-history'), require('@angular/common')) :
3
- typeof define === 'function' && define.amd ? define('slate-angular', ['exports', 'slate', 'is-hotkey', '@angular/core', 'direction', 'rxjs', 'debug', '@angular/forms', 'slate-history', '@angular/common'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["slate-angular"] = {}, global.slate, global.isHotkey, global.ng.core, global.getDirection, global.rxjs, global.Debug, global.ng.forms, global.slateHistory, global.ng.common));
5
- })(this, (function (exports, slate, isHotkey, i0, getDirection, rxjs, Debug, forms, slateHistory, i2) { 'use strict';
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n["default"] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
- var getDirection__default = /*#__PURE__*/_interopDefaultLegacy(getDirection);
29
- var Debug__default = /*#__PURE__*/_interopDefaultLegacy(Debug);
30
- var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
31
-
32
- /*! *****************************************************************************
33
- Copyright (c) Microsoft Corporation.
34
-
35
- Permission to use, copy, modify, and/or distribute this software for any
36
- purpose with or without fee is hereby granted.
37
-
38
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
39
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
40
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
41
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
42
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
43
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
44
- PERFORMANCE OF THIS SOFTWARE.
45
- ***************************************************************************** */
46
- /* global Reflect, Promise */
47
- var extendStatics = function (d, b) {
48
- extendStatics = Object.setPrototypeOf ||
49
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
50
- function (d, b) { for (var p in b)
51
- if (Object.prototype.hasOwnProperty.call(b, p))
52
- d[p] = b[p]; };
53
- return extendStatics(d, b);
54
- };
55
- function __extends(d, b) {
56
- if (typeof b !== "function" && b !== null)
57
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
58
- extendStatics(d, b);
59
- function __() { this.constructor = d; }
60
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
61
- }
62
- var __assign = function () {
63
- __assign = Object.assign || function __assign(t) {
64
- for (var s, i = 1, n = arguments.length; i < n; i++) {
65
- s = arguments[i];
66
- for (var p in s)
67
- if (Object.prototype.hasOwnProperty.call(s, p))
68
- t[p] = s[p];
69
- }
70
- return t;
71
- };
72
- return __assign.apply(this, arguments);
73
- };
74
- function __rest(s, e) {
75
- var t = {};
76
- for (var p in s)
77
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
78
- t[p] = s[p];
79
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
80
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
81
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
82
- t[p[i]] = s[p[i]];
83
- }
84
- return t;
85
- }
86
- function __decorate(decorators, target, key, desc) {
87
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
88
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
89
- r = Reflect.decorate(decorators, target, key, desc);
90
- else
91
- for (var i = decorators.length - 1; i >= 0; i--)
92
- if (d = decorators[i])
93
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
94
- return c > 3 && r && Object.defineProperty(target, key, r), r;
95
- }
96
- function __param(paramIndex, decorator) {
97
- return function (target, key) { decorator(target, key, paramIndex); };
98
- }
99
- function __metadata(metadataKey, metadataValue) {
100
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
101
- return Reflect.metadata(metadataKey, metadataValue);
102
- }
103
- function __awaiter(thisArg, _arguments, P, generator) {
104
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
105
- return new (P || (P = Promise))(function (resolve, reject) {
106
- function fulfilled(value) { try {
107
- step(generator.next(value));
108
- }
109
- catch (e) {
110
- reject(e);
111
- } }
112
- function rejected(value) { try {
113
- step(generator["throw"](value));
114
- }
115
- catch (e) {
116
- reject(e);
117
- } }
118
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
119
- step((generator = generator.apply(thisArg, _arguments || [])).next());
120
- });
121
- }
122
- function __generator(thisArg, body) {
123
- var _ = { label: 0, sent: function () { if (t[0] & 1)
124
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
125
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
126
- function verb(n) { return function (v) { return step([n, v]); }; }
127
- function step(op) {
128
- if (f)
129
- throw new TypeError("Generator is already executing.");
130
- while (_)
131
- try {
132
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
133
- return t;
134
- if (y = 0, t)
135
- op = [op[0] & 2, t.value];
136
- switch (op[0]) {
137
- case 0:
138
- case 1:
139
- t = op;
140
- break;
141
- case 4:
142
- _.label++;
143
- return { value: op[1], done: false };
144
- case 5:
145
- _.label++;
146
- y = op[1];
147
- op = [0];
148
- continue;
149
- case 7:
150
- op = _.ops.pop();
151
- _.trys.pop();
152
- continue;
153
- default:
154
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
155
- _ = 0;
156
- continue;
157
- }
158
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
159
- _.label = op[1];
160
- break;
161
- }
162
- if (op[0] === 6 && _.label < t[1]) {
163
- _.label = t[1];
164
- t = op;
165
- break;
166
- }
167
- if (t && _.label < t[2]) {
168
- _.label = t[2];
169
- _.ops.push(op);
170
- break;
171
- }
172
- if (t[2])
173
- _.ops.pop();
174
- _.trys.pop();
175
- continue;
176
- }
177
- op = body.call(thisArg, _);
178
- }
179
- catch (e) {
180
- op = [6, e];
181
- y = 0;
182
- }
183
- finally {
184
- f = t = 0;
185
- }
186
- if (op[0] & 5)
187
- throw op[1];
188
- return { value: op[0] ? op[1] : void 0, done: true };
189
- }
190
- }
191
- var __createBinding = Object.create ? (function (o, m, k, k2) {
192
- if (k2 === undefined)
193
- k2 = k;
194
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
195
- }) : (function (o, m, k, k2) {
196
- if (k2 === undefined)
197
- k2 = k;
198
- o[k2] = m[k];
199
- });
200
- function __exportStar(m, o) {
201
- for (var p in m)
202
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
203
- __createBinding(o, m, p);
204
- }
205
- function __values(o) {
206
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
207
- if (m)
208
- return m.call(o);
209
- if (o && typeof o.length === "number")
210
- return {
211
- next: function () {
212
- if (o && i >= o.length)
213
- o = void 0;
214
- return { value: o && o[i++], done: !o };
215
- }
216
- };
217
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
218
- }
219
- function __read(o, n) {
220
- var m = typeof Symbol === "function" && o[Symbol.iterator];
221
- if (!m)
222
- return o;
223
- var i = m.call(o), r, ar = [], e;
224
- try {
225
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
226
- ar.push(r.value);
227
- }
228
- catch (error) {
229
- e = { error: error };
230
- }
231
- finally {
232
- try {
233
- if (r && !r.done && (m = i["return"]))
234
- m.call(i);
235
- }
236
- finally {
237
- if (e)
238
- throw e.error;
239
- }
240
- }
241
- return ar;
242
- }
243
- /** @deprecated */
244
- function __spread() {
245
- for (var ar = [], i = 0; i < arguments.length; i++)
246
- ar = ar.concat(__read(arguments[i]));
247
- return ar;
248
- }
249
- /** @deprecated */
250
- function __spreadArrays() {
251
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
252
- s += arguments[i].length;
253
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
254
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
255
- r[k] = a[j];
256
- return r;
257
- }
258
- function __spreadArray(to, from) {
259
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
260
- to[j] = from[i];
261
- return to;
262
- }
263
- function __await(v) {
264
- return this instanceof __await ? (this.v = v, this) : new __await(v);
265
- }
266
- function __asyncGenerator(thisArg, _arguments, generator) {
267
- if (!Symbol.asyncIterator)
268
- throw new TypeError("Symbol.asyncIterator is not defined.");
269
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
270
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
271
- function verb(n) { if (g[n])
272
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
273
- function resume(n, v) { try {
274
- step(g[n](v));
275
- }
276
- catch (e) {
277
- settle(q[0][3], e);
278
- } }
279
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
280
- function fulfill(value) { resume("next", value); }
281
- function reject(value) { resume("throw", value); }
282
- function settle(f, v) { if (f(v), q.shift(), q.length)
283
- resume(q[0][0], q[0][1]); }
284
- }
285
- function __asyncDelegator(o) {
286
- var i, p;
287
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
288
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
289
- }
290
- function __asyncValues(o) {
291
- if (!Symbol.asyncIterator)
292
- throw new TypeError("Symbol.asyncIterator is not defined.");
293
- var m = o[Symbol.asyncIterator], i;
294
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
295
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
296
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
297
- }
298
- function __makeTemplateObject(cooked, raw) {
299
- if (Object.defineProperty) {
300
- Object.defineProperty(cooked, "raw", { value: raw });
301
- }
302
- else {
303
- cooked.raw = raw;
304
- }
305
- return cooked;
306
- }
307
- ;
308
- var __setModuleDefault = Object.create ? (function (o, v) {
309
- Object.defineProperty(o, "default", { enumerable: true, value: v });
310
- }) : function (o, v) {
311
- o["default"] = v;
312
- };
313
- function __importStar(mod) {
314
- if (mod && mod.__esModule)
315
- return mod;
316
- var result = {};
317
- if (mod != null)
318
- for (var k in mod)
319
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
320
- __createBinding(result, mod, k);
321
- __setModuleDefault(result, mod);
322
- return result;
323
- }
324
- function __importDefault(mod) {
325
- return (mod && mod.__esModule) ? mod : { default: mod };
326
- }
327
- function __classPrivateFieldGet(receiver, state, kind, f) {
328
- if (kind === "a" && !f)
329
- throw new TypeError("Private accessor was defined without a getter");
330
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
331
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
332
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
333
- }
334
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
335
- if (kind === "m")
336
- throw new TypeError("Private method is not writable");
337
- if (kind === "a" && !f)
338
- throw new TypeError("Private accessor was defined without a setter");
339
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
340
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
341
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
342
- }
343
-
344
- /**
345
- * Two weak maps that allow us rebuild a path given a node. They are populated
346
- * at render time such that after a render occurs we can always backtrack.
347
- */
348
- var EDITOR_TO_WINDOW = new WeakMap();
349
- var NODE_TO_INDEX = new WeakMap();
350
- var NODE_TO_PARENT = new WeakMap();
351
- /**
352
- * Weak maps that allow us to go between Slate nodes and DOM nodes. These
353
- * are used to resolve DOM event-related logic into Slate actions.
354
- */
355
- var EDITOR_TO_ELEMENT = new WeakMap();
356
- var EDITOR_TO_PLACEHOLDER = new WeakMap();
357
- var ELEMENT_TO_NODE = new WeakMap();
358
- // Deprecated
359
- var KEY_TO_ELEMENT = new WeakMap();
360
- var NODE_TO_ELEMENT = new WeakMap();
361
- var NODE_TO_KEY = new WeakMap();
362
- /**
363
- * Weak maps for storing editor-related state.
364
- */
365
- var IS_READONLY = new WeakMap();
366
- var IS_FOCUSED = new WeakMap();
367
- var IS_DRAGGING = new WeakMap();
368
- var IS_CLICKING = new WeakMap();
369
- /**
370
- * Weak map for associating the context `onChange` context with the plugin.
371
- */
372
- var EDITOR_TO_ON_CHANGE = new WeakMap();
373
- // export const NODE_TO_VIEWNODE = new WeakMap<Node, ViewNode>();
374
- /**
375
- * Symbols.
376
- */
377
- var PLACEHOLDER_SYMBOL = Symbol('placeholder');
378
- /**
379
- * Weak map for associating the html element with the component.
380
- */
381
- var ELEMENT_TO_COMPONENT = new WeakMap();
382
-
383
- /**
384
- * Types.
385
- */
386
- // COMPAT: This is required to prevent TypeScript aliases from doing some very
387
- // weird things for Slate's types with the same name as globals. (2019/11/27)
388
- // https://github.com/microsoft/TypeScript/issues/35002
389
- var DOMNode = globalThis.Node;
390
- var DOMComment = globalThis.Comment;
391
- var DOMElement = globalThis.Element;
392
- var DOMText = globalThis.Text;
393
- var DOMRange = globalThis.Range;
394
- var DOMSelection = globalThis.Selection;
395
- var DOMStaticRange = globalThis.StaticRange;
396
- /**
397
- * Returns the host window of a DOM node
398
- */
399
- var getDefaultView = function (value) {
400
- return ((value && value.ownerDocument && value.ownerDocument.defaultView) || null);
401
- };
402
- /**
403
- * Check if a DOM node is a comment node.
404
- */
405
- var isDOMComment = function (value) {
406
- return isDOMNode(value) && value.nodeType === 8;
407
- };
408
- /**
409
- * Check if a DOM node is an element node.
410
- */
411
- var isDOMElement = function (value) {
412
- return isDOMNode(value) && value.nodeType === 1;
413
- };
414
- /**
415
- * Check if a value is a DOM node.
416
- */
417
- var isDOMNode = function (value) {
418
- var window = getDefaultView(value);
419
- return !!window && value instanceof window.Node;
420
- };
421
- /**
422
- * Check if a value is a DOM selection.
423
- */
424
- var isDOMSelection = function (value) {
425
- var window = value && value.anchorNode && getDefaultView(value.anchorNode);
426
- return !!window && value instanceof window.Selection;
427
- };
428
- /**
429
- * Check if a DOM node is an element node.
430
- */
431
- var isDOMText = function (value) {
432
- return isDOMNode(value) && value.nodeType === 3;
433
- };
434
- /**
435
- * Checks whether a paste event is a plaintext-only event.
436
- */
437
- var isPlainTextOnlyPaste = function (event) {
438
- return (event.clipboardData &&
439
- event.clipboardData.getData('text/plain') !== '' &&
440
- event.clipboardData.types.length === 1);
441
- };
442
- /**
443
- * Normalize a DOM point so that it always refers to a text node.
444
- */
445
- var normalizeDOMPoint = function (domPoint) {
446
- var _a;
447
- var _b = __read(domPoint, 2), node = _b[0], offset = _b[1];
448
- // If it's an element node, its offset refers to the index of its children
449
- // including comment nodes, so try to find the right text child node.
450
- if (isDOMElement(node) && node.childNodes.length) {
451
- var isLast = offset === node.childNodes.length;
452
- var index = isLast ? offset - 1 : offset;
453
- ;
454
- _a = __read(getEditableChildAndIndex(node, index, isLast ? 'backward' : 'forward'), 2), node = _a[0], index = _a[1];
455
- // If the editable child found is in front of input offset, we instead seek to its end
456
- isLast = index < offset;
457
- // If the node has children, traverse until we have a leaf node. Leaf nodes
458
- // can be either text nodes, or other void DOM nodes.
459
- while (isDOMElement(node) && node.childNodes.length) {
460
- var i = isLast ? node.childNodes.length - 1 : 0;
461
- node = getEditableChild(node, i, isLast ? 'backward' : 'forward');
462
- }
463
- // Determine the new offset inside the text node.
464
- offset =
465
- isLast && node.textContent != null ? node.textContent.length : 0;
466
- }
467
- // Return the node and offset.
468
- return [node, offset];
469
- };
470
- /**
471
- * Determines wether the active element is nested within a shadowRoot
472
- */
473
- var hasShadowRoot = function () {
474
- return !!(window.document.activeElement && window.document.activeElement.shadowRoot);
475
- };
476
- /**
477
- * Get the nearest editable child and index at `index` in a `parent`, preferring
478
- * `direction`.
479
- */
480
- var getEditableChildAndIndex = function (parent, index, direction) {
481
- var childNodes = parent.childNodes;
482
- var child = childNodes[index];
483
- var i = index;
484
- var triedForward = false;
485
- var triedBackward = false;
486
- // While the child is a comment node, or an element node with no children,
487
- // keep iterating to find a sibling non-void, non-comment node.
488
- while (isDOMComment(child) ||
489
- (isDOMElement(child) && child.childNodes.length === 0) ||
490
- (isDOMElement(child) && child.getAttribute('contenteditable') === 'false')) {
491
- if (triedForward && triedBackward) {
492
- break;
493
- }
494
- if (i >= childNodes.length) {
495
- triedForward = true;
496
- i = index - 1;
497
- direction = 'backward';
498
- continue;
499
- }
500
- if (i < 0) {
501
- triedBackward = true;
502
- i = index + 1;
503
- direction = 'forward';
504
- continue;
505
- }
506
- child = childNodes[i];
507
- index = i;
508
- i += direction === 'forward' ? 1 : -1;
509
- }
510
- return [child, index];
511
- };
512
- /**
513
- * Get the nearest editable child at `index` in a `parent`, preferring
514
- * `direction`.
515
- */
516
- var getEditableChild = function (parent, index, direction) {
517
- var _a = __read(getEditableChildAndIndex(parent, index, direction), 1), child = _a[0];
518
- return child;
519
- };
520
- /**
521
- * Get a plaintext representation of the content of a node, accounting for block
522
- * elements which get a newline appended.
523
- *
524
- * The domNode must be attached to the DOM.
525
- */
526
- var getPlainText = function (domNode) {
527
- var e_1, _a;
528
- var text = '';
529
- if (isDOMText(domNode) && domNode.nodeValue) {
530
- return domNode.nodeValue;
531
- }
532
- if (isDOMElement(domNode)) {
533
- try {
534
- for (var _b = __values(Array.from(domNode.childNodes)), _c = _b.next(); !_c.done; _c = _b.next()) {
535
- var childNode = _c.value;
536
- text += getPlainText(childNode);
537
- }
538
- }
539
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
540
- finally {
541
- try {
542
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
543
- }
544
- finally { if (e_1) throw e_1.error; }
545
- }
546
- var display = getComputedStyle(domNode).getPropertyValue('display');
547
- if (display === 'block' || display === 'list' || domNode.tagName === 'BR') {
548
- text += '\n';
549
- }
550
- }
551
- return text;
552
- };
553
- /**
554
- * Get x-slate-fragment attribute from data-slate-fragment
555
- */
556
- var catchSlateFragment = /data-slate-fragment="(.+?)"/m;
557
- var getSlateFragmentAttribute = function (dataTransfer) {
558
- var htmlData = dataTransfer.getData('text/html');
559
- var _a = __read(htmlData.match(catchSlateFragment) || [], 2), fragment = _a[1];
560
- return fragment;
561
- };
562
- /**
563
- * Get the x-slate-fragment attribute that exist in text/html data
564
- * and append it to the DataTransfer object
565
- */
566
- var getClipboardData = function (dataTransfer, clipboardFormatKey) {
567
- if (clipboardFormatKey === void 0) { clipboardFormatKey = 'x-slate-fragment'; }
568
- if (!dataTransfer.getData("application/" + clipboardFormatKey)) {
569
- var fragment = getSlateFragmentAttribute(dataTransfer);
570
- if (fragment) {
571
- var clipboardData_1 = new DataTransfer();
572
- dataTransfer.types.forEach(function (type) {
573
- clipboardData_1.setData(type, dataTransfer.getData(type));
574
- });
575
- clipboardData_1.setData("application/" + clipboardFormatKey, fragment);
576
- return clipboardData_1;
577
- }
578
- }
579
- return dataTransfer;
580
- };
581
-
582
- /**
583
- * An auto-incrementing identifier for keys.
584
- */
585
- var n = 0;
586
- /**
587
- * A class that keeps track of a key string. We use a full class here because we
588
- * want to be able to use them as keys in `WeakMap` objects.
589
- */
590
- var Key = /** @class */ (function () {
591
- function Key() {
592
- this.id = "" + n++;
593
- }
594
- return Key;
595
- }());
596
-
597
- var IS_IOS = typeof navigator !== 'undefined' &&
598
- typeof window !== 'undefined' &&
599
- /iPad|iPhone|iPod/.test(navigator.userAgent) &&
600
- !window.MSStream;
601
- var IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
602
- var IS_ANDROID = typeof navigator !== 'undefined' && /Android/.test(navigator.userAgent);
603
- var IS_FIREFOX = typeof navigator !== 'undefined' &&
604
- /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
605
- var IS_SAFARI = typeof navigator !== 'undefined' &&
606
- /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
607
- // "modern" Edge was released at 79.x
608
- var IS_EDGE_LEGACY = typeof navigator !== 'undefined' &&
609
- /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent);
610
- var IS_CHROME = typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent);
611
- // Native beforeInput events don't work well with react on Chrome 75 and older, Chrome 76+ can use beforeInput
612
- var IS_CHROME_LEGACY = typeof navigator !== 'undefined' &&
613
- /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent);
614
- // Firefox did not support `beforeInput` until `v87`.
615
- var IS_FIREFOX_LEGACY = typeof navigator !== 'undefined' &&
616
- /^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])).*/i.test(navigator.userAgent);
617
- // qq browser
618
- var IS_QQBROWSER = typeof navigator !== 'undefined' && /.*QQBrowser/.test(navigator.userAgent);
619
- // UC mobile browser
620
- var IS_UC_MOBILE = typeof navigator !== 'undefined' && /.*UCBrowser/.test(navigator.userAgent);
621
- // Wechat browser
622
- var IS_WECHATBROWSER = typeof navigator !== 'undefined' && /.*Wechat/.test(navigator.userAgent);
623
- // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
624
- // Chrome Legacy doesn't support `beforeinput` correctly
625
- var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY &&
626
- !IS_EDGE_LEGACY &&
627
- // globalThis is undefined in older browsers
628
- typeof globalThis !== 'undefined' &&
629
- globalThis.InputEvent &&
630
- // @ts-ignore The `getTargetRanges` property isn't recognized.
631
- typeof globalThis.InputEvent.prototype.getTargetRanges === 'function';
632
-
633
- var FAKE_LEFT_BLOCK_CARD_OFFSET = -1;
634
- var FAKE_RIGHT_BLOCK_CARD_OFFSET = -2;
635
- function hasBlockCardWithNode(node) {
636
- return node && (node.parentElement.hasAttribute('card-target') || (node instanceof HTMLElement && node.hasAttribute('card-target')));
637
- }
638
- function hasBlockCard(selection) {
639
- return hasBlockCardWithNode(selection === null || selection === void 0 ? void 0 : selection.anchorNode) || hasBlockCardWithNode(selection === null || selection === void 0 ? void 0 : selection.focusNode);
640
- }
641
- function getCardTargetAttribute(node) {
642
- return node.parentElement.attributes['card-target'] || (node instanceof HTMLElement && node.attributes['card-target']);
643
- }
644
- function isCardLeft(node) {
645
- var cardTarget = getCardTargetAttribute(node);
646
- return cardTarget && cardTarget.nodeValue === 'card-left';
647
- }
648
- function isCardLeftByTargetAttr(targetAttr) {
649
- return targetAttr && targetAttr.nodeValue === 'card-left';
650
- }
651
- function isCardRightByTargetAttr(targetAttr) {
652
- return targetAttr && targetAttr.nodeValue === 'card-right';
653
- }
654
- function isCardCenterByTargetAttr(targetAttr) {
655
- return targetAttr && targetAttr.nodeValue === 'card-center';
656
- }
657
-
658
- var AngularEditor = {
659
- /**
660
- * Return the host window of the current editor.
661
- */
662
- getWindow: function (editor) {
663
- var window = EDITOR_TO_WINDOW.get(editor);
664
- if (!window) {
665
- throw new Error('Unable to find a host window element for this editor');
666
- }
667
- return window;
668
- },
669
- /**
670
- * Find a key for a Slate node.
671
- */
672
- findKey: function (editor, node) {
673
- var key = NODE_TO_KEY.get(node);
674
- if (!key) {
675
- key = new Key();
676
- NODE_TO_KEY.set(node, key);
677
- }
678
- return key;
679
- },
680
- /**
681
- * handle editor error.
682
- */
683
- onError: function (errorData) {
684
- if (errorData.nativeError) {
685
- throw errorData.nativeError;
686
- }
687
- },
688
- /**
689
- * Find the path of Slate node.
690
- */
691
- findPath: function (editor, node) {
692
- var path = [];
693
- var child = node;
694
- while (true) {
695
- var parent = NODE_TO_PARENT.get(child);
696
- if (parent == null) {
697
- if (slate.Editor.isEditor(child)) {
698
- return path;
699
- }
700
- else {
701
- break;
702
- }
703
- }
704
- var i = NODE_TO_INDEX.get(child);
705
- if (i == null) {
706
- break;
707
- }
708
- path.unshift(i);
709
- child = parent;
710
- }
711
- throw new Error("Unable to find the path for Slate node: " + JSON.stringify(node));
712
- },
713
- /**
714
- * Find the DOM node that implements DocumentOrShadowRoot for the editor.
715
- */
716
- findDocumentOrShadowRoot: function (editor) {
717
- var el = AngularEditor.toDOMNode(editor, editor);
718
- var root = el.getRootNode();
719
- if ((root instanceof Document || root instanceof ShadowRoot) &&
720
- root.getSelection != null) {
721
- return root;
722
- }
723
- return el.ownerDocument;
724
- },
725
- /**
726
- * Check if the editor is focused.
727
- */
728
- isFocused: function (editor) {
729
- return !!IS_FOCUSED.get(editor);
730
- },
731
- /**
732
- * Check if the editor is in read-only mode.
733
- */
734
- isReadonly: function (editor) {
735
- return !!IS_READONLY.get(editor);
736
- },
737
- /**
738
- * Check if the editor is hanging right.
739
- */
740
- isBlockHangingRight: function (editor) {
741
- var selection = editor.selection;
742
- if (!selection) {
743
- return false;
744
- }
745
- if (slate.Range.isCollapsed(selection)) {
746
- return false;
747
- }
748
- var _b = __read(slate.Range.edges(selection), 2), start = _b[0], end = _b[1];
749
- var endBlock = slate.Editor.above(editor, { at: end, match: function (node) { return slate.Editor.isBlock(editor, node); } });
750
- return slate.Editor.isStart(editor, end, endBlock[1]);
751
- },
752
- /**
753
- * Blur the editor.
754
- */
755
- blur: function (editor) {
756
- var el = AngularEditor.toDOMNode(editor, editor);
757
- var root = AngularEditor.findDocumentOrShadowRoot(editor);
758
- IS_FOCUSED.set(editor, false);
759
- if (root.activeElement === el) {
760
- el.blur();
761
- }
762
- },
763
- /**
764
- * Focus the editor.
765
- */
766
- focus: function (editor) {
767
- var el = AngularEditor.toDOMNode(editor, editor);
768
- IS_FOCUSED.set(editor, true);
769
- var window = AngularEditor.getWindow(editor);
770
- if (window.document.activeElement !== el) {
771
- el.focus({ preventScroll: true });
772
- }
773
- },
774
- /**
775
- * Deselect the editor.
776
- */
777
- deselect: function (editor) {
778
- var selection = editor.selection;
779
- var root = AngularEditor.findDocumentOrShadowRoot(editor);
780
- var domSelection = root.getSelection();
781
- if (domSelection && domSelection.rangeCount > 0) {
782
- domSelection.removeAllRanges();
783
- }
784
- if (selection) {
785
- slate.Transforms.deselect(editor);
786
- }
787
- },
788
- /**
789
- * Check if a DOM node is within the editor.
790
- */
791
- hasDOMNode: function (editor, target, options) {
792
- if (options === void 0) { options = {}; }
793
- var _b = options.editable, editable = _b === void 0 ? false : _b;
794
- var editorEl = AngularEditor.toDOMNode(editor, editor);
795
- var targetEl;
796
- // COMPAT: In Firefox, reading `target.nodeType` will throw an error if
797
- // target is originating from an internal "restricted" element (e.g. a
798
- // stepper arrow on a number input). (2018/05/04)
799
- // https://github.com/ianstormtaylor/slate/issues/1819
800
- try {
801
- targetEl = (isDOMElement(target) ? target : target.parentElement);
802
- }
803
- catch (err) {
804
- if (!err.message.includes('Permission denied to access property "nodeType"')) {
805
- throw err;
806
- }
807
- }
808
- if (!targetEl) {
809
- return false;
810
- }
811
- return targetEl.closest("[data-slate-editor]") === editorEl &&
812
- (!editable || targetEl.isContentEditable ||
813
- !!targetEl.getAttribute('data-slate-zero-width'));
814
- },
815
- /**
816
- * Insert data from a `DataTransfer` into the editor.
817
- */
818
- insertData: function (editor, data) {
819
- editor.insertData(data);
820
- },
821
- /**
822
- * Insert fragment data from a `DataTransfer` into the editor.
823
- */
824
- insertFragmentData: function (editor, data) {
825
- return editor.insertFragmentData(data);
826
- },
827
- /**
828
- * Insert text data from a `DataTransfer` into the editor.
829
- */
830
- insertTextData: function (editor, data) {
831
- return editor.insertTextData(data);
832
- },
833
- /**
834
- * onKeydown hook.
835
- */
836
- onKeydown: function (editor, data) {
837
- editor.onKeydown(data);
838
- },
839
- /**
840
- * onClick hook.
841
- */
842
- onClick: function (editor, data) {
843
- editor.onClick(data);
844
- },
845
- /**
846
- * Sets data from the currently selected fragment on a `DataTransfer`.
847
- */
848
- setFragmentData: function (editor, data, originEvent) {
849
- editor.setFragmentData(data, originEvent);
850
- },
851
- deleteCutData: function (editor) {
852
- editor.deleteCutData();
853
- },
854
- /**
855
- * Find the native DOM element from a Slate node.
856
- */
857
- toDOMNode: function (editor, node) {
858
- var domNode = slate.Editor.isEditor(node)
859
- ? EDITOR_TO_ELEMENT.get(editor)
860
- : NODE_TO_ELEMENT.get(node);
861
- if (!domNode) {
862
- throw new Error("Cannot resolve a DOM node from Slate node: " + JSON.stringify(node));
863
- }
864
- return domNode;
865
- },
866
- /**
867
- * Find a native DOM selection point from a Slate point.
868
- */
869
- toDOMPoint: function (editor, point) {
870
- var e_1, _b;
871
- var _c = __read(slate.Editor.node(editor, point.path), 1), node = _c[0];
872
- var el = AngularEditor.toDOMNode(editor, node);
873
- var domPoint;
874
- // block card
875
- var cardTargetAttr = getCardTargetAttribute(el);
876
- if (cardTargetAttr) {
877
- if (point.offset === FAKE_LEFT_BLOCK_CARD_OFFSET) {
878
- var cursorNode = AngularEditor.getCardCursorNode(editor, node, { direction: 'left' });
879
- return [cursorNode, 1];
880
- }
881
- else {
882
- var cursorNode = AngularEditor.getCardCursorNode(editor, node, { direction: 'right' });
883
- return [cursorNode, 1];
884
- }
885
- }
886
- // If we're inside a void node, force the offset to 0, otherwise the zero
887
- // width spacing character will result in an incorrect offset of 1
888
- if (slate.Editor.void(editor, { at: point })) {
889
- point = { path: point.path, offset: 0 };
890
- }
891
- // For each leaf, we need to isolate its content, which means filtering
892
- // to its direct text and zero-width spans. (We have to filter out any
893
- // other siblings that may have been rendered alongside them.)
894
- var selector = "[data-slate-string], [data-slate-zero-width]";
895
- var texts = Array.from(el.querySelectorAll(selector));
896
- var start = 0;
897
- try {
898
- for (var texts_1 = __values(texts), texts_1_1 = texts_1.next(); !texts_1_1.done; texts_1_1 = texts_1.next()) {
899
- var text = texts_1_1.value;
900
- var domNode = text.childNodes[0];
901
- if (domNode == null || domNode.textContent == null) {
902
- continue;
903
- }
904
- var length = domNode.textContent.length;
905
- var attr = text.getAttribute('data-slate-length');
906
- var trueLength = attr == null ? length : parseInt(attr, 10);
907
- var end = start + trueLength;
908
- if (point.offset <= end) {
909
- var offset = Math.min(length, Math.max(0, point.offset - start));
910
- domPoint = [domNode, offset];
911
- // fixed cursor position after zero width char
912
- if (offset === 0 && length === 1 && domNode.textContent === '\uFEFF') {
913
- domPoint = [domNode, offset + 1];
914
- }
915
- break;
916
- }
917
- start = end;
918
- }
919
- }
920
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
921
- finally {
922
- try {
923
- if (texts_1_1 && !texts_1_1.done && (_b = texts_1.return)) _b.call(texts_1);
924
- }
925
- finally { if (e_1) throw e_1.error; }
926
- }
927
- if (!domPoint) {
928
- throw new Error("Cannot resolve a DOM point from Slate point: " + JSON.stringify(point));
929
- }
930
- return domPoint;
931
- },
932
- /**
933
- * Find a native DOM range from a Slate `range`.
934
- */
935
- toDOMRange: function (editor, range) {
936
- var anchor = range.anchor, focus = range.focus;
937
- var isBackward = slate.Range.isBackward(range);
938
- var domAnchor = AngularEditor.toDOMPoint(editor, anchor);
939
- var domFocus = slate.Range.isCollapsed(range) ? domAnchor : AngularEditor.toDOMPoint(editor, focus);
940
- var window = AngularEditor.getWindow(editor);
941
- var domRange = window.document.createRange();
942
- var _b = __read(isBackward ? domFocus : domAnchor, 2), startNode = _b[0], startOffset = _b[1];
943
- var _c = __read(isBackward ? domAnchor : domFocus, 2), endNode = _c[0], endOffset = _c[1];
944
- // A slate Point at zero-width Leaf always has an offset of 0 but a native DOM selection at
945
- // zero-width node has an offset of 1 so we have to check if we are in a zero-width node and
946
- // adjust the offset accordingly.
947
- var startEl = (isDOMElement(startNode)
948
- ? startNode
949
- : startNode.parentElement);
950
- var isStartAtZeroWidth = !!startEl.getAttribute('data-slate-zero-width');
951
- var endEl = (isDOMElement(endNode)
952
- ? endNode
953
- : endNode.parentElement);
954
- var isEndAtZeroWidth = !!endEl.getAttribute('data-slate-zero-width');
955
- domRange.setStart(startNode, isStartAtZeroWidth ? 1 : startOffset);
956
- domRange.setEnd(endNode, isEndAtZeroWidth ? 1 : endOffset);
957
- return domRange;
958
- },
959
- /**
960
- * Find a Slate node from a native DOM `element`.
961
- */
962
- toSlateNode: function (editor, domNode) {
963
- var domEl = isDOMElement(domNode) ? domNode : domNode.parentElement;
964
- if (domEl && !domEl.hasAttribute('data-slate-node')) {
965
- domEl = domEl.closest("[data-slate-node]");
966
- }
967
- var node = domEl ? ELEMENT_TO_NODE.get(domEl) : null;
968
- if (!node) {
969
- throw new Error("Cannot resolve a Slate node from DOM node: " + domEl);
970
- }
971
- return node;
972
- },
973
- /**
974
- * Get the target range from a DOM `event`.
975
- */
976
- findEventRange: function (editor, event) {
977
- if ('nativeEvent' in event) {
978
- event = event.nativeEvent;
979
- }
980
- var x = event.clientX, y = event.clientY, target = event.target;
981
- if (x == null || y == null) {
982
- throw new Error("Cannot resolve a Slate range from a DOM event: " + event);
983
- }
984
- var node = AngularEditor.toSlateNode(editor, event.target);
985
- var path = AngularEditor.findPath(editor, node);
986
- // If the drop target is inside a void node, move it into either the
987
- // next or previous node, depending on which side the `x` and `y`
988
- // coordinates are closest to.
989
- if (slate.Editor.isVoid(editor, node)) {
990
- var rect = target.getBoundingClientRect();
991
- var isPrev = editor.isInline(node)
992
- ? x - rect.left < rect.left + rect.width - x
993
- : y - rect.top < rect.top + rect.height - y;
994
- var edge = slate.Editor.point(editor, path, {
995
- edge: isPrev ? 'start' : 'end'
996
- });
997
- var point = isPrev ? slate.Editor.before(editor, edge) : slate.Editor.after(editor, edge);
998
- if (point) {
999
- return slate.Editor.range(editor, point);
1000
- }
1001
- }
1002
- // Else resolve a range from the caret position where the drop occured.
1003
- var domRange;
1004
- var window = AngularEditor.getWindow(editor);
1005
- var document = window.document;
1006
- // COMPAT: In Firefox, `caretRangeFromPoint` doesn't exist. (2016/07/25)
1007
- if (document.caretRangeFromPoint) {
1008
- domRange = document.caretRangeFromPoint(x, y);
1009
- }
1010
- else {
1011
- var position = document.caretPositionFromPoint(x, y);
1012
- if (position) {
1013
- domRange = document.createRange();
1014
- domRange.setStart(position.offsetNode, position.offset);
1015
- domRange.setEnd(position.offsetNode, position.offset);
1016
- }
1017
- }
1018
- if (!domRange) {
1019
- throw new Error("Cannot resolve a Slate range from a DOM event: " + event);
1020
- }
1021
- // Resolve a Slate range from the DOM range.
1022
- var range = AngularEditor.toSlateRange(editor, domRange);
1023
- return range;
1024
- },
1025
- /**
1026
- * Find a Slate point from a DOM selection's `domNode` and `domOffset`.
1027
- */
1028
- toSlatePoint: function (editor, domPoint) {
1029
- var _b = __read(domPoint, 1), domNode = _b[0];
1030
- var _c = __read(normalizeDOMPoint(domPoint), 2), nearestNode = _c[0], nearestOffset = _c[1];
1031
- var parentNode = nearestNode.parentNode;
1032
- var textNode = null;
1033
- var offset = 0;
1034
- // block card
1035
- var cardTargetAttr = getCardTargetAttribute(domNode);
1036
- if (cardTargetAttr) {
1037
- var domSelection = window.getSelection();
1038
- var isBackward = editor.selection && slate.Range.isBackward(editor.selection);
1039
- var blockCardEntry = AngularEditor.toSlateCardEntry(editor, domNode) || AngularEditor.toSlateCardEntry(editor, nearestNode);
1040
- var _d = __read(blockCardEntry, 2), blockPath = _d[1];
1041
- if (domSelection.isCollapsed) {
1042
- if (isCardLeftByTargetAttr(cardTargetAttr)) {
1043
- return { path: blockPath, offset: -1 };
1044
- }
1045
- else {
1046
- return { path: blockPath, offset: -2 };
1047
- }
1048
- }
1049
- // forward
1050
- // and to the end of previous node
1051
- if (isCardLeftByTargetAttr(cardTargetAttr) && !isBackward) {
1052
- var endPath = blockPath[blockPath.length - 1] <= 0
1053
- ? blockPath
1054
- : slate.Path.previous(blockPath);
1055
- return slate.Editor.end(editor, endPath);
1056
- }
1057
- // to the of current node
1058
- if ((isCardCenterByTargetAttr(cardTargetAttr) ||
1059
- isCardRightByTargetAttr(cardTargetAttr)) &&
1060
- !isBackward) {
1061
- return slate.Editor.end(editor, blockPath);
1062
- }
1063
- // backward
1064
- // and to the start of next node
1065
- if (isCardRightByTargetAttr(cardTargetAttr) && isBackward) {
1066
- return slate.Editor.start(editor, slate.Path.next(blockPath));
1067
- }
1068
- // and to the start of current node
1069
- if ((isCardCenterByTargetAttr(cardTargetAttr) ||
1070
- isCardLeftByTargetAttr(cardTargetAttr)) &&
1071
- isBackward) {
1072
- return slate.Editor.start(editor, blockPath);
1073
- }
1074
- }
1075
- if (parentNode) {
1076
- var voidNode = parentNode.closest('[data-slate-void="true"]');
1077
- var leafNode = parentNode.closest('[data-slate-leaf]');
1078
- var domNode_1 = null;
1079
- // Calculate how far into the text node the `nearestNode` is, so that we
1080
- // can determine what the offset relative to the text node is.
1081
- if (leafNode) {
1082
- textNode = leafNode.closest('[data-slate-node="text"]');
1083
- var window = AngularEditor.getWindow(editor);
1084
- var range = window.document.createRange();
1085
- range.setStart(textNode, 0);
1086
- range.setEnd(nearestNode, nearestOffset);
1087
- var contents = range.cloneContents();
1088
- var removals = __spreadArray(__spreadArray([], __read(Array.prototype.slice.call(contents.querySelectorAll('[data-slate-zero-width]')))), __read(Array.prototype.slice.call(contents.querySelectorAll('[contenteditable=false]'))));
1089
- removals.forEach(function (el) {
1090
- el.parentNode.removeChild(el);
1091
- });
1092
- // COMPAT: Edge has a bug where Range.prototype.toString() will
1093
- // convert \n into \r\n. The bug causes a loop when slate-react
1094
- // attempts to reposition its cursor to match the native position. Use
1095
- // textContent.length instead.
1096
- // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/
1097
- offset = contents.textContent.length;
1098
- domNode_1 = textNode;
1099
- }
1100
- else if (voidNode) {
1101
- // For void nodes, the element with the offset key will be a cousin, not an
1102
- // ancestor, so find it by going down from the nearest void parent.
1103
- leafNode = voidNode.querySelector('[data-slate-leaf]');
1104
- parentNode = voidNode.querySelector('[data-slate-length="0"]');
1105
- textNode = leafNode.closest('[data-slate-node="text"]');
1106
- domNode_1 = leafNode;
1107
- offset = domNode_1.textContent.length;
1108
- }
1109
- // COMPAT: If the parent node is a Slate zero-width space, editor is
1110
- // because the text node should have no characters. However, during IME
1111
- // composition the ASCII characters will be prepended to the zero-width
1112
- // space, so subtract 1 from the offset to account for the zero-width
1113
- // space character.
1114
- if (domNode_1 &&
1115
- offset === domNode_1.textContent.length &&
1116
- (parentNode && parentNode.hasAttribute('data-slate-zero-width'))) {
1117
- offset--;
1118
- }
1119
- }
1120
- if (!textNode) {
1121
- throw new Error("Cannot resolve a Slate point from DOM point: " + domPoint);
1122
- }
1123
- // COMPAT: If someone is clicking from one Slate editor into another,
1124
- // the select event fires twice, once for the old editor's `element`
1125
- // first, and then afterwards for the correct `element`. (2017/03/03)
1126
- var slateNode = AngularEditor.toSlateNode(editor, textNode);
1127
- var path = AngularEditor.findPath(editor, slateNode);
1128
- return { path: path, offset: offset };
1129
- },
1130
- /**
1131
- * Find a Slate range from a DOM range or selection.
1132
- */
1133
- toSlateRange: function (editor, domRange) {
1134
- var el = isDOMSelection(domRange) ? domRange.anchorNode : domRange.startContainer;
1135
- var anchorNode;
1136
- var anchorOffset;
1137
- var focusNode;
1138
- var focusOffset;
1139
- var isCollapsed;
1140
- if (el) {
1141
- if (isDOMSelection(domRange)) {
1142
- anchorNode = domRange.anchorNode;
1143
- anchorOffset = domRange.anchorOffset;
1144
- focusNode = domRange.focusNode;
1145
- focusOffset = domRange.focusOffset;
1146
- // COMPAT: There's a bug in chrome that always returns `true` for
1147
- // `isCollapsed` for a Selection that comes from a ShadowRoot.
1148
- // (2020/08/08)
1149
- // https://bugs.chromium.org/p/chromium/issues/detail?id=447523
1150
- if (IS_CHROME && hasShadowRoot()) {
1151
- isCollapsed =
1152
- domRange.anchorNode === domRange.focusNode &&
1153
- domRange.anchorOffset === domRange.focusOffset;
1154
- }
1155
- else {
1156
- isCollapsed = domRange.isCollapsed;
1157
- }
1158
- }
1159
- else {
1160
- anchorNode = domRange.startContainer;
1161
- anchorOffset = domRange.startOffset;
1162
- focusNode = domRange.endContainer;
1163
- focusOffset = domRange.endOffset;
1164
- isCollapsed = domRange.collapsed;
1165
- }
1166
- }
1167
- if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
1168
- throw new Error("Cannot resolve a Slate range from DOM range: " + domRange);
1169
- }
1170
- var anchor = AngularEditor.toSlatePoint(editor, [anchorNode, anchorOffset]);
1171
- var focus = isCollapsed ? anchor : AngularEditor.toSlatePoint(editor, [focusNode, focusOffset]);
1172
- return { anchor: anchor, focus: focus };
1173
- },
1174
- isLeafBlock: function (editor, node) {
1175
- return slate.Element.isElement(node) && !editor.isInline(node) && slate.Editor.hasInlines(editor, node);
1176
- },
1177
- isBlockCardLeftCursor: function (editor) {
1178
- return editor.selection.anchor.offset === FAKE_LEFT_BLOCK_CARD_OFFSET && editor.selection.focus.offset === FAKE_LEFT_BLOCK_CARD_OFFSET;
1179
- },
1180
- isBlockCardRightCursor: function (editor) {
1181
- return editor.selection.anchor.offset === FAKE_RIGHT_BLOCK_CARD_OFFSET && editor.selection.focus.offset === FAKE_RIGHT_BLOCK_CARD_OFFSET;
1182
- },
1183
- getCardCursorNode: function (editor, blockCardNode, options) {
1184
- var blockCardElement = AngularEditor.toDOMNode(editor, blockCardNode);
1185
- var cardCenter = blockCardElement.parentElement;
1186
- return options.direction === 'left'
1187
- ? cardCenter.previousElementSibling
1188
- : cardCenter.nextElementSibling;
1189
- },
1190
- toSlateCardEntry: function (editor, node) {
1191
- var _a;
1192
- var element = (_a = node.parentElement
1193
- .closest('.slate-block-card')) === null || _a === void 0 ? void 0 : _a.querySelector('[card-target="card-center"]').firstElementChild;
1194
- var slateNode = AngularEditor.toSlateNode(editor, element);
1195
- var path = AngularEditor.findPath(editor, slateNode);
1196
- return [slateNode, path];
1197
- },
1198
- /**
1199
- * move native selection to card-left or card-right
1200
- * @param editor
1201
- * @param blockCardNode
1202
- * @param options
1203
- */
1204
- moveBlockCard: function (editor, blockCardNode, options) {
1205
- var cursorNode = AngularEditor.getCardCursorNode(editor, blockCardNode, options);
1206
- var window = AngularEditor.getWindow(editor);
1207
- var domSelection = window.getSelection();
1208
- domSelection.setBaseAndExtent(cursorNode, 1, cursorNode, 1);
1209
- },
1210
- /**
1211
- * move slate selection to card-left or card-right
1212
- * @param editor
1213
- * @param path
1214
- * @param options
1215
- */
1216
- moveBlockCardCursor: function (editor, path, options) {
1217
- var cursor = { path: path, offset: options.direction === 'left' ? FAKE_LEFT_BLOCK_CARD_OFFSET : FAKE_RIGHT_BLOCK_CARD_OFFSET };
1218
- slate.Transforms.select(editor, { anchor: cursor, focus: cursor });
1219
- },
1220
- hasRange: function (editor, range) {
1221
- var anchor = range.anchor, focus = range.focus;
1222
- return (slate.Editor.hasPath(editor, anchor.path) && slate.Editor.hasPath(editor, focus.path));
1223
- },
1224
- };
1225
-
1226
- /**
1227
- * Hotkey mappings for each platform.
1228
- */
1229
- var HOTKEYS = {
1230
- bold: 'mod+b',
1231
- compose: ['down', 'left', 'right', 'up', 'backspace', 'enter'],
1232
- moveBackward: 'left',
1233
- moveForward: 'right',
1234
- moveUp: 'up',
1235
- moveDown: 'down',
1236
- moveWordBackward: 'ctrl+left',
1237
- moveWordForward: 'ctrl+right',
1238
- deleteBackward: 'shift?+backspace',
1239
- deleteForward: 'shift?+delete',
1240
- extendBackward: 'shift+left',
1241
- extendForward: 'shift+right',
1242
- italic: 'mod+i',
1243
- splitBlock: 'shift?+enter',
1244
- undo: 'mod+z'
1245
- };
1246
- var APPLE_HOTKEYS = {
1247
- moveLineBackward: 'opt+up',
1248
- moveLineForward: 'opt+down',
1249
- moveWordBackward: 'opt+left',
1250
- moveWordForward: 'opt+right',
1251
- deleteBackward: ['ctrl+backspace', 'ctrl+h'],
1252
- deleteForward: ['ctrl+delete', 'ctrl+d'],
1253
- deleteLineBackward: 'cmd+shift?+backspace',
1254
- deleteLineForward: ['cmd+shift?+delete', 'ctrl+k'],
1255
- deleteWordBackward: 'opt+shift?+backspace',
1256
- deleteWordForward: 'opt+shift?+delete',
1257
- extendLineBackward: 'opt+shift+up',
1258
- extendLineForward: 'opt+shift+down',
1259
- redo: 'cmd+shift+z',
1260
- transposeCharacter: 'ctrl+t'
1261
- };
1262
- var WINDOWS_HOTKEYS = {
1263
- deleteWordBackward: 'ctrl+shift?+backspace',
1264
- deleteWordForward: 'ctrl+shift?+delete',
1265
- redo: ['ctrl+y', 'ctrl+shift+z']
1266
- };
1267
- /**
1268
- * Create a platform-aware hotkey checker.
1269
- */
1270
- var create = function (key) {
1271
- var generic = HOTKEYS[key];
1272
- var apple = APPLE_HOTKEYS[key];
1273
- var windows = WINDOWS_HOTKEYS[key];
1274
- var isGeneric = generic && isHotkey.isKeyHotkey(generic);
1275
- var isApple = apple && isHotkey.isKeyHotkey(apple);
1276
- var isWindows = windows && isHotkey.isKeyHotkey(windows);
1277
- return function (event) {
1278
- if (isGeneric && isGeneric(event)) {
1279
- return true;
1280
- }
1281
- if (IS_APPLE && isApple && isApple(event)) {
1282
- return true;
1283
- }
1284
- if (!IS_APPLE && isWindows && isWindows(event)) {
1285
- return true;
1286
- }
1287
- return false;
1288
- };
1289
- };
1290
- /**
1291
- * Hotkeys.
1292
- */
1293
- var hotkeys = {
1294
- isBold: create('bold'),
1295
- isCompose: create('compose'),
1296
- isMoveBackward: create('moveBackward'),
1297
- isMoveForward: create('moveForward'),
1298
- isMoveUp: create('moveUp'),
1299
- isMoveDown: create('moveDown'),
1300
- isDeleteBackward: create('deleteBackward'),
1301
- isDeleteForward: create('deleteForward'),
1302
- isDeleteLineBackward: create('deleteLineBackward'),
1303
- isDeleteLineForward: create('deleteLineForward'),
1304
- isDeleteWordBackward: create('deleteWordBackward'),
1305
- isDeleteWordForward: create('deleteWordForward'),
1306
- isExtendBackward: create('extendBackward'),
1307
- isExtendForward: create('extendForward'),
1308
- isExtendLineBackward: create('extendLineBackward'),
1309
- isExtendLineForward: create('extendLineForward'),
1310
- isItalic: create('italic'),
1311
- isMoveLineBackward: create('moveLineBackward'),
1312
- isMoveLineForward: create('moveLineForward'),
1313
- isMoveWordBackward: create('moveWordBackward'),
1314
- isMoveWordForward: create('moveWordForward'),
1315
- isRedo: create('redo'),
1316
- isSplitBlock: create('splitBlock'),
1317
- isTransposeCharacter: create('transposeCharacter'),
1318
- isUndo: create('undo')
1319
- };
1320
-
1321
- function isTemplateRef(value) {
1322
- return value && value instanceof i0.TemplateRef;
1323
- }
1324
- function isComponentType(value) {
1325
- return !isTemplateRef(value);
1326
- }
1327
-
1328
- var shallowCompare = function (obj1, obj2) { return Object.keys(obj1).length === Object.keys(obj2).length &&
1329
- Object.keys(obj1).every(function (key) { return obj2.hasOwnProperty(key) && obj1[key] === obj2[key]; }); };
1330
- /**
1331
- * Check if a list of decorator ranges are equal to another.
1332
- *
1333
- * PERF: this requires the two lists to also have the ranges inside them in the
1334
- * same order, but this is an okay constraint for us since decorations are
1335
- * kept in order, and the odd case where they aren't is okay to re-render for.
1336
- */
1337
- var isDecoratorRangeListEqual = function (list, another) {
1338
- if (list.length !== another.length) {
1339
- return false;
1340
- }
1341
- for (var i = 0; i < list.length; i++) {
1342
- var range = list[i];
1343
- var other = another[i];
1344
- var rangeAnchor = range.anchor, rangeFocus = range.focus, rangeOwnProps = __rest(range, ["anchor", "focus"]);
1345
- var otherAnchor = other.anchor, otherFocus = other.focus, otherOwnProps = __rest(other, ["anchor", "focus"]);
1346
- if (!slate.Range.equals(range, other) ||
1347
- range[PLACEHOLDER_SYMBOL] !== other[PLACEHOLDER_SYMBOL] ||
1348
- !shallowCompare(rangeOwnProps, otherOwnProps)) {
1349
- return false;
1350
- }
1351
- }
1352
- return true;
1353
- };
1354
-
1355
- var isValid = function (value) { return (slate.Element.isElement(value) &&
1356
- value.children.length > 0 &&
1357
- value.children.every(function (child) { return isValid(child); })) ||
1358
- slate.Text.isText(value); };
1359
- var check = function (document) {
1360
- return document.every(function (value) { return slate.Element.isElement(value) && isValid(value); });
1361
- ;
1362
- };
1363
- function normalize(document) {
1364
- return document.filter(function (value) { return slate.Element.isElement(value) && isValid(value); });
1365
- }
1366
-
1367
- /**
1368
- * Utilities for single-line deletion
1369
- */
1370
- var doRectsIntersect = function (rect, compareRect) {
1371
- var middle = (compareRect.top + compareRect.bottom) / 2;
1372
- return rect.top <= middle && rect.bottom >= middle;
1373
- };
1374
- var areRangesSameLine = function (editor, range1, range2) {
1375
- var rect1 = AngularEditor.toDOMRange(editor, range1).getBoundingClientRect();
1376
- var rect2 = AngularEditor.toDOMRange(editor, range2).getBoundingClientRect();
1377
- return doRectsIntersect(rect1, rect2) && doRectsIntersect(rect2, rect1);
1378
- };
1379
- /**
1380
- * A helper utility that returns the end portion of a `Range`
1381
- * which is located on a single line.
1382
- *
1383
- * @param {Editor} editor The editor object to compare against
1384
- * @param {Range} parentRange The parent range to compare against
1385
- * @returns {Range} A valid portion of the parentRange which is one a single line
1386
- */
1387
- var findCurrentLineRange = function (editor, parentRange) {
1388
- var parentRangeBoundary = slate.Editor.range(editor, slate.Range.end(parentRange));
1389
- var positions = Array.from(slate.Editor.positions(editor, { at: parentRange }));
1390
- var left = 0;
1391
- var right = positions.length;
1392
- var middle = Math.floor(right / 2);
1393
- if (areRangesSameLine(editor, slate.Editor.range(editor, positions[left]), parentRangeBoundary)) {
1394
- return slate.Editor.range(editor, positions[left], parentRangeBoundary);
1395
- }
1396
- if (positions.length < 2) {
1397
- return slate.Editor.range(editor, positions[positions.length - 1], parentRangeBoundary);
1398
- }
1399
- while (middle !== positions.length && middle !== left) {
1400
- if (areRangesSameLine(editor, slate.Editor.range(editor, positions[middle]), parentRangeBoundary)) {
1401
- right = middle;
1402
- }
1403
- else {
1404
- left = middle;
1405
- }
1406
- middle = Math.floor((left + right) / 2);
1407
- }
1408
- return slate.Editor.range(editor, positions[right], parentRangeBoundary);
1409
- };
1410
-
1411
- var withAngular = function (editor, clipboardFormatKey) {
1412
- if (clipboardFormatKey === void 0) { clipboardFormatKey = 'x-slate-fragment'; }
1413
- var e = editor;
1414
- var apply = e.apply, onChange = e.onChange, deleteBackward = e.deleteBackward;
1415
- e.deleteBackward = function (unit) {
1416
- if (unit !== 'line') {
1417
- return deleteBackward(unit);
1418
- }
1419
- if (editor.selection && slate.Range.isCollapsed(editor.selection)) {
1420
- var parentBlockEntry = slate.Editor.above(editor, {
1421
- match: function (n) { return slate.Editor.isBlock(editor, n); },
1422
- at: editor.selection,
1423
- });
1424
- if (parentBlockEntry) {
1425
- var _a = __read(parentBlockEntry, 2), parentBlockPath = _a[1];
1426
- var parentElementRange = slate.Editor.range(editor, parentBlockPath, editor.selection.anchor);
1427
- var currentLineRange = findCurrentLineRange(e, parentElementRange);
1428
- if (!slate.Range.isCollapsed(currentLineRange)) {
1429
- slate.Transforms.delete(editor, { at: currentLineRange });
1430
- }
1431
- }
1432
- }
1433
- };
1434
- e.apply = function (op) {
1435
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
1436
- var matches = [];
1437
- switch (op.type) {
1438
- case 'insert_text':
1439
- case 'remove_text':
1440
- case 'set_node': {
1441
- try {
1442
- for (var _f = __values(slate.Editor.levels(e, { at: op.path })), _g = _f.next(); !_g.done; _g = _f.next()) {
1443
- var _h = __read(_g.value, 2), node = _h[0], path = _h[1];
1444
- var key = AngularEditor.findKey(e, node);
1445
- matches.push([path, key]);
1446
- }
1447
- }
1448
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1449
- finally {
1450
- try {
1451
- if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
1452
- }
1453
- finally { if (e_1) throw e_1.error; }
1454
- }
1455
- break;
1456
- }
1457
- case 'insert_node':
1458
- case 'remove_node':
1459
- case 'merge_node':
1460
- case 'split_node': {
1461
- try {
1462
- for (var _j = __values(slate.Editor.levels(e, {
1463
- at: slate.Path.parent(op.path),
1464
- })), _k = _j.next(); !_k.done; _k = _j.next()) {
1465
- var _l = __read(_k.value, 2), node = _l[0], path = _l[1];
1466
- var key = AngularEditor.findKey(e, node);
1467
- matches.push([path, key]);
1468
- }
1469
- }
1470
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1471
- finally {
1472
- try {
1473
- if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
1474
- }
1475
- finally { if (e_2) throw e_2.error; }
1476
- }
1477
- break;
1478
- }
1479
- case 'move_node': {
1480
- var commonPath = slate.Path.common(slate.Path.parent(op.path), slate.Path.parent(op.newPath));
1481
- try {
1482
- for (var _m = __values(slate.Editor.levels(e, { at: slate.Path.parent(op.path) })), _o = _m.next(); !_o.done; _o = _m.next()) {
1483
- var _p = __read(_o.value, 2), node = _p[0], path = _p[1];
1484
- var key = AngularEditor.findKey(e, node);
1485
- matches.push([slate.Editor.pathRef(editor, path), key]);
1486
- }
1487
- }
1488
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1489
- finally {
1490
- try {
1491
- if (_o && !_o.done && (_c = _m.return)) _c.call(_m);
1492
- }
1493
- finally { if (e_3) throw e_3.error; }
1494
- }
1495
- try {
1496
- for (var _q = __values(slate.Editor.levels(e, { at: slate.Path.parent(op.newPath) })), _r = _q.next(); !_r.done; _r = _q.next()) {
1497
- var _s = __read(_r.value, 2), node = _s[0], path = _s[1];
1498
- if (path.length > commonPath.length) {
1499
- var key = AngularEditor.findKey(e, node);
1500
- matches.push([slate.Editor.pathRef(editor, path), key]);
1501
- }
1502
- }
1503
- }
1504
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1505
- finally {
1506
- try {
1507
- if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
1508
- }
1509
- finally { if (e_4) throw e_4.error; }
1510
- }
1511
- break;
1512
- }
1513
- }
1514
- apply(op);
1515
- try {
1516
- for (var matches_1 = __values(matches), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {
1517
- var _t = __read(matches_1_1.value, 2), source = _t[0], key = _t[1];
1518
- var _u = __read(slate.Editor.node(e, slate.Path.isPath(source) ? source : source.current), 1), node = _u[0];
1519
- NODE_TO_KEY.set(node, key);
1520
- }
1521
- }
1522
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1523
- finally {
1524
- try {
1525
- if (matches_1_1 && !matches_1_1.done && (_e = matches_1.return)) _e.call(matches_1);
1526
- }
1527
- finally { if (e_5) throw e_5.error; }
1528
- }
1529
- };
1530
- e.onChange = function () {
1531
- var onContextChange = EDITOR_TO_ON_CHANGE.get(e);
1532
- if (onContextChange) {
1533
- onContextChange();
1534
- }
1535
- onChange();
1536
- };
1537
- e.setFragmentData = function (data) {
1538
- var selection = e.selection;
1539
- if (!selection) {
1540
- return;
1541
- }
1542
- var _a = __read(slate.Range.edges(selection), 2), start = _a[0], end = _a[1];
1543
- var startVoid = slate.Editor.void(e, { at: start.path });
1544
- var endVoid = slate.Editor.void(e, { at: end.path });
1545
- if (slate.Range.isCollapsed(selection) && !startVoid) {
1546
- return;
1547
- }
1548
- // Create a fake selection so that we can add a Base64-encoded copy of the
1549
- // fragment to the HTML, to decode on future pastes.
1550
- var domRange = AngularEditor.toDOMRange(e, selection);
1551
- var contents = domRange.cloneContents();
1552
- var attach = contents.childNodes[0];
1553
- // Make sure attach is non-empty, since empty nodes will not get copied.
1554
- var contentsArray = Array.from(contents.children);
1555
- contentsArray.forEach(function (node) {
1556
- if (node.textContent && node.textContent.trim() !== '') {
1557
- attach = node;
1558
- }
1559
- });
1560
- // COMPAT: If the end node is a void node, we need to move the end of the
1561
- // range from the void node's spacer span, to the end of the void node's
1562
- // content, since the spacer is before void's content in the DOM.
1563
- if (endVoid) {
1564
- var _b = __read(endVoid, 1), voidNode = _b[0];
1565
- var r = domRange.cloneRange();
1566
- var domNode = AngularEditor.toDOMNode(e, voidNode);
1567
- r.setEndAfter(domNode);
1568
- contents = r.cloneContents();
1569
- }
1570
- // COMPAT: If the start node is a void node, we need to attach the encoded
1571
- // fragment to the void node's content node instead of the spacer, because
1572
- // attaching it to empty `<div>/<span>` nodes will end up having it erased by
1573
- // most browsers. (2018/04/27)
1574
- if (startVoid) {
1575
- attach = contents.querySelector('[data-slate-spacer]');
1576
- }
1577
- // Remove any zero-width space spans from the cloned DOM so that they don't
1578
- // show up elsewhere when pasted.
1579
- Array.from(contents.querySelectorAll('[data-slate-zero-width]')).forEach(function (zw) {
1580
- var isNewline = zw.getAttribute('data-slate-zero-width') === 'n';
1581
- zw.textContent = isNewline ? '\n' : '';
1582
- });
1583
- // Set a `data-slate-fragment` attribute on a non-empty node, so it shows up
1584
- // in the HTML, and can be used for intra-Slate pasting. If it's a text
1585
- // node, wrap it in a `<span>` so we have something to set an attribute on.
1586
- if (isDOMText(attach)) {
1587
- var span = attach.ownerDocument.createElement('span');
1588
- // COMPAT: In Chrome and Safari, if we don't add the `white-space` style
1589
- // then leading and trailing spaces will be ignored. (2017/09/21)
1590
- span.style.whiteSpace = 'pre';
1591
- span.appendChild(attach);
1592
- contents.appendChild(span);
1593
- attach = span;
1594
- }
1595
- var fragment = e.getFragment();
1596
- var stringObj = JSON.stringify(fragment);
1597
- var encoded = window.btoa(encodeURIComponent(stringObj));
1598
- attach.setAttribute('data-slate-fragment', encoded);
1599
- data.setData("application/" + clipboardFormatKey, encoded);
1600
- // Add the content to a <div> so that we can get its inner HTML.
1601
- var div = contents.ownerDocument.createElement('div');
1602
- div.appendChild(contents);
1603
- div.setAttribute('hidden', 'true');
1604
- contents.ownerDocument.body.appendChild(div);
1605
- data.setData('text/html', div.innerHTML);
1606
- data.setData('text/plain', getPlainText(div));
1607
- contents.ownerDocument.body.removeChild(div);
1608
- return data;
1609
- };
1610
- e.deleteCutData = function () {
1611
- var selection = editor.selection;
1612
- if (selection) {
1613
- if (slate.Range.isExpanded(selection)) {
1614
- slate.Editor.deleteFragment(editor);
1615
- }
1616
- else {
1617
- var node = slate.Node.parent(editor, selection.anchor.path);
1618
- if (slate.Editor.isVoid(editor, node)) {
1619
- slate.Transforms.delete(editor);
1620
- }
1621
- }
1622
- }
1623
- };
1624
- e.insertData = function (data) {
1625
- if (!e.insertFragmentData(data)) {
1626
- e.insertTextData(data);
1627
- }
1628
- };
1629
- e.insertFragmentData = function (data) {
1630
- /**
1631
- * Checking copied fragment from application/x-slate-fragment or data-slate-fragment
1632
- */
1633
- var fragment = data.getData("application/" + clipboardFormatKey) ||
1634
- getSlateFragmentAttribute(data);
1635
- if (fragment) {
1636
- var decoded = decodeURIComponent(window.atob(fragment));
1637
- var parsed = JSON.parse(decoded);
1638
- e.insertFragment(parsed);
1639
- return true;
1640
- }
1641
- return false;
1642
- };
1643
- e.insertTextData = function (data) {
1644
- var e_6, _a;
1645
- var text = data.getData('text/plain');
1646
- if (text) {
1647
- var lines = text.split(/\r\n|\r|\n/);
1648
- var split = false;
1649
- try {
1650
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
1651
- var line = lines_1_1.value;
1652
- if (split) {
1653
- slate.Transforms.splitNodes(e, { always: true });
1654
- }
1655
- e.insertText(line);
1656
- split = true;
1657
- }
1658
- }
1659
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1660
- finally {
1661
- try {
1662
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
1663
- }
1664
- finally { if (e_6) throw e_6.error; }
1665
- }
1666
- return true;
1667
- }
1668
- return false;
1669
- };
1670
- e.onKeydown = function () { };
1671
- e.onClick = function () { };
1672
- e.isBlockCard = function (element) { return false; };
1673
- e.onError = function (errorData) {
1674
- if (errorData.nativeError) {
1675
- console.error(errorData.nativeError);
1676
- }
1677
- else {
1678
- console.error(errorData);
1679
- }
1680
- };
1681
- return e;
1682
- };
1683
-
1684
- var TOP_BLUR = 'blur';
1685
- var TOP_COMPOSITION_END = 'compositionend';
1686
- var TOP_COMPOSITION_START = 'compositionstart';
1687
- var TOP_COMPOSITION_UPDATE = 'compositionupdate';
1688
- var TOP_KEY_DOWN = 'keydown';
1689
- var TOP_KEY_PRESS = 'keypress';
1690
- var TOP_KEY_UP = 'keyup';
1691
- var TOP_MOUSE_DOWN = 'mousedown';
1692
- var TOP_MOUSE_MOVE = 'mousemove';
1693
- var TOP_MOUSE_OUT = 'mouseout';
1694
- var TOP_TEXT_INPUT = 'textInput';
1695
- var TOP_PASTE = 'paste';
1696
-
1697
- /**
1698
- * Copyright (c) Facebook, Inc. and its affiliates.
1699
- *
1700
- * This source code is licensed under the MIT license found in the
1701
- * LICENSE file in the root directory of this source tree.
1702
- */
1703
- /**
1704
- * These variables store information about text content of a target node,
1705
- * allowing comparison of content before and after a given event.
1706
- *
1707
- * Identify the node where selection currently begins, then observe
1708
- * both its text content and its current position in the DOM. Since the
1709
- * browser may natively replace the target node during composition, we can
1710
- * use its position to find its replacement.
1711
- *
1712
- *
1713
- */
1714
- var root = null;
1715
- var startText = null;
1716
- var fallbackText = null;
1717
- function initialize(nativeEventTarget) {
1718
- root = nativeEventTarget;
1719
- startText = getText();
1720
- return true;
1721
- }
1722
- function reset() {
1723
- root = null;
1724
- startText = null;
1725
- fallbackText = null;
1726
- }
1727
- function getData() {
1728
- if (fallbackText) {
1729
- return fallbackText;
1730
- }
1731
- var start;
1732
- var startValue = startText;
1733
- var startLength = startValue.length;
1734
- var end;
1735
- var endValue = getText();
1736
- var endLength = endValue.length;
1737
- for (start = 0; start < startLength; start++) {
1738
- if (startValue[start] !== endValue[start]) {
1739
- break;
1740
- }
1741
- }
1742
- var minEnd = startLength - start;
1743
- for (end = 1; end <= minEnd; end++) {
1744
- if (startValue[startLength - end] !== endValue[endLength - end]) {
1745
- break;
1746
- }
1747
- }
1748
- var sliceTail = end > 1 ? 1 - end : undefined;
1749
- fallbackText = endValue.slice(start, sliceTail);
1750
- return fallbackText;
1751
- }
1752
- function getText() {
1753
- if ('value' in root) {
1754
- return root.value;
1755
- }
1756
- return root.textContent;
1757
- }
1758
-
1759
- /**
1760
- * Copyright (c) Facebook, Inc. and its affiliates.
1761
- *
1762
- * This source code is licensed under the MIT license found in the
1763
- * LICENSE file in the root directory of this source tree.
1764
- */
1765
- var canUseDOM = !!(typeof window !== 'undefined' &&
1766
- typeof window.document !== 'undefined' &&
1767
- typeof window.document.createElement !== 'undefined');
1768
- var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
1769
- var START_KEYCODE = 229;
1770
- var canUseCompositionEvent = canUseDOM && 'CompositionEvent' in window;
1771
- var documentMode = null;
1772
- if (canUseDOM && 'documentMode' in document) {
1773
- documentMode = document.documentMode;
1774
- }
1775
- // Webkit offers a very useful `textInput` event that can be used to
1776
- // directly represent `beforeInput`. The IE `textinput` event is not as
1777
- // useful, so we don't use it.
1778
- var canUseTextInputEvent = canUseDOM && 'TextEvent' in window && !documentMode;
1779
- // In IE9+, we have access to composition events, but the data supplied
1780
- // by the native compositionend event may be incorrect. Japanese ideographic
1781
- // spaces, for instance (\u3000) are not recorded correctly.
1782
- var useFallbackCompositionData = canUseDOM && (!canUseCompositionEvent || (documentMode && documentMode > 8 && documentMode <= 11));
1783
- var SPACEBAR_CODE = 32;
1784
- var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE);
1785
- // Events and their corresponding property names.
1786
- var eventTypes = {
1787
- beforeInput: {
1788
- phasedRegistrationNames: {
1789
- bubbled: 'onBeforeInput',
1790
- captured: 'onBeforeInputCapture'
1791
- },
1792
- dependencies: [TOP_COMPOSITION_END, TOP_KEY_PRESS, TOP_TEXT_INPUT, TOP_PASTE]
1793
- }
1794
- };
1795
- // Track whether we've ever handled a keypress on the space key.
1796
- var hasSpaceKeypress = false;
1797
- /**
1798
- * Return whether a native keypress event is assumed to be a command.
1799
- * This is required because Firefox fires `keypress` events for key commands
1800
- * (cut, copy, select-all, etc.) even though no character is inserted.
1801
- */
1802
- function isKeypressCommand(nativeEvent) {
1803
- return ((nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) &&
1804
- // ctrlKey && altKey is equivalent to AltGr, and is not a command.
1805
- !(nativeEvent.ctrlKey && nativeEvent.altKey));
1806
- }
1807
- /**
1808
- * Does our fallback mode think that this event is the end of composition?
1809
- *
1810
- */
1811
- function isFallbackCompositionEnd(topLevelType, nativeEvent) {
1812
- switch (topLevelType) {
1813
- case TOP_KEY_UP:
1814
- // Command keys insert or clear IME input.
1815
- return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1;
1816
- case TOP_KEY_DOWN:
1817
- // Expect IME keyCode on each keydown. If we get any other
1818
- // code we must have exited earlier.
1819
- return nativeEvent.keyCode !== START_KEYCODE;
1820
- case TOP_KEY_PRESS:
1821
- case TOP_MOUSE_DOWN:
1822
- case TOP_BLUR:
1823
- // Events are not possible without cancelling IME.
1824
- return true;
1825
- default:
1826
- return false;
1827
- }
1828
- }
1829
- /**
1830
- * Google Input Tools provides composition data via a CustomEvent,
1831
- * with the `data` property populated in the `detail` object. If this
1832
- * is available on the event object, use it. If not, this is a plain
1833
- * composition event and we have nothing special to extract.
1834
- *
1835
- */
1836
- function getDataFromCustomEvent(nativeEvent) {
1837
- var detail = nativeEvent.detail;
1838
- if (typeof detail === 'object' && 'data' in detail) {
1839
- return detail.data;
1840
- }
1841
- return null;
1842
- }
1843
- /**
1844
- * Check if a composition event was triggered by Korean IME.
1845
- * Our fallback mode does not work well with IE's Korean IME,
1846
- * so just use native composition events when Korean IME is used.
1847
- * Although CompositionEvent.locale property is deprecated,
1848
- * it is available in IE, where our fallback mode is enabled.
1849
- *
1850
- */
1851
- function isUsingKoreanIME(nativeEvent) {
1852
- return nativeEvent.locale === 'ko';
1853
- }
1854
- // Track the current IME composition status, if any.
1855
- var isComposing = false;
1856
- function getNativeBeforeInputChars(topLevelType, nativeEvent) {
1857
- switch (topLevelType) {
1858
- case TOP_COMPOSITION_END:
1859
- return getDataFromCustomEvent(nativeEvent);
1860
- case TOP_KEY_PRESS:
1861
- /**
1862
- * If native `textInput` events are available, our goal is to make
1863
- * use of them. However, there is a special case: the spacebar key.
1864
- * In Webkit, preventing default on a spacebar `textInput` event
1865
- * cancels character insertion, but it *also* causes the browser
1866
- * to fall back to its default spacebar behavior of scrolling the
1867
- * page.
1868
- *
1869
- * Tracking at:
1870
- * https://code.google.com/p/chromium/issues/detail?id=355103
1871
- *
1872
- * To avoid this issue, use the keypress event as if no `textInput`
1873
- * event is available.
1874
- */
1875
- var which = nativeEvent.which;
1876
- if (which !== SPACEBAR_CODE) {
1877
- return null;
1878
- }
1879
- hasSpaceKeypress = true;
1880
- return SPACEBAR_CHAR;
1881
- case TOP_TEXT_INPUT:
1882
- // Record the characters to be added to the DOM.
1883
- var chars = nativeEvent.data;
1884
- // If it's a spacebar character, assume that we have already handled
1885
- // it at the keypress level and bail immediately. Android Chrome
1886
- // doesn't give us keycodes, so we need to ignore it.
1887
- if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
1888
- return null;
1889
- }
1890
- return chars;
1891
- default:
1892
- // For other native event types, do nothing.
1893
- return null;
1894
- }
1895
- }
1896
- /**
1897
- * For browsers that do not provide the `textInput` event, extract the
1898
- * appropriate string to use for SyntheticInputEvent.
1899
- *
1900
- */
1901
- function getFallbackBeforeInputChars(topLevelType, nativeEvent) {
1902
- // If we are currently composing (IME) and using a fallback to do so,
1903
- // try to extract the composed characters from the fallback object.
1904
- // If composition event is available, we extract a string only at
1905
- // compositionevent, otherwise extract it at fallback events.
1906
- if (isComposing) {
1907
- if (topLevelType === TOP_COMPOSITION_END || (!canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent))) {
1908
- var chars = getData();
1909
- reset();
1910
- isComposing = false;
1911
- return chars;
1912
- }
1913
- return null;
1914
- }
1915
- switch (topLevelType) {
1916
- case TOP_PASTE:
1917
- // If a paste event occurs after a keypress, throw out the input
1918
- // chars. Paste events should not lead to BeforeInput events.
1919
- return null;
1920
- case TOP_KEY_PRESS:
1921
- /**
1922
- * As of v27, Firefox may fire keypress events even when no character
1923
- * will be inserted. A few possibilities:
1924
- *
1925
- * - `which` is `0`. Arrow keys, Esc key, etc.
1926
- *
1927
- * - `which` is the pressed key code, but no char is available.
1928
- * Ex: 'AltGr + d` in Polish. There is no modified character for
1929
- * this key combination and no character is inserted into the
1930
- * document, but FF fires the keypress for char code `100` anyway.
1931
- * No `input` event will occur.
1932
- *
1933
- * - `which` is the pressed key code, but a command combination is
1934
- * being used. Ex: `Cmd+C`. No character is inserted, and no
1935
- * `input` event will occur.
1936
- */
1937
- if (!isKeypressCommand(nativeEvent)) {
1938
- // IE fires the `keypress` event when a user types an emoji via
1939
- // Touch keyboard of Windows. In such a case, the `char` property
1940
- // holds an emoji character like `\uD83D\uDE0A`. Because its length
1941
- // is 2, the property `which` does not represent an emoji correctly.
1942
- // In such a case, we directly return the `char` property instead of
1943
- // using `which`.
1944
- if (nativeEvent.char && nativeEvent.char.length > 1) {
1945
- return nativeEvent.char;
1946
- }
1947
- else if (nativeEvent.which) {
1948
- return String.fromCharCode(nativeEvent.which);
1949
- }
1950
- }
1951
- return null;
1952
- case TOP_COMPOSITION_END:
1953
- return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent) ? null : nativeEvent.data;
1954
- default:
1955
- return null;
1956
- }
1957
- }
1958
- /**
1959
- * Extract a SyntheticInputEvent for `beforeInput`, based on either native
1960
- * `textInput` or fallback behavior.
1961
- *
1962
- */
1963
- function extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
1964
- var chars;
1965
- if (canUseTextInputEvent) {
1966
- chars = getNativeBeforeInputChars(topLevelType, nativeEvent);
1967
- }
1968
- else {
1969
- chars = getFallbackBeforeInputChars(topLevelType, nativeEvent);
1970
- }
1971
- // If no characters are being inserted, no BeforeInput event should
1972
- // be fired.
1973
- if (!chars) {
1974
- return null;
1975
- }
1976
- var beforeInputEvent = new BeforeInputEvent();
1977
- beforeInputEvent.data = chars;
1978
- beforeInputEvent.nativeEvent = nativeEvent;
1979
- return beforeInputEvent;
1980
- }
1981
- /**
1982
- * Create an `onBeforeInput` event to match
1983
- * http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-inputevents.
1984
- *
1985
- * This event plugin is based on the native `textInput` event
1986
- * available in Chrome, Safari, Opera, and IE. This event fires after
1987
- * `onKeyPress` and `onCompositionEnd`, but before `onInput`.
1988
- *
1989
- * `beforeInput` is spec'd but not implemented in any browsers, and
1990
- * the `input` event does not provide any useful information about what has
1991
- * actually been added, contrary to the spec. Thus, `textInput` is the best
1992
- * available event to identify the characters that have actually been inserted
1993
- * into the target node.
1994
- *
1995
- * This plugin is also responsible for emitting `composition` events, thus
1996
- * allowing us to share composition fallback code for both `beforeInput` and
1997
- * `composition` event types.
1998
- */
1999
- var BeforeInputEventPlugin = {
2000
- extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
2001
- return extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget);
2002
- }
2003
- };
2004
- var BeforeInputEvent = /** @class */ (function () {
2005
- function BeforeInputEvent() {
2006
- }
2007
- return BeforeInputEvent;
2008
- }());
2009
-
2010
- var BEFORE_INPUT_EVENTS = [
2011
- // { name: 'blur', handler: 'onBlur', isTriggerBeforeInput: true },
2012
- // { name: 'compositionstart', handler: 'onCompositionStart', isTriggerBeforeInput: true },
2013
- { name: 'compositionupdate', handler: null, isTriggerBeforeInput: true },
2014
- // { name: 'compositionend', handler: 'onCompositionEnd', isTriggerBeforeInput: false },
2015
- // { name: 'keydown', handler: 'onKeyDown', isTriggerBeforeInput: true },
2016
- { name: 'keypress', handler: null, isTriggerBeforeInput: true },
2017
- { name: 'keyup', handler: 'onKeyUp', isTriggerBeforeInput: true },
2018
- { name: 'mousedown', handler: 'onMouseDown', isTriggerBeforeInput: true },
2019
- { name: 'textInput', handler: null, isTriggerBeforeInput: true },
2020
- // { name: 'paste', handler: 'onPaste', isTriggerBeforeInput: true }
2021
- ];
2022
-
2023
- exports.SlateErrorCode = void 0;
2024
- (function (SlateErrorCode) {
2025
- SlateErrorCode[SlateErrorCode["ToNativeSelectionError"] = 2100] = "ToNativeSelectionError";
2026
- SlateErrorCode[SlateErrorCode["ToSlateSelectionError"] = 2101] = "ToSlateSelectionError";
2027
- SlateErrorCode[SlateErrorCode["OnDOMBeforeInputError"] = 2102] = "OnDOMBeforeInputError";
2028
- SlateErrorCode[SlateErrorCode["OnSyntheticBeforeInputError"] = 2103] = "OnSyntheticBeforeInputError";
2029
- SlateErrorCode[SlateErrorCode["OnDOMKeydownError"] = 2104] = "OnDOMKeydownError";
2030
- SlateErrorCode[SlateErrorCode["GetStartPointError"] = 2105] = "GetStartPointError";
2031
- SlateErrorCode[SlateErrorCode["NotFoundPreviousRootNodeError"] = 3100] = "NotFoundPreviousRootNodeError";
2032
- SlateErrorCode[SlateErrorCode["InvalidValueError"] = 4100] = "InvalidValueError";
2033
- })(exports.SlateErrorCode || (exports.SlateErrorCode = {}));
2034
-
2035
- var SlateBlockCardComponent = /** @class */ (function () {
2036
- function SlateBlockCardComponent(elementRef) {
2037
- this.elementRef = elementRef;
2038
- }
2039
- Object.defineProperty(SlateBlockCardComponent.prototype, "nativeElement", {
2040
- get: function () {
2041
- return this.elementRef.nativeElement;
2042
- },
2043
- enumerable: false,
2044
- configurable: true
2045
- });
2046
- Object.defineProperty(SlateBlockCardComponent.prototype, "centerContainerElement", {
2047
- get: function () {
2048
- return this.centerContianer.nativeElement;
2049
- },
2050
- enumerable: false,
2051
- configurable: true
2052
- });
2053
- SlateBlockCardComponent.prototype.ngOnInit = function () {
2054
- this.append();
2055
- this.nativeElement.classList.add("slate-block-card");
2056
- };
2057
- SlateBlockCardComponent.prototype.append = function () {
2058
- var _this = this;
2059
- this.centerRootNodes.forEach(function (rootNode) { return !_this.centerContainerElement.contains(rootNode) && _this.centerContainerElement.appendChild(rootNode); });
2060
- };
2061
- SlateBlockCardComponent.prototype.initializeCenter = function (rootNodes) {
2062
- this.centerRootNodes = rootNodes;
2063
- };
2064
- return SlateBlockCardComponent;
2065
- }());
2066
- SlateBlockCardComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateBlockCardComponent, deps: [{ token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Component });
2067
- SlateBlockCardComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateBlockCardComponent, selector: "slate-block-card, [slateBlockCard]", viewQueries: [{ propertyName: "centerContianer", first: true, predicate: ["centerContianer"], descendants: true, static: true }], ngImport: i0__namespace, template: "<span card-target=\"card-left\" class=\"card-left\">{{ '\\uFEFF' }}</span>\n<div card-target=\"card-center\" #centerContianer></div>\n<span card-target=\"card-right\" class=\"card-right\">{{ '\\uFEFF' }}</span>" });
2068
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateBlockCardComponent, decorators: [{
2069
- type: i0.Component,
2070
- args: [{
2071
- selector: 'slate-block-card, [slateBlockCard]',
2072
- templateUrl: 'block-card.component.html'
2073
- }]
2074
- }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }]; }, propDecorators: { centerContianer: [{
2075
- type: i0.ViewChild,
2076
- args: ['centerContianer', { static: true }]
2077
- }] } });
2078
-
2079
- /**
2080
- * Dynamically create/update components or templates
2081
- * Provide rootNodes for the view container
2082
- * If the dynamically created component uses onpush mode, then it must call markForCheck when setting the context
2083
- */
2084
- var ViewContainerItem = /** @class */ (function () {
2085
- function ViewContainerItem(viewContainerRef, componentFactoryResolver) {
2086
- this.viewContainerRef = viewContainerRef;
2087
- this.componentFactoryResolver = componentFactoryResolver;
2088
- this.initialized = false;
2089
- }
2090
- Object.defineProperty(ViewContainerItem.prototype, "rootNodes", {
2091
- get: function () {
2092
- return this.getRootNodes();
2093
- },
2094
- enumerable: false,
2095
- configurable: true
2096
- });
2097
- ViewContainerItem.prototype.getRootNodes = function () {
2098
- if (this.embeddedViewRef) {
2099
- return this.embeddedViewRef.rootNodes.filter(function (rootNode) { return isDOMElement(rootNode); });
2100
- }
2101
- if (this.componentRef) {
2102
- return [this.componentRef.instance.nativeElement];
2103
- }
2104
- return [];
2105
- };
2106
- ViewContainerItem.prototype.destroyView = function () {
2107
- if (this.embeddedViewRef) {
2108
- this.embeddedViewRef.destroy();
2109
- this.embeddedViewRef = null;
2110
- }
2111
- if (this.componentRef) {
2112
- this.componentRef.destroy();
2113
- this.componentRef = null;
2114
- }
2115
- };
2116
- ViewContainerItem.prototype.createView = function () {
2117
- this.initialized = true;
2118
- this.viewType = this.getViewType();
2119
- var context = this.getContext();
2120
- if (isTemplateRef(this.viewType)) {
2121
- this.embeddedViewContext = { context: context, viewContext: this.viewContext };
2122
- var embeddedViewRef = this.viewContainerRef.createEmbeddedView(this.viewType, this.embeddedViewContext);
2123
- this.embeddedViewRef = embeddedViewRef;
2124
- }
2125
- if (isComponentType(this.viewType)) {
2126
- var componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.viewType);
2127
- var componentRef = this.viewContainerRef.createComponent(componentFactory);
2128
- componentRef.instance.context = context;
2129
- componentRef.instance.viewContext = this.viewContext;
2130
- this.componentRef = componentRef;
2131
- }
2132
- };
2133
- ViewContainerItem.prototype.updateView = function () {
2134
- var viewType = this.getViewType();
2135
- var context = this.getContext();
2136
- if (this.viewType === viewType) {
2137
- if (this.componentRef) {
2138
- if (this.memoizedContext(this.componentRef.instance.context, context)) {
2139
- return;
2140
- }
2141
- this.componentRef.instance.context = context;
2142
- }
2143
- if (this.embeddedViewRef) {
2144
- if (this.memoizedContext(this.embeddedViewContext.context, context)) {
2145
- return;
2146
- }
2147
- this.embeddedViewContext.context = context;
2148
- }
2149
- }
2150
- else {
2151
- this.viewType = viewType;
2152
- var firstRootNode = this.rootNodes[0];
2153
- if (isTemplateRef(this.viewType)) {
2154
- this.embeddedViewContext = { context: context, viewContext: this.viewContext };
2155
- var embeddedViewRef = this.viewContainerRef.createEmbeddedView(this.viewType, this.embeddedViewContext);
2156
- firstRootNode.replaceWith.apply(firstRootNode, __spreadArray([], __read(embeddedViewRef.rootNodes.filter(function (rootNode) { return isDOMElement(rootNode); }))));
2157
- this.destroyView();
2158
- this.embeddedViewRef = embeddedViewRef;
2159
- }
2160
- if (isComponentType(this.viewType)) {
2161
- var componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.viewType);
2162
- var componentRef = this.viewContainerRef.createComponent(componentFactory);
2163
- componentRef.instance.context = context;
2164
- componentRef.instance.viewContext = this.viewContext;
2165
- firstRootNode.replaceWith(componentRef.instance.nativeElement);
2166
- this.destroyView();
2167
- this.componentRef = componentRef;
2168
- }
2169
- }
2170
- };
2171
- ViewContainerItem.prototype.appendBlockCardElement = function () {
2172
- if (this.blockCardComponentRef) {
2173
- this.blockCardComponentRef.instance.append();
2174
- }
2175
- };
2176
- return ViewContainerItem;
2177
- }());
2178
- ViewContainerItem.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: ViewContainerItem, deps: [{ token: i0__namespace.ViewContainerRef }, { token: i0__namespace.ComponentFactoryResolver }], target: i0__namespace.ɵɵFactoryTarget.Directive });
2179
- ViewContainerItem.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: ViewContainerItem, inputs: { viewContext: "viewContext" }, ngImport: i0__namespace });
2180
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: ViewContainerItem, decorators: [{
2181
- type: i0.Directive
2182
- }], ctorParameters: function () { return [{ type: i0__namespace.ViewContainerRef }, { type: i0__namespace.ComponentFactoryResolver }]; }, propDecorators: { viewContext: [{
2183
- type: i0.Input
2184
- }] } });
2185
-
2186
- function hasBeforeContextChange(value) {
2187
- if (value.beforeContextChange) {
2188
- return true;
2189
- }
2190
- return false;
2191
- }
2192
-
2193
- /**
2194
- * base class for custom element component or text component
2195
- */
2196
- var BaseComponent = /** @class */ (function () {
2197
- function BaseComponent(elementRef, cdr) {
2198
- this.elementRef = elementRef;
2199
- this.cdr = cdr;
2200
- }
2201
- Object.defineProperty(BaseComponent.prototype, "context", {
2202
- get: function () {
2203
- return this._context;
2204
- },
2205
- set: function (value) {
2206
- if (hasBeforeContextChange(this)) {
2207
- this.beforeContextChange(value);
2208
- }
2209
- this._context = value;
2210
- this.onContextChange();
2211
- },
2212
- enumerable: false,
2213
- configurable: true
2214
- });
2215
- Object.defineProperty(BaseComponent.prototype, "editor", {
2216
- get: function () {
2217
- return this.viewContext && this.viewContext.editor;
2218
- },
2219
- enumerable: false,
2220
- configurable: true
2221
- });
2222
- Object.defineProperty(BaseComponent.prototype, "nativeElement", {
2223
- get: function () {
2224
- return this.elementRef.nativeElement;
2225
- },
2226
- enumerable: false,
2227
- configurable: true
2228
- });
2229
- return BaseComponent;
2230
- }());
2231
- BaseComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseComponent, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.ChangeDetectorRef }], target: i0__namespace.ɵɵFactoryTarget.Directive });
2232
- BaseComponent.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: BaseComponent, inputs: { context: "context", viewContext: "viewContext" }, ngImport: i0__namespace });
2233
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseComponent, decorators: [{
2234
- type: i0.Directive
2235
- }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.ChangeDetectorRef }]; }, propDecorators: { context: [{
2236
- type: i0.Input
2237
- }], viewContext: [{
2238
- type: i0.Input
2239
- }] } });
2240
- /**
2241
- * base class for custom leaf component
2242
- */
2243
- var BaseLeafComponent = /** @class */ (function (_super) {
2244
- __extends(BaseLeafComponent, _super);
2245
- function BaseLeafComponent() {
2246
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
2247
- _this.initialized = false;
2248
- _this.isSlateLeaf = true;
2249
- return _this;
2250
- }
2251
- Object.defineProperty(BaseLeafComponent.prototype, "text", {
2252
- get: function () {
2253
- return this.context && this.context.text;
2254
- },
2255
- enumerable: false,
2256
- configurable: true
2257
- });
2258
- Object.defineProperty(BaseLeafComponent.prototype, "leaf", {
2259
- get: function () {
2260
- return this.context && this.context.leaf;
2261
- },
2262
- enumerable: false,
2263
- configurable: true
2264
- });
2265
- BaseLeafComponent.prototype.ngOnInit = function () {
2266
- this.initialized = true;
2267
- };
2268
- BaseLeafComponent.prototype.onContextChange = function () {
2269
- if (!this.initialized) {
2270
- return;
2271
- }
2272
- this.cdr.markForCheck();
2273
- };
2274
- BaseLeafComponent.prototype.renderPlaceholder = function () {
2275
- // issue-1: IME input was interrupted
2276
- // issue-2: IME input focus jumping
2277
- // Issue occurs when the span node of the placeholder is before the slateString span node
2278
- if (this.context.leaf['placeholder']) {
2279
- if (!this.placeholderElement) {
2280
- this.placeholderElement = document.createElement('span');
2281
- this.placeholderElement.innerText = this.context.leaf['placeholder'];
2282
- this.placeholderElement.contentEditable = 'false';
2283
- this.placeholderElement.setAttribute('data-slate-placeholder', 'true');
2284
- this.nativeElement.classList.add('leaf-with-placeholder');
2285
- this.nativeElement.appendChild(this.placeholderElement);
2286
- }
2287
- }
2288
- else {
2289
- this.destroyPlaceholder();
2290
- }
2291
- };
2292
- BaseLeafComponent.prototype.destroyPlaceholder = function () {
2293
- if (this.placeholderElement) {
2294
- this.placeholderElement.remove();
2295
- this.placeholderElement = null;
2296
- this.nativeElement.classList.remove('leaf-with-placeholder');
2297
- }
2298
- };
2299
- return BaseLeafComponent;
2300
- }(BaseComponent));
2301
- BaseLeafComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseLeafComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Directive });
2302
- BaseLeafComponent.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: BaseLeafComponent, host: { properties: { "attr.data-slate-leaf": "this.isSlateLeaf" } }, usesInheritance: true, ngImport: i0__namespace });
2303
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseLeafComponent, decorators: [{
2304
- type: i0.Directive
2305
- }], propDecorators: { isSlateLeaf: [{
2306
- type: i0.HostBinding,
2307
- args: ['attr.data-slate-leaf']
2308
- }] } });
2309
- /**
2310
- * base class for custom element component
2311
- */
2312
- var BaseElementComponent = /** @class */ (function (_super) {
2313
- __extends(BaseElementComponent, _super);
2314
- function BaseElementComponent() {
2315
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
2316
- _this.initialized = false;
2317
- return _this;
2318
- }
2319
- Object.defineProperty(BaseElementComponent.prototype, "element", {
2320
- get: function () {
2321
- return this._context && this._context.element;
2322
- },
2323
- enumerable: false,
2324
- configurable: true
2325
- });
2326
- Object.defineProperty(BaseElementComponent.prototype, "selection", {
2327
- get: function () {
2328
- return this._context && this._context.selection;
2329
- },
2330
- enumerable: false,
2331
- configurable: true
2332
- });
2333
- Object.defineProperty(BaseElementComponent.prototype, "decorations", {
2334
- get: function () {
2335
- return this._context && this._context.decorations;
2336
- },
2337
- enumerable: false,
2338
- configurable: true
2339
- });
2340
- Object.defineProperty(BaseElementComponent.prototype, "children", {
2341
- get: function () {
2342
- return this._context && this._context.element.children;
2343
- },
2344
- enumerable: false,
2345
- configurable: true
2346
- });
2347
- Object.defineProperty(BaseElementComponent.prototype, "isCollapsed", {
2348
- get: function () {
2349
- return this.selection && slate.Range.isCollapsed(this.editor.selection);
2350
- },
2351
- enumerable: false,
2352
- configurable: true
2353
- });
2354
- Object.defineProperty(BaseElementComponent.prototype, "readonly", {
2355
- get: function () {
2356
- return this._context && this._context.readonly;
2357
- },
2358
- enumerable: false,
2359
- configurable: true
2360
- });
2361
- BaseElementComponent.prototype.ngOnInit = function () {
2362
- this.updateWeakMap();
2363
- for (var key in this._context.attributes) {
2364
- this.nativeElement.setAttribute(key, this._context.attributes[key]);
2365
- }
2366
- this.initialized = true;
2367
- };
2368
- BaseElementComponent.prototype.updateWeakMap = function () {
2369
- NODE_TO_ELEMENT.set(this.element, this.nativeElement);
2370
- ELEMENT_TO_NODE.set(this.nativeElement, this.element);
2371
- ELEMENT_TO_COMPONENT.set(this.element, this);
2372
- };
2373
- BaseElementComponent.prototype.ngOnDestroy = function () {
2374
- if (NODE_TO_ELEMENT.get(this.element) === this.nativeElement) {
2375
- NODE_TO_ELEMENT.delete(this.element);
2376
- }
2377
- if (ELEMENT_TO_COMPONENT.get(this.element) === this) {
2378
- ELEMENT_TO_COMPONENT.delete(this.element);
2379
- }
2380
- };
2381
- BaseElementComponent.prototype.onContextChange = function () {
2382
- this.childrenContext = this.getChildrenContext();
2383
- if (!this.initialized) {
2384
- return;
2385
- }
2386
- this.cdr.markForCheck();
2387
- this.updateWeakMap();
2388
- };
2389
- BaseElementComponent.prototype.getChildrenContext = function () {
2390
- return {
2391
- parent: this._context.element,
2392
- selection: this._context.selection,
2393
- decorations: this._context.decorations,
2394
- decorate: this._context.decorate,
2395
- readonly: this._context.readonly
2396
- };
2397
- };
2398
- return BaseElementComponent;
2399
- }(BaseComponent));
2400
- BaseElementComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseElementComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Directive });
2401
- BaseElementComponent.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: BaseElementComponent, usesInheritance: true, ngImport: i0__namespace });
2402
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseElementComponent, decorators: [{
2403
- type: i0.Directive
2404
- }] });
2405
- /**
2406
- * base class for custom text component
2407
- */
2408
- var BaseTextComponent = /** @class */ (function (_super) {
2409
- __extends(BaseTextComponent, _super);
2410
- function BaseTextComponent() {
2411
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
2412
- _this.initialized = false;
2413
- return _this;
2414
- }
2415
- Object.defineProperty(BaseTextComponent.prototype, "text", {
2416
- get: function () {
2417
- return this._context && this._context.text;
2418
- },
2419
- enumerable: false,
2420
- configurable: true
2421
- });
2422
- BaseTextComponent.prototype.ngOnInit = function () {
2423
- this.updateWeakMap();
2424
- this.initialized = true;
2425
- };
2426
- BaseTextComponent.prototype.updateWeakMap = function () {
2427
- ELEMENT_TO_NODE.set(this.nativeElement, this.text);
2428
- NODE_TO_ELEMENT.set(this.text, this.nativeElement);
2429
- };
2430
- BaseTextComponent.prototype.ngOnDestroy = function () {
2431
- if (NODE_TO_ELEMENT.get(this.text) === this.nativeElement) {
2432
- NODE_TO_ELEMENT.delete(this.text);
2433
- }
2434
- };
2435
- BaseTextComponent.prototype.onContextChange = function () {
2436
- if (!this.initialized) {
2437
- return;
2438
- }
2439
- this.cdr.markForCheck();
2440
- this.updateWeakMap();
2441
- };
2442
- return BaseTextComponent;
2443
- }(BaseComponent));
2444
- BaseTextComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseTextComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Directive });
2445
- BaseTextComponent.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: BaseTextComponent, usesInheritance: true, ngImport: i0__namespace });
2446
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: BaseTextComponent, decorators: [{
2447
- type: i0.Directive
2448
- }] });
2449
-
2450
- /**
2451
- * the sepcial container for angular template
2452
- * Add the rootNodes of each child component to the parentElement
2453
- * Remove useless DOM elements, eg: comment...
2454
- */
2455
- var ViewContainer = /** @class */ (function () {
2456
- function ViewContainer(elementRef, differs) {
2457
- this.elementRef = elementRef;
2458
- this.differs = differs;
2459
- }
2460
- ViewContainer.prototype.ngAfterViewInit = function () {
2461
- var _this = this;
2462
- var differ = this.differs.find(this.childrenComponent).create(function (index, item) {
2463
- return item;
2464
- });
2465
- // first diff
2466
- differ.diff(this.childrenComponent);
2467
- var parentElement = this.elementRef.nativeElement.parentElement;
2468
- if (this.childrenComponent.length > 0) {
2469
- parentElement.insertBefore(this.createFragment(), this.elementRef.nativeElement);
2470
- this.elementRef.nativeElement.remove();
2471
- }
2472
- this.childrenComponent.changes.subscribe(function (value) {
2473
- var iterableChanges = differ.diff(_this.childrenComponent);
2474
- if (iterableChanges) {
2475
- iterableChanges.forEachOperation(function (record, previousIndex, currentIndex) {
2476
- // removed
2477
- if (currentIndex === null) {
2478
- return;
2479
- }
2480
- // added or moved
2481
- _this.handleContainerItemChange(record, parentElement);
2482
- });
2483
- }
2484
- });
2485
- };
2486
- ViewContainer.prototype.getPreviousRootNode = function (currentIndex) {
2487
- if (currentIndex === 0) {
2488
- return null;
2489
- }
2490
- var previousComponent = this.childrenComponent.find(function (item, index) { return index === currentIndex - 1; });
2491
- var previousRootNode = previousComponent.rootNodes[previousComponent.rootNodes.length - 1];
2492
- if (previousRootNode) {
2493
- return previousRootNode;
2494
- }
2495
- else {
2496
- return this.getPreviousRootNode(currentIndex - 1);
2497
- }
2498
- };
2499
- ViewContainer.prototype.createFragment = function () {
2500
- var fragment = document.createDocumentFragment();
2501
- this.childrenComponent.forEach(function (component, index) {
2502
- fragment.append.apply(fragment, __spreadArray([], __read(component.rootNodes)));
2503
- });
2504
- return fragment;
2505
- };
2506
- ViewContainer.prototype.handleContainerItemChange = function (record, parentElement) {
2507
- // first insert
2508
- if (this.elementRef.nativeElement.parentElement && this.elementRef.nativeElement.parentElement === parentElement) {
2509
- var fragment = document.createDocumentFragment();
2510
- fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
2511
- parentElement.insertBefore(fragment, this.elementRef.nativeElement);
2512
- this.elementRef.nativeElement.remove();
2513
- return;
2514
- }
2515
- // insert at start location
2516
- if (record.currentIndex === 0) {
2517
- var fragment = document.createDocumentFragment();
2518
- fragment.append.apply(fragment, __spreadArray([], __read(record.item.rootNodes)));
2519
- parentElement.prepend(fragment);
2520
- }
2521
- else {
2522
- // insert afterend of previous component end
2523
- var previousRootNode_1 = this.getPreviousRootNode(record.currentIndex);
2524
- if (previousRootNode_1) {
2525
- record.item.rootNodes.forEach(function (rootNode) {
2526
- previousRootNode_1.insertAdjacentElement('afterend', rootNode);
2527
- previousRootNode_1 = rootNode;
2528
- });
2529
- }
2530
- else {
2531
- this.viewContext.editor.onError({
2532
- code: exports.SlateErrorCode.NotFoundPreviousRootNodeError,
2533
- name: 'not found previous rootNode',
2534
- nativeError: null
2535
- });
2536
- }
2537
- }
2538
- // Solve the block-card DOMElement loss when moving nodes
2539
- record.item.appendBlockCardElement();
2540
- };
2541
- return ViewContainer;
2542
- }());
2543
- ViewContainer.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: ViewContainer, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.IterableDiffers }], target: i0__namespace.ɵɵFactoryTarget.Directive });
2544
- ViewContainer.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: ViewContainer, inputs: { viewContext: "viewContext" }, ngImport: i0__namespace });
2545
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: ViewContainer, decorators: [{
2546
- type: i0.Directive
2547
- }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.IterableDiffers }]; }, propDecorators: { viewContext: [{
2548
- type: i0.Input
2549
- }] } });
2550
-
2551
- var SlateStringComponent = /** @class */ (function (_super) {
2552
- __extends(SlateStringComponent, _super);
2553
- function SlateStringComponent(elementRef, viewContainerRef) {
2554
- var _this = _super.call(this, viewContainerRef, null) || this;
2555
- _this.elementRef = elementRef;
2556
- _this.viewContainerRef = viewContainerRef;
2557
- return _this;
2558
- }
2559
- SlateStringComponent.prototype.ngOnInit = function () {
2560
- this.createView();
2561
- };
2562
- SlateStringComponent.prototype.ngOnChanges = function () {
2563
- if (!this.initialized) {
2564
- return;
2565
- }
2566
- this.updateView();
2567
- };
2568
- SlateStringComponent.prototype.ngAfterViewInit = function () {
2569
- this.elementRef.nativeElement.remove();
2570
- };
2571
- SlateStringComponent.prototype.getViewType = function () {
2572
- var path = AngularEditor.findPath(this.viewContext.editor, this.context.text);
2573
- var parentPath = slate.Path.parent(path);
2574
- // COMPAT: Render text inside void nodes with a zero-width space.
2575
- // So the node can contain selection but the text is not visible.
2576
- if (this.viewContext.editor.isVoid(this.context.parent)) {
2577
- return this.viewContext.templateComponent.emptyStringTemplate;
2578
- }
2579
- // COMPAT: If this is the last text node in an empty block, render a zero-
2580
- // width space that will convert into a line break when copying and pasting
2581
- // to support expected plain text.
2582
- if (this.context.leaf.text === '' &&
2583
- this.context.parent.children[this.context.parent.children.length - 1] === this.context.text &&
2584
- !this.viewContext.editor.isInline(this.context.parent) &&
2585
- slate.Editor.string(this.viewContext.editor, parentPath) === '') {
2586
- return this.viewContext.templateComponent.lineBreakEmptyStringTemplate;
2587
- }
2588
- // COMPAT: If the text is empty, it's because it's on the edge of an inline
2589
- // node, so we render a zero-width space so that the selection can be
2590
- // inserted next to it still.
2591
- if (this.context.leaf.text === '') {
2592
- return this.viewContext.templateComponent.emptyTextTemplate;
2593
- }
2594
- // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
2595
- // so we need to add an extra trailing new lines to prevent that.
2596
- if (this.context.isLast && this.context.leaf.text.slice(-1) === '\n') {
2597
- return this.viewContext.templateComponent.compatStringTemplate;
2598
- }
2599
- return this.viewContext.templateComponent.stringTemplate;
2600
- };
2601
- SlateStringComponent.prototype.getContext = function () {
2602
- return { text: this.context.leaf.text, elementStringLength: slate.Node.string(this.context.parent).length };
2603
- };
2604
- SlateStringComponent.prototype.memoizedContext = function (prev, next) {
2605
- return false;
2606
- };
2607
- return SlateStringComponent;
2608
- }(ViewContainerItem));
2609
- SlateStringComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateStringComponent, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.ViewContainerRef }], target: i0__namespace.ɵɵFactoryTarget.Component });
2610
- SlateStringComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateStringComponent, selector: "span[slateString]", inputs: { context: "context" }, usesInheritance: true, usesOnChanges: true, ngImport: i0__namespace, template: '', isInline: true, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
2611
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateStringComponent, decorators: [{
2612
- type: i0.Component,
2613
- args: [{
2614
- selector: 'span[slateString]',
2615
- template: '',
2616
- changeDetection: i0.ChangeDetectionStrategy.OnPush
2617
- }]
2618
- }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.ViewContainerRef }]; }, propDecorators: { context: [{
2619
- type: i0.Input
2620
- }] } });
2621
-
2622
- var SlateDefaultLeafComponent = /** @class */ (function (_super) {
2623
- __extends(SlateDefaultLeafComponent, _super);
2624
- function SlateDefaultLeafComponent() {
2625
- return _super !== null && _super.apply(this, arguments) || this;
2626
- }
2627
- SlateDefaultLeafComponent.prototype.onContextChange = function () {
2628
- _super.prototype.onContextChange.call(this);
2629
- this.renderPlaceholder();
2630
- };
2631
- SlateDefaultLeafComponent.prototype.ngOnDestroy = function () {
2632
- // Because the placeholder span is not in the current component, it is destroyed along with the current component
2633
- this.destroyPlaceholder();
2634
- };
2635
- return SlateDefaultLeafComponent;
2636
- }(BaseLeafComponent));
2637
- SlateDefaultLeafComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultLeafComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
2638
- SlateDefaultLeafComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateDefaultLeafComponent, selector: "span[slateDefaultLeaf]", host: { attributes: { "data-slate-leaf": "true" } }, usesInheritance: true, ngImport: i0__namespace, template: "<span slateString [context]=\"context\" [viewContext]=\"viewContext\"><span>", isInline: true, components: [{ type: SlateStringComponent, selector: "span[slateString]", inputs: ["context"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
2639
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultLeafComponent, decorators: [{
2640
- type: i0.Component,
2641
- args: [{
2642
- selector: 'span[slateDefaultLeaf]',
2643
- template: "<span slateString [context]=\"context\" [viewContext]=\"viewContext\"><span>",
2644
- changeDetection: i0.ChangeDetectionStrategy.OnPush,
2645
- host: {
2646
- 'data-slate-leaf': 'true'
2647
- }
2648
- }]
2649
- }] });
2650
-
2651
- var SlateLeafComponent = /** @class */ (function (_super) {
2652
- __extends(SlateLeafComponent, _super);
2653
- function SlateLeafComponent() {
2654
- return _super !== null && _super.apply(this, arguments) || this;
2655
- }
2656
- SlateLeafComponent.prototype.ngOnInit = function () {
2657
- this.createView();
2658
- };
2659
- SlateLeafComponent.prototype.getContext = function () {
2660
- return this.context;
2661
- };
2662
- SlateLeafComponent.prototype.getViewType = function () {
2663
- return this.viewContext.renderLeaf && this.viewContext.renderLeaf(this.context.leaf) || SlateDefaultLeafComponent;
2664
- };
2665
- SlateLeafComponent.prototype.memoizedContext = function (prev, next) {
2666
- return false;
2667
- };
2668
- SlateLeafComponent.prototype.ngOnChanges = function (simpleChanges) {
2669
- if (!this.initialized) {
2670
- return;
2671
- }
2672
- this.updateView();
2673
- };
2674
- return SlateLeafComponent;
2675
- }(ViewContainerItem));
2676
- SlateLeafComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateLeafComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
2677
- SlateLeafComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateLeafComponent, selector: "slate-leaf", inputs: { context: "context" }, usesInheritance: true, usesOnChanges: true, ngImport: i0__namespace, template: '', isInline: true, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
2678
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateLeafComponent, decorators: [{
2679
- type: i0.Component,
2680
- args: [{
2681
- selector: 'slate-leaf',
2682
- template: '',
2683
- changeDetection: i0.ChangeDetectionStrategy.OnPush,
2684
- }]
2685
- }], propDecorators: { context: [{
2686
- type: i0.Input
2687
- }] } });
2688
-
2689
- var SlateLeavesComponent = /** @class */ (function (_super) {
2690
- __extends(SlateLeavesComponent, _super);
2691
- function SlateLeavesComponent() {
2692
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
2693
- _this.initialized = false;
2694
- return _this;
2695
- }
2696
- SlateLeavesComponent.prototype.ngOnInit = function () {
2697
- this.leaves = slate.Text.decorations(this.context.text, this.context.decorations);
2698
- this.leafContexts = this.getLeafCotexts();
2699
- this.initialized = true;
2700
- };
2701
- SlateLeavesComponent.prototype.getLeafCotexts = function () {
2702
- var _this = this;
2703
- return this.leaves.map(function (leaf, index) {
2704
- return {
2705
- leaf: leaf,
2706
- text: _this.context.text,
2707
- parent: _this.context.parent,
2708
- index: index,
2709
- isLast: _this.context.isLast && index === _this.leaves.length - 1
2710
- };
2711
- });
2712
- };
2713
- SlateLeavesComponent.prototype.ngOnChanges = function (simpleChanges) {
2714
- if (!this.initialized) {
2715
- return;
2716
- }
2717
- var context = simpleChanges['context'];
2718
- var previousValue = context.previousValue;
2719
- var currentValue = context.currentValue;
2720
- if (previousValue.text !== currentValue.text || !isDecoratorRangeListEqual(previousValue.decorations, currentValue.decorations)) {
2721
- this.leaves = slate.Text.decorations(this.context.text, this.context.decorations);
2722
- }
2723
- this.leafContexts = this.getLeafCotexts();
2724
- };
2725
- SlateLeavesComponent.prototype.trackBy = function (index, item) {
2726
- return index;
2727
- };
2728
- return SlateLeavesComponent;
2729
- }(ViewContainer));
2730
- SlateLeavesComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateLeavesComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
2731
- SlateLeavesComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateLeavesComponent, selector: "slate-leaves", inputs: { context: "context" }, viewQueries: [{ propertyName: "childrenComponent", predicate: SlateLeafComponent, descendants: true, read: SlateLeafComponent }], usesInheritance: true, usesOnChanges: true, ngImport: i0__namespace, template: "<slate-leaf\n [context]=\"context\" [viewContext]=\"viewContext\"\n [viewContext]=\"viewContext\"\n *ngFor=\"let context of leafContexts; trackBy: trackBy\"></slate-leaf>\n ", isInline: true, components: [{ type: SlateLeafComponent, selector: "slate-leaf", inputs: ["context"] }], directives: [{ type: i2__namespace.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
2732
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateLeavesComponent, decorators: [{
2733
- type: i0.Component,
2734
- args: [{
2735
- selector: 'slate-leaves',
2736
- template: "<slate-leaf\n [context]=\"context\" [viewContext]=\"viewContext\"\n [viewContext]=\"viewContext\"\n *ngFor=\"let context of leafContexts; trackBy: trackBy\"></slate-leaf>\n ",
2737
- changeDetection: i0.ChangeDetectionStrategy.OnPush
2738
- }]
2739
- }], propDecorators: { context: [{
2740
- type: i0.Input
2741
- }], childrenComponent: [{
2742
- type: i0.ViewChildren,
2743
- args: [SlateLeafComponent, { read: SlateLeafComponent }]
2744
- }] } });
2745
-
2746
- var SlateDefaultTextComponent = /** @class */ (function (_super) {
2747
- __extends(SlateDefaultTextComponent, _super);
2748
- function SlateDefaultTextComponent() {
2749
- return _super !== null && _super.apply(this, arguments) || this;
2750
- }
2751
- return SlateDefaultTextComponent;
2752
- }(BaseTextComponent));
2753
- SlateDefaultTextComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultTextComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
2754
- SlateDefaultTextComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateDefaultTextComponent, selector: "span[slateDefaultText]", host: { attributes: { "data-slate-node": "text" } }, usesInheritance: true, ngImport: i0__namespace, template: "<slate-leaves [context]=\"context\" [viewContext]=\"viewContext\" [viewContext]=\"viewContext\"></slate-leaves>", isInline: true, components: [{ type: SlateLeavesComponent, selector: "slate-leaves", inputs: ["context"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
2755
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultTextComponent, decorators: [{
2756
- type: i0.Component,
2757
- args: [{
2758
- selector: 'span[slateDefaultText]',
2759
- template: "<slate-leaves [context]=\"context\" [viewContext]=\"viewContext\" [viewContext]=\"viewContext\"></slate-leaves>",
2760
- changeDetection: i0.ChangeDetectionStrategy.OnPush,
2761
- host: {
2762
- 'data-slate-node': 'text'
2763
- }
2764
- }]
2765
- }] });
2766
-
2767
- var SlateVoidTextComponent = /** @class */ (function (_super) {
2768
- __extends(SlateVoidTextComponent, _super);
2769
- function SlateVoidTextComponent() {
2770
- return _super !== null && _super.apply(this, arguments) || this;
2771
- }
2772
- SlateVoidTextComponent.prototype.ngOnInit = function () {
2773
- this.isLeafBlock = AngularEditor.isLeafBlock(this.viewContext.editor, this.context.parent);
2774
- _super.prototype.ngOnInit.call(this);
2775
- };
2776
- SlateVoidTextComponent.prototype.ngOnChanges = function () {
2777
- if (!this.initialized) {
2778
- return;
2779
- }
2780
- this.isLeafBlock = AngularEditor.isLeafBlock(this.viewContext.editor, this.context.parent);
2781
- };
2782
- return SlateVoidTextComponent;
2783
- }(BaseTextComponent));
2784
- SlateVoidTextComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateVoidTextComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
2785
- SlateVoidTextComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateVoidTextComponent, selector: "span[slateVoidText]", host: { attributes: { "data-slate-spacer": "true", "data-slate-node": "text" }, properties: { "attr.contenteditable": "isLeafBlock" }, classAttribute: "slate-spacer" }, usesInheritance: true, usesOnChanges: true, ngImport: i0__namespace, template: "<slate-leaves [context]=\"context\" [viewContext]=\"viewContext\" [viewContext]=\"viewContext\"></slate-leaves>", isInline: true, components: [{ type: SlateLeavesComponent, selector: "slate-leaves", inputs: ["context"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
2786
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateVoidTextComponent, decorators: [{
2787
- type: i0.Component,
2788
- args: [{
2789
- selector: 'span[slateVoidText]',
2790
- template: "<slate-leaves [context]=\"context\" [viewContext]=\"viewContext\" [viewContext]=\"viewContext\"></slate-leaves>",
2791
- changeDetection: i0.ChangeDetectionStrategy.OnPush,
2792
- host: {
2793
- '[attr.contenteditable]': 'isLeafBlock',
2794
- 'data-slate-spacer': "true",
2795
- 'class': 'slate-spacer',
2796
- 'data-slate-node': 'text'
2797
- }
2798
- }]
2799
- }] });
2800
-
2801
- var SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN = new i0.InjectionToken('slate-default-element-token');
2802
-
2803
- var SlateDescendantComponent = /** @class */ (function (_super) {
2804
- __extends(SlateDescendantComponent, _super);
2805
- function SlateDescendantComponent(viewContainerRef, componentFactoryResolver, defaultElementComponentType) {
2806
- var _this = _super.call(this, viewContainerRef, componentFactoryResolver) || this;
2807
- _this.viewContainerRef = viewContainerRef;
2808
- _this.componentFactoryResolver = componentFactoryResolver;
2809
- _this.defaultElementComponentType = defaultElementComponentType;
2810
- return _this;
2811
- }
2812
- Object.defineProperty(SlateDescendantComponent.prototype, "rootNodes", {
2813
- get: function () {
2814
- if (this.blockCardComponentRef) {
2815
- return [this.blockCardComponentRef.instance.nativeElement];
2816
- }
2817
- return _super.prototype.getRootNodes.call(this);
2818
- },
2819
- enumerable: false,
2820
- configurable: true
2821
- });
2822
- Object.defineProperty(SlateDescendantComponent.prototype, "isBlockCard", {
2823
- get: function () {
2824
- return this.viewContext.editor.isBlockCard(this.descendant);
2825
- },
2826
- enumerable: false,
2827
- configurable: true
2828
- });
2829
- SlateDescendantComponent.prototype.ngOnInit = function () {
2830
- NODE_TO_INDEX.set(this.descendant, this.index);
2831
- NODE_TO_PARENT.set(this.descendant, this.context.parent);
2832
- this.createView();
2833
- if (this.isBlockCard) {
2834
- this.createBlockCard();
2835
- }
2836
- };
2837
- SlateDescendantComponent.prototype.destroyView = function () {
2838
- _super.prototype.destroyView.call(this);
2839
- this.destroyBlockCard();
2840
- };
2841
- SlateDescendantComponent.prototype.ngOnChanges = function () {
2842
- if (!this.initialized) {
2843
- return;
2844
- }
2845
- NODE_TO_INDEX.set(this.descendant, this.index);
2846
- NODE_TO_PARENT.set(this.descendant, this.context.parent);
2847
- this.updateView();
2848
- if (this.isBlockCard) {
2849
- this.updateBlockCard();
2850
- }
2851
- };
2852
- SlateDescendantComponent.prototype.destroyBlockCard = function () {
2853
- if (this.blockCardComponentRef) {
2854
- this.blockCardComponentRef.destroy();
2855
- this.blockCardComponentRef = null;
2856
- }
2857
- };
2858
- SlateDescendantComponent.prototype.createBlockCard = function () {
2859
- var rootNodes = this.rootNodes;
2860
- var componentFactory = this.componentFactoryResolver.resolveComponentFactory(SlateBlockCardComponent);
2861
- this.blockCardComponentRef = this.viewContainerRef.createComponent(componentFactory, null, null);
2862
- this.blockCardComponentRef.instance.initializeCenter(rootNodes);
2863
- };
2864
- SlateDescendantComponent.prototype.updateBlockCard = function () {
2865
- if (this.blockCardComponentRef) {
2866
- return;
2867
- }
2868
- var rootNodes = this.rootNodes;
2869
- this.createBlockCard();
2870
- var firstRootNode = rootNodes[0];
2871
- firstRootNode.replaceWith(this.blockCardComponentRef.instance.nativeElement);
2872
- };
2873
- SlateDescendantComponent.prototype.getCommonContext = function () {
2874
- var e_1, _a;
2875
- var path = AngularEditor.findPath(this.viewContext.editor, this.context.parent);
2876
- var p = path.concat(this.index);
2877
- try {
2878
- var range = slate.Editor.range(this.viewContext.editor, p);
2879
- var sel = this.context.selection && slate.Range.intersection(range, this.context.selection);
2880
- var ds = this.context.decorate([this.descendant, p]);
2881
- try {
2882
- for (var _b = __values(this.context.decorations), _c = _b.next(); !_c.done; _c = _b.next()) {
2883
- var dec = _c.value;
2884
- var d = slate.Range.intersection(dec, range);
2885
- if (d) {
2886
- ds.push(d);
2887
- }
2888
- }
2889
- }
2890
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2891
- finally {
2892
- try {
2893
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2894
- }
2895
- finally { if (e_1) throw e_1.error; }
2896
- }
2897
- return { selection: sel, decorations: ds };
2898
- }
2899
- catch (error) {
2900
- this.viewContext.editor.onError({ code: exports.SlateErrorCode.GetStartPointError, nativeError: error });
2901
- return { selection: null, decorations: [] };
2902
- }
2903
- };
2904
- SlateDescendantComponent.prototype.getContext = function () {
2905
- if (slate.Element.isElement(this.descendant)) {
2906
- var computedContext = this.getCommonContext();
2907
- var key = AngularEditor.findKey(this.viewContext.editor, this.descendant);
2908
- var isInline = this.viewContext.editor.isInline(this.descendant);
2909
- var isVoid = this.viewContext.editor.isVoid(this.descendant);
2910
- var elementContext = Object.assign(Object.assign({ element: this.descendant }, computedContext), { attributes: {
2911
- 'data-slate-node': 'element',
2912
- 'data-slate-key': key.id
2913
- }, decorate: this.context.decorate, readonly: this.context.readonly });
2914
- if (isInline) {
2915
- elementContext.attributes['data-slate-inline'] = true;
2916
- }
2917
- if (isVoid) {
2918
- elementContext.attributes['data-slate-void'] = true;
2919
- elementContext.attributes.contenteditable = false;
2920
- }
2921
- return elementContext;
2922
- }
2923
- else {
2924
- var computedContext = this.getCommonContext();
2925
- var isLeafBlock = AngularEditor.isLeafBlock(this.viewContext.editor, this.context.parent);
2926
- var textContext = {
2927
- decorations: computedContext.decorations,
2928
- isLast: isLeafBlock && this.index === this.context.parent.children.length - 1,
2929
- parent: this.context.parent,
2930
- text: this.descendant
2931
- };
2932
- return textContext;
2933
- }
2934
- };
2935
- SlateDescendantComponent.prototype.getViewType = function () {
2936
- if (slate.Element.isElement(this.descendant)) {
2937
- return (this.viewContext.renderElement && this.viewContext.renderElement(this.descendant)) || this.defaultElementComponentType;
2938
- }
2939
- else {
2940
- var isVoid = this.viewContext.editor.isVoid(this.context.parent);
2941
- return isVoid ? SlateVoidTextComponent : (this.viewContext.renderText && this.viewContext.renderText(this.descendant)) || SlateDefaultTextComponent;
2942
- }
2943
- };
2944
- SlateDescendantComponent.prototype.memoizedElementContext = function (prev, next) {
2945
- return (prev.element === next.element &&
2946
- (!this.viewContext.isStrictDecorate || prev.decorate === next.decorate) &&
2947
- prev.readonly === next.readonly &&
2948
- isDecoratorRangeListEqual(prev.decorations, next.decorations) &&
2949
- (prev.selection === next.selection ||
2950
- (!!prev.selection &&
2951
- !!next.selection &&
2952
- slate.Range.equals(prev.selection, next.selection))));
2953
- };
2954
- SlateDescendantComponent.prototype.memoizedTextContext = function (prev, next) {
2955
- return (next.parent === prev.parent &&
2956
- next.isLast === prev.isLast &&
2957
- next.text === prev.text &&
2958
- isDecoratorRangeListEqual(next.decorations, prev.decorations));
2959
- };
2960
- SlateDescendantComponent.prototype.memoizedContext = function (prev, next) {
2961
- if (slate.Element.isElement(this.descendant)) {
2962
- return this.memoizedElementContext(prev, next);
2963
- }
2964
- else {
2965
- return this.memoizedTextContext(prev, next);
2966
- }
2967
- };
2968
- return SlateDescendantComponent;
2969
- }(ViewContainerItem));
2970
- SlateDescendantComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDescendantComponent, deps: [{ token: i0__namespace.ViewContainerRef }, { token: i0__namespace.ComponentFactoryResolver }, { token: SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN }], target: i0__namespace.ɵɵFactoryTarget.Component });
2971
- SlateDescendantComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateDescendantComponent, selector: "slate-descendant", inputs: { descendant: "descendant", context: "context", viewContext: "viewContext", index: "index" }, usesInheritance: true, usesOnChanges: true, ngImport: i0__namespace, template: '', isInline: true, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
2972
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDescendantComponent, decorators: [{
2973
- type: i0.Component,
2974
- args: [{
2975
- selector: 'slate-descendant',
2976
- template: '',
2977
- changeDetection: i0.ChangeDetectionStrategy.OnPush
2978
- }]
2979
- }], ctorParameters: function () {
2980
- return [{ type: i0__namespace.ViewContainerRef }, { type: i0__namespace.ComponentFactoryResolver }, { type: undefined, decorators: [{
2981
- type: i0.Inject,
2982
- args: [SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN]
2983
- }] }];
2984
- }, propDecorators: { descendant: [{
2985
- type: i0.Input
2986
- }], context: [{
2987
- type: i0.Input
2988
- }], viewContext: [{
2989
- type: i0.Input
2990
- }], index: [{
2991
- type: i0.Input
2992
- }] } });
2993
-
2994
- var SlateChildrenComponent = /** @class */ (function (_super) {
2995
- __extends(SlateChildrenComponent, _super);
2996
- function SlateChildrenComponent() {
2997
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
2998
- _this.trackBy = function (index, node) {
2999
- return _this.viewContext.trackBy(node) || AngularEditor.findKey(_this.viewContext.editor, node);
3000
- };
3001
- return _this;
3002
- }
3003
- SlateChildrenComponent.prototype.ngOnInit = function () {
3004
- };
3005
- return SlateChildrenComponent;
3006
- }(ViewContainer));
3007
- SlateChildrenComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateChildrenComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
3008
- SlateChildrenComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateChildrenComponent, selector: "slate-children", inputs: { children: "children", context: "context", viewContext: "viewContext" }, viewQueries: [{ propertyName: "childrenComponent", predicate: SlateDescendantComponent, descendants: true, read: SlateDescendantComponent }], usesInheritance: true, ngImport: i0__namespace, template: "<slate-descendant \n [descendant]=\"descendant\"\n [context]=\"context\" [viewContext]=\"viewContext\"\n [viewContext]=\"viewContext\"\n [index]=\"index\"\n *ngFor=\"let descendant of children;let index = index; trackBy: trackBy\"></slate-descendant>", isInline: true, components: [{ type: SlateDescendantComponent, selector: "slate-descendant", inputs: ["descendant", "context", "viewContext", "index"] }], directives: [{ type: i2__namespace.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
3009
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateChildrenComponent, decorators: [{
3010
- type: i0.Component,
3011
- args: [{
3012
- selector: 'slate-children',
3013
- template: "<slate-descendant \n [descendant]=\"descendant\"\n [context]=\"context\" [viewContext]=\"viewContext\"\n [viewContext]=\"viewContext\"\n [index]=\"index\"\n *ngFor=\"let descendant of children;let index = index; trackBy: trackBy\"></slate-descendant>",
3014
- changeDetection: i0.ChangeDetectionStrategy.OnPush
3015
- }]
3016
- }], propDecorators: { children: [{
3017
- type: i0.Input
3018
- }], context: [{
3019
- type: i0.Input
3020
- }], viewContext: [{
3021
- type: i0.Input
3022
- }], childrenComponent: [{
3023
- type: i0.ViewChildren,
3024
- args: [SlateDescendantComponent, { read: SlateDescendantComponent }]
3025
- }] } });
3026
-
3027
- var SlateStringTemplateComponent = /** @class */ (function () {
3028
- function SlateStringTemplateComponent() {
3029
- }
3030
- return SlateStringTemplateComponent;
3031
- }());
3032
- SlateStringTemplateComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateStringTemplateComponent, deps: [], target: i0__namespace.ɵɵFactoryTarget.Component });
3033
- SlateStringTemplateComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateStringTemplateComponent, selector: "slate-string-template", viewQueries: [{ propertyName: "stringTemplate", first: true, predicate: ["stringTemplate"], descendants: true, read: i0.TemplateRef, static: true }, { propertyName: "compatStringTemplate", first: true, predicate: ["compatStringTemplate"], descendants: true, read: i0.TemplateRef, static: true }, { propertyName: "emptyStringTemplate", first: true, predicate: ["emptyStringTemplate"], descendants: true, read: i0.TemplateRef, static: true }, { propertyName: "emptyTextTemplate", first: true, predicate: ["emptyTextTemplate"], descendants: true, read: i0.TemplateRef, static: true }, { propertyName: "lineBreakEmptyStringTemplate", first: true, predicate: ["lineBreakEmptyStringTemplate"], descendants: true, read: i0.TemplateRef, static: true }], ngImport: i0__namespace, template: "<ng-template #stringTemplate let-context=\"context\" let-viewContext=\"viewContext\">\n <span editable-text data-slate-string=\"true\">{{ context.text }}</span>\n</ng-template>\n<ng-template #compatStringTemplate let-context=\"context\" let-viewContext=\"viewContext\">\n <!-- Compatible with Chinese input in Chrome with \\n -->\n <span editable-text data-slate-string=\"true\">{{ context.text }}<span data-slate-zero-width>{{'\\uFEFF'}}</span></span>\n</ng-template>\n<ng-template #emptyStringTemplate let-context=\"context\" let-viewContext=\"viewContext\">\n <span editable-text data-slate-zero-width=\"z\" attr.data-slate-length=\"{{ context.elementStringLength }}\">{{ '\\uFEFF' }}</span>\n</ng-template>\n<ng-template #emptyTextTemplate let-context=\"context\" let-viewContext=\"viewContext\">\n <span editable-text data-slate-zero-width=\"z\" data-slate-length=\"0\">{{ '\\uFEFF' }}</span>\n</ng-template>\n<ng-template #lineBreakEmptyStringTemplate let-context=\"context\" let-viewContext=\"viewContext\">\n <span editable-text data-slate-zero-width=\"n\" attr.data-slate-length=\"{{ context.elementStringLength }}\">{{ '\\uFEFF'\n }}<br /></span>\n</ng-template>", changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
3034
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateStringTemplateComponent, decorators: [{
3035
- type: i0.Component,
3036
- args: [{
3037
- selector: 'slate-string-template',
3038
- templateUrl: 'template.component.html',
3039
- changeDetection: i0.ChangeDetectionStrategy.OnPush
3040
- }]
3041
- }], propDecorators: { stringTemplate: [{
3042
- type: i0.ViewChild,
3043
- args: ['stringTemplate', { read: i0.TemplateRef, static: true }]
3044
- }], compatStringTemplate: [{
3045
- type: i0.ViewChild,
3046
- args: ['compatStringTemplate', { read: i0.TemplateRef, static: true }]
3047
- }], emptyStringTemplate: [{
3048
- type: i0.ViewChild,
3049
- args: ['emptyStringTemplate', { read: i0.TemplateRef, static: true }]
3050
- }], emptyTextTemplate: [{
3051
- type: i0.ViewChild,
3052
- args: ['emptyTextTemplate', { read: i0.TemplateRef, static: true }]
3053
- }], lineBreakEmptyStringTemplate: [{
3054
- type: i0.ViewChild,
3055
- args: ['lineBreakEmptyStringTemplate', { read: i0.TemplateRef, static: true }]
3056
- }] } });
3057
-
3058
- var timeDebug = Debug__default["default"]('slate-angular-time');
3059
- // not correctly clipboardData on beforeinput
3060
- var forceOnDOMPaste = IS_SAFARI;
3061
- var SlateEditableComponent = /** @class */ (function () {
3062
- function SlateEditableComponent(elementRef, renderer2, cdr, ngZone, injector) {
3063
- this.elementRef = elementRef;
3064
- this.renderer2 = renderer2;
3065
- this.cdr = cdr;
3066
- this.ngZone = ngZone;
3067
- this.injector = injector;
3068
- this.destroy$ = new rxjs.Subject();
3069
- this.isComposing = false;
3070
- this.isDraggingInternally = false;
3071
- this.isUpdatingSelection = false;
3072
- this.latestElement = null;
3073
- this.manualListeners = [];
3074
- this.onTouchedCallback = function () { };
3075
- this.onChangeCallback = function () { };
3076
- this.decorate = function () { return []; };
3077
- this.isStrictDecorate = true;
3078
- this.trackBy = function () { return null; };
3079
- this.readonly = false;
3080
- //#endregion
3081
- //#region DOM attr
3082
- this.spellCheck = false;
3083
- this.autoCorrect = false;
3084
- this.autoCapitalize = false;
3085
- this.dataSlateEditor = true;
3086
- this.dataSlateNode = 'value';
3087
- this.dataGramm = false;
3088
- }
3089
- Object.defineProperty(SlateEditableComponent.prototype, "hasBeforeInputSupport", {
3090
- get: function () {
3091
- return HAS_BEFORE_INPUT_SUPPORT;
3092
- },
3093
- enumerable: false,
3094
- configurable: true
3095
- });
3096
- SlateEditableComponent.prototype.ngOnInit = function () {
3097
- var _this = this;
3098
- this.editor.injector = this.injector;
3099
- this.editor.children = [];
3100
- var window = getDefaultView(this.elementRef.nativeElement);
3101
- EDITOR_TO_WINDOW.set(this.editor, window);
3102
- EDITOR_TO_ELEMENT.set(this.editor, this.elementRef.nativeElement);
3103
- NODE_TO_ELEMENT.set(this.editor, this.elementRef.nativeElement);
3104
- ELEMENT_TO_NODE.set(this.elementRef.nativeElement, this.editor);
3105
- IS_READONLY.set(this.editor, this.readonly);
3106
- EDITOR_TO_ON_CHANGE.set(this.editor, function () {
3107
- _this.ngZone.run(function () {
3108
- _this.onChange();
3109
- });
3110
- });
3111
- this.ngZone.runOutsideAngular(function () {
3112
- _this.initialize();
3113
- });
3114
- this.initializeViewContext();
3115
- this.initializeContext();
3116
- // remove unused DOM, just keep templateComponent instance
3117
- this.templateElementRef.nativeElement.remove();
3118
- // add browser class
3119
- var browserClass = IS_FIREFOX ? 'firefox' : (IS_SAFARI ? 'safari' : '');
3120
- browserClass && this.elementRef.nativeElement.classList.add(browserClass);
3121
- };
3122
- SlateEditableComponent.prototype.ngOnChanges = function (simpleChanges) {
3123
- if (!this.initialized) {
3124
- return;
3125
- }
3126
- var decorateChange = simpleChanges['decorate'];
3127
- if (decorateChange) {
3128
- this.forceFlush();
3129
- }
3130
- var readonlyChange = simpleChanges['readonly'];
3131
- if (readonlyChange) {
3132
- IS_READONLY.set(this.editor, this.readonly);
3133
- this.detectContext();
3134
- this.toSlateSelection();
3135
- }
3136
- };
3137
- SlateEditableComponent.prototype.registerOnChange = function (fn) {
3138
- this.onChangeCallback = fn;
3139
- };
3140
- SlateEditableComponent.prototype.registerOnTouched = function (fn) {
3141
- this.onTouchedCallback = fn;
3142
- };
3143
- SlateEditableComponent.prototype.writeValue = function (value) {
3144
- if (value && value.length) {
3145
- if (check(value)) {
3146
- this.editor.children = value;
3147
- }
3148
- else {
3149
- this.editor.onError({
3150
- code: exports.SlateErrorCode.InvalidValueError,
3151
- name: 'initialize invalid data',
3152
- data: value
3153
- });
3154
- this.editor.children = normalize(value);
3155
- }
3156
- this.initializeContext();
3157
- this.cdr.markForCheck();
3158
- }
3159
- };
3160
- SlateEditableComponent.prototype.initialize = function () {
3161
- var _this = this;
3162
- this.initialized = true;
3163
- var window = AngularEditor.getWindow(this.editor);
3164
- this.addEventListener('selectionchange', function (event) {
3165
- _this.toSlateSelection();
3166
- }, window.document);
3167
- if (HAS_BEFORE_INPUT_SUPPORT) {
3168
- this.addEventListener('beforeinput', this.onDOMBeforeInput.bind(this));
3169
- }
3170
- this.addEventListener('blur', this.onDOMBlur.bind(this));
3171
- this.addEventListener('click', this.onDOMClick.bind(this));
3172
- this.addEventListener('compositionend', this.onDOMCompositionEnd.bind(this));
3173
- this.addEventListener('compositionstart', this.onDOMCompositionStart.bind(this));
3174
- this.addEventListener('copy', this.onDOMCopy.bind(this));
3175
- this.addEventListener('cut', this.onDOMCut.bind(this));
3176
- this.addEventListener('dragover', this.onDOMDragOver.bind(this));
3177
- this.addEventListener('dragstart', this.onDOMDragStart.bind(this));
3178
- this.addEventListener('dragend', this.onDOMDragEnd.bind(this));
3179
- this.addEventListener('drop', this.onDOMDrop.bind(this));
3180
- this.addEventListener('focus', this.onDOMFocus.bind(this));
3181
- this.addEventListener('keydown', this.onDOMKeydown.bind(this));
3182
- this.addEventListener('paste', this.onDOMPaste.bind(this));
3183
- BEFORE_INPUT_EVENTS.forEach(function (event) {
3184
- _this.addEventListener(event.name, function () { });
3185
- });
3186
- };
3187
- SlateEditableComponent.prototype.toNativeSelection = function () {
3188
- var _this = this;
3189
- try {
3190
- var selection = this.editor.selection;
3191
- var root = AngularEditor.findDocumentOrShadowRoot(this.editor);
3192
- var domSelection = root.getSelection();
3193
- if (this.isComposing || !domSelection || !AngularEditor.isFocused(this.editor)) {
3194
- return;
3195
- }
3196
- var hasDomSelection = domSelection.type !== 'None';
3197
- // If the DOM selection is properly unset, we're done.
3198
- if (!selection && !hasDomSelection) {
3199
- return;
3200
- }
3201
- // If the DOM selection is already correct, we're done.
3202
- // verify that the dom selection is in the editor
3203
- var editorElement = EDITOR_TO_ELEMENT.get(this.editor);
3204
- var hasDomSelectionInEditor = false;
3205
- if (editorElement.contains(domSelection.anchorNode) && editorElement.contains(domSelection.focusNode)) {
3206
- hasDomSelectionInEditor = true;
3207
- }
3208
- // If the DOM selection is in the editor and the editor selection is already correct, we're done.
3209
- if (hasDomSelection &&
3210
- hasDomSelectionInEditor &&
3211
- selection &&
3212
- hasStringTarget(domSelection) &&
3213
- slate.Range.equals(AngularEditor.toSlateRange(this.editor, domSelection), selection)) {
3214
- return;
3215
- }
3216
- // when <Editable/> is being controlled through external value
3217
- // then its children might just change - DOM responds to it on its own
3218
- // but Slate's value is not being updated through any operation
3219
- // and thus it doesn't transform selection on its own
3220
- if (selection && !AngularEditor.hasRange(this.editor, selection)) {
3221
- this.editor.selection = AngularEditor.toSlateRange(this.editor, domSelection);
3222
- return;
3223
- }
3224
- // Otherwise the DOM selection is out of sync, so update it.
3225
- var el_1 = AngularEditor.toDOMNode(this.editor, this.editor);
3226
- this.isUpdatingSelection = true;
3227
- var newDomRange_1 = selection && AngularEditor.toDOMRange(this.editor, selection);
3228
- if (newDomRange_1) {
3229
- // COMPAT: Since the DOM range has no concept of backwards/forwards
3230
- // we need to check and do the right thing here.
3231
- if (slate.Range.isBackward(selection)) {
3232
- // eslint-disable-next-line max-len
3233
- domSelection.setBaseAndExtent(newDomRange_1.endContainer, newDomRange_1.endOffset, newDomRange_1.startContainer, newDomRange_1.startOffset);
3234
- }
3235
- else {
3236
- // eslint-disable-next-line max-len
3237
- domSelection.setBaseAndExtent(newDomRange_1.startContainer, newDomRange_1.startOffset, newDomRange_1.endContainer, newDomRange_1.endOffset);
3238
- }
3239
- }
3240
- else {
3241
- domSelection.removeAllRanges();
3242
- }
3243
- setTimeout(function () {
3244
- // COMPAT: In Firefox, it's not enough to create a range, you also need
3245
- // to focus the contenteditable element too. (2016/11/16)
3246
- if (newDomRange_1 && IS_FIREFOX) {
3247
- el_1.focus();
3248
- }
3249
- _this.isUpdatingSelection = false;
3250
- });
3251
- }
3252
- catch (error) {
3253
- this.editor.onError({ code: exports.SlateErrorCode.ToNativeSelectionError, nativeError: error });
3254
- }
3255
- };
3256
- SlateEditableComponent.prototype.onChange = function () {
3257
- this.forceFlush();
3258
- this.onChangeCallback(this.editor.children);
3259
- };
3260
- SlateEditableComponent.prototype.ngAfterViewChecked = function () {
3261
- timeDebug('editable ngAfterViewChecked');
3262
- };
3263
- SlateEditableComponent.prototype.ngDoCheck = function () {
3264
- timeDebug('editable ngDoCheck');
3265
- };
3266
- SlateEditableComponent.prototype.forceFlush = function () {
3267
- var _this = this;
3268
- timeDebug('start data sync');
3269
- this.detectContext();
3270
- this.cdr.detectChanges();
3271
- // repair collaborative editing when Chinese input is interrupted by other users' cursors
3272
- // when the DOMElement where the selection is located is removed
3273
- // the compositionupdate and compositionend events will no longer be fired
3274
- // so isComposing needs to be corrected
3275
- // need exec after this.cdr.detectChanges() to render HTML
3276
- // need exec before this.toNativeSelection() to correct native selection
3277
- if (this.isComposing) {
3278
- // Composition input text be not rendered when user composition input with selection is expanded
3279
- // At this time, the following matching conditions are met, assign isComposing to false, and the status is wrong
3280
- // this time condition is true and isComposiing is assigned false
3281
- // Therefore, need to wait for the composition input text to be rendered before performing condition matching
3282
- setTimeout(function () {
3283
- var textNode = slate.Node.get(_this.editor, _this.editor.selection.anchor.path);
3284
- var textDOMNode = AngularEditor.toDOMNode(_this.editor, textNode);
3285
- var textContent = '';
3286
- // skip decorate text
3287
- textDOMNode.querySelectorAll('[editable-text]').forEach(function (stringDOMNode) {
3288
- var text = stringDOMNode.textContent;
3289
- var zeroChar = '\uFEFF';
3290
- // remove zero with char
3291
- if (text.startsWith(zeroChar)) {
3292
- text = text.slice(1);
3293
- }
3294
- if (text.endsWith(zeroChar)) {
3295
- text = text.slice(0, text.length - 1);
3296
- }
3297
- textContent += text;
3298
- });
3299
- if (slate.Node.string(textNode).endsWith(textContent)) {
3300
- _this.isComposing = false;
3301
- }
3302
- }, 0);
3303
- }
3304
- this.toNativeSelection();
3305
- timeDebug('end data sync');
3306
- };
3307
- SlateEditableComponent.prototype.initializeContext = function () {
3308
- this.context = {
3309
- parent: this.editor,
3310
- selection: this.editor.selection,
3311
- decorations: this.generateDecorations(),
3312
- decorate: this.decorate,
3313
- readonly: this.readonly
3314
- };
3315
- };
3316
- SlateEditableComponent.prototype.initializeViewContext = function () {
3317
- this.viewContext = {
3318
- editor: this.editor,
3319
- renderElement: this.renderElement,
3320
- renderLeaf: this.renderLeaf,
3321
- renderText: this.renderText,
3322
- trackBy: this.trackBy,
3323
- isStrictDecorate: this.isStrictDecorate,
3324
- templateComponent: this.templateComponent
3325
- };
3326
- };
3327
- SlateEditableComponent.prototype.detectContext = function () {
3328
- var decorations = this.generateDecorations();
3329
- if (this.context.selection !== this.editor.selection ||
3330
- this.context.decorate !== this.decorate ||
3331
- this.context.readonly !== this.readonly ||
3332
- !isDecoratorRangeListEqual(this.context.decorations, decorations)) {
3333
- this.context = {
3334
- parent: this.editor,
3335
- selection: this.editor.selection,
3336
- decorations: decorations,
3337
- decorate: this.decorate,
3338
- readonly: this.readonly
3339
- };
3340
- }
3341
- };
3342
- SlateEditableComponent.prototype.composePlaceholderDecorate = function (editor) {
3343
- if (this.placeholderDecorate) {
3344
- return this.placeholderDecorate(editor) || [];
3345
- }
3346
- if (this.placeholder &&
3347
- editor.children.length === 1 &&
3348
- Array.from(slate.Node.texts(editor)).length === 1 &&
3349
- slate.Node.string(editor) === '') {
3350
- var start = slate.Editor.start(editor, []);
3351
- return [
3352
- {
3353
- placeholder: this.placeholder,
3354
- anchor: start,
3355
- focus: start,
3356
- },
3357
- ];
3358
- }
3359
- else {
3360
- return [];
3361
- }
3362
- };
3363
- SlateEditableComponent.prototype.generateDecorations = function () {
3364
- var decorations = this.decorate([this.editor, []]);
3365
- var placeholderDecorations = this.isComposing
3366
- ? []
3367
- : this.composePlaceholderDecorate(this.editor);
3368
- decorations.push.apply(decorations, __spreadArray([], __read(placeholderDecorations)));
3369
- return decorations;
3370
- };
3371
- //#region event proxy
3372
- SlateEditableComponent.prototype.addEventListener = function (eventName, listener, target) {
3373
- var _this = this;
3374
- if (target === void 0) { target = this.elementRef.nativeElement; }
3375
- this.manualListeners.push(this.renderer2.listen(target, eventName, function (event) {
3376
- var beforeInputEvent = extractBeforeInputEvent(event.type, null, event, event.target);
3377
- if (beforeInputEvent) {
3378
- _this.onFallbackBeforeInput(beforeInputEvent);
3379
- }
3380
- listener(event);
3381
- }));
3382
- };
3383
- SlateEditableComponent.prototype.toSlateSelection = function () {
3384
- if (!this.readonly && !this.isComposing && !this.isUpdatingSelection && !this.isDraggingInternally) {
3385
- try {
3386
- var root = AngularEditor.findDocumentOrShadowRoot(this.editor);
3387
- var activeElement = root.activeElement;
3388
- var el = AngularEditor.toDOMNode(this.editor, this.editor);
3389
- var domSelection = root.getSelection();
3390
- if (activeElement === el || hasEditableTarget(this.editor, activeElement)) {
3391
- this.latestElement = activeElement;
3392
- IS_FOCUSED.set(this.editor, true);
3393
- }
3394
- else {
3395
- IS_FOCUSED.delete(this.editor);
3396
- }
3397
- if (!domSelection) {
3398
- return slate.Transforms.deselect(this.editor);
3399
- }
3400
- var editorElement = EDITOR_TO_ELEMENT.get(this.editor);
3401
- var hasDomSelectionInEditor = editorElement.contains(domSelection.anchorNode) && editorElement.contains(domSelection.focusNode);
3402
- if (!hasDomSelectionInEditor) {
3403
- slate.Transforms.deselect(this.editor);
3404
- return;
3405
- }
3406
- // try to get the selection directly, because some terrible case can be normalize for normalizeDOMPoint
3407
- // for example, double-click the last cell of the table to select a non-editable DOM
3408
- var range = AngularEditor.toSlateRange(this.editor, domSelection);
3409
- if (this.editor.selection && slate.Range.equals(range, this.editor.selection) && !hasStringTarget(domSelection)) {
3410
- // force adjust DOMSelection
3411
- this.toNativeSelection();
3412
- }
3413
- else {
3414
- slate.Transforms.select(this.editor, range);
3415
- }
3416
- }
3417
- catch (error) {
3418
- this.editor.onError({ code: exports.SlateErrorCode.ToSlateSelectionError, nativeError: error });
3419
- }
3420
- }
3421
- };
3422
- SlateEditableComponent.prototype.onDOMBeforeInput = function (event) {
3423
- var editor = this.editor;
3424
- if (!this.readonly && hasEditableTarget(editor, event.target) && !this.isDOMEventHandled(event, this.beforeInput)) {
3425
- try {
3426
- var selection = editor.selection;
3427
- var type = event.inputType;
3428
- var data = event.dataTransfer || event.data || undefined;
3429
- event.preventDefault();
3430
- // COMPAT: If the selection is expanded, even if the command seems like
3431
- // a delete forward/backward command it should delete the selection.
3432
- if (selection && slate.Range.isExpanded(selection) && type.startsWith('delete')) {
3433
- var direction = type.endsWith('Backward') ? 'backward' : 'forward';
3434
- slate.Editor.deleteFragment(editor, { direction: direction });
3435
- return;
3436
- }
3437
- switch (type) {
3438
- case 'deleteByComposition':
3439
- case 'deleteByCut':
3440
- case 'deleteByDrag': {
3441
- slate.Editor.deleteFragment(editor);
3442
- break;
3443
- }
3444
- case 'deleteContent':
3445
- case 'deleteContentForward': {
3446
- slate.Editor.deleteForward(editor);
3447
- break;
3448
- }
3449
- case 'deleteContentBackward': {
3450
- slate.Editor.deleteBackward(editor);
3451
- break;
3452
- }
3453
- case 'deleteEntireSoftLine': {
3454
- slate.Editor.deleteBackward(editor, { unit: 'line' });
3455
- slate.Editor.deleteForward(editor, { unit: 'line' });
3456
- break;
3457
- }
3458
- case 'deleteHardLineBackward': {
3459
- slate.Editor.deleteBackward(editor, { unit: 'block' });
3460
- break;
3461
- }
3462
- case 'deleteSoftLineBackward': {
3463
- slate.Editor.deleteBackward(editor, { unit: 'line' });
3464
- break;
3465
- }
3466
- case 'deleteHardLineForward': {
3467
- slate.Editor.deleteForward(editor, { unit: 'block' });
3468
- break;
3469
- }
3470
- case 'deleteSoftLineForward': {
3471
- slate.Editor.deleteForward(editor, { unit: 'line' });
3472
- break;
3473
- }
3474
- case 'deleteWordBackward': {
3475
- slate.Editor.deleteBackward(editor, { unit: 'word' });
3476
- break;
3477
- }
3478
- case 'deleteWordForward': {
3479
- slate.Editor.deleteForward(editor, { unit: 'word' });
3480
- break;
3481
- }
3482
- case 'insertLineBreak':
3483
- case 'insertParagraph': {
3484
- slate.Editor.insertBreak(editor);
3485
- break;
3486
- }
3487
- case 'insertFromComposition': {
3488
- // COMPAT: in safari, `compositionend` event is dispatched after
3489
- // the beforeinput event with the inputType "insertFromComposition" has been dispatched.
3490
- // https://www.w3.org/TR/input-events-2/
3491
- // so the following code is the right logic
3492
- // because DOM selection in sync will be exec before `compositionend` event
3493
- // isComposing is true will prevent DOM selection being update correctly.
3494
- this.isComposing = false;
3495
- preventInsertFromComposition(event, this.editor);
3496
- }
3497
- case 'insertFromDrop':
3498
- case 'insertFromPaste':
3499
- case 'insertFromYank':
3500
- case 'insertReplacementText':
3501
- case 'insertText': {
3502
- // use a weak comparison instead of 'instanceof' to allow
3503
- // programmatic access of paste events coming from external windows
3504
- // like cypress where cy.window does not work realibly
3505
- if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'DataTransfer') {
3506
- AngularEditor.insertData(editor, data);
3507
- }
3508
- else if (typeof data === 'string') {
3509
- slate.Editor.insertText(editor, data);
3510
- }
3511
- break;
3512
- }
3513
- }
3514
- }
3515
- catch (error) {
3516
- this.editor.onError({ code: exports.SlateErrorCode.OnDOMBeforeInputError, nativeError: error });
3517
- }
3518
- }
3519
- };
3520
- SlateEditableComponent.prototype.onDOMBlur = function (event) {
3521
- if (this.readonly ||
3522
- this.isUpdatingSelection ||
3523
- !hasEditableTarget(this.editor, event.target) ||
3524
- this.isDOMEventHandled(event, this.blur)) {
3525
- return;
3526
- }
3527
- var window = AngularEditor.getWindow(this.editor);
3528
- // COMPAT: If the current `activeElement` is still the previous
3529
- // one, this is due to the window being blurred when the tab
3530
- // itself becomes unfocused, so we want to abort early to allow to
3531
- // editor to stay focused when the tab becomes focused again.
3532
- var root = AngularEditor.findDocumentOrShadowRoot(this.editor);
3533
- if (this.latestElement === root.activeElement) {
3534
- return;
3535
- }
3536
- var relatedTarget = event.relatedTarget;
3537
- var el = AngularEditor.toDOMNode(this.editor, this.editor);
3538
- // COMPAT: The event should be ignored if the focus is returning
3539
- // to the editor from an embedded editable element (eg. an <input>
3540
- // element inside a void node).
3541
- if (relatedTarget === el) {
3542
- return;
3543
- }
3544
- // COMPAT: The event should be ignored if the focus is moving from
3545
- // the editor to inside a void node's spacer element.
3546
- if (isDOMElement(relatedTarget) && relatedTarget.hasAttribute('data-slate-spacer')) {
3547
- return;
3548
- }
3549
- // COMPAT: The event should be ignored if the focus is moving to a
3550
- // non- editable section of an element that isn't a void node (eg.
3551
- // a list item of the check list example).
3552
- if (relatedTarget != null && isDOMNode(relatedTarget) && AngularEditor.hasDOMNode(this.editor, relatedTarget)) {
3553
- var node = AngularEditor.toSlateNode(this.editor, relatedTarget);
3554
- if (slate.Element.isElement(node) && !this.editor.isVoid(node)) {
3555
- return;
3556
- }
3557
- }
3558
- IS_FOCUSED.delete(this.editor);
3559
- };
3560
- SlateEditableComponent.prototype.onDOMClick = function (event) {
3561
- if (!this.readonly &&
3562
- hasTarget(this.editor, event.target) &&
3563
- !this.isDOMEventHandled(event, this.click) &&
3564
- isDOMNode(event.target)) {
3565
- var node = AngularEditor.toSlateNode(this.editor, event.target);
3566
- var path = AngularEditor.findPath(this.editor, node);
3567
- var start = slate.Editor.start(this.editor, path);
3568
- var end = slate.Editor.end(this.editor, path);
3569
- var startVoid = slate.Editor.void(this.editor, { at: start });
3570
- var endVoid = slate.Editor.void(this.editor, { at: end });
3571
- if (startVoid && endVoid && slate.Path.equals(startVoid[1], endVoid[1])) {
3572
- var range = slate.Editor.range(this.editor, start);
3573
- slate.Transforms.select(this.editor, range);
3574
- }
3575
- }
3576
- };
3577
- SlateEditableComponent.prototype.onDOMCompositionEnd = function (event) {
3578
- if (!event.data && !slate.Range.isCollapsed(this.editor.selection)) {
3579
- slate.Transforms.delete(this.editor);
3580
- }
3581
- if (hasEditableTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.compositionEnd)) {
3582
- // COMPAT: In Chrome/Firefox, `beforeinput` events for compositions
3583
- // aren't correct and never fire the "insertFromComposition"
3584
- // type that we need. So instead, insert whenever a composition
3585
- // ends since it will already have been committed to the DOM.
3586
- if (this.isComposing === true && !IS_SAFARI && event.data) {
3587
- preventInsertFromComposition(event, this.editor);
3588
- slate.Editor.insertText(this.editor, event.data);
3589
- }
3590
- // COMPAT: In Firefox 87.0 CompositionEnd fire twice
3591
- // so we need avoid repeat isnertText by isComposing === true,
3592
- this.isComposing = false;
3593
- }
3594
- this.detectContext();
3595
- this.cdr.detectChanges();
3596
- };
3597
- SlateEditableComponent.prototype.onDOMCompositionStart = function (event) {
3598
- var selection = this.editor.selection;
3599
- if (selection) {
3600
- // solve the problem of cross node Chinese input
3601
- if (slate.Range.isExpanded(selection)) {
3602
- slate.Editor.deleteFragment(this.editor);
3603
- this.forceFlush();
3604
- }
3605
- }
3606
- if (hasEditableTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.compositionStart)) {
3607
- this.isComposing = true;
3608
- }
3609
- this.detectContext();
3610
- this.cdr.detectChanges();
3611
- };
3612
- SlateEditableComponent.prototype.onDOMCopy = function (event) {
3613
- var window = AngularEditor.getWindow(this.editor);
3614
- var isOutsideSlate = !hasStringTarget(window.getSelection()) && isTargetInsideVoid(this.editor, event.target);
3615
- if (!isOutsideSlate && hasTarget(this.editor, event.target) && !this.readonly && !this.isDOMEventHandled(event, this.copy)) {
3616
- event.preventDefault();
3617
- AngularEditor.setFragmentData(this.editor, event.clipboardData, 'copy');
3618
- }
3619
- };
3620
- SlateEditableComponent.prototype.onDOMCut = function (event) {
3621
- if (!this.readonly && hasEditableTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.cut)) {
3622
- event.preventDefault();
3623
- AngularEditor.setFragmentData(this.editor, event.clipboardData, 'cut');
3624
- var selection = this.editor.selection;
3625
- if (selection) {
3626
- AngularEditor.deleteCutData(this.editor);
3627
- }
3628
- }
3629
- };
3630
- SlateEditableComponent.prototype.onDOMDragOver = function (event) {
3631
- if (hasTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.dragOver)) {
3632
- // Only when the target is void, call `preventDefault` to signal
3633
- // that drops are allowed. Editable content is droppable by
3634
- // default, and calling `preventDefault` hides the cursor.
3635
- var node = AngularEditor.toSlateNode(this.editor, event.target);
3636
- if (slate.Editor.isVoid(this.editor, node)) {
3637
- event.preventDefault();
3638
- }
3639
- }
3640
- };
3641
- SlateEditableComponent.prototype.onDOMDragStart = function (event) {
3642
- if (!this.readonly && hasTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.dragStart)) {
3643
- var node = AngularEditor.toSlateNode(this.editor, event.target);
3644
- var path = AngularEditor.findPath(this.editor, node);
3645
- var voidMatch = slate.Editor.isVoid(this.editor, node) ||
3646
- slate.Editor.void(this.editor, { at: path, voids: true });
3647
- // If starting a drag on a void node, make sure it is selected
3648
- // so that it shows up in the selection's fragment.
3649
- if (voidMatch) {
3650
- var range = slate.Editor.range(this.editor, path);
3651
- slate.Transforms.select(this.editor, range);
3652
- }
3653
- this.isDraggingInternally = true;
3654
- AngularEditor.setFragmentData(this.editor, event.dataTransfer, 'drag');
3655
- }
3656
- };
3657
- SlateEditableComponent.prototype.onDOMDrop = function (event) {
3658
- var editor = this.editor;
3659
- if (!this.readonly && hasTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.drop)) {
3660
- event.preventDefault();
3661
- // Keep a reference to the dragged range before updating selection
3662
- var draggedRange = editor.selection;
3663
- // Find the range where the drop happened
3664
- var range = AngularEditor.findEventRange(editor, event);
3665
- var data = event.dataTransfer;
3666
- slate.Transforms.select(editor, range);
3667
- if (this.isDraggingInternally) {
3668
- if (draggedRange) {
3669
- slate.Transforms.delete(editor, {
3670
- at: draggedRange,
3671
- });
3672
- }
3673
- this.isDraggingInternally = false;
3674
- }
3675
- AngularEditor.insertData(editor, data);
3676
- // When dragging from another source into the editor, it's possible
3677
- // that the current editor does not have focus.
3678
- if (!AngularEditor.isFocused(editor)) {
3679
- AngularEditor.focus(editor);
3680
- }
3681
- }
3682
- };
3683
- SlateEditableComponent.prototype.onDOMDragEnd = function (event) {
3684
- if (!this.readonly && this.isDraggingInternally && hasTarget(this.editor, event.target) && !this.isDOMEventHandled(event, this.dragEnd)) {
3685
- this.isDraggingInternally = false;
3686
- }
3687
- };
3688
- SlateEditableComponent.prototype.onDOMFocus = function (event) {
3689
- if (!this.readonly &&
3690
- !this.isUpdatingSelection &&
3691
- hasEditableTarget(this.editor, event.target) &&
3692
- !this.isDOMEventHandled(event, this.focus)) {
3693
- var el = AngularEditor.toDOMNode(this.editor, this.editor);
3694
- var root = AngularEditor.findDocumentOrShadowRoot(this.editor);
3695
- this.latestElement = root.activeElement;
3696
- // COMPAT: If the editor has nested editable elements, the focus
3697
- // can go to them. In Firefox, this must be prevented because it
3698
- // results in issues with keyboard navigation. (2017/03/30)
3699
- if (IS_FIREFOX && event.target !== el) {
3700
- el.focus();
3701
- return;
3702
- }
3703
- IS_FOCUSED.set(this.editor, true);
3704
- }
3705
- };
3706
- SlateEditableComponent.prototype.onDOMKeydown = function (event) {
3707
- var editor = this.editor;
3708
- if (!this.readonly &&
3709
- hasEditableTarget(editor, event.target) &&
3710
- !this.isComposing &&
3711
- !this.isDOMEventHandled(event, this.keydown)) {
3712
- var nativeEvent = event;
3713
- var selection = editor.selection;
3714
- var element = editor.children[selection !== null ? selection.focus.path[0] : 0];
3715
- var isRTL = getDirection__default["default"](slate.Node.string(element)) === 'rtl';
3716
- try {
3717
- // COMPAT: Since we prevent the default behavior on
3718
- // `beforeinput` events, the browser doesn't think there's ever
3719
- // any history stack to undo or redo, so we have to manage these
3720
- // hotkeys ourselves. (2019/11/06)
3721
- if (hotkeys.isRedo(nativeEvent)) {
3722
- event.preventDefault();
3723
- if (slateHistory.HistoryEditor.isHistoryEditor(editor)) {
3724
- editor.redo();
3725
- }
3726
- return;
3727
- }
3728
- if (hotkeys.isUndo(nativeEvent)) {
3729
- event.preventDefault();
3730
- if (slateHistory.HistoryEditor.isHistoryEditor(editor)) {
3731
- editor.undo();
3732
- }
3733
- return;
3734
- }
3735
- // COMPAT: Certain browsers don't handle the selection updates
3736
- // properly. In Chrome, the selection isn't properly extended.
3737
- // And in Firefox, the selection isn't properly collapsed.
3738
- // (2017/10/17)
3739
- if (hotkeys.isMoveLineBackward(nativeEvent)) {
3740
- event.preventDefault();
3741
- slate.Transforms.move(editor, { unit: 'line', reverse: true });
3742
- return;
3743
- }
3744
- if (hotkeys.isMoveLineForward(nativeEvent)) {
3745
- event.preventDefault();
3746
- slate.Transforms.move(editor, { unit: 'line' });
3747
- return;
3748
- }
3749
- if (hotkeys.isExtendLineBackward(nativeEvent)) {
3750
- event.preventDefault();
3751
- slate.Transforms.move(editor, {
3752
- unit: 'line',
3753
- edge: 'focus',
3754
- reverse: true
3755
- });
3756
- return;
3757
- }
3758
- if (hotkeys.isExtendLineForward(nativeEvent)) {
3759
- event.preventDefault();
3760
- slate.Transforms.move(editor, { unit: 'line', edge: 'focus' });
3761
- return;
3762
- }
3763
- // COMPAT: If a void node is selected, or a zero-width text node
3764
- // adjacent to an inline is selected, we need to handle these
3765
- // hotkeys manually because browsers won't be able to skip over
3766
- // the void node with the zero-width space not being an empty
3767
- // string.
3768
- if (hotkeys.isMoveBackward(nativeEvent)) {
3769
- event.preventDefault();
3770
- if (selection && slate.Range.isCollapsed(selection)) {
3771
- slate.Transforms.move(editor, { reverse: !isRTL });
3772
- }
3773
- else {
3774
- slate.Transforms.collapse(editor, { edge: 'start' });
3775
- }
3776
- return;
3777
- }
3778
- if (hotkeys.isMoveForward(nativeEvent)) {
3779
- event.preventDefault();
3780
- if (selection && slate.Range.isCollapsed(selection)) {
3781
- slate.Transforms.move(editor, { reverse: isRTL });
3782
- }
3783
- else {
3784
- slate.Transforms.collapse(editor, { edge: 'end' });
3785
- }
3786
- return;
3787
- }
3788
- if (hotkeys.isMoveWordBackward(nativeEvent)) {
3789
- event.preventDefault();
3790
- if (selection && slate.Range.isExpanded(selection)) {
3791
- slate.Transforms.collapse(editor, { edge: 'focus' });
3792
- }
3793
- slate.Transforms.move(editor, { unit: 'word', reverse: !isRTL });
3794
- return;
3795
- }
3796
- if (hotkeys.isMoveWordForward(nativeEvent)) {
3797
- event.preventDefault();
3798
- if (selection && slate.Range.isExpanded(selection)) {
3799
- slate.Transforms.collapse(editor, { edge: 'focus' });
3800
- }
3801
- slate.Transforms.move(editor, { unit: 'word', reverse: isRTL });
3802
- return;
3803
- }
3804
- // COMPAT: Certain browsers don't support the `beforeinput` event, so we
3805
- // fall back to guessing at the input intention for hotkeys.
3806
- // COMPAT: In iOS, some of these hotkeys are handled in the
3807
- if (!HAS_BEFORE_INPUT_SUPPORT) {
3808
- // We don't have a core behavior for these, but they change the
3809
- // DOM if we don't prevent them, so we have to.
3810
- if (hotkeys.isBold(nativeEvent) || hotkeys.isItalic(nativeEvent) || hotkeys.isTransposeCharacter(nativeEvent)) {
3811
- event.preventDefault();
3812
- return;
3813
- }
3814
- if (hotkeys.isSplitBlock(nativeEvent)) {
3815
- event.preventDefault();
3816
- slate.Editor.insertBreak(editor);
3817
- return;
3818
- }
3819
- if (hotkeys.isDeleteBackward(nativeEvent)) {
3820
- event.preventDefault();
3821
- if (selection && slate.Range.isExpanded(selection)) {
3822
- slate.Editor.deleteFragment(editor, { direction: 'backward' });
3823
- }
3824
- else {
3825
- slate.Editor.deleteBackward(editor);
3826
- }
3827
- return;
3828
- }
3829
- if (hotkeys.isDeleteForward(nativeEvent)) {
3830
- event.preventDefault();
3831
- if (selection && slate.Range.isExpanded(selection)) {
3832
- slate.Editor.deleteFragment(editor, { direction: 'forward' });
3833
- }
3834
- else {
3835
- slate.Editor.deleteForward(editor);
3836
- }
3837
- return;
3838
- }
3839
- if (hotkeys.isDeleteLineBackward(nativeEvent)) {
3840
- event.preventDefault();
3841
- if (selection && slate.Range.isExpanded(selection)) {
3842
- slate.Editor.deleteFragment(editor, { direction: 'backward' });
3843
- }
3844
- else {
3845
- slate.Editor.deleteBackward(editor, { unit: 'line' });
3846
- }
3847
- return;
3848
- }
3849
- if (hotkeys.isDeleteLineForward(nativeEvent)) {
3850
- event.preventDefault();
3851
- if (selection && slate.Range.isExpanded(selection)) {
3852
- slate.Editor.deleteFragment(editor, { direction: 'forward' });
3853
- }
3854
- else {
3855
- slate.Editor.deleteForward(editor, { unit: 'line' });
3856
- }
3857
- return;
3858
- }
3859
- if (hotkeys.isDeleteWordBackward(nativeEvent)) {
3860
- event.preventDefault();
3861
- if (selection && slate.Range.isExpanded(selection)) {
3862
- slate.Editor.deleteFragment(editor, { direction: 'backward' });
3863
- }
3864
- else {
3865
- slate.Editor.deleteBackward(editor, { unit: 'word' });
3866
- }
3867
- return;
3868
- }
3869
- if (hotkeys.isDeleteWordForward(nativeEvent)) {
3870
- event.preventDefault();
3871
- if (selection && slate.Range.isExpanded(selection)) {
3872
- slate.Editor.deleteFragment(editor, { direction: 'forward' });
3873
- }
3874
- else {
3875
- slate.Editor.deleteForward(editor, { unit: 'word' });
3876
- }
3877
- return;
3878
- }
3879
- }
3880
- else {
3881
- if (IS_CHROME || IS_SAFARI) {
3882
- // COMPAT: Chrome and Safari support `beforeinput` event but do not fire
3883
- // an event when deleting backwards in a selected void inline node
3884
- if (selection &&
3885
- (hotkeys.isDeleteBackward(nativeEvent) ||
3886
- hotkeys.isDeleteForward(nativeEvent)) &&
3887
- slate.Range.isCollapsed(selection)) {
3888
- var currentNode = slate.Node.parent(editor, selection.anchor.path);
3889
- if (slate.Element.isElement(currentNode) &&
3890
- slate.Editor.isVoid(editor, currentNode) &&
3891
- slate.Editor.isInline(editor, currentNode)) {
3892
- event.preventDefault();
3893
- slate.Editor.deleteBackward(editor, { unit: 'block' });
3894
- return;
3895
- }
3896
- }
3897
- }
3898
- }
3899
- }
3900
- catch (error) {
3901
- this.editor.onError({ code: exports.SlateErrorCode.OnDOMKeydownError, nativeError: error });
3902
- }
3903
- }
3904
- };
3905
- SlateEditableComponent.prototype.onDOMPaste = function (event) {
3906
- // COMPAT: Certain browsers don't support the `beforeinput` event, so we
3907
- // fall back to React's `onPaste` here instead.
3908
- // COMPAT: Firefox, Chrome and Safari are not emitting `beforeinput` events
3909
- // when "paste without formatting" option is used.
3910
- // This unfortunately needs to be handled with paste events instead.
3911
- if (!this.isDOMEventHandled(event, this.paste) &&
3912
- (!HAS_BEFORE_INPUT_SUPPORT || isPlainTextOnlyPaste(event) || forceOnDOMPaste) &&
3913
- !this.readonly &&
3914
- hasEditableTarget(this.editor, event.target)) {
3915
- event.preventDefault();
3916
- AngularEditor.insertData(this.editor, event.clipboardData);
3917
- }
3918
- };
3919
- SlateEditableComponent.prototype.onFallbackBeforeInput = function (event) {
3920
- // COMPAT: Certain browsers don't support the `beforeinput` event, so we
3921
- // fall back to React's leaky polyfill instead just for it. It
3922
- // only works for the `insertText` input type.
3923
- if (!HAS_BEFORE_INPUT_SUPPORT &&
3924
- !this.readonly &&
3925
- !this.isDOMEventHandled(event.nativeEvent, this.beforeInput) &&
3926
- hasEditableTarget(this.editor, event.nativeEvent.target)) {
3927
- event.nativeEvent.preventDefault();
3928
- try {
3929
- var text = event.data;
3930
- if (!slate.Range.isCollapsed(this.editor.selection)) {
3931
- slate.Editor.deleteFragment(this.editor);
3932
- }
3933
- // just handle Non-IME input
3934
- if (!this.isComposing) {
3935
- slate.Editor.insertText(this.editor, text);
3936
- }
3937
- }
3938
- catch (error) {
3939
- this.editor.onError({ code: exports.SlateErrorCode.ToNativeSelectionError, nativeError: error });
3940
- }
3941
- }
3942
- };
3943
- SlateEditableComponent.prototype.isDOMEventHandled = function (event, handler) {
3944
- if (!handler) {
3945
- return false;
3946
- }
3947
- handler(event);
3948
- return event.defaultPrevented;
3949
- };
3950
- //#endregion
3951
- SlateEditableComponent.prototype.ngOnDestroy = function () {
3952
- NODE_TO_ELEMENT.delete(this.editor);
3953
- this.manualListeners.forEach(function (manualListener) {
3954
- manualListener();
3955
- });
3956
- this.destroy$.complete();
3957
- EDITOR_TO_ON_CHANGE.delete(this.editor);
3958
- };
3959
- return SlateEditableComponent;
3960
- }());
3961
- SlateEditableComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateEditableComponent, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.Renderer2 }, { token: i0__namespace.ChangeDetectorRef }, { token: i0__namespace.NgZone }, { token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Component });
3962
- SlateEditableComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateEditableComponent, selector: "slate-editable", inputs: { editor: "editor", renderElement: "renderElement", renderLeaf: "renderLeaf", renderText: "renderText", decorate: "decorate", placeholderDecorate: "placeholderDecorate", isStrictDecorate: "isStrictDecorate", trackBy: "trackBy", readonly: "readonly", placeholder: "placeholder", beforeInput: "beforeInput", blur: "blur", click: "click", compositionEnd: "compositionEnd", compositionStart: "compositionStart", copy: "copy", cut: "cut", dragOver: "dragOver", dragStart: "dragStart", dragEnd: "dragEnd", drop: "drop", focus: "focus", keydown: "keydown", paste: "paste", spellCheck: "spellCheck", autoCorrect: "autoCorrect", autoCapitalize: "autoCapitalize" }, host: { properties: { "attr.contenteditable": "readonly ? undefined : true", "attr.role": "readonly ? undefined : 'textbox'", "attr.spellCheck": "!hasBeforeInputSupport ? false : spellCheck", "attr.autoCorrect": "!hasBeforeInputSupport ? 'false' : autoCorrect", "attr.autoCapitalize": "!hasBeforeInputSupport ? 'false' : autoCapitalize", "attr.data-slate-editor": "this.dataSlateEditor", "attr.data-slate-node": "this.dataSlateNode", "attr.data-gramm": "this.dataGramm" }, classAttribute: "slate-editable-container" }, providers: [{
3963
- provide: forms.NG_VALUE_ACCESSOR,
3964
- useExisting: i0.forwardRef(function () { return SlateEditableComponent; }),
3965
- multi: true
3966
- }], viewQueries: [{ propertyName: "templateComponent", first: true, predicate: ["templateComponent"], descendants: true, static: true }, { propertyName: "templateElementRef", first: true, predicate: ["templateComponent"], descendants: true, read: i0.ElementRef, static: true }], usesOnChanges: true, ngImport: i0__namespace, template: "<slate-children [children]=\"editor.children\" [context]=\"context\" [viewContext]=\"viewContext\"></slate-children>\n<slate-string-template #templateComponent></slate-string-template>", components: [{ type: SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }, { type: SlateStringTemplateComponent, selector: "slate-string-template" }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
3967
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateEditableComponent, decorators: [{
3968
- type: i0.Component,
3969
- args: [{
3970
- selector: 'slate-editable',
3971
- host: {
3972
- class: 'slate-editable-container',
3973
- '[attr.contenteditable]': 'readonly ? undefined : true',
3974
- '[attr.role]': "readonly ? undefined : 'textbox'",
3975
- '[attr.spellCheck]': "!hasBeforeInputSupport ? false : spellCheck",
3976
- '[attr.autoCorrect]': "!hasBeforeInputSupport ? 'false' : autoCorrect",
3977
- '[attr.autoCapitalize]': "!hasBeforeInputSupport ? 'false' : autoCapitalize"
3978
- },
3979
- templateUrl: 'editable.component.html',
3980
- changeDetection: i0.ChangeDetectionStrategy.OnPush,
3981
- providers: [{
3982
- provide: forms.NG_VALUE_ACCESSOR,
3983
- useExisting: i0.forwardRef(function () { return SlateEditableComponent; }),
3984
- multi: true
3985
- }]
3986
- }]
3987
- }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.Renderer2 }, { type: i0__namespace.ChangeDetectorRef }, { type: i0__namespace.NgZone }, { type: i0__namespace.Injector }]; }, propDecorators: { editor: [{
3988
- type: i0.Input
3989
- }], renderElement: [{
3990
- type: i0.Input
3991
- }], renderLeaf: [{
3992
- type: i0.Input
3993
- }], renderText: [{
3994
- type: i0.Input
3995
- }], decorate: [{
3996
- type: i0.Input
3997
- }], placeholderDecorate: [{
3998
- type: i0.Input
3999
- }], isStrictDecorate: [{
4000
- type: i0.Input
4001
- }], trackBy: [{
4002
- type: i0.Input
4003
- }], readonly: [{
4004
- type: i0.Input
4005
- }], placeholder: [{
4006
- type: i0.Input
4007
- }], beforeInput: [{
4008
- type: i0.Input
4009
- }], blur: [{
4010
- type: i0.Input
4011
- }], click: [{
4012
- type: i0.Input
4013
- }], compositionEnd: [{
4014
- type: i0.Input
4015
- }], compositionStart: [{
4016
- type: i0.Input
4017
- }], copy: [{
4018
- type: i0.Input
4019
- }], cut: [{
4020
- type: i0.Input
4021
- }], dragOver: [{
4022
- type: i0.Input
4023
- }], dragStart: [{
4024
- type: i0.Input
4025
- }], dragEnd: [{
4026
- type: i0.Input
4027
- }], drop: [{
4028
- type: i0.Input
4029
- }], focus: [{
4030
- type: i0.Input
4031
- }], keydown: [{
4032
- type: i0.Input
4033
- }], paste: [{
4034
- type: i0.Input
4035
- }], spellCheck: [{
4036
- type: i0.Input
4037
- }], autoCorrect: [{
4038
- type: i0.Input
4039
- }], autoCapitalize: [{
4040
- type: i0.Input
4041
- }], dataSlateEditor: [{
4042
- type: i0.HostBinding,
4043
- args: ['attr.data-slate-editor']
4044
- }], dataSlateNode: [{
4045
- type: i0.HostBinding,
4046
- args: ['attr.data-slate-node']
4047
- }], dataGramm: [{
4048
- type: i0.HostBinding,
4049
- args: ['attr.data-gramm']
4050
- }], templateComponent: [{
4051
- type: i0.ViewChild,
4052
- args: ['templateComponent', { static: true }]
4053
- }], templateElementRef: [{
4054
- type: i0.ViewChild,
4055
- args: ['templateComponent', { static: true, read: i0.ElementRef }]
4056
- }] } });
4057
- /**
4058
- * Check if the target is editable and in the editor.
4059
- */
4060
- var hasEditableTarget = function (editor, target) {
4061
- return isDOMNode(target) && AngularEditor.hasDOMNode(editor, target, { editable: true });
4062
- };
4063
- /**
4064
- * Check if two DOM range objects are equal.
4065
- */
4066
- var isRangeEqual = function (a, b) {
4067
- return ((a.startContainer === b.startContainer &&
4068
- a.startOffset === b.startOffset &&
4069
- a.endContainer === b.endContainer &&
4070
- a.endOffset === b.endOffset) ||
4071
- (a.startContainer === b.endContainer &&
4072
- a.startOffset === b.endOffset &&
4073
- a.endContainer === b.startContainer &&
4074
- a.endOffset === b.startOffset));
4075
- };
4076
- /**
4077
- * Check if the target is in the editor.
4078
- */
4079
- var hasTarget = function (editor, target) {
4080
- return isDOMNode(target) && AngularEditor.hasDOMNode(editor, target);
4081
- };
4082
- /**
4083
- * Check if the target is inside void and in the editor.
4084
- */
4085
- var isTargetInsideVoid = function (editor, target) {
4086
- var slateNode = hasTarget(editor, target) && AngularEditor.toSlateNode(editor, target);
4087
- return slate.Editor.isVoid(editor, slateNode);
4088
- };
4089
- var hasStringTarget = function (domSelection) {
4090
- return (domSelection.anchorNode.parentElement.hasAttribute('data-slate-string') || domSelection.anchorNode.parentElement.hasAttribute('data-slate-zero-width')) &&
4091
- (domSelection.focusNode.parentElement.hasAttribute('data-slate-string') || domSelection.focusNode.parentElement.hasAttribute('data-slate-zero-width'));
4092
- };
4093
- /**
4094
- * remove default insert from composition
4095
- * @param text
4096
- */
4097
- var preventInsertFromComposition = function (event, editor) {
4098
- var types = ['compositionend', 'insertFromComposition'];
4099
- if (!types.includes(event.type)) {
4100
- return;
4101
- }
4102
- var insertText = event.data;
4103
- var window = AngularEditor.getWindow(editor);
4104
- var domSelection = window.getSelection();
4105
- // ensure text node insert composition input text
4106
- if (insertText && domSelection.anchorNode instanceof Text && domSelection.anchorNode.textContent.endsWith(insertText)) {
4107
- var textNode = domSelection.anchorNode;
4108
- textNode.splitText(textNode.length - insertText.length).remove();
4109
- }
4110
- };
4111
-
4112
- var SlateElementComponent = /** @class */ (function (_super) {
4113
- __extends(SlateElementComponent, _super);
4114
- function SlateElementComponent() {
4115
- return _super !== null && _super.apply(this, arguments) || this;
4116
- }
4117
- return SlateElementComponent;
4118
- }(BaseElementComponent));
4119
- SlateElementComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateElementComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
4120
- SlateElementComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateElementComponent, selector: "[slateElement]", usesInheritance: true, ngImport: i0__namespace, template: '<slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children><ng-content></ng-content>', isInline: true, components: [{ type: SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
4121
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateElementComponent, decorators: [{
4122
- type: i0.Component,
4123
- args: [{
4124
- selector: '[slateElement]',
4125
- template: '<slate-children [children]="children" [context]="childrenContext" [viewContext]="viewContext"></slate-children><ng-content></ng-content>',
4126
- changeDetection: i0.ChangeDetectionStrategy.OnPush
4127
- }]
4128
- }] });
4129
-
4130
- var SlateDefaultElementComponent = /** @class */ (function (_super) {
4131
- __extends(SlateDefaultElementComponent, _super);
4132
- function SlateDefaultElementComponent() {
4133
- return _super !== null && _super.apply(this, arguments) || this;
4134
- }
4135
- return SlateDefaultElementComponent;
4136
- }(BaseElementComponent));
4137
- SlateDefaultElementComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultElementComponent, deps: null, target: i0__namespace.ɵɵFactoryTarget.Component });
4138
- SlateDefaultElementComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.7", type: SlateDefaultElementComponent, selector: "div[slateDefaultElement]", usesInheritance: true, ngImport: i0__namespace, template: "<slate-children [children]=\"children\" [context]=\"childrenContext\" [viewContext]=\"viewContext\"></slate-children>", isInline: true, components: [{ type: SlateChildrenComponent, selector: "slate-children", inputs: ["children", "context", "viewContext"] }], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
4139
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateDefaultElementComponent, decorators: [{
4140
- type: i0.Component,
4141
- args: [{
4142
- selector: 'div[slateDefaultElement]',
4143
- template: "<slate-children [children]=\"children\" [context]=\"childrenContext\" [viewContext]=\"viewContext\"></slate-children>",
4144
- changeDetection: i0.ChangeDetectionStrategy.OnPush
4145
- }]
4146
- }] });
4147
-
4148
- var SlateModule = /** @class */ (function () {
4149
- function SlateModule() {
4150
- }
4151
- return SlateModule;
4152
- }());
4153
- SlateModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
4154
- SlateModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateModule, declarations: [SlateEditableComponent,
4155
- SlateDefaultElementComponent,
4156
- SlateElementComponent,
4157
- SlateVoidTextComponent,
4158
- SlateDefaultTextComponent,
4159
- SlateStringComponent,
4160
- SlateStringTemplateComponent,
4161
- SlateDescendantComponent,
4162
- SlateChildrenComponent,
4163
- SlateBlockCardComponent,
4164
- SlateLeafComponent,
4165
- SlateLeavesComponent,
4166
- SlateDefaultLeafComponent], imports: [i2.CommonModule], exports: [SlateEditableComponent, SlateChildrenComponent, SlateElementComponent, SlateLeavesComponent, SlateStringComponent] });
4167
- SlateModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateModule, providers: [
4168
- {
4169
- provide: SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN,
4170
- useValue: SlateDefaultElementComponent
4171
- },
4172
- ], imports: [[i2.CommonModule]] });
4173
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0__namespace, type: SlateModule, decorators: [{
4174
- type: i0.NgModule,
4175
- args: [{
4176
- declarations: [
4177
- SlateEditableComponent,
4178
- SlateDefaultElementComponent,
4179
- SlateElementComponent,
4180
- SlateVoidTextComponent,
4181
- SlateDefaultTextComponent,
4182
- SlateStringComponent,
4183
- SlateStringTemplateComponent,
4184
- SlateDescendantComponent,
4185
- SlateChildrenComponent,
4186
- SlateBlockCardComponent,
4187
- SlateLeafComponent,
4188
- SlateLeavesComponent,
4189
- SlateDefaultLeafComponent
4190
- ],
4191
- imports: [i2.CommonModule],
4192
- entryComponents: [SlateBlockCardComponent, SlateStringComponent, SlateDefaultElementComponent, SlateDefaultLeafComponent, SlateVoidTextComponent, SlateDefaultTextComponent],
4193
- exports: [SlateEditableComponent, SlateChildrenComponent, SlateElementComponent, SlateLeavesComponent, SlateStringComponent],
4194
- providers: [
4195
- {
4196
- provide: SLATE_DEFAULT_ELEMENT_COMPONENT_TOKEN,
4197
- useValue: SlateDefaultElementComponent
4198
- },
4199
- ]
4200
- }]
4201
- }] });
4202
-
4203
- /*
4204
- * Public API Surface of slate-angular
4205
- */
4206
-
4207
- /**
4208
- * Generated bundle index. Do not edit.
4209
- */
4210
-
4211
- exports.AngularEditor = AngularEditor;
4212
- exports.BaseComponent = BaseComponent;
4213
- exports.BaseElementComponent = BaseElementComponent;
4214
- exports.BaseLeafComponent = BaseLeafComponent;
4215
- exports.BaseTextComponent = BaseTextComponent;
4216
- exports.DOMComment = DOMComment;
4217
- exports.DOMElement = DOMElement;
4218
- exports.DOMNode = DOMNode;
4219
- exports.DOMRange = DOMRange;
4220
- exports.DOMSelection = DOMSelection;
4221
- exports.DOMStaticRange = DOMStaticRange;
4222
- exports.DOMText = DOMText;
4223
- exports.EDITOR_TO_ELEMENT = EDITOR_TO_ELEMENT;
4224
- exports.EDITOR_TO_ON_CHANGE = EDITOR_TO_ON_CHANGE;
4225
- exports.EDITOR_TO_PLACEHOLDER = EDITOR_TO_PLACEHOLDER;
4226
- exports.EDITOR_TO_WINDOW = EDITOR_TO_WINDOW;
4227
- exports.ELEMENT_TO_COMPONENT = ELEMENT_TO_COMPONENT;
4228
- exports.ELEMENT_TO_NODE = ELEMENT_TO_NODE;
4229
- exports.FAKE_LEFT_BLOCK_CARD_OFFSET = FAKE_LEFT_BLOCK_CARD_OFFSET;
4230
- exports.FAKE_RIGHT_BLOCK_CARD_OFFSET = FAKE_RIGHT_BLOCK_CARD_OFFSET;
4231
- exports.HAS_BEFORE_INPUT_SUPPORT = HAS_BEFORE_INPUT_SUPPORT;
4232
- exports.IS_ANDROID = IS_ANDROID;
4233
- exports.IS_APPLE = IS_APPLE;
4234
- exports.IS_CHROME = IS_CHROME;
4235
- exports.IS_CHROME_LEGACY = IS_CHROME_LEGACY;
4236
- exports.IS_CLICKING = IS_CLICKING;
4237
- exports.IS_DRAGGING = IS_DRAGGING;
4238
- exports.IS_EDGE_LEGACY = IS_EDGE_LEGACY;
4239
- exports.IS_FIREFOX = IS_FIREFOX;
4240
- exports.IS_FIREFOX_LEGACY = IS_FIREFOX_LEGACY;
4241
- exports.IS_FOCUSED = IS_FOCUSED;
4242
- exports.IS_IOS = IS_IOS;
4243
- exports.IS_QQBROWSER = IS_QQBROWSER;
4244
- exports.IS_READONLY = IS_READONLY;
4245
- exports.IS_SAFARI = IS_SAFARI;
4246
- exports.IS_UC_MOBILE = IS_UC_MOBILE;
4247
- exports.IS_WECHATBROWSER = IS_WECHATBROWSER;
4248
- exports.KEY_TO_ELEMENT = KEY_TO_ELEMENT;
4249
- exports.Key = Key;
4250
- exports.NODE_TO_ELEMENT = NODE_TO_ELEMENT;
4251
- exports.NODE_TO_INDEX = NODE_TO_INDEX;
4252
- exports.NODE_TO_KEY = NODE_TO_KEY;
4253
- exports.NODE_TO_PARENT = NODE_TO_PARENT;
4254
- exports.PLACEHOLDER_SYMBOL = PLACEHOLDER_SYMBOL;
4255
- exports.SlateChildrenComponent = SlateChildrenComponent;
4256
- exports.SlateEditableComponent = SlateEditableComponent;
4257
- exports.SlateElementComponent = SlateElementComponent;
4258
- exports.SlateLeavesComponent = SlateLeavesComponent;
4259
- exports.SlateModule = SlateModule;
4260
- exports.SlateStringComponent = SlateStringComponent;
4261
- exports.check = check;
4262
- exports.getCardTargetAttribute = getCardTargetAttribute;
4263
- exports.getClipboardData = getClipboardData;
4264
- exports.getDefaultView = getDefaultView;
4265
- exports.getEditableChild = getEditableChild;
4266
- exports.getEditableChildAndIndex = getEditableChildAndIndex;
4267
- exports.getPlainText = getPlainText;
4268
- exports.getSlateFragmentAttribute = getSlateFragmentAttribute;
4269
- exports.hasBeforeContextChange = hasBeforeContextChange;
4270
- exports.hasBlockCard = hasBlockCard;
4271
- exports.hasBlockCardWithNode = hasBlockCardWithNode;
4272
- exports.hasShadowRoot = hasShadowRoot;
4273
- exports.hotkeys = hotkeys;
4274
- exports.isCardCenterByTargetAttr = isCardCenterByTargetAttr;
4275
- exports.isCardLeft = isCardLeft;
4276
- exports.isCardLeftByTargetAttr = isCardLeftByTargetAttr;
4277
- exports.isCardRightByTargetAttr = isCardRightByTargetAttr;
4278
- exports.isComponentType = isComponentType;
4279
- exports.isDOMComment = isDOMComment;
4280
- exports.isDOMElement = isDOMElement;
4281
- exports.isDOMNode = isDOMNode;
4282
- exports.isDOMSelection = isDOMSelection;
4283
- exports.isDOMText = isDOMText;
4284
- exports.isDecoratorRangeListEqual = isDecoratorRangeListEqual;
4285
- exports.isPlainTextOnlyPaste = isPlainTextOnlyPaste;
4286
- exports.isTemplateRef = isTemplateRef;
4287
- exports.isValid = isValid;
4288
- exports.normalize = normalize;
4289
- exports.normalizeDOMPoint = normalizeDOMPoint;
4290
- exports.shallowCompare = shallowCompare;
4291
- exports.withAngular = withAngular;
4292
-
4293
- Object.defineProperty(exports, '__esModule', { value: true });
4294
-
4295
- }));
4296
- //# sourceMappingURL=slate-angular.umd.js.map