@verdocs/web-sdk 6.5.0-beta.6 → 6.5.0-beta.8

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.
Files changed (32) hide show
  1. package/dist/cjs/verdocs-preview.verdocs-send.verdocs-template-attachments.verdocs-template-build-tabs.verdocs-template-fields.verdocs-template-roles.verdocs-template-settings.entry.cjs.js.map +1 -1
  2. package/dist/cjs/verdocs-preview_7.cjs.entry.js +17 -6
  3. package/dist/collection/components/embeds/verdocs-preview/verdocs-preview.js +16 -4
  4. package/dist/collection/components/embeds/verdocs-preview/verdocs-preview.js.map +1 -1
  5. package/dist/components/{p-CWDgjfsa.js → p-DNdpsH4O.js} +18 -6
  6. package/dist/components/p-DNdpsH4O.js.map +1 -0
  7. package/dist/components/verdocs-build.js +1 -1
  8. package/dist/components/verdocs-preview.js +1 -1
  9. package/dist/custom-elements.json +2422 -0
  10. package/dist/esm/verdocs-preview.verdocs-send.verdocs-template-attachments.verdocs-template-build-tabs.verdocs-template-fields.verdocs-template-roles.verdocs-template-settings.entry.js.map +1 -1
  11. package/dist/esm/verdocs-preview_7.entry.js +17 -6
  12. package/dist/esm-es5/verdocs-preview.verdocs-send.verdocs-template-attachments.verdocs-template-build-tabs.verdocs-template-fields.verdocs-template-roles.verdocs-template-settings.entry.js.map +1 -1
  13. package/dist/esm-es5/verdocs-preview_7.entry.js +2 -2
  14. package/dist/esm-es5/verdocs-preview_7.entry.js.map +1 -1
  15. package/dist/globals.css +112 -0
  16. package/dist/overrides.css +73 -0
  17. package/dist/types/components/embeds/verdocs-preview/verdocs-preview.d.ts +2 -1
  18. package/dist/verdocs-web-sdk/p-074dcd6d.system.entry.js +8 -0
  19. package/dist/verdocs-web-sdk/p-074dcd6d.system.entry.js.map +1 -0
  20. package/dist/verdocs-web-sdk/p-0fe8cbcc.entry.js +8 -0
  21. package/dist/verdocs-web-sdk/p-0fe8cbcc.entry.js.map +1 -0
  22. package/dist/verdocs-web-sdk/p-B8zpaHu-.system.js +1 -1
  23. package/dist/verdocs-web-sdk/p-B_fxHI4F.system.js.map +1 -0
  24. package/dist/verdocs-web-sdk/verdocs-preview.verdocs-send.verdocs-template-attachments.verdocs-template-build-tabs.verdocs-template-fields.verdocs-template-roles.verdocs-template-settings.entry.esm.js.map +1 -1
  25. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  26. package/package.json +3 -2
  27. package/dist/components/p-CWDgjfsa.js.map +0 -1
  28. package/dist/verdocs-web-sdk/p-76986e09.entry.js +0 -8
  29. package/dist/verdocs-web-sdk/p-76986e09.entry.js.map +0 -1
  30. package/dist/verdocs-web-sdk/p-BndeQeTv.system.js.map +0 -1
  31. package/dist/verdocs-web-sdk/p-ebccaef7.system.entry.js +0 -8
  32. package/dist/verdocs-web-sdk/p-ebccaef7.system.entry.js.map +0 -1
@@ -2,6 +2,7 @@
2
2
 
3
3
  var index$1 = require('./index-CQ5bTnED.js');
4
4
  var jsSdk = require('@verdocs/js-sdk');
5
+ var utils = require('./utils-LPO6l9nR.js');
5
6
  var errors = require('./errors-D1XRvnet.js');
6
7
  var Datastore = require('./Datastore-B-sxWSPD.js');
7
8
  var Environment = require('./Environment-3vWt0C1Q.js');
