@wildwinter/app-shell 0.26.0 → 0.28.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/dist/index.d.cts CHANGED
@@ -568,7 +568,18 @@ interface TipRect {
568
568
  declare function tipAt(key: string, rect: TipRect, text: string): void;
569
569
  /** Take any tip down: the pointer has left, or a gesture has started. */
570
570
  declare function hideTip(): void;
571
- /** Wire the one delegated controller. Idempotent; later options are ignored. */
571
+ /**
572
+ * Wire the one delegated controller. Mounting happens once; OPTIONS do not.
573
+ *
574
+ * An explicit call is always authoritative about its options, even after something else has already
575
+ * mounted the listener. That ordering is not hypothetical, and Storyletter caught it before it shipped:
576
+ * once components self-mount (see `ensureTooltipHost`), a host's own
577
+ * `initTooltips({ suppressed })` could land second and be dropped by an early return, silently taking
578
+ * a rule like "no tooltips in Writing View" with it. Nothing would fail and nothing would show.
579
+ *
580
+ * Components therefore call this with NO arguments: they mount the renderer without claiming the
581
+ * options, and the host keeps the last word on behaviour.
582
+ */
572
583
  declare function initTooltips(opts?: TooltipOptions): void;
573
584
 
574
585
  /**
package/dist/index.d.ts CHANGED
@@ -568,7 +568,18 @@ interface TipRect {
568
568
  declare function tipAt(key: string, rect: TipRect, text: string): void;
569
569
  /** Take any tip down: the pointer has left, or a gesture has started. */
570
570
  declare function hideTip(): void;
571
- /** Wire the one delegated controller. Idempotent; later options are ignored. */
571
+ /**
572
+ * Wire the one delegated controller. Mounting happens once; OPTIONS do not.
573
+ *
574
+ * An explicit call is always authoritative about its options, even after something else has already
575
+ * mounted the listener. That ordering is not hypothetical, and Storyletter caught it before it shipped:
576
+ * once components self-mount (see `ensureTooltipHost`), a host's own
577
+ * `initTooltips({ suppressed })` could land second and be dropped by an early return, silently taking
578
+ * a rule like "no tooltips in Writing View" with it. Nothing would fail and nothing would show.
579
+ *
580
+ * Components therefore call this with NO arguments: they mount the renderer without claiming the
581
+ * options, and the host keeps the last word on behaviour.
582
+ */
572
583
  declare function initTooltips(opts?: TooltipOptions): void;
573
584
 
574
585
  /**
package/dist/index.js CHANGED
@@ -1,6 +1,155 @@
1
1
  export { JOB_PROGRESS } from './chunk-MDGOIT3O.js';
2
2
  export { EDIT_MENU, PANE_MENU } from './chunk-YLINCOQD.js';
3
3
 
4
+ // src/tooltip.ts
5
+ var B_OPEN = "";
6
+ var B_CLOSE = "";
7
+ function tipBold(s) {
8
+ return `${B_OPEN}${s}${B_CLOSE}`;
9
+ }
10
+ function renderTip(host, text) {
11
+ host.textContent = "";
12
+ const re = /\u0002([^\u0003]*)\u0003/g;
13
+ let last = 0;
14
+ let m;
15
+ while ((m = re.exec(text)) !== null) {
16
+ if (m.index > last) host.append(text.slice(last, m.index));
17
+ const strong = document.createElement("strong");
18
+ strong.textContent = m[1] ?? "";
19
+ host.append(strong);
20
+ last = m.index + m[0].length;
21
+ }
22
+ if (last < text.length) host.append(text.slice(last));
23
+ }
24
+ var inited = false;
25
+ var checked = false;
26
+ var suppressed;
27
+ var SHOW_DELAY = 350;
28
+ var EDGE = 6;
29
+ var GAP = 7;
30
+ var tip = null;
31
+ var timer = 0;
32
+ var active = null;
33
+ var activeKey = null;
34
+ function ensureEl() {
35
+ if (tip) return tip;
36
+ const el2 = document.createElement("div");
37
+ el2.className = "tooltip";
38
+ el2.setAttribute("role", "tooltip");
39
+ el2.hidden = true;
40
+ document.body.appendChild(el2);
41
+ tip = el2;
42
+ return el2;
43
+ }
44
+ var rectOf = (anchor) => anchor instanceof HTMLElement ? anchor.getBoundingClientRect() : anchor;
45
+ function place(anchor) {
46
+ const t = ensureEl();
47
+ const r = rectOf(anchor);
48
+ const tr = t.getBoundingClientRect();
49
+ let top = r.top - tr.height - GAP;
50
+ if (top < EDGE) top = r.top + r.height + GAP;
51
+ let left = r.left + r.width / 2 - tr.width / 2;
52
+ left = Math.max(EDGE, Math.min(left, window.innerWidth - tr.width - EDGE));
53
+ t.style.left = `${Math.round(left)}px`;
54
+ t.style.top = `${Math.round(top)}px`;
55
+ }
56
+ function show(anchor) {
57
+ const text = anchor.dataset["tip"];
58
+ if (!text) return;
59
+ paint(anchor, text);
60
+ }
61
+ function paint(anchor, text) {
62
+ if (suppressed?.()) return;
63
+ const t = ensureEl();
64
+ const host = (anchor instanceof HTMLElement ? anchor.closest("dialog[open]") : null) ?? document.body;
65
+ if (t.parentElement !== host) host.appendChild(t);
66
+ active = anchor instanceof HTMLElement ? anchor : null;
67
+ renderTip(t, text);
68
+ t.hidden = false;
69
+ t.classList.remove("show");
70
+ void t.offsetWidth;
71
+ place(anchor);
72
+ t.classList.add("show");
73
+ }
74
+ function hide() {
75
+ if (timer) {
76
+ window.clearTimeout(timer);
77
+ timer = 0;
78
+ }
79
+ active = null;
80
+ activeKey = null;
81
+ if (tip) {
82
+ tip.hidden = true;
83
+ tip.classList.remove("show");
84
+ }
85
+ }
86
+ function schedule(anchor) {
87
+ if (anchor === active) return;
88
+ if (timer) window.clearTimeout(timer);
89
+ timer = window.setTimeout(() => show(anchor), SHOW_DELAY);
90
+ }
91
+ function tipAt(key, rect, text) {
92
+ if (key === activeKey) {
93
+ if (tip && !tip.hidden) {
94
+ renderTip(tip, text);
95
+ place(rect);
96
+ }
97
+ return;
98
+ }
99
+ hide();
100
+ activeKey = key;
101
+ timer = window.setTimeout(() => {
102
+ timer = 0;
103
+ paint(rect, text);
104
+ }, SHOW_DELAY);
105
+ }
106
+ function hideTip() {
107
+ hide();
108
+ }
109
+ function ensureTooltipHost() {
110
+ initTooltips();
111
+ }
112
+ function checkTooltipHost() {
113
+ if (checked) return;
114
+ checked = true;
115
+ setTimeout(() => {
116
+ if (inited || typeof document === "undefined") return;
117
+ if (document.querySelector("[data-tip]")) {
118
+ console.warn("app-shell: something set `data-tip` but no tooltip host is mounted, so those rollovers will not draw. Call initTooltips() once per window.");
119
+ }
120
+ }, 0);
121
+ }
122
+ var tipAncestor = (n) => n instanceof Element ? n.closest("[data-tip]") : null;
123
+ function initTooltips(opts = {}) {
124
+ if (opts.suppressed !== void 0) suppressed = opts.suppressed;
125
+ if (inited) return;
126
+ inited = true;
127
+ document.addEventListener("pointerover", (e) => {
128
+ const el2 = tipAncestor(e.target);
129
+ if (el2) schedule(el2);
130
+ });
131
+ document.addEventListener("pointerout", (e) => {
132
+ const el2 = tipAncestor(e.target);
133
+ if (!el2) return;
134
+ const to = e.relatedTarget;
135
+ if (to instanceof Node && el2.contains(to)) return;
136
+ hide();
137
+ });
138
+ document.addEventListener("focusin", (e) => {
139
+ const el2 = tipAncestor(e.target);
140
+ if (el2) schedule(el2);
141
+ });
142
+ document.addEventListener("focusout", () => hide());
143
+ document.addEventListener("pointerdown", () => hide(), true);
144
+ document.addEventListener("scroll", () => {
145
+ if (active) hide();
146
+ }, true);
147
+ document.addEventListener("keydown", (e) => {
148
+ if (e.key === "Escape") hide();
149
+ });
150
+ window.addEventListener("blur", () => hide());
151
+ }
152
+
4
153
  // src/dom.ts
5
154
  function el(tag, classNameOrProps, ...children) {
6
155
  const node = document.createElement(tag);
@@ -11,12 +160,14 @@ function el(tag, classNameOrProps, ...children) {
11
160
  if (props.tip !== void 0) {
12
161
  node.dataset["tip"] = props.tip;
13
162
  node.setAttribute("aria-label", props.tip);
163
+ ensureTooltipHost();
14
164
  }
15
165
  if (props.onClick) node.addEventListener("click", props.onClick);
16
166
  for (const child of children) {
17
167
  if (child === null || child === void 0) continue;
18
168
  node.append(child);
19
169
  }
170
+ checkTooltipHost();
20
171
  return node;
21
172
  }
22
173
  function iconBtn(glyph, title, onClick, disabled = false, danger = false) {
@@ -473,7 +624,9 @@ function pinButton(opts) {
473
624
  const reflect = () => {
474
625
  b.classList.toggle("on", pinned);
475
626
  b.setAttribute("aria-pressed", String(pinned));
476
- b.title = pinned ? "Pinned on top: click to unpin" : "Click to keep on top";
627
+ const label2 = pinned ? "Pinned on top: click to unpin" : "Click to keep on top";
628
+ b.dataset["tip"] = label2;
629
+ b.setAttribute("aria-label", label2);
477
630
  };
478
631
  reflect();
479
632
  b.addEventListener("click", () => {
@@ -1181,141 +1334,6 @@ function mountJobProgress(host, opts) {
1181
1334
  return view;
1182
1335
  }
1183
1336
 
1184
- // src/tooltip.ts
1185
- var B_OPEN = "";
1186
- var B_CLOSE = "";
1187
- function tipBold(s) {
1188
- return `${B_OPEN}${s}${B_CLOSE}`;
1189
- }
1190
- function renderTip(host, text) {
1191
- host.textContent = "";
1192
- const re = /\u0002([^\u0003]*)\u0003/g;
1193
- let last = 0;
1194
- let m;
1195
- while ((m = re.exec(text)) !== null) {
1196
- if (m.index > last) host.append(text.slice(last, m.index));
1197
- const strong = document.createElement("strong");
1198
- strong.textContent = m[1] ?? "";
1199
- host.append(strong);
1200
- last = m.index + m[0].length;
1201
- }
1202
- if (last < text.length) host.append(text.slice(last));
1203
- }
1204
- var inited = false;
1205
- var suppressed;
1206
- var SHOW_DELAY = 350;
1207
- var EDGE = 6;
1208
- var GAP = 7;
1209
- var tip = null;
1210
- var timer = 0;
1211
- var active = null;
1212
- var activeKey = null;
1213
- function ensureEl() {
1214
- if (tip) return tip;
1215
- const el2 = document.createElement("div");
1216
- el2.className = "tooltip";
1217
- el2.setAttribute("role", "tooltip");
1218
- el2.hidden = true;
1219
- document.body.appendChild(el2);
1220
- tip = el2;
1221
- return el2;
1222
- }
1223
- var rectOf = (anchor) => anchor instanceof HTMLElement ? anchor.getBoundingClientRect() : anchor;
1224
- function place(anchor) {
1225
- const t = ensureEl();
1226
- const r = rectOf(anchor);
1227
- const tr = t.getBoundingClientRect();
1228
- let top = r.top - tr.height - GAP;
1229
- if (top < EDGE) top = r.top + r.height + GAP;
1230
- let left = r.left + r.width / 2 - tr.width / 2;
1231
- left = Math.max(EDGE, Math.min(left, window.innerWidth - tr.width - EDGE));
1232
- t.style.left = `${Math.round(left)}px`;
1233
- t.style.top = `${Math.round(top)}px`;
1234
- }
1235
- function show(anchor) {
1236
- const text = anchor.dataset["tip"];
1237
- if (!text) return;
1238
- paint(anchor, text);
1239
- }
1240
- function paint(anchor, text) {
1241
- if (suppressed?.()) return;
1242
- const t = ensureEl();
1243
- const host = (anchor instanceof HTMLElement ? anchor.closest("dialog[open]") : null) ?? document.body;
1244
- if (t.parentElement !== host) host.appendChild(t);
1245
- active = anchor instanceof HTMLElement ? anchor : null;
1246
- renderTip(t, text);
1247
- t.hidden = false;
1248
- t.classList.remove("show");
1249
- void t.offsetWidth;
1250
- place(anchor);
1251
- t.classList.add("show");
1252
- }
1253
- function hide() {
1254
- if (timer) {
1255
- window.clearTimeout(timer);
1256
- timer = 0;
1257
- }
1258
- active = null;
1259
- activeKey = null;
1260
- if (tip) {
1261
- tip.hidden = true;
1262
- tip.classList.remove("show");
1263
- }
1264
- }
1265
- function schedule(anchor) {
1266
- if (anchor === active) return;
1267
- if (timer) window.clearTimeout(timer);
1268
- timer = window.setTimeout(() => show(anchor), SHOW_DELAY);
1269
- }
1270
- function tipAt(key, rect, text) {
1271
- if (key === activeKey) {
1272
- if (tip && !tip.hidden) {
1273
- renderTip(tip, text);
1274
- place(rect);
1275
- }
1276
- return;
1277
- }
1278
- hide();
1279
- activeKey = key;
1280
- timer = window.setTimeout(() => {
1281
- timer = 0;
1282
- paint(rect, text);
1283
- }, SHOW_DELAY);
1284
- }
1285
- function hideTip() {
1286
- hide();
1287
- }
1288
- var tipAncestor = (n) => n instanceof Element ? n.closest("[data-tip]") : null;
1289
- function initTooltips(opts = {}) {
1290
- if (inited) return;
1291
- inited = true;
1292
- suppressed = opts.suppressed;
1293
- document.addEventListener("pointerover", (e) => {
1294
- const el2 = tipAncestor(e.target);
1295
- if (el2) schedule(el2);
1296
- });
1297
- document.addEventListener("pointerout", (e) => {
1298
- const el2 = tipAncestor(e.target);
1299
- if (!el2) return;
1300
- const to = e.relatedTarget;
1301
- if (to instanceof Node && el2.contains(to)) return;
1302
- hide();
1303
- });
1304
- document.addEventListener("focusin", (e) => {
1305
- const el2 = tipAncestor(e.target);
1306
- if (el2) schedule(el2);
1307
- });
1308
- document.addEventListener("focusout", () => hide());
1309
- document.addEventListener("pointerdown", () => hide(), true);
1310
- document.addEventListener("scroll", () => {
1311
- if (active) hide();
1312
- }, true);
1313
- document.addEventListener("keydown", (e) => {
1314
- if (e.key === "Escape") hide();
1315
- });
1316
- window.addEventListener("blur", () => hide());
1317
- }
1318
-
1319
1337
  // src/save.ts
1320
1338
  function createSaveController(opts) {
1321
1339
  const delayMs = opts.delayMs ?? 700;