@window-splitter/web-component 1.0.1
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/.storybook/main.js +27 -0
- package/.storybook/preview.css +23 -0
- package/.storybook/preview.js +15 -0
- package/.tshy/build.json +8 -0
- package/.tshy/commonjs.json +19 -0
- package/.tshy/esm.json +18 -0
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +24 -0
- package/LICENSE +7 -0
- package/README.md +59 -0
- package/dist/commonjs/index.d.ts +77 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +533 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/index.d.ts +77 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +527 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/eslint.config.mjs +10 -0
- package/package.json +84 -0
- package/src/WebComponentWindowSplitter.stories.ts +873 -0
- package/src/WebComponentWindowSplitter.test.ts +299 -0
- package/src/__snapshots__/WebComponentWindowSplitter.test.ts.snap +54 -0
- package/src/index.ts +660 -0
- package/tsconfig.json +8 -0
- package/vitest.config.js +17 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { SendFn, GroupMachineContextValue, Unit, OnResizeCallback } from "@window-splitter/state";
|
|
2
|
+
import { LitElement, PropertyValues } from "lit";
|
|
3
|
+
import { MoveEvents, SharedPanelProps } from "@window-splitter/interface";
|
|
4
|
+
export declare class PanelGroup extends LitElement {
|
|
5
|
+
private observer;
|
|
6
|
+
private cleanupChildrenObserver;
|
|
7
|
+
private groupId;
|
|
8
|
+
private context;
|
|
9
|
+
private send;
|
|
10
|
+
private isPrerender;
|
|
11
|
+
private state;
|
|
12
|
+
constructor();
|
|
13
|
+
getId(): string;
|
|
14
|
+
getPixelSizes(): number[];
|
|
15
|
+
getPercentageSizes(): number[];
|
|
16
|
+
getTemplate(): string;
|
|
17
|
+
getState(): "idle" | "dragging";
|
|
18
|
+
setSizes(updates: Unit[]): void;
|
|
19
|
+
private measureSize;
|
|
20
|
+
private measureChildren;
|
|
21
|
+
firstUpdated(): void;
|
|
22
|
+
disconnectedCallback(): void;
|
|
23
|
+
render(): import("lit").TemplateResult<1>;
|
|
24
|
+
}
|
|
25
|
+
export declare class Panel extends LitElement {
|
|
26
|
+
static observedContexts: string[];
|
|
27
|
+
onCollapseChange?: (newCollapsed: boolean, el: Panel) => void;
|
|
28
|
+
onResize?: OnResizeCallback;
|
|
29
|
+
collapseAnimation?: SharedPanelProps<boolean>["collapseAnimation"];
|
|
30
|
+
collapsed?: boolean;
|
|
31
|
+
min?: string;
|
|
32
|
+
max?: string;
|
|
33
|
+
default?: string;
|
|
34
|
+
collapsible?: string;
|
|
35
|
+
defaultCollapsed?: string;
|
|
36
|
+
collapsedSize?: string;
|
|
37
|
+
isStaticAtRest?: string;
|
|
38
|
+
context: GroupMachineContextValue;
|
|
39
|
+
send: SendFn;
|
|
40
|
+
isPrerender: boolean;
|
|
41
|
+
id: string;
|
|
42
|
+
constructor();
|
|
43
|
+
collapse(): void;
|
|
44
|
+
isCollapsed(): boolean;
|
|
45
|
+
expand(): void;
|
|
46
|
+
isExpanded(): boolean;
|
|
47
|
+
getPixelSize(): number;
|
|
48
|
+
getPercentageSize(): number;
|
|
49
|
+
setSize(size: Unit): void;
|
|
50
|
+
private initPanel;
|
|
51
|
+
private getPanelData;
|
|
52
|
+
private getAttributes;
|
|
53
|
+
protected firstUpdated(_changedProperties: PropertyValues): void;
|
|
54
|
+
disconnectedCallback(): void;
|
|
55
|
+
updated(changedProperties: PropertyValues): void;
|
|
56
|
+
render(): import("lit").TemplateResult<1>;
|
|
57
|
+
}
|
|
58
|
+
export declare class PanelResizer extends LitElement {
|
|
59
|
+
static observedContexts: string[];
|
|
60
|
+
onDragStart?: () => void;
|
|
61
|
+
onDrag?: (e: Parameters<NonNullable<MoveEvents["onMove"]>>[0]) => void;
|
|
62
|
+
onDragEnd?: () => void;
|
|
63
|
+
context: GroupMachineContextValue;
|
|
64
|
+
send: SendFn;
|
|
65
|
+
isPrerender: boolean;
|
|
66
|
+
size?: string;
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
constructor();
|
|
69
|
+
private initPanelResizer;
|
|
70
|
+
private getHandleData;
|
|
71
|
+
private getAttributes;
|
|
72
|
+
protected firstUpdated(_changedProperties: PropertyValues): void;
|
|
73
|
+
updated(changedProperties: PropertyValues): void;
|
|
74
|
+
disconnectedCallback(): void;
|
|
75
|
+
render(): import("lit").TemplateResult<1>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,MAAM,EACN,wBAAwB,EACxB,IAAI,EAQJ,gBAAgB,EASjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAEvD,OAAO,EAIL,UAAU,EACV,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAuCpC,qBAAa,UAAW,SAAQ,UAAU;IACxC,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,uBAAuB,CAAa;IAC5C,OAAO,CAAC,OAAO,CAAS;IAGxB,OAAO,CAAC,OAAO,CAA2B;IAE1C,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO,CAAC,WAAW,CAAQ;IAE3B,OAAO,CAAC,KAAK,CAAqB;;IAyD3B,KAAK;IAIL,aAAa;IAIb,kBAAkB;IAIlB,WAAW;IAOX,QAAQ;IAIR,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE;IAe/B,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,eAAe;IAyCvB,YAAY;IAYZ,oBAAoB;IAMpB,MAAM;CAYP;AAED,qBAAa,KAAM,SAAQ,UAAU;IACnC,MAAM,CAAC,gBAAgB,WAAY;IAE5B,gBAAgB,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,KAAK,IAAI,CAAC;IAC9D,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,iBAAiB,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,CAAC;IAG1E,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIjB,OAAO,EAAE,wBAAwB,CAAC;IAIlC,IAAI,EAAE,MAAM,CAAC;IAIb,WAAW,UAAQ;IAE1B,EAAE,EAAE,MAAM,CAAC;;IAUJ,QAAQ;IAKR,WAAW;IAMX,MAAM;IAKN,UAAU;IAMV,YAAY;IAIZ,iBAAiB;IAIjB,OAAO,CAAC,IAAI,EAAE,IAAI;IAIzB,OAAO,CAAC,SAAS;IAqBjB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,aAAa;IAqBrB,SAAS,CAAC,YAAY,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;IAgChE,oBAAoB,IAAI,IAAI;IAM5B,OAAO,CAAC,iBAAiB,EAAE,cAAc;IAyCzC,MAAM;CAGP;AAED,qBAAa,YAAa,SAAQ,UAAU;IAC1C,MAAM,CAAC,gBAAgB,WAAY;IAE5B,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACvE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IAIvB,OAAO,EAAE,wBAAwB,CAAC;IAGlC,IAAI,EAAE,MAAM,CAAC;IAGb,WAAW,UAAQ;IAG1B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,QAAQ,CAAC,EAAE,OAAO,CAAC;;IAUnB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,aAAa;IAyCrB,SAAS,CAAC,YAAY,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;IAqEhE,OAAO,CAAC,iBAAiB,EAAE,cAAc;IAczC,oBAAoB,IAAI,IAAI;IAM5B,MAAM;CAGP"}
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { groupMachine, initializePanel, initializePanelHandleData, buildTemplate, getCursor, isPanelData, getGroupSize, prepareSnapshot, getCollapsiblePanelForHandleId, getPanelPixelSize, getPanelPercentageSize, getPanelGroupPixelSizes, getPanelGroupPercentageSizes, prepareItems, haveConstraintsChangedForPanel, haveConstraintsChangedForPanelHandle, } from "@window-splitter/state";
|
|
8
|
+
import { html, LitElement } from "lit";
|
|
9
|
+
import { property } from "lit/decorators.js";
|
|
10
|
+
import { getPanelDomAttributes, getPanelResizerDomAttributes, move, } from "@window-splitter/interface";
|
|
11
|
+
import { consume, createContext, provide } from "@lit/context";
|
|
12
|
+
const isPrerenderContext = createContext("isPrerender");
|
|
13
|
+
const sendContext = createContext("send");
|
|
14
|
+
const contextContext = createContext("context");
|
|
15
|
+
const stateContext = createContext("state");
|
|
16
|
+
let _id = 0;
|
|
17
|
+
const getNextId = () => {
|
|
18
|
+
_id++;
|
|
19
|
+
return `${_id}`;
|
|
20
|
+
};
|
|
21
|
+
function updateAttributes(element,
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
attributes) {
|
|
24
|
+
for (const attr of Object.keys(attributes)) {
|
|
25
|
+
if (attr === "style") {
|
|
26
|
+
for (const style of Object.keys(attributes[attr])) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
element.style[style] = attributes[attr][style];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
element.setAttribute(attr, attributes[attr]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function isBooleanPropValue(value) {
|
|
38
|
+
if (value === "true" || value === "")
|
|
39
|
+
return true;
|
|
40
|
+
if (value === "false")
|
|
41
|
+
return false;
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
export class PanelGroup extends LitElement {
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
this.isPrerender = true;
|
|
48
|
+
this.observer = new ResizeObserver(() => { });
|
|
49
|
+
this.cleanupChildrenObserver = () => { };
|
|
50
|
+
const autosaveId = this.getAttribute("autosaveId");
|
|
51
|
+
const autosaveStrategy = this.getAttribute("autosaveStrategy") || "localStorage";
|
|
52
|
+
this.groupId = this.getAttribute("id") || autosaveId || getNextId();
|
|
53
|
+
let snapshot = this.getAttribute("snapshot");
|
|
54
|
+
if (!snapshot &&
|
|
55
|
+
typeof window !== "undefined" &&
|
|
56
|
+
autosaveId &&
|
|
57
|
+
autosaveStrategy === "localStorage") {
|
|
58
|
+
const localSnapshot = localStorage.getItem(autosaveId);
|
|
59
|
+
if (localSnapshot) {
|
|
60
|
+
snapshot = localSnapshot;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const [initialState, send, machineState] = groupMachine({
|
|
64
|
+
orientation: this.getAttribute("orientation") || "horizontal",
|
|
65
|
+
groupId: this.groupId,
|
|
66
|
+
autosaveStrategy,
|
|
67
|
+
...(snapshot ? prepareSnapshot(JSON.parse(snapshot)) : undefined),
|
|
68
|
+
}, (s) => {
|
|
69
|
+
const oldContext = this.context;
|
|
70
|
+
this.context = s;
|
|
71
|
+
if (oldContext.items.length !== s.items.length) {
|
|
72
|
+
this.cleanupChildrenObserver?.();
|
|
73
|
+
this.measureChildren();
|
|
74
|
+
}
|
|
75
|
+
this.requestUpdate();
|
|
76
|
+
});
|
|
77
|
+
this.state = machineState;
|
|
78
|
+
this.send = send;
|
|
79
|
+
this.context = initialState;
|
|
80
|
+
}
|
|
81
|
+
getId() {
|
|
82
|
+
return this.groupId;
|
|
83
|
+
}
|
|
84
|
+
getPixelSizes() {
|
|
85
|
+
return getPanelGroupPixelSizes(this.context);
|
|
86
|
+
}
|
|
87
|
+
getPercentageSizes() {
|
|
88
|
+
return getPanelGroupPercentageSizes(this.context);
|
|
89
|
+
}
|
|
90
|
+
getTemplate() {
|
|
91
|
+
return buildTemplate({
|
|
92
|
+
...this.context,
|
|
93
|
+
items: prepareItems(this.context),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getState() {
|
|
97
|
+
return this.state.current === "idle" ? "idle" : "dragging";
|
|
98
|
+
}
|
|
99
|
+
setSizes(updates) {
|
|
100
|
+
for (let index = 0; index < updates.length; index++) {
|
|
101
|
+
const item = this.context.items[index];
|
|
102
|
+
const update = updates[index];
|
|
103
|
+
if (item && isPanelData(item) && update) {
|
|
104
|
+
this.send({
|
|
105
|
+
type: "setPanelPixelSize",
|
|
106
|
+
panelId: item.id,
|
|
107
|
+
size: update,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
measureSize() {
|
|
113
|
+
if (this.observer) {
|
|
114
|
+
this.observer.disconnect();
|
|
115
|
+
}
|
|
116
|
+
this.observer = new ResizeObserver(([entry]) => {
|
|
117
|
+
if (!entry)
|
|
118
|
+
return;
|
|
119
|
+
if (entry.contentRect.width > 0 && entry.contentRect.height > 0) {
|
|
120
|
+
this.send({ type: "setSize", size: entry.contentRect });
|
|
121
|
+
this.measureChildren();
|
|
122
|
+
this.isPrerender = false;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
this.observer.observe(this.renderRoot.querySelector("div"));
|
|
126
|
+
}
|
|
127
|
+
measureChildren() {
|
|
128
|
+
if (this.cleanupChildrenObserver) {
|
|
129
|
+
this.cleanupChildrenObserver();
|
|
130
|
+
}
|
|
131
|
+
const childrenObserver = new ResizeObserver((childrenEntries) => {
|
|
132
|
+
const childrenSizes = {};
|
|
133
|
+
for (const childEntry of childrenEntries) {
|
|
134
|
+
const child = childEntry.target;
|
|
135
|
+
const childId = child.getAttribute("data-splitter-id");
|
|
136
|
+
const childSize = childEntry.borderBoxSize[0];
|
|
137
|
+
if (childId && childSize) {
|
|
138
|
+
childrenSizes[childId] = {
|
|
139
|
+
width: childSize.inlineSize,
|
|
140
|
+
height: childSize.blockSize,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
this.send({ type: "setActualItemsSize", childrenSizes });
|
|
145
|
+
});
|
|
146
|
+
if (!this.shadowRoot)
|
|
147
|
+
return;
|
|
148
|
+
const slot = this.shadowRoot.querySelector("slot");
|
|
149
|
+
if (!slot)
|
|
150
|
+
return;
|
|
151
|
+
const elements = slot.assignedElements();
|
|
152
|
+
for (const child of elements) {
|
|
153
|
+
childrenObserver.observe(child);
|
|
154
|
+
}
|
|
155
|
+
this.cleanupChildrenObserver = () => {
|
|
156
|
+
childrenObserver.disconnect();
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
firstUpdated() {
|
|
160
|
+
this.send({ type: "unlockGroup" });
|
|
161
|
+
if (this.observer) {
|
|
162
|
+
this.observer.disconnect();
|
|
163
|
+
}
|
|
164
|
+
this.measureSize();
|
|
165
|
+
this.setAttribute("data-panel-group-wrapper", "");
|
|
166
|
+
this.setAttribute("id", this.groupId);
|
|
167
|
+
}
|
|
168
|
+
disconnectedCallback() {
|
|
169
|
+
this.observer?.disconnect();
|
|
170
|
+
this.cleanupChildrenObserver?.();
|
|
171
|
+
this.send({ type: "lockGroup" });
|
|
172
|
+
}
|
|
173
|
+
render() {
|
|
174
|
+
const template = this.context.orientation === "horizontal"
|
|
175
|
+
? `grid-template-columns: ${buildTemplate(this.context)};`
|
|
176
|
+
: `grid-template-rows: ${buildTemplate(this.context)}`;
|
|
177
|
+
return html `
|
|
178
|
+
<div style="display: grid;height: 100%;${template}">
|
|
179
|
+
<slot></slot>
|
|
180
|
+
</div>
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
__decorate([
|
|
185
|
+
provide({ context: contextContext })
|
|
186
|
+
], PanelGroup.prototype, "context", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
provide({ context: sendContext })
|
|
189
|
+
], PanelGroup.prototype, "send", void 0);
|
|
190
|
+
__decorate([
|
|
191
|
+
provide({ context: isPrerenderContext })
|
|
192
|
+
], PanelGroup.prototype, "isPrerender", void 0);
|
|
193
|
+
__decorate([
|
|
194
|
+
provide({ context: stateContext })
|
|
195
|
+
], PanelGroup.prototype, "state", void 0);
|
|
196
|
+
export class Panel extends LitElement {
|
|
197
|
+
constructor() {
|
|
198
|
+
super();
|
|
199
|
+
this.isPrerender = true;
|
|
200
|
+
this.id ||= getNextId();
|
|
201
|
+
this.send = () => { };
|
|
202
|
+
this.context = {};
|
|
203
|
+
}
|
|
204
|
+
collapse() {
|
|
205
|
+
if (!this.getPanelData()?.collapsible)
|
|
206
|
+
return;
|
|
207
|
+
this.send({ type: "collapsePanel", panelId: this.id, controlled: true });
|
|
208
|
+
}
|
|
209
|
+
isCollapsed() {
|
|
210
|
+
return Boolean(this.getPanelData()?.collapsible && this.getPanelData()?.collapsed);
|
|
211
|
+
}
|
|
212
|
+
expand() {
|
|
213
|
+
if (!this.getPanelData()?.collapsible)
|
|
214
|
+
return;
|
|
215
|
+
this.send({ type: "expandPanel", panelId: this.id, controlled: true });
|
|
216
|
+
}
|
|
217
|
+
isExpanded() {
|
|
218
|
+
return Boolean(this.getPanelData()?.collapsible && !this.getPanelData()?.collapsed);
|
|
219
|
+
}
|
|
220
|
+
getPixelSize() {
|
|
221
|
+
return getPanelPixelSize(this.context, this.id);
|
|
222
|
+
}
|
|
223
|
+
getPercentageSize() {
|
|
224
|
+
return getPanelPercentageSize(this.context, this.id);
|
|
225
|
+
}
|
|
226
|
+
setSize(size) {
|
|
227
|
+
this.send({ type: "setPanelPixelSize", panelId: this.id, size });
|
|
228
|
+
}
|
|
229
|
+
initPanel() {
|
|
230
|
+
return initializePanel({
|
|
231
|
+
id: this.id,
|
|
232
|
+
min: this.getAttribute("min"),
|
|
233
|
+
max: this.getAttribute("max"),
|
|
234
|
+
collapsible: isBooleanPropValue(this.getAttribute("collapsible")),
|
|
235
|
+
collapsed: isBooleanPropValue(this.getAttribute("collapsed")),
|
|
236
|
+
collapsedSize: this.getAttribute("collapsedSize"),
|
|
237
|
+
onCollapseChange: this.onCollapseChange
|
|
238
|
+
? { current: (e) => this.onCollapseChange?.(e, this) }
|
|
239
|
+
: undefined,
|
|
240
|
+
collapseAnimation: this.collapseAnimation,
|
|
241
|
+
onResize: this.onResize ? { current: this.onResize } : undefined,
|
|
242
|
+
defaultCollapsed: isBooleanPropValue(this.getAttribute("defaultCollapsed")),
|
|
243
|
+
default: this.getAttribute("default"),
|
|
244
|
+
isStaticAtRest: isBooleanPropValue(this.getAttribute("isStaticAtRest")),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
getPanelData() {
|
|
248
|
+
return this.context?.items.find((item) => item.id === this.id);
|
|
249
|
+
}
|
|
250
|
+
getAttributes() {
|
|
251
|
+
return {
|
|
252
|
+
...getPanelDomAttributes({
|
|
253
|
+
groupId: this.context.groupId,
|
|
254
|
+
id: this.id,
|
|
255
|
+
collapsible: this.getAttribute("collapsible") === "true",
|
|
256
|
+
collapsed: this.getAttribute("collapsed") === "true"
|
|
257
|
+
? true
|
|
258
|
+
: this.getAttribute("collapsed") === "false"
|
|
259
|
+
? false
|
|
260
|
+
: undefined,
|
|
261
|
+
}),
|
|
262
|
+
style: {
|
|
263
|
+
minWidth: 0,
|
|
264
|
+
minHeight: 0,
|
|
265
|
+
overflow: "hidden",
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
firstUpdated(_changedProperties) {
|
|
270
|
+
updateAttributes(this, this.getAttributes());
|
|
271
|
+
if (this.getPanelData()) {
|
|
272
|
+
this.send?.({
|
|
273
|
+
type: "rebindPanelCallbacks",
|
|
274
|
+
data: {
|
|
275
|
+
id: this.id,
|
|
276
|
+
onCollapseChange: this.onCollapseChange
|
|
277
|
+
? { current: (e) => this.onCollapseChange?.(e, this) }
|
|
278
|
+
: undefined,
|
|
279
|
+
onResize: this.onResize ? { current: this.onResize } : undefined,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
if (this.isPrerender) {
|
|
285
|
+
this.send({ type: "registerPanel", data: this.initPanel() });
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
const groupElement = this.closest("window-splitter");
|
|
289
|
+
if (!groupElement)
|
|
290
|
+
return;
|
|
291
|
+
const order = Array.from(groupElement.children).indexOf(this);
|
|
292
|
+
if (typeof order !== "number")
|
|
293
|
+
return;
|
|
294
|
+
this.send({
|
|
295
|
+
type: "registerDynamicPanel",
|
|
296
|
+
data: { ...this.initPanel(), order },
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
disconnectedCallback() {
|
|
302
|
+
requestAnimationFrame(() => this.send({ type: "unregisterPanel", id: this.id }));
|
|
303
|
+
}
|
|
304
|
+
updated(changedProperties) {
|
|
305
|
+
if (changedProperties.has("collapsed")) {
|
|
306
|
+
const isControlled = this.getPanelData()?.collapseIsControlled;
|
|
307
|
+
if (isControlled) {
|
|
308
|
+
if (this.collapsed) {
|
|
309
|
+
this.send({
|
|
310
|
+
type: "collapsePanel",
|
|
311
|
+
panelId: this.id,
|
|
312
|
+
controlled: true,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
this.send({
|
|
317
|
+
type: "expandPanel",
|
|
318
|
+
panelId: this.id,
|
|
319
|
+
controlled: true,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (changedProperties.has("min") ||
|
|
325
|
+
changedProperties.has("max") ||
|
|
326
|
+
changedProperties.has("default") ||
|
|
327
|
+
changedProperties.has("collapsible") ||
|
|
328
|
+
changedProperties.has("collapsedSize") ||
|
|
329
|
+
changedProperties.has("defaultCollapsed") ||
|
|
330
|
+
changedProperties.has("isStaticAtRest")) {
|
|
331
|
+
const currentPanelData = this.getPanelData();
|
|
332
|
+
if (currentPanelData &&
|
|
333
|
+
haveConstraintsChangedForPanel(currentPanelData, this.initPanel())) {
|
|
334
|
+
this.send({ type: "updateConstraints", data: this.initPanel() });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
render() {
|
|
339
|
+
return html `<slot></slot>`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
Panel.observedContexts = ["send"];
|
|
343
|
+
__decorate([
|
|
344
|
+
property({ type: Boolean, reflect: true })
|
|
345
|
+
], Panel.prototype, "collapsed", void 0);
|
|
346
|
+
__decorate([
|
|
347
|
+
property({ type: String, reflect: true })
|
|
348
|
+
], Panel.prototype, "min", void 0);
|
|
349
|
+
__decorate([
|
|
350
|
+
property({ type: String, reflect: true })
|
|
351
|
+
], Panel.prototype, "max", void 0);
|
|
352
|
+
__decorate([
|
|
353
|
+
property({ type: String, reflect: true })
|
|
354
|
+
], Panel.prototype, "default", void 0);
|
|
355
|
+
__decorate([
|
|
356
|
+
property({ type: String, reflect: true })
|
|
357
|
+
], Panel.prototype, "collapsible", void 0);
|
|
358
|
+
__decorate([
|
|
359
|
+
property({ type: String, reflect: true })
|
|
360
|
+
], Panel.prototype, "defaultCollapsed", void 0);
|
|
361
|
+
__decorate([
|
|
362
|
+
property({ type: String, reflect: true })
|
|
363
|
+
], Panel.prototype, "collapsedSize", void 0);
|
|
364
|
+
__decorate([
|
|
365
|
+
property({ type: String, reflect: true })
|
|
366
|
+
], Panel.prototype, "isStaticAtRest", void 0);
|
|
367
|
+
__decorate([
|
|
368
|
+
consume({ context: contextContext }),
|
|
369
|
+
property({ attribute: false })
|
|
370
|
+
], Panel.prototype, "context", void 0);
|
|
371
|
+
__decorate([
|
|
372
|
+
consume({ context: sendContext }),
|
|
373
|
+
property({ attribute: false })
|
|
374
|
+
], Panel.prototype, "send", void 0);
|
|
375
|
+
__decorate([
|
|
376
|
+
consume({ context: isPrerenderContext }),
|
|
377
|
+
property({ attribute: false })
|
|
378
|
+
], Panel.prototype, "isPrerender", void 0);
|
|
379
|
+
export class PanelResizer extends LitElement {
|
|
380
|
+
constructor() {
|
|
381
|
+
super();
|
|
382
|
+
this.isPrerender = true;
|
|
383
|
+
this.id ||= getNextId();
|
|
384
|
+
this.send = () => { };
|
|
385
|
+
this.context = {};
|
|
386
|
+
}
|
|
387
|
+
initPanelResizer() {
|
|
388
|
+
return initializePanelHandleData({
|
|
389
|
+
id: this.id,
|
|
390
|
+
size: this.getAttribute("size") || "0px",
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
getHandleData() {
|
|
394
|
+
return this.context?.items.find((item) => item.id === this.id);
|
|
395
|
+
}
|
|
396
|
+
getAttributes() {
|
|
397
|
+
const handleIndex = this.context?.items.findIndex((item) => item.id === this.id);
|
|
398
|
+
const panelBeforeHandle = handleIndex !== undefined &&
|
|
399
|
+
isPanelData(this.context?.items[handleIndex - 1])
|
|
400
|
+
? this.context?.items[handleIndex - 1]
|
|
401
|
+
: undefined;
|
|
402
|
+
const handleData = this.getHandleData() || this.initPanelResizer();
|
|
403
|
+
return {
|
|
404
|
+
...getPanelResizerDomAttributes({
|
|
405
|
+
groupId: this.context?.groupId,
|
|
406
|
+
id: this.id,
|
|
407
|
+
orientation: this.context?.orientation || "horizontal",
|
|
408
|
+
isDragging: this.context?.activeDragHandleId === this.id,
|
|
409
|
+
activeDragHandleId: this.context?.activeDragHandleId,
|
|
410
|
+
disabled: this.disabled,
|
|
411
|
+
controlsId: panelBeforeHandle?.id,
|
|
412
|
+
min: panelBeforeHandle?.min,
|
|
413
|
+
max: panelBeforeHandle?.max,
|
|
414
|
+
currentValue: panelBeforeHandle?.currentValue,
|
|
415
|
+
groupSize: getGroupSize(this.context),
|
|
416
|
+
}),
|
|
417
|
+
tabIndex: this.disabled ? -1 : 0,
|
|
418
|
+
style: {
|
|
419
|
+
cursor: this.context ? getCursor(this.context) : undefined,
|
|
420
|
+
width: this.context?.orientation === "horizontal"
|
|
421
|
+
? `${handleData.size.value.toNumber()}px`
|
|
422
|
+
: "100%",
|
|
423
|
+
height: this.context?.orientation === "vertical"
|
|
424
|
+
? `${handleData.size.value.toNumber()}px`
|
|
425
|
+
: "100%",
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
firstUpdated(_changedProperties) {
|
|
430
|
+
const { moveProps } = move({
|
|
431
|
+
onMoveStart: () => {
|
|
432
|
+
this.send({
|
|
433
|
+
type: "dragHandleStart",
|
|
434
|
+
handleId: this.id,
|
|
435
|
+
});
|
|
436
|
+
this.onDragStart?.();
|
|
437
|
+
document.body.style.cursor = getCursor(this.context) || "auto";
|
|
438
|
+
},
|
|
439
|
+
onMove: (e) => {
|
|
440
|
+
this.send({
|
|
441
|
+
type: "dragHandle",
|
|
442
|
+
handleId: this.id,
|
|
443
|
+
value: e,
|
|
444
|
+
});
|
|
445
|
+
this.onDrag?.(e);
|
|
446
|
+
},
|
|
447
|
+
onMoveEnd: () => {
|
|
448
|
+
this.send({ type: "dragHandleEnd", handleId: this.id });
|
|
449
|
+
this.onDragEnd?.();
|
|
450
|
+
document.body.style.cursor = "auto";
|
|
451
|
+
},
|
|
452
|
+
});
|
|
453
|
+
this.addEventListener("pointerdown", (e) => {
|
|
454
|
+
if (this.disabled)
|
|
455
|
+
return;
|
|
456
|
+
moveProps.onPointerDown(e);
|
|
457
|
+
});
|
|
458
|
+
this.addEventListener("keydown", (e) => {
|
|
459
|
+
moveProps.onKeyDown(e);
|
|
460
|
+
const collapsiblePanel = getCollapsiblePanelForHandleId(this.context, this.id);
|
|
461
|
+
if (e.key === "Enter" && collapsiblePanel) {
|
|
462
|
+
if (collapsiblePanel.collapsed) {
|
|
463
|
+
this.send({ type: "expandPanel", panelId: collapsiblePanel.id });
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
this.send({ type: "collapsePanel", panelId: collapsiblePanel.id });
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
updateAttributes(this, this.getAttributes());
|
|
471
|
+
if (!this.getHandleData()) {
|
|
472
|
+
if (this.isPrerender) {
|
|
473
|
+
this.send({
|
|
474
|
+
type: "registerPanelHandle",
|
|
475
|
+
data: this.initPanelResizer(),
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
const groupElement = this.closest("window-splitter");
|
|
480
|
+
if (!groupElement)
|
|
481
|
+
return;
|
|
482
|
+
const order = Array.from(groupElement.children).indexOf(this);
|
|
483
|
+
if (typeof order !== "number")
|
|
484
|
+
return;
|
|
485
|
+
this.send({
|
|
486
|
+
type: "registerPanelHandle",
|
|
487
|
+
data: { ...this.initPanelResizer(), order },
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
updated(changedProperties) {
|
|
493
|
+
if (changedProperties.has("size")) {
|
|
494
|
+
const currentHandleData = this.getHandleData();
|
|
495
|
+
if (currentHandleData &&
|
|
496
|
+
haveConstraintsChangedForPanelHandle(currentHandleData, this.initPanelResizer())) {
|
|
497
|
+
this.send({ type: "updateConstraints", data: this.initPanelResizer() });
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
disconnectedCallback() {
|
|
502
|
+
requestAnimationFrame(() => this.send({ type: "unregisterPanelHandle", id: this.id }));
|
|
503
|
+
}
|
|
504
|
+
render() {
|
|
505
|
+
return html `<slot></slot>`;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
PanelResizer.observedContexts = ["send"];
|
|
509
|
+
__decorate([
|
|
510
|
+
consume({ context: contextContext }),
|
|
511
|
+
property({ attribute: false })
|
|
512
|
+
], PanelResizer.prototype, "context", void 0);
|
|
513
|
+
__decorate([
|
|
514
|
+
consume({ context: sendContext }),
|
|
515
|
+
property({ attribute: false })
|
|
516
|
+
], PanelResizer.prototype, "send", void 0);
|
|
517
|
+
__decorate([
|
|
518
|
+
consume({ context: isPrerenderContext }),
|
|
519
|
+
property({ attribute: false })
|
|
520
|
+
], PanelResizer.prototype, "isPrerender", void 0);
|
|
521
|
+
__decorate([
|
|
522
|
+
property({ type: String, reflect: true })
|
|
523
|
+
], PanelResizer.prototype, "size", void 0);
|
|
524
|
+
__decorate([
|
|
525
|
+
property({ type: Boolean, reflect: true })
|
|
526
|
+
], PanelResizer.prototype, "disabled", void 0);
|
|
527
|
+
//# sourceMappingURL=index.js.map
|