@verdocs/web-sdk 1.12.33 → 1.12.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/verdocs-build.cjs.entry.js +13 -3
- package/dist/cjs/verdocs-button-panel_3.cjs.entry.js +6 -1
- package/dist/cjs/verdocs-progress-bar.cjs.entry.js +23 -0
- package/dist/cjs/verdocs-send.cjs.entry.js +5 -3
- package/dist/cjs/verdocs-template-create_3.cjs.entry.js +755 -0
- package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/controls/verdocs-progress-bar/verdocs-progress-bar.css +31 -0
- package/dist/collection/components/controls/verdocs-progress-bar/verdocs-progress-bar.js +84 -0
- package/dist/collection/components/controls/verdocs-progress-bar/verdocs-progress-bar.stories.js +12 -0
- package/dist/collection/components/embeds/verdocs-build/verdocs-build.js +27 -3
- package/dist/collection/components/embeds/verdocs-send/verdocs-send.css +1 -0
- package/dist/collection/components/embeds/verdocs-send/verdocs-send.js +4 -2
- package/dist/collection/components/templates/verdocs-template-create/verdocs-template-create.css +3 -1
- package/dist/collection/components/templates/verdocs-template-create/verdocs-template-create.js +20 -24
- package/dist/collection/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.js +7 -1
- package/dist/collection/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.stories.js +2 -1
- package/dist/collection/components/templates/verdocs-template-fields/verdocs-template-fields.css +2 -0
- package/dist/collection/components/templates/verdocs-template-fields/verdocs-template-fields.stories.js +1 -2
- package/dist/collection/components/templates/verdocs-template-roles/verdocs-template-roles.js +2 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/verdocs-build.js +79 -15
- package/dist/components/verdocs-progress-bar.d.ts +11 -0
- package/dist/components/verdocs-progress-bar.js +6 -0
- package/dist/components/verdocs-progress-bar2.js +38 -0
- package/dist/components/verdocs-send.js +5 -3
- package/dist/components/verdocs-template-create2.js +33 -31
- package/dist/components/verdocs-template-field-properties2.js +7 -1
- package/dist/components/verdocs-template-fields2.js +1 -1
- package/dist/components/verdocs-template-roles.js +1 -374
- package/dist/{esm/verdocs-template-roles.entry.js → components/verdocs-template-roles2.js} +100 -22
- package/dist/docs.json +119 -2
- package/dist/esm/loader.js +1 -1
- package/dist/esm/verdocs-build.entry.js +13 -3
- package/dist/esm/verdocs-button-panel_3.entry.js +6 -1
- package/dist/esm/verdocs-progress-bar.entry.js +19 -0
- package/dist/esm/verdocs-send.entry.js +5 -3
- package/dist/esm/verdocs-template-create_3.entry.js +749 -0
- package/dist/esm/verdocs-web-sdk.js +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/verdocs-build.entry.js +1 -1
- package/dist/esm-es5/verdocs-button-panel_3.entry.js +1 -1
- package/dist/esm-es5/verdocs-progress-bar.entry.js +1 -0
- package/dist/esm-es5/verdocs-send.entry.js +1 -1
- package/dist/esm-es5/verdocs-template-create_3.entry.js +1 -0
- package/dist/esm-es5/verdocs-web-sdk.js +1 -1
- package/dist/types/components/controls/verdocs-progress-bar/verdocs-progress-bar.d.ts +18 -0
- package/dist/types/components/controls/verdocs-progress-bar/verdocs-progress-bar.stories.d.ts +8 -0
- package/dist/types/components/embeds/verdocs-build/verdocs-build.d.ts +6 -0
- package/dist/types/components/templates/verdocs-template-create/verdocs-template-create.d.ts +2 -0
- package/dist/types/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.d.ts +1 -0
- package/dist/types/components.d.ts +41 -0
- package/dist/verdocs-web-sdk/p-2413519c.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-423b6ddf.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-5cf14e4c.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-6caf1137.system.js +1 -1
- package/dist/verdocs-web-sdk/p-6e1e787a.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-a2cd33fd.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-bcc9c2d8.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-c4229602.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-e4b18c52.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-0ba7360f.system.entry.js → p-fdbafc1f.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-fe2ab7b9.entry.js +1 -0
- package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/verdocs-template-create_2.cjs.entry.js +0 -473
- package/dist/cjs/verdocs-template-roles.cjs.entry.js +0 -304
- package/dist/esm/verdocs-template-create_2.entry.js +0 -468
- package/dist/esm-es5/verdocs-template-create_2.entry.js +0 -1
- package/dist/esm-es5/verdocs-template-roles.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-0c5c9ebf.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-13b8ec6f.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-1da14840.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-4ddd2113.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-6f828ccb.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-a2438331.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-baf138a0.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-cd0bdac3.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-e890fc53.entry.js +0 -1
@@ -0,0 +1,749 @@
|
|
1
|
+
import { r as registerInstance, c as createEvent, h, H as Host, F as Fragment, a as getElement } from './index-5260ed60.js';
|
2
|
+
import './Types-6dc82c14.js';
|
3
|
+
import { c as createTemplate, g as getTemplate } from './Templates-8e4ab976.js';
|
4
|
+
import { c as createTemplateDocument } from './TemplateDocuments-618934d0.js';
|
5
|
+
import { V as VerdocsEndpoint, T as TemplateSenderTypes } from './VerdocsEndpoint-d0a126c0.js';
|
6
|
+
import { S as SDKError } from './errors-9b5498c8.js';
|
7
|
+
import { i as interact } from './interact.min-ad5c452f.js';
|
8
|
+
import { u as updateField, c as createField } from './Fields-c82e6df3.js';
|
9
|
+
import { b as getRoleIndex, r as renderDocumentField, e as updateCssTransform, f as defaultWidth, h as defaultHeight } from './utils-9628af35.js';
|
10
|
+
import { s as state } from './templateStore-17c872da.js';
|
11
|
+
import { l as loadTemplate } from './Templates-deedf4bd.js';
|
12
|
+
import { u as updateRole, c as createRole } from './Roles-6eb459df.js';
|
13
|
+
import { g as getRGBA } from './Colors-1b298092.js';
|
14
|
+
import './Envelopes-19a6e456.js';
|
15
|
+
import './Files-70a192df.js';
|
16
|
+
import './index-d264c496.js';
|
17
|
+
import './Primitives-054bc6e5.js';
|
18
|
+
|
19
|
+
const verdocsTemplateCreateCss = "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 svg{width:64px;fill:#5c6575}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}";
|
20
|
+
|
21
|
+
const unicodeNBSP = ' ';
|
22
|
+
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>';
|
23
|
+
const VerdocsTemplateCreate = class {
|
24
|
+
constructor(hostRef) {
|
25
|
+
registerInstance(this, hostRef);
|
26
|
+
this.exit = createEvent(this, "exit", 7);
|
27
|
+
this.next = createEvent(this, "next", 7);
|
28
|
+
this.sdkError = createEvent(this, "sdkError", 7);
|
29
|
+
this.endpoint = VerdocsEndpoint.getDefault();
|
30
|
+
this.file = undefined;
|
31
|
+
this.creating = false;
|
32
|
+
this.progressLabel = 'Uploading...';
|
33
|
+
this.progressPercent = 0;
|
34
|
+
}
|
35
|
+
componentWillLoad() {
|
36
|
+
this.endpoint.setTimeout(30000);
|
37
|
+
this.endpoint.loadSession();
|
38
|
+
}
|
39
|
+
handleFileChanged(e) {
|
40
|
+
var _a;
|
41
|
+
this.file = ((_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0]) || null;
|
42
|
+
console.log('[CREATE] Selected file', this.file);
|
43
|
+
// this.filePath = e.target.files?.[0]?.name;
|
44
|
+
}
|
45
|
+
handleUpload(e) {
|
46
|
+
e.stopPropagation();
|
47
|
+
const fileElem = document.getElementById('verdocs-template-create-file');
|
48
|
+
fileElem.click();
|
49
|
+
}
|
50
|
+
handleCancel(e) {
|
51
|
+
e.stopPropagation();
|
52
|
+
this.exit.emit();
|
53
|
+
}
|
54
|
+
async handleSubmit(e) {
|
55
|
+
var _a, _b, _c, _d;
|
56
|
+
e.stopPropagation();
|
57
|
+
console.log('Submitting');
|
58
|
+
// Should be true if we're here because onClick is only enabled then. We're just guarding this for Typescript.
|
59
|
+
if (!this.file) {
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
this.creating = true;
|
63
|
+
this.progressLabel = 'Uploading...';
|
64
|
+
try {
|
65
|
+
const template = await createTemplate(this.endpoint, { name: this.file.name });
|
66
|
+
console.log('[CREATE] Created template', template);
|
67
|
+
const template_document = await createTemplateDocument(this.endpoint, template.id, this.file, percent => {
|
68
|
+
console.log('Upload progress', percent);
|
69
|
+
this.progressPercent = percent;
|
70
|
+
});
|
71
|
+
console.log('[CREATE] Created document', template_document);
|
72
|
+
this.progressLabel = 'Processing...';
|
73
|
+
this.progressPercent = 0;
|
74
|
+
const finalTemplate = await getTemplate(this.endpoint, template.id);
|
75
|
+
(_a = this.next) === null || _a === void 0 ? void 0 : _a.emit(finalTemplate);
|
76
|
+
this.creating = false;
|
77
|
+
this.progressLabel = '';
|
78
|
+
this.progressPercent = 0;
|
79
|
+
}
|
80
|
+
catch (e) {
|
81
|
+
console.log('[CREATE] Error creating template', e);
|
82
|
+
(_b = this.sdkError) === null || _b === void 0 ? void 0 : _b.emit(new SDKError(e.message, (_c = e.response) === null || _c === void 0 ? void 0 : _c.status, (_d = e.response) === null || _d === void 0 ? void 0 : _d.data));
|
83
|
+
this.creating = false;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
render() {
|
87
|
+
if (!this.endpoint.session) {
|
88
|
+
return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
|
89
|
+
}
|
90
|
+
return (h("form", { onSubmit: e => e.preventDefault(), onClick: e => e.stopPropagation(), autocomplete: "off" }, h("input", { type: "file", id: "verdocs-template-create-file", multiple: true, accept: "application/pdf", 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" }, h("div", null, h("span", { innerHTML: FileIcon })), h("div", { style: { marginTop: '20px', fontSize: '20px', fontWeight: 'bold', overflowWrap: 'anywhere' } }, this.file ? this.file.name : 'Drag a file here'), h("div", { style: {
|
91
|
+
marginTop: '20px',
|
92
|
+
marginBottom: '20px',
|
93
|
+
fontSize: '16px',
|
94
|
+
height: '20px',
|
95
|
+
} }, this.file ? unicodeNBSP : 'Or, if you prefer...'), h("verdocs-button", { label: this.file ? 'Select a different file' : 'Select a file from your computer', size: "small", onClick: e => this.handleUpload(e) }))), 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 }))));
|
96
|
+
}
|
97
|
+
};
|
98
|
+
VerdocsTemplateCreate.style = verdocsTemplateCreateCss;
|
99
|
+
|
100
|
+
const verdocsTemplateFieldsCss = "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 #0000000f;box-shadow:0 0 10px 5px #0000000f}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;-ms-flex:0 0 50px;flex:0 0 50px;-ms-flex-align:center;align-items:center;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:center;justify-content:center;-webkit-column-gap:15px;-moz-column-gap:15px;column-gap:15px;background:#46497d}verdocs-template-fields #verdocs-template-fields-toolbar svg{width:24px;height:24px}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_group{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_button_group{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}";
|
101
|
+
|
102
|
+
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>';
|
103
|
+
const iconTextarea = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" 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"/></svg>';
|
104
|
+
const iconCheck = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" 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"/></svg>';
|
105
|
+
const iconRadio = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" 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"/></svg>';
|
106
|
+
const iconDatepicker = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" 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"/></svg>';
|
107
|
+
const iconSignature = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" 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"/></svg>';
|
108
|
+
const iconInitial = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" d="M6.225 20.775V7h-5V3.225H15V7h-5v13.775Zm9.775 0v-8h-3V9h9.775v3.775h-3v8Z"/></svg>';
|
109
|
+
const iconTimestamp = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path fill="#ffffff" 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"></path></svg>';
|
110
|
+
const iconDropdown = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" stroke-width="1.5" stroke="currentColor"><path stroke="#ffffff" 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" /></svg>';
|
111
|
+
const separator = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14.707 14.707"><g><rect x="6.275" y="0" fill="#ffffff7f" width="1" height="15"/></g></svg>';
|
112
|
+
const menuOptions = [
|
113
|
+
{ id: 'signature', tooltip: 'Signature', icon: iconSignature },
|
114
|
+
{ id: 'initial', tooltip: 'Initials', icon: iconInitial },
|
115
|
+
{ id: 'sep1', tooltip: '', icon: separator },
|
116
|
+
{ id: 'textbox', tooltip: 'Text Box', icon: iconTextbox },
|
117
|
+
{ id: 'textarea', tooltip: 'Text Area', icon: iconTextarea },
|
118
|
+
{ id: 'checkbox_group', tooltip: 'Check Box', icon: iconCheck },
|
119
|
+
{ id: 'radio_button_group', tooltip: 'Radio Button', icon: iconRadio },
|
120
|
+
{ id: 'dropdown', tooltip: 'Dropdown', icon: iconDropdown },
|
121
|
+
{ id: 'sep2', tooltip: '', icon: separator },
|
122
|
+
{ id: 'date', tooltip: 'Date', icon: iconDatepicker },
|
123
|
+
{ id: 'timestamp', tooltip: 'Timestamp', icon: iconTimestamp },
|
124
|
+
// {id: 'sep3', tooltip: '', icon: separator},
|
125
|
+
// {id: 'attachment', tooltip: 'Attachment', icon: 'A'},
|
126
|
+
// {id: 'payment', tooltip: 'Payment', icon: 'P'},
|
127
|
+
];
|
128
|
+
const VerdocsTemplateFields = class {
|
129
|
+
constructor(hostRef) {
|
130
|
+
registerInstance(this, hostRef);
|
131
|
+
this.sdkError = createEvent(this, "sdkError", 7);
|
132
|
+
this.templateUpdated = createEvent(this, "templateUpdated", 7);
|
133
|
+
this.pageHeights = {};
|
134
|
+
this.cachedPageInfo = {};
|
135
|
+
this.endpoint = VerdocsEndpoint.getDefault();
|
136
|
+
this.templateId = null;
|
137
|
+
this.toolbarTargetId = null;
|
138
|
+
this.placing = null;
|
139
|
+
this.selectedRoleName = '';
|
140
|
+
this.rerender = 1;
|
141
|
+
}
|
142
|
+
async componentWillLoad() {
|
143
|
+
var _a, _b, _c, _d, _e, _f;
|
144
|
+
try {
|
145
|
+
this.endpoint.loadSession();
|
146
|
+
if (!this.templateId) {
|
147
|
+
console.log(`[FIELDS] Missing required template ID ${this.templateId}`);
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
if (!this.endpoint.session) {
|
151
|
+
console.log('[BUILD] Unable to start builder session, must be authenticated');
|
152
|
+
return;
|
153
|
+
}
|
154
|
+
try {
|
155
|
+
console.log(`[FIELDS] Loading template ${this.templateId}`, this.endpoint.session);
|
156
|
+
await loadTemplate(this.endpoint, this.templateId, true);
|
157
|
+
this.selectedRoleName = state.roleNames[0];
|
158
|
+
console.log('Starting with role', this.selectedRoleName);
|
159
|
+
}
|
160
|
+
catch (e) {
|
161
|
+
console.log('[FIELDS] Error loading template', e);
|
162
|
+
(_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));
|
163
|
+
}
|
164
|
+
}
|
165
|
+
catch (e) {
|
166
|
+
console.log('[FIELDS] Error with preview session', e);
|
167
|
+
(_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));
|
168
|
+
}
|
169
|
+
}
|
170
|
+
componentDidRender() {
|
171
|
+
interact.dynamicDrop(true);
|
172
|
+
const toolbarTarget = this.toolbarTargetId ? document.getElementById(this.toolbarTargetId) : null;
|
173
|
+
const toolbarEl = document.getElementById('verdocs-template-fields-toolbar');
|
174
|
+
if (toolbarTarget && toolbarEl) {
|
175
|
+
console.log('[FIELDS] Moving toolbar');
|
176
|
+
toolbarEl.remove();
|
177
|
+
toolbarTarget.append(toolbarEl);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
// Stop field-placement mode if ESC is pressed
|
181
|
+
handleKeyDown(ev) {
|
182
|
+
if (ev.key === 'Escape') {
|
183
|
+
this.placing = null;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
async handleFieldChange(field, e, optionId) {
|
187
|
+
console.log('[FIELDS] handleFieldChange', field, e, optionId);
|
188
|
+
this.rerender++;
|
189
|
+
}
|
190
|
+
attachFieldAttributes(pageInfo, field, roleIndex, el) {
|
191
|
+
el.addEventListener('input', e => this.handleFieldChange(field, e));
|
192
|
+
el.addEventListener('settingsChanged', () => {
|
193
|
+
var _a;
|
194
|
+
console.log('Settings', state.fields);
|
195
|
+
this.selectedRoleName = field.role_name;
|
196
|
+
console.log('settings changed', this.selectedRoleName, field);
|
197
|
+
el.setAttribute('roleindex', getRoleIndex(state.roleNames, field.role_name));
|
198
|
+
this.rerender++;
|
199
|
+
el.setAttribute('rerender', this.rerender);
|
200
|
+
(_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: state.template, event: 'updated-field' });
|
201
|
+
});
|
202
|
+
el.addEventListener('deleted', () => {
|
203
|
+
var _a;
|
204
|
+
console.log('deleted', this, field);
|
205
|
+
el.remove();
|
206
|
+
this.rerender++;
|
207
|
+
(_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: state.template, event: 'updated-field' });
|
208
|
+
});
|
209
|
+
el.setAttribute('roleindex', roleIndex);
|
210
|
+
el.setAttribute('pageNumber', pageInfo.pageNumber);
|
211
|
+
el.setAttribute('xScale', pageInfo.xScale);
|
212
|
+
el.setAttribute('yScale', pageInfo.yScale);
|
213
|
+
el.setAttribute('name', field.name);
|
214
|
+
}
|
215
|
+
handlePageRendered(e) {
|
216
|
+
const pageInfo = e.detail;
|
217
|
+
console.log('[FIELDS] Page rendered', pageInfo.pageNumber, pageInfo);
|
218
|
+
this.cachedPageInfo[pageInfo.pageNumber] = pageInfo;
|
219
|
+
this.pageHeights[pageInfo.pageNumber] = pageInfo.naturalHeight;
|
220
|
+
const fields = state.fields.filter(field => field.page_sequence === pageInfo.pageNumber);
|
221
|
+
// const fields = this.fields.filter(field => field.page_sequence === pageInfo.renderedPage.pageNumber);
|
222
|
+
// console.log('[FIELDS] Fields on page', fields);
|
223
|
+
fields.forEach(field => {
|
224
|
+
const roleIndex = getRoleIndex(state.roleNames, field.role_name);
|
225
|
+
const el = renderDocumentField(field, pageInfo, roleIndex, { disabled: true, editable: true, draggable: true });
|
226
|
+
if (!el) {
|
227
|
+
return;
|
228
|
+
}
|
229
|
+
if (Array.isArray(el)) {
|
230
|
+
el.forEach(e => {
|
231
|
+
this.attachFieldAttributes(pageInfo, field, roleIndex, e);
|
232
|
+
interact(e).draggable({
|
233
|
+
listeners: {
|
234
|
+
start(event) {
|
235
|
+
console.log('[FIELDS] Drag started', event.type, event.target);
|
236
|
+
},
|
237
|
+
move(event) {
|
238
|
+
const oldX = +(event.target.getAttribute('posX') || 0);
|
239
|
+
const oldY = +(event.target.getAttribute('posY') || 0);
|
240
|
+
const xScale = +(event.target.getAttribute('xScale') || 1);
|
241
|
+
const yScale = +(event.target.getAttribute('yScale') || 1);
|
242
|
+
const newX = event.dx / xScale + oldX;
|
243
|
+
const newY = event.dy / yScale + oldY;
|
244
|
+
event.target.setAttribute('posX', newX);
|
245
|
+
event.target.setAttribute('posy', newY);
|
246
|
+
updateCssTransform(event.target, 'translate', `${newX}px, ${newY}px`);
|
247
|
+
},
|
248
|
+
end: this.handleMoveField.bind(this),
|
249
|
+
},
|
250
|
+
});
|
251
|
+
});
|
252
|
+
}
|
253
|
+
else {
|
254
|
+
this.attachFieldAttributes(pageInfo, field, roleIndex, el);
|
255
|
+
interact(el).draggable({
|
256
|
+
listeners: {
|
257
|
+
start(event) {
|
258
|
+
console.log('[FIELDS] Drag started', event.type, event.target);
|
259
|
+
},
|
260
|
+
move(event) {
|
261
|
+
const oldX = +(event.target.getAttribute('posX') || 0);
|
262
|
+
const oldY = +(event.target.getAttribute('posY') || 0);
|
263
|
+
const xScale = +(event.target.getAttribute('xScale') || 1);
|
264
|
+
const yScale = +(event.target.getAttribute('yScale') || 1);
|
265
|
+
const newX = event.dx / xScale + oldX;
|
266
|
+
const newY = event.dy / yScale + oldY;
|
267
|
+
event.target.setAttribute('posX', newX);
|
268
|
+
event.target.setAttribute('posy', newY);
|
269
|
+
updateCssTransform(event.target, 'translate', `${newX}px, ${newY}px`);
|
270
|
+
},
|
271
|
+
end: this.handleMoveField.bind(this),
|
272
|
+
},
|
273
|
+
});
|
274
|
+
}
|
275
|
+
});
|
276
|
+
}
|
277
|
+
async handleMoveField(e) {
|
278
|
+
const pageNumber = e.target.getAttribute('pageNumber');
|
279
|
+
const { naturalWidth = 612, naturalHeight = 792, renderedHeight = 792 } = this.cachedPageInfo[pageNumber];
|
280
|
+
console.log('[FIELDS] Drag ended', pageNumber, e.target);
|
281
|
+
const clientRect = e.target.getBoundingClientRect();
|
282
|
+
const parent = e.target.parentElement;
|
283
|
+
const parentRect = parent.getBoundingClientRect();
|
284
|
+
// These two being backwards is not a mistake. Left measures "over" from the left (positive displacement) while bottom measures
|
285
|
+
// "up" from the bottom (negative displacement).
|
286
|
+
const newX = Math.max(clientRect.left - parentRect.left, 0);
|
287
|
+
const newY = Math.max(renderedHeight - (parentRect.bottom - clientRect.bottom), 0);
|
288
|
+
const { x, y } = this.viewCoordinatesToPageCoordinates(newX, newY, pageNumber, naturalWidth - e.rect.width, naturalHeight - e.rect.height);
|
289
|
+
const name = e.target.getAttribute('name');
|
290
|
+
const option = +(e.target.getAttribute('option') || '0');
|
291
|
+
const field = state.fields.find(field => field.name === name);
|
292
|
+
console.log('Will update', name, option, field);
|
293
|
+
if (field) {
|
294
|
+
switch (field.type) {
|
295
|
+
case 'attachment':
|
296
|
+
case 'payment':
|
297
|
+
case 'initial':
|
298
|
+
case 'signature':
|
299
|
+
case 'date':
|
300
|
+
case 'dropdown':
|
301
|
+
case 'textarea':
|
302
|
+
case 'textbox':
|
303
|
+
case 'timestamp':
|
304
|
+
field.setting.x = x;
|
305
|
+
field.setting.y = y;
|
306
|
+
break;
|
307
|
+
case 'checkbox_group':
|
308
|
+
case 'radio_button_group':
|
309
|
+
{
|
310
|
+
const opt = field.setting.options[option];
|
311
|
+
if (opt) {
|
312
|
+
opt.x = x;
|
313
|
+
opt.y = y;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
break;
|
317
|
+
}
|
318
|
+
await updateField(this.endpoint, this.templateId, name, field);
|
319
|
+
this.handlePageRendered({ detail: this.cachedPageInfo[pageNumber] });
|
320
|
+
}
|
321
|
+
}
|
322
|
+
generateFieldName(type, pageNumber) {
|
323
|
+
let i = 1;
|
324
|
+
let fieldName;
|
325
|
+
do {
|
326
|
+
fieldName = `${type}P${pageNumber}-${i}`;
|
327
|
+
console.log('testing field', fieldName);
|
328
|
+
i++;
|
329
|
+
} while (state.fields.some(field => field.name === fieldName));
|
330
|
+
console.log('Will use field name', fieldName, state.fields);
|
331
|
+
return fieldName;
|
332
|
+
}
|
333
|
+
// Scale the X,Y clicks to the virtual page dimensions. Also ensure the field doesn't go off the page.
|
334
|
+
viewCoordinatesToPageCoordinates(viewX, viewY, pageNumber, xMax, yMax) {
|
335
|
+
const { xScale = 1, yScale = 1, renderedHeight = 792 } = this.cachedPageInfo[pageNumber];
|
336
|
+
const x = Math.floor(Math.min(viewX / xScale, xMax));
|
337
|
+
const y = Math.floor(Math.min(Math.max(renderedHeight - viewY, 0) / yScale, yMax));
|
338
|
+
return { x, y };
|
339
|
+
}
|
340
|
+
async handleClickPage(e, page) {
|
341
|
+
var _a;
|
342
|
+
if (this.placing) {
|
343
|
+
console.log('Placing field', this.placing, page.sequence, e.offsetX, e.offsetY);
|
344
|
+
const pageNumber = page.sequence;
|
345
|
+
const clickedX = e.offsetX;
|
346
|
+
const clickedY = e.offsetY;
|
347
|
+
const width = defaultWidth(this.placing);
|
348
|
+
const height = defaultHeight(this.placing);
|
349
|
+
const cachedPage = this.cachedPageInfo[pageNumber];
|
350
|
+
console.log('Cached page', cachedPage);
|
351
|
+
const { naturalWidth = 612, naturalHeight = 792 } = cachedPage;
|
352
|
+
const coords = this.viewCoordinatesToPageCoordinates(clickedX, clickedY, pageNumber, naturalWidth - width, naturalHeight - height);
|
353
|
+
const x = Math.floor(coords.x);
|
354
|
+
const y = Math.floor(coords.y);
|
355
|
+
const field = {
|
356
|
+
name: this.generateFieldName(this.placing, pageNumber),
|
357
|
+
role_name: this.selectedRoleName,
|
358
|
+
template_id: this.templateId,
|
359
|
+
type: this.placing,
|
360
|
+
required: true,
|
361
|
+
page_sequence: pageNumber,
|
362
|
+
validator: null,
|
363
|
+
setting: { x, y }, // In the future, this is all we should send, see below
|
364
|
+
};
|
365
|
+
// TODO: Fix how the server validates all this. It uses a JSON schema and is very particular about shapes for each field type.
|
366
|
+
// That makes it harder for third party developers to create fields via API calls. It would be better to always set X/Y and
|
367
|
+
// let the server normalize the rest, discarding properties that are invalid and back-filling defaults as needed.
|
368
|
+
switch (field.type) {
|
369
|
+
case 'attachment':
|
370
|
+
case 'payment':
|
371
|
+
field.setting = { x, y };
|
372
|
+
break;
|
373
|
+
case 'initial':
|
374
|
+
case 'signature':
|
375
|
+
field.setting = { x, y, result: '' };
|
376
|
+
break;
|
377
|
+
case 'checkbox_group':
|
378
|
+
// @ts-ignore
|
379
|
+
field.setting = {
|
380
|
+
minimum_checked: 0,
|
381
|
+
maximum_checked: 1000,
|
382
|
+
options: [
|
383
|
+
{
|
384
|
+
id: `${field.name}-1`,
|
385
|
+
value: 'Option 1',
|
386
|
+
checked: false,
|
387
|
+
x,
|
388
|
+
y,
|
389
|
+
},
|
390
|
+
],
|
391
|
+
};
|
392
|
+
break;
|
393
|
+
case 'date':
|
394
|
+
field.setting = { x, y, width, height, result: '' };
|
395
|
+
break;
|
396
|
+
// TODO: What is this?
|
397
|
+
// case 'placeholder':break;
|
398
|
+
case 'dropdown':
|
399
|
+
field.required = false;
|
400
|
+
field.setting = { x, y, width, height, value: null, placeholder: 'Choose', options: [{ id: 'option-1', value: 'Option 1' }] };
|
401
|
+
break;
|
402
|
+
case 'radio_button_group':
|
403
|
+
// @ts-ignore
|
404
|
+
field.setting = {
|
405
|
+
options: [
|
406
|
+
{
|
407
|
+
id: `${field.name}-1`,
|
408
|
+
value: 'Option 1',
|
409
|
+
selected: false,
|
410
|
+
x,
|
411
|
+
y,
|
412
|
+
},
|
413
|
+
],
|
414
|
+
};
|
415
|
+
break;
|
416
|
+
// TODO: What about textareas?
|
417
|
+
case 'textarea':
|
418
|
+
case 'textbox':
|
419
|
+
field.setting = { x, y, width, height, result: '', leading: 0, alignment: 0, upperCase: false };
|
420
|
+
break;
|
421
|
+
case 'timestamp':
|
422
|
+
field.setting = { x, y, width, height };
|
423
|
+
break;
|
424
|
+
}
|
425
|
+
// ??? We don't actually have a unique field type for multi-line text?
|
426
|
+
if (field.type === 'textarea') {
|
427
|
+
field.type = 'textbox';
|
428
|
+
}
|
429
|
+
const saved = await createField(this.endpoint, this.templateId, field);
|
430
|
+
console.log('Saved field', saved);
|
431
|
+
state.fields.push(saved);
|
432
|
+
this.placing = null;
|
433
|
+
(_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, template: state.template, event: 'added-field' });
|
434
|
+
this.handlePageRendered({ detail: this.cachedPageInfo[pageNumber] });
|
435
|
+
}
|
436
|
+
}
|
437
|
+
render() {
|
438
|
+
if (!this.endpoint.session) {
|
439
|
+
return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
|
440
|
+
}
|
441
|
+
// TODO: Render a better error
|
442
|
+
if (state.loading || !state.template) {
|
443
|
+
return (h(Host, null, h("verdocs-loader", null)));
|
444
|
+
}
|
445
|
+
const pages = [...state.template.pages];
|
446
|
+
pages.sort((a, b) => a.sequence - b.sequence);
|
447
|
+
return (h(Host, { class: this.placing ? { [`placing-${this.placing}`]: true } : {}, "data-r": this.rerender, onSubmit: () => {
|
448
|
+
console.log('onSubmit');
|
449
|
+
} }, h("div", { id: "verdocs-template-fields-toolbar" }, menuOptions.map(option => (h("verdocs-toolbar-icon", { text: option.tooltip, icon: option.icon, onClick: () => {
|
450
|
+
if (option.tooltip) {
|
451
|
+
// We have empty tooltips on the separators, quick hack...
|
452
|
+
this.placing = option.id;
|
453
|
+
}
|
454
|
+
} })))), h("div", { class: "pages" }, pages.map(page => {
|
455
|
+
return (h("verdocs-template-document-page", { templateId: page.template_id, documentId: page.document_id, pageNumber: page.sequence, virtualWidth: 612, virtualHeight: 792, onClick: (e) => this.handleClickPage(e, page), onPageRendered: e => this.handlePageRendered(e), layers: [
|
456
|
+
{ name: 'page', type: 'canvas' },
|
457
|
+
{ name: 'controls', type: 'div' },
|
458
|
+
] }));
|
459
|
+
}))));
|
460
|
+
}
|
461
|
+
};
|
462
|
+
VerdocsTemplateFields.style = verdocsTemplateFieldsCss;
|
463
|
+
|
464
|
+
const verdocsTemplateRolesCss = "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:#4c56cb;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-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;display:-ms-flexbox;display:flex;-webkit-column-gap:10px;-moz-column-gap:10px;column-gap:10px;-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 5px 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:#654dcb7f;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:#654dcb7f;-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:20px;height:20px;stroke:#666666;margin-bottom:-5px}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}";
|
465
|
+
|
466
|
+
const senderLabels = {
|
467
|
+
[TemplateSenderTypes.EVERYONE]: 'Everyone',
|
468
|
+
[TemplateSenderTypes.EVERYONE_AS_CREATOR]: 'Everyone as Me',
|
469
|
+
[TemplateSenderTypes.ORGANIZATION_MEMBER]: 'Organization member',
|
470
|
+
[TemplateSenderTypes.ORGANIZATION_MEMBER_AS_CREATOR]: 'Organization Member as Me',
|
471
|
+
[TemplateSenderTypes.CREATOR]: 'Me',
|
472
|
+
};
|
473
|
+
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>';
|
474
|
+
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>';
|
475
|
+
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>';
|
476
|
+
const doneIcon = '<svg focusable="false" aria-hidden="true" viewBox="0 0 24 24" fill="#00000089"><path d="m18 7-1.41-1.41-6.34 6.34 1.41 1.41L18 7zm4.24-1.41L11.66 16.17 7.48 12l-1.41 1.41L11.66 19l12-12-1.42-1.41zM.41 13.41 6 19l1.41-1.41L1.83 12 .41 13.41z"></path></svg>';
|
477
|
+
const plusIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="#ffffff" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" d="M12 9v6m3-3H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>`;
|
478
|
+
const iconSigner = '<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><path 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"/></svg>';
|
479
|
+
const iconApprover = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm13.36-1.814a.75.75 0 10-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.14-.094l3.75-5.25z" clip-rule="evenodd" /></svg>`;
|
480
|
+
const iconCC = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M1.5 8.67v8.58a3 3 0 003 3h15a3 3 0 003-3V8.67l-8.928 5.493a3 3 0 01-3.144 0L1.5 8.67z" /><path d="M22.5 6.908V6.75a3 3 0 00-3-3h-15a3 3 0 00-3 3v.158l9.714 5.978a1.5 1.5 0 001.572 0L22.5 6.908z" /></svg>`;
|
481
|
+
const VerdocsTemplateRoles = class {
|
482
|
+
constructor(hostRef) {
|
483
|
+
registerInstance(this, hostRef);
|
484
|
+
this.next = createEvent(this, "next", 7);
|
485
|
+
this.exit = createEvent(this, "exit", 7);
|
486
|
+
this.sdkError = createEvent(this, "sdkError", 7);
|
487
|
+
this.templateUpdated = createEvent(this, "templateUpdated", 7);
|
488
|
+
this.sequences = [];
|
489
|
+
this.endpoint = VerdocsEndpoint.getDefault();
|
490
|
+
this.templateId = '';
|
491
|
+
this.showingRoleDialog = null;
|
492
|
+
this.showingSenderDialog = false;
|
493
|
+
this.sender = null;
|
494
|
+
this.forceRerender = 1;
|
495
|
+
}
|
496
|
+
async componentWillLoad() {
|
497
|
+
var _a, _b, _c, _d, _e, _f;
|
498
|
+
try {
|
499
|
+
this.endpoint.loadSession();
|
500
|
+
if (!this.templateId) {
|
501
|
+
console.log(`[ROLES] Missing required template ID ${this.templateId}`);
|
502
|
+
return;
|
503
|
+
}
|
504
|
+
if (!this.endpoint.session) {
|
505
|
+
console.log('[ROLES] Unable to start builder session, must be authenticated');
|
506
|
+
return;
|
507
|
+
}
|
508
|
+
try {
|
509
|
+
console.log(`[ROLES] Loading template ${this.templateId}`, this.endpoint.session);
|
510
|
+
await loadTemplate(this.endpoint, this.templateId, true);
|
511
|
+
}
|
512
|
+
catch (e) {
|
513
|
+
console.log('[ROLES] Error loading template', e);
|
514
|
+
(_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));
|
515
|
+
}
|
516
|
+
this.sortTemplateRoles();
|
517
|
+
this.renumberTemplateRoles();
|
518
|
+
}
|
519
|
+
catch (e) {
|
520
|
+
console.log('[FIELDS] Error with preview session', e);
|
521
|
+
(_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));
|
522
|
+
}
|
523
|
+
}
|
524
|
+
componentDidRender() {
|
525
|
+
interact.dynamicDrop(true);
|
526
|
+
interact('.recipient').draggable({
|
527
|
+
listeners: {
|
528
|
+
start: function handleStart(e) {
|
529
|
+
e.target.classList.add('dragging');
|
530
|
+
this.el.classList.add('dragging');
|
531
|
+
}.bind(this),
|
532
|
+
move: function handleMove(e) {
|
533
|
+
const oldX = +(e.target.getAttribute('posX') || 0);
|
534
|
+
const oldY = +(e.target.getAttribute('posY') || 0);
|
535
|
+
const newX = e.dx + oldX;
|
536
|
+
const newY = e.dy + oldY;
|
537
|
+
e.target.setAttribute('posX', newX);
|
538
|
+
e.target.setAttribute('posy', newY);
|
539
|
+
e.target.style.transform = `translate(${newX + 100}px, ${newY - 40}px)`;
|
540
|
+
}.bind(this),
|
541
|
+
end: function handleEnd(e) {
|
542
|
+
e.target.classList.remove('dragging');
|
543
|
+
this.el.classList.remove('dragging');
|
544
|
+
// console.log('end', event);
|
545
|
+
e.target.setAttribute('posX', 0);
|
546
|
+
e.target.setAttribute('posy', 0);
|
547
|
+
e.target.style.transform = `translate(0px, 0px)`;
|
548
|
+
}.bind(this),
|
549
|
+
},
|
550
|
+
});
|
551
|
+
interact('.dropzone').dropzone({
|
552
|
+
overlap: 0.05,
|
553
|
+
ondrop: function handleDrop(event) {
|
554
|
+
var _a, _b;
|
555
|
+
event.target.classList.remove('active');
|
556
|
+
// target will be the recipient e.g. <div class="recipient" data-rolename="Buyer" />
|
557
|
+
// relatedTarget will be the drop zone, e.g. <div class="dropzone" data-order="2" data-sequence="1" />
|
558
|
+
// console.log(event.relatedTarget, ' was dropped into ', event.target);
|
559
|
+
// We don't use the role's own order, we rely on the fact that we sorted earlier on the order field. Many legacy
|
560
|
+
// records don't have order fields yet - they're all 1. That doesn't hurt the sort but it would hurt us here if it
|
561
|
+
// went 1..1..1 instead of 1..2..3. By using half values here it's easier to handle the drop event later. We don't
|
562
|
+
// need to do a fancy find/arraymove dance. We just set the dropped element to the half value, sort the result,
|
563
|
+
// then do a final renumber. It's not expensive to do because most flows are typically a small handful (e.g. 1-4)
|
564
|
+
// recipients. They never have hundreds.
|
565
|
+
const roleName = event.relatedTarget.dataset.rolename;
|
566
|
+
const targetSequence = +event.target.dataset.sequence;
|
567
|
+
const targetOrder = +event.target.dataset.order;
|
568
|
+
const changingRole = (_a = state.template) === null || _a === void 0 ? void 0 : _a.roles.find(role => role.name === roleName);
|
569
|
+
if (changingRole) {
|
570
|
+
// To handle the renumbering, we update the role being moved to the new values, which will be some half-interval e.g.
|
571
|
+
// sequence 1.5 order 1. Then we
|
572
|
+
changingRole.sequence = targetSequence;
|
573
|
+
changingRole.order = targetOrder;
|
574
|
+
this.sortTemplateRoles();
|
575
|
+
this.renumberTemplateRoles();
|
576
|
+
this.forceRerender++;
|
577
|
+
// We have to update ALL the roles to be sure each gets new proper sequence/order numbers assigned.
|
578
|
+
// TODO: We could optimize this by tracking "dirty" states and only update the roles that have changed. But it's a LOT more
|
579
|
+
// code to do right, and since most workflows will typically only have 2-4 recipients max, it may not be worth it.
|
580
|
+
Promise.all((_b = state.template) === null || _b === void 0 ? void 0 : _b.roles.map(role => updateRole(this.endpoint, this.templateId, role.name, {
|
581
|
+
sequence: role.sequence,
|
582
|
+
order: role.order,
|
583
|
+
})))
|
584
|
+
.then(() => {
|
585
|
+
var _a;
|
586
|
+
console.log('[ROLES] Updated roles');
|
587
|
+
(_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'updated-role', endpoint: this.endpoint, template: state.template });
|
588
|
+
})
|
589
|
+
.catch(e => console.log('[ROLES] Role updates failed', e));
|
590
|
+
}
|
591
|
+
}.bind(this),
|
592
|
+
ondropactivate: e => {
|
593
|
+
e.target.classList.add('visible');
|
594
|
+
},
|
595
|
+
ondropdeactivate: e => {
|
596
|
+
e.target.classList.remove('visible');
|
597
|
+
},
|
598
|
+
ondragenter: e => {
|
599
|
+
e.target.classList.add('active');
|
600
|
+
},
|
601
|
+
ondragleave: e => {
|
602
|
+
e.target.classList.remove('active');
|
603
|
+
},
|
604
|
+
});
|
605
|
+
}
|
606
|
+
handleCancel(e) {
|
607
|
+
var _a;
|
608
|
+
e.stopPropagation();
|
609
|
+
(_a = this.exit) === null || _a === void 0 ? void 0 : _a.emit();
|
610
|
+
}
|
611
|
+
handleSubmit(e) {
|
612
|
+
var _a;
|
613
|
+
e.stopPropagation();
|
614
|
+
(_a = this.next) === null || _a === void 0 ? void 0 : _a.emit();
|
615
|
+
}
|
616
|
+
sortTemplateRoles() {
|
617
|
+
var _a;
|
618
|
+
(_a = state.template) === null || _a === void 0 ? void 0 : _a.roles.sort((a, b) => {
|
619
|
+
return a.sequence === b.sequence ? a.order - b.order : a.sequence - b.sequence;
|
620
|
+
});
|
621
|
+
}
|
622
|
+
extractSequenceNumbers() {
|
623
|
+
var _a;
|
624
|
+
this.sequences = [];
|
625
|
+
(_a = state.template) === null || _a === void 0 ? void 0 : _a.roles.forEach(role => {
|
626
|
+
if (!this.sequences.includes(role.sequence)) {
|
627
|
+
this.sequences.push(role.sequence);
|
628
|
+
}
|
629
|
+
});
|
630
|
+
}
|
631
|
+
renumberTemplateRoles() {
|
632
|
+
// Extract the sequence numbers because they may now be something like [2.5, 1, 2]
|
633
|
+
this.extractSequenceNumbers();
|
634
|
+
// We need to renumber each role only ONE TIME
|
635
|
+
const renumbered = [];
|
636
|
+
// If the user dragged an entry from below a row to above it, we end up here like [1,0]. Make sure it's [0,1] for the next operation.
|
637
|
+
this.sequences.sort((a, b) => a - b);
|
638
|
+
this.sequences.forEach((originalSequence, newSequenceIndex) => {
|
639
|
+
var _a;
|
640
|
+
(_a = state.template) === null || _a === void 0 ? void 0 : _a.roles.filter(role => role.sequence === originalSequence).forEach((role, newOrderIndex) => {
|
641
|
+
if (!renumbered.includes(role.name)) {
|
642
|
+
role.sequence = newSequenceIndex + 1;
|
643
|
+
role.order = newOrderIndex + 1;
|
644
|
+
renumbered.push(role.name);
|
645
|
+
}
|
646
|
+
});
|
647
|
+
});
|
648
|
+
// Now re-extract them to get our final result e.g. [1, 2, 3]
|
649
|
+
this.extractSequenceNumbers();
|
650
|
+
}
|
651
|
+
// Look for name conflicts, because they're UGC and can be anything, regardless of order.
|
652
|
+
getNextRoleName() {
|
653
|
+
var _a, _b;
|
654
|
+
let name = '';
|
655
|
+
let nextNumber = (_a = state.template) === null || _a === void 0 ? void 0 : _a.roles.length;
|
656
|
+
do {
|
657
|
+
nextNumber++;
|
658
|
+
name = `Recipient ${nextNumber}`;
|
659
|
+
} while (!name || ((_b = state.template) === null || _b === void 0 ? void 0 : _b.roles.some(role => role.name === name)));
|
660
|
+
return name;
|
661
|
+
}
|
662
|
+
handleAddRole(e, sequence) {
|
663
|
+
e.stopPropagation();
|
664
|
+
// We don't need to look for a unique order number because we're already working with a sorted/renumbered set by now.
|
665
|
+
const order = state.template.roles.filter(role => role.sequence === sequence).length + 1;
|
666
|
+
const name = this.getNextRoleName();
|
667
|
+
console.log('Will create', name, sequence, order);
|
668
|
+
createRole(this.endpoint, this.templateId, {
|
669
|
+
template_id: this.templateId,
|
670
|
+
name,
|
671
|
+
full_name: '',
|
672
|
+
email: '',
|
673
|
+
phone: '',
|
674
|
+
sequence,
|
675
|
+
order,
|
676
|
+
type: 'signer',
|
677
|
+
delegator: false,
|
678
|
+
})
|
679
|
+
.then(r => {
|
680
|
+
var _a;
|
681
|
+
console.log('Created role', r);
|
682
|
+
state.template.roles.push(r);
|
683
|
+
this.renumberTemplateRoles();
|
684
|
+
this.forceRerender++;
|
685
|
+
(_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'created-role', endpoint: this.endpoint, template: state.template });
|
686
|
+
})
|
687
|
+
.catch(e => {
|
688
|
+
console.log('Error creating role', e);
|
689
|
+
});
|
690
|
+
}
|
691
|
+
handleAddStep(e, sequence) {
|
692
|
+
e.stopPropagation();
|
693
|
+
const order = 1;
|
694
|
+
const name = this.getNextRoleName();
|
695
|
+
console.log('Will create', name, sequence, order);
|
696
|
+
createRole(this.endpoint, this.templateId, {
|
697
|
+
template_id: this.templateId,
|
698
|
+
name,
|
699
|
+
full_name: '',
|
700
|
+
email: '',
|
701
|
+
phone: '',
|
702
|
+
sequence,
|
703
|
+
order,
|
704
|
+
type: 'signer',
|
705
|
+
delegator: false,
|
706
|
+
})
|
707
|
+
.then(r => {
|
708
|
+
var _a;
|
709
|
+
console.log('Created role', r);
|
710
|
+
state.template.roles.push(r);
|
711
|
+
this.renumberTemplateRoles();
|
712
|
+
this.forceRerender++;
|
713
|
+
(_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'created-role', endpoint: this.endpoint, template: state.template });
|
714
|
+
})
|
715
|
+
.catch(e => {
|
716
|
+
console.log('Error creating role', e);
|
717
|
+
});
|
718
|
+
}
|
719
|
+
render() {
|
720
|
+
var _a;
|
721
|
+
if (!this.endpoint.session) {
|
722
|
+
return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
|
723
|
+
}
|
724
|
+
if (state.loading || !state.template) {
|
725
|
+
return (h(Host, null, h("verdocs-loader", null)));
|
726
|
+
}
|
727
|
+
const roleNames = (((_a = state.template) === null || _a === void 0 ? void 0 : _a.roles) || []).map(role => role.name);
|
728
|
+
return (h(Host, null, h("form", { onSubmit: e => e.preventDefault(), onClick: e => e.stopPropagation(), autocomplete: "off", "data-r": this.forceRerender }, 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" }, "Sender:"), " ", senderLabels[state.template.sender], ' ', h("div", { class: "settings-button", innerHTML: settingsIcon, onClick: () => (this.showingSenderDialog = true), "aria-role": "button" })))), 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"))), this.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 }), state.template.roles
|
729
|
+
.filter(role => role.sequence === sequence)
|
730
|
+
.map(role => {
|
731
|
+
const unknown = !role.email;
|
732
|
+
return unknown ? (h(Fragment, null, h("div", { class: "recipient", style: { backgroundColor: getRGBA(getRoleIndex(roleNames, role.name)) }, "data-rolename": role.name }, 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(roleNames, role.name)) }, "data-rolename": role.name }, h("span", { class: "type-icon", innerHTML: role.type === 'signer' ? iconSigner : role.type === 'cc' ? iconCC : iconApprover }), role.full_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 })));
|
733
|
+
}), h("button", { class: "add-role", innerHTML: plusIcon, onClick: e => this.handleAddRole(e, sequence) }))), this.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": this.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, this.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: e => this.handleCancel(e) }), h("verdocs-button", { label: "OK", size: "small", onClick: e => this.handleSubmit(e), disabled: roleNames.length < 1 }))), this.showingRoleDialog && (h("verdocs-template-role-properties", { endpoint: this.endpoint, templateId: this.templateId, roleName: this.showingRoleDialog, onClose: () => {
|
734
|
+
this.showingRoleDialog = null;
|
735
|
+
this.forceRerender++;
|
736
|
+
}, onDelete: e => {
|
737
|
+
var _a;
|
738
|
+
console.log('deleted', e.detail);
|
739
|
+
this.renumberTemplateRoles();
|
740
|
+
this.showingRoleDialog = null;
|
741
|
+
this.forceRerender++;
|
742
|
+
(_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit({ event: 'deleted-role', endpoint: this.endpoint, template: state.template });
|
743
|
+
} })), this.showingSenderDialog && h("verdocs-template-sender", { endpoint: this.endpoint, templateId: this.templateId, onClose: () => (this.showingSenderDialog = false) })));
|
744
|
+
}
|
745
|
+
get el() { return getElement(this); }
|
746
|
+
};
|
747
|
+
VerdocsTemplateRoles.style = verdocsTemplateRolesCss;
|
748
|
+
|
749
|
+
export { VerdocsTemplateCreate as verdocs_template_create, VerdocsTemplateFields as verdocs_template_fields, VerdocsTemplateRoles as verdocs_template_roles };
|