@dile/editor 3.0.36 → 3.0.38

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.
package/editor.spec.js CHANGED
@@ -1,4 +1,4 @@
1
- import { describe, it, expect, afterEach } from 'vitest';
1
+ import { describe, it, expect, afterEach, vi } from 'vitest';
2
2
  import './editor.js';
3
3
 
4
4
  describe('dile-editor', () => {
@@ -53,4 +53,20 @@ describe('dile-editor', () => {
53
53
 
54
54
  expect(el.value).toBe('Hello world');
55
55
  });
56
+
57
+ it('applies only the latest external value when initialization finishes', async () => {
58
+ const el = await renderEditor();
59
+ const calls = [];
60
+
61
+ el.editor = { updateEditorContent: (value) => calls.push(value) };
62
+ el.textarea = { value: '' };
63
+ el.initialized = false;
64
+
65
+ el.updateEditorContent('first draft');
66
+ el.updateEditorContent('final draft');
67
+ el.setInitialized();
68
+
69
+ expect(calls).toEqual(['final draft']);
70
+ expect(el.textarea.value).toBe('final draft');
71
+ });
56
72
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/editor",
3
- "version": "3.0.36",
3
+ "version": "3.0.38",
4
4
  "description": "Flexible Web Component for rich text editing with WYSIWYG and Markdown support. Easy to integrate, customizable UI, powered by ProseMirror.",
5
5
  "keywords": [
6
6
  "markdown",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@dile/icons": "^2.5.1",
34
- "@dile/ui": "^3.7.1",
34
+ "@dile/ui": "^3.7.3",
35
35
  "lit": "^2.7.0 || ^3.0.0",
36
36
  "prosemirror-commands": "^1.6.2",
37
37
  "prosemirror-example-setup": "^1.2.3",
@@ -42,5 +42,5 @@
42
42
  "prosemirror-state": "^1.4.3",
43
43
  "prosemirror-view": "^1.37.0"
44
44
  },
45
- "gitHead": "26a2bfb903854225bb67f335e4dd04ac6a4ca1ed"
45
+ "gitHead": "281d2b7e180aab43f03511f4bd34798684081ba0"
46
46
  }
package/src/DileEditor.js CHANGED
@@ -212,10 +212,10 @@ export class DileEditor extends DileI18nMixin(DileEmmitChange(LitElement)) {
212
212
  }
213
213
 
214
214
  updated(changedProperties) {
215
- if(changedProperties.has('value') && this.isValueExternalyUpdated) {
216
- this.updateEditorContent(this.value);
217
- }
218
215
  if(changedProperties.has('value')) {
216
+ if (this.isValueExternalyUpdated) {
217
+ this.updateEditorContent(this.value);
218
+ }
219
219
  this.emmitChange();
220
220
  this.internals.setFormValue(this.value);
221
221
  }
@@ -307,14 +307,29 @@ export class DileEditor extends DileI18nMixin(DileEmmitChange(LitElement)) {
307
307
  }
308
308
 
309
309
  updateEditorContent(value) {
310
- if(this.initialized) {
311
- this.editor.updateEditorContent(value);
312
- this.textarea.value = value;
313
- } else {
314
- setTimeout(() => this.updateEditorContent(value), 100);
310
+ if (!this.editor || !this.textarea) {
311
+ return;
312
+ }
313
+
314
+ this._pendingEditorValue = value;
315
+
316
+ if (this.initialized) {
317
+ this.flushPendingEditorValue();
318
+ return;
315
319
  }
316
320
  }
317
321
 
322
+ flushPendingEditorValue() {
323
+ if (!this.editor || !this.textarea || this._pendingEditorValue === undefined) {
324
+ return;
325
+ }
326
+
327
+ const value = this._pendingEditorValue;
328
+ this.editor.updateEditorContent(value);
329
+ this.textarea.value = value;
330
+ this._pendingEditorValue = undefined;
331
+ }
332
+
318
333
  get isValueExternalyUpdated() {
319
334
  return this.editorMarkdown != this.value
320
335
  }
@@ -340,6 +355,7 @@ export class DileEditor extends DileI18nMixin(DileEmmitChange(LitElement)) {
340
355
 
341
356
  setInitialized() {
342
357
  this.initialized = true;
358
+ this.flushPendingEditorValue();
343
359
  }
344
360
 
345
361
  focus() {