@verdocs/web-sdk 4.2.158 → 5.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.
Files changed (491) hide show
  1. package/dist/cjs/Datastore-b1742da2.js +1783 -0
  2. package/dist/cjs/{index-2589e4d1.js → index-ccac8641.js} +11 -27
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/{utils-6d673ca1.js → utils-ba1e95e0.js} +3 -2
  5. package/dist/cjs/verdocs-auth.cjs.entry.js +1 -1
  6. package/dist/cjs/verdocs-build.cjs.entry.js +22 -13
  7. package/dist/cjs/verdocs-button-panel_2.cjs.entry.js +1 -1
  8. package/dist/cjs/{verdocs-button_3.cjs.entry.js → verdocs-button_2.cjs.entry.js} +1 -56
  9. package/dist/cjs/{verdocs-checkbox_4.cjs.entry.js → verdocs-checkbox_6.cjs.entry.js} +115 -24
  10. package/dist/cjs/verdocs-contact-picker_2.cjs.entry.js +2 -2
  11. package/dist/cjs/verdocs-dialog.cjs.entry.js +1 -1
  12. package/dist/cjs/verdocs-dropdown.cjs.entry.js +1 -1
  13. package/dist/cjs/verdocs-envelope-document-page.cjs.entry.js +2 -2
  14. package/dist/cjs/verdocs-envelope-recipient-link_2.cjs.entry.js +30 -15
  15. package/dist/cjs/verdocs-envelope-recipient-summary.cjs.entry.js +32 -17
  16. package/dist/cjs/verdocs-envelope-sidebar.cjs.entry.js +64 -45
  17. package/dist/cjs/verdocs-envelopes-list.cjs.entry.js +2 -2
  18. package/dist/cjs/verdocs-field-attachment_13.cjs.entry.js +104 -155
  19. package/dist/cjs/verdocs-field-payment.cjs.entry.js +38 -25
  20. package/dist/cjs/verdocs-file-chooser_2.cjs.entry.js +1 -1
  21. package/dist/cjs/verdocs-kba-dialog_2.cjs.entry.js +27 -5
  22. package/dist/cjs/verdocs-ok-dialog.cjs.entry.js +1 -1
  23. package/dist/cjs/verdocs-organization-card_2.cjs.entry.js +1 -1
  24. package/dist/cjs/verdocs-pagination_2.cjs.entry.js +2 -2
  25. package/dist/cjs/{verdocs-preview_9.cjs.entry.js → verdocs-preview_6.cjs.entry.js} +252 -469
  26. package/dist/cjs/verdocs-quick-functions.cjs.entry.js +1 -1
  27. package/dist/cjs/verdocs-radio-button.cjs.entry.js +1 -1
  28. package/dist/cjs/verdocs-search-box.cjs.entry.js +1 -1
  29. package/dist/cjs/verdocs-search-tabs.cjs.entry.js +1 -1
  30. package/dist/cjs/verdocs-sign.cjs.entry.js +11 -12
  31. package/dist/cjs/verdocs-spinner.cjs.entry.js +1 -1
  32. package/dist/cjs/verdocs-status-indicator.cjs.entry.js +1 -1
  33. package/dist/cjs/verdocs-table.cjs.entry.js +1 -1
  34. package/dist/cjs/verdocs-template-card.cjs.entry.js +1 -1
  35. package/dist/cjs/verdocs-template-create.cjs.entry.js +108 -0
  36. package/dist/cjs/verdocs-template-document-page_2.cjs.entry.js +78 -63
  37. package/dist/cjs/verdocs-template-role-properties.cjs.entry.js +58 -37
  38. package/dist/cjs/verdocs-template-star.cjs.entry.js +2 -2
  39. package/dist/cjs/verdocs-template-tags.cjs.entry.js +2 -2
  40. package/dist/cjs/verdocs-templates-list.cjs.entry.js +1 -1
  41. package/dist/cjs/verdocs-toggle.cjs.entry.js +1 -1
  42. package/dist/cjs/verdocs-web-sdk.cjs.js +3 -3
  43. package/dist/collection/collection-manifest.json +2 -4
  44. package/dist/collection/components/controls/verdocs-text-input/verdocs-text-input.js +5 -21
  45. package/dist/collection/components/embeds/verdocs-build/verdocs-build.js +27 -40
  46. package/dist/collection/components/embeds/verdocs-preview/verdocs-preview.js +27 -28
  47. package/dist/collection/components/embeds/verdocs-send/verdocs-send.js +45 -44
  48. package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.js +12 -11
  49. package/dist/collection/components/embeds/verdocs-view/verdocs-view.js +28 -28
  50. package/dist/collection/components/envelopes/verdocs-envelope-recipient-link/verdocs-envelope-recipient-link.js +34 -15
  51. package/dist/collection/components/envelopes/verdocs-envelope-recipient-summary/verdocs-envelope-recipient-summary.js +35 -17
  52. package/dist/collection/components/envelopes/verdocs-envelope-sidebar/verdocs-envelope-sidebar.js +67 -45
  53. package/dist/collection/components/fields/verdocs-field-attachment/verdocs-field-attachment.js +29 -18
  54. package/dist/collection/components/fields/verdocs-field-checkbox/verdocs-field-checkbox.js +30 -20
  55. package/dist/collection/components/fields/verdocs-field-date/verdocs-field-date.js +30 -22
  56. package/dist/collection/components/fields/verdocs-field-dropdown/verdocs-field-dropdown.js +29 -17
  57. package/dist/collection/components/fields/verdocs-field-initial/verdocs-field-initial.js +30 -18
  58. package/dist/collection/components/fields/verdocs-field-payment/verdocs-field-payment.js +192 -139
  59. package/dist/collection/components/fields/verdocs-field-radio/verdocs-field-radio.js +30 -20
  60. package/dist/collection/components/fields/verdocs-field-signature/verdocs-field-signature.js +30 -18
  61. package/dist/collection/components/fields/verdocs-field-textarea/verdocs-field-textarea.js +31 -19
  62. package/dist/collection/components/fields/verdocs-field-textbox/verdocs-field-textbox.css +31 -0
  63. package/dist/collection/components/fields/verdocs-field-textbox/verdocs-field-textbox.js +44 -44
  64. package/dist/collection/components/fields/verdocs-field-timestamp/verdocs-field-timestamp.js +29 -17
  65. package/dist/collection/components/templates/verdocs-template-attachments/verdocs-template-attachments.js +37 -17
  66. package/dist/collection/components/templates/verdocs-template-build-tabs/verdocs-template-build-tabs.js +37 -32
  67. package/dist/collection/components/templates/verdocs-template-create/verdocs-template-create.js +7 -15
  68. package/dist/collection/components/templates/verdocs-template-document-page/verdocs-template-document-page.css +6 -0
  69. package/dist/collection/components/templates/verdocs-template-document-page/verdocs-template-document-page.js +79 -61
  70. package/dist/collection/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.js +48 -24
  71. package/dist/collection/components/templates/verdocs-template-fields/verdocs-template-fields.js +63 -61
  72. package/dist/collection/components/templates/verdocs-template-role-properties/verdocs-template-role-properties.js +61 -36
  73. package/dist/collection/components/templates/verdocs-template-roles/verdocs-template-roles.js +63 -46
  74. package/dist/collection/components/templates/verdocs-template-star/verdocs-template-star.js +1 -1
  75. package/dist/collection/components/templates/verdocs-template-tags/verdocs-template-tags.js +1 -1
  76. package/dist/collection/utils/Datastore.js +141 -0
  77. package/dist/collection/utils/Templates.js +2 -0
  78. package/dist/collection/utils/utils.js +3 -2
  79. package/dist/components/index.js +1 -5
  80. package/dist/components/{p-3044c9cb.js → p-070bebd7.js} +1 -1
  81. package/dist/components/{p-1b60debe.js → p-0a69031f.js} +29 -28
  82. package/dist/components/{p-69881420.js → p-0ca7012b.js} +1 -1
  83. package/dist/components/{p-b2bf338f.js → p-0d063bf9.js} +65 -35
  84. package/dist/components/{p-ac7578f6.js → p-0e332769.js} +1 -1
  85. package/dist/components/{p-a655b737.js → p-15d530b8.js} +6 -6
  86. package/dist/components/{p-71dd305b.js → p-18999830.js} +2 -2
  87. package/dist/components/{p-90540412.js → p-1ae5d7e0.js} +1 -1
  88. package/dist/components/{p-8f942993.js → p-1ca705bc.js} +31 -30
  89. package/dist/components/{p-4d2f2954.js → p-1e2e8b1c.js} +1 -1
  90. package/dist/components/{p-c7a21595.js → p-1e67ebdf.js} +67 -42
  91. package/dist/components/{p-fe2dca8c.js → p-22da6d14.js} +2 -2
  92. package/dist/components/{p-945d225a.js → p-22e52874.js} +90 -88
  93. package/dist/components/{p-85ef4d07.js → p-2548f3f0.js} +49 -38
  94. package/dist/components/{p-263dc67d.js → p-315d6592.js} +1 -1
  95. package/dist/components/{p-4dc4418a.js → p-3201d529.js} +1 -1
  96. package/dist/components/{p-7786799a.js → p-324ed895.js} +8 -4
  97. package/dist/components/{p-b679d760.js → p-49153610.js} +32 -31
  98. package/dist/components/{p-03660739.js → p-4afcdc84.js} +30 -31
  99. package/dist/components/{p-b0af9b72.js → p-4bc5ac82.js} +3 -2
  100. package/dist/components/{p-ffe8b41d.js → p-4dd750e9.js} +1 -1
  101. package/dist/components/{p-82fb3284.js → p-58c2bd5d.js} +1 -1
  102. package/dist/components/{p-d3170dcd.js → p-5a9cea40.js} +4 -4
  103. package/dist/components/{p-8b27ce22.js → p-5d4bbcd0.js} +1 -1
  104. package/dist/components/{p-1e66385b.js → p-5d82a9f3.js} +64 -57
  105. package/dist/components/{p-877eaf65.js → p-5eb45a4f.js} +1 -1
  106. package/dist/components/{p-62f8b36c.js → p-6400f542.js} +36 -14
  107. package/dist/components/{p-e4ac6259.js → p-6fcd99d1.js} +2 -2
  108. package/dist/components/{p-921297ba.js → p-84ae0283.js} +1 -1
  109. package/dist/components/{p-7927a846.js → p-8d3c0b4c.js} +2 -2
  110. package/dist/components/{p-83a2fa2f.js → p-8fbc64e9.js} +72 -55
  111. package/dist/components/{p-0e64ccc3.js → p-9bb47a5a.js} +1 -1
  112. package/dist/components/{p-12594438.js → p-9c3fd545.js} +31 -31
  113. package/dist/components/{p-fe533b11.js → p-a22a3b1b.js} +125 -101
  114. package/dist/components/{p-df4ac086.js → p-a3e12c74.js} +2 -2
  115. package/dist/components/{p-6e8c00bc.js → p-b0c02eb8.js} +31 -30
  116. package/dist/components/{p-6b369b14.js → p-b16c202a.js} +1 -1
  117. package/dist/components/{p-3518350d.js → p-b9034018.js} +4 -4
  118. package/dist/components/{p-c7db1c7d.js → p-c25e82b9.js} +52 -53
  119. package/dist/components/{p-4535a9fd.js → p-c7b00ce6.js} +36 -17
  120. package/dist/components/{p-e4a852b5.js → p-c8fedb4e.js} +7 -6
  121. package/dist/components/{p-83245875.js → p-cf6ea837.js} +2 -2
  122. package/dist/components/{p-b8cd75c0.js → p-d9704a51.js} +55 -45
  123. package/dist/components/p-da4d4eed.js +1781 -0
  124. package/dist/components/{p-cdf871dd.js → p-dd701894.js} +29 -28
  125. package/dist/components/p-ea5954bd.js +4 -0
  126. package/dist/components/{p-42a676b7.js → p-ec894daf.js} +2 -2
  127. package/dist/components/{p-72e959a7.js → p-ecc818bb.js} +30 -31
  128. package/dist/components/{p-ed9a1a21.js → p-ed88b8d2.js} +44 -24
  129. package/dist/components/{p-556596e4.js → p-f72b9c45.js} +1 -1
  130. package/dist/components/{p-a7bbe96b.js → p-f990140a.js} +3 -3
  131. package/dist/components/{p-db4a15fd.js → p-fcad60f5.js} +1 -1
  132. package/dist/components/{p-0162bdd3.js → p-fd96322b.js} +30 -33
  133. package/dist/components/verdocs-auth.js +4 -4
  134. package/dist/components/verdocs-build.js +99 -103
  135. package/dist/components/verdocs-button-panel.js +1 -1
  136. package/dist/components/verdocs-button.js +1 -1
  137. package/dist/components/verdocs-checkbox.js +1 -1
  138. package/dist/components/verdocs-component-error.js +1 -1
  139. package/dist/components/verdocs-contact-picker.js +1 -1
  140. package/dist/components/verdocs-dialog.js +1 -1
  141. package/dist/components/verdocs-dropdown.js +1 -1
  142. package/dist/components/verdocs-envelope-document-page.js +1 -1
  143. package/dist/components/verdocs-envelope-recipient-link.js +1 -1
  144. package/dist/components/verdocs-envelope-recipient-summary.js +37 -19
  145. package/dist/components/verdocs-envelope-sidebar.js +76 -54
  146. package/dist/components/verdocs-envelopes-list.js +12 -12
  147. package/dist/components/verdocs-field-attachment.js +1 -1
  148. package/dist/components/verdocs-field-checkbox.js +1 -1
  149. package/dist/components/verdocs-field-date.js +1 -1
  150. package/dist/components/verdocs-field-dropdown.js +1 -1
  151. package/dist/components/verdocs-field-initial.js +1 -1
  152. package/dist/components/verdocs-field-payment.js +106 -33
  153. package/dist/components/verdocs-field-radio.js +1 -1
  154. package/dist/components/verdocs-field-signature.js +1 -1
  155. package/dist/components/verdocs-field-textarea.js +1 -1
  156. package/dist/components/verdocs-field-textbox.js +1 -1
  157. package/dist/components/verdocs-field-timestamp.js +1 -1
  158. package/dist/components/verdocs-file-chooser.js +1 -1
  159. package/dist/components/verdocs-help-icon.js +1 -1
  160. package/dist/components/verdocs-initial-dialog.js +1 -1
  161. package/dist/components/verdocs-kba-dialog.js +1 -1
  162. package/dist/components/verdocs-loader.js +1 -1
  163. package/dist/components/verdocs-ok-dialog.js +1 -1
  164. package/dist/components/verdocs-organization-card.js +2 -2
  165. package/dist/components/verdocs-pagination.js +1 -1
  166. package/dist/components/verdocs-portal.js +1 -1
  167. package/dist/components/verdocs-preview.js +1 -1
  168. package/dist/components/verdocs-progress-bar.js +1 -1
  169. package/dist/components/verdocs-quick-filter.js +1 -1
  170. package/dist/components/verdocs-quick-functions.js +1 -1
  171. package/dist/components/verdocs-radio-button.js +1 -1
  172. package/dist/components/verdocs-search-box.js +1 -1
  173. package/dist/components/verdocs-search-tabs.js +1 -1
  174. package/dist/components/verdocs-select-input.js +1 -1
  175. package/dist/components/verdocs-send.js +1 -1
  176. package/dist/components/verdocs-sign.js +24 -23
  177. package/dist/components/verdocs-signature-dialog.js +1 -1
  178. package/dist/components/verdocs-spinner.js +1 -1
  179. package/dist/components/verdocs-status-indicator.js +1 -1
  180. package/dist/components/verdocs-switch.js +1 -1
  181. package/dist/components/verdocs-table.js +1 -1
  182. package/dist/components/verdocs-tabs.js +1 -1
  183. package/dist/components/verdocs-template-attachments.js +1 -1
  184. package/dist/components/verdocs-template-build-tabs.js +1 -1
  185. package/dist/components/verdocs-template-card.js +1 -1
  186. package/dist/components/verdocs-template-create.js +148 -1
  187. package/dist/components/verdocs-template-document-page.js +1 -1
  188. package/dist/components/verdocs-template-field-properties.js +1 -1
  189. package/dist/components/verdocs-template-fields.js +1 -1
  190. package/dist/components/verdocs-template-role-properties.js +1 -1
  191. package/dist/components/verdocs-template-roles.js +1 -1
  192. package/dist/components/verdocs-template-star.js +1 -1
  193. package/dist/components/verdocs-template-tags.js +2 -2
  194. package/dist/components/verdocs-templates-list.js +11 -11
  195. package/dist/components/verdocs-text-input.js +1 -1
  196. package/dist/components/verdocs-toggle-button.js +1 -1
  197. package/dist/components/verdocs-toggle.js +1 -1
  198. package/dist/components/verdocs-toolbar-icon.js +1 -1
  199. package/dist/components/verdocs-upload-dialog.js +1 -1
  200. package/dist/components/verdocs-view.js +1 -1
  201. package/dist/esm/Datastore-52fcbac6.js +1781 -0
  202. package/dist/esm/{index-c8587076.js → index-272d51a4.js} +12 -26
  203. package/dist/esm/loader.js +3 -3
  204. package/dist/esm/{utils-27fa12eb.js → utils-47de6f79.js} +3 -2
  205. package/dist/esm/verdocs-auth.entry.js +1 -1
  206. package/dist/esm/verdocs-build.entry.js +23 -14
  207. package/dist/esm/verdocs-button-panel_2.entry.js +1 -1
  208. package/dist/esm/{verdocs-button_3.entry.js → verdocs-button_2.entry.js} +2 -56
  209. package/dist/esm/{verdocs-checkbox_4.entry.js → verdocs-checkbox_6.entry.js} +115 -26
  210. package/dist/esm/verdocs-contact-picker_2.entry.js +2 -2
  211. package/dist/esm/verdocs-dialog.entry.js +1 -1
  212. package/dist/esm/verdocs-dropdown.entry.js +1 -1
  213. package/dist/esm/verdocs-envelope-document-page.entry.js +2 -2
  214. package/dist/esm/verdocs-envelope-recipient-link_2.entry.js +31 -16
  215. package/dist/esm/verdocs-envelope-recipient-summary.entry.js +33 -18
  216. package/dist/esm/verdocs-envelope-sidebar.entry.js +65 -46
  217. package/dist/esm/verdocs-envelopes-list.entry.js +2 -2
  218. package/dist/esm/verdocs-field-attachment_13.entry.js +104 -155
  219. package/dist/esm/verdocs-field-payment.entry.js +38 -25
  220. package/dist/esm/verdocs-file-chooser_2.entry.js +1 -1
  221. package/dist/esm/verdocs-kba-dialog_2.entry.js +27 -5
  222. package/dist/esm/verdocs-ok-dialog.entry.js +1 -1
  223. package/dist/esm/verdocs-organization-card_2.entry.js +1 -1
  224. package/dist/esm/verdocs-pagination_2.entry.js +2 -2
  225. package/dist/esm/{verdocs-preview_9.entry.js → verdocs-preview_6.entry.js} +256 -470
  226. package/dist/esm/verdocs-quick-functions.entry.js +1 -1
  227. package/dist/esm/verdocs-radio-button.entry.js +1 -1
  228. package/dist/esm/verdocs-search-box.entry.js +1 -1
  229. package/dist/esm/verdocs-search-tabs.entry.js +1 -1
  230. package/dist/esm/verdocs-sign.entry.js +11 -12
  231. package/dist/esm/verdocs-spinner.entry.js +1 -1
  232. package/dist/esm/verdocs-status-indicator.entry.js +1 -1
  233. package/dist/esm/verdocs-table.entry.js +1 -1
  234. package/dist/esm/verdocs-template-card.entry.js +1 -1
  235. package/dist/{components/p-f9cc62a7.js → esm/verdocs-template-create.entry.js} +15 -69
  236. package/dist/esm/verdocs-template-document-page_2.entry.js +79 -64
  237. package/dist/esm/verdocs-template-role-properties.entry.js +59 -38
  238. package/dist/esm/verdocs-template-star.entry.js +2 -2
  239. package/dist/esm/verdocs-template-tags.entry.js +2 -2
  240. package/dist/esm/verdocs-templates-list.entry.js +1 -1
  241. package/dist/esm/verdocs-toggle.entry.js +1 -1
  242. package/dist/esm/verdocs-web-sdk.js +4 -4
  243. package/dist/esm-es5/Datastore-52fcbac6.js +1 -0
  244. package/dist/esm-es5/index-272d51a4.js +1 -0
  245. package/dist/esm-es5/loader.js +1 -1
  246. package/dist/esm-es5/{utils-27fa12eb.js → utils-47de6f79.js} +1 -1
  247. package/dist/esm-es5/verdocs-auth.entry.js +1 -1
  248. package/dist/esm-es5/verdocs-build.entry.js +1 -1
  249. package/dist/esm-es5/verdocs-button-panel_2.entry.js +1 -1
  250. package/dist/esm-es5/verdocs-button_2.entry.js +1 -0
  251. package/dist/esm-es5/verdocs-checkbox_6.entry.js +1 -0
  252. package/dist/esm-es5/verdocs-contact-picker_2.entry.js +1 -1
  253. package/dist/esm-es5/verdocs-dialog.entry.js +1 -1
  254. package/dist/esm-es5/verdocs-dropdown.entry.js +1 -1
  255. package/dist/esm-es5/verdocs-envelope-document-page.entry.js +1 -1
  256. package/dist/esm-es5/verdocs-envelope-recipient-link_2.entry.js +1 -1
  257. package/dist/esm-es5/verdocs-envelope-recipient-summary.entry.js +1 -1
  258. package/dist/esm-es5/verdocs-envelope-sidebar.entry.js +1 -1
  259. package/dist/esm-es5/verdocs-envelopes-list.entry.js +1 -1
  260. package/dist/esm-es5/verdocs-field-attachment_13.entry.js +1 -1
  261. package/dist/esm-es5/verdocs-field-payment.entry.js +1 -1
  262. package/dist/esm-es5/verdocs-file-chooser_2.entry.js +1 -1
  263. package/dist/esm-es5/verdocs-kba-dialog_2.entry.js +1 -1
  264. package/dist/esm-es5/verdocs-ok-dialog.entry.js +1 -1
  265. package/dist/esm-es5/verdocs-organization-card_2.entry.js +1 -1
  266. package/dist/esm-es5/verdocs-pagination_2.entry.js +1 -1
  267. package/dist/esm-es5/verdocs-preview_6.entry.js +1 -0
  268. package/dist/esm-es5/verdocs-quick-functions.entry.js +1 -1
  269. package/dist/esm-es5/verdocs-radio-button.entry.js +1 -1
  270. package/dist/esm-es5/verdocs-search-box.entry.js +1 -1
  271. package/dist/esm-es5/verdocs-search-tabs.entry.js +1 -1
  272. package/dist/esm-es5/verdocs-sign.entry.js +1 -1
  273. package/dist/esm-es5/verdocs-spinner.entry.js +1 -1
  274. package/dist/esm-es5/verdocs-status-indicator.entry.js +1 -1
  275. package/dist/esm-es5/verdocs-table.entry.js +1 -1
  276. package/dist/esm-es5/verdocs-template-card.entry.js +1 -1
  277. package/dist/esm-es5/verdocs-template-create.entry.js +1 -0
  278. package/dist/esm-es5/verdocs-template-document-page_2.entry.js +1 -1
  279. package/dist/esm-es5/verdocs-template-role-properties.entry.js +1 -1
  280. package/dist/esm-es5/verdocs-template-star.entry.js +1 -1
  281. package/dist/esm-es5/verdocs-template-tags.entry.js +1 -1
  282. package/dist/esm-es5/verdocs-templates-list.entry.js +1 -1
  283. package/dist/esm-es5/verdocs-toggle.entry.js +1 -1
  284. package/dist/esm-es5/verdocs-web-sdk.js +1 -1
  285. package/dist/types/components/controls/verdocs-text-input/verdocs-text-input.d.ts +0 -2
  286. package/dist/types/components/embeds/verdocs-build/verdocs-build.d.ts +8 -32
  287. package/dist/types/components/embeds/verdocs-preview/verdocs-preview.d.ts +6 -8
  288. package/dist/types/components/embeds/verdocs-send/verdocs-send.d.ts +7 -6
  289. package/dist/types/components/embeds/verdocs-sign/verdocs-sign.d.ts +3 -3
  290. package/dist/types/components/embeds/verdocs-view/verdocs-view.d.ts +6 -5
  291. package/dist/types/components/envelopes/verdocs-envelope-recipient-link/verdocs-envelope-recipient-link.d.ts +6 -3
  292. package/dist/types/components/envelopes/verdocs-envelope-recipient-summary/verdocs-envelope-recipient-summary.d.ts +6 -3
  293. package/dist/types/components/envelopes/verdocs-envelope-sidebar/verdocs-envelope-sidebar.d.ts +8 -4
  294. package/dist/types/components/fields/verdocs-field-attachment/verdocs-field-attachment.d.ts +6 -7
  295. package/dist/types/components/fields/verdocs-field-checkbox/verdocs-field-checkbox.d.ts +6 -7
  296. package/dist/types/components/fields/verdocs-field-date/verdocs-field-date.d.ts +6 -7
  297. package/dist/types/components/fields/verdocs-field-dropdown/verdocs-field-dropdown.d.ts +6 -7
  298. package/dist/types/components/fields/verdocs-field-initial/verdocs-field-initial.d.ts +6 -7
  299. package/dist/types/components/fields/verdocs-field-payment/verdocs-field-payment.d.ts +44 -30
  300. package/dist/types/components/fields/verdocs-field-radio/verdocs-field-radio.d.ts +6 -7
  301. package/dist/types/components/fields/verdocs-field-signature/verdocs-field-signature.d.ts +6 -7
  302. package/dist/types/components/fields/verdocs-field-textarea/verdocs-field-textarea.d.ts +6 -7
  303. package/dist/types/components/fields/verdocs-field-textbox/verdocs-field-textbox.d.ts +5 -12
  304. package/dist/types/components/fields/verdocs-field-timestamp/verdocs-field-timestamp.d.ts +6 -7
  305. package/dist/types/components/templates/verdocs-template-attachments/verdocs-template-attachments.d.ts +6 -2
  306. package/dist/types/components/templates/verdocs-template-build-tabs/verdocs-template-build-tabs.d.ts +7 -4
  307. package/dist/types/components/templates/verdocs-template-document-page/verdocs-template-document-page.d.ts +7 -4
  308. package/dist/types/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.d.ts +7 -8
  309. package/dist/types/components/templates/verdocs-template-fields/verdocs-template-fields.d.ts +6 -8
  310. package/dist/types/components/templates/verdocs-template-role-properties/verdocs-template-role-properties.d.ts +7 -7
  311. package/dist/types/components/templates/verdocs-template-roles/verdocs-template-roles.d.ts +7 -6
  312. package/dist/types/components.d.ts +176 -330
  313. package/dist/types/utils/Datastore.d.ts +24 -0
  314. package/dist/types/utils/Templates.d.ts +3 -0
  315. package/dist/types/utils/utils.d.ts +1 -1
  316. package/dist/verdocs-web-sdk/{p-98c5f5a5.entry.js → p-0ca1e87c.entry.js} +1 -1
  317. package/dist/verdocs-web-sdk/p-0e9de098.entry.js +1 -0
  318. package/dist/verdocs-web-sdk/{p-fc053d00.entry.js → p-167e3d7e.entry.js} +1 -1
  319. package/dist/verdocs-web-sdk/{p-7bd37bca.entry.js → p-2a1287ec.entry.js} +1 -1
  320. package/dist/verdocs-web-sdk/{p-6419b913.system.js → p-2be751c4.system.js} +1 -1
  321. package/dist/verdocs-web-sdk/{p-cb30f11e.entry.js → p-2f73c9de.entry.js} +1 -1
  322. package/dist/verdocs-web-sdk/p-3364cc13.system.entry.js +1 -0
  323. package/dist/verdocs-web-sdk/{p-196bc80f.system.entry.js → p-37d747fb.system.entry.js} +1 -1
  324. package/dist/verdocs-web-sdk/p-386d789c.system.entry.js +1 -0
  325. package/dist/verdocs-web-sdk/p-3a1fa556.system.entry.js +1 -0
  326. package/dist/verdocs-web-sdk/{p-0fd57194.entry.js → p-41cbf650.entry.js} +1 -1
  327. package/dist/verdocs-web-sdk/{p-26715b8b.entry.js → p-4b36ca30.entry.js} +1 -1
  328. package/dist/verdocs-web-sdk/{p-98501408.system.entry.js → p-4e9e154f.system.entry.js} +1 -1
  329. package/dist/verdocs-web-sdk/{p-a3778013.system.entry.js → p-511a4ecc.system.entry.js} +1 -1
  330. package/dist/verdocs-web-sdk/{p-65a4e01e.entry.js → p-524f37a0.entry.js} +1 -1
  331. package/dist/verdocs-web-sdk/{p-13fe8650.system.entry.js → p-53f4c7c3.system.entry.js} +1 -1
  332. package/dist/verdocs-web-sdk/p-54f085d1.entry.js +1 -0
  333. package/dist/verdocs-web-sdk/{p-cca517dc.entry.js → p-584113d1.entry.js} +1 -1
  334. package/dist/verdocs-web-sdk/{p-f8cad58e.entry.js → p-5f1a000c.entry.js} +1 -1
  335. package/dist/verdocs-web-sdk/{p-256f07fd.system.entry.js → p-62f15675.system.entry.js} +1 -1
  336. package/dist/verdocs-web-sdk/{p-9b921211.js → p-650697bd.js} +1 -1
  337. package/dist/verdocs-web-sdk/{p-c06d2604.entry.js → p-65c5398e.entry.js} +1 -1
  338. package/dist/verdocs-web-sdk/{p-0446030b.entry.js → p-6ced37ed.entry.js} +1 -1
  339. package/dist/verdocs-web-sdk/{p-16619383.entry.js → p-7464b84f.entry.js} +1 -1
  340. package/dist/verdocs-web-sdk/{p-6e3fa0c4.system.entry.js → p-761f6656.system.entry.js} +1 -1
  341. package/dist/verdocs-web-sdk/{p-30bc5986.entry.js → p-76cc40fe.entry.js} +1 -1
  342. package/dist/verdocs-web-sdk/{p-c45dc777.entry.js → p-771c2f92.entry.js} +1 -1
  343. package/dist/verdocs-web-sdk/p-78191329.system.entry.js +1 -0
  344. package/dist/verdocs-web-sdk/{p-f3c995d8.system.entry.js → p-7c8938e7.system.entry.js} +1 -1
  345. package/dist/verdocs-web-sdk/{p-1ce2f724.system.entry.js → p-80ce3711.system.entry.js} +1 -1
  346. package/dist/verdocs-web-sdk/p-81c8663f.entry.js +1 -0
  347. package/dist/verdocs-web-sdk/p-8221a48f.entry.js +1 -0
  348. package/dist/verdocs-web-sdk/p-860b9f94.system.entry.js +1 -0
  349. package/dist/verdocs-web-sdk/p-89cdecac.system.entry.js +1 -0
  350. package/dist/verdocs-web-sdk/p-8a2ff048.entry.js +1 -0
  351. package/dist/verdocs-web-sdk/p-8c03fc69.entry.js +1 -0
  352. package/dist/verdocs-web-sdk/p-8d401072.system.entry.js +1 -0
  353. package/dist/verdocs-web-sdk/{p-921b56fd.system.entry.js → p-914e131c.system.entry.js} +1 -1
  354. package/dist/verdocs-web-sdk/{p-5737f0ae.system.js → p-9186f42e.system.js} +1 -1
  355. package/dist/verdocs-web-sdk/{p-8e233a6b.system.entry.js → p-9227d400.system.entry.js} +1 -1
  356. package/dist/verdocs-web-sdk/p-92ce6180.entry.js +1 -0
  357. package/dist/verdocs-web-sdk/p-9567cb7d.system.entry.js +1 -0
  358. package/dist/verdocs-web-sdk/p-97b00cae.system.entry.js +1 -0
  359. package/dist/verdocs-web-sdk/{p-4b4801ad.system.entry.js → p-982f1b36.system.entry.js} +1 -1
  360. package/dist/verdocs-web-sdk/{p-1b6736fe.system.entry.js → p-9d0b0e36.system.entry.js} +1 -1
  361. package/dist/verdocs-web-sdk/{p-6d1d86ff.system.entry.js → p-a08886c1.system.entry.js} +1 -1
  362. package/dist/verdocs-web-sdk/{p-e25e1dcf.entry.js → p-a165607e.entry.js} +1 -1
  363. package/dist/verdocs-web-sdk/p-a242aa80.system.entry.js +1 -0
  364. package/dist/verdocs-web-sdk/{p-5d6a2fda.system.entry.js → p-a9635106.system.entry.js} +1 -1
  365. package/dist/verdocs-web-sdk/p-aebb0cd9.system.entry.js +1 -0
  366. package/dist/verdocs-web-sdk/p-b0b958a0.entry.js +1 -0
  367. package/dist/verdocs-web-sdk/p-b8737f7b.entry.js +1 -0
  368. package/dist/verdocs-web-sdk/{p-49988769.js → p-b9654a5e.js} +2 -2
  369. package/dist/verdocs-web-sdk/p-bb0effe1.entry.js +1 -0
  370. package/dist/verdocs-web-sdk/p-bcc23811.entry.js +1 -0
  371. package/dist/verdocs-web-sdk/{p-0c3a471b.entry.js → p-bd7406ae.entry.js} +1 -1
  372. package/dist/verdocs-web-sdk/{p-e8d91957.entry.js → p-bdd7b3d3.entry.js} +1 -1
  373. package/dist/verdocs-web-sdk/{p-c5818330.entry.js → p-c1728f5c.entry.js} +1 -1
  374. package/dist/verdocs-web-sdk/p-c18c718f.system.js +1 -0
  375. package/dist/verdocs-web-sdk/{p-731066de.system.entry.js → p-c6fd3e53.system.entry.js} +1 -1
  376. package/dist/verdocs-web-sdk/p-c7cd6843.entry.js +1 -0
  377. package/dist/verdocs-web-sdk/{p-4f7c72f9.system.entry.js → p-c9f40726.system.entry.js} +1 -1
  378. package/dist/verdocs-web-sdk/p-ca712f40.system.entry.js +1 -0
  379. package/dist/verdocs-web-sdk/p-cbb75c5e.system.entry.js +1 -0
  380. package/dist/verdocs-web-sdk/{p-751b0280.entry.js → p-d475fff3.entry.js} +1 -1
  381. package/dist/verdocs-web-sdk/{p-91c4298b.system.entry.js → p-d5870e33.system.entry.js} +1 -1
  382. package/dist/verdocs-web-sdk/{p-e5126f26.system.entry.js → p-d8dae4e9.system.entry.js} +1 -1
  383. package/dist/verdocs-web-sdk/{p-93093a7a.system.entry.js → p-d98cbd0f.system.entry.js} +1 -1
  384. package/dist/verdocs-web-sdk/p-da4d4eed.js +1 -0
  385. package/dist/verdocs-web-sdk/{p-2298c22e.entry.js → p-ddb17b3e.entry.js} +1 -1
  386. package/dist/verdocs-web-sdk/p-df04f0ca.entry.js +1 -0
  387. package/dist/verdocs-web-sdk/{p-9ff1be63.entry.js → p-df392ef9.entry.js} +1 -1
  388. package/dist/verdocs-web-sdk/p-e2b70dfb.system.js +1 -0
  389. package/dist/verdocs-web-sdk/{p-2aea0c7b.system.entry.js → p-e438bd02.system.entry.js} +1 -1
  390. package/dist/verdocs-web-sdk/{p-0c42cb22.system.entry.js → p-e5d291f3.system.entry.js} +1 -1
  391. package/dist/verdocs-web-sdk/{p-7f1e0c5e.entry.js → p-e6dbb0f7.entry.js} +1 -1
  392. package/dist/verdocs-web-sdk/{p-c4d61c66.entry.js → p-e83cd333.entry.js} +1 -1
  393. package/dist/verdocs-web-sdk/p-edfb1951.system.entry.js +1 -0
  394. package/dist/verdocs-web-sdk/p-f4fcf7a5.entry.js +1 -0
  395. package/dist/verdocs-web-sdk/{p-97b951e6.system.entry.js → p-f5d01982.system.entry.js} +1 -1
  396. package/dist/verdocs-web-sdk/{p-6e55af26.system.entry.js → p-f9b37af2.system.entry.js} +1 -1
  397. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  398. package/dist/verdocs-web-sdk/verdocs-web-sdk.js +1 -1
  399. package/package.json +3 -3
  400. package/dist/cjs/EnvelopeStore-f1cd9bd3.js +0 -96
  401. package/dist/cjs/TemplateFieldStore-7bcc0f7a.js +0 -44
  402. package/dist/cjs/TemplateRoleStore-e8bb00ec.js +0 -51
  403. package/dist/cjs/TemplateStore-db21be4d.js +0 -99
  404. package/dist/cjs/index-2a189d85.js +0 -3721
  405. package/dist/cjs/index-76d03a35.js +0 -196
  406. package/dist/cjs/verdocs-loader.cjs.entry.js +0 -20
  407. package/dist/collection/components/templates/verdocs-template-name/verdocs-template-name.css +0 -0
  408. package/dist/collection/components/templates/verdocs-template-name/verdocs-template-name.js +0 -196
  409. package/dist/collection/components/templates/verdocs-template-visibillity/verdocs-template-visibility.css +0 -86
  410. package/dist/collection/components/templates/verdocs-template-visibillity/verdocs-template-visibility.js +0 -203
  411. package/dist/collection/utils/EnvelopeStore.js +0 -90
  412. package/dist/collection/utils/TemplateFieldStore.js +0 -36
  413. package/dist/collection/utils/TemplateRoleStore.js +0 -41
  414. package/dist/collection/utils/TemplateStore.js +0 -94
  415. package/dist/components/p-00d39dca.js +0 -39
  416. package/dist/components/p-0933fb2d.js +0 -127
  417. package/dist/components/p-09d28afd.js +0 -97
  418. package/dist/components/p-3555cef1.js +0 -122
  419. package/dist/components/p-474b6663.js +0 -1314
  420. package/dist/components/p-821f2345.js +0 -93
  421. package/dist/components/p-9b5a4f9e.js +0 -44
  422. package/dist/components/p-a706bac9.js +0 -3719
  423. package/dist/components/verdocs-template-name.d.ts +0 -11
  424. package/dist/components/verdocs-template-name.js +0 -6
  425. package/dist/components/verdocs-template-visibility.d.ts +0 -11
  426. package/dist/components/verdocs-template-visibility.js +0 -6
  427. package/dist/esm/EnvelopeStore-4599b7d3.js +0 -93
  428. package/dist/esm/TemplateFieldStore-909147d8.js +0 -39
  429. package/dist/esm/TemplateRoleStore-2fef1fdb.js +0 -44
  430. package/dist/esm/TemplateStore-ace14a8b.js +0 -97
  431. package/dist/esm/index-24d8ae6a.js +0 -194
  432. package/dist/esm/index-7588a071.js +0 -3719
  433. package/dist/esm/verdocs-loader.entry.js +0 -16
  434. package/dist/esm-es5/EnvelopeStore-4599b7d3.js +0 -1
  435. package/dist/esm-es5/TemplateFieldStore-909147d8.js +0 -1
  436. package/dist/esm-es5/TemplateRoleStore-2fef1fdb.js +0 -1
  437. package/dist/esm-es5/TemplateStore-ace14a8b.js +0 -1
  438. package/dist/esm-es5/index-24d8ae6a.js +0 -1
  439. package/dist/esm-es5/index-7588a071.js +0 -1
  440. package/dist/esm-es5/index-c8587076.js +0 -1
  441. package/dist/esm-es5/verdocs-button_3.entry.js +0 -1
  442. package/dist/esm-es5/verdocs-checkbox_4.entry.js +0 -1
  443. package/dist/esm-es5/verdocs-loader.entry.js +0 -1
  444. package/dist/esm-es5/verdocs-preview_9.entry.js +0 -1
  445. package/dist/types/components/templates/verdocs-template-name/verdocs-template-name.d.ts +0 -41
  446. package/dist/types/components/templates/verdocs-template-visibillity/verdocs-template-visibility.d.ts +0 -42
  447. package/dist/types/utils/EnvelopeStore.d.ts +0 -12
  448. package/dist/types/utils/TemplateFieldStore.d.ts +0 -9
  449. package/dist/types/utils/TemplateRoleStore.d.ts +0 -11
  450. package/dist/types/utils/TemplateStore.d.ts +0 -16
  451. package/dist/verdocs-web-sdk/p-0c51c5be.entry.js +0 -1
  452. package/dist/verdocs-web-sdk/p-194f9f4d.entry.js +0 -1
  453. package/dist/verdocs-web-sdk/p-1bb57e5d.entry.js +0 -1
  454. package/dist/verdocs-web-sdk/p-2211234d.system.js +0 -1
  455. package/dist/verdocs-web-sdk/p-2305c1e8.system.entry.js +0 -1
  456. package/dist/verdocs-web-sdk/p-341d540f.system.entry.js +0 -1
  457. package/dist/verdocs-web-sdk/p-368a36ea.system.js +0 -1
  458. package/dist/verdocs-web-sdk/p-36b5d46e.entry.js +0 -1
  459. package/dist/verdocs-web-sdk/p-483f3d7f.entry.js +0 -1
  460. package/dist/verdocs-web-sdk/p-569434fb.system.js +0 -1
  461. package/dist/verdocs-web-sdk/p-56c1ebd6.entry.js +0 -1
  462. package/dist/verdocs-web-sdk/p-5bf2910c.system.entry.js +0 -1
  463. package/dist/verdocs-web-sdk/p-60da2bbe.system.entry.js +0 -1
  464. package/dist/verdocs-web-sdk/p-6fda3817.js +0 -1
  465. package/dist/verdocs-web-sdk/p-79e222f8.entry.js +0 -1
  466. package/dist/verdocs-web-sdk/p-7d18cb23.system.entry.js +0 -1
  467. package/dist/verdocs-web-sdk/p-7d593603.system.js +0 -1
  468. package/dist/verdocs-web-sdk/p-9515e206.system.entry.js +0 -1
  469. package/dist/verdocs-web-sdk/p-9fabdbb1.system.entry.js +0 -1
  470. package/dist/verdocs-web-sdk/p-a04aac80.entry.js +0 -1
  471. package/dist/verdocs-web-sdk/p-a706bac9.js +0 -1
  472. package/dist/verdocs-web-sdk/p-b17843d9.system.js +0 -1
  473. package/dist/verdocs-web-sdk/p-b56793c4.entry.js +0 -1
  474. package/dist/verdocs-web-sdk/p-b7a9f07d.system.entry.js +0 -1
  475. package/dist/verdocs-web-sdk/p-b84d1a25.system.entry.js +0 -1
  476. package/dist/verdocs-web-sdk/p-bb253149.js +0 -1
  477. package/dist/verdocs-web-sdk/p-bd642df2.js +0 -1
  478. package/dist/verdocs-web-sdk/p-c7115b35.system.entry.js +0 -1
  479. package/dist/verdocs-web-sdk/p-cde4c155.js +0 -1
  480. package/dist/verdocs-web-sdk/p-d86c8c1a.entry.js +0 -1
  481. package/dist/verdocs-web-sdk/p-dbddb752.system.entry.js +0 -1
  482. package/dist/verdocs-web-sdk/p-dcd3eb1b.js +0 -1
  483. package/dist/verdocs-web-sdk/p-e123f19c.entry.js +0 -1
  484. package/dist/verdocs-web-sdk/p-e294b6c2.system.entry.js +0 -1
  485. package/dist/verdocs-web-sdk/p-e48b387d.system.entry.js +0 -1
  486. package/dist/verdocs-web-sdk/p-e83a163d.entry.js +0 -1
  487. package/dist/verdocs-web-sdk/p-e952ab89.system.entry.js +0 -1
  488. package/dist/verdocs-web-sdk/p-f08eb8bf.entry.js +0 -1
  489. package/dist/verdocs-web-sdk/p-f5064e0c.system.js +0 -1
  490. package/dist/verdocs-web-sdk/p-f79b8537.system.js +0 -1
  491. package/dist/verdocs-web-sdk/p-fa06e241.entry.js +0 -1
