pict-section-fileview 1.0.0 → 1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Steven Velozo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-fileview",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A universal, embeddable file viewer: one control that detects a file's type (from a Sluice record or a bare range-served URL) and dispatches it to the right renderer — code, markdown, images (ordinary + enormous), PDF, video and audio — delegating each media kind to a purpose-built child section.",
5
5
  "main": "source/Pict-Section-Fileview.js",
6
6
  "scripts": {
@@ -470,6 +470,22 @@ class PictFileviewProvider extends libPictProvider
470
470
  this.pict.ContentAssignment.assignContent(this.toolbarSelector, tmpHTML);
471
471
  }
472
472
 
473
+ /**
474
+ * True when the stage element exists AND still holds mounted content. The reuse-one-per-kind fast-paths in
475
+ * _mountResolved() assume the previously mounted DOM is still on the page -- but a host that re-stamps our mount
476
+ * point on its own re-render (e.g. the fileview host div lives inside the consumer view's template, so every
477
+ * consumer render() wipes it) leaves _currentHandle pointing at detached nodes. There "same descriptor -> return"
478
+ * and the in-place update() would both paint nothing (blank stage). When the stage was wiped this returns false so
479
+ * _mountResolved falls through to a clean destroy + re-mount. DOM-less contexts (SSR / unit tests) report true so
480
+ * they never force a churn the environment cannot observe.
481
+ */
482
+ _isStagePopulated()
483
+ {
484
+ if (typeof document === 'undefined') { return true; }
485
+ let tmpStageElement = document.querySelector(this.stageSelector);
486
+ return !!(tmpStageElement && tmpStageElement.children && tmpStageElement.children.length > 0);
487
+ }
488
+
473
489
  _mountResolved()
474
490
  {
475
491
  const tmpStage = this.stageSelector;
@@ -499,11 +515,15 @@ class PictFileviewProvider extends libPictProvider
499
515
  }
500
516
 
501
517
  // Reuse-one-per-kind. Pict has no removeView, so re-minting a child per file leaks views/observers. When
502
- // the resolved renderer is the one already mounted:
518
+ // the resolved renderer is the one already mounted AND its mounted DOM is still on the page:
503
519
  // - same descriptor identity (a bare re-render) → nothing to do;
504
520
  // - new file, renderer exposes update() → re-feed the live child in place, no teardown;
505
521
  // - otherwise → fall through to a clean destroy + re-mount.
506
- if (this._currentHandle && this._currentHandle.Hash === tmpRenderer.Hash)
522
+ // The _isStagePopulated() guard is essential: a consumer that re-stamps our host on its own re-render wipes the
523
+ // stage out from under us, detaching the mounted child. Without the guard both fast-paths leave a blank stage;
524
+ // with it we fall through to a re-mount and repaint. (A consumer with a stable host never trips it, so normal
525
+ // file-to-file switching still reuses the child via update() with no churn.)
526
+ if (this._currentHandle && this._currentHandle.Hash === tmpRenderer.Hash && this._isStagePopulated())
507
527
  {
508
528
  if (this._currentHandle.Descriptor === this._descriptor) { return; }
509
529
  if (typeof this._currentHandle.update === 'function')