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

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,63 @@ 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
+ if (value.type === 'string') {
2106
+ this.removeLineBreakEmptyStringDOM();
2107
+ }
2108
+ else {
2109
+ this.textNode?.remove();
2110
+ this.brNode?.remove();
2111
+ }
2112
+ }
2113
+ if (this.context.type === 'string') {
2114
+ if (value.type === 'lineBreakEmptyString') {
2115
+ this.removeStringDOM();
2116
+ }
2117
+ }
2118
+ }
2119
+ }
2108
2120
  onContextChange() {
2121
+ if (this.context.type === 'string') {
2122
+ this.createStringDOM();
2123
+ }
2124
+ else if (this.context.type === 'lineBreakEmptyString') {
2125
+ this.createLineBreakEmptyStringDOM();
2126
+ }
2127
+ }
2128
+ createLineBreakEmptyStringDOM() {
2129
+ this.nativeElement.setAttribute('data-slate-zero-width', 'n');
2130
+ this.nativeElement.setAttribute('data-slate-length', `${this.context.elementStringLength}`);
2131
+ this.textNode = document.createTextNode(`\uFEFF`);
2132
+ this.brNode = document.createElement('br');
2133
+ this.nativeElement.append(this.textNode, this.brNode);
2134
+ }
2135
+ removeLineBreakEmptyStringDOM() {
2136
+ this.brNode?.remove();
2137
+ // remove zero width character
2138
+ const zeroWidthCharacterIndex = this.textNode?.textContent.indexOf(`\uFEFF`);
2139
+ this.textNode?.deleteData(zeroWidthCharacterIndex, 1);
2140
+ this.nativeElement.removeAttribute('data-slate-zero-width');
2141
+ this.nativeElement.removeAttribute('data-slate-length');
2142
+ }
2143
+ createStringDOM() {
2144
+ this.nativeElement.setAttribute('data-slate-string', 'true');
2145
+ this.updateStringDOM();
2146
+ }
2147
+ updateStringDOM() {
2109
2148
  // Avoid breaking some browser default behaviors, such as spellCheck, android composition input state
2110
2149
  if (this.nativeElement.textContent !== this.context.text) {
2111
2150
  this.nativeElement.textContent = this.context.text;
2112
2151
  }
2113
2152
  }
2153
+ removeStringDOM() {
2154
+ this.nativeElement.removeAttribute('data-slate-string');
2155
+ this.nativeElement.textContent = '';
2156
+ }
2114
2157
  ngOnInit() {
2115
2158
  this.nativeElement.setAttribute('editable-text', '');
2116
- this.nativeElement.setAttribute('data-slate-string', 'true');
2117
2159
  }
2118
2160
  }
