@gramlot/gramlot 0.3.9 → 0.3.15
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/dist/components/editors/__init__.py +13 -0
- package/dist/components/{editors.js → editors/assets/collection.js} +354 -418
- package/dist/components/editors/assets/index.js +2 -0
- package/dist/components/editors/commands.json +7 -0
- package/dist/components/editors/grammar.json +7045 -0
- package/dist/components/inputs/__init__.py +13 -0
- package/dist/components/{inputs.js → inputs/assets/collection.js} +291 -200
- package/dist/components/inputs/assets/index.js +2 -0
- package/dist/components/inputs/commands.json +7 -0
- package/dist/components/inputs/grammar.json +42881 -0
- package/dist/components/layout/__init__.py +13 -0
- package/dist/components/layout/assets/collection.js +25737 -0
- package/dist/components/layout/assets/index.js +2 -0
- package/dist/components/layout/commands.json +7 -0
- package/dist/components/layout/grammar.json +1798 -0
- package/dist/components/tree/__init__.py +13 -0
- package/dist/components/{tree.js → tree/assets/collection.js} +62 -175
- package/dist/components/tree/assets/index.js +2 -0
- package/dist/components/tree/commands.json +7 -0
- package/dist/components/tree/grammar.json +339 -0
- package/dist/components/typst/__init__.py +13 -0
- package/dist/components/typst/assets/collection.js +4 -0
- package/dist/components/typst/assets/index.js +2 -0
- package/dist/components/typst/commands.json +7 -0
- package/dist/components/typst/grammar.json +81 -0
- package/dist/gramlot.js +2525 -905
- package/dist/gramlot.min.js +109 -28
- package/dist/runtime-notices.json +0 -196
- package/package.json +1 -1
- package/src/binding/ask-dialog.js +1 -1
- package/src/binding/installation.js +5 -6
- package/src/binding/remote.js +9 -2
- package/src/binding/runtime.js +12 -5
- package/src/bootstrap.d.ts +1 -1
- package/src/bootstrap.js +52 -30
- package/src/builder/binding.json +25 -0
- package/src/builder/gramlot-builder.js +16 -3
- package/src/builder/source.js +41 -4
- package/src/collection-artifact.d.ts +11 -0
- package/src/collection-artifact.js +57 -0
- package/src/commands.d.ts +9 -0
- package/src/commands.js +36 -0
- package/src/components/bases.js +1 -1
- package/src/components/border-container.js +33 -2
- package/src/components/buttons.js +84 -161
- package/src/components/choice-editor.js +31 -10
- package/src/components/database-choices.js +110 -0
- package/src/components/inputs.js +15 -2
- package/src/components/layout.js +5 -3
- package/src/components/menus.js +346 -0
- package/src/components/popup.js +15 -2
- package/src/components/registry.js +18 -3
- package/src/components/toolbar-overflow.js +181 -0
- package/src/components/tree.js +14 -4
- package/src/components/validation.js +1 -1
- package/src/components/windows.js +284 -0
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +4 -2
- package/src/handlers/rpc-handler.d.ts +6 -1
- package/src/handlers/rpc-handler.js +7 -2
- package/src/handlers/source-handler.d.ts +2 -1
- package/src/handlers/source-handler.js +10 -1
- package/src/index-page-styles.js +1 -1
- package/src/index-theme.js +1 -1
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/renderer/attributes.js +11 -2
- package/src/renderer/gramlot-html-renderer.js +1 -0
- package/src/renderer/gramlot-renderer.js +13 -3
- package/src/server/assets.js +2 -2
- package/src/server/gramlot-file-server.d.ts +2 -0
- package/src/server/gramlot-file-server.js +45 -1
- package/src/server/gramlot-server.d.ts +20 -2
- package/src/server/gramlot-server.js +86 -6
- package/src/server/page-base.js +1 -0
- package/src/server/page.d.ts +3 -0
- package/src/view/button.js +47 -3
- package/src/view/controls.js +8 -0
- package/src/view/html.js +8 -0
- package/src/view/menu-command.js +45 -0
- package/src/view/menu.js +87 -0
- package/themes/gramlot-compact/README.md +19 -0
- package/themes/gramlot-compact/theme.css +138 -45
- package/themes/joanna/README.md +19 -0
- package/themes/joanna/theme.css +134 -78
- package/themes/mela/theme.css +184 -0
- package/themes/mimi/README.md +19 -0
- package/themes/mimi/theme.css +133 -77
- package/themes/palettes/README.md +3 -0
- package/themes/palettes/compact.css +86 -0
- package/themes/palettes/joanna.css +86 -0
- package/themes/palettes/mimi.css +86 -0
- package/tools/gramlot-tools-inspector.js +3 -3
- package/dist/components/layout.js +0 -1402
- package/dist/components/typst.js +0 -4
|
@@ -1,1402 +0,0 @@
|
|
|
1
|
-
// src/webcomponent.js
|
|
2
|
-
var NAME = /^[a-z][.0-9_a-z\-\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
|
|
3
|
-
var RESERVED = /* @__PURE__ */ new Set([
|
|
4
|
-
"annotation-xml",
|
|
5
|
-
"color-profile",
|
|
6
|
-
"font-face",
|
|
7
|
-
"font-face-src",
|
|
8
|
-
"font-face-uri",
|
|
9
|
-
"font-face-format",
|
|
10
|
-
"font-face-name",
|
|
11
|
-
"missing-glyph"
|
|
12
|
-
]);
|
|
13
|
-
function webcomponentCode(attrs) {
|
|
14
|
-
const code = attrs.code;
|
|
15
|
-
if (typeof code !== "string" || NAME.exec(code)?.[0] !== code || !code.includes("-") || RESERVED.has(code)) {
|
|
16
|
-
throw new TypeError("webcomponent: code must be a literal custom-element name");
|
|
17
|
-
}
|
|
18
|
-
return code;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/components/registry.js
|
|
22
|
-
function freeze(value) {
|
|
23
|
-
for (const child of Object.values(value)) if (child && typeof child === "object") freeze(child);
|
|
24
|
-
return Object.freeze(value);
|
|
25
|
-
}
|
|
26
|
-
function annotation(parameter) {
|
|
27
|
-
if (typeof parameter.dtype !== "string" && !Array.isArray(parameter.dtype)) throw new TypeError("Component parameter requires dtype");
|
|
28
|
-
const alternatives = (Array.isArray(parameter.dtype) ? parameter.dtype : [parameter.dtype]).map((dtype) => ({ kind: "dtype", dtype }));
|
|
29
|
-
if (parameter.nullable) alternatives.push({ kind: "dtype", dtype: "NN" });
|
|
30
|
-
if (parameter.binding && parameter.dtype !== "T") alternatives.push({
|
|
31
|
-
kind: "annotated",
|
|
32
|
-
base: { kind: "dtype", dtype: "T" },
|
|
33
|
-
metadata: [{ kind: "regex", pattern: "^[\\^=].+", flags: 0 }]
|
|
34
|
-
});
|
|
35
|
-
return alternatives.length === 1 ? alternatives[0] : { kind: "union", items: alternatives };
|
|
36
|
-
}
|
|
37
|
-
function defineComponent({ name, tag, base, mixins = [], parameters = {}, subTags = "", presentationDefaults = [], dataScope = false, command = false, childParameters = {}, sourceContext = false, bagStore = false, dragSource = false, implementation }) {
|
|
38
|
-
webcomponentCode({ code: tag });
|
|
39
|
-
if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(name)) throw new TypeError("Invalid component authoring name");
|
|
40
|
-
const effective = { ...base.parameters };
|
|
41
|
-
for (const mixin of mixins) {
|
|
42
|
-
for (const [key, spec] of Object.entries(mixin.parameters)) {
|
|
43
|
-
if (Object.hasOwn(effective, key)) throw new Error(`Duplicate mixin parameter: ${key}`);
|
|
44
|
-
effective[key] = spec;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
Object.assign(effective, parameters);
|
|
48
|
-
for (const spec of Object.values(effective)) annotation(spec);
|
|
49
|
-
return Object.freeze({
|
|
50
|
-
name,
|
|
51
|
-
tag,
|
|
52
|
-
base,
|
|
53
|
-
subTags,
|
|
54
|
-
presentationDefaults: Object.freeze([...presentationDefaults]),
|
|
55
|
-
dataScope,
|
|
56
|
-
command,
|
|
57
|
-
bagStore,
|
|
58
|
-
mixins: Object.freeze([...mixins]),
|
|
59
|
-
parameters: freeze(structuredClone(effective)),
|
|
60
|
-
childParameters: freeze(structuredClone(childParameters)),
|
|
61
|
-
sourceContext,
|
|
62
|
-
dragSource,
|
|
63
|
-
implementation
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
var ComponentCollection = class {
|
|
67
|
-
#classes = /* @__PURE__ */ new WeakMap();
|
|
68
|
-
constructor({ name, components }) {
|
|
69
|
-
this.name = name;
|
|
70
|
-
this.components = Object.freeze([...components]);
|
|
71
|
-
const names = /* @__PURE__ */ new Set(), tags = /* @__PURE__ */ new Set();
|
|
72
|
-
for (const component of components) {
|
|
73
|
-
if (names.has(component.name.toLowerCase()) || tags.has(component.tag)) {
|
|
74
|
-
throw new Error(`Duplicate component: ${component.name}`);
|
|
75
|
-
}
|
|
76
|
-
names.add(component.name.toLowerCase());
|
|
77
|
-
tags.add(component.tag);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/** Same JSON consumed by Python and JavaScript Builders. */
|
|
81
|
-
toDocument() {
|
|
82
|
-
return {
|
|
83
|
-
document_format: { name: "builder_grammar", version: "1.1" },
|
|
84
|
-
grammar: { name: this.name, version: null, title: this.name, description: null },
|
|
85
|
-
abstracts: {},
|
|
86
|
-
elements: Object.fromEntries(this.components.map((component) => [component.name, {
|
|
87
|
-
doc: null,
|
|
88
|
-
sub_tags: component.subTags,
|
|
89
|
-
parent_tags: null,
|
|
90
|
-
inherits_from: null,
|
|
91
|
-
ns: null,
|
|
92
|
-
node_label: null,
|
|
93
|
-
collection_key: null,
|
|
94
|
-
attributes: {
|
|
95
|
-
parameters: [
|
|
96
|
-
...Object.entries(component.parameters).map(([name, spec]) => ({
|
|
97
|
-
name,
|
|
98
|
-
kind: "keyword_only",
|
|
99
|
-
role: "attribute",
|
|
100
|
-
annotation: annotation(spec),
|
|
101
|
-
has_default: true,
|
|
102
|
-
default: spec.default ?? null
|
|
103
|
-
})),
|
|
104
|
-
{
|
|
105
|
-
name: "attr",
|
|
106
|
-
kind: "var_keyword",
|
|
107
|
-
role: "attribute",
|
|
108
|
-
annotation: { kind: "any" },
|
|
109
|
-
has_default: false
|
|
110
|
-
}
|
|
111
|
-
],
|
|
112
|
-
accepts_var_keyword: true,
|
|
113
|
-
accepts_var_positional: false
|
|
114
|
-
},
|
|
115
|
-
_meta: { render_tag: component.tag, gramlot_component: {
|
|
116
|
-
parameters: structuredClone(component.parameters),
|
|
117
|
-
presentationDefaults: [...component.presentationDefaults],
|
|
118
|
-
dataScope: component.dataScope,
|
|
119
|
-
command: component.command,
|
|
120
|
-
...Object.keys(component.childParameters).length ? { childParameters: structuredClone(component.childParameters) } : {},
|
|
121
|
-
...component.sourceContext ? { sourceContext: true } : {},
|
|
122
|
-
...component.dragSource ? { dragSource: true } : {},
|
|
123
|
-
...component.bagStore ? { bagStore: true } : {}
|
|
124
|
-
} }
|
|
125
|
-
}]))
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/** Register once per document realm, only when the collection is activated. */
|
|
129
|
-
register(window) {
|
|
130
|
-
if (this.#classes.has(window)) return;
|
|
131
|
-
const classes = [];
|
|
132
|
-
for (const component of this.components) {
|
|
133
|
-
if (window.customElements.get(component.tag)) throw new Error(`Custom element already registered: ${component.tag}`);
|
|
134
|
-
let Base = component.base(window.HTMLElement);
|
|
135
|
-
for (const mixin of component.mixins) Base = mixin(Base);
|
|
136
|
-
const Class = component.implementation(Base);
|
|
137
|
-
Object.defineProperty(Class, "gramlotComponent", { value: component });
|
|
138
|
-
classes.push([component.tag, Class]);
|
|
139
|
-
}
|
|
140
|
-
for (const [tag, Class] of classes) window.customElements.define(tag, Class);
|
|
141
|
-
this.#classes.set(window, classes);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
function defineCollection(options) {
|
|
145
|
-
return new ComponentCollection(options);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/components/labelbox.js
|
|
149
|
-
var POSITIONS = ["TL", "TC", "TR", "L", "R", "BL", "BC", "BR"];
|
|
150
|
-
function project(element, attrs, adapt, previous) {
|
|
151
|
-
const next = adapt(attrs);
|
|
152
|
-
for (const key of /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(next)])) {
|
|
153
|
-
if (next[key] == null) element.removeAttribute(key);
|
|
154
|
-
else element.setAttribute(key, String(next[key]));
|
|
155
|
-
}
|
|
156
|
-
return next;
|
|
157
|
-
}
|
|
158
|
-
function Labelbox(Base) {
|
|
159
|
-
return class extends Base {
|
|
160
|
-
#previous = { box: {}, label: {}, labelBox: {}, controlBox: {} };
|
|
161
|
-
constructor() {
|
|
162
|
-
super();
|
|
163
|
-
this.box = this.ownerDocument.createElement("div");
|
|
164
|
-
this.box.className = "labelbox";
|
|
165
|
-
this.labelBox = this.ownerDocument.createElement("div");
|
|
166
|
-
this.labelBox.className = "label-box";
|
|
167
|
-
this.fieldLabel = this.ownerDocument.createElement("label");
|
|
168
|
-
this.fieldLabel.id = "field-label";
|
|
169
|
-
this.fieldLabel.htmlFor = "control";
|
|
170
|
-
this.labelBox.append(this.fieldLabel);
|
|
171
|
-
this.box.append(this.labelBox, this.controlBox);
|
|
172
|
-
const style = this.ownerDocument.createElement("style");
|
|
173
|
-
style.textContent = `.labelbox{--gramlot-label-width:initial;--gramlot-formlet-label-width:initial;display:grid;gap:var(--gramlot-label-gap,.25em);grid-template-areas:'label' 'control'}
|
|
174
|
-
.label-box{grid-area:label;color:var(--gramlot-label-color,var(--gramlot-text-secondary,inherit));font-size:var(--gramlot-label-size,1em)} .control-box{grid-area:control}
|
|
175
|
-
.labelbox[data-position='L']{grid-template-areas:'label control';align-items:center}
|
|
176
|
-
.labelbox[data-position='R']{grid-template-areas:'control label';align-items:center}
|
|
177
|
-
.labelbox[data-position^='B']{grid-template-areas:'control' 'label'}
|
|
178
|
-
.labelbox[data-position$='C']>.label-box{text-align:center}
|
|
179
|
-
.labelbox[data-position$='R']>.label-box{text-align:right}
|
|
180
|
-
.label-box[hidden]{display:none} .label-box label{display:block}
|
|
181
|
-
.labelbox[data-position='L']>.label-box{text-align:right;padding-right:2px}
|
|
182
|
-
.labelbox[data-formlet-aligned]>.label-box>label{width:max-content;margin-left:auto}
|
|
183
|
-
.labelbox[data-position='L']{grid-template-columns:var(--gramlot-label-width,var(--gramlot-formlet-label-width,max-content)) minmax(0,1fr)}`;
|
|
184
|
-
this.shadowRoot.append(style, this.box);
|
|
185
|
-
}
|
|
186
|
-
projectAttributes(attrs, adapt) {
|
|
187
|
-
const rest = super.projectAttributes(attrs, adapt);
|
|
188
|
-
const { lbl, lbl_position = "TL" } = this.parameters;
|
|
189
|
-
if (!POSITIONS.includes(lbl_position)) throw new TypeError(`Invalid lbl_position: ${lbl_position}`);
|
|
190
|
-
const groups = { box: {}, label: {}, labelBox: {}, controlBox: {} };
|
|
191
|
-
const prefixes = [["box_l_", "labelBox"], ["box_c_", "controlBox"], ["lbl_", "label"], ["box_", "box"]];
|
|
192
|
-
for (const [name, value] of Object.entries(rest)) {
|
|
193
|
-
const match = prefixes.find(([prefix]) => name.startsWith(prefix));
|
|
194
|
-
if (match) {
|
|
195
|
-
groups[match[1]][name.slice(match[0].length)] = value;
|
|
196
|
-
delete rest[name];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
const elements = { box: this.box, label: this.fieldLabel, labelBox: this.labelBox, controlBox: this.controlBox };
|
|
200
|
-
for (const [name, element] of Object.entries(elements)) {
|
|
201
|
-
this.#previous[name] = project(element, groups[name], adapt, this.#previous[name]);
|
|
202
|
-
}
|
|
203
|
-
if (attrs.lbl_width == null) this.box.style.removeProperty("--gramlot-label-width");
|
|
204
|
-
else this.box.style.setProperty("--gramlot-label-width", attrs.lbl_width);
|
|
205
|
-
this.box.classList.add("labelbox");
|
|
206
|
-
this.labelBox.classList.add("label-box");
|
|
207
|
-
this.controlBox.classList.add("control-box");
|
|
208
|
-
this.box.dataset.position = lbl_position;
|
|
209
|
-
this.fieldLabel.textContent = lbl ?? "";
|
|
210
|
-
this.labelBox.hidden = lbl == null || lbl === "";
|
|
211
|
-
if (this.control.localName !== "input") {
|
|
212
|
-
if (this.labelBox.hidden) this.control.removeAttribute("aria-labelledby");
|
|
213
|
-
else this.control.setAttribute("aria-labelledby", "field-label");
|
|
214
|
-
}
|
|
215
|
-
this.dispatchEvent(new this.ownerDocument.defaultView.Event("gramlot-label-layout", { bubbles: true }));
|
|
216
|
-
return rest;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
Labelbox.parameters = {
|
|
221
|
-
lbl: { dtype: "T", qualification: "intl_str", nullable: true, binding: "read" },
|
|
222
|
-
lbl_position: { dtype: "T", default: "TL", binding: "read", enum: POSITIONS }
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// src/components/parameters.js
|
|
226
|
-
function projectParameters(element, attrs) {
|
|
227
|
-
element.parameters = Object.fromEntries(Object.entries(element.constructor.gramlotComponent.parameters).map(([name, spec]) => [name, Object.hasOwn(attrs, name) ? attrs[name] : spec.default]));
|
|
228
|
-
return Object.fromEntries(Object.entries(attrs).filter(([name]) => !Object.hasOwn(element.parameters, name)));
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// src/components/container.js
|
|
232
|
-
function Container(HTMLElement) {
|
|
233
|
-
return class extends HTMLElement {
|
|
234
|
-
constructor() {
|
|
235
|
-
super();
|
|
236
|
-
const shadow = this.attachShadow({ mode: "open" });
|
|
237
|
-
const style = this.ownerDocument.createElement("style");
|
|
238
|
-
style.textContent = `:host{display:block;min-width:0;font:inherit;color:var(--gramlot-ink,CanvasText)}
|
|
239
|
-
*,*::before,*::after{box-sizing:border-box}.control-box{min-width:0}slot{display:contents}
|
|
240
|
-
::slotted(*){min-width:0;max-width:100%}`;
|
|
241
|
-
this.controlBox = this.ownerDocument.createElement("div");
|
|
242
|
-
this.controlBox.className = "control-box";
|
|
243
|
-
this.control = this.controlBox;
|
|
244
|
-
this.control.id = "control";
|
|
245
|
-
this.control.append(this.ownerDocument.createElement("slot"));
|
|
246
|
-
shadow.append(style, this.controlBox);
|
|
247
|
-
}
|
|
248
|
-
projectAttributes(attrs) {
|
|
249
|
-
return projectParameters(this, attrs);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
Container.parameters = {};
|
|
254
|
-
|
|
255
|
-
// src/components/border-container.js
|
|
256
|
-
var SIDES = ["top", "bottom", "left", "right"];
|
|
257
|
-
var REGIONS = [...SIDES, "center"];
|
|
258
|
-
var horizontal = (side) => side === "top" || side === "bottom";
|
|
259
|
-
function projectBorderChild(element, attrs, { adapt, invoke, publish, publishParent, writeParameter }) {
|
|
260
|
-
const rest = { ...attrs }, splitter = {}, drawer = {};
|
|
261
|
-
for (const [name, value] of Object.entries(rest)) {
|
|
262
|
-
for (const [prefix, group] of [["splitter_", splitter], ["drawer_", drawer]]) {
|
|
263
|
-
if (name.startsWith(prefix)) {
|
|
264
|
-
group[name.slice(prefix.length)] = value;
|
|
265
|
-
delete rest[name];
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
const region = rest.region;
|
|
270
|
-
if (!REGIONS.includes(region)) throw new TypeError(`Invalid border region: ${region}`);
|
|
271
|
-
const min = rest.minSize ?? 0, max = rest.maxSize ?? Infinity;
|
|
272
|
-
if (typeof min !== "number" || typeof max !== "number" || !Number.isFinite(min) || min < 0 || max < min || Number.isNaN(max)) {
|
|
273
|
-
throw new TypeError("Border minSize/maxSize must be nonnegative pixel limits, with maxSize >= minSize");
|
|
274
|
-
}
|
|
275
|
-
if (![void 0, null, false, true, "close"].includes(rest.drawer)) throw new TypeError("drawer must be true, false or close");
|
|
276
|
-
const probe = element.ownerDocument.createElement("div");
|
|
277
|
-
probe.style.cssText = rest.style ?? "";
|
|
278
|
-
const dimension = horizontal(region) ? "height" : "width";
|
|
279
|
-
const numeric = typeof rest[dimension] === "number";
|
|
280
|
-
if (numeric) {
|
|
281
|
-
if (!Number.isFinite(rest[dimension]) || rest[dimension] < 0) throw new TypeError("Border numeric dimensions must be finite nonnegative pixels");
|
|
282
|
-
probe.style[dimension] = `${rest[dimension]}px`;
|
|
283
|
-
}
|
|
284
|
-
const size = probe.style[dimension];
|
|
285
|
-
delete rest.width;
|
|
286
|
-
delete rest.height;
|
|
287
|
-
probe.style.width = "100%";
|
|
288
|
-
probe.style.height = "100%";
|
|
289
|
-
rest.style = probe.style.cssText;
|
|
290
|
-
const { label, icon, minimize = true, onclick, ...drawerStyle } = drawer;
|
|
291
|
-
if (typeof minimize !== "boolean") throw new TypeError("drawer_minimize must be a boolean");
|
|
292
|
-
const drawerAttrs = adapt(drawerStyle);
|
|
293
|
-
const drawerProbe = element.ownerDocument.createElement("div");
|
|
294
|
-
drawerProbe.style.cssText = drawerAttrs.style ?? "";
|
|
295
|
-
const background = drawerProbe.style.backgroundColor;
|
|
296
|
-
if (background) drawerProbe.style.setProperty("--gramlot-drawer-background", background);
|
|
297
|
-
if (drawerAttrs.style != null) drawerAttrs.style = drawerProbe.style.cssText;
|
|
298
|
-
const config = {
|
|
299
|
-
region,
|
|
300
|
-
size,
|
|
301
|
-
min,
|
|
302
|
-
max,
|
|
303
|
-
splitter: rest.splitter === true,
|
|
304
|
-
drawer: rest.drawer,
|
|
305
|
-
hidden: rest.hidden === true,
|
|
306
|
-
splitterAttrs: adapt(splitter),
|
|
307
|
-
drawerAttrs,
|
|
308
|
-
label,
|
|
309
|
-
icon,
|
|
310
|
-
minimize,
|
|
311
|
-
writeParameter: (size2) => {
|
|
312
|
-
if (numeric) writeParameter(dimension, size2);
|
|
313
|
-
},
|
|
314
|
-
notifications: {
|
|
315
|
-
closableChange: (payload) => publish("closable_change", payload),
|
|
316
|
-
splitterResize: (payload) => publishParent("splitter_resize", payload)
|
|
317
|
-
},
|
|
318
|
-
onToggle: onclick ? (evt, show) => invoke("drawer_onclick", onclick, { evt, show }) : null
|
|
319
|
-
};
|
|
320
|
-
for (const key of ["region", "splitter", "drawer", "minSize", "maxSize"]) delete rest[key];
|
|
321
|
-
rest.slot = region;
|
|
322
|
-
return { rest, config };
|
|
323
|
-
}
|
|
324
|
-
function applyAttributes(element, attrs, previous) {
|
|
325
|
-
for (const key of /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(attrs)])) {
|
|
326
|
-
if (attrs[key] == null) element.removeAttribute(key);
|
|
327
|
-
else element.setAttribute(key, String(attrs[key]));
|
|
328
|
-
}
|
|
329
|
-
return attrs;
|
|
330
|
-
}
|
|
331
|
-
var ContentPane = defineComponent({
|
|
332
|
-
name: "contentPane",
|
|
333
|
-
tag: "gramlot-content-pane",
|
|
334
|
-
base: Container,
|
|
335
|
-
subTags: "*",
|
|
336
|
-
implementation: (Base) => class extends Base {
|
|
337
|
-
constructor() {
|
|
338
|
-
super();
|
|
339
|
-
const style = this.ownerDocument.createElement("style");
|
|
340
|
-
style.textContent = ":host{min-height:0;overflow:auto}.control-box{height:100%;min-height:0}";
|
|
341
|
-
this.shadowRoot.append(style);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
var BorderContainer = defineComponent({
|
|
346
|
-
name: "borderContainer",
|
|
347
|
-
tag: "gramlot-border-container",
|
|
348
|
-
base: Container,
|
|
349
|
-
subTags: "*",
|
|
350
|
-
childParameters: { region: { required: true, enum: REGIONS, unique: true }, width: {}, height: {}, drawer_onclick: { inline: ["evt", "show"] } },
|
|
351
|
-
parameters: {
|
|
352
|
-
design: { dtype: "T", default: "headline", binding: "read", enum: ["headline", "sidebar"] },
|
|
353
|
-
persist: { dtype: "B", default: false, binding: "read" }
|
|
354
|
-
},
|
|
355
|
-
// Named as the component: inside the body `BorderContainer` is this class, owner of the static state.
|
|
356
|
-
implementation: (Base) => class BorderContainer2 extends Base {
|
|
357
|
-
// The region configuration of each child element, for this class in this window (ComponentCollection.register).
|
|
358
|
-
static #borderRegions = /* @__PURE__ */ new WeakMap();
|
|
359
|
-
static projectChild(element, attrs, context) {
|
|
360
|
-
const { rest, config } = projectBorderChild(element, attrs, context);
|
|
361
|
-
BorderContainer2.#borderRegions.set(element, config);
|
|
362
|
-
if (element.parentElement?.constructor.gramlotComponent?.name === "borderContainer") element.parentElement.projectRegion(element);
|
|
363
|
-
return rest;
|
|
364
|
-
}
|
|
365
|
-
#regions = /* @__PURE__ */ new Map();
|
|
366
|
-
#observer;
|
|
367
|
-
#contentObserver;
|
|
368
|
-
#drag;
|
|
369
|
-
constructor() {
|
|
370
|
-
super();
|
|
371
|
-
this.control.replaceChildren();
|
|
372
|
-
const doc = this.ownerDocument;
|
|
373
|
-
this.#contentObserver = new doc.defaultView.ResizeObserver((entries) => {
|
|
374
|
-
for (const { target } of entries) {
|
|
375
|
-
const region = target.closest(".region");
|
|
376
|
-
region.style.setProperty("--drawer-content-width", `${target.offsetWidth}px`);
|
|
377
|
-
region.style.setProperty("--drawer-content-height", `${target.offsetHeight}px`);
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
const style = doc.createElement("style");
|
|
381
|
-
style.textContent = `:host{min-height:0;overflow:hidden}
|
|
382
|
-
.control-box{height:100%;min-height:0;display:grid;
|
|
383
|
-
grid-template-columns:var(--left,0px) minmax(0,1fr) var(--right,0px);
|
|
384
|
-
grid-template-rows:var(--top,0px) minmax(0,1fr) var(--bottom,0px);
|
|
385
|
-
grid-template-areas:'top top top' 'left center right' 'bottom bottom bottom'}
|
|
386
|
-
.control-box[data-drawer-motion]{transition:grid-template-columns var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),grid-template-rows var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
|
|
387
|
-
.control-box[data-design=sidebar]{grid-template-areas:'left top right' 'left center right' 'left bottom right'}
|
|
388
|
-
.region{position:relative;min-width:0;min-height:0;overflow:visible}
|
|
389
|
-
.viewport{height:100%;min-width:0;min-height:0;overflow:auto}
|
|
390
|
-
.region[data-side=left]>.viewport{padding-right:var(--region-splitter,0px)}
|
|
391
|
-
.region[data-side=right]>.viewport{padding-left:var(--region-splitter,0px)}
|
|
392
|
-
.region[data-side=top]>.viewport{padding-bottom:var(--region-splitter,0px)}
|
|
393
|
-
.region[data-side=bottom]>.viewport{padding-top:var(--region-splitter,0px)}
|
|
394
|
-
.viewport[hidden]{display:none}
|
|
395
|
-
.control-box[data-drawer-motion] .viewport{transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out);opacity:1;visibility:visible}
|
|
396
|
-
.control-box[data-drawer-motion] .viewport[hidden]{display:block;opacity:0;visibility:hidden;
|
|
397
|
-
transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),visibility 0s var(--gramlot-drawer-duration,.24s)}::slotted(*){min-height:0}
|
|
398
|
-
.separator{position:absolute;z-index:2;touch-action:none;user-select:none;background:var(--gramlot-splitter-background,var(--gramlot-border-control,#aaa))}
|
|
399
|
-
.separator[data-axis=x]{top:0;bottom:0;width:var(--gramlot-splitter-size,1px);cursor:col-resize}
|
|
400
|
-
.separator[data-axis=y]{left:0;right:0;height:var(--gramlot-splitter-size,1px);cursor:row-resize}
|
|
401
|
-
.separator[data-side=left]{right:0}.separator[data-side=right]{left:0}
|
|
402
|
-
.separator[data-side=top]{bottom:0}.separator[data-side=bottom]{top:0}
|
|
403
|
-
.separator:hover{background:var(--gramlot-splitter-hover,#91a4bd)}
|
|
404
|
-
.separator::before{content:'';position:absolute;inset:0}
|
|
405
|
-
.separator[data-axis=x]::before{left:calc((100% - max(100%,var(--gramlot-touch-target,12px))) / 2);width:max(100%,var(--gramlot-touch-target,12px))}
|
|
406
|
-
.separator[data-axis=y]::before{top:calc((100% - max(100%,var(--gramlot-touch-target,12px))) / 2);height:max(100%,var(--gramlot-touch-target,12px))}
|
|
407
|
-
.separator[data-draggable=false]{cursor:default;background:transparent}
|
|
408
|
-
.separator[data-draggable=false]::before{display:none}
|
|
409
|
-
.separator[data-axis=x][data-draggable=false]{width:0!important}
|
|
410
|
-
.separator[data-axis=y][data-draggable=false]{height:0!important}
|
|
411
|
-
.separator:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:1px}
|
|
412
|
-
.drawer{position:absolute;z-index:3;cursor:pointer;appearance:none;font:inherit;
|
|
413
|
-
font-size:var(--gramlot-drawer-font-size,11px);line-height:1.2;white-space:nowrap;
|
|
414
|
-
--drawer-background:var(--gramlot-drawer-background,var(--gramlot-text-secondary,#777));
|
|
415
|
-
color:var(--gramlot-drawer-color,hsl(from var(--drawer-background) 0 0 clamp(20,calc((60 - l) * 1000),100)));
|
|
416
|
-
background:var(--drawer-background);outline:none;
|
|
417
|
-
border:0;border-radius:0;box-shadow:none;
|
|
418
|
-
min-width:0;min-height:0;padding:0;
|
|
419
|
-
opacity:var(--gramlot-drawer-opacity,.20);
|
|
420
|
-
transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
421
|
-
transform var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
422
|
-
width var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
423
|
-
height var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
424
|
-
max-width var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
425
|
-
max-height var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out),
|
|
426
|
-
margin var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
|
|
427
|
-
.drawer:hover,.drawer:focus-visible{opacity:var(--gramlot-drawer-active-opacity,1)}
|
|
428
|
-
[data-axis=x]>.drawer[data-resizable]{cursor:col-resize}
|
|
429
|
-
[data-axis=y]>.drawer[data-resizable]{cursor:row-resize}
|
|
430
|
-
@media (hover:hover){
|
|
431
|
-
[data-axis=x]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-cross-scale,1.75),var(--gramlot-drawer-hover-length-scale,1.12))}
|
|
432
|
-
[data-axis=y]>.drawer:hover{transform:scale(var(--gramlot-drawer-hover-length-scale,1.12),var(--gramlot-drawer-hover-cross-scale,1.75))}
|
|
433
|
-
.separator>.drawer:is([data-labelled],[data-icon]):hover{transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
[data-axis=x]>.drawer{--drawer-closed-width:var(--gramlot-drawer-thickness,6px);--drawer-closed-height:var(--gramlot-drawer-length,40px);
|
|
437
|
-
top:50%;margin-top:calc(var(--gramlot-drawer-length,40px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
|
|
438
|
-
[data-axis=y]>.drawer{--drawer-closed-width:var(--gramlot-drawer-length,40px);--drawer-closed-height:var(--gramlot-drawer-thickness,6px);
|
|
439
|
-
left:50%;margin-left:calc(var(--gramlot-drawer-length,40px) / -2);width:var(--drawer-closed-width);height:var(--drawer-closed-height)}
|
|
440
|
-
.drawer::after{content:'';position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
|
|
441
|
-
width:max(100%,var(--gramlot-touch-target,var(--gramlot-drawer-hit-target,12px)));height:max(100%,var(--gramlot-touch-target,var(--gramlot-drawer-hit-target,12px)))}
|
|
442
|
-
.drawer{--drawer-reveal-width:var(--gramlot-drawer-reveal-width,var(--drawer-content-width,0px));--drawer-reveal-height:var(--gramlot-drawer-reveal-height,var(--drawer-content-height,0px))}
|
|
443
|
-
.drawer[data-labelled]{opacity:var(--gramlot-drawer-active-opacity,1)}
|
|
444
|
-
[data-side=left]>.drawer{transform-origin:left center;left:100%;border-left:0;border-radius:0 calc(var(--gramlot-radius-sm,4px) * 2) calc(var(--gramlot-radius-sm,4px) * 2) 0}
|
|
445
|
-
[data-side=right]>.drawer{transform-origin:right center;right:100%;border-right:0;border-radius:calc(var(--gramlot-radius-sm,4px) * 2) 0 0 calc(var(--gramlot-radius-sm,4px) * 2)}
|
|
446
|
-
[data-side=top]>.drawer{transform-origin:center top;top:100%;border-top:0;border-radius:0 0 calc(var(--gramlot-radius-sm,4px) * 2) calc(var(--gramlot-radius-sm,4px) * 2)}
|
|
447
|
-
[data-side=bottom]>.drawer{transform-origin:center bottom;bottom:100%;border-bottom:0;border-radius:calc(var(--gramlot-radius-sm,4px) * 2) calc(var(--gramlot-radius-sm,4px) * 2) 0 0}
|
|
448
|
-
.drawer:is([data-labelled],[data-icon]){width:max-content;height:max-content;padding:0}
|
|
449
|
-
.drawer-viewport{display:block;overflow:hidden;min-width:0;min-height:0;max-width:inherit;max-height:inherit}
|
|
450
|
-
.drawer-content{display:flex;width:max-content;height:max-content;align-items:center;gap:var(--gramlot-drawer-content-gap,4px);box-sizing:border-box;
|
|
451
|
-
padding:var(--gramlot-drawer-padding,2px 8px);overflow:hidden;pointer-events:none;
|
|
452
|
-
min-width:0;min-height:0}
|
|
453
|
-
.drawer-icon{display:block;flex:none;font-size:var(--gramlot-drawer-icon-size,1em);line-height:1}
|
|
454
|
-
.drawer-icon[hidden],.drawer-label:empty{display:none}
|
|
455
|
-
.drawer-label{display:block;flex:none;pointer-events:none}
|
|
456
|
-
.drawer-rotated .drawer-content{flex-direction:column;padding:var(--gramlot-drawer-padding,8px 2px)}
|
|
457
|
-
.drawer-rotated .drawer-label{writing-mode:vertical-rl;text-orientation:mixed}
|
|
458
|
-
.separator[data-axis=x]>.drawer.drawer-rotated{margin-top:0;translate:0 -50%}
|
|
459
|
-
/* Icon and caption reveal as one unit; the resting grip stays thin. */
|
|
460
|
-
.separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]){--drawer-open:var(--gramlot-drawer-reveal,0);
|
|
461
|
-
opacity:calc(var(--gramlot-drawer-opacity,.20) + (var(--gramlot-drawer-active-opacity,1) - var(--gramlot-drawer-opacity,.20)) * var(--drawer-open));
|
|
462
|
-
display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr);
|
|
463
|
-
min-width:0;min-height:0;
|
|
464
|
-
max-width:calc(var(--drawer-closed-width) + (var(--drawer-reveal-width) - var(--drawer-closed-width)) * var(--drawer-open));
|
|
465
|
-
max-height:calc(var(--drawer-closed-height) + (var(--drawer-reveal-height) - var(--drawer-closed-height)) * var(--drawer-open))}
|
|
466
|
-
.separator[data-axis=x]>.drawer.drawer-reveal{margin-top:0;translate:0 -50%}
|
|
467
|
-
[data-axis=y]>.drawer:is([data-labelled],[data-icon]){margin-left:0;translate:-50% 0}
|
|
468
|
-
.drawer-reveal .drawer-content{opacity:var(--drawer-open);
|
|
469
|
-
transition:opacity var(--gramlot-drawer-duration,.24s) var(--gramlot-drawer-easing,ease-out)}
|
|
470
|
-
@media (hover:none),(pointer:coarse){.separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]){--drawer-open:1}}
|
|
471
|
-
@media (hover:hover){.separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]):hover{--drawer-open:1;transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}}
|
|
472
|
-
.separator>.drawer:is([data-labelled],[data-icon]):is(:active,[data-active]){transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
|
|
473
|
-
.separator>.drawer.drawer-reveal:is([data-labelled],[data-icon]):is(:focus-visible,:active,[data-active]){--drawer-open:1;transform:scale(var(--gramlot-drawer-label-hover-scale,1.04))}
|
|
474
|
-
@media (prefers-reduced-motion:reduce){.drawer,.drawer-reveal .drawer-content,.control-box[data-drawer-motion],.control-box[data-drawer-motion] .viewport{transition:none!important}}
|
|
475
|
-
.drawer[hidden],.separator[hidden]{display:none}
|
|
476
|
-
.drag-cover{position:absolute;inset:0;z-index:4;display:none}
|
|
477
|
-
:host{position:relative}.drag-cover[data-active]{display:block}`;
|
|
478
|
-
for (const side of REGIONS) {
|
|
479
|
-
const cell = doc.createElement("div");
|
|
480
|
-
cell.className = "region";
|
|
481
|
-
cell.style.gridArea = side;
|
|
482
|
-
const viewport = doc.createElement("div");
|
|
483
|
-
viewport.className = "viewport";
|
|
484
|
-
cell.dataset.side = side;
|
|
485
|
-
viewport.id = `region-${side}`;
|
|
486
|
-
const slot = doc.createElement("slot");
|
|
487
|
-
slot.name = side;
|
|
488
|
-
viewport.append(slot);
|
|
489
|
-
cell.append(viewport);
|
|
490
|
-
const state = { cell, viewport, child: null, config: null, visibility: null, closed: false, suppressDrawerClick: false, size: null, splitterAttrs: {}, drawerAttrs: {} };
|
|
491
|
-
if (side !== "center") {
|
|
492
|
-
const separator = doc.createElement("div");
|
|
493
|
-
separator.className = "separator";
|
|
494
|
-
separator.dataset.side = side;
|
|
495
|
-
separator.dataset.axis = horizontal(side) ? "y" : "x";
|
|
496
|
-
separator.setAttribute("role", "separator");
|
|
497
|
-
separator.setAttribute("aria-label", `Resize ${side} region`);
|
|
498
|
-
separator.setAttribute("aria-orientation", horizontal(side) ? "horizontal" : "vertical");
|
|
499
|
-
separator.setAttribute("aria-controls", viewport.id);
|
|
500
|
-
const drawer = doc.createElement("button");
|
|
501
|
-
drawer.type = "button";
|
|
502
|
-
drawer.className = "drawer";
|
|
503
|
-
drawer.setAttribute("aria-controls", viewport.id);
|
|
504
|
-
const drawerIcon = doc.createElement("span");
|
|
505
|
-
drawerIcon.className = "drawer-icon";
|
|
506
|
-
drawerIcon.setAttribute("aria-hidden", "true");
|
|
507
|
-
const drawerLabel = doc.createElement("span");
|
|
508
|
-
drawerLabel.className = "drawer-label";
|
|
509
|
-
const drawerContent = doc.createElement("span");
|
|
510
|
-
drawerContent.className = "drawer-content";
|
|
511
|
-
const drawerViewport = doc.createElement("span");
|
|
512
|
-
drawerViewport.className = "drawer-viewport";
|
|
513
|
-
drawerContent.append(drawerIcon, drawerLabel);
|
|
514
|
-
drawerViewport.append(drawerContent);
|
|
515
|
-
drawer.append(drawerViewport);
|
|
516
|
-
separator.append(drawer);
|
|
517
|
-
cell.append(separator);
|
|
518
|
-
drawer.addEventListener("pointerdown", (evt) => {
|
|
519
|
-
if (evt.button === 0) drawer.setAttribute("data-active", "");
|
|
520
|
-
});
|
|
521
|
-
for (const event of ["pointerup", "pointercancel", "lostpointercapture", "pointerleave"]) {
|
|
522
|
-
drawer.addEventListener(event, (evt) => {
|
|
523
|
-
if (event !== "pointerleave" || !drawer.hasPointerCapture(evt.pointerId)) drawer.removeAttribute("data-active");
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
Object.assign(state, { separator, drawer, drawerIcon, drawerLabel, drawerContent });
|
|
527
|
-
separator.addEventListener("pointerdown", (evt) => this.#startDrag(side, evt));
|
|
528
|
-
separator.addEventListener("keydown", (evt) => this.#keyResize(side, evt));
|
|
529
|
-
drawer.addEventListener("click", (evt) => {
|
|
530
|
-
evt.stopPropagation();
|
|
531
|
-
if (state.suppressDrawerClick && evt.detail !== 0) {
|
|
532
|
-
state.suppressDrawerClick = false;
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
state.closed = !state.closed;
|
|
536
|
-
this.#render(side, true);
|
|
537
|
-
state.config.onToggle?.(evt, !state.closed);
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
this.#regions.set(side, state);
|
|
541
|
-
this.control.append(cell);
|
|
542
|
-
slot.addEventListener("slotchange", () => this.#sync());
|
|
543
|
-
}
|
|
544
|
-
this.cover = doc.createElement("div");
|
|
545
|
-
this.cover.className = "drag-cover";
|
|
546
|
-
this.shadowRoot.append(style, this.cover);
|
|
547
|
-
this.control.addEventListener("transitionend", (event) => {
|
|
548
|
-
if (event.target !== this.control) return;
|
|
549
|
-
this.control.removeAttribute("data-drawer-motion");
|
|
550
|
-
for (const [side, state] of this.#regions) {
|
|
551
|
-
state.separator?.setAttribute("aria-valuenow", String(Math.round(this.#extent(side))));
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
this.#observer = new doc.defaultView.MutationObserver(() => this.#sync());
|
|
555
|
-
}
|
|
556
|
-
connectedCallback() {
|
|
557
|
-
this.#observer.observe(this, { childList: true });
|
|
558
|
-
for (const state of this.#regions.values()) if (state.drawerContent) this.#contentObserver.observe(state.drawerContent);
|
|
559
|
-
this.#sync();
|
|
560
|
-
}
|
|
561
|
-
disconnectedCallback() {
|
|
562
|
-
this.#observer.disconnect();
|
|
563
|
-
this.#contentObserver.disconnect();
|
|
564
|
-
this.#stopDrag();
|
|
565
|
-
}
|
|
566
|
-
projectAttributes(attrs, adapt) {
|
|
567
|
-
const rest = super.projectAttributes(attrs, adapt);
|
|
568
|
-
if (!["headline", "sidebar"].includes(this.parameters.design)) throw new TypeError("Invalid border design");
|
|
569
|
-
if (Object.hasOwn(attrs, "liveSplitters")) throw new TypeError("Border splitters are always live; omit liveSplitters");
|
|
570
|
-
if (this.parameters.persist && !attrs.id) throw new TypeError("Persistent borderContainer requires a stable id");
|
|
571
|
-
this.control.dataset.design = this.parameters.design;
|
|
572
|
-
return rest;
|
|
573
|
-
}
|
|
574
|
-
#sync() {
|
|
575
|
-
const children = /* @__PURE__ */ new Map();
|
|
576
|
-
for (const child of this.children) {
|
|
577
|
-
const config = BorderContainer2.#borderRegions.get(child);
|
|
578
|
-
if (!config) continue;
|
|
579
|
-
if (children.has(config.region)) throw new Error(`Duplicate border region: ${config.region}`);
|
|
580
|
-
children.set(config.region, child);
|
|
581
|
-
}
|
|
582
|
-
for (const [side, state] of this.#regions) {
|
|
583
|
-
const child = children.get(side) ?? null;
|
|
584
|
-
if (state.child !== child) {
|
|
585
|
-
if (this.#drag?.side === side) this.#stopDrag();
|
|
586
|
-
state.child = child;
|
|
587
|
-
state.config = null;
|
|
588
|
-
state.visibility = null;
|
|
589
|
-
state.size = null;
|
|
590
|
-
state.closed = false;
|
|
591
|
-
}
|
|
592
|
-
if (child) this.projectRegion(child);
|
|
593
|
-
else {
|
|
594
|
-
state.config = null;
|
|
595
|
-
this.#render(side);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
projectRegion(child) {
|
|
600
|
-
const config = BorderContainer2.#borderRegions.get(child), side = config.region, state = this.#regions.get(side);
|
|
601
|
-
if (state.child !== child) {
|
|
602
|
-
this.#sync();
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
const before = state.config;
|
|
606
|
-
if (!before || before.size !== config.size) {
|
|
607
|
-
state.size = config.size || "auto";
|
|
608
|
-
if (!before && this.parameters.persist) {
|
|
609
|
-
const saved = this.ownerDocument.cookie.split("; ").find((item) => item.startsWith(`${this.#cookie(side)}=`));
|
|
610
|
-
if (saved) state.size = decodeURIComponent(saved.split("=").slice(1).join("="));
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
if (!before || before.drawer !== config.drawer) state.closed = config.drawer === "close";
|
|
614
|
-
state.config = config;
|
|
615
|
-
if (side !== "center") {
|
|
616
|
-
state.splitterAttrs = applyAttributes(state.separator, config.splitterAttrs, state.splitterAttrs);
|
|
617
|
-
state.drawerAttrs = applyAttributes(state.drawer, config.drawerAttrs, state.drawerAttrs);
|
|
618
|
-
state.separator.classList.add("separator");
|
|
619
|
-
state.drawer.classList.add("drawer");
|
|
620
|
-
state.drawer.classList.toggle("drawer-reveal", config.minimize);
|
|
621
|
-
state.drawer.classList.toggle("drawer-rotated", !horizontal(side));
|
|
622
|
-
state.drawerLabel.innerHTML = config.label ?? "";
|
|
623
|
-
state.drawerIcon.textContent = config.icon ?? "";
|
|
624
|
-
state.drawerIcon.hidden = !config.icon;
|
|
625
|
-
state.drawer.toggleAttribute("data-icon", !!config.icon);
|
|
626
|
-
state.drawer.toggleAttribute("data-labelled", !!config.label);
|
|
627
|
-
}
|
|
628
|
-
this.#render(side);
|
|
629
|
-
}
|
|
630
|
-
#render(side, animate = false) {
|
|
631
|
-
const state = this.#regions.get(side), c = state.config;
|
|
632
|
-
const visible = !!c && !c.hidden && !state.closed;
|
|
633
|
-
const previous = state.visibility;
|
|
634
|
-
state.visibility = c ? { open: visible, drawer: !!c.drawer } : null;
|
|
635
|
-
state.viewport.inert = !visible;
|
|
636
|
-
if (previous && previous.open !== visible) {
|
|
637
|
-
this.control.toggleAttribute("data-drawer-motion", !!c?.drawer && animate && !this.#drag);
|
|
638
|
-
if (this.control.hasAttribute("data-drawer-motion")) {
|
|
639
|
-
const durations = this.ownerDocument.defaultView.getComputedStyle(this.control).transitionDuration;
|
|
640
|
-
if (durations.split(",").every((duration) => Number.parseFloat(duration) === 0)) {
|
|
641
|
-
this.control.removeAttribute("data-drawer-motion");
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
state.viewport.hidden = !visible;
|
|
646
|
-
if (side === "center") return;
|
|
647
|
-
this.control.style.setProperty(`--${side}`, visible ? state.size : "0px");
|
|
648
|
-
state.separator.hidden = !c || c.hidden || !c.splitter && !c.drawer;
|
|
649
|
-
const draggable = visible && c.splitter;
|
|
650
|
-
state.cell.style.setProperty("--region-splitter", draggable ? state.separator.style[horizontal(side) ? "height" : "width"] || "var(--gramlot-splitter-size,1px)" : "0px");
|
|
651
|
-
state.separator.dataset.draggable = String(!!draggable);
|
|
652
|
-
state.separator.setAttribute("role", draggable ? "separator" : "presentation");
|
|
653
|
-
state.separator.tabIndex = draggable ? 0 : -1;
|
|
654
|
-
state.drawer.hidden = !c?.drawer;
|
|
655
|
-
state.drawer.toggleAttribute("data-resizable", !!c?.splitter);
|
|
656
|
-
state.drawer.setAttribute("aria-expanded", String(visible));
|
|
657
|
-
state.drawer.setAttribute("aria-label", `${visible ? "Close" : "Open"} ${side} region`);
|
|
658
|
-
state.drawer.title = c?.drawerAttrs.title ?? state.drawer.getAttribute("aria-label");
|
|
659
|
-
state.separator.setAttribute("aria-valuemin", String(c?.min ?? 0));
|
|
660
|
-
state.separator.setAttribute("aria-valuenow", String(Math.round(this.#extent(side))));
|
|
661
|
-
if (c && Number.isFinite(c.max)) state.separator.setAttribute("aria-valuemax", String(c.max));
|
|
662
|
-
else state.separator.removeAttribute("aria-valuemax");
|
|
663
|
-
if (c && previous && (previous.drawer || c.drawer) && previous.open !== visible) {
|
|
664
|
-
c.notifications.closableChange({ open: visible, region: side });
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
#extent(side) {
|
|
668
|
-
const box = this.#regions.get(side).cell.getBoundingClientRect();
|
|
669
|
-
return horizontal(side) ? box.height : box.width;
|
|
670
|
-
}
|
|
671
|
-
#resize(side, desired) {
|
|
672
|
-
this.control.removeAttribute("data-drawer-motion");
|
|
673
|
-
const state = this.#regions.get(side), c = state.config;
|
|
674
|
-
const opposite = { left: "right", right: "left", top: "bottom", bottom: "top" }[side];
|
|
675
|
-
const box = this.control.getBoundingClientRect();
|
|
676
|
-
const available = Math.max(0, (horizontal(side) ? box.height : box.width) - this.#extent(opposite));
|
|
677
|
-
const size = Math.max(Math.min(c.min, available), Math.min(desired, c.max, available));
|
|
678
|
-
state.size = `${size}px`;
|
|
679
|
-
this.#render(side);
|
|
680
|
-
c.writeParameter(size);
|
|
681
|
-
}
|
|
682
|
-
#keyResize(side, evt) {
|
|
683
|
-
const state = this.#regions.get(side);
|
|
684
|
-
if (evt.target !== state.separator || !state.config?.splitter || state.closed) return;
|
|
685
|
-
const keys = horizontal(side) ? ["ArrowUp", "ArrowDown"] : ["ArrowLeft", "ArrowRight"];
|
|
686
|
-
if (!keys.includes(evt.key)) return;
|
|
687
|
-
evt.preventDefault();
|
|
688
|
-
const sign = ["left", "top"].includes(side) ? 1 : -1;
|
|
689
|
-
const previousSize = this.#extent(side);
|
|
690
|
-
this.#resize(side, previousSize + (evt.key === keys[0] ? -1 : 1) * sign);
|
|
691
|
-
this.#commitResize(side, previousSize);
|
|
692
|
-
}
|
|
693
|
-
#startDrag(side, evt) {
|
|
694
|
-
const state = this.#regions.get(side);
|
|
695
|
-
if (evt.button !== 0) return;
|
|
696
|
-
state.suppressDrawerClick = false;
|
|
697
|
-
if (!state.config?.splitter) return;
|
|
698
|
-
const fromDrawer = state.drawer.contains(evt.target);
|
|
699
|
-
if (!fromDrawer) evt.preventDefault();
|
|
700
|
-
this.#stopDrag();
|
|
701
|
-
const axis = horizontal(side) ? "clientY" : "clientX", start = evt[axis], size = this.#extent(side);
|
|
702
|
-
const sign = ["left", "top"].includes(side) ? 1 : -1;
|
|
703
|
-
const controller = new this.ownerDocument.defaultView.AbortController();
|
|
704
|
-
const captureTarget = fromDrawer ? state.drawer : state.separator, pointerId = evt.pointerId;
|
|
705
|
-
let resizing = !fromDrawer;
|
|
706
|
-
this.#drag = { side, controller, captureTarget, pointerId };
|
|
707
|
-
captureTarget.setPointerCapture(pointerId);
|
|
708
|
-
if (resizing) this.cover.setAttribute("data-active", "");
|
|
709
|
-
const options = { signal: controller.signal };
|
|
710
|
-
captureTarget.addEventListener("pointermove", (event) => {
|
|
711
|
-
if (event.pointerId !== pointerId) return;
|
|
712
|
-
const distance = event[axis] - start;
|
|
713
|
-
if (!resizing && Math.abs(distance) < 4) return;
|
|
714
|
-
state.suppressDrawerClick = fromDrawer;
|
|
715
|
-
if (state.closed && sign * distance <= 0) return;
|
|
716
|
-
const opening = state.closed;
|
|
717
|
-
state.closed = false;
|
|
718
|
-
resizing = true;
|
|
719
|
-
this.cover.setAttribute("data-active", "");
|
|
720
|
-
this.#resize(side, size + sign * distance);
|
|
721
|
-
if (opening) state.config.onToggle?.(event, true);
|
|
722
|
-
}, options);
|
|
723
|
-
const finish = (event) => {
|
|
724
|
-
if (event.pointerId !== pointerId) return;
|
|
725
|
-
this.#stopDrag();
|
|
726
|
-
if (resizing) this.#commitResize(side, size);
|
|
727
|
-
};
|
|
728
|
-
captureTarget.addEventListener("pointerup", finish, options);
|
|
729
|
-
captureTarget.addEventListener("pointercancel", finish, options);
|
|
730
|
-
captureTarget.addEventListener("lostpointercapture", finish, options);
|
|
731
|
-
}
|
|
732
|
-
#stopDrag() {
|
|
733
|
-
if (!this.#drag) return;
|
|
734
|
-
const { controller, captureTarget, pointerId } = this.#drag;
|
|
735
|
-
this.#drag = null;
|
|
736
|
-
controller.abort();
|
|
737
|
-
this.cover.removeAttribute("data-active");
|
|
738
|
-
if (captureTarget.hasPointerCapture(pointerId)) captureTarget.releasePointerCapture(pointerId);
|
|
739
|
-
}
|
|
740
|
-
#commitResize(side, previousSize) {
|
|
741
|
-
const state = this.#regions.get(side), size = this.#extent(side);
|
|
742
|
-
if (size === previousSize) return;
|
|
743
|
-
this.#save(side);
|
|
744
|
-
state.config.notifications.splitterResize({ region: side, size: `${size}px`, previousSize: `${previousSize}px` });
|
|
745
|
-
}
|
|
746
|
-
#cookie(side) {
|
|
747
|
-
return encodeURIComponent(`gramlot-border-${this.id}-${side}`);
|
|
748
|
-
}
|
|
749
|
-
#save(side) {
|
|
750
|
-
if (this.parameters.persist) this.ownerDocument.cookie = `${this.#cookie(side)}=${encodeURIComponent(this.#regions.get(side).size)}; Path=/; SameSite=Lax`;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
});
|
|
754
|
-
|
|
755
|
-
// src/components/selected-container.js
|
|
756
|
-
function SelectedContainer(HTMLElement) {
|
|
757
|
-
return class SelectedContainer2 extends Container(HTMLElement) {
|
|
758
|
-
// The panel configuration of each child element and the count of the panel slots made, for this class
|
|
759
|
-
// in this window (ComponentCollection.register).
|
|
760
|
-
static #selectionPanels = /* @__PURE__ */ new WeakMap();
|
|
761
|
-
static #panelSequence = 0;
|
|
762
|
-
static projectChild(element, attrs, actions) {
|
|
763
|
-
const { pageName = null, title = "", icon = "", badge = null, badge_color = "", closable = false, onClose, hidden = false, disabled = false, ...rest } = attrs;
|
|
764
|
-
if (pageName !== null && typeof pageName !== "string") throw new TypeError("pageName must be a string");
|
|
765
|
-
if (typeof closable !== "boolean") throw new TypeError("closable must be a boolean");
|
|
766
|
-
const panels = SelectedContainer2.#selectionPanels;
|
|
767
|
-
const slot = panels.get(element)?.slot ?? `panel-${++SelectedContainer2.#panelSequence}`;
|
|
768
|
-
panels.set(element, {
|
|
769
|
-
pageName,
|
|
770
|
-
title,
|
|
771
|
-
icon,
|
|
772
|
-
badge,
|
|
773
|
-
badge_color,
|
|
774
|
-
closable,
|
|
775
|
-
hidden,
|
|
776
|
-
disabled,
|
|
777
|
-
slot,
|
|
778
|
-
remove: actions.remove,
|
|
779
|
-
allowClose: () => onClose == null ? true : actions.invoke("onClose", onClose, {})
|
|
780
|
-
});
|
|
781
|
-
rest.slot = slot;
|
|
782
|
-
if (element.parentElement) element.parentElement.scheduleSelection();
|
|
783
|
-
return rest;
|
|
784
|
-
}
|
|
785
|
-
#panels = /* @__PURE__ */ new Map();
|
|
786
|
-
#selected = null;
|
|
787
|
-
#initialized = false;
|
|
788
|
-
#scheduled = false;
|
|
789
|
-
#requested = { selectedPage: null, selected: null };
|
|
790
|
-
#observer;
|
|
791
|
-
#context;
|
|
792
|
-
constructor() {
|
|
793
|
-
super();
|
|
794
|
-
this.control.replaceChildren();
|
|
795
|
-
this.control.className = "control-box selection";
|
|
796
|
-
const style = this.ownerDocument.createElement("style");
|
|
797
|
-
style.textContent = `:host{min-height:0;overflow:hidden}.selection{height:100%;min-height:0;display:flex;flex-direction:column}
|
|
798
|
-
.panels{flex:1;min-height:0;min-width:0;position:relative}.panel{height:100%;min-height:0;overflow:auto}
|
|
799
|
-
.panel[hidden]{display:none}::slotted(*){height:100%;min-height:0}`;
|
|
800
|
-
this.panelArea = this.ownerDocument.createElement("div");
|
|
801
|
-
this.panelArea.className = "panels";
|
|
802
|
-
this.control.append(this.panelArea);
|
|
803
|
-
this.shadowRoot.append(style);
|
|
804
|
-
this.#observer = new this.ownerDocument.defaultView.MutationObserver(() => this.scheduleSelection());
|
|
805
|
-
}
|
|
806
|
-
setSourceContext(context) {
|
|
807
|
-
this.#context = context;
|
|
808
|
-
}
|
|
809
|
-
connectedCallback() {
|
|
810
|
-
this.#observer.observe(this, { childList: true });
|
|
811
|
-
this.scheduleSelection();
|
|
812
|
-
}
|
|
813
|
-
disconnectedCallback() {
|
|
814
|
-
this.#observer.disconnect();
|
|
815
|
-
}
|
|
816
|
-
scheduleSelection() {
|
|
817
|
-
if (this.#scheduled) return;
|
|
818
|
-
this.#scheduled = true;
|
|
819
|
-
queueMicrotask(() => {
|
|
820
|
-
this.#scheduled = false;
|
|
821
|
-
if (this.isConnected) this.#sync();
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
projectAttributes(attrs, adapt) {
|
|
825
|
-
const rest = super.projectAttributes(attrs, adapt);
|
|
826
|
-
const { selected, selectedPage } = this.parameters;
|
|
827
|
-
if (selected != null && (!Number.isInteger(selected) || selected < 0)) throw new TypeError("selected must be a nonnegative index or null");
|
|
828
|
-
if (selectedPage != null && typeof selectedPage !== "string") throw new TypeError("selectedPage must be a string or null");
|
|
829
|
-
this.scheduleSelection();
|
|
830
|
-
return rest;
|
|
831
|
-
}
|
|
832
|
-
#sync() {
|
|
833
|
-
const records = [], names = /* @__PURE__ */ new Set();
|
|
834
|
-
for (const child of this.children) {
|
|
835
|
-
const config = SelectedContainer2.#selectionPanels.get(child);
|
|
836
|
-
if (!config) continue;
|
|
837
|
-
if (config.pageName != null && names.has(config.pageName)) throw new Error(`Duplicate pageName: ${config.pageName}`);
|
|
838
|
-
names.add(config.pageName);
|
|
839
|
-
let record = this.#panels.get(child);
|
|
840
|
-
if (!record) {
|
|
841
|
-
const viewport = this.ownerDocument.createElement("div");
|
|
842
|
-
viewport.className = "panel";
|
|
843
|
-
viewport.hidden = true;
|
|
844
|
-
viewport.id = config.slot;
|
|
845
|
-
viewport.setAttribute("role", "group");
|
|
846
|
-
const slot = this.ownerDocument.createElement("slot");
|
|
847
|
-
slot.name = config.slot;
|
|
848
|
-
viewport.append(slot);
|
|
849
|
-
this.panelArea.append(viewport);
|
|
850
|
-
record = { child, viewport, config, index: records.length };
|
|
851
|
-
this.#panels.set(child, record);
|
|
852
|
-
}
|
|
853
|
-
record.config = config;
|
|
854
|
-
records.push(record);
|
|
855
|
-
}
|
|
856
|
-
const previousIndex = this.#selected?.index ?? 0;
|
|
857
|
-
for (const [child, record] of this.#panels) {
|
|
858
|
-
if (!records.includes(record)) {
|
|
859
|
-
record.viewport.remove();
|
|
860
|
-
this.#panels.delete(child);
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
records.forEach((record, index) => {
|
|
864
|
-
record.index = index;
|
|
865
|
-
});
|
|
866
|
-
this.#panels = new Map(records.map((record) => [record.child, record]));
|
|
867
|
-
const { selectedPage, selected } = this.parameters;
|
|
868
|
-
const nameChanged = !Object.is(selectedPage, this.#requested.selectedPage);
|
|
869
|
-
const indexChanged = !Object.is(selected, this.#requested.selected);
|
|
870
|
-
this.#requested = { selectedPage, selected };
|
|
871
|
-
const available = (record) => record && !record.config.hidden && !record.config.disabled;
|
|
872
|
-
let target = this.#selected;
|
|
873
|
-
if (!this.#initialized || nameChanged || indexChanged) {
|
|
874
|
-
const requested = nameChanged || !this.#initialized && selectedPage != null ? records.find((record) => record.config.pageName === selectedPage) : records[selected];
|
|
875
|
-
if (available(requested)) target = requested;
|
|
876
|
-
}
|
|
877
|
-
if (!records.includes(target) || !available(target)) {
|
|
878
|
-
target = records.slice(previousIndex).find(available) ?? records.slice(0, previousIndex).reverse().find(available) ?? null;
|
|
879
|
-
}
|
|
880
|
-
this.renderTabs(records, target);
|
|
881
|
-
if (records.length || this.#initialized) this.#select(target);
|
|
882
|
-
}
|
|
883
|
-
renderTabs() {
|
|
884
|
-
}
|
|
885
|
-
selectPanel(record) {
|
|
886
|
-
if (record.config.hidden || record.config.disabled) return;
|
|
887
|
-
this.#select(record);
|
|
888
|
-
}
|
|
889
|
-
#payload(record, selected) {
|
|
890
|
-
const page = record.config.pageName ?? record.index;
|
|
891
|
-
return { page, index: record.index, selected, change: `${page}_${selected ? "show" : "hide"}` };
|
|
892
|
-
}
|
|
893
|
-
#writeSelection(target) {
|
|
894
|
-
this.#context.writeParameter("selectedPage", target?.config.pageName ?? null);
|
|
895
|
-
this.#context.writeParameter("selected", target?.index ?? null);
|
|
896
|
-
}
|
|
897
|
-
#select(target) {
|
|
898
|
-
const previous = this.#selected, initial = !this.#initialized;
|
|
899
|
-
if (!initial && target === previous) {
|
|
900
|
-
this.#writeSelection(target);
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
if (!initial) {
|
|
904
|
-
if (previous) this.#context.publish("hiding", { pageName: previous.config.pageName, index: previous.index });
|
|
905
|
-
if (target) this.#context.publish("showing", { pageName: target.config.pageName, index: target.index });
|
|
906
|
-
}
|
|
907
|
-
this.#selected = target;
|
|
908
|
-
this.#initialized = true;
|
|
909
|
-
for (const record of this.#panels.values()) record.viewport.hidden = record !== target;
|
|
910
|
-
this.renderTabs([...this.#panels.values()], target);
|
|
911
|
-
this.#writeSelection(target);
|
|
912
|
-
if (!initial && previous) this.#context.publish("selected", this.#payload(previous, false));
|
|
913
|
-
if (target) this.#context.publish("selected", this.#payload(target, true));
|
|
914
|
-
}
|
|
915
|
-
closePanel(record) {
|
|
916
|
-
if (!record.config.closable) return;
|
|
917
|
-
const allowed = record.config.allowClose();
|
|
918
|
-
if (typeof allowed !== "boolean") throw new TypeError("onClose must return a synchronous boolean");
|
|
919
|
-
if (!allowed) return;
|
|
920
|
-
const payload = { pageName: record.config.pageName, index: record.index, wasSelected: record === this.#selected };
|
|
921
|
-
this.#context.publish("closing", payload);
|
|
922
|
-
record.config.remove();
|
|
923
|
-
this.#sync();
|
|
924
|
-
this.#context.publish("closed", payload);
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
SelectedContainer.parameters = {
|
|
929
|
-
selectedPage: { dtype: "T", default: null, nullable: true, binding: "twoWay" },
|
|
930
|
-
selected: { dtype: "L", default: null, nullable: true, binding: "twoWay" }
|
|
931
|
-
};
|
|
932
|
-
var selectionChildParameters = { onClose: { inline: [] } };
|
|
933
|
-
var StackContainer = defineComponent({
|
|
934
|
-
name: "stackContainer",
|
|
935
|
-
tag: "gramlot-stack-container",
|
|
936
|
-
base: SelectedContainer,
|
|
937
|
-
subTags: "*",
|
|
938
|
-
sourceContext: true,
|
|
939
|
-
childParameters: selectionChildParameters,
|
|
940
|
-
implementation: (Base) => class extends Base {
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
var TabContainer = defineComponent({
|
|
944
|
-
name: "tabContainer",
|
|
945
|
-
tag: "gramlot-tab-container",
|
|
946
|
-
base: SelectedContainer,
|
|
947
|
-
subTags: "*",
|
|
948
|
-
sourceContext: true,
|
|
949
|
-
childParameters: selectionChildParameters,
|
|
950
|
-
parameters: {
|
|
951
|
-
tabMode: { dtype: "T", default: "tabs", binding: "read", enum: ["tabs", "underline"] },
|
|
952
|
-
tabPosition: { dtype: "T", default: "top", binding: "read", enum: ["top", "bottom", "left", "right"] },
|
|
953
|
-
tabAlign: { dtype: "T", default: "start", binding: "read", enum: ["start", "center", "end"] }
|
|
954
|
-
},
|
|
955
|
-
implementation: (Base) => class extends Base {
|
|
956
|
-
#tabs = /* @__PURE__ */ new Map();
|
|
957
|
-
constructor() {
|
|
958
|
-
super();
|
|
959
|
-
const doc = this.ownerDocument;
|
|
960
|
-
this.tabStrip = doc.createElement("div");
|
|
961
|
-
this.tabStrip.className = "tabs";
|
|
962
|
-
this.tabStrip.setAttribute("role", "tablist");
|
|
963
|
-
this.control.prepend(this.tabStrip);
|
|
964
|
-
const style = doc.createElement("style");
|
|
965
|
-
style.textContent = `
|
|
966
|
-
.selection{min-width:0;--tab-border:var(--gramlot-tab-border,var(--gramlot-border,#aaa));
|
|
967
|
-
--tab-radius:var(--gramlot-tab-radius,4px);--tab-indicator:var(--gramlot-tab-indicator-color,var(--gramlot-action,#3766b5))}
|
|
968
|
-
.panels{background:var(--gramlot-tab-selected-background,var(--gramlot-surface,white))}
|
|
969
|
-
.tabs{display:var(--gramlot-tab-strip-display,flex);flex:none;align-items:stretch;gap:var(--gramlot-tab-gap,3px);min-width:0;min-height:0;
|
|
970
|
-
padding:var(--gramlot-tab-strip-padding,4px);overflow:auto;overscroll-behavior:contain;
|
|
971
|
-
border-bottom:1px solid var(--tab-border);background:var(--gramlot-tab-background,var(--gramlot-surface-subtle,#eef1f5))}
|
|
972
|
-
[data-align=center] .tabs{justify-content:safe center}
|
|
973
|
-
[data-align=end] .tabs{justify-content:safe flex-end}
|
|
974
|
-
.tab-entry{position:relative;display:flex;flex:none;align-items:stretch;border:1px solid transparent;border-bottom:0;
|
|
975
|
-
border-radius:var(--tab-radius) var(--tab-radius) 0 0;color:var(--gramlot-tab-color,var(--gramlot-text-secondary,#555))}
|
|
976
|
-
.tab-entry:has([aria-selected=true]){border-color:var(--tab-border);color:var(--gramlot-tab-selected-color,var(--gramlot-ink,#222));
|
|
977
|
-
background:var(--gramlot-tab-selected-background,var(--gramlot-surface,white))}
|
|
978
|
-
button{box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:var(--gramlot-tab-content-gap,.4em);
|
|
979
|
-
font:inherit;line-height:1.2;color:inherit;border:0;background:transparent;cursor:pointer;white-space:nowrap;min-width:0;
|
|
980
|
-
padding:var(--gramlot-tab-padding,4px 10px);min-height:max(var(--gramlot-touch-target,0px),var(--gramlot-tab-height,28px));border-radius:inherit}
|
|
981
|
-
button[aria-selected=true]{font-weight:600}
|
|
982
|
-
.icon,.badge{flex:none}.icon:empty{display:none}.caption{overflow:hidden;text-overflow:ellipsis}
|
|
983
|
-
.badge{font-size:var(--gramlot-tab-badge-size,.8em);font-weight:600;line-height:1.3;border-radius:999px;
|
|
984
|
-
min-width:1.3em;padding:var(--gramlot-tab-badge-padding,0 .35em);text-align:center;
|
|
985
|
-
background:var(--gramlot-tab-badge-background,var(--gramlot-brand-blue,#3766b5));color:var(--gramlot-tab-badge-color,white)}
|
|
986
|
-
@media(hover:hover){button:not(:disabled):hover{background:var(--gramlot-tab-hover-background,var(--gramlot-selected,#e8f1fc))}}
|
|
987
|
-
button:disabled{opacity:.5;cursor:default}
|
|
988
|
-
button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-3px}
|
|
989
|
-
.close{align-self:center;flex:none;min-height:var(--gramlot-touch-target,20px);min-width:var(--gramlot-touch-target,20px);
|
|
990
|
-
padding:0;margin-inline-end:3px;border-radius:var(--tab-radius);font-size:1.15em}
|
|
991
|
-
[hidden]{display:none!important}
|
|
992
|
-
[data-position=top] .tabs{padding-bottom:0}
|
|
993
|
-
[data-position=bottom]{flex-direction:column-reverse}
|
|
994
|
-
[data-position=bottom] .tabs{border-bottom:0;border-top:1px solid var(--tab-border);padding-top:0}
|
|
995
|
-
[data-position=bottom] .tab-entry{border-bottom:1px solid transparent;border-top:0;border-radius:0 0 var(--tab-radius) var(--tab-radius)}
|
|
996
|
-
[data-position=left]{flex-direction:row}[data-position=right]{flex-direction:row-reverse}
|
|
997
|
-
:is([data-position=left],[data-position=right]) .tabs{flex-direction:column;max-width:min(40%,var(--gramlot-tab-side-width,12rem));border-bottom:0}
|
|
998
|
-
:is([data-position=left],[data-position=right]) button[role=tab]{flex:1;justify-content:flex-start}
|
|
999
|
-
[data-position=left] .tabs{border-right:1px solid var(--tab-border);padding-right:0}
|
|
1000
|
-
[data-position=right] .tabs{border-left:1px solid var(--tab-border);padding-left:0}
|
|
1001
|
-
[data-position=left] .tab-entry{border-bottom:1px solid transparent;border-right:0;border-radius:var(--tab-radius) 0 0 var(--tab-radius)}
|
|
1002
|
-
[data-position=right] .tab-entry{border-bottom:1px solid transparent;border-left:0;border-radius:0 var(--tab-radius) var(--tab-radius) 0}
|
|
1003
|
-
.tab-entry:has([aria-selected=true]){border-color:var(--tab-border)}
|
|
1004
|
-
[data-mode=underline] .tabs{background:transparent}
|
|
1005
|
-
[data-mode=underline] .tab-entry{border:0;border-radius:0;background:transparent}
|
|
1006
|
-
[data-mode=underline] .tab-entry:has([aria-selected=true])::after{content:'';position:absolute;pointer-events:none;
|
|
1007
|
-
background:var(--tab-indicator);height:var(--gramlot-tab-indicator-size,2px);bottom:0;left:0;right:0}
|
|
1008
|
-
[data-mode=underline][data-position=bottom] .tab-entry::after{top:0;bottom:auto}
|
|
1009
|
-
[data-mode=underline]:is([data-position=left],[data-position=right]) .tab-entry::after{height:auto;width:var(--gramlot-tab-indicator-size,2px);top:0;bottom:0}
|
|
1010
|
-
[data-mode=underline][data-position=left] .tab-entry::after{left:auto;right:0}
|
|
1011
|
-
[data-mode=underline][data-position=right] .tab-entry::after{left:0;right:auto}`;
|
|
1012
|
-
this.shadowRoot.append(style);
|
|
1013
|
-
}
|
|
1014
|
-
projectAttributes(attrs, adapt) {
|
|
1015
|
-
const rest = super.projectAttributes(attrs, adapt);
|
|
1016
|
-
const { tabMode, tabPosition, tabAlign } = this.parameters;
|
|
1017
|
-
if (!["tabs", "underline"].includes(tabMode)) throw new TypeError("Invalid tabMode");
|
|
1018
|
-
if (!["top", "bottom", "left", "right"].includes(tabPosition)) throw new TypeError("Invalid tabPosition");
|
|
1019
|
-
if (!["start", "center", "end"].includes(tabAlign)) throw new TypeError("Invalid tabAlign");
|
|
1020
|
-
this.control.dataset.mode = tabMode;
|
|
1021
|
-
this.control.dataset.position = tabPosition;
|
|
1022
|
-
this.control.dataset.align = tabAlign;
|
|
1023
|
-
this.tabStrip.setAttribute("aria-orientation", ["left", "right"].includes(tabPosition) ? "vertical" : "horizontal");
|
|
1024
|
-
return rest;
|
|
1025
|
-
}
|
|
1026
|
-
renderTabs(records, selected) {
|
|
1027
|
-
for (const [record, entry] of this.#tabs) {
|
|
1028
|
-
if (!records.includes(record)) {
|
|
1029
|
-
entry.root.remove();
|
|
1030
|
-
this.#tabs.delete(record);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
for (const [index, record] of records.entries()) {
|
|
1034
|
-
let entry = this.#tabs.get(record);
|
|
1035
|
-
if (!entry) {
|
|
1036
|
-
const doc = this.ownerDocument, root = doc.createElement("div"), button = doc.createElement("button"), close = doc.createElement("button");
|
|
1037
|
-
root.className = "tab-entry";
|
|
1038
|
-
button.type = close.type = "button";
|
|
1039
|
-
button.setAttribute("role", "tab");
|
|
1040
|
-
button.id = `tab-${record.config.slot}`;
|
|
1041
|
-
button.setAttribute("aria-controls", record.viewport.id);
|
|
1042
|
-
record.viewport.setAttribute("role", "tabpanel");
|
|
1043
|
-
record.viewport.setAttribute("aria-labelledby", button.id);
|
|
1044
|
-
const icon = doc.createElement("span"), caption2 = doc.createElement("span"), badge = doc.createElement("span");
|
|
1045
|
-
icon.className = "icon";
|
|
1046
|
-
icon.setAttribute("aria-hidden", "true");
|
|
1047
|
-
caption2.className = "caption";
|
|
1048
|
-
badge.className = "badge";
|
|
1049
|
-
button.append(icon, caption2, badge);
|
|
1050
|
-
close.className = "close";
|
|
1051
|
-
close.textContent = "\xD7";
|
|
1052
|
-
button.addEventListener("click", () => this.selectPanel(record));
|
|
1053
|
-
close.addEventListener("click", () => {
|
|
1054
|
-
this.closePanel(record);
|
|
1055
|
-
if (!close.isConnected) this.tabStrip.querySelector("[aria-selected=true]")?.focus();
|
|
1056
|
-
});
|
|
1057
|
-
button.addEventListener("keydown", (event) => {
|
|
1058
|
-
if (event.key === "Delete") {
|
|
1059
|
-
event.preventDefault();
|
|
1060
|
-
this.closePanel(record);
|
|
1061
|
-
this.tabStrip.querySelector("[aria-selected=true]")?.focus();
|
|
1062
|
-
return;
|
|
1063
|
-
}
|
|
1064
|
-
const vertical = ["left", "right"].includes(this.parameters.tabPosition);
|
|
1065
|
-
const previous = vertical ? "ArrowUp" : "ArrowLeft", nextKey = vertical ? "ArrowDown" : "ArrowRight";
|
|
1066
|
-
if (![previous, nextKey, "Home", "End"].includes(event.key)) return;
|
|
1067
|
-
event.preventDefault();
|
|
1068
|
-
const available = [...this.#tabs].filter(([r]) => !r.config.hidden && !r.config.disabled).sort(([a], [b]) => a.index - b.index);
|
|
1069
|
-
let index2 = available.findIndex(([r]) => r === record);
|
|
1070
|
-
index2 = event.key === "Home" ? 0 : event.key === "End" ? available.length - 1 : (index2 + (event.key === nextKey ? 1 : -1) + available.length) % available.length;
|
|
1071
|
-
const [next, tab] = available[index2];
|
|
1072
|
-
this.selectPanel(next);
|
|
1073
|
-
tab.button.focus();
|
|
1074
|
-
tab.button.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
1075
|
-
});
|
|
1076
|
-
root.append(button, close);
|
|
1077
|
-
this.tabStrip.append(root);
|
|
1078
|
-
entry = { root, button, close, icon, caption: caption2, badge };
|
|
1079
|
-
this.#tabs.set(record, entry);
|
|
1080
|
-
}
|
|
1081
|
-
if (this.tabStrip.children[index] !== entry.root) this.tabStrip.insertBefore(entry.root, this.tabStrip.children[index] ?? null);
|
|
1082
|
-
entry.root.hidden = !!record.config.hidden;
|
|
1083
|
-
const caption = record.config.title || record.config.pageName || String(record.index + 1);
|
|
1084
|
-
entry.caption.textContent = caption;
|
|
1085
|
-
entry.button.title = caption;
|
|
1086
|
-
entry.icon.textContent = record.config.icon;
|
|
1087
|
-
entry.badge.textContent = record.config.badge ?? "";
|
|
1088
|
-
entry.badge.hidden = record.config.badge == null || record.config.badge === "";
|
|
1089
|
-
entry.badge.style.backgroundColor = record.config.badge_color;
|
|
1090
|
-
entry.button.setAttribute("aria-label", entry.badge.hidden ? caption : `${caption} ${record.config.badge}`);
|
|
1091
|
-
entry.button.disabled = !!record.config.disabled;
|
|
1092
|
-
entry.button.setAttribute("aria-selected", String(record === selected));
|
|
1093
|
-
entry.button.tabIndex = record === selected ? 0 : -1;
|
|
1094
|
-
entry.close.hidden = !record.config.closable;
|
|
1095
|
-
entry.close.disabled = !!record.config.disabled;
|
|
1096
|
-
entry.close.setAttribute("aria-label", `Close ${caption}`);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
});
|
|
1101
|
-
|
|
1102
|
-
// src/components/popup.js
|
|
1103
|
-
var VIEWPORT_MARGIN = 8;
|
|
1104
|
-
var ANCHOR_GAP = 3;
|
|
1105
|
-
function positionPopup(popup, anchor, { align = "start", matchWidth = false, inset = 0 } = {}) {
|
|
1106
|
-
const view = anchor.ownerDocument.defaultView;
|
|
1107
|
-
const field = anchor.getBoundingClientRect();
|
|
1108
|
-
const availableWidth = Math.max(0, view.innerWidth - 2 * VIEWPORT_MARGIN);
|
|
1109
|
-
popup.style.setProperty("--gramlot-popup-available-width", `${availableWidth}px`);
|
|
1110
|
-
if (matchWidth) popup.style.width = `${Math.min(Math.max(0, field.width - 2 * inset), availableWidth)}px`;
|
|
1111
|
-
popup.style.removeProperty("--gramlot-popup-available-height");
|
|
1112
|
-
const natural = popup.getBoundingClientRect();
|
|
1113
|
-
const below = Math.max(0, view.innerHeight - VIEWPORT_MARGIN - field.bottom - ANCHOR_GAP);
|
|
1114
|
-
const above = Math.max(0, field.top - VIEWPORT_MARGIN - ANCHOR_GAP);
|
|
1115
|
-
const upwards = natural.height > below && above > below;
|
|
1116
|
-
popup.style.setProperty("--gramlot-popup-available-height", `${upwards ? above : below}px`);
|
|
1117
|
-
const size = popup.getBoundingClientRect();
|
|
1118
|
-
const left = align === "end" ? field.right - size.width - inset : field.left + inset;
|
|
1119
|
-
const top = upwards ? field.top - size.height - ANCHOR_GAP : field.bottom + ANCHOR_GAP;
|
|
1120
|
-
popup.style.left = `${Math.max(VIEWPORT_MARGIN, Math.min(left, view.innerWidth - size.width - VIEWPORT_MARGIN))}px`;
|
|
1121
|
-
popup.style.top = `${Math.max(VIEWPORT_MARGIN, Math.min(top, view.innerHeight - size.height - VIEWPORT_MARGIN))}px`;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
// src/components/formlet-labels.js
|
|
1125
|
-
var FormletLabels = class {
|
|
1126
|
-
#fields = /* @__PURE__ */ new Set();
|
|
1127
|
-
#observer;
|
|
1128
|
-
#frame;
|
|
1129
|
-
constructor(formlet) {
|
|
1130
|
-
this.formlet = formlet;
|
|
1131
|
-
this.window = formlet.ownerDocument.defaultView;
|
|
1132
|
-
this.slot = formlet.control.querySelector("slot");
|
|
1133
|
-
}
|
|
1134
|
-
connect() {
|
|
1135
|
-
this.#observer = new this.window.ResizeObserver(this.schedule);
|
|
1136
|
-
this.#observer.observe(this.formlet.control);
|
|
1137
|
-
this.slot.addEventListener("slotchange", this.schedule);
|
|
1138
|
-
this.formlet.addEventListener("gramlot-label-layout", this.schedule);
|
|
1139
|
-
this.formlet.ownerDocument.fonts.addEventListener("loadingdone", this.schedule);
|
|
1140
|
-
this.schedule();
|
|
1141
|
-
}
|
|
1142
|
-
disconnect() {
|
|
1143
|
-
this.#observer.disconnect();
|
|
1144
|
-
this.window.cancelAnimationFrame(this.#frame);
|
|
1145
|
-
this.#frame = void 0;
|
|
1146
|
-
this.slot.removeEventListener("slotchange", this.schedule);
|
|
1147
|
-
this.formlet.removeEventListener("gramlot-label-layout", this.schedule);
|
|
1148
|
-
this.formlet.ownerDocument.fonts.removeEventListener("loadingdone", this.schedule);
|
|
1149
|
-
for (const field of this.#fields) this.#clear(field);
|
|
1150
|
-
this.#fields.clear();
|
|
1151
|
-
}
|
|
1152
|
-
schedule = () => {
|
|
1153
|
-
if (!this.formlet.isConnected || this.#frame !== void 0) return;
|
|
1154
|
-
this.#frame = this.window.requestAnimationFrame(() => {
|
|
1155
|
-
this.#frame = void 0;
|
|
1156
|
-
this.#align();
|
|
1157
|
-
});
|
|
1158
|
-
};
|
|
1159
|
-
#clear(field) {
|
|
1160
|
-
delete field.box.dataset.formletAligned;
|
|
1161
|
-
field.box.style.removeProperty("--gramlot-formlet-label-width");
|
|
1162
|
-
}
|
|
1163
|
-
#align() {
|
|
1164
|
-
const fields = new Set(this.slot.assignedElements().filter((field) => "fieldLabel" in field && field.box.dataset.position === "L"));
|
|
1165
|
-
for (const field of this.#fields) if (!fields.has(field)) {
|
|
1166
|
-
this.#observer.unobserve(field.fieldLabel);
|
|
1167
|
-
this.#clear(field);
|
|
1168
|
-
}
|
|
1169
|
-
for (const field of fields) {
|
|
1170
|
-
field.box.dataset.formletAligned = "";
|
|
1171
|
-
if (!this.#fields.has(field)) this.#observer.observe(field.fieldLabel);
|
|
1172
|
-
}
|
|
1173
|
-
this.#fields = fields;
|
|
1174
|
-
const columns = /* @__PURE__ */ new Map();
|
|
1175
|
-
for (const field of fields) {
|
|
1176
|
-
if (!field.getClientRects().length) continue;
|
|
1177
|
-
const host = field.getBoundingClientRect();
|
|
1178
|
-
const label = field.labelBox.getBoundingClientRect();
|
|
1179
|
-
const style = this.window.getComputedStyle(field.labelBox);
|
|
1180
|
-
const boxStyle = this.window.getComputedStyle(field.box);
|
|
1181
|
-
const gap = parseFloat(boxStyle.columnGap) || 0;
|
|
1182
|
-
const labelLeft = field.labelBox.hidden ? field.box.getBoundingClientRect().left + parseFloat(boxStyle.paddingLeft) + parseFloat(boxStyle.borderLeftWidth) : label.left;
|
|
1183
|
-
const inset = labelLeft - host.left + gap;
|
|
1184
|
-
const width = field.box.style.getPropertyValue("--gramlot-label-width") ? label.width : field.fieldLabel.getBoundingClientRect().width + parseFloat(style.paddingLeft) + parseFloat(style.paddingRight) + parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
|
|
1185
|
-
const column = columns.get(host.left) ?? [];
|
|
1186
|
-
column.push({ field, inset, width });
|
|
1187
|
-
columns.set(host.left, column);
|
|
1188
|
-
}
|
|
1189
|
-
for (const column of columns.values()) {
|
|
1190
|
-
const edge = Math.max(...column.map(({ inset, width }) => inset + width));
|
|
1191
|
-
for (const { field, inset } of column) {
|
|
1192
|
-
field.box.style.setProperty("--gramlot-formlet-label-width", `${edge - inset}px`);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
};
|
|
1197
|
-
|
|
1198
|
-
// src/components/layout.js
|
|
1199
|
-
var COPY_FEEDBACK_DURATION = 1600;
|
|
1200
|
-
var Formlet = defineComponent({
|
|
1201
|
-
name: "formlet",
|
|
1202
|
-
tag: "gramlot-formlet",
|
|
1203
|
-
base: Container,
|
|
1204
|
-
subTags: "*",
|
|
1205
|
-
presentationDefaults: ["lbl_", "box_"],
|
|
1206
|
-
parameters: {
|
|
1207
|
-
columns: { dtype: ["L", "T"], default: 1, binding: "read" },
|
|
1208
|
-
col_min_width: { dtype: "T", nullable: true, binding: "read" }
|
|
1209
|
-
},
|
|
1210
|
-
implementation: (Base) => class extends Base {
|
|
1211
|
-
#labels;
|
|
1212
|
-
constructor() {
|
|
1213
|
-
super();
|
|
1214
|
-
const style = this.ownerDocument.createElement("style");
|
|
1215
|
-
style.textContent = `.control-box{display:grid;gap:inherit;align-items:start}
|
|
1216
|
-
:host{gap:var(--gramlot-formlet-gap,8px 16px)}`;
|
|
1217
|
-
this.shadowRoot.append(style);
|
|
1218
|
-
this.#labels = new FormletLabels(this);
|
|
1219
|
-
}
|
|
1220
|
-
connectedCallback() {
|
|
1221
|
-
this.#labels.connect();
|
|
1222
|
-
}
|
|
1223
|
-
disconnectedCallback() {
|
|
1224
|
-
this.#labels.disconnect();
|
|
1225
|
-
}
|
|
1226
|
-
projectAttributes(attrs, adapt) {
|
|
1227
|
-
const rest = super.projectAttributes(attrs, adapt);
|
|
1228
|
-
const { columns, col_min_width } = this.parameters;
|
|
1229
|
-
if (typeof columns === "number" && (!Number.isInteger(columns) || columns < 1)) {
|
|
1230
|
-
throw new TypeError("formlet columns must be a positive integer or CSS track list");
|
|
1231
|
-
}
|
|
1232
|
-
this.control.style.gridTemplateColumns = col_min_width ? `repeat(auto-fit, minmax(min(100%, ${col_min_width}), 1fr))` : typeof columns === "number" ? `repeat(${columns}, minmax(0, 1fr))` : columns;
|
|
1233
|
-
this.#labels.schedule();
|
|
1234
|
-
return Object.fromEntries(Object.entries(rest).filter(([name]) => !/^(lbl_|box_)/.test(name)));
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
});
|
|
1238
|
-
var GroupBox = defineComponent({
|
|
1239
|
-
name: "groupBox",
|
|
1240
|
-
tag: "gramlot-group-box",
|
|
1241
|
-
base: Container,
|
|
1242
|
-
subTags: "*",
|
|
1243
|
-
dataScope: true,
|
|
1244
|
-
mixins: [Labelbox],
|
|
1245
|
-
parameters: {
|
|
1246
|
-
copy: { dtype: "B", default: false, binding: "read" },
|
|
1247
|
-
lbl_variant: { dtype: "T", default: "bar", binding: "read", enum: ["bar", "underline"] }
|
|
1248
|
-
},
|
|
1249
|
-
implementation: (Base) => class extends Base {
|
|
1250
|
-
#generation = 0;
|
|
1251
|
-
#timer;
|
|
1252
|
-
#busy = false;
|
|
1253
|
-
#menuEvents;
|
|
1254
|
-
#menuOpen = false;
|
|
1255
|
-
constructor() {
|
|
1256
|
-
super();
|
|
1257
|
-
this.control.setAttribute("role", "group");
|
|
1258
|
-
this.fieldLabel.removeAttribute("for");
|
|
1259
|
-
const doc = this.ownerDocument;
|
|
1260
|
-
const style = doc.createElement("style");
|
|
1261
|
-
style.textContent = `.labelbox{gap:0;border:1px solid var(--gramlot-border-control,#aaa);border-radius:var(--gramlot-radius-sm,4px)}
|
|
1262
|
-
.label-box{display:flex;align-items:center;gap:.4em;padding:var(--gramlot-group-header-padding,.35em .65em);background:var(--gramlot-surface-subtle,#eef1f5)}
|
|
1263
|
-
.label-box[hidden]{display:none}.label-box label{flex:1;min-width:0}
|
|
1264
|
-
.control-box{padding:var(--gramlot-group-padding,.65em)}.labelbox[data-variant=underline]{border:0}
|
|
1265
|
-
[data-variant=underline]>.label-box{background:transparent;border-bottom:1px solid var(--gramlot-border-control,#aaa)}
|
|
1266
|
-
.actions{display:flex;align-items:center}.actions[hidden]{display:none}
|
|
1267
|
-
button{font:inherit;color:inherit;cursor:pointer;border:0;border-radius:var(--gramlot-radius-sm,4px);background:transparent;
|
|
1268
|
-
padding:var(--gramlot-group-action-padding,.2em .4em);min-width:var(--gramlot-touch-target,var(--gramlot-group-action-size,24px));min-height:var(--gramlot-touch-target,var(--gramlot-group-action-size,24px))}
|
|
1269
|
-
button:hover{background:var(--gramlot-field-readonly-background,#ddd)}button:disabled{opacity:.5}
|
|
1270
|
-
button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight)}
|
|
1271
|
-
.copy-menu{max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);max-height:var(--gramlot-popup-available-height,100vh);overflow:auto;border:1px solid var(--gramlot-border-control,#aaa);
|
|
1272
|
-
background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText);border-radius:var(--gramlot-radius-sm,4px)}
|
|
1273
|
-
.copy-menu button{display:block;width:100%;text-align:left}
|
|
1274
|
-
.status{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}`;
|
|
1275
|
-
this.actions = doc.createElement("span");
|
|
1276
|
-
this.actions.className = "actions";
|
|
1277
|
-
this.copyButton = doc.createElement("button");
|
|
1278
|
-
this.copyButton.type = "button";
|
|
1279
|
-
this.copyButton.textContent = "\u29C9";
|
|
1280
|
-
this.copyButton.title = "Copy TYTX";
|
|
1281
|
-
this.copyButton.setAttribute("aria-label", "Copy TYTX");
|
|
1282
|
-
this.menuButton = doc.createElement("button");
|
|
1283
|
-
this.menuButton.type = "button";
|
|
1284
|
-
this.menuButton.textContent = "\u25BE";
|
|
1285
|
-
this.menuButton.setAttribute("aria-label", "Choose copy format");
|
|
1286
|
-
this.menuButton.setAttribute("aria-expanded", "false");
|
|
1287
|
-
this.copyMenu = doc.createElement("div");
|
|
1288
|
-
this.copyMenu.className = "copy-menu";
|
|
1289
|
-
this.copyMenu.id = "copy-menu";
|
|
1290
|
-
this.copyMenu.setAttribute("popover", "auto");
|
|
1291
|
-
this.menuButton.setAttribute("aria-controls", "copy-menu");
|
|
1292
|
-
for (const format of ["TYTX", "JSON"]) {
|
|
1293
|
-
const button = doc.createElement("button");
|
|
1294
|
-
button.type = "button";
|
|
1295
|
-
button.textContent = `Copy ${format}`;
|
|
1296
|
-
button.addEventListener("click", () => {
|
|
1297
|
-
this.closeCopyMenu();
|
|
1298
|
-
this.copyData(format);
|
|
1299
|
-
});
|
|
1300
|
-
this.copyMenu.append(button);
|
|
1301
|
-
}
|
|
1302
|
-
this.status = doc.createElement("span");
|
|
1303
|
-
this.status.className = "status";
|
|
1304
|
-
this.status.setAttribute("role", "status");
|
|
1305
|
-
this.copyButton.addEventListener("click", () => this.copyData("TYTX"));
|
|
1306
|
-
this.menuButton.addEventListener("click", () => {
|
|
1307
|
-
if (this.#menuOpen) {
|
|
1308
|
-
this.closeCopyMenu();
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
this.copyMenu.showPopover();
|
|
1312
|
-
this.#menuOpen = true;
|
|
1313
|
-
positionPopup(this.copyMenu, this.menuButton, { align: "end" });
|
|
1314
|
-
const view = doc.defaultView;
|
|
1315
|
-
this.#menuEvents = new view.AbortController();
|
|
1316
|
-
const options = { capture: true, signal: this.#menuEvents.signal };
|
|
1317
|
-
view.addEventListener("scroll", (event) => {
|
|
1318
|
-
if (!event.composedPath().includes(this.copyMenu)) this.closeCopyMenu();
|
|
1319
|
-
}, options);
|
|
1320
|
-
view.addEventListener("resize", () => this.closeCopyMenu(), options);
|
|
1321
|
-
this.copyMenu.firstElementChild.focus();
|
|
1322
|
-
});
|
|
1323
|
-
this.copyMenu.addEventListener("toggle", (event) => {
|
|
1324
|
-
this.menuButton.setAttribute("aria-expanded", String(event.newState === "open"));
|
|
1325
|
-
if (event.newState === "closed") {
|
|
1326
|
-
this.#menuOpen = false;
|
|
1327
|
-
this.#menuEvents?.abort();
|
|
1328
|
-
this.#menuEvents = null;
|
|
1329
|
-
}
|
|
1330
|
-
});
|
|
1331
|
-
this.actions.append(this.copyButton, this.menuButton, this.status);
|
|
1332
|
-
this.labelBox.append(this.actions);
|
|
1333
|
-
this.shadowRoot.append(style, this.copyMenu);
|
|
1334
|
-
}
|
|
1335
|
-
closeCopyMenu() {
|
|
1336
|
-
if (this.#menuOpen) this.copyMenu.hidePopover();
|
|
1337
|
-
this.#menuOpen = false;
|
|
1338
|
-
this.#menuEvents?.abort();
|
|
1339
|
-
this.#menuEvents = null;
|
|
1340
|
-
this.menuButton.setAttribute("aria-expanded", "false");
|
|
1341
|
-
}
|
|
1342
|
-
projectAttributes(attrs, adapt) {
|
|
1343
|
-
const rest = super.projectAttributes(attrs, adapt);
|
|
1344
|
-
if (!this.constructor.gramlotComponent.parameters.lbl_variant.enum.includes(this.parameters.lbl_variant)) throw new TypeError("groupBox lbl_variant must be bar or underline");
|
|
1345
|
-
this.box.dataset.variant = this.parameters.lbl_variant;
|
|
1346
|
-
this.actions.hidden = !this.parameters.copy;
|
|
1347
|
-
if (!this.parameters.copy) this.closeCopyMenu();
|
|
1348
|
-
this.labelBox.hidden = this.labelBox.hidden && !this.parameters.copy;
|
|
1349
|
-
this.copyButton.disabled = this.#busy;
|
|
1350
|
-
this.menuButton.disabled = this.#busy;
|
|
1351
|
-
return rest;
|
|
1352
|
-
}
|
|
1353
|
-
async copyData(format = "TYTX") {
|
|
1354
|
-
if (!["TYTX", "JSON"].includes(format)) throw new TypeError("Copy format must be TYTX or JSON");
|
|
1355
|
-
if (!this.parameters.copy || this.#busy || !this.isConnected) return;
|
|
1356
|
-
const generation = ++this.#generation;
|
|
1357
|
-
this.copyButton.title = "Copy TYTX";
|
|
1358
|
-
this.copyButton.textContent = "\u29C9";
|
|
1359
|
-
this.status.textContent = "";
|
|
1360
|
-
this.#busy = true;
|
|
1361
|
-
this.copyButton.disabled = this.menuButton.disabled = true;
|
|
1362
|
-
this.ownerDocument.defaultView.clearTimeout(this.#timer);
|
|
1363
|
-
try {
|
|
1364
|
-
const bag = this.readDataScope();
|
|
1365
|
-
const text = format === "TYTX" ? bag.toTytx() : JSON.stringify(bag.asDict(false, false, true), null, 2);
|
|
1366
|
-
await this.ownerDocument.defaultView.navigator.clipboard.writeText(text);
|
|
1367
|
-
if (generation !== this.#generation || !this.isConnected) return;
|
|
1368
|
-
this.copyButton.textContent = "\u2713";
|
|
1369
|
-
this.status.textContent = `Copied ${format}`;
|
|
1370
|
-
this.#timer = this.ownerDocument.defaultView.setTimeout(() => {
|
|
1371
|
-
this.copyButton.textContent = "\u29C9";
|
|
1372
|
-
this.status.textContent = "";
|
|
1373
|
-
}, COPY_FEEDBACK_DURATION);
|
|
1374
|
-
} catch (error) {
|
|
1375
|
-
if (generation !== this.#generation || !this.isConnected) return;
|
|
1376
|
-
this.copyButton.textContent = "!";
|
|
1377
|
-
this.copyButton.title = this.status.textContent = `Copy failed: ${error.message}`;
|
|
1378
|
-
} finally {
|
|
1379
|
-
if (generation === this.#generation) {
|
|
1380
|
-
this.#busy = false;
|
|
1381
|
-
this.copyButton.disabled = this.menuButton.disabled = false;
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
disconnectedCallback() {
|
|
1386
|
-
this.closeCopyMenu();
|
|
1387
|
-
this.#generation++;
|
|
1388
|
-
this.#busy = false;
|
|
1389
|
-
this.ownerDocument.defaultView.clearTimeout(this.#timer);
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
});
|
|
1393
|
-
var layout_default = defineCollection({ name: "layout", components: [Formlet, GroupBox, ContentPane, BorderContainer, StackContainer, TabContainer] });
|
|
1394
|
-
export {
|
|
1395
|
-
BorderContainer,
|
|
1396
|
-
ContentPane,
|
|
1397
|
-
Formlet,
|
|
1398
|
-
GroupBox,
|
|
1399
|
-
StackContainer,
|
|
1400
|
-
TabContainer,
|
|
1401
|
-
layout_default as default
|
|
1402
|
-
};
|