@@ -1,16 +1,12 @@
1
- import { r as registerInstance, c as createEvent, h, H as Host, F as Fragment, g as getElement } from './index-c8587076.js';
2
- import { VerdocsEndpoint, integerSequence, getOrganizationContacts, isValidEmail, createEnvelope, getRGBA, formatFullName, createTemplateDocument, deleteTemplateDocument, createTemplate, updateField, createField, updateTemplate, updateTemplateRole, createTemplateRole } from '@verdocs/js-sdk';
3
- import { g as getTemplateFieldStore, u as updateStoreField } from './TemplateFieldStore-909147d8.js';
4
- import { g as getTemplateRoleStore, b as getRoleNames, a as getRoleIndex, u as updateStoreRole } from './TemplateRoleStore-2fef1fdb.js';
5
- import { g as getTemplateStore } from './TemplateStore-ace14a8b.js';
1
+ import { r as registerInstance, c as createEvent, h, H as Host, F as Fragment, g as getElement } from './index-272d51a4.js';
2
+ import { VerdocsEndpoint, getTemplate, integerSequence, getOrganizationContacts, isValidEmail, createEnvelope, getRGBA, formatFullName, createTemplateDocument, deleteTemplateDocument, updateField, createField, updateTemplateRole, createTemplateRole } from '@verdocs/js-sdk';
6
3
  import { S as SDKError } from './errors-887f1e88.js';
