@floless/app 0.172.0 → 0.172.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/floless-server.cjs +16893 -12178
- package/dist/schemas/drawing-check.profile.v1.schema.json +7 -1
- package/dist/skills/floless-app-steel-model/SKILL.md +2 -2
- package/dist/skills/floless-app-steel-model/references/elements.md +45 -5
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +6 -2
- package/dist/web/app.css +62 -0
- package/dist/web/aware.js +34 -3
- package/dist/web/chat.js +19 -1
- package/dist/web/commands-drawing-check.js +2 -0
- package/dist/web/commands-shell.js +34 -0
- package/dist/web/commands-steel.js +50 -0
- package/dist/web/drawing-check-editor.html +9 -0
- package/dist/web/drawing-check-editor.js +127 -14
- package/dist/web/element-plan.js +98 -0
- package/dist/web/index.html +24 -0
- package/dist/web/instructor.js +1 -0
- package/dist/web/model-elements.js +256 -15
- package/dist/web/pdf-active-content.js +38 -0
- package/dist/web/steel-3d-view.js +5 -1
- package/dist/web/steel-ai-marks.js +19 -3
- package/dist/web/steel-catalog-picker.js +7 -2
- package/dist/web/steel-editor.html +164 -14
- package/dist/web/steel-profile-card-state.js +378 -0
- package/dist/web/steel-profile-card.js +778 -0
- package/dist/web/steel-shape-sketch-core.js +380 -0
- package/dist/web/steel-shape-sketcher.js +595 -0
- package/dist/web/workspaces.js +340 -26
- package/package.json +2 -1
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
// The profile card (epic #3382 §7.2, slice P2): wherever a profile name is shown or edited, hovering or focusing the field
|
|
2
|
+
// opens a card that decodes it. A parametric name is split into its sizes with the size letter under each, with the order
|
|
3
|
+
// it is written in, a labelled drawing and a field per size; editing a size previews in 3D and Enter applies it. Other names
|
|
4
|
+
// get their own state (a library profile's facts, an extra number, a missing size, a Tekla shape not drawn yet, an unknown
|
|
5
|
+
// name). The card can be pinned as a block under the Profile row.
|
|
6
|
+
//
|
|
7
|
+
// This file owns the popover, the timers, the pin, the keyboard and the live 3D preview. What a card says lives in
|
|
8
|
+
// `steel-profile-card-state.js` (pure); what a change does to the model is the editor's, handed in as `host`.
|
|
9
|
+
|
|
10
|
+
import * as P from './steel-parametric-pick.js';
|
|
11
|
+
import {
|
|
12
|
+
announcement, cardHtml, definitionByPrefix, drawingFor, esc, fieldsHtml, formNameText, hintFor, initialForm, judgeForm,
|
|
13
|
+
nameHtml, orderHtml, profileCardState, resultHtml, typingText,
|
|
14
|
+
} from './steel-profile-card-state.js';
|
|
15
|
+
|
|
16
|
+
export { profileCardState };
|
|
17
|
+
|
|
18
|
+
const PIN_KEY = 'floless.steel.profileCard.pinned';
|
|
19
|
+
const HOVER_MS = 400;
|
|
20
|
+
const LEAVE_MS = 350;
|
|
21
|
+
const PREVIEW_MS = 120;
|
|
22
|
+
const FIELD_SELECTOR = 'input.combo[data-src=profiles], [data-profile-card]';
|
|
23
|
+
|
|
24
|
+
const STYLE = `
|
|
25
|
+
#profileCard{position:fixed;z-index:50;width:372px;max-width:calc(100vw - 16px);max-height:calc(100vh - 16px);overflow:auto;box-sizing:border-box;padding:12px 14px;background:var(--panel);color:var(--text);border:1px solid var(--ctrl-border);border-radius:8px;box-shadow:var(--shadow-lg);font-size:12px;line-height:1.45;scrollbar-width:thin;scrollbar-color:var(--scroll) transparent}
|
|
26
|
+
#profileCard[hidden]{display:none}
|
|
27
|
+
.pcd-pin-host{margin:6px 0 0}
|
|
28
|
+
.pcd-pin-host[hidden]{display:none}
|
|
29
|
+
.pcd-pin-host .pcd{padding:10px 12px;background:var(--field);border:1px solid var(--line);border-radius:8px}
|
|
30
|
+
.pcd-pin-host .pcd:empty{display:none}
|
|
31
|
+
#profileCard::-webkit-scrollbar,.pcd-pin-host::-webkit-scrollbar{width:8px;height:8px}
|
|
32
|
+
#profileCard::-webkit-scrollbar-thumb{background:var(--scroll);border-radius:8px}
|
|
33
|
+
#profileCard::-webkit-scrollbar-button{display:none}
|
|
34
|
+
.pcd-head{display:flex;align-items:baseline;gap:8px;margin:0 0 8px}
|
|
35
|
+
.pcd-pfx{font:700 13px ui-monospace,Consolas,monospace}
|
|
36
|
+
.pcd-title{color:var(--mut);flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
37
|
+
.pcd-links{display:flex;gap:10px;flex:none}
|
|
38
|
+
.pcd-link{background:none;border:0;padding:0;margin:0;color:var(--info-ink,var(--brand));font:inherit;cursor:pointer;width:auto;height:auto;min-height:0}
|
|
39
|
+
.pcd-link:hover{text-decoration:underline}
|
|
40
|
+
.pcd-link:focus-visible,.pcd-btn:focus-visible,.pcd-in input:focus-visible{outline:2px solid var(--brand);outline-offset:1px}
|
|
41
|
+
.pcd-name{display:flex;flex-wrap:wrap;align-items:flex-start;gap:2px;font:600 16px ui-monospace,Consolas,monospace;margin:0 0 4px;overflow-wrap:anywhere}
|
|
42
|
+
.pcd-sep{padding-top:1px;color:var(--mut)}
|
|
43
|
+
.pcd-prefix{color:var(--text);font-weight:700}
|
|
44
|
+
.pcd-size{display:inline-flex;flex-direction:column;align-items:center;padding:1px 4px;border-radius:4px;border:1px solid transparent}
|
|
45
|
+
.pcd-size b{font-weight:600}
|
|
46
|
+
.pcd-size i{font:italic 10px ui-monospace,Consolas,monospace;color:var(--mut);margin-top:-1px}
|
|
47
|
+
.pcd-size.on{background:var(--brand);border-color:var(--brand);color:#fff}
|
|
48
|
+
.pcd-size.on i{color:#fff}
|
|
49
|
+
.pcd-order{color:var(--mut);margin:0 0 8px}
|
|
50
|
+
.pcd-order code{font:12px ui-monospace,Consolas,monospace;color:var(--text)}
|
|
51
|
+
.pcd-draw{background:var(--bg,var(--field));border:1px solid var(--line);border-radius:6px;padding:6px;margin:0 0 10px;color:var(--brand)}
|
|
52
|
+
.pcd-draw svg{display:block;width:100%;height:auto;max-height:190px}
|
|
53
|
+
.pcd-pin-host .pcd-draw svg{max-height:130px}
|
|
54
|
+
.pcd-draw.pcd-lib{width:84px;height:84px;padding:10px;color:var(--text)}
|
|
55
|
+
.pcd-draw .pcd-note{color:var(--mut)}
|
|
56
|
+
.pcd-fields{border-top:1px solid var(--line)}
|
|
57
|
+
.pcd-row{display:grid;grid-template-columns:1fr 112px;align-items:center;gap:2px 8px;padding:5px 4px;border-bottom:1px solid var(--line)}
|
|
58
|
+
.pcd-row.on{background:var(--brand-soft,rgba(59,130,246,.14))}
|
|
59
|
+
.pcd-row label{color:var(--text)}
|
|
60
|
+
.pcd-row label i{font:italic 12px ui-monospace,Consolas,monospace;color:var(--info-ink,var(--brand));display:inline-block;min-width:12px}
|
|
61
|
+
.pcd-opt{color:var(--mut)}
|
|
62
|
+
.pcd-in{display:flex;align-items:center;gap:6px}
|
|
63
|
+
.pcd-in input{width:100%;min-width:0;box-sizing:border-box;text-align:right;font:12px ui-monospace,Consolas,monospace;padding:4px 7px;background:var(--field);color:var(--text);border:1px solid var(--ctrl-border);border-radius:5px;height:auto}
|
|
64
|
+
.pcd-in input[aria-invalid=true]{border-color:var(--warn)}
|
|
65
|
+
.pcd-in u{text-decoration:none;color:var(--mut);width:18px;font-size:11px}
|
|
66
|
+
.pcd-hint{grid-column:1 / -1;color:var(--mut);font-size:11px;text-align:right;min-height:0}
|
|
67
|
+
.pcd-hint:empty{display:none}
|
|
68
|
+
.pcd-hint.bad{color:var(--warn)}
|
|
69
|
+
.pcd-typing{margin:8px 0 0;color:var(--mut)}
|
|
70
|
+
.pcd-typing:empty{display:none}
|
|
71
|
+
.pcd-typing b,.pcd-typing i{color:var(--text)}
|
|
72
|
+
.pcd-facts{display:flex;gap:14px;flex-wrap:wrap;margin:8px 0 0;color:var(--mut)}
|
|
73
|
+
.pcd-facts b{color:var(--text);font-weight:650}
|
|
74
|
+
.pcd-lfacts{display:grid;grid-template-columns:1fr auto;margin:0 0 8px}
|
|
75
|
+
.pcd-lfacts dt,.pcd-lfacts dd{margin:0;padding:4px 0;border-bottom:1px solid var(--line)}
|
|
76
|
+
.pcd-lfacts dt{color:var(--mut)}.pcd-lfacts dd{text-align:right;font-variant-numeric:tabular-nums}
|
|
77
|
+
.pcd-note{color:var(--mut);margin:6px 0 0}
|
|
78
|
+
.pcd-warn{margin:8px 0 0;padding:7px 9px;border-radius:6px;background:var(--warn-bg);color:var(--warn)}
|
|
79
|
+
.pcd-keys{margin:10px 0 0;color:var(--mut);font-size:11px}
|
|
80
|
+
.pcd-keys kbd{font:600 10px ui-monospace,Consolas,monospace;padding:1px 5px;border:1px solid var(--ctrl-border);border-radius:4px;background:var(--field);color:var(--text)}
|
|
81
|
+
.pcd-actions{display:flex;gap:8px;flex-wrap:wrap;margin:10px 0 0}
|
|
82
|
+
.pcd-btn{width:auto;height:auto;min-height:0;padding:5px 12px;border-radius:6px;border:1px solid var(--ctrl-border);background:var(--btn);color:var(--text);font:inherit;cursor:pointer}
|
|
83
|
+
.pcd-btn:hover{border-color:var(--brand)}
|
|
84
|
+
.pcd-btn.primary{background:var(--brand);border-color:var(--brand);color:#fff}
|
|
85
|
+
.pcd-readings{display:grid;gap:6px;margin:8px 0 0}
|
|
86
|
+
.pcd-reading{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:6px 8px;border:1px solid var(--line);border-radius:6px}
|
|
87
|
+
.pcd-reading code{display:block;font:600 13px ui-monospace,Consolas,monospace}
|
|
88
|
+
.pcd-reading .pcd-note{margin:0;display:block}
|
|
89
|
+
.pcd-info{flex:none;width:auto;min-width:30px;padding:0 7px}
|
|
90
|
+
.pcd-tag{flex:none;padding:0 6px;border-radius:999px;background:var(--warn-bg);color:var(--warn);font-size:10px;font-weight:650}
|
|
91
|
+
.pcd-tag[hidden]{display:none}
|
|
92
|
+
.pcd-extra{color:var(--warn);text-decoration:line-through}
|
|
93
|
+
.pcd-words{color:var(--mut)}
|
|
94
|
+
.pcd-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
95
|
+
`;
|
|
96
|
+
|
|
97
|
+
/** The saved choice, per browser profile (the person's own, like their other editor choices). Never throws. */
|
|
98
|
+
function readPinned() { try { return globalThis.localStorage?.getItem(PIN_KEY) === '1'; } catch { return false; } }
|
|
99
|
+
function writePinned(on) { try { globalThis.localStorage?.setItem(PIN_KEY, on ? '1' : '0'); } catch { /* a blocked store only forgets the choice */ } }
|
|
100
|
+
|
|
101
|
+
export function ensureCardStyles(doc) {
|
|
102
|
+
if (doc.getElementById('profileCardStyles')) return;
|
|
103
|
+
const style = doc.createElement('style');
|
|
104
|
+
style.id = 'profileCardStyles';
|
|
105
|
+
style.textContent = STYLE;
|
|
106
|
+
doc.head.appendChild(style);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Put the card on the page.
|
|
111
|
+
* @param {{
|
|
112
|
+
* document: Document, panel: () => Element | null,
|
|
113
|
+
* context: () => any, describeField: (el: Element) => ({ kind: string, ids: string[], member: any, readonly?: boolean } | null),
|
|
114
|
+
* preview: (info: any, args: any) => true | string, endPreview: () => void, commit: (info: any, args: any) => boolean,
|
|
115
|
+
* openCatalog: (info: any, text: string) => void, define: (text: string) => void, load: () => Promise<any>,
|
|
116
|
+
* selectionKey: () => string, say?: (message: string) => void,
|
|
117
|
+
* }} host
|
|
118
|
+
*/
|
|
119
|
+
export function installProfileCard(host) {
|
|
120
|
+
const doc = host.document;
|
|
121
|
+
const win = doc.defaultView || globalThis;
|
|
122
|
+
ensureCardStyles(doc);
|
|
123
|
+
|
|
124
|
+
let pinned = readPinned();
|
|
125
|
+
const root = doc.createElement('div');
|
|
126
|
+
root.id = 'profileCard';
|
|
127
|
+
root.className = 'pcd';
|
|
128
|
+
root.setAttribute('role', 'dialog');
|
|
129
|
+
root.setAttribute('aria-modal', 'false');
|
|
130
|
+
root.setAttribute('aria-label', 'Profile card');
|
|
131
|
+
root.setAttribute('aria-live', 'off');
|
|
132
|
+
root.hidden = true;
|
|
133
|
+
doc.body.appendChild(root);
|
|
134
|
+
const live = doc.createElement('div');
|
|
135
|
+
live.className = 'pcd-sr';
|
|
136
|
+
live.setAttribute('role', 'status');
|
|
137
|
+
live.setAttribute('aria-live', 'polite');
|
|
138
|
+
doc.body.appendChild(live);
|
|
139
|
+
|
|
140
|
+
const floatView = makeView(root, 'float');
|
|
141
|
+
const pinHost = doc.createElement('div');
|
|
142
|
+
pinHost.className = 'pcd-pin-host';
|
|
143
|
+
pinHost.id = 'profileCardPin';
|
|
144
|
+
pinHost.hidden = true;
|
|
145
|
+
const pinRoot = doc.createElement('div');
|
|
146
|
+
pinRoot.className = 'pcd';
|
|
147
|
+
pinRoot.setAttribute('role', 'group');
|
|
148
|
+
pinRoot.setAttribute('aria-label', 'Profile card');
|
|
149
|
+
pinHost.appendChild(pinRoot);
|
|
150
|
+
const pinView = makeView(pinRoot, 'pin');
|
|
151
|
+
|
|
152
|
+
let hoverTimer = null;
|
|
153
|
+
let leaveTimer = null;
|
|
154
|
+
let previewTimer = null;
|
|
155
|
+
let previewing = null; // the view whose sizes are previewed in 3D right now
|
|
156
|
+
let bypassChange = false;
|
|
157
|
+
let quiet = false;
|
|
158
|
+
let lastAnnounced = '';
|
|
159
|
+
|
|
160
|
+
function makeView(rootEl, mode) {
|
|
161
|
+
return { root: rootEl, mode, el: null, elId: '', info: null, state: null, form: null, judged: null, drawing: null, skeleton: '', baseProfile: '', ids: '', pending: false, focusSym: null, activeAt: 0, signature: '', dismissed: null };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const isField = (el) => !!(el && el.nodeType === 1 && el.matches && el.matches(FIELD_SELECTOR));
|
|
165
|
+
const textOf = (el) => (el.matches('input') ? el.value : (el.getAttribute('data-profile-card') || ''));
|
|
166
|
+
const inCard = (node) => !!(node && (root.contains(node) || pinHost.contains(node)));
|
|
167
|
+
|
|
168
|
+
// ---- painting ------------------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
function session(view) {
|
|
171
|
+
const info = view.info;
|
|
172
|
+
const canPreview = !!info && (info.kind === 'member' || info.kind === 'selection') && !info.readonly;
|
|
173
|
+
const base = view.baseProfile;
|
|
174
|
+
const keeps = info && info.kind === 'selection'
|
|
175
|
+
? 'The members keep their sizes until then.'
|
|
176
|
+
: `The member keeps its last complete size${base ? `, ${base}` : ''}, until then.`;
|
|
177
|
+
return { canPreview, keepsText: keeps };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function stateFor(view) {
|
|
181
|
+
const el = view.el;
|
|
182
|
+
const info = view.info;
|
|
183
|
+
const ctx = host.context();
|
|
184
|
+
const focused = doc.activeElement === el;
|
|
185
|
+
const caret = focused && el.matches('input') && el.selectionStart != null ? el.selectionStart : null;
|
|
186
|
+
return { ctx, state: profileCardState({ text: textOf(el), caret, ctx, member: info.member }) };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function paint(view) {
|
|
190
|
+
if (!view.el || !view.el.isConnected) {
|
|
191
|
+
const again = view.elId ? doc.getElementById(view.elId) : null;
|
|
192
|
+
if (!again) { if (view.mode === 'float') closeFloat(); return; }
|
|
193
|
+
view.el = again;
|
|
194
|
+
}
|
|
195
|
+
view.info = host.describeField(view.el);
|
|
196
|
+
view.ids = host.selectionKey();
|
|
197
|
+
if (!view.info) { if (view.mode === 'float') closeFloat(); else view.root.innerHTML = ''; return; }
|
|
198
|
+
const editing = !!(view.form && view.form.edited && view.state && view.state.kind === 'parametric');
|
|
199
|
+
let ctx;
|
|
200
|
+
let state;
|
|
201
|
+
if (editing) { ctx = host.context(); state = view.state; } else ({ ctx, state } = stateFor(view));
|
|
202
|
+
if (state.kind === 'loading' && !view.loadAsked) {
|
|
203
|
+
view.loadAsked = true;
|
|
204
|
+
host.load().then(() => { view.loadAsked = false; paint(view); }, () => { view.loadAsked = false; paint(view); });
|
|
205
|
+
}
|
|
206
|
+
if (state.kind === 'none' || (view.dismissed != null && view.dismissed === textOf(view.el))) {
|
|
207
|
+
view.state = state;
|
|
208
|
+
view.skeleton = '';
|
|
209
|
+
view.html = '';
|
|
210
|
+
if (view.mode === 'float') { root.hidden = true; } else view.root.innerHTML = '';
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
view.state = state;
|
|
214
|
+
let judged = null;
|
|
215
|
+
let drawing = null;
|
|
216
|
+
if (state.kind === 'parametric') {
|
|
217
|
+
const fresh = initialForm(state, ctx);
|
|
218
|
+
if (!view.form || view.form.key !== fresh.key || (!view.form.edited && view.form.sourceText !== fresh.sourceText)) {
|
|
219
|
+
view.form = fresh;
|
|
220
|
+
view.baseProfile = view.info.member?.profile || '';
|
|
221
|
+
}
|
|
222
|
+
if (view.info.kind === 'selection') view.baseProfile = '';
|
|
223
|
+
view.ids = host.selectionKey();
|
|
224
|
+
judged = judgeForm(state, view.form, ctx, view.info.member?.material);
|
|
225
|
+
view.judged = judged;
|
|
226
|
+
drawing = drawingFor(state.definition, judged, view.form.focus ?? state.caret?.symbol ?? null, ctx);
|
|
227
|
+
view.drawing = drawing;
|
|
228
|
+
} else { view.form = null; view.judged = null; }
|
|
229
|
+
const key = `${state.kind}|${state.definition?.id || ''}|${state.bound ? 'b' : 't'}|${ctx.units}|${pinned ? 'p' : 'f'}|${view.info.readonly ? 'r' : 'w'}`;
|
|
230
|
+
const sess = session(view);
|
|
231
|
+
if (state.kind === 'parametric' && view.skeleton === key && view.root.querySelector('[data-part=fields]')) {
|
|
232
|
+
updateParts(view, state, judged, drawing, ctx, sess);
|
|
233
|
+
} else {
|
|
234
|
+
const was = doc.activeElement;
|
|
235
|
+
const html = cardHtml(state, { form: view.form, judged, ctx, pinned, session: sess, drawing });
|
|
236
|
+
// The same card again (a panel redraw woke the painter) is left alone: replacing it would eat a click in progress.
|
|
237
|
+
if (state.kind !== 'parametric' && view.skeleton === key && view.html === html && view.root.firstChild) { if (view.mode === 'float') { root.hidden = false; place(view); } return; }
|
|
238
|
+
view.html = html;
|
|
239
|
+
view.root.innerHTML = html;
|
|
240
|
+
view.skeleton = key;
|
|
241
|
+
if (state.kind === 'parametric') { updateHints(view, judged, ctx); if (view.info.readonly) view.root.querySelectorAll('input[data-sym]').forEach((i) => { i.readOnly = true; }); }
|
|
242
|
+
if (was && was !== doc.activeElement && was.isConnected && was.focus && !inCard(was)) was.focus();
|
|
243
|
+
}
|
|
244
|
+
view.root.setAttribute('aria-label', view.mode === 'pin' ? 'Profile card, pinned' : `Profile card: ${view.root.querySelector('.pcd-pfx')?.textContent || ''} ${view.root.querySelector('.pcd-title')?.textContent || ''}`.trim());
|
|
245
|
+
if (view.mode === 'float') { root.hidden = false; place(view); }
|
|
246
|
+
announce(state, judged);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function updateParts(view, state, judged, drawing, ctx, sess) {
|
|
250
|
+
const part = (name) => view.root.querySelector(`[data-part=${name}]`);
|
|
251
|
+
const set = (name, html) => { const node = part(name); if (node) node.innerHTML = html; };
|
|
252
|
+
set('name', nameHtml(state, view.form, judged));
|
|
253
|
+
set('order', orderHtml(state.definition));
|
|
254
|
+
set('draw', drawing?.svg || '<div class=pcd-note>No drawing for this shape yet.</div>');
|
|
255
|
+
set('result', resultHtml(state, view.form, judged, ctx, sess));
|
|
256
|
+
const tag = part('tag');
|
|
257
|
+
if (tag) tag.hidden = !view.form.edited;
|
|
258
|
+
const typing = part('typing');
|
|
259
|
+
if (typing) typing.innerHTML = view.form.edited ? '' : typingText(state);
|
|
260
|
+
const focus = view.form.focus ?? state.caret?.symbol ?? null;
|
|
261
|
+
view.root.querySelectorAll('.pcd-row').forEach((row) => row.classList.toggle('on', row.getAttribute('data-symbol') === focus));
|
|
262
|
+
view.root.querySelectorAll('input[data-sym]').forEach((input) => {
|
|
263
|
+
const sym = input.getAttribute('data-sym');
|
|
264
|
+
if (doc.activeElement !== input && input.value !== (view.form.texts[sym] ?? '')) input.value = view.form.texts[sym] ?? '';
|
|
265
|
+
});
|
|
266
|
+
updateHints(view, judged, ctx);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function updateHints(view, judged, ctx) {
|
|
270
|
+
if (!judged || !view.state || view.state.kind !== 'parametric') return;
|
|
271
|
+
P.formFields(view.state.definition, ctx.units).forEach((field, index) => {
|
|
272
|
+
const hint = view.root.querySelector(`#pcdF${index}H`);
|
|
273
|
+
const input = view.root.querySelector(`#pcdF${index}`);
|
|
274
|
+
if (!hint || !input) return;
|
|
275
|
+
const h = hintFor(field, view.form.texts[field.symbol] ?? '', judged, ctx.units);
|
|
276
|
+
hint.textContent = h.text;
|
|
277
|
+
hint.classList.toggle('bad', !!h.bad);
|
|
278
|
+
input.setAttribute('aria-invalid', h.bad ? 'true' : 'false');
|
|
279
|
+
if (h.bad) input.setAttribute('aria-describedby', hint.id); else input.removeAttribute('aria-describedby');
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function announce(state, judged) {
|
|
284
|
+
const text = announcement(state, judged);
|
|
285
|
+
if (text && text !== lastAnnounced) { lastAnnounced = text; live.textContent = text; }
|
|
286
|
+
if (!text) lastAnnounced = '';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function place(view) {
|
|
290
|
+
const el = view.el;
|
|
291
|
+
if (!el || !el.isConnected) return;
|
|
292
|
+
const r = el.getBoundingClientRect();
|
|
293
|
+
const w = root.offsetWidth || 372;
|
|
294
|
+
const h = root.offsetHeight || 320;
|
|
295
|
+
const pane = el.closest('#panel');
|
|
296
|
+
const pr = pane ? pane.getBoundingClientRect() : r;
|
|
297
|
+
let left = pr.left - w - 10;
|
|
298
|
+
let top = r.top - 24;
|
|
299
|
+
if (left < 8) { left = Math.min(Math.max(8, r.left), Math.max(8, win.innerWidth - w - 8)); top = r.bottom + 6; }
|
|
300
|
+
top = Math.max(8, Math.min(top, win.innerHeight - h - 8));
|
|
301
|
+
root.style.left = `${Math.round(left)}px`;
|
|
302
|
+
root.style.top = `${Math.round(top)}px`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ---- opening and closing ----------------------------------------------------------------------------
|
|
306
|
+
|
|
307
|
+
function openFloat(el) {
|
|
308
|
+
if (pinned && pinView.el === el) return;
|
|
309
|
+
const info = host.describeField(el);
|
|
310
|
+
if (!info) return;
|
|
311
|
+
if (floatView.el !== el) { endSession(floatView, true); floatView.form = null; floatView.dismissed = null; floatView.skeleton = ''; }
|
|
312
|
+
floatView.el = el;
|
|
313
|
+
floatView.elId = el.id || '';
|
|
314
|
+
paint(floatView);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function closeFloat() {
|
|
318
|
+
clearTimeout(hoverTimer);
|
|
319
|
+
clearTimeout(leaveTimer);
|
|
320
|
+
endSession(floatView, true);
|
|
321
|
+
restorePending(floatView);
|
|
322
|
+
root.hidden = true;
|
|
323
|
+
floatView.skeleton = '';
|
|
324
|
+
floatView.state = null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Put the field back to what the member holds when its change was held back and the card goes away. */
|
|
328
|
+
function restorePending(view) {
|
|
329
|
+
if (!view.pending) return;
|
|
330
|
+
view.pending = false;
|
|
331
|
+
const el = view.el && view.el.isConnected ? view.el : (view.elId ? doc.getElementById(view.elId) : null);
|
|
332
|
+
const member = view.info && view.info.member;
|
|
333
|
+
if (el && el.matches('input') && member && el.value !== member.profile) el.value = member.profile;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function endSession(view, revert) {
|
|
337
|
+
// Only a view that is really in a session ends one: the preview timer belongs to whichever view is being typed in.
|
|
338
|
+
if (view.form && view.form.edited) {
|
|
339
|
+
clearTimeout(previewTimer);
|
|
340
|
+
if (revert && previewing === view) host.endPreview();
|
|
341
|
+
view.form.edited = false;
|
|
342
|
+
view.form.sourceText = null;
|
|
343
|
+
}
|
|
344
|
+
if (previewing === view) previewing = null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ---- typing in a size field: preview, apply, undo -----------------------------------------------------
|
|
348
|
+
|
|
349
|
+
function viewOf(node) { return root.contains(node) ? floatView : pinHost.contains(node) ? pinView : null; }
|
|
350
|
+
|
|
351
|
+
function schedulePreview(view) {
|
|
352
|
+
clearTimeout(previewTimer);
|
|
353
|
+
previewTimer = setTimeout(() => runPreview(view), PREVIEW_MS);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function spellingFor(view, judged) {
|
|
357
|
+
const ctx = host.context();
|
|
358
|
+
const typed = { text: P.typedName(view.state.definition, view.form.texts), units: ctx.units };
|
|
359
|
+
const honest = P.honestSpelling(view.state.definition, judged.params, typed);
|
|
360
|
+
return honest ? { ...honest, source: 'typed' } : null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function runPreview(view) {
|
|
364
|
+
if (!view.state || view.state.kind !== 'parametric' || !view.form.edited) return;
|
|
365
|
+
const sess = session(view);
|
|
366
|
+
const ctx = host.context();
|
|
367
|
+
const judged = judgeForm(view.state, view.form, ctx, view.info.member?.material);
|
|
368
|
+
view.judged = judged;
|
|
369
|
+
if (!sess.canPreview) return;
|
|
370
|
+
if (judged.status === 'ok' || judged.status === 'outside') {
|
|
371
|
+
const answer = host.preview(view.info, { definition: view.state.definition, params: judged.params, spelling: spellingFor(view, judged) });
|
|
372
|
+
previewing = view;
|
|
373
|
+
if (answer !== true) {
|
|
374
|
+
const note = view.root.querySelector('[data-part=result]');
|
|
375
|
+
if (note) note.insertAdjacentHTML('beforeend', `<div class="pcd-warn"><span aria-hidden=true>!</span> ${esc(String(answer))}</div>`);
|
|
376
|
+
}
|
|
377
|
+
} else if (previewing === view) {
|
|
378
|
+
host.endPreview();
|
|
379
|
+
previewing = null;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function onSizeInput(view, input) {
|
|
384
|
+
const sym = input.getAttribute('data-sym');
|
|
385
|
+
if (view.form.texts[sym] === input.value && view.form.edited) return;
|
|
386
|
+
view.form.texts[sym] = input.value;
|
|
387
|
+
view.form.edited = true;
|
|
388
|
+
view.form.focus = sym;
|
|
389
|
+
view.focusSym = sym;
|
|
390
|
+
const ctx = host.context();
|
|
391
|
+
view.judged = judgeForm(view.state, view.form, ctx, view.info.member?.material);
|
|
392
|
+
view.drawing = drawingFor(view.state.definition, view.judged, sym, ctx);
|
|
393
|
+
updateParts(view, view.state, view.judged, view.drawing, ctx, session(view));
|
|
394
|
+
schedulePreview(view);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function commitForm(view) {
|
|
398
|
+
clearTimeout(previewTimer);
|
|
399
|
+
runJudgeNow(view);
|
|
400
|
+
const judged = view.judged;
|
|
401
|
+
if (!(judged.status === 'ok' || judged.status === 'outside')) {
|
|
402
|
+
const bad = judged.invalid[0]?.field || judged.missing[0];
|
|
403
|
+
const input = bad ? view.root.querySelector(`input[data-sym="${bad.symbol}"]`) : null;
|
|
404
|
+
if (input) input.focus();
|
|
405
|
+
live.textContent = `Not applied. ${(view.root.querySelector('[data-part=result]')?.textContent || '').trim()} Press Escape to put the old size back.`;
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const spelling = spellingFor(view, judged);
|
|
409
|
+
const info = view.info;
|
|
410
|
+
const definition = view.state.definition;
|
|
411
|
+
const params = judged.params;
|
|
412
|
+
const name = judged.name;
|
|
413
|
+
if (previewing === view) { host.endPreview(); previewing = null; }
|
|
414
|
+
const sym = view.form.focus;
|
|
415
|
+
let taken = true;
|
|
416
|
+
if (info.kind === 'member' || info.kind === 'selection') taken = host.commit(info, { definition, params, spelling }) !== false;
|
|
417
|
+
else setFieldText(view.el, name);
|
|
418
|
+
if (!taken) {
|
|
419
|
+
// The editor said why (a toast); the typed sizes stay so they can be fixed, and nothing was applied.
|
|
420
|
+
live.textContent = 'Not applied. The member keeps its section. Change the sizes, or press Escape to put the old ones back.';
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
live.textContent = `Applied ${name}.`;
|
|
424
|
+
lastAnnounced = '';
|
|
425
|
+
view.form.edited = false;
|
|
426
|
+
view.form.sourceText = null;
|
|
427
|
+
// The card stays open on the applied section, with the cursor where it was, so the next size can be changed at once.
|
|
428
|
+
view.form = null;
|
|
429
|
+
paint(view);
|
|
430
|
+
const again = sym ? view.root.querySelector(`input[data-sym="${cssEscape(sym)}"]`) : null;
|
|
431
|
+
if (again) again.focus();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function runJudgeNow(view) {
|
|
435
|
+
const ctx = host.context();
|
|
436
|
+
view.judged = judgeForm(view.state, view.form, ctx, view.info.member?.material);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function revertForm(view) {
|
|
440
|
+
clearTimeout(previewTimer);
|
|
441
|
+
if (previewing === view) { host.endPreview(); previewing = null; }
|
|
442
|
+
view.form = null;
|
|
443
|
+
paint(view);
|
|
444
|
+
const first = view.root.querySelector('input[data-sym]');
|
|
445
|
+
if (first && view.state && view.state.kind === 'parametric') first.focus();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function refocus(view) {
|
|
449
|
+
const again = view.elId ? doc.getElementById(view.elId) : null;
|
|
450
|
+
if (again) { view.el = again; again.focus(); }
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function setFieldText(el, text) {
|
|
454
|
+
if (!el || !el.matches('input')) return;
|
|
455
|
+
el.value = text;
|
|
456
|
+
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
457
|
+
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// ---- buttons --------------------------------------------------------------------------------------------
|
|
461
|
+
|
|
462
|
+
function onClick(view, button) {
|
|
463
|
+
const action = button.getAttribute('data-pcd');
|
|
464
|
+
const state = view.state;
|
|
465
|
+
if (action === 'pin') { setPinned(!pinned); return; }
|
|
466
|
+
if (action === 'catalog') { const text = textOf(view.el); const info = view.info; if (view.mode === 'float') closeFloat(); host.openCatalog(info, text); return; }
|
|
467
|
+
if (action === 'define') { host.define(textOf(view.el)); return; }
|
|
468
|
+
if (action === 'retry') { host.load().then(() => paint(view), () => paint(view)); paint(view); return; }
|
|
469
|
+
if (action === 'keep') {
|
|
470
|
+
view.dismissed = textOf(view.el);
|
|
471
|
+
view.pending = false;
|
|
472
|
+
const el = view.el;
|
|
473
|
+
bypassChange = true;
|
|
474
|
+
try { el.dispatchEvent(new Event('change', { bubbles: true })); } finally { bypassChange = false; }
|
|
475
|
+
if (view.mode === 'float') closeFloat(); else paint(view);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (action === 'use' && state && state.kind === 'extra' && state.trimmed) {
|
|
479
|
+
const el = view.el;
|
|
480
|
+
view.pending = false;
|
|
481
|
+
setFieldText(el, state.trimmed.text);
|
|
482
|
+
if (view.mode === 'float') closeFloat();
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (action === 'reading' && state && state.kind === 'ambiguous') {
|
|
486
|
+
const reading = state.readings[Number(button.getAttribute('data-index'))];
|
|
487
|
+
if (!reading) return;
|
|
488
|
+
const info = view.info;
|
|
489
|
+
if ((info.kind === 'member' || info.kind === 'selection') && !info.readonly) {
|
|
490
|
+
const spelling = P.honestSpelling(reading.definition, reading.params, { text: state.text, units: reading.units });
|
|
491
|
+
view.pending = false;
|
|
492
|
+
host.commit(info, { definition: reading.definition, params: reading.params, spelling: spelling ? { ...spelling, source: 'typed' } : null });
|
|
493
|
+
refocus(view);
|
|
494
|
+
} else {
|
|
495
|
+
setFieldText(view.el, reading.canonical);
|
|
496
|
+
}
|
|
497
|
+
if (view.mode === 'float') closeFloat();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function setPinned(on) {
|
|
502
|
+
pinned = !!on;
|
|
503
|
+
writePinned(pinned);
|
|
504
|
+
closeFloat();
|
|
505
|
+
floatView.el = null;
|
|
506
|
+
syncPin();
|
|
507
|
+
if (!pinned) { const field = pinView.el; if (field) openFloat(field); }
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// ---- the pin under the Profile row, and the ⓘ button ------------------------------------------------------
|
|
511
|
+
|
|
512
|
+
function profileFieldsIn(panel) {
|
|
513
|
+
return [...panel.querySelectorAll('input.combo[data-src=profiles]')].filter((el) => el.id === 'pf' || el.id === 'addProf');
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** The pinned card leaves the pane: a size still being previewed is put back first, never left on the model. */
|
|
517
|
+
function dropPin() {
|
|
518
|
+
endSession(pinView, true);
|
|
519
|
+
pinView.form = null;
|
|
520
|
+
pinView.el = null;
|
|
521
|
+
pinHost.remove();
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function syncPin() {
|
|
525
|
+
const panel = host.panel();
|
|
526
|
+
if (!panel) return;
|
|
527
|
+
const [field] = profileFieldsIn(panel);
|
|
528
|
+
if (!field) { dropPin(); return; }
|
|
529
|
+
// ⓘ: the touch route to the card, beside the field's own buttons.
|
|
530
|
+
const row = field.parentElement;
|
|
531
|
+
const block = (row && row.closest('.f')) || row;
|
|
532
|
+
if (row && !row.querySelector('[data-pcd-info]')) {
|
|
533
|
+
const button = doc.createElement('button');
|
|
534
|
+
button.type = 'button';
|
|
535
|
+
button.className = 'ghost pcd-info';
|
|
536
|
+
button.setAttribute('data-pcd-info', '');
|
|
537
|
+
button.setAttribute('data-command-id', 'steel.profile-card-info');
|
|
538
|
+
button.setAttribute('aria-label', 'Show the profile card');
|
|
539
|
+
button.setAttribute('data-tip', 'Show what this profile name means: its sizes, drawing and weight. Alt+Down in the field moves into the card.');
|
|
540
|
+
button.textContent = 'ⓘ';
|
|
541
|
+
row.appendChild(button);
|
|
542
|
+
}
|
|
543
|
+
if (!pinned) { dropPin(); return; }
|
|
544
|
+
if (pinHost.previousElementSibling !== block || !pinHost.isConnected) {
|
|
545
|
+
// A redraw of the panel takes the pinned card out and puts it back: a field being typed in gets its cursor back.
|
|
546
|
+
const hadFocus = pinView.focusSym && Date.now() - pinView.activeAt < 1500 ? pinView.focusSym : null;
|
|
547
|
+
const caret = hadFocus ? lastCaret : null;
|
|
548
|
+
block.after(pinHost);
|
|
549
|
+
if (hadFocus) {
|
|
550
|
+
const input = pinRoot.querySelector(`input[data-sym="${cssEscape(hadFocus)}"]`);
|
|
551
|
+
if (input) { input.focus(); if (caret != null && input.setSelectionRange) { try { input.setSelectionRange(caret, caret); } catch { /* not a text input */ } } }
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
pinHost.hidden = false;
|
|
555
|
+
pinView.el = field;
|
|
556
|
+
pinView.elId = field.id;
|
|
557
|
+
const editing = !!(pinView.form && pinView.form.edited);
|
|
558
|
+
if (editing && pinView.ids && pinView.ids !== host.selectionKey()) { endSession(pinView, true); pinView.form = null; }
|
|
559
|
+
// Painting the card changes the panel, which wakes this again: only paint when what it shows has changed, or it would never stop.
|
|
560
|
+
const signature = `${field.id}|${field.value}|${pinned}|${host.selectionKey()}|${pinHost.isConnected}`;
|
|
561
|
+
if (signature === pinView.signature && pinView.root.firstChild) return;
|
|
562
|
+
pinView.signature = signature;
|
|
563
|
+
paint(pinView);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
let lastCaret = null;
|
|
567
|
+
const cssEscape = (value) => (win.CSS && win.CSS.escape ? win.CSS.escape(value) : String(value).replace(/["\\]/g, '\\$&'));
|
|
568
|
+
|
|
569
|
+
// ---- events ------------------------------------------------------------------------------------------------
|
|
570
|
+
|
|
571
|
+
const fieldOf = (node) => (node && node.closest ? node.closest(FIELD_SELECTOR) : null);
|
|
572
|
+
|
|
573
|
+
doc.addEventListener('mouseover', (event) => {
|
|
574
|
+
const field = fieldOf(event.target);
|
|
575
|
+
if (!field) { if (inCard(event.target)) clearTimeout(leaveTimer); return; }
|
|
576
|
+
clearTimeout(leaveTimer);
|
|
577
|
+
if (pinned && pinView.el === field) return;
|
|
578
|
+
if (!root.hidden && floatView.el === field) return;
|
|
579
|
+
clearTimeout(hoverTimer);
|
|
580
|
+
hoverTimer = setTimeout(() => openFloat(field), HOVER_MS);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
doc.addEventListener('mouseout', (event) => {
|
|
584
|
+
const leaving = fieldOf(event.target) || (root.contains(event.target) ? root : null);
|
|
585
|
+
if (!leaving) return;
|
|
586
|
+
const to = event.relatedTarget;
|
|
587
|
+
if (to && (fieldOf(to) === leaving || root.contains(to))) return;
|
|
588
|
+
clearTimeout(hoverTimer);
|
|
589
|
+
clearTimeout(leaveTimer);
|
|
590
|
+
leaveTimer = setTimeout(() => {
|
|
591
|
+
if (root.hidden) return;
|
|
592
|
+
const active = doc.activeElement;
|
|
593
|
+
if (root.contains(active) || active === floatView.el) return;
|
|
594
|
+
if (floatView.form && floatView.form.edited) return;
|
|
595
|
+
closeFloat();
|
|
596
|
+
}, LEAVE_MS);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
doc.addEventListener('focusin', (event) => {
|
|
600
|
+
if (quiet) return;
|
|
601
|
+
if (pinHost.contains(event.target) && event.target.getAttribute && event.target.getAttribute('data-sym')) {
|
|
602
|
+
pinView.focusSym = event.target.getAttribute('data-sym');
|
|
603
|
+
pinView.activeAt = Date.now();
|
|
604
|
+
}
|
|
605
|
+
const field = fieldOf(event.target);
|
|
606
|
+
if (!field || !field.matches('input')) { if (!inCard(event.target) && !root.hidden && !(floatView.form && floatView.form.edited)) { /* focus left for elsewhere: the focusout timer decides */ } return; }
|
|
607
|
+
clearTimeout(leaveTimer);
|
|
608
|
+
clearTimeout(hoverTimer);
|
|
609
|
+
if (pinned && pinView.el === field) { paint(pinView); return; }
|
|
610
|
+
openFloat(field);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
doc.addEventListener('focusout', (event) => {
|
|
614
|
+
const field = fieldOf(event.target);
|
|
615
|
+
const view = viewOf(event.target);
|
|
616
|
+
if (view) {
|
|
617
|
+
const sym = event.target.getAttribute && event.target.getAttribute('data-sym');
|
|
618
|
+
if (sym && view.mode === 'pin') { view.focusSym = sym; lastCaret = event.target.selectionStart; }
|
|
619
|
+
}
|
|
620
|
+
if (!field && !view) return;
|
|
621
|
+
setTimeout(() => {
|
|
622
|
+
const active = doc.activeElement;
|
|
623
|
+
if (inCard(active) || (floatView.el && active === floatView.el)) return;
|
|
624
|
+
if (pinHost.contains(doc.activeElement)) return;
|
|
625
|
+
if (floatView.form && floatView.form.edited && !floatView.el?.isConnected) return;
|
|
626
|
+
if (!root.hidden && (floatView.form ? !floatView.form.edited : true)) {
|
|
627
|
+
// The pointer may still be over the card (clicking its drawing, say): keep it.
|
|
628
|
+
if (root.matches(':hover')) return;
|
|
629
|
+
closeFloat();
|
|
630
|
+
}
|
|
631
|
+
}, 160);
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
doc.addEventListener('input', (event) => {
|
|
635
|
+
const target = event.target;
|
|
636
|
+
const sizeInput = target && target.matches && target.matches('input[data-sym]') ? target : null;
|
|
637
|
+
if (sizeInput) {
|
|
638
|
+
if (pinHost.contains(sizeInput)) { pinView.activeAt = Date.now(); lastCaret = sizeInput.selectionStart; }
|
|
639
|
+
const view = viewOf(sizeInput);
|
|
640
|
+
if (view && view.state && view.state.kind === 'parametric') onSizeInput(view, sizeInput);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const field = fieldOf(target);
|
|
644
|
+
if (!field || !field.matches('input')) return;
|
|
645
|
+
// Typing in the field itself ends a size session: the field is the person's again.
|
|
646
|
+
for (const view of [floatView, pinView]) {
|
|
647
|
+
if (view.el === field || (view === floatView && !root.hidden)) {
|
|
648
|
+
if (event.isTrusted && view.form && view.form.edited) { endSession(view, true); view.form = null; }
|
|
649
|
+
view.dismissed = null;
|
|
650
|
+
view.pending = false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (pinned && pinView.el === field) paint(pinView); else if (root.hidden) openFloat(field); else paint(floatView);
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
const refreshCaret = (event) => {
|
|
657
|
+
const field = fieldOf(event.target);
|
|
658
|
+
if (!field || !field.matches('input')) return;
|
|
659
|
+
if (pinned && pinView.el === field) paint(pinView); else if (!root.hidden && floatView.el === field) paint(floatView);
|
|
660
|
+
};
|
|
661
|
+
doc.addEventListener('keyup', (event) => { if (!['Escape', 'Enter', 'Tab'].includes(event.key)) refreshCaret(event); });
|
|
662
|
+
doc.addEventListener('click', (event) => {
|
|
663
|
+
const info = event.target.closest && event.target.closest('[data-pcd-info]');
|
|
664
|
+
if (info) {
|
|
665
|
+
const field = info.parentElement.querySelector('input.combo[data-src=profiles]');
|
|
666
|
+
if (field) { if (pinned) { paint(pinView); } else if (!root.hidden && floatView.el === field) closeFloat(); else { openFloat(field); } }
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
const button = event.target.closest && event.target.closest('[data-pcd]');
|
|
670
|
+
if (button && inCard(button)) { const view = viewOf(button); if (view) onClick(view, button); return; }
|
|
671
|
+
refreshCaret(event);
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
// Pressing a card button must not pull focus out of the Profile field: that would commit the half-typed name as a side effect.
|
|
675
|
+
doc.addEventListener('mousedown', (event) => {
|
|
676
|
+
const button = event.target && event.target.closest && event.target.closest('button[data-pcd]');
|
|
677
|
+
if (button && inCard(button)) event.preventDefault();
|
|
678
|
+
}, true);
|
|
679
|
+
|
|
680
|
+
// A size field: Enter applies, Escape undoes (and a second Escape closes).
|
|
681
|
+
doc.addEventListener('keydown', (event) => {
|
|
682
|
+
const input = event.target && event.target.matches && event.target.matches('input[data-sym]') ? event.target : null;
|
|
683
|
+
if (!input) return;
|
|
684
|
+
const view = viewOf(input);
|
|
685
|
+
if (!view || !view.state || view.state.kind !== 'parametric') return;
|
|
686
|
+
if (event.key === 'Enter') { event.preventDefault(); event.stopPropagation(); if (view.info.readonly) return; commitForm(view); }
|
|
687
|
+
}, true);
|
|
688
|
+
|
|
689
|
+
// The keyboard's way into the card: Alt+Down from the Profile field moves to the first size (or button).
|
|
690
|
+
win.addEventListener('keydown', (event) => {
|
|
691
|
+
if (!(event.altKey && event.key === 'ArrowDown')) return;
|
|
692
|
+
const field = fieldOf(event.target);
|
|
693
|
+
if (!field || !field.matches('input')) return;
|
|
694
|
+
const view = pinned && pinView.el === field ? pinView : (!root.hidden && floatView.el === field ? floatView : null);
|
|
695
|
+
const target = view && (view.root.querySelector('input[data-sym]') || view.root.querySelector('button[data-pcd]:not([data-pcd=pin])'));
|
|
696
|
+
if (!target) return;
|
|
697
|
+
event.preventDefault(); event.stopImmediatePropagation();
|
|
698
|
+
target.focus();
|
|
699
|
+
}, true);
|
|
700
|
+
|
|
701
|
+
// Escape closes the card before anything else: before the suggestion list, before a dialog behind it.
|
|
702
|
+
win.addEventListener('keydown', (event) => {
|
|
703
|
+
if (event.key !== 'Escape') return;
|
|
704
|
+
const input = event.target && event.target.matches && event.target.matches('input[data-sym]') ? event.target : null;
|
|
705
|
+
const view = input ? viewOf(input) : null;
|
|
706
|
+
if (view && view.form && view.form.edited) {
|
|
707
|
+
event.preventDefault(); event.stopImmediatePropagation();
|
|
708
|
+
revertForm(view);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
if (!root.hidden) {
|
|
712
|
+
const involved = inCard(doc.activeElement) || (floatView.el && doc.activeElement === floatView.el);
|
|
713
|
+
// A card that is only open because the pointer is over a field is closed, but the Escape goes on to whatever it was for.
|
|
714
|
+
if (involved) { event.preventDefault(); event.stopImmediatePropagation(); }
|
|
715
|
+
const field = floatView.el;
|
|
716
|
+
const refocusField = inCard(doc.activeElement);
|
|
717
|
+
closeFloat();
|
|
718
|
+
// Giving the field its focus back is not a reason to open the card again.
|
|
719
|
+
if (refocusField && field && field.isConnected && field.focus) { quiet = true; try { field.focus({ preventScroll: true }); } finally { quiet = false; } }
|
|
720
|
+
}
|
|
721
|
+
}, true);
|
|
722
|
+
|
|
723
|
+
// A name that is not complete (a size still to type, an extra number) is held back from the member: the card says what is
|
|
724
|
+
// missing and offers "Use …" or "Keep as typed". The member keeps the last complete size (Nothing refuses, it asks).
|
|
725
|
+
doc.addEventListener('change', (event) => {
|
|
726
|
+
if (bypassChange) return;
|
|
727
|
+
const field = fieldOf(event.target);
|
|
728
|
+
if (!field || !field.matches('input') || field.id !== 'pf') return;
|
|
729
|
+
const info = host.describeField(field);
|
|
730
|
+
if (!info || info.kind !== 'member' || !info.member || !info.member.stored) return;
|
|
731
|
+
const { state } = stateFor({ el: field, info });
|
|
732
|
+
if (state.kind !== 'incomplete' && state.kind !== 'extra') return;
|
|
733
|
+
event.stopImmediatePropagation();
|
|
734
|
+
event.preventDefault();
|
|
735
|
+
const view = pinned && pinView.el === field ? pinView : floatView;
|
|
736
|
+
if (view === floatView) { floatView.el = field; floatView.elId = field.id; }
|
|
737
|
+
view.pending = true;
|
|
738
|
+
view.dismissed = null;
|
|
739
|
+
paint(view);
|
|
740
|
+
}, true);
|
|
741
|
+
|
|
742
|
+
const panelEl = host.panel();
|
|
743
|
+
if (panelEl && win.MutationObserver) {
|
|
744
|
+
let queued = false;
|
|
745
|
+
new win.MutationObserver((records) => {
|
|
746
|
+
// The pinned card lives inside the panel: painting it must not wake the observer again, or it would paint forever.
|
|
747
|
+
if (records.every((r) => pinHost.contains(r.target))) return;
|
|
748
|
+
if (queued) return;
|
|
749
|
+
queued = true;
|
|
750
|
+
Promise.resolve().then(() => {
|
|
751
|
+
queued = false;
|
|
752
|
+
syncPin();
|
|
753
|
+
if (selectionMoved()) closeFloat();
|
|
754
|
+
else if (!root.hidden && floatView.el && !floatView.el.isConnected) {
|
|
755
|
+
const again = floatView.elId ? doc.getElementById(floatView.elId) : null;
|
|
756
|
+
if (again) { floatView.el = again; place(floatView); } else closeFloat();
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}).observe(panelEl, { childList: true, subtree: true });
|
|
760
|
+
}
|
|
761
|
+
/** The floating card was made for the members selected when it opened: a different selection ends it (and puts back any preview). */
|
|
762
|
+
function selectionMoved() {
|
|
763
|
+
return !root.hidden && !!floatView.ids && floatView.ids !== host.selectionKey();
|
|
764
|
+
}
|
|
765
|
+
win.addEventListener('resize', () => { if (!root.hidden) place(floatView); });
|
|
766
|
+
syncPin();
|
|
767
|
+
|
|
768
|
+
return {
|
|
769
|
+
open: (el) => openFloat(el),
|
|
770
|
+
close: closeFloat,
|
|
771
|
+
isPinned: () => pinned,
|
|
772
|
+
syncSelection: () => { if (selectionMoved()) closeFloat(); },
|
|
773
|
+
setPinned,
|
|
774
|
+
root, pinHost,
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
export { definitionByPrefix, fieldsHtml, formNameText };
|