@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,1029 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright schukai GmbH and contributors 2023. All Rights Reserved.
|
3
|
+
* Node module: @schukai/monster
|
4
|
+
* This file is licensed under the AGPLv3 License.
|
5
|
+
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
|
+
*/
|
7
|
+
import { instanceSymbol } from "../../constants.mjs";
|
8
|
+
import { createPopper } from "@popperjs/core";
|
9
|
+
import { extend } from "../../data/extend.mjs";
|
10
|
+
import { Pathfinder } from "../../data/pathfinder.mjs";
|
11
|
+
import {addAttributeToken, addToObjectLink, hasObjectLink} from "../../dom/attributes.mjs";
|
12
|
+
import {ATTRIBUTE_ERRORMESSAGE, ATTRIBUTE_PREFIX, ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
|
13
|
+
import {
|
14
|
+
assembleMethodSymbol,
|
15
|
+
CustomElement,
|
16
|
+
getSlottedElements,
|
17
|
+
registerCustomElement,
|
18
|
+
} from "../../dom/customelement.mjs";
|
19
|
+
import { findTargetElementFromEvent } from "../../dom/events.mjs";
|
20
|
+
import { getDocument } from "../../dom/util.mjs";
|
21
|
+
import { random } from "../../math/random.mjs";
|
22
|
+
import { getGlobal } from "../../types/global.mjs";
|
23
|
+
import { ID } from "../../types/id.mjs";
|
24
|
+
import { isArray, isString } from "../../types/is.mjs";
|
25
|
+
import { TokenList } from "../../types/tokenlist.mjs";
|
26
|
+
import { clone } from "../../util/clone.mjs";
|
27
|
+
import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
|
28
|
+
import { Processing } from "../../util/processing.mjs";
|
29
|
+
import {
|
30
|
+
ATTRIBUTE_BUTTON_LABEL,
|
31
|
+
ATTRIBUTE_FORM_RELOAD,
|
32
|
+
ATTRIBUTE_FORM_URL,
|
33
|
+
STYLE_DISPLAY_MODE_BLOCK,
|
34
|
+
} from "./constants.mjs";
|
35
|
+
|
36
|
+
import { TabsStyleSheet } from "./stylesheet/tabs.mjs";
|
37
|
+
import { loadAndAssignContent } from "./util/fetch.mjs";
|
38
|
+
import {
|
39
|
+
popperInstanceSymbol,
|
40
|
+
setEventListenersModifiers,
|
41
|
+
} from "./util/popper.mjs";
|
42
|
+
|
43
|
+
export { Tabs };
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @private
|
47
|
+
* @type {symbol}
|
48
|
+
*/
|
49
|
+
const popperElementSymbol = Symbol("popperElement");
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @private
|
53
|
+
* @type {symbol}
|
54
|
+
*/
|
55
|
+
const popperNavElementSymbol = Symbol("popperNavElement");
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @private
|
59
|
+
* @type {symbol}
|
60
|
+
*/
|
61
|
+
const controlElementSymbol = Symbol("controlElement");
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @private
|
65
|
+
* @type {symbol}
|
66
|
+
*/
|
67
|
+
const navElementSymbol = Symbol("navElement");
|
68
|
+
/**
|
69
|
+
* @private
|
70
|
+
* @type {symbol}
|
71
|
+
*/
|
72
|
+
const switchElementSymbol = Symbol("switchElement");
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @private
|
76
|
+
* @type {symbol}
|
77
|
+
*/
|
78
|
+
const changeTabEventHandler = Symbol("changeTabEventHandler");
|
79
|
+
/**
|
80
|
+
* @private
|
81
|
+
* @type {symbol}
|
82
|
+
*/
|
83
|
+
const removeTabEventHandler = Symbol("removeTabEventHandler");
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @private
|
87
|
+
* @type {symbol}
|
88
|
+
*/
|
89
|
+
const popperSwitchEventHandler = Symbol("popperSwitchEventHandler");
|
90
|
+
|
91
|
+
/**
|
92
|
+
* local symbol
|
93
|
+
* @private
|
94
|
+
* @type {symbol}
|
95
|
+
*/
|
96
|
+
const closeEventHandler = Symbol("closeEventHandler");
|
97
|
+
|
98
|
+
/**
|
99
|
+
* @private
|
100
|
+
* @type {symbol}
|
101
|
+
*/
|
102
|
+
const mutationObserverSymbol = Symbol("mutationObserver");
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @private
|
106
|
+
* @type {symbol}
|
107
|
+
*/
|
108
|
+
const dimensionsSymbol = Symbol("dimensions");
|
109
|
+
|
110
|
+
/**
|
111
|
+
* @private
|
112
|
+
* @type {symbol}
|
113
|
+
*/
|
114
|
+
const timerCallbackSymbol = Symbol("timerCallback");
|
115
|
+
|
116
|
+
/**
|
117
|
+
* local symbol
|
118
|
+
* @private
|
119
|
+
* @type {symbol}
|
120
|
+
*/
|
121
|
+
const resizeObserverSymbol = Symbol("resizeObserver");
|
122
|
+
|
123
|
+
/**
|
124
|
+
* This CustomControl creates a tab element with a variety of options.
|
125
|
+
*
|
126
|
+
* <img src="./images/tabs.png">
|
127
|
+
*
|
128
|
+
* You can create this control either by specifying the HTML tag `<monster-tabs />` directly in the HTML or using
|
129
|
+
* Javascript via the `document.createElement('monster-tabs');` method.
|
130
|
+
*
|
131
|
+
* ```html
|
132
|
+
* <monster-tabs></monster-tabs>
|
133
|
+
* ```
|
134
|
+
*
|
135
|
+
* Or you can create this CustomControl directly in Javascript:
|
136
|
+
*
|
137
|
+
* ```js
|
138
|
+
* import {Tabs} from '@schukai/component-form/source/tab.js';
|
139
|
+
* document.createElement('monster-tabs');
|
140
|
+
* ```
|
141
|
+
*
|
142
|
+
* @example <caption>Create a simple tab control</caption>
|
143
|
+
* <monster-tabs>
|
144
|
+
* <div id="tab1">Tab 1</div>
|
145
|
+
* <div id="tab2">Tab 2</div>
|
146
|
+
* </monster-tabs>
|
147
|
+
*
|
148
|
+
* @startuml tabs.png
|
149
|
+
* skinparam monochrome true
|
150
|
+
* skinparam shadowing false
|
151
|
+
* HTMLElement <|-- CustomElement
|
152
|
+
* CustomElement <|-- CustomControl
|
153
|
+
* CustomControl <|-- Tabs
|
154
|
+
* @enduml
|
155
|
+
*
|
156
|
+
* @since 1.10.0
|
157
|
+
* @copyright schukai GmbH
|
158
|
+
* @memberOf Monster.Components.Form
|
159
|
+
* @summary A configurable tab control
|
160
|
+
* @fires Monster.Components.Form.event:monster-fetched
|
161
|
+
*/
|
162
|
+
class Tabs extends CustomElement {
|
163
|
+
/**
|
164
|
+
* This method is called by the `instanceof` operator.
|
165
|
+
* @returns {symbol}
|
166
|
+
* @since 2.1.0
|
167
|
+
*/
|
168
|
+
static get [instanceSymbol]() {
|
169
|
+
return Symbol.for("@schukai/component-form/tabs");
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* To set the options via the html tag the attribute `data-monster-options` must be used.
|
174
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
175
|
+
*
|
176
|
+
* The individual configuration values can be found in the table.
|
177
|
+
*
|
178
|
+
* @property {Object} templates Template definitions
|
179
|
+
* @property {string} templates.main Main template
|
180
|
+
* @property {Object} labels
|
181
|
+
* @property {string} labels.new-tab-label="New Tab"
|
182
|
+
* @property {Object} fetch Fetch [see Using Fetch mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
|
183
|
+
* @property {String} fetch.redirect=error
|
184
|
+
* @property {String} fetch.method=GET
|
185
|
+
* @property {String} fetch.mode=same-origin
|
186
|
+
* @property {String} fetch.credentials=same-origin
|
187
|
+
* @property {Object} fetch.headers={"accept":"text/html"}}
|
188
|
+
* @property {Object} popper [PopperJS Options](https://popper.js.org/docs/v2/)
|
189
|
+
* @property {string} popper.placement=bottom PopperJS placement
|
190
|
+
* @property {Object[]} modifiers={name:offset} PopperJS placement
|
191
|
+
*/
|
192
|
+
get defaults() {
|
193
|
+
return Object.assign({}, super.defaults, {
|
194
|
+
templates: {
|
195
|
+
main: getTemplate(),
|
196
|
+
},
|
197
|
+
labels: {
|
198
|
+
"new-tab-label": "New Tab",
|
199
|
+
},
|
200
|
+
buttons: {
|
201
|
+
standard: [],
|
202
|
+
popper: [],
|
203
|
+
},
|
204
|
+
fetch: {
|
205
|
+
redirect: "error",
|
206
|
+
method: "GET",
|
207
|
+
mode: "same-origin",
|
208
|
+
credentials: "same-origin",
|
209
|
+
headers: {
|
210
|
+
accept: "text/html",
|
211
|
+
},
|
212
|
+
},
|
213
|
+
popper: {
|
214
|
+
placement: "bottom",
|
215
|
+
modifiers: [
|
216
|
+
{
|
217
|
+
name: "offset",
|
218
|
+
options: {
|
219
|
+
offset: [0, 2],
|
220
|
+
},
|
221
|
+
},
|
222
|
+
|
223
|
+
{
|
224
|
+
name: "eventListeners",
|
225
|
+
enabled: false,
|
226
|
+
},
|
227
|
+
],
|
228
|
+
},
|
229
|
+
});
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* This method is called internal and should not be called directly.
|
234
|
+
*/
|
235
|
+
[assembleMethodSymbol]() {;
|
236
|
+
super[assembleMethodSymbol]();
|
237
|
+
|
238
|
+
initControlReferences.call(this);
|
239
|
+
|
240
|
+
this[dimensionsSymbol] = new Pathfinder({ data: {} });
|
241
|
+
// change and remove Tabs
|
242
|
+
initEventHandler.call(this);
|
243
|
+
|
244
|
+
// setup structure
|
245
|
+
initTabButtons.call(this).then(() => {
|
246
|
+
initPopperSwitch.call(this);
|
247
|
+
initPopper.call(this);
|
248
|
+
attachResizeObserver.call(this);
|
249
|
+
attachTabChangeObserver.call(this);
|
250
|
+
});
|
251
|
+
}
|
252
|
+
|
253
|
+
/**
|
254
|
+
* This method is called internal and should not be called directly.
|
255
|
+
*
|
256
|
+
* @return {CSSStyleSheet[]}
|
257
|
+
*/
|
258
|
+
static getCSSStyleSheet() {
|
259
|
+
return [TabsStyleSheet];
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* This method is called internal and should not be called directly.
|
264
|
+
*
|
265
|
+
* @return {string}
|
266
|
+
*/
|
267
|
+
static getTag() {
|
268
|
+
return "monster-tabs";
|
269
|
+
}
|
270
|
+
|
271
|
+
/**
|
272
|
+
* This method is called by the dom and should not be called directly.
|
273
|
+
*
|
274
|
+
* @return {void}
|
275
|
+
*/
|
276
|
+
connectedCallback() {
|
277
|
+
super.connectedCallback();
|
278
|
+
|
279
|
+
const document = getDocument();;
|
280
|
+
|
281
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
282
|
+
// close on outside ui-events
|
283
|
+
document.addEventListener(type, this[closeEventHandler]);
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
/**
|
288
|
+
* This method is called by the dom and should not be called directly.
|
289
|
+
*
|
290
|
+
* @return {void}
|
291
|
+
*/
|
292
|
+
disconnectedCallback() {
|
293
|
+
super.disconnectedCallback();
|
294
|
+
|
295
|
+
const document = getDocument();
|
296
|
+
|
297
|
+
// close on outside ui-events
|
298
|
+
for (const [, type] of Object.entries(["click", "touch"])) {
|
299
|
+
document.removeEventListener(type, this[closeEventHandler]);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
/**
|
305
|
+
* @private
|
306
|
+
*/
|
307
|
+
function initPopperSwitch() {;
|
308
|
+
|
309
|
+
const nodes = getSlottedElements.call(this, `[${ATTRIBUTE_ROLE}="switch"]`); // null ↦ only unnamed slots
|
310
|
+
let switchButton;
|
311
|
+
if (nodes.size === 0) {
|
312
|
+
switchButton = document.createElement("button");
|
313
|
+
switchButton.setAttribute(ATTRIBUTE_ROLE, "switch");
|
314
|
+
switchButton.setAttribute("part", "switch");
|
315
|
+
switchButton.classList.add("hidden");
|
316
|
+
switchButton.innerHTML =
|
317
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/></svg>';
|
318
|
+
this[navElementSymbol].prepend(switchButton);
|
319
|
+
} else {
|
320
|
+
switchButton = nodes.next();
|
321
|
+
}
|
322
|
+
|
323
|
+
/**
|
324
|
+
* @param {Event} event
|
325
|
+
*/
|
326
|
+
this[popperSwitchEventHandler] = (event) => {
|
327
|
+
const element = findTargetElementFromEvent(event, ATTRIBUTE_ROLE, "switch");
|
328
|
+
|
329
|
+
if (element instanceof HTMLButtonElement) {
|
330
|
+
togglePopper.call(this);
|
331
|
+
}
|
332
|
+
};
|
333
|
+
|
334
|
+
for (const type of ["click", "touch"]) {
|
335
|
+
switchButton.addEventListener(type, this[popperSwitchEventHandler]);
|
336
|
+
}
|
337
|
+
|
338
|
+
this[switchElementSymbol] = switchButton;
|
339
|
+
}
|
340
|
+
|
341
|
+
/**
|
342
|
+
* @private
|
343
|
+
*/
|
344
|
+
function hidePopper() {
|
345
|
+
|
346
|
+
if (!this[popperInstanceSymbol]) {
|
347
|
+
return;
|
348
|
+
}
|
349
|
+
|
350
|
+
this[popperElementSymbol].style.display = "none";
|
351
|
+
// performance https://popper.js.org/docs/v2/tutorial/#performance
|
352
|
+
setEventListenersModifiers.call(this, false);
|
353
|
+
}
|
354
|
+
|
355
|
+
/**
|
356
|
+
* @private
|
357
|
+
*/
|
358
|
+
function showPopper() {
|
359
|
+
|
360
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
361
|
+
return;
|
362
|
+
}
|
363
|
+
|
364
|
+
this[popperElementSymbol].style.visibility = "hidden";
|
365
|
+
this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
|
366
|
+
// performance https://popper.js.org/docs/v2/tutorial/#performance
|
367
|
+
setEventListenersModifiers.call(this, true);
|
368
|
+
|
369
|
+
this[popperInstanceSymbol].update();
|
370
|
+
|
371
|
+
new Processing(() => {
|
372
|
+
this[popperElementSymbol].style.removeProperty("visibility");
|
373
|
+
}).run(undefined).then(
|
374
|
+
() => {},
|
375
|
+
).catch(e=>{
|
376
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
377
|
+
});
|
378
|
+
}
|
379
|
+
|
380
|
+
/**
|
381
|
+
* @private
|
382
|
+
*/
|
383
|
+
function togglePopper() {
|
384
|
+
|
385
|
+
if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
|
386
|
+
hidePopper.call(this);
|
387
|
+
} else {
|
388
|
+
showPopper.call(this);
|
389
|
+
}
|
390
|
+
}
|
391
|
+
|
392
|
+
/**
|
393
|
+
* @private
|
394
|
+
*/
|
395
|
+
function attachResizeObserver() {
|
396
|
+
|
397
|
+
// against flickering
|
398
|
+
this[resizeObserverSymbol] = new ResizeObserver((entries) => {
|
399
|
+
if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
|
400
|
+
try {
|
401
|
+
this[timerCallbackSymbol].touch();
|
402
|
+
return;
|
403
|
+
} catch (e) {
|
404
|
+
delete this[timerCallbackSymbol];
|
405
|
+
}
|
406
|
+
}
|
407
|
+
|
408
|
+
this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
|
409
|
+
this[dimensionsSymbol].setVia("data.calculated", false);
|
410
|
+
checkAndRearrangeButtons.call(this);
|
411
|
+
});
|
412
|
+
});
|
413
|
+
|
414
|
+
this[resizeObserverSymbol].observe(this[navElementSymbol]);
|
415
|
+
}
|
416
|
+
|
417
|
+
/**
|
418
|
+
* @private
|
419
|
+
*/
|
420
|
+
function attachTabChangeObserver() {
|
421
|
+
|
422
|
+
// against flickering
|
423
|
+
new MutationObserver((mutations) => {
|
424
|
+
let runUpdate = false;
|
425
|
+
|
426
|
+
for (const mutation of mutations) {
|
427
|
+
if (mutation.type === "childList") {
|
428
|
+
if (
|
429
|
+
mutation.addedNodes.length > 0 ||
|
430
|
+
mutation.removedNodes.length > 0
|
431
|
+
) {
|
432
|
+
runUpdate = true;
|
433
|
+
break;
|
434
|
+
}
|
435
|
+
}
|
436
|
+
}
|
437
|
+
|
438
|
+
if (runUpdate === true) {
|
439
|
+
this[dimensionsSymbol].setVia("data.calculated", false);
|
440
|
+
initTabButtons.call(this);
|
441
|
+
}
|
442
|
+
}).observe(this, {
|
443
|
+
childList: true,
|
444
|
+
});
|
445
|
+
}
|
446
|
+
|
447
|
+
/**
|
448
|
+
* @private
|
449
|
+
* @return {Select}
|
450
|
+
* @external "external:createPopper"
|
451
|
+
* @see {@link Plugins}
|
452
|
+
*/
|
453
|
+
function initPopper() {
|
454
|
+
const self = this;
|
455
|
+
|
456
|
+
const options = extend({}, self.getOption("popper"));
|
457
|
+
|
458
|
+
self[popperInstanceSymbol] = createPopper(
|
459
|
+
self[switchElementSymbol],
|
460
|
+
self[popperElementSymbol],
|
461
|
+
options,
|
462
|
+
);
|
463
|
+
|
464
|
+
const observer1 = new MutationObserver(function (mutations) {
|
465
|
+
let runUpdate = false;
|
466
|
+
|
467
|
+
for (const mutation of mutations) {
|
468
|
+
if (mutation.type === "childList") {
|
469
|
+
if (
|
470
|
+
mutation.addedNodes.length > 0 ||
|
471
|
+
mutation.removedNodes.length > 0
|
472
|
+
) {
|
473
|
+
runUpdate = true;
|
474
|
+
break;
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
478
|
+
|
479
|
+
if (runUpdate === true) {
|
480
|
+
self[popperInstanceSymbol].update();
|
481
|
+
}
|
482
|
+
});
|
483
|
+
|
484
|
+
observer1.observe(self[popperNavElementSymbol], {
|
485
|
+
childList: true,
|
486
|
+
subtree: true,
|
487
|
+
});
|
488
|
+
|
489
|
+
return self;
|
490
|
+
}
|
491
|
+
|
492
|
+
/**
|
493
|
+
* @private
|
494
|
+
* @param {HTMLElement} element
|
495
|
+
*/
|
496
|
+
function show(element) {
|
497
|
+
|
498
|
+
if (!this.shadowRoot) {
|
499
|
+
throw new Error("no shadow-root is defined");
|
500
|
+
}
|
501
|
+
|
502
|
+
const reference = element.getAttribute(`${ATTRIBUTE_PREFIX}tab-reference`);
|
503
|
+
|
504
|
+
const nodes = getSlottedElements.call(this);
|
505
|
+
for (const node of nodes) {
|
506
|
+
const id = node.getAttribute("id");
|
507
|
+
|
508
|
+
if (id === reference) {
|
509
|
+
node.classList.add("active");
|
510
|
+
|
511
|
+
if (node.hasAttribute(ATTRIBUTE_FORM_URL)) {
|
512
|
+
const url = node.getAttribute(ATTRIBUTE_FORM_URL);
|
513
|
+
|
514
|
+
if (
|
515
|
+
!node.hasAttribute(ATTRIBUTE_FORM_RELOAD) ||
|
516
|
+
node.getAttribute(ATTRIBUTE_FORM_RELOAD).toLowerCase() === "onshow"
|
517
|
+
) {
|
518
|
+
node.removeAttribute(ATTRIBUTE_FORM_URL);
|
519
|
+
}
|
520
|
+
|
521
|
+
const options = this.getOption("fetch", {});
|
522
|
+
const filter = undefined;
|
523
|
+
loadAndAssignContent(node, url, options,filter).then(() => {
|
524
|
+
|
525
|
+
}).catch(e=>{
|
526
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
527
|
+
});
|
528
|
+
}
|
529
|
+
} else {
|
530
|
+
node.classList.remove("active");
|
531
|
+
}
|
532
|
+
}
|
533
|
+
|
534
|
+
const standardButtons = this.getOption("buttons.standard");
|
535
|
+
for (const index in standardButtons) {
|
536
|
+
const button = standardButtons[index];
|
537
|
+
const state = button["reference"] === reference ? "active" : "inactive";
|
538
|
+
this.setOption(`buttons.standard.${index}.state`, state);
|
539
|
+
}
|
540
|
+
|
541
|
+
const popperButton = this.getOption("buttons.popper");
|
542
|
+
for (const index in popperButton) {
|
543
|
+
const button = popperButton[index];
|
544
|
+
const state = button["reference"] === reference ? "active" : "inactive";
|
545
|
+
this.setOption(`buttons.popper.${index}.state`, state);
|
546
|
+
}
|
547
|
+
|
548
|
+
hidePopper.call(this);
|
549
|
+
}
|
550
|
+
|
551
|
+
/**
|
552
|
+
* @private
|
553
|
+
*/
|
554
|
+
function initEventHandler() {
|
555
|
+
|
556
|
+
if (!this.shadowRoot) {
|
557
|
+
throw new Error("no shadow-root is defined");
|
558
|
+
}
|
559
|
+
|
560
|
+
/**
|
561
|
+
* @param {Event} event
|
562
|
+
*/
|
563
|
+
this[changeTabEventHandler] = (event) => {
|
564
|
+
const element = findTargetElementFromEvent(event, ATTRIBUTE_ROLE, "button");
|
565
|
+
|
566
|
+
if (element instanceof HTMLButtonElement && element.disabled !== true) {
|
567
|
+
show.call(this, element);
|
568
|
+
}
|
569
|
+
};
|
570
|
+
|
571
|
+
/**
|
572
|
+
* @param {Event} event
|
573
|
+
*/
|
574
|
+
this[removeTabEventHandler] = (event) => {
|
575
|
+
const element = findTargetElementFromEvent(
|
576
|
+
event,
|
577
|
+
ATTRIBUTE_ROLE,
|
578
|
+
"remove-tab",
|
579
|
+
);
|
580
|
+
|
581
|
+
if (element instanceof HTMLElement) {
|
582
|
+
const button = findTargetElementFromEvent(
|
583
|
+
event,
|
584
|
+
ATTRIBUTE_ROLE,
|
585
|
+
"button",
|
586
|
+
);
|
587
|
+
|
588
|
+
if (button instanceof HTMLButtonElement && button.disabled !== true) {
|
589
|
+
const reference = button.getAttribute(
|
590
|
+
`${ATTRIBUTE_PREFIX}tab-reference`,
|
591
|
+
);
|
592
|
+
if (reference) {
|
593
|
+
const container = this.querySelector(`[id=${reference}]`);
|
594
|
+
if (container instanceof HTMLElement) {
|
595
|
+
container.remove();
|
596
|
+
initTabButtons.call(this);
|
597
|
+
}
|
598
|
+
}
|
599
|
+
}
|
600
|
+
}
|
601
|
+
};
|
602
|
+
|
603
|
+
this[navElementSymbol].addEventListener("touch", this[changeTabEventHandler]);
|
604
|
+
this[navElementSymbol].addEventListener("click", this[changeTabEventHandler]);
|
605
|
+
|
606
|
+
this[navElementSymbol].addEventListener("touch", this[removeTabEventHandler]);
|
607
|
+
this[navElementSymbol].addEventListener("click", this[removeTabEventHandler]);
|
608
|
+
|
609
|
+
/**
|
610
|
+
* @param {Event} event
|
611
|
+
*/
|
612
|
+
this[closeEventHandler] = (event) => {
|
613
|
+
const path = event.composedPath();
|
614
|
+
|
615
|
+
for (const [, element] of Object.entries(path)) {
|
616
|
+
if (element === this) {
|
617
|
+
return;
|
618
|
+
}
|
619
|
+
}
|
620
|
+
|
621
|
+
hidePopper.call(this);
|
622
|
+
};
|
623
|
+
|
624
|
+
return this;
|
625
|
+
}
|
626
|
+
|
627
|
+
/**
|
628
|
+
* @private
|
629
|
+
* @param observedNode
|
630
|
+
*/
|
631
|
+
function attachTabMutationObserver(observedNode) {
|
632
|
+
const self = this;
|
633
|
+
|
634
|
+
if (hasObjectLink(observedNode, mutationObserverSymbol)) {
|
635
|
+
return;
|
636
|
+
}
|
637
|
+
|
638
|
+
/**
|
639
|
+
* this construct monitors a node whether it is disabled or modified
|
640
|
+
* @type {MutationObserver}
|
641
|
+
*/
|
642
|
+
const observer = new MutationObserver(function (mutations) {
|
643
|
+
if (isArray(mutations)) {
|
644
|
+
const mutation = mutations.pop();
|
645
|
+
if (mutation instanceof MutationRecord) {
|
646
|
+
initTabButtons.call(self);
|
647
|
+
}
|
648
|
+
}
|
649
|
+
});
|
650
|
+
|
651
|
+
observer.observe(observedNode, {
|
652
|
+
childList: false,
|
653
|
+
attributes: true,
|
654
|
+
subtree: false,
|
655
|
+
attributeFilter: [
|
656
|
+
"disabled",
|
657
|
+
ATTRIBUTE_BUTTON_LABEL,
|
658
|
+
`${ATTRIBUTE_PREFIX}button-icon`,
|
659
|
+
],
|
660
|
+
});
|
661
|
+
|
662
|
+
addToObjectLink(observedNode, mutationObserverSymbol, observer);
|
663
|
+
}
|
664
|
+
|
665
|
+
/**
|
666
|
+
* @private
|
667
|
+
* @return {Select}
|
668
|
+
* @throws {Error} no shadow-root is defined
|
669
|
+
*/
|
670
|
+
function initControlReferences() {;
|
671
|
+
|
672
|
+
if (!this.shadowRoot) {
|
673
|
+
throw new Error("no shadow-root is defined");
|
674
|
+
}
|
675
|
+
|
676
|
+
this[controlElementSymbol] = this.shadowRoot.querySelector(
|
677
|
+
`[${ATTRIBUTE_ROLE}=control]`,
|
678
|
+
);
|
679
|
+
this[navElementSymbol] = this.shadowRoot.querySelector(
|
680
|
+
`nav[${ATTRIBUTE_ROLE}=nav]`,
|
681
|
+
);
|
682
|
+
this[popperElementSymbol] = this.shadowRoot.querySelector(
|
683
|
+
`[${ATTRIBUTE_ROLE}=popper]`,
|
684
|
+
);
|
685
|
+
this[popperNavElementSymbol] = this.shadowRoot.querySelector(
|
686
|
+
`[${ATTRIBUTE_ROLE}=popper-nav]`,
|
687
|
+
);
|
688
|
+
}
|
689
|
+
|
690
|
+
/**
|
691
|
+
* @private
|
692
|
+
* @return {Promise<unknown>}
|
693
|
+
* @throws {Error} no shadow-root is defined
|
694
|
+
*
|
695
|
+
*/
|
696
|
+
function initTabButtons() {;
|
697
|
+
|
698
|
+
if (!this.shadowRoot) {
|
699
|
+
throw new Error("no shadow-root is defined");
|
700
|
+
}
|
701
|
+
|
702
|
+
let activeReference;
|
703
|
+
|
704
|
+
const dimensionsCalculated = this[dimensionsSymbol].getVia(
|
705
|
+
"data.calculated",
|
706
|
+
false,
|
707
|
+
);
|
708
|
+
|
709
|
+
const buttons = [];
|
710
|
+
const nodes = getSlottedElements.call(this, undefined, null); // null ↦ only unnamed slots
|
711
|
+
|
712
|
+
for (const node of nodes) {
|
713
|
+
if (!(node instanceof HTMLElement)) continue;
|
714
|
+
let label = getButtonLabel.call(this, node);
|
715
|
+
|
716
|
+
let reference;
|
717
|
+
if (node.hasAttribute("id")) {
|
718
|
+
reference = node.getAttribute("id");
|
719
|
+
}
|
720
|
+
|
721
|
+
let disabled;
|
722
|
+
if (node.hasAttribute("disabled") || node.disabled === true) {
|
723
|
+
disabled = true;
|
724
|
+
}
|
725
|
+
|
726
|
+
if (!reference) {
|
727
|
+
reference = new ID("tab").toString();
|
728
|
+
node.setAttribute("id", reference);
|
729
|
+
}
|
730
|
+
|
731
|
+
if (node.hasAttribute(`${ATTRIBUTE_PREFIX}button-icon`)) {
|
732
|
+
label = `<span part="label">${label}</span><img part="icon" src="${node.getAttribute(
|
733
|
+
`${ATTRIBUTE_PREFIX}button-icon`,
|
734
|
+
)}">`;
|
735
|
+
}
|
736
|
+
|
737
|
+
let remove = false;
|
738
|
+
if (node.hasAttribute(`${ATTRIBUTE_PREFIX}removable`)) {
|
739
|
+
remove = true;
|
740
|
+
}
|
741
|
+
|
742
|
+
if (node.matches(".active") === true && disabled !== true) {
|
743
|
+
node.classList.remove("active");
|
744
|
+
activeReference = reference;
|
745
|
+
}
|
746
|
+
|
747
|
+
const state = "";
|
748
|
+
const classes = dimensionsCalculated ? "" : "invisible";
|
749
|
+
|
750
|
+
buttons.push({
|
751
|
+
reference,
|
752
|
+
label,
|
753
|
+
state,
|
754
|
+
class: classes,
|
755
|
+
disabled,
|
756
|
+
remove,
|
757
|
+
});
|
758
|
+
|
759
|
+
attachTabMutationObserver.call(this, node);
|
760
|
+
}
|
761
|
+
|
762
|
+
this.setOption("buttons.standard", clone(buttons));
|
763
|
+
this.setOption("buttons.popper", []);
|
764
|
+
this.setOption("marker", random());
|
765
|
+
|
766
|
+
return adjustButtonVisibility.call(this).then(() => {
|
767
|
+
if (activeReference) {
|
768
|
+
return new Processing(() => {
|
769
|
+
const button = this.shadowRoot.querySelector(
|
770
|
+
`[${ATTRIBUTE_PREFIX}tab-reference="${activeReference}"]`,
|
771
|
+
);
|
772
|
+
if (button instanceof HTMLButtonElement && button.disabled !== true) {
|
773
|
+
show.call(this, button);
|
774
|
+
}
|
775
|
+
}).run(undefined).then(
|
776
|
+
() => {},
|
777
|
+
).catch(e=>{
|
778
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, e.message);
|
779
|
+
});
|
780
|
+
}
|
781
|
+
|
782
|
+
return Promise.resolve();
|
783
|
+
});
|
784
|
+
}
|
785
|
+
|
786
|
+
function checkAndRearrangeButtons() {;
|
787
|
+
|
788
|
+
if (this[dimensionsSymbol].getVia("data.calculated", false) !== true) {
|
789
|
+
calculateNavigationButtonsDimensions.call(this);
|
790
|
+
}
|
791
|
+
|
792
|
+
rearrangeButtons.call(this);
|
793
|
+
}
|
794
|
+
|
795
|
+
/**
|
796
|
+
* @private
|
797
|
+
* @return {Promise<unknown>}
|
798
|
+
*/
|
799
|
+
function adjustButtonVisibility() {
|
800
|
+
const self = this;
|
801
|
+
|
802
|
+
return new Promise((resolve) => {
|
803
|
+
const observer = new MutationObserver(function (mutations) {
|
804
|
+
const defCount = self.getOption("buttons.standard").length;
|
805
|
+
const domCount = self[navElementSymbol].querySelectorAll(
|
806
|
+
'button[data-monster-role="button"]',
|
807
|
+
).length;
|
808
|
+
|
809
|
+
// in drawing
|
810
|
+
if (defCount !== domCount) return;
|
811
|
+
|
812
|
+
observer.disconnect();
|
813
|
+
|
814
|
+
checkAndRearrangeButtons.call(self);
|
815
|
+
|
816
|
+
resolve();
|
817
|
+
});
|
818
|
+
|
819
|
+
observer.observe(self[navElementSymbol], {
|
820
|
+
attributes: true,
|
821
|
+
});
|
822
|
+
});
|
823
|
+
}
|
824
|
+
|
825
|
+
/**
|
826
|
+
* @private
|
827
|
+
* @param {string} value
|
828
|
+
* @return {number}
|
829
|
+
*/
|
830
|
+
function getDimValue(value) {
|
831
|
+
if ([undefined, null].indexOf(value) !== -1) {
|
832
|
+
return 0;
|
833
|
+
}
|
834
|
+
|
835
|
+
const valueAsInt = parseInt(value, 10);
|
836
|
+
|
837
|
+
if (isNaN(valueAsInt)) {
|
838
|
+
return 0;
|
839
|
+
}
|
840
|
+
|
841
|
+
return valueAsInt;
|
842
|
+
}
|
843
|
+
|
844
|
+
/**
|
845
|
+
* @private
|
846
|
+
* @param {HTMLElement} node
|
847
|
+
* @return {number}
|
848
|
+
*/
|
849
|
+
function calcBoxWidth(node) {
|
850
|
+
const dim = getGlobal("window").getComputedStyle(node);
|
851
|
+
const bounding = node.getBoundingClientRect();
|
852
|
+
|
853
|
+
return (
|
854
|
+
getDimValue(dim["border-left-width"]) +
|
855
|
+
getDimValue(dim["padding-left"]) +
|
856
|
+
getDimValue(dim["margin-left"]) +
|
857
|
+
getDimValue(bounding["width"]) +
|
858
|
+
getDimValue(dim["border-right-width"]) +
|
859
|
+
getDimValue(dim["margin-right"]) +
|
860
|
+
getDimValue(dim["padding-left"])
|
861
|
+
);
|
862
|
+
}
|
863
|
+
|
864
|
+
/**
|
865
|
+
* @private
|
866
|
+
* @return {Object}
|
867
|
+
*/
|
868
|
+
function rearrangeButtons() {;
|
869
|
+
|
870
|
+
const standardButtons = [];
|
871
|
+
const popperButtons = [];
|
872
|
+
|
873
|
+
let sum = 0;
|
874
|
+
const space = this[dimensionsSymbol].getVia("data.space");
|
875
|
+
|
876
|
+
const buttons = this.getOption("buttons.standard");
|
877
|
+
for (const [, button] of buttons.entries()) {
|
878
|
+
const ref = button?.reference;
|
879
|
+
|
880
|
+
sum += this[dimensionsSymbol].getVia(`data.button.${ref}`);
|
881
|
+
|
882
|
+
if (sum > space) {
|
883
|
+
popperButtons.push(clone(button));
|
884
|
+
} else {
|
885
|
+
standardButtons.push(clone(button));
|
886
|
+
}
|
887
|
+
}
|
888
|
+
|
889
|
+
this.setOption("buttons.standard", standardButtons);
|
890
|
+
this.setOption("buttons.popper", popperButtons);
|
891
|
+
|
892
|
+
if (this[switchElementSymbol]) {
|
893
|
+
if (popperButtons.length > 0) {
|
894
|
+
this[switchElementSymbol].classList.remove("hidden");
|
895
|
+
} else {
|
896
|
+
this[switchElementSymbol].classList.add("hidden");
|
897
|
+
}
|
898
|
+
}
|
899
|
+
}
|
900
|
+
|
901
|
+
/**
|
902
|
+
* @private
|
903
|
+
* @return {Object}
|
904
|
+
*/
|
905
|
+
function calculateNavigationButtonsDimensions() {;
|
906
|
+
|
907
|
+
const width = this[navElementSymbol].getBoundingClientRect().width;
|
908
|
+
|
909
|
+
let startEndWidth = 0;
|
910
|
+
|
911
|
+
getSlottedElements.call(this, undefined, "start").forEach((node) => {
|
912
|
+
startEndWidth += calcBoxWidth.call(this, node);
|
913
|
+
});
|
914
|
+
|
915
|
+
getSlottedElements.call(this, undefined, "end").forEach((node) => {
|
916
|
+
startEndWidth += calcBoxWidth.call(this, node);
|
917
|
+
});
|
918
|
+
|
919
|
+
this[dimensionsSymbol].setVia("data.space", width - startEndWidth - 2);
|
920
|
+
this[dimensionsSymbol].setVia("data.visible", !(width === 0));
|
921
|
+
|
922
|
+
const buttons = this
|
923
|
+
.getOption("buttons.standard")
|
924
|
+
.concat(this.getOption("buttons.popper"));
|
925
|
+
|
926
|
+
for (const [i, button] of buttons.entries()) {
|
927
|
+
const ref = button?.reference;
|
928
|
+
const element = this[navElementSymbol].querySelector(
|
929
|
+
`:scope > [${ATTRIBUTE_PREFIX}tab-reference="${ref}"]`,
|
930
|
+
);
|
931
|
+
if (!(element instanceof HTMLButtonElement)) continue;
|
932
|
+
|
933
|
+
this[dimensionsSymbol].setVia(
|
934
|
+
`data.button.${ref}`,
|
935
|
+
calcBoxWidth.call(this, element),
|
936
|
+
);
|
937
|
+
button["class"] = new TokenList(button["class"])
|
938
|
+
.remove("invisible")
|
939
|
+
.toString();
|
940
|
+
}
|
941
|
+
|
942
|
+
const slots = this[controlElementSymbol].querySelectorAll(
|
943
|
+
`nav[${ATTRIBUTE_PREFIX}role=nav] > slot.invisible, slot[${ATTRIBUTE_PREFIX}role=slot].invisible`,
|
944
|
+
);
|
945
|
+
for (const [, slot] of slots.entries()) {
|
946
|
+
slot.classList.remove("invisible");
|
947
|
+
}
|
948
|
+
|
949
|
+
this[dimensionsSymbol].setVia("data.calculated", true);
|
950
|
+
this.setOption("buttons.standard", clone(buttons));
|
951
|
+
}
|
952
|
+
|
953
|
+
/**
|
954
|
+
* @private
|
955
|
+
* @param {HTMLElement} node
|
956
|
+
* @return {string}
|
957
|
+
*/
|
958
|
+
function getButtonLabel(node) {;
|
959
|
+
|
960
|
+
let label;
|
961
|
+
let setLabel = false;
|
962
|
+
if (node.hasAttribute(ATTRIBUTE_BUTTON_LABEL)) {
|
963
|
+
label = node.getAttribute(ATTRIBUTE_BUTTON_LABEL);
|
964
|
+
} else {
|
965
|
+
label = node.innerText;
|
966
|
+
setLabel = true;
|
967
|
+
}
|
968
|
+
|
969
|
+
if (!isString(label)) {
|
970
|
+
label = "";
|
971
|
+
}
|
972
|
+
|
973
|
+
label = label.trim();
|
974
|
+
|
975
|
+
if (label === "") {
|
976
|
+
label = this.getOption("labels.new-tab-label", "New Tab");
|
977
|
+
}
|
978
|
+
|
979
|
+
if (label.length > 100) {
|
980
|
+
label = `${label.substring(0, 99)}…`;
|
981
|
+
}
|
982
|
+
|
983
|
+
if (setLabel === true) {
|
984
|
+
node.setAttribute(ATTRIBUTE_BUTTON_LABEL, label);
|
985
|
+
}
|
986
|
+
|
987
|
+
return label;
|
988
|
+
}
|
989
|
+
|
990
|
+
/**
|
991
|
+
* @private
|
992
|
+
* @return {string}
|
993
|
+
*/
|
994
|
+
function getTemplate() {
|
995
|
+
// language=HTML
|
996
|
+
return `
|
997
|
+
<template id="buttons">
|
998
|
+
<button part="button"
|
999
|
+
data-monster-role="button"
|
1000
|
+
data-monster-attributes="
|
1001
|
+
data-monster-state path:buttons.state,
|
1002
|
+
disabled path:buttons.disabled | if:true,
|
1003
|
+
data-monster-tab-reference path:buttons.reference"><span
|
1004
|
+
data-monster-replace="path:buttons.label"></span><span part="remove-tab"
|
1005
|
+
data-monster-attributes="class path:buttons.remove | ?:remove-tab:hidden "
|
1006
|
+
data-monster-role="remove-tab"
|
1007
|
+
tabindex="-1"></span></button>
|
1008
|
+
</template>
|
1009
|
+
<div data-monster-role="control" part="control">
|
1010
|
+
<nav data-monster-role="nav" part="nav"
|
1011
|
+
data-monster-attributes="data-monster-marker path:marker"
|
1012
|
+
data-monster-insert="buttons path:buttons.standard">
|
1013
|
+
<slot name="start" class="invisible"></slot>
|
1014
|
+
<div data-monster-role="popper" part="popper" tabindex="-1" class="monster-color-primary-1">
|
1015
|
+
<div data-popper-arrow></div>
|
1016
|
+
|
1017
|
+
|
1018
|
+
<div part="popper-nav" data-monster-role="popper-nav"
|
1019
|
+
data-monster-insert="buttons path:buttons.popper"
|
1020
|
+
tabindex="-1"></div>
|
1021
|
+
</div>
|
1022
|
+
<slot name="popper" class="invisible"></slot>
|
1023
|
+
<slot name="end" class="invisible"></slot>
|
1024
|
+
</nav>
|
1025
|
+
<slot data-monster-role="slot" class="invisible"></slot>
|
1026
|
+
</div>`;
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
registerCustomElement(Tabs);
|