jekyll-dice-tray 0.5.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e3b5e6ffc89df4600f4c4a25d765e3bc5efcd96d3671817cfc19c0edf540e7f
4
- data.tar.gz: eeb98f0a9a72e5caac9dfa0608f402cfefb90c914c0ecacf2dc170d6484decd8
3
+ metadata.gz: d9bd0677666a51acbbbb3ca6bf5b67d1f5bb1ef638fa4ba2fc86a3ea5a0f4cc9
4
+ data.tar.gz: 8832cb5174a2d58f10f7aa8534a91b8865b296323d81a097e6d476422b2b1e31
5
5
  SHA512:
6
- metadata.gz: 76359d77b57187df74358db7c49116928b201ce19ffa3130e3af0584087cce008c220baacbea6185f2e5a39686c27b4c78c6010702a9d2576f258158a9df36b7
7
- data.tar.gz: 0b6e4439a8265f518ee925cb7f497fe5c3daa6c2dfd180d67ba8e7dcbefab68495f25bb50805b4d594d2cf777b3f32ed4a9172c5564c512de072db5d80db1ccd
6
+ metadata.gz: 558222307d26787647131df280b6e35055d644a9dfe2c97b9f2ce752e5ff179a56b21b96467dcea47633b4fb6a3128536931b2a0600a2b935dabdb5946867ba7
7
+ data.tar.gz: 5e69d92fe00836cef6d4aa013a3f4e320cbed50e4a082a7826f8085ef4ec68b6f9a4b4d96829e4348ff95aa7ce5706e03c336fd8dd81924366343b21dd73dd1b
data/README.md CHANGED
@@ -4,7 +4,7 @@ A Jekyll plugin gem that:
4
4
 
5
5
  - Adds an overlay dice tray that accepts dice rolling input
6
6
  - Recognizes dice expressions in rendered pages like `d4`, `1d6`, `1d20+1` and turns them into clickable links that roll in the tray
7
- - Clicking a lookup-table die (any `dN`) rolls and shows the matching entry — supports any number of side-by-side key/value column groups, ranges like `3–12`, and tables with or without headers. One die in the header searches the whole table; multiple dice each search their own column group
7
+ - Clicking a lookup-table die (any `dN`) rolls and shows the matching entry — supports any number of side-by-side key/value column groups, ranges like `3–12`, and tables with or without headers. Header dice always search the whole table (side-by-side column groups included)
8
8
  - Persists input history, result history, minimize status
9
9
 
10
10
  https://github.com/user-attachments/assets/6ef8d788-a1ee-49d4-ab26-f63899bb4a10
@@ -179,14 +179,6 @@
179
179
  return Array.prototype.slice.call(row.querySelectorAll("td, th"));
180
180
  }
181
181
 
182
- function cellColumnIndex(row, cell) {
183
- var cells = rowCells(row);
184
- for (var i = 0; i < cells.length; i++) {
185
- if (cells[i] === cell) return i;
186
- }
187
- return -1;
188
- }
189
-
190
182
  function rowLooksLikeHeader(row) {
191
183
  if (!row) return false;
192
184
  if (row.querySelector("th")) return true;
@@ -269,13 +261,11 @@
269
261
  return max;
270
262
  }
271
263
 
