dsh-ustc-quota 1.1.57 → 1.1.58

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 +68 -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.58';
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,37 @@ window.__ModuleLoader__.load({
1209
1209
  const DOCK_TRANSCRIPT_FLOOR = 360;
1210
1210
 
1211
1211
 
1212
- function measureRightDock() {
1212
+ // First come, first served. Each plugin right dock claims an arrival number the
1213
+ // moment it becomes active on the right and publishes it as a data attribute, so
1214
+ // a neighbour can compare. The earlier arrival keeps the natural slot; the later
1215
+ // one stacks below it. Deliberately not id-ordered or height-ordered — whoever
1216
+ // got there first wins, which is the least surprising rule for the user.
1217
+ const ARRIVAL_KEY = '__dshRightDockArrival';
1218
+ function claimDockArrival() {
1219
+ try {
1220
+ const scope = typeof window === 'undefined' ? null : window;
1221
+ if (!scope) return 0;
1222
+ const next = (Number(scope[ARRIVAL_KEY]) || 0) + 1;
1223
+ scope[ARRIVAL_KEY] = next;
1224
+ return next;
1225
+ } catch {
1226
+ return 0;
1227
+ }
1228
+ }
1229
+
1230
+ function neighbourDockVisible() {
1231
+ try {
1232
+ for (const node of document.querySelectorAll('[data-codex-advisor-dock="right"]')) {
1233
+ const rect = node.getBoundingClientRect();
1234
+ if (rect.width > 0 && rect.height > 0) return true;
1235
+ }
1236
+ } catch {
1237
+ return false;
1238
+ }
1239
+ return false;
1240
+ }
1241
+
1242
+ function measureRightDock(arrival, wasHereFirst) {
1213
1243
  const holder = document.querySelector('[data-slot="main.conversation"]');
1214
1244
  const column = holder ? (holder.firstElementChild || holder) : null;
1215
1245
  if (!column) return null;
@@ -1279,19 +1309,33 @@ window.__ModuleLoader__.load({
1279
1309
  let stackTop = contentTop;
1280
1310
  try {
1281
1311
  // 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.
1312
+ // every overlapping neighbour makes two docks chase each other downwards, so
1313
+ // the rule is arrival order: yield to a neighbour only when it arrived first.
1314
+ // A neighbour that arrived later stacks below us instead. Neighbours that do
1315
+ // not publish an arrival number fall back to position: yield when it already
1316
+ // sits in this slot, and on an exact tie let the earlier id win so the very
1317
+ // first paint cannot deadlock.
1287
1318
  const MY_DOCK_ID = 'ustc-quota';
1288
1319
  for (const node of document.querySelectorAll('[data-codex-advisor-dock="right"]')) {
1289
1320
  const rect = node.getBoundingClientRect();
1290
1321
  if (rect.height <= 0 || rect.width <= 0) continue;
1291
1322
  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;
1323
+ const neighbourArrival = Number(node.getAttribute('data-codex-advisor-dock-order')) || 0;
1324
+ let yieldToNeighbour;
1325
+ if (neighbourArrival > 0 && arrival > 0) {
1326
+ yieldToNeighbour = neighbourArrival < arrival;
1327
+ } else if (wasHereFirst && rect.top > contentTop) {
1328
+ // We were already on the right when the neighbour appeared and it sits
1329
+ // below us: never chase it. If instead it shares our slot (a neighbour
1330
+ // that has not adopted this contract yet) fall through to the position
1331
+ // rule, because two overlapping cards are worse than a wrong order.
1332
+ yieldToNeighbour = false;
1333
+ } else {
1334
+ const startsAbove = rect.top < contentTop - 1;
1335
+ const tiedAndEarlier = Math.abs(rect.top - contentTop) <= 1 && NEIGHBOUR_DOCK_ID < MY_DOCK_ID;
1336
+ yieldToNeighbour = startsAbove || tiedAndEarlier;
1337
+ }
1338
+ if (!yieldToNeighbour) continue;
1295
1339
  if (rect.bottom > stackTop && rect.top < columnRect.bottom) {
1296
1340
  stackTop = Math.max(stackTop, Math.round(rect.bottom) + DOCK_GAP);
1297
1341
  }
@@ -1316,6 +1360,18 @@ window.__ModuleLoader__.load({
1316
1360
  const [box, setBox] = React.useState(null);
1317
1361
  const activeRef = React.useRef(active);
1318
1362
  activeRef.current = active;
1363
+ const arrivalRef = React.useRef(0);
1364
+ const firstRef = React.useRef(false);
1365
+ React.useEffect(() => {
1366
+ if (active) {
1367
+ firstRef.current = !neighbourDockVisible();
1368
+ arrivalRef.current = claimDockArrival();
1369
+ setBox(measureRightDock(arrivalRef.current, firstRef.current));
1370
+ } else {
1371
+ arrivalRef.current = 0;
1372
+ firstRef.current = false;
1373
+ }
1374
+ }, [active]);
1319
1375
  React.useEffect(() => {
1320
1376
  let frame = 0;
1321
1377
  let observer = null;
@@ -1330,7 +1386,7 @@ window.__ModuleLoader__.load({
1330
1386
  observer = new ResizeObserver(schedule);
1331
1387
  observer.observe(column);
1332
1388
  }
1333
- setBox(measureRightDock());
1389
+ setBox(measureRightDock(arrivalRef.current, firstRef.current));
1334
1390
  };
1335
1391
  function schedule() {
1336
1392
  if (!frame) frame = window.requestAnimationFrame(measure);
@@ -1349,6 +1405,7 @@ window.__ModuleLoader__.load({
1349
1405
  const shown = active && box !== null;
1350
1406
  return h('div', {
1351
1407
  'data-ustc-quota-dock': 'right',
1408
+ 'data-ustc-quota-dock-order': arrivalRef.current || undefined,
1352
1409
  style: {
1353
1410
  position: 'fixed',
1354
1411
  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.58';
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.58",
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).",