@ohmygame/plugin-ui 2.4.0 → 2.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/index.d.ts +3 -0
- package/package.json +1 -1
- package/plugin-ui.css +5 -0
- package/ui/1/base.js +17 -0
- package/ui/1/controls.js +85 -2
- package/ui/1/custom-elements.json +2190 -746
- package/ui/1/data.js +238 -0
- package/ui/1/feedback.js +5 -4
- package/ui/1/floating.js +111 -0
- package/ui/1/forms.js +440 -39
- package/ui/1/index.d.ts +313 -1
- package/ui/1/index.js +2 -0
- package/ui/1/layout.js +36 -6
- package/ui/1/media.js +77 -0
- package/ui/1/overlays.js +465 -0
package/README.md
CHANGED
|
@@ -22,6 +22,13 @@ const project = await host.request("project.info");
|
|
|
22
22
|
Pages allow no inline scripts and no other sites' scripts, so a page's own
|
|
23
23
|
script is a file beside it.
|
|
24
24
|
|
|
25
|
+
The shared stylesheet reserves space for traditional page scrollbars with
|
|
26
|
+
`scrollbar-gutter: stable`; tabs and disclosures can change height without
|
|
27
|
+
shifting the page horizontally. Dialog content does the same within its own
|
|
28
|
+
scroll area. Overlay scrollbars keep the platform's normal behavior. A plugin
|
|
29
|
+
with its own scroll container should apply this property to that container;
|
|
30
|
+
avoid `100vw` for content width or JavaScript scrollbar-width compensation.
|
|
31
|
+
|
|
25
32
|
Install the package for its types and for editor support:
|
|
26
33
|
|
|
27
34
|
- `@ohmygame/plugin-ui` types the bridge, for example
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type PluginUiMethod =
|
|
|
8
8
|
| "command.run"
|
|
9
9
|
| "ui.toast"
|
|
10
10
|
| "ui.confirm"
|
|
11
|
+
| "browser.open"
|
|
11
12
|
| "files.list"
|
|
12
13
|
| "files.read"
|
|
13
14
|
| "files.write"
|
|
@@ -146,6 +147,8 @@ export interface PluginUiHost {
|
|
|
146
147
|
files: PluginFiles;
|
|
147
148
|
request(method: "ui.toast", params: PluginUiToast): Promise<null>;
|
|
148
149
|
request(method: "ui.confirm", params: PluginUiConfirm): Promise<boolean>;
|
|
150
|
+
/** Opens an HTTP(S) address in a new Browser tab and reveals the panel. Desktop project pages only; visible pages may ask at most 5 times in 10 seconds. No page access is granted. */
|
|
151
|
+
request(method: "browser.open", params: { url: string }): Promise<null>;
|
|
149
152
|
request(method: "composer.fill", params: PluginUiComposerFill): Promise<null>;
|
|
150
153
|
/** The project's latest turns that changed files, newest first; `limit` is 1 to 100, 20 when left out. */
|
|
151
154
|
request(method: "history.list", params?: { limit?: number }): Promise<{ turns: PluginHistoryTurn[] }>;
|
package/package.json
CHANGED
package/plugin-ui.css
CHANGED
|
@@ -108,8 +108,13 @@
|
|
|
108
108
|
--shadow-float: 0 8px 28px rgb(0 0 0 / 9%), 0 0 0 1px rgb(0 0 0 / 7%);
|
|
109
109
|
color-scheme: light;
|
|
110
110
|
}
|
|
111
|
+
/* Keep page width stable when tabs or disclosures change its scroll height. */
|
|
112
|
+
html { scrollbar-gutter: stable; }
|
|
111
113
|
* { box-sizing: border-box; }
|
|
112
114
|
body { margin: 0; padding: var(--space-4); }
|
|
115
|
+
@media (min-width: 720px) {
|
|
116
|
+
body { padding: var(--space-6); }
|
|
117
|
+
}
|
|
113
118
|
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
|
|
114
119
|
|
|
115
120
|
.omg-row { display: flex; align-items: center; gap: var(--space-2); min-height: 32px; }
|
package/ui/1/base.js
CHANGED
|
@@ -105,3 +105,20 @@ export function filled(slot) {
|
|
|
105
105
|
export function define(name, component) {
|
|
106
106
|
if (!customElements.get(name)) customElements.define(name, component);
|
|
107
107
|
}
|
|
108
|
+
|
|
109
|
+
// Follow focus across the components' open shadow roots.
|
|
110
|
+
export function activeElement(root = document) {
|
|
111
|
+
let active = root.activeElement;
|
|
112
|
+
while (active?.shadowRoot?.activeElement)
|
|
113
|
+
active = active.shadowRoot.activeElement;
|
|
114
|
+
return active;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function containsFocus(host) {
|
|
118
|
+
let node = activeElement(host.ownerDocument);
|
|
119
|
+
while (node) {
|
|
120
|
+
if (node === host) return true;
|
|
121
|
+
node = node.parentNode || node.host;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
package/ui/1/controls.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Controls: buttons,
|
|
2
|
-
// select.
|
|
1
|
+
// Controls: buttons, command buttons, and collapsible content.
|
|
3
2
|
import { connect } from "../../plugin-ui.js";
|
|
4
3
|
import { OmgElement, css, define, text } from "./base.js";
|
|
5
4
|
|
|
@@ -96,6 +95,89 @@ class OmgButton extends OmgElement {
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
|
|
98
|
+
/**
|
|
99
|
+
* `<omg-disclosure heading open disabled>`: a plain title row with a leading
|
|
100
|
+
* arrow that shows or hides content. Closing keeps the content mounted and
|
|
101
|
+
* returns focus to the button when focus was inside. Enter and Space use the
|
|
102
|
+
* button's native activation.
|
|
103
|
+
*
|
|
104
|
+
* @attr {string} heading - The button's label.
|
|
105
|
+
* @attr {boolean} open - Shows the content; closed by default.
|
|
106
|
+
* @attr {boolean} disabled - Disables the button, without changing the content's state.
|
|
107
|
+
* @prop {boolean} open - The `open` attribute; setting it does not emit an event.
|
|
108
|
+
* @prop {boolean} disabled - The `disabled` attribute.
|
|
109
|
+
* @fires {{ open: boolean }} omg-toggle - The person opened or closed the content; bubbles across shadow roots.
|
|
110
|
+
* @slot - The content, retained while closed.
|
|
111
|
+
* @part button - The toggle button.
|
|
112
|
+
* @part heading - The button's label.
|
|
113
|
+
* @part icon - The expansion arrow.
|
|
114
|
+
* @part body - The content, hidden while closed.
|
|
115
|
+
*/
|
|
116
|
+
class OmgDisclosure extends OmgElement {
|
|
117
|
+
static observedAttributes = ["heading", "open", "disabled"];
|
|
118
|
+
static delegatesFocus = true;
|
|
119
|
+
static styles = [
|
|
120
|
+
css(`
|
|
121
|
+
:host { display: block; min-width: 0; }
|
|
122
|
+
button {
|
|
123
|
+
display: grid; grid-template-columns: var(--space-2) minmax(0, 1fr); align-items: center; gap: var(--space-2); width: 100%; min-height: 30px;
|
|
124
|
+
padding: var(--space-1) 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--color-text);
|
|
125
|
+
font: inherit; font-weight: var(--weight-medium); text-align: start; cursor: pointer;
|
|
126
|
+
transition: background var(--duration-fast);
|
|
127
|
+
}
|
|
128
|
+
button:not(:disabled):hover { background: color-mix(in srgb, var(--color-hover) 60%, transparent); }
|
|
129
|
+
button:disabled { opacity: 0.4; cursor: default; }
|
|
130
|
+
.heading { min-width: 0; overflow-wrap: anywhere; }
|
|
131
|
+
/* Centre the SVG's visible strokes in an 8px track, matching the status dot. */
|
|
132
|
+
.icon { width: 14px; height: 14px; justify-self: center; color: var(--color-text-secondary); transform: rotate(-90deg); transition: transform var(--duration-fast); }
|
|
133
|
+
:host([open]) .icon { transform: rotate(0deg); }
|
|
134
|
+
.body { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; padding-top: var(--space-2); padding-inline-start: var(--space-4); }
|
|
135
|
+
`),
|
|
136
|
+
];
|
|
137
|
+
static template = `
|
|
138
|
+
<button part="button" type="button" aria-expanded="false" aria-controls="body">
|
|
139
|
+
<svg class="icon" part="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="m4 6 4 4 4-4" /></svg>
|
|
140
|
+
<span class="heading" part="heading"></span>
|
|
141
|
+
</button>
|
|
142
|
+
<div id="body" class="body" part="body" hidden><slot></slot></div>`;
|
|
143
|
+
|
|
144
|
+
constructor() {
|
|
145
|
+
super();
|
|
146
|
+
this.part("button").addEventListener("click", () => {
|
|
147
|
+
if (this.disabled) return;
|
|
148
|
+
this.open = !this.open;
|
|
149
|
+
this.dispatchEvent(new CustomEvent("omg-toggle", { bubbles: true, composed: true, detail: { open: this.open } }));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
get open() {
|
|
154
|
+
return this.hasAttribute("open");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
set open(value) {
|
|
158
|
+
this.toggleAttribute("open", Boolean(value));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get disabled() {
|
|
162
|
+
return this.hasAttribute("disabled");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
set disabled(value) {
|
|
166
|
+
this.toggleAttribute("disabled", Boolean(value));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
update() {
|
|
170
|
+
const button = this.part("button");
|
|
171
|
+
const body = this.part("body");
|
|
172
|
+
const active = this.getRootNode().activeElement;
|
|
173
|
+
if (!this.open && !body.hidden && active !== this && this.contains(active)) button.focus();
|
|
174
|
+
text(this.part("heading"), this.getAttribute("heading"));
|
|
175
|
+
button.disabled = this.disabled;
|
|
176
|
+
button.setAttribute("aria-expanded", String(this.open));
|
|
177
|
+
body.hidden = !this.open;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
99
181
|
/** Commands running now from command buttons that wait for one another. */
|
|
100
182
|
const running = new Set();
|
|
101
183
|
const changes = new EventTarget();
|
|
@@ -228,4 +310,5 @@ class OmgCommandButton extends OmgButton {
|
|
|
228
310
|
}
|
|
229
311
|
|
|
230
312
|
define("omg-button", OmgButton);
|
|
313
|
+
define("omg-disclosure", OmgDisclosure);
|
|
231
314
|
define("omg-command-button", OmgCommandButton);
|