4
+ import { S as Store } from './Datastore-52fcbac6.js';
7
5
  import { V as VerdocsToast } from './Toast-c4843828.js';
8
- import { D as DocIcon, P as PngIcon, J as JpgIcon, a as PdfIcon, F as FileIcon$1, b as PageCountIcon, T as TrashIcon } from './Icons-faf0377f.js';
6
+ import { D as DocIcon, P as PngIcon, J as JpgIcon, a as PdfIcon, F as FileIcon, b as PageCountIcon, T as TrashIcon } from './Icons-faf0377f.js';
9
7
  import { f as format } from './format-b8602175.js';
10
8
  import { i as interact } from './interact.min-a71beb3d.js';
11
- import { b as updateCssTransform, c as removeCssTransform, d as setControlStyles, g as getFieldId, e as defaultWidth, f as defaultHeight } from './utils-27fa12eb.js';
12
- import './index-24d8ae6a.js';
13
- import './index-7588a071.js';
9
+ import { b as updateCssTransform, c as removeCssTransform, d as setControlStyles, g as getFieldId, e as defaultWidth, f as defaultHeight } from './utils-47de6f79.js';
14
10
  import './_commonjsHelpers-bdec4bbd.js';
15
11
  import './Types-95d86a44.js';
16
12
 
@@ -21,16 +17,31 @@ const VerdocsPreview = class {
21
17
  constructor(hostRef) {
22
18
  registerInstance(this, hostRef);
23
19
  this.sdkError = createEvent(this, "sdkError", 7);
24
- this.templateStore = null;
25
- this.fieldStore = null;
26
- this.roleStore = null;
20
+ this.templateListenerId = null;
27
21
  this.endpoint = VerdocsEndpoint.getDefault();
28
22
  this.templateId = null;
29
23
  this.loading = true;
24
+ this.template = null;
25
+ }
26
+ disconnectedCallback() {
27
+ this.unlistenToTemplate();
28
+ }
29
+ async listenToTemplate() {
30
+ this.unlistenToTemplate();
31
+ Store.subscribe('templates', this.templateId, () => getTemplate(this.endpoint, this.templateId), false, (template) => {
32
+ this.template = template;
33
+ this.loading = false;
34
+ });
35
+ }
36
+ unlistenToTemplate() {
37
+ if (this.templateListenerId) {
38
+ Store.store.delListener(this.templateListenerId);
39
+ this.templateListenerId = null;
40
+ }
30
41
  }
31
42
  onTemplateIdChanged(newTemplateId) {
32
43
  console.log('[PREVIEW] Template ID changed', newTemplateId);
33
- this.loadTemplate(newTemplateId).catch((e) => console.log('Unknown Error', e));
44
+ this.listenToTemplate();
34
45
  }
35
46
  async componentWillLoad() {
36
47
  var _a, _b, _c;
@@ -44,40 +55,25 @@ const VerdocsPreview = class {
44
55
  console.log(`[PREVIEW] Missing required template ID ${this.templateId}`);
45
56
  return;
46
57
  }
47
- return this.loadTemplate(this.templateId);
58
+ this.listenToTemplate();
48
59
  }
49
60
  catch (e) {
50
61
  console.log('[PREVIEW] Error with preview session', e);
51
62
  (_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));
52
63
  }
53
64
  }
54
- async loadTemplate(templateId) {
55
- if (templateId) {
56
- getTemplateStore(this.endpoint, templateId, false)
57
- .then(ts => {
58
- this.templateStore = ts;
59
- this.fieldStore = getTemplateFieldStore(this.templateId);
60
- this.roleStore = getTemplateRoleStore(this.templateId);
61
- this.loading = false;
62
- })
63
- .catch(e => {
64
- console.log('Unable to load template', e);
65
- throw e;
66
- });
67
- }
68
- }
69
65
  handlePageRendered(_e) {
70
66
  // const pageInfo = e.detail as IDocumentPageInfo;
71
- // const fields = this.templateStore?.state?.fields.filter(field => field.page === pageInfo.pageNumber);
67
+ // const fields = (this.template?.fields || []).filter(field => field.page === pageInfo.pageNumber);
72
68
  // console.log('[PREVIEW] Page rendered', pageInfo, fields);
73
69
  // fields.forEach(field => renderDocumentField(field, pageInfo, {disabled: true, editable: false, draggable: false}));
74
70
  }