@@ -9,9 +10,8 @@ var Toast = require('./Toast-CFBM1R4z.js');
9
10
  var Icons = require('./Icons-DTZAw6hQ.js');
10
11
  var index$2 = require('./index-CeUF44L9.js');
11
12
  var interact_min = require('./interact.min-BAnZvLwr.js');
12
- var utils = require('./utils-LPO6l9nR.js');
13
- require('./_commonjsHelpers-BJu3ubxk.js');
14
13
  require('./Types-RUyU-svM.js');
14
+ require('./_commonjsHelpers-BJu3ubxk.js');
15
15
 
16
16
  const verdocsPreviewCss = "@-webkit-keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}@keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}verdocs-preview{font-family:var(--verdocs-primary-font, \"Inter\", \"Barlow\", sans-serif);display:-ms-flexbox;display:flex;padding:15px;row-gap:15px;min-height:200px;position:relative;-ms-flex-align:center;align-items:center;-webkit-box-sizing:border-box;box-sizing:border-box;-ms-flex-direction:column;flex-direction:column}verdocs-preview div,verdocs-preview canvas{-webkit-box-sizing:border-box;box-sizing:border-box}";
17
17
 
@@ -20,6 +20,7 @@ const VerdocsPreview = class {
20
20
  index$1.registerInstance(this, hostRef);
21
21
  this.sdkError = index$1.createEvent(this, "sdkError");
22
22
  this.templateListenerId = null;
23
+ this.renderedPages = {};
23
24
  /**
24
25
  * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.
25
26
  */
@@ -70,11 +71,21 @@ const VerdocsPreview = class {
70
71
  (_a = this.sdkError) === null || _a === void 0 ? void 0 : _a.emit(new errors.SDKError(e.message, (_b = e.response) === null || _b === void 0 ? void 0 : _b.status, (_c = e.response) === null || _c === void 0 ? void 0 : _c.data));
71
72
  }
72
73
  }
73
- handlePageRendered(_e) {
74
- // const pageInfo = e.detail as IDocumentPageInfo;
75
- // const fields = (this.template?.fields || []).filter(field => field.page === pageInfo.pageNumber);
74
+ handlePageRendered(e) {
75
+ var _a;
76
+ const pageInfo = e.detail;
77
+ this.renderedPages[`${pageInfo.documentId}:${pageInfo.pageNumber}`] = pageInfo;
78
+ const fields = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.fields) || []).filter(field => {
79
+ // Templates created on the new builder have document_id set, but old ones may not.
80
+ // If document_id is missing, we assume it's for the first document or use legacy logic.
81
+ // However, for this fix, we primarily care about multi-doc templates which should have IDs.
82
+ if (field['document_id']) {
83
+ return field['document_id'] === pageInfo.documentId && field.page === pageInfo.pageNumber;
84
+ }
85
+ return field.page === pageInfo.pageNumber;
86
+ });
76
87
  // console.log('[PREVIEW] Page rendered', pageInfo, fields);
77
- // fields.forEach(field => renderDocumentField(field, pageInfo, {disabled: true, editable: false, draggable: false}));
88
+ fields.forEach(field => utils.renderDocumentField('template', field, pageInfo, { disabled: true, editable: false, draggable: false }));
78
89
  }
79
90
  render() {
80
91
  var _a;
@@ -1,5 +1,6 @@
1
1
  import { getTemplate, integerSequence, VerdocsEndpoint } from "@verdocs/js-sdk";
2
2
  import { Host, h, Fragment } from "@stencil/core";
3
+ import { renderDocumentField } from "../../../utils/utils";
3
4
  import { SDKError } from "../../../utils/errors";
4
5
  import { Store } from "../../../utils/Datastore";
5
6
  /**
@@ -17,6 +18,7 @@ import { Store } from "../../../utils/Datastore";
17
18
  export class VerdocsPreview {
18
19
  constructor() {
19
20
  this.templateListenerId = null;
21
+ this.renderedPages = {};
20
22
  /**
21
23
  * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.
22
24
  */
@@ -67,11 +69,21 @@ export class VerdocsPreview {
67
69
  (_a = this.sdkError) === null || _a === void 0 ? void 0 : _a.emit(new SDKError(e.message, (_b = e.response) === null || _b === void 0 ? void 0 : _b.status, (_c = e.response) === null || _c === void 0 ? void 0 : _c.data));
68
70
  }
69
71
  }
