@verdocs/web-sdk 4.2.158 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Datastore-b1742da2.js +1783 -0
- package/dist/cjs/{index-2589e4d1.js → index-ccac8641.js} +11 -27
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/{utils-6d673ca1.js → utils-ba1e95e0.js} +3 -2
- package/dist/cjs/verdocs-auth.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-build.cjs.entry.js +22 -13
- package/dist/cjs/verdocs-button-panel_2.cjs.entry.js +1 -1
- package/dist/cjs/{verdocs-button_3.cjs.entry.js → verdocs-button_2.cjs.entry.js} +1 -56
- package/dist/cjs/{verdocs-checkbox_4.cjs.entry.js → verdocs-checkbox_6.cjs.entry.js} +115 -24
- package/dist/cjs/verdocs-contact-picker_2.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-dialog.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-dropdown.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-envelope-document-page.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-envelope-recipient-link_2.cjs.entry.js +30 -15
- package/dist/cjs/verdocs-envelope-recipient-summary.cjs.entry.js +32 -17
- package/dist/cjs/verdocs-envelope-sidebar.cjs.entry.js +64 -45
- package/dist/cjs/verdocs-envelopes-list.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-field-attachment_13.cjs.entry.js +104 -155
- package/dist/cjs/verdocs-field-payment.cjs.entry.js +38 -25
- package/dist/cjs/verdocs-file-chooser_2.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-kba-dialog_2.cjs.entry.js +27 -5
- package/dist/cjs/verdocs-ok-dialog.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-organization-card_2.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-pagination_2.cjs.entry.js +2 -2
- package/dist/cjs/{verdocs-preview_9.cjs.entry.js → verdocs-preview_6.cjs.entry.js} +252 -469
- package/dist/cjs/verdocs-quick-functions.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-radio-button.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-search-box.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-search-tabs.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-sign.cjs.entry.js +11 -12
- package/dist/cjs/verdocs-spinner.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-status-indicator.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-table.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-template-card.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-template-create.cjs.entry.js +108 -0
- package/dist/cjs/verdocs-template-document-page_2.cjs.entry.js +78 -63
- package/dist/cjs/verdocs-template-role-properties.cjs.entry.js +58 -37
- package/dist/cjs/verdocs-template-star.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-template-tags.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-templates-list.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-toggle.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-web-sdk.cjs.js +3 -3
- package/dist/collection/collection-manifest.json +2 -4
- package/dist/collection/components/controls/verdocs-text-input/verdocs-text-input.js +5 -21
- package/dist/collection/components/embeds/verdocs-build/verdocs-build.js +27 -40
- package/dist/collection/components/embeds/verdocs-preview/verdocs-preview.js +27 -28
- package/dist/collection/components/embeds/verdocs-send/verdocs-send.js +45 -44
- package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.js +12 -11
- package/dist/collection/components/embeds/verdocs-view/verdocs-view.js +28 -28
- package/dist/collection/components/envelopes/verdocs-envelope-recipient-link/verdocs-envelope-recipient-link.js +34 -15
- package/dist/collection/components/envelopes/verdocs-envelope-recipient-summary/verdocs-envelope-recipient-summary.js +35 -17
- package/dist/collection/components/envelopes/verdocs-envelope-sidebar/verdocs-envelope-sidebar.js +67 -45
- package/dist/collection/components/fields/verdocs-field-attachment/verdocs-field-attachment.js +29 -18
- package/dist/collection/components/fields/verdocs-field-checkbox/verdocs-field-checkbox.js +30 -20
- package/dist/collection/components/fields/verdocs-field-date/verdocs-field-date.js +30 -22
- package/dist/collection/components/fields/verdocs-field-dropdown/verdocs-field-dropdown.js +29 -17
- package/dist/collection/components/fields/verdocs-field-initial/verdocs-field-initial.js +30 -18
- package/dist/collection/components/fields/verdocs-field-payment/verdocs-field-payment.js +192 -139
- package/dist/collection/components/fields/verdocs-field-radio/verdocs-field-radio.js +30 -20
- package/dist/collection/components/fields/verdocs-field-signature/verdocs-field-signature.js +30 -18
- package/dist/collection/components/fields/verdocs-field-textarea/verdocs-field-textarea.js +31 -19
- package/dist/collection/components/fields/verdocs-field-textbox/verdocs-field-textbox.css +31 -0
- package/dist/collection/components/fields/verdocs-field-textbox/verdocs-field-textbox.js +44 -44
- package/dist/collection/components/fields/verdocs-field-timestamp/verdocs-field-timestamp.js +29 -17
- package/dist/collection/components/templates/verdocs-template-attachments/verdocs-template-attachments.js +37 -17
- package/dist/collection/components/templates/verdocs-template-build-tabs/verdocs-template-build-tabs.js +37 -32
- package/dist/collection/components/templates/verdocs-template-create/verdocs-template-create.js +7 -15
- package/dist/collection/components/templates/verdocs-template-document-page/verdocs-template-document-page.css +6 -0
- package/dist/collection/components/templates/verdocs-template-document-page/verdocs-template-document-page.js +79 -61
- package/dist/collection/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.js +48 -24
- package/dist/collection/components/templates/verdocs-template-fields/verdocs-template-fields.js +63 -61
- package/dist/collection/components/templates/verdocs-template-role-properties/verdocs-template-role-properties.js +61 -36
- package/dist/collection/components/templates/verdocs-template-roles/verdocs-template-roles.js +63 -46
- package/dist/collection/components/templates/verdocs-template-star/verdocs-template-star.js +1 -1
- package/dist/collection/components/templates/verdocs-template-tags/verdocs-template-tags.js +1 -1
- package/dist/collection/utils/Datastore.js +141 -0
- package/dist/collection/utils/Templates.js +2 -0
- package/dist/collection/utils/utils.js +3 -2
- package/dist/components/index.js +1 -5
- package/dist/components/{p-3044c9cb.js → p-070bebd7.js} +1 -1
- package/dist/components/{p-1b60debe.js → p-0a69031f.js} +29 -28
- package/dist/components/{p-69881420.js → p-0ca7012b.js} +1 -1
- package/dist/components/{p-b2bf338f.js → p-0d063bf9.js} +65 -35
- package/dist/components/{p-ac7578f6.js → p-0e332769.js} +1 -1
- package/dist/components/{p-a655b737.js → p-15d530b8.js} +6 -6
- package/dist/components/{p-71dd305b.js → p-18999830.js} +2 -2
- package/dist/components/{p-90540412.js → p-1ae5d7e0.js} +1 -1
- package/dist/components/{p-8f942993.js → p-1ca705bc.js} +31 -30
- package/dist/components/{p-4d2f2954.js → p-1e2e8b1c.js} +1 -1
- package/dist/components/{p-c7a21595.js → p-1e67ebdf.js} +67 -42
- package/dist/components/{p-fe2dca8c.js → p-22da6d14.js} +2 -2
- package/dist/components/{p-945d225a.js → p-22e52874.js} +90 -88
- package/dist/components/{p-85ef4d07.js → p-2548f3f0.js} +49 -38
- package/dist/components/{p-263dc67d.js → p-315d6592.js} +1 -1
- package/dist/components/{p-4dc4418a.js → p-3201d529.js} +1 -1
- package/dist/components/{p-7786799a.js → p-324ed895.js} +8 -4
- package/dist/components/{p-b679d760.js → p-49153610.js} +32 -31
- package/dist/components/{p-03660739.js → p-4afcdc84.js} +30 -31
- package/dist/components/{p-b0af9b72.js → p-4bc5ac82.js} +3 -2
- package/dist/components/{p-ffe8b41d.js → p-4dd750e9.js} +1 -1
- package/dist/components/{p-82fb3284.js → p-58c2bd5d.js} +1 -1
- package/dist/components/{p-d3170dcd.js → p-5a9cea40.js} +4 -4
- package/dist/components/{p-8b27ce22.js → p-5d4bbcd0.js} +1 -1
- package/dist/components/{p-1e66385b.js → p-5d82a9f3.js} +64 -57
- package/dist/components/{p-877eaf65.js → p-5eb45a4f.js} +1 -1
- package/dist/components/{p-62f8b36c.js → p-6400f542.js} +36 -14
- package/dist/components/{p-e4ac6259.js → p-6fcd99d1.js} +2 -2
- package/dist/components/{p-921297ba.js → p-84ae0283.js} +1 -1
- package/dist/components/{p-7927a846.js → p-8d3c0b4c.js} +2 -2
- package/dist/components/{p-83a2fa2f.js → p-8fbc64e9.js} +72 -55
- package/dist/components/{p-0e64ccc3.js → p-9bb47a5a.js} +1 -1
- package/dist/components/{p-12594438.js → p-9c3fd545.js} +31 -31
- package/dist/components/{p-fe533b11.js → p-a22a3b1b.js} +125 -101
- package/dist/components/{p-df4ac086.js → p-a3e12c74.js} +2 -2
- package/dist/components/{p-6e8c00bc.js → p-b0c02eb8.js} +31 -30
- package/dist/components/{p-6b369b14.js → p-b16c202a.js} +1 -1
- package/dist/components/{p-3518350d.js → p-b9034018.js} +4 -4
- package/dist/components/{p-c7db1c7d.js → p-c25e82b9.js} +52 -53
- package/dist/components/{p-4535a9fd.js → p-c7b00ce6.js} +36 -17
- package/dist/components/{p-e4a852b5.js → p-c8fedb4e.js} +7 -6
- package/dist/components/{p-83245875.js → p-cf6ea837.js} +2 -2
- package/dist/components/{p-b8cd75c0.js → p-d9704a51.js} +55 -45
- package/dist/components/p-da4d4eed.js +1781 -0
- package/dist/components/{p-cdf871dd.js → p-dd701894.js} +29 -28
- package/dist/components/p-ea5954bd.js +4 -0
- package/dist/components/{p-42a676b7.js → p-ec894daf.js} +2 -2
- package/dist/components/{p-72e959a7.js → p-ecc818bb.js} +30 -31
- package/dist/components/{p-ed9a1a21.js → p-ed88b8d2.js} +44 -24
- package/dist/components/{p-556596e4.js → p-f72b9c45.js} +1 -1
- package/dist/components/{p-a7bbe96b.js → p-f990140a.js} +3 -3
- package/dist/components/{p-db4a15fd.js → p-fcad60f5.js} +1 -1
- package/dist/components/{p-0162bdd3.js → p-fd96322b.js} +30 -33
- package/dist/components/verdocs-auth.js +4 -4
- package/dist/components/verdocs-build.js +99 -103
- package/dist/components/verdocs-button-panel.js +1 -1
- package/dist/components/verdocs-button.js +1 -1
- package/dist/components/verdocs-checkbox.js +1 -1
- package/dist/components/verdocs-component-error.js +1 -1
- package/dist/components/verdocs-contact-picker.js +1 -1
- package/dist/components/verdocs-dialog.js +1 -1
- package/dist/components/verdocs-dropdown.js +1 -1
- package/dist/components/verdocs-envelope-document-page.js +1 -1
- package/dist/components/verdocs-envelope-recipient-link.js +1 -1
- package/dist/components/verdocs-envelope-recipient-summary.js +37 -19
- package/dist/components/verdocs-envelope-sidebar.js +76 -54
- package/dist/components/verdocs-envelopes-list.js +12 -12
- package/dist/components/verdocs-field-attachment.js +1 -1
- package/dist/components/verdocs-field-checkbox.js +1 -1
- package/dist/components/verdocs-field-date.js +1 -1
- package/dist/components/verdocs-field-dropdown.js +1 -1
- package/dist/components/verdocs-field-initial.js +1 -1
- package/dist/components/verdocs-field-payment.js +106 -33
- package/dist/components/verdocs-field-radio.js +1 -1
- package/dist/components/verdocs-field-signature.js +1 -1
- package/dist/components/verdocs-field-textarea.js +1 -1
- package/dist/components/verdocs-field-textbox.js +1 -1
- package/dist/components/verdocs-field-timestamp.js +1 -1
- package/dist/components/verdocs-file-chooser.js +1 -1
- package/dist/components/verdocs-help-icon.js +1 -1
- package/dist/components/verdocs-initial-dialog.js +1 -1
- package/dist/components/verdocs-kba-dialog.js +1 -1
- package/dist/components/verdocs-loader.js +1 -1
- package/dist/components/verdocs-ok-dialog.js +1 -1
- package/dist/components/verdocs-organization-card.js +2 -2
- package/dist/components/verdocs-pagination.js +1 -1
- package/dist/components/verdocs-portal.js +1 -1
- package/dist/components/verdocs-preview.js +1 -1
- package/dist/components/verdocs-progress-bar.js +1 -1
- package/dist/components/verdocs-quick-filter.js +1 -1
- package/dist/components/verdocs-quick-functions.js +1 -1
- package/dist/components/verdocs-radio-button.js +1 -1
- package/dist/components/verdocs-search-box.js +1 -1
- package/dist/components/verdocs-search-tabs.js +1 -1
- package/dist/components/verdocs-select-input.js +1 -1
- package/dist/components/verdocs-send.js +1 -1
- package/dist/components/verdocs-sign.js +24 -23
- package/dist/components/verdocs-signature-dialog.js +1 -1
- package/dist/components/verdocs-spinner.js +1 -1
- package/dist/components/verdocs-status-indicator.js +1 -1
- package/dist/components/verdocs-switch.js +1 -1
- package/dist/components/verdocs-table.js +1 -1
- package/dist/components/verdocs-tabs.js +1 -1
- package/dist/components/verdocs-template-attachments.js +1 -1
- package/dist/components/verdocs-template-build-tabs.js +1 -1
- package/dist/components/verdocs-template-card.js +1 -1
- package/dist/components/verdocs-template-create.js +148 -1
- package/dist/components/verdocs-template-document-page.js +1 -1
- package/dist/components/verdocs-template-field-properties.js +1 -1
- package/dist/components/verdocs-template-fields.js +1 -1
- package/dist/components/verdocs-template-role-properties.js +1 -1
- package/dist/components/verdocs-template-roles.js +1 -1
- package/dist/components/verdocs-template-star.js +1 -1
- package/dist/components/verdocs-template-tags.js +2 -2
- package/dist/components/verdocs-templates-list.js +11 -11
- package/dist/components/verdocs-text-input.js +1 -1
- package/dist/components/verdocs-toggle-button.js +1 -1
- package/dist/components/verdocs-toggle.js +1 -1
- package/dist/components/verdocs-toolbar-icon.js +1 -1
- package/dist/components/verdocs-upload-dialog.js +1 -1
- package/dist/components/verdocs-view.js +1 -1
- package/dist/esm/Datastore-52fcbac6.js +1781 -0
- package/dist/esm/{index-c8587076.js → index-272d51a4.js} +12 -26
- package/dist/esm/loader.js +3 -3
- package/dist/esm/{utils-27fa12eb.js → utils-47de6f79.js} +3 -2
- package/dist/esm/verdocs-auth.entry.js +1 -1
- package/dist/esm/verdocs-build.entry.js +23 -14
- package/dist/esm/verdocs-button-panel_2.entry.js +1 -1
- package/dist/esm/{verdocs-button_3.entry.js → verdocs-button_2.entry.js} +2 -56
- package/dist/esm/{verdocs-checkbox_4.entry.js → verdocs-checkbox_6.entry.js} +115 -26
- package/dist/esm/verdocs-contact-picker_2.entry.js +2 -2
- package/dist/esm/verdocs-dialog.entry.js +1 -1
- package/dist/esm/verdocs-dropdown.entry.js +1 -1
- package/dist/esm/verdocs-envelope-document-page.entry.js +2 -2
- package/dist/esm/verdocs-envelope-recipient-link_2.entry.js +31 -16
- package/dist/esm/verdocs-envelope-recipient-summary.entry.js +33 -18
- package/dist/esm/verdocs-envelope-sidebar.entry.js +65 -46
- package/dist/esm/verdocs-envelopes-list.entry.js +2 -2
- package/dist/esm/verdocs-field-attachment_13.entry.js +104 -155
- package/dist/esm/verdocs-field-payment.entry.js +38 -25
- package/dist/esm/verdocs-file-chooser_2.entry.js +1 -1
- package/dist/esm/verdocs-kba-dialog_2.entry.js +27 -5
- package/dist/esm/verdocs-ok-dialog.entry.js +1 -1
- package/dist/esm/verdocs-organization-card_2.entry.js +1 -1
- package/dist/esm/verdocs-pagination_2.entry.js +2 -2
- package/dist/esm/{verdocs-preview_9.entry.js → verdocs-preview_6.entry.js} +256 -470
- package/dist/esm/verdocs-quick-functions.entry.js +1 -1
- package/dist/esm/verdocs-radio-button.entry.js +1 -1
- package/dist/esm/verdocs-search-box.entry.js +1 -1
- package/dist/esm/verdocs-search-tabs.entry.js +1 -1
- package/dist/esm/verdocs-sign.entry.js +11 -12
- package/dist/esm/verdocs-spinner.entry.js +1 -1
- package/dist/esm/verdocs-status-indicator.entry.js +1 -1
- package/dist/esm/verdocs-table.entry.js +1 -1
- package/dist/esm/verdocs-template-card.entry.js +1 -1
- package/dist/{components/p-f9cc62a7.js → esm/verdocs-template-create.entry.js} +15 -69
- package/dist/esm/verdocs-template-document-page_2.entry.js +79 -64
- package/dist/esm/verdocs-template-role-properties.entry.js +59 -38
- package/dist/esm/verdocs-template-star.entry.js +2 -2
- package/dist/esm/verdocs-template-tags.entry.js +2 -2
- package/dist/esm/verdocs-templates-list.entry.js +1 -1
- package/dist/esm/verdocs-toggle.entry.js +1 -1
- package/dist/esm/verdocs-web-sdk.js +4 -4
- package/dist/esm-es5/Datastore-52fcbac6.js +1 -0
- package/dist/esm-es5/index-272d51a4.js +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/{utils-27fa12eb.js → utils-47de6f79.js} +1 -1
- package/dist/esm-es5/verdocs-auth.entry.js +1 -1
- package/dist/esm-es5/verdocs-build.entry.js +1 -1
- package/dist/esm-es5/verdocs-button-panel_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-button_2.entry.js +1 -0
- package/dist/esm-es5/verdocs-checkbox_6.entry.js +1 -0
- package/dist/esm-es5/verdocs-contact-picker_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-dropdown.entry.js +1 -1
- package/dist/esm-es5/verdocs-envelope-document-page.entry.js +1 -1
- package/dist/esm-es5/verdocs-envelope-recipient-link_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-envelope-recipient-summary.entry.js +1 -1
- package/dist/esm-es5/verdocs-envelope-sidebar.entry.js +1 -1
- package/dist/esm-es5/verdocs-envelopes-list.entry.js +1 -1
- package/dist/esm-es5/verdocs-field-attachment_13.entry.js +1 -1
- package/dist/esm-es5/verdocs-field-payment.entry.js +1 -1
- package/dist/esm-es5/verdocs-file-chooser_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-kba-dialog_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-ok-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-organization-card_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-pagination_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-preview_6.entry.js +1 -0
- package/dist/esm-es5/verdocs-quick-functions.entry.js +1 -1
- package/dist/esm-es5/verdocs-radio-button.entry.js +1 -1
- package/dist/esm-es5/verdocs-search-box.entry.js +1 -1
- package/dist/esm-es5/verdocs-search-tabs.entry.js +1 -1
- package/dist/esm-es5/verdocs-sign.entry.js +1 -1
- package/dist/esm-es5/verdocs-spinner.entry.js +1 -1
- package/dist/esm-es5/verdocs-status-indicator.entry.js +1 -1
- package/dist/esm-es5/verdocs-table.entry.js +1 -1
- package/dist/esm-es5/verdocs-template-card.entry.js +1 -1
- package/dist/esm-es5/verdocs-template-create.entry.js +1 -0
- package/dist/esm-es5/verdocs-template-document-page_2.entry.js +1 -1
- package/dist/esm-es5/verdocs-template-role-properties.entry.js +1 -1
- package/dist/esm-es5/verdocs-template-star.entry.js +1 -1
- package/dist/esm-es5/verdocs-template-tags.entry.js +1 -1
- package/dist/esm-es5/verdocs-templates-list.entry.js +1 -1
- package/dist/esm-es5/verdocs-toggle.entry.js +1 -1
- package/dist/esm-es5/verdocs-web-sdk.js +1 -1
- package/dist/types/components/controls/verdocs-text-input/verdocs-text-input.d.ts +0 -2
- package/dist/types/components/embeds/verdocs-build/verdocs-build.d.ts +8 -32
- package/dist/types/components/embeds/verdocs-preview/verdocs-preview.d.ts +6 -8
- package/dist/types/components/embeds/verdocs-send/verdocs-send.d.ts +7 -6
- package/dist/types/components/embeds/verdocs-sign/verdocs-sign.d.ts +3 -3
- package/dist/types/components/embeds/verdocs-view/verdocs-view.d.ts +6 -5
- package/dist/types/components/envelopes/verdocs-envelope-recipient-link/verdocs-envelope-recipient-link.d.ts +6 -3
- package/dist/types/components/envelopes/verdocs-envelope-recipient-summary/verdocs-envelope-recipient-summary.d.ts +6 -3
- package/dist/types/components/envelopes/verdocs-envelope-sidebar/verdocs-envelope-sidebar.d.ts +8 -4
- package/dist/types/components/fields/verdocs-field-attachment/verdocs-field-attachment.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-checkbox/verdocs-field-checkbox.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-date/verdocs-field-date.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-dropdown/verdocs-field-dropdown.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-initial/verdocs-field-initial.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-payment/verdocs-field-payment.d.ts +44 -30
- package/dist/types/components/fields/verdocs-field-radio/verdocs-field-radio.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-signature/verdocs-field-signature.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-textarea/verdocs-field-textarea.d.ts +6 -7
- package/dist/types/components/fields/verdocs-field-textbox/verdocs-field-textbox.d.ts +5 -12
- package/dist/types/components/fields/verdocs-field-timestamp/verdocs-field-timestamp.d.ts +6 -7
- package/dist/types/components/templates/verdocs-template-attachments/verdocs-template-attachments.d.ts +6 -2
- package/dist/types/components/templates/verdocs-template-build-tabs/verdocs-template-build-tabs.d.ts +7 -4
- package/dist/types/components/templates/verdocs-template-document-page/verdocs-template-document-page.d.ts +7 -4
- package/dist/types/components/templates/verdocs-template-field-properties/verdocs-template-field-properties.d.ts +7 -8
- package/dist/types/components/templates/verdocs-template-fields/verdocs-template-fields.d.ts +6 -8
- package/dist/types/components/templates/verdocs-template-role-properties/verdocs-template-role-properties.d.ts +7 -7
- package/dist/types/components/templates/verdocs-template-roles/verdocs-template-roles.d.ts +7 -6
- package/dist/types/components.d.ts +176 -330
- package/dist/types/utils/Datastore.d.ts +24 -0
- package/dist/types/utils/Templates.d.ts +3 -0
- package/dist/types/utils/utils.d.ts +1 -1
- package/dist/verdocs-web-sdk/{p-98c5f5a5.entry.js → p-0ca1e87c.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-0e9de098.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-fc053d00.entry.js → p-167e3d7e.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-7bd37bca.entry.js → p-2a1287ec.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-6419b913.system.js → p-2be751c4.system.js} +1 -1
- package/dist/verdocs-web-sdk/{p-cb30f11e.entry.js → p-2f73c9de.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-3364cc13.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-196bc80f.system.entry.js → p-37d747fb.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-386d789c.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-3a1fa556.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-0fd57194.entry.js → p-41cbf650.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-26715b8b.entry.js → p-4b36ca30.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-98501408.system.entry.js → p-4e9e154f.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-a3778013.system.entry.js → p-511a4ecc.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-65a4e01e.entry.js → p-524f37a0.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-13fe8650.system.entry.js → p-53f4c7c3.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-54f085d1.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-cca517dc.entry.js → p-584113d1.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-f8cad58e.entry.js → p-5f1a000c.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-256f07fd.system.entry.js → p-62f15675.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-9b921211.js → p-650697bd.js} +1 -1
- package/dist/verdocs-web-sdk/{p-c06d2604.entry.js → p-65c5398e.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-0446030b.entry.js → p-6ced37ed.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-16619383.entry.js → p-7464b84f.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-6e3fa0c4.system.entry.js → p-761f6656.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-30bc5986.entry.js → p-76cc40fe.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-c45dc777.entry.js → p-771c2f92.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-78191329.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-f3c995d8.system.entry.js → p-7c8938e7.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-1ce2f724.system.entry.js → p-80ce3711.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-81c8663f.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-8221a48f.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-860b9f94.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-89cdecac.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-8a2ff048.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-8c03fc69.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-8d401072.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-921b56fd.system.entry.js → p-914e131c.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-5737f0ae.system.js → p-9186f42e.system.js} +1 -1
- package/dist/verdocs-web-sdk/{p-8e233a6b.system.entry.js → p-9227d400.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-92ce6180.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-9567cb7d.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-97b00cae.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-4b4801ad.system.entry.js → p-982f1b36.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-1b6736fe.system.entry.js → p-9d0b0e36.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-6d1d86ff.system.entry.js → p-a08886c1.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-e25e1dcf.entry.js → p-a165607e.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-a242aa80.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-5d6a2fda.system.entry.js → p-a9635106.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-aebb0cd9.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-b0b958a0.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-b8737f7b.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-49988769.js → p-b9654a5e.js} +2 -2
- package/dist/verdocs-web-sdk/p-bb0effe1.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-bcc23811.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-0c3a471b.entry.js → p-bd7406ae.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-e8d91957.entry.js → p-bdd7b3d3.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-c5818330.entry.js → p-c1728f5c.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-c18c718f.system.js +1 -0
- package/dist/verdocs-web-sdk/{p-731066de.system.entry.js → p-c6fd3e53.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-c7cd6843.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-4f7c72f9.system.entry.js → p-c9f40726.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-ca712f40.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-cbb75c5e.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-751b0280.entry.js → p-d475fff3.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-91c4298b.system.entry.js → p-d5870e33.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-e5126f26.system.entry.js → p-d8dae4e9.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-93093a7a.system.entry.js → p-d98cbd0f.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-da4d4eed.js +1 -0
- package/dist/verdocs-web-sdk/{p-2298c22e.entry.js → p-ddb17b3e.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-df04f0ca.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-9ff1be63.entry.js → p-df392ef9.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-e2b70dfb.system.js +1 -0
- package/dist/verdocs-web-sdk/{p-2aea0c7b.system.entry.js → p-e438bd02.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-0c42cb22.system.entry.js → p-e5d291f3.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-7f1e0c5e.entry.js → p-e6dbb0f7.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-c4d61c66.entry.js → p-e83cd333.entry.js} +1 -1
- package/dist/verdocs-web-sdk/p-edfb1951.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-f4fcf7a5.entry.js +1 -0
- package/dist/verdocs-web-sdk/{p-97b951e6.system.entry.js → p-f5d01982.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/{p-6e55af26.system.entry.js → p-f9b37af2.system.entry.js} +1 -1
- package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
- package/dist/verdocs-web-sdk/verdocs-web-sdk.js +1 -1
- package/package.json +3 -3
- package/dist/cjs/EnvelopeStore-f1cd9bd3.js +0 -96
- package/dist/cjs/TemplateFieldStore-7bcc0f7a.js +0 -44
- package/dist/cjs/TemplateRoleStore-e8bb00ec.js +0 -51
- package/dist/cjs/TemplateStore-db21be4d.js +0 -99
- package/dist/cjs/index-2a189d85.js +0 -3721
- package/dist/cjs/index-76d03a35.js +0 -196
- package/dist/cjs/verdocs-loader.cjs.entry.js +0 -20
- package/dist/collection/components/templates/verdocs-template-name/verdocs-template-name.css +0 -0
- package/dist/collection/components/templates/verdocs-template-name/verdocs-template-name.js +0 -196
- package/dist/collection/components/templates/verdocs-template-visibillity/verdocs-template-visibility.css +0 -86
- package/dist/collection/components/templates/verdocs-template-visibillity/verdocs-template-visibility.js +0 -203
- package/dist/collection/utils/EnvelopeStore.js +0 -90
- package/dist/collection/utils/TemplateFieldStore.js +0 -36
- package/dist/collection/utils/TemplateRoleStore.js +0 -41
- package/dist/collection/utils/TemplateStore.js +0 -94
- package/dist/components/p-00d39dca.js +0 -39
- package/dist/components/p-0933fb2d.js +0 -127
- package/dist/components/p-09d28afd.js +0 -97
- package/dist/components/p-3555cef1.js +0 -122
- package/dist/components/p-474b6663.js +0 -1314
- package/dist/components/p-821f2345.js +0 -93
- package/dist/components/p-9b5a4f9e.js +0 -44
- package/dist/components/p-a706bac9.js +0 -3719
- package/dist/components/verdocs-template-name.d.ts +0 -11
- package/dist/components/verdocs-template-name.js +0 -6
- package/dist/components/verdocs-template-visibility.d.ts +0 -11
- package/dist/components/verdocs-template-visibility.js +0 -6
- package/dist/esm/EnvelopeStore-4599b7d3.js +0 -93
- package/dist/esm/TemplateFieldStore-909147d8.js +0 -39
- package/dist/esm/TemplateRoleStore-2fef1fdb.js +0 -44
- package/dist/esm/TemplateStore-ace14a8b.js +0 -97
- package/dist/esm/index-24d8ae6a.js +0 -194
- package/dist/esm/index-7588a071.js +0 -3719
- package/dist/esm/verdocs-loader.entry.js +0 -16
- package/dist/esm-es5/EnvelopeStore-4599b7d3.js +0 -1
- package/dist/esm-es5/TemplateFieldStore-909147d8.js +0 -1
- package/dist/esm-es5/TemplateRoleStore-2fef1fdb.js +0 -1
- package/dist/esm-es5/TemplateStore-ace14a8b.js +0 -1
- package/dist/esm-es5/index-24d8ae6a.js +0 -1
- package/dist/esm-es5/index-7588a071.js +0 -1
- package/dist/esm-es5/index-c8587076.js +0 -1
- package/dist/esm-es5/verdocs-button_3.entry.js +0 -1
- package/dist/esm-es5/verdocs-checkbox_4.entry.js +0 -1
- package/dist/esm-es5/verdocs-loader.entry.js +0 -1
- package/dist/esm-es5/verdocs-preview_9.entry.js +0 -1
- package/dist/types/components/templates/verdocs-template-name/verdocs-template-name.d.ts +0 -41
- package/dist/types/components/templates/verdocs-template-visibillity/verdocs-template-visibility.d.ts +0 -42
- package/dist/types/utils/EnvelopeStore.d.ts +0 -12
- package/dist/types/utils/TemplateFieldStore.d.ts +0 -9
- package/dist/types/utils/TemplateRoleStore.d.ts +0 -11
- package/dist/types/utils/TemplateStore.d.ts +0 -16
- package/dist/verdocs-web-sdk/p-0c51c5be.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-194f9f4d.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-1bb57e5d.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-2211234d.system.js +0 -1
- package/dist/verdocs-web-sdk/p-2305c1e8.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-341d540f.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-368a36ea.system.js +0 -1
- package/dist/verdocs-web-sdk/p-36b5d46e.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-483f3d7f.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-569434fb.system.js +0 -1
- package/dist/verdocs-web-sdk/p-56c1ebd6.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-5bf2910c.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-60da2bbe.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-6fda3817.js +0 -1
- package/dist/verdocs-web-sdk/p-79e222f8.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-7d18cb23.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-7d593603.system.js +0 -1
- package/dist/verdocs-web-sdk/p-9515e206.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-9fabdbb1.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-a04aac80.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-a706bac9.js +0 -1
- package/dist/verdocs-web-sdk/p-b17843d9.system.js +0 -1
- package/dist/verdocs-web-sdk/p-b56793c4.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-b7a9f07d.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-b84d1a25.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-bb253149.js +0 -1
- package/dist/verdocs-web-sdk/p-bd642df2.js +0 -1
- package/dist/verdocs-web-sdk/p-c7115b35.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-cde4c155.js +0 -1
- package/dist/verdocs-web-sdk/p-d86c8c1a.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-dbddb752.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-dcd3eb1b.js +0 -1
- package/dist/verdocs-web-sdk/p-e123f19c.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-e294b6c2.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-e48b387d.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-e83a163d.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-e952ab89.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-f08eb8bf.entry.js +0 -1
- package/dist/verdocs-web-sdk/p-f5064e0c.system.js +0 -1
- package/dist/verdocs-web-sdk/p-f79b8537.system.js +0 -1
- package/dist/verdocs-web-sdk/p-fa06e241.entry.js +0 -1
@@ -0,0 +1,1783 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const jsSdk = require('@verdocs/js-sdk');
|
4
|
+
|
5
|
+
const getTypeOf = (thing) => typeof thing;
|
6
|
+
const EMPTY_STRING = '';
|
7
|
+
const STRING = getTypeOf(EMPTY_STRING);
|
8
|
+
const BOOLEAN = getTypeOf(true);
|
9
|
+
const NUMBER = getTypeOf(0);
|
10
|
+
const FUNCTION = getTypeOf(getTypeOf);
|
11
|
+
const TYPE = 'type';
|
12
|
+
const DEFAULT = 'default';
|
13
|
+
const LISTENER = 'Listener';
|
14
|
+
const ADD = 'add';
|
15
|
+
const HAS = 'Has';
|
16
|
+
const IDS = 'Ids';
|
17
|
+
const TABLE = 'Table';
|
18
|
+
const TABLES = TABLE + 's';
|
19
|
+
const TABLE_IDS = TABLE + IDS;
|
20
|
+
const ROW = 'Row';
|
21
|
+
const ROW_COUNT = ROW + 'Count';
|
22
|
+
const ROW_IDS = ROW + IDS;
|
23
|
+
const CELL = 'Cell';
|
24
|
+
const CELL_IDS = CELL + IDS;
|
25
|
+
const VALUE = 'Value';
|
26
|
+
const VALUES = VALUE + 's';
|
27
|
+
const VALUE_IDS = VALUE + IDS;
|
28
|
+
const id = (key) => EMPTY_STRING + key;
|
29
|
+
const isFiniteNumber = isFinite;
|
30
|
+
const isInstanceOf = (thing, cls) => thing instanceof cls;
|
31
|
+
const isUndefined = (thing) => thing == void 0;
|
32
|
+
const ifNotUndefined = (value, then, otherwise) =>
|
33
|
+
isUndefined(value) ? otherwise?.() : then(value);
|
34
|
+
const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
|
35
|
+
const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
|
36
|
+
const isArray = (thing) => Array.isArray(thing);
|
37
|
+
const slice = (arrayOrString, start, end) => arrayOrString.slice(start, end);
|
38
|
+
const size = (arrayOrString) => arrayOrString.length;
|
39
|
+
const test = (regex, subject) => regex.test(subject);
|
40
|
+
|
41
|
+
const arrayHas = (array, value) => array.includes(value);
|
42
|
+
const arrayEvery = (array, cb) => array.every(cb);
|
43
|
+
const arrayIsEqual = (array1, array2) =>
|
44
|
+
size(array1) === size(array2) &&
|
45
|
+
arrayEvery(array1, (value1, index) => array2[index] === value1);
|
46
|
+
const arraySort = (array, sorter) => array.sort(sorter);
|
47
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
48
|
+
const arrayMap = (array, cb) => array.map(cb);
|
49
|
+
const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
|
50
|
+
const arrayPush = (array, ...values) => array.push(...values);
|
51
|
+
const arrayShift = (array) => array.shift();
|
52
|
+
|
53
|
+
const object = Object;
|
54
|
+
const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
|
55
|
+
const objEntries = object.entries;
|
56
|
+
const objFrozen = object.isFrozen;
|
57
|
+
const isObject = (obj) =>
|
58
|
+
!isUndefined(obj) &&
|
59
|
+
ifNotUndefined(
|
60
|
+
getPrototypeOf(obj),
|
61
|
+
(objPrototype) =>
|
62
|
+
objPrototype == object.prototype ||
|
63
|
+
isUndefined(getPrototypeOf(objPrototype)),
|
64
|
+
|
65
|
+
/* istanbul ignore next */
|
66
|
+
() => true,
|
67
|
+
);
|
68
|
+
const objIds = object.keys;
|
69
|
+
const objFreeze = object.freeze;
|
70
|
+
const objHas = (obj, id) => id in obj;
|
71
|
+
const objDel = (obj, id) => {
|
72
|
+
delete obj[id];
|
73
|
+
return obj;
|
74
|
+
};
|
75
|
+
const objToArray = (obj, cb) =>
|
76
|
+
arrayMap(objEntries(obj), ([id, value]) => cb(value, id));
|
77
|
+
const objSize = (obj) => size(objIds(obj));
|
78
|
+
const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
|
79
|
+
const objValidate = (obj, validateChild, onInvalidObj, emptyIsValid = 0) => {
|
80
|
+
if (
|
81
|
+
isUndefined(obj) ||
|
82
|
+
!isObject(obj) ||
|
83
|
+
(!emptyIsValid && objIsEmpty(obj)) ||
|
84
|
+
objFrozen(obj)
|
85
|
+
) {
|
86
|
+
onInvalidObj?.();
|
87
|
+
return false;
|
88
|
+
}
|
89
|
+
objToArray(obj, (child, id) => {
|
90
|
+
if (!validateChild(child, id)) {
|
91
|
+
objDel(obj, id);
|
92
|
+
}
|
93
|
+
});
|
94
|
+
return emptyIsValid ? true : !objIsEmpty(obj);
|
95
|
+
};
|
96
|
+
|
97
|
+
const collSizeN = (collSizer) => (coll) =>
|
98
|
+
arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
|
99
|
+
const collSize = (coll) => coll?.size ?? 0;
|
100
|
+
const collSize2 = collSizeN(collSize);
|
101
|
+
const collSize3 = collSizeN(collSize2);
|
102
|
+
const collSize4 = collSizeN(collSize3);
|
103
|
+
const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
|
104
|
+
const collIsEmpty = (coll) => isUndefined(coll) || collSize(coll) == 0;
|
105
|
+
const collValues = (coll) => [...(coll?.values() ?? [])];
|
106
|
+
const collClear = (coll) => coll.clear();
|
107
|
+
const collForEach = (coll, cb) => coll?.forEach(cb);
|
108
|
+
const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
|
109
|
+
|
110
|
+
const mapNew = (entries) => new Map(entries);
|
111
|
+
const mapKeys = (map) => [...(map?.keys() ?? [])];
|
112
|
+
const mapGet = (map, key) => map?.get(key);
|
113
|
+
const mapForEach = (map, cb) =>
|
114
|
+
collForEach(map, (value, key) => cb(key, value));
|
115
|
+
const mapMap = (coll, cb) =>
|
116
|
+
arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
|
117
|
+
const mapSet = (map, key, value) =>
|
118
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
119
|
+
const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
|
120
|
+
if (!collHas(map, key)) {
|
121
|
+
mapSet(map, key, getDefaultValue());
|
122
|
+
} else {
|
123
|
+
hadExistingValue?.(mapGet(map, key));
|
124
|
+
}
|
125
|
+
return mapGet(map, key);
|
126
|
+
};
|
127
|
+
const mapMatch = (map, obj, set, del = mapSet) => {
|
128
|
+
objToArray(obj, (value, id) => set(map, id, value));
|
129
|
+
mapForEach(map, (id) => (objHas(obj, id) ? 0 : del(map, id)));
|
130
|
+
return map;
|
131
|
+
};
|
132
|
+
const mapToObj = (map, valueMapper, excludeMapValue, excludeObjValue) => {
|
133
|
+
const obj = {};
|
134
|
+
collForEach(map, (mapValue, id) => {
|
135
|
+
if (!excludeMapValue?.(mapValue, id)) {
|
136
|
+
const objValue = valueMapper ? valueMapper(mapValue, id) : mapValue;
|
137
|
+
if (!excludeObjValue?.(objValue)) {
|
138
|
+
obj[id] = objValue;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
});
|
142
|
+
return obj;
|
143
|
+
};
|
144
|
+
const mapToObj2 = (map, valueMapper, excludeMapValue) =>
|
145
|
+
mapToObj(
|
146
|
+
map,
|
147
|
+
(childMap) => mapToObj(childMap, valueMapper, excludeMapValue),
|
148
|
+
collIsEmpty,
|
149
|
+
objIsEmpty,
|
150
|
+
);
|
151
|
+
const mapToObj3 = (map, valueMapper, excludeMapValue) =>
|
152
|
+
mapToObj(
|
153
|
+
map,
|
154
|
+
(childMap) => mapToObj2(childMap, valueMapper, excludeMapValue),
|
155
|
+
collIsEmpty,
|
156
|
+
objIsEmpty,
|
157
|
+
);
|
158
|
+
const mapClone = (map, mapValue) => {
|
159
|
+
const map2 = mapNew();
|
160
|
+
collForEach(map, (value, key) => map2.set(key, mapValue?.(value) ?? value));
|
161
|
+
return map2;
|
162
|
+
};
|
163
|
+
const mapClone2 = (map) => mapClone(map, mapClone);
|
164
|
+
const mapClone3 = (map) => mapClone(map, mapClone2);
|
165
|
+
const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
|
166
|
+
ifNotUndefined(
|
167
|
+
(ensureLeaf ? mapEnsure : mapGet)(
|
168
|
+
node,
|
169
|
+
path[p],
|
170
|
+
p > size(path) - 2 ? ensureLeaf : mapNew,
|
171
|
+
),
|
172
|
+
(nodeOrLeaf) => {
|
173
|
+
if (p > size(path) - 2) {
|
174
|
+
if (pruneLeaf?.(nodeOrLeaf)) {
|
175
|
+
mapSet(node, path[p]);
|
176
|
+
}
|
177
|
+
return nodeOrLeaf;
|
178
|
+
}
|
179
|
+
const leaf = visitTree(nodeOrLeaf, path, ensureLeaf, pruneLeaf, p + 1);
|
180
|
+
if (collIsEmpty(nodeOrLeaf)) {
|
181
|
+
mapSet(node, path[p]);
|
182
|
+
}
|
183
|
+
return leaf;
|
184
|
+
},
|
185
|
+
);
|
186
|
+
|
187
|
+
const getCellOrValueType = (cellOrValue) => {
|
188
|
+
const type = getTypeOf(cellOrValue);
|
189
|
+
return isTypeStringOrBoolean(type) ||
|
190
|
+
(type == NUMBER && isFiniteNumber(cellOrValue))
|
191
|
+
? type
|
192
|
+
: void 0;
|
193
|
+
};
|
194
|
+
const setOrDelCell = (store, tableId, rowId, cellId, cell) =>
|
195
|
+
isUndefined(cell)
|
196
|
+
? store.delCell(tableId, rowId, cellId, true)
|
197
|
+
: store.setCell(tableId, rowId, cellId, cell);
|
198
|
+
const setOrDelValue = (store, valueId, value) =>
|
199
|
+
isUndefined(value) ? store.delValue(valueId) : store.setValue(valueId, value);
|
200
|
+
|
201
|
+
const setNew = (entryOrEntries) =>
|
202
|
+
new Set(
|
203
|
+
isArray(entryOrEntries) || isUndefined(entryOrEntries)
|
204
|
+
? entryOrEntries
|
205
|
+
: [entryOrEntries],
|
206
|
+
);
|
207
|
+
const setAdd = (set, value) => set?.add(value);
|
208
|
+
|
209
|
+
const INTEGER = /^\d+$/;
|
210
|
+
const getPoolFunctions = () => {
|
211
|
+
const pool = [];
|
212
|
+
let nextId = 0;
|
213
|
+
return [
|
214
|
+
(reuse) => (reuse ? arrayShift(pool) : null) ?? EMPTY_STRING + nextId++,
|
215
|
+
(id) => {
|
216
|
+
if (test(INTEGER, id) && size(pool) < 1e3) {
|
217
|
+
arrayPush(pool, id);
|
218
|
+
}
|
219
|
+
},
|
220
|
+
];
|
221
|
+
};
|
222
|
+
|
223
|
+
const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
224
|
+
const leaves = [];
|
225
|
+
const deep = (node, p) =>
|
226
|
+
p == size(path)
|
227
|
+
? arrayPush(leaves, node)
|
228
|
+
: path[p] === null
|
229
|
+
? collForEach(node, (node2) => deep(node2, p + 1))
|
230
|
+
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
231
|
+
deep(deepIdSet, 0);
|
232
|
+
return leaves;
|
233
|
+
};
|
234
|
+
const getListenerFunctions = (getThing) => {
|
235
|
+
let thing;
|
236
|
+
const [getId, releaseId] = getPoolFunctions();
|
237
|
+
const allListeners = mapNew();
|
238
|
+
const addListener = (
|
239
|
+
listener,
|
240
|
+
idSetNode,
|
241
|
+
path,
|
242
|
+
pathGetters = [],
|
243
|
+
extraArgsGetter = () => [],
|
244
|
+
) => {
|
245
|
+
thing ??= getThing();
|
246
|
+
const id = getId(1);
|
247
|
+
mapSet(allListeners, id, [
|
248
|
+
listener,
|
249
|
+
idSetNode,
|
250
|
+
path,
|
251
|
+
pathGetters,
|
252
|
+
extraArgsGetter,
|
253
|
+
]);
|
254
|
+
setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
|
255
|
+
return id;
|
256
|
+
};
|
257
|
+
const callListeners = (idSetNode, ids, ...extraArgs) =>
|
258
|
+
arrayForEach(getWildcardedLeaves(idSetNode, ids), (set) =>
|
259
|
+
collForEach(set, (id) =>
|
260
|
+
mapGet(allListeners, id)[0](thing, ...(ids ?? []), ...extraArgs),
|
261
|
+
),
|
262
|
+
);
|
263
|
+
const delListener = (id) =>
|
264
|
+
ifNotUndefined(mapGet(allListeners, id), ([, idSetNode, idOrNulls]) => {
|
265
|
+
visitTree(idSetNode, idOrNulls ?? [EMPTY_STRING], void 0, (idSet) => {
|
266
|
+
collDel(idSet, id);
|
267
|
+
return collIsEmpty(idSet) ? 1 : 0;
|
268
|
+
});
|
269
|
+
mapSet(allListeners, id);
|
270
|
+
releaseId(id);
|
271
|
+
return idOrNulls;
|
272
|
+
});
|
273
|
+
const callListener = (id) =>
|
274
|
+
ifNotUndefined(
|
275
|
+
mapGet(allListeners, id),
|
276
|
+
([listener, , path = [], pathGetters, extraArgsGetter]) => {
|
277
|
+
const callWithIds = (...ids) => {
|
278
|
+
const index = size(ids);
|
279
|
+
if (index == size(path)) {
|
280
|
+
listener(thing, ...ids, ...extraArgsGetter(ids));
|
281
|
+
} else if (isUndefined(path[index])) {
|
282
|
+
arrayForEach(pathGetters[index]?.(...ids) ?? [], (id2) =>
|
283
|
+
callWithIds(...ids, id2),
|
284
|
+
);
|
285
|
+
} else {
|
286
|
+
callWithIds(...ids, path[index]);
|
287
|
+
}
|
288
|
+
};
|
289
|
+
callWithIds();
|
290
|
+
},
|
291
|
+
);
|
292
|
+
return [addListener, callListeners, delListener, callListener];
|
293
|
+
};
|
294
|
+
const defaultSorter = (sortKey1, sortKey2) =>
|
295
|
+
(sortKey1 ?? 0) < (sortKey2 ?? 0) ? -1 : 1;
|
296
|
+
|
297
|
+
const pairNew = (value) => [value, value];
|
298
|
+
const pairCollSize2 = (pair, func = collSize2) => func(pair[0]) + func(pair[1]);
|
299
|
+
const pairNewMap = () => [mapNew(), mapNew()];
|
300
|
+
const pairClone = (array) => [...array];
|
301
|
+
const pairIsEqual = ([entry1, entry2]) => entry1 === entry2;
|
302
|
+
|
303
|
+
const jsonString = JSON.stringify;
|
304
|
+
const jsonParse = JSON.parse;
|
305
|
+
const jsonStringWithMap = (obj) =>
|
306
|
+
jsonString(obj, (_key, value) =>
|
307
|
+
isInstanceOf(value, Map) ? object.fromEntries([...value]) : value,
|
308
|
+
);
|
309
|
+
|
310
|
+
const idsChanged = (changedIds, id2, addedOrRemoved) =>
|
311
|
+
mapSet(
|
312
|
+
changedIds,
|
313
|
+
id2,
|
314
|
+
mapGet(changedIds, id2) == -addedOrRemoved ? void 0 : addedOrRemoved,
|
315
|
+
);
|
316
|
+
const createStore = () => {
|
317
|
+
let hasTablesSchema;
|
318
|
+
let hasValuesSchema;
|
319
|
+
let hadTables = false;
|
320
|
+
let hadValues = false;
|
321
|
+
let transactions = 0;
|
322
|
+
let internalListeners = [];
|
323
|
+
const changedTableIds = mapNew();
|
324
|
+
const changedTableCellIds = mapNew();
|
325
|
+
const changedRowCount = mapNew();
|
326
|
+
const changedRowIds = mapNew();
|
327
|
+
const changedCellIds = mapNew();
|
328
|
+
const changedCells = mapNew();
|
329
|
+
const changedValueIds = mapNew();
|
330
|
+
const changedValues = mapNew();
|
331
|
+
const invalidCells = mapNew();
|
332
|
+
const invalidValues = mapNew();
|
333
|
+
const tablesSchemaMap = mapNew();
|
334
|
+
const tablesSchemaRowCache = mapNew();
|
335
|
+
const valuesSchemaMap = mapNew();
|
336
|
+
const valuesDefaulted = mapNew();
|
337
|
+
const valuesNonDefaulted = setNew();
|
338
|
+
const tablePoolFunctions = mapNew();
|
339
|
+
const tableCellIds = mapNew();
|
340
|
+
const tablesMap = mapNew();
|
341
|
+
const valuesMap = mapNew();
|
342
|
+
const hasTablesListeners = pairNewMap();
|
343
|
+
const tablesListeners = pairNewMap();
|
344
|
+
const tableIdsListeners = pairNewMap();
|
345
|
+
const hasTableListeners = pairNewMap();
|
346
|
+
const tableListeners = pairNewMap();
|
347
|
+
const tableCellIdsListeners = pairNewMap();
|
348
|
+
const hasTableCellListeners = pairNewMap();
|
349
|
+
const rowCountListeners = pairNewMap();
|
350
|
+
const rowIdsListeners = pairNewMap();
|
351
|
+
const sortedRowIdsListeners = pairNewMap();
|
352
|
+
const hasRowListeners = pairNewMap();
|
353
|
+
const rowListeners = pairNewMap();
|
354
|
+
const cellIdsListeners = pairNewMap();
|
355
|
+
const hasCellListeners = pairNewMap();
|
356
|
+
const cellListeners = pairNewMap();
|
357
|
+
const invalidCellListeners = pairNewMap();
|
358
|
+
const invalidValueListeners = pairNewMap();
|
359
|
+
const hasValuesListeners = pairNewMap();
|
360
|
+
const valuesListeners = pairNewMap();
|
361
|
+
const valueIdsListeners = pairNewMap();
|
362
|
+
const hasValueListeners = pairNewMap();
|
363
|
+
const valueListeners = pairNewMap();
|
364
|
+
const startTransactionListeners = mapNew();
|
365
|
+
const finishTransactionListeners = pairNewMap();
|
366
|
+
const [addListener, callListeners, delListenerImpl, callListenerImpl] =
|
367
|
+
getListenerFunctions(() => store);
|
368
|
+
const validateTablesSchema = (tableSchema) =>
|
369
|
+
objValidate(tableSchema, (tableSchema2) =>
|
370
|
+
objValidate(tableSchema2, validateCellOrValueSchema),
|
371
|
+
);
|
372
|
+
const validateValuesSchema = (valuesSchema) =>
|
373
|
+
objValidate(valuesSchema, validateCellOrValueSchema);
|
374
|
+
const validateCellOrValueSchema = (schema) => {
|
375
|
+
if (!objValidate(schema, (_child, id2) => arrayHas([TYPE, DEFAULT], id2))) {
|
376
|
+
return false;
|
377
|
+
}
|
378
|
+
const type = schema[TYPE];
|
379
|
+
if (!isTypeStringOrBoolean(type) && type != NUMBER) {
|
380
|
+
return false;
|
381
|
+
}
|
382
|
+
if (getCellOrValueType(schema[DEFAULT]) != type) {
|
383
|
+
objDel(schema, DEFAULT);
|
384
|
+
}
|
385
|
+
return true;
|
386
|
+
};
|
387
|
+
const validateContent = isArray;
|
388
|
+
const validateTables = (tables) =>
|
389
|
+
objValidate(tables, validateTable, cellInvalid);
|
390
|
+
const validateTable = (table, tableId) =>
|
391
|
+
(!hasTablesSchema ||
|
392
|
+
collHas(tablesSchemaMap, tableId) ||
|
393
|
+
/* istanbul ignore next */
|
394
|
+
cellInvalid(tableId)) &&
|
395
|
+
objValidate(
|
396
|
+
table,
|
397
|
+
(row, rowId) => validateRow(tableId, rowId, row),
|
398
|
+
() => cellInvalid(tableId),
|
399
|
+
);
|
400
|
+
const validateRow = (tableId, rowId, row, skipDefaults) =>
|
401
|
+
objValidate(
|
402
|
+
skipDefaults ? row : addDefaultsToRow(row, tableId, rowId),
|
403
|
+
(cell, cellId) =>
|
404
|
+
ifNotUndefined(
|
405
|
+
getValidatedCell(tableId, rowId, cellId, cell),
|
406
|
+
(validCell) => {
|
407
|
+
row[cellId] = validCell;
|
408
|
+
return true;
|
409
|
+
},
|
410
|
+
() => false,
|
411
|
+
),
|
412
|
+
() => cellInvalid(tableId, rowId),
|
413
|
+
);
|
414
|
+
const getValidatedCell = (tableId, rowId, cellId, cell) =>
|
415
|
+
hasTablesSchema
|
416
|
+
? ifNotUndefined(
|
417
|
+
mapGet(mapGet(tablesSchemaMap, tableId), cellId),
|
418
|
+
(cellSchema) =>
|
419
|
+
getCellOrValueType(cell) != cellSchema[TYPE]
|
420
|
+
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
|
421
|
+
: cell,
|
422
|
+
() => cellInvalid(tableId, rowId, cellId, cell),
|
423
|
+
)
|
424
|
+
: isUndefined(getCellOrValueType(cell))
|
425
|
+
? cellInvalid(tableId, rowId, cellId, cell)
|
426
|
+
: cell;
|
427
|
+
const validateValues = (values, skipDefaults) =>
|
428
|
+
objValidate(
|
429
|
+
skipDefaults ? values : addDefaultsToValues(values),
|
430
|
+
(value, valueId) =>
|
431
|
+
ifNotUndefined(
|
432
|
+
getValidatedValue(valueId, value),
|
433
|
+
(validValue) => {
|
434
|
+
values[valueId] = validValue;
|
435
|
+
return true;
|
436
|
+
},
|
437
|
+
() => false,
|
438
|
+
),
|
439
|
+
() => valueInvalid(),
|
440
|
+
);
|
441
|
+
const getValidatedValue = (valueId, value) =>
|
442
|
+
hasValuesSchema
|
443
|
+
? ifNotUndefined(
|
444
|
+
mapGet(valuesSchemaMap, valueId),
|
445
|
+
(valueSchema) =>
|
446
|
+
getCellOrValueType(value) != valueSchema[TYPE]
|
447
|
+
? valueInvalid(valueId, value, valueSchema[DEFAULT])
|
448
|
+
: value,
|
449
|
+
() => valueInvalid(valueId, value),
|
450
|
+
)
|
451
|
+
: isUndefined(getCellOrValueType(value))
|
452
|
+
? valueInvalid(valueId, value)
|
453
|
+
: value;
|
454
|
+
const addDefaultsToRow = (row, tableId, rowId) => {
|
455
|
+
ifNotUndefined(
|
456
|
+
mapGet(tablesSchemaRowCache, tableId),
|
457
|
+
([rowDefaulted, rowNonDefaulted]) => {
|
458
|
+
collForEach(rowDefaulted, (cell, cellId) => {
|
459
|
+
if (!objHas(row, cellId)) {
|
460
|
+
row[cellId] = cell;
|
461
|
+
}
|
462
|
+
});
|
463
|
+
collForEach(rowNonDefaulted, (cellId) => {
|
464
|
+
if (!objHas(row, cellId)) {
|
465
|
+
cellInvalid(tableId, rowId, cellId);
|
466
|
+
}
|
467
|
+
});
|
468
|
+
},
|
469
|
+
);
|
470
|
+
return row;
|
471
|
+
};
|
472
|
+
const addDefaultsToValues = (values) => {
|
473
|
+
if (hasValuesSchema) {
|
474
|
+
collForEach(valuesDefaulted, (value, valueId) => {
|
475
|
+
if (!objHas(values, valueId)) {
|
476
|
+
values[valueId] = value;
|
477
|
+
}
|
478
|
+
});
|
479
|
+
collForEach(valuesNonDefaulted, (valueId) => {
|
480
|
+
if (!objHas(values, valueId)) {
|
481
|
+
valueInvalid(valueId);
|
482
|
+
}
|
483
|
+
});
|
484
|
+
}
|
485
|
+
return values;
|
486
|
+
};
|
487
|
+
const setValidTablesSchema = (tablesSchema) =>
|
488
|
+
mapMatch(
|
489
|
+
tablesSchemaMap,
|
490
|
+
tablesSchema,
|
491
|
+
(_tablesSchema, tableId, tableSchema) => {
|
492
|
+
const rowDefaulted = mapNew();
|
493
|
+
const rowNonDefaulted = setNew();
|
494
|
+
mapMatch(
|
495
|
+
mapEnsure(tablesSchemaMap, tableId, mapNew),
|
496
|
+
tableSchema,
|
497
|
+
(tableSchemaMap, cellId, cellSchema) => {
|
498
|
+
mapSet(tableSchemaMap, cellId, cellSchema);
|
499
|
+
ifNotUndefined(
|
500
|
+
cellSchema[DEFAULT],
|
501
|
+
(def) => mapSet(rowDefaulted, cellId, def),
|
502
|
+
() => setAdd(rowNonDefaulted, cellId),
|
503
|
+
);
|
504
|
+
},
|
505
|
+
);
|
506
|
+
mapSet(tablesSchemaRowCache, tableId, [rowDefaulted, rowNonDefaulted]);
|
507
|
+
},
|
508
|
+
(_tablesSchema, tableId) => {
|
509
|
+
mapSet(tablesSchemaMap, tableId);
|
510
|
+
mapSet(tablesSchemaRowCache, tableId);
|
511
|
+
},
|
512
|
+
);
|
513
|
+
const setValidValuesSchema = (valuesSchema) =>
|
514
|
+
mapMatch(
|
515
|
+
valuesSchemaMap,
|
516
|
+
valuesSchema,
|
517
|
+
(_valuesSchema, valueId, valueSchema) => {
|
518
|
+
mapSet(valuesSchemaMap, valueId, valueSchema);
|
519
|
+
ifNotUndefined(
|
520
|
+
valueSchema[DEFAULT],
|
521
|
+
(def) => mapSet(valuesDefaulted, valueId, def),
|
522
|
+
() => setAdd(valuesNonDefaulted, valueId),
|
523
|
+
);
|
524
|
+
},
|
525
|
+
(_valuesSchema, valueId) => {
|
526
|
+
mapSet(valuesSchemaMap, valueId);
|
527
|
+
mapSet(valuesDefaulted, valueId);
|
528
|
+
collDel(valuesNonDefaulted, valueId);
|
529
|
+
},
|
530
|
+
);
|
531
|
+
const setOrDelTables = (tables) =>
|
532
|
+
objIsEmpty(tables) ? delTables() : setTables(tables);
|
533
|
+
const setValidContent = ([tables, values]) => {
|
534
|
+
(objIsEmpty(tables) ? delTables : setTables)(tables);
|
535
|
+
(objIsEmpty(values) ? delValues : setValues)(values);
|
536
|
+
};
|
537
|
+
const setValidTables = (tables) =>
|
538
|
+
mapMatch(
|
539
|
+
tablesMap,
|
540
|
+
tables,
|
541
|
+
(_tables, tableId, table) => setValidTable(tableId, table),
|
542
|
+
(_tables, tableId) => delValidTable(tableId),
|
543
|
+
);
|
544
|
+
const setValidTable = (tableId, table) =>
|
545
|
+
mapMatch(
|
546
|
+
mapEnsure(tablesMap, tableId, () => {
|
547
|
+
tableIdsChanged(tableId, 1);
|
548
|
+
mapSet(tablePoolFunctions, tableId, getPoolFunctions());
|
549
|
+
mapSet(tableCellIds, tableId, mapNew());
|
550
|
+
return mapNew();
|
551
|
+
}),
|
552
|
+
table,
|
553
|
+
(tableMap, rowId, row) => setValidRow(tableId, tableMap, rowId, row),
|
554
|
+
(tableMap, rowId) => delValidRow(tableId, tableMap, rowId),
|
555
|
+
);
|
556
|
+
const setValidRow = (tableId, tableMap, rowId, row, forceDel) =>
|
557
|
+
mapMatch(
|
558
|
+
mapEnsure(tableMap, rowId, () => {
|
559
|
+
rowIdsChanged(tableId, rowId, 1);
|
560
|
+
return mapNew();
|
561
|
+
}),
|
562
|
+
row,
|
563
|
+
(rowMap, cellId, cell) =>
|
564
|
+
setValidCell(tableId, rowId, rowMap, cellId, cell),
|
565
|
+
(rowMap, cellId) =>
|
566
|
+
delValidCell(tableId, tableMap, rowId, rowMap, cellId, forceDel),
|
567
|
+
);
|
568
|
+
const setValidCell = (tableId, rowId, rowMap, cellId, cell) => {
|
569
|
+
if (!collHas(rowMap, cellId)) {
|
570
|
+
cellIdsChanged(tableId, rowId, cellId, 1);
|
571
|
+
}
|
572
|
+
const oldCell = mapGet(rowMap, cellId);
|
573
|
+
if (cell !== oldCell) {
|
574
|
+
cellChanged(tableId, rowId, cellId, oldCell, cell);
|
575
|
+
mapSet(rowMap, cellId, cell);
|
576
|
+
}
|
577
|
+
};
|
578
|
+
const setCellIntoDefaultRow = (tableId, tableMap, rowId, cellId, validCell) =>
|
579
|
+
ifNotUndefined(
|
580
|
+
mapGet(tableMap, rowId),
|
581
|
+
(rowMap) => setValidCell(tableId, rowId, rowMap, cellId, validCell),
|
582
|
+
() =>
|
583
|
+
setValidRow(
|
584
|
+
tableId,
|
585
|
+
tableMap,
|
586
|
+
rowId,
|
587
|
+
addDefaultsToRow({[cellId]: validCell}, tableId, rowId),
|
588
|
+
),
|
589
|
+
);
|
590
|
+
const setOrDelValues = (values) =>
|
591
|
+
objIsEmpty(values) ? delValues() : setValues(values);
|
592
|
+
const setValidValues = (values) =>
|
593
|
+
mapMatch(
|
594
|
+
valuesMap,
|
595
|
+
values,
|
596
|
+
(_valuesMap, valueId, value) => setValidValue(valueId, value),
|
597
|
+
(_valuesMap, valueId) => delValidValue(valueId),
|
598
|
+
);
|
599
|
+
const setValidValue = (valueId, value) => {
|
600
|
+
if (!collHas(valuesMap, valueId)) {
|
601
|
+
valueIdsChanged(valueId, 1);
|
602
|
+
}
|
603
|
+
const oldValue = mapGet(valuesMap, valueId);
|
604
|
+
if (value !== oldValue) {
|
605
|
+
valueChanged(valueId, oldValue, value);
|
606
|
+
mapSet(valuesMap, valueId, value);
|
607
|
+
}
|
608
|
+
};
|
609
|
+
const getNewRowId = (tableId, reuse) => {
|
610
|
+
const [getId] = mapGet(tablePoolFunctions, tableId);
|
611
|
+
let rowId;
|
612
|
+
do {
|
613
|
+
rowId = getId(reuse);
|
614
|
+
} while (collHas(mapGet(tablesMap, tableId), rowId));
|
615
|
+
return rowId;
|
616
|
+
};
|
617
|
+
const getOrCreateTable = (tableId) =>
|
618
|
+
mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});
|
619
|
+
const delValidTable = (tableId) => setValidTable(tableId, {});
|
620
|
+
const delValidRow = (tableId, tableMap, rowId) => {
|
621
|
+
const [, releaseId] = mapGet(tablePoolFunctions, tableId);
|
622
|
+
releaseId(rowId);
|
623
|
+
setValidRow(tableId, tableMap, rowId, {}, true);
|
624
|
+
};
|
625
|
+
const delValidCell = (tableId, table, rowId, row, cellId, forceDel) => {
|
626
|
+
const defaultCell = mapGet(
|
627
|
+
mapGet(tablesSchemaRowCache, tableId)?.[0],
|
628
|
+
cellId,
|
629
|
+
);
|
630
|
+
if (!isUndefined(defaultCell) && !forceDel) {
|
631
|
+
return setValidCell(tableId, rowId, row, cellId, defaultCell);
|
632
|
+
}
|
633
|
+
const delCell2 = (cellId2) => {
|
634
|
+
cellChanged(tableId, rowId, cellId2, mapGet(row, cellId2));
|
635
|
+
cellIdsChanged(tableId, rowId, cellId2, -1);
|
636
|
+
mapSet(row, cellId2);
|
637
|
+
};
|
638
|
+
if (isUndefined(defaultCell)) {
|
639
|
+
delCell2(cellId);
|
640
|
+
} else {
|
641
|
+
mapForEach(row, delCell2);
|
642
|
+
}
|
643
|
+
if (collIsEmpty(row)) {
|
644
|
+
rowIdsChanged(tableId, rowId, -1);
|
645
|
+
if (collIsEmpty(mapSet(table, rowId))) {
|
646
|
+
tableIdsChanged(tableId, -1);
|
647
|
+
mapSet(tablesMap, tableId);
|
648
|
+
mapSet(tablePoolFunctions, tableId);
|
649
|
+
mapSet(tableCellIds, tableId);
|
650
|
+
}
|
651
|
+
}
|
652
|
+
};
|
653
|
+
const delValidValue = (valueId) => {
|
654
|
+
const defaultValue = mapGet(valuesDefaulted, valueId);
|
655
|
+
if (!isUndefined(defaultValue)) {
|
656
|
+
return setValidValue(valueId, defaultValue);
|
657
|
+
}
|
658
|
+
valueChanged(valueId, mapGet(valuesMap, valueId));
|
659
|
+
valueIdsChanged(valueId, -1);
|
660
|
+
mapSet(valuesMap, valueId);
|
661
|
+
};
|
662
|
+
const tableIdsChanged = (tableId, addedOrRemoved) =>
|
663
|
+
idsChanged(changedTableIds, tableId, addedOrRemoved);
|
664
|
+
const rowIdsChanged = (tableId, rowId, addedOrRemoved) =>
|
665
|
+
idsChanged(
|
666
|
+
mapEnsure(changedRowIds, tableId, mapNew),
|
667
|
+
rowId,
|
668
|
+
addedOrRemoved,
|
669
|
+
) &&
|
670
|
+
mapSet(
|
671
|
+
changedRowCount,
|
672
|
+
tableId,
|
673
|
+
mapEnsure(changedRowCount, tableId, () => 0) + addedOrRemoved,
|
674
|
+
);
|
675
|
+
const cellIdsChanged = (tableId, rowId, cellId, addedOrRemoved) => {
|
676
|
+
const cellIds = mapGet(tableCellIds, tableId);
|
677
|
+
const count = mapGet(cellIds, cellId) ?? 0;
|
678
|
+
if (
|
679
|
+
(count == 0 && addedOrRemoved == 1) ||
|
680
|
+
(count == 1 && addedOrRemoved == -1)
|
681
|
+
) {
|
682
|
+
idsChanged(
|
683
|
+
mapEnsure(changedTableCellIds, tableId, mapNew),
|
684
|
+
cellId,
|
685
|
+
addedOrRemoved,
|
686
|
+
);
|
687
|
+
}
|
688
|
+
mapSet(
|
689
|
+
cellIds,
|
690
|
+
cellId,
|
691
|
+
count != -addedOrRemoved ? count + addedOrRemoved : null,
|
692
|
+
);
|
693
|
+
idsChanged(
|
694
|
+
mapEnsure(mapEnsure(changedCellIds, tableId, mapNew), rowId, mapNew),
|
695
|
+
cellId,
|
696
|
+
addedOrRemoved,
|
697
|
+
);
|
698
|
+
};
|
699
|
+
const cellChanged = (tableId, rowId, cellId, oldCell, newCell) => {
|
700
|
+
mapEnsure(
|
701
|
+
mapEnsure(mapEnsure(changedCells, tableId, mapNew), rowId, mapNew),
|
702
|
+
cellId,
|
703
|
+
() => [oldCell, 0],
|
704
|
+
)[1] = newCell;
|
705
|
+
internalListeners[3]?.(tableId, rowId, cellId, newCell);
|
706
|
+
};
|
707
|
+
const valueIdsChanged = (valueId, addedOrRemoved) =>
|
708
|
+
idsChanged(changedValueIds, valueId, addedOrRemoved);
|
709
|
+
const valueChanged = (valueId, oldValue, newValue) => {
|
710
|
+
mapEnsure(changedValues, valueId, () => [oldValue, 0])[1] = newValue;
|
711
|
+
internalListeners[4]?.(valueId, newValue);
|
712
|
+
};
|
713
|
+
const cellInvalid = (tableId, rowId, cellId, invalidCell, defaultedCell) => {
|
714
|
+
arrayPush(
|
715
|
+
mapEnsure(
|
716
|
+
mapEnsure(mapEnsure(invalidCells, tableId, mapNew), rowId, mapNew),
|
717
|
+
cellId,
|
718
|
+
() => [],
|
719
|
+
),
|
720
|
+
invalidCell,
|
721
|
+
);
|
722
|
+
return defaultedCell;
|
723
|
+
};
|
724
|
+
const valueInvalid = (valueId, invalidValue, defaultedValue) => {
|
725
|
+
arrayPush(
|
726
|
+
mapEnsure(invalidValues, valueId, () => []),
|
727
|
+
invalidValue,
|
728
|
+
);
|
729
|
+
return defaultedValue;
|
730
|
+
};
|
731
|
+
const getCellChange = (tableId, rowId, cellId) =>
|
732
|
+
ifNotUndefined(
|
733
|
+
mapGet(mapGet(mapGet(changedCells, tableId), rowId), cellId),
|
734
|
+
([oldCell, newCell]) => [true, oldCell, newCell],
|
735
|
+
() => [false, ...pairNew(getCell(tableId, rowId, cellId))],
|
736
|
+
);
|
737
|
+
const getValueChange = (valueId) =>
|
738
|
+
ifNotUndefined(
|
739
|
+
mapGet(changedValues, valueId),
|
740
|
+
([oldValue, newValue]) => [true, oldValue, newValue],
|
741
|
+
() => [false, ...pairNew(getValue(valueId))],
|
742
|
+
);
|
743
|
+
const callInvalidCellListeners = (mutator) =>
|
744
|
+
!collIsEmpty(invalidCells) && !collIsEmpty(invalidCellListeners[mutator])
|
745
|
+
? collForEach(
|
746
|
+
mutator ? mapClone3(invalidCells) : invalidCells,
|
747
|
+
(rows, tableId) =>
|
748
|
+
collForEach(rows, (cells, rowId) =>
|
749
|
+
collForEach(cells, (invalidCell, cellId) =>
|
750
|
+
callListeners(
|
751
|
+
invalidCellListeners[mutator],
|
752
|
+
[tableId, rowId, cellId],
|
753
|
+
invalidCell,
|
754
|
+
),
|
755
|
+
),
|
756
|
+
),
|
757
|
+
)
|
758
|
+
: 0;
|
759
|
+
const callInvalidValueListeners = (mutator) =>
|
760
|
+
!collIsEmpty(invalidValues) && !collIsEmpty(invalidValueListeners[mutator])
|
761
|
+
? collForEach(
|
762
|
+
mutator ? mapClone(invalidValues) : invalidValues,
|
763
|
+
(invalidValue, valueId) =>
|
764
|
+
callListeners(
|
765
|
+
invalidValueListeners[mutator],
|
766
|
+
[valueId],
|
767
|
+
invalidValue,
|
768
|
+
),
|
769
|
+
)
|
770
|
+
: 0;
|
771
|
+
const callIdsAndHasListenersIfChanged = (
|
772
|
+
changedIds,
|
773
|
+
idListeners,
|
774
|
+
hasListeners,
|
775
|
+
ids,
|
776
|
+
) => {
|
777
|
+
if (!collIsEmpty(changedIds)) {
|
778
|
+
callListeners(idListeners, ids, () => mapToObj(changedIds));
|
779
|
+
mapForEach(changedIds, (changedId, changed) =>
|
780
|
+
callListeners(hasListeners, [...(ids ?? []), changedId], changed == 1),
|
781
|
+
);
|
782
|
+
return 1;
|
783
|
+
}
|
784
|
+
};
|
785
|
+
const callTabularListenersForChanges = (mutator) => {
|
786
|
+
const hasTablesNow = hasTables();
|
787
|
+
if (hasTablesNow != hadTables) {
|
788
|
+
callListeners(hasTablesListeners[mutator], void 0, hasTablesNow);
|
789
|
+
}
|
790
|
+
const emptySortedRowIdListeners = collIsEmpty(
|
791
|
+
sortedRowIdsListeners[mutator],
|
792
|
+
);
|
793
|
+
const emptyIdAndHasListeners =
|
794
|
+
collIsEmpty(cellIdsListeners[mutator]) &&
|
795
|
+
collIsEmpty(hasCellListeners[mutator]) &&
|
796
|
+
collIsEmpty(rowIdsListeners[mutator]) &&
|
797
|
+
collIsEmpty(hasRowListeners[mutator]) &&
|
798
|
+
collIsEmpty(tableCellIdsListeners[mutator]) &&
|
799
|
+
collIsEmpty(hasTableCellListeners[mutator]) &&
|
800
|
+
collIsEmpty(rowCountListeners[mutator]) &&
|
801
|
+
emptySortedRowIdListeners &&
|
802
|
+
collIsEmpty(tableIdsListeners[mutator]) &&
|
803
|
+
collIsEmpty(hasTableListeners[mutator]);
|
804
|
+
const emptyOtherListeners =
|
805
|
+
collIsEmpty(cellListeners[mutator]) &&
|
806
|
+
collIsEmpty(rowListeners[mutator]) &&
|
807
|
+
collIsEmpty(tableListeners[mutator]) &&
|
808
|
+
collIsEmpty(tablesListeners[mutator]);
|
809
|
+
if (!emptyIdAndHasListeners || !emptyOtherListeners) {
|
810
|
+
const changes = mutator
|
811
|
+
? [
|
812
|
+
mapClone(changedTableIds),
|
813
|
+
mapClone2(changedTableCellIds),
|
814
|
+
mapClone(changedRowCount),
|
815
|
+
mapClone2(changedRowIds),
|
816
|
+
mapClone3(changedCellIds),
|
817
|
+
mapClone3(changedCells),
|
818
|
+
]
|
819
|
+
: [
|
820
|
+
changedTableIds,
|
821
|
+
changedTableCellIds,
|
822
|
+
changedRowCount,
|
823
|
+
changedRowIds,
|
824
|
+
changedCellIds,
|
825
|
+
changedCells,
|
826
|
+
];
|
827
|
+
if (!emptyIdAndHasListeners) {
|
828
|
+
callIdsAndHasListenersIfChanged(
|
829
|
+
changes[0],
|
830
|
+
tableIdsListeners[mutator],
|
831
|
+
hasTableListeners[mutator],
|
832
|
+
);
|
833
|
+
collForEach(changes[1], (changedIds, tableId) =>
|
834
|
+
callIdsAndHasListenersIfChanged(
|
835
|
+
changedIds,
|
836
|
+
tableCellIdsListeners[mutator],
|
837
|
+
hasTableCellListeners[mutator],
|
838
|
+
[tableId],
|
839
|
+
),
|
840
|
+
);
|
841
|
+
collForEach(changes[2], (changedCount, tableId) => {
|
842
|
+
if (changedCount != 0) {
|
843
|
+
callListeners(
|
844
|
+
rowCountListeners[mutator],
|
845
|
+
[tableId],
|
846
|
+
getRowCount(tableId),
|
847
|
+
);
|
848
|
+
}
|
849
|
+
});
|
850
|
+
const calledSortableTableIds = setNew();
|
851
|
+
collForEach(changes[3], (changedIds, tableId) => {
|
852
|
+
if (
|
853
|
+
callIdsAndHasListenersIfChanged(
|
854
|
+
changedIds,
|
855
|
+
rowIdsListeners[mutator],
|
856
|
+
hasRowListeners[mutator],
|
857
|
+
[tableId],
|
858
|
+
) &&
|
859
|
+
!emptySortedRowIdListeners
|
860
|
+
) {
|
861
|
+
callListeners(sortedRowIdsListeners[mutator], [tableId, null]);
|
862
|
+
setAdd(calledSortableTableIds, tableId);
|
863
|
+
}
|
864
|
+
});
|
865
|
+
if (!emptySortedRowIdListeners) {
|
866
|
+
collForEach(changes[5], (rows, tableId) => {
|
867
|
+
if (!collHas(calledSortableTableIds, tableId)) {
|
868
|
+
const sortableCellIds = setNew();
|
869
|
+
collForEach(rows, (cells) =>
|
870
|
+
collForEach(cells, ([oldCell, newCell], cellId) =>
|
871
|
+
newCell !== oldCell
|
872
|
+
? setAdd(sortableCellIds, cellId)
|
873
|
+
: collDel(cells, cellId),
|
874
|
+
),
|
875
|
+
);
|
876
|
+
collForEach(sortableCellIds, (cellId) =>
|
877
|
+
callListeners(sortedRowIdsListeners[mutator], [
|
878
|
+
tableId,
|
879
|
+
cellId,
|
880
|
+
]),
|
881
|
+
);
|
882
|
+
}
|
883
|
+
});
|
884
|
+
}
|
885
|
+
collForEach(changes[4], (rowCellIds, tableId) =>
|
886
|
+
collForEach(rowCellIds, (changedIds, rowId) =>
|
887
|
+
callIdsAndHasListenersIfChanged(
|
888
|
+
changedIds,
|
889
|
+
cellIdsListeners[mutator],
|
890
|
+
hasCellListeners[mutator],
|
891
|
+
[tableId, rowId],
|
892
|
+
),
|
893
|
+
),
|
894
|
+
);
|
895
|
+
}
|
896
|
+
if (!emptyOtherListeners) {
|
897
|
+
let tablesChanged;
|
898
|
+
collForEach(changes[5], (rows, tableId) => {
|
899
|
+
let tableChanged;
|
900
|
+
collForEach(rows, (cells, rowId) => {
|
901
|
+
let rowChanged;
|
902
|
+
collForEach(cells, ([oldCell, newCell], cellId) => {
|
903
|
+
if (newCell !== oldCell) {
|
904
|
+
callListeners(
|
905
|
+
cellListeners[mutator],
|
906
|
+
[tableId, rowId, cellId],
|
907
|
+
newCell,
|
908
|
+
oldCell,
|
909
|
+
getCellChange,
|
910
|
+
);
|
911
|
+
tablesChanged = tableChanged = rowChanged = 1;
|
912
|
+
}
|
913
|
+
});
|
914
|
+
if (rowChanged) {
|
915
|
+
callListeners(
|
916
|
+
rowListeners[mutator],
|
917
|
+
[tableId, rowId],
|
918
|
+
getCellChange,
|
919
|
+
);
|
920
|
+
}
|
921
|
+
});
|
922
|
+
if (tableChanged) {
|
923
|
+
callListeners(tableListeners[mutator], [tableId], getCellChange);
|
924
|
+
}
|
925
|
+
});
|
926
|
+
if (tablesChanged) {
|
927
|
+
callListeners(tablesListeners[mutator], void 0, getCellChange);
|
928
|
+
}
|
929
|
+
}
|
930
|
+
}
|
931
|
+
};
|
932
|
+
const callValuesListenersForChanges = (mutator) => {
|
933
|
+
const hasValuesNow = hasValues();
|
934
|
+
if (hasValuesNow != hadValues) {
|
935
|
+
callListeners(hasValuesListeners[mutator], void 0, hasValuesNow);
|
936
|
+
}
|
937
|
+
const emptyIdAndHasListeners =
|
938
|
+
collIsEmpty(valueIdsListeners[mutator]) &&
|
939
|
+
collIsEmpty(hasValueListeners[mutator]);
|
940
|
+
const emptyOtherListeners =
|
941
|
+
collIsEmpty(valueListeners[mutator]) &&
|
942
|
+
collIsEmpty(valuesListeners[mutator]);
|
943
|
+
if (!emptyIdAndHasListeners || !emptyOtherListeners) {
|
944
|
+
const changes = mutator
|
945
|
+
? [mapClone(changedValueIds), mapClone(changedValues)]
|
946
|
+
: [changedValueIds, changedValues];
|
947
|
+
if (!emptyIdAndHasListeners) {
|
948
|
+
callIdsAndHasListenersIfChanged(
|
949
|
+
changes[0],
|
950
|
+
valueIdsListeners[mutator],
|
951
|
+
hasValueListeners[mutator],
|
952
|
+
);
|
953
|
+
}
|
954
|
+
if (!emptyOtherListeners) {
|
955
|
+
let valuesChanged;
|
956
|
+
collForEach(changes[1], ([oldValue, newValue], valueId) => {
|
957
|
+
if (newValue !== oldValue) {
|
958
|
+
callListeners(
|
959
|
+
valueListeners[mutator],
|
960
|
+
[valueId],
|
961
|
+
newValue,
|
962
|
+
oldValue,
|
963
|
+
getValueChange,
|
964
|
+
);
|
965
|
+
valuesChanged = 1;
|
966
|
+
}
|
967
|
+
});
|
968
|
+
if (valuesChanged) {
|
969
|
+
callListeners(valuesListeners[mutator], void 0, getValueChange);
|
970
|
+
}
|
971
|
+
}
|
972
|
+
}
|
973
|
+
};
|
974
|
+
const fluentTransaction = (actions, ...args) => {
|
975
|
+
transaction(() => actions(...arrayMap(args, id)));
|
976
|
+
return store;
|
977
|
+
};
|
978
|
+
const getContent = () => [getTables(), getValues()];
|
979
|
+
const getTables = () => mapToObj3(tablesMap);
|
980
|
+
const getTableIds = () => mapKeys(tablesMap);
|
981
|
+
const getTable = (tableId) => mapToObj2(mapGet(tablesMap, id(tableId)));
|
982
|
+
const getTableCellIds = (tableId) =>
|
983
|
+
mapKeys(mapGet(tableCellIds, id(tableId)));
|
984
|
+
const getRowCount = (tableId) => collSize(mapGet(tablesMap, id(tableId)));
|
985
|
+
const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
|
986
|
+
const getSortedRowIds = (tableId, cellId, descending, offset = 0, limit) =>
|
987
|
+
arrayMap(
|
988
|
+
slice(
|
989
|
+
arraySort(
|
990
|
+
mapMap(mapGet(tablesMap, id(tableId)), (row, rowId) => [
|
991
|
+
isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
|
992
|
+
rowId,
|
993
|
+
]),
|
994
|
+
([cell1], [cell2]) =>
|
995
|
+
defaultSorter(cell1, cell2) * (descending ? -1 : 1),
|
996
|
+
),
|
997
|
+
offset,
|
998
|
+
isUndefined(limit) ? limit : offset + limit,
|
999
|
+
),
|
1000
|
+
([, rowId]) => rowId,
|
1001
|
+
);
|
1002
|
+
const getRow = (tableId, rowId) =>
|
1003
|
+
mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
1004
|
+
const getCellIds = (tableId, rowId) =>
|
1005
|
+
mapKeys(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
1006
|
+
const getCell = (tableId, rowId, cellId) =>
|
1007
|
+
mapGet(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
|
1008
|
+
const getValues = () => mapToObj(valuesMap);
|
1009
|
+
const getValueIds = () => mapKeys(valuesMap);
|
1010
|
+
const getValue = (valueId) => mapGet(valuesMap, id(valueId));
|
1011
|
+
const hasTables = () => !collIsEmpty(tablesMap);
|
1012
|
+
const hasTable = (tableId) => collHas(tablesMap, id(tableId));
|
1013
|
+
const hasTableCell = (tableId, cellId) =>
|
1014
|
+
collHas(mapGet(tableCellIds, id(tableId)), id(cellId));
|
1015
|
+
const hasRow = (tableId, rowId) =>
|
1016
|
+
collHas(mapGet(tablesMap, id(tableId)), id(rowId));
|
1017
|
+
const hasCell = (tableId, rowId, cellId) =>
|
1018
|
+
collHas(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
|
1019
|
+
const hasValues = () => !collIsEmpty(valuesMap);
|
1020
|
+
const hasValue = (valueId) => collHas(valuesMap, id(valueId));
|
1021
|
+
const getTablesJson = () => jsonStringWithMap(tablesMap);
|
1022
|
+
const getValuesJson = () => jsonStringWithMap(valuesMap);
|
1023
|
+
const getJson = () => jsonStringWithMap([tablesMap, valuesMap]);
|
1024
|
+
const getTablesSchemaJson = () => jsonStringWithMap(tablesSchemaMap);
|
1025
|
+
const getValuesSchemaJson = () => jsonStringWithMap(valuesSchemaMap);
|
1026
|
+
const getSchemaJson = () =>
|
1027
|
+
jsonStringWithMap([tablesSchemaMap, valuesSchemaMap]);
|
1028
|
+
const setContent = (content) =>
|
1029
|
+
fluentTransaction(() =>
|
1030
|
+
validateContent(content) ? setValidContent(content) : 0,
|
1031
|
+
);
|
1032
|
+
const setTables = (tables) =>
|
1033
|
+
fluentTransaction(() =>
|
1034
|
+
validateTables(tables) ? setValidTables(tables) : 0,
|
1035
|
+
);
|
1036
|
+
const setTable = (tableId, table) =>
|
1037
|
+
fluentTransaction(
|
1038
|
+
(tableId2) =>
|
1039
|
+
validateTable(table, tableId2) ? setValidTable(tableId2, table) : 0,
|
1040
|
+
tableId,
|
1041
|
+
);
|
1042
|
+
const setRow = (tableId, rowId, row) =>
|
1043
|
+
fluentTransaction(
|
1044
|
+
(tableId2, rowId2) =>
|
1045
|
+
validateRow(tableId2, rowId2, row)
|
1046
|
+
? setValidRow(tableId2, getOrCreateTable(tableId2), rowId2, row)
|
1047
|
+
: 0,
|
1048
|
+
tableId,
|
1049
|
+
rowId,
|
1050
|
+
);
|
1051
|
+
const addRow = (tableId, row, reuseRowIds = true) =>
|
1052
|
+
transaction(() => {
|
1053
|
+
let rowId = void 0;
|
1054
|
+
if (validateRow(tableId, rowId, row)) {
|
1055
|
+
tableId = id(tableId);
|
1056
|
+
setValidRow(
|
1057
|
+
tableId,
|
1058
|
+
getOrCreateTable(tableId),
|
1059
|
+
(rowId = getNewRowId(tableId, reuseRowIds ? 1 : 0)),
|
1060
|
+
row,
|
1061
|
+
);
|
1062
|
+
}
|
1063
|
+
return rowId;
|
1064
|
+
});
|
1065
|
+
const setPartialRow = (tableId, rowId, partialRow) =>
|
1066
|
+
fluentTransaction(
|
1067
|
+
(tableId2, rowId2) => {
|
1068
|
+
if (validateRow(tableId2, rowId2, partialRow, 1)) {
|
1069
|
+
const table = getOrCreateTable(tableId2);
|
1070
|
+
objToArray(partialRow, (cell, cellId) =>
|
1071
|
+
setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
|
1072
|
+
);
|
1073
|
+
}
|
1074
|
+
},
|
1075
|
+
tableId,
|
1076
|
+
rowId,
|
1077
|
+
);
|
1078
|
+
const setCell = (tableId, rowId, cellId, cell) =>
|
1079
|
+
fluentTransaction(
|
1080
|
+
(tableId2, rowId2, cellId2) =>
|
1081
|
+
ifNotUndefined(
|
1082
|
+
getValidatedCell(
|
1083
|
+
tableId2,
|
1084
|
+
rowId2,
|
1085
|
+
cellId2,
|
1086
|
+
isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
|
1087
|
+
),
|
1088
|
+
(validCell) =>
|
1089
|
+
setCellIntoDefaultRow(
|
1090
|
+
tableId2,
|
1091
|
+
getOrCreateTable(tableId2),
|
1092
|
+
rowId2,
|
1093
|
+
cellId2,
|
1094
|
+
validCell,
|
1095
|
+
),
|
1096
|
+
),
|
1097
|
+
tableId,
|
1098
|
+
rowId,
|
1099
|
+
cellId,
|
1100
|
+
);
|
1101
|
+
const setValues = (values) =>
|
1102
|
+
fluentTransaction(() =>
|
1103
|
+
validateValues(values) ? setValidValues(values) : 0,
|
1104
|
+
);
|
1105
|
+
const setPartialValues = (partialValues) =>
|
1106
|
+
fluentTransaction(() =>
|
1107
|
+
validateValues(partialValues, 1)
|
1108
|
+
? objToArray(partialValues, (value, valueId) =>
|
1109
|
+
setValidValue(valueId, value),
|
1110
|
+
)
|
1111
|
+
: 0,
|
1112
|
+
);
|
1113
|
+
const setValue = (valueId, value) =>
|
1114
|
+
fluentTransaction(
|
1115
|
+
(valueId2) =>
|
1116
|
+
ifNotUndefined(
|
1117
|
+
getValidatedValue(
|
1118
|
+
valueId2,
|
1119
|
+
isFunction(value) ? value(getValue(valueId2)) : value,
|
1120
|
+
),
|
1121
|
+
(validValue) => setValidValue(valueId2, validValue),
|
1122
|
+
),
|
1123
|
+
valueId,
|
1124
|
+
);
|
1125
|
+
const applyChanges = (changes) =>
|
1126
|
+
fluentTransaction(() => {
|
1127
|
+
objToArray(changes[0], (table, tableId) =>
|
1128
|
+
isUndefined(table)
|
1129
|
+
? delTable(tableId)
|
1130
|
+
: objToArray(table, (row, rowId) =>
|
1131
|
+
isUndefined(row)
|
1132
|
+
? delRow(tableId, rowId)
|
1133
|
+
: objToArray(row, (cell, cellId) =>
|
1134
|
+
setOrDelCell(store, tableId, rowId, cellId, cell),
|
1135
|
+
),
|
1136
|
+
),
|
1137
|
+
);
|
1138
|
+
objToArray(changes[1], (value, valueId) =>
|
1139
|
+
setOrDelValue(store, valueId, value),
|
1140
|
+
);
|
1141
|
+
});
|
1142
|
+
const setTablesJson = (tablesJson) => {
|
1143
|
+
try {
|
1144
|
+
setOrDelTables(jsonParse(tablesJson));
|
1145
|
+
} catch {}
|
1146
|
+
return store;
|
1147
|
+
};
|
1148
|
+
const setValuesJson = (valuesJson) => {
|
1149
|
+
try {
|
1150
|
+
setOrDelValues(jsonParse(valuesJson));
|
1151
|
+
} catch {}
|
1152
|
+
return store;
|
1153
|
+
};
|
1154
|
+
const setJson = (tablesAndValuesJson) =>
|
1155
|
+
fluentTransaction(() => {
|
1156
|
+
try {
|
1157
|
+
const [tables, values] = jsonParse(tablesAndValuesJson);
|
1158
|
+
setOrDelTables(tables);
|
1159
|
+
setOrDelValues(values);
|
1160
|
+
} catch {
|
1161
|
+
setTablesJson(tablesAndValuesJson);
|
1162
|
+
}
|
1163
|
+
});
|
1164
|
+
const setTablesSchema = (tablesSchema) =>
|
1165
|
+
fluentTransaction(() => {
|
1166
|
+
if ((hasTablesSchema = validateTablesSchema(tablesSchema))) {
|
1167
|
+
setValidTablesSchema(tablesSchema);
|
1168
|
+
if (!collIsEmpty(tablesMap)) {
|
1169
|
+
const tables = getTables();
|
1170
|
+
delTables();
|
1171
|
+
setTables(tables);
|
1172
|
+
}
|
1173
|
+
}
|
1174
|
+
});
|
1175
|
+
const setValuesSchema = (valuesSchema) =>
|
1176
|
+
fluentTransaction(() => {
|
1177
|
+
if ((hasValuesSchema = validateValuesSchema(valuesSchema))) {
|
1178
|
+
const values = getValues();
|
1179
|
+
delValuesSchema();
|
1180
|
+
delValues();
|
1181
|
+
hasValuesSchema = true;
|
1182
|
+
setValidValuesSchema(valuesSchema);
|
1183
|
+
setValues(values);
|
1184
|
+
}
|
1185
|
+
});
|
1186
|
+
const setSchema = (tablesSchema, valuesSchema) =>
|
1187
|
+
fluentTransaction(() => {
|
1188
|
+
setTablesSchema(tablesSchema);
|
1189
|
+
setValuesSchema(valuesSchema);
|
1190
|
+
});
|
1191
|
+
const delTables = () => fluentTransaction(() => setValidTables({}));
|
1192
|
+
const delTable = (tableId) =>
|
1193
|
+
fluentTransaction(
|
1194
|
+
(tableId2) =>
|
1195
|
+
collHas(tablesMap, tableId2) ? delValidTable(tableId2) : 0,
|
1196
|
+
tableId,
|
1197
|
+
);
|
1198
|
+
const delRow = (tableId, rowId) =>
|
1199
|
+
fluentTransaction(
|
1200
|
+
(tableId2, rowId2) =>
|
1201
|
+
ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
|
1202
|
+
collHas(tableMap, rowId2)
|
1203
|
+
? delValidRow(tableId2, tableMap, rowId2)
|
1204
|
+
: 0,
|
1205
|
+
),
|
1206
|
+
tableId,
|
1207
|
+
rowId,
|
1208
|
+
);
|
1209
|
+
const delCell = (tableId, rowId, cellId, forceDel) =>
|
1210
|
+
fluentTransaction(
|
1211
|
+
(tableId2, rowId2, cellId2) =>
|
1212
|
+
ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
|
1213
|
+
ifNotUndefined(mapGet(tableMap, rowId2), (rowMap) =>
|
1214
|
+
collHas(rowMap, cellId2)
|
1215
|
+
? delValidCell(
|
1216
|
+
tableId2,
|
1217
|
+
tableMap,
|
1218
|
+
rowId2,
|
1219
|
+
rowMap,
|
1220
|
+
cellId2,
|
1221
|
+
forceDel,
|
1222
|
+
)
|
1223
|
+
: 0,
|
1224
|
+
),
|
1225
|
+
),
|
1226
|
+
tableId,
|
1227
|
+
rowId,
|
1228
|
+
cellId,
|
1229
|
+
);
|
1230
|
+
const delValues = () => fluentTransaction(() => setValidValues({}));
|
1231
|
+
const delValue = (valueId) =>
|
1232
|
+
fluentTransaction(
|
1233
|
+
(valueId2) =>
|
1234
|
+
collHas(valuesMap, valueId2) ? delValidValue(valueId2) : 0,
|
1235
|
+
valueId,
|
1236
|
+
);
|
1237
|
+
const delTablesSchema = () =>
|
1238
|
+
fluentTransaction(() => {
|
1239
|
+
setValidTablesSchema({});
|
1240
|
+
hasTablesSchema = false;
|
1241
|
+
});
|
1242
|
+
const delValuesSchema = () =>
|
1243
|
+
fluentTransaction(() => {
|
1244
|
+
setValidValuesSchema({});
|
1245
|
+
hasValuesSchema = false;
|
1246
|
+
});
|
1247
|
+
const delSchema = () =>
|
1248
|
+
fluentTransaction(() => {
|
1249
|
+
delTablesSchema();
|
1250
|
+
delValuesSchema();
|
1251
|
+
});
|
1252
|
+
const transaction = (actions, doRollback) => {
|
1253
|
+
if (transactions != -1) {
|
1254
|
+
startTransaction();
|
1255
|
+
const result = actions();
|
1256
|
+
finishTransaction(doRollback);
|
1257
|
+
return result;
|
1258
|
+
}
|
1259
|
+
};
|
1260
|
+
const startTransaction = () => {
|
1261
|
+
if (transactions != -1) {
|
1262
|
+
transactions++;
|
1263
|
+
}
|
1264
|
+
if (transactions == 1) {
|
1265
|
+
internalListeners[0]?.();
|
1266
|
+
callListeners(startTransactionListeners);
|
1267
|
+
}
|
1268
|
+
return store;
|
1269
|
+
};
|
1270
|
+
const getTransactionChanges = () => [
|
1271
|
+
mapToObj(
|
1272
|
+
changedCells,
|
1273
|
+
(table, tableId) =>
|
1274
|
+
mapGet(changedTableIds, tableId) === -1
|
1275
|
+
? void 0
|
1276
|
+
: mapToObj(
|
1277
|
+
table,
|
1278
|
+
(row, rowId) =>
|
1279
|
+
mapGet(mapGet(changedRowIds, tableId), rowId) === -1
|
1280
|
+
? void 0
|
1281
|
+
: mapToObj(
|
1282
|
+
row,
|
1283
|
+
([, newCell]) => newCell,
|
1284
|
+
(changedCell) => pairIsEqual(changedCell),
|
1285
|
+
),
|
1286
|
+
collIsEmpty,
|
1287
|
+
objIsEmpty,
|
1288
|
+
),
|
1289
|
+
collIsEmpty,
|
1290
|
+
objIsEmpty,
|
1291
|
+
),
|
1292
|
+
mapToObj(
|
1293
|
+
changedValues,
|
1294
|
+
([, newValue]) => newValue,
|
1295
|
+
(changedValue) => pairIsEqual(changedValue),
|
1296
|
+
),
|
1297
|
+
1,
|
1298
|
+
];
|
1299
|
+
const getTransactionLog = () => [
|
1300
|
+
!collIsEmpty(changedCells),
|
1301
|
+
!collIsEmpty(changedValues),
|
1302
|
+
mapToObj3(changedCells, pairClone, pairIsEqual),
|
1303
|
+
mapToObj3(invalidCells),
|
1304
|
+
mapToObj(changedValues, pairClone, pairIsEqual),
|
1305
|
+
mapToObj(invalidValues),
|
1306
|
+
mapToObj(changedTableIds),
|
1307
|
+
mapToObj2(changedRowIds),
|
1308
|
+
mapToObj3(changedCellIds),
|
1309
|
+
mapToObj(changedValueIds),
|
1310
|
+
];
|
1311
|
+
const finishTransaction = (doRollback) => {
|
1312
|
+
if (transactions > 0) {
|
1313
|
+
transactions--;
|
1314
|
+
if (transactions == 0) {
|
1315
|
+
transactions = 1;
|
1316
|
+
callInvalidCellListeners(1);
|
1317
|
+
if (!collIsEmpty(changedCells)) {
|
1318
|
+
callTabularListenersForChanges(1);
|
1319
|
+
}
|
1320
|
+
callInvalidValueListeners(1);
|
1321
|
+
if (!collIsEmpty(changedValues)) {
|
1322
|
+
callValuesListenersForChanges(1);
|
1323
|
+
}
|
1324
|
+
if (doRollback?.(store)) {
|
1325
|
+
collForEach(changedCells, (table, tableId) =>
|
1326
|
+
collForEach(table, (row, rowId) =>
|
1327
|
+
collForEach(row, ([oldCell], cellId) =>
|
1328
|
+
setOrDelCell(store, tableId, rowId, cellId, oldCell),
|
1329
|
+
),
|
1330
|
+
),
|
1331
|
+
);
|
1332
|
+
collClear(changedCells);
|
1333
|
+
collForEach(changedValues, ([oldValue], valueId) =>
|
1334
|
+
setOrDelValue(store, valueId, oldValue),
|
1335
|
+
);
|
1336
|
+
collClear(changedValues);
|
1337
|
+
}
|
1338
|
+
callListeners(finishTransactionListeners[0], void 0);
|
1339
|
+
transactions = -1;
|
1340
|
+
callInvalidCellListeners(0);
|
1341
|
+
if (!collIsEmpty(changedCells)) {
|
1342
|
+
callTabularListenersForChanges(0);
|
1343
|
+
}
|
1344
|
+
callInvalidValueListeners(0);
|
1345
|
+
if (!collIsEmpty(changedValues)) {
|
1346
|
+
callValuesListenersForChanges(0);
|
1347
|
+
}
|
1348
|
+
internalListeners[1]?.();
|
1349
|
+
callListeners(finishTransactionListeners[1], void 0);
|
1350
|
+
internalListeners[2]?.();
|
1351
|
+
transactions = 0;
|
1352
|
+
hadTables = hasTables();
|
1353
|
+
hadValues = hasValues();
|
1354
|
+
arrayForEach(
|
1355
|
+
[
|
1356
|
+
changedTableIds,
|
1357
|
+
changedTableCellIds,
|
1358
|
+
changedRowCount,
|
1359
|
+
changedRowIds,
|
1360
|
+
changedCellIds,
|
1361
|
+
changedCells,
|
1362
|
+
invalidCells,
|
1363
|
+
changedValueIds,
|
1364
|
+
changedValues,
|
1365
|
+
invalidValues,
|
1366
|
+
],
|
1367
|
+
collClear,
|
1368
|
+
);
|
1369
|
+
}
|
1370
|
+
}
|
1371
|
+
return store;
|
1372
|
+
};
|
1373
|
+
const forEachTable = (tableCallback) =>
|
1374
|
+
collForEach(tablesMap, (tableMap, tableId) =>
|
1375
|
+
tableCallback(tableId, (rowCallback) =>
|
1376
|
+
collForEach(tableMap, (rowMap, rowId) =>
|
1377
|
+
rowCallback(rowId, (cellCallback) =>
|
1378
|
+
mapForEach(rowMap, cellCallback),
|
1379
|
+
),
|
1380
|
+
),
|
1381
|
+
),
|
1382
|
+
);
|
1383
|
+
const forEachTableCell = (tableId, tableCellCallback) =>
|
1384
|
+
mapForEach(mapGet(tableCellIds, id(tableId)), tableCellCallback);
|
1385
|
+
const forEachRow = (tableId, rowCallback) =>
|
1386
|
+
collForEach(mapGet(tablesMap, id(tableId)), (rowMap, rowId) =>
|
1387
|
+
rowCallback(rowId, (cellCallback) => mapForEach(rowMap, cellCallback)),
|
1388
|
+
);
|
1389
|
+
const forEachCell = (tableId, rowId, cellCallback) =>
|
1390
|
+
mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
|
1391
|
+
const forEachValue = (valueCallback) => mapForEach(valuesMap, valueCallback);
|
1392
|
+
const addSortedRowIdsListener = (
|
1393
|
+
tableId,
|
1394
|
+
cellId,
|
1395
|
+
descending,
|
1396
|
+
offset,
|
1397
|
+
limit,
|
1398
|
+
listener,
|
1399
|
+
mutator,
|
1400
|
+
) => {
|
1401
|
+
let sortedRowIds = getSortedRowIds(
|
1402
|
+
tableId,
|
1403
|
+
cellId,
|
1404
|
+
descending,
|
1405
|
+
offset,
|
1406
|
+
limit,
|
1407
|
+
);
|
1408
|
+
return addListener(
|
1409
|
+
() => {
|
1410
|
+
const newSortedRowIds = getSortedRowIds(
|
1411
|
+
tableId,
|
1412
|
+
cellId,
|
1413
|
+
descending,
|
1414
|
+
offset,
|
1415
|
+
limit,
|
1416
|
+
);
|
1417
|
+
if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
|
1418
|
+
sortedRowIds = newSortedRowIds;
|
1419
|
+
listener(
|
1420
|
+
store,
|
1421
|
+
tableId,
|
1422
|
+
cellId,
|
1423
|
+
descending,
|
1424
|
+
offset,
|
1425
|
+
limit,
|
1426
|
+
sortedRowIds,
|
1427
|
+
);
|
1428
|
+
}
|
1429
|
+
},
|
1430
|
+
sortedRowIdsListeners[mutator ? 1 : 0],
|
1431
|
+
[tableId, cellId],
|
1432
|
+
[getTableIds],
|
1433
|
+
);
|
1434
|
+
};
|
1435
|
+
const addStartTransactionListener = (listener) =>
|
1436
|
+
addListener(listener, startTransactionListeners);
|
1437
|
+
const addWillFinishTransactionListener = (listener) =>
|
1438
|
+
addListener(listener, finishTransactionListeners[0]);
|
1439
|
+
const addDidFinishTransactionListener = (listener) =>
|
1440
|
+
addListener(listener, finishTransactionListeners[1]);
|
1441
|
+
const callListener = (listenerId) => {
|
1442
|
+
callListenerImpl(listenerId);
|
1443
|
+
return store;
|
1444
|
+
};
|
1445
|
+
const delListener = (listenerId) => {
|
1446
|
+
delListenerImpl(listenerId);
|
1447
|
+
return store;
|
1448
|
+
};
|
1449
|
+
const getListenerStats = () => ({
|
1450
|
+
hasTables: pairCollSize2(hasTablesListeners),
|
1451
|
+
tables: pairCollSize2(tablesListeners),
|
1452
|
+
tableIds: pairCollSize2(tableIdsListeners),
|
1453
|
+
hasTable: pairCollSize2(hasTableListeners),
|
1454
|
+
table: pairCollSize2(tableListeners),
|
1455
|
+
tableCellIds: pairCollSize2(tableCellIdsListeners),
|
1456
|
+
hasTableCell: pairCollSize2(hasTableCellListeners, collSize3),
|
1457
|
+
rowCount: pairCollSize2(rowCountListeners),
|
1458
|
+
rowIds: pairCollSize2(rowIdsListeners),
|
1459
|
+
sortedRowIds: pairCollSize2(sortedRowIdsListeners),
|
1460
|
+
hasRow: pairCollSize2(hasRowListeners, collSize3),
|
1461
|
+
row: pairCollSize2(rowListeners, collSize3),
|
1462
|
+
cellIds: pairCollSize2(cellIdsListeners, collSize3),
|
1463
|
+
hasCell: pairCollSize2(hasCellListeners, collSize4),
|
1464
|
+
cell: pairCollSize2(cellListeners, collSize4),
|
1465
|
+
invalidCell: pairCollSize2(invalidCellListeners, collSize4),
|
1466
|
+
hasValues: pairCollSize2(hasValuesListeners),
|
1467
|
+
values: pairCollSize2(valuesListeners),
|
1468
|
+
valueIds: pairCollSize2(valueIdsListeners),
|
1469
|
+
hasValue: pairCollSize2(hasValueListeners),
|
1470
|
+
value: pairCollSize2(valueListeners),
|
1471
|
+
invalidValue: pairCollSize2(invalidValueListeners),
|
1472
|
+
transaction:
|
1473
|
+
collSize2(startTransactionListeners) +
|
1474
|
+
pairCollSize2(finishTransactionListeners),
|
1475
|
+
});
|
1476
|
+
const setInternalListeners = (
|
1477
|
+
preStartTransaction,
|
1478
|
+
preFinishTransaction,
|
1479
|
+
postFinishTransaction,
|
1480
|
+
cellChanged2,
|
1481
|
+
valueChanged2,
|
1482
|
+
) =>
|
1483
|
+
(internalListeners = [
|
1484
|
+
preStartTransaction,
|
1485
|
+
preFinishTransaction,
|
1486
|
+
postFinishTransaction,
|
1487
|
+
cellChanged2,
|
1488
|
+
valueChanged2,
|
1489
|
+
]);
|
1490
|
+
const store = {
|
1491
|
+
getContent,
|
1492
|
+
getTables,
|
1493
|
+
getTableIds,
|
1494
|
+
getTable,
|
1495
|
+
getTableCellIds,
|
1496
|
+
getRowCount,
|
1497
|
+
getRowIds,
|
1498
|
+
getSortedRowIds,
|
1499
|
+
getRow,
|
1500
|
+
getCellIds,
|
1501
|
+
getCell,
|
1502
|
+
getValues,
|
1503
|
+
getValueIds,
|
1504
|
+
getValue,
|
1505
|
+
hasTables,
|
1506
|
+
hasTable,
|
1507
|
+
hasTableCell,
|
1508
|
+
hasRow,
|
1509
|
+
hasCell,
|
1510
|
+
hasValues,
|
1511
|
+
hasValue,
|
1512
|
+
getTablesJson,
|
1513
|
+
getValuesJson,
|
1514
|
+
getJson,
|
1515
|
+
getTablesSchemaJson,
|
1516
|
+
getValuesSchemaJson,
|
1517
|
+
getSchemaJson,
|
1518
|
+
hasTablesSchema: () => hasTablesSchema,
|
1519
|
+
hasValuesSchema: () => hasValuesSchema,
|
1520
|
+
setContent,
|
1521
|
+
setTables,
|
1522
|
+
setTable,
|
1523
|
+
setRow,
|
1524
|
+
addRow,
|
1525
|
+
setPartialRow,
|
1526
|
+
setCell,
|
1527
|
+
setValues,
|
1528
|
+
setPartialValues,
|
1529
|
+
setValue,
|
1530
|
+
applyChanges,
|
1531
|
+
setTablesJson,
|
1532
|
+
setValuesJson,
|
1533
|
+
setJson,
|
1534
|
+
setTablesSchema,
|
1535
|
+
setValuesSchema,
|
1536
|
+
setSchema,
|
1537
|
+
delTables,
|
1538
|
+
delTable,
|
1539
|
+
delRow,
|
1540
|
+
delCell,
|
1541
|
+
delValues,
|
1542
|
+
delValue,
|
1543
|
+
delTablesSchema,
|
1544
|
+
delValuesSchema,
|
1545
|
+
delSchema,
|
1546
|
+
transaction,
|
1547
|
+
startTransaction,
|
1548
|
+
getTransactionChanges,
|
1549
|
+
getTransactionLog,
|
1550
|
+
finishTransaction,
|
1551
|
+
forEachTable,
|
1552
|
+
forEachTableCell,
|
1553
|
+
forEachRow,
|
1554
|
+
forEachCell,
|
1555
|
+
forEachValue,
|
1556
|
+
addSortedRowIdsListener,
|
1557
|
+
addStartTransactionListener,
|
1558
|
+
addWillFinishTransactionListener,
|
1559
|
+
addDidFinishTransactionListener,
|
1560
|
+
callListener,
|
1561
|
+
delListener,
|
1562
|
+
getListenerStats,
|
1563
|
+
isMergeable: () => false,
|
1564
|
+
// only used internally by other modules
|
1565
|
+
createStore,
|
1566
|
+
addListener,
|
1567
|
+
callListeners,
|
1568
|
+
setInternalListeners,
|
1569
|
+
};
|
1570
|
+
objToArray(
|
1571
|
+
{
|
1572
|
+
[HAS + TABLES]: [0, hasTablesListeners, [], () => [hasTables()]],
|
1573
|
+
[TABLES]: [0, tablesListeners],
|
1574
|
+
[TABLE_IDS]: [0, tableIdsListeners],
|
1575
|
+
[HAS + TABLE]: [
|
1576
|
+
1,
|
1577
|
+
hasTableListeners,
|
1578
|
+
[getTableIds],
|
1579
|
+
(ids) => [hasTable(...ids)],
|
1580
|
+
],
|
1581
|
+
[TABLE]: [1, tableListeners, [getTableIds]],
|
1582
|
+
[TABLE + CELL_IDS]: [1, tableCellIdsListeners, [getTableIds]],
|
1583
|
+
[HAS + TABLE + CELL]: [
|
1584
|
+
2,
|
1585
|
+
hasTableCellListeners,
|
1586
|
+
[getTableIds, getTableCellIds],
|
1587
|
+
(ids) => [hasTableCell(...ids)],
|
1588
|
+
],
|
1589
|
+
[ROW_COUNT]: [1, rowCountListeners, [getTableIds]],
|
1590
|
+
[ROW_IDS]: [1, rowIdsListeners, [getTableIds]],
|
1591
|
+
[HAS + ROW]: [
|
1592
|
+
2,
|
1593
|
+
hasRowListeners,
|
1594
|
+
[getTableIds, getRowIds],
|
1595
|
+
(ids) => [hasRow(...ids)],
|
1596
|
+
],
|
1597
|
+
[ROW]: [2, rowListeners, [getTableIds, getRowIds]],
|
1598
|
+
[CELL_IDS]: [2, cellIdsListeners, [getTableIds, getRowIds]],
|
1599
|
+
[HAS + CELL]: [
|
1600
|
+
3,
|
1601
|
+
hasCellListeners,
|
1602
|
+
[getTableIds, getRowIds, getCellIds],
|
1603
|
+
(ids) => [hasCell(...ids)],
|
1604
|
+
],
|
1605
|
+
[CELL]: [
|
1606
|
+
3,
|
1607
|
+
cellListeners,
|
1608
|
+
[getTableIds, getRowIds, getCellIds],
|
1609
|
+
(ids) => pairNew(getCell(...ids)),
|
1610
|
+
],
|
1611
|
+
InvalidCell: [3, invalidCellListeners],
|
1612
|
+
[HAS + VALUES]: [0, hasValuesListeners, [], () => [hasValues()]],
|
1613
|
+
[VALUES]: [0, valuesListeners],
|
1614
|
+
[VALUE_IDS]: [0, valueIdsListeners],
|
1615
|
+
[HAS + VALUE]: [
|
1616
|
+
1,
|
1617
|
+
hasValueListeners,
|
1618
|
+
[getValueIds],
|
1619
|
+
(ids) => [hasValue(...ids)],
|
1620
|
+
],
|
1621
|
+
[VALUE]: [
|
1622
|
+
1,
|
1623
|
+
valueListeners,
|
1624
|
+
[getValueIds],
|
1625
|
+
(ids) => pairNew(getValue(ids[0])),
|
1626
|
+
],
|
1627
|
+
InvalidValue: [1, invalidValueListeners],
|
1628
|
+
},
|
1629
|
+
([argumentCount, idSetNode, pathGetters, extraArgsGetter], listenable) => {
|
1630
|
+
store[ADD + listenable + LISTENER] = (...args) =>
|
1631
|
+
addListener(
|
1632
|
+
args[argumentCount],
|
1633
|
+
idSetNode[args[argumentCount + 1] ? 1 : 0],
|
1634
|
+
argumentCount > 0 ? slice(args, 0, argumentCount) : void 0,
|
1635
|
+
pathGetters,
|
1636
|
+
extraArgsGetter,
|
1637
|
+
);
|
1638
|
+
},
|
1639
|
+
);
|
1640
|
+
return objFreeze(store);
|
1641
|
+
};
|
1642
|
+
|
1643
|
+
const store = createStore();
|
1644
|
+
// For now, we clear the database every page load to keep it clean and small.
|
1645
|
+
// We're only using it to synchronize data between isolated components. e-Signing
|
1646
|
+
// flows don't really benefit from "offline-first" approaches anyway, since most
|
1647
|
+
// of a user's interactions need to go through our servers anyway.
|
1648
|
+
store.delTables();
|
1649
|
+
store.delValues();
|
1650
|
+
console.log('[STORE] Data store initialized.');
|
1651
|
+
const safeJsonParse = (val, fallback) => {
|
1652
|
+
try {
|
1653
|
+
return JSON.parse(val);
|
1654
|
+
}
|
1655
|
+
catch (e) {
|
1656
|
+
return fallback || null;
|
1657
|
+
}
|
1658
|
+
};
|
1659
|
+
const objectToRow = (obj) => {
|
1660
|
+
const row = {};
|
1661
|
+
for (let key in obj) {
|
1662
|
+
if (typeof obj[key] === 'string' || typeof obj[key] === 'number' || typeof obj[key] === 'boolean') {
|
1663
|
+
row[key] = obj[key];
|
1664
|
+
}
|
1665
|
+
else if (obj[key] === null) {
|
1666
|
+
row[`__null__${key}`] = '';
|
1667
|
+
}
|
1668
|
+
else if (Array.isArray(obj[key])) {
|
1669
|
+
row[`__array__${key}`] = JSON.stringify(obj[key]);
|
1670
|
+
}
|
1671
|
+
else if (typeof obj[key] === 'object') {
|
1672
|
+
row[`__object__${key}`] = JSON.stringify(obj[key]);
|
1673
|
+
}
|
1674
|
+
}
|
1675
|
+
return row;
|
1676
|
+
};
|
1677
|
+
const rowToObject = (row) => {
|
1678
|
+
const obj = {};
|
1679
|
+
for (let key in row) {
|
1680
|
+
if (key.startsWith('__null__')) {
|
1681
|
+
obj[key.replace('__null__', '')] = null;
|
1682
|
+
}
|
1683
|
+
else if (typeof row[key] === 'string' && key.startsWith('__array__')) {
|
1684
|
+
obj[key.replace('__array__', '')] = safeJsonParse(row[key]);
|
1685
|
+
}
|
1686
|
+
else if (typeof row[key] === 'string' && key.startsWith('__object__')) {
|
1687
|
+
obj[key.replace('__object__', '')] = safeJsonParse(row[key]);
|
1688
|
+
}
|
1689
|
+
else {
|
1690
|
+
obj[key] = row[key];
|
1691
|
+
}
|
1692
|
+
}
|
1693
|
+
return obj;
|
1694
|
+
};
|
1695
|
+
const Store = {
|
1696
|
+
store,
|
1697
|
+
// Extends the store's listener mechanism with two features:
|
1698
|
+
// 1. Apply typing to the return result, and pass the whole updated value to the callback instead
|
1699
|
+
// of just the "changes".
|
1700
|
+
// 2. Fire the callback immediately with the current value, so that the component can initialize.
|
1701
|
+
subscribe(tableId, rowId, getter, forceReload, callback) {
|
1702
|
+
// We call the callback immediately if the row exists so we get an SWR-like behavior.
|
1703
|
+
if (store.hasRow(tableId, rowId)) {
|
1704
|
+
callback(rowToObject(store.getRow(tableId, rowId)));
|
1705
|
+
}
|
1706
|
+
const listenerId = store.addRowListener(tableId, rowId, () => {
|
1707
|
+
const row = store.getRow(tableId, rowId);
|
1708
|
+
callback(rowToObject(row));
|
1709
|
+
});
|
1710
|
+
if (!store.hasRow(tableId, rowId) || forceReload) {
|
1711
|
+
console.log('[STORE] Reloading', { tableId, rowId });
|
1712
|
+
getter()
|
1713
|
+
.then(result => {
|
1714
|
+
// We don't need to call the callback because it's already listening
|
1715
|
+
console.log('[STORE] Loaded row', { tableId, rowId, forceReload }, result);
|
1716
|
+
store.setRow(tableId, rowId, objectToRow(result));
|
1717
|
+
})
|
1718
|
+
.catch(e => {
|
1719
|
+
console.error('[STORE] Error getting row', { tableId, rowId, forceReload }, e);
|
1720
|
+
});
|
1721
|
+
}
|
1722
|
+
return listenerId;
|
1723
|
+
},
|
1724
|
+
unsubscribe(listenerId) {
|
1725
|
+
store.delListener(listenerId);
|
1726
|
+
},
|
1727
|
+
async getTemplate(endpoint, templateId, reload = false) {
|
1728
|
+
if (!reload) {
|
1729
|
+
if (!store.hasRow('templates', templateId)) {
|
1730
|
+
return null;
|
1731
|
+
}
|
1732
|
+
const row = store.getRow('templates', templateId);
|
1733
|
+
return rowToObject(row);
|
1734
|
+
}
|
1735
|
+
const template = await jsSdk.getTemplate(endpoint, templateId);
|
1736
|
+
store.setRow('templates', templateId, objectToRow(template));
|
1737
|
+
return template;
|
1738
|
+
},
|
1739
|
+
updateTemplate(templateId, template) {
|
1740
|
+
store.setRow('templates', templateId, objectToRow(template));
|
1741
|
+
return template;
|
1742
|
+
},
|
1743
|
+
async getEnvelope(endpoint, envelopeId, reload = false) {
|
1744
|
+
if (!reload) {
|
1745
|
+
if (!store.hasRow('envelopes', envelopeId)) {
|
1746
|
+
return null;
|
1747
|
+
}
|
1748
|
+
const row = store.getRow('envelopes', envelopeId);
|
1749
|
+
return rowToObject(row);
|
1750
|
+
}
|
1751
|
+
const envelope = await jsSdk.getTemplate(endpoint, envelopeId);
|
1752
|
+
store.setRow('envelopes', envelopeId, objectToRow(envelope));
|
1753
|
+
return envelope;
|
1754
|
+
},
|
1755
|
+
updateEnvelope(envelopeId, envelope) {
|
1756
|
+
store.setRow('envelopes', envelopeId, objectToRow(envelope));
|
1757
|
+
return envelope;
|
1758
|
+
},
|
1759
|
+
// Get a field from an already-loaded envelope or template. Intended to be
|
1760
|
+
// called by the verdocs-field-* components themselves which are only rendered
|
1761
|
+
// after a template or envelope is already loaded and cached in the store, so
|
1762
|
+
// no attempt is made to load the parent record if it isn't already known.
|
1763
|
+
getField(source, sourceId, fieldName) {
|
1764
|
+
if (source === 'template') {
|
1765
|
+
const row = store.getRow('templates', sourceId);
|
1766
|
+
const template = rowToObject(row);
|
1767
|
+
const field = (template.fields || []).find(field => field.name === fieldName);
|
1768
|
+
const roleNames = (template.roles || []).map(role => role.name);
|
1769
|
+
const index = roleNames.findIndex(name => name === field.role_name);
|
1770
|
+
return { index: Math.max(index, 0), field };
|
1771
|
+
}
|
1772
|
+
else {
|
1773
|
+
const row = store.getRow('envelopes', sourceId);
|
1774
|
+
const envelope = rowToObject(row);
|
1775
|
+
const field = (envelope.fields || []).find(field => field.name === fieldName);
|
1776
|
+
const roleNames = (envelope.recipients || []).map(recipient => recipient.role_name);
|
1777
|
+
const index = roleNames.findIndex(name => name === field.role_name);
|
1778
|
+
return { index, field };
|
1779
|
+
}
|
1780
|
+
},
|
1781
|
+
};
|
1782
|
+
|
1783
|
+
exports.Store = Store;
|