@verdocs/web-sdk 1.4.0 → 1.4.7
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/Auth-4ec35ac7.js +97 -0
- package/dist/cjs/{Token-b86e5335.js → Token-ac80819a.js} +3 -135
- package/dist/{verdocs-web-sdk/buffer-es6-5cef4368.js → cjs/buffer-es6-bc8199b1.js} +47 -14
- package/dist/cjs/index-589f3be8.js +1356 -0
- package/dist/cjs/loader.cjs.js +3 -19
- package/dist/cjs/{index-9c6e5f50.js → popper-71bf3058.js} +0 -186
- package/dist/cjs/verdocs-auth.cjs.entry.js +10 -206
- package/dist/cjs/verdocs-button_2.cjs.entry.js +104 -0
- package/dist/cjs/{verdocs-view.cjs.entry.js → verdocs-dropdown_12.cjs.entry.js} +3314 -51
- package/dist/cjs/verdocs-initial-dialog.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-kba-dialog.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-loader.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-ok-dialog.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-organization-card.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-quick-functions.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-search-activity_2.cjs.entry.js +228 -0
- package/dist/cjs/verdocs-search-tabs.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-search.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-sign.cjs.entry.js +4 -1512
- package/dist/cjs/verdocs-signature-dialog.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-status-indicator.cjs.entry.js +4 -90
- package/dist/cjs/verdocs-template-card.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-template-tags.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-toggle.cjs.entry.js +1 -1
- package/dist/cjs/verdocs-upload-dialog.cjs.entry.js +2 -2
- package/dist/cjs/verdocs-web-sdk.cjs.js +5 -117
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/controls/verdocs-button/verdocs-button.css +2 -2
- package/dist/collection/components/controls/verdocs-button/verdocs-button.js +0 -1
- package/dist/collection/components/dialogs/verdocs-kba-dialog/verdocs-kba-dialog.css +1 -1
- package/dist/collection/components/dialogs/verdocs-ok-dialog/verdocs-ok-dialog.css +2 -2
- package/dist/collection/components/dialogs/verdocs-signature-dialog/verdocs-signature-dialog.css +4 -4
- package/dist/collection/components/dialogs/verdocs-upload-dialog/verdocs-upload-dialog.css +2 -2
- package/dist/collection/components/elements/verdocs-field-attachment/verdocs-field-attachment.css +2 -4
- package/dist/collection/components/elements/verdocs-field-checkbox-group/verdocs-field-checkbox.css +1 -3
- package/dist/collection/components/elements/verdocs-field-date/verdocs-field-date.css +1 -3
- package/dist/collection/components/elements/verdocs-field-dropdown/verdocs-field-dropdown.css +1 -3
- package/dist/collection/components/elements/verdocs-field-initial/verdocs-field-initial.css +1 -3
- package/dist/collection/components/elements/verdocs-field-payment/verdocs-field-payment.css +1 -3
- package/dist/collection/components/elements/verdocs-field-radio-button-group/verdocs-field-radio-button.css +1 -3
- package/dist/collection/components/elements/verdocs-field-signature/verdocs-field-signature.css +1 -3
- package/dist/collection/components/elements/verdocs-field-textarea/verdocs-field-textarea.css +1 -3
- package/dist/collection/components/elements/verdocs-field-textbox/verdocs-field-textbox.css +1 -3
- package/dist/collection/components/elements/verdocs-quick-functions/verdocs-quick-functions.css +1 -3
- package/dist/collection/components/elements/verdocs-search-activity/verdocs-search-activity.css +1 -3
- package/dist/collection/components/elements/verdocs-search-box/verdocs-search-box.css +1 -3
- package/dist/collection/components/elements/verdocs-search-tabs/verdocs-search-tabs.css +1 -0
- package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.css +1 -1
- package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.js +7 -9
- package/dist/collection/components/embeds/verdocs-search/verdocs-search.css +1 -1
- package/dist/collection/components/embeds/verdocs-sign/verdocs-sign.css +1 -1
- package/dist/collection/components/embeds/verdocs-view/verdocs-view.css +1 -1
- package/dist/components/Auth.js +23 -88
- package/dist/components/Token.js +2 -135
- package/dist/components/buffer-es6.js +39 -14
- package/dist/components/index.js +0 -4
- package/dist/components/{index3.js → popper.js} +0 -186
- package/dist/components/verdocs-auth.js +6 -201
- package/dist/components/verdocs-button2.js +2 -3
- package/dist/components/verdocs-dropdown2.js +2 -2
- package/dist/components/verdocs-field-attachment2.js +2 -2
- package/dist/components/verdocs-field-checkbox2.js +2 -2
- package/dist/components/verdocs-field-date2.js +2 -214
- package/dist/components/verdocs-field-dropdown2.js +2 -2
- package/dist/components/verdocs-field-initial2.js +2 -2
- package/dist/components/verdocs-field-payment2.js +2 -2
- package/dist/components/verdocs-field-radio-button2.js +2 -2
- package/dist/components/verdocs-field-signature2.js +2 -2
- package/dist/components/verdocs-field-textarea2.js +2 -2
- package/dist/components/verdocs-field-textbox2.js +2 -2
- package/dist/components/verdocs-initial-dialog2.js +1 -1
- package/dist/components/verdocs-kba-dialog.js +2 -2
- package/dist/components/verdocs-loader2.js +1 -1
- package/dist/components/verdocs-ok-dialog2.js +2 -2
- package/dist/components/verdocs-organization-card.js +1 -1
- package/dist/components/verdocs-quick-functions.js +2 -2
- package/dist/components/verdocs-search-activity2.js +16 -104
- package/dist/components/verdocs-search-box2.js +2 -2
- package/dist/components/verdocs-search-tabs.js +2 -2
- package/dist/components/verdocs-search.js +2 -2
- package/dist/components/verdocs-sign.js +2 -1509
- package/dist/components/verdocs-signature-dialog2.js +2 -2
- package/dist/components/verdocs-status-indicator.js +3 -88
- package/dist/components/verdocs-template-card.js +1 -1
- package/dist/components/verdocs-template-tags.js +1 -1
- package/dist/components/verdocs-text-input2.js +1 -1
- package/dist/components/verdocs-toggle.js +1 -1
- package/dist/components/verdocs-upload-dialog2.js +2 -2
- package/dist/components/verdocs-view2.js +7 -34
- package/dist/docs.json +3 -3
- package/dist/esm/Auth-15cd42a8.js +92 -0
- package/dist/{verdocs-web-sdk/Token-29eea56d.js → esm/Token-ce37bd9d.js} +2 -135
- package/dist/{cjs/buffer-es6-b2c1c885.js → esm/buffer-es6-136673c8.js} +38 -15
- package/dist/esm/index-859bc689.js +1327 -0
- package/dist/esm/loader.js +3 -19
- package/dist/esm/{index-432c65a6.js → popper-93ecb064.js} +0 -186
- package/dist/esm/verdocs-auth.entry.js +7 -203
- package/dist/esm/verdocs-button_2.entry.js +99 -0
- package/dist/esm/{verdocs-view.entry.js → verdocs-dropdown_12.entry.js} +3287 -35
- package/dist/esm/verdocs-initial-dialog.entry.js +1 -1
- package/dist/esm/verdocs-kba-dialog.entry.js +2 -2
- package/dist/esm/verdocs-loader.entry.js +1 -1
- package/dist/esm/verdocs-ok-dialog.entry.js +2 -2
- package/dist/esm/verdocs-organization-card.entry.js +1 -1
- package/dist/esm/verdocs-quick-functions.entry.js +2 -2
- package/dist/esm/verdocs-search-activity_2.entry.js +223 -0
- package/dist/esm/verdocs-search-tabs.entry.js +2 -2
- package/dist/esm/verdocs-search.entry.js +2 -2
- package/dist/esm/verdocs-sign.entry.js +4 -1512
- package/dist/esm/verdocs-signature-dialog.entry.js +2 -2
- package/dist/esm/verdocs-status-indicator.entry.js +3 -89
- package/dist/esm/verdocs-template-card.entry.js +1 -1
- package/dist/esm/verdocs-template-tags.entry.js +1 -1
- package/dist/esm/verdocs-toggle.entry.js +1 -1
- package/dist/esm/verdocs-upload-dialog.entry.js +2 -2
- package/dist/esm/verdocs-web-sdk.js +5 -117
- package/dist/esm-es5/Auth-15cd42a8.js +1 -0
- package/dist/esm-es5/Token-ce37bd9d.js +1 -0
- package/dist/esm-es5/buffer-es6-136673c8.js +7 -0
- package/dist/esm-es5/index-859bc689.js +2 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/popper-93ecb064.js +1 -0
- package/dist/esm-es5/verdocs-auth.entry.js +1 -1
- package/dist/esm-es5/verdocs-button_2.entry.js +1 -0
- package/dist/esm-es5/verdocs-dropdown_12.entry.js +23 -0
- package/dist/esm-es5/verdocs-initial-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-kba-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-loader.entry.js +1 -1
- package/dist/esm-es5/verdocs-ok-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-organization-card.entry.js +1 -1
- package/dist/esm-es5/verdocs-quick-functions.entry.js +1 -1
- package/dist/esm-es5/verdocs-search-activity_2.entry.js +1 -0
- package/dist/esm-es5/verdocs-search-tabs.entry.js +1 -1
- package/dist/esm-es5/verdocs-search.entry.js +1 -1
- package/dist/esm-es5/verdocs-sign.entry.js +1 -1
- package/dist/esm-es5/verdocs-signature-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-status-indicator.entry.js +1 -11
- package/dist/esm-es5/verdocs-template-card.entry.js +1 -1
- package/dist/esm-es5/verdocs-template-tags.entry.js +1 -1
- package/dist/esm-es5/verdocs-toggle.entry.js +1 -1
- package/dist/esm-es5/verdocs-upload-dialog.entry.js +1 -1
- package/dist/esm-es5/verdocs-web-sdk.js +1 -1
- package/dist/types/components/embeds/verdocs-auth/verdocs-auth.d.ts +4 -2
- package/dist/verdocs-web-sdk/index.esm.js +0 -1
- package/dist/verdocs-web-sdk/p-0353c423.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-0c0b4a10.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-144e0842.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-15b7ed4d.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-1f55d8ac.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-2b57857d.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-2bc58746.js +2 -0
- package/dist/verdocs-web-sdk/p-2c161242.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-39633a02.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-432c3151.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-4368df79.system.entry.js +23 -0
- package/dist/verdocs-web-sdk/p-4c66f794.js +1 -0
- package/dist/verdocs-web-sdk/{index.system.js → p-50ea2036.system.js} +0 -0
- package/dist/verdocs-web-sdk/p-5dfd73f9.system.js +7 -0
- package/dist/verdocs-web-sdk/p-6393b2b4.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-66b19637.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-6802ef91.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-69ef22bd.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-6fa6fb3c.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-737b2e99.js +1 -0
- package/dist/verdocs-web-sdk/p-829b235c.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-8730dc92.system.js +1 -0
- package/dist/verdocs-web-sdk/p-88a300c5.system.js +1 -0
- package/dist/verdocs-web-sdk/p-96c0bf40.system.js +1 -0
- package/dist/verdocs-web-sdk/p-9b34c794.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-9d8d8c78.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-a1143ddb.entry.js +23 -0
- package/dist/verdocs-web-sdk/p-a7cfe6fc.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-b9164c4b.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-bf2620cb.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-c2f97ef9.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-caed7818.system.js +2 -0
- package/dist/verdocs-web-sdk/p-cc127684.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-cd6a2c40.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-cec13589.system.js +1 -0
- package/dist/verdocs-web-sdk/p-d14a6057.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-d6206c17.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-da667373.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-e2e643c5.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-e6e2894e.js +1 -0
- package/dist/verdocs-web-sdk/p-e719f9ca.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-ea6d6dc7.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-ed5baeb4.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-ef932a87.js +1 -0
- package/dist/verdocs-web-sdk/p-f0d0f959.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-f0e6fde0.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-f4219236.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-f7e26fbd.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-f814d5cc.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/p-fd853e54.system.entry.js +1 -0
- package/dist/verdocs-web-sdk/verdocs-web-sdk.css +1 -57
- package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -129
- package/dist/verdocs-web-sdk/verdocs-web-sdk.js +2 -1
- package/package.json +4 -4
- package/dist/cjs/Auth-0146ddd8.js +0 -161
- package/dist/cjs/app-globals-3a1e7e63.js +0 -5
- package/dist/cjs/css-shim-e9231523.js +0 -6
- package/dist/cjs/dom-7fb93981.js +0 -75
- package/dist/cjs/index-a24f3b6a.js +0 -3096
- package/dist/cjs/index-b5a86b04.js +0 -4
- package/dist/cjs/index-c4be37e1.js +0 -54
- package/dist/cjs/shadow-css-abc19485.js +0 -389
- package/dist/cjs/verdocs-button.cjs.entry.js +0 -49
- package/dist/cjs/verdocs-dropdown.cjs.entry.js +0 -80
- package/dist/cjs/verdocs-field-attachment.cjs.entry.js +0 -59
- package/dist/cjs/verdocs-field-checkbox.cjs.entry.js +0 -39
- package/dist/cjs/verdocs-field-date.cjs.entry.js +0 -2968
- package/dist/cjs/verdocs-field-dropdown.cjs.entry.js +0 -59
- package/dist/cjs/verdocs-field-initial.cjs.entry.js +0 -52
- package/dist/cjs/verdocs-field-payment.cjs.entry.js +0 -86
- package/dist/cjs/verdocs-field-radio-button.cjs.entry.js +0 -48
- package/dist/cjs/verdocs-field-signature.cjs.entry.js +0 -52
- package/dist/cjs/verdocs-field-textarea.cjs.entry.js +0 -63
- package/dist/cjs/verdocs-field-textbox.cjs.entry.js +0 -63
- package/dist/cjs/verdocs-search-activity.cjs.entry.js +0 -263
- package/dist/cjs/verdocs-search-box.cjs.entry.js +0 -60
- package/dist/cjs/verdocs-text-input.cjs.entry.js +0 -62
- package/dist/components/index2.js +0 -1
- package/dist/components/index4.js +0 -47
- package/dist/custom-elements.json +0 -830
- package/dist/esm/Auth-4b21fced.js +0 -157
- package/dist/esm/Token-29eea56d.js +0 -2458
- package/dist/esm/app-globals-0f993ce5.js +0 -3
- package/dist/esm/buffer-es6-5cef4368.js +0 -1985
- package/dist/esm/css-shim-60f618b9.js +0 -4
- package/dist/esm/dom-4eeb3fee.js +0 -73
- package/dist/esm/index-97ec070b.js +0 -47
- package/dist/esm/index-ddbd60b5.js +0 -3059
- package/dist/esm/index-ef172650.js +0 -1
- package/dist/esm/shadow-css-02866686.js +0 -387
- package/dist/esm/verdocs-button.entry.js +0 -45
- package/dist/esm/verdocs-dropdown.entry.js +0 -76
- package/dist/esm/verdocs-field-attachment.entry.js +0 -55
- package/dist/esm/verdocs-field-checkbox.entry.js +0 -35
- package/dist/esm/verdocs-field-date.entry.js +0 -2964
- package/dist/esm/verdocs-field-dropdown.entry.js +0 -55
- package/dist/esm/verdocs-field-initial.entry.js +0 -48
- package/dist/esm/verdocs-field-payment.entry.js +0 -82
- package/dist/esm/verdocs-field-radio-button.entry.js +0 -44
- package/dist/esm/verdocs-field-signature.entry.js +0 -48
- package/dist/esm/verdocs-field-textarea.entry.js +0 -59
- package/dist/esm/verdocs-field-textbox.entry.js +0 -59
- package/dist/esm/verdocs-search-activity.entry.js +0 -259
- package/dist/esm/verdocs-search-box.entry.js +0 -56
- package/dist/esm/verdocs-text-input.entry.js +0 -58
- package/dist/esm-es5/Auth-4b21fced.js +0 -1
- package/dist/esm-es5/Token-29eea56d.js +0 -1
- package/dist/esm-es5/app-globals-0f993ce5.js +0 -1
- package/dist/esm-es5/buffer-es6-5cef4368.js +0 -7
- package/dist/esm-es5/css-shim-60f618b9.js +0 -1
- package/dist/esm-es5/dom-4eeb3fee.js +0 -21
- package/dist/esm-es5/index-432c65a6.js +0 -1
- package/dist/esm-es5/index-97ec070b.js +0 -1
- package/dist/esm-es5/index-ddbd60b5.js +0 -2
- package/dist/esm-es5/index-ef172650.js +0 -1
- package/dist/esm-es5/shadow-css-02866686.js +0 -12
- package/dist/esm-es5/verdocs-button.entry.js +0 -1
- package/dist/esm-es5/verdocs-dropdown.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-attachment.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-checkbox.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-date.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-dropdown.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-initial.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-payment.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-radio-button.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-signature.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-textarea.entry.js +0 -1
- package/dist/esm-es5/verdocs-field-textbox.entry.js +0 -1
- package/dist/esm-es5/verdocs-search-activity.entry.js +0 -1
- package/dist/esm-es5/verdocs-search-box.entry.js +0 -1
- package/dist/esm-es5/verdocs-text-input.entry.js +0 -1
- package/dist/esm-es5/verdocs-view.entry.js +0 -23
- package/dist/verdocs-web-sdk/Auth-4b21fced.js +0 -157
- package/dist/verdocs-web-sdk/Auth-82e38539.system.js +0 -1
- package/dist/verdocs-web-sdk/Token-c1cf309e.system.js +0 -1
- package/dist/verdocs-web-sdk/app-globals-0f993ce5.js +0 -3
- package/dist/verdocs-web-sdk/app-globals-497eb362.system.js +0 -1
- package/dist/verdocs-web-sdk/buffer-es6-aa11181b.system.js +0 -7
- package/dist/verdocs-web-sdk/css-shim-60f618b9.js +0 -4
- package/dist/verdocs-web-sdk/css-shim-e41ceccc.system.js +0 -1
- package/dist/verdocs-web-sdk/dom-4eeb3fee.js +0 -73
- package/dist/verdocs-web-sdk/dom-89b5deb7.system.js +0 -21
- package/dist/verdocs-web-sdk/index-027b383e.system.js +0 -1
- package/dist/verdocs-web-sdk/index-06e036a1.system.js +0 -1
- package/dist/verdocs-web-sdk/index-432c65a6.js +0 -1974
- package/dist/verdocs-web-sdk/index-5d49316f.system.js +0 -1
- package/dist/verdocs-web-sdk/index-6465280a.system.js +0 -2
- package/dist/verdocs-web-sdk/index-97ec070b.js +0 -47
- package/dist/verdocs-web-sdk/index-ddbd60b5.js +0 -3059
- package/dist/verdocs-web-sdk/index-ef172650.js +0 -1
- package/dist/verdocs-web-sdk/shadow-css-02866686.js +0 -387
- package/dist/verdocs-web-sdk/shadow-css-6207e159.system.js +0 -13
- package/dist/verdocs-web-sdk/verdocs-auth.entry.js +0 -302
- package/dist/verdocs-web-sdk/verdocs-auth.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-button.entry.js +0 -45
- package/dist/verdocs-web-sdk/verdocs-button.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-dropdown.entry.js +0 -76
- package/dist/verdocs-web-sdk/verdocs-dropdown.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-attachment.entry.js +0 -55
- package/dist/verdocs-web-sdk/verdocs-field-attachment.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-checkbox.entry.js +0 -35
- package/dist/verdocs-web-sdk/verdocs-field-checkbox.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-date.entry.js +0 -2964
- package/dist/verdocs-web-sdk/verdocs-field-date.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-dropdown.entry.js +0 -55
- package/dist/verdocs-web-sdk/verdocs-field-dropdown.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-initial.entry.js +0 -48
- package/dist/verdocs-web-sdk/verdocs-field-initial.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-payment.entry.js +0 -82
- package/dist/verdocs-web-sdk/verdocs-field-payment.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-radio-button.entry.js +0 -44
- package/dist/verdocs-web-sdk/verdocs-field-radio-button.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-signature.entry.js +0 -48
- package/dist/verdocs-web-sdk/verdocs-field-signature.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-textarea.entry.js +0 -59
- package/dist/verdocs-web-sdk/verdocs-field-textarea.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-field-textbox.entry.js +0 -59
- package/dist/verdocs-web-sdk/verdocs-field-textbox.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-initial-dialog.entry.js +0 -239
- package/dist/verdocs-web-sdk/verdocs-initial-dialog.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-kba-dialog.entry.js +0 -77
- package/dist/verdocs-web-sdk/verdocs-kba-dialog.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-loader.entry.js +0 -15
- package/dist/verdocs-web-sdk/verdocs-loader.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-ok-dialog.entry.js +0 -44
- package/dist/verdocs-web-sdk/verdocs-ok-dialog.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-organization-card.entry.js +0 -18
- package/dist/verdocs-web-sdk/verdocs-organization-card.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-quick-functions.entry.js +0 -27
- package/dist/verdocs-web-sdk/verdocs-quick-functions.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-search-activity.entry.js +0 -259
- package/dist/verdocs-web-sdk/verdocs-search-activity.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-search-box.entry.js +0 -56
- package/dist/verdocs-web-sdk/verdocs-search-box.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-search-tabs.entry.js +0 -16
- package/dist/verdocs-web-sdk/verdocs-search-tabs.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-search.entry.js +0 -15
- package/dist/verdocs-web-sdk/verdocs-search.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-sign.entry.js +0 -1995
- package/dist/verdocs-web-sdk/verdocs-sign.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-signature-dialog.entry.js +0 -235
- package/dist/verdocs-web-sdk/verdocs-signature-dialog.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-status-indicator.entry.js +0 -7611
- package/dist/verdocs-web-sdk/verdocs-status-indicator.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-template-card.entry.js +0 -34
- package/dist/verdocs-web-sdk/verdocs-template-card.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-template-tags.entry.js +0 -16
- package/dist/verdocs-web-sdk/verdocs-template-tags.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-text-input.entry.js +0 -58
- package/dist/verdocs-web-sdk/verdocs-text-input.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-toggle.entry.js +0 -32
- package/dist/verdocs-web-sdk/verdocs-toggle.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-upload-dialog.entry.js +0 -119
- package/dist/verdocs-web-sdk/verdocs-upload-dialog.system.entry.js +0 -1
- package/dist/verdocs-web-sdk/verdocs-view.entry.js +0 -16118
- package/dist/verdocs-web-sdk/verdocs-view.system.entry.js +0 -23
- package/dist/verdocs-web-sdk/verdocs-web-sdk.system.js +0 -1
|
@@ -1,2968 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const index = require('./index-a24f3b6a.js');
|
|
6
|
-
|
|
7
|
-
function hasProperty(obj, prop) {
|
|
8
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function lastItemOf(arr) {
|
|
12
|
-
return arr[arr.length - 1];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// push only the items not included in the array
|
|
16
|
-
function pushUnique(arr, ...items) {
|
|
17
|
-
items.forEach((item) => {
|
|
18
|
-
if (arr.includes(item)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
arr.push(item);
|
|
22
|
-
});
|
|
23
|
-
return arr;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function stringToArray(str, separator) {
|
|
27
|
-
// convert empty string to an empty array
|
|
28
|
-
return str ? str.split(separator) : [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function isInRange(testVal, min, max) {
|
|
32
|
-
const minOK = min === undefined || testVal >= min;
|
|
33
|
-
const maxOK = max === undefined || testVal <= max;
|
|
34
|
-
return minOK && maxOK;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function limitToRange(val, min, max) {
|
|
38
|
-
if (val < min) {
|
|
39
|
-
return min;
|
|
40
|
-
}
|
|
41
|
-
if (val > max) {
|
|
42
|
-
return max;
|
|
43
|
-
}
|
|
44
|
-
return val;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function createTagRepeat(tagName, repeat, attributes = {}, index = 0, html = '') {
|
|
48
|
-
const openTagSrc = Object.keys(attributes).reduce((src, attr) => {
|
|
49
|
-
let val = attributes[attr];
|
|
50
|
-
if (typeof val === 'function') {
|
|
51
|
-
val = val(index);
|
|
52
|
-
}
|
|
53
|
-
return `${src} ${attr}="${val}"`;
|
|
54
|
-
}, tagName);
|
|
55
|
-
html += `<${openTagSrc}></${tagName}>`;
|
|
56
|
-
|
|
57
|
-
const next = index + 1;
|
|
58
|
-
return next < repeat
|
|
59
|
-
? createTagRepeat(tagName, repeat, attributes, next, html)
|
|
60
|
-
: html;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Remove the spacing surrounding tags for HTML parser not to create text nodes
|
|
64
|
-
// before/after elements
|
|
65
|
-
function optimizeTemplateHTML(html) {
|
|
66
|
-
return html.replace(/>\s+/g, '>').replace(/\s+</, '<');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function stripTime(timeValue) {
|
|
70
|
-
return new Date(timeValue).setHours(0, 0, 0, 0);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function today() {
|
|
74
|
-
return new Date().setHours(0, 0, 0, 0);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Get the time value of the start of given date or year, month and day
|
|
78
|
-
function dateValue(...args) {
|
|
79
|
-
switch (args.length) {
|
|
80
|
-
case 0:
|
|
81
|
-
return today();
|
|
82
|
-
case 1:
|
|
83
|
-
return stripTime(args[0]);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// use setFullYear() to keep 2-digit year from being mapped to 1900-1999
|
|
87
|
-
const newDate = new Date(0);
|
|
88
|
-
newDate.setFullYear(...args);
|
|
89
|
-
return newDate.setHours(0, 0, 0, 0);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function addDays(date, amount) {
|
|
93
|
-
const newDate = new Date(date);
|
|
94
|
-
return newDate.setDate(newDate.getDate() + amount);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function addWeeks(date, amount) {
|
|
98
|
-
return addDays(date, amount * 7);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function addMonths(date, amount) {
|
|
102
|
-
// If the day of the date is not in the new month, the last day of the new
|
|
103
|
-
// month will be returned. e.g. Jan 31 + 1 month → Feb 28 (not Mar 03)
|
|
104
|
-
const newDate = new Date(date);
|
|
105
|
-
const monthsToSet = newDate.getMonth() + amount;
|
|
106
|
-
let expectedMonth = monthsToSet % 12;
|
|
107
|
-
if (expectedMonth < 0) {
|
|
108
|
-
expectedMonth += 12;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const time = newDate.setMonth(monthsToSet);
|
|
112
|
-
return newDate.getMonth() !== expectedMonth ? newDate.setDate(0) : time;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function addYears(date, amount) {
|
|
116
|
-
// If the date is Feb 29 and the new year is not a leap year, Feb 28 of the
|
|
117
|
-
// new year will be returned.
|
|
118
|
-
const newDate = new Date(date);
|
|
119
|
-
const expectedMonth = newDate.getMonth();
|
|
120
|
-
const time = newDate.setFullYear(newDate.getFullYear() + amount);
|
|
121
|
-
return expectedMonth === 1 && newDate.getMonth() === 2 ? newDate.setDate(0) : time;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Calculate the distance bettwen 2 days of the week
|
|
125
|
-
function dayDiff(day, from) {
|
|
126
|
-
return (day - from + 7) % 7;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Get the date of the specified day of the week of given base date
|
|
130
|
-
function dayOfTheWeekOf(baseDate, dayOfWeek, weekStart = 0) {
|
|
131
|
-
const baseDay = new Date(baseDate).getDay();
|
|
132
|
-
return addDays(baseDate, dayDiff(dayOfWeek, weekStart) - dayDiff(baseDay, weekStart));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Get the ISO week of a date
|
|
136
|
-
function getWeek(date) {
|
|
137
|
-
// start of ISO week is Monday
|
|
138
|
-
const thuOfTheWeek = dayOfTheWeekOf(date, 4, 1);
|
|
139
|
-
// 1st week == the week where the 4th of January is in
|
|
140
|
-
const firstThu = dayOfTheWeekOf(new Date(thuOfTheWeek).setMonth(0, 4), 4, 1);
|
|
141
|
-
return Math.round((thuOfTheWeek - firstThu) / 604800000) + 1;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Get the start year of the period of years that includes given date
|
|
145
|
-
// years: length of the year period
|
|
146
|
-
function startOfYearPeriod(date, years) {
|
|
147
|
-
/* @see https://en.wikipedia.org/wiki/Year_zero#ISO_8601 */
|
|
148
|
-
const year = new Date(date).getFullYear();
|
|
149
|
-
return Math.floor(year / years) * years;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Convert date to the first/last date of the month/year of the date
|
|
153
|
-
function regularizeDate(date, timeSpan, useLastDate) {
|
|
154
|
-
if (timeSpan !== 1 && timeSpan !== 2) {
|
|
155
|
-
return date;
|
|
156
|
-
}
|
|
157
|
-
const newDate = new Date(date);
|
|
158
|
-
if (timeSpan === 1) {
|
|
159
|
-
useLastDate
|
|
160
|
-
? newDate.setMonth(newDate.getMonth() + 1, 0)
|
|
161
|
-
: newDate.setDate(1);
|
|
162
|
-
} else {
|
|
163
|
-
useLastDate
|
|
164
|
-
? newDate.setFullYear(newDate.getFullYear() + 1, 0, 0)
|
|
165
|
-
: newDate.setMonth(0, 1);
|
|
166
|
-
}
|
|
167
|
-
return newDate.setHours(0, 0, 0, 0);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// pattern for format parts
|
|
171
|
-
const reFormatTokens = /dd?|DD?|mm?|MM?|yy?(?:yy)?/;
|
|
172
|
-
// pattern for non date parts
|
|
173
|
-
const reNonDateParts = /[\s!-/:-@[-`{-~年月日]+/;
|
|
174
|
-
// cache for persed formats
|
|
175
|
-
let knownFormats = {};
|
|
176
|
-
// parse funtions for date parts
|
|
177
|
-
const parseFns = {
|
|
178
|
-
y(date, year) {
|
|
179
|
-
return new Date(date).setFullYear(parseInt(year, 10));
|
|
180
|
-
},
|
|
181
|
-
m(date, month, locale) {
|
|
182
|
-
const newDate = new Date(date);
|
|
183
|
-
let monthIndex = parseInt(month, 10) - 1;
|
|
184
|
-
|
|
185
|
-
if (isNaN(monthIndex)) {
|
|
186
|
-
if (!month) {
|
|
187
|
-
return NaN;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const monthName = month.toLowerCase();
|
|
191
|
-
const compareNames = name => name.toLowerCase().startsWith(monthName);
|
|
192
|
-
// compare with both short and full names because some locales have periods
|
|
193
|
-
// in the short names (not equal to the first X letters of the full names)
|
|
194
|
-
monthIndex = locale.monthsShort.findIndex(compareNames);
|
|
195
|
-
if (monthIndex < 0) {
|
|
196
|
-
monthIndex = locale.months.findIndex(compareNames);
|
|
197
|
-
}
|
|
198
|
-
if (monthIndex < 0) {
|
|
199
|
-
return NaN;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
newDate.setMonth(monthIndex);
|
|
204
|
-
return newDate.getMonth() !== normalizeMonth(monthIndex)
|
|
205
|
-
? newDate.setDate(0)
|
|
206
|
-
: newDate.getTime();
|
|
207
|
-
},
|
|
208
|
-
d(date, day) {
|
|
209
|
-
return new Date(date).setDate(parseInt(day, 10));
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
// format functions for date parts
|
|
213
|
-
const formatFns = {
|
|
214
|
-
d(date) {
|
|
215
|
-
return date.getDate();
|
|
216
|
-
},
|
|
217
|
-
dd(date) {
|
|
218
|
-
return padZero(date.getDate(), 2);
|
|
219
|
-
},
|
|
220
|
-
D(date, locale) {
|
|
221
|
-
return locale.daysShort[date.getDay()];
|
|
222
|
-
},
|
|
223
|
-
DD(date, locale) {
|
|
224
|
-
return locale.days[date.getDay()];
|
|
225
|
-
},
|
|
226
|
-
m(date) {
|
|
227
|
-
return date.getMonth() + 1;
|
|
228
|
-
},
|
|
229
|
-
mm(date) {
|
|
230
|
-
return padZero(date.getMonth() + 1, 2);
|
|
231
|
-
},
|
|
232
|
-
M(date, locale) {
|
|
233
|
-
return locale.monthsShort[date.getMonth()];
|
|
234
|
-
},
|
|
235
|
-
MM(date, locale) {
|
|
236
|
-
return locale.months[date.getMonth()];
|
|
237
|
-
},
|
|
238
|
-
y(date) {
|
|
239
|
-
return date.getFullYear();
|
|
240
|
-
},
|
|
241
|
-
yy(date) {
|
|
242
|
-
return padZero(date.getFullYear(), 2).slice(-2);
|
|
243
|
-
},
|
|
244
|
-
yyyy(date) {
|
|
245
|
-
return padZero(date.getFullYear(), 4);
|
|
246
|
-
},
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
// get month index in normal range (0 - 11) from any number
|
|
250
|
-
function normalizeMonth(monthIndex) {
|
|
251
|
-
return monthIndex > -1 ? monthIndex % 12 : normalizeMonth(monthIndex + 12);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function padZero(num, length) {
|
|
255
|
-
return num.toString().padStart(length, '0');
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function parseFormatString(format) {
|
|
259
|
-
if (typeof format !== 'string') {
|
|
260
|
-
throw new Error("Invalid date format.");
|
|
261
|
-
}
|
|
262
|
-
if (format in knownFormats) {
|
|
263
|
-
return knownFormats[format];
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// sprit the format string into parts and seprators
|
|
267
|
-
const separators = format.split(reFormatTokens);
|
|
268
|
-
const parts = format.match(new RegExp(reFormatTokens, 'g'));
|
|
269
|
-
if (separators.length === 0 || !parts) {
|
|
270
|
-
throw new Error("Invalid date format.");
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// collect format functions used in the format
|
|
274
|
-
const partFormatters = parts.map(token => formatFns[token]);
|
|
275
|
-
|
|
276
|
-
// collect parse function keys used in the format
|
|
277
|
-
// iterate over parseFns' keys in order to keep the order of the keys.
|
|
278
|
-
const partParserKeys = Object.keys(parseFns).reduce((keys, key) => {
|
|
279
|
-
const token = parts.find(part => part[0] !== 'D' && part[0].toLowerCase() === key);
|
|
280
|
-
if (token) {
|
|
281
|
-
keys.push(key);
|
|
282
|
-
}
|
|
283
|
-
return keys;
|
|
284
|
-
}, []);
|
|
285
|
-
|
|
286
|
-
return knownFormats[format] = {
|
|
287
|
-
parser(dateStr, locale) {
|
|
288
|
-
const dateParts = dateStr.split(reNonDateParts).reduce((dtParts, part, index) => {
|
|
289
|
-
if (part.length > 0 && parts[index]) {
|
|
290
|
-
const token = parts[index][0];
|
|
291
|
-
if (token === 'M') {
|
|
292
|
-
dtParts.m = part;
|
|
293
|
-
} else if (token !== 'D') {
|
|
294
|
-
dtParts[token] = part;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return dtParts;
|
|
298
|
-
}, {});
|
|
299
|
-
|
|
300
|
-
// iterate over partParserkeys so that the parsing is made in the oder
|
|
301
|
-
// of year, month and day to prevent the day parser from correcting last
|
|
302
|
-
// day of month wrongly
|
|
303
|
-
return partParserKeys.reduce((origDate, key) => {
|
|
304
|
-
const newDate = parseFns[key](origDate, dateParts[key], locale);
|
|
305
|
-
// ingnore the part failed to parse
|
|
306
|
-
return isNaN(newDate) ? origDate : newDate;
|
|
307
|
-
}, today());
|
|
308
|
-
},
|
|
309
|
-
formatter(date, locale) {
|
|
310
|
-
let dateStr = partFormatters.reduce((str, fn, index) => {
|
|
311
|
-
return str += `${separators[index]}${fn(date, locale)}`;
|
|
312
|
-
}, '');
|
|
313
|
-
// separators' length is always parts' length + 1,
|
|
314
|
-
return dateStr += lastItemOf(separators);
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function parseDate(dateStr, format, locale) {
|
|
320
|
-
if (dateStr instanceof Date || typeof dateStr === 'number') {
|
|
321
|
-
const date = stripTime(dateStr);
|
|
322
|
-
return isNaN(date) ? undefined : date;
|
|
323
|
-
}
|
|
324
|
-
if (!dateStr) {
|
|
325
|
-
return undefined;
|
|
326
|
-
}
|
|
327
|
-
if (dateStr === 'today') {
|
|
328
|
-
return today();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (format && format.toValue) {
|
|
332
|
-
const date = format.toValue(dateStr, format, locale);
|
|
333
|
-
return isNaN(date) ? undefined : stripTime(date);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return parseFormatString(format).parser(dateStr, locale);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function formatDate(date, format, locale) {
|
|
340
|
-
if (isNaN(date) || (!date && date !== 0)) {
|
|
341
|
-
return '';
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const dateObj = typeof date === 'number' ? new Date(date) : date;
|
|
345
|
-
|
|
346
|
-
if (format.toDisplay) {
|
|
347
|
-
return format.toDisplay(dateObj, format, locale);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return parseFormatString(format).formatter(dateObj, locale);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const range = document.createRange();
|
|
354
|
-
|
|
355
|
-
function parseHTML(html) {
|
|
356
|
-
return range.createContextualFragment(html);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function getParent(el) {
|
|
360
|
-
return el.parentElement
|
|
361
|
-
|| (el.parentNode instanceof ShadowRoot ? el.parentNode.host : undefined);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function isActiveElement(el) {
|
|
365
|
-
return el.getRootNode().activeElement === el;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// equivalent to jQuery's :visble
|
|
369
|
-
function isVisible(el) {
|
|
370
|
-
return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function hideElement(el) {
|
|
374
|
-
if (el.style.display === 'none') {
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
// back up the existing display setting in data-style-display
|
|
378
|
-
if (el.style.display) {
|
|
379
|
-
el.dataset.styleDisplay = el.style.display;
|
|
380
|
-
}
|
|
381
|
-
el.style.display = 'none';
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function showElement(el) {
|
|
385
|
-
if (el.style.display !== 'none') {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
if (el.dataset.styleDisplay) {
|
|
389
|
-
// restore backed-up dispay property
|
|
390
|
-
el.style.display = el.dataset.styleDisplay;
|
|
391
|
-
delete el.dataset.styleDisplay;
|
|
392
|
-
} else {
|
|
393
|
-
el.style.display = '';
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function emptyChildNodes(el) {
|
|
398
|
-
if (el.firstChild) {
|
|
399
|
-
el.removeChild(el.firstChild);
|
|
400
|
-
emptyChildNodes(el);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
function replaceChildNodes(el, newChildNodes) {
|
|
405
|
-
emptyChildNodes(el);
|
|
406
|
-
if (newChildNodes instanceof DocumentFragment) {
|
|
407
|
-
el.appendChild(newChildNodes);
|
|
408
|
-
} else if (typeof newChildNodes === 'string') {
|
|
409
|
-
el.appendChild(parseHTML(newChildNodes));
|
|
410
|
-
} else if (typeof newChildNodes.forEach === 'function') {
|
|
411
|
-
newChildNodes.forEach((node) => {
|
|
412
|
-
el.appendChild(node);
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const listenerRegistry = new WeakMap();
|
|
418
|
-
const {addEventListener, removeEventListener} = EventTarget.prototype;
|
|
419
|
-
|
|
420
|
-
// Register event listeners to a key object
|
|
421
|
-
// listeners: array of listener definitions;
|
|
422
|
-
// - each definition must be a flat array of event target and the arguments
|
|
423
|
-
// used to call addEventListener() on the target
|
|
424
|
-
function registerListeners(keyObj, listeners) {
|
|
425
|
-
let registered = listenerRegistry.get(keyObj);
|
|
426
|
-
if (!registered) {
|
|
427
|
-
registered = [];
|
|
428
|
-
listenerRegistry.set(keyObj, registered);
|
|
429
|
-
}
|
|
430
|
-
listeners.forEach((listener) => {
|
|
431
|
-
addEventListener.call(...listener);
|
|
432
|
-
registered.push(listener);
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function unregisterListeners(keyObj) {
|
|
437
|
-
let listeners = listenerRegistry.get(keyObj);
|
|
438
|
-
if (!listeners) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
listeners.forEach((listener) => {
|
|
442
|
-
removeEventListener.call(...listener);
|
|
443
|
-
});
|
|
444
|
-
listenerRegistry.delete(keyObj);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// Event.composedPath() polyfill for Edge
|
|
448
|
-
// based on https://gist.github.com/kleinfreund/e9787d73776c0e3750dcfcdc89f100ec
|
|
449
|
-
if (!Event.prototype.composedPath) {
|
|
450
|
-
const getComposedPath = (node, path = []) => {
|
|
451
|
-
path.push(node);
|
|
452
|
-
|
|
453
|
-
let parent;
|
|
454
|
-
if (node.parentNode) {
|
|
455
|
-
parent = node.parentNode;
|
|
456
|
-
} else if (node.host) { // ShadowRoot
|
|
457
|
-
parent = node.host;
|
|
458
|
-
} else if (node.defaultView) { // Document
|
|
459
|
-
parent = node.defaultView;
|
|
460
|
-
}
|
|
461
|
-
return parent ? getComposedPath(parent, path) : path;
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
Event.prototype.composedPath = function () {
|
|
465
|
-
return getComposedPath(this.target);
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function findFromPath(path, criteria, currentTarget) {
|
|
470
|
-
const [node, ...rest] = path;
|
|
471
|
-
if (criteria(node)) {
|
|
472
|
-
return node;
|
|
473
|
-
}
|
|
474
|
-
if (node === currentTarget || node.tagName === 'HTML' || rest.length === 0) {
|
|
475
|
-
// stop when reaching currentTarget or <html>
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
return findFromPath(rest, criteria, currentTarget);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// Search for the actual target of a delegated event
|
|
482
|
-
function findElementInEventPath(ev, selector) {
|
|
483
|
-
const criteria = typeof selector === 'function'
|
|
484
|
-
? selector
|
|
485
|
-
: el => el instanceof Element && el.matches(selector);
|
|
486
|
-
return findFromPath(ev.composedPath(), criteria, ev.currentTarget);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// default locales
|
|
490
|
-
const locales = {
|
|
491
|
-
en: {
|
|
492
|
-
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
|
493
|
-
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
494
|
-
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
|
|
495
|
-
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
|
496
|
-
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
|
497
|
-
today: "Today",
|
|
498
|
-
clear: "Clear",
|
|
499
|
-
titleFormat: "MM y"
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
// config options updatable by setOptions() and their default values
|
|
504
|
-
const defaultOptions = {
|
|
505
|
-
autohide: false,
|
|
506
|
-
beforeShowDay: null,
|
|
507
|
-
beforeShowDecade: null,
|
|
508
|
-
beforeShowMonth: null,
|
|
509
|
-
beforeShowYear: null,
|
|
510
|
-
calendarWeeks: false,
|
|
511
|
-
clearBtn: false,
|
|
512
|
-
dateDelimiter: ',',
|
|
513
|
-
datesDisabled: [],
|
|
514
|
-
daysOfWeekDisabled: [],
|
|
515
|
-
daysOfWeekHighlighted: [],
|
|
516
|
-
defaultViewDate: undefined, // placeholder, defaults to today() by the program
|
|
517
|
-
disableTouchKeyboard: false,
|
|
518
|
-
format: 'mm/dd/yyyy',
|
|
519
|
-
language: 'en',
|
|
520
|
-
maxDate: null,
|
|
521
|
-
maxNumberOfDates: 1,
|
|
522
|
-
maxView: 3,
|
|
523
|
-
minDate: null,
|
|
524
|
-
nextArrow: '»',
|
|
525
|
-
orientation: 'auto',
|
|
526
|
-
pickLevel: 0,
|
|
527
|
-
prevArrow: '«',
|
|
528
|
-
showDaysOfWeek: true,
|
|
529
|
-
showOnClick: true,
|
|
530
|
-
showOnFocus: true,
|
|
531
|
-
startView: 0,
|
|
532
|
-
title: '',
|
|
533
|
-
todayBtn: false,
|
|
534
|
-
todayBtnMode: 0,
|
|
535
|
-
todayHighlight: false,
|
|
536
|
-
updateOnBlur: true,
|
|
537
|
-
weekStart: 0,
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
const {
|
|
541
|
-
language: defaultLang,
|
|
542
|
-
format: defaultFormat,
|
|
543
|
-
weekStart: defaultWeekStart,
|
|
544
|
-
} = defaultOptions;
|
|
545
|
-
|
|
546
|
-
// Reducer function to filter out invalid day-of-week from the input
|
|
547
|
-
function sanitizeDOW(dow, day) {
|
|
548
|
-
return dow.length < 6 && day >= 0 && day < 7
|
|
549
|
-
? pushUnique(dow, day)
|
|
550
|
-
: dow;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function calcEndOfWeek(startOfWeek) {
|
|
554
|
-
return (startOfWeek + 6) % 7;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// validate input date. if invalid, fallback to the original value
|
|
558
|
-
function validateDate(value, format, locale, origValue) {
|
|
559
|
-
const date = parseDate(value, format, locale);
|
|
560
|
-
return date !== undefined ? date : origValue;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// Validate viewId. if invalid, fallback to the original value
|
|
564
|
-
function validateViewId(value, origValue, max = 3) {
|
|
565
|
-
const viewId = parseInt(value, 10);
|
|
566
|
-
return viewId >= 0 && viewId <= max ? viewId : origValue;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// Create Datepicker configuration to set
|
|
570
|
-
function processOptions(options, datepicker) {
|
|
571
|
-
const inOpts = Object.assign({}, options);
|
|
572
|
-
const config = {};
|
|
573
|
-
const locales = datepicker.constructor.locales;
|
|
574
|
-
const rangeSideIndex = datepicker.rangeSideIndex;
|
|
575
|
-
let {
|
|
576
|
-
format,
|
|
577
|
-
language,
|
|
578
|
-
locale,
|
|
579
|
-
maxDate,
|
|
580
|
-
maxView,
|
|
581
|
-
minDate,
|
|
582
|
-
pickLevel,
|
|
583
|
-
startView,
|
|
584
|
-
weekStart,
|
|
585
|
-
} = datepicker.config || {};
|
|
586
|
-
|
|
587
|
-
if (inOpts.language) {
|
|
588
|
-
let lang;
|
|
589
|
-
if (inOpts.language !== language) {
|
|
590
|
-
if (locales[inOpts.language]) {
|
|
591
|
-
lang = inOpts.language;
|
|
592
|
-
} else {
|
|
593
|
-
// Check if langauge + region tag can fallback to the one without
|
|
594
|
-
// region (e.g. fr-CA → fr)
|
|
595
|
-
lang = inOpts.language.split('-')[0];
|
|
596
|
-
if (locales[lang] === undefined) {
|
|
597
|
-
lang = false;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
delete inOpts.language;
|
|
602
|
-
if (lang) {
|
|
603
|
-
language = config.language = lang;
|
|
604
|
-
|
|
605
|
-
// update locale as well when updating language
|
|
606
|
-
const origLocale = locale || locales[defaultLang];
|
|
607
|
-
// use default language's properties for the fallback
|
|
608
|
-
locale = Object.assign({
|
|
609
|
-
format: defaultFormat,
|
|
610
|
-
weekStart: defaultWeekStart
|
|
611
|
-
}, locales[defaultLang]);
|
|
612
|
-
if (language !== defaultLang) {
|
|
613
|
-
Object.assign(locale, locales[language]);
|
|
614
|
-
}
|
|
615
|
-
config.locale = locale;
|
|
616
|
-
// if format and/or weekStart are the same as old locale's defaults,
|
|
617
|
-
// update them to new locale's defaults
|
|
618
|
-
if (format === origLocale.format) {
|
|
619
|
-
format = config.format = locale.format;
|
|
620
|
-
}
|
|
621
|
-
if (weekStart === origLocale.weekStart) {
|
|
622
|
-
weekStart = config.weekStart = locale.weekStart;
|
|
623
|
-
config.weekEnd = calcEndOfWeek(locale.weekStart);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
if (inOpts.format) {
|
|
629
|
-
const hasToDisplay = typeof inOpts.format.toDisplay === 'function';
|
|
630
|
-
const hasToValue = typeof inOpts.format.toValue === 'function';
|
|
631
|
-
const validFormatString = reFormatTokens.test(inOpts.format);
|
|
632
|
-
if ((hasToDisplay && hasToValue) || validFormatString) {
|
|
633
|
-
format = config.format = inOpts.format;
|
|
634
|
-
}
|
|
635
|
-
delete inOpts.format;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
//*** pick level ***//
|
|
639
|
-
let newPickLevel = pickLevel;
|
|
640
|
-
if (inOpts.pickLevel !== undefined) {
|
|
641
|
-
newPickLevel = validateViewId(inOpts.pickLevel, 2);
|
|
642
|
-
delete inOpts.pickLevel;
|
|
643
|
-
}
|
|
644
|
-
if (newPickLevel !== pickLevel) {
|
|
645
|
-
if (newPickLevel > pickLevel) {
|
|
646
|
-
// complement current minDate/madDate so that the existing range will be
|
|
647
|
-
// expanded to fit the new level later
|
|
648
|
-
if (inOpts.minDate === undefined) {
|
|
649
|
-
inOpts.minDate = minDate;
|
|
650
|
-
}
|
|
651
|
-
if (inOpts.maxDate === undefined) {
|
|
652
|
-
inOpts.maxDate = maxDate;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
// complement datesDisabled so that it will be reset later
|
|
656
|
-
if (!inOpts.datesDisabled) {
|
|
657
|
-
inOpts.datesDisabled = [];
|
|
658
|
-
}
|
|
659
|
-
pickLevel = config.pickLevel = newPickLevel;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
//*** dates ***//
|
|
663
|
-
// while min and maxDate for "no limit" in the options are better to be null
|
|
664
|
-
// (especially when updating), the ones in the config have to be undefined
|
|
665
|
-
// because null is treated as 0 (= unix epoch) when comparing with time value
|
|
666
|
-
let minDt = minDate;
|
|
667
|
-
let maxDt = maxDate;
|
|
668
|
-
if (inOpts.minDate !== undefined) {
|
|
669
|
-
const defaultMinDt = dateValue(0, 0, 1);
|
|
670
|
-
minDt = inOpts.minDate === null
|
|
671
|
-
? defaultMinDt // set 0000-01-01 to prevent negative values for year
|
|
672
|
-
: validateDate(inOpts.minDate, format, locale, minDt);
|
|
673
|
-
if (minDt !== defaultMinDt) {
|
|
674
|
-
minDt = regularizeDate(minDt, pickLevel, false);
|
|
675
|
-
}
|
|
676
|
-
delete inOpts.minDate;
|
|
677
|
-
}
|
|
678
|
-
if (inOpts.maxDate !== undefined) {
|
|
679
|
-
maxDt = inOpts.maxDate === null
|
|
680
|
-
? undefined
|
|
681
|
-
: validateDate(inOpts.maxDate, format, locale, maxDt);
|
|
682
|
-
if (maxDt !== undefined) {
|
|
683
|
-
maxDt = regularizeDate(maxDt, pickLevel, true);
|
|
684
|
-
}
|
|
685
|
-
delete inOpts.maxDate;
|
|
686
|
-
}
|
|
687
|
-
if (maxDt < minDt) {
|
|
688
|
-
minDate = config.minDate = maxDt;
|
|
689
|
-
maxDate = config.maxDate = minDt;
|
|
690
|
-
} else {
|
|
691
|
-
if (minDate !== minDt) {
|
|
692
|
-
minDate = config.minDate = minDt;
|
|
693
|
-
}
|
|
694
|
-
if (maxDate !== maxDt) {
|
|
695
|
-
maxDate = config.maxDate = maxDt;
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
if (inOpts.datesDisabled) {
|
|
700
|
-
config.datesDisabled = inOpts.datesDisabled.reduce((dates, dt) => {
|
|
701
|
-
const date = parseDate(dt, format, locale);
|
|
702
|
-
return date !== undefined
|
|
703
|
-
? pushUnique(dates, regularizeDate(date, pickLevel, rangeSideIndex))
|
|
704
|
-
: dates;
|
|
705
|
-
}, []);
|
|
706
|
-
delete inOpts.datesDisabled;
|
|
707
|
-
}
|
|
708
|
-
if (inOpts.defaultViewDate !== undefined) {
|
|
709
|
-
const viewDate = parseDate(inOpts.defaultViewDate, format, locale);
|
|
710
|
-
if (viewDate !== undefined) {
|
|
711
|
-
config.defaultViewDate = viewDate;
|
|
712
|
-
}
|
|
713
|
-
delete inOpts.defaultViewDate;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
//*** days of week ***//
|
|
717
|
-
if (inOpts.weekStart !== undefined) {
|
|
718
|
-
const wkStart = Number(inOpts.weekStart) % 7;
|
|
719
|
-
if (!isNaN(wkStart)) {
|
|
720
|
-
weekStart = config.weekStart = wkStart;
|
|
721
|
-
config.weekEnd = calcEndOfWeek(wkStart);
|
|
722
|
-
}
|
|
723
|
-
delete inOpts.weekStart;
|
|
724
|
-
}
|
|
725
|
-
if (inOpts.daysOfWeekDisabled) {
|
|
726
|
-
config.daysOfWeekDisabled = inOpts.daysOfWeekDisabled.reduce(sanitizeDOW, []);
|
|
727
|
-
delete inOpts.daysOfWeekDisabled;
|
|
728
|
-
}
|
|
729
|
-
if (inOpts.daysOfWeekHighlighted) {
|
|
730
|
-
config.daysOfWeekHighlighted = inOpts.daysOfWeekHighlighted.reduce(sanitizeDOW, []);
|
|
731
|
-
delete inOpts.daysOfWeekHighlighted;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
//*** multi date ***//
|
|
735
|
-
if (inOpts.maxNumberOfDates !== undefined) {
|
|
736
|
-
const maxNumberOfDates = parseInt(inOpts.maxNumberOfDates, 10);
|
|
737
|
-
if (maxNumberOfDates >= 0) {
|
|
738
|
-
config.maxNumberOfDates = maxNumberOfDates;
|
|
739
|
-
config.multidate = maxNumberOfDates !== 1;
|
|
740
|
-
}
|
|
741
|
-
delete inOpts.maxNumberOfDates;
|
|
742
|
-
}
|
|
743
|
-
if (inOpts.dateDelimiter) {
|
|
744
|
-
config.dateDelimiter = String(inOpts.dateDelimiter);
|
|
745
|
-
delete inOpts.dateDelimiter;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
//*** view ***//
|
|
749
|
-
let newMaxView = maxView;
|
|
750
|
-
if (inOpts.maxView !== undefined) {
|
|
751
|
-
newMaxView = validateViewId(inOpts.maxView, maxView);
|
|
752
|
-
delete inOpts.maxView;
|
|
753
|
-
}
|
|
754
|
-
// ensure max view >= pick level
|
|
755
|
-
newMaxView = pickLevel > newMaxView ? pickLevel : newMaxView;
|
|
756
|
-
if (newMaxView !== maxView) {
|
|
757
|
-
maxView = config.maxView = newMaxView;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
let newStartView = startView;
|
|
761
|
-
if (inOpts.startView !== undefined) {
|
|
762
|
-
newStartView = validateViewId(inOpts.startView, newStartView);
|
|
763
|
-
delete inOpts.startView;
|
|
764
|
-
}
|
|
765
|
-
// ensure pick level <= start view <= max view
|
|
766
|
-
if (newStartView < pickLevel) {
|
|
767
|
-
newStartView = pickLevel;
|
|
768
|
-
} else if (newStartView > maxView) {
|
|
769
|
-
newStartView = maxView;
|
|
770
|
-
}
|
|
771
|
-
if (newStartView !== startView) {
|
|
772
|
-
config.startView = newStartView;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
//*** template ***//
|
|
776
|
-
if (inOpts.prevArrow) {
|
|
777
|
-
const prevArrow = parseHTML(inOpts.prevArrow);
|
|
778
|
-
if (prevArrow.childNodes.length > 0) {
|
|
779
|
-
config.prevArrow = prevArrow.childNodes;
|
|
780
|
-
}
|
|
781
|
-
delete inOpts.prevArrow;
|
|
782
|
-
}
|
|
783
|
-
if (inOpts.nextArrow) {
|
|
784
|
-
const nextArrow = parseHTML(inOpts.nextArrow);
|
|
785
|
-
if (nextArrow.childNodes.length > 0) {
|
|
786
|
-
config.nextArrow = nextArrow.childNodes;
|
|
787
|
-
}
|
|
788
|
-
delete inOpts.nextArrow;
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
//*** misc ***//
|
|
792
|
-
if (inOpts.disableTouchKeyboard !== undefined) {
|
|
793
|
-
config.disableTouchKeyboard = 'ontouchstart' in document && !!inOpts.disableTouchKeyboard;
|
|
794
|
-
delete inOpts.disableTouchKeyboard;
|
|
795
|
-
}
|
|
796
|
-
if (inOpts.orientation) {
|
|
797
|
-
const orientation = inOpts.orientation.toLowerCase().split(/\s+/g);
|
|
798
|
-
config.orientation = {
|
|
799
|
-
x: orientation.find(x => (x === 'left' || x === 'right')) || 'auto',
|
|
800
|
-
y: orientation.find(y => (y === 'top' || y === 'bottom')) || 'auto',
|
|
801
|
-
};
|
|
802
|
-
delete inOpts.orientation;
|
|
803
|
-
}
|
|
804
|
-
if (inOpts.todayBtnMode !== undefined) {
|
|
805
|
-
switch(inOpts.todayBtnMode) {
|
|
806
|
-
case 0:
|
|
807
|
-
case 1:
|
|
808
|
-
config.todayBtnMode = inOpts.todayBtnMode;
|
|
809
|
-
}
|
|
810
|
-
delete inOpts.todayBtnMode;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
//*** copy the rest ***//
|
|
814
|
-
Object.keys(inOpts).forEach((key) => {
|
|
815
|
-
if (inOpts[key] !== undefined && hasProperty(defaultOptions, key)) {
|
|
816
|
-
config[key] = inOpts[key];
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
|
|
820
|
-
return config;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
const pickerTemplate = optimizeTemplateHTML(`<div class="datepicker">
|
|
824
|
-
<div class="datepicker-picker">
|
|
825
|
-
<div class="datepicker-header">
|
|
826
|
-
<div class="datepicker-title"></div>
|
|
827
|
-
<div class="datepicker-controls">
|
|
828
|
-
<button type="button" class="%buttonClass% prev-btn"></button>
|
|
829
|
-
<button type="button" class="%buttonClass% view-switch"></button>
|
|
830
|
-
<button type="button" class="%buttonClass% next-btn"></button>
|
|
831
|
-
</div>
|
|
832
|
-
</div>
|
|
833
|
-
<div class="datepicker-main"></div>
|
|
834
|
-
<div class="datepicker-footer">
|
|
835
|
-
<div class="datepicker-controls">
|
|
836
|
-
<button type="button" class="%buttonClass% today-btn"></button>
|
|
837
|
-
<button type="button" class="%buttonClass% clear-btn"></button>
|
|
838
|
-
</div>
|
|
839
|
-
</div>
|
|
840
|
-
</div>
|
|
841
|
-
</div>`);
|
|
842
|
-
|
|
843
|
-
const daysTemplate = optimizeTemplateHTML(`<div class="days">
|
|
844
|
-
<div class="days-of-week">${createTagRepeat('span', 7, {class: 'dow'})}</div>
|
|
845
|
-
<div class="datepicker-grid">${createTagRepeat('span', 42)}</div>
|
|
846
|
-
</div>`);
|
|
847
|
-
|
|
848
|
-
const calendarWeeksTemplate = optimizeTemplateHTML(`<div class="calendar-weeks">
|
|
849
|
-
<div class="days-of-week"><span class="dow"></span></div>
|
|
850
|
-
<div class="weeks">${createTagRepeat('span', 6, {class: 'week'})}</div>
|
|
851
|
-
</div>`);
|
|
852
|
-
|
|
853
|
-
// Base class of the view classes
|
|
854
|
-
class View {
|
|
855
|
-
constructor(picker, config) {
|
|
856
|
-
Object.assign(this, config, {
|
|
857
|
-
picker,
|
|
858
|
-
element: parseHTML(`<div class="datepicker-view"></div>`).firstChild,
|
|
859
|
-
selected: [],
|
|
860
|
-
});
|
|
861
|
-
this.init(this.picker.datepicker.config);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
init(options) {
|
|
865
|
-
if (options.pickLevel !== undefined) {
|
|
866
|
-
this.isMinView = this.id === options.pickLevel;
|
|
867
|
-
}
|
|
868
|
-
this.setOptions(options);
|
|
869
|
-
this.updateFocus();
|
|
870
|
-
this.updateSelection();
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
// Execute beforeShow() callback and apply the result to the element
|
|
874
|
-
// args:
|
|
875
|
-
// - current - current value on the iteration on view rendering
|
|
876
|
-
// - timeValue - time value of the date to pass to beforeShow()
|
|
877
|
-
performBeforeHook(el, current, timeValue) {
|
|
878
|
-
let result = this.beforeShow(new Date(timeValue));
|
|
879
|
-
switch (typeof result) {
|
|
880
|
-
case 'boolean':
|
|
881
|
-
result = {enabled: result};
|
|
882
|
-
break;
|
|
883
|
-
case 'string':
|
|
884
|
-
result = {classes: result};
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
if (result) {
|
|
888
|
-
if (result.enabled === false) {
|
|
889
|
-
el.classList.add('disabled');
|
|
890
|
-
pushUnique(this.disabled, current);
|
|
891
|
-
}
|
|
892
|
-
if (result.classes) {
|
|
893
|
-
const extraClasses = result.classes.split(/\s+/);
|
|
894
|
-
el.classList.add(...extraClasses);
|
|
895
|
-
if (extraClasses.includes('disabled')) {
|
|
896
|
-
pushUnique(this.disabled, current);
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
if (result.content) {
|
|
900
|
-
replaceChildNodes(el, result.content);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
class DaysView extends View {
|
|
907
|
-
constructor(picker) {
|
|
908
|
-
super(picker, {
|
|
909
|
-
id: 0,
|
|
910
|
-
name: 'days',
|
|
911
|
-
cellClass: 'day',
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
init(options, onConstruction = true) {
|
|
916
|
-
if (onConstruction) {
|
|
917
|
-
const inner = parseHTML(daysTemplate).firstChild;
|
|
918
|
-
this.dow = inner.firstChild;
|
|
919
|
-
this.grid = inner.lastChild;
|
|
920
|
-
this.element.appendChild(inner);
|
|
921
|
-
}
|
|
922
|
-
super.init(options);
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
setOptions(options) {
|
|
926
|
-
let updateDOW;
|
|
927
|
-
|
|
928
|
-
if (hasProperty(options, 'minDate')) {
|
|
929
|
-
this.minDate = options.minDate;
|
|
930
|
-
}
|
|
931
|
-
if (hasProperty(options, 'maxDate')) {
|
|
932
|
-
this.maxDate = options.maxDate;
|
|
933
|
-
}
|
|
934
|
-
if (options.datesDisabled) {
|
|
935
|
-
this.datesDisabled = options.datesDisabled;
|
|
936
|
-
}
|
|
937
|
-
if (options.daysOfWeekDisabled) {
|
|
938
|
-
this.daysOfWeekDisabled = options.daysOfWeekDisabled;
|
|
939
|
-
updateDOW = true;
|
|
940
|
-
}
|
|
941
|
-
if (options.daysOfWeekHighlighted) {
|
|
942
|
-
this.daysOfWeekHighlighted = options.daysOfWeekHighlighted;
|
|
943
|
-
}
|
|
944
|
-
if (options.todayHighlight !== undefined) {
|
|
945
|
-
this.todayHighlight = options.todayHighlight;
|
|
946
|
-
}
|
|
947
|
-
if (options.weekStart !== undefined) {
|
|
948
|
-
this.weekStart = options.weekStart;
|
|
949
|
-
this.weekEnd = options.weekEnd;
|
|
950
|
-
updateDOW = true;
|
|
951
|
-
}
|
|
952
|
-
if (options.locale) {
|
|
953
|
-
const locale = this.locale = options.locale;
|
|
954
|
-
this.dayNames = locale.daysMin;
|
|
955
|
-
this.switchLabelFormat = locale.titleFormat;
|
|
956
|
-
updateDOW = true;
|
|
957
|
-
}
|
|
958
|
-
if (options.beforeShowDay !== undefined) {
|
|
959
|
-
this.beforeShow = typeof options.beforeShowDay === 'function'
|
|
960
|
-
? options.beforeShowDay
|
|
961
|
-
: undefined;
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
if (options.calendarWeeks !== undefined) {
|
|
965
|
-
if (options.calendarWeeks && !this.calendarWeeks) {
|
|
966
|
-
const weeksElem = parseHTML(calendarWeeksTemplate).firstChild;
|
|
967
|
-
this.calendarWeeks = {
|
|
968
|
-
element: weeksElem,
|
|
969
|
-
dow: weeksElem.firstChild,
|
|
970
|
-
weeks: weeksElem.lastChild,
|
|
971
|
-
};
|
|
972
|
-
this.element.insertBefore(weeksElem, this.element.firstChild);
|
|
973
|
-
} else if (this.calendarWeeks && !options.calendarWeeks) {
|
|
974
|
-
this.element.removeChild(this.calendarWeeks.element);
|
|
975
|
-
this.calendarWeeks = null;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
if (options.showDaysOfWeek !== undefined) {
|
|
979
|
-
if (options.showDaysOfWeek) {
|
|
980
|
-
showElement(this.dow);
|
|
981
|
-
if (this.calendarWeeks) {
|
|
982
|
-
showElement(this.calendarWeeks.dow);
|
|
983
|
-
}
|
|
984
|
-
} else {
|
|
985
|
-
hideElement(this.dow);
|
|
986
|
-
if (this.calendarWeeks) {
|
|
987
|
-
hideElement(this.calendarWeeks.dow);
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
// update days-of-week when locale, daysOfweekDisabled or weekStart is changed
|
|
993
|
-
if (updateDOW) {
|
|
994
|
-
Array.from(this.dow.children).forEach((el, index) => {
|
|
995
|
-
const dow = (this.weekStart + index) % 7;
|
|
996
|
-
el.textContent = this.dayNames[dow];
|
|
997
|
-
el.className = this.daysOfWeekDisabled.includes(dow) ? 'dow disabled' : 'dow';
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
// Apply update on the focused date to view's settings
|
|
1003
|
-
updateFocus() {
|
|
1004
|
-
const viewDate = new Date(this.picker.viewDate);
|
|
1005
|
-
const viewYear = viewDate.getFullYear();
|
|
1006
|
-
const viewMonth = viewDate.getMonth();
|
|
1007
|
-
const firstOfMonth = dateValue(viewYear, viewMonth, 1);
|
|
1008
|
-
const start = dayOfTheWeekOf(firstOfMonth, this.weekStart, this.weekStart);
|
|
1009
|
-
|
|
1010
|
-
this.first = firstOfMonth;
|
|
1011
|
-
this.last = dateValue(viewYear, viewMonth + 1, 0);
|
|
1012
|
-
this.start = start;
|
|
1013
|
-
this.focused = this.picker.viewDate;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// Apply update on the selected dates to view's settings
|
|
1017
|
-
updateSelection() {
|
|
1018
|
-
const {dates, rangepicker} = this.picker.datepicker;
|
|
1019
|
-
this.selected = dates;
|
|
1020
|
-
if (rangepicker) {
|
|
1021
|
-
this.range = rangepicker.dates;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
// Update the entire view UI
|
|
1026
|
-
render() {
|
|
1027
|
-
// update today marker on ever render
|
|
1028
|
-
this.today = this.todayHighlight ? today() : undefined;
|
|
1029
|
-
// refresh disabled dates on every render in order to clear the ones added
|
|
1030
|
-
// by beforeShow hook at previous render
|
|
1031
|
-
this.disabled = [...this.datesDisabled];
|
|
1032
|
-
|
|
1033
|
-
const switchLabel = formatDate(this.focused, this.switchLabelFormat, this.locale);
|
|
1034
|
-
this.picker.setViewSwitchLabel(switchLabel);
|
|
1035
|
-
this.picker.setPrevBtnDisabled(this.first <= this.minDate);
|
|
1036
|
-
this.picker.setNextBtnDisabled(this.last >= this.maxDate);
|
|
1037
|
-
|
|
1038
|
-
if (this.calendarWeeks) {
|
|
1039
|
-
// start of the UTC week (Monday) of the 1st of the month
|
|
1040
|
-
const startOfWeek = dayOfTheWeekOf(this.first, 1, 1);
|
|
1041
|
-
Array.from(this.calendarWeeks.weeks.children).forEach((el, index) => {
|
|
1042
|
-
el.textContent = getWeek(addWeeks(startOfWeek, index));
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
|
-
Array.from(this.grid.children).forEach((el, index) => {
|
|
1046
|
-
const classList = el.classList;
|
|
1047
|
-
const current = addDays(this.start, index);
|
|
1048
|
-
const date = new Date(current);
|
|
1049
|
-
const day = date.getDay();
|
|
1050
|
-
|
|
1051
|
-
el.className = `datepicker-cell ${this.cellClass}`;
|
|
1052
|
-
el.dataset.date = current;
|
|
1053
|
-
el.textContent = date.getDate();
|
|
1054
|
-
|
|
1055
|
-
if (current < this.first) {
|
|
1056
|
-
classList.add('prev');
|
|
1057
|
-
} else if (current > this.last) {
|
|
1058
|
-
classList.add('next');
|
|
1059
|
-
}
|
|
1060
|
-
if (this.today === current) {
|
|
1061
|
-
classList.add('today');
|
|
1062
|
-
}
|
|
1063
|
-
if (current < this.minDate || current > this.maxDate || this.disabled.includes(current)) {
|
|
1064
|
-
classList.add('disabled');
|
|
1065
|
-
}
|
|
1066
|
-
if (this.daysOfWeekDisabled.includes(day)) {
|
|
1067
|
-
classList.add('disabled');
|
|
1068
|
-
pushUnique(this.disabled, current);
|
|
1069
|
-
}
|
|
1070
|
-
if (this.daysOfWeekHighlighted.includes(day)) {
|
|
1071
|
-
classList.add('highlighted');
|
|
1072
|
-
}
|
|
1073
|
-
if (this.range) {
|
|
1074
|
-
const [rangeStart, rangeEnd] = this.range;
|
|
1075
|
-
if (current > rangeStart && current < rangeEnd) {
|
|
1076
|
-
classList.add('range');
|
|
1077
|
-
}
|
|
1078
|
-
if (current === rangeStart) {
|
|
1079
|
-
classList.add('range-start');
|
|
1080
|
-
}
|
|
1081
|
-
if (current === rangeEnd) {
|
|
1082
|
-
classList.add('range-end');
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
if (this.selected.includes(current)) {
|
|
1086
|
-
classList.add('selected');
|
|
1087
|
-
}
|
|
1088
|
-
if (current === this.focused) {
|
|
1089
|
-
classList.add('focused');
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
if (this.beforeShow) {
|
|
1093
|
-
this.performBeforeHook(el, current, current);
|
|
1094
|
-
}
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// Update the view UI by applying the changes of selected and focused items
|
|
1099
|
-
refresh() {
|
|
1100
|
-
const [rangeStart, rangeEnd] = this.range || [];
|
|
1101
|
-
this.grid
|
|
1102
|
-
.querySelectorAll('.range, .range-start, .range-end, .selected, .focused')
|
|
1103
|
-
.forEach((el) => {
|
|
1104
|
-
el.classList.remove('range', 'range-start', 'range-end', 'selected', 'focused');
|
|
1105
|
-
});
|
|
1106
|
-
Array.from(this.grid.children).forEach((el) => {
|
|
1107
|
-
const current = Number(el.dataset.date);
|
|
1108
|
-
const classList = el.classList;
|
|
1109
|
-
if (current > rangeStart && current < rangeEnd) {
|
|
1110
|
-
classList.add('range');
|
|
1111
|
-
}
|
|
1112
|
-
if (current === rangeStart) {
|
|
1113
|
-
classList.add('range-start');
|
|
1114
|
-
}
|
|
1115
|
-
if (current === rangeEnd) {
|
|
1116
|
-
classList.add('range-end');
|
|
1117
|
-
}
|
|
1118
|
-
if (this.selected.includes(current)) {
|
|
1119
|
-
classList.add('selected');
|
|
1120
|
-
}
|
|
1121
|
-
if (current === this.focused) {
|
|
1122
|
-
classList.add('focused');
|
|
1123
|
-
}
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
// Update the view UI by applying the change of focused item
|
|
1128
|
-
refreshFocus() {
|
|
1129
|
-
const index = Math.round((this.focused - this.start) / 86400000);
|
|
1130
|
-
this.grid.querySelectorAll('.focused').forEach((el) => {
|
|
1131
|
-
el.classList.remove('focused');
|
|
1132
|
-
});
|
|
1133
|
-
this.grid.children[index].classList.add('focused');
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
function computeMonthRange(range, thisYear) {
|
|
1138
|
-
if (!range || !range[0] || !range[1]) {
|
|
1139
|
-
return;
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
const [[startY, startM], [endY, endM]] = range;
|
|
1143
|
-
if (startY > thisYear || endY < thisYear) {
|
|
1144
|
-
return;
|
|
1145
|
-
}
|
|
1146
|
-
return [
|
|
1147
|
-
startY === thisYear ? startM : -1,
|
|
1148
|
-
endY === thisYear ? endM : 12,
|
|
1149
|
-
];
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
class MonthsView extends View {
|
|
1153
|
-
constructor(picker) {
|
|
1154
|
-
super(picker, {
|
|
1155
|
-
id: 1,
|
|
1156
|
-
name: 'months',
|
|
1157
|
-
cellClass: 'month',
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
init(options, onConstruction = true) {
|
|
1162
|
-
if (onConstruction) {
|
|
1163
|
-
this.grid = this.element;
|
|
1164
|
-
this.element.classList.add('months', 'datepicker-grid');
|
|
1165
|
-
this.grid.appendChild(parseHTML(createTagRepeat('span', 12, {'data-month': ix => ix})));
|
|
1166
|
-
}
|
|
1167
|
-
super.init(options);
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
setOptions(options) {
|
|
1171
|
-
if (options.locale) {
|
|
1172
|
-
this.monthNames = options.locale.monthsShort;
|
|
1173
|
-
}
|
|
1174
|
-
if (hasProperty(options, 'minDate')) {
|
|
1175
|
-
if (options.minDate === undefined) {
|
|
1176
|
-
this.minYear = this.minMonth = this.minDate = undefined;
|
|
1177
|
-
} else {
|
|
1178
|
-
const minDateObj = new Date(options.minDate);
|
|
1179
|
-
this.minYear = minDateObj.getFullYear();
|
|
1180
|
-
this.minMonth = minDateObj.getMonth();
|
|
1181
|
-
this.minDate = minDateObj.setDate(1);
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
if (hasProperty(options, 'maxDate')) {
|
|
1185
|
-
if (options.maxDate === undefined) {
|
|
1186
|
-
this.maxYear = this.maxMonth = this.maxDate = undefined;
|
|
1187
|
-
} else {
|
|
1188
|
-
const maxDateObj = new Date(options.maxDate);
|
|
1189
|
-
this.maxYear = maxDateObj.getFullYear();
|
|
1190
|
-
this.maxMonth = maxDateObj.getMonth();
|
|
1191
|
-
this.maxDate = dateValue(this.maxYear, this.maxMonth + 1, 0);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
if (this.isMinView) {
|
|
1195
|
-
if (options.datesDisabled) {
|
|
1196
|
-
this.datesDisabled = options.datesDisabled;
|
|
1197
|
-
}
|
|
1198
|
-
} else {
|
|
1199
|
-
this.datesDisabled = [];
|
|
1200
|
-
}
|
|
1201
|
-
if (options.beforeShowMonth !== undefined) {
|
|
1202
|
-
this.beforeShow = typeof options.beforeShowMonth === 'function'
|
|
1203
|
-
? options.beforeShowMonth
|
|
1204
|
-
: undefined;
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
// Update view's settings to reflect the viewDate set on the picker
|
|
1209
|
-
updateFocus() {
|
|
1210
|
-
const viewDate = new Date(this.picker.viewDate);
|
|
1211
|
-
this.year = viewDate.getFullYear();
|
|
1212
|
-
this.focused = viewDate.getMonth();
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
// Update view's settings to reflect the selected dates
|
|
1216
|
-
updateSelection() {
|
|
1217
|
-
const {dates, rangepicker} = this.picker.datepicker;
|
|
1218
|
-
this.selected = dates.reduce((selected, timeValue) => {
|
|
1219
|
-
const date = new Date(timeValue);
|
|
1220
|
-
const year = date.getFullYear();
|
|
1221
|
-
const month = date.getMonth();
|
|
1222
|
-
if (selected[year] === undefined) {
|
|
1223
|
-
selected[year] = [month];
|
|
1224
|
-
} else {
|
|
1225
|
-
pushUnique(selected[year], month);
|
|
1226
|
-
}
|
|
1227
|
-
return selected;
|
|
1228
|
-
}, {});
|
|
1229
|
-
if (rangepicker && rangepicker.dates) {
|
|
1230
|
-
this.range = rangepicker.dates.map(timeValue => {
|
|
1231
|
-
const date = new Date(timeValue);
|
|
1232
|
-
return isNaN(date) ? undefined : [date.getFullYear(), date.getMonth()];
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
// Update the entire view UI
|
|
1238
|
-
render() {
|
|
1239
|
-
// refresh disabled months on every render in order to clear the ones added
|
|
1240
|
-
// by beforeShow hook at previous render
|
|
1241
|
-
// this.disabled = [...this.datesDisabled];
|
|
1242
|
-
this.disabled = this.datesDisabled.reduce((arr, disabled) => {
|
|
1243
|
-
const dt = new Date(disabled);
|
|
1244
|
-
if (this.year === dt.getFullYear()) {
|
|
1245
|
-
arr.push(dt.getMonth());
|
|
1246
|
-
}
|
|
1247
|
-
return arr;
|
|
1248
|
-
}, []);
|
|
1249
|
-
|
|
1250
|
-
this.picker.setViewSwitchLabel(this.year);
|
|
1251
|
-
this.picker.setPrevBtnDisabled(this.year <= this.minYear);
|
|
1252
|
-
this.picker.setNextBtnDisabled(this.year >= this.maxYear);
|
|
1253
|
-
|
|
1254
|
-
const selected = this.selected[this.year] || [];
|
|
1255
|
-
const yrOutOfRange = this.year < this.minYear || this.year > this.maxYear;
|
|
1256
|
-
const isMinYear = this.year === this.minYear;
|
|
1257
|
-
const isMaxYear = this.year === this.maxYear;
|
|
1258
|
-
const range = computeMonthRange(this.range, this.year);
|
|
1259
|
-
|
|
1260
|
-
Array.from(this.grid.children).forEach((el, index) => {
|
|
1261
|
-
const classList = el.classList;
|
|
1262
|
-
const date = dateValue(this.year, index, 1);
|
|
1263
|
-
|
|
1264
|
-
el.className = `datepicker-cell ${this.cellClass}`;
|
|
1265
|
-
if (this.isMinView) {
|
|
1266
|
-
el.dataset.date = date;
|
|
1267
|
-
}
|
|
1268
|
-
// reset text on every render to clear the custom content set
|
|
1269
|
-
// by beforeShow hook at previous render
|
|
1270
|
-
el.textContent = this.monthNames[index];
|
|
1271
|
-
|
|
1272
|
-
if (
|
|
1273
|
-
yrOutOfRange
|
|
1274
|
-
|| isMinYear && index < this.minMonth
|
|
1275
|
-
|| isMaxYear && index > this.maxMonth
|
|
1276
|
-
|| this.disabled.includes(index)
|
|
1277
|
-
) {
|
|
1278
|
-
classList.add('disabled');
|
|
1279
|
-
}
|
|
1280
|
-
if (range) {
|
|
1281
|
-
const [rangeStart, rangeEnd] = range;
|
|
1282
|
-
if (index > rangeStart && index < rangeEnd) {
|
|
1283
|
-
classList.add('range');
|
|
1284
|
-
}
|
|
1285
|
-
if (index === rangeStart) {
|
|
1286
|
-
classList.add('range-start');
|
|
1287
|
-
}
|
|
1288
|
-
if (index === rangeEnd) {
|
|
1289
|
-
classList.add('range-end');
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
if (selected.includes(index)) {
|
|
1293
|
-
classList.add('selected');
|
|
1294
|
-
}
|
|
1295
|
-
if (index === this.focused) {
|
|
1296
|
-
classList.add('focused');
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
if (this.beforeShow) {
|
|
1300
|
-
this.performBeforeHook(el, index, date);
|
|
1301
|
-
}
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
// Update the view UI by applying the changes of selected and focused items
|
|
1306
|
-
refresh() {
|
|
1307
|
-
const selected = this.selected[this.year] || [];
|
|
1308
|
-
const [rangeStart, rangeEnd] = computeMonthRange(this.range, this.year) || [];
|
|
1309
|
-
this.grid
|
|
1310
|
-
.querySelectorAll('.range, .range-start, .range-end, .selected, .focused')
|
|
1311
|
-
.forEach((el) => {
|
|
1312
|
-
el.classList.remove('range', 'range-start', 'range-end', 'selected', 'focused');
|
|
1313
|
-
});
|
|
1314
|
-
Array.from(this.grid.children).forEach((el, index) => {
|
|
1315
|
-
const classList = el.classList;
|
|
1316
|
-
if (index > rangeStart && index < rangeEnd) {
|
|
1317
|
-
classList.add('range');
|
|
1318
|
-
}
|
|
1319
|
-
if (index === rangeStart) {
|
|
1320
|
-
classList.add('range-start');
|
|
1321
|
-
}
|
|
1322
|
-
if (index === rangeEnd) {
|
|
1323
|
-
classList.add('range-end');
|
|
1324
|
-
}
|
|
1325
|
-
if (selected.includes(index)) {
|
|
1326
|
-
classList.add('selected');
|
|
1327
|
-
}
|
|
1328
|
-
if (index === this.focused) {
|
|
1329
|
-
classList.add('focused');
|
|
1330
|
-
}
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
// Update the view UI by applying the change of focused item
|
|
1335
|
-
refreshFocus() {
|
|
1336
|
-
this.grid.querySelectorAll('.focused').forEach((el) => {
|
|
1337
|
-
el.classList.remove('focused');
|
|
1338
|
-
});
|
|
1339
|
-
this.grid.children[this.focused].classList.add('focused');
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
function toTitleCase(word) {
|
|
1344
|
-
return [...word].reduce((str, ch, ix) => str += ix ? ch : ch.toUpperCase(), '');
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
// Class representing the years and decades view elements
|
|
1348
|
-
class YearsView extends View {
|
|
1349
|
-
constructor(picker, config) {
|
|
1350
|
-
super(picker, config);
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
init(options, onConstruction = true) {
|
|
1354
|
-
if (onConstruction) {
|
|
1355
|
-
this.navStep = this.step * 10;
|
|
1356
|
-
this.beforeShowOption = `beforeShow${toTitleCase(this.cellClass)}`;
|
|
1357
|
-
this.grid = this.element;
|
|
1358
|
-
this.element.classList.add(this.name, 'datepicker-grid');
|
|
1359
|
-
this.grid.appendChild(parseHTML(createTagRepeat('span', 12)));
|
|
1360
|
-
}
|
|
1361
|
-
super.init(options);
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
setOptions(options) {
|
|
1365
|
-
if (hasProperty(options, 'minDate')) {
|
|
1366
|
-
if (options.minDate === undefined) {
|
|
1367
|
-
this.minYear = this.minDate = undefined;
|
|
1368
|
-
} else {
|
|
1369
|
-
this.minYear = startOfYearPeriod(options.minDate, this.step);
|
|
1370
|
-
this.minDate = dateValue(this.minYear, 0, 1);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
if (hasProperty(options, 'maxDate')) {
|
|
1374
|
-
if (options.maxDate === undefined) {
|
|
1375
|
-
this.maxYear = this.maxDate = undefined;
|
|
1376
|
-
} else {
|
|
1377
|
-
this.maxYear = startOfYearPeriod(options.maxDate, this.step);
|
|
1378
|
-
this.maxDate = dateValue(this.maxYear, 11, 31);
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
if (this.isMinView) {
|
|
1382
|
-
if (options.datesDisabled) {
|
|
1383
|
-
this.datesDisabled = options.datesDisabled;
|
|
1384
|
-
}
|
|
1385
|
-
} else {
|
|
1386
|
-
this.datesDisabled = [];
|
|
1387
|
-
}
|
|
1388
|
-
if (options[this.beforeShowOption] !== undefined) {
|
|
1389
|
-
const beforeShow = options[this.beforeShowOption];
|
|
1390
|
-
this.beforeShow = typeof beforeShow === 'function' ? beforeShow : undefined;
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
// Update view's settings to reflect the viewDate set on the picker
|
|
1395
|
-
updateFocus() {
|
|
1396
|
-
const viewDate = new Date(this.picker.viewDate);
|
|
1397
|
-
const first = startOfYearPeriod(viewDate, this.navStep);
|
|
1398
|
-
const last = first + 9 * this.step;
|
|
1399
|
-
|
|
1400
|
-
this.first = first;
|
|
1401
|
-
this.last = last;
|
|
1402
|
-
this.start = first - this.step;
|
|
1403
|
-
this.focused = startOfYearPeriod(viewDate, this.step);
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
// Update view's settings to reflect the selected dates
|
|
1407
|
-
updateSelection() {
|
|
1408
|
-
const {dates, rangepicker} = this.picker.datepicker;
|
|
1409
|
-
this.selected = dates.reduce((years, timeValue) => {
|
|
1410
|
-
return pushUnique(years, startOfYearPeriod(timeValue, this.step));
|
|
1411
|
-
}, []);
|
|
1412
|
-
if (rangepicker && rangepicker.dates) {
|
|
1413
|
-
this.range = rangepicker.dates.map(timeValue => {
|
|
1414
|
-
if (timeValue !== undefined) {
|
|
1415
|
-
return startOfYearPeriod(timeValue, this.step);
|
|
1416
|
-
}
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
// Update the entire view UI
|
|
1422
|
-
render() {
|
|
1423
|
-
// refresh disabled years on every render in order to clear the ones added
|
|
1424
|
-
// by beforeShow hook at previous render
|
|
1425
|
-
// this.disabled = [...this.datesDisabled];
|
|
1426
|
-
this.disabled = this.datesDisabled.map(disabled => new Date(disabled).getFullYear());
|
|
1427
|
-
|
|
1428
|
-
this.picker.setViewSwitchLabel(`${this.first}-${this.last}`);
|
|
1429
|
-
this.picker.setPrevBtnDisabled(this.first <= this.minYear);
|
|
1430
|
-
this.picker.setNextBtnDisabled(this.last >= this.maxYear);
|
|
1431
|
-
|
|
1432
|
-
Array.from(this.grid.children).forEach((el, index) => {
|
|
1433
|
-
const classList = el.classList;
|
|
1434
|
-
const current = this.start + (index * this.step);
|
|
1435
|
-
const date = dateValue(current, 0, 1);
|
|
1436
|
-
|
|
1437
|
-
el.className = `datepicker-cell ${this.cellClass}`;
|
|
1438
|
-
if (this.isMinView) {
|
|
1439
|
-
el.dataset.date = date;
|
|
1440
|
-
}
|
|
1441
|
-
el.textContent = el.dataset.year = current;
|
|
1442
|
-
|
|
1443
|
-
if (index === 0) {
|
|
1444
|
-
classList.add('prev');
|
|
1445
|
-
} else if (index === 11) {
|
|
1446
|
-
classList.add('next');
|
|
1447
|
-
}
|
|
1448
|
-
if (current < this.minYear || current > this.maxYear || this.disabled.includes(current)) {
|
|
1449
|
-
classList.add('disabled');
|
|
1450
|
-
}
|
|
1451
|
-
if (this.range) {
|
|
1452
|
-
const [rangeStart, rangeEnd] = this.range;
|
|
1453
|
-
if (current > rangeStart && current < rangeEnd) {
|
|
1454
|
-
classList.add('range');
|
|
1455
|
-
}
|
|
1456
|
-
if (current === rangeStart) {
|
|
1457
|
-
classList.add('range-start');
|
|
1458
|
-
}
|
|
1459
|
-
if (current === rangeEnd) {
|
|
1460
|
-
classList.add('range-end');
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
if (this.selected.includes(current)) {
|
|
1464
|
-
classList.add('selected');
|
|
1465
|
-
}
|
|
1466
|
-
if (current === this.focused) {
|
|
1467
|
-
classList.add('focused');
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
if (this.beforeShow) {
|
|
1471
|
-
this.performBeforeHook(el, current, date);
|
|
1472
|
-
}
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
// Update the view UI by applying the changes of selected and focused items
|
|
1477
|
-
refresh() {
|
|
1478
|
-
const [rangeStart, rangeEnd] = this.range || [];
|
|
1479
|
-
this.grid
|
|
1480
|
-
.querySelectorAll('.range, .range-start, .range-end, .selected, .focused')
|
|
1481
|
-
.forEach((el) => {
|
|
1482
|
-
el.classList.remove('range', 'range-start', 'range-end', 'selected', 'focused');
|
|
1483
|
-
});
|
|
1484
|
-
Array.from(this.grid.children).forEach((el) => {
|
|
1485
|
-
const current = Number(el.textContent);
|
|
1486
|
-
const classList = el.classList;
|
|
1487
|
-
if (current > rangeStart && current < rangeEnd) {
|
|
1488
|
-
classList.add('range');
|
|
1489
|
-
}
|
|
1490
|
-
if (current === rangeStart) {
|
|
1491
|
-
classList.add('range-start');
|
|
1492
|
-
}
|
|
1493
|
-
if (current === rangeEnd) {
|
|
1494
|
-
classList.add('range-end');
|
|
1495
|
-
}
|
|
1496
|
-
if (this.selected.includes(current)) {
|
|
1497
|
-
classList.add('selected');
|
|
1498
|
-
}
|
|
1499
|
-
if (current === this.focused) {
|
|
1500
|
-
classList.add('focused');
|
|
1501
|
-
}
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
// Update the view UI by applying the change of focused item
|
|
1506
|
-
refreshFocus() {
|
|
1507
|
-
const index = Math.round((this.focused - this.start) / this.step);
|
|
1508
|
-
this.grid.querySelectorAll('.focused').forEach((el) => {
|
|
1509
|
-
el.classList.remove('focused');
|
|
1510
|
-
});
|
|
1511
|
-
this.grid.children[index].classList.add('focused');
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
function triggerDatepickerEvent(datepicker, type) {
|
|
1516
|
-
const detail = {
|
|
1517
|
-
date: datepicker.getDate(),
|
|
1518
|
-
viewDate: new Date(datepicker.picker.viewDate),
|
|
1519
|
-
viewId: datepicker.picker.currentView.id,
|
|
1520
|
-
datepicker,
|
|
1521
|
-
};
|
|
1522
|
-
datepicker.element.dispatchEvent(new CustomEvent(type, {detail}));
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
// direction: -1 (to previous), 1 (to next)
|
|
1526
|
-
function goToPrevOrNext(datepicker, direction) {
|
|
1527
|
-
const {minDate, maxDate} = datepicker.config;
|
|
1528
|
-
const {currentView, viewDate} = datepicker.picker;
|
|
1529
|
-
let newViewDate;
|
|
1530
|
-
switch (currentView.id) {
|
|
1531
|
-
case 0:
|
|
1532
|
-
newViewDate = addMonths(viewDate, direction);
|
|
1533
|
-
break;
|
|
1534
|
-
case 1:
|
|
1535
|
-
newViewDate = addYears(viewDate, direction);
|
|
1536
|
-
break;
|
|
1537
|
-
default:
|
|
1538
|
-
newViewDate = addYears(viewDate, direction * currentView.navStep);
|
|
1539
|
-
}
|
|
1540
|
-
newViewDate = limitToRange(newViewDate, minDate, maxDate);
|
|
1541
|
-
datepicker.picker.changeFocus(newViewDate).render();
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
function switchView(datepicker) {
|
|
1545
|
-
const viewId = datepicker.picker.currentView.id;
|
|
1546
|
-
if (viewId === datepicker.config.maxView) {
|
|
1547
|
-
return;
|
|
1548
|
-
}
|
|
1549
|
-
datepicker.picker.changeView(viewId + 1).render();
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
function unfocus(datepicker) {
|
|
1553
|
-
if (datepicker.config.updateOnBlur) {
|
|
1554
|
-
datepicker.update({revert: true});
|
|
1555
|
-
} else {
|
|
1556
|
-
datepicker.refresh('input');
|
|
1557
|
-
}
|
|
1558
|
-
datepicker.hide();
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
function goToSelectedMonthOrYear(datepicker, selection) {
|
|
1562
|
-
const picker = datepicker.picker;
|
|
1563
|
-
const viewDate = new Date(picker.viewDate);
|
|
1564
|
-
const viewId = picker.currentView.id;
|
|
1565
|
-
const newDate = viewId === 1
|
|
1566
|
-
? addMonths(viewDate, selection - viewDate.getMonth())
|
|
1567
|
-
: addYears(viewDate, selection - viewDate.getFullYear());
|
|
1568
|
-
|
|
1569
|
-
picker.changeFocus(newDate).changeView(viewId - 1).render();
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
function onClickTodayBtn(datepicker) {
|
|
1573
|
-
const picker = datepicker.picker;
|
|
1574
|
-
const currentDate = today();
|
|
1575
|
-
if (datepicker.config.todayBtnMode === 1) {
|
|
1576
|
-
if (datepicker.config.autohide) {
|
|
1577
|
-
datepicker.setDate(currentDate);
|
|
1578
|
-
return;
|
|
1579
|
-
}
|
|
1580
|
-
datepicker.setDate(currentDate, {render: false});
|
|
1581
|
-
picker.update();
|
|
1582
|
-
}
|
|
1583
|
-
if (picker.viewDate !== currentDate) {
|
|
1584
|
-
picker.changeFocus(currentDate);
|
|
1585
|
-
}
|
|
1586
|
-
picker.changeView(0).render();
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
function onClickClearBtn(datepicker) {
|
|
1590
|
-
datepicker.setDate({clear: true});
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
function onClickViewSwitch(datepicker) {
|
|
1594
|
-
switchView(datepicker);
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
function onClickPrevBtn(datepicker) {
|
|
1598
|
-
goToPrevOrNext(datepicker, -1);
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
function onClickNextBtn(datepicker) {
|
|
1602
|
-
goToPrevOrNext(datepicker, 1);
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
// For the picker's main block to delegete the events from `datepicker-cell`s
|
|
1606
|
-
function onClickView(datepicker, ev) {
|
|
1607
|
-
const target = findElementInEventPath(ev, '.datepicker-cell');
|
|
1608
|
-
if (!target || target.classList.contains('disabled')) {
|
|
1609
|
-
return;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
const {id, isMinView} = datepicker.picker.currentView;
|
|
1613
|
-
if (isMinView) {
|
|
1614
|
-
datepicker.setDate(Number(target.dataset.date));
|
|
1615
|
-
} else if (id === 1) {
|
|
1616
|
-
goToSelectedMonthOrYear(datepicker, Number(target.dataset.month));
|
|
1617
|
-
} else {
|
|
1618
|
-
goToSelectedMonthOrYear(datepicker, Number(target.dataset.year));
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
function onMousedownPicker(ev) {
|
|
1623
|
-
ev.preventDefault();
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
const orientClasses = ['left', 'top', 'right', 'bottom'].reduce((obj, key) => {
|
|
1627
|
-
obj[key] = `datepicker-orient-${key}`;
|
|
1628
|
-
return obj;
|
|
1629
|
-
}, {});
|
|
1630
|
-
const toPx = num => num ? `${num}px` : num;
|
|
1631
|
-
|
|
1632
|
-
function processPickerOptions(picker, options) {
|
|
1633
|
-
if (options.title !== undefined) {
|
|
1634
|
-
if (options.title) {
|
|
1635
|
-
picker.controls.title.textContent = options.title;
|
|
1636
|
-
showElement(picker.controls.title);
|
|
1637
|
-
} else {
|
|
1638
|
-
picker.controls.title.textContent = '';
|
|
1639
|
-
hideElement(picker.controls.title);
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
if (options.prevArrow) {
|
|
1643
|
-
const prevBtn = picker.controls.prevBtn;
|
|
1644
|
-
emptyChildNodes(prevBtn);
|
|
1645
|
-
options.prevArrow.forEach((node) => {
|
|
1646
|
-
prevBtn.appendChild(node.cloneNode(true));
|
|
1647
|
-
});
|
|
1648
|
-
}
|
|
1649
|
-
if (options.nextArrow) {
|
|
1650
|
-
const nextBtn = picker.controls.nextBtn;
|
|
1651
|
-
emptyChildNodes(nextBtn);
|
|
1652
|
-
options.nextArrow.forEach((node) => {
|
|
1653
|
-
nextBtn.appendChild(node.cloneNode(true));
|
|
1654
|
-
});
|
|
1655
|
-
}
|
|
1656
|
-
if (options.locale) {
|
|
1657
|
-
picker.controls.todayBtn.textContent = options.locale.today;
|
|
1658
|
-
picker.controls.clearBtn.textContent = options.locale.clear;
|
|
1659
|
-
}
|
|
1660
|
-
if (options.todayBtn !== undefined) {
|
|
1661
|
-
if (options.todayBtn) {
|
|
1662
|
-
showElement(picker.controls.todayBtn);
|
|
1663
|
-
} else {
|
|
1664
|
-
hideElement(picker.controls.todayBtn);
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
if (hasProperty(options, 'minDate') || hasProperty(options, 'maxDate')) {
|
|
1668
|
-
const {minDate, maxDate} = picker.datepicker.config;
|
|
1669
|
-
picker.controls.todayBtn.disabled = !isInRange(today(), minDate, maxDate);
|
|
1670
|
-
}
|
|
1671
|
-
if (options.clearBtn !== undefined) {
|
|
1672
|
-
if (options.clearBtn) {
|
|
1673
|
-
showElement(picker.controls.clearBtn);
|
|
1674
|
-
} else {
|
|
1675
|
-
hideElement(picker.controls.clearBtn);
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
// Compute view date to reset, which will be...
|
|
1681
|
-
// - the last item of the selected dates or defaultViewDate if no selection
|
|
1682
|
-
// - limitted to minDate or maxDate if it exceeds the range
|
|
1683
|
-
function computeResetViewDate(datepicker) {
|
|
1684
|
-
const {dates, config} = datepicker;
|
|
1685
|
-
const viewDate = dates.length > 0 ? lastItemOf(dates) : config.defaultViewDate;
|
|
1686
|
-
return limitToRange(viewDate, config.minDate, config.maxDate);
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
// Change current view's view date
|
|
1690
|
-
function setViewDate(picker, newDate) {
|
|
1691
|
-
const oldViewDate = new Date(picker.viewDate);
|
|
1692
|
-
const newViewDate = new Date(newDate);
|
|
1693
|
-
const {id, year, first, last} = picker.currentView;
|
|
1694
|
-
const viewYear = newViewDate.getFullYear();
|
|
1695
|
-
|
|
1696
|
-
picker.viewDate = newDate;
|
|
1697
|
-
if (viewYear !== oldViewDate.getFullYear()) {
|
|
1698
|
-
triggerDatepickerEvent(picker.datepicker, 'changeYear');
|
|
1699
|
-
}
|
|
1700
|
-
if (newViewDate.getMonth() !== oldViewDate.getMonth()) {
|
|
1701
|
-
triggerDatepickerEvent(picker.datepicker, 'changeMonth');
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
// return whether the new date is in different period on time from the one
|
|
1705
|
-
// displayed in the current view
|
|
1706
|
-
// when true, the view needs to be re-rendered on the next UI refresh.
|
|
1707
|
-
switch (id) {
|
|
1708
|
-
case 0:
|
|
1709
|
-
return newDate < first || newDate > last;
|
|
1710
|
-
case 1:
|
|
1711
|
-
return viewYear !== year;
|
|
1712
|
-
default:
|
|
1713
|
-
return viewYear < first || viewYear > last;
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
function getTextDirection(el) {
|
|
1718
|
-
return window.getComputedStyle(el).direction;
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
// find the closet scrollable ancestor elemnt under the body
|
|
1722
|
-
function findScrollParents(el) {
|
|
1723
|
-
const parent = getParent(el);
|
|
1724
|
-
if (parent === document.body || !parent) {
|
|
1725
|
-
return;
|
|
1726
|
-
}
|
|
1727
|
-
|
|
1728
|
-
// checking overflow only is enough because computed overflow cannot be
|
|
1729
|
-
// visible or a combination of visible and other when either axis is set
|
|
1730
|
-
// to other than visible.
|
|
1731
|
-
// (Setting one axis to other than 'visible' while the other is 'visible'
|
|
1732
|
-
// results in the other axis turning to 'auto')
|
|
1733
|
-
return window.getComputedStyle(parent).overflow !== 'visible'
|
|
1734
|
-
? parent
|
|
1735
|
-
: findScrollParents(parent);
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
// Class representing the picker UI
|
|
1739
|
-
class Picker {
|
|
1740
|
-
constructor(datepicker) {
|
|
1741
|
-
const {config} = this.datepicker = datepicker;
|
|
1742
|
-
|
|
1743
|
-
const template = pickerTemplate.replace(/%buttonClass%/g, config.buttonClass);
|
|
1744
|
-
const element = this.element = parseHTML(template).firstChild;
|
|
1745
|
-
const [header, main, footer] = element.firstChild.children;
|
|
1746
|
-
const title = header.firstElementChild;
|
|
1747
|
-
const [prevBtn, viewSwitch, nextBtn] = header.lastElementChild.children;
|
|
1748
|
-
const [todayBtn, clearBtn] = footer.firstChild.children;
|
|
1749
|
-
const controls = {
|
|
1750
|
-
title,
|
|
1751
|
-
prevBtn,
|
|
1752
|
-
viewSwitch,
|
|
1753
|
-
nextBtn,
|
|
1754
|
-
todayBtn,
|
|
1755
|
-
clearBtn,
|
|
1756
|
-
};
|
|
1757
|
-
this.main = main;
|
|
1758
|
-
this.controls = controls;
|
|
1759
|
-
|
|
1760
|
-
const elementClass = datepicker.inline ? 'inline' : 'dropdown';
|
|
1761
|
-
element.classList.add(`datepicker-${elementClass}`);
|
|
1762
|
-
|
|
1763
|
-
processPickerOptions(this, config);
|
|
1764
|
-
this.viewDate = computeResetViewDate(datepicker);
|
|
1765
|
-
|
|
1766
|
-
// set up event listeners
|
|
1767
|
-
registerListeners(datepicker, [
|
|
1768
|
-
[element, 'mousedown', onMousedownPicker],
|
|
1769
|
-
[main, 'click', onClickView.bind(null, datepicker)],
|
|
1770
|
-
[controls.viewSwitch, 'click', onClickViewSwitch.bind(null, datepicker)],
|
|
1771
|
-
[controls.prevBtn, 'click', onClickPrevBtn.bind(null, datepicker)],
|
|
1772
|
-
[controls.nextBtn, 'click', onClickNextBtn.bind(null, datepicker)],
|
|
1773
|
-
[controls.todayBtn, 'click', onClickTodayBtn.bind(null, datepicker)],
|
|
1774
|
-
[controls.clearBtn, 'click', onClickClearBtn.bind(null, datepicker)],
|
|
1775
|
-
]);
|
|
1776
|
-
|
|
1777
|
-
// set up views
|
|
1778
|
-
this.views = [
|
|
1779
|
-
new DaysView(this),
|
|
1780
|
-
new MonthsView(this),
|
|
1781
|
-
new YearsView(this, {id: 2, name: 'years', cellClass: 'year', step: 1}),
|
|
1782
|
-
new YearsView(this, {id: 3, name: 'decades', cellClass: 'decade', step: 10}),
|
|
1783
|
-
];
|
|
1784
|
-
this.currentView = this.views[config.startView];
|
|
1785
|
-
|
|
1786
|
-
this.currentView.render();
|
|
1787
|
-
this.main.appendChild(this.currentView.element);
|
|
1788
|
-
if (config.container) {
|
|
1789
|
-
config.container.appendChild(this.element);
|
|
1790
|
-
} else {
|
|
1791
|
-
datepicker.inputField.after(this.element);
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
setOptions(options) {
|
|
1796
|
-
processPickerOptions(this, options);
|
|
1797
|
-
this.views.forEach((view) => {
|
|
1798
|
-
view.init(options, false);
|
|
1799
|
-
});
|
|
1800
|
-
this.currentView.render();
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
detach() {
|
|
1804
|
-
this.element.remove();
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
show() {
|
|
1808
|
-
if (this.active) {
|
|
1809
|
-
return;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
const {datepicker, element} = this;
|
|
1813
|
-
if (datepicker.inline) {
|
|
1814
|
-
element.classList.add('active');
|
|
1815
|
-
} else {
|
|
1816
|
-
// ensure picker's direction matches input's
|
|
1817
|
-
const inputDirection = getTextDirection(datepicker.inputField);
|
|
1818
|
-
if (inputDirection !== getTextDirection(getParent(element))) {
|
|
1819
|
-
element.dir = inputDirection;
|
|
1820
|
-
} else if (element.dir) {
|
|
1821
|
-
element.removeAttribute('dir');
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
element.style.visiblity = 'hidden';
|
|
1825
|
-
element.classList.add('active');
|
|
1826
|
-
this.place();
|
|
1827
|
-
element.style.visiblity = '';
|
|
1828
|
-
|
|
1829
|
-
if (datepicker.config.disableTouchKeyboard) {
|
|
1830
|
-
datepicker.inputField.blur();
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
this.active = true;
|
|
1834
|
-
triggerDatepickerEvent(datepicker, 'show');
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
hide() {
|
|
1838
|
-
if (!this.active) {
|
|
1839
|
-
return;
|
|
1840
|
-
}
|
|
1841
|
-
this.datepicker.exitEditMode();
|
|
1842
|
-
this.element.classList.remove('active');
|
|
1843
|
-
this.active = false;
|
|
1844
|
-
triggerDatepickerEvent(this.datepicker, 'hide');
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
place() {
|
|
1848
|
-
const {classList, offsetParent, style} = this.element;
|
|
1849
|
-
const {config, inputField} = this.datepicker;
|
|
1850
|
-
const {
|
|
1851
|
-
width: calendarWidth,
|
|
1852
|
-
height: calendarHeight,
|
|
1853
|
-
} = this.element.getBoundingClientRect();
|
|
1854
|
-
const {
|
|
1855
|
-
left: inputLeft,
|
|
1856
|
-
top: inputTop,
|
|
1857
|
-
right: inputRight,
|
|
1858
|
-
bottom: inputBottom,
|
|
1859
|
-
width: inputWidth,
|
|
1860
|
-
height: inputHeight
|
|
1861
|
-
} = inputField.getBoundingClientRect();
|
|
1862
|
-
let {x: orientX, y: orientY} = config.orientation;
|
|
1863
|
-
let left = inputLeft;
|
|
1864
|
-
let top = inputTop;
|
|
1865
|
-
|
|
1866
|
-
// caliculate offsetLeft/Top of inputField
|
|
1867
|
-
if (offsetParent === document.body || !offsetParent) {
|
|
1868
|
-
left += window.scrollX;
|
|
1869
|
-
top += window.scrollY;
|
|
1870
|
-
} else {
|
|
1871
|
-
const offsetParentRect = offsetParent.getBoundingClientRect();
|
|
1872
|
-
left -= offsetParentRect.left - offsetParent.scrollLeft;
|
|
1873
|
-
top -= offsetParentRect.top - offsetParent.scrollTop;
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
// caliculate the boundaries of the visible area that contains inputField
|
|
1877
|
-
const scrollParent = findScrollParents(inputField);
|
|
1878
|
-
let scrollAreaLeft = 0;
|
|
1879
|
-
let scrollAreaTop = 0;
|
|
1880
|
-
let {
|
|
1881
|
-
clientWidth: scrollAreaRight,
|
|
1882
|
-
clientHeight: scrollAreaBottom,
|
|
1883
|
-
} = document.documentElement;
|
|
1884
|
-
|
|
1885
|
-
if (scrollParent) {
|
|
1886
|
-
const scrollParentRect = scrollParent.getBoundingClientRect();
|
|
1887
|
-
if (scrollParentRect.top > 0) {
|
|
1888
|
-
scrollAreaTop = scrollParentRect.top;
|
|
1889
|
-
}
|
|
1890
|
-
if (scrollParentRect.left > 0) {
|
|
1891
|
-
scrollAreaLeft = scrollParentRect.left;
|
|
1892
|
-
}
|
|
1893
|
-
if (scrollParentRect.right < scrollAreaRight) {
|
|
1894
|
-
scrollAreaRight = scrollParentRect.right;
|
|
1895
|
-
}
|
|
1896
|
-
if (scrollParentRect.bottom < scrollAreaBottom) {
|
|
1897
|
-
scrollAreaBottom = scrollParentRect.bottom;
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
// determine the horizontal orientation and left position
|
|
1902
|
-
let adjustment = 0;
|
|
1903
|
-
if (orientX === 'auto') {
|
|
1904
|
-
if (inputLeft < scrollAreaLeft) {
|
|
1905
|
-
orientX = 'left';
|
|
1906
|
-
adjustment = scrollAreaLeft - inputLeft;
|
|
1907
|
-
} else if (inputLeft + calendarWidth > scrollAreaRight) {
|
|
1908
|
-
orientX = 'right';
|
|
1909
|
-
if (scrollAreaRight < inputRight) {
|
|
1910
|
-
adjustment = scrollAreaRight - inputRight;
|
|
1911
|
-
}
|
|
1912
|
-
} else if (getTextDirection(inputField) === 'rtl') {
|
|
1913
|
-
orientX = inputRight - calendarWidth < scrollAreaLeft ? 'left' : 'right';
|
|
1914
|
-
} else {
|
|
1915
|
-
orientX = 'left';
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
if (orientX === 'right') {
|
|
1919
|
-
left += inputWidth - calendarWidth;
|
|
1920
|
-
}
|
|
1921
|
-
left += adjustment;
|
|
1922
|
-
|
|
1923
|
-
// determine the vertical orientation and top position
|
|
1924
|
-
if (orientY === 'auto') {
|
|
1925
|
-
if (inputTop - calendarHeight > scrollAreaTop) {
|
|
1926
|
-
orientY = inputBottom + calendarHeight > scrollAreaBottom ? 'top' : 'bottom';
|
|
1927
|
-
} else {
|
|
1928
|
-
orientY = 'bottom';
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
if (orientY === 'top') {
|
|
1932
|
-
top -= calendarHeight;
|
|
1933
|
-
} else {
|
|
1934
|
-
top += inputHeight;
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
classList.remove(...Object.values(orientClasses));
|
|
1938
|
-
classList.add(orientClasses[orientX], orientClasses[orientY]);
|
|
1939
|
-
|
|
1940
|
-
style.left = toPx(left);
|
|
1941
|
-
style.top = toPx(top);
|
|
1942
|
-
}
|
|
1943
|
-
|
|
1944
|
-
setViewSwitchLabel(labelText) {
|
|
1945
|
-
this.controls.viewSwitch.textContent = labelText;
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
setPrevBtnDisabled(disabled) {
|
|
1949
|
-
this.controls.prevBtn.disabled = disabled;
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
|
-
setNextBtnDisabled(disabled) {
|
|
1953
|
-
this.controls.nextBtn.disabled = disabled;
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
changeView(viewId) {
|
|
1957
|
-
const oldView = this.currentView;
|
|
1958
|
-
const newView = this.views[viewId];
|
|
1959
|
-
if (newView.id !== oldView.id) {
|
|
1960
|
-
this.currentView = newView;
|
|
1961
|
-
this._renderMethod = 'render';
|
|
1962
|
-
triggerDatepickerEvent(this.datepicker, 'changeView');
|
|
1963
|
-
this.main.replaceChild(newView.element, oldView.element);
|
|
1964
|
-
}
|
|
1965
|
-
return this;
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
// Change the focused date (view date)
|
|
1969
|
-
changeFocus(newViewDate) {
|
|
1970
|
-
this._renderMethod = setViewDate(this, newViewDate) ? 'render' : 'refreshFocus';
|
|
1971
|
-
this.views.forEach((view) => {
|
|
1972
|
-
view.updateFocus();
|
|
1973
|
-
});
|
|
1974
|
-
return this;
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
|
-
// Apply the change of the selected dates
|
|
1978
|
-
update() {
|
|
1979
|
-
const newViewDate = computeResetViewDate(this.datepicker);
|
|
1980
|
-
this._renderMethod = setViewDate(this, newViewDate) ? 'render' : 'refresh';
|
|
1981
|
-
this.views.forEach((view) => {
|
|
1982
|
-
view.updateFocus();
|
|
1983
|
-
view.updateSelection();
|
|
1984
|
-
});
|
|
1985
|
-
return this;
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
// Refresh the picker UI
|
|
1989
|
-
render(quickRender = true) {
|
|
1990
|
-
const renderMethod = (quickRender && this._renderMethod) || 'render';
|
|
1991
|
-
delete this._renderMethod;
|
|
1992
|
-
|
|
1993
|
-
this.currentView[renderMethod]();
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
// Find the closest date that doesn't meet the condition for unavailable date
|
|
1998
|
-
// Returns undefined if no available date is found
|
|
1999
|
-
// addFn: function to calculate the next date
|
|
2000
|
-
// - args: time value, amount
|
|
2001
|
-
// increase: amount to pass to addFn
|
|
2002
|
-
// testFn: function to test the unavailablity of the date
|
|
2003
|
-
// - args: time value; retun: true if unavailable
|
|
2004
|
-
function findNextAvailableOne(date, addFn, increase, testFn, min, max) {
|
|
2005
|
-
if (!isInRange(date, min, max)) {
|
|
2006
|
-
return;
|
|
2007
|
-
}
|
|
2008
|
-
if (testFn(date)) {
|
|
2009
|
-
const newDate = addFn(date, increase);
|
|
2010
|
-
return findNextAvailableOne(newDate, addFn, increase, testFn, min, max);
|
|
2011
|
-
}
|
|
2012
|
-
return date;
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
// direction: -1 (left/up), 1 (right/down)
|
|
2016
|
-
// vertical: true for up/down, false for left/right
|
|
2017
|
-
function moveByArrowKey(datepicker, ev, direction, vertical) {
|
|
2018
|
-
const picker = datepicker.picker;
|
|
2019
|
-
const currentView = picker.currentView;
|
|
2020
|
-
const step = currentView.step || 1;
|
|
2021
|
-
let viewDate = picker.viewDate;
|
|
2022
|
-
let addFn;
|
|
2023
|
-
let testFn;
|
|
2024
|
-
switch (currentView.id) {
|
|
2025
|
-
case 0:
|
|
2026
|
-
if (vertical) {
|
|
2027
|
-
viewDate = addDays(viewDate, direction * 7);
|
|
2028
|
-
} else if (ev.ctrlKey || ev.metaKey) {
|
|
2029
|
-
viewDate = addYears(viewDate, direction);
|
|
2030
|
-
} else {
|
|
2031
|
-
viewDate = addDays(viewDate, direction);
|
|
2032
|
-
}
|
|
2033
|
-
addFn = addDays;
|
|
2034
|
-
testFn = (date) => currentView.disabled.includes(date);
|
|
2035
|
-
break;
|
|
2036
|
-
case 1:
|
|
2037
|
-
viewDate = addMonths(viewDate, vertical ? direction * 4 : direction);
|
|
2038
|
-
addFn = addMonths;
|
|
2039
|
-
testFn = (date) => {
|
|
2040
|
-
const dt = new Date(date);
|
|
2041
|
-
const {year, disabled} = currentView;
|
|
2042
|
-
return dt.getFullYear() === year && disabled.includes(dt.getMonth());
|
|
2043
|
-
};
|
|
2044
|
-
break;
|
|
2045
|
-
default:
|
|
2046
|
-
viewDate = addYears(viewDate, direction * (vertical ? 4 : 1) * step);
|
|
2047
|
-
addFn = addYears;
|
|
2048
|
-
testFn = date => currentView.disabled.includes(startOfYearPeriod(date, step));
|
|
2049
|
-
}
|
|
2050
|
-
viewDate = findNextAvailableOne(
|
|
2051
|
-
viewDate,
|
|
2052
|
-
addFn,
|
|
2053
|
-
direction < 0 ? -step : step,
|
|
2054
|
-
testFn,
|
|
2055
|
-
currentView.minDate,
|
|
2056
|
-
currentView.maxDate
|
|
2057
|
-
);
|
|
2058
|
-
if (viewDate !== undefined) {
|
|
2059
|
-
picker.changeFocus(viewDate).render();
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
function onKeydown(datepicker, ev) {
|
|
2064
|
-
const key = ev.key;
|
|
2065
|
-
if (key === 'Tab') {
|
|
2066
|
-
unfocus(datepicker);
|
|
2067
|
-
return;
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
const picker = datepicker.picker;
|
|
2071
|
-
const {id, isMinView} = picker.currentView;
|
|
2072
|
-
if (!picker.active) {
|
|
2073
|
-
if (key === 'ArrowDown') {
|
|
2074
|
-
picker.show();
|
|
2075
|
-
} else {
|
|
2076
|
-
if (key === 'Enter') {
|
|
2077
|
-
datepicker.update();
|
|
2078
|
-
} else if (key === 'Escape') {
|
|
2079
|
-
picker.show();
|
|
2080
|
-
}
|
|
2081
|
-
return;
|
|
2082
|
-
}
|
|
2083
|
-
} else if (datepicker.editMode) {
|
|
2084
|
-
if (key === 'Enter') {
|
|
2085
|
-
datepicker.exitEditMode({update: true, autohide: datepicker.config.autohide});
|
|
2086
|
-
} else if (key === 'Escape') {
|
|
2087
|
-
picker.hide();
|
|
2088
|
-
}
|
|
2089
|
-
return;
|
|
2090
|
-
} else {
|
|
2091
|
-
if (key === 'ArrowLeft') {
|
|
2092
|
-
if (ev.ctrlKey || ev.metaKey) {
|
|
2093
|
-
goToPrevOrNext(datepicker, -1);
|
|
2094
|
-
} else if (ev.shiftKey) {
|
|
2095
|
-
datepicker.enterEditMode();
|
|
2096
|
-
return;
|
|
2097
|
-
} else {
|
|
2098
|
-
moveByArrowKey(datepicker, ev, -1, false);
|
|
2099
|
-
}
|
|
2100
|
-
} else if (key === 'ArrowRight') {
|
|
2101
|
-
if (ev.ctrlKey || ev.metaKey) {
|
|
2102
|
-
goToPrevOrNext(datepicker, 1);
|
|
2103
|
-
} else if (ev.shiftKey) {
|
|
2104
|
-
datepicker.enterEditMode();
|
|
2105
|
-
return;
|
|
2106
|
-
} else {
|
|
2107
|
-
moveByArrowKey(datepicker, ev, 1, false);
|
|
2108
|
-
}
|
|
2109
|
-
} else if (key === 'ArrowUp') {
|
|
2110
|
-
if (ev.ctrlKey || ev.metaKey) {
|
|
2111
|
-
switchView(datepicker);
|
|
2112
|
-
} else if (ev.shiftKey) {
|
|
2113
|
-
datepicker.enterEditMode();
|
|
2114
|
-
return;
|
|
2115
|
-
} else {
|
|
2116
|
-
moveByArrowKey(datepicker, ev, -1, true);
|
|
2117
|
-
}
|
|
2118
|
-
} else if (key === 'ArrowDown') {
|
|
2119
|
-
if (ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
|
|
2120
|
-
datepicker.enterEditMode();
|
|
2121
|
-
return;
|
|
2122
|
-
}
|
|
2123
|
-
moveByArrowKey(datepicker, ev, 1, true);
|
|
2124
|
-
} else if (key === 'Enter') {
|
|
2125
|
-
if (isMinView) {
|
|
2126
|
-
datepicker.setDate(picker.viewDate);
|
|
2127
|
-
return;
|
|
2128
|
-
}
|
|
2129
|
-
picker.changeView(id - 1).render();
|
|
2130
|
-
} else {
|
|
2131
|
-
if (key === 'Escape') {
|
|
2132
|
-
picker.hide();
|
|
2133
|
-
} else if (
|
|
2134
|
-
key === 'Backspace'
|
|
2135
|
-
|| key === 'Delete'
|
|
2136
|
-
|| (key.length === 1 && !ev.ctrlKey && !ev.metaKey)
|
|
2137
|
-
) {
|
|
2138
|
-
datepicker.enterEditMode();
|
|
2139
|
-
}
|
|
2140
|
-
return;
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
ev.preventDefault();
|
|
2144
|
-
}
|
|
2145
|
-
|
|
2146
|
-
function onFocus(datepicker) {
|
|
2147
|
-
if (datepicker.config.showOnFocus && !datepicker._showing) {
|
|
2148
|
-
datepicker.show();
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
|
|
2152
|
-
// for the prevention for entering edit mode while getting focus on click
|
|
2153
|
-
function onMousedown(datepicker, ev) {
|
|
2154
|
-
const el = ev.target;
|
|
2155
|
-
if (datepicker.picker.active || datepicker.config.showOnClick) {
|
|
2156
|
-
el._active = isActiveElement(el);
|
|
2157
|
-
el._clicking = setTimeout(() => {
|
|
2158
|
-
delete el._active;
|
|
2159
|
-
delete el._clicking;
|
|
2160
|
-
}, 2000);
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
|
|
2164
|
-
function onClickInput(datepicker, ev) {
|
|
2165
|
-
const el = ev.target;
|
|
2166
|
-
if (!el._clicking) {
|
|
2167
|
-
return;
|
|
2168
|
-
}
|
|
2169
|
-
clearTimeout(el._clicking);
|
|
2170
|
-
delete el._clicking;
|
|
2171
|
-
|
|
2172
|
-
if (el._active) {
|
|
2173
|
-
datepicker.enterEditMode();
|
|
2174
|
-
}
|
|
2175
|
-
delete el._active;
|
|
2176
|
-
|
|
2177
|
-
if (datepicker.config.showOnClick) {
|
|
2178
|
-
datepicker.show();
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
|
|
2182
|
-
function onPaste(datepicker, ev) {
|
|
2183
|
-
if (ev.clipboardData.types.includes('text/plain')) {
|
|
2184
|
-
datepicker.enterEditMode();
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
// for the `document` to delegate the events from outside the picker/input field
|
|
2189
|
-
function onClickOutside(datepicker, ev) {
|
|
2190
|
-
const {element, picker} = datepicker;
|
|
2191
|
-
// check both picker's and input's activeness to make updateOnBlur work in
|
|
2192
|
-
// the cases where...
|
|
2193
|
-
// - picker is hidden by ESC key press → input stays focused
|
|
2194
|
-
// - input is unfocused by closing mobile keyboard → piker is kept shown
|
|
2195
|
-
if (!picker.active && !isActiveElement(element)) {
|
|
2196
|
-
return;
|
|
2197
|
-
}
|
|
2198
|
-
const pickerElem = picker.element;
|
|
2199
|
-
if (findElementInEventPath(ev, el => el === element || el === pickerElem)) {
|
|
2200
|
-
return;
|
|
2201
|
-
}
|
|
2202
|
-
unfocus(datepicker);
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
function stringifyDates(dates, config) {
|
|
2206
|
-
return dates
|
|
2207
|
-
.map(dt => formatDate(dt, config.format, config.locale))
|
|
2208
|
-
.join(config.dateDelimiter);
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
// parse input dates and create an array of time values for selection
|
|
2212
|
-
// returns undefined if there are no valid dates in inputDates
|
|
2213
|
-
// when origDates (current selection) is passed, the function works to mix
|
|
2214
|
-
// the input dates into the current selection
|
|
2215
|
-
function processInputDates(datepicker, inputDates, clear = false) {
|
|
2216
|
-
// const {config, dates: origDates, rangepicker} = datepicker;
|
|
2217
|
-
const {config, dates: origDates, rangeSideIndex} = datepicker;
|
|
2218
|
-
if (inputDates.length === 0) {
|
|
2219
|
-
// empty input is considered valid unless origiDates is passed
|
|
2220
|
-
return clear ? [] : undefined;
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2223
|
-
// const rangeEnd = rangepicker && datepicker === rangepicker.datepickers[1];
|
|
2224
|
-
let newDates = inputDates.reduce((dates, dt) => {
|
|
2225
|
-
let date = parseDate(dt, config.format, config.locale);
|
|
2226
|
-
if (date === undefined) {
|
|
2227
|
-
return dates;
|
|
2228
|
-
}
|
|
2229
|
-
// adjust to 1st of the month/Jan 1st of the year
|
|
2230
|
-
// or to the last day of the monh/Dec 31st of the year if the datepicker
|
|
2231
|
-
// is the range-end picker of a rangepicker
|
|
2232
|
-
date = regularizeDate(date, config.pickLevel, rangeSideIndex);
|
|
2233
|
-
if (
|
|
2234
|
-
isInRange(date, config.minDate, config.maxDate)
|
|
2235
|
-
&& !dates.includes(date)
|
|
2236
|
-
&& !config.datesDisabled.includes(date)
|
|
2237
|
-
&& (config.pickLevel > 0 || !config.daysOfWeekDisabled.includes(new Date(date).getDay()))
|
|
2238
|
-
) {
|
|
2239
|
-
dates.push(date);
|
|
2240
|
-
}
|
|
2241
|
-
return dates;
|
|
2242
|
-
}, []);
|
|
2243
|
-
if (newDates.length === 0) {
|
|
2244
|
-
return;
|
|
2245
|
-
}
|
|
2246
|
-
if (config.multidate && !clear) {
|
|
2247
|
-
// get the synmetric difference between origDates and newDates
|
|
2248
|
-
newDates = newDates.reduce((dates, date) => {
|
|
2249
|
-
if (!origDates.includes(date)) {
|
|
2250
|
-
dates.push(date);
|
|
2251
|
-
}
|
|
2252
|
-
return dates;
|
|
2253
|
-
}, origDates.filter(date => !newDates.includes(date)));
|
|
2254
|
-
}
|
|
2255
|
-
// do length check always because user can input multiple dates regardless of the mode
|
|
2256
|
-
return config.maxNumberOfDates && newDates.length > config.maxNumberOfDates
|
|
2257
|
-
? newDates.slice(config.maxNumberOfDates * -1)
|
|
2258
|
-
: newDates;
|
|
2259
|
-
}
|
|
2260
|
-
|
|
2261
|
-
// refresh the UI elements
|
|
2262
|
-
// modes: 1: input only, 2, picker only, 3 both
|
|
2263
|
-
function refreshUI(datepicker, mode = 3, quickRender = true) {
|
|
2264
|
-
const {config, picker, inputField} = datepicker;
|
|
2265
|
-
if (mode & 2) {
|
|
2266
|
-
const newView = picker.active ? config.pickLevel : config.startView;
|
|
2267
|
-
picker.update().changeView(newView).render(quickRender);
|
|
2268
|
-
}
|
|
2269
|
-
if (mode & 1 && inputField) {
|
|
2270
|
-
inputField.value = stringifyDates(datepicker.dates, config);
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
|
|
2274
|
-
function setDate(datepicker, inputDates, options) {
|
|
2275
|
-
let {clear, render, autohide, revert} = options;
|
|
2276
|
-
if (render === undefined) {
|
|
2277
|
-
render = true;
|
|
2278
|
-
}
|
|
2279
|
-
if (!render) {
|
|
2280
|
-
autohide = false;
|
|
2281
|
-
} else if (autohide === undefined) {
|
|
2282
|
-
autohide = datepicker.config.autohide;
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
const newDates = processInputDates(datepicker, inputDates, clear);
|
|
2286
|
-
if (!newDates && !revert) {
|
|
2287
|
-
return;
|
|
2288
|
-
}
|
|
2289
|
-
if (newDates && newDates.toString() !== datepicker.dates.toString()) {
|
|
2290
|
-
datepicker.dates = newDates;
|
|
2291
|
-
refreshUI(datepicker, render ? 3 : 1);
|
|
2292
|
-
triggerDatepickerEvent(datepicker, 'changeDate');
|
|
2293
|
-
} else {
|
|
2294
|
-
refreshUI(datepicker, 1);
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
if (autohide) {
|
|
2298
|
-
datepicker.hide();
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
|
-
/**
|
|
2303
|
-
* Class representing a date picker
|
|
2304
|
-
*/
|
|
2305
|
-
class Datepicker {
|
|
2306
|
-
/**
|
|
2307
|
-
* Create a date picker
|
|
2308
|
-
* @param {Element} element - element to bind a date picker
|
|
2309
|
-
* @param {Object} [options] - config options
|
|
2310
|
-
* @param {DateRangePicker} [rangepicker] - DateRangePicker instance the
|
|
2311
|
-
* date picker belongs to. Use this only when creating date picker as a part
|
|
2312
|
-
* of date range picker
|
|
2313
|
-
*/
|
|
2314
|
-
constructor(element, options = {}, rangepicker = undefined) {
|
|
2315
|
-
element.datepicker = this;
|
|
2316
|
-
this.element = element;
|
|
2317
|
-
|
|
2318
|
-
const config = this.config = Object.assign({
|
|
2319
|
-
buttonClass: (options.buttonClass && String(options.buttonClass)) || 'button',
|
|
2320
|
-
container: null,
|
|
2321
|
-
defaultViewDate: today(),
|
|
2322
|
-
maxDate: undefined,
|
|
2323
|
-
minDate: undefined,
|
|
2324
|
-
}, processOptions(defaultOptions, this));
|
|
2325
|
-
// configure by type
|
|
2326
|
-
const inline = this.inline = element.tagName !== 'INPUT';
|
|
2327
|
-
let inputField;
|
|
2328
|
-
if (inline) {
|
|
2329
|
-
config.container = element;
|
|
2330
|
-
} else {
|
|
2331
|
-
if (options.container) {
|
|
2332
|
-
// omit string type check because it doesn't guarantee to avoid errors
|
|
2333
|
-
// (invalid selector string causes abend with sytax error)
|
|
2334
|
-
config.container = options.container instanceof HTMLElement
|
|
2335
|
-
? options.container
|
|
2336
|
-
: document.querySelector(options.container);
|
|
2337
|
-
}
|
|
2338
|
-
inputField = this.inputField = element;
|
|
2339
|
-
inputField.classList.add('datepicker-input');
|
|
2340
|
-
}
|
|
2341
|
-
if (rangepicker) {
|
|
2342
|
-
// check validiry
|
|
2343
|
-
const index = rangepicker.inputs.indexOf(inputField);
|
|
2344
|
-
const datepickers = rangepicker.datepickers;
|
|
2345
|
-
if (index < 0 || index > 1 || !Array.isArray(datepickers)) {
|
|
2346
|
-
throw Error('Invalid rangepicker object.');
|
|
2347
|
-
}
|
|
2348
|
-
// attach itaelf to the rangepicker here so that processInputDates() can
|
|
2349
|
-
// determine if this is the range-end picker of the rangepicker while
|
|
2350
|
-
// setting inital values when pickLevel > 0
|
|
2351
|
-
datepickers[index] = this;
|
|
2352
|
-
// add getter for rangepicker
|
|
2353
|
-
Object.defineProperty(this, 'rangepicker', {
|
|
2354
|
-
get() {
|
|
2355
|
-
return rangepicker;
|
|
2356
|
-
},
|
|
2357
|
-
});
|
|
2358
|
-
Object.defineProperty(this, 'rangeSideIndex', {
|
|
2359
|
-
get() {
|
|
2360
|
-
return index;
|
|
2361
|
-
},
|
|
2362
|
-
});
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
// set up config
|
|
2366
|
-
this._options = options;
|
|
2367
|
-
Object.assign(config, processOptions(options, this));
|
|
2368
|
-
|
|
2369
|
-
// set initial dates
|
|
2370
|
-
let initialDates;
|
|
2371
|
-
if (inline) {
|
|
2372
|
-
initialDates = stringToArray(element.dataset.date, config.dateDelimiter);
|
|
2373
|
-
delete element.dataset.date;
|
|
2374
|
-
} else {
|
|
2375
|
-
initialDates = stringToArray(inputField.value, config.dateDelimiter);
|
|
2376
|
-
}
|
|
2377
|
-
this.dates = [];
|
|
2378
|
-
// process initial value
|
|
2379
|
-
const inputDateValues = processInputDates(this, initialDates);
|
|
2380
|
-
if (inputDateValues && inputDateValues.length > 0) {
|
|
2381
|
-
this.dates = inputDateValues;
|
|
2382
|
-
}
|
|
2383
|
-
if (inputField) {
|
|
2384
|
-
inputField.value = stringifyDates(this.dates, config);
|
|
2385
|
-
}
|
|
2386
|
-
|
|
2387
|
-
const picker = this.picker = new Picker(this);
|
|
2388
|
-
|
|
2389
|
-
if (inline) {
|
|
2390
|
-
this.show();
|
|
2391
|
-
} else {
|
|
2392
|
-
// set up event listeners in other modes
|
|
2393
|
-
const onMousedownDocument = onClickOutside.bind(null, this);
|
|
2394
|
-
const listeners = [
|
|
2395
|
-
[inputField, 'keydown', onKeydown.bind(null, this)],
|
|
2396
|
-
[inputField, 'focus', onFocus.bind(null, this)],
|
|
2397
|
-
[inputField, 'mousedown', onMousedown.bind(null, this)],
|
|
2398
|
-
[inputField, 'click', onClickInput.bind(null, this)],
|
|
2399
|
-
[inputField, 'paste', onPaste.bind(null, this)],
|
|
2400
|
-
[document, 'mousedown', onMousedownDocument],
|
|
2401
|
-
[document, 'touchstart', onMousedownDocument],
|
|
2402
|
-
[window, 'resize', picker.place.bind(picker)]
|
|
2403
|
-
];
|
|
2404
|
-
registerListeners(this, listeners);
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
/**
|
|
2409
|
-
* Format Date object or time value in given format and language
|
|
2410
|
-
* @param {Date|Number} date - date or time value to format
|
|
2411
|
-
* @param {String|Object} format - format string or object that contains
|
|
2412
|
-
* toDisplay() custom formatter, whose signature is
|
|
2413
|
-
* - args:
|
|
2414
|
-
* - date: {Date} - Date instance of the date passed to the method
|
|
2415
|
-
* - format: {Object} - the format object passed to the method
|
|
2416
|
-
* - locale: {Object} - locale for the language specified by `lang`
|
|
2417
|
-
* - return:
|
|
2418
|
-
* {String} formatted date
|
|
2419
|
-
* @param {String} [lang=en] - language code for the locale to use
|
|
2420
|
-
* @return {String} formatted date
|
|
2421
|
-
*/
|
|
2422
|
-
static formatDate(date, format, lang) {
|
|
2423
|
-
return formatDate(date, format, lang && locales[lang] || locales.en);
|
|
2424
|
-
}
|
|
2425
|
-
|
|
2426
|
-
/**
|
|
2427
|
-
* Parse date string
|
|
2428
|
-
* @param {String|Date|Number} dateStr - date string, Date object or time
|
|
2429
|
-
* value to parse
|
|
2430
|
-
* @param {String|Object} format - format string or object that contains
|
|
2431
|
-
* toValue() custom parser, whose signature is
|
|
2432
|
-
* - args:
|
|
2433
|
-
* - dateStr: {String|Date|Number} - the dateStr passed to the method
|
|
2434
|
-
* - format: {Object} - the format object passed to the method
|
|
2435
|
-
* - locale: {Object} - locale for the language specified by `lang`
|
|
2436
|
-
* - return:
|
|
2437
|
-
* {Date|Number} parsed date or its time value
|
|
2438
|
-
* @param {String} [lang=en] - language code for the locale to use
|
|
2439
|
-
* @return {Number} time value of parsed date
|
|
2440
|
-
*/
|
|
2441
|
-
static parseDate(dateStr, format, lang) {
|
|
2442
|
-
return parseDate(dateStr, format, lang && locales[lang] || locales.en);
|
|
2443
|
-
}
|
|
2444
|
-
|
|
2445
|
-
/**
|
|
2446
|
-
* @type {Object} - Installed locales in `[languageCode]: localeObject` format
|
|
2447
|
-
* en`:_English (US)_ is pre-installed.
|
|
2448
|
-
*/
|
|
2449
|
-
static get locales() {
|
|
2450
|
-
return locales;
|
|
2451
|
-
}
|
|
2452
|
-
|
|
2453
|
-
/**
|
|
2454
|
-
* @type {Boolean} - Whether the picker element is shown. `true` whne shown
|
|
2455
|
-
*/
|
|
2456
|
-
get active() {
|
|
2457
|
-
return !!(this.picker && this.picker.active);
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
/**
|
|
2461
|
-
* @type {HTMLDivElement} - DOM object of picker element
|
|
2462
|
-
*/
|
|
2463
|
-
get pickerElement() {
|
|
2464
|
-
return this.picker ? this.picker.element : undefined;
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
/**
|
|
2468
|
-
* Set new values to the config options
|
|
2469
|
-
* @param {Object} options - config options to update
|
|
2470
|
-
*/
|
|
2471
|
-
setOptions(options) {
|
|
2472
|
-
const picker = this.picker;
|
|
2473
|
-
const newOptions = processOptions(options, this);
|
|
2474
|
-
Object.assign(this._options, options);
|
|
2475
|
-
Object.assign(this.config, newOptions);
|
|
2476
|
-
picker.setOptions(newOptions);
|
|
2477
|
-
|
|
2478
|
-
refreshUI(this, 3);
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
|
-
/**
|
|
2482
|
-
* Show the picker element
|
|
2483
|
-
*/
|
|
2484
|
-
show() {
|
|
2485
|
-
if (this.inputField) {
|
|
2486
|
-
if (this.inputField.disabled) {
|
|
2487
|
-
return;
|
|
2488
|
-
}
|
|
2489
|
-
if (!isActiveElement(this.inputField) && !this.config.disableTouchKeyboard) {
|
|
2490
|
-
this._showing = true;
|
|
2491
|
-
this.inputField.focus();
|
|
2492
|
-
delete this._showing;
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
this.picker.show();
|
|
2496
|
-
}
|
|
2497
|
-
|
|
2498
|
-
/**
|
|
2499
|
-
* Hide the picker element
|
|
2500
|
-
* Not available on inline picker
|
|
2501
|
-
*/
|
|
2502
|
-
hide() {
|
|
2503
|
-
if (this.inline) {
|
|
2504
|
-
return;
|
|
2505
|
-
}
|
|
2506
|
-
this.picker.hide();
|
|
2507
|
-
this.picker.update().changeView(this.config.startView).render();
|
|
2508
|
-
}
|
|
2509
|
-
|
|
2510
|
-
/**
|
|
2511
|
-
* Destroy the Datepicker instance
|
|
2512
|
-
* @return {Detepicker} - the instance destroyed
|
|
2513
|
-
*/
|
|
2514
|
-
destroy() {
|
|
2515
|
-
this.hide();
|
|
2516
|
-
unregisterListeners(this);
|
|
2517
|
-
this.picker.detach();
|
|
2518
|
-
if (!this.inline) {
|
|
2519
|
-
this.inputField.classList.remove('datepicker-input');
|
|
2520
|
-
}
|
|
2521
|
-
delete this.element.datepicker;
|
|
2522
|
-
return this;
|
|
2523
|
-
}
|
|
2524
|
-
|
|
2525
|
-
/**
|
|
2526
|
-
* Get the selected date(s)
|
|
2527
|
-
*
|
|
2528
|
-
* The method returns a Date object of selected date by default, and returns
|
|
2529
|
-
* an array of selected dates in multidate mode. If format string is passed,
|
|
2530
|
-
* it returns date string(s) formatted in given format.
|
|
2531
|
-
*
|
|
2532
|
-
* @param {String} [format] - Format string to stringify the date(s)
|
|
2533
|
-
* @return {Date|String|Date[]|String[]} - selected date(s), or if none is
|
|
2534
|
-
* selected, empty array in multidate mode and untitled in sigledate mode
|
|
2535
|
-
*/
|
|
2536
|
-
getDate(format = undefined) {
|
|
2537
|
-
const callback = format
|
|
2538
|
-
? date => formatDate(date, format, this.config.locale)
|
|
2539
|
-
: date => new Date(date);
|
|
2540
|
-
|
|
2541
|
-
if (this.config.multidate) {
|
|
2542
|
-
return this.dates.map(callback);
|
|
2543
|
-
}
|
|
2544
|
-
if (this.dates.length > 0) {
|
|
2545
|
-
return callback(this.dates[0]);
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
/**
|
|
2550
|
-
* Set selected date(s)
|
|
2551
|
-
*
|
|
2552
|
-
* In multidate mode, you can pass multiple dates as a series of arguments
|
|
2553
|
-
* or an array. (Since each date is parsed individually, the type of the
|
|
2554
|
-
* dates doesn't have to be the same.)
|
|
2555
|
-
* The given dates are used to toggle the select status of each date. The
|
|
2556
|
-
* number of selected dates is kept from exceeding the length set to
|
|
2557
|
-
* maxNumberOfDates.
|
|
2558
|
-
*
|
|
2559
|
-
* With clear: true option, the method can be used to clear the selection
|
|
2560
|
-
* and to replace the selection instead of toggling in multidate mode.
|
|
2561
|
-
* If the option is passed with no date arguments or an empty dates array,
|
|
2562
|
-
* it works as "clear" (clear the selection then set nothing), and if the
|
|
2563
|
-
* option is passed with new dates to select, it works as "replace" (clear
|
|
2564
|
-
* the selection then set the given dates)
|
|
2565
|
-
*
|
|
2566
|
-
* When render: false option is used, the method omits re-rendering the
|
|
2567
|
-
* picker element. In this case, you need to call refresh() method later in
|
|
2568
|
-
* order for the picker element to reflect the changes. The input field is
|
|
2569
|
-
* refreshed always regardless of this option.
|
|
2570
|
-
*
|
|
2571
|
-
* When invalid (unparsable, repeated, disabled or out-of-range) dates are
|
|
2572
|
-
* passed, the method ignores them and applies only valid ones. In the case
|
|
2573
|
-
* that all the given dates are invalid, which is distinguished from passing
|
|
2574
|
-
* no dates, the method considers it as an error and leaves the selection
|
|
2575
|
-
* untouched. (The input field also remains untouched unless revert: true
|
|
2576
|
-
* option is used.)
|
|
2577
|
-
*
|
|
2578
|
-
* @param {...(Date|Number|String)|Array} [dates] - Date strings, Date
|
|
2579
|
-
* objects, time values or mix of those for new selection
|
|
2580
|
-
* @param {Object} [options] - function options
|
|
2581
|
-
* - clear: {boolean} - Whether to clear the existing selection
|
|
2582
|
-
* defualt: false
|
|
2583
|
-
* - render: {boolean} - Whether to re-render the picker element
|
|
2584
|
-
* default: true
|
|
2585
|
-
* - autohide: {boolean} - Whether to hide the picker element after re-render
|
|
2586
|
-
* Ignored when used with render: false
|
|
2587
|
-
* default: config.autohide
|
|
2588
|
-
* - revert: {boolean} - Whether to refresh the input field when all the
|
|
2589
|
-
* passed dates are invalid
|
|
2590
|
-
* default: false
|
|
2591
|
-
*/
|
|
2592
|
-
setDate(...args) {
|
|
2593
|
-
const dates = [...args];
|
|
2594
|
-
const opts = {};
|
|
2595
|
-
const lastArg = lastItemOf(args);
|
|
2596
|
-
if (
|
|
2597
|
-
typeof lastArg === 'object'
|
|
2598
|
-
&& !Array.isArray(lastArg)
|
|
2599
|
-
&& !(lastArg instanceof Date)
|
|
2600
|
-
&& lastArg
|
|
2601
|
-
) {
|
|
2602
|
-
Object.assign(opts, dates.pop());
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
const inputDates = Array.isArray(dates[0]) ? dates[0] : dates;
|
|
2606
|
-
setDate(this, inputDates, opts);
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2609
|
-
/**
|
|
2610
|
-
* Update the selected date(s) with input field's value
|
|
2611
|
-
* Not available on inline picker
|
|
2612
|
-
*
|
|
2613
|
-
* The input field will be refreshed with properly formatted date string.
|
|
2614
|
-
*
|
|
2615
|
-
* In the case that all the entered dates are invalid (unparsable, repeated,
|
|
2616
|
-
* disabled or out-of-range), whixh is distinguished from empty input field,
|
|
2617
|
-
* the method leaves the input field untouched as well as the selection by
|
|
2618
|
-
* default. If revert: true option is used in this case, the input field is
|
|
2619
|
-
* refreshed with the existing selection.
|
|
2620
|
-
*
|
|
2621
|
-
* @param {Object} [options] - function options
|
|
2622
|
-
* - autohide: {boolean} - whether to hide the picker element after refresh
|
|
2623
|
-
* default: false
|
|
2624
|
-
* - revert: {boolean} - Whether to refresh the input field when all the
|
|
2625
|
-
* passed dates are invalid
|
|
2626
|
-
* default: false
|
|
2627
|
-
*/
|
|
2628
|
-
update(options = undefined) {
|
|
2629
|
-
if (this.inline) {
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2632
|
-
|
|
2633
|
-
const opts = Object.assign(options || {}, {clear: true, render: true});
|
|
2634
|
-
const inputDates = stringToArray(this.inputField.value, this.config.dateDelimiter);
|
|
2635
|
-
setDate(this, inputDates, opts);
|
|
2636
|
-
}
|
|
2637
|
-
|
|
2638
|
-
/**
|
|
2639
|
-
* Refresh the picker element and the associated input field
|
|
2640
|
-
* @param {String} [target] - target item when refreshing one item only
|
|
2641
|
-
* 'picker' or 'input'
|
|
2642
|
-
* @param {Boolean} [forceRender] - whether to re-render the picker element
|
|
2643
|
-
* regardless of its state instead of optimized refresh
|
|
2644
|
-
*/
|
|
2645
|
-
refresh(target = undefined, forceRender = false) {
|
|
2646
|
-
if (target && typeof target !== 'string') {
|
|
2647
|
-
forceRender = target;
|
|
2648
|
-
target = undefined;
|
|
2649
|
-
}
|
|
2650
|
-
|
|
2651
|
-
let mode;
|
|
2652
|
-
if (target === 'picker') {
|
|
2653
|
-
mode = 2;
|
|
2654
|
-
} else if (target === 'input') {
|
|
2655
|
-
mode = 1;
|
|
2656
|
-
} else {
|
|
2657
|
-
mode = 3;
|
|
2658
|
-
}
|
|
2659
|
-
refreshUI(this, mode, !forceRender);
|
|
2660
|
-
}
|
|
2661
|
-
|
|
2662
|
-
/**
|
|
2663
|
-
* Enter edit mode
|
|
2664
|
-
* Not available on inline picker or when the picker element is hidden
|
|
2665
|
-
*/
|
|
2666
|
-
enterEditMode() {
|
|
2667
|
-
if (this.inline || !this.picker.active || this.editMode) {
|
|
2668
|
-
return;
|
|
2669
|
-
}
|
|
2670
|
-
this.editMode = true;
|
|
2671
|
-
this.inputField.classList.add('in-edit');
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
/**
|
|
2675
|
-
* Exit from edit mode
|
|
2676
|
-
* Not available on inline picker
|
|
2677
|
-
* @param {Object} [options] - function options
|
|
2678
|
-
* - update: {boolean} - whether to call update() after exiting
|
|
2679
|
-
* If false, input field is revert to the existing selection
|
|
2680
|
-
* default: false
|
|
2681
|
-
*/
|
|
2682
|
-
exitEditMode(options = undefined) {
|
|
2683
|
-
if (this.inline || !this.editMode) {
|
|
2684
|
-
return;
|
|
2685
|
-
}
|
|
2686
|
-
const opts = Object.assign({update: false}, options);
|
|
2687
|
-
delete this.editMode;
|
|
2688
|
-
this.inputField.classList.remove('in-edit');
|
|
2689
|
-
if (opts.update) {
|
|
2690
|
-
this.update(opts);
|
|
2691
|
-
}
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
|
|
2695
|
-
// filter out the config options inapproprite to pass to Datepicker
|
|
2696
|
-
function filterOptions(options) {
|
|
2697
|
-
const newOpts = Object.assign({}, options);
|
|
2698
|
-
|
|
2699
|
-
delete newOpts.inputs;
|
|
2700
|
-
delete newOpts.allowOneSidedRange;
|
|
2701
|
-
delete newOpts.maxNumberOfDates; // to ensure each datepicker handles a single date
|
|
2702
|
-
|
|
2703
|
-
return newOpts;
|
|
2704
|
-
}
|
|
2705
|
-
|
|
2706
|
-
function setupDatepicker(rangepicker, changeDateListener, el, options) {
|
|
2707
|
-
registerListeners(rangepicker, [
|
|
2708
|
-
[el, 'changeDate', changeDateListener],
|
|
2709
|
-
]);
|
|
2710
|
-
new Datepicker(el, options, rangepicker);
|
|
2711
|
-
}
|
|
2712
|
-
|
|
2713
|
-
function onChangeDate(rangepicker, ev) {
|
|
2714
|
-
// to prevent both datepickers trigger the other side's update each other
|
|
2715
|
-
if (rangepicker._updating) {
|
|
2716
|
-
return;
|
|
2717
|
-
}
|
|
2718
|
-
rangepicker._updating = true;
|
|
2719
|
-
|
|
2720
|
-
const target = ev.target;
|
|
2721
|
-
if (target.datepicker === undefined) {
|
|
2722
|
-
return;
|
|
2723
|
-
}
|
|
2724
|
-
|
|
2725
|
-
const datepickers = rangepicker.datepickers;
|
|
2726
|
-
const setDateOptions = {render: false};
|
|
2727
|
-
const changedSide = rangepicker.inputs.indexOf(target);
|
|
2728
|
-
const otherSide = changedSide === 0 ? 1 : 0;
|
|
2729
|
-
const changedDate = datepickers[changedSide].dates[0];
|
|
2730
|
-
const otherDate = datepickers[otherSide].dates[0];
|
|
2731
|
-
|
|
2732
|
-
if (changedDate !== undefined && otherDate !== undefined) {
|
|
2733
|
-
// if the start of the range > the end, swap them
|
|
2734
|
-
if (changedSide === 0 && changedDate > otherDate) {
|
|
2735
|
-
datepickers[0].setDate(otherDate, setDateOptions);
|
|
2736
|
-
datepickers[1].setDate(changedDate, setDateOptions);
|
|
2737
|
-
} else if (changedSide === 1 && changedDate < otherDate) {
|
|
2738
|
-
datepickers[0].setDate(changedDate, setDateOptions);
|
|
2739
|
-
datepickers[1].setDate(otherDate, setDateOptions);
|
|
2740
|
-
}
|
|
2741
|
-
} else if (!rangepicker.allowOneSidedRange) {
|
|
2742
|
-
// to prevent the range from becoming one-sided, copy changed side's
|
|
2743
|
-
// selection (no matter if it's empty) to the other side
|
|
2744
|
-
if (changedDate !== undefined || otherDate !== undefined) {
|
|
2745
|
-
setDateOptions.clear = true;
|
|
2746
|
-
datepickers[otherSide].setDate(datepickers[changedSide].dates, setDateOptions);
|
|
2747
|
-
}
|
|
2748
|
-
}
|
|
2749
|
-
datepickers[0].picker.update().render();
|
|
2750
|
-
datepickers[1].picker.update().render();
|
|
2751
|
-
delete rangepicker._updating;
|
|
2752
|
-
}
|
|
2753
|
-
|
|
2754
|
-
/**
|
|
2755
|
-
* Class representing a date range picker
|
|
2756
|
-
*/
|
|
2757
|
-
class DateRangePicker {
|
|
2758
|
-
/**
|
|
2759
|
-
* Create a date range picker
|
|
2760
|
-
* @param {Element} element - element to bind a date range picker
|
|
2761
|
-
* @param {Object} [options] - config options
|
|
2762
|
-
*/
|
|
2763
|
-
constructor(element, options = {}) {
|
|
2764
|
-
const inputs = Array.isArray(options.inputs)
|
|
2765
|
-
? options.inputs
|
|
2766
|
-
: Array.from(element.querySelectorAll('input'));
|
|
2767
|
-
if (inputs.length < 2) {
|
|
2768
|
-
return;
|
|
2769
|
-
}
|
|
2770
|
-
|
|
2771
|
-
element.rangepicker = this;
|
|
2772
|
-
this.element = element;
|
|
2773
|
-
this.inputs = inputs.slice(0, 2);
|
|
2774
|
-
this.allowOneSidedRange = !!options.allowOneSidedRange;
|
|
2775
|
-
|
|
2776
|
-
const changeDateListener = onChangeDate.bind(null, this);
|
|
2777
|
-
const cleanOptions = filterOptions(options);
|
|
2778
|
-
// in order for initial date setup to work right when pcicLvel > 0,
|
|
2779
|
-
// let Datepicker constructor add the instance to the rangepicker
|
|
2780
|
-
const datepickers = [];
|
|
2781
|
-
Object.defineProperty(this, 'datepickers', {
|
|
2782
|
-
get() {
|
|
2783
|
-
return datepickers;
|
|
2784
|
-
},
|
|
2785
|
-
});
|
|
2786
|
-
setupDatepicker(this, changeDateListener, this.inputs[0], cleanOptions);
|
|
2787
|
-
setupDatepicker(this, changeDateListener, this.inputs[1], cleanOptions);
|
|
2788
|
-
Object.freeze(datepickers);
|
|
2789
|
-
// normalize the range if inital dates are given
|
|
2790
|
-
if (datepickers[0].dates.length > 0) {
|
|
2791
|
-
onChangeDate(this, {target: this.inputs[0]});
|
|
2792
|
-
} else if (datepickers[1].dates.length > 0) {
|
|
2793
|
-
onChangeDate(this, {target: this.inputs[1]});
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
|
|
2797
|
-
/**
|
|
2798
|
-
* @type {Array} - selected date of the linked date pickers
|
|
2799
|
-
*/
|
|
2800
|
-
get dates() {
|
|
2801
|
-
return this.datepickers.length === 2
|
|
2802
|
-
? [
|
|
2803
|
-
this.datepickers[0].dates[0],
|
|
2804
|
-
this.datepickers[1].dates[0],
|
|
2805
|
-
]
|
|
2806
|
-
: undefined;
|
|
2807
|
-
}
|
|
2808
|
-
|
|
2809
|
-
/**
|
|
2810
|
-
* Set new values to the config options
|
|
2811
|
-
* @param {Object} options - config options to update
|
|
2812
|
-
*/
|
|
2813
|
-
setOptions(options) {
|
|
2814
|
-
this.allowOneSidedRange = !!options.allowOneSidedRange;
|
|
2815
|
-
|
|
2816
|
-
const cleanOptions = filterOptions(options);
|
|
2817
|
-
this.datepickers[0].setOptions(cleanOptions);
|
|
2818
|
-
this.datepickers[1].setOptions(cleanOptions);
|
|
2819
|
-
}
|
|
2820
|
-
|
|
2821
|
-
/**
|
|
2822
|
-
* Destroy the DateRangePicker instance
|
|
2823
|
-
* @return {DateRangePicker} - the instance destroyed
|
|
2824
|
-
*/
|
|
2825
|
-
destroy() {
|
|
2826
|
-
this.datepickers[0].destroy();
|
|
2827
|
-
this.datepickers[1].destroy();
|
|
2828
|
-
unregisterListeners(this);
|
|
2829
|
-
delete this.element.rangepicker;
|
|
2830
|
-
}
|
|
2831
|
-
|
|
2832
|
-
/**
|
|
2833
|
-
* Get the start and end dates of the date range
|
|
2834
|
-
*
|
|
2835
|
-
* The method returns Date objects by default. If format string is passed,
|
|
2836
|
-
* it returns date strings formatted in given format.
|
|
2837
|
-
* The result array always contains 2 items (start date/end date) and
|
|
2838
|
-
* undefined is used for unselected side. (e.g. If none is selected,
|
|
2839
|
-
* the result will be [undefined, undefined]. If only the end date is set
|
|
2840
|
-
* when allowOneSidedRange config option is true, [undefined, endDate] will
|
|
2841
|
-
* be returned.)
|
|
2842
|
-
*
|
|
2843
|
-
* @param {String} [format] - Format string to stringify the dates
|
|
2844
|
-
* @return {Array} - Start and end dates
|
|
2845
|
-
*/
|
|
2846
|
-
getDates(format = undefined) {
|
|
2847
|
-
const callback = format
|
|
2848
|
-
? date => formatDate(date, format, this.datepickers[0].config.locale)
|
|
2849
|
-
: date => new Date(date);
|
|
2850
|
-
|
|
2851
|
-
return this.dates.map(date => date === undefined ? date : callback(date));
|
|
2852
|
-
}
|
|
2853
|
-
|
|
2854
|
-
/**
|
|
2855
|
-
* Set the start and end dates of the date range
|
|
2856
|
-
*
|
|
2857
|
-
* The method calls datepicker.setDate() internally using each of the
|
|
2858
|
-
* arguments in start→end order.
|
|
2859
|
-
*
|
|
2860
|
-
* When a clear: true option object is passed instead of a date, the method
|
|
2861
|
-
* clears the date.
|
|
2862
|
-
*
|
|
2863
|
-
* If an invalid date, the same date as the current one or an option object
|
|
2864
|
-
* without clear: true is passed, the method considers that argument as an
|
|
2865
|
-
* "ineffective" argument because calling datepicker.setDate() with those
|
|
2866
|
-
* values makes no changes to the date selection.
|
|
2867
|
-
*
|
|
2868
|
-
* When the allowOneSidedRange config option is false, passing {clear: true}
|
|
2869
|
-
* to clear the range works only when it is done to the last effective
|
|
2870
|
-
* argument (in other words, passed to rangeEnd or to rangeStart along with
|
|
2871
|
-
* ineffective rangeEnd). This is because when the date range is changed,
|
|
2872
|
-
* it gets normalized based on the last change at the end of the changing
|
|
2873
|
-
* process.
|
|
2874
|
-
*
|
|
2875
|
-
* @param {Date|Number|String|Object} rangeStart - Start date of the range
|
|
2876
|
-
* or {clear: true} to clear the date
|
|
2877
|
-
* @param {Date|Number|String|Object} rangeEnd - End date of the range
|
|
2878
|
-
* or {clear: true} to clear the date
|
|
2879
|
-
*/
|
|
2880
|
-
setDates(rangeStart, rangeEnd) {
|
|
2881
|
-
const [datepicker0, datepicker1] = this.datepickers;
|
|
2882
|
-
const origDates = this.dates;
|
|
2883
|
-
|
|
2884
|
-
// If range normalization runs on every change, we can't set a new range
|
|
2885
|
-
// that starts after the end of the current range correctly because the
|
|
2886
|
-
// normalization process swaps start↔︎end right after setting the new start
|
|
2887
|
-
// date. To prevent this, the normalization process needs to run once after
|
|
2888
|
-
// both of the new dates are set.
|
|
2889
|
-
this._updating = true;
|
|
2890
|
-
datepicker0.setDate(rangeStart);
|
|
2891
|
-
datepicker1.setDate(rangeEnd);
|
|
2892
|
-
delete this._updating;
|
|
2893
|
-
|
|
2894
|
-
if (datepicker1.dates[0] !== origDates[1]) {
|
|
2895
|
-
onChangeDate(this, {target: this.inputs[1]});
|
|
2896
|
-
} else if (datepicker0.dates[0] !== origDates[0]) {
|
|
2897
|
-
onChangeDate(this, {target: this.inputs[0]});
|
|
2898
|
-
}
|
|
2899
|
-
}
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
const verdocsFieldDateCss = ".datepicker{display:none}.datepicker.active{display:block}.datepicker-dropdown{position:absolute;top:0;left:0;z-index:20;padding-top:4px}.datepicker-dropdown.datepicker-orient-top{padding-top:0;padding-bottom:4px}.datepicker-picker{display:inline-block;border-radius:4px;background-color:white}.datepicker-dropdown .datepicker-picker{-webkit-box-shadow:0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);box-shadow:0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1)}.datepicker-picker span{display:block;-ms-flex:1;flex:1;border:0;border-radius:4px;cursor:default;text-align:center;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.datepicker-main{padding:2px}.datepicker-footer{-webkit-box-shadow:inset 0 1px 1px rgba(10, 10, 10, 0.1);box-shadow:inset 0 1px 1px rgba(10, 10, 10, 0.1);background-color:whitesmoke}.datepicker-grid,.datepicker-view .days-of-week,.datepicker-view,.datepicker-controls{display:-ms-flexbox;display:flex}.datepicker-grid{-ms-flex-wrap:wrap;flex-wrap:wrap}.datepicker-view .days .datepicker-cell,.datepicker-view .dow{-ms-flex-preferred-size:14.2857142857%;flex-basis:14.2857142857%}.datepicker-view.datepicker-grid .datepicker-cell{-ms-flex-preferred-size:25%;flex-basis:25%}.datepicker-cell,.datepicker-view .week{height:2.25rem;line-height:2.25rem}.datepicker-title{-webkit-box-shadow:inset 0 -1px 1px rgba(10, 10, 10, 0.1);box-shadow:inset 0 -1px 1px rgba(10, 10, 10, 0.1);background-color:whitesmoke;padding:0.375rem 0.75rem;text-align:center;font-weight:700}.datepicker-header .datepicker-controls{padding:2px 2px 0}.datepicker-controls .button{display:-ms-inline-flexbox;display:inline-flex;position:relative;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;margin:0;border:1px solid #dbdbdb;border-radius:4px;-webkit-box-shadow:none;box-shadow:none;background-color:white;cursor:pointer;padding:calc(0.375em - 1px) 0.75em;height:2.25em;vertical-align:top;text-align:center;line-height:1.5;white-space:nowrap;color:#363636;font-size:1rem}.datepicker-controls .button:focus,.datepicker-controls .button:active{outline:none}.datepicker-controls .button:hover{border-color:#b5b5b5;color:#363636}.datepicker-controls .button:focus{border-color:#3273dc;color:#363636}.datepicker-controls .button:focus:not(:active){-webkit-box-shadow:0 0 0 0.125em rgba(50, 115, 220, 0.25);box-shadow:0 0 0 0.125em rgba(50, 115, 220, 0.25)}.datepicker-controls .button:active{border-color:#4a4a4a;color:#363636}.datepicker-controls .button[disabled]{cursor:not-allowed}.datepicker-header .datepicker-controls .button{border-color:transparent;font-weight:bold}.datepicker-header .datepicker-controls .button:hover{background-color:#f9f9f9}.datepicker-header .datepicker-controls .button:focus:not(:active){-webkit-box-shadow:0 0 0 0.125em rgba(255, 255, 255, 0.25);box-shadow:0 0 0 0.125em rgba(255, 255, 255, 0.25)}.datepicker-header .datepicker-controls .button:active{background-color:#f2f2f2}.datepicker-header .datepicker-controls .button[disabled]{-webkit-box-shadow:none;box-shadow:none}.datepicker-footer .datepicker-controls .button{margin:calc(0.375rem - 1px) 0.375rem;border-radius:2px;width:100%;font-size:0.75rem}.datepicker-controls .view-switch{-ms-flex:auto;flex:auto}.datepicker-controls .prev-btn,.datepicker-controls .next-btn{padding-right:0.375rem;padding-left:0.375rem;width:2.25rem}.datepicker-controls .prev-btn.disabled,.datepicker-controls .next-btn.disabled{visibility:hidden}.datepicker-view .dow{height:1.5rem;line-height:1.5rem;font-size:0.875rem;font-weight:700}.datepicker-view .week{width:2.25rem;color:#b5b5b5;font-size:0.75rem}@media (max-width: 22.5rem){.datepicker-view .week{width:1.96875rem}}.datepicker-grid{width:15.75rem}@media (max-width: 22.5rem){.calendar-weeks+.days .datepicker-grid{width:13.78125rem}}.datepicker-cell:not(.disabled):hover{background-color:#f9f9f9;cursor:pointer}.datepicker-cell.focused:not(.selected){background-color:#e8e8e8}.datepicker-cell.selected,.datepicker-cell.selected:hover{background-color:#3273dc;color:#fff;font-weight:600}.datepicker-cell.disabled{color:#dbdbdb}.datepicker-cell.prev:not(.disabled),.datepicker-cell.next:not(.disabled){color:#7a7a7a}.datepicker-cell.prev.selected,.datepicker-cell.next.selected{color:#e6e6e6}.datepicker-cell.highlighted:not(.selected):not(.range):not(.today){border-radius:0;background-color:whitesmoke}.datepicker-cell.highlighted:not(.selected):not(.range):not(.today):not(.disabled):hover{background-color:#eeeeee}.datepicker-cell.highlighted:not(.selected):not(.range):not(.today).focused{background-color:#e8e8e8}.datepicker-cell.today:not(.selected){background-color:#00d1b2}.datepicker-cell.today:not(.selected):not(.disabled){color:#fff}.datepicker-cell.today.focused:not(.selected){background-color:#00c4a7}.datepicker-cell.range-end:not(.selected),.datepicker-cell.range-start:not(.selected){background-color:#b5b5b5;color:#fff}.datepicker-cell.range-end.focused:not(.selected),.datepicker-cell.range-start.focused:not(.selected){background-color:#afafaf}.datepicker-cell.range-start{border-radius:4px 0 0 4px}.datepicker-cell.range-end{border-radius:0 4px 4px 0}.datepicker-cell.range{border-radius:0;background-color:#dbdbdb}.datepicker-cell.range:not(.disabled):not(.focused):not(.today):hover{background-color:#d5d5d5}.datepicker-cell.range.disabled{color:#c2c2c2}.datepicker-cell.range.focused{background-color:#cfcfcf}.datepicker-view.datepicker-grid .datepicker-cell{height:4.5rem;line-height:4.5rem}.datepicker-input.in-edit{border-color:#2366d1}.datepicker-input.in-edit:focus,.datepicker-input.in-edit:active{-webkit-box-shadow:0 0 0.25em 0.25em rgba(35, 102, 209, 0.2);box-shadow:0 0 0.25em 0.25em rgba(35, 102, 209, 0.2)}verdocs-field-date{font-family:sans-serif;font-family:var(--verdocs-font);width:64px;height:15px;display:block;font-size:11px;position:relative;letter-spacing:0.3px;background-color:transparent;-webkit-transform-origin:bottom left;transform-origin:bottom left}verdocs-field-date input{-webkit-box-sizing:border-box;box-sizing:border-box;color:rgba(0, 0, 0, 0.87);font-weight:500;-webkit-transform-origin:0 0;transform-origin:0 0;height:100%;width:100%;background:none;font-size:11px;border:1px solid #ccc;-webkit-appearance:none;-moz-appearance:none;appearance:none}verdocs-field-date input.hide{display:none}verdocs-field-date.required input{border:1px solid var(--verdocs-required-color)}verdocs-field-date.focused{-webkit-animation:verdocs-field-pulse 0.75s 2;animation:verdocs-field-pulse 0.75s 2}";
|
|
2903
|
-
|
|
2904
|
-
const VerdocsFieldDate = class {
|
|
2905
|
-
constructor(hostRef) {
|
|
2906
|
-
index.registerInstance(this, hostRef);
|
|
2907
|
-
this.fieldFocus = index.createEvent(this, "fieldFocus", 7);
|
|
2908
|
-
this.fieldBlur = index.createEvent(this, "fieldBlur", 7);
|
|
2909
|
-
this.fieldChange = index.createEvent(this, "fieldChange", 7);
|
|
2910
|
-
this.fieldInput = index.createEvent(this, "fieldInput", 7);
|
|
2911
|
-
/**
|
|
2912
|
-
* A placeholder to assist the user in completing the field.
|
|
2913
|
-
*/
|
|
2914
|
-
this.placeholder = 'Select Date';
|
|
2915
|
-
/**
|
|
2916
|
-
* Sets the tabIndex of the input element.
|
|
2917
|
-
*/
|
|
2918
|
-
this.order = 1;
|
|
2919
|
-
/**
|
|
2920
|
-
* Sets the value of the input element.
|
|
2921
|
-
*/
|
|
2922
|
-
this.value = '';
|
|
2923
|
-
/**
|
|
2924
|
-
* If true, the field will be marked required.
|
|
2925
|
-
*/
|
|
2926
|
-
this.required = false;
|
|
2927
|
-
/**
|
|
2928
|
-
* Sets the disabled attribute of the input element.
|
|
2929
|
-
*/
|
|
2930
|
-
this.disabled = false;
|
|
2931
|
-
this.focused = false;
|
|
2932
|
-
}
|
|
2933
|
-
async focusField() {
|
|
2934
|
-
this.focused = true;
|
|
2935
|
-
this.el.focus();
|
|
2936
|
-
this.fieldFocus.emit(true);
|
|
2937
|
-
}
|
|
2938
|
-
componentDidLoad() {
|
|
2939
|
-
new Datepicker(this.el, {
|
|
2940
|
-
autohide: true,
|
|
2941
|
-
todayHighlight: true,
|
|
2942
|
-
});
|
|
2943
|
-
this.el.addEventListener('changeDate', (e) => {
|
|
2944
|
-
console.log('changeDate', e.detail.date.toISOString());
|
|
2945
|
-
});
|
|
2946
|
-
}
|
|
2947
|
-
handleBlur() {
|
|
2948
|
-
this.focused = false;
|
|
2949
|
-
this.fieldBlur.emit(true);
|
|
2950
|
-
}
|
|
2951
|
-
handleFocus() {
|
|
2952
|
-
this.focused = true;
|
|
2953
|
-
this.fieldFocus.emit(true);
|
|
2954
|
-
}
|
|
2955
|
-
handleChange(e) {
|
|
2956
|
-
this.fieldChange.emit(e.target.value);
|
|
2957
|
-
}
|
|
2958
|
-
handleInput(e) {
|
|
2959
|
-
this.fieldInput.emit(e.target.value);
|
|
2960
|
-
}
|
|
2961
|
-
// NOTE: We don't use a "date" field here because browsers vary widely in their formatting of it.
|
|
2962
|
-
render() {
|
|
2963
|
-
return (index.h(index.Host, { class: { focused: this.focused, required: this.required, storybook: !!(window === null || window === void 0 ? void 0 : window['STORYBOOK_ENV']) } }, index.h("input", { type: "text", value: "", placeholder: this.placeholder, required: this.required, ref: el => (this.el = el), onBlur: () => this.handleBlur(), onFocus: () => this.handleFocus(), onChange: e => this.handleChange(e), onInput: e => this.handleInput(e) })));
|
|
2964
|
-
}
|
|
2965
|
-
};
|
|
2966
|
-
VerdocsFieldDate.style = verdocsFieldDateCss;
|
|
2967
|
-
|
|
2968
|
-
exports.verdocs_field_date = VerdocsFieldDate;
|