markstream-angular 2.0.0 → 2.0.1
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.
|
@@ -4389,6 +4389,7 @@ class InfographicBlockNodeComponent {
|
|
|
4389
4389
|
this.viewReady = false;
|
|
4390
4390
|
this.destroyed = false;
|
|
4391
4391
|
this.renderToken = 0;
|
|
4392
|
+
this.renderScheduled = false;
|
|
4392
4393
|
this.copyTimer = null;
|
|
4393
4394
|
this.infographicInstance = null;
|
|
4394
4395
|
}
|
|
@@ -4469,17 +4470,18 @@ class InfographicBlockNodeComponent {
|
|
|
4469
4470
|
}
|
|
4470
4471
|
ngAfterViewInit() {
|
|
4471
4472
|
this.viewReady = true;
|
|
4472
|
-
|
|
4473
|
+
this.scheduleInfographicRender();
|
|
4473
4474
|
}
|
|
4474
4475
|
ngOnChanges() {
|
|
4475
4476
|
if (!this.viewReady)
|
|
4476
4477
|
return;
|
|
4477
4478
|
this.containerMinHeight = '';
|
|
4478
|
-
|
|
4479
|
+
this.scheduleInfographicRender();
|
|
4479
4480
|
}
|
|
4480
4481
|
ngOnDestroy() {
|
|
4481
4482
|
this.destroyed = true;
|
|
4482
4483
|
this.renderToken += 1;
|
|
4484
|
+
this.renderScheduled = false;
|
|
4483
4485
|
if (this.copyTimer != null && typeof window !== 'undefined')
|
|
4484
4486
|
window.clearTimeout(this.copyTimer);
|
|
4485
4487
|
this.destroyInfographic();
|
|
@@ -4537,7 +4539,7 @@ class InfographicBlockNodeComponent {
|
|
|
4537
4539
|
toggleCollapsed() {
|
|
4538
4540
|
this.collapsed = !this.collapsed;
|
|
4539
4541
|
if (!this.collapsed)
|
|
4540
|
-
|
|
4542
|
+
this.scheduleInfographicRender();
|
|
4541
4543
|
this.cdr.markForCheck();
|
|
4542
4544
|
}
|
|
4543
4545
|
adjustZoom(delta) {
|
|
@@ -4548,6 +4550,16 @@ class InfographicBlockNodeComponent {
|
|
|
4548
4550
|
this.zoom = 1;
|
|
4549
4551
|
this.cdr.markForCheck();
|
|
4550
4552
|
}
|
|
4553
|
+
scheduleInfographicRender() {
|
|
4554
|
+
if (this.destroyed || this.renderScheduled)
|
|
4555
|
+
return;
|
|
4556
|
+
this.renderScheduled = true;
|
|
4557
|
+
queueMicrotask(() => {
|
|
4558
|
+
this.renderScheduled = false;
|
|
4559
|
+
if (!this.destroyed)
|
|
4560
|
+
void this.renderInfographic();
|
|
4561
|
+
});
|
|
4562
|
+
}
|
|
4551
4563
|
async renderInfographic() {
|
|
4552
4564
|
if (this.destroyed || !this.viewReady || this.collapsed || this.showSource)
|
|
4553
4565
|
return;
|
|
@@ -4565,32 +4577,61 @@ class InfographicBlockNodeComponent {
|
|
|
4565
4577
|
this.renderToken += 1;
|
|
4566
4578
|
this.rendering = true;
|
|
4567
4579
|
this.error = '';
|
|
4568
|
-
this.svgMarkup = '';
|
|
4569
|
-
clearElement(host);
|
|
4570
4580
|
this.cdr.markForCheck();
|
|
4571
4581
|
return;
|
|
4572
4582
|
}
|
|
4583
|
+
const final = !this.resolvedLoading;
|
|
4573
4584
|
const token = ++this.renderToken;
|
|
4574
4585
|
this.rendering = true;
|
|
4575
4586
|
this.error = '';
|
|
4576
4587
|
this.cdr.markForCheck();
|
|
4588
|
+
let nextInstance = null;
|
|
4589
|
+
let previousChildren = null;
|
|
4577
4590
|
try {
|
|
4578
4591
|
const InfographicClass = await getInfographic();
|
|
4579
4592
|
if (!InfographicClass)
|
|
4580
4593
|
throw new Error('Infographic renderer is not available.');
|
|
4581
4594
|
if (this.destroyed || token !== this.renderToken)
|
|
4582
4595
|
return;
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
const instance = new InfographicClass({
|
|
4596
|
+
previousChildren = Array.from(host.childNodes);
|
|
4597
|
+
nextInstance = new InfographicClass({
|
|
4586
4598
|
container: host,
|
|
4587
4599
|
width: '100%',
|
|
4588
4600
|
height: '100%',
|
|
4589
4601
|
});
|
|
4590
|
-
|
|
4591
|
-
|
|
4602
|
+
let renderErrorMessage = '';
|
|
4603
|
+
let renderCompleted = false;
|
|
4604
|
+
nextInstance.on?.('error', (error) => {
|
|
4605
|
+
const errors = Array.isArray(error) ? error : [error];
|
|
4606
|
+
renderErrorMessage = errors
|
|
4607
|
+
.map((item) => {
|
|
4608
|
+
if (item instanceof Error)
|
|
4609
|
+
return item.message;
|
|
4610
|
+
if (typeof item === 'string')
|
|
4611
|
+
return item;
|
|
4612
|
+
if (item && typeof item === 'object' && 'message' in item)
|
|
4613
|
+
return String(item.message ?? '');
|
|
4614
|
+
return String(item ?? '');
|
|
4615
|
+
})
|
|
4616
|
+
.filter(Boolean)
|
|
4617
|
+
.join('; ');
|
|
4618
|
+
});
|
|
4619
|
+
nextInstance.on?.('rendered', () => {
|
|
4620
|
+
renderCompleted = true;
|
|
4621
|
+
});
|
|
4622
|
+
nextInstance.render(source);
|
|
4623
|
+
if (renderErrorMessage)
|
|
4624
|
+
throw new Error(renderErrorMessage);
|
|
4625
|
+
const nextChildren = Array.from(host.childNodes);
|
|
4626
|
+
const replacedChildren = nextChildren.length > 0 && (nextChildren.length !== previousChildren.length
|
|
4627
|
+
|| nextChildren.some((child, index) => child !== previousChildren?.[index]));
|
|
4628
|
+
if (!renderCompleted && !replacedChildren)
|
|
4629
|
+
throw new Error('Infographic render returned empty output.');
|
|
4592
4630
|
if (this.destroyed || token !== this.renderToken)
|
|
4593
4631
|
return;
|
|
4632
|
+
this.infographicInstance?.destroy?.();
|
|
4633
|
+
this.infographicInstance = nextInstance;
|
|
4634
|
+
nextInstance = null;
|
|
4594
4635
|
const svg = host.querySelector('svg');
|
|
4595
4636
|
this.svgMarkup = svg ? svg.outerHTML : '';
|
|
4596
4637
|
const measuredHeight = host.scrollHeight;
|
|
@@ -4601,13 +4642,21 @@ class InfographicBlockNodeComponent {
|
|
|
4601
4642
|
catch (error) {
|
|
4602
4643
|
if (this.destroyed || token !== this.renderToken)
|
|
4603
4644
|
return;
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
this.
|
|
4607
|
-
|
|
4608
|
-
|
|
4645
|
+
nextInstance?.destroy?.();
|
|
4646
|
+
nextInstance = null;
|
|
4647
|
+
if (final && !this.resolvedLoading && source === this.code.trim()) {
|
|
4648
|
+
this.destroyInfographic();
|
|
4649
|
+
this.svgMarkup = '';
|
|
4650
|
+
this.showSource = true;
|
|
4651
|
+
this.error = error instanceof Error ? error.message : 'Failed to render infographic.';
|
|
4652
|
+
clearElement(host);
|
|
4653
|
+
}
|
|
4654
|
+
else if (previousChildren) {
|
|
4655
|
+
host.replaceChildren(...previousChildren);
|
|
4656
|
+
}
|
|
4609
4657
|
}
|
|
4610
4658
|
finally {
|
|
4659
|
+
nextInstance?.destroy?.();
|
|
4611
4660
|
if (token === this.renderToken) {
|
|
4612
4661
|
this.rendering = false;
|
|
4613
4662
|
this.cdr.markForCheck();
|
|
@@ -4739,7 +4788,9 @@ class InfographicBlockNodeComponent {
|
|
|
4739
4788
|
#previewHost
|
|
4740
4789
|
class="infographic-render"
|
|
4741
4790
|
[style.minHeight]="resolvedContainerMinHeight"
|
|
4742
|
-
|
|
4791
|
+
>
|
|
4792
|
+
<pre *ngIf="!svgMarkup && !error" class="markstream-angular-enhanced-block__source infographic-pending-source"><code translate="no">{{ code }}</code></pre>
|
|
4793
|
+
</div>
|
|
4743
4794
|
|
|
4744
4795
|
<pre *ngIf="showSource" class="markstream-angular-enhanced-block__source"><code translate="no">{{ code }}</code></pre>
|
|
4745
4796
|
|
|
@@ -4872,7 +4923,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.26", ngImpo
|
|
|
4872
4923
|
#previewHost
|
|
4873
4924
|
class="infographic-render"
|
|
4874
4925
|
[style.minHeight]="resolvedContainerMinHeight"
|
|
4875
|
-
|
|
4926
|
+
>
|
|
4927
|
+
<pre *ngIf="!svgMarkup && !error" class="markstream-angular-enhanced-block__source infographic-pending-source"><code translate="no">{{ code }}</code></pre>
|
|
4928
|
+
</div>
|
|
4876
4929
|
|
|
4877
4930
|
<pre *ngIf="showSource" class="markstream-angular-enhanced-block__source"><code translate="no">{{ code }}</code></pre>
|
|
4878
4931
|
|