openproject-primer_view_components 0.96.0 → 0.97.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/app/assets/javascripts/primer_view_components.js +5 -5
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/assets/styles/primer_view_components.css +1 -1
- data/app/assets/styles/primer_view_components.css.map +1 -1
- data/app/components/primer/alpha/action_list/item.rb +2 -1
- data/app/components/primer/alpha/action_list.css +1 -1
- data/app/components/primer/alpha/action_list.css.json +9 -22
- data/app/components/primer/alpha/action_list.css.map +1 -1
- data/app/components/primer/alpha/action_list.html.erb +1 -5
- data/app/components/primer/alpha/action_list.pcss +43 -81
- data/app/components/primer/alpha/action_list.rb +9 -7
- data/app/components/primer/alpha/action_menu/action_menu_element.js +84 -234
- data/app/components/primer/alpha/action_menu/action_menu_element.ts +92 -273
- data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.js +1 -1
- data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.ts +1 -1
- data/app/components/primer/alpha/action_menu/menu_loader.d.ts +21 -0
- data/app/components/primer/alpha/action_menu/menu_loader.js +221 -0
- data/app/components/primer/alpha/action_menu/menu_loader.ts +269 -0
- data/lib/primer/view_components/version.rb +1 -1
- data/previews/primer/alpha/action_list_preview.rb +46 -1
- data/previews/primer/alpha/action_menu_preview/sub_menus.html.erb +1 -1
- data/previews/primer/alpha/action_menu_preview.rb +5 -2
- data/static/arguments.json +2 -2
- data/static/classes.json +3 -3
- data/static/classnames.cjs +1 -1
- data/static/classnames.js +1 -1
- data/static/info_arch.json +21 -2
- data/static/previews.json +13 -0
- metadata +4 -1
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _MenuLoader_instances, _MenuLoader_host, _MenuLoader_request, _MenuLoader_ownedLoaders, _MenuLoader_emptyLoaders, _MenuLoader_preload_get, _MenuLoader_invalidate, _MenuLoader_load, _MenuLoader_adopt, _MenuLoader_own, _MenuLoader_onReplace, _MenuLoader_onReplaced, _MenuLoader_keepInputs, _MenuLoader_dropKeptInputs;
|
|
13
|
+
// Loads a deferred menu's items. The one rule (`sync`): a load starts when
|
|
14
|
+
// there is no current request, when the host src differs from the current
|
|
15
|
+
// request's, or when the body holds no element (other code emptied it, or
|
|
16
|
+
// the last response was empty); the current loader still in the body is
|
|
17
|
+
// retried. A closed lazy menu waits for the open moment (`opening`) instead.
|
|
18
|
+
export class MenuLoader {
|
|
19
|
+
constructor(host) {
|
|
20
|
+
_MenuLoader_instances.add(this);
|
|
21
|
+
_MenuLoader_host.set(this, void 0);
|
|
22
|
+
// The current request: the loader it was made with and the src it was
|
|
23
|
+
// made for. Never updated; a new request replaces it. The src is recorded
|
|
24
|
+
// because the loader's attribute is configuration a morph may rewrite while
|
|
25
|
+
// the request is in flight; the record is what was requested, so a
|
|
26
|
+
// rewritten loader cannot pass an old response off as new.
|
|
27
|
+
_MenuLoader_request.set(this, null
|
|
28
|
+
// Every loader this module created or adopted, so completions of
|
|
29
|
+
// superseded ones can be told apart
|
|
30
|
+
);
|
|
31
|
+
// Every loader this module created or adopted, so completions of
|
|
32
|
+
// superseded ones can be told apart
|
|
33
|
+
_MenuLoader_ownedLoaders.set(this, new WeakSet()
|
|
34
|
+
// Loaders whose response had no menu items, with the body they left
|
|
35
|
+
// empty. That body staying empty is not a reason to load again before the
|
|
36
|
+
// next open; a body other code puts in its place is.
|
|
37
|
+
);
|
|
38
|
+
// Loaders whose response had no menu items, with the body they left
|
|
39
|
+
// empty. That body staying empty is not a reason to load again before the
|
|
40
|
+
// next open; a body other code puts in its place is.
|
|
41
|
+
_MenuLoader_emptyLoaders.set(this, new WeakMap());
|
|
42
|
+
__classPrivateFieldSet(this, _MenuLoader_host, host, "f");
|
|
43
|
+
}
|
|
44
|
+
// A primary menu with `src` renders its loader as a template
|
|
45
|
+
get deferred() {
|
|
46
|
+
return Boolean(__classPrivateFieldGet(this, _MenuLoader_host, "f").template());
|
|
47
|
+
}
|
|
48
|
+
// The current loader is still waiting in the body
|
|
49
|
+
get pending() {
|
|
50
|
+
const loader = __classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader;
|
|
51
|
+
return Boolean(loader) && loader.parentElement === (__classPrivateFieldGet(this, _MenuLoader_host, "f").body() ?? null);
|
|
52
|
+
}
|
|
53
|
+
// `data-ready` means no load is pending
|
|
54
|
+
updateReady() {
|
|
55
|
+
if (!this.deferred)
|
|
56
|
+
return;
|
|
57
|
+
if (this.pending) {
|
|
58
|
+
__classPrivateFieldGet(this, _MenuLoader_host, "f").element.removeAttribute('data-ready');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
__classPrivateFieldGet(this, _MenuLoader_host, "f").element.setAttribute('data-ready', 'true');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
sync(opening = false) {
|
|
65
|
+
const src = (__classPrivateFieldGet(this, _MenuLoader_host, "f").element.getAttribute('src') ?? '').trim();
|
|
66
|
+
if (!this.deferred || !src)
|
|
67
|
+
return;
|
|
68
|
+
if (!(opening || __classPrivateFieldGet(this, _MenuLoader_host, "f").isOpen() || __classPrivateFieldGet(this, _MenuLoader_instances, "a", _MenuLoader_preload_get))) {
|
|
69
|
+
// A pending or failed loader for another src must not render meanwhile;
|
|
70
|
+
// a completed one is kept, so setting its src again does not reload
|
|
71
|
+
if (__classPrivateFieldGet(this, _MenuLoader_request, "f") && src !== __classPrivateFieldGet(this, _MenuLoader_request, "f").src && this.pending)
|
|
72
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_invalidate).call(this);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const loader = __classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader;
|
|
76
|
+
if (!__classPrivateFieldGet(this, _MenuLoader_request, "f") || src !== __classPrivateFieldGet(this, _MenuLoader_request, "f").src || !__classPrivateFieldGet(this, _MenuLoader_host, "f").body()?.firstElementChild) {
|
|
77
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_load).call(this, src, opening);
|
|
78
|
+
}
|
|
79
|
+
else if (loader?.isConnected) {
|
|
80
|
+
// A retry fetches the loader's own src, which a morph may have rewritten
|
|
81
|
+
if ((loader.getAttribute('src') ?? '').trim() === __classPrivateFieldGet(this, _MenuLoader_request, "f").src) {
|
|
82
|
+
loader.classList.remove('is-error');
|
|
83
|
+
loader.refetch();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_load).call(this, src, opening);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Forgets the current request so the menu loads again at the current src:
|
|
91
|
+
// at once when open or preloaded, otherwise when it next opens.
|
|
92
|
+
refresh() {
|
|
93
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_invalidate).call(this);
|
|
94
|
+
this.sync();
|
|
95
|
+
}
|
|
96
|
+
// Picks up loaders other code inserts into the body (the last one wins, so
|
|
97
|
+
// a loader appended next to a pending one supersedes it), and loads again
|
|
98
|
+
// when other code empties the body, such as a morph of the server markup,
|
|
99
|
+
// which renders the body empty.
|
|
100
|
+
mutated(records) {
|
|
101
|
+
if (!this.deferred)
|
|
102
|
+
return;
|
|
103
|
+
const body = __classPrivateFieldGet(this, _MenuLoader_host, "f").body();
|
|
104
|
+
if (!body)
|
|
105
|
+
return;
|
|
106
|
+
if (records.some(record => record.addedNodes.length > 0)) {
|
|
107
|
+
const fragments = Array.from(body.querySelectorAll(':scope > include-fragment')).filter(fragment => !__classPrivateFieldGet(this, _MenuLoader_ownedLoaders, "f").has(fragment));
|
|
108
|
+
const fragment = fragments.at(-1);
|
|
109
|
+
if (fragment)
|
|
110
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_adopt).call(this, fragment);
|
|
111
|
+
}
|
|
112
|
+
// An empty body was emptied or replaced by other code, unless it is the
|
|
113
|
+
// one the current loader left empty; loading again there would loop on a
|
|
114
|
+
// preloaded menu, so that one waits for the next open
|
|
115
|
+
const loader = __classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader;
|
|
116
|
+
if (!body.firstElementChild && !(loader && __classPrivateFieldGet(this, _MenuLoader_emptyLoaders, "f").get(loader) === body))
|
|
117
|
+
this.sync();
|
|
118
|
+
this.updateReady();
|
|
119
|
+
}
|
|
120
|
+
// Form inputs are kept on the host for a pending or failed load
|
|
121
|
+
get keepingInputs() {
|
|
122
|
+
return Boolean(__classPrivateFieldGet(this, _MenuLoader_host, "f").element.querySelector(':scope > [data-list-inputs]'));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_MenuLoader_host = new WeakMap(), _MenuLoader_request = new WeakMap(), _MenuLoader_ownedLoaders = new WeakMap(), _MenuLoader_emptyLoaders = new WeakMap(), _MenuLoader_instances = new WeakSet(), _MenuLoader_preload_get = function _MenuLoader_preload_get() {
|
|
126
|
+
return __classPrivateFieldGet(this, _MenuLoader_host, "f").template()?.content.firstElementChild?.getAttribute('loading') === 'eager';
|
|
127
|
+
}, _MenuLoader_invalidate = function _MenuLoader_invalidate() {
|
|
128
|
+
__classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader.remove();
|
|
129
|
+
__classPrivateFieldSet(this, _MenuLoader_request, null, "f");
|
|
130
|
+
this.updateReady();
|
|
131
|
+
}, _MenuLoader_load = function _MenuLoader_load(src, opening) {
|
|
132
|
+
const body = __classPrivateFieldGet(this, _MenuLoader_host, "f").body();
|
|
133
|
+
const template = __classPrivateFieldGet(this, _MenuLoader_host, "f").template()?.content.firstElementChild;
|
|
134
|
+
if (!body || !template)
|
|
135
|
+
return;
|
|
136
|
+
// Imported, not cloned, so the loader is upgraded before it connects
|
|
137
|
+
const loader = __classPrivateFieldGet(this, _MenuLoader_host, "f").element.ownerDocument.importNode(template, true);
|
|
138
|
+
loader.setAttribute('src', src);
|
|
139
|
+
loader.setAttribute('loading', 'eager');
|
|
140
|
+
__classPrivateFieldSet(this, _MenuLoader_request, { loader, src }, "f");
|
|
141
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_own).call(this, loader);
|
|
142
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_keepInputs).call(this, body);
|
|
143
|
+
body.prepend(loader);
|
|
144
|
+
__classPrivateFieldGet(this, _MenuLoader_host, "f").onLoadStart(loader, opening || __classPrivateFieldGet(this, _MenuLoader_host, "f").isOpen());
|
|
145
|
+
// A focus handler may have started a newer load meanwhile
|
|
146
|
+
if (__classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader !== loader)
|
|
147
|
+
return;
|
|
148
|
+
for (const child of Array.from(body.childNodes)) {
|
|
149
|
+
if (child !== loader)
|
|
150
|
+
child.remove();
|
|
151
|
+
}
|
|
152
|
+
this.updateReady();
|
|
153
|
+
}, _MenuLoader_adopt = function _MenuLoader_adopt(fragment) {
|
|
154
|
+
const body = __classPrivateFieldGet(this, _MenuLoader_host, "f").body();
|
|
155
|
+
if (!body)
|
|
156
|
+
return;
|
|
157
|
+
const src = (fragment.getAttribute('src') ?? '').trim();
|
|
158
|
+
__classPrivateFieldSet(this, _MenuLoader_request, { loader: fragment, src }, "f");
|
|
159
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_own).call(this, fragment);
|
|
160
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_keepInputs).call(this, body);
|
|
161
|
+
const open = __classPrivateFieldGet(this, _MenuLoader_host, "f").isOpen();
|
|
162
|
+
__classPrivateFieldGet(this, _MenuLoader_host, "f").onLoadStart(fragment, open);
|
|
163
|
+
// A focus handler may have started a newer load meanwhile
|
|
164
|
+
if (__classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader !== fragment)
|
|
165
|
+
return;
|
|
166
|
+
for (const child of Array.from(body.childNodes)) {
|
|
167
|
+
if (child !== fragment)
|
|
168
|
+
child.remove();
|
|
169
|
+
}
|
|
170
|
+
const element = __classPrivateFieldGet(this, _MenuLoader_host, "f").element;
|
|
171
|
+
if (src && src !== element.getAttribute('src')) {
|
|
172
|
+
element.setAttribute('src', src);
|
|
173
|
+
}
|
|
174
|
+
else if (__classPrivateFieldGet(this, _MenuLoader_host, "f").isOpen() || __classPrivateFieldGet(this, _MenuLoader_instances, "a", _MenuLoader_preload_get)) {
|
|
175
|
+
// An unchanged src does not run the rule, and a lazy loader inserted
|
|
176
|
+
// before its attributes never starts on its own
|
|
177
|
+
this.sync();
|
|
178
|
+
}
|
|
179
|
+
}, _MenuLoader_own = function _MenuLoader_own(loader) {
|
|
180
|
+
__classPrivateFieldGet(this, _MenuLoader_ownedLoaders, "f").add(loader);
|
|
181
|
+
loader.addEventListener('include-fragment-replace', event => __classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_onReplace).call(this, loader, event));
|
|
182
|
+
loader.addEventListener('include-fragment-replaced', () => __classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_onReplaced).call(this, loader));
|
|
183
|
+
}, _MenuLoader_onReplace = function _MenuLoader_onReplace(loader, event) {
|
|
184
|
+
if (loader !== __classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader)
|
|
185
|
+
return;
|
|
186
|
+
// Other code removed the current loader before it completed, eg. by
|
|
187
|
+
// emptying the body, or rewrote its src, eg. by a morph: its response is
|
|
188
|
+
// not the one requested and must not render or mark the menu ready
|
|
189
|
+
const body = __classPrivateFieldGet(this, _MenuLoader_host, "f").body();
|
|
190
|
+
if (!body || loader.parentElement !== body || (loader.getAttribute('src') ?? '').trim() !== __classPrivateFieldGet(this, _MenuLoader_request, "f").src) {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
// A response without menu items is discarded, so the body stays empty
|
|
195
|
+
// and the menu loads again when it next opens
|
|
196
|
+
const fragment = event instanceof CustomEvent ? event.detail?.fragment : null;
|
|
197
|
+
if (!(fragment instanceof DocumentFragment))
|
|
198
|
+
return;
|
|
199
|
+
if (!fragment.querySelector(__classPrivateFieldGet(this, _MenuLoader_host, "f").itemSelector)) {
|
|
200
|
+
fragment.replaceChildren();
|
|
201
|
+
__classPrivateFieldGet(this, _MenuLoader_emptyLoaders, "f").set(loader, body);
|
|
202
|
+
}
|
|
203
|
+
}, _MenuLoader_onReplaced = function _MenuLoader_onReplaced(loader) {
|
|
204
|
+
// A superseded loader that completed late
|
|
205
|
+
if (loader !== __classPrivateFieldGet(this, _MenuLoader_request, "f")?.loader)
|
|
206
|
+
return;
|
|
207
|
+
// Before the menu syncs its inputs, so they come from the response; a
|
|
208
|
+
// load the menu's completion work starts keeps the response's inputs
|
|
209
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_dropKeptInputs).call(this);
|
|
210
|
+
__classPrivateFieldGet(this, _MenuLoader_host, "f").onLoaded();
|
|
211
|
+
this.updateReady();
|
|
212
|
+
}, _MenuLoader_keepInputs = function _MenuLoader_keepInputs(body) {
|
|
213
|
+
const inputs = body.querySelector('[data-list-inputs]');
|
|
214
|
+
if (!inputs)
|
|
215
|
+
return;
|
|
216
|
+
__classPrivateFieldGet(this, _MenuLoader_instances, "m", _MenuLoader_dropKeptInputs).call(this);
|
|
217
|
+
__classPrivateFieldGet(this, _MenuLoader_host, "f").element.append(inputs);
|
|
218
|
+
}, _MenuLoader_dropKeptInputs = function _MenuLoader_dropKeptInputs() {
|
|
219
|
+
for (const inputs of __classPrivateFieldGet(this, _MenuLoader_host, "f").element.querySelectorAll(':scope > [data-list-inputs]'))
|
|
220
|
+
inputs.remove();
|
|
221
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import type {IncludeFragmentElement} from '@github/include-fragment-element'
|
|
2
|
+
|
|
3
|
+
// What MenuLoader needs from the menu it loads into. The loader owns
|
|
4
|
+
// requests, adoption, readiness and kept form inputs; the menu owns focus,
|
|
5
|
+
// popover state, the dynamic label and input sync.
|
|
6
|
+
export type MenuLoaderHost = {
|
|
7
|
+
// The <action-menu>: its `src` is the state, and it receives `data-ready`
|
|
8
|
+
// and the form inputs kept while a load is pending
|
|
9
|
+
element: HTMLElement
|
|
10
|
+
// The primary overlay's body, looked up on every call, since other code
|
|
11
|
+
// may replace the body or the overlay
|
|
12
|
+
body(): HTMLElement | undefined
|
|
13
|
+
template(): HTMLTemplateElement | undefined
|
|
14
|
+
// Matches the menu's items; a response without a match is empty
|
|
15
|
+
itemSelector: string
|
|
16
|
+
isOpen(): boolean
|
|
17
|
+
// A loader is in the body and about to replace its old content; keepOpen
|
|
18
|
+
// when the menu is open or opening
|
|
19
|
+
onLoadStart(fragment: IncludeFragmentElement, keepOpen: boolean): void
|
|
20
|
+
// The current loader's response is in the body
|
|
21
|
+
onLoaded(): void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type LoaderRequest = Readonly<{loader: IncludeFragmentElement; src: string}>
|
|
25
|
+
|
|
26
|
+
// Loads a deferred menu's items. The one rule (`sync`): a load starts when
|
|
27
|
+
// there is no current request, when the host src differs from the current
|
|
28
|
+
// request's, or when the body holds no element (other code emptied it, or
|
|
29
|
+
// the last response was empty); the current loader still in the body is
|
|
30
|
+
// retried. A closed lazy menu waits for the open moment (`opening`) instead.
|
|
31
|
+
export class MenuLoader {
|
|
32
|
+
#host: MenuLoaderHost
|
|
33
|
+
|
|
34
|
+
// The current request: the loader it was made with and the src it was
|
|
35
|
+
// made for. Never updated; a new request replaces it. The src is recorded
|
|
36
|
+
// because the loader's attribute is configuration a morph may rewrite while
|
|
37
|
+
// the request is in flight; the record is what was requested, so a
|
|
38
|
+
// rewritten loader cannot pass an old response off as new.
|
|
39
|
+
#request: LoaderRequest | null = null
|
|
40
|
+
// Every loader this module created or adopted, so completions of
|
|
41
|
+
// superseded ones can be told apart
|
|
42
|
+
#ownedLoaders = new WeakSet<IncludeFragmentElement>()
|
|
43
|
+
// Loaders whose response had no menu items, with the body they left
|
|
44
|
+
// empty. That body staying empty is not a reason to load again before the
|
|
45
|
+
// next open; a body other code puts in its place is.
|
|
46
|
+
#emptyLoaders = new WeakMap<IncludeFragmentElement, HTMLElement>()
|
|
47
|
+
|
|
48
|
+
constructor(host: MenuLoaderHost) {
|
|
49
|
+
this.#host = host
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A primary menu with `src` renders its loader as a template
|
|
53
|
+
get deferred(): boolean {
|
|
54
|
+
return Boolean(this.#host.template())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get #preload(): boolean {
|
|
58
|
+
return this.#host.template()?.content.firstElementChild?.getAttribute('loading') === 'eager'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The current loader is still waiting in the body
|
|
62
|
+
get pending(): boolean {
|
|
63
|
+
const loader = this.#request?.loader
|
|
64
|
+
return Boolean(loader) && loader!.parentElement === (this.#host.body() ?? null)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// `data-ready` means no load is pending
|
|
68
|
+
updateReady() {
|
|
69
|
+
if (!this.deferred) return
|
|
70
|
+
|
|
71
|
+
if (this.pending) {
|
|
72
|
+
this.#host.element.removeAttribute('data-ready')
|
|
73
|
+
} else {
|
|
74
|
+
this.#host.element.setAttribute('data-ready', 'true')
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
sync(opening = false) {
|
|
79
|
+
const src = (this.#host.element.getAttribute('src') ?? '').trim()
|
|
80
|
+
if (!this.deferred || !src) return
|
|
81
|
+
|
|
82
|
+
if (!(opening || this.#host.isOpen() || this.#preload)) {
|
|
83
|
+
// A pending or failed loader for another src must not render meanwhile;
|
|
84
|
+
// a completed one is kept, so setting its src again does not reload
|
|
85
|
+
if (this.#request && src !== this.#request.src && this.pending) this.#invalidate()
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const loader = this.#request?.loader
|
|
90
|
+
if (!this.#request || src !== this.#request.src || !this.#host.body()?.firstElementChild) {
|
|
91
|
+
this.#load(src, opening)
|
|
92
|
+
} else if (loader?.isConnected) {
|
|
93
|
+
// A retry fetches the loader's own src, which a morph may have rewritten
|
|
94
|
+
if ((loader.getAttribute('src') ?? '').trim() === this.#request.src) {
|
|
95
|
+
loader.classList.remove('is-error')
|
|
96
|
+
loader.refetch()
|
|
97
|
+
} else {
|
|
98
|
+
this.#load(src, opening)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Forgets the current request so the menu loads again at the current src:
|
|
104
|
+
// at once when open or preloaded, otherwise when it next opens.
|
|
105
|
+
refresh() {
|
|
106
|
+
this.#invalidate()
|
|
107
|
+
this.sync()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Picks up loaders other code inserts into the body (the last one wins, so
|
|
111
|
+
// a loader appended next to a pending one supersedes it), and loads again
|
|
112
|
+
// when other code empties the body, such as a morph of the server markup,
|
|
113
|
+
// which renders the body empty.
|
|
114
|
+
mutated(records: MutationRecord[]) {
|
|
115
|
+
if (!this.deferred) return
|
|
116
|
+
|
|
117
|
+
const body = this.#host.body()
|
|
118
|
+
if (!body) return
|
|
119
|
+
|
|
120
|
+
if (records.some(record => record.addedNodes.length > 0)) {
|
|
121
|
+
const fragments = Array.from(body.querySelectorAll<IncludeFragmentElement>(':scope > include-fragment')).filter(
|
|
122
|
+
fragment => !this.#ownedLoaders.has(fragment),
|
|
123
|
+
)
|
|
124
|
+
const fragment = fragments.at(-1)
|
|
125
|
+
if (fragment) this.#adopt(fragment)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// An empty body was emptied or replaced by other code, unless it is the
|
|
129
|
+
// one the current loader left empty; loading again there would loop on a
|
|
130
|
+
// preloaded menu, so that one waits for the next open
|
|
131
|
+
const loader = this.#request?.loader
|
|
132
|
+
if (!body.firstElementChild && !(loader && this.#emptyLoaders.get(loader) === body)) this.sync()
|
|
133
|
+
|
|
134
|
+
this.updateReady()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Drops the current request. Its loader is removed even while the menu is
|
|
138
|
+
// detached, since upstream still completes the fetch there.
|
|
139
|
+
#invalidate() {
|
|
140
|
+
this.#request?.loader.remove()
|
|
141
|
+
this.#request = null
|
|
142
|
+
this.updateReady()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Starts a request for src with a fresh loader from the template, which
|
|
146
|
+
// replaces whatever the body holds.
|
|
147
|
+
#load(src: string, opening: boolean) {
|
|
148
|
+
const body = this.#host.body()
|
|
149
|
+
const template = this.#host.template()?.content.firstElementChild
|
|
150
|
+
if (!body || !template) return
|
|
151
|
+
|
|
152
|
+
// Imported, not cloned, so the loader is upgraded before it connects
|
|
153
|
+
const loader = this.#host.element.ownerDocument.importNode(template, true) as IncludeFragmentElement
|
|
154
|
+
loader.setAttribute('src', src)
|
|
155
|
+
loader.setAttribute('loading', 'eager')
|
|
156
|
+
|
|
157
|
+
this.#request = {loader, src}
|
|
158
|
+
this.#own(loader)
|
|
159
|
+
this.#keepInputs(body)
|
|
160
|
+
|
|
161
|
+
body.prepend(loader)
|
|
162
|
+
this.#host.onLoadStart(loader, opening || this.#host.isOpen())
|
|
163
|
+
// A focus handler may have started a newer load meanwhile
|
|
164
|
+
if (this.#request?.loader !== loader) return
|
|
165
|
+
|
|
166
|
+
for (const child of Array.from(body.childNodes)) {
|
|
167
|
+
if (child !== loader) child.remove()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
this.updateReady()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Makes an inserted loader the current request. Its src is reflected onto
|
|
174
|
+
// the host, so the rule sees the request as current: an open or preloaded
|
|
175
|
+
// menu loads it at once (upstream's busy guard drops the duplicate for an
|
|
176
|
+
// eager loader), a closed lazy one when it opens, unless the loader is eager
|
|
177
|
+
// and has already started itself. Idiomorph inserts a loader before setting
|
|
178
|
+
// its attributes, but sets them synchronously, so the loader arrives here
|
|
179
|
+
// with its src; one that gets its src only in a later task is replaced with
|
|
180
|
+
// a load at the host src. The template is not touched.
|
|
181
|
+
#adopt(fragment: IncludeFragmentElement) {
|
|
182
|
+
const body = this.#host.body()
|
|
183
|
+
if (!body) return
|
|
184
|
+
|
|
185
|
+
const src = (fragment.getAttribute('src') ?? '').trim()
|
|
186
|
+
|
|
187
|
+
this.#request = {loader: fragment, src}
|
|
188
|
+
this.#own(fragment)
|
|
189
|
+
this.#keepInputs(body)
|
|
190
|
+
|
|
191
|
+
const open = this.#host.isOpen()
|
|
192
|
+
this.#host.onLoadStart(fragment, open)
|
|
193
|
+
// A focus handler may have started a newer load meanwhile
|
|
194
|
+
if (this.#request?.loader !== fragment) return
|
|
195
|
+
|
|
196
|
+
for (const child of Array.from(body.childNodes)) {
|
|
197
|
+
if (child !== fragment) child.remove()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const element = this.#host.element
|
|
201
|
+
if (src && src !== element.getAttribute('src')) {
|
|
202
|
+
element.setAttribute('src', src)
|
|
203
|
+
} else if (this.#host.isOpen() || this.#preload) {
|
|
204
|
+
// An unchanged src does not run the rule, and a lazy loader inserted
|
|
205
|
+
// before its attributes never starts on its own
|
|
206
|
+
this.sync()
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Loaders are never reused, so the listeners need no lifetime of their own
|
|
211
|
+
#own(loader: IncludeFragmentElement) {
|
|
212
|
+
this.#ownedLoaders.add(loader)
|
|
213
|
+
loader.addEventListener('include-fragment-replace', event => this.#onReplace(loader, event))
|
|
214
|
+
loader.addEventListener('include-fragment-replaced', () => this.#onReplaced(loader))
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
#onReplace(loader: IncludeFragmentElement, event: Event) {
|
|
218
|
+
if (loader !== this.#request?.loader) return
|
|
219
|
+
|
|
220
|
+
// Other code removed the current loader before it completed, eg. by
|
|
221
|
+
// emptying the body, or rewrote its src, eg. by a morph: its response is
|
|
222
|
+
// not the one requested and must not render or mark the menu ready
|
|
223
|
+
const body = this.#host.body()
|
|
224
|
+
if (!body || loader.parentElement !== body || (loader.getAttribute('src') ?? '').trim() !== this.#request.src) {
|
|
225
|
+
event.preventDefault()
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// A response without menu items is discarded, so the body stays empty
|
|
230
|
+
// and the menu loads again when it next opens
|
|
231
|
+
const fragment: unknown = event instanceof CustomEvent ? event.detail?.fragment : null
|
|
232
|
+
if (!(fragment instanceof DocumentFragment)) return
|
|
233
|
+
|
|
234
|
+
if (!fragment.querySelector(this.#host.itemSelector)) {
|
|
235
|
+
fragment.replaceChildren()
|
|
236
|
+
this.#emptyLoaders.set(loader, body)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#onReplaced(loader: IncludeFragmentElement) {
|
|
241
|
+
// A superseded loader that completed late
|
|
242
|
+
if (loader !== this.#request?.loader) return
|
|
243
|
+
|
|
244
|
+
// Before the menu syncs its inputs, so they come from the response; a
|
|
245
|
+
// load the menu's completion work starts keeps the response's inputs
|
|
246
|
+
this.#dropKeptInputs()
|
|
247
|
+
this.#host.onLoaded()
|
|
248
|
+
this.updateReady()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Keeps the current form inputs submitting while a load replaces the body,
|
|
252
|
+
// also when it fails: they move to the host until a response brings its own
|
|
253
|
+
#keepInputs(body: HTMLElement) {
|
|
254
|
+
const inputs = body.querySelector('[data-list-inputs]')
|
|
255
|
+
if (!inputs) return
|
|
256
|
+
|
|
257
|
+
this.#dropKeptInputs()
|
|
258
|
+
this.#host.element.append(inputs)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Form inputs are kept on the host for a pending or failed load
|
|
262
|
+
get keepingInputs(): boolean {
|
|
263
|
+
return Boolean(this.#host.element.querySelector(':scope > [data-list-inputs]'))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
#dropKeptInputs() {
|
|
267
|
+
for (const inputs of this.#host.element.querySelectorAll(':scope > [data-list-inputs]')) inputs.remove()
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -125,6 +125,51 @@ module Primer
|
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
+
# Lines start at the label and run through trailing visuals. The first item and
|
|
129
|
+
# the item after a manual divider get none. Hidden items are not supported with
|
|
130
|
+
# dividers. The hidden items here pin what the lines do around them: additional dividers.
|
|
131
|
+
#
|
|
132
|
+
# @label With dividers
|
|
133
|
+
# @hidden
|
|
134
|
+
# @snapshot
|
|
135
|
+
def with_dividers
|
|
136
|
+
render(Primer::Alpha::ActionList.new(aria: { label: "List with dividers" }, show_dividers: true)) do |component|
|
|
137
|
+
component.with_item(label: "Hidden item", hidden: true)
|
|
138
|
+
component.with_item(label: "First visible item")
|
|
139
|
+
component.with_item(label: "Leading visual") do |item|
|
|
140
|
+
item.with_leading_visual_icon(icon: :gear)
|
|
141
|
+
end
|
|
142
|
+
component.with_item(label: "Trailing visual") do |item|
|
|
143
|
+
item.with_trailing_visual_label(scheme: :accent) { "New" }
|
|
144
|
+
end
|
|
145
|
+
component.with_item(label: "Inline description", description_scheme: :inline) do |item|
|
|
146
|
+
item.with_leading_visual_icon(icon: :star)
|
|
147
|
+
item.with_description { "Description" }
|
|
148
|
+
item.with_trailing_visual_icon(icon: :check)
|
|
149
|
+
end
|
|
150
|
+
component.with_item(label: "Block description", description_scheme: :block) do |item|
|
|
151
|
+
item.with_leading_visual_icon(icon: :star)
|
|
152
|
+
item.with_description { "Description" }
|
|
153
|
+
item.with_trailing_visual_icon(icon: :check)
|
|
154
|
+
end
|
|
155
|
+
component.with_item(label: "Disabled item", disabled: true) do |item|
|
|
156
|
+
item.with_leading_visual_icon(icon: :lock)
|
|
157
|
+
end
|
|
158
|
+
component.with_item(label: "Hidden item", hidden: true)
|
|
159
|
+
component.with_item(label: "After a hidden item")
|
|
160
|
+
component.with_item(label: "Form item", href: "/", form_arguments: { method: :post, name: "foo" })
|
|
161
|
+
component.with_divider
|
|
162
|
+
component.with_item(label: "After a divider")
|
|
163
|
+
component.with_divider
|
|
164
|
+
component.with_item(label: "Hidden item – breaks the line rules", hidden: true)
|
|
165
|
+
component.with_item(label: "After a divider and a hidden item")
|
|
166
|
+
component.with_item(label: "Hidden item", hidden: true)
|
|
167
|
+
component.with_divider
|
|
168
|
+
component.with_item(label: "After a collapsed divider")
|
|
169
|
+
component.with_item(label: "Last item")
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
128
173
|
# @label Divider
|
|
129
174
|
#
|
|
130
175
|
# @param scheme [Symbol] select [subtle, filled]
|
|
@@ -534,7 +579,7 @@ module Primer
|
|
|
534
579
|
)) do |component|
|
|
535
580
|
component.with_heading(title: "Action List")
|
|
536
581
|
component.with_item(label: "Item one", href: "/", active: true)
|
|
537
|
-
component.with_item(label: "Item two", href: "/")
|
|
582
|
+
component.with_item(label: "Item two", href: "/")
|
|
538
583
|
component.with_item(label: "Item three", href: "/")
|
|
539
584
|
end
|
|
540
585
|
end
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<% menu.with_show_button { "Edit" } %>
|
|
5
5
|
<% menu.with_item(label: "Cut") %>
|
|
6
6
|
<% menu.with_item(label: "Copy") %>
|
|
7
|
-
<% menu.with_sub_menu_item(label: "Paste special", anchor_align: sub_menu_anchor_align, anchor_side: sub_menu_anchor_side, anchor_when_narrow: anchor_when_narrow) do |sub_menu| %>
|
|
7
|
+
<% menu.with_sub_menu_item(label: "Paste special", disabled: disable_sub_menu, anchor_align: sub_menu_anchor_align, anchor_side: sub_menu_anchor_side, anchor_when_narrow: anchor_when_narrow) do |sub_menu| %>
|
|
8
8
|
<% sub_menu.with_leading_visual_icon(icon: :"sparkle-fill") %>
|
|
9
9
|
<% sub_menu.with_item(label: "Paste plain text") %>
|
|
10
10
|
<% sub_menu.with_item(label: "Paste formulas") %>
|
|
@@ -510,19 +510,22 @@ module Primer
|
|
|
510
510
|
# @param anchor_when_narrow [Symbol] select [inherit, bottom, fullscreen, left, right]
|
|
511
511
|
# @param sub_menu_anchor_align [Symbol] select [start, center, end]
|
|
512
512
|
# @param sub_menu_anchor_side [Symbol] select [outside_bottom, outside_top, outside_left, outside_right]
|
|
513
|
+
# @param disable_sub_menu toggle
|
|
513
514
|
def sub_menus(
|
|
514
515
|
anchor_align: Primer::Alpha::ActionMenu::PrimaryMenu::DEFAULT_ANCHOR_ALIGN,
|
|
515
516
|
anchor_side: Primer::Alpha::ActionMenu::PrimaryMenu::DEFAULT_ANCHOR_SIDE,
|
|
516
517
|
anchor_when_narrow: Primer::Alpha::ActionMenu::SubMenu::DEFAULT_ANCHOR_WHEN_NARROW,
|
|
517
518
|
sub_menu_anchor_align: Primer::Alpha::ActionMenu::SubMenu::DEFAULT_ANCHOR_ALIGN,
|
|
518
|
-
sub_menu_anchor_side: Primer::Alpha::ActionMenu::SubMenu::DEFAULT_ANCHOR_SIDE
|
|
519
|
+
sub_menu_anchor_side: Primer::Alpha::ActionMenu::SubMenu::DEFAULT_ANCHOR_SIDE,
|
|
520
|
+
disable_sub_menu: false
|
|
519
521
|
)
|
|
520
522
|
render_with_template(locals: {
|
|
521
523
|
anchor_align: anchor_align.to_sym,
|
|
522
524
|
anchor_side: anchor_side.to_sym,
|
|
523
525
|
anchor_when_narrow: anchor_when_narrow.to_sym,
|
|
524
526
|
sub_menu_anchor_align: sub_menu_anchor_align,
|
|
525
|
-
sub_menu_anchor_side: sub_menu_anchor_side
|
|
527
|
+
sub_menu_anchor_side: sub_menu_anchor_side,
|
|
528
|
+
disable_sub_menu: disable_sub_menu
|
|
526
529
|
})
|
|
527
530
|
end
|
|
528
531
|
end
|
data/static/arguments.json
CHANGED
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"name": "show_dividers",
|
|
95
95
|
"type": "Boolean",
|
|
96
96
|
"default": "`false`",
|
|
97
|
-
"description": "Display a
|
|
97
|
+
"description": "Display a dividing line above each item in the list when it does not follow a header or divider. These are more subtle than manually inserted dividers. Only supported by `ActionList` itself so far. Menus have too many special cases. Hidden items are not supported, whether they are rendered with `hidden: true` or hidden later, eg. by filtering: the lines are placed with CSS sibling selectors. To leave items out, don't render them, or remove them from the DOM rather than setting `hidden`."
|
|
98
98
|
},
|
|
99
99
|
{
|
|
100
100
|
"name": "select_variant",
|
|
@@ -369,7 +369,7 @@
|
|
|
369
369
|
"name": "show_dividers",
|
|
370
370
|
"type": "Boolean",
|
|
371
371
|
"default": "`false`",
|
|
372
|
-
"description": "Display a
|
|
372
|
+
"description": "Display a dividing line above each item in the list when it does not follow a header or divider. These are more subtle than manually inserted dividers. Only supported by `ActionList` itself so far. Menus have too many special cases. Hidden items are not supported, whether they are rendered with `hidden: true` or hidden later, eg. by filtering: the lines are placed with CSS sibling selectors. To leave items out, don't render them, or remove them from the DOM rather than setting `hidden`."
|
|
373
373
|
},
|
|
374
374
|
{
|
|
375
375
|
"name": "select_variant",
|
data/static/classes.json
CHANGED
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"ActionListItem": [
|
|
36
36
|
"Primer::Alpha::ActionList"
|
|
37
37
|
],
|
|
38
|
+
"ActionListItem--divided": [
|
|
39
|
+
"Primer::Alpha::ActionList"
|
|
40
|
+
],
|
|
38
41
|
"ActionListItem--subItem": [
|
|
39
42
|
"Primer::Alpha::ActionList"
|
|
40
43
|
],
|
|
@@ -83,9 +86,6 @@
|
|
|
83
86
|
"ActionListWrap": [
|
|
84
87
|
"Primer::Alpha::ActionList"
|
|
85
88
|
],
|
|
86
|
-
"ActionListWrap--divided": [
|
|
87
|
-
"Primer::Alpha::ActionList"
|
|
88
|
-
],
|
|
89
89
|
"ActionListWrap--inset": [
|
|
90
90
|
"Primer::Alpha::ActionList"
|
|
91
91
|
],
|
data/static/classnames.cjs
CHANGED
|
@@ -23,6 +23,7 @@ module.exports = new Set([
|
|
|
23
23
|
'ActionListItem',
|
|
24
24
|
'ActionListItem--danger',
|
|
25
25
|
'ActionListItem--disabled',
|
|
26
|
+
'ActionListItem--divided',
|
|
26
27
|
'ActionListItem--hasSubItem',
|
|
27
28
|
'ActionListItem--navActive',
|
|
28
29
|
'ActionListItem--subItem',
|
|
@@ -43,7 +44,6 @@ module.exports = new Set([
|
|
|
43
44
|
'ActionListItem-visual--leading',
|
|
44
45
|
'ActionListItem-visual--trailing',
|
|
45
46
|
'ActionListWrap',
|
|
46
|
-
'ActionListWrap--divided',
|
|
47
47
|
'ActionListWrap--inset',
|
|
48
48
|
'AvatarStack',
|
|
49
49
|
'AvatarStack--right',
|