@mintplayer/web-components 2.20.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunks/{datatable-qkYf-N0c.mjs → datatable-CrK1ZNq-.mjs} +132 -130
- package/chunks/{pagination-Bcz1TwlS.mjs → pagination-DgDp3v3u.mjs} +1 -1
- package/custom-elements.json +3119 -3416
- package/datatable/index.mjs +1 -1
- package/datatable/src/components/mp-datatable.d.ts +4 -0
- package/datatable/src/types/tree.d.ts +7 -0
- package/dropdown-menu/index.mjs +16 -23
- package/dropdown-menu/src/components/mp-dropdown-menu.d.ts +5 -8
- package/dropdown-menu/src/index.d.ts +1 -1
- package/dropdown-menu/src/types/dropdown.d.ts +0 -2
- package/dropdown-menu/src/types/index.d.ts +1 -1
- package/file-manager/index.mjs +1 -1
- package/light-dom/index.mjs +61 -121
- package/light-dom/src/install-light-styles.d.ts +10 -22
- package/light-dom/src/scoped-html.d.ts +0 -6
- package/machine/index.d.ts +1 -0
- package/machine/index.mjs +47 -0
- package/machine/src/index.d.ts +2 -0
- package/machine/src/machine-controller.d.ts +25 -0
- package/machine/src/props-directive.d.ts +21 -0
- package/package.json +10 -1
- package/pagination/index.mjs +1 -1
- package/tile-manager/index.mjs +150 -731
- package/tile-manager/src/components/index.d.ts +1 -2
- package/tile-manager/src/components/mp-tile-manager.d.ts +107 -0
- package/tile-manager/src/index.d.ts +2 -3
- package/tree-select/index.mjs +63 -55
- package/tree-select/src/components/mp-tree-select.d.ts +16 -5
- package/typeahead/index.d.ts +1 -0
- package/typeahead/index.mjs +220 -0
- package/typeahead/src/components/mp-typeahead.d.ts +67 -0
- package/typeahead/src/index.d.ts +3 -0
- package/tile-manager/src/components/mint-tile-manager.element.d.ts +0 -212
- package/tile-manager/src/components/mint-tile-manager.element.template.d.ts +0 -2
- package/tile-manager/src/types/grid-rect.d.ts +0 -12
- package/tile-manager/src/types/index.d.ts +0 -3
- package/tile-manager/src/types/tile-layout-snapshot.d.ts +0 -15
- package/tile-manager/src/types/tile-position.d.ts +0 -10
- package/tile-manager/src/utils/grid-geometry.d.ts +0 -49
- package/tile-manager/src/utils/index.d.ts +0 -1
- package/tile-manager/src/utils/pack.d.ts +0 -24
package/tile-manager/index.mjs
CHANGED
|
@@ -1,772 +1,191 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
//#
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let o = [r, ...i], l = e.filter((e) => !e.locked && e.id !== t.id).slice().sort((e, t) => {
|
|
23
|
-
let n = e.position.rowStart - t.position.rowStart;
|
|
24
|
-
return n === 0 ? e.position.colStart - t.position.colStart : n;
|
|
25
|
-
}), d = l.reduce((e, t) => {
|
|
26
|
-
let r = c(t, [...o, ...e], n);
|
|
27
|
-
return r ? [...e, r] : e;
|
|
28
|
-
}, []);
|
|
29
|
-
if (d.length !== l.length) return {
|
|
30
|
-
layout: s(e),
|
|
31
|
-
blocked: !0
|
|
32
|
-
};
|
|
33
|
-
let f = u(d, o, n), p = new Map([
|
|
34
|
-
r,
|
|
35
|
-
...i,
|
|
36
|
-
...f
|
|
37
|
-
].map((e) => [e.id, e.position]));
|
|
38
|
-
return {
|
|
39
|
-
layout: e.map((e) => ({
|
|
40
|
-
id: e.id,
|
|
41
|
-
position: p.get(e.id) ?? { ...e.position }
|
|
42
|
-
})),
|
|
43
|
-
blocked: !1
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function s(e) {
|
|
47
|
-
return e.map((e) => ({
|
|
48
|
-
id: e.id,
|
|
49
|
-
position: { ...e.position }
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
function c(e, t, n) {
|
|
53
|
-
let { colSpan: r, rowSpan: i } = e.position;
|
|
54
|
-
if (r > n) return null;
|
|
55
|
-
if (!t.some((t) => a(e.position, t.position))) return {
|
|
56
|
-
id: e.id,
|
|
57
|
-
position: { ...e.position }
|
|
58
|
-
};
|
|
59
|
-
let o = l({
|
|
60
|
-
colSpan: r,
|
|
61
|
-
rowSpan: i
|
|
62
|
-
}, t, n);
|
|
63
|
-
return o ? {
|
|
64
|
-
id: e.id,
|
|
65
|
-
position: o
|
|
66
|
-
} : null;
|
|
67
|
-
}
|
|
68
|
-
function l(e, t, n) {
|
|
69
|
-
let r = t.reduce((e, t) => Math.max(e, t.position.rowStart + t.position.rowSpan - 1), 0) + e.rowSpan, i = n - e.colSpan + 1;
|
|
70
|
-
if (i < 1) return null;
|
|
71
|
-
for (let n = 1; n <= r; n++) for (let r = 0; r < i; r++) {
|
|
72
|
-
let i = r + 1, o = !1;
|
|
73
|
-
for (let r = 0; r < t.length; r++) if (a({
|
|
74
|
-
rowStart: n,
|
|
75
|
-
colStart: i,
|
|
76
|
-
colSpan: e.colSpan,
|
|
77
|
-
rowSpan: e.rowSpan
|
|
78
|
-
}, t[r].position)) {
|
|
79
|
-
o = !0;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
if (!o) return {
|
|
83
|
-
rowStart: n,
|
|
84
|
-
colStart: i,
|
|
85
|
-
colSpan: e.colSpan,
|
|
86
|
-
rowSpan: e.rowSpan
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
function u(e, t, n) {
|
|
92
|
-
return d(e, t, n, 10);
|
|
93
|
-
}
|
|
94
|
-
function d(e, t, n, r) {
|
|
95
|
-
if (r <= 0) return e;
|
|
96
|
-
let { result: i, changed: a } = f(e, t, n);
|
|
97
|
-
return a ? d(i, t, n, r - 1) : i;
|
|
98
|
-
}
|
|
99
|
-
function f(e, t, n) {
|
|
100
|
-
return e.slice().sort((e, t) => {
|
|
101
|
-
let n = e.position.rowStart - t.position.rowStart;
|
|
102
|
-
return n === 0 ? e.position.colStart - t.position.colStart : n;
|
|
103
|
-
}).reduce((e, n) => {
|
|
104
|
-
let r = [...t, ...e.result.filter((e) => e.id !== n.id)], i = p(n.position, r), a = i.rowStart !== n.position.rowStart;
|
|
105
|
-
return {
|
|
106
|
-
result: [...e.result, {
|
|
107
|
-
id: n.id,
|
|
108
|
-
position: i
|
|
109
|
-
}],
|
|
110
|
-
changed: e.changed || a
|
|
111
|
-
};
|
|
112
|
-
}, {
|
|
113
|
-
result: [],
|
|
114
|
-
changed: !1
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function p(e, t) {
|
|
118
|
-
if (e.rowStart <= 1) return e;
|
|
119
|
-
for (let n = 1; n < e.rowStart; n++) {
|
|
120
|
-
let r = !1;
|
|
121
|
-
for (let i = 0; i < t.length; i++) if (a({
|
|
122
|
-
...e,
|
|
123
|
-
rowStart: n
|
|
124
|
-
}, t[i].position)) {
|
|
125
|
-
r = !0;
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
if (!r) return {
|
|
129
|
-
...e,
|
|
130
|
-
rowStart: n
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return e;
|
|
134
|
-
}
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region libs/mintplayer-web-components/tile-manager/src/utils/grid-geometry.ts
|
|
137
|
-
function m(e) {
|
|
138
|
-
let t = e.width + e.gapX, n = e.height + e.gapY;
|
|
139
|
-
return !(t > 0) || !(n > 0) || !Number.isFinite(t) || !Number.isFinite(n) ? null : {
|
|
140
|
-
x: t,
|
|
141
|
-
y: n
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function h(e, t) {
|
|
145
|
-
return {
|
|
146
|
-
x: (e.colStart - 1) * (t.width + t.gapX),
|
|
147
|
-
y: (e.rowStart - 1) * (t.height + t.gapY)
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function g({ pointer: e, gridOrigin: t, pointerOffset: n }) {
|
|
151
|
-
return {
|
|
152
|
-
x: e.x - t.x - n.x,
|
|
153
|
-
y: e.y - t.y - n.y
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function _(e, t, n, r) {
|
|
157
|
-
let i = m(n);
|
|
158
|
-
if (!i) return null;
|
|
159
|
-
let a = g(e), o = Math.round(a.x / i.x) + 1, s = Math.round(a.y / i.y) + 1;
|
|
160
|
-
return {
|
|
161
|
-
colStart: Math.max(1, Math.min(o, r - t.colSpan + 1)),
|
|
162
|
-
rowStart: Math.max(1, s),
|
|
163
|
-
colSpan: t.colSpan,
|
|
164
|
-
rowSpan: t.rowSpan
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function v(e, t, n) {
|
|
168
|
-
let r = g(e), i = h(t, n);
|
|
169
|
-
return {
|
|
170
|
-
x: Math.round(r.x - i.x),
|
|
171
|
-
y: Math.round(r.y - i.y)
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function y(e, t, n, r, i, a) {
|
|
175
|
-
let o = m(i);
|
|
176
|
-
if (!o) return null;
|
|
177
|
-
let s = Math.round(e.x / o.x), c = Math.round(e.y / o.y);
|
|
178
|
-
return {
|
|
179
|
-
colSpan: t === "bottom" ? n.colSpan : Math.max(1, Math.min(n.colSpan + s, a - r + 1)),
|
|
180
|
-
rowSpan: t === "side" ? n.rowSpan : Math.max(1, n.rowSpan + c)
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
n`<!-- Tile shells are rendered dynamically by render(). This file exists so the
|
|
184
|
-
codegen-wc target produces a \`styles\` export from the sibling .scss; the
|
|
185
|
-
\`template\` export it generates is intentionally unused. -->`;
|
|
186
|
-
var b = i(":host {\n display: block;\n position: relative;\n box-sizing: border-box;\n width: 100%;\n contain: layout paint style;\n --bs-tile-radius: 0.5rem;\n --bs-tile-bg: var(--bs-body-bg, #fff);\n --bs-tile-border: var(--bs-border-color, #dee2e6);\n --bs-tile-shadow: var(--bs-box-shadow-sm, 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075));\n --bs-tile-handle-color: var(--bs-secondary, #6c757d);\n --bs-tile-blocked-color: var(--bs-danger, #dc3545);\n}\n\n.tile-grid {\n display: grid;\n grid-auto-rows: var(--mp-tile-row-height, 8rem);\n gap: var(--mp-tile-gap, 0.5rem);\n width: 100%;\n position: relative;\n}\n\n.tile {\n position: relative;\n display: flex;\n flex-direction: column;\n background: var(--bs-tile-bg);\n border: 1px solid var(--bs-tile-border);\n border-radius: var(--bs-tile-radius);\n box-shadow: var(--bs-tile-shadow);\n overflow: hidden;\n min-width: 0;\n min-height: 0;\n transition: transform 150ms cubic-bezier(0.2, 0, 0, 1);\n will-change: transform;\n}\n\n.tile[data-dragging=true] {\n z-index: 5;\n cursor: grabbing;\n box-shadow: var(--bs-box-shadow, 0 0.5rem 1rem rgba(0, 0, 0, 0.15));\n transition: none;\n}\n\n.tile[data-resizing=true] {\n z-index: 4;\n transition: width 150ms cubic-bezier(0.2, 0, 0, 1), height 150ms cubic-bezier(0.2, 0, 0, 1);\n}\n\n.tile[data-blocked=true] {\n outline: 2px solid var(--bs-tile-blocked-color);\n outline-offset: -2px;\n animation: tile-shake 200ms ease-in-out;\n}\n\n@keyframes tile-shake {\n 0%, 100% {\n transform: translateX(0);\n }\n 25% {\n transform: translateX(-3px);\n }\n 75% {\n transform: translateX(3px);\n }\n}\n.tile[data-pressing=true] {\n filter: brightness(0.96);\n transition: filter 100ms ease-out;\n}\n\n.tile__header-shell {\n flex: 0 0 auto;\n user-select: none;\n -webkit-user-select: none;\n -webkit-touch-callout: none;\n cursor: grab;\n}\n\n.tile__header-shell ::slotted(*) {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n padding: 0.5rem 0.75rem;\n font-size: 0.875rem;\n font-weight: 500;\n color: var(--bs-body-color, inherit);\n background: linear-gradient(to bottom, rgba(var(--bs-primary-rgb, 13, 110, 253), 0.1), rgba(var(--bs-primary-rgb, 13, 110, 253), 0.04));\n border-bottom: 1px solid var(--bs-border-color, #dee2e6);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n touch-action: none;\n user-select: none;\n -webkit-user-select: none;\n -webkit-touch-callout: none;\n}\n\n.tile[data-drag-mode=off] .tile__header-shell,\n.tile[data-locked-move=true] .tile__header-shell {\n cursor: default;\n}\n\n.tile__content-shell {\n flex: 1 1 auto;\n min-width: 0;\n min-height: 0;\n overflow: auto;\n}\n\n.tile__resize-side,\n.tile__resize-bottom,\n.tile__resize-corner {\n position: absolute;\n z-index: 2;\n background: transparent;\n touch-action: none;\n -webkit-user-select: none;\n user-select: none;\n opacity: 0;\n transition: opacity 120ms ease-out;\n}\n\n.tile:hover .tile__resize-side,\n.tile:hover .tile__resize-bottom,\n.tile:hover .tile__resize-corner,\n:host([resize-mode=always]) .tile__resize-side,\n:host([resize-mode=always]) .tile__resize-bottom,\n:host([resize-mode=always]) .tile__resize-corner {\n opacity: 1;\n}\n\n@media (pointer: coarse) {\n .tile__resize-side,\n .tile__resize-bottom,\n .tile__resize-corner {\n opacity: 1;\n }\n}\n.tile__resize-side {\n right: -2px;\n top: 25%;\n bottom: 25%;\n width: 6px;\n cursor: ew-resize;\n}\n\n.tile__resize-bottom {\n left: 25%;\n right: 25%;\n bottom: -2px;\n height: 6px;\n cursor: ns-resize;\n}\n\n.tile__resize-corner {\n right: -2px;\n bottom: -2px;\n width: 14px;\n height: 14px;\n cursor: nwse-resize;\n}\n\n.tile__resize-corner::before {\n content: \"\";\n position: absolute;\n right: 3px;\n bottom: 3px;\n width: 8px;\n height: 8px;\n border-right: 2px solid var(--bs-tile-handle-color);\n border-bottom: 2px solid var(--bs-tile-handle-color);\n border-bottom-right-radius: 2px;\n}\n\n:host([resize-mode=off]) .tile__resize-side,\n:host([resize-mode=off]) .tile__resize-bottom,\n:host([resize-mode=off]) .tile__resize-corner {\n display: none;\n}\n\n.tile[data-locked-resize=true] .tile__resize-side,\n.tile[data-locked-resize=true] .tile__resize-bottom,\n.tile[data-locked-resize=true] .tile__resize-corner {\n display: none;\n}\n\n.tile-grid__live-region,\n.tile-grid__sr-only {\n position: absolute;\n width: 1px;\n height: 1px;\n margin: -1px;\n padding: 0;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .tile {\n transition: none !important;\n }\n .tile[data-blocked=true] {\n animation: none;\n }\n}\n:host(:focus-visible) {\n outline: 2px solid var(--bs-primary, #0d6efd);\n outline-offset: 2px;\n}\n\n.tile:focus-visible {\n outline: 2px solid var(--bs-primary, #0d6efd);\n outline-offset: -2px;\n}"), x = "Press M to enter move mode. In move mode, arrow keys move the tile, Shift with arrow keys resize it, Enter commits, Escape cancels.", S = 0, C = 600, w = 10, T = 150, E = 5, D = class extends t {
|
|
187
|
-
constructor(...t) {
|
|
188
|
-
super(...t), this.tiles = [], this.columnCount = null, this.minColumnWidth = "200px", this.minRowHeight = "8rem", this.gap = "0.5rem", this.dragMode = "header", this.resizeMode = "hover", this.animateReflow = !0, this.label = null, this.gestureState = { kind: "idle" }, this.keyboardState = { kind: "idle" }, this.previewLayout = null, this.gestureKind = "idle", this.blocked = !1, this.effectiveColumnCount = 1, this.focusedTileId = null, this.liveAnnouncer = new e(this), this.instanceId = `mp-tile-manager-${++S}`, this.hostResizeObserver = null, this.flipPreviousRects = /* @__PURE__ */ new Map(), this.cellMetrics = {
|
|
189
|
-
width: 0,
|
|
190
|
-
height: 0,
|
|
191
|
-
gapX: 0,
|
|
192
|
-
gapY: 0
|
|
193
|
-
}, this.onWindowPointerMove = (e) => this.handlePointerMove(e), this.onWindowPointerUp = (e) => this.handlePointerUp(e), this.onWindowPointerCancel = (e) => this.handlePointerCancel(e), this.onWindowKeyDown = (e) => this.handleEscapeKey(e), this.onVisibilityChange = () => {
|
|
194
|
-
document.visibilityState === "hidden" && this.cancelGesture();
|
|
195
|
-
}, this.lastPointerPosition = null;
|
|
196
|
-
}
|
|
1
|
+
import { adoptLightStyles as e, installLightStyles as t } from "../light-dom/index.mjs";
|
|
2
|
+
import { MachineController as n, props as r } from "../machine/index.mjs";
|
|
3
|
+
import { LitElement as i, css as a, html as o } from "lit";
|
|
4
|
+
import { repeat as s } from "lit/directives/repeat.js";
|
|
5
|
+
import { styleMap as c } from "lit/directives/style-map.js";
|
|
6
|
+
import { DEFAULT_GAP as l, DEFAULT_MIN_COLUMN_WIDTH as u, TILE_MANAGER_SCOPE as d, TileFlip as f, TileManagerMachine as p, connect as m, gridPointer as h, readCellMetrics as g, tileManagerScopedStyles as _, withoutNarrowerLayouts as v } from "@mintplayer/ui-core/tile-manager";
|
|
7
|
+
//#region libs/mintplayer-web-components/tile-manager/src/components/mp-tile-manager.ts
|
|
8
|
+
var y = [
|
|
9
|
+
"tiles",
|
|
10
|
+
"layouts",
|
|
11
|
+
"breakpoints",
|
|
12
|
+
"stackBelow",
|
|
13
|
+
"maxColumns",
|
|
14
|
+
"minColumnWidth",
|
|
15
|
+
"minRowHeight",
|
|
16
|
+
"gap",
|
|
17
|
+
"dragMode",
|
|
18
|
+
"resizeMode",
|
|
19
|
+
"label",
|
|
20
|
+
"messages"
|
|
21
|
+
], b = 0, x = class extends i {
|
|
197
22
|
static {
|
|
198
|
-
this.styles =
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
"column-count",
|
|
204
|
-
"min-column-width",
|
|
205
|
-
"min-row-height",
|
|
206
|
-
"gap",
|
|
207
|
-
"drag-mode",
|
|
208
|
-
"resize-mode",
|
|
209
|
-
"animate-reflow",
|
|
210
|
-
"label"
|
|
211
|
-
];
|
|
23
|
+
this.styles = a`
|
|
24
|
+
:host {
|
|
25
|
+
display: block;
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
212
28
|
}
|
|
213
29
|
static {
|
|
214
30
|
this.properties = {
|
|
215
31
|
tiles: { attribute: !1 },
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
32
|
+
layouts: { attribute: !1 },
|
|
33
|
+
breakpoints: { attribute: !1 },
|
|
34
|
+
stackBelow: {
|
|
35
|
+
type: Number,
|
|
36
|
+
attribute: "stack-below"
|
|
37
|
+
},
|
|
38
|
+
maxColumns: {
|
|
39
|
+
type: Number,
|
|
40
|
+
attribute: "max-columns"
|
|
219
41
|
},
|
|
220
42
|
minColumnWidth: {
|
|
221
|
-
|
|
222
|
-
|
|
43
|
+
type: Number,
|
|
44
|
+
attribute: "min-column-width"
|
|
223
45
|
},
|
|
224
46
|
minRowHeight: {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
},
|
|
228
|
-
gap: {
|
|
229
|
-
attribute: "gap",
|
|
230
|
-
type: String
|
|
47
|
+
type: String,
|
|
48
|
+
attribute: "min-row-height"
|
|
231
49
|
},
|
|
50
|
+
gap: { type: Number },
|
|
232
51
|
dragMode: {
|
|
233
|
-
attribute: "drag-mode",
|
|
234
52
|
type: String,
|
|
53
|
+
attribute: "drag-mode",
|
|
235
54
|
reflect: !0
|
|
236
55
|
},
|
|
237
56
|
resizeMode: {
|
|
238
|
-
attribute: "resize-mode",
|
|
239
57
|
type: String,
|
|
58
|
+
attribute: "resize-mode",
|
|
240
59
|
reflect: !0
|
|
241
60
|
},
|
|
242
61
|
animateReflow: {
|
|
243
|
-
|
|
244
|
-
|
|
62
|
+
type: Boolean,
|
|
63
|
+
attribute: "animate-reflow"
|
|
245
64
|
},
|
|
246
|
-
label: {
|
|
247
|
-
|
|
248
|
-
type: String
|
|
249
|
-
},
|
|
250
|
-
previewLayout: { state: !0 },
|
|
251
|
-
gestureKind: { state: !0 },
|
|
252
|
-
blocked: { state: !0 },
|
|
253
|
-
focusedTileId: { state: !0 }
|
|
65
|
+
label: { type: String },
|
|
66
|
+
messages: { attribute: !1 }
|
|
254
67
|
};
|
|
255
68
|
}
|
|
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
|
-
} : null, d = [
|
|
285
|
-
`grid-column: ${t.colStart} / span ${t.colSpan}`,
|
|
286
|
-
`grid-row: ${t.rowStart} / span ${t.rowSpan}`,
|
|
287
|
-
c ? `transform: ${c}` : "",
|
|
288
|
-
u ? `width: ${u.width}px` : "",
|
|
289
|
-
u ? `height: ${u.height}px` : ""
|
|
290
|
-
].filter(Boolean).join("; "), f = this.resolveFocusableTileId() === e.id;
|
|
291
|
-
return n`
|
|
292
|
-
<div
|
|
293
|
-
class="tile"
|
|
294
|
-
role="button"
|
|
295
|
-
tabindex=${f ? "0" : "-1"}
|
|
296
|
-
aria-describedby=${this.instructionsId}
|
|
297
|
-
aria-pressed=${this.keyboardState.kind === "move" && this.keyboardState.tileId === e.id ? "true" : "false"}
|
|
298
|
-
data-tile-id=${e.id}
|
|
299
|
-
data-dragging=${i ? "true" : "false"}
|
|
300
|
-
data-resizing=${a ? "true" : "false"}
|
|
301
|
-
data-blocked=${o ? "true" : "false"}
|
|
302
|
-
data-pressing=${s ? "true" : "false"}
|
|
303
|
-
data-drag-mode=${this.dragMode}
|
|
304
|
-
data-locked-move=${e.disableMove ? "true" : "false"}
|
|
305
|
-
data-locked-resize=${e.disableResize ? "true" : "false"}
|
|
306
|
-
aria-label=${e.label ?? r}
|
|
307
|
-
style=${d}
|
|
308
|
-
@pointerdown=${(t) => this.onTilePointerDown(t, e)}
|
|
309
|
-
@keydown=${(t) => this.onTileKeyDown(t, e)}
|
|
310
|
-
@focus=${() => this.onTileFocus(e)}
|
|
311
|
-
>
|
|
312
|
-
<div class="tile__header-shell">
|
|
313
|
-
<slot name=${`${e.id}-header`}></slot>
|
|
314
|
-
</div>
|
|
315
|
-
<div class="tile__content-shell">
|
|
316
|
-
<slot name=${`${e.id}-content`}></slot>
|
|
317
|
-
</div>
|
|
318
|
-
${e.disableResize || this.resizeMode === "off" ? r : n`
|
|
319
|
-
<div class="tile__resize-side" data-resize="side"
|
|
320
|
-
@pointerdown=${(t) => this.onResizeHandlePointerDown(t, e, "side")}></div>
|
|
321
|
-
<div class="tile__resize-bottom" data-resize="bottom"
|
|
322
|
-
@pointerdown=${(t) => this.onResizeHandlePointerDown(t, e, "bottom")}></div>
|
|
323
|
-
<div class="tile__resize-corner" data-resize="corner"
|
|
324
|
-
@pointerdown=${(t) => this.onResizeHandlePointerDown(t, e, "corner")}></div>
|
|
325
|
-
`}
|
|
326
|
-
</div>
|
|
327
|
-
`;
|
|
328
|
-
}
|
|
329
|
-
computeGridStyle() {
|
|
330
|
-
return [
|
|
331
|
-
`grid-template-columns: ${this.columnCount && this.columnCount > 0 ? `repeat(${this.columnCount}, minmax(0, 1fr))` : `repeat(auto-fit, minmax(${this.minColumnWidth}, 1fr))`}`,
|
|
332
|
-
`--mp-tile-row-height: ${this.minRowHeight}`,
|
|
333
|
-
`--mp-tile-gap: ${this.gap}`
|
|
334
|
-
].join("; ");
|
|
69
|
+
#e;
|
|
70
|
+
#t;
|
|
71
|
+
#n;
|
|
72
|
+
#r;
|
|
73
|
+
#i;
|
|
74
|
+
#a;
|
|
75
|
+
#o;
|
|
76
|
+
#s;
|
|
77
|
+
#c;
|
|
78
|
+
#l;
|
|
79
|
+
#u;
|
|
80
|
+
constructor() {
|
|
81
|
+
super(), this.tiles = [], this.layouts = {}, this.breakpoints = null, this.stackBelow = null, this.maxColumns = 6, this.minColumnWidth = u, this.minRowHeight = "8rem", this.gap = l, this.dragMode = "header", this.resizeMode = "hover", this.animateReflow = !0, this.label = null, this.messages = {}, this.machine = new p({ vibrate: (e) => navigator.vibrate?.(e) }), this.#e = new n(this, this.machine), this.#t = `mp-tile-manager-${++b}`, this.#n = new f(), this.#r = !1, this.#i = null, this.#a = 0, this.#o = null, this.#s = 0, this.#c = 0, this.#l = null, this.#u = () => {
|
|
82
|
+
document.visibilityState === "hidden" && this.machine.cancelGesture();
|
|
83
|
+
}, this.machine.subscribe(() => {
|
|
84
|
+
let e = this.machine.rendered;
|
|
85
|
+
if (e === this.#i) return;
|
|
86
|
+
this.#i = e;
|
|
87
|
+
let t = this.#d;
|
|
88
|
+
t && this.animateReflow && this.machine.snapshot.measured && (this.#n.first(t), this.#r = !0);
|
|
89
|
+
}), this.machine.onEvent((e) => {
|
|
90
|
+
let { type: t, ...n } = e;
|
|
91
|
+
this.dispatchEvent(new CustomEvent(t, {
|
|
92
|
+
detail: n,
|
|
93
|
+
bubbles: !1,
|
|
94
|
+
composed: !0
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
335
97
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (this.columnCount && this.columnCount > 0) this.effectiveColumnCount = this.columnCount;
|
|
344
|
-
else {
|
|
345
|
-
let e = t.gridTemplateColumns.split(/\s+/).filter(Boolean);
|
|
346
|
-
this.effectiveColumnCount = Math.max(1, e.length);
|
|
347
|
-
}
|
|
348
|
-
let n = e.getBoundingClientRect(), r = this.effectiveColumnCount, i = parseFloat(t.columnGap) || 0, a = parseFloat(t.rowGap) || 0, o = (n.width - (r - 1) * i) / r, s = parseFloat(t.gridAutoRows) || n.width / r;
|
|
349
|
-
this.cellMetrics = {
|
|
350
|
-
width: o,
|
|
351
|
-
height: s,
|
|
352
|
-
gapX: i,
|
|
353
|
-
gapY: a
|
|
98
|
+
captureLayout() {
|
|
99
|
+
return {
|
|
100
|
+
columnCount: this.machine.snapshot.columnCount,
|
|
101
|
+
layout: this.machine.rendered.map((e) => ({
|
|
102
|
+
id: e.id,
|
|
103
|
+
position: { ...e.position }
|
|
104
|
+
}))
|
|
354
105
|
};
|
|
355
106
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (t.kind !== "drag" || t.tileId !== e) return null;
|
|
359
|
-
let n = this.lastPointerPosition;
|
|
360
|
-
if (!n) return null;
|
|
361
|
-
let r = this.shadowRoot?.querySelector(".tile-grid");
|
|
362
|
-
if (!r) return null;
|
|
363
|
-
let i = v(this.dragPointer(r, t, n), t.currentRect, this.cellMetrics);
|
|
364
|
-
return `translate(${i.x}px, ${i.y}px)`;
|
|
107
|
+
resetLayout(e) {
|
|
108
|
+
this.machine.resetLayout(e);
|
|
365
109
|
}
|
|
366
|
-
|
|
367
|
-
let
|
|
368
|
-
return
|
|
369
|
-
pointer: n,
|
|
370
|
-
gridOrigin: {
|
|
371
|
-
x: r.left,
|
|
372
|
-
y: r.top
|
|
373
|
-
},
|
|
374
|
-
pointerOffset: {
|
|
375
|
-
x: t.pointerOffset.dx,
|
|
376
|
-
y: t.pointerOffset.dy
|
|
377
|
-
}
|
|
378
|
-
};
|
|
110
|
+
get isGestureActive() {
|
|
111
|
+
let e = this.machine.snapshot.gesture.kind;
|
|
112
|
+
return e === "drag" || e === "resize";
|
|
379
113
|
}
|
|
380
114
|
connectedCallback() {
|
|
381
|
-
super.connectedCallback(), document.addEventListener("visibilitychange", this.
|
|
115
|
+
super.connectedCallback(), this.renderRoot instanceof ShadowRoot && (this.#l?.(), this.#l = e(this.renderRoot)), document.addEventListener("visibilitychange", this.#u), this.hasUpdated && this.#f();
|
|
382
116
|
}
|
|
383
117
|
disconnectedCallback() {
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
firstUpdated() {
|
|
387
|
-
this.updateLayoutCache();
|
|
388
|
-
let e = !1;
|
|
389
|
-
this.hostResizeObserver = new ResizeObserver(() => {
|
|
390
|
-
e || (e = !0, requestAnimationFrame(() => {
|
|
391
|
-
e = !1, this.updateLayoutCache();
|
|
392
|
-
}));
|
|
393
|
-
}), this.hostResizeObserver.observe(this);
|
|
118
|
+
super.disconnectedCallback(), this.#l?.(), this.#l = null, document.removeEventListener("visibilitychange", this.#u), this.#o?.disconnect(), this.#o = null, cancelAnimationFrame(this.#s), this.#s = 0, this.machine.cancelGesture();
|
|
394
119
|
}
|
|
395
|
-
|
|
396
|
-
|
|
120
|
+
get #d() {
|
|
121
|
+
return this.renderRoot.querySelector(".tile-grid");
|
|
397
122
|
}
|
|
398
123
|
willUpdate(e) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
let t = this.shadowRoot?.querySelector(".tile-grid");
|
|
404
|
-
t && (this.flipPreviousRects.clear(), t.querySelectorAll(".tile").forEach((e) => {
|
|
405
|
-
let t = e.dataset.tileId;
|
|
406
|
-
t && this.flipPreviousRects.set(t, e.getBoundingClientRect());
|
|
407
|
-
}));
|
|
408
|
-
}
|
|
409
|
-
updated(e) {
|
|
410
|
-
if ((e.has("columnCount") || e.has("minColumnWidth") || e.has("minRowHeight") || e.has("gap")) && this.updateLayoutCache(), !this.shouldAnimate() || this.flipPreviousRects.size === 0) return;
|
|
411
|
-
let t = this.shadowRoot?.querySelector(".tile-grid");
|
|
412
|
-
if (!t) return;
|
|
413
|
-
let n = this.activeTileId();
|
|
414
|
-
t.querySelectorAll(".tile").forEach((e) => {
|
|
415
|
-
let t = e.dataset.tileId;
|
|
416
|
-
if (!t || t === n) return;
|
|
417
|
-
let r = this.flipPreviousRects.get(t);
|
|
418
|
-
if (!r) return;
|
|
419
|
-
let i = e.getBoundingClientRect(), a = r.left - i.left, o = r.top - i.top;
|
|
420
|
-
if (Math.abs(a) < .5 && Math.abs(o) < .5) return;
|
|
421
|
-
let s = e.style.transition;
|
|
422
|
-
e.style.transition = "none", e.style.transform = `translate(${a}px, ${o}px)`, requestAnimationFrame(() => {
|
|
423
|
-
e.style.transition = s, e.style.transform = "";
|
|
424
|
-
});
|
|
425
|
-
}), this.flipPreviousRects.clear();
|
|
426
|
-
}
|
|
427
|
-
shouldAnimate() {
|
|
428
|
-
return !this.animateReflow || typeof window > "u" || typeof window.matchMedia != "function" ? !1 : !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
429
|
-
}
|
|
430
|
-
onTilePointerDown(e, t) {
|
|
431
|
-
(e.button === 0 || e.pointerType !== "mouse") && this.gestureState.kind === "idle" && (this.dragMode === "off" || t.disableMove || (this.dragMode !== "header" && e.pointerType !== "touch" || e.composedPath().some((e) => e instanceof HTMLElement && e.classList?.contains("tile__header-shell"))) && (e.pointerType === "touch" ? this.armTouchDrag(e, t) : this.armPointerDrag(e, t)));
|
|
432
|
-
}
|
|
433
|
-
onResizeHandlePointerDown(e, t, n) {
|
|
434
|
-
(e.button === 0 || e.pointerType !== "mouse") && (t.disableResize || this.resizeMode === "off" || this.gestureState.kind === "idle" && (e.stopPropagation(), e.preventDefault(), this.beginResize(e, t, n)));
|
|
435
|
-
}
|
|
436
|
-
armPointerDrag(e, t) {
|
|
437
|
-
let n = e.clientX, r = e.clientY, i = (o) => {
|
|
438
|
-
if (o.pointerId !== e.pointerId) return;
|
|
439
|
-
let s = o.clientX - n, c = o.clientY - r;
|
|
440
|
-
Math.hypot(s, c) >= E && (window.removeEventListener("pointermove", i), window.removeEventListener("pointerup", a), window.removeEventListener("pointercancel", a), this.beginDrag(o, t));
|
|
441
|
-
}, a = (t) => {
|
|
442
|
-
t.pointerId === e.pointerId && (window.removeEventListener("pointermove", i), window.removeEventListener("pointerup", a), window.removeEventListener("pointercancel", a));
|
|
443
|
-
};
|
|
444
|
-
window.addEventListener("pointermove", i), window.addEventListener("pointerup", a), window.addEventListener("pointercancel", a);
|
|
124
|
+
let t = y.filter((t) => e.has(t));
|
|
125
|
+
t.length && this.machine.setInputs(Object.fromEntries(t.map((e) => [e, this[e]])));
|
|
445
126
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
this.beginDragFromTouchArm(t, n, r, i);
|
|
456
|
-
}
|
|
457
|
-
}, C);
|
|
458
|
-
this.gestureState = {
|
|
459
|
-
kind: "arming-touch-drag",
|
|
460
|
-
pointerId: i,
|
|
461
|
-
tileId: t.id,
|
|
462
|
-
startX: n,
|
|
463
|
-
startY: r,
|
|
464
|
-
timer: o,
|
|
465
|
-
pressingTimer: a
|
|
466
|
-
}, this.gestureKind = "arming-touch-drag";
|
|
467
|
-
let s = (e) => {
|
|
468
|
-
if (e.pointerId !== i || this.gestureState.kind !== "arming-touch-drag") return;
|
|
469
|
-
let t = e.clientX - n, a = e.clientY - r;
|
|
470
|
-
Math.hypot(t, a) > w && (this.cleanupTouchArming(), window.removeEventListener("pointermove", s), window.removeEventListener("pointerup", c), window.removeEventListener("pointercancel", c));
|
|
471
|
-
}, c = (e) => {
|
|
472
|
-
e.pointerId === i && (this.gestureState.kind === "arming-touch-drag" && this.cleanupTouchArming(), window.removeEventListener("pointermove", s), window.removeEventListener("pointerup", c), window.removeEventListener("pointercancel", c));
|
|
473
|
-
};
|
|
474
|
-
window.addEventListener("pointermove", s), window.addEventListener("pointerup", c), window.addEventListener("pointercancel", c);
|
|
475
|
-
}
|
|
476
|
-
cleanupTouchArming() {
|
|
477
|
-
if (this.gestureState.kind !== "arming-touch-drag") return;
|
|
478
|
-
let { timer: e, pressingTimer: t } = this.gestureState;
|
|
479
|
-
e !== null && window.clearTimeout(e), t !== null && window.clearTimeout(t), this.gestureState = { kind: "idle" }, this.gestureKind = "idle", this.requestUpdate();
|
|
480
|
-
}
|
|
481
|
-
beginDragFromTouchArm(e, t, n, r) {
|
|
482
|
-
this.startDrag(e, r, t, n) && this.requestUpdate();
|
|
483
|
-
}
|
|
484
|
-
beginDrag(e, t) {
|
|
485
|
-
this.startDrag(t, e.pointerId, e.clientX, e.clientY) && this.runPackerForCurrentGesture();
|
|
486
|
-
}
|
|
487
|
-
startDrag(e, t, n, r) {
|
|
488
|
-
this.updateLayoutCache();
|
|
489
|
-
let i = this.shadowRoot?.querySelector(".tile-grid");
|
|
490
|
-
if (!i) return !1;
|
|
491
|
-
let a = i.getBoundingClientRect(), o = h(e.position, this.cellMetrics);
|
|
492
|
-
return this.gestureState = {
|
|
493
|
-
kind: "drag",
|
|
494
|
-
pointerId: t,
|
|
495
|
-
tileId: e.id,
|
|
496
|
-
pointerOffset: {
|
|
497
|
-
dx: n - (a.left + o.x),
|
|
498
|
-
dy: r - (a.top + o.y)
|
|
499
|
-
},
|
|
500
|
-
currentRect: { ...e.position },
|
|
501
|
-
blocked: !1
|
|
502
|
-
}, this.gestureKind = "drag", this.lastPointerPosition = {
|
|
503
|
-
x: n,
|
|
504
|
-
y: r
|
|
505
|
-
}, this.attachWindowListeners(), this.announceDragBegin(e), !0;
|
|
506
|
-
}
|
|
507
|
-
beginResize(e, t, n) {
|
|
508
|
-
this.gestureState = {
|
|
509
|
-
kind: "resize",
|
|
510
|
-
pointerId: e.pointerId,
|
|
511
|
-
tileId: t.id,
|
|
512
|
-
mode: n,
|
|
513
|
-
startPointer: {
|
|
514
|
-
x: e.clientX,
|
|
515
|
-
y: e.clientY
|
|
516
|
-
},
|
|
517
|
-
startSpans: {
|
|
518
|
-
colSpan: t.position.colSpan,
|
|
519
|
-
rowSpan: t.position.rowSpan
|
|
520
|
-
},
|
|
521
|
-
currentRect: { ...t.position },
|
|
522
|
-
blocked: !1
|
|
523
|
-
}, this.gestureKind = "resize", this.lastPointerPosition = {
|
|
524
|
-
x: e.clientX,
|
|
525
|
-
y: e.clientY
|
|
526
|
-
}, this.attachWindowListeners(), this.announceResizeBegin(t), this.runPackerForCurrentGesture();
|
|
527
|
-
}
|
|
528
|
-
announceDragBegin(e) {
|
|
529
|
-
let t = e.label ?? `tile at row ${e.position.rowStart}, column ${e.position.colStart}`;
|
|
530
|
-
this.liveAnnouncer.announce(`Dragging ${t}.`);
|
|
531
|
-
}
|
|
532
|
-
announceResizeBegin(e) {
|
|
533
|
-
let t = e.label ?? `tile at row ${e.position.rowStart}, column ${e.position.colStart}`;
|
|
534
|
-
this.liveAnnouncer.announce(`Resizing ${t}.`);
|
|
535
|
-
}
|
|
536
|
-
attachWindowListeners() {
|
|
537
|
-
window.addEventListener("pointermove", this.onWindowPointerMove), window.addEventListener("pointerup", this.onWindowPointerUp), window.addEventListener("pointercancel", this.onWindowPointerCancel), window.addEventListener("keydown", this.onWindowKeyDown);
|
|
538
|
-
}
|
|
539
|
-
detachWindowListeners() {
|
|
540
|
-
window.removeEventListener("pointermove", this.onWindowPointerMove), window.removeEventListener("pointerup", this.onWindowPointerUp), window.removeEventListener("pointercancel", this.onWindowPointerCancel), window.removeEventListener("keydown", this.onWindowKeyDown);
|
|
541
|
-
}
|
|
542
|
-
handleEscapeKey(e) {
|
|
543
|
-
e.key === "Escape" && this.gestureState.kind !== "idle" && (e.preventDefault(), this.cancelGesture());
|
|
544
|
-
}
|
|
545
|
-
handlePointerMove(e) {
|
|
546
|
-
let t = this.gestureState;
|
|
547
|
-
t.kind !== "idle" && t.kind !== "arming-touch-drag" && e.pointerId === t.pointerId && (this.lastPointerPosition = {
|
|
548
|
-
x: e.clientX,
|
|
549
|
-
y: e.clientY
|
|
550
|
-
}, this.runPackerForCurrentGesture());
|
|
551
|
-
}
|
|
552
|
-
handlePointerUp(e) {
|
|
553
|
-
let t = this.gestureState;
|
|
554
|
-
t.kind !== "idle" && t.kind !== "arming-touch-drag" && e.pointerId === t.pointerId && (t.blocked ? this.cancelGesture("blocked") : this.commitGesture());
|
|
555
|
-
}
|
|
556
|
-
handlePointerCancel(e) {
|
|
557
|
-
let t = this.gestureState;
|
|
558
|
-
t.kind !== "idle" && (t.kind === "arming-touch-drag" || e.pointerId === t.pointerId) && this.cancelGesture();
|
|
559
|
-
}
|
|
560
|
-
runPackerForCurrentGesture() {
|
|
561
|
-
let e = this.gestureState;
|
|
562
|
-
if (e.kind !== "drag" && e.kind !== "resize") return;
|
|
563
|
-
let t = this.tiles.find((t) => t.id === e.tileId);
|
|
564
|
-
if (!t) {
|
|
565
|
-
this.cancelGesture();
|
|
566
|
-
return;
|
|
127
|
+
firstUpdated() {
|
|
128
|
+
this.#f();
|
|
129
|
+
}
|
|
130
|
+
updated() {
|
|
131
|
+
let e = this.machine.snapshot, t = this.#d;
|
|
132
|
+
if (this.#r && t && (this.#r = !1, this.#n.play(t, e.gesture.kind === "drag" ? e.gesture.tileId : null)), e.focusRequest && e.focusRequest.seq !== this.#a) {
|
|
133
|
+
this.#a = e.focusRequest.seq;
|
|
134
|
+
let t = e.focusRequest.tileId;
|
|
135
|
+
Array.from(this.renderRoot.querySelectorAll("[data-tile-id]")).find((e) => e.dataset.tileId === t)?.focus();
|
|
567
136
|
}
|
|
568
|
-
let n = e.kind === "drag" ? this.computeDragRect(e, t) : this.computeResizeRect(e, t);
|
|
569
|
-
if (!n) return;
|
|
570
|
-
e.currentRect = n;
|
|
571
|
-
let r = this.effectiveColumnCount, i = o(this.tiles.map((e) => ({
|
|
572
|
-
id: e.id,
|
|
573
|
-
position: e.position,
|
|
574
|
-
locked: !!e.disableMove
|
|
575
|
-
})), {
|
|
576
|
-
id: t.id,
|
|
577
|
-
rect: n
|
|
578
|
-
}, r);
|
|
579
|
-
this.previewLayout = i.layout;
|
|
580
|
-
let a = e.blocked;
|
|
581
|
-
e.blocked = i.blocked, i.blocked && !a && this.liveAnnouncer.announce("Move blocked by a locked tile."), this.blocked = i.blocked, this.requestUpdate();
|
|
582
137
|
}
|
|
583
|
-
|
|
584
|
-
let
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
computeResizeRect(e, t) {
|
|
590
|
-
let n = this.lastPointerPosition;
|
|
591
|
-
if (!n) return null;
|
|
592
|
-
let r = y({
|
|
593
|
-
x: n.x - e.startPointer.x,
|
|
594
|
-
y: n.y - e.startPointer.y
|
|
595
|
-
}, e.mode, e.startSpans, t.position.colStart, this.cellMetrics, this.effectiveColumnCount);
|
|
596
|
-
return r ? {
|
|
597
|
-
colStart: t.position.colStart,
|
|
598
|
-
rowStart: t.position.rowStart,
|
|
599
|
-
...r
|
|
600
|
-
} : null;
|
|
601
|
-
}
|
|
602
|
-
commitGesture() {
|
|
603
|
-
let e = this.gestureState;
|
|
604
|
-
if (e.kind !== "drag" && e.kind !== "resize") return;
|
|
605
|
-
let t = this.previewLayout;
|
|
606
|
-
if (!t) {
|
|
607
|
-
this.cleanupGesture();
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
let n = new Map(this.tiles.map((e) => [e.id, e.position])), r = this.tiles.map((e) => {
|
|
611
|
-
let n = t.find((t) => t.id === e.id);
|
|
612
|
-
return n ? {
|
|
613
|
-
...e,
|
|
614
|
-
position: n.position
|
|
615
|
-
} : e;
|
|
616
|
-
});
|
|
617
|
-
this.tiles = r, t.forEach((e) => {
|
|
618
|
-
let t = n.get(e.id);
|
|
619
|
-
(!t || !this.positionsEqual(t, e.position)) && this.dispatchEvent(new CustomEvent("tilepositionchange", {
|
|
620
|
-
detail: {
|
|
621
|
-
id: e.id,
|
|
622
|
-
position: e.position
|
|
623
|
-
},
|
|
624
|
-
bubbles: !1,
|
|
625
|
-
composed: !0
|
|
138
|
+
#f() {
|
|
139
|
+
let e = this.#d;
|
|
140
|
+
!e || this.#o || typeof ResizeObserver > "u" || (this.#o = new ResizeObserver((e) => {
|
|
141
|
+
let t = e[e.length - 1];
|
|
142
|
+
this.#c = t.contentBoxSize?.[0]?.inlineSize ?? t.contentRect.width, !this.#s && (this.#s = requestAnimationFrame(() => {
|
|
143
|
+
this.#s = 0, this.machine.measure(this.#c);
|
|
626
144
|
}));
|
|
627
|
-
}), this.
|
|
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
|
-
activeTileId() {
|
|
659
|
-
let e = this.gestureState;
|
|
660
|
-
return e.kind === "drag" || e.kind === "resize" || e.kind === "arming-touch-drag" ? e.tileId : null;
|
|
661
|
-
}
|
|
662
|
-
captureLayout() {
|
|
663
|
-
return this.tiles.map((e) => ({
|
|
664
|
-
id: e.id,
|
|
665
|
-
position: { ...e.position }
|
|
666
|
-
}));
|
|
667
|
-
}
|
|
668
|
-
get isGestureActive() {
|
|
669
|
-
return this.gestureState.kind === "drag" || this.gestureState.kind === "resize";
|
|
670
|
-
}
|
|
671
|
-
onTileKeyDown(e, t) {
|
|
672
|
-
let n = this.keyboardState;
|
|
673
|
-
if (n.kind === "idle") {
|
|
674
|
-
if (e.key === "m" || e.key === "M") {
|
|
675
|
-
if (t.disableMove && t.disableResize) return;
|
|
676
|
-
e.preventDefault(), this.keyboardState = {
|
|
677
|
-
kind: "move",
|
|
678
|
-
tileId: t.id,
|
|
679
|
-
entryTiles: this.tiles.map((e) => ({
|
|
680
|
-
...e,
|
|
681
|
-
position: { ...e.position }
|
|
682
|
-
}))
|
|
683
|
-
}, this.requestUpdate(), this.liveAnnouncer.announce("Move mode enabled. Use arrow keys to move, Shift with arrow keys to resize, Enter to commit, Escape to cancel.");
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
this.handleFocusNavigation(e, t);
|
|
687
|
-
} else if (n.tileId === t.id) {
|
|
688
|
-
if (e.key === "Escape" || e.key === "Enter") {
|
|
689
|
-
e.preventDefault();
|
|
690
|
-
let t = n.kind === "move" ? n.entryTiles : null;
|
|
691
|
-
this.keyboardState = { kind: "idle" }, this.requestUpdate(), e.key === "Escape" && t && (this.tiles = t, this.requestUpdate(), this.dispatchEvent(new CustomEvent("tilelayoutchange", {
|
|
692
|
-
detail: this.cloneSnapshot(t.map((e) => ({
|
|
693
|
-
id: e.id,
|
|
694
|
-
position: e.position
|
|
695
|
-
}))),
|
|
696
|
-
bubbles: !1,
|
|
697
|
-
composed: !0
|
|
698
|
-
}))), this.liveAnnouncer.announce(e.key === "Enter" ? "Move committed." : "Move cancelled and reverted.");
|
|
699
|
-
} else if (e.key.startsWith("Arrow")) {
|
|
700
|
-
e.preventDefault();
|
|
701
|
-
let n = e.shiftKey;
|
|
702
|
-
this.applyKeyboardStep(t, e.key, n);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
handleFocusNavigation(e, t) {
|
|
707
|
-
if (e.key !== "ArrowUp" && e.key !== "ArrowDown" && e.key !== "ArrowLeft" && e.key !== "ArrowRight" && e.key !== "Home" && e.key !== "End" || this.tiles.length <= 1) return !1;
|
|
708
|
-
let n = [...this.tiles].sort((e, t) => e.position.rowStart === t.position.rowStart ? e.position.colStart - t.position.colStart : e.position.rowStart - t.position.rowStart), r = n.findIndex((e) => e.id === t.id);
|
|
709
|
-
if (r < 0) return !1;
|
|
710
|
-
let i = r;
|
|
711
|
-
if (i = e.key === "Home" ? 0 : e.key === "End" ? n.length - 1 : e.key === "ArrowRight" || e.key === "ArrowDown" ? (r + 1) % n.length : (r - 1 + n.length) % n.length, i === r) return !0;
|
|
712
|
-
e.preventDefault();
|
|
713
|
-
let a = n[i];
|
|
714
|
-
return this.focusedTileId = a.id, this.requestUpdate(), queueMicrotask(() => {
|
|
715
|
-
(this.shadowRoot?.querySelector(`.tile[data-tile-id="${a.id}"]`))?.focus();
|
|
716
|
-
}), !0;
|
|
717
|
-
}
|
|
718
|
-
onTileFocus(e) {
|
|
719
|
-
this.focusedTileId !== e.id && (this.focusedTileId = e.id, this.requestUpdate());
|
|
720
|
-
}
|
|
721
|
-
resolveFocusableTileId() {
|
|
722
|
-
return this.tiles.length === 0 ? null : this.focusedTileId && this.tiles.some((e) => e.id === this.focusedTileId) ? this.focusedTileId : [...this.tiles].sort((e, t) => e.position.rowStart === t.position.rowStart ? e.position.colStart - t.position.colStart : e.position.rowStart - t.position.rowStart)[0]?.id ?? null;
|
|
145
|
+
}), this.#o.observe(e));
|
|
146
|
+
}
|
|
147
|
+
#p(e, t, n) {
|
|
148
|
+
let r = this.#d;
|
|
149
|
+
r && this.machine.pointerDown(t, n, h(e, r), g(r, this.machine.snapshot.columnCount)) === "capture" && (e.preventDefault(), e.currentTarget.closest("[data-tile-id]")?.setPointerCapture(e.pointerId));
|
|
150
|
+
}
|
|
151
|
+
#m(e) {
|
|
152
|
+
let t = this.#d;
|
|
153
|
+
t && this.machine.pointerMove(h(e, t)) === "capture" && e.currentTarget.setPointerCapture(e.pointerId);
|
|
154
|
+
}
|
|
155
|
+
#h(e, t) {
|
|
156
|
+
this.machine.keydown(t, e.key, { shift: e.shiftKey }) && e.preventDefault();
|
|
157
|
+
}
|
|
158
|
+
#g(e) {
|
|
159
|
+
return o`<div class="tile" ${r(e.attrs)} style=${c(e.style)}
|
|
160
|
+
@pointerdown=${(t) => this.#p(t, e.id, "body")}
|
|
161
|
+
@pointermove=${(e) => this.#m(e)}
|
|
162
|
+
@pointerup=${(e) => this.machine.pointerUp(e)}
|
|
163
|
+
@pointercancel=${(e) => this.machine.pointerCancel(e)}
|
|
164
|
+
@lostpointercapture=${(e) => this.machine.pointerCancel(e)}
|
|
165
|
+
@keydown=${(t) => this.#h(t, e.id)}
|
|
166
|
+
@focus=${() => this.machine.focus(e.id)}
|
|
167
|
+
@blur=${() => this.machine.blur(e.id)}>
|
|
168
|
+
<div class="tile-header" ${r(e.header)} @pointerdown=${(t) => this.#p(t, e.id, "header")}>
|
|
169
|
+
<slot name=${`${e.id}-header`}></slot>
|
|
170
|
+
</div>
|
|
171
|
+
<div class="tile-content" ${r(e.content)}><slot name=${`${e.id}-content`}></slot></div>
|
|
172
|
+
${e.grips.map((t) => o`<span class="tile-grip" ${r(t.attrs)}
|
|
173
|
+
@pointerdown=${(n) => this.#p(n, e.id, t.handle)}></span>`)}
|
|
174
|
+
</div>`;
|
|
723
175
|
}
|
|
724
|
-
|
|
725
|
-
let
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}, c = o(this.tiles.map((e) => ({
|
|
736
|
-
id: e.id,
|
|
737
|
-
position: e.position,
|
|
738
|
-
locked: !!e.disableMove
|
|
739
|
-
})), {
|
|
740
|
-
id: e.id,
|
|
741
|
-
rect: s
|
|
742
|
-
}, r);
|
|
743
|
-
if (c.blocked) {
|
|
744
|
-
this.liveAnnouncer.announce("Move blocked.");
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
let l = this.tiles.map((e) => {
|
|
748
|
-
let t = c.layout.find((t) => t.id === e.id);
|
|
749
|
-
return t ? {
|
|
750
|
-
...e,
|
|
751
|
-
position: t.position
|
|
752
|
-
} : e;
|
|
753
|
-
});
|
|
754
|
-
this.tiles = l, this.dispatchEvent(new CustomEvent("tilelayoutchange", {
|
|
755
|
-
detail: this.cloneSnapshot(c.layout),
|
|
756
|
-
bubbles: !1,
|
|
757
|
-
composed: !0
|
|
758
|
-
})), c.layout.forEach((e) => {
|
|
759
|
-
this.dispatchEvent(new CustomEvent("tilepositionchange", {
|
|
760
|
-
detail: {
|
|
761
|
-
id: e.id,
|
|
762
|
-
position: e.position
|
|
763
|
-
},
|
|
764
|
-
bubbles: !1,
|
|
765
|
-
composed: !0
|
|
766
|
-
}));
|
|
767
|
-
}), this.liveAnnouncer.announce(n ? `Tile resized to ${s.colSpan} columns by ${s.rowSpan} rows` : `Tile moved to row ${s.rowStart}, column ${s.colStart}`);
|
|
176
|
+
render() {
|
|
177
|
+
let e = m(this.#e.machine, this.#t);
|
|
178
|
+
return o`<div class="mp-tile-manager" ${r(e.board.attrs)} style=${c(e.board.style)}>
|
|
179
|
+
<div class="tile-container" ${r(e.container)}>
|
|
180
|
+
<div class="tile-grid" ${r(e.grid.attrs)} style=${c(e.grid.style)}>
|
|
181
|
+
${s(e.tiles, (e) => e.id, (e) => this.#g(e))}
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
${s(e.descriptions, (e) => e.key, (e) => o`<div class="tile-sr-only" ${r(e.attrs)}>${e.text}</div>`)}
|
|
185
|
+
<span class="tile-sr-only" ${r(e.live.attrs)}>${e.live.text}</span>
|
|
186
|
+
</div>`;
|
|
768
187
|
}
|
|
769
188
|
};
|
|
770
|
-
typeof customElements < "u" && !customElements.get("mp-tile-manager") && customElements.define("mp-tile-manager",
|
|
189
|
+
t(d, _), typeof customElements < "u" && !customElements.get("mp-tile-manager") && customElements.define("mp-tile-manager", x);
|
|
771
190
|
//#endregion
|
|
772
|
-
export {
|
|
191
|
+
export { x as MintTileManagerElement, v as withoutNarrowerLayouts };
|