Diff: STRATO-apps/wordpress_03/app/wp-includes/js/dist/script-modules/block-library/accordion/view.js
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
import * as __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__ from "@wordpress/interactivity";
2
+
/******/ // The require scope
3
+
/******/ var __webpack_require__ = {};
4
+
/******/
5
+
/************************************************************************/
6
+
/******/ /* webpack/runtime/define property getters */
7
+
/******/ (() => {
8
+
/******/ // define getter functions for harmony exports
9
+
/******/ __webpack_require__.d = (exports, definition) => {
10
+
/******/ for(var key in definition) {
11
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
12
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
13
+
/******/ }
14
+
/******/ }
15
+
/******/ };
16
+
/******/ })();
17
+
/******/
18
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
19
+
/******/ (() => {
20
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
21
+
/******/ })();
22
+
/******/
23
+
/************************************************************************/
24
+
var __webpack_exports__ = {};
25
+
26
+
;// external "@wordpress/interactivity"
27
+
var x = (y) => {
28
+
var x = {}; __webpack_require__.d(x, y); return x
29
+
}
30
+
var y = (x) => (() => (x))
31
+
const interactivity_namespaceObject = x({ ["getContext"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext), ["store"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store), ["withSyncEvent"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.withSyncEvent) });
32
+
;// ./node_modules/@wordpress/block-library/build-module/accordion/view.js
33
+
34
+
let hashHandled = false;
35
+
const { actions } = (0,interactivity_namespaceObject.store)(
36
+
"core/accordion",
37
+
{
38
+
state: {
39
+
get isOpen() {
40
+
const { id, accordionItems } = (0,interactivity_namespaceObject.getContext)();
41
+
const accordionItem = accordionItems.find(
42
+
(item) => item.id === id
43
+
);
44
+
return accordionItem ? accordionItem.isOpen : false;
45
+
}
46
+
},
47
+
actions: {
48
+
toggle: () => {
49
+
const context = (0,interactivity_namespaceObject.getContext)();
50
+
const { id, autoclose, accordionItems } = context;
51
+
const accordionItem = accordionItems.find(
52
+
(item) => item.id === id
53
+
);
54
+
if (autoclose) {
55
+
accordionItems.forEach((item) => {
56
+
item.isOpen = item.id === id ? !accordionItem.isOpen : false;
57
+
});
58
+
} else {
59
+
accordionItem.isOpen = !accordionItem.isOpen;
60
+
}
61
+
},
62
+
handleKeyDown: (0,interactivity_namespaceObject.withSyncEvent)((event) => {
63
+
if (event.key !== "ArrowUp" && event.key !== "ArrowDown" && event.key !== "Home" && event.key !== "End") {
64
+
return;
65
+
}
66
+
event.preventDefault();
67
+
const context = (0,interactivity_namespaceObject.getContext)();
68
+
const { id, accordionItems } = context;
69
+
const currentIndex = accordionItems.findIndex(
70
+
(item) => item.id === id
71
+
);
72
+
let nextIndex;
73
+
switch (event.key) {
74
+
case "ArrowUp":
75
+
nextIndex = Math.max(0, currentIndex - 1);
76
+
break;
77
+
case "ArrowDown":
78
+
nextIndex = Math.min(
79
+
currentIndex + 1,
80
+
accordionItems.length - 1
81
+
);
82
+
break;
83
+
case "Home":
84
+
nextIndex = 0;
85
+
break;
86
+
case "End":
87
+
nextIndex = accordionItems.length - 1;
88
+
break;
89
+
}
90
+
const nextId = accordionItems[nextIndex].id;
91
+
const nextButton = document.getElementById(nextId);
92
+
if (nextButton) {
93
+
nextButton.focus();
94
+
}
95
+
}),
96
+
openPanelByHash: () => {
97
+
if (hashHandled || !window.location?.hash?.length) {
98
+
return;
99
+
}
100
+
const context = (0,interactivity_namespaceObject.getContext)();
101
+
const { id, accordionItems, autoclose } = context;
102
+
const hash = decodeURIComponent(
103
+
window.location.hash.slice(1)
104
+
);
105
+
const targetElement = window.document.getElementById(hash);
106
+
if (!targetElement) {
107
+
return;
108
+
}
109
+
const panelElement = window.document.querySelector(
110
+
'.wp-block-accordion-panel[aria-labelledby="' + id + '"]'
111
+
);
112
+
if (!panelElement || !panelElement.contains(targetElement)) {
113
+
return;
114
+
}
115
+
hashHandled = true;
116
+
if (autoclose) {
117
+
accordionItems.forEach((item) => {
118
+
item.isOpen = item.id === id;
119
+
});
120
+
} else {
121
+
const targetItem = accordionItems.find(
122
+
(item) => item.id === id
123
+
);
124
+
if (targetItem) {
125
+
targetItem.isOpen = true;
126
+
}
127
+
}
128
+
window.setTimeout(() => {
129
+
targetElement.scrollIntoView();
130
+
}, 0);
131
+
}
132
+
},
133
+
callbacks: {
134
+
initAccordionItems: () => {
135
+
const context = (0,interactivity_namespaceObject.getContext)();
136
+
const { id, openByDefault, accordionItems } = context;
137
+
accordionItems.push({
138
+
id,
139
+
isOpen: openByDefault
140
+
});
141
+
actions.openPanelByHash();
142
+
},
143
+
hashChange: () => {
144
+
hashHandled = false;
145
+
actions.openPanelByHash();
146
+
}
147
+
}
148
+
},
149
+
{ lock: true }
150
+
);
151
+
152
+