@vertexvis/doc-viewer 1.0.0-canary.6 → 1.0.0-canary.7

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.
@@ -663,6 +663,14 @@ class DocumentLayersController {
663
663
  function getElementBoundingClientRect(element) {
664
664
  return element.getBoundingClientRect();
665
665
  }
666
+ function getAllVertexElementChildren(element) {
667
+ return getAllChildren(element)
668
+ .filter(node => node.nodeName.startsWith('VERTEX-'))
669
+ .reduce((elements, element) => [...elements, element, ...getAllChildren(element)], []);
670
+ }
671
+ function getAllChildren(element) {
672
+ return Array.from(element.querySelectorAll('*'));
673
+ }
666
674
 
667
675
  const DRAG_PIXEL_THRESHOLD = 2;
668
676
  class PanInteractionHandler {
@@ -34644,6 +34652,7 @@ const VertexDocumentViewer = class {
34644
34652
  this.handlePageLoaded = this.handlePageLoaded.bind(this);
34645
34653
  this.handlePageDrawn = this.handlePageDrawn.bind(this);
34646
34654
  this.resizeObserver = new ResizeObserver(this.handleElementResize);
34655
+ this.registerSlotChangeListeners();
34647
34656
  }
34648
34657
  componentShouldUpdate(newValue, oldValue, propName) {
34649
34658
  // Ignore updates to the documentState property, as it is only intended to reflect the current state
@@ -34655,6 +34664,7 @@ const VertexDocumentViewer = class {
34655
34664
  (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
34656
34665
  this.updateComponentDimensions();
34657
34666
  this.handleSrcChange();
34667
+ this.injectViewerApi();
34658
34668
  }
34659
34669
  disconnectedCallback() {
34660
34670
  var _a;
@@ -34742,9 +34752,9 @@ const VertexDocumentViewer = class {
34742
34752
  this.updateInteractionHandler();
34743
34753
  }
34744
34754
  render() {
34745
- return (index.h(index.Host, { key: '45d2a2dceb6008a12702493edc50337f5d3568f7' }, index.h("div", { key: '862161f98d61fdf01996202e3e9be6281eea62ae', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, index.h("div", { key: '05936dfbd06a9b0a05f21d7ada870a40109e93d0', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
34755
+ return (index.h(index.Host, { key: 'f1ddf0b4e321bc244a5d757e48f6d71c23caca3c' }, index.h("div", { key: '174c64c537f4b0f1c45fc6543e5b7f54515e4063', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, index.h("div", { key: '4c47dadba03b32bde017252a9a8ea7f6e6d323f3', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
34746
34756
  'enable-pointer-events ': window.PointerEvent != null,
34747
- }) }, index.h("canvas", { key: '230fc4741a7eb3c621d93056ab959d3cfd3d9a20', role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: '6720a16f6e5ee1bfd605dc8adb6413a4f6d44e24' }))));
34757
+ }) }, index.h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), index.h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
34748
34758
  }
34749
34759
  getDocumentApi() {
34750
34760
  if (this.documentApi == null) {
@@ -34816,6 +34826,19 @@ const VertexDocumentViewer = class {
34816
34826
  }
34817
34827
  handler.initialize(this.canvasEl);
34818
34828
  }
34829
+ registerSlotChangeListeners() {
34830
+ this.mutationObserver = new MutationObserver(_ => this.injectViewerApi());
34831
+ this.mutationObserver.observe(this.hostEl, {
34832
+ childList: true,
34833
+ subtree: true,
34834
+ });
34835
+ }
34836
+ injectViewerApi() {
34837
+ getAllVertexElementChildren(this.hostEl).forEach(node => {
34838
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34839
+ node.viewer = this.hostEl;
34840
+ });
34841
+ }
34819
34842
  get hostEl() { return index.getElement(this); }
34820
34843
  static get watchers() { return {
34821
34844
  "src": [{
@@ -6,7 +6,7 @@ import { h, Host } from "@stencil/core";
6
6
  import { Dimensions } from "@vertexvis/geometry";
7
7
  import classNames from "classnames";
8
8
  import { DocumentLayersController } from "../../lib/document/layers/controller";
9
- import { getElementBoundingClientRect } from "../../lib/dom";
9
+ import { getAllVertexElementChildren, getElementBoundingClientRect } from "../../lib/dom";
10
10
  import { PanInteractionHandler } from "../../lib/interactions/pan-interaction-handler";
11
11
  import { PdfJsProvider } from "../../lib/pdf/pdfjs-provider";
12
12
  export class VertexDocumentViewer {
@@ -35,6 +35,7 @@ export class VertexDocumentViewer {
35
35
  this.handlePageLoaded = this.handlePageLoaded.bind(this);
36
36
  this.handlePageDrawn = this.handlePageDrawn.bind(this);
37
37
  this.resizeObserver = new ResizeObserver(this.handleElementResize);
38
+ this.registerSlotChangeListeners();
38
39
  }
39
40
  componentShouldUpdate(newValue, oldValue, propName) {
40
41
  // Ignore updates to the documentState property, as it is only intended to reflect the current state
@@ -46,6 +47,7 @@ export class VertexDocumentViewer {
46
47
  (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.hostEl);
47
48
  this.updateComponentDimensions();
48
49
  this.handleSrcChange();
50
+ this.injectViewerApi();
49
51
  }
50
52
  disconnectedCallback() {
51
53
  var _a;
@@ -133,9 +135,9 @@ export class VertexDocumentViewer {
133
135
  this.updateInteractionHandler();
134
136
  }
135
137
  render() {
136
- return (h(Host, { key: '45d2a2dceb6008a12702493edc50337f5d3568f7' }, h("div", { key: '862161f98d61fdf01996202e3e9be6281eea62ae', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, h("div", { key: '05936dfbd06a9b0a05f21d7ada870a40109e93d0', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
138
+ return (h(Host, { key: 'f1ddf0b4e321bc244a5d757e48f6d71c23caca3c' }, h("div", { key: '174c64c537f4b0f1c45fc6543e5b7f54515e4063', ref: ref => (this.viewerContainerElement = ref), class: "viewer-container", onContextMenu: event => event.preventDefault() }, h("div", { key: '4c47dadba03b32bde017252a9a8ea7f6e6d323f3', ref: ref => (this.canvasContainerElement = ref), class: classNames('canvas-container', {
137
139
  'enable-pointer-events ': window.PointerEvent != null,
138
- }) }, h("canvas", { key: '230fc4741a7eb3c621d93056ab959d3cfd3d9a20', role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: '6720a16f6e5ee1bfd605dc8adb6413a4f6d44e24' }))));
140
+ }) }, h("canvas", { key: 'b8697a0a5be45d212b16b3bd4b7b50a70c0a1143', role: "presentation", ref: el => (this.canvasEl = el) })), h("slot", { key: 'c9ec02fd4bfaa251d8fc742fc868b0d91ee70618' }))));
139
141
  }
140
142
  getDocumentApi() {
141
143
  if (this.documentApi == null) {
@@ -207,6 +209,19 @@ export class VertexDocumentViewer {
207
209
  }
208
210
  handler.initialize(this.canvasEl);
209
211
  }
212
+ registerSlotChangeListeners() {
213
+ this.mutationObserver = new MutationObserver(_ => this.injectViewerApi());
214
+ this.mutationObserver.observe(this.hostEl, {
215
+ childList: true,
216
+ subtree: true,
217
+ });
218
+ }
219
+ injectViewerApi() {
220
+ getAllVertexElementChildren(this.hostEl).forEach(node => {
221
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
222
+ node.viewer = this.hostEl;
223
+ });
224
+ }
210
225
  static get is() { return "vertex-document-viewer"; }
211
226
  static get encapsulation() { return "shadow"; }
212
227
  static get originalStyleUrls() {
@@ -4,3 +4,11 @@
4
4
  export function getElementBoundingClientRect(element) {
5
5
  return element.getBoundingClientRect();
6
6
  }
7
+ export function getAllVertexElementChildren(element) {
8
+ return getAllChildren(element)
9
+ .filter(node => node.nodeName.startsWith('VERTEX-'))
10
+ .reduce((elements, element) => [...elements, element, ...getAllChildren(element)], []);
11
+ }
12
+ function getAllChildren(element) {
13
+ return Array.from(element.querySelectorAll('*'));
14
+ }