70
- handlePageRendered(_e) {
71
- // const pageInfo = e.detail as IDocumentPageInfo;
72
- // const fields = (this.template?.fields || []).filter(field => field.page === pageInfo.pageNumber);
72
+ handlePageRendered(e) {
73
+ var _a;
74
+ const pageInfo = e.detail;
75
+ this.renderedPages[`${pageInfo.documentId}:${pageInfo.pageNumber}`] = pageInfo;
76
+ const fields = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.fields) || []).filter(field => {
77
+ // Templates created on the new builder have document_id set, but old ones may not.
78
+ // If document_id is missing, we assume it's for the first document or use legacy logic.
79
+ // However, for this fix, we primarily care about multi-doc templates which should have IDs.
80
+ if (field['document_id']) {
81
+ return field['document_id'] === pageInfo.documentId && field.page === pageInfo.pageNumber;
82
+ }
83
+ return field.page === pageInfo.pageNumber;
84
+ });
73
85
  // console.log('[PREVIEW] Page rendered', pageInfo, fields);
74
- // fields.forEach(field => renderDocumentField(field, pageInfo, {disabled: true, editable: false, draggable: false}));
86
+ fields.forEach(field => renderDocumentField('template', field, pageInfo, { disabled: true, editable: false, draggable: false }));
75
87
  }
