slate-angular 15.1.0-next.2 → 15.1.0-next.3

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.
@@ -1624,25 +1624,19 @@ function restoreDom(editor, execute) {
1624
1624
  class SlateStringTemplateComponent {
1625
1625
  }
1626
1626
  SlateStringTemplateComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: SlateStringTemplateComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1627
- SlateStringTemplateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.4", type: SlateStringTemplateComponent, selector: "slate-string-template", viewQueries: [{ propertyName: "compatStringTemplate", first: true, predicate: ["compatStringTemplate"], descendants: true, read: TemplateRef, static: true }, { propertyName: "emptyStringTemplate", first: true, predicate: ["emptyStringTemplate"], descendants: true, read: TemplateRef, static: true }, { propertyName: "emptyTextTemplate", first: true, predicate: ["emptyTextTemplate"], descendants: true, read: TemplateRef, static: true }, { propertyName: "lineBreakEmptyStringTemplate", first: true, predicate: ["lineBreakEmptyStringTemplate"], descendants: true, read: TemplateRef, static: true }], ngImport: i0, template: "<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\"\n >{{ context.text }}<span data-slate-zero-width>{{ '\\uFEFF' }}</span></span\n >\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' }}<br /></span>\n</ng-template>\n", changeDetection: i0.ChangeDetectionStrategy.OnPush });
1627
+ SlateStringTemplateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.4", type: SlateStringTemplateComponent, selector: "slate-string-template", viewQueries: [{ propertyName: "compatibleStringTemplate", first: true, predicate: ["compatibleStringTemplate"], descendants: true, read: TemplateRef, static: true }, { propertyName: "voidStringTemplate", first: true, predicate: ["voidStringTemplate"], descendants: true, read: TemplateRef, static: true }, { propertyName: "emptyTextTemplate", first: true, predicate: ["emptyTextTemplate"], descendants: true, read: TemplateRef, static: true }], ngImport: i0, template: "<ng-template #compatibleStringTemplate let-context=\"context\" let-viewContext=\"viewContext\">\n <!-- Compatible with Chinese input in Chrome with \\n -->\n <span editable-text data-slate-string=\"true\"\n >{{ context.text }}<span data-slate-zero-width>{{ '\\uFEFF' }}</span></span\n >\n</ng-template>\n<ng-template #voidStringTemplate 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", changeDetection: i0.ChangeDetectionStrategy.OnPush });
1628
1628
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: SlateStringTemplateComponent, decorators: [{
1629
1629
  type: Component,
1630
- args: [{ selector: 'slate-string-template', changeDetection: ChangeDetectionStrategy.OnPush, template: "<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\"\n >{{ context.text }}<span data-slate-zero-width>{{ '\\uFEFF' }}</span></span\n >\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' }}<br /></span>\n</ng-template>\n" }]
1631
- }], propDecorators: { compatStringTemplate: [{
1630
+ args: [{ selector: 'slate-string-template', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-template #compatibleStringTemplate let-context=\"context\" let-viewContext=\"viewContext\">\n <!-- Compatible with Chinese input in Chrome with \\n -->\n <span editable-text data-slate-string=\"true\"\n >{{ context.text }}<span data-slate-zero-width>{{ '\\uFEFF' }}</span></span\n >\n</ng-template>\n<ng-template #voidStringTemplate 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" }]
1631
+ }], propDecorators: { compatibleStringTemplate: [{
1632
1632
  type: ViewChild,
1633
- args: ['compatStringTemplate', { read: TemplateRef, static: true }]
1634
- }], emptyStringTemplate: [{
1633
+ args: ['compatibleStringTemplate', { read: TemplateRef, static: true }]
1634
+ }], voidStringTemplate: [{
1635
1635
  type: ViewChild,
1636
- args: ['emptyStringTemplate', { read: TemplateRef, static: true }]
1636
+ args: ['voidStringTemplate', { read: TemplateRef, static: true }]
1637
1637
  }], emptyTextTemplate: [{
1638
1638
  type: ViewChild,
1639
1639
  args: ['emptyTextTemplate', { read: TemplateRef, static: true }]
1640
- }], lineBreakEmptyStringTemplate: [{
1641
- type: ViewChild,
1642
- args: ['lineBreakEmptyStringTemplate', {
1643
- read: TemplateRef,
1644
- static: true
1645
- }]
1646
1640
  }] } });
1647
1641
 
1648
1642
  class SlateBlockCardComponent {
@@ -2105,15 +2099,57 @@ class SlateDefaultStringComponent extends BaseComponent {
2105
2099
  this.elementRef = elementRef;
2106
2100
  this.cdr = cdr;
2107
2101
  }
2102
+ beforeContextChange(value) {
2103
+ if (this.context) {
2104
+ if (this.context.type === 'lineBreakEmptyString') {
2105
+ this.removeLineBreakEmptyStringDOM();
2106
+ }
2107
+ if (this.context.type === 'string') {
2108
+ if (value.type === 'lineBreakEmptyString') {
2109
+ this.removeStringDOM();
2110
+ }
2111
+ }
2112
+ }
2113
+ }
2108
2114
  onContextChange() {
2115
+ if (this.context.type === 'string') {
2116
+ this.createStringDOM();
2117
+ }
2118
+ else if (this.context.type === 'lineBreakEmptyString') {
2119
+ this.createLineBreakEmptyStringDOM();
2120
+ }
2121
+ }
2122
+ createLineBreakEmptyStringDOM() {
2123
+ this.nativeElement.setAttribute('data-slate-zero-width', 'n');
2124
+ this.nativeElement.setAttribute('data-slate-length', `${this.context.elementStringLength}`);
2125
+ this.textNode = document.createTextNode(`\uFEFF`);
2126
+ this.brNode = document.createElement('br');
2127
+ this.nativeElement.append(this.textNode, this.brNode);
2128
+ }
2129
+ removeLineBreakEmptyStringDOM() {
2130
+ this.brNode?.remove();
2131
+ // remove zero width character
2132
+ const zeroWidthCharacterIndex = this.textNode?.textContent.indexOf(`\uFEFF`);
2133
+ this.textNode?.deleteData(zeroWidthCharacterIndex, 1);
2134
+ this.nativeElement.removeAttribute('data-slate-zero-width');
2135
+ this.nativeElement.removeAttribute('data-slate-length');
2136
+ }
2137
+ createStringDOM() {
2138
+ this.nativeElement.setAttribute('data-slate-string', 'true');
2139
+ this.updateStringDOM();
2140
+ }
2141
+ updateStringDOM() {
2109
2142
  // Avoid breaking some browser default behaviors, such as spellCheck, android composition input state
2110
2143
  if (this.nativeElement.textContent !== this.context.text) {
2111
2144
  this.nativeElement.textContent = this.context.text;
2112
2145
  }
2113
2146
  }
2147
+ removeStringDOM() {
2148
+ this.nativeElement.removeAttribute('data-slate-string');
2149
+ this.nativeElement.textContent = '';
2150
+ }
2114
2151
  ngOnInit() {
2115
2152
  this.nativeElement.setAttribute('editable-text', '');
2116
- this.nativeElement.setAttribute('data-slate-string', 'true');
2117
2153
  }
2118
2154
  }
2119
2155
  SlateDefaultStringComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: SlateDefaultStringComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
@@ -2145,40 +2181,60 @@ class SlateStringComponent extends ViewContainerItem {
2145
2181
  ngAfterViewInit() {
2146
2182
  this.elementRef.nativeElement.remove();
2147
2183
  }
2148
- getViewType() {
2184
+ // COMPAT: If this is the last text node in an empty block, render a zero-
2185
+ // width space that will convert into a line break when copying and pasting
2186
+ // to support expected plain text.
2187
+ isLineBreakEmptyString() {
2149
2188
  const path = AngularEditor.findPath(this.viewContext.editor, this.context.text);
2150
2189
  const parentPath = Path.parent(path);
2151
- // COMPAT: Render text inside void nodes with a zero-width space.
2152
- // So the node can contain selection but the text is not visible.
2153
- if (this.viewContext.editor.isVoid(this.context.parent)) {
2154
- return this.viewContext.templateComponent.emptyStringTemplate;
2155
- }
2156
- // COMPAT: If this is the last text node in an empty block, render a zero-
2157
- // width space that will convert into a line break when copying and pasting
2158
- // to support expected plain text.
2159
- if (this.context.leaf.text === '' &&
2190
+ return (this.context.leaf.text === '' &&
2160
2191
  this.context.parent.children[this.context.parent.children.length - 1] === this.context.text &&
2161
2192
  !this.viewContext.editor.isInline(this.context.parent) &&
2162
- Editor.string(this.viewContext.editor, parentPath) === '') {
2163
- return this.viewContext.templateComponent.lineBreakEmptyStringTemplate;
2193
+ Editor.string(this.viewContext.editor, parentPath) === '');
2194
+ }
2195
+ // COMPAT: If the text is empty, it's because it's on the edge of an inline
2196
+ // node, so we render a zero-width space so that the selection can be
2197
+ // inserted next to it still.
2198
+ isEmptyText() {
2199
+ return this.context.leaf.text === '';
2200
+ }
2201
+ // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
2202
+ // so we need to add an extra trailing new lines to prevent that.
2203
+ isCompatibleString() {
2204
+ return this.context.isLast && this.context.leaf.text.slice(-1) === '\n';
2205
+ }
2206
+ // COMPAT: Render text inside void nodes with a zero-width space.
2207
+ // So the node can contain selection but the text is not visible.
2208
+ isVoid() {
2209
+ return this.viewContext.editor.isVoid(this.context.parent);
2210
+ }
2211
+ getViewType() {
2212
+ if (this.isVoid()) {
2213
+ return this.viewContext.templateComponent.voidStringTemplate;
2164
2214
  }
2165
- // COMPAT: If the text is empty, it's because it's on the edge of an inline
2166
- // node, so we render a zero-width space so that the selection can be
2167
- // inserted next to it still.
2168
- if (this.context.leaf.text === '') {
2215
+ if (this.isLineBreakEmptyString()) {
2216
+ return SlateDefaultStringComponent;
2217
+ }
2218
+ if (this.isEmptyText()) {
2169
2219
  return this.viewContext.templateComponent.emptyTextTemplate;
2170
2220
  }
2171
- // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
2172
- // so we need to add an extra trailing new lines to prevent that.
2173
- if (this.context.isLast && this.context.leaf.text.slice(-1) === '\n') {
2174
- return this.viewContext.templateComponent.compatStringTemplate;
2221
+ if (this.isCompatibleString()) {
2222
+ return this.viewContext.templateComponent.compatibleStringTemplate;
2175
2223
  }
2176
2224
  return SlateDefaultStringComponent;
2177
2225
  }
2226
+ getType() {
2227
+ if (this.isLineBreakEmptyString()) {
2228
+ return 'lineBreakEmptyString';
2229
+ }
2230
+ return 'string';
2231
+ }
2178
2232
  getContext() {
2233
+ const stringType = this.getType();
2179
2234
  return {
2180
2235
  text: this.context.leaf.text,
2181
- elementStringLength: Node.string(this.context.parent).length
2236
+ elementStringLength: Node.string(this.context.parent).length,
2237
+ type: stringType
2182
2238
  };
2183
2239
  }
2184
2240
  memoizedContext(prev, next) {
@@ -2262,10 +2318,10 @@ class SlateLeavesComponent extends ViewContainer {
2262
2318
  }
2263
2319
  ngOnInit() {
2264
2320
  this.leaves = Text$1.decorations(this.context.text, this.context.decorations);
2265
- this.leafContexts = this.getLeafCotexts();
2321
+ this.leafContexts = this.getLeafContexts();
2266
2322
  this.initialized = true;
2267
2323
  }
2268
- getLeafCotexts() {
2324
+ getLeafContexts() {
2269
2325
  return this.leaves.map((leaf, index) => {
2270
2326
  return {
2271
2327
  leaf,
@@ -2286,7 +2342,7 @@ class SlateLeavesComponent extends ViewContainer {
2286
2342
  if (previousValue.text !== currentValue.text || !isDecoratorRangeListEqual(previousValue.decorations, currentValue.decorations)) {
2287
2343
  this.leaves = Text$1.decorations(this.context.text, this.context.decorations);
2288
2344
  }
2289
- this.leafContexts = this.getLeafCotexts();
2345
+ this.leafContexts = this.getLeafContexts();
2290
2346
  }
2291
2347
  trackBy(index, item) {
2292
2348
  return index;
@@ -2635,7 +2691,7 @@ class SlateEditableComponent {
2635
2691
  this.initializeViewContext();
2636
2692
  this.initializeContext();
2637
2693
  // remove unused DOM, just keep templateComponent instance
2638
- this.templateElementRef.nativeElement.remove();
2694
+ // this.templateElementRef.nativeElement.remove();
2639
2695
  // add browser class
2640
2696
  let browserClass = IS_FIREFOX ? 'firefox' : IS_SAFARI ? 'safari' : '';
2641
2697
  browserClass && this.elementRef.nativeElement.classList.add(browserClass);