markstream-angular 2.0.0 → 2.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.
@@ -1100,6 +1100,12 @@ class CodeBlockNodeComponent {
1100
1100
  this.destroyed = false;
1101
1101
  this.copyTimer = null;
1102
1102
  this.deferredHeightSyncRaf = null;
1103
+ this.hasEditorInput = false;
1104
+ this.lastEditorIsDiff = false;
1105
+ this.lastEditorOriginalCode = '';
1106
+ this.lastEditorResolvedCode = '';
1107
+ this.lastEditorLanguage = '';
1108
+ this.lastEditorShowLoadingPlaceholder = false;
1103
1109
  this.lastRuntimeHostKey = '';
1104
1110
  this.closeInlinePreview = () => {
1105
1111
  this.inlinePreviewOpen = false;
@@ -1326,13 +1332,31 @@ class CodeBlockNodeComponent {
1326
1332
  themes[1],
1327
1333
  this.resolvedShowLineNumbers ? 'lines' : 'no-lines',
1328
1334
  ].join('\u0000');
1329
- if (nextOptions !== this.lastCodeBlockOptions || runtimeHostKey !== this.lastRuntimeHostKey) {
1335
+ const runtimeChanged = nextOptions !== this.lastCodeBlockOptions || runtimeHostKey !== this.lastRuntimeHostKey;
1336
+ if (runtimeChanged) {
1330
1337
  this.lastCodeBlockOptions = nextOptions;
1331
1338
  this.lastRuntimeHostKey = runtimeHostKey;
1332
1339
  this.disposeRuntimeHelpers();
1333
1340
  }
1341
+ const isDiff = this.isDiff;
1342
+ const originalCode = this.originalCode;
1343
+ const resolvedCode = this.resolvedCode;
1344
+ const language = this.language;
1345
+ const showLoadingPlaceholder = this.showLoadingPlaceholder;
1346
+ const editorInputChanged = !this.hasEditorInput
1347
+ || isDiff !== this.lastEditorIsDiff
1348
+ || originalCode !== this.lastEditorOriginalCode
1349
+ || resolvedCode !== this.lastEditorResolvedCode
1350
+ || language !== this.lastEditorLanguage
1351
+ || showLoadingPlaceholder !== this.lastEditorShowLoadingPlaceholder;
1352
+ this.hasEditorInput = true;
1353
+ this.lastEditorIsDiff = isDiff;
1354
+ this.lastEditorOriginalCode = originalCode;
1355
+ this.lastEditorResolvedCode = resolvedCode;
1356
+ this.lastEditorLanguage = language;
1357
+ this.lastEditorShowLoadingPlaceholder = showLoadingPlaceholder;
1334
1358
  this.applyInitialFontSize();
1335
- if (!this.viewReady)
1359
+ if (!this.viewReady || (!runtimeChanged && !editorInputChanged))
1336
1360
  return;
1337
1361
  void this.syncEditorState();
1338
1362
  }
@@ -4389,6 +4413,7 @@ class InfographicBlockNodeComponent {
4389
4413
  this.viewReady = false;
4390
4414
  this.destroyed = false;
4391
4415
  this.renderToken = 0;
4416
+ this.renderScheduled = false;
4392
4417
  this.copyTimer = null;
4393
4418
  this.infographicInstance = null;
4394
4419
  }
@@ -4469,17 +4494,18 @@ class InfographicBlockNodeComponent {
4469
4494
  }
4470
4495
  ngAfterViewInit() {
4471
4496
  this.viewReady = true;
4472
- queueMicrotask(() => void this.renderInfographic());
4497
+ this.scheduleInfographicRender();
4473
4498
  }
4474
4499
  ngOnChanges() {
4475
4500
  if (!this.viewReady)
4476
4501
  return;
4477
4502
  this.containerMinHeight = '';
4478
- queueMicrotask(() => void this.renderInfographic());
4503
+ this.scheduleInfographicRender();
4479
4504
  }
4480
4505
  ngOnDestroy() {
4481
4506
  this.destroyed = true;
4482
4507
  this.renderToken += 1;
4508
+ this.renderScheduled = false;
4483
4509
  if (this.copyTimer != null && typeof window !== 'undefined')
4484
4510
  window.clearTimeout(this.copyTimer);
4485
4511
  this.destroyInfographic();
@@ -4537,7 +4563,7 @@ class InfographicBlockNodeComponent {
4537
4563
  toggleCollapsed() {
4538
4564
  this.collapsed = !this.collapsed;
4539
4565
  if (!this.collapsed)
4540
- queueMicrotask(() => void this.renderInfographic());
4566
+ this.scheduleInfographicRender();
4541
4567
  this.cdr.markForCheck();
4542
4568
  }
4543
4569
  adjustZoom(delta) {
@@ -4548,6 +4574,16 @@ class InfographicBlockNodeComponent {
4548
4574
  this.zoom = 1;
4549
4575
  this.cdr.markForCheck();
4550
4576
  }
4577
+ scheduleInfographicRender() {
4578
+ if (this.destroyed || this.renderScheduled)
4579
+ return;
4580
+ this.renderScheduled = true;
4581
+ queueMicrotask(() => {
4582
+ this.renderScheduled = false;
4583
+ if (!this.destroyed)
4584
+ void this.renderInfographic();
4585
+ });
4586
+ }
4551
4587
  async renderInfographic() {
4552
4588
  if (this.destroyed || !this.viewReady || this.collapsed || this.showSource)
4553
4589
  return;
@@ -4565,32 +4601,61 @@ class InfographicBlockNodeComponent {
4565
4601
  this.renderToken += 1;
4566
4602
  this.rendering = true;
4567
4603
  this.error = '';
4568
- this.svgMarkup = '';
4569
- clearElement(host);
4570
4604
  this.cdr.markForCheck();
4571
4605
  return;
4572
4606
  }
4607
+ const final = !this.resolvedLoading;
4573
4608
  const token = ++this.renderToken;
4574
4609
  this.rendering = true;
4575
4610
  this.error = '';
4576
4611
  this.cdr.markForCheck();
4612
+ let nextInstance = null;
4613
+ let previousChildren = null;
4577
4614
  try {
4578
4615
  const InfographicClass = await getInfographic();
4579
4616
  if (!InfographicClass)
4580
4617
  throw new Error('Infographic renderer is not available.');
4581
4618
  if (this.destroyed || token !== this.renderToken)
4582
4619
  return;
4583
- this.destroyInfographic();
4584
- clearElement(host);
4585
- const instance = new InfographicClass({
4620
+ previousChildren = Array.from(host.childNodes);
4621
+ nextInstance = new InfographicClass({
4586
4622
  container: host,
4587
4623
  width: '100%',
4588
4624
  height: '100%',
4589
4625
  });
4590
- this.infographicInstance = instance;
4591
- instance.render(source);
4626
+ let renderErrorMessage = '';
4627
+ let renderCompleted = false;
4628
+ nextInstance.on?.('error', (error) => {
4629
+ const errors = Array.isArray(error) ? error : [error];
4630
+ renderErrorMessage = errors
4631
+ .map((item) => {
4632
+ if (item instanceof Error)
4633
+ return item.message;
4634
+ if (typeof item === 'string')
4635
+ return item;
4636
+ if (item && typeof item === 'object' && 'message' in item)
4637
+ return String(item.message ?? '');
4638
+ return String(item ?? '');
4639
+ })
4640
+ .filter(Boolean)
4641
+ .join('; ');
4642
+ });
4643
+ nextInstance.on?.('rendered', () => {
4644
+ renderCompleted = true;
4645
+ });
4646
+ nextInstance.render(source);
4647
+ if (renderErrorMessage)
4648
+ throw new Error(renderErrorMessage);
4649
+ const nextChildren = Array.from(host.childNodes);
4650
+ const replacedChildren = nextChildren.length > 0 && (nextChildren.length !== previousChildren.length
4651
+ || nextChildren.some((child, index) => child !== previousChildren?.[index]));
4652
+ if (!renderCompleted && !replacedChildren)
4653
+ throw new Error('Infographic render returned empty output.');
4592
4654
  if (this.destroyed || token !== this.renderToken)
4593
4655
  return;
4656
+ this.infographicInstance?.destroy?.();
4657
+ this.infographicInstance = nextInstance;
4658
+ nextInstance = null;
4594
4659
  const svg = host.querySelector('svg');
4595
4660
  this.svgMarkup = svg ? svg.outerHTML : '';
4596
4661
  const measuredHeight = host.scrollHeight;
@@ -4601,13 +4666,21 @@ class InfographicBlockNodeComponent {
4601
4666
  catch (error) {
4602
4667
  if (this.destroyed || token !== this.renderToken)
4603
4668
  return;
4604
- this.destroyInfographic();
4605
- this.svgMarkup = '';
4606
- this.showSource = true;
4607
- this.error = error instanceof Error ? error.message : 'Failed to render infographic.';
4608
- clearElement(host);
4669
+ nextInstance?.destroy?.();
4670
+ nextInstance = null;
4671
+ if (final && !this.resolvedLoading && source === this.code.trim()) {
4672
+ this.destroyInfographic();
4673
+ this.svgMarkup = '';
4674
+ this.showSource = true;
4675
+ this.error = error instanceof Error ? error.message : 'Failed to render infographic.';
4676
+ clearElement(host);
4677
+ }
4678
+ else if (previousChildren) {
4679
+ host.replaceChildren(...previousChildren);
4680
+ }
4609
4681
  }
4610
4682
  finally {
4683
+ nextInstance?.destroy?.();
4611
4684
  if (token === this.renderToken) {
4612
4685
  this.rendering = false;
4613
4686
  this.cdr.markForCheck();
@@ -4739,7 +4812,9 @@ class InfographicBlockNodeComponent {
4739
4812
  #previewHost
4740
4813
  class="infographic-render"
4741
4814
  [style.minHeight]="resolvedContainerMinHeight"
4742
- ></div>
4815
+ >
4816
+ <pre *ngIf="!svgMarkup && !error" class="markstream-angular-enhanced-block__source infographic-pending-source"><code translate="no">{{ code }}</code></pre>
4817
+ </div>
4743
4818
 
4744
4819
  <pre *ngIf="showSource" class="markstream-angular-enhanced-block__source"><code translate="no">{{ code }}</code></pre>
4745
4820
 
@@ -4872,7 +4947,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.26", ngImpo
4872
4947
  #previewHost
4873
4948
  class="infographic-render"
4874
4949
  [style.minHeight]="resolvedContainerMinHeight"
4875
- ></div>
4950
+ >
4951
+ <pre *ngIf="!svgMarkup && !error" class="markstream-angular-enhanced-block__source infographic-pending-source"><code translate="no">{{ code }}</code></pre>
4952
+ </div>
4876
4953
 
4877
4954
  <pre *ngIf="showSource" class="markstream-angular-enhanced-block__source"><code translate="no">{{ code }}</code></pre>
4878
4955