2119
2161
  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 +2187,60 @@ class SlateStringComponent extends ViewContainerItem {
2145
2187
  ngAfterViewInit() {
2146
2188
  this.elementRef.nativeElement.remove();
2147
2189
  }
2148
- getViewType() {
2190
+ // COMPAT: If this is the last text node in an empty block, render a zero-
2191
+ // width space that will convert into a line break when copying and pasting
2192
+ // to support expected plain text.
2193
+ isLineBreakEmptyString() {
2149
2194
  const path = AngularEditor.findPath(this.viewContext.editor, this.context.text);
2150
2195
  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 === '' &&
2196
+ return (this.context.leaf.text === '' &&
2160
2197
  this.context.parent.children[this.context.parent.children.length - 1] === this.context.text &&
2161
2198
  !this.viewContext.editor.isInline(this.context.parent) &&
2162
- Editor.string(this.viewContext.editor, parentPath) === '') {
2163
- return this.viewContext.templateComponent.lineBreakEmptyStringTemplate;
2199
+ Editor.string(this.viewContext.editor, parentPath) === '');
2200
+ }
2201
+ // COMPAT: If the text is empty, it's because it's on the edge of an inline
2202
+ // node, so we render a zero-width space so that the selection can be
2203
+ // inserted next to it still.
2204
+ isEmptyText() {
2205
+ return this.context.leaf.text === '';
2206
+ }
2207
+ // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
2208
+ // so we need to add an extra trailing new lines to prevent that.
2209
+ isCompatibleString() {
2210
+ return this.context.isLast && this.context.leaf.text.slice(-1) === '\n';
2211
+ }
2212
+ // COMPAT: Render text inside void nodes with a zero-width space.
2213
+ // So the node can contain selection but the text is not visible.
2214
+ isVoid() {
2215
+ return this.viewContext.editor.isVoid(this.context.parent);
2216
+ }
2217
+ getViewType() {
2218
+ if (this.isVoid()) {
2219
+ return this.viewContext.templateComponent.voidStringTemplate;
2164
2220
  }
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 === '') {
2221
+ if (this.isLineBreakEmptyString()) {
2222
+ return SlateDefaultStringComponent;
2223
+ }
2224
+ if (this.isEmptyText()) {
2169
2225
  return this.viewContext.templateComponent.emptyTextTemplate;
2170
2226
  }
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;
2227
+ if (this.isCompatibleString()) {
2228
+ return this.viewContext.templateComponent.compatibleStringTemplate;
2175
2229
  }
2176
2230
  return SlateDefaultStringComponent;
2177
2231
  }
2232
+ getType() {
2233
+ if (this.isLineBreakEmptyString()) {
2234
+ return 'lineBreakEmptyString';
2235
+ }
2236
+ return 'string';
2237
+ }
2178
2238
  getContext() {
2239
+ const stringType = this.getType();
2179
2240
  return {
2180
2241
  text: this.context.leaf.text,
2181
- elementStringLength: Node.string(this.context.parent).length
2242
+ elementStringLength: Node.string(this.context.parent).length,
2243
+ type: stringType
2182
2244
  };
2183
2245
  }
2184
2246
  memoizedContext(prev, next) {
@@ -2262,10 +2324,10 @@ class SlateLeavesComponent extends ViewContainer {
2262
2324
  }
2263
2325
  ngOnInit() {
2264
2326
  this.leaves = Text$1.decorations(this.context.text, this.context.decorations);
2265
- this.leafContexts = this.getLeafCotexts();
2327
+ this.leafContexts = this.getLeafContexts();
2266
2328
  this.initialized = true;
2267
2329
  }
2268
- getLeafCotexts() {
2330
+ getLeafContexts() {
2269
2331
  return this.leaves.map((leaf, index) => {
2270
2332
  return {
2271
2333
  leaf,
@@ -2286,7 +2348,7 @@ class SlateLeavesComponent extends ViewContainer {
2286
2348
  if (previousValue.text !== currentValue.text || !isDecoratorRangeListEqual(previousValue.decorations, currentValue.decorations)) {
2287
2349
  this.leaves = Text$1.decorations(this.context.text, this.context.decorations);
2288
2350
  }
2289
- this.leafContexts = this.getLeafCotexts();
2351
+ this.leafContexts = this.getLeafContexts();
2290
2352
  }
2291
2353
  trackBy(index, item) {
2292
2354
  return index;
@@ -2635,7 +2697,7 @@ class SlateEditableComponent {
2635
2697
  this.initializeViewContext();
2636
2698
  this.initializeContext();
2637
2699
  // remove unused DOM, just keep templateComponent instance
2638
- this.templateElementRef.nativeElement.remove();
2700
+ // this.templateElementRef.nativeElement.remove();
2639
2701
  // add browser class
2640
2702
  let browserClass = IS_FIREFOX ? 'firefox' : IS_SAFARI ? 'safari' : '';
2641
2703
  browserClass && this.elementRef.nativeElement.classList.add(browserClass);
@@ -3833,5 +3895,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImpor
3833
3895
  * Generated bundle index. Do not edit.
3834
3896
  */
3835
3897
 
3836
- export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, DOMComment, DOMElement, DOMNode, DOMRange, DOMSelection, DOMStaticRange, DOMText, EDITOR_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_PLACEHOLDER, EDITOR_TO_WINDOW, ELEMENT_TO_COMPONENT, ELEMENT_TO_NODE, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_CLICKING, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_QQBROWSER, IS_READONLY, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, KEY_TO_ELEMENT, Key, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, SlateChildrenComponent, SlateDefaultStringComponent, SlateEditableComponent, SlateElementComponent, SlateErrorCode, SlateLeavesComponent, SlateModule, SlateStringComponent, check, getCardTargetAttribute, getClipboardData, getDefaultView, getEditableChild, getEditableChildAndIndex, getPlainText, getSlateFragmentAttribute, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hasShadowRoot, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isComponentType, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isDecoratorRangeListEqual, isPlainTextOnlyPaste, isTemplateRef, isValid, normalize, normalizeDOMPoint, shallowCompare, withAngular };
3898
+ export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, DOMComment, DOMElement, DOMNode, DOMRange, DOMSelection, DOMStaticRange, DOMText, EDITOR_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_PLACEHOLDER, EDITOR_TO_WINDOW, ELEMENT_TO_COMPONENT, ELEMENT_TO_NODE, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_CLICKING, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_QQBROWSER, IS_READONLY, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, KEY_TO_ELEMENT, Key, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, SlateChildrenComponent, SlateDefaultStringComponent, SlateEditableComponent, SlateElementComponent, SlateErrorCode, SlateLeavesComponent, SlateModule, SlateStringComponent, check, defaultScrollSelectionIntoView, getCardTargetAttribute, getClipboardData, getDefaultView, getEditableChild, getEditableChildAndIndex, getPlainText, getSlateFragmentAttribute, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hasShadowRoot, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isComponentType, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isDecoratorRangeListEqual, isPlainTextOnlyPaste, isTemplateRef, isValid, normalize, normalizeDOMPoint, shallowCompare, withAngular };
3837
3899
  //# sourceMappingURL=slate-angular.mjs.map