@verdocs/web-sdk 2.3.12 → 2.3.13

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 (81) hide show
  1. package/dist/cjs/TemplateFieldStore-7449e5ff.js +24 -0
  2. package/dist/cjs/{TemplateStore-17b9fdfe.js → TemplateStore-0074c71d.js} +2 -0
  3. package/dist/cjs/ipc-test.cjs.entry.js +2 -1
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/verdocs-build.cjs.entry.js +2 -1
  6. package/dist/cjs/verdocs-button-panel_2.cjs.entry.js +60 -43
  7. package/dist/cjs/verdocs-field-textbox.cjs.entry.js +10 -1
  8. package/dist/cjs/verdocs-preview_8.cjs.entry.js +2 -1
  9. package/dist/cjs/verdocs-template-fields_4.cjs.entry.js +41 -37
  10. package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
  11. package/dist/collection/components/fields/verdocs-field-textbox/verdocs-field-textbox.js +27 -1
  12. package/dist/collection/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.js +61 -44
  13. package/dist/collection/components/templates/verdocs-template-fields/verdocs-template-fields.js +40 -36
  14. package/dist/collection/utils/TemplateFieldStore.js +18 -0
  15. package/dist/collection/utils/TemplateStore.js +2 -0
  16. package/dist/components/TemplateStore.js +20 -1
  17. package/dist/components/verdocs-field-textbox.js +10 -1
  18. package/dist/components/verdocs-preview2.js +1 -1
  19. package/dist/components/verdocs-template-field-properties2.js +61 -45
  20. package/dist/components/verdocs-template-fields2.js +40 -37
  21. package/dist/custom-elements.json +2071 -0
  22. package/dist/docs.json +18 -1
  23. package/dist/esm/TemplateFieldStore-4f1b6332.js +21 -0
  24. package/dist/esm/{TemplateStore-ad77a294.js → TemplateStore-a2ebdaca.js} +2 -0
  25. package/dist/esm/ipc-test.entry.js +2 -1
  26. package/dist/esm/loader.js +1 -1
  27. package/dist/esm/verdocs-build.entry.js +2 -1
  28. package/dist/esm/verdocs-button-panel_2.entry.js +60 -43
  29. package/dist/esm/verdocs-field-textbox.entry.js +10 -1
  30. package/dist/esm/verdocs-preview_8.entry.js +2 -1
  31. package/dist/esm/verdocs-template-fields_4.entry.js +41 -37
  32. package/dist/esm/verdocs-web-sdk.js +1 -1
  33. package/dist/esm-es5/TemplateFieldStore-4f1b6332.js +1 -0
  34. package/dist/esm-es5/TemplateStore-a2ebdaca.js +1 -0
  35. package/dist/esm-es5/ipc-test.entry.js +1 -1
  36. package/dist/esm-es5/loader.js +1 -1
  37. package/dist/esm-es5/verdocs-build.entry.js +1 -1
  38. package/dist/esm-es5/verdocs-button-panel_2.entry.js +1 -1
  39. package/dist/esm-es5/verdocs-field-textbox.entry.js +1 -1
  40. package/dist/esm-es5/verdocs-preview_8.entry.js +1 -1
  41. package/dist/esm-es5/verdocs-template-fields_4.entry.js +1 -1
  42. package/dist/esm-es5/verdocs-web-sdk.js +1 -1
  43. package/dist/types/components/fields/verdocs-field-textbox/verdocs-field-textbox.d.ts +7 -0
  44. package/dist/types/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.d.ts +7 -5
  45. package/dist/types/components/templates/verdocs-template-fields/verdocs-template-fields.d.ts +4 -2
  46. package/dist/types/components.d.ts +8 -0
  47. package/dist/types/utils/TemplateFieldStore.d.ts +6 -0
  48. package/dist/types/utils/TemplateStore.d.ts +1 -1
  49. package/dist/verdocs-web-sdk/p-084c23e4.system.js +1 -0
  50. package/dist/verdocs-web-sdk/p-12d00a0f.entry.js +1 -0
  51. package/dist/verdocs-web-sdk/p-32c40388.entry.js +1 -0
  52. package/dist/verdocs-web-sdk/p-358aef29.entry.js +1 -0
  53. package/dist/verdocs-web-sdk/p-3cd0d440.system.entry.js +1 -0
  54. package/dist/verdocs-web-sdk/p-429cad70.js +1 -0
  55. package/dist/verdocs-web-sdk/p-4e74bb3c.entry.js +1 -0
  56. package/dist/verdocs-web-sdk/p-588d6cea.system.entry.js +1 -0
  57. package/dist/verdocs-web-sdk/{p-b467d981.system.entry.js → p-5aa77f6d.system.entry.js} +1 -1
  58. package/dist/verdocs-web-sdk/p-5bf12ef8.entry.js +1 -0
  59. package/dist/verdocs-web-sdk/p-72978ba3.system.entry.js +1 -0
  60. package/dist/verdocs-web-sdk/p-8dc15d33.js +1 -0
  61. package/dist/verdocs-web-sdk/p-a627881e.system.js +1 -0
  62. package/dist/verdocs-web-sdk/p-aae6b4e0.entry.js +1 -0
  63. package/dist/verdocs-web-sdk/p-bd9ba3b3.system.entry.js +1 -0
  64. package/dist/verdocs-web-sdk/p-e3ffc00f.system.entry.js +1 -0
  65. package/dist/verdocs-web-sdk/p-f04bf956.system.js +1 -1
  66. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  67. package/package.json +1 -1
  68. package/dist/esm-es5/TemplateStore-ad77a294.js +0 -1
  69. package/dist/verdocs-web-sdk/p-1c08edf7.system.entry.js +0 -1
  70. package/dist/verdocs-web-sdk/p-746fce21.entry.js +0 -1
  71. package/dist/verdocs-web-sdk/p-79168c6a.system.entry.js +0 -1
  72. package/dist/verdocs-web-sdk/p-82b5e475.system.js +0 -1
  73. package/dist/verdocs-web-sdk/p-85df0da6.entry.js +0 -1
  74. package/dist/verdocs-web-sdk/p-9a5c0882.system.entry.js +0 -1
  75. package/dist/verdocs-web-sdk/p-9d2995a9.entry.js +0 -1
  76. package/dist/verdocs-web-sdk/p-ab98a02d.system.entry.js +0 -1
  77. package/dist/verdocs-web-sdk/p-ae83f4a0.entry.js +0 -1
  78. package/dist/verdocs-web-sdk/p-da3faf4a.entry.js +0 -1
  79. package/dist/verdocs-web-sdk/p-e760f894.entry.js +0 -1
  80. package/dist/verdocs-web-sdk/p-f3dde708.js +0 -1
  81. package/dist/verdocs-web-sdk/p-fe67b620.system.entry.js +0 -1
