slate-angular 1.9.3 → 13.0.2

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