272
- function collectRowEntriesForGroups(row, groups, allowedKeyIndices) {
264
+ function collectRowEntriesForGroups(row, groups) {
273
265
  var cells = rowCells(row);
274
266
  var entries = [];
275
- var allowAll = !allowedKeyIndices || !allowedKeyIndices.length;
276
267
  for (var g = 0; g < groups.length; g++) {
277
268
  var group = groups[g];
278
- if (!allowAll && allowedKeyIndices.indexOf(group.keyIndex) === -1) continue;
279
269
  var keyCell = cells[group.keyIndex];
280
270
  if (!keyCell) continue;
281
271
  var key = parseKeyEntry(normalizeCellText(keyCell));
@@ -302,16 +292,17 @@
302
292
  if (!table || !groups || !groups.length) return false;
303
293
  var matches = 0;
304
294
  eachDataRow(table, headerRow, function (row) {
305
- matches += collectRowEntriesForGroups(row, groups, null).length;
295
+ matches += collectRowEntriesForGroups(row, groups).length;
306
296
  });
307
297
  return matches >= 2;
308
298
  }
309
299
 
310
- function findLookupMatch(table, headerRow, groups, rollTotal, allowedKeyIndices) {
300
+ // Header dice (one or many side-by-side) always search every key column in the table.
301
+ function findLookupMatch(table, headerRow, groups, rollTotal) {
311
302
  var exact = null;
312
303
  var range = null;
313
304
  eachDataRow(table, headerRow, function (row) {
314
- var entries = collectRowEntriesForGroups(row, groups, allowedKeyIndices);
305
+ var entries = collectRowEntriesForGroups(row, groups);
315
306
  for (var e = 0; e < entries.length; e++) {
316
307
  var entry = entries[e];
317
308
  if (entry.key.kind === "exact" && entry.key.value === rollTotal) {
@@ -329,45 +320,18 @@
329
320
  return exact || range;
330
321
  }
331
322
 
332
- function headerDiceCount(headerRow) {
333
- if (!headerRow) return 0;
334
- return headerRow.querySelectorAll('a[data-dice]').length;
335
- }
336
-
337
- function groupForColumn(groups, columnIndex) {
338
- for (var g = 0; g < groups.length; g++) {
339
- var group = groups[g];
340
- if (columnIndex === group.keyIndex) return group;
341
- if (group.valueIndices.indexOf(columnIndex) !== -1) return group;
342
- }
343
- return null;
344
- }
345
-
346
- // One die in the header (e.g. d100 over many pairs) => search every group.
347
- // Several dice (e.g. d10 | Weather | d10 | Terrain | d6 | Mood) => only the clicked group.
348
- function allowedKeyIndicesForClick(headerRow, clickCell, groups) {
349
- if (!headerRow || !clickCell || !groups.length) return null;
350
- if (headerDiceCount(headerRow) <= 1) return null;
351
- var col = cellColumnIndex(headerRow, clickCell);
352
- if (col < 0) return null;
353
- var group = groupForColumn(groups, col);
354
- return group ? [group.keyIndex] : null;
355
- }
356
-
357
323
  function getLookupTableContext(anchor, rollTotal) {
358
324
  if (!anchor || !anchor.closest || rollTotal == null) return null;
359
325
 
360
326
  var cell = null;
361
327
  var table = null;
362
328
  var headerRow = null;
363
- var allowedKeys = null;
364
329
  var sourceTable = anchor._jdtSourceTable;
365
330
 
366
331
  if (sourceTable && sourceTable.querySelector) {
367
332
  // Re-roll from a previous table result in the tray.
368
333
  table = sourceTable;
369
334
  headerRow = findTableHeaderRow(table);
370
- allowedKeys = anchor._jdtAllowedKeyIndices || null;
371
335
  } else {
372
336
  cell = anchor.closest("td, th");
373
337
  if (!cell) return null;
@@ -384,10 +348,7 @@
384
348
  var groups = buildColumnGroups(keyColumns, tableColumnCount(table, headerRow));
385
349
  if (!isLookupTable(table, headerRow, groups)) return null;
386
350
 
387
- if (allowedKeys == null && cell && headerRow) {
388
- allowedKeys = allowedKeyIndicesForClick(headerRow, cell, groups);
389
- }
390
- var matched = findLookupMatch(table, headerRow, groups, rollTotal, allowedKeys);
351
+ var matched = findLookupMatch(table, headerRow, groups, rollTotal);
391
352
  if (!matched) return null;
392
353
 
393
354
  var headerCells = headerRow ? rowCells(headerRow) : [];
@@ -420,9 +381,7 @@
420
381
  });
421
382
  }
422
383
 
423
- return columns.length
424
- ? { columns: columns, _sourceTable: table, _allowedKeyIndices: allowedKeys }
425
- : null;
384
+ return columns.length ? { columns: columns, _sourceTable: table } : null;
426
385
  }
427
386
 
428
387
  function serializableTableContext(tableContext) {
@@ -459,9 +418,6 @@
459
418
  if (tableContext._sourceTable && tableContext._sourceTable.querySelector) {
460
419
  reroll._jdtSourceTable = tableContext._sourceTable;
461
420
  }
462
- if (tableContext._allowedKeyIndices) {
463
- reroll._jdtAllowedKeyIndices = tableContext._allowedKeyIndices;
464
- }
465
421
  headerSpan.appendChild(reroll);
466
422
  } else if (col.header_html) {
467
423
  headerSpan.innerHTML = col.header_html;
@@ -1,6 +1,6 @@
1
1
  module Jekyll
2
2
  module DiceTray
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-dice-tray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - directsun