@@ -4,6 +4,7 @@ import { integerSequence } from '@verdocs/js-sdk/Utils/Primitives';
4
4
  import { createField, updateField } from '@verdocs/js-sdk/Templates/Fields';
5
5
  import { h, Host } from '@stencil/core';
6
6
  import { defaultHeight, defaultWidth, getRoleIndex, renderDocumentField, updateCssTransform } from '../../../utils/utils';
7
+ import { createTemplateFieldStore } from '../../../utils/TemplateFieldStore';
7
8
  import { getRoleNames, getTemplateStore } from '../../../utils/TemplateStore';
8
9
  import { SDKError } from '../../../utils/errors';
9
10
  const iconTextbox = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" d="M3.425 16.15V13h11.15v3.15Zm0-5.15V7.85h17.15V11Z"/></svg>';
@@ -39,7 +40,8 @@ const menuOptions = [
39
40
  export class VerdocsTemplateFields {
40
41
  constructor() {
41
42
  this.pageHeights = {};
42
- this.store = null;
43
+ this.templateStore = null;
44
+ this.fieldStore = null;
43
45
  this.cachedPageInfo = {};
44
46
  this.endpoint = VerdocsEndpoint.getDefault();
45
47
  this.templateId = null;
@@ -61,9 +63,10 @@ export class VerdocsTemplateFields {
61
63
  console.log('[FIELDS] Unable to start builder session, must be authenticated');
62
64
  return;
63
65
  }
64
- this.store = await getTemplateStore(this.endpoint, this.templateId, true);
65
- console.log(`[FIELDS] Loaded template ${this.templateId}`, this.store.state);
66
- this.selectedRoleName = ((_d = (_c = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.roles) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) || '';
66
+ this.templateStore = await getTemplateStore(this.endpoint, this.templateId, true);
67
+ this.fieldStore = createTemplateFieldStore(this.templateStore.state);
68
+ console.log(`[FIELDS] Loaded template ${this.templateId}`, this.templateStore.state, this.fieldStore);
69
+ this.selectedRoleName = ((_d = (_c = (_b = (_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.roles) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) || '';
67
70
  console.log('[FIELDS] Starting with role', this.selectedRoleName);
68
71
  }
69
72
  catch (e) {
@@ -84,8 +87,8 @@ export class VerdocsTemplateFields {
84
87
  componentWillUpdate() {
85
88
  var _a, _b, _c, _d, _e, _f;
86
89
  // If a new role was added and there were none yet so far, or the "selected" role was deleted, reset our selection
87
- if (!this.selectedRoleName || !(((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.roles) || []).find(role => role.name === this.selectedRoleName)) {
88
- this.selectedRoleName = ((_f = (_e = (_d = (_c = this.store) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.roles) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.name) || '';
90
+ if (!this.selectedRoleName || !(((_b = (_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.roles) || []).find(role => role.name === this.selectedRoleName)) {
91
+ this.selectedRoleName = ((_f = (_e = (_d = (_c = this.templateStore) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.roles) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.name) || '';
89
92
  console.log('[FIELDS] Selected new role', this.selectedRoleName);
90
93
  }
91
94
  }
@@ -99,35 +102,39 @@ export class VerdocsTemplateFields {
99
102
  console.log('[FIELDS] handleFieldChange', field, e, optionId);
100
103
  this.rerender++;
101
104
  }
102
- handleFieldSettingsChange(pageInfo, field, roleIndex, el, newFieldData) {
103
- var _a, _b, _c, _d;
105
+ handleFieldSettingsChange(pageInfo, field, el, newFieldData) {
106
+ var _a, _b;
107
+ // handleFieldSettingsChange(pageInfo: any, field: any, roleIndex: number, el: any, newFieldData: any) {
104
108
  console.log('[FIELDS] Field settings changed', field.name, newFieldData);
105
109
  Object.assign(field, newFieldData);
106
110
  el.field = newFieldData;
107
111
  this.selectedRoleName = field.role_name;
108
- el.setAttribute('roleindex', getRoleIndex(getRoleNames(this.store), field.role_name));
109
- el.field = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.fields.find(f => f.name === field.name);
112
+ el.setAttribute('roleindex', getRoleIndex(getRoleNames(this.templateStore), field.role_name));
113
+ el.field = this.fieldStore.get(field.name);
110
114
  this.rerender++;
111
115
  el.setAttribute('rerender', this.rerender);
112
- (_c = this.templateUpdated) === null || _c === void 0 ? void 0 : _c.emit({ endpoint: this.endpoint, template: (_d = this.store) === null || _d === void 0 ? void 0 : _d.state, event: 'updated-field' });
116
+ (_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' });
113
117
  console.log('[FIELDS] Re-rendering field', field.name, pageInfo.pageNumber);
114
- this.reRenderField(field, pageInfo.pageNumber);
115
- const newEl = renderDocumentField(field, pageInfo, roleIndex, { disabled: true, editable: true, draggable: true });
116
- if (!newEl) {
117
- return;
118
- }
118
+ this.fieldStore.set(field.name, field);
119
+ // this.reRenderField(field, pageInfo.pageNumber);
120
+ // const newEl = renderDocumentField(field, pageInfo, roleIndex, {disabled: true, editable: true, draggable: true});
121
+ // if (!newEl) {
122
+ // return;
123
+ // }
119
124
  }
120
125
  attachFieldAttributes(pageInfo, field, roleIndex, el) {
121
126
  el.addEventListener('input', e => this.handleFieldChange(field, e));
122
- el.addEventListener('settingsChanged', e => this.handleFieldSettingsChange(pageInfo, field, roleIndex, el, e.detail.field));
127
+ el.addEventListener('settingsChanged', e => this.handleFieldSettingsChange(pageInfo, field, el, e.detail.field));
128
+ // el.addEventListener('settingsChanged', e => this.handleFieldSettingsChange(pageInfo, field, roleIndex, el, e.detail.field));
123
129
  el.addEventListener('deleted', () => {
124
130
  var _a, _b;
125
131
  console.log('[FIELDS] Deleted', this, field);
126
132
  el.remove();
127
133
  this.rerender++;
128
- (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: (_b = this.store) === null || _b === void 0 ? void 0 : _b.state, event: 'updated-field' });
134
+ (_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' });
129
135
  });
130
136
  el.setAttribute('templateid', this.templateId);
137
+ el.setAttribute('fieldname', field.name);
131
138
  el.setAttribute('roleindex', roleIndex);
132
139
  el.setAttribute('pageNumber', pageInfo.pageNumber);
133
140
  el.setAttribute('xScale', pageInfo.xScale);
@@ -135,17 +142,16 @@ export class VerdocsTemplateFields {
135
142
  el.setAttribute('name', field.name);
136
143
  }
137
144
  handlePageRendered(e) {
138
- var _a;
139
145
  const pageInfo = e.detail;
140
146
  console.log('[FIELDS] Page rendered', pageInfo.pageNumber, pageInfo);
141
147
  this.cachedPageInfo[pageInfo.pageNumber] = pageInfo;
142
148
  this.pageHeights[pageInfo.pageNumber] = pageInfo.naturalHeight;
143
- const fields = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state.fields.filter(field => field.page_sequence === pageInfo.pageNumber);
149
+ const fields = Object.values(this.fieldStore.state).filter(field => field.page_sequence === pageInfo.pageNumber);
144
150
  fields.forEach(field => this.reRenderField(field, pageInfo.pageNumber));
145
151
  }
146
152
  reRenderField(field, pageNumber) {
147
153
  const pageInfo = this.cachedPageInfo[pageNumber];
148
- const roleIndex = getRoleIndex(getRoleNames(this.store), field.role_name);
154
+ const roleIndex = getRoleIndex(getRoleNames(this.templateStore), field.role_name);
149
155
  const el = renderDocumentField(field, pageInfo, roleIndex, { disabled: true, editable: true, draggable: true });
150
156
  if (!el) {
151
157
  return;
@@ -181,10 +187,9 @@ export class VerdocsTemplateFields {
181
187
  updateCssTransform(event.target, 'translate', `${newX}px, ${newY}px`);
182
188
  }
183
189
  async handleMoveEnd(event) {
184
- var _a;
185
190
  const name = event.target.getAttribute('name');
186
191
  const option = +(event.target.getAttribute('option') || '0');
187
- const field = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state.fields.find(field => field.name === name);
192
+ const field = this.fieldStore.get(name);
188
193
  console.log('Dropped field', name, field);
189
194
  if (!field) {
190
195
  console.log('[FIELDS] Unable to find field', name);
@@ -231,19 +236,19 @@ export class VerdocsTemplateFields {
231
236
  console.log('[FIELDS] Will update', name, option, field);
232
237
  const newFieldData = await updateField(this.endpoint, this.templateId, name, field);
233
238
  const pageInfo = this.cachedPageInfo[pageNumber];
234
- const roleIndex = getRoleIndex(getRoleNames(this.store), field.role_name);
235
- this.handleFieldSettingsChange(pageInfo, field, roleIndex, event.target, newFieldData);
239
+ // const roleIndex = getRoleIndex(getRoleNames(this.templateStore), field.role_name);
240
+ this.handleFieldSettingsChange(pageInfo, field, event.target, newFieldData);
241
+ // this.handleFieldSettingsChange(pageInfo, field, roleIndex, event.target, newFieldData);
236
242
  event.target.removeAttribute('posX');
237
243
  event.target.removeAttribute('posY');
238
244
  }
239
245
  generateFieldName(type, pageNumber) {
240
- var _a;
241
246
  let i = 1;
242
247
  let fieldName;
243
248
  do {
244
249
  fieldName = `${type}P${pageNumber}-${i}`;
245
250
  i++;
246
- } while ((_a = this.store) === null || _a === void 0 ? void 0 : _a.state.fields.some(field => field.name === fieldName));
251
+ } while (Object.values(this.fieldStore.state).some(field => field.name === fieldName));
247
252
  return fieldName;
248
253
  }
249
254
  // Scale the X,Y clicks to the virtual page dimensions. Also ensure the field doesn't go off the page.
@@ -255,7 +260,7 @@ export class VerdocsTemplateFields {
255
260
  return { x, y };
256
261
  }
257
262
  async handleClickPage(e, pageNumber) {
258
- var _a, _b, _c;
263
+ var _a, _b;
259
264
  if (this.placing) {
260
265
  const clickedX = e.offsetX;
261
266
  const clickedY = e.offsetY;
@@ -282,6 +287,7 @@ export class VerdocsTemplateFields {
282
287
  width,
283
288
  height,
284
289
  };
290
+ console.log('[FIELDS] Will save new field', field);
285
291
  // TODO: Fix how the server validates all this. It uses a JSON schema and is very particular about shapes for each field type.
286
292
  // That makes it harder for third party developers to create fields via API calls. It would be better to always set X/Y and
287
293
  // let the server normalize the rest, discarding properties that are invalid and back-filling defaults as needed.
@@ -348,11 +354,9 @@ export class VerdocsTemplateFields {
348
354
  }
349
355
  const saved = await createField(this.endpoint, this.templateId, field);
350
356
  console.log('Saved field', saved);
351
- if (this.store.state) {
352
- this.store.state.fields = [...(_a = this.store) === null || _a === void 0 ? void 0 : _a.state.fields, saved];
353
- }
357
+ this.fieldStore.set(saved.name, saved);
354
358
  this.placing = null;
355
- (_b = this.templateUpdated) === null || _b === void 0 ? void 0 : _b.emit({ endpoint: this.endpoint, template: (_c = this.store) === null || _c === void 0 ? void 0 : _c.state, event: 'added-field' });
359
+ (_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' });
356
360
  this.handlePageRendered({ detail: this.cachedPageInfo[pageNumber] });
357
361
  }
358
362
  }
@@ -363,10 +367,10 @@ export class VerdocsTemplateFields {
363
367
  return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
364
368
  }
365
369
  // TODO: Render a better error
366
- if (!((_a = this.store) === null || _a === void 0 ? void 0 : _a.state.isLoaded)) {
370
+ if (!((_a = this.templateStore) === null || _a === void 0 ? void 0 : _a.state.isLoaded)) {
367
371
  return (h(Host, null, h("verdocs-loader", null)));
368
372
  }
369
- const selectableRoles = (_c = (_b = this.store) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.roles.map(role => ({ value: role.name, label: role.name }));
373
+ const selectableRoles = (_c = (_b = this.templateStore) === null || _b === void 0 ? void 0 : _b.state) === null || _c === void 0 ? void 0 : _c.roles.map(role => ({ value: role.name, label: role.name }));
370
374
  return (h(Host, { class: this.placing ? { [`placing-${this.placing}`]: true } : {}, "data-r": this.rerender, onSubmit: () => {
371
375
  console.log('onSubmit');
372
376
  } }, 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, onClick: () => {
@@ -380,13 +384,13 @@ export class VerdocsTemplateFields {
380
384
  this.showMustSelectRole = true;
381
385
  }
382
386
  }
383
- } })))), h("div", { class: "pages" }, (((_e = (_d = this.store) === null || _d === void 0 ? void 0 : _d.state) === null || _e === void 0 ? void 0 : _e.template_documents) || []).map(document => {
387
+ } })))), h("div", { class: "pages" }, (((_e = (_d = this.templateStore) === null || _d === void 0 ? void 0 : _d.state) === null || _e === void 0 ? void 0 : _e.template_documents) || []).map(document => {
384
388
  const pageNumbers = integerSequence(1, document.page_numbers);
385
389
  return pageNumbers.map(page => (h("verdocs-template-document-page", { templateId: this.templateId, documentId: document.id, pageNumber: page, virtualWidth: 612, virtualHeight: 792, onClick: (e) => this.handleClickPage(e, page), onPageRendered: e => this.handlePageRendered(e), layers: [
386
390
  { name: 'page', type: 'canvas' },
387
391
  { name: 'controls', type: 'div' },
388
392
  ] })));
389
- })), this.showMustSelectRole && (h("verdocs-ok-dialog", { heading: "Unable to add field", message: ((_h = (_g = (_f = this.store) === null || _f === void 0 ? void 0 : _f.state) === null || _g === void 0 ? void 0 : _g.roles) === null || _h === void 0 ? void 0 : _h.length) > 0 ? 'Please select a role before adding fields.' : 'Please add at least one role before adding fields.', onNext: () => (this.showMustSelectRole = false) }))));
393
+ })), this.showMustSelectRole && (h("verdocs-ok-dialog", { heading: "Unable to add field", message: ((_h = (_g = (_f = this.templateStore) === null || _f === void 0 ? void 0 : _f.state) === null || _g === void 0 ? void 0 : _g.roles) === null || _h === void 0 ? void 0 : _h.length) > 0 ? 'Please select a role before adding fields.' : 'Please add at least one role before adding fields.', onNext: () => (this.showMustSelectRole = false) }))));
390
394
  }
391
395
  static get is() { return "verdocs-template-fields"; }
392
396
  static get originalStyleUrls() {
@@ -0,0 +1,18 @@
1
+ import { createStore } from '@stencil/store';
2
+ const templateFieldStores = {};
3
+ export const getTemplateFieldStore = (templateId) => templateFieldStores[templateId];
4
+ export const createTemplateFieldStore = (template) => {
5
+ console.log('Creating template field store for template: ', template);
6
+ let store = getTemplateFieldStore(template.id);
7
+ if (!store) {
8
+ store = createStore({});
9
+ templateFieldStores[template.id] = store;
10
+ }
11
+ else {
12
+ store.reset();
13
+ }
14
+ template.fields.forEach(field => {
15
+ store.set(field.name, field);
16
+ });
17
+ return store;
18
+ };
@@ -1,6 +1,7 @@
1
1
  import { createStore } from '@stencil/store';
2
2
  import { getTemplate } from '@verdocs/js-sdk/Templates/Templates';
3
3
  import { TemplateSenderTypes } from '@verdocs/js-sdk/Templates/Types';
4
+ import { createTemplateFieldStore } from "./TemplateFieldStore";
4
5
  const createTemplateStore = (templateId) => {
5
6
  const now = new Date().toISOString();
6
7
  return createStore({
@@ -79,6 +80,7 @@ export const getTemplateStore = async (endpoint, templateId, forceReload = false
79
80
  store.state.isLoading = false;
80
81
  store.state.updateCount++;
81
82
  }
83
+ createTemplateFieldStore(store.state);
82
84
  return store;
83
85
  };
84
86
  export const getRoleNames = (store) => { var _a; return (((_a = store === null || store === void 0 ? void 0 : store.state) === null || _a === void 0 ? void 0 : _a.roles) || []).map(role => role.name); };
@@ -1,6 +1,24 @@
1
1
  import { c as createStore } from './index4.js';
2
2
  import { g as getTemplate, b as TemplateSenderTypes } from './VerdocsEndpoint.js';
3
3
 
4
+ const templateFieldStores = {};
5
+ const getTemplateFieldStore = (templateId) => templateFieldStores[templateId];
6
+ const createTemplateFieldStore = (template) => {
7
+ console.log('Creating template field store for template: ', template);
8
+ let store = getTemplateFieldStore(template.id);
9
+ if (!store) {
10
+ store = createStore({});
11
+ templateFieldStores[template.id] = store;
12
+ }
13
+ else {
14
+ store.reset();
15
+ }
16
+ template.fields.forEach(field => {
17
+ store.set(field.name, field);
18
+ });
19
+ return store;
20
+ };
21
+
4
22
  const createTemplateStore = (templateId) => {
5
23
  const now = new Date().toISOString();
6
24
  return createStore({
@@ -79,8 +97,9 @@ const getTemplateStore = async (endpoint, templateId, forceReload = false) => {
79
97
  store.state.isLoading = false;
80
98
  store.state.updateCount++;
81
99
  }
100
+ createTemplateFieldStore(store.state);
82
101
  return store;
83
102
  };
84
103
  const getRoleNames = (store) => { var _a; return (((_a = store === null || store === void 0 ? void 0 : store.state) === null || _a === void 0 ? void 0 : _a.roles) || []).map(role => role.name); };
85
104
 
86
- export { getRoleNames as a, getTemplateStore as g };
105
+ export { getTemplateFieldStore as a, getRoleNames as b, createTemplateFieldStore as c, getTemplateStore as g };
@@ -5,6 +5,7 @@ import { V as VerdocsEndpoint } from './VerdocsEndpoint.js';
5
5
  import { u as updateField } from './Fields.js';
6
6
  import { g as getRGBA } from './Colors.js';
7
7
  import { g as getFieldSettings } from './utils.js';
8
+ import { a as getTemplateFieldStore } from './TemplateStore.js';
8
9
  import { d as defineCustomElement$9 } from './verdocs-button2.js';
9
10
  import { d as defineCustomElement$8 } from './verdocs-button-panel2.js';
10
11
  import { d as defineCustomElement$7 } from './verdocs-checkbox2.js';
@@ -23,9 +24,11 @@ const VerdocsFieldTextbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
23
24
  this.__registerHost();
24
25
  this.settingsChanged = createEvent(this, "settingsChanged", 7);
25
26
  this.deleted = createEvent(this, "deleted", 7);
27
+ this.fieldStore = null;
26
28
  this.endpoint = VerdocsEndpoint.getDefault();
27
29
  this.templateid = '';
28
30
  this.field = null;
31
+ this.fieldname = '';
29
32
  this.disabled = false;
30
33
  this.editable = false;
31
34
  this.moveable = false;
@@ -50,6 +53,10 @@ const VerdocsFieldTextbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
50
53
  settingsPanel.hidePanel();
51
54
  }
52
55
  }
56
+ async componentWillLoad() {
57
+ console.log('Loading field', this.field);
58
+ this.fieldStore = getTemplateFieldStore(this.templateid);
59
+ }
53
60
  componentDidRender() {
54
61
  interact_min.dynamicDrop(true);
55
62
  if (this.editable) {
@@ -98,6 +105,8 @@ const VerdocsFieldTextbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
98
105
  }
99
106
  render() {
100
107
  var _a, _b, _c, _d;
108
+ const f = this.fieldStore.get(this.fieldname);
109
+ console.log('rendering field', f);
101
110
  const settings = getFieldSettings(this.field);
102
111
  let disabled = (_b = (_a = this.disabled) !== null && _a !== void 0 ? _a : settings.disabled) !== null && _b !== void 0 ? _b : false;
103
112
  const backgroundColor = this.field['rgba'] || getRGBA(this.roleindex);
@@ -114,7 +123,6 @@ const VerdocsFieldTextbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
114
123
  return this.hideSettingsPanel();
115
124
  }, onSettingsChanged: e => {
116
125
  var _a;
117
- console.log('here');
118
126
  (_a = this.settingsChanged) === null || _a === void 0 ? void 0 : _a.emit(e.detail);
119
127
  return this.hideSettingsPanel();
120
128
  }, helpText: 'Text boxes may be used to capture simple text input. Participant-entered values will be stored for later retrieval via the "name" field.<br /><br />If marked required, the participant must complete the field before proceeding.' })))));
@@ -125,6 +133,7 @@ const VerdocsFieldTextbox$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
125
133
  "endpoint": [16],
126
134
  "templateid": [1],
127
135
  "field": [16],
136
+ "fieldname": [1],
128
137
  "disabled": [4],
129
138
  "editable": [4],
130
139
  "moveable": [4],
@@ -2,7 +2,7 @@ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/
2
2
  import './Types.js';
3
3
  import { V as VerdocsEndpoint } from './VerdocsEndpoint.js';
4
4
  import { r as renderDocumentField, b as getRoleIndex } from './utils.js';
5
- import { g as getTemplateStore, a as getRoleNames } from './TemplateStore.js';
5
+ import { g as getTemplateStore, b as getRoleNames } from './TemplateStore.js';
6
6
  import { S as SDKError } from './errors.js';
7
7
  import { d as defineCustomElement$2 } from './verdocs-loader2.js';
8
8
  import { d as defineCustomElement$1 } from './verdocs-template-document-page2.js';
@@ -3,7 +3,7 @@ import { c as commonjsGlobal } from './_commonjsHelpers.js';
3
3
  import './Types.js';
4
4
  import { V as VerdocsEndpoint } from './VerdocsEndpoint.js';
5
5
  import { u as updateField, d as deleteField } from './Fields.js';
6
- import { g as getTemplateStore } from './TemplateStore.js';
6
+ import { g as getTemplateStore, c as createTemplateFieldStore } from './TemplateStore.js';
7
7
  import { S as SDKError } from './errors.js';
8
8
  import { d as defineCustomElement$6 } from './verdocs-button2.js';
9
9
  import { d as defineCustomElement$5 } from './verdocs-checkbox2.js';
@@ -214,21 +214,23 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
214
214
  this.delete = createEvent(this, "delete", 7);
215
215
  this.settingsChanged = createEvent(this, "settingsChanged", 7);
216
216
  this.sdkError = createEvent(this, "sdkError", 7);
217
- this.store = null;
217
+ this.templateStore = null;
218
+ this.fieldStore = null;
219
+ this.watcher = null;
218
220
  this.endpoint = VerdocsEndpoint.getDefault();
219
221
  this.templateId = '';
220
222
  this.fieldName = '';
221
223
  this.helpText = '';
222
224
  this.dirty = false;
223
225
  this.loading = true;
224
- this.type = 'signature';
225
226
  this.setting = null;
226
227
  this.label = '';
228
+ this.type = 'textbox';
227
229
  this.name = '';
230
+ this.required = false;
228
231
  this.roleName = '';
229
232
  this.group = '';
230
233
  this.fieldType = '';
231
- this.required = false;
232
234
  this.options = [];
233
235
  this.placeholder = '';
234
236
  this.value = '';
@@ -236,7 +238,7 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
236
238
  this.showingHelp = false;
237
239
  }
238
240
  async componentWillLoad() {
239
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
241
+ var _a, _b, _c, _d, _e, _f, _g;
240
242
  try {
241
243
  this.endpoint.loadSession();
242
244
  if (!this.templateId) {
@@ -251,11 +253,36 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
251
253
  console.log('[FIELD PROPERTIES] Unable to start builder session, must be authenticated');
252
254
  return;
253
255
  }
254
- this.store = await getTemplateStore(this.endpoint, this.templateId, false);
255
- const field = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.fields.find(field => field.name === this.fieldName);
256
+ this.templateStore = await getTemplateStore(this.endpoint, this.templateId);
257
+ this.fieldStore = await createTemplateFieldStore(this.templateStore.state);
258
+ const field = this.fieldStore.get(this.fieldName);
256
259
  if (!field) {
257
- console.log(`[FIELD PROPERTIES] Unable to find field "${this.fieldName}" in template`);
260
+ console.log(`[FIELD PROPERTIES] Unable to find field "${this.fieldName}" in fields`);
261
+ }
262
+ else {
263
+ console.log('props', field);
258
264
  }
265
+ createTemplateFieldStore(this.templateStore.state);
266
+ this.watcher = this.fieldStore.onChange(this.fieldName, field => {
267
+ var _a, _b, _c, _d;
268
+ console.log('Field changed', field);
269
+ this.type = field.type;
270
+ this.name = field.name;
271
+ this.label = field.label;
272
+ this.group = field.name;
273
+ this.roleName = field.role_name;
274
+ this.required = field.required;
275
+ this.fieldType = field.type;
276
+ // TODO: Talk about how we want to handle labels/placeholders
277
+ this.placeholder = ((_a = field.setting) === null || _a === void 0 ? void 0 : _a.placeholder) || '';
278
+ this.value = ((_b = field.setting) === null || _b === void 0 ? void 0 : _b.result) || '';
279
+ this.leading = ((_c = field.setting) === null || _c === void 0 ? void 0 : _c.leading) || 0;
280
+ this.setting = field.setting || {};
281
+ this.options = ((_d = field.setting) === null || _d === void 0 ? void 0 : _d.options) || [];
282
+ this.dirty = false;
283
+ this.loading = false;
284
+ });
285
+ console.log('watcher', this.watcher);
259
286
  this.type = field.type;
260
287
  this.name = field.name;
261
288
  this.label = field.label;
@@ -264,36 +291,37 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
264
291
  this.required = field.required;
265
292
  this.fieldType = field.type;
266
293
  // TODO: Talk about how we want to handle labels/placeholders
267
- this.placeholder = ((_c = field.setting) === null || _c === void 0 ? void 0 : _c.placeholder) || '';
268
- this.value = ((_d = field.setting) === null || _d === void 0 ? void 0 : _d.result) || '';
269
- this.leading = ((_e = field.setting) === null || _e === void 0 ? void 0 : _e.leading) || 0;
294
+ this.placeholder = ((_a = field.setting) === null || _a === void 0 ? void 0 : _a.placeholder) || '';
295
+ this.value = ((_b = field.setting) === null || _b === void 0 ? void 0 : _b.result) || '';
296
+ this.leading = ((_c = field.setting) === null || _c === void 0 ? void 0 : _c.leading) || 0;
270
297
  this.setting = field.setting || {};
271
- this.options = ((_f = field.setting) === null || _f === void 0 ? void 0 : _f.options) || [];
298
+ this.options = ((_d = field.setting) === null || _d === void 0 ? void 0 : _d.options) || [];
272
299
  this.dirty = false;
273
300
  this.loading = false;
301
+ console.log('Displaying settings for', this.setting);
274
302
  }
275
303
  catch (e) {
276
304
  console.log('[FIELD PROPERTIES] Error loading template', e);
277
305
  this.loading = false;
278
- (_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));
306
+ (_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));
279
307
  }
280
308
  }
281
309
  handleCancel(e) {
282
- var _a, _b, _c, _d, _e, _f;
310
+ var _a, _b, _c, _d;
283
311
  e.stopPropagation();
284
- const field = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.fields.find(field => field.name === this.fieldName);
312
+ const field = this.fieldStore.get(this.fieldName);
285
313
  if (field) {
286
314
  this.name = field.name;
287
315
  this.label = field.label;
288
316
  this.roleName = field.role_name;
289
317
  this.required = field.required;
290
318
  // TODO: Talk about how we want to handle labels/placeholders
291
- this.placeholder = ((_c = field.setting) === null || _c === void 0 ? void 0 : _c.placeholder) || '';
292
- this.value = ((_d = field.setting) === null || _d === void 0 ? void 0 : _d.result) || '';
293
- this.leading = ((_e = field.setting) === null || _e === void 0 ? void 0 : _e.leading) || 0;
319
+ this.placeholder = ((_a = field.setting) === null || _a === void 0 ? void 0 : _a.placeholder) || '';
320
+ this.value = ((_b = field.setting) === null || _b === void 0 ? void 0 : _b.result) || '';
321
+ this.leading = ((_c = field.setting) === null || _c === void 0 ? void 0 : _c.leading) || 0;
294
322
  }
295
323
  this.dirty = false;
296
- (_f = this.close) === null || _f === void 0 ? void 0 : _f.emit();
324
+ (_d = this.close) === null || _d === void 0 ? void 0 : _d.emit();
297
325
  }
298
326
  handleSave(e) {
299
327
  e.stopPropagation();
@@ -319,6 +347,7 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
319
347
  options: this.options,
320
348
  };
321
349
  }
350
+ console.log('FP: Will update', newProperties);
322
351
  updateField(this.endpoint, this.templateId, this.fieldName, newProperties)
323
352
  .then(field => {
324
353
  var _a, _b;
@@ -370,33 +399,19 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
370
399
  });
371
400
  }
372
401
  updateField(newField) {
373
- const newFields = [...this.store.state.fields];
374
- newFields.forEach(field => {
375
- if (field.name === this.fieldName) {
376
- Object.assign(field, newField);
377
- // field.name = this.name;
378
- // field.role_name = this.roleName;
379
- // field.required = this.required;
380
- // field.label = this.placeholder;
381
- // field.setting.result = this.defaultValue;
382
- // if (field.setting.options) {
383
- // field.setting.options = this.options;
384
- // }
385
- }
386
- });
387
- this.store.state.fields = newFields;
402
+ const oldField = this.fieldStore.get(this.fieldName) || {};
403
+ console.log('Updating field', newField, oldField);
404
+ Object.assign(oldField, newField);
405
+ this.fieldStore.set(this.fieldName, newField);
388
406
  }
389
407
  async handleDelete(e) {
390
408
  e.stopPropagation();
391
409
  if (window.confirm('Are you sure you wish to remove this field? This action cannot be undone.')) {
392
410
  deleteField(this.endpoint, this.templateId, this.fieldName)
393
411
  .then(() => {
394
- var _a, _b, _c, _d, _e;
395
- this.store.state.fields = [...(_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.fields.filter(field => field.name !== this.fieldName)];
396
- (_d = (_c = this.store) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.roles.forEach(role => {
397
- role.fields = [...role.fields.filter(field => field.name !== this.fieldName)];
398
- });
399
- (_e = this.delete) === null || _e === void 0 ? void 0 : _e.emit({ templateId: this.templateId, roleName: this.roleName });
412
+ var _a;
413
+ this.fieldStore.set(this.fieldName, undefined);
414
+ (_a = this.delete) === null || _a === void 0 ? void 0 : _a.emit({ templateId: this.templateId, roleName: this.roleName });
400
415
  })
401
416
  .catch(e => {
402
417
  console.log('[FIELD PROPERTIES] Deletion error', e);
@@ -404,12 +419,13 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
404
419
  }
405
420
  }
406
421
  render() {
407
- var _a, _b, _c, _d;
422
+ var _a;
423
+ // console.log('Rendering field properties', this.fieldStore.get(this.fieldName));
408
424
  if (!this.endpoint.session) {
409
425
  return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
410
426
  }
411
427
  // This is meant to be a companion for larger visual experiences so we just go blank on errors for now.
412
- if (!this.endpoint.session || !((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.isLoaded)) {
428
+ if (!this.endpoint.session || !this.fieldStore.get(this.fieldName)) {
413
429
  return h(Host, { class: "empty" });
414
430
  }
415
431
  if (this.helpText && this.showingHelp) {
@@ -425,7 +441,7 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
425
441
  placeholder: "Optional Label...", onInput: (e) => {
426
442
  this.label = e.target.value;
427
443
  this.dirty = true;
428
- } })), h("div", { class: "row" }, h("div", { class: "input-label" }, "Role:"), h("verdocs-select-input", { value: this.roleName, options: (_d = (_c = this.store) === null || _c === void 0 ? void 0 : _c.state) === null || _d === void 0 ? void 0 : _d.roles.map(role => ({ label: role.name, value: role.name })), onInput: (e) => {
444
+ } })), h("div", { class: "row" }, h("div", { class: "input-label" }, "Role:"), h("verdocs-select-input", { value: this.roleName, options: (_a = this.templateStore.state) === null || _a === void 0 ? void 0 : _a.roles.map(role => ({ label: role.name, value: role.name })), onInput: (e) => {
429
445
  this.roleName = e.target.value;
430
446
  this.dirty = true;
431
447
  } })), ['textbox', 'textarea'].includes(this.type) && (h("div", { class: "row", style: { marginTop: '10px', marginBottom: '10px' } }, h("verdocs-text-input", { id: "verdocs-field-value", label: "Value", value: this.value, autocomplete: "off", placeholder: "Pre-defined value...", onInput: (e) => {
@@ -472,14 +488,14 @@ const VerdocsTemplateFieldProperties = /*@__PURE__*/ proxyCustomElement(class ex
472
488
  "helpText": [1, "help-text"],
473
489
  "dirty": [32],
474
490
  "loading": [32],
475
- "type": [32],
476
491
  "setting": [32],
477
492
  "label": [32],
493
+ "type": [32],
478
494
  "name": [32],
495
+ "required": [32],
479
496
  "roleName": [32],
480
497
  "group": [32],
481
498
  "fieldType": [32],
482
- "required": [32],
483
499
  "options": [32],
484
500
  "placeholder": [32],
485
501
  "value": [32],