76
88
  render() {
77
89
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"verdocs-preview.js","sourceRoot":"","sources":["../../../../src/components/embeds/verdocs-preview/verdocs-preview.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,eAAe,EAAa,eAAe,EAAC,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAC,KAAK,EAAgB,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AACpG,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAC,KAAK,EAAC,MAAM,0BAA0B,CAAC;AAE/C;;;;;;;;;;;GAWG;AAMH,MAAM,OAAO,cAAc;IAL3B;QAMU,uBAAkB,GAAG,IAAI,CAAC;QAElC;;WAEG;QACK,aAAQ,GAAoB,eAAe,CAAC,UAAU,EAAE,CAAC;QAEjE;;WAEG;QACK,eAAU,GAAkB,IAAI,CAAC;QAQhC,YAAO,GAAG,IAAI,CAAC;QACf,aAAQ,GAAqB,IAAI,CAAC;KAsG5C;IApGC,oBAAoB;QAClB,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,KAAK,CAAC,SAAS,CACb,WAAW,EACX,IAAI,CAAC,UAAU,EACf,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,EACjD,KAAK,EACL,CAAC,QAAmB,EAAE,EAAE;YACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,IAAI,CAAC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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {getTemplate, integerSequence, ITemplate, VerdocsEndpoint} from '@verdocs/js-sdk';\nimport {Event, EventEmitter, Host, Component, Prop, h, State, Fragment, Watch} from '@stencil/core';\nimport {SDKError} from '../../../utils/errors';\nimport {Store} from '../../../utils/Datastore';\n\n/**\n * Display a template preview experience. This will display the template's attached\n * documents with signing fields overlaid on each page. Fields will be color-coded\n * by recipient, and will be read-only (cannot be filled, moved, or altered).\n *\n * ```ts\n * <verdocs-preview\n * templateId={TEMPLATE_ID}\n * onSdkError={({ detail }) => { console.log('SDK error', detail) }\n * />\n * ```\n */\n@Component({\n tag: 'verdocs-preview',\n styleUrl: 'verdocs-preview.scss',\n shadow: false,\n})\nexport class VerdocsPreview {\n private templateListenerId = null;\n\n /**\n * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.\n */\n @Prop() endpoint: VerdocsEndpoint = VerdocsEndpoint.getDefault();\n\n /**\n * The ID of the template to create the document from.\n */\n @Prop() templateId: string | null = null;\n\n /**\n * Event fired if an error occurs. The event details will contain information about the error. Most errors will\n * terminate the process, and the calling application should correct the condition and re-render the component.\n */\n @Event({composed: true}) sdkError: EventEmitter<SDKError>;\n\n @State() loading = true;\n @State() template: ITemplate | null = null;\n\n disconnectedCallback() {\n this.unlistenToTemplate();\n }\n\n async listenToTemplate() {\n this.unlistenToTemplate();\n Store.subscribe(\n 'templates',\n this.templateId,\n () => getTemplate(this.endpoint, this.templateId),\n false,\n (template: ITemplate) => {\n this.template = template;\n this.loading = false;\n },\n );\n }\n\n unlistenToTemplate() {\n if (this.templateListenerId) {\n Store.store.delListener(this.templateListenerId);\n this.templateListenerId = null;\n }\n }\n\n @Watch('templateId')\n onTemplateIdChanged(newTemplateId: string) {\n console.log('[PREVIEW] Template ID changed', newTemplateId);\n this.listenToTemplate();\n }\n\n async componentWillLoad() {\n try {\n this.endpoint.loadSession();\n if (!this.endpoint.session) {\n console.log('[PREVIEW] Unable to start builder session, must be authenticated');\n return;\n }\n\n if (!this.templateId) {\n console.log(`[PREVIEW] Missing required template ID ${this.templateId}`);\n return;\n }\n\n this.listenToTemplate();\n } catch (e) {\n console.log('[PREVIEW] Error with preview session', e);\n this.sdkError?.emit(new SDKError(e.message, e.response?.status, e.response?.data));\n }\n }\n\n handlePageRendered(_e: any) {\n // const pageInfo = e.detail as IDocumentPageInfo;\n // const fields = (this.template?.fields || []).filter(field => field.page === pageInfo.pageNumber);\n // console.log('[PREVIEW] Page rendered', pageInfo, fields);\n // fields.forEach(field => renderDocumentField(field, pageInfo, {disabled: true, editable: false, draggable: false}));\n }\n\n render() {\n if (this.loading) {\n return (\n <Host>\n <verdocs-loader />\n </Host>\n );\n }\n\n return (\n <Host>\n {(this.template?.documents || []).map(document => {\n const pageNumbers = integerSequence(1, document.pages);\n return (\n <Fragment>\n {pageNumbers.map(pageNumber => {\n const pageSize = document.page_sizes?.[pageNumber] || {width: 612, height: 792};\n\n return (\n <verdocs-template-document-page\n templateId={document.template_id}\n documentId={document.id}\n pageNumber={pageNumber}\n disabled={true}\n editable={false}\n done={false}\n virtualWidth={pageSize.width}\n virtualHeight={pageSize.height}\n onPageRendered={e => this.handlePageRendered(e)}\n layers={[\n {name: 'page', type: 'canvas'},\n {name: 'controls', type: 'div'},\n ]}\n />\n );\n })}\n </Fragment>\n );\n })}\n </Host>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"verdocs-preview.js","sourceRoot":"","sources":["../../../../src/components/embeds/verdocs-preview/verdocs-preview.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,eAAe,EAAa,eAAe,EAAC,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAC,KAAK,EAAgB,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAC,MAAM,eAAe,CAAC;AACpG,OAAO,EAAC,mBAAmB,EAAC,MAAM,sBAAsB,CAAC;AA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AAC,EAC/C,MAAM,EAAE;wBACN,EAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAC;wBAC9B,EAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAC;qBAChC,GACD,CACH,CAAC;YACJ,CAAC,CAAC,CACO,CACZ,CAAC;QACJ,CAAC,CAAC,CACG,CACR,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {getTemplate, integerSequence, ITemplate, VerdocsEndpoint} from '@verdocs/js-sdk';\nimport {Event, EventEmitter, Host, Component, Prop, h, State, Fragment, Watch} from '@stencil/core';\nimport {renderDocumentField} from '../../../utils/utils';\nimport {IDocumentPageInfo} from '../../../utils/Types';\nimport {SDKError} from '../../../utils/errors';\nimport {Store} from '../../../utils/Datastore';\n\n/**\n * Display a template preview experience. This will display the template's attached\n * documents with signing fields overlaid on each page. Fields will be color-coded\n * by recipient, and will be read-only (cannot be filled, moved, or altered).\n *\n * ```ts\n * <verdocs-preview\n * templateId={TEMPLATE_ID}\n * onSdkError={({ detail }) => { console.log('SDK error', detail) }\n * />\n * ```\n */\n@Component({\n tag: 'verdocs-preview',\n styleUrl: 'verdocs-preview.scss',\n shadow: false,\n})\nexport class VerdocsPreview {\n private templateListenerId = null;\n private renderedPages: Record<string, IDocumentPageInfo> = {};\n\n /**\n * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.\n */\n @Prop() endpoint: VerdocsEndpoint = VerdocsEndpoint.getDefault();\n\n /**\n * The ID of the template to create the document from.\n */\n @Prop() templateId: string | null = null;\n\n /**\n * Event fired if an error occurs. The event details will contain information about the error. Most errors will\n * terminate the process, and the calling application should correct the condition and re-render the component.\n */\n @Event({composed: true}) sdkError: EventEmitter<SDKError>;\n\n @State() loading = true;\n @State() template: ITemplate | null = null;\n\n disconnectedCallback() {\n this.unlistenToTemplate();\n }\n\n async listenToTemplate() {\n this.unlistenToTemplate();\n Store.subscribe(\n 'templates',\n this.templateId,\n () => getTemplate(this.endpoint, this.templateId),\n false,\n (template: ITemplate) => {\n this.template = template;\n this.loading = false;\n },\n );\n }\n\n unlistenToTemplate() {\n if (this.templateListenerId) {\n Store.store.delListener(this.templateListenerId);\n this.templateListenerId = null;\n }\n }\n\n @Watch('templateId')\n onTemplateIdChanged(newTemplateId: string) {\n console.log('[PREVIEW] Template ID changed', newTemplateId);\n this.listenToTemplate();\n }\n\n async componentWillLoad() {\n try {\n this.endpoint.loadSession();\n if (!this.endpoint.session) {\n console.log('[PREVIEW] Unable to start builder session, must be authenticated');\n return;\n }\n\n if (!this.templateId) {\n console.log(`[PREVIEW] Missing required template ID ${this.templateId}`);\n return;\n }\n\n this.listenToTemplate();\n } catch (e) {\n console.log('[PREVIEW] Error with preview session', e);\n this.sdkError?.emit(new SDKError(e.message, e.response?.status, e.response?.data));\n }\n }\n\n handlePageRendered(e: any) {\n const pageInfo = e.detail as IDocumentPageInfo;\n this.renderedPages[`${pageInfo.documentId}:${pageInfo.pageNumber}`] = pageInfo;\n\n const fields = (this.template?.fields || []).filter(field => {\n // Templates created on the new builder have document_id set, but old ones may not.\n // If document_id is missing, we assume it's for the first document or use legacy logic.\n // However, for this fix, we primarily care about multi-doc templates which should have IDs.\n if (field['document_id']) {\n return field['document_id'] === pageInfo.documentId && field.page === pageInfo.pageNumber;\n }\n return field.page === pageInfo.pageNumber;\n });\n\n // console.log('[PREVIEW] Page rendered', pageInfo, fields);\n fields.forEach(field => renderDocumentField('template', field, pageInfo, {disabled: true, editable: false, draggable: false}));\n }\n\n render() {\n if (this.loading) {\n return (\n <Host>\n <verdocs-loader />\n </Host>\n );\n }\n\n return (\n <Host>\n {(this.template?.documents || []).map(document => {\n const pageNumbers = integerSequence(1, document.pages);\n return (\n <Fragment>\n {pageNumbers.map(pageNumber => {\n const pageSize = document.page_sizes?.[pageNumber] || {width: 612, height: 792};\n\n return (\n <verdocs-template-document-page\n templateId={document.template_id}\n documentId={document.id}\n pageNumber={pageNumber}\n disabled={true}\n editable={false}\n done={false}\n virtualWidth={pageSize.width}\n virtualHeight={pageSize.height}\n onPageRendered={e => this.handlePageRendered(e)}\n layers={[\n {name: 'page', type: 'canvas'},\n {name: 'controls', type: 'div'},\n ]}\n />\n );\n })}\n </Fragment>\n );\n })}\n </Host>\n );\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { p as proxyCustomElement, H, c as createEvent, h, d as Host, F as Fragment } from './p-CUAGH_8P.js';
2
2
  import { VerdocsEndpoint, getTemplate, integerSequence } from '@verdocs/js-sdk';
3
+ import { b as renderDocumentField } from './p-B3TbYvlU.js';
3
4
  import { S as SDKError } from './p-C1sRVZWv.js';
4
5
  import { S as Store } from './p-bS8INhRF.js';
5
6
  import { d as defineCustomElement$q } from './p-CfODrICH.js';
@@ -39,6 +40,7 @@ const VerdocsPreview = /*@__PURE__*/ proxyCustomElement(class VerdocsPreview ext
39
40
  }
40
41
  this.sdkError = createEvent(this, "sdkError");
41
42
  this.templateListenerId = null;
43
+ this.renderedPages = {};
42
44
  /**
43
45
  * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.
44
46
  */
@@ -89,11 +91,21 @@ const VerdocsPreview = /*@__PURE__*/ proxyCustomElement(class VerdocsPreview ext
89
91
  (_a = this.sdkError) === null || _a === void 0 ? void 0 : _a.emit(new SDKError(e.message, (_b = e.response) === null || _b === void 0 ? void 0 : _b.status, (_c = e.response) === null || _c === void 0 ? void 0 : _c.data));
90
92
  }
91
93
  }
92
- handlePageRendered(_e) {
93
- // const pageInfo = e.detail as IDocumentPageInfo;
94
- // const fields = (this.template?.fields || []).filter(field => field.page === pageInfo.pageNumber);
94
+ handlePageRendered(e) {
95
+ var _a;
96
+ const pageInfo = e.detail;
97
+ this.renderedPages[`${pageInfo.documentId}:${pageInfo.pageNumber}`] = pageInfo;
98
+ const fields = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.fields) || []).filter(field => {
99
+ // Templates created on the new builder have document_id set, but old ones may not.
100
+ // If document_id is missing, we assume it's for the first document or use legacy logic.
101
+ // However, for this fix, we primarily care about multi-doc templates which should have IDs.
102
+ if (field['document_id']) {
103
+ return field['document_id'] === pageInfo.documentId && field.page === pageInfo.pageNumber;
104
+ }
105
+ return field.page === pageInfo.pageNumber;
106
+ });
95
107
  // console.log('[PREVIEW] Page rendered', pageInfo, fields);
96
- // fields.forEach(field => renderDocumentField(field, pageInfo, {disabled: true, editable: false, draggable: false}));
108
+ fields.forEach(field => renderDocumentField('template', field, pageInfo, { disabled: true, editable: false, draggable: false }));
97
109
  }
98
110
  render() {
99
111
  var _a;
@@ -269,6 +281,6 @@ function defineCustomElement() {
269
281
  }
270
282
 
271
283
  export { VerdocsPreview as V, defineCustomElement as d };
272
- //# sourceMappingURL=p-CWDgjfsa.js.map
284
+ //# sourceMappingURL=p-DNdpsH4O.js.map
273
285
 
274
- //# sourceMappingURL=p-CWDgjfsa.js.map
286
+ //# sourceMappingURL=p-DNdpsH4O.js.map
@@ -0,0 +1 @@
1
+ {"file":"p-DNdpsH4O.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB,GAAG,+tBAA+tB;;MCwB5uB,cAAc,iBAAAA,kBAAA,CAAA,MAAA,cAAA,SAAAC,CAAA,CAAA;AAL3B,IAAA,WAAA,CAAA,YAAA,EAAA;;;;;;AAMU,QAAA,IAAkB,CAAA,kBAAA,GAAG,IAAI;AACzB,QAAA,IAAa,CAAA,aAAA,GAAsC,EAAE;AAE7D;;AAEG;AACK,QAAA,IAAA,CAAA,QAAQ,GAAoB,eAAe,CAAC,UAAU,EAAE;AAEhE;;AAEG;AACK,QAAA,IAAU,CAAA,UAAA,GAAkB,IAAI;AAQ/B,QAAA,IAAO,CAAA,OAAA,GAAG,IAAI;AACd,QAAA,IAAQ,CAAA,QAAA,GAAqB,IAAI;AAiH3C;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["__stencil_proxyCustomElement","HTMLElement"],"sources":["src/components/embeds/verdocs-preview/verdocs-preview.scss?tag=verdocs-preview","src/components/embeds/verdocs-preview/verdocs-preview.tsx"],"sourcesContent":["@import '../../../theme.scss';\n\nverdocs-preview {\n font-family: $verdocs-primary-font;\n display: flex;\n padding: 15px;\n row-gap: 15px;\n min-height: 200px;\n position: relative;\n align-items: center;\n box-sizing: border-box;\n flex-direction: column;\n\n div,\n canvas {\n box-sizing: border-box;\n }\n}\n","import {getTemplate, integerSequence, ITemplate, VerdocsEndpoint} from '@verdocs/js-sdk';\nimport {Event, EventEmitter, Host, Component, Prop, h, State, Fragment, Watch} from '@stencil/core';\nimport {renderDocumentField} from '../../../utils/utils';\nimport {IDocumentPageInfo} from '../../../utils/Types';\nimport {SDKError} from '../../../utils/errors';\nimport {Store} from '../../../utils/Datastore';\n\n/**\n * Display a template preview experience. This will display the template's attached\n * documents with signing fields overlaid on each page. Fields will be color-coded\n * by recipient, and will be read-only (cannot be filled, moved, or altered).\n *\n * ```ts\n * <verdocs-preview\n * templateId={TEMPLATE_ID}\n * onSdkError={({ detail }) => { console.log('SDK error', detail) }\n * />\n * ```\n */\n@Component({\n tag: 'verdocs-preview',\n styleUrl: 'verdocs-preview.scss',\n shadow: false,\n})\nexport class VerdocsPreview {\n private templateListenerId = null;\n private renderedPages: Record<string, IDocumentPageInfo> = {};\n\n /**\n * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.\n */\n @Prop() endpoint: VerdocsEndpoint = VerdocsEndpoint.getDefault();\n\n /**\n * The ID of the template to create the document from.\n */\n @Prop() templateId: string | null = null;\n\n /**\n * Event fired if an error occurs. The event details will contain information about the error. Most errors will\n * terminate the process, and the calling application should correct the condition and re-render the component.\n */\n @Event({composed: true}) sdkError: EventEmitter<SDKError>;\n\n @State() loading = true;\n @State() template: ITemplate | null = null;\n\n disconnectedCallback() {\n this.unlistenToTemplate();\n }\n\n async listenToTemplate() {\n this.unlistenToTemplate();\n Store.subscribe(\n 'templates',\n this.templateId,\n () => getTemplate(this.endpoint, this.templateId),\n false,\n (template: ITemplate) => {\n this.template = template;\n this.loading = false;\n },\n );\n }\n\n unlistenToTemplate() {\n if (this.templateListenerId) {\n Store.store.delListener(this.templateListenerId);\n this.templateListenerId = null;\n }\n }\n\n @Watch('templateId')\n onTemplateIdChanged(newTemplateId: string) {\n console.log('[PREVIEW] Template ID changed', newTemplateId);\n this.listenToTemplate();\n }\n\n async componentWillLoad() {\n try {\n this.endpoint.loadSession();\n if (!this.endpoint.session) {\n console.log('[PREVIEW] Unable to start builder session, must be authenticated');\n return;\n }\n\n if (!this.templateId) {\n console.log(`[PREVIEW] Missing required template ID ${this.templateId}`);\n return;\n }\n\n this.listenToTemplate();\n } catch (e) {\n console.log('[PREVIEW] Error with preview session', e);\n this.sdkError?.emit(new SDKError(e.message, e.response?.status, e.response?.data));\n }\n }\n\n handlePageRendered(e: any) {\n const pageInfo = e.detail as IDocumentPageInfo;\n this.renderedPages[`${pageInfo.documentId}:${pageInfo.pageNumber}`] = pageInfo;\n\n const fields = (this.template?.fields || []).filter(field => {\n // Templates created on the new builder have document_id set, but old ones may not.\n // If document_id is missing, we assume it's for the first document or use legacy logic.\n // However, for this fix, we primarily care about multi-doc templates which should have IDs.\n if (field['document_id']) {\n return field['document_id'] === pageInfo.documentId && field.page === pageInfo.pageNumber;\n }\n return field.page === pageInfo.pageNumber;\n });\n\n // console.log('[PREVIEW] Page rendered', pageInfo, fields);\n fields.forEach(field => renderDocumentField('template', field, pageInfo, {disabled: true, editable: false, draggable: false}));\n }\n\n render() {\n if (this.loading) {\n return (\n <Host>\n <verdocs-loader />\n </Host>\n );\n }\n\n return (\n <Host>\n {(this.template?.documents || []).map(document => {\n const pageNumbers = integerSequence(1, document.pages);\n return (\n <Fragment>\n {pageNumbers.map(pageNumber => {\n const pageSize = document.page_sizes?.[pageNumber] || {width: 612, height: 792};\n\n return (\n <verdocs-template-document-page\n templateId={document.template_id}\n documentId={document.id}\n pageNumber={pageNumber}\n disabled={true}\n editable={false}\n done={false}\n virtualWidth={pageSize.width}\n virtualHeight={pageSize.height}\n onPageRendered={e => this.handlePageRendered(e)}\n layers={[\n {name: 'page', type: 'canvas'},\n {name: 'controls', type: 'div'},\n ]}\n />\n );\n })}\n </Fragment>\n );\n })}\n </Host>\n );\n }\n}\n"],"version":3}
@@ -26,7 +26,7 @@ import { d as defineCustomElement$o } from './p-ypE1cZc7.js';
26
26
  import { d as defineCustomElement$n } from './p-DC3uqKak.js';
27
27
  import { d as defineCustomElement$m } from './p-f_4iQ-e-.js';
28
28
  import { d as defineCustomElement$l } from './p-BHVk6zkr.js';
29
- import { d as defineCustomElement$k } from './p-CWDgjfsa.js';
29
+ import { d as defineCustomElement$k } from './p-DNdpsH4O.js';
30
30
  import { d as defineCustomElement$j } from './p-B4oEvTcO.js';
31
31
  import { d as defineCustomElement$i } from './p-B1TD7C4M.js';
32
32
  import { d as defineCustomElement$h } from './p-vk97395M.js';
@@ -1,4 +1,4 @@
1
- import { V as VerdocsPreview$1, d as defineCustomElement$1 } from './p-CWDgjfsa.js';
1
+ import { V as VerdocsPreview$1, d as defineCustomElement$1 } from './p-DNdpsH4O.js';
2
2
 
3
3
  const VerdocsPreview = VerdocsPreview$1;
4
4
  const defineCustomElement = defineCustomElement$1;