75
71
  render() {
76
- var _a, _b;
72
+ var _a;
77
73
  if (this.loading) {
78
74
  return (h(Host, null, h("verdocs-loader", null)));
79
75
  }
80
- return (h(Host, null, (((_b = (_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.documents) || []).map(document => {
76
+ return (h(Host, null, (((_a = this.template) === null || _a === void 0 ? void 0 : _a.documents) || []).map(document => {
81
77
  const pageNumbers = integerSequence(1, document.pages);
82
78
  return (h(Fragment, null, pageNumbers.map(pageNumber => {
83
79
  var _a;
@@ -95,6 +91,9 @@ const VerdocsPreview = class {
95
91
  };
96
92
  VerdocsPreview.style = VerdocsPreviewStyle0;
97
93
 
94
+ const getRoleNames = (template) => ((template === null || template === void 0 ? void 0 : template.roles) || []).map(role => role.name);
95
+ const getRoleIndex = (template, role_name) => Math.max(getRoleNames(template).findIndex(name => name === role_name), 0);
96
+
98
97
  const verdocsSendCss = "@-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-send{padding:10px;position:relative;background:#ffffff;-ms-flex-direction:column;flex-direction:column;font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif}verdocs-send.sendable{display:-ms-flexbox;display:flex}verdocs-send .recipients{position:relative}verdocs-send .left-line{top:32px;left:20px;z-index:1;width:12px;bottom:30px;position:absolute;background:#ffffff;border-left:3px dotted #9b9b9b}verdocs-send .level{display:-ms-flexbox;display:flex;-webkit-column-gap:10px;-moz-column-gap:10px;column-gap:10px;margin-left:50px;position:relative;-ms-flex-direction:row;flex-direction:row;padding:8px 0 4px 0;border-bottom:1px solid rgba(151, 151, 151, 0.2666666667)}verdocs-send .level .level-icon{top:14px;z-index:2;left:-40px;width:24px;height:24px;position:absolute;background:#ffffff}verdocs-send .level .level-icon svg{fill:rgba(0, 0, 0, 0.537254902)}verdocs-send .level .recipient{height:30px;display:-ms-flexbox;display:flex;-ms-flex:0 0 30px;flex:0 0 30px;color:#000000;cursor:pointer;font-size:14px;-ms-flex-align:center;align-items:center;border-radius:30px;-ms-flex-direction:row;flex-direction:row;background:#dddddd;white-space:nowrap;border:2px solid #dddddd;padding:2px 10px 2px 14px}verdocs-send .level .recipient .icon{width:22px;height:22px;-ms-flex:0 0 22px;flex:0 0 22px;margin:0 0 0 10px}verdocs-send .level .recipient .icon svg{width:22px;height:22px;fill:#333333;outline:none}verdocs-send .level .complete{-ms-flex:1;flex:1;height:30px;display:-ms-flexbox;display:flex;color:#000000;font-size:14px;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row;padding:3px 10px 3px 2px}verdocs-send .buttons{display:-ms-flexbox;display:flex;margin-top:10px;-webkit-column-gap:15px;-moz-column-gap:15px;column-gap:15px;-ms-flex-direction:row;flex-direction:row}verdocs-send verdocs-contact-picker{left:0;top:41px;z-index:10;position:absolute;border:1px solid #dddddd;-webkit-box-shadow:0 0 6px 3px rgba(0, 0, 0, 0.1);box-shadow:0 0 6px 3px rgba(0, 0, 0, 0.1)}";
99
98
  const VerdocsSendStyle0 = verdocsSendCss;
100
99
 
@@ -110,6 +109,7 @@ const VerdocsSend = class {
110
109
  this.exit = createEvent(this, "exit", 7);
111
110
  this.sdkError = createEvent(this, "sdkError", 7);
112
111
  this.searchContacts = createEvent(this, "searchContacts", 7);
112
+ this.templateListenerId = null;
113
113
  this.endpoint = VerdocsEndpoint.getDefault();
114
114
  this.templateId = null;
115
115
  this.environment = '';
@@ -118,15 +118,33 @@ const VerdocsSend = class {
118
118
  this.sessionContacts = [];
119
119
  this.sending = false;
120
120
  this.rolesCompleted = {};
121
- this.templateStore = null;
122
- this.roleStore = null;
121
+ this.loading = true;
122
+ this.template = null;
123
+ }
124
+ disconnectedCallback() {
125
+ this.unlistenToTemplate();
126
+ }
127
+ async listenToTemplate() {
128
+ console.log('[SEND] Loading template', this.templateId);
129
+ this.unlistenToTemplate();
130
+ Store.subscribe('templates', this.templateId, () => getTemplate(this.endpoint, this.templateId), false, (template) => {
131
+ this.template = template;
132
+ this.loading = false;
133
+ this.rolesCompleted = {};
134
+ });
135
+ }
136
+ unlistenToTemplate() {
137
+ if (this.templateListenerId) {
138
+ Store.store.delListener(this.templateListenerId);
139
+ this.templateListenerId = null;
140
+ }
123
141
  }
124
142
  async reset() {
125
143
  this.rolesCompleted = {};
126
144
  }
127
145
  onTemplateIdChanged(newTemplateId) {
128
146
  console.log('[SEND] Template ID changed', newTemplateId);
129
- this.loadTemplate(newTemplateId).catch((e) => console.log('Unknown Error', e));
147
+ this.listenToTemplate();
130
148
  }
131
149
  async componentWillLoad() {
132
150
  var _a, _b, _c;
@@ -163,37 +181,18 @@ const VerdocsSend = class {
163
181
  console.log(`[SEND] Missing required template ID ${this.templateId}`);
164
182
  return;
165
183
  }
166
- return this.loadTemplate(this.templateId);
184
+ this.listenToTemplate();
167
185
  }
168
186
  catch (e) {
169
187
  console.log('[SEND] Error with send session', e);
170
188
  (_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));
171
189
  }
172
190
  }
173
- async loadTemplate(templateId) {
174
- var _a, _b, _c, _d, _e;
175
- if (!templateId) {
176
- return;
177
- }
178
- try {
179
- this.templateStore = await getTemplateStore(this.endpoint, templateId, false);
180
- this.roleStore = getTemplateRoleStore(templateId);
181
- this.recomputeRolesCompleted();
182
- if (!((_b = (_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.is_sendable)) {
183
- console.warn(`[SEND] Template is not sendable`, templateId);
184
- }
185
- }
186
- catch (e) {
187
- console.log('[SEND] Error with preview session', e);
188
- (_c = this.sdkError) === null || _c === void 0 ? void 0 : _c.emit(new SDKError(e.message, (_d = e.response) === null || _d === void 0 ? void 0 : _d.status, (_e = e.response) === null || _e === void 0 ? void 0 : _e.data));
189
- }
190
- }
191
191
  recomputeRolesCompleted() {
192
192
  var _a;
193
- const roles = ((_a = this.roleStore) === null || _a === void 0 ? void 0 : _a.get('roles')) || [];
194
- const rolesAtLevel = {};
195
193
  this.rolesCompleted = {};
196
- roles.forEach(role => {
194
+ const rolesAtLevel = {};
195
+ (((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || []).forEach(role => {
197
196
  const level = role.sequence - 1;
198
197
  rolesAtLevel[level] || (rolesAtLevel[level] = []);
199
198
  const id = `r-${level}-${rolesAtLevel[level].length}`;
@@ -207,15 +206,13 @@ const VerdocsSend = class {
207
206
  }
208
207
  getLevels() {
209
208
  var _a;
210
- const roles = ((_a = this.roleStore) === null || _a === void 0 ? void 0 : _a.get('roles')) || [];
211
- const levels = [...new Set(roles.map(role => role.sequence - 1))];
209
+ const levels = [...new Set((((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || []).map(role => role.sequence - 1))];
212
210
  levels.sort((a, b) => a - b);
213
211
  return levels;
214
212
  }
215
213
  getRolesAtLevel(level) {
216
214
  var _a;
217
- const roles = ((_a = this.roleStore) === null || _a === void 0 ? void 0 : _a.get('roles')) || [];
218
- const rolesAtLevel = roles
215
+ const rolesAtLevel = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || [])
219
216
  .filter(role => role.sequence - 1 === level)
220
217
  .map((role, index) => ({
221
218
  ...role,
@@ -248,7 +245,7 @@ const VerdocsSend = class {
248
245
  this.showPickerForId = role.id;
249
246
  }
250
247
  handleSend(e) {
251
- var _a, _b, _c;
248
+ var _a, _b;
252
249
  if (this.sending) {
253
250
  console.log('[SEND] Skipping duplicate send', e);
254
251
  return;
@@ -260,7 +257,7 @@ const VerdocsSend = class {
260
257
  (_a = this.sendingEnvelope) === null || _a === void 0 ? void 0 : _a.emit({ sending: true });
261
258
  const details = {
262
259
  template_id: this.templateId,
263
- name: ((_c = (_b = this.templateStore) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.name) || '',
260
+ name: ((_b = this.template) === null || _b === void 0 ? void 0 : _b.name) || 'New Envelope',
264
261
  environment: this.environment,
265
262
  initial_reminder: 0,
266
263
  followup_reminders: 0,
@@ -271,12 +268,12 @@ const VerdocsSend = class {
271
268
  console.log('[SEND] Creating envelope', details);
272
269
  createEnvelope(this.endpoint, details)
273
270
  .then(r => {
274
- var _a, _b, _c, _d;
271
+ var _a, _b;
275
272
  console.log('[SEND] Send envelope', r);
276
273
  this.reset().catch((e) => console.log('Unknown Error', e));
277
274
  this.sending = false;
278
275
  (_a = this.sendingEnvelope) === null || _a === void 0 ? void 0 : _a.emit({ sending: false });
279
- (_b = this.send) === null || _b === void 0 ? void 0 : _b.emit({ ...details, name: ((_d = (_c = this.templateStore) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.name) || 'New Envelope', envelope_id: r.id, envelope: r });
276
+ (_b = this.send) === null || _b === void 0 ? void 0 : _b.emit({ ...details, name: details.name, envelope_id: r.id, envelope: r });
280
277
  })
281
278
  .catch(e => {
282
279
  var _a, _b, _c;
@@ -292,22 +289,25 @@ const VerdocsSend = class {
292
289
  (_a = this.exit) === null || _a === void 0 ? void 0 : _a.emit();
293
290
  }
294
291
  render() {
295
- var _a, _b;
292
+ var _a;
293
+ if (this.loading) {
294
+ return (h(Host, null, h("verdocs-loader", null)));
295
+ }
296
296
  if (!this.endpoint.session) {
297
297
  return (h(Host, { style: { display: 'flex' } }, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
298
298
  }
299
299
  const levels = this.getLevels();
300
- const roleNames = getRoleNames(this.roleStore);
301
300
  const rolesAssigned = Object.values(this.rolesCompleted).filter(recipient => isValidEmail(recipient.email));
302
301
  // TODO: Reactivate once SMS is re-enabled
303
302
  // const rolesAssigned = Object.values(this.rolesCompleted).filter(recipient => isValidEmail(recipient.email) || isValidPhone(recipient.phone));
304
- const allRolesAssigned = rolesAssigned.length >= roleNames.length;
305
- // console.log('[SEND] Roles completed', this.rolesCompleted);
306
- return (h(Host, { class: { sendable: (_b = (_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.is_sendable } }, h("div", { class: "recipients" }, h("div", { class: "left-line" }), h("div", { class: `level level-start` }, this.getLevelIcon(-1), h("div", { class: "complete" }, "Send Envelope")), levels.map(level => (h("div", { class: `level level-${level}` }, this.getLevelIcon(level), this.getRolesAtLevel(level).map(role => {
303
+ const allRolesAssigned = rolesAssigned.length >= getRoleNames(this.template).length;
304
+ return (h(Host, { class: { sendable: (_a = this.template) === null || _a === void 0 ? void 0 : _a.is_sendable } }, h("div", { class: "recipients" }, h("div", { class: "left-line" }), h("div", { class: `level level-start` }, this.getLevelIcon(-1), h("div", { class: "complete" }, "Send Envelope")), levels.map(level => (h("div", { class: `level level-${level}` }, this.getLevelIcon(level), this.getRolesAtLevel(level).map(role => {
307
305
  var _a, _b, _c, _d;
308
306
  const unknown = !role.email;
309
307
  const elId = `verdocs-send-recipient-${role.role_name}`;
310
- return unknown ? (h("div", { class: "recipient", "data-ri": getRoleIndex(this.roleStore, role.role_name), "data-rn": role.role_name, style: { backgroundColor: getRGBA(getRoleIndex(this.roleStore, role.role_name)) }, onClick: e => this.handleClickRole(e, role), id: elId }, ((_a = this.rolesCompleted[role.id]) === null || _a === void 0 ? void 0 : _a.first_name) ? formatFullName(this.rolesCompleted[role.id]) : role.role_name, h("div", { class: "icon", innerHTML: editIcon }), this.showPickerForId === role.id && (h("verdocs-portal", { anchor: elId, onClickAway: () => (this.showPickerForId = '') }, h("verdocs-contact-picker", { onExit: () => (this.showPickerForId = ''), onNext: e => this.handleSelectContact(e, role), contactSuggestions: this.sessionContacts, templateRole: (_b = this.rolesCompleted[role.id]) !== null && _b !== void 0 ? _b : role, onSearchContacts: e => { var _a; return (_a = this.searchContacts) === null || _a === void 0 ? void 0 : _a.emit(e.detail); } }))))) : (h("div", { class: "recipient", style: { borderColor: getRGBA(getRoleIndex(this.roleStore, role.role_name)) }, onClick: e => this.handleClickRole(e, role), id: elId }, ((_c = this.rolesCompleted[role.id]) === null || _c === void 0 ? void 0 : _c.first_name) ? formatFullName(this.rolesCompleted[role.id]) : role.role_name, h("div", { class: "icon", innerHTML: editIcon }), this.showPickerForId === role.id && (h("verdocs-portal", { anchor: elId, onClickAway: () => (this.showPickerForId = '') }, h("verdocs-contact-picker", { onExit: () => (this.showPickerForId = ''), onNext: e => this.handleSelectContact(e, role), contactSuggestions: this.sessionContacts, templateRole: ((_d = this.rolesCompleted[role.id]) !== null && _d !== void 0 ? _d : role), onSearchContacts: e => { var _a; return (_a = this.searchContacts) === null || _a === void 0 ? void 0 : _a.emit(e.detail); } })))));
308
+ const roleIndex = getRoleIndex(this.template, role.role_name);
309
+ const rgba = getRGBA(roleIndex);
310
+ return unknown ? (h("div", { class: "recipient", "data-ri": roleIndex, "data-rn": role.role_name, style: { backgroundColor: rgba }, onClick: e => this.handleClickRole(e, role), id: elId }, ((_a = this.rolesCompleted[role.id]) === null || _a === void 0 ? void 0 : _a.first_name) ? formatFullName(this.rolesCompleted[role.id]) : role.role_name, h("div", { class: "icon", innerHTML: editIcon }), this.showPickerForId === role.id && (h("verdocs-portal", { anchor: elId, onClickAway: () => (this.showPickerForId = '') }, h("verdocs-contact-picker", { onExit: () => (this.showPickerForId = ''), onNext: e => this.handleSelectContact(e, role), contactSuggestions: this.sessionContacts, templateRole: (_b = this.rolesCompleted[role.id]) !== null && _b !== void 0 ? _b : role, onSearchContacts: e => { var _a; return (_a = this.searchContacts) === null || _a === void 0 ? void 0 : _a.emit(e.detail); } }))))) : (h("div", { class: "recipient", style: { borderColor: rgba }, onClick: e => this.handleClickRole(e, role), id: elId }, ((_c = this.rolesCompleted[role.id]) === null || _c === void 0 ? void 0 : _c.first_name) ? formatFullName(this.rolesCompleted[role.id]) : role.role_name, h("div", { class: "icon", innerHTML: editIcon }), this.showPickerForId === role.id && (h("verdocs-portal", { anchor: elId, onClickAway: () => (this.showPickerForId = '') }, h("verdocs-contact-picker", { onExit: () => (this.showPickerForId = ''), onNext: e => this.handleSelectContact(e, role), contactSuggestions: this.sessionContacts, templateRole: ((_d = this.rolesCompleted[role.id]) !== null && _d !== void 0 ? _d : role), onSearchContacts: e => { var _a; return (_a = this.searchContacts) === null || _a === void 0 ? void 0 : _a.emit(e.detail); } })))));
311
311
  })))), h("div", { class: `level level-done` }, this.getLevelIcon(levels.length), h("div", { class: "complete" }, "Signing Complete"))), h("div", { class: "buttons" }, h("verdocs-button", { label: "Cancel", size: "small", variant: "outline", onClick: e => this.handleCancel(e), disabled: this.sending }), h("verdocs-button", { label: "Send", size: "small", disabled: !allRolesAssigned || this.sending, onClick: e => this.handleSend(e) }), this.sending && h("verdocs-spinner", null))));
312
312
  }
313
313
  static get watchers() { return {
@@ -326,6 +326,7 @@ const VerdocsTemplateAttachments = class {
326
326
  this.next = createEvent(this, "next", 7);
327
327
  this.templateUpdated = createEvent(this, "templateUpdated", 7);
328
328
  this.sdkError = createEvent(this, "sdkError", 7);
329
+ this.templateListenerId = null;
329
330
  this.endpoint = VerdocsEndpoint.getDefault();
330
331
  this.templateId = '';
331
332
  this.uploading = false;
@@ -333,7 +334,8 @@ const VerdocsTemplateAttachments = class {
333
334
  this.progressPercent = 0;
334
335
  this.showDeleteError = false;
335
336
  this.confirmDeleteDocument = null;
336
- this.store = null;
337
+ this.loading = true;
338
+ this.template = null;
337
339
  }
338
340
  async componentWillLoad() {
339
341
  var _a, _b, _c;
@@ -347,13 +349,29 @@ const VerdocsTemplateAttachments = class {
347
349
  console.log('[ROLES] Unable to start builder session, must be authenticated');
348
350
  return;
349
351
  }
350
- this.store = await getTemplateStore(this.endpoint, this.templateId, false);
352
+ this.listenToTemplate();
351
353
  }
352
354
  catch (e) {
353
355
  console.log('[TEMPLATE ATTACHMENTS] Error loading template', e);
354
356
  (_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));
355
357
  }
356
358
  }
359
+ disconnectedCallback() {
360
+ this.unlistenToTemplate();
361
+ }
362
+ async listenToTemplate() {
363
+ this.unlistenToTemplate();
364
+ Store.subscribe('templates', this.templateId, () => getTemplate(this.endpoint, this.templateId), false, (template) => {
365
+ this.template = template;
366
+ this.loading = false;
367
+ });
368
+ }
369
+ unlistenToTemplate() {
370
+ if (this.templateListenerId) {
371
+ Store.store.delListener(this.templateListenerId);
372
+ this.templateListenerId = null;
373
+ }
374
+ }
357
375
  handleCancel(e) {
358
376
  e.stopPropagation();
359
377
  this.exit.emit();
@@ -380,9 +398,10 @@ const VerdocsTemplateAttachments = class {
380
398
  try {
381
399
  const template = await createTemplateDocument(this.endpoint, this.templateId, file, this.handleUploadProgress.bind(this));
382
400
  console.log('[ATTACHMENTS] Created attachment', template);
383
- this.store = await getTemplateStore(this.endpoint, this.templateId, false);
384
- console.log('[ATTACHMENTS] Updated template', this.store.state);
385
- (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: this.store.state, event: 'attachments' });
401
+ // TODO: Just updated it in place.
402
+ this.template = await Store.getTemplate(this.endpoint, this.templateId, true);
403
+ console.log('[ATTACHMENTS] Updated template', this.template);
404
+ (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: this.template, event: 'attachments' });
386
405
  this.uploading = false;
387
406
  this.progressLabel = '';
388
407
  this.progressPercent = 0;
@@ -399,17 +418,18 @@ const VerdocsTemplateAttachments = class {
399
418
  this.uploading = false;
400
419
  this.progressLabel = '';
401
420
  this.progressPercent = 0;
402
- (_a = this.next) === null || _a === void 0 ? void 0 : _a.emit({ template: this.store.state });
421
+ (_a = this.next) === null || _a === void 0 ? void 0 : _a.emit({ template: this.template });
403
422
  }
404
423
  async confirmDelete() {
405
424
  await deleteTemplateDocument(this.endpoint, this.templateId, this.confirmDeleteDocument.id);
406
- this.store = await getTemplateStore(this.endpoint, this.templateId, false);
407
- console.log('[ATTACHMENTS] New template', this.store.state);
425
+ // TODO: Update it in place
426
+ this.template = await Store.getTemplate(this.endpoint, this.templateId, true);
427
+ console.log('[ATTACHMENTS] New template', this.template);
408
428
  this.confirmDeleteDocument = null;
409
429
  }
410
430
  async handleDelete(document) {
411
431
  var _a;
412
- if (((_a = this.store.state) === null || _a === void 0 ? void 0 : _a.documents.length) > 1) {
432
+ if ((((_a = this.template) === null || _a === void 0 ? void 0 : _a.documents) || []).length > 1) {
413
433
  this.confirmDeleteDocument = document;
414
434
  }
415
435
  else {
@@ -428,22 +448,21 @@ const VerdocsTemplateAttachments = class {
428
448
  case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
429
449
  return DocIcon;
430
450
  }
431
- return FileIcon$1;
451
+ return FileIcon;
432
452
  }
433
453
  render() {
434
- var _a, _b, _c;
454
+ var _a, _b;
435
455
  if (!this.endpoint.session) {
436
456
  return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
437
457
  }
438
- const templateState = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state;
439
- if (!templateState.isLoaded) {
458
+ if (this.loading) {
440
459
  return (h(Host, { class: "loading" }, h("verdocs-loader", null)));
441
460
  }
442
461
  // This is meant to be a companion for larger visual experiences so we just go blank on errors for now.
443
- if (!this.endpoint.session || !templateState.profile_id) {
462
+ if (!this.endpoint.session || !this.template) {
444
463
  return h(Host, { class: "empty" });
445
464
  }
446
- return (h(Host, null, h("h5", null, "Existing Attachments"), h("div", { class: "attachments" }, (_b = this.store) === null || _b === void 0 ? void 0 : _b.state.documents.map(document => (h("div", { class: "attachment" }, h("div", { class: "file-icon", innerHTML: this.getFileIcon(document) }), h("div", { class: "filename", title: document.name }, document.name), h("div", { class: "pages" }, h("div", { class: "count" }, document.pages), h("div", { class: "pages-icon", innerHTML: PageCountIcon })), h("div", { class: "trash-icon", innerHTML: TrashIcon, onClick: () => this.handleDelete(document) }))))), h("h5", null, "Attach a New Document"), this.uploading ? (h("div", { class: "loader-wrapper" }, h("verdocs-loader", null), this.progressLabel && (h("div", { class: "progress-wrapper" }, h("verdocs-progress-bar", { showPercent: true, percent: this.progressPercent, label: this.progressLabel }))))) : (h("verdocs-file-chooser", { onFileSelected: e => this.handleUpload(e) })), h("div", { class: "buttons" }, h("verdocs-button", { variant: "outline", label: "Cancel", size: "small", onClick: e => this.handleCancel(e), disabled: this.uploading }), h("verdocs-button", { label: "Next", size: "small", onClick: e => this.handleNext(e), disabled: !((_c = this.store) === null || _c === void 0 ? void 0 : _c.state.documents.length) || this.uploading })), this.showDeleteError && (h("verdocs-ok-dialog", { heading: "Unable to Delete Attachment", message: "Templates must contain at least one attachment.", onNext: () => (this.showDeleteError = false) })), this.confirmDeleteDocument && (h("verdocs-ok-dialog", { heading: "Delete this Attachment?", message: "This operation cannot be undone. All fields placed<br />on the deleted attachment will also be removed.", onNext: () => this.confirmDelete(), showCancel: true, onExit: () => {
465
+ return (h(Host, null, h("h5", null, "Existing Attachments"), h("div", { class: "attachments" }, (((_a = this.template) === null || _a === void 0 ? void 0 : _a.documents) || []).map(document => (h("div", { class: "attachment" }, h("div", { class: "file-icon", innerHTML: this.getFileIcon(document) }), h("div", { class: "filename", title: document.name }, document.name), h("div", { class: "pages" }, h("div", { class: "count" }, document.pages), h("div", { class: "pages-icon", innerHTML: PageCountIcon })), h("div", { class: "trash-icon", innerHTML: TrashIcon, onClick: () => this.handleDelete(document) }))))), h("h5", null, "Attach a New Document"), this.uploading ? (h("div", { class: "loader-wrapper" }, h("verdocs-loader", null), this.progressLabel && (h("div", { class: "progress-wrapper" }, h("verdocs-progress-bar", { showPercent: true, percent: this.progressPercent, label: this.progressLabel }))))) : (h("verdocs-file-chooser", { onFileSelected: e => this.handleUpload(e) })), h("div", { class: "buttons" }, h("verdocs-button", { variant: "outline", label: "Cancel", size: "small", onClick: e => this.handleCancel(e), disabled: this.uploading }), h("verdocs-button", { label: "Next", size: "small", onClick: e => this.handleNext(e), disabled: !(((_b = this.template) === null || _b === void 0 ? void 0 : _b.documents) || []).length || this.uploading })), this.showDeleteError && (h("verdocs-ok-dialog", { heading: "Unable to Delete Attachment", message: "Templates must contain at least one attachment.", onNext: () => (this.showDeleteError = false) })), this.confirmDeleteDocument && (h("verdocs-ok-dialog", { heading: "Delete this Attachment?", message: "This operation cannot be undone. All fields placed<br />on the deleted attachment will also be removed.", onNext: () => this.confirmDelete(), showCancel: true, onExit: () => {
447
466
  this.confirmDeleteDocument = null;
448
467
  } }))));
449
468
  }
@@ -461,21 +480,38 @@ const VerdocsTemplateBuildTabs = class {
461
480
  registerInstance(this, hostRef);
462
481
  this.sdkError = createEvent(this, "sdkError", 7);
463
482
  this.stepChanged = createEvent(this, "stepChanged", 7);
483
+ this.templateListenerId = null;
464
484
  this.endpoint = VerdocsEndpoint.getDefault();
465
485
  this.templateId = null;
466
486
  this.step = 'preview';
467
- this.templateStore = null;
487
+ this.loading = true;
488
+ this.template = null;
489
+ }
490
+ disconnectedCallback() {
491
+ this.unlistenToTemplate();
492
+ }
493
+ async listenToTemplate() {
494
+ this.unlistenToTemplate();
495
+ Store.subscribe('templates', this.templateId, () => getTemplate(this.endpoint, this.templateId), false, (template) => {
496
+ this.template = template;
497
+ this.loading = false;
498
+ });
499
+ }
500
+ unlistenToTemplate() {
501
+ if (this.templateListenerId) {
502
+ Store.store.delListener(this.templateListenerId);
503
+ this.templateListenerId = null;
504
+ }
468
505
  }
469
506
  onTemplateIdChanged(newTemplateId) {
470
507
  console.log('[BUILD_TABS] Template ID changed', newTemplateId);
471
- this.loadTemplate(newTemplateId).catch((e) => console.log('Unknown Error', e));
508
+ this.listenToTemplate();
472
509
  }
473
510
  onStepChanged(newStep) {
474
511
  console.log('[BUILD_TABS] Step changed', newStep);
475
- this.loadTemplate(this.templateId).catch((e) => console.log('Unknown Error', e));
476
512
  }
477
513
  async componentWillLoad() {
478
- var _a, _b, _c, _d, _e, _f;
514
+ var _a, _b, _c;
479
515
  try {
480
516
  this.endpoint.loadSession();
481
517
  if (!this.endpoint.session) {
@@ -487,27 +523,16 @@ const VerdocsTemplateBuildTabs = class {
487
523
  console.log('[BUILD_TABS] Missing required template ID, forcing view to attachments');
488
524
  return;
489
525
  }
490
- try {
491
- this.templateStore = await getTemplateStore(this.endpoint, this.templateId, false);
492
- }
493
- catch (e) {
494
- console.log('[BUILD_TABS] Error loading template', e);
495
- (_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));
496
- }
526
+ this.listenToTemplate();
497
527
  }
498
528
  catch (e) {
499
529
  console.log('[BUILD_TABS] Error loading template', e);
500
- (_d = this.sdkError) === null || _d === void 0 ? void 0 : _d.emit(new SDKError(e.message, (_e = e.response) === null || _e === void 0 ? void 0 : _e.status, (_f = e.response) === null || _f === void 0 ? void 0 : _f.data));
501
- }
502
- }
503
- async loadTemplate(templateId) {
504
- if (templateId) {
505
- this.templateStore = await getTemplateStore(this.endpoint, templateId, false);
530
+ (_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));
506
531
  }
507
532
  }
508
533
  setStep(e) {
509
534
  var _a;
510
- console.log('Selected step', e.detail.tab.id);
535
+ console.log('[BUILD_TABS] Selected step', e.detail.tab.id);
511
536
  e.stopPropagation();
512
537
  e.preventDefault();
513
538
  this.step = e.detail.tab.id;
@@ -526,18 +551,16 @@ const VerdocsTemplateBuildTabs = class {
526
551
  });
527
552
  }
528
553
  render() {
529
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
554
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
555
+ if (this.loading) {
556
+ return (h(Host, null, h("verdocs-loader", null)));
557
+ }
530
558
  if (!this.endpoint.session) {
531
559
  return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
532
560
  }
533
- let canPreview = false;
534
- let canEditFields = false;
535
- let canEditRoles = false;
536
- if (this.templateId && this.templateStore && this.templateStore.state) {
537
- canEditRoles = ((_c = (_b = (_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.documents) === null || _c === void 0 ? void 0 : _c.length) > 0;
538
- canEditFields = canEditRoles && ((_f = (_e = (_d = this.templateStore) === null || _d === void 0 ? void 0 : _d.state) === null || _e === void 0 ? void 0 : _e.roles) === null || _f === void 0 ? void 0 : _f.length) > 0;
539
- canPreview = canEditFields && ((_j = (_h = (_g = this.templateStore) === null || _g === void 0 ? void 0 : _g.state) === null || _h === void 0 ? void 0 : _h.fields) === null || _j === void 0 ? void 0 : _j.length) > 0;
540
- }
561
+ const canEditRoles = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.documents) || []).length > 0;
562
+ let canEditFields = canEditRoles && (((_b = this.template) === null || _b === void 0 ? void 0 : _b.roles) || []).length > 0;
563
+ const canPreview = canEditFields && (((_c = this.template) === null || _c === void 0 ? void 0 : _c.fields) || []).length > 0;
541
564
  let selectedStepIndex = Math.max(STEPS.indexOf(this.step), 0);
542
565
  if (!canPreview && selectedStepIndex >= 4) {
543
566
  selectedStepIndex = 3;
@@ -554,8 +577,8 @@ const VerdocsTemplateBuildTabs = class {
554
577
  { id: 'settings', disabled: !canEditFields, label: 'Settings' },
555
578
  { id: 'fields', disabled: !canEditFields, label: 'Fields' },
556
579
  { id: 'preview', disabled: !canPreview, label: 'Preview/Send' },
557
- ] }), this.templateId && (h("div", { class: "info" }, h("verdocs-button-panel", { icon: HelpIcon }, h("div", { class: "template-details-panel" }, h("h6", null, "Template Details"), h("div", { class: "row" }, h("label", null, "ID:"), h("div", { class: "value" }, this.templateId), h("div", { class: "icon-button", innerHTML: CopyIcon, onClick: () => this.copyTemplateId() })), h("div", { class: "row" }, h("label", null, "Name:"), h("div", { class: "value" }, (_l = (_k = this.templateStore) === null || _k === void 0 ? void 0 : _k.state) === null || _l === void 0 ? void 0 : _l.name)), h("div", { class: "row" }, h("label", null, "Visibility:"), h("div", { class: "value" }, ((_o = (_m = this.templateStore) === null || _m === void 0 ? void 0 : _m.state) === null || _o === void 0 ? void 0 : _o.is_public) ? 'Public' : ((_q = (_p = this.templateStore) === null || _p === void 0 ? void 0 : _p.state) === null || _q === void 0 ? void 0 : _q.is_personal) ? 'Private' : 'Shared')), h("div", { class: "row" }, h("label", null, "Created:"), h("div", { class: "value" }, ((_s = (_r = this.templateStore) === null || _r === void 0 ? void 0 : _r.state) === null || _s === void 0 ? void 0 : _s.counter) ? format(new Date((_u = (_t = this.templateStore) === null || _t === void 0 ? void 0 : _t.state) === null || _u === void 0 ? void 0 : _u.created_at), 'P p') : '')), h("div", { class: "row" }, h("label", null, "Used:"), h("div", { class: "value" }, (_w = (_v = this.templateStore) === null || _v === void 0 ? void 0 : _v.state) === null || _w === void 0 ? void 0 :
558
- _w.counter, " time(s)"))))))));
580
+ ] }), this.templateId && (h("div", { class: "info" }, h("verdocs-button-panel", { icon: HelpIcon }, h("div", { class: "template-details-panel" }, h("h6", null, "Template Details"), h("div", { class: "row" }, h("label", null, "ID:"), h("div", { class: "value" }, this.templateId), h("div", { class: "icon-button", innerHTML: CopyIcon, onClick: () => this.copyTemplateId() })), h("div", { class: "row" }, h("label", null, "Name:"), h("div", { class: "value" }, (_d = this.template) === null || _d === void 0 ? void 0 : _d.name)), h("div", { class: "row" }, h("label", null, "Visibility:"), h("div", { class: "value" }, ((_e = this.template) === null || _e === void 0 ? void 0 : _e.is_public) ? 'Public' : ((_f = this.template) === null || _f === void 0 ? void 0 : _f.is_personal) ? 'Private' : 'Shared')), h("div", { class: "row" }, h("label", null, "Created:"), h("div", { class: "value" }, ((_g = this.template) === null || _g === void 0 ? void 0 : _g.counter) ? format(new Date((_h = this.template) === null || _h === void 0 ? void 0 : _h.created_at), 'P p') : '')), h("div", { class: "row" }, h("label", null, "Used:"), h("div", { class: "value" }, (_j = this.template) === null || _j === void 0 ? void 0 :
581
+ _j.counter, " time(s)"))))))));
559
582
  }
560
583
  static get watchers() { return {
561
584
  "templateId": ["onTemplateIdChanged"],
@@ -564,112 +587,6 @@ const VerdocsTemplateBuildTabs = class {
564
587
  };
565
588
  VerdocsTemplateBuildTabs.style = VerdocsTemplateBuildTabsStyle0;
566
589
 
567
- const verdocsTemplateCreateCss = "@-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-template-create{font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif}verdocs-template-create form{background-color:#ffffff;padding:12px;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}verdocs-template-create form .upload-box{-webkit-box-sizing:border-box;box-sizing:border-box;width:320px;text-align:center;padding:44px 18px 66px;border:2px dashed #979797;color:rgba(0, 0, 0, 0.54)}verdocs-template-create form .upload-box.drag-over{border:2px solid #4c56cb}verdocs-template-create form .upload-box svg{width:64px;fill:#5c6575}verdocs-template-create p{color:#33364b;margin-top:20px;font-size:18px;font-weight:500;overflow-wrap:anywhere}verdocs-template-create p.subscript{color:#5c6575;font-size:14px;margin:20px}verdocs-template-create .loader-wrapper{background-color:#ffffff;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-webkit-box-sizing:border-box;box-sizing:border-box;position:relative;width:320px;height:320px;text-align:center;border:2px dashed #979797;-ms-flex-pack:end;justify-content:flex-end}verdocs-template-create .progress-wrapper{padding:20px}verdocs-template-create .buttons{display:-ms-flexbox;display:flex;-webkit-column-gap:8px;-moz-column-gap:8px;column-gap:8px;margin-top:16px;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:end;justify-content:flex-end}verdocs-template-create .buttons .flex-fill{-ms-flex:1;flex:1}verdocs-template-create ::-webkit-input-placeholder{color:#aaaaaa}verdocs-template-create ::-moz-placeholder{color:#aaaaaa}verdocs-template-create :-ms-input-placeholder{color:#aaaaaa}verdocs-template-create ::-ms-input-placeholder{color:#aaaaaa}verdocs-template-create ::placeholder{color:#aaaaaa}verdocs-template-create .error{margin:20px 0;color:#cc0000}";
568
- const VerdocsTemplateCreateStyle0 = verdocsTemplateCreateCss;
569
-
570
- const FileIcon = '<svg focusable="false" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 2c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6H6zm7 7V3.5L18.5 9H13z"></path></svg>';
571
- const VerdocsTemplateCreate = class {
572
- constructor(hostRef) {
573
- registerInstance(this, hostRef);
574
- this.exit = createEvent(this, "exit", 7);
575
- this.next = createEvent(this, "next", 7);
576
- this.sdkError = createEvent(this, "sdkError", 7);
577
- this.templateCreated = createEvent(this, "templateCreated", 7);
578
- this.endpoint = VerdocsEndpoint.getDefault();
579
- this.maxSize = 20.5 * 1024 * 1024;
580
- this.file = undefined;
581
- this.creating = false;
582
- this.progressLabel = 'Uploading...';
583
- this.progressPercent = 0;
584
- this.errorMessage = '';
585
- }
586
- componentWillLoad() {
587
- this.endpoint.setTimeout(30000);
588
- this.endpoint.loadSession();
589
- }
590
- handleFileChanged(e) {
591
- var _a;
592
- this.errorMessage = '';
593
- this.file = ((_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0]) || null;
594
- console.log('[CREATE] Selected file', this.file);
595
- const totalSize = this.file.size;
596
- if (totalSize > this.maxSize) {
597
- this.errorMessage = 'Total file size must not exceed 20MB.';
598
- }
599
- }
600
- handleUpload(e) {
601
- e.stopPropagation();
602
- const fileElem = document.getElementById('verdocs-template-create-file');
603
- fileElem.click();
604
- }
605
- handleCancel(e) {
606
- e.stopPropagation();
607
- this.exit.emit();
608
- }
609
- async handleSubmit(e) {
610
- var _a, _b, _c;
611
- e.stopPropagation();
612
- // Should be true if we're here because onClick is only enabled then. We're just guarding this for Typescript.
613
- if (!this.file) {
614
- return;
615
- }
616
- this.creating = true;
617
- this.progressLabel = 'Uploading...';
618
- try {
619
- const template = await createTemplate(this.endpoint, {
620
- name: this.file.name,
621
- // TODO: Make optional in the SDK
622
- initial_reminder: 0,
623
- followup_reminders: 0,
624
- documents: [this.file],
625
- }, percent => {
626
- if (percent >= 99) {
627
- this.progressLabel = 'Processing...';
628
- this.progressPercent = 100;
629
- }
630
- else {
631
- this.progressPercent = percent;
632
- }
633
- });
634
- console.log('[CREATE] Created template', template);
635
- getTemplateStore(this.endpoint, template.id, true)
636
- .then(() => {
637
- var _a, _b;
638
- (_a = this.templateCreated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template, templateId: template.id });
639
- (_b = this.next) === null || _b === void 0 ? void 0 : _b.emit(template);
640
- this.creating = false;
641
- this.progressLabel = '';
642
- this.progressPercent = 0;
643
- })
644
- .catch(e => {
645
- console.log(e);
646
- });
647
- }
648
- catch (e) {
649
- console.log('[CREATE] Error creating template', e);
650
- (_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));
651
- this.creating = false;
652
- }
653
- }
654
- render() {
655
- if (!this.endpoint.session) {
656
- return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
657
- }
658
- return (h(Host, null, h("form", { onSubmit: e => e.preventDefault(), onClick: e => e.stopPropagation(), autocomplete: "off" }, h("input", { type: "file", id: "verdocs-template-create-file", multiple: true, accept: ".pdf,application/pdf,.doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", style: { display: 'none' }, onChange: e => this.handleFileChanged(e) }), this.creating ? (h("div", { class: "loader-wrapper" }, h("verdocs-loader", null), this.progressLabel && (h("div", { class: "progress-wrapper" }, h("verdocs-progress-bar", { showPercent: true, percent: this.progressPercent, label: this.progressLabel }))))) : (h("div", { class: "upload-box", onDrop: (e) => {
659
- e.preventDefault();
660
- e.target.classList.remove('drag-over');
661
- this.file = e.dataTransfer.files[0];
662
- if (this.file.size > this.maxSize) {
663
- this.errorMessage = 'Total file size must not exceed 20MB.';
664
- }
665
- }, onDragOver: (e) => {
666
- e.preventDefault();
667
- e.dataTransfer.dropEffect = 'copy';
668
- }, onDragEnter: (e) => e.target.classList.add('drag-over'), onDragLeave: (e) => e.target.classList.remove('drag-over') }, h("span", { innerHTML: FileIcon, style: { display: 'flex', justifyContent: 'center' } }), h("p", null, this.file ? this.file.name : 'Drag and drop your files here'), h("p", { class: "subscript" }, "Supported files: PDF, Word"), h("verdocs-button", { label: this.file ? 'Select a different file' : 'Select a file from your computer', size: "small", onClick: e => this.handleUpload(e) }))), !!this.errorMessage && h("div", { class: "error" }, this.errorMessage), h("div", { class: "buttons" }, h("verdocs-button", { variant: "outline", label: "Cancel", size: "small", onClick: e => this.handleCancel(e), disabled: this.creating }), h("verdocs-button", { label: "Next", size: "small", onClick: e => this.handleSubmit(e), disabled: !this.file || this.creating || !!this.errorMessage })))));
669
- }
670
- };
671
- VerdocsTemplateCreate.style = VerdocsTemplateCreateStyle0;
672
-
673
590
  const verdocsTemplateFieldsCss = "@-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-template-fields{font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif;position:relative;display:block;min-height:600px}verdocs-template-fields .page-0{padding:65px 15px 0 15px;-webkit-box-sizing:border-box;box-sizing:border-box}verdocs-template-fields .page-0 .user-placed-fields{height:100px;position:relative;background:#ffffff;-webkit-box-shadow:0 0 10px 5px rgba(0, 0, 0, 0.0588235294);box-shadow:0 0 10px 5px rgba(0, 0, 0, 0.0588235294)}verdocs-template-fields .page-0 .user-placed-fields .title{top:0;left:0;color:#ffffff;font-size:12px;padding:3px 6px;font-weight:bold;position:absolute;background:#46497d}verdocs-template-fields .pages{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-template-fields .pages div,verdocs-template-fields .pages canvas{-webkit-box-sizing:border-box;box-sizing:border-box}verdocs-template-fields #verdocs-template-fields-toolbar{height:50px;display:-ms-flexbox;display:flex;-webkit-column-gap:15px;-moz-column-gap:15px;column-gap:15px;font-weight:700;padding:0 20px 0 0;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row;color:#f5f5fa;-ms-flex-pack:center;justify-content:center;background:#46497d}verdocs-template-fields #verdocs-template-fields-toolbar>verdocs-select-input{margin:0}verdocs-template-fields #verdocs-template-fields-toolbar svg{width:24px;height:24px}verdocs-template-fields #verdocs-template-fields-toolbar .add-for{margin:0;font-weight:500;color:#f5f5fa}verdocs-template-fields #verdocs-template-fields-toolbar verdocs-select-input{margin:0 20px 0 0}@media all and (max-width: 1000px){verdocs-template-fields #verdocs-template-fields-toolbar{-webkit-column-gap:8px;-moz-column-gap:8px;column-gap:8px;padding:0 10px 0 0}verdocs-template-fields #verdocs-template-fields-toolbar svg{-webkit-transform:scale(0.8);transform:scale(0.8)}verdocs-template-fields #verdocs-template-fields-toolbar .add-for,verdocs-template-fields #verdocs-template-fields-toolbar verdocs-select-input{display:none}}@media all and (max-width: 600px){verdocs-template-fields #verdocs-template-fields-toolbar{-webkit-column-gap:6px;-moz-column-gap:6px;column-gap:6px}verdocs-template-fields #verdocs-template-fields-toolbar svg{-webkit-transform:scale(0.6);transform:scale(0.6)}verdocs-template-fields #verdocs-template-fields-toolbar .separator,verdocs-template-fields #verdocs-template-fields-toolbar .add-for,verdocs-template-fields #verdocs-template-fields-toolbar verdocs-select-input{display:none}}verdocs-template-fields.placing-attachment{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='m10.55 16.55 7.275-7.275L16.05 7.5l-5.5 5.45-2.675-2.65L6.1 12.075Zm-5.375 4.925q-1.125 0-1.887-.763-.763-.762-.763-1.887V5.175q0-1.125.763-1.888.762-.762 1.887-.762h13.65q1.125 0 1.888.762.762.763.762 1.888v13.65q0 1.125-.762 1.887-.763.763-1.888.763Zm0-2.65h13.65V5.175H5.175v13.65Zm0-13.65v13.65-13.65Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-checkbox{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='m10.55 16.55 7.275-7.275L16.05 7.5l-5.5 5.45-2.675-2.65L6.1 12.075Zm-5.375 4.925q-1.125 0-1.887-.763-.763-.762-.763-1.887V5.175q0-1.125.763-1.888.762-.762 1.887-.762h13.65q1.125 0 1.888.762.762.763.762 1.888v13.65q0 1.125-.762 1.887-.763.763-1.888.763Zm0-2.65h13.65V5.175H5.175v13.65Zm0-13.65v13.65-13.65Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-date{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath fill='%23000000' d='M7.6 13.925q-.55 0-.925-.375t-.375-.925q0-.55.375-.937.375-.388.925-.388t.925.388q.375.387.375.937t-.375.925q-.375.375-.925.375Zm4.4 0q-.55 0-.925-.375t-.375-.925q0-.55.375-.937.375-.388.925-.388t.925.388q.375.387.375.937t-.375.925q-.375.375-.925.375Zm4.4 0q-.55 0-.925-.375t-.375-.925q0-.55.375-.937.375-.388.925-.388t.925.388q.375.387.375.937t-.375.925q-.375.375-.925.375ZM5.3 22.85q-1.325 0-2.238-.912-.912-.913-.912-2.238V6.3q0-1.325.912-2.238.913-.912 2.238-.912H6v-2h2.575v2h6.85v-2H18v2h.7q1.325 0 2.238.912.912.913.912 2.238v13.4q0 1.325-.912 2.238-.913.912-2.238.912Zm0-3.15h13.4V10H5.3v9.7ZM5.3 8h13.4V6.3H5.3Zm0 0V6.3 8Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-dropdown{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24' stroke-width='1.5' stroke='currentColor'%3E%3Cpath stroke='%23000000' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5h14.25M3 9h9.75M3 13.5h9.75m4.5-4.5v12m0 0l-3.75-3.75M17.25 21L21 17.25' /%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-initial{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='M6.225 20.775V7h-5V3.225H15V7h-5v13.775Zm9.775 0v-8h-3V9h9.775v3.775h-3v8Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-payment{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='m10.55 16.55 7.275-7.275L16.05 7.5l-5.5 5.45-2.675-2.65L6.1 12.075Zm-5.375 4.925q-1.125 0-1.887-.763-.763-.762-.763-1.887V5.175q0-1.125.763-1.888.762-.762 1.887-.762h13.65q1.125 0 1.888.762.762.763.762 1.888v13.65q0 1.125-.762 1.887-.763.763-1.888.763Zm0-2.65h13.65V5.175H5.175v13.65Zm0-13.65v13.65-13.65Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-radio{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='M12 17q2.075 0 3.538-1.463Q17 14.075 17 12t-1.462-3.538Q14.075 7 12 7 9.925 7 8.463 8.462 7 9.925 7 12q0 2.075 1.463 3.537Q9.925 17 12 17Zm0 5.85q-2.275 0-4.25-.85t-3.438-2.312Q2.85 18.225 2 16.25q-.85-1.975-.85-4.25T2 7.75q.85-1.975 2.312-3.438Q5.775 2.85 7.75 2q1.975-.85 4.25-.85t4.25.85q1.975.85 3.438 2.312Q21.15 5.775 22 7.75q.85 1.975.85 4.25T22 16.25q-.85 1.975-2.312 3.438Q18.225 21.15 16.25 22q-1.975.85-4.25.85Zm0-3.15q3.25 0 5.475-2.225Q19.7 15.25 19.7 12q0-3.25-2.225-5.475Q15.25 4.3 12 4.3q-3.25 0-5.475 2.225Q4.3 8.75 4.3 12q0 3.25 2.225 5.475Q8.75 19.7 12 19.7Zm0-7.7Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-signature{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='m9.225 21.225 4.65-4.65h8.45v4.65Zm-5.35-2.2H5.05l8.5-8.5-1.175-1.175-8.5 8.5Zm14.25-9.95L13.8 4.8l1.325-1.325q.625-.65 1.525-.663.9-.012 1.6.663l1.225 1.175q.675.675.663 1.562-.013.888-.663 1.513ZM16.7 10.55 6 21.225H1.675V16.9L12.35 6.225Zm-3.725-.625-.6-.575 1.175 1.175Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-textarea{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath d='M3.225 20.725v-3.15h11.55v3.15Zm0-4.775V12.8h17.55v3.15Zm0-4.75V8.05h17.55v3.15Zm0-4.775v-3.15h17.55v3.15Z'/%3E%3C/svg%3E\") 16 16, pointer}verdocs-template-fields.placing-textbox{cursor:url(\"data:image/svg+xml,%3Csvg width='32' height='15' viewBox='0 0 32 15' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cmask id='path-1-inside-1_1401_24' fill='white'%3E%3Cpath d='M0 0H32V15H0V0Z'/%3E%3C/mask%3E%3Cpath d='M0 0H32V15H0V0Z' fill='%234C56CB' fill-opacity='0.1'/%3E%3Cpath d='M0 0V-1H-1V0H0ZM0 15H-1V16H0V15ZM0 1H32V-1H0V1ZM32 14H0V16H32V14ZM1 15V0H-1V15H1Z' fill='%234C56CB' mask='url(%23path-1-inside-1_1401_24)'/%3E%3Cpath d='M3 11.8V8.65H14.15V11.8H3ZM3 6.65V3.5H20.15V6.65H3Z' fill='%234C56CB'/%3E%3Cline x1='31.5' y1='1' x2='31.5' y2='14' stroke='%234C56CB' stroke-opacity='0.32' stroke-dasharray='1 1'/%3E%3C/svg%3E%0A\") 0 14, pointer}verdocs-template-fields.placing-timestamp{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' width='24'%3E%3Cpath fill='%23000000' d='M9 1h6v2H9zm10.03 6.39 1.42-1.42c-.43-.51-.9-.99-1.41-1.41l-1.42 1.42C16.07 4.74 14.12 4 12 4c-4.97 0-9 4.03-9 9s4.02 9 9 9 9-4.03 9-9c0-2.12-.74-4.07-1.97-5.61zM13 14h-2V8h2v6z'%3E%3C/path%3E%3C/svg%3E\") 16 16, pointer}";
674
591
  const VerdocsTemplateFieldsStyle0 = verdocsTemplateFieldsCss;
675
592
 
@@ -704,10 +621,8 @@ const VerdocsTemplateFields = class {
704
621
  this.sdkError = createEvent(this, "sdkError", 7);
705
622
  this.templateUpdated = createEvent(this, "templateUpdated", 7);
706
623
  this.fieldsUpdated = createEvent(this, "fieldsUpdated", 7);
624
+ this.templateListenerId = null;
707
625
  this.pageHeights = {};
708
- this.templateStore = null;
709
- this.fieldStore = null;
710
- this.roleStore = null;
711
626
  this.cachedPageInfo = {};
712
627
  this.endpoint = VerdocsEndpoint.getDefault();
713
628
  this.templateId = null;
@@ -716,9 +631,10 @@ const VerdocsTemplateFields = class {
716
631
  this.showMustSelectRole = false;
717
632
  this.selectedRoleName = '';
718
633
  this.loading = true;
634
+ this.template = null;
719
635
  }
720
- onTemplateIdChanged(newTemplateId) {
721
- this.loadTemplate(newTemplateId).catch((e) => console.log('Unknown Error', e));
636
+ onTemplateIdChanged() {
637
+ this.listenToTemplate();
722
638
  }
723
639
  // Stop field-placement mode if ESC is pressed
724
640
  handleKeyDown(ev) {
@@ -727,7 +643,7 @@ const VerdocsTemplateFields = class {
727
643
  }
728
644
  }
729
645
  async componentWillLoad() {
730
- var _a, _b, _c, _d, _e, _f;
646
+ var _a, _b, _c;
731
647
  try {
732
648
  this.endpoint.loadSession();
733
649
  if (!this.templateId) {
@@ -738,17 +654,11 @@ const VerdocsTemplateFields = class {
738
654
  console.log('[FIELDS] Unable to start builder session, must be authenticated');
739
655
  return;
740
656
  }
741
- try {
742
- this.loadTemplate(this.templateId).catch(e => console.log('[BUILD] Unable to load template', e));
743
- }
744
- catch (e) {
745
- console.log('[FIELDS] Error loading template', e);
746
- (_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));
747
- }
657
+ this.listenToTemplate();
748
658
  }
749
659
  catch (e) {
750
660
  console.log('[FIELDS] Error with fields session', e);
751
- (_d = this.sdkError) === null || _d === void 0 ? void 0 : _d.emit(new SDKError(e.message, (_e = e.response) === null || _e === void 0 ? void 0 : _e.status, (_f = e.response) === null || _f === void 0 ? void 0 : _f.data));
661
+ (_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));
752
662
  }
753
663
  }
754
664
  componentDidRender() {
@@ -764,35 +674,40 @@ const VerdocsTemplateFields = class {
764
674
  componentWillUpdate() {
765
675
  var _a, _b;
766
676
  // If a new role was added and there were none yet so far, or the "selected" role was deleted, reset our selection
767
- const roles = ((_a = this.roleStore) === null || _a === void 0 ? void 0 : _a.get('roles')) || [];
677
+ const roles = ((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || [];
768
678
  if (!this.selectedRoleName || !roles.find(role => role && role.name === this.selectedRoleName)) {
769
679
  this.selectedRoleName = ((_b = roles[0]) === null || _b === void 0 ? void 0 : _b.name) || '';
770
680
  console.log('[FIELDS] Selected new role', this.selectedRoleName);
771
681
  }
772
682
  }
773
- async loadTemplate(templateId) {
774
- var _a, _b;
775
- if (templateId) {
776
- this.loading = true;
777
- this.templateStore = await getTemplateStore(this.endpoint, templateId, false);
778
- this.roleStore = getTemplateRoleStore(this.templateId);
779
- this.fieldStore = getTemplateFieldStore(this.templateId);
780
- this.selectedRoleName = ((_b = (_a = this.roleStore.get('roles')) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.name) || '';
683
+ disconnectedCallback() {
684
+ this.unlistenToTemplate();
685
+ }
686
+ async listenToTemplate() {
687
+ this.unlistenToTemplate();
688
+ Store.subscribe('templates', this.templateId, () => getTemplate(this.endpoint, this.templateId), false, (template) => {
689
+ var _a, _b;
690
+ this.template = template;
781
691
  this.loading = false;
782
- // TODO: Necessary?
783
- // this.fieldsUpdated?.emit({event: 'updated', endpoint: this.endpoint, templateId: this.templateId, fields});
692
+ this.selectedRoleName = ((_b = (_a = template.roles) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.name) || '';
693
+ });
694
+ }
695
+ unlistenToTemplate() {
696
+ if (this.templateListenerId) {
697
+ Store.store.delListener(this.templateListenerId);
698
+ this.templateListenerId = null;
784
699
  }
785
700
  }
786
701
  attachFieldAttributes(pageInfo, field, el) {
787
702
  // el.addEventListener('input', e => this.handleFieldChange(field, e));
788
703
  el.addEventListener('settingsChanged', () => {
789
- var _a, _b;
790
- (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: (_b = this.templateStore) === null || _b === void 0 ? void 0 : _b.state, event: 'added-field' });
704
+ var _a;
705
+ (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: this.template, event: 'added-field' });
791
706
  });
792
707
  el.addEventListener('deleted', () => {
793
- var _a, _b;
708
+ var _a;
794
709
  el.remove();
795
- (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: (_b = this.templateStore) === null || _b === void 0 ? void 0 : _b.state, event: 'updated-field' });
710
+ (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: this.template, event: 'updated-field' });
796
711
  });
797
712
  el.setAttribute('templateid', this.templateId);
798
713
  el.setAttribute('fieldname', field.name);
@@ -802,12 +717,12 @@ const VerdocsTemplateFields = class {
802
717
  el.setAttribute('name', field.name);
803
718
  }
804
719
  handlePageRendered(e) {
720
+ var _a;
805
721
  const pageInfo = e.detail;
806
722
  // console.log('[FIELDS] Page rendered', pageInfo.pageNumber, pageInfo.xScale, pageInfo.yScale);
807
723
  this.cachedPageInfo[pageInfo.pageNumber] = pageInfo;
808
724
  this.pageHeights[pageInfo.pageNumber] = pageInfo.naturalHeight;
809
- this.fieldStore
810
- .get('fields')
725
+ (((_a = this.template) === null || _a === void 0 ? void 0 : _a.fields) || [])
811
726
  .filter(field => field && field.page === pageInfo.pageNumber)
812
727
  .forEach(field => {
813
728
  const id = getFieldId(field);
@@ -839,10 +754,9 @@ const VerdocsTemplateFields = class {
839
754
  updateCssTransform(event.target, 'translate', `${newX}px, ${newY}px`);
840
755
  }
841
756
  async handleMoveEnd(event) {
842
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
757
+ var _a, _b, _c, _d, _e, _f, _g, _h;
843
758
  const name = event.target.getAttribute('fieldname');
844
- const option = +(event.target.getAttribute('option') || '0');
845
- const field = this.fieldStore.get('fields').find(field => field.name === name);
759
+ const field = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.fields) || []).find(field => field.name === name);
846
760
  if (!field) {
847
761
  console.log('[FIELDS] Unable to find field', name, event.target);
848
762
  return;
@@ -858,10 +772,9 @@ const VerdocsTemplateFields = class {
858
772
  // (positive displacement) while bottom measures "up" from the bottom (negative displacement).
859
773
  const newX = Math.max(clientRect.left - parentRect.left, 0);
860
774
  let newY = Math.max(renderedHeight - (parentRect.bottom - clientRect.bottom), 0);
861
- console.log('drop', { pageNumber, newX, newY });
862
775
  let newPageNumber = parseInt(pageNumber);
863
776
  if (newY > renderedHeight) {
864
- newPageNumber = Math.min(newPageNumber + 1, ((_d = (_c = (_b = (_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.documents) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.pages) || 1);
777
+ newPageNumber = Math.min(newPageNumber + 1, ((_d = (_c = (((_b = this.template) === null || _b === void 0 ? void 0 : _b.documents) || [])) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.pages) || 1);
865
778
  newY -= renderedHeight;
866
779
  renderedHeight = this.cachedPageInfo[newPageNumber].renderedHeight;
867
780
  console.log('Next page', { newPageNumber, newY, renderedHeight });
@@ -870,38 +783,43 @@ const VerdocsTemplateFields = class {
870
783
  newPageNumber = Math.max(newPageNumber - 1, 1);
871
784
  renderedHeight = this.cachedPageInfo[newPageNumber].renderedHeight;
872
785
  newY += renderedHeight;
873
- console.log('Next page', { newPageNumber, newY, renderedHeight });
786
+ console.log('[FIELDS] Next page', { newPageNumber, newY, renderedHeight });
874
787
  }
875
788
  const { x, y } = this.viewCoordinatesToPageCoordinates(newX, newY, pageNumber, naturalWidth - width, naturalHeight - height);
876
789
  try {
877
790
  const params = { x, y, page: newPageNumber };
878
- console.log('[FIELDS] Will update', name, y, option, params);
879
- const newFieldData = await updateField(this.endpoint, this.templateId, name, params);
880
- console.log('[FIELDS] Updated', newFieldData);
881
- updateStoreField(this.fieldStore, name, newFieldData);
791
+ const updatedField = await updateField(this.endpoint, this.templateId, name, params);
792
+ console.log('[FIELDS] Updated', updatedField);
793
+ const newTemplate = JSON.parse(JSON.stringify(this.template));
794
+ const fieldIndex = newTemplate.fields.findIndex(field => field.name === name);
795
+ if (fieldIndex > -1) {
796
+ newTemplate.fields[fieldIndex] = updatedField;
797
+ }
798
+ Store.updateTemplate(this.templateId, newTemplate);
882
799
  event.target.removeAttribute('posX');
883
800
  event.target.removeAttribute('posY');
884
801
  removeCssTransform(event.target);
885
802
  const { xScale = 1, yScale = 1 } = this.cachedPageInfo[pageNumber];
886
- setControlStyles(event.target, newFieldData, xScale, yScale);
887
- (_e = this.templateUpdated) === null || _e === void 0 ? void 0 : _e.emit({ endpoint: this.endpoint, template: (_f = this.templateStore) === null || _f === void 0 ? void 0 : _f.state, event: 'updated-field' });
803
+ setControlStyles(event.target, updatedField, xScale, yScale);
804
+ (_e = this.templateUpdated) === null || _e === void 0 ? void 0 : _e.emit({ endpoint: this.endpoint, template: newTemplate, event: 'updated-field' });
888
805
  }
889
806
  catch (e) {
890
807
  VerdocsToast('Error updating field, please try again later', { style: 'error' });
891
808
  console.log('[FIELDS] Error updating field', e);
892
- (_g = this.sdkError) === null || _g === void 0 ? void 0 : _g.emit(new SDKError(e.message, (_h = e.response) === null || _h === void 0 ? void 0 : _h.status, (_j = e.response) === null || _j === void 0 ? void 0 : _j.data));
809
+ (_f = this.sdkError) === null || _f === void 0 ? void 0 : _f.emit(new SDKError(e.message, (_g = e.response) === null || _g === void 0 ? void 0 : _g.status, (_h = e.response) === null || _h === void 0 ? void 0 : _h.data));
893
810
  event.target.removeAttribute('posX');
894
811
  event.target.removeAttribute('posY');
895
812
  removeCssTransform(event.target);
896
813
  }
897
814
  }
898
815
  generateFieldName(type, pageNumber) {
816
+ var _a;
899
817
  let i = 1;
900
818
  let fieldName;
901
819
  do {
902
820
  fieldName = `${type}P${pageNumber}-${i}`;
903
821
  i++;
904
- } while (this.fieldStore.get('fields').some(field => field && field.name === fieldName));
822
+ } while ((((_a = this.template) === null || _a === void 0 ? void 0 : _a.fields) || []).some(field => field && field.name === fieldName));
905
823
  return fieldName;
906
824
  }
907
825
  // Scale the X,Y clicks to the virtual page dimensions. Also ensure the field doesn't go off the page.
@@ -912,7 +830,7 @@ const VerdocsTemplateFields = class {
912
830
  return { x, y };
913
831
  }
914
832
  async handleClickPage(e, pageNumber) {
915
- var _a, _b;
833
+ var _a;
916
834
  if (this.placing) {
917
835
  const clickedX = e.offsetX;
918
836
  const clickedY = e.offsetY;
@@ -945,22 +863,24 @@ const VerdocsTemplateFields = class {
945
863
  options: this.placing === 'radio' ? [{ id: 'option-1', label: 'Option 1' }] : [],
946
864
  };
947
865
  console.log('[FIELDS] Will save new field', field);
948
- const saved = await createField(this.endpoint, this.templateId, field);
949
- console.log('[FIELDS] Saved field', saved);
950
- this.fieldStore.set('fields', [...this.fieldStore.get('fields'), saved]);
866
+ const newField = await createField(this.endpoint, this.templateId, field);
867
+ console.log('[FIELDS] Saved field', newField);
868
+ const newTemplate = JSON.parse(JSON.stringify(this.template));
869
+ newTemplate.fields.push(newField);
870
+ Store.updateTemplate(this.templateId, newTemplate);
871
+ (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: newTemplate, event: 'added-field' });
951
872
  this.placing = null;
952
- (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: (_b = this.templateStore) === null || _b === void 0 ? void 0 : _b.state, event: 'added-field' });
953
873
  }
954
874
  }
955
875
  render() {
956
876
  var _a, _b, _c;
877
+ if (this.loading) {
878
+ return (h(Host, null, h("verdocs-loader", null)));
879
+ }
957
880
  if (!this.endpoint.session) {
958
881
  return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
959
882
  }
960
- if (this.loading || !((_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state.isLoaded)) {
961
- return (h(Host, null, h("verdocs-loader", null)));
962
- }
963
- const selectableRoles = this.roleStore.get('roles').map(role => ({ value: role.name, label: role.full_name ? `${role.name}: ${role.full_name}` : role.name }));
883
+ const selectableRoles = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || []).map(role => ({ value: role.name, label: role.full_name ? `${role.name}: ${role.full_name}` : role.name }));
964
884
  return (h(Host, { class: this.placing ? { [`placing-${this.placing}`]: true } : {}, onSubmit: () => { } }, h("div", { id: "verdocs-template-fields-toolbar" }, h("div", { class: "add-for" }, "Add field:"), h("verdocs-select-input", { value: this.selectedRoleName, options: selectableRoles, onInput: (e) => (this.selectedRoleName = e.target.value) }), menuOptions.map(option => (h("verdocs-toolbar-icon", { text: option.tooltip, icon: option.icon, class: option.class, onClick: () => {
965
885
  // We ignore empty-tooltip entries because they're separators
966
886
  if (option.tooltip) {
@@ -972,7 +892,7 @@ const VerdocsTemplateFields = class {
972
892
  this.showMustSelectRole = true;
973
893
  }
974
894
  }
975
- } })))), h("div", { class: "pages" }, (((_c = (_b = this.templateStore) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.documents) || []).map(document => {
895
+ } })))), h("div", { class: "pages" }, (((_b = this.template) === null || _b === void 0 ? void 0 : _b.documents) || []).map(document => {
976
896
  const pageNumbers = integerSequence(1, document.pages);
977
897
  return pageNumbers.map(page => {
978
898
  const pageSize = document.page_sizes[page];
@@ -981,7 +901,7 @@ const VerdocsTemplateFields = class {
981
901
  { name: 'controls', type: 'div' },
982
902
  ] }));
983
903
  });
984
- })), this.showMustSelectRole && (h("verdocs-ok-dialog", { heading: "Unable to add field", message: this.roleStore.get('roles').length > 0 ? 'Please select a role before adding fields.' : 'Please add at least one role before adding fields.', onNext: () => (this.showMustSelectRole = false) }))));
904
+ })), this.showMustSelectRole && (h("verdocs-ok-dialog", { heading: "Unable to add field", message: (((_c = this.template) === null || _c === void 0 ? void 0 : _c.roles) || []).length > 0 ? 'Please select a role before adding fields.' : 'Please add at least one role before adding fields.', onNext: () => (this.showMustSelectRole = false) }))));
985
905
  }
986
906
  static get watchers() { return {
987
907
  "templateId": ["onTemplateIdChanged"]
@@ -989,85 +909,13 @@ const VerdocsTemplateFields = class {
989
909
  };
990
910
  VerdocsTemplateFields.style = VerdocsTemplateFieldsStyle0;
991
911
 
992
- const verdocsTemplateNameCss = "";
993
- const VerdocsTemplateNameStyle0 = verdocsTemplateNameCss;
994
-
995
- const VerdocsTemplateName = class {
996
- constructor(hostRef) {
997
- registerInstance(this, hostRef);
998
- this.close = createEvent(this, "close", 7);
999
- this.sdkError = createEvent(this, "sdkError", 7);
1000
- this.templateUpdated = createEvent(this, "templateUpdated", 7);
1001
- this.store = null;
1002
- this.endpoint = VerdocsEndpoint.getDefault();
1003
- this.templateId = '';
1004
- this.name = '';
1005
- this.dirty = false;
1006
- }
1007
- async componentWillLoad() {
1008
- var _a, _b, _c, _d, _e;
1009
- try {
1010
- this.endpoint.loadSession();
1011
- if (!this.templateId) {
1012
- console.log(`[ROLES] Missing required template ID ${this.templateId}`);
1013
- return;
1014
- }
1015
- if (!this.endpoint.session) {
1016
- console.log('[ROLES] Unable to start builder session, must be authenticated');
1017
- return;
1018
- }
1019
- this.store = await getTemplateStore(this.endpoint, this.templateId, false);
1020
- this.name = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.name;
1021
- this.dirty = false;
1022
- }
1023
- catch (e) {
1024
- console.log('[TEMPLATE NAME] Error loading template', e);
1025
- (_c = this.sdkError) === null || _c === void 0 ? void 0 : _c.emit(new SDKError(e.message, (_d = e.response) === null || _d === void 0 ? void 0 : _d.status, (_e = e.response) === null || _e === void 0 ? void 0 : _e.data));
1026
- }
1027
- }
1028
- handleCancel(e) {
1029
- var _a, _b, _c;
1030
- e.stopPropagation();
1031
- this.name = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.name;
1032
- this.dirty = false;
1033
- console.log('Closing');
1034
- (_c = this.close) === null || _c === void 0 ? void 0 : _c.emit();
1035
- }
1036
- async handleSave(e) {
1037
- var _a, _b, _c;
1038
- e.stopPropagation();
1039
- await updateTemplate(this.endpoint, this.templateId, { name: this.name });
1040
- if ((_a = this.store) === null || _a === void 0 ? void 0 : _a.state) {
1041
- this.store.state.name = this.name;
1042
- }
1043
- this.dirty = false;
1044
- (_b = this.templateUpdated) === null || _b === void 0 ? void 0 : _b.emit({ endpoint: this.endpoint, template: this.store.state, event: 'name' });
1045
- (_c = this.close) === null || _c === void 0 ? void 0 : _c.emit();
1046
- }
1047
- render() {
1048
- var _a, _b;
1049
- if (!this.endpoint.session) {
1050
- return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
1051
- }
1052
- if ((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.isLoading) {
1053
- return (h(Host, { class: "loading" }, h("verdocs-loader", null)));
1054
- }
1055
- return (h(Host, null, h("form", { onSubmit: e => e.preventDefault(), onClick: e => e.stopPropagation(), autocomplete: "off" }, h("label", { htmlFor: "verdocs-template-name" }, "Template Name"), h("verdocs-text-input", { id: "verdocs-template-name", value: this.name, autocomplete: "off", placeholder: "Template Name...", onInput: (e) => {
1056
- var _a, _b;
1057
- this.name = e.target.value;
1058
- this.dirty = this.name !== ((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.name);
1059
- } }), h("div", { class: "buttons" }, h("verdocs-button", { size: "small", variant: "outline", label: "Cancel", disabled: !this.dirty, onClick: e => this.handleCancel(e) }), h("verdocs-button", { size: "small", label: "Save", disabled: !this.dirty, onClick: e => this.handleSave(e) })))));
1060
- }
1061
- };
1062
- VerdocsTemplateName.style = VerdocsTemplateNameStyle0;
1063
-
1064
912
  const verdocsTemplateRolesCss = "@-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-template-roles{display:block;min-width:400px;font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif}verdocs-template-roles>form{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;background-color:#ffffff;padding:12px}verdocs-template-roles>form h5{font-size:16px;font-weight:bold;color:#46497d;margin:0 0 10px 0}verdocs-template-roles>form .participants{position:relative}verdocs-template-roles>form .left-line{top:32px;left:11px;z-index:1;width:12px;bottom:30px;position:absolute;background:#ffffff;border-left:3px dotted #9b9b9b}verdocs-template-roles>form .row{display:-ms-flexbox;display:flex;-webkit-column-gap:0;-moz-column-gap:0;column-gap:0;min-height:35px;margin-top:0;margin-left:40px;position:relative;-ms-flex-direction:row;flex-direction:row;padding:6px 0 4px 0}verdocs-template-roles>form .row .row-roles{-ms-flex:1;flex:1;gap:10px;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-direction:row;flex-direction:row}verdocs-template-roles>form .row .icon{top:14px;z-index:2;left:-40px;width:24px;height:24px;position:absolute;background:#ffffff}verdocs-template-roles>form .row .sender{height:30px;display:-ms-flexbox;display:flex;font-size:14px;line-height:30px;-ms-flex-align:center;align-items:center;border-radius:30px;-ms-flex-direction:row;flex-direction:row;padding:0 15px 0 15px;border:1px solid #c6c9cc;background-color:#f5f5fa}verdocs-template-roles>form .row .complete{height:30px;display:-ms-flexbox;display:flex;font-size:14px;padding:0 15px;line-height:30px;-ms-flex-direction:row;flex-direction:row;border-radius:30px;background-color:#f5f5fa;border:1px solid #aeb4bf}verdocs-template-roles>form .row .label{font-weight:bold;margin-right:6px;color:#33364b}verdocs-template-roles>form .row .settings-button{display:-ms-flexbox;display:flex;cursor:pointer;margin:0 0 0 9px}verdocs-template-roles>form .row .recipient{height:30px;display:-ms-flexbox;display:flex;font-size:14px;border-radius:30px;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row;padding:0 5px 0 6px;white-space:nowrap;border:2px solid #aeb4bf}verdocs-template-roles>form .row .recipient .type-icon{width:24px;height:24px;-webkit-transform:scale(0.8);transform:scale(0.8);opacity:0.6;margin:0 12px 0 0}verdocs-template-roles>form .row .recipient.dragging{position:absolute}verdocs-template-roles>form .row .recipient.dragging+.dropzone{display:none !important}verdocs-template-roles>form .row .dropzone{width:14px;height:30px;display:none}verdocs-template-roles>form .row .dropzone svg{fill:#cccccc}verdocs-template-roles>form .row .dropzone.visible{margin:0 7px;display:-ms-flexbox;display:flex;-ms-flex:0 0 14px;flex:0 0 14px}verdocs-template-roles>form .row .dropzone.active{-ms-flex:0 0 120px;flex:0 0 120px;border-radius:30px;background:rgba(101, 77, 203, 0.4980392157);border:1px dashed #654dcb}verdocs-template-roles>form label{display:block;font-size:14px;font-weight:500;margin:0 0 4px 0;color:#5c6575}verdocs-template-roles>form input{border:none;font-size:18px;padding:3px 6px 3px 0;background:transparent;border-bottom:1px solid #33364b}verdocs-template-roles>form input:focus{outline:none}verdocs-template-roles .row.add-sequence{display:none}verdocs-template-roles .add-role{margin:0;padding:0;border:none;opacity:0.5;cursor:pointer;background:none}verdocs-template-roles .add-role:hover{opacity:1}verdocs-template-roles .add-role svg{width:32px;height:32px}verdocs-template-roles .add-step{margin:0;padding:0;border:none;opacity:0.5;cursor:pointer;background:none}verdocs-template-roles .add-step:hover{opacity:1}verdocs-template-roles .add-step svg{width:32px;height:32px}verdocs-template-roles.dragging .add-role{display:none}verdocs-template-roles.dragging form .row .recipient+.dropzone{display:-ms-flexbox;display:flex}verdocs-template-roles.dragging .row.add-sequence{display:-ms-flexbox;display:flex}verdocs-template-roles.dragging .row.add-sequence .dropzone{opacity:0.5;-ms-flex:0 0 120px;flex:0 0 120px;border-radius:30px;-ms-flex-align:center;align-items:center;background:rgba(101, 77, 203, 0.4980392157);-ms-flex-pack:center;justify-content:center;border:1px dashed #654dcb}verdocs-template-roles.dragging .row.add-sequence .dropzone.active{opacity:1}verdocs-template-roles .buttons{display:-ms-flexbox;display:flex;-webkit-column-gap:8px;-moz-column-gap:8px;column-gap:8px;margin-top:16px;-ms-flex-direction:row;flex-direction:row}verdocs-template-roles .empty{font-size:13px;margin-top:15px;margin-bottom:5px}verdocs-template-roles .empty svg{width:16px;height:16px;stroke:#666666;margin-bottom:2px;display:inline-block}verdocs-template-roles ::-webkit-input-placeholder{color:#aaaaaa}verdocs-template-roles ::-moz-placeholder{color:#aaaaaa}verdocs-template-roles :-ms-input-placeholder{color:#aaaaaa}verdocs-template-roles ::-ms-input-placeholder{color:#aaaaaa}verdocs-template-roles ::placeholder{color:#aaaaaa}";
1065
913
  const VerdocsTemplateRolesStyle0 = verdocsTemplateRolesCss;
1066
914
 
1067
- const senderLabels = {
1068
- template_owner: 'Template Owner',
1069
- envelope_creator: 'Envelope Creator',
1070
- };
915
+ // const senderLabels: Record<TTemplateSender, string> = {
916
+ // template_owner: 'Template Owner',
917
+ // envelope_creator: 'Envelope Creator',
918
+ // };
1071
919
  const settingsIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" fill="#00000089"><path d="m8.021 17.917-.313-2.5q-.27-.125-.625-.334-.354-.208-.625-.395l-2.312.979-1.979-3.438 1.979-1.5q-.021-.167-.031-.364-.011-.198-.011-.365 0-.146.011-.344.01-.198.031-.385l-1.979-1.5 1.979-3.417 2.312.958q.271-.187.615-.385t.635-.344l.313-2.5h3.958l.313 2.5q.312.167.625.344.312.177.604.385l2.333-.958 1.979 3.417-1.979 1.521q.021.187.021.364V10q0 .146-.01.333-.011.188-.011.396l1.958 1.5-1.979 3.438-2.312-.979q-.292.208-.615.395-.323.188-.614.334l-.313 2.5Zm1.937-5.355q1.063 0 1.813-.75t.75-1.812q0-1.062-.75-1.812t-1.813-.75q-1.041 0-1.802.75-.76.75-.76 1.812t.76 1.812q.761.75 1.802.75Zm0-1.333q-.5 0-.864-.364-.365-.365-.365-.865t.365-.865q.364-.364.864-.364t.865.364q.365.365.365.865t-.365.865q-.365.364-.865.364ZM10.021 10Zm-.854 6.583h1.666l.25-2.187q.605-.167 1.136-.49.531-.323 1.031-.802l2.021.875.854-1.375-1.792-1.354q.105-.333.136-.635.031-.303.031-.615 0-.292-.031-.573-.031-.281-.115-.635l1.792-1.396-.834-1.375-2.062.875q-.438-.438-1.021-.781-.583-.344-1.125-.49l-.271-2.208H9.167l-.271 2.208q-.584.146-1.125.458-.542.313-1.042.792l-2.021-.854-.833 1.375 1.75 1.354q-.083.333-.125.646-.042.312-.042.604t.042.594q.042.302.125.635l-1.75 1.375.833 1.375 2.021-.854q.479.458 1.021.771.542.312 1.146.479Z"/></svg>';
1072
920
  const startIcon = '<svg focusable="false" aria-hidden="true" viewBox="0 0 24 24" fill="#00000089"><path d="M2 12C2 6.48 6.48 2 12 2s10 4.48 10 10-4.48 10-10 10S2 17.52 2 12zm10 6c3.31 0 6-2.69 6-6s-2.69-6-6-6-6 2.69-6 6 2.69 6 6 6z"></path></svg>';
1073
921
  const stepIcon = '<svg focusable="false" aria-hidden="true" viewBox="0 0 24 24" fill="#00000089"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"></path></svg>';
@@ -1083,13 +931,31 @@ const VerdocsTemplateRoles = class {
1083
931
  this.exit = createEvent(this, "exit", 7);
1084
932
  this.sdkError = createEvent(this, "sdkError", 7);
1085
933
  this.rolesUpdated = createEvent(this, "rolesUpdated", 7);
1086
- this.templateStore = null;
1087
- this.roleStore = null;
934
+ this.templateListenerId = null;
1088
935
  this.endpoint = VerdocsEndpoint.getDefault();
1089
936
  this.templateId = '';
1090
937
  this.showingRoleDialog = null;
1091
938
  this.sender = null;
1092
939
  this.loading = true;
940
+ this.template = null;
941
+ }
942
+ disconnectedCallback() {
943
+ this.unlistenToTemplate();
944
+ }
945
+ async listenToTemplate() {
946
+ console.log('[ROLES] Loading template', this.templateId);
947
+ this.unlistenToTemplate();
948
+ Store.subscribe('templates', this.templateId, () => getTemplate(this.endpoint, this.templateId), false, (template) => {
949
+ console.log('[BUILD] Template Updated', template);
950
+ this.template = template;
951
+ this.loading = false;
952
+ });
953
+ }
954
+ unlistenToTemplate() {
955
+ if (this.templateListenerId) {
956
+ Store.store.delListener(this.templateListenerId);
957
+ this.templateListenerId = null;
958
+ }
1093
959
  }
1094
960
  async componentWillLoad() {
1095
961
  var _a, _b, _c;
@@ -1103,18 +969,7 @@ const VerdocsTemplateRoles = class {
1103
969
  console.log('[ROLES] Unable to start builder session, must be authenticated');
1104
970
  return;
1105
971
  }
1106
- await getTemplateStore(this.endpoint, this.templateId, false)
1107
- .then(ts => {
1108
- this.templateStore = ts;
1109
- this.roleStore = getTemplateRoleStore(this.templateId);
1110
- this.loading = false;
1111
- this.roleStore.onChange('roles', roles => {
1112
- var _a;
1113
- console.log('[ROLES] Roles changed', { roles });
1114
- (_a = this.rolesUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'updated', endpoint: this.endpoint, templateId: this.templateId, roles });
1115
- });
1116
- })
1117
- .catch(e => console.warn(e));
972
+ this.listenToTemplate();
1118
973
  }
1119
974
  catch (e) {
1120
975
  console.log('[FIELDS] Error with preview session', e);
@@ -1158,12 +1013,8 @@ const VerdocsTemplateRoles = class {
1158
1013
  overlap: 0.05,
1159
1014
  ondrop: async function onDrop(event) {
1160
1015
  var _a;
1161
- console.log('dropped', event.target.classList);
1162
1016
  event.target.classList.remove('active');
1163
- const roleName = event.relatedTarget.dataset.rolename;
1164
- const targetSequence = +event.target.dataset.sequence;
1165
- const targetOrder = +event.target.dataset.order;
1166
- updateStoreRole(this.roleStore, roleName, { sequence: targetSequence, order: targetOrder });
1017
+ // This will re-sort the roles and renumbers them via server calls if necessary
1167
1018
  await this.renumberTemplateRoles();
1168
1019
  console.log('[ROLES] Updated roles', this.getSortedRoles());
1169
1020
  (_a = this.rolesUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'updated', endpoint: this.endpoint, templateId: this.templateId, roles: this.getSortedRoles() });
@@ -1191,7 +1042,10 @@ const VerdocsTemplateRoles = class {
1191
1042
  (_a = this.next) === null || _a === void 0 ? void 0 : _a.emit();
1192
1043
  }
1193
1044
  getSortedRoles() {
1194
- return this.roleStore.state.roles.sort((a, b) => {
1045
+ var _a;
1046
+ // NOTE: This mutates the source array but that's OK because everything that touches
1047
+ // it will want the same thing done.
1048
+ return (((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || []).sort((a, b) => {
1195
1049
  return a.sequence === b.sequence ? a.order - b.order : a.sequence - b.sequence;
1196
1050
  });
1197
1051
  }
@@ -1209,14 +1063,15 @@ const VerdocsTemplateRoles = class {
1209
1063
  return roles.map(role => role.name);
1210
1064
  }
1211
1065
  getRolesAtSequence(sequence) {
1066
+ var _a;
1212
1067
  // Entries can be undefined when deleted because Stencil has no remove() operator yet for stores.
1213
1068
  // See https://github.com/ionic-team/stencil-store/issues/23
1214
- return this.roleStore.state.roles.filter(role => role && role.sequence === sequence);
1069
+ return (((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || []).filter(role => role && role.sequence === sequence);
1215
1070
  }
1216
1071
  // When the user drags a role around, we handle placement "between" items by assigning it a half-order number
1217
1072
  // e.g. 1.5 to place it between items 1 and 2, 0.5 to place it at the beginning, or last+0.5 to place it at the end.
1218
1073
  // Then we re-sort the list of roles and renumber them.
1219
- renumberTemplateRoles() {
1074
+ async renumberTemplateRoles() {
1220
1075
  // console.log('Renumbering roles', this.getSequenceNumbers(), JSON.stringify(this.roleStore.state));
1221
1076
  // Avoid dupe renumber attempts
1222
1077
  const renumbered = [];
@@ -1229,24 +1084,30 @@ const VerdocsTemplateRoles = class {
1229
1084
  role.sequence = newSequenceIndex + 1;
1230
1085
  role.order = newOrderIndex + 1;
1231
1086
  renumbered.push(role.name);
1232
- renumberRequests.push(updateTemplateRole(this.endpoint, this.templateId, role.name, {
1233
- sequence: role.sequence,
1234
- order: role.order,
1235
- }));
1087
+ renumberRequests.push(updateTemplateRole(this.endpoint, this.templateId, role.name, { sequence: role.sequence, order: role.order }));
1236
1088
  }
1237
1089
  }
1238
1090
  });
1239
1091
  });
1240
- return Promise.all(renumberRequests);
1092
+ if (renumberRequests.length > 0) {
1093
+ console.log(`[ROLES] Submitting ${renumberRequests.length} renumber requests`);
1094
+ return Promise.all(renumberRequests).then(async () => {
1095
+ // When renumbering, we don't try to update the store for every individual item
1096
+ // changing. We just do it once at the end.
1097
+ this.template = await Store.getTemplate(this.endpoint, this.templateId, true);
1098
+ });
1099
+ }
1100
+ return true;
1241
1101
  }
1242
1102
  // Look for name conflicts, because they're UGC and can be anything, regardless of order.
1243
1103
  getNextRoleName() {
1104
+ var _a, _b;
1244
1105
  let name = '';
1245
- let nextNumber = Object.keys(this.roleStore.state).length - 1;
1106
+ let nextNumber = (((_a = this.template) === null || _a === void 0 ? void 0 : _a.roles) || []).length;
1246
1107
  do {
1247
1108
  nextNumber++;
1248
1109
  name = `Recipient ${nextNumber}`;
1249
- } while (!name || this.roleStore.state.roles.some(role => role && role.name === name));
1110
+ } while (!name || (((_b = this.template) === null || _b === void 0 ? void 0 : _b.roles) || []).some(role => role && role.name === name));
1250
1111
  return name;
1251
1112
  }
1252
1113
  callCreateRole(name, sequence, order) {
@@ -1266,10 +1127,15 @@ const VerdocsTemplateRoles = class {
1266
1127
  delegator: false,
1267
1128
  kba_method: null,
1268
1129
  })
1269
- .then(async (r) => {
1130
+ .then(async (role) => {
1270
1131
  var _a;
1271
- console.log('[ROLES] Created role', r);
1272
- this.roleStore.set('roles', [...this.roleStore.state.roles, r]);
1132
+ console.log('[ROLES] Created role', role);
1133
+ const newTemplate = JSON.parse(JSON.stringify(this.template));
1134
+ newTemplate.roles.push(role);
1135
+ // TODO: Verify this immediately triggers a self-update
1136
+ console.log('Updating template in data store');
1137
+ Store.updateTemplate(this.templateId, newTemplate);
1138
+ // This will re-sort the roles and renumbers them via server calls if necessary
1273
1139
  await this.renumberTemplateRoles();
1274
1140
  (_a = this.rolesUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'added', endpoint: this.endpoint, templateId: this.templateId, roles: this.getSortedRoles() });
1275
1141
  })
@@ -1290,25 +1156,23 @@ const VerdocsTemplateRoles = class {
1290
1156
  this.callCreateRole(name, sequence, order);
1291
1157
  }
1292
1158
  render() {
1293
- var _a, _b, _c, _d;
1294
1159
  if (!this.endpoint.session) {
1295
1160
  return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
1296
1161
  }
1297
- if (this.loading || !((_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state.isLoaded)) {
1298
- console.log('Loading', this.loading, (_b = this.templateStore) === null || _b === void 0 ? void 0 : _b.state.isLoaded);
1162
+ if (this.loading || !this.template) {
1299
1163
  return (h(Host, { class: "loading" }, h("verdocs-loader", null)));
1300
1164
  }
1301
1165
  const roleNames = this.getRoleNames();
1302
1166
  const sequences = this.getSequenceNumbers();
1303
- return (h(Host, null, h("form", { onSubmit: e => e.preventDefault(), onClick: e => e.stopPropagation(), autocomplete: "off" }, h("h5", null, "Roles and Workflow"), h("div", { class: "participants" }, h("div", { class: "left-line" }), h("div", { class: "row" }, h("div", { class: "icon", innerHTML: startIcon }), h("div", { class: "row-roles" }, h("div", { class: "sender" }, h("span", { class: "label" }, "Owner:"), " ", senderLabels[(_d = (_c = this.templateStore) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.sender], ' '))), h("div", { class: "row add-sequence", "data-sequence": 0 }, h("div", { class: "icon", innerHTML: plusIcon }), h("div", { class: "row-roles" }, h("div", { class: "dropzone", "data-sequence": 0, "data-order": 1 }, "Add Step"))), sequences.map(sequence => (h(Fragment, null, h("div", { class: "row" }, h("div", { class: "icon", innerHTML: stepIcon }), h("div", { class: "row-roles" }, h("div", { class: "dropzone", "data-order": 0.5, "data-sequence": sequence }), this.getRolesAtSequence(sequence).map(role => {
1167
+ return (h(Host, null, h("form", { onSubmit: e => e.preventDefault(), onClick: e => e.stopPropagation(), autocomplete: "off" }, h("h5", null, "Roles and Workflow"), h("div", { class: "participants" }, h("div", { class: "left-line" }), h("div", { class: "row" }, h("div", { class: "icon", innerHTML: startIcon }), h("div", { class: "row-roles" }, h("div", { class: "sender" }, h("span", { class: "label" }, "Send Envelope")))), h("div", { class: "row add-sequence", "data-sequence": 0 }, h("div", { class: "icon", innerHTML: plusIcon }), h("div", { class: "row-roles" }, h("div", { class: "dropzone", "data-sequence": 0, "data-order": 1 }, "Add Step"))), sequences.map(sequence => (h(Fragment, null, h("div", { class: "row" }, h("div", { class: "icon", innerHTML: stepIcon }), h("div", { class: "row-roles" }, h("div", { class: "dropzone", "data-order": 0.5, "data-sequence": sequence }), this.getRolesAtSequence(sequence).map(role => {
1304
1168
  const unknown = !role.email;
1305
- console.log('ras', sequence, role);
1306
- return unknown ? (h(Fragment, null, h("div", { class: "recipient", style: { backgroundColor: getRGBA(getRoleIndex(this.roleStore, role.name)) }, "data-rolename": role.name, "data-sequence": sequence, "data-order": role.order }, h("span", { class: "type-icon", innerHTML: role.type === 'signer' ? iconSigner : role.type === 'cc' ? iconCC : iconApprover }), role.name, " ", h("div", { class: "settings-button", innerHTML: settingsIcon, onClick: () => (this.showingRoleDialog = role.name), "aria-role": "button" })), h("div", { class: "dropzone", "data-order": role.order + 0.5, "data-sequence": sequence }))) : (h(Fragment, null, h("div", { class: "recipient", style: { borderColor: getRGBA(getRoleIndex(this.roleStore, role.name)) }, "data-rolename": role.name, "data-sequence": sequence, "data-order": role.order }, h("span", { class: "type-icon", innerHTML: role.type === 'signer' ? iconSigner : role.type === 'cc' ? iconCC : iconApprover }), formatFullName(role), " ", h("div", { class: "settings-button", innerHTML: settingsIcon, onClick: () => (this.showingRoleDialog = role.name), "aria-role": "button" })), h("div", { class: "dropzone", "data-order": role.order + 0.5, "data-sequence": sequence })));
1169
+ return unknown ? (h(Fragment, null, h("div", { class: "recipient", style: { backgroundColor: getRGBA(getRoleIndex(this.template, role.name)) }, "data-rolename": role.name, "data-sequence": sequence, "data-order": role.order }, h("span", { class: "type-icon", innerHTML: role.type === 'signer' ? iconSigner : role.type === 'cc' ? iconCC : iconApprover }), role.name, " ", h("div", { class: "settings-button", innerHTML: settingsIcon, onClick: () => (this.showingRoleDialog = role.name), "aria-role": "button" })), h("div", { class: "dropzone", "data-order": role.order + 0.5, "data-sequence": sequence }))) : (h(Fragment, null, h("div", { class: "recipient", style: { borderColor: getRGBA(getRoleIndex(this.template, role.name)) }, "data-rolename": role.name, "data-sequence": sequence, "data-order": role.order }, h("span", { class: "type-icon", innerHTML: role.type === 'signer' ? iconSigner : role.type === 'cc' ? iconCC : iconApprover }), formatFullName(role), " ", h("div", { class: "settings-button", innerHTML: settingsIcon, onClick: () => (this.showingRoleDialog = role.name), "aria-role": "button" })), h("div", { class: "dropzone", "data-order": role.order + 0.5, "data-sequence": sequence })));
1307
1170
  }), h("button", { class: "add-role", innerHTML: plusIcon, onClick: e => this.handleAddRole(e, sequence) }))), sequences.length > 0 && (h("div", { class: "row add-sequence", "data-sequence": sequence }, h("div", { class: "row-roles" }, h("div", { class: "icon", innerHTML: plusIcon }), h("div", { class: "dropzone", "data-sequence": sequence + 1, "data-order": 1 }, "Add Step"))))))), h("div", { class: "row", "data-sequence": sequences.length + 1 }, h("div", { class: "row-roles" }, h("div", { class: "icon", innerHTML: plusIcon }), h("button", { class: "add-step", innerHTML: plusIcon, onClick: e => this.handleAddStep(e, sequences.length + 1) }))), h("div", { class: "row" }, h("div", { class: "icon", innerHTML: doneIcon }), h("div", { class: "row-roles" }, h("div", { class: "complete" }, "Document Complete")))), roleNames.length < 1 && (h("div", { class: "empty" }, "You must add at least one Role before proceeding.", h("br", null), " Click the ", h("span", { innerHTML: plusIcon }), " Add button above to get started.")), h("div", { class: "buttons" }, h("div", { class: "flex-fill" }), h("verdocs-button", { variant: "outline", label: "Cancel", size: "small", onClick: () => this.handleCancel() }), h("verdocs-button", { label: "OK", size: "small", onClick: () => this.handleSubmit(), disabled: roleNames.length < 1 }))), this.showingRoleDialog && (h("verdocs-template-role-properties", { endpoint: this.endpoint, templateId: this.templateId, roleName: this.showingRoleDialog, onClose: () => {
1308
1171
  this.showingRoleDialog = null;
1309
1172
  }, onDelete: async () => {
1310
1173
  var _a;
1311
1174
  this.showingRoleDialog = null;
1175
+ // This will re-sort the roles and renumbers them via server calls if necessary
1312
1176
  await this.renumberTemplateRoles();
1313
1177
  (_a = this.rolesUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'deleted', endpoint: this.endpoint, templateId: this.templateId, roles: this.getSortedRoles() });
1314
1178
  } }))));
@@ -1317,82 +1181,4 @@ const VerdocsTemplateRoles = class {
1317
1181
  };
1318
1182
  VerdocsTemplateRoles.style = VerdocsTemplateRolesStyle0;
1319
1183
 
1320
- const verdocsTemplateVisibilityCss = "@-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-template-visibility{font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif}verdocs-template-visibility.loading{min-height:300px;position:relative;display:block}verdocs-template-visibility.empty{display:none}verdocs-template-visibility form{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}verdocs-template-visibility form .description{font-size:14px;text-align:justify;color:#5c6575}verdocs-template-visibility form h5{font-size:16px;font-weight:bold;color:#4c56cb;margin:0}verdocs-template-visibility form label{-ms-flex:1;flex:1;display:-ms-flexbox;display:flex;font-size:16px;font-weight:500;margin:0 0 4px 0;color:#33364b}verdocs-template-visibility form input{border:none;font-size:18px;padding:3px 6px 3px 0;background:transparent;border-bottom:1px solid #33364b}verdocs-template-visibility form input:focus{outline:none}verdocs-template-visibility form .input-row{display:-ms-flexbox;display:flex;margin:20px 0 0 0;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row}verdocs-template-visibility form .input-row verdocs-text-input{margin:0;display:-ms-flexbox;display:flex;-ms-flex:0 0 40px;flex:0 0 40px}verdocs-template-visibility form .input-row verdocs-text-input input{text-align:center}verdocs-template-visibility form .input-row verdocs-checkbox{-ms-flex:0;flex:0;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center}verdocs-template-visibility form .input-row verdocs-checkbox label>input[type=checkbox]+*::before{margin-right:0}verdocs-template-visibility .buttons{display:-ms-flexbox;display:flex;-webkit-column-gap:8px;-moz-column-gap:8px;column-gap:8px;margin-top:25px;-ms-flex-direction:row;flex-direction:row}verdocs-template-visibility ::-webkit-input-placeholder{color:#aaaaaa}verdocs-template-visibility ::-moz-placeholder{color:#aaaaaa}verdocs-template-visibility :-ms-input-placeholder{color:#aaaaaa}verdocs-template-visibility ::-ms-input-placeholder{color:#aaaaaa}verdocs-template-visibility ::placeholder{color:#aaaaaa}";
1321
- const VerdocsTemplateVisibilityStyle0 = verdocsTemplateVisibilityCss;
1322
-
1323
- const VerdocsTemplateVisibility = class {
1324
- constructor(hostRef) {
1325
- registerInstance(this, hostRef);
1326
- this.close = createEvent(this, "close", 7);
1327
- this.sdkError = createEvent(this, "sdkError", 7);
1328
- this.templateUpdated = createEvent(this, "templateUpdated", 7);
1329
- this.store = null;
1330
- this.endpoint = VerdocsEndpoint.getDefault();
1331
- this.templateId = '';
1332
- this.dirty = false;
1333
- this.personal = false;
1334
- this.public = false;
1335
- }
1336
- async componentWillLoad() {
1337
- var _a, _b, _c, _d, _e, _f, _g;
1338
- try {
1339
- this.endpoint.loadSession();
1340
- if (!this.templateId) {
1341
- console.log(`[VISIBILITY] Missing required template ID ${this.templateId}`);
1342
- return;
1343
- }
1344
- if (!this.endpoint.session) {
1345
- console.log('[VISIBILITY] Unable to start builder session, must be authenticated');
1346
- return;
1347
- }
1348
- this.store = await getTemplateStore(this.endpoint, this.templateId, false);
1349
- this.personal = ((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.is_personal) || true;
1350
- this.public = ((_d = (_c = this.store) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.is_public) || false;
1351
- this.dirty = false;
1352
- }
1353
- catch (e) {
1354
- console.log('[TEMPLATE VISIBILITY] Error loading template', e);
1355
- (_e = this.sdkError) === null || _e === void 0 ? void 0 : _e.emit(new SDKError(e.message, (_f = e.response) === null || _f === void 0 ? void 0 : _f.status, (_g = e.response) === null || _g === void 0 ? void 0 : _g.data));
1356
- }
1357
- }
1358
- handleCancel(e) {
1359
- var _a, _b, _c, _d, _e;
1360
- e.stopPropagation();
1361
- this.personal = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.is_personal;
1362
- this.public = (_d = (_c = this.store) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.is_public;
1363
- this.dirty = false;
1364
- (_e = this.close) === null || _e === void 0 ? void 0 : _e.emit();
1365
- }
1366
- async handleSave(e) {
1367
- var _a, _b, _c;
1368
- e.stopPropagation();
1369
- await updateTemplate(this.endpoint, this.templateId, { is_personal: this.personal, is_public: this.public });
1370
- if ((_a = this.store) === null || _a === void 0 ? void 0 : _a.state) {
1371
- this.store.state.is_personal = this.personal;
1372
- this.store.state.is_public = this.public;
1373
- }
1374
- this.dirty = false;
1375
- (_b = this.templateUpdated) === null || _b === void 0 ? void 0 : _b.emit({ endpoint: this.endpoint, template: this.store.state, event: 'visibility' });
1376
- (_c = this.close) === null || _c === void 0 ? void 0 : _c.emit();
1377
- }
1378
- render() {
1379
- var _a, _b;
1380
- if (!this.endpoint.session) {
1381
- return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
1382
- }
1383
- // This is meant to be a companion for larger visual experiences so we just go blank on errors for now.
1384
- if (!this.endpoint.session || !((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.isLoaded)) {
1385
- return h(Host, { class: "empty" });
1386
- }
1387
- return (h(Host, null, h("form", { onSubmit: e => e.preventDefault(), onClick: e => e.stopPropagation(), autocomplete: "off" }, h("h5", null, "Visibility"), h("div", { class: "input-row" }, h("label", { htmlFor: "verdocs-is-shared" }, "Shared"), h("verdocs-checkbox", { id: "verdocs-is-shared", name: "is-shared", checked: !this.personal, value: "on", onInput: (e) => {
1388
- this.personal = !e.target.checked;
1389
- this.dirty = true;
1390
- } })), h("div", { class: "description" }, "Shared templates are visible to other members of your Organization (if any)."), h("div", { class: "input-row" }, h("label", { htmlFor: "verdocs-is-public" }, "Public"), h("verdocs-checkbox", { id: "verdocs-is-public", name: "is-public", checked: this.public, value: "on", onInput: (e) => {
1391
- this.public = e.target.checked;
1392
- this.dirty = true;
1393
- } })), h("div", { class: "description" }, "Public templates may appear in results when any other user searches for templates. Note that a template may be both Personal and Public, which may be useful if you want your template to be found via search but not otherwise displayed to other members of your Organization (if any)."), h("div", { class: "buttons" }, h("verdocs-button", { size: "small", variant: "outline", label: "Cancel", disabled: !this.dirty, onClick: e => this.handleCancel(e) }), h("verdocs-button", { size: "small", label: "Save", disabled: !this.dirty, onClick: e => this.handleSave(e) })))));
1394
- }
1395
- };
1396
- VerdocsTemplateVisibility.style = VerdocsTemplateVisibilityStyle0;
1397
-
1398
- export { VerdocsPreview as verdocs_preview, VerdocsSend as verdocs_send, VerdocsTemplateAttachments as verdocs_template_attachments, VerdocsTemplateBuildTabs as verdocs_template_build_tabs, VerdocsTemplateCreate as verdocs_template_create, VerdocsTemplateFields as verdocs_template_fields, VerdocsTemplateName as verdocs_template_name, VerdocsTemplateRoles as verdocs_template_roles, VerdocsTemplateVisibility as verdocs_template_visibility };
1184
+ export { VerdocsPreview as verdocs_preview, VerdocsSend as verdocs_send, VerdocsTemplateAttachments as verdocs_template_attachments, VerdocsTemplateBuildTabs as verdocs_template_build_tabs, VerdocsTemplateFields as verdocs_template_fields, VerdocsTemplateRoles as verdocs_template_roles };