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