@schukai/monster 3.51.5 → 3.52.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +25 -0
- package/README.md +15 -12
- package/example/components/form/button.mjs +10 -0
- package/example/components/form/select.mjs +25 -0
- package/example/components/form/tree-select.mjs +27 -0
- package/example/components/host/host.mjs +0 -0
- package/example/components/notify/message.mjs +4 -0
- package/example/components/notify/notify.mjs +4 -0
- package/example/components/state/log.mjs +0 -0
- package/example/components/state/state.mjs +0 -0
- package/example/data/datasource/server/restapi.mjs +7 -1
- package/package.json +6 -2
- package/source/components/constants.mjs +132 -0
- package/source/components/datatable/columnbar.mjs +310 -0
- package/source/components/datatable/constants.mjs +121 -0
- package/source/components/datatable/dataset.mjs +219 -0
- package/source/components/datatable/datasource/dom.mjs +186 -0
- package/source/components/datatable/datasource/namespace.mjs +13 -0
- package/source/components/datatable/datasource/rest.mjs +400 -0
- package/source/components/datatable/datasource.mjs +102 -0
- package/source/components/datatable/datatable/header.mjs +268 -0
- package/source/components/datatable/datatable/namespace.mjs +13 -0
- package/source/components/datatable/datatable.mjs +789 -0
- package/source/components/datatable/embedded-pagination.mjs +113 -0
- package/source/components/datatable/filter/abstract-base.mjs +31 -0
- package/source/components/datatable/filter/date-range.mjs +1041 -0
- package/source/components/datatable/filter/input.mjs +175 -0
- package/source/components/datatable/filter/namespace.mjs +13 -0
- package/source/components/datatable/filter/range.mjs +671 -0
- package/source/components/datatable/filter/select.mjs +65 -0
- package/source/components/datatable/filter/settings.mjs +116 -0
- package/source/components/datatable/filter-button.mjs +98 -0
- package/source/components/datatable/filter.mjs +929 -0
- package/source/components/datatable/namespace.mjs +11 -0
- package/source/components/datatable/pagination.mjs +456 -0
- package/source/components/datatable/style/column-bar.pcss +123 -0
- package/source/components/datatable/style/dataset.pcss +13 -0
- package/source/components/datatable/style/datasource.pcss +16 -0
- package/source/components/datatable/style/datatable.pcss +239 -0
- package/source/components/datatable/style/embedded-pagination.pcss +101 -0
- package/source/components/datatable/style/filter-button.pcss +22 -0
- package/source/components/datatable/style/filter-controls-defaults.pcss +46 -0
- package/source/components/datatable/style/filter-date-range.pcss +9 -0
- package/source/components/datatable/style/filter-range.pcss +5 -0
- package/source/components/datatable/style/filter.pcss +156 -0
- package/source/components/datatable/style/pagination.pcss +59 -0
- package/source/components/datatable/style/select-filter.pcss +27 -0
- package/source/components/datatable/stylesheet/column-bar.mjs +27 -0
- package/source/components/datatable/stylesheet/dataset.mjs +27 -0
- package/source/components/datatable/stylesheet/datasource.mjs +27 -0
- package/source/components/datatable/stylesheet/datatable.mjs +27 -0
- package/source/components/datatable/stylesheet/embedded-pagination.mjs +27 -0
- package/source/components/datatable/stylesheet/filter-button.mjs +27 -0
- package/source/components/datatable/stylesheet/filter-controls-defaults.mjs +27 -0
- package/source/components/datatable/stylesheet/filter-date-range.mjs +27 -0
- package/source/components/datatable/stylesheet/filter-range.mjs +27 -0
- package/source/components/datatable/stylesheet/filter.mjs +27 -0
- package/source/components/datatable/stylesheet/namespace.mjs +13 -0
- package/source/components/datatable/stylesheet/pagination.mjs +27 -0
- package/source/components/datatable/stylesheet/select-filter.mjs +27 -0
- package/source/components/datatable/util.mjs +60 -0
- package/source/components/form/action-button.mjs +262 -0
- package/source/components/form/api-button.mjs +515 -0
- package/source/components/form/button-bar.mjs +739 -0
- package/source/components/form/button.mjs +350 -0
- package/source/components/form/confirm-button.mjs +330 -0
- package/source/components/form/constants.mjs +111 -0
- package/source/components/form/context-help.mjs +123 -0
- package/source/components/form/events.mjs +84 -0
- package/source/components/form/form.mjs +601 -0
- package/source/components/form/message-state-button.mjs +396 -0
- package/source/components/form/namespace.mjs +13 -0
- package/source/components/form/popper-button.mjs +435 -0
- package/source/components/form/popper.mjs +487 -0
- package/source/components/form/reload.mjs +360 -0
- package/source/components/form/select.mjs +2314 -0
- package/source/components/form/shadow-reload.mjs +137 -0
- package/source/components/form/state-button.mjs +182 -0
- package/source/components/form/style/action-button.pcss +41 -0
- package/source/components/form/style/api-button.pcss +0 -0
- package/source/components/form/style/button-bar.pcss +51 -0
- package/source/components/form/style/button.pcss +8 -0
- package/source/components/form/style/confirm-button.pcss +17 -0
- package/source/components/form/style/context-help.pcss +16 -0
- package/source/components/form/style/form.pcss +10 -0
- package/source/components/form/style/message-state-button.pcss +10 -0
- package/source/components/form/style/popper-button.pcss +16 -0
- package/source/components/form/style/popper.pcss +8 -0
- package/source/components/form/style/select.pcss +265 -0
- package/source/components/form/style/state-button.pcss +116 -0
- package/source/components/form/style/tabs.pcss +173 -0
- package/source/components/form/style/tree-select.pcss +81 -0
- package/source/components/form/stylesheet/action-button.mjs +27 -0
- package/source/components/form/stylesheet/api-button.mjs +27 -0
- package/source/components/form/stylesheet/button-bar.mjs +27 -0
- package/source/components/form/stylesheet/button.mjs +27 -0
- package/source/components/form/stylesheet/confirm-button.mjs +27 -0
- package/source/components/form/stylesheet/context-help.mjs +27 -0
- package/source/components/form/stylesheet/form.mjs +27 -0
- package/source/components/form/stylesheet/message-state-button.mjs +27 -0
- package/source/components/form/stylesheet/namespace.mjs +13 -0
- package/source/components/form/stylesheet/popper-button.mjs +27 -0
- package/source/components/form/stylesheet/popper.mjs +27 -0
- package/source/components/form/stylesheet/select.mjs +27 -0
- package/source/components/form/stylesheet/state-button.mjs +27 -0
- package/source/components/form/stylesheet/tabs.mjs +27 -0
- package/source/components/form/stylesheet/tree-select.mjs +27 -0
- package/source/components/form/tabs.mjs +1029 -0
- package/source/components/form/template.mjs +373 -0
- package/source/components/form/tree-select.mjs +527 -0
- package/source/components/form/types/namespace.mjs +13 -0
- package/source/components/form/types/state.mjs +93 -0
- package/source/components/form/util/fetch.mjs +133 -0
- package/source/components/form/util/floating-ui.mjs +245 -0
- package/source/components/form/util/namespace.mjs +13 -0
- package/source/components/form/util/popper.mjs +49 -0
- package/source/components/host/call-button.mjs +236 -0
- package/source/components/host/collapse.mjs +526 -0
- package/source/components/host/config-manager.mjs +304 -0
- package/source/components/host/constants.mjs +18 -0
- package/source/components/host/details.mjs +268 -0
- package/source/components/host/events.mjs +131 -0
- package/source/components/host/host.mjs +420 -0
- package/source/components/host/namespace.mjs +13 -0
- package/source/components/host/overlay.mjs +339 -0
- package/source/components/host/style/call-button.pcss +36 -0
- package/source/components/host/style/collapse.pcss +67 -0
- package/source/components/host/style/config-manager.pcss +5 -0
- package/source/components/host/style/details.pcss +68 -0
- package/source/components/host/style/host.pcss +43 -0
- package/source/components/host/style/overlay.pcss +73 -0
- package/source/components/host/style/toggle-button.pcss +36 -0
- package/source/components/host/style/viewer.pcss +13 -0
- package/source/components/host/stylesheet/call-button.mjs +27 -0
- package/source/components/host/stylesheet/collapse.mjs +27 -0
- package/source/components/host/stylesheet/config-manager.mjs +27 -0
- package/source/components/host/stylesheet/details.mjs +27 -0
- package/source/components/host/stylesheet/host.mjs +27 -0
- package/source/components/host/stylesheet/namespace.mjs +13 -0
- package/source/components/host/stylesheet/overlay.mjs +27 -0
- package/source/components/host/stylesheet/toggle-button.mjs +27 -0
- package/source/components/host/stylesheet/viewer.mjs +27 -0
- package/source/components/host/toggle-button.mjs +88 -0
- package/source/components/host/util.mjs +23 -0
- package/source/components/host/viewer.mjs +309 -0
- package/source/components/namespace.mjs +14 -0
- package/source/components/notify/constants.mjs +15 -0
- package/source/components/notify/events.mjs +15 -0
- package/source/components/notify/message.mjs +374 -0
- package/source/components/notify/namespace.mjs +15 -0
- package/source/components/notify/notify.mjs +236 -0
- package/source/components/notify/style/message.pcss +57 -0
- package/source/components/notify/style/notify.pcss +118 -0
- package/source/components/notify/stylesheet/message.mjs +27 -0
- package/source/components/notify/stylesheet/namespace.mjs +15 -0
- package/source/components/notify/stylesheet/notify.mjs +27 -0
- package/source/components/state/log/entry.mjs +126 -0
- package/source/components/state/log/namespace.mjs +13 -0
- package/source/components/state/log.mjs +275 -0
- package/source/components/state/namespace.mjs +13 -0
- package/source/components/state/state.mjs +131 -0
- package/source/components/state/style/log.pcss +111 -0
- package/source/components/state/style/state.pcss +113 -0
- package/source/components/state/stylesheet/log.mjs +27 -0
- package/source/components/state/stylesheet/state.mjs +27 -0
- package/source/components/style/badge.pcss +92 -0
- package/source/components/style/border.pcss +77 -0
- package/source/components/style/button.pcss +105 -0
- package/source/components/style/card.pcss +108 -0
- package/source/components/style/color.pcss +257 -0
- package/source/components/style/common.pcss +105 -0
- package/source/components/style/control.pcss +11 -0
- package/source/components/style/data-grid.pcss +43 -0
- package/source/components/style/display.pcss +42 -0
- package/source/components/style/floating-ui.pcss +33 -0
- package/source/components/style/form.pcss +5 -0
- package/source/components/style/host.pcss +15 -0
- package/source/components/style/link.pcss +63 -0
- package/source/components/style/mixin/badge.pcss +18 -0
- package/source/components/style/mixin/button.pcss +52 -0
- package/source/components/style/mixin/form.pcss +247 -0
- package/source/components/style/mixin/hover.pcss +8 -0
- package/source/components/style/mixin/media.pcss +107 -0
- package/source/components/style/mixin/property.pcss +292 -0
- package/source/components/style/mixin/skeleton.pcss +26 -0
- package/source/components/style/mixin/spinner.pcss +24 -0
- package/source/components/style/mixin/typography.pcss +52 -0
- package/source/components/style/normalize.pcss +14 -0
- package/source/components/style/popper.pcss +78 -0
- package/source/components/style/property.pcss +17 -0
- package/source/components/style/ripple.pcss +14 -0
- package/source/components/style/skeleton.pcss +28 -0
- package/source/components/style/space.pcss +47 -0
- package/source/components/style/spinner.pcss +6 -0
- package/source/components/style/table.pcss +46 -0
- package/source/components/style/theme.pcss +119 -0
- package/source/components/style/typography.pcss +131 -0
- package/source/components/stylesheet/badge.mjs +27 -0
- package/source/components/stylesheet/border.mjs +27 -0
- package/source/components/stylesheet/button.mjs +27 -0
- package/source/components/stylesheet/card.mjs +27 -0
- package/source/components/stylesheet/color.mjs +27 -0
- package/source/components/stylesheet/common.mjs +27 -0
- package/source/components/stylesheet/control.mjs +27 -0
- package/source/components/stylesheet/data-grid.mjs +27 -0
- package/source/components/stylesheet/display.mjs +27 -0
- package/source/components/stylesheet/floating-ui.mjs +27 -0
- package/source/components/stylesheet/form.mjs +27 -0
- package/source/components/stylesheet/host.mjs +27 -0
- package/source/components/stylesheet/link.mjs +27 -0
- package/source/components/stylesheet/namespace.mjs +13 -0
- package/source/components/stylesheet/normalize.mjs +27 -0
- package/source/components/stylesheet/popper.mjs +27 -0
- package/source/components/stylesheet/property.mjs +27 -0
- package/source/components/stylesheet/ripple.mjs +27 -0
- package/source/components/stylesheet/skeleton.mjs +27 -0
- package/source/components/stylesheet/space.mjs +27 -0
- package/source/components/stylesheet/spinner.mjs +27 -0
- package/source/components/stylesheet/table.mjs +27 -0
- package/source/components/stylesheet/theme.mjs +27 -0
- package/source/components/stylesheet/tree-menu.mjs +33 -0
- package/source/components/stylesheet/typography.mjs +27 -0
- package/source/components/tree-menu/namespace.mjs +13 -0
- package/source/components/tree-menu/style/tree-menu.pcss +107 -0
- package/source/components/tree-menu/stylesheet/namespace.mjs +13 -0
- package/source/components/tree-menu/stylesheet/tree-menu.mjs +27 -0
- package/source/components/tree-menu/tree-menu.mjs +660 -0
- package/source/constraints/abstract.mjs +17 -24
- package/source/constraints/abstractoperator.mjs +27 -22
- package/source/constraints/andoperator.mjs +20 -17
- package/source/constraints/invalid.mjs +17 -17
- package/source/constraints/isarray.mjs +20 -20
- package/source/constraints/isobject.mjs +20 -20
- package/source/constraints/oroperator.mjs +45 -45
- package/source/constraints/valid.mjs +17 -17
- package/source/data/buildmap.mjs +108 -103
- package/source/data/buildtree.mjs +59 -57
- package/source/data/datasource/dom.mjs +80 -84
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/data-fetch-error.mjs +27 -25
- package/source/data/datasource/server/restapi/writeerror.mjs +35 -32
- package/source/data/datasource/server/restapi.mjs +176 -177
- package/source/data/datasource/server/webconnect.mjs +150 -156
- package/source/data/datasource/server.mjs +62 -63
- package/source/data/datasource/storage/localstorage.mjs +25 -24
- package/source/data/datasource/storage/sessionstorage.mjs +28 -25
- package/source/data/datasource/storage.mjs +74 -73
- package/source/data/datasource.mjs +177 -168
- package/source/data/diff.mjs +98 -97
- package/source/data/extend.mjs +42 -42
- package/source/data/pathfinder.mjs +301 -288
- package/source/data/pipe.mjs +36 -36
- package/source/data/transformer.mjs +742 -726
- package/source/dom/assembler.mjs +44 -44
- package/source/dom/attributes.mjs +142 -122
- package/source/dom/constants.mjs +62 -58
- package/source/dom/customcontrol.mjs +299 -299
- package/source/dom/customelement.mjs +843 -806
- package/source/dom/dimension.mjs +56 -46
- package/source/dom/events.mjs +74 -69
- package/source/dom/focusmanager.mjs +175 -175
- package/source/dom/locale.mjs +28 -28
- package/source/dom/ready.mjs +13 -13
- package/source/dom/resource/data.mjs +117 -111
- package/source/dom/resource/link/stylesheet.mjs +16 -16
- package/source/dom/resource/link.mjs +94 -96
- package/source/dom/resource/script.mjs +72 -74
- package/source/dom/resource.mjs +174 -172
- package/source/dom/resourcemanager.mjs +152 -156
- package/source/dom/slotted.mjs +78 -80
- package/source/dom/template.mjs +126 -112
- package/source/dom/theme.mjs +35 -35
- package/source/dom/updater.mjs +673 -651
- package/source/dom/util/extract-keys.mjs +34 -22
- package/source/dom/util/init-options-from-attributes.mjs +46 -38
- package/source/dom/util/namespace.mjs +13 -0
- package/source/dom/util/set-option-from-attribute.mjs +35 -29
- package/source/dom/util.mjs +112 -81
- package/source/dom/worker/factory.mjs +83 -83
- package/source/i18n/formatter.mjs +75 -73
- package/source/i18n/locale.mjs +146 -144
- package/source/i18n/provider.mjs +70 -64
- package/source/i18n/providers/embed.mjs +136 -127
- package/source/i18n/providers/fetch.mjs +84 -76
- package/source/i18n/translations.mjs +205 -195
- package/source/logging/handler/console.mjs +36 -36
- package/source/logging/handler.mjs +140 -140
- package/source/logging/logentry.mjs +25 -25
- package/source/logging/logger.mjs +177 -175
- package/source/math/random.mjs +63 -59
- package/source/monster.mjs +223 -103
- package/source/net/webconnect/message.mjs +31 -31
- package/source/net/webconnect.mjs +278 -271
- package/source/text/bracketed-key-value-hash.mjs +182 -179
- package/source/text/formatter.mjs +235 -210
- package/source/text/generate-range-comparison-expression.mjs +56 -34
- package/source/text/namespace.mjs +1 -1
- package/source/types/base.mjs +69 -61
- package/source/types/basewithoptions.mjs +46 -46
- package/source/types/binary.mjs +20 -20
- package/source/types/dataurl.mjs +96 -90
- package/source/types/global.mjs +45 -39
- package/source/types/id.mjs +25 -25
- package/source/types/internal.mjs +115 -114
- package/source/types/is.mjs +56 -40
- package/source/types/mediatype.mjs +119 -119
- package/source/types/namespace.mjs +1 -1
- package/source/types/node.mjs +160 -150
- package/source/types/nodelist.mjs +94 -96
- package/source/types/noderecursiveiterator.mjs +50 -50
- package/source/types/observablequeue.mjs +73 -73
- package/source/types/observer.mjs +114 -106
- package/source/types/observerlist.mjs +66 -66
- package/source/types/proxyobserver.mjs +210 -210
- package/source/types/queue.mjs +63 -63
- package/source/types/randomid.mjs +13 -13
- package/source/types/regex.mjs +3 -1
- package/source/types/stack.mjs +64 -64
- package/source/types/tokenlist.mjs +206 -205
- package/source/types/typeof.mjs +12 -10
- package/source/types/uniquequeue.mjs +48 -48
- package/source/types/uuid.mjs +32 -32
- package/source/types/validate.mjs +67 -67
- package/source/types/version.mjs +115 -105
- package/source/util/clone.mjs +103 -91
- package/source/util/comparator.mjs +97 -97
- package/source/util/deadmansswitch.mjs +40 -44
- package/source/util/freeze.mjs +10 -9
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +104 -105
- package/source/util/runtime.mjs +56 -44
- package/source/util/trimspaces.mjs +24 -24
- package/test/cases/components/form/button.mjs +122 -0
- package/test/cases/components/form/confirm-button.mjs +127 -0
- package/test/cases/components/form/form.mjs +317 -0
- package/test/cases/components/form/reload.mjs +188 -0
- package/test/cases/components/form/select.mjs +229 -0
- package/test/cases/components/form/state-button.mjs +130 -0
- package/test/cases/components/form/tabs.mjs +98 -0
- package/test/cases/components/form/template.mjs +189 -0
- package/test/cases/components/form/tree-select.mjs +216 -0
- package/test/cases/components/host/details.mjs +68 -0
- package/test/cases/components/host/host.mjs +70 -0
- package/test/cases/components/host/overlay.mjs +60 -0
- package/test/cases/components/host/util.mjs +79 -0
- package/test/cases/components/notify/message.mjs +39 -0
- package/test/cases/components/notify/notify.mjs +89 -0
- package/test/cases/dom/customcontrol.mjs +5 -4
- package/test/cases/math/random.mjs +0 -1
- package/test/cases/monster.mjs +1 -1
- package/test/cases/net/webconnect/message.mjs +0 -1
- package/test/cases/types/node.mjs +1 -1
- package/test/util/chai-dom.mjs +2 -2
- package/test/util/intersection-mock.mjs +69 -0
- package/test/util/jsdom.mjs +41 -25
- package/test/util/localstorage.mjs +1 -0
- package/test/util/resize-observer.mjs +29 -0
- package/test/util/websocket.mjs +4 -1
- package/test/web/import.js +16 -1
- package/test/web/test.html +28 -5
- package/test/web/tests.js +30398 -17879
@@ -0,0 +1,1041 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2023 schukai GmbH
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0
|
4
|
+
*/
|
5
|
+
|
6
|
+
import { instanceSymbol } from "../../../constants.mjs";
|
7
|
+
import {
|
8
|
+
assembleMethodSymbol,
|
9
|
+
registerCustomElement,
|
10
|
+
} from "../../../dom/customelement.mjs";
|
11
|
+
import { FilterDateRangeStyleSheet } from "../stylesheet/filter-date-range.mjs";
|
12
|
+
import { FilterControlsDefaultsStyleSheet } from "../stylesheet/filter-controls-defaults.mjs";
|
13
|
+
import { AbstractBase } from "./abstract-base.mjs";
|
14
|
+
import { positionPopper } from "../../form/util/floating-ui.mjs";
|
15
|
+
import { ATTRIBUTE_ROLE } from "../../../dom/constants.mjs";
|
16
|
+
import { getDocument } from "../../../dom/util.mjs";
|
17
|
+
import { STYLE_DISPLAY_MODE_BLOCK } from "../constants.mjs";
|
18
|
+
import { DeadMansSwitch } from "../../../util/deadmansswitch.mjs";
|
19
|
+
import {
|
20
|
+
addAttributeToken,
|
21
|
+
removeAttributeToken,
|
22
|
+
} from "../../../dom/attributes.mjs";
|
23
|
+
import { findTargetElementFromEvent } from "../../../dom/events.mjs";
|
24
|
+
|
25
|
+
export { DateRange };
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @private
|
29
|
+
* @type {symbol}
|
30
|
+
*/
|
31
|
+
const timerCallbackSymbol = Symbol("timerCallback");
|
32
|
+
|
33
|
+
// /**
|
34
|
+
// * @private
|
35
|
+
// * @type {symbol}
|
36
|
+
// */
|
37
|
+
// const internalStateSymbol = Symbol("internalState");
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @private
|
41
|
+
* @type {symbol}
|
42
|
+
*/
|
43
|
+
const radioInputsElementSymbol = Symbol("radioInputsElement");
|
44
|
+
/**
|
45
|
+
* @private
|
46
|
+
* @type {symbol}
|
47
|
+
*/
|
48
|
+
const inputInputsElementSymbol = Symbol("inputInputsElement");
|
49
|
+
|
50
|
+
/**
|
51
|
+
* @private
|
52
|
+
* @type {symbol}
|
53
|
+
*/
|
54
|
+
const selectInputsElementSymbol = Symbol("selectInputsElement");
|
55
|
+
|
56
|
+
/**
|
57
|
+
* local symbol
|
58
|
+
* @private
|
59
|
+
* @type {symbol}
|
60
|
+
*/
|
61
|
+
const resizeObserverSymbol = Symbol("resizeObserver");
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @private
|
65
|
+
* @type {symbol}
|
66
|
+
*/
|
67
|
+
const controlElementSymbol = Symbol("controlElement");
|
68
|
+
|
69
|
+
/**
|
70
|
+
* local symbol
|
71
|
+
* @private
|
72
|
+
* @type {symbol}
|
73
|
+
*/
|
74
|
+
const closeEventHandler = Symbol("closeEventHandler");
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @private
|
78
|
+
* @type {symbol}
|
79
|
+
*/
|
80
|
+
const inputElementSymbol = Symbol("inputElement");
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @private
|
84
|
+
* @type {symbol}
|
85
|
+
*/
|
86
|
+
const formContainerElementSymbol = Symbol("formContainerElement");
|
87
|
+
|
88
|
+
/**
|
89
|
+
* local symbol
|
90
|
+
* @private
|
91
|
+
* @type {symbol}
|
92
|
+
*/
|
93
|
+
const popperElementSymbol = Symbol("popperElement");
|
94
|
+
|
95
|
+
/**
|
96
|
+
* local symbol
|
97
|
+
* @private
|
98
|
+
* @type {symbol}
|
99
|
+
*/
|
100
|
+
const arrowElementSymbol = Symbol("arrowElement");
|
101
|
+
|
102
|
+
/**
|
103
|
+
* The date-range filter control is used to filter a data set by a date range.
|
104
|
+
*
|
105
|
+
* <img src="./images/data-range.png">
|
106
|
+
*
|
107
|
+
* Dependencies: the system uses functions of the [monsterjs](https://monsterjs.org/) library
|
108
|
+
*
|
109
|
+
* You can create this control either by specifying the HTML tag <monster-filter-date-range />` directly in the HTML or using
|
110
|
+
* Javascript via the `document.createElement('monster-filter-date-range');` method.
|
111
|
+
*
|
112
|
+
* ```html
|
113
|
+
* <monster-filter-date-range></monster-filter-date-range>
|
114
|
+
* ```
|
115
|
+
*
|
116
|
+
* Or you can create this CustomControl directly in Javascript:
|
117
|
+
*
|
118
|
+
* ```js
|
119
|
+
* import '@schukai/component-datatable/source/filter/date-range.mjs';
|
120
|
+
* document.createElement('monster-filter-date-range');
|
121
|
+
* ```
|
122
|
+
*
|
123
|
+
* @startuml data-range.png
|
124
|
+
* skinparam monochrome true
|
125
|
+
* skinparam shadowing false
|
126
|
+
* HTMLElement <|-- CustomElement
|
127
|
+
* CustomElement <|-- AbstractBase
|
128
|
+
* AbstractBase <|-- DateRange
|
129
|
+
* @enduml
|
130
|
+
*
|
131
|
+
* @copyright schukai GmbH
|
132
|
+
* @memberOf Monster.Components.Datatable.Filter
|
133
|
+
* @summary A date range filter control
|
134
|
+
*/
|
135
|
+
class DateRange extends AbstractBase {
|
136
|
+
// constructor() {
|
137
|
+
// super();
|
138
|
+
// this[internalStateSymbol] = {}
|
139
|
+
// }
|
140
|
+
|
141
|
+
/**
|
142
|
+
* This method is called by the `instanceof` operator.
|
143
|
+
* @returns {symbol}
|
144
|
+
*/
|
145
|
+
static get [instanceSymbol]() {
|
146
|
+
return Symbol.for(
|
147
|
+
"@schukai/monster/components/filter/date-range@@instance",
|
148
|
+
);
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
*
|
153
|
+
* @return {FilterButton}
|
154
|
+
*/
|
155
|
+
[assembleMethodSymbol]() {;
|
156
|
+
super[assembleMethodSymbol]();
|
157
|
+
|
158
|
+
initControlReferences.call(this);
|
159
|
+
initEventHandler.call(this);
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* This is a method of [internal api](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
|
164
|
+
*
|
165
|
+
* @param {*} value
|
166
|
+
*/
|
167
|
+
set value(value) {
|
168
|
+
this[inputElementSymbol].value = value;
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* @returns {*}
|
173
|
+
*/
|
174
|
+
get value() {
|
175
|
+
return this[inputElementSymbol].value;
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* To set the options via the html tag the attribute `data-monster-options` must be used.
|
180
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
181
|
+
*
|
182
|
+
* The individual configuration values can be found in the table.
|
183
|
+
*
|
184
|
+
* @returns {Object}
|
185
|
+
*
|
186
|
+
* @property {Object} templates
|
187
|
+
* @property {string} templates.main
|
188
|
+
* @property {Object} labels
|
189
|
+
* @property {Object} features
|
190
|
+
* @property {boolean} features.moreThan
|
191
|
+
* @property {boolean} features.within
|
192
|
+
* @property {boolean} features.today
|
193
|
+
*/
|
194
|
+
get defaults() {
|
195
|
+
const d = Object.assign({}, super.defaults, {
|
196
|
+
templates: {
|
197
|
+
main: getTemplate(),
|
198
|
+
},
|
199
|
+
|
200
|
+
labels: {
|
201
|
+
singleValue: "Value",
|
202
|
+
fromValue: "From",
|
203
|
+
toValue: "To",
|
204
|
+
rangeFrom: "From",
|
205
|
+
rangeTo: "To",
|
206
|
+
todayValue: "Today",
|
207
|
+
withinValue: "Within",
|
208
|
+
months: "Months",
|
209
|
+
days: "Days",
|
210
|
+
years: "Years",
|
211
|
+
weeks: "Weeks",
|
212
|
+
moreThanValue: "More than",
|
213
|
+
},
|
214
|
+
|
215
|
+
features: {
|
216
|
+
moreThan: true,
|
217
|
+
within: true,
|
218
|
+
today: true,
|
219
|
+
},
|
220
|
+
|
221
|
+
popper: {
|
222
|
+
placement: "bottom",
|
223
|
+
middleware: ["flip", "offset:1"],
|
224
|
+
},
|
225
|
+
});
|
226
|
+
|
227
|
+
return initOptionsFromArguments.call(this, d);
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
*
|
232
|
+
* @return {CSSStyleSheet[]}
|
233
|
+
*/
|
234
|
+
static getCSSStyleSheet() {
|
235
|
+
return [FilterControlsDefaultsStyleSheet, FilterDateRangeStyleSheet];
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
*
|
240
|
+
* @return {string}
|
241
|
+
*/
|
242
|
+
static getTag() {
|
243
|
+
return "monster-filter-date-range";
|
244
|
+
}
|
245
|
+
|
246
|
+
/**
|
247
|
+
* @return {void}
|
248
|
+
*/
|
249
|
+
connectedCallback() {
|
250
|
+
super.connectedCallback();
|
251
|
+
|
252
|
+
const document = getDocument();;
|
253
|
+
|
254
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
255
|
+
// close on outside ui-events
|
256
|
+
document.addEventListener(type, this[closeEventHandler]);
|
257
|
+
}
|
258
|
+
|
259
|
+
updatePopper.call(this);
|
260
|
+
attachResizeObserver.call(this);
|
261
|
+
}
|
262
|
+
|
263
|
+
/**
|
264
|
+
* @return {void}
|
265
|
+
*/
|
266
|
+
disconnectedCallback() {
|
267
|
+
super.disconnectedCallback();
|
268
|
+
|
269
|
+
// close on outside ui-events
|
270
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
271
|
+
document.removeEventListener(type, this[closeEventHandler]);
|
272
|
+
}
|
273
|
+
|
274
|
+
disconnectResizeObserver.call(this);
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
*
|
279
|
+
* @return {Monster.Datatable.Filter.Range}
|
280
|
+
*/
|
281
|
+
showDialog() {
|
282
|
+
show.call(this);
|
283
|
+
return this;
|
284
|
+
}
|
285
|
+
|
286
|
+
/**
|
287
|
+
*
|
288
|
+
* @return {Monster.Datatable.Filter.Range}
|
289
|
+
*/
|
290
|
+
hideDialog() {
|
291
|
+
hide.call(this);
|
292
|
+
return this;
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
*
|
297
|
+
* @return {Monster.Datatable.Filter.Range}
|
298
|
+
*/
|
299
|
+
toggleDialog() {
|
300
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
301
|
+
this.hideDialog();
|
302
|
+
} else {
|
303
|
+
this.showDialog();
|
304
|
+
}
|
305
|
+
return this;
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
/**
|
310
|
+
*
|
311
|
+
* @param {HTMLElement} group
|
312
|
+
* @param {string} type
|
313
|
+
*/
|
314
|
+
function updateMainFilterValueFromPopperChange(group, type) {;
|
315
|
+
|
316
|
+
function calculateTargetDate(diff) {
|
317
|
+
if (isNaN(diff)) {
|
318
|
+
diff = 0;
|
319
|
+
}
|
320
|
+
const currentDate = new Date();
|
321
|
+
currentDate.setDate(currentDate.getDate() + diff);
|
322
|
+
return currentDate.toISOString().slice(0, 10);
|
323
|
+
}
|
324
|
+
|
325
|
+
if (type === "single") {
|
326
|
+
this[inputElementSymbol].value =
|
327
|
+
group.querySelector("input[type=date]").value;
|
328
|
+
} else if (type === "from") {
|
329
|
+
this[inputElementSymbol].value =
|
330
|
+
group.querySelector("input[type=date]").value + "-";
|
331
|
+
} else if (type === "to") {
|
332
|
+
this[inputElementSymbol].value =
|
333
|
+
"-" + group.querySelector("input[type=date]").value;
|
334
|
+
} else if (type === "from-to") {
|
335
|
+
// this option contain two input fields, we check which one was changed and read the other one
|
336
|
+
// the other field is in the same form group, for simplification we get both controls from the group here
|
337
|
+
const group = this[formContainerElementSymbol].querySelectorAll(
|
338
|
+
"input[type=radio][value=" + type + "] ~ input[type=date]",
|
339
|
+
);
|
340
|
+
let from = group[0].value;
|
341
|
+
|
342
|
+
if (from === "" || from === null || from < 0) {
|
343
|
+
from = 0;
|
344
|
+
}
|
345
|
+
|
346
|
+
let to = group[1].value;
|
347
|
+
if (to === "" || to === null || to < 0) {
|
348
|
+
to = 0;
|
349
|
+
}
|
350
|
+
|
351
|
+
let range;
|
352
|
+
if (from === 0 && to === 0) {
|
353
|
+
range = "";
|
354
|
+
} else if (from === 0) {
|
355
|
+
range = "-" + to;
|
356
|
+
} else if (to === 0) {
|
357
|
+
range = from + "-";
|
358
|
+
} else if (from === to) {
|
359
|
+
range = from;
|
360
|
+
} else {
|
361
|
+
range = from + "-" + to;
|
362
|
+
}
|
363
|
+
|
364
|
+
this[inputElementSymbol].value = range;
|
365
|
+
} else if (type === "today") {
|
366
|
+
this[inputElementSymbol].value = new Date().toISOString().slice(0, 10);
|
367
|
+
} else if (type === "within" || type === "more-than") {
|
368
|
+
const diffValue = parseInt(group.querySelector("input[type=number]").value);
|
369
|
+
const duration = group.querySelector("select").value;
|
370
|
+
|
371
|
+
let diffInDays;
|
372
|
+
switch (duration) {
|
373
|
+
case "days":
|
374
|
+
diffInDays = diffValue;
|
375
|
+
break;
|
376
|
+
case "weeks":
|
377
|
+
diffInDays = diffValue * 7;
|
378
|
+
break;
|
379
|
+
case "months":
|
380
|
+
diffInDays = diffValue * 30;
|
381
|
+
break;
|
382
|
+
case "years":
|
383
|
+
diffInDays = diffValue * 365;
|
384
|
+
break;
|
385
|
+
default:
|
386
|
+
diffInDays = 0;
|
387
|
+
}
|
388
|
+
|
389
|
+
if (diffInDays === 0) {
|
390
|
+
this[inputElementSymbol].value = "";
|
391
|
+
return;
|
392
|
+
}
|
393
|
+
|
394
|
+
const suffix = type !== "within" ? "" : "-";
|
395
|
+
const prefix = type !== "within" ? "-" : "";
|
396
|
+
|
397
|
+
this[inputElementSymbol].value =
|
398
|
+
suffix +
|
399
|
+
calculateTargetDate(type === "within" ? diffInDays : -diffInDays) +
|
400
|
+
prefix;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
|
404
|
+
/**
|
405
|
+
* @private
|
406
|
+
* @return {initEventHandler}
|
407
|
+
*/
|
408
|
+
function initEventHandler() {;
|
409
|
+
|
410
|
+
this[closeEventHandler] = (event) => {
|
411
|
+
const path = event.composedPath();
|
412
|
+
|
413
|
+
for (const [, element] of Object.entries(path)) {
|
414
|
+
if (element === this) {
|
415
|
+
return;
|
416
|
+
}
|
417
|
+
}
|
418
|
+
hide.call(this);
|
419
|
+
};
|
420
|
+
|
421
|
+
this[inputElementSymbol].addEventListener("click", () => {
|
422
|
+
this.toggleDialog();
|
423
|
+
});
|
424
|
+
|
425
|
+
this[formContainerElementSymbol].addEventListener("click", (event) => {
|
426
|
+
const element = findTargetElementFromEvent(
|
427
|
+
event,
|
428
|
+
"data-monster-role",
|
429
|
+
"range-type",
|
430
|
+
);
|
431
|
+
if (!element) {
|
432
|
+
return;
|
433
|
+
}
|
434
|
+
|
435
|
+
const type = element.getAttribute("data-monster-range-type");
|
436
|
+
const radio = this[formContainerElementSymbol].querySelector(
|
437
|
+
"input[type=radio][value=" + type + "]",
|
438
|
+
);
|
439
|
+
if (!radio) {
|
440
|
+
return;
|
441
|
+
}
|
442
|
+
|
443
|
+
radio.checked = true;
|
444
|
+
|
445
|
+
if (type === "today") {
|
446
|
+
this[inputElementSymbol].value = new Date().toISOString().slice(0, 10);
|
447
|
+
return;
|
448
|
+
}
|
449
|
+
|
450
|
+
// enable input from this group and disable the other
|
451
|
+
const group = this[formContainerElementSymbol].querySelectorAll(
|
452
|
+
"input[type=radio][value=" +
|
453
|
+
type +
|
454
|
+
"] ~ input, input[type=radio][value=" +
|
455
|
+
type +
|
456
|
+
"] ~ select",
|
457
|
+
);
|
458
|
+
for (const [, element] of Object.entries(group)) {
|
459
|
+
element.disabled = false;
|
460
|
+
}
|
461
|
+
|
462
|
+
const otherGroup = this[formContainerElementSymbol].querySelectorAll(
|
463
|
+
"input[type=radio]:not([value=" +
|
464
|
+
type +
|
465
|
+
"]) ~ input, input[type=radio]:not([value=" +
|
466
|
+
type +
|
467
|
+
"]) ~ select",
|
468
|
+
);
|
469
|
+
for (const [, element] of Object.entries(otherGroup)) {
|
470
|
+
element.disabled = true;
|
471
|
+
}
|
472
|
+
});
|
473
|
+
|
474
|
+
// change the input value if the user change the value of the radio button
|
475
|
+
this[inputElementSymbol].addEventListener("change", (event) => {
|
476
|
+
setTimeout(() => {
|
477
|
+
updatePopperInputsFromMainValue.call(this);
|
478
|
+
}, 0);
|
479
|
+
});
|
480
|
+
|
481
|
+
// if the user change the value of on of the input fields, we should update the value of the input field
|
482
|
+
this[formContainerElementSymbol].addEventListener("change", (event) => {
|
483
|
+
const element = findTargetElementFromEvent(
|
484
|
+
event,
|
485
|
+
"data-monster-watch",
|
486
|
+
"true",
|
487
|
+
);
|
488
|
+
if (!element) {
|
489
|
+
return;
|
490
|
+
}
|
491
|
+
|
492
|
+
const group = findTargetElementFromEvent(
|
493
|
+
event,
|
494
|
+
"data-monster-role",
|
495
|
+
"range-type",
|
496
|
+
);
|
497
|
+
if (!group) {
|
498
|
+
return;
|
499
|
+
}
|
500
|
+
|
501
|
+
const type = group.getAttribute("data-monster-range-type");
|
502
|
+
updateMainFilterValueFromPopperChange.call(this, group, type);
|
503
|
+
});
|
504
|
+
|
505
|
+
this.addEventListener("keydown", (event) => {
|
506
|
+
// if key code esc than hide dialog
|
507
|
+
if (event.key === "Escape") {
|
508
|
+
hide.call(this);
|
509
|
+
|
510
|
+
setTimeout(() => {
|
511
|
+
this[inputElementSymbol].focus();
|
512
|
+
}, 10);
|
513
|
+
|
514
|
+
return;
|
515
|
+
}
|
516
|
+
|
517
|
+
const input = findTargetElementFromEvent(
|
518
|
+
event,
|
519
|
+
"data-monster-role",
|
520
|
+
"input",
|
521
|
+
);
|
522
|
+
|
523
|
+
if (!input) {
|
524
|
+
return;
|
525
|
+
}
|
526
|
+
|
527
|
+
// key code down should activate first radio with name="singleValue"
|
528
|
+
if (event.key === "ArrowDown") {
|
529
|
+
show.call(this);
|
530
|
+
}
|
531
|
+
});
|
532
|
+
|
533
|
+
return this;
|
534
|
+
}
|
535
|
+
|
536
|
+
/**
|
537
|
+
* @private
|
538
|
+
*/
|
539
|
+
function attachResizeObserver() {;
|
540
|
+
|
541
|
+
// against flickering
|
542
|
+
this[resizeObserverSymbol] = new ResizeObserver((entries) => {
|
543
|
+
if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
|
544
|
+
try {
|
545
|
+
this[timerCallbackSymbol].touch();
|
546
|
+
return;
|
547
|
+
} catch (e) {
|
548
|
+
delete this[timerCallbackSymbol];
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
|
553
|
+
updatePopper.call(this);
|
554
|
+
});
|
555
|
+
});
|
556
|
+
|
557
|
+
this[resizeObserverSymbol].observe(this.parentElement);
|
558
|
+
}
|
559
|
+
|
560
|
+
function disconnectResizeObserver() {;
|
561
|
+
if (this[resizeObserverSymbol] instanceof ResizeObserver) {
|
562
|
+
this[resizeObserverSymbol].disconnect();
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
/**
|
567
|
+
* @private
|
568
|
+
*/
|
569
|
+
function hide() {;
|
570
|
+
|
571
|
+
this[popperElementSymbol].style.display = "none";
|
572
|
+
removeAttributeToken(this[controlElementSymbol], "class", "open");
|
573
|
+
}
|
574
|
+
|
575
|
+
/**
|
576
|
+
* @private
|
577
|
+
* @this PopperButton
|
578
|
+
*/
|
579
|
+
function show() {;
|
580
|
+
|
581
|
+
if (this.getOption("disabled", false) === true) {
|
582
|
+
return;
|
583
|
+
}
|
584
|
+
|
585
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
586
|
+
return;
|
587
|
+
}
|
588
|
+
|
589
|
+
this[popperElementSymbol].style.visibility = "hidden";
|
590
|
+
this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
|
591
|
+
|
592
|
+
addAttributeToken(this[controlElementSymbol], "class", "open");
|
593
|
+
|
594
|
+
// if value is "" than we should clear the form
|
595
|
+
if (this[inputElementSymbol].value === "") {
|
596
|
+
clearAndDisableFormGroups.call(this);
|
597
|
+
}
|
598
|
+
|
599
|
+
setTimeout(() => {
|
600
|
+
updatePopperInputsFromMainValue.call(this);
|
601
|
+
updatePopper.call(this);
|
602
|
+
}, 0);
|
603
|
+
}
|
604
|
+
|
605
|
+
/**
|
606
|
+
* @private
|
607
|
+
*/
|
608
|
+
function clearAndDisableFormGroups() {;
|
609
|
+
|
610
|
+
this[radioInputsElementSymbol].forEach((radio) => {
|
611
|
+
radio.checked = false;
|
612
|
+
});
|
613
|
+
|
614
|
+
this[inputInputsElementSymbol].forEach((input) => {
|
615
|
+
input.value = "";
|
616
|
+
input.disabled = true;
|
617
|
+
});
|
618
|
+
|
619
|
+
this[selectInputsElementSymbol].forEach((select) => {
|
620
|
+
select.value = "";
|
621
|
+
select.disabled = true;
|
622
|
+
});
|
623
|
+
}
|
624
|
+
|
625
|
+
/**
|
626
|
+
* @private
|
627
|
+
* @returns {string}
|
628
|
+
*/
|
629
|
+
function guessRangeTypeFromCurrentValue() {;
|
630
|
+
|
631
|
+
const value = this[inputElementSymbol].value.trim();
|
632
|
+
|
633
|
+
if (value === "") {
|
634
|
+
return "empty";
|
635
|
+
}
|
636
|
+
|
637
|
+
const singleDateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
638
|
+
const fromDateRegex = /^\d{4}-\d{2}-\d{2}-$/;
|
639
|
+
const toDateRegex = /^-\d{4}-\d{2}-\d{2}$/;
|
640
|
+
const fromToDateRegex = /^\d{4}-\d{2}-\d{2}-\d{4}-\d{2}-\d{2}$/;
|
641
|
+
|
642
|
+
if (singleDateRegex.test(value)) {
|
643
|
+
return "single";
|
644
|
+
}
|
645
|
+
|
646
|
+
if (fromToDateRegex.test(value)) {
|
647
|
+
return "from-to";
|
648
|
+
}
|
649
|
+
|
650
|
+
if (fromDateRegex.test(value)) {
|
651
|
+
return "from";
|
652
|
+
}
|
653
|
+
|
654
|
+
if (toDateRegex.test(value)) {
|
655
|
+
return "to";
|
656
|
+
}
|
657
|
+
|
658
|
+
return "invalid";
|
659
|
+
}
|
660
|
+
|
661
|
+
function getRangeTypeFromForm() {;
|
662
|
+
|
663
|
+
const group = this[formContainerElementSymbol].querySelector(
|
664
|
+
"input[type=radio][name=rangeType]:checked",
|
665
|
+
);
|
666
|
+
if (!group) {
|
667
|
+
return;
|
668
|
+
}
|
669
|
+
|
670
|
+
return group.value;
|
671
|
+
}
|
672
|
+
|
673
|
+
/**
|
674
|
+
* function, that calculates starting from a date a range of days, months, weeks or years
|
675
|
+
*
|
676
|
+
* @example
|
677
|
+
*
|
678
|
+
* // if today is 2020-10-12
|
679
|
+
* calculateDateRangeFromToday("2020-10-12", "days") // 0
|
680
|
+
* calculateDateRangeFromToday("2020-10-13", "days") // 1
|
681
|
+
* calculateDateRangeFromToday("2020-12-14", "days") // 63
|
682
|
+
* calculateDateRangeFromToday("2020-10-12", "months") // 0
|
683
|
+
* calculateDateRangeFromToday("2020-11-12", "months") // 1
|
684
|
+
* calculateDateRangeFromToday("2021-10-12", "months") // 11
|
685
|
+
*
|
686
|
+
* @param {string} date
|
687
|
+
* @param {string} unit (day, month, year, week)
|
688
|
+
* @returns {number} range
|
689
|
+
*/
|
690
|
+
function calculateDateRangeFromToday(date, unit) {
|
691
|
+
// calculate the date of today -1
|
692
|
+
const yesterday = new Date();
|
693
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
694
|
+
|
695
|
+
const dateAsObj = new Date(date);
|
696
|
+
|
697
|
+
const diff = dateAsObj.getTime() - yesterday.getTime();
|
698
|
+
|
699
|
+
// return the rages in days, months, years or weeks
|
700
|
+
switch (unit) {
|
701
|
+
case "days":
|
702
|
+
return Math.floor(diff / (1000 * 60 * 60 * 24));
|
703
|
+
case "months":
|
704
|
+
return Math.floor(diff / (1000 * 60 * 60 * 24 * 30));
|
705
|
+
case "years":
|
706
|
+
return Math.floor(diff / (1000 * 60 * 60 * 24 * 365));
|
707
|
+
case "weeks":
|
708
|
+
return Math.floor(diff / (1000 * 60 * 60 * 24 * 7));
|
709
|
+
}
|
710
|
+
|
711
|
+
return 0;
|
712
|
+
}
|
713
|
+
|
714
|
+
/**
|
715
|
+
* @private
|
716
|
+
*/
|
717
|
+
function updatePopperInputsFromMainValue() {;
|
718
|
+
|
719
|
+
const featuresMoreThan = this.getOption("features.moreThan", false);
|
720
|
+
const featuresWithin = this.getOption("features.within", false);
|
721
|
+
|
722
|
+
let guessedValueType = guessRangeTypeFromCurrentValue.call(this);
|
723
|
+
if (
|
724
|
+
!guessedValueType ||
|
725
|
+
guessedValueType === "empty" ||
|
726
|
+
guessedValueType === "invalid"
|
727
|
+
) {
|
728
|
+
return;
|
729
|
+
}
|
730
|
+
|
731
|
+
const rangeType = getRangeTypeFromForm.call(this);
|
732
|
+
if (guessedValueType === rangeType) {
|
733
|
+
return;
|
734
|
+
}
|
735
|
+
|
736
|
+
let lastRangeUnit = "days";
|
737
|
+
|
738
|
+
// check if type from form is within and current type is to
|
739
|
+
// if so, then do not update the form
|
740
|
+
if (
|
741
|
+
guessedValueType === "to" &&
|
742
|
+
rangeType === "within" &&
|
743
|
+
featuresWithin === true
|
744
|
+
) {
|
745
|
+
guessedValueType = "within";
|
746
|
+
lastRangeUnit = this[formContainerElementSymbol].querySelector(
|
747
|
+
`input[name=rangeType][value=within] ~ select[name=withinValueUnit]`,
|
748
|
+
).value;
|
749
|
+
}
|
750
|
+
|
751
|
+
// check if type from form is more than and current type is to
|
752
|
+
// if so, then do not update the form
|
753
|
+
if (
|
754
|
+
guessedValueType === "from" &&
|
755
|
+
rangeType === "more-than" &&
|
756
|
+
featuresMoreThan === true
|
757
|
+
) {
|
758
|
+
return;
|
759
|
+
}
|
760
|
+
|
761
|
+
clearAndDisableFormGroups.call(this);
|
762
|
+
|
763
|
+
let radio = this[formContainerElementSymbol].querySelector(
|
764
|
+
`input[name=rangeType][value=${guessedValueType}]`,
|
765
|
+
);
|
766
|
+
let input;
|
767
|
+
let select;
|
768
|
+
|
769
|
+
switch (guessedValueType) {
|
770
|
+
case "within":
|
771
|
+
radio.checked = true;
|
772
|
+
input = this[formContainerElementSymbol].querySelector(
|
773
|
+
`input[name=rangeType][value=within] ~ input[name=withinValue]`,
|
774
|
+
);
|
775
|
+
select = this[formContainerElementSymbol].querySelector(
|
776
|
+
`input[name=rangeType][value=within] ~ select[name=withinValueUnit]`,
|
777
|
+
);
|
778
|
+
|
779
|
+
input.disabled = false;
|
780
|
+
select.disabled = false;
|
781
|
+
|
782
|
+
const d1 = this[inputElementSymbol].value.substring(1);
|
783
|
+
const range1 = calculateDateRangeFromToday(d1, lastRangeUnit);
|
784
|
+
select.value = lastRangeUnit;
|
785
|
+
input.value = range1;
|
786
|
+
break;
|
787
|
+
|
788
|
+
case "more-than":
|
789
|
+
radio.checked = true;
|
790
|
+
input = this[formContainerElementSymbol].querySelector(
|
791
|
+
`input[name=rangeType][value=more-than] ~ input[name=moreThanValue]`,
|
792
|
+
);
|
793
|
+
select = this[formContainerElementSymbol].querySelector(
|
794
|
+
`input[name=rangeType][value=more-than] ~ select[name=moreThanValueUnit]`,
|
795
|
+
);
|
796
|
+
|
797
|
+
input.disabled = false;
|
798
|
+
select.disabled = false;
|
799
|
+
|
800
|
+
const d2 = this[inputElementSymbol].value.substring(0, 10);
|
801
|
+
const range2 = calculateDateRangeFromToday(d2, lastRangeUnit);
|
802
|
+
select.value = lastRangeUnit;
|
803
|
+
input.value = range2;
|
804
|
+
break;
|
805
|
+
|
806
|
+
case "single":
|
807
|
+
// check if the date is today
|
808
|
+
const today = new Date();
|
809
|
+
const date = new Date(this[inputElementSymbol].value);
|
810
|
+
|
811
|
+
const featuresToday = this.getOption("features.today", false);
|
812
|
+
|
813
|
+
if (
|
814
|
+
featuresToday &&
|
815
|
+
today.getFullYear() === date.getFullYear() &&
|
816
|
+
today.getMonth() === date.getMonth() &&
|
817
|
+
today.getDate() === date.getDate()
|
818
|
+
) {
|
819
|
+
radio = this[formContainerElementSymbol].querySelector(
|
820
|
+
`input[name=rangeType][value=today]`,
|
821
|
+
);
|
822
|
+
input = this[formContainerElementSymbol].querySelector(
|
823
|
+
`input[name=rangeType][value=today] ~ input[name=todayValue]`,
|
824
|
+
);
|
825
|
+
} else {
|
826
|
+
input = this[formContainerElementSymbol].querySelector(
|
827
|
+
`input[name=rangeType][value=single] ~ input[name=singleValue]`,
|
828
|
+
);
|
829
|
+
input.disabled = false;
|
830
|
+
}
|
831
|
+
|
832
|
+
radio.checked = true;
|
833
|
+
input.value = this[inputElementSymbol].value;
|
834
|
+
|
835
|
+
break;
|
836
|
+
case "from":
|
837
|
+
radio.checked = true;
|
838
|
+
const fromInput = this[formContainerElementSymbol].querySelector(
|
839
|
+
`input[name=rangeType][value=from] ~ input[name=fromValue]`,
|
840
|
+
);
|
841
|
+
// the input value has an - suffix
|
842
|
+
fromInput.value = this[inputElementSymbol].value.substring(
|
843
|
+
0,
|
844
|
+
this[inputElementSymbol].value.length - 1,
|
845
|
+
);
|
846
|
+
fromInput.disabled = false;
|
847
|
+
|
848
|
+
break;
|
849
|
+
case "to":
|
850
|
+
radio.checked = true;
|
851
|
+
const toInput = this[formContainerElementSymbol].querySelector(
|
852
|
+
`input[name=rangeType][value=to] ~ input[name=toValue]`,
|
853
|
+
);
|
854
|
+
// the input value has an - prefix
|
855
|
+
toInput.value = this[inputElementSymbol].value.substring(1);
|
856
|
+
toInput.disabled = false;
|
857
|
+
|
858
|
+
break;
|
859
|
+
|
860
|
+
case "from-to":
|
861
|
+
radio.checked = true;
|
862
|
+
const fromToInput = this[formContainerElementSymbol].querySelector(
|
863
|
+
`input[name=rangeType][value=from-to] ~ input[name=fromValue]`,
|
864
|
+
);
|
865
|
+
const toToInput = this[formContainerElementSymbol].querySelector(
|
866
|
+
`input[name=rangeType][value=from-to] ~ input[name=toValue]`,
|
867
|
+
);
|
868
|
+
|
869
|
+
const fromToRegexWithNamedGroups =
|
870
|
+
/(?<from>\d{4}-\d{2}-\d{2})-(?<to>\d{4}-\d{2}-\d{2})/;
|
871
|
+
const groups = fromToRegexWithNamedGroups.exec(
|
872
|
+
this[inputElementSymbol].value,
|
873
|
+
);
|
874
|
+
|
875
|
+
fromToInput.value = groups.groups.from;
|
876
|
+
toToInput.value = groups.groups.to;
|
877
|
+
|
878
|
+
fromToInput.disabled = false;
|
879
|
+
toToInput.disabled = false;
|
880
|
+
|
881
|
+
break;
|
882
|
+
}
|
883
|
+
}
|
884
|
+
|
885
|
+
/**
|
886
|
+
* @private
|
887
|
+
* @return {Monster.Components.Datatable.Filter.Range}
|
888
|
+
*/
|
889
|
+
function initControlReferences() {;
|
890
|
+
|
891
|
+
if (!this.shadowRoot) {
|
892
|
+
throw new Error("no shadow-root is defined");
|
893
|
+
}
|
894
|
+
|
895
|
+
this[controlElementSymbol] = this.shadowRoot.querySelector(
|
896
|
+
`[${ATTRIBUTE_ROLE}=control]`,
|
897
|
+
);
|
898
|
+
this[inputElementSymbol] = this.shadowRoot.querySelector(
|
899
|
+
`[${ATTRIBUTE_ROLE}=input]`,
|
900
|
+
);
|
901
|
+
this[popperElementSymbol] = this.shadowRoot.querySelector(
|
902
|
+
`[${ATTRIBUTE_ROLE}=popper]`,
|
903
|
+
);
|
904
|
+
this[arrowElementSymbol] = this.shadowRoot.querySelector(
|
905
|
+
`[${ATTRIBUTE_ROLE}=arrow]`,
|
906
|
+
);
|
907
|
+
this[formContainerElementSymbol] = this.shadowRoot.querySelector(
|
908
|
+
`[${ATTRIBUTE_ROLE}=form]`,
|
909
|
+
);
|
910
|
+
|
911
|
+
this[radioInputsElementSymbol] = this[
|
912
|
+
formContainerElementSymbol
|
913
|
+
].querySelectorAll(`input[name=rangeType]`);
|
914
|
+
this[inputInputsElementSymbol] = this[
|
915
|
+
formContainerElementSymbol
|
916
|
+
].querySelectorAll(`input[name=rangeType] ~ input`);
|
917
|
+
this[selectInputsElementSymbol] = this[
|
918
|
+
formContainerElementSymbol
|
919
|
+
].querySelectorAll(`input[name=rangeType] ~ select`);
|
920
|
+
|
921
|
+
return this;
|
922
|
+
}
|
923
|
+
|
924
|
+
/**
|
925
|
+
* @private
|
926
|
+
* @param {object} options
|
927
|
+
* @return {object}
|
928
|
+
*/
|
929
|
+
function initOptionsFromArguments(options) {;
|
930
|
+
|
931
|
+
return options;
|
932
|
+
}
|
933
|
+
|
934
|
+
/**
|
935
|
+
* @private
|
936
|
+
*/
|
937
|
+
function updatePopper() {;
|
938
|
+
|
939
|
+
if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
|
940
|
+
return;
|
941
|
+
}
|
942
|
+
|
943
|
+
if (this.getOption("disabled", false) === true) {
|
944
|
+
return;
|
945
|
+
}
|
946
|
+
|
947
|
+
positionPopper.call(
|
948
|
+
this,
|
949
|
+
this[controlElementSymbol],
|
950
|
+
this[popperElementSymbol],
|
951
|
+
this.getOption("popper", {}),
|
952
|
+
);
|
953
|
+
}
|
954
|
+
|
955
|
+
/**
|
956
|
+
* @private
|
957
|
+
* @return {string}
|
958
|
+
*/
|
959
|
+
function getTemplate() {
|
960
|
+
// language=HTML
|
961
|
+
return `
|
962
|
+
<div data-monster-role="control" part="control">
|
963
|
+
<input data-monster-attributes="disabled path:disabled | if:true, class path:classes.input"
|
964
|
+
data-monster-role="input"
|
965
|
+
part="button"
|
966
|
+
data-monster-replace="path:labels.button">
|
967
|
+
|
968
|
+
<div data-monster-role="popper" part="popper" tabindex="-1" class="monster-color-primary-1">
|
969
|
+
<div data-monster-role="arrow"></div>
|
970
|
+
<div part="filter" class="flex" data-monster-replace="path:filter">
|
971
|
+
<div class="form-container" data-monster-role="form">
|
972
|
+
|
973
|
+
<div data-monster-role="range-type" data-monster-range-type="today" data-monster-attributes="class path:features.moreThan | ?:form-group:hidden">
|
974
|
+
<input type="radio" name="rangeType" value="today" tabindex="0">
|
975
|
+
<label for="today"><span data-monster-replace="path:labels.todayValue"></span></label>
|
976
|
+
<input type="hidden" name="todayValue" disabled tabindex="0">
|
977
|
+
</div>
|
978
|
+
|
979
|
+
<div data-monster-role="range-type" data-monster-range-type="within" data-monster-attributes="class path:features.within | ?:form-group:hidden">
|
980
|
+
<input type="radio" name="rangeType" value="within" tabindex="0">
|
981
|
+
<label for="within"><span
|
982
|
+
data-monster-replace="path:labels.withinValue"></span></label>
|
983
|
+
<input data-monster-watch="true" type="number" name="withinValue" disabled
|
984
|
+
tabindex="0">
|
985
|
+
<select data-monster-watch="true" name="withinValueUnit" disabled tabindex="0">
|
986
|
+
<option selected value="days" data-monster-replace="path:labels.days"></option>
|
987
|
+
<option value="weeks" data-monster-replace="path:labels.weeks"></option>
|
988
|
+
<option value="months" data-monster-replace="path:labels.months"></option>
|
989
|
+
<option value="years" data-monster-replace="path:labels.years"></option>
|
990
|
+
</select>
|
991
|
+
</div>
|
992
|
+
|
993
|
+
<div data-monster-role="range-type" data-monster-range-type="more-than" data-monster-attributes="class path:features.moreThan | ?:form-group:hidden">
|
994
|
+
<input type="radio" name="rangeType" value="more-than" tabindex="0">
|
995
|
+
<label for="more-than"><span
|
996
|
+
data-monster-replace="path:labels.moreThanValue"></span></label>
|
997
|
+
<input data-monster-watch="true" type="number" name="moreThanValue" disabled
|
998
|
+
tabindex="0">
|
999
|
+
<select data-monster-watch="true" name="moreThanValueUnit" disabled tabindex="0">
|
1000
|
+
<option selected value="days" data-monster-replace="path:labels.days"></option>
|
1001
|
+
<option value="weeks" data-monster-replace="path:labels.weeks"></option>
|
1002
|
+
<option value="months" data-monster-replace="path:labels.months"></option>
|
1003
|
+
<option value="years" data-monster-replace="path:labels.years"></option>
|
1004
|
+
</select>
|
1005
|
+
</div>
|
1006
|
+
|
1007
|
+
<div class="form-group" data-monster-role="range-type" data-monster-range-type="single">
|
1008
|
+
<input type="radio" name="rangeType" value="single" tabindex="0">
|
1009
|
+
<label for="single"><span data-monster-replace="path:labels.singleValue"></span></label>
|
1010
|
+
<input type="date" data-monster-watch="true" name="singleValue" disabled tabindex="0">
|
1011
|
+
</div>
|
1012
|
+
|
1013
|
+
<div class="form-group" data-monster-role="range-type" data-monster-range-type="from">
|
1014
|
+
<input type="radio" name="rangeType" value="from" tabindex="0">
|
1015
|
+
<label for="from"><span data-monster-replace="path:labels.fromValue"></span></label>
|
1016
|
+
<input type="date" data-monster-watch="true" name="fromValue" disabled tabindex="0">
|
1017
|
+
</div>
|
1018
|
+
|
1019
|
+
<div class="form-group" data-monster-role="range-type" data-monster-range-type="to">
|
1020
|
+
<input type="radio" name="rangeType" value="to" tabindex="0">
|
1021
|
+
<label for="to"><span data-monster-replace="path:labels.toValue"></span></label>
|
1022
|
+
<input type="date" data-monster-watch="true" name="toValue" disabled tabindex="0">
|
1023
|
+
</div>
|
1024
|
+
|
1025
|
+
<div class="form-group" data-monster-role="range-type" data-monster-range-type="from-to">
|
1026
|
+
<input type="radio" name="rangeType" value="from-to" tabindex="0">
|
1027
|
+
<label for="rangeFrom"><span data-monster-replace="path:labels.fromValue"></span></label>
|
1028
|
+
<input type="date" data-monster-watch="true" name="fromValue" disabled tabindex="0">
|
1029
|
+
<label for="rangeTo"><span data-monster-replace="path:labels.toValue"></span></label>
|
1030
|
+
<input type="date" data-monster-watch="true" name="toValue" disabled tabindex="0">
|
1031
|
+
</div>
|
1032
|
+
|
1033
|
+
|
1034
|
+
</div>
|
1035
|
+
</div>
|
1036
|
+
</div>
|
1037
|
+
|
1038
|
+
`;
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
registerCustomElement(DateRange);
|