dsh-ustc-quota 1.1.57 → 1.1.59

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.
Files changed (3) hide show
  1. package/client.js +67 -11
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -11,7 +11,7 @@ window.__ModuleLoader__.load({
11
11
  const UPDATE_ENDPOINT = 'plugins/dsh-ustc-quota/update';
12
12
  const UPDATE_APPLY_ENDPOINT = 'plugins/dsh-ustc-quota/update/apply';
13
13
  const WINDOW_IDS = ['3h', '12h', '24h'];
14
- const CLIENT_VERSION = '1.1.57';
14
+ const CLIENT_VERSION = '1.1.59';
15
15
  const UPDATE_INTERVAL_MS = 24 * 60 * 60 * 1000;
16
16
  const CLIENT_VERSION_KEY = `${NS}:client-version`;
17
17
  const CLIENT_RELOAD_KEY = `${NS}:client-reload`;
@@ -1209,7 +1209,35 @@ window.__ModuleLoader__.load({
1209
1209
  const DOCK_TRANSCRIPT_FLOOR = 360;
1210
1210
 
1211
1211
 
1212
- function measureRightDock() {
1212
+ // First come, first served. A dock stamps the moment it becomes active on the
1213
+ // right and publishes that stamp, so peers can compare arrivals without sharing
1214
+ // any global state: an earlier stamp keeps the natural slot, a later one stacks
1215
+ // below. Timestamps survive module reloads and cross-plugin isolation, which a
1216
+ // shared counter does not.
1217
+ const ARRIVAL_ATTR = 'data-ustc-quota-dock-arrived-at';
1218
+ const PEER_ARRIVAL_ATTR = 'data-codex-advisor-dock-arrived-at';
1219
+ const ARRIVAL_TIE_MS = 4;
1220
+ function claimDockArrival() {
1221
+ try {
1222
+ return Date.now();
1223
+ } catch {
1224
+ return 0;
1225
+ }
1226
+ }
1227
+
1228
+ function neighbourDockVisible() {
1229
+ try {
1230
+ for (const node of document.querySelectorAll('[data-codex-advisor-dock="right"]')) {
1231
+ const rect = node.getBoundingClientRect();
1232
+ if (rect.width > 0 && rect.height > 0) return true;
1233
+ }
1234
+ } catch {
1235
+ return false;
1236
+ }
1237
+ return false;
1238
+ }
1239
+
1240
+ function measureRightDock(arrival, wasHereFirst) {
1213
1241
  const holder = document.querySelector('[data-slot="main.conversation"]');
1214
1242
  const column = holder ? (holder.firstElementChild || holder) : null;
1215
1243
  if (!column) return null;
@@ -1279,19 +1307,34 @@ window.__ModuleLoader__.load({
1279
1307
  let stackTop = contentTop;
1280
1308
  try {
1281
1309
  // Other plugins place their own right docks on the same anchor. Deferring to
1282
- // every neighbour that overlaps this band makes two docks chase each other
1283
- // downwards: each one steps below the other, forever. Break the symmetry —
1284
- // yield only to a neighbour that starts strictly above this slot, or that
1285
- // starts at the same top and sorts earlier by id. Exactly one dock then
1286
- // yields per pair, so the arrangement settles after a single step.
1310
+ // every overlapping neighbour makes two docks chase each other downwards, so
1311
+ // the rule is arrival order: yield to a neighbour only when it arrived first.
1312
+ // A neighbour that arrived later stacks below us instead. Neighbours that do
1313
+ // not publish an arrival number fall back to position: yield when it already
1314
+ // sits in this slot, and on an exact tie let the earlier id win so the very
1315
+ // first paint cannot deadlock.
1287
1316
  const MY_DOCK_ID = 'ustc-quota';
1288
1317
  for (const node of document.querySelectorAll('[data-codex-advisor-dock="right"]')) {
1289
1318
  const rect = node.getBoundingClientRect();
1290
1319
  if (rect.height <= 0 || rect.width <= 0) continue;
1291
1320
  const NEIGHBOUR_DOCK_ID = 'codex-advisor';
1292
- const startsAbove = rect.top < contentTop - 1;
1293
- const tiedAndEarlier = Math.abs(rect.top - contentTop) <= 1 && NEIGHBOUR_DOCK_ID < MY_DOCK_ID;
1294
- if (!startsAbove && !tiedAndEarlier) continue;
1321
+ const neighbourArrival = Number(node.getAttribute(PEER_ARRIVAL_ATTR)) || 0;
1322
+ let yieldToNeighbour;
1323
+ if (neighbourArrival > 0 && arrival > 0 && Math.abs(neighbourArrival - arrival) > ARRIVAL_TIE_MS) {
1324
+ // Both sides published a stamp: the earlier arrival keeps the slot.
1325
+ yieldToNeighbour = neighbourArrival < arrival;
1326
+ } else if (wasHereFirst && rect.top > contentTop) {
1327
+ // We were already on the right when the neighbour appeared and it sits
1328
+ // below us: never chase it. If instead it shares our slot (a neighbour
1329
+ // that has not adopted this contract yet) fall through to the position
1330
+ // rule, because two overlapping cards are worse than a wrong order.
1331
+ yieldToNeighbour = false;
1332
+ } else {
1333
+ const startsAbove = rect.top < contentTop - 1;
1334
+ const tiedAndEarlier = Math.abs(rect.top - contentTop) <= 1 && NEIGHBOUR_DOCK_ID < MY_DOCK_ID;
1335
+ yieldToNeighbour = startsAbove || tiedAndEarlier;
1336
+ }
1337
+ if (!yieldToNeighbour) continue;
1295
1338
  if (rect.bottom > stackTop && rect.top < columnRect.bottom) {
1296
1339
  stackTop = Math.max(stackTop, Math.round(rect.bottom) + DOCK_GAP);
1297
1340
  }
@@ -1316,6 +1359,18 @@ window.__ModuleLoader__.load({
1316
1359
  const [box, setBox] = React.useState(null);
1317
1360
  const activeRef = React.useRef(active);
1318
1361
  activeRef.current = active;
1362
+ const arrivalRef = React.useRef(0);
1363
+ const firstRef = React.useRef(false);
1364
+ React.useEffect(() => {
1365
+ if (active) {
1366
+ firstRef.current = !neighbourDockVisible();
1367
+ arrivalRef.current = claimDockArrival();
1368
+ setBox(measureRightDock(arrivalRef.current, firstRef.current));
1369
+ } else {
1370
+ arrivalRef.current = 0;
1371
+ firstRef.current = false;
1372
+ }
1373
+ }, [active]);
1319
1374
  React.useEffect(() => {
1320
1375
  let frame = 0;
1321
1376
  let observer = null;
@@ -1330,7 +1385,7 @@ window.__ModuleLoader__.load({
1330
1385
  observer = new ResizeObserver(schedule);
1331
1386
  observer.observe(column);
1332
1387
  }
1333
- setBox(measureRightDock());
1388
+ setBox(measureRightDock(arrivalRef.current, firstRef.current));
1334
1389
  };
1335
1390
  function schedule() {
1336
1391
  if (!frame) frame = window.requestAnimationFrame(measure);
@@ -1349,6 +1404,7 @@ window.__ModuleLoader__.load({
1349
1404
  const shown = active && box !== null;
1350
1405
  return h('div', {
1351
1406
  'data-ustc-quota-dock': 'right',
1407
+ [ARRIVAL_ATTR]: arrivalRef.current || undefined,
1352
1408
  style: {
1353
1409
  position: 'fixed',
1354
1410
  top: box ? box.top : 0,
package/index.js CHANGED
@@ -22,7 +22,7 @@ const ROUTE_PATH = '/plugins/dsh-ustc-quota/snapshot';
22
22
  const UPDATE_PATH = '/plugins/dsh-ustc-quota/update';
23
23
  const UPDATE_APPLY_PATH = '/plugins/dsh-ustc-quota/update/apply';
24
24
  const UPDATE_TOKEN_TTL_MS = 30 * 60 * 1000;
25
- const PLUGIN_VERSION = '1.1.57';
25
+ const PLUGIN_VERSION = '1.1.59';
26
26
  const KEY_INFO_PATH = 'key/info';
27
27
  const USER_INFO_PATH = 'user/info';
28
28
  const DISCOVERY_TTL_MS = 30000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ustc-quota",
3
- "version": "1.1.57",
3
+ "version": "1.1.59",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Live 3h/12h/24h USTC token quota card in the DSH sidebar (works with the USTC TokenWorks distribution).",