@gbti/ryker 0.2.4 → 0.3.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Ryker 0.2.4
2
+ * Ryker 0.3.0
3
3
  * A drop-in editing layer for authored HTML reports.
4
4
  *
5
5
  * Generated bundle. Do not edit. Sources, in load order:
@@ -7,27 +7,28 @@
7
7
  * config/config.js (157 lines)
8
8
  * security/scan.js (86 lines)
9
9
  * editor/sanitize.js (218 lines)
10
- * editor/blocks.js (596 lines)
10
+ * editor/fields.js (113 lines)
11
+ * editor/blocks.js (598 lines)
11
12
  * export/zip.js (193 lines)
12
- * export/html.js (217 lines)
13
- * export/markdown.js (297 lines)
13
+ * export/html.js (226 lines)
14
+ * export/markdown.js (338 lines)
14
15
  * export/target.js (66 lines)
15
16
  * export/packager.js (277 lines)
16
17
  * ui/theme.js (61 lines)
17
- * ui/styles.js (421 lines)
18
- * ui/shell.js (241 lines)
18
+ * ui/styles.js (486 lines)
19
+ * ui/shell.js (252 lines)
19
20
  * ui/icons.js (68 lines)
20
21
  * ui/tooltip.js (82 lines)
21
- * ui/dialog.js (138 lines)
22
- * ui/menu.js (104 lines)
22
+ * ui/dialog.js (176 lines)
23
+ * ui/menu.js (114 lines)
23
24
  * ui/about.js (80 lines)
24
25
  * export/dialog.js (213 lines)
25
- * editor/editable.js (596 lines)
26
- * editor/history.js (248 lines)
27
- * editor/formatbar.js (252 lines)
26
+ * editor/editable.js (600 lines)
27
+ * editor/history.js (296 lines)
28
+ * editor/formatbar.js (264 lines)
28
29
  * editor/links.js (173 lines)
29
- * editor/pick.js (228 lines)
30
- * editor/multi.js (172 lines)
30
+ * editor/pick.js (305 lines)
31
+ * editor/multi.js (176 lines)
31
32
  * editor/table.js (345 lines)
32
33
  * editor/outline.js (289 lines)
33
34
  * editor/move.js (436 lines)
@@ -35,14 +36,15 @@
35
36
  * ui/rail.js (530 lines)
36
37
  * instructions/steps.js (592 lines)
37
38
  * instructions/moves.js (158 lines)
38
- * instructions/instructions.js (517 lines)
39
- * instructions/merge.js (405 lines)
40
- * storage/fs.js (336 lines)
41
- * storage/logger.js (433 lines)
42
- * instructions/browser.js (296 lines)
39
+ * instructions/instructions.js (546 lines)
40
+ * instructions/merge.js (432 lines)
41
+ * comments/comments.js (369 lines)
42
+ * storage/fs.js (340 lines)
43
+ * storage/logger.js (439 lines)
44
+ * instructions/browser.js (299 lines)
43
45
  * ui/pane.js (292 lines)
44
- * storage/recover.js (335 lines)
45
- * bootstrap/boot.js (546 lines)
46
+ * storage/recover.js (348 lines)
47
+ * bootstrap/boot.js (578 lines)
46
48
  *
47
49
  * Classic script by design: module scripts do not load from file:// URLs,
48
50
  * and a report handed over as a ZIP is opened from disk.
@@ -50,7 +52,7 @@
50
52
  (function () {
51
53
  'use strict';
52
54
  if (window.Ryker && window.Ryker.VERSION) return;
53
- var Ryker = { VERSION: "0.2.4", BUILD: "Ryker", SURFACE: "drop-in" };
55
+ var Ryker = { VERSION: "0.3.0", BUILD: "Ryker", SURFACE: "drop-in" };
54
56
  window.Ryker = Ryker;
55
57
 
56
58
  /* ---- utils/dom.js ---------------------------------------------- */
@@ -573,6 +575,121 @@
573
575
  })();
574
576
 
575
577
 
578
+ /* ---- editor/fields.js ------------------------------------------ */
579
+ // Text boxes the page owns, which Ryker leaves to the page.
580
+ //
581
+ // Ryker arms its own editing hosts, one per prose block, and marks each with
582
+ // ryker-editing. A page can bring editors of its own: a post composer, a mail
583
+ // body, a chat box. Those are contenteditable hosts Ryker did not arm, or form
584
+ // fields, and the page's own script holds their state (React, Draft.js,
585
+ // ProseMirror). Measured on x.com/compose/post, 2026-11-10: the composer is a
586
+ // Draft.js host inside an aria-modal dialog, and Ryker's pick gesture, finding
587
+ // no block under the pointer, reached past the dialog to an icon in the
588
+ // timeline behind it and prevented the press, so the composer could never
589
+ // take a caret or a selection. Everything here exists so that a press, a pick
590
+ // or an armed block never lands inside one of these.
591
+ Ryker.fields = (function () {
592
+ 'use strict';
593
+
594
+ var TEXT_INPUT = /^(text|search|email|url|tel|password|number|)$/;
595
+
596
+ function elementOf(node) {
597
+ if (node && node.nodeType === 3) node = node.parentElement;
598
+ return node && node.nodeType === 1 ? node : null;
599
+ }
600
+
601
+ function ours(el) { return !!(Ryker.shell && Ryker.shell.owns(el)); }
602
+
603
+ // A form control a person types into. Buttons, checkboxes and the like are
604
+ // controls too, but a press on them selects nothing Ryker could take.
605
+ function isTextControl(node) {
606
+ var el = elementOf(node);
607
+ if (!el || ours(el)) return false;
608
+ if (el.tagName === 'TEXTAREA' || el.tagName === 'SELECT') return true;
609
+ return el.tagName === 'INPUT' && TEXT_INPUT.test(String(el.getAttribute('type') || '').toLowerCase());
610
+ }
611
+
612
+ function pageHost(el) {
613
+ if (!el.hasAttribute || !el.hasAttribute('contenteditable')) return false;
614
+ if (el.classList.contains('ryker-editing')) return false;
615
+ return String(el.getAttribute('contenteditable')).toLowerCase() !== 'false';
616
+ }
617
+
618
+ /** The outermost editing host the page made, containing node, or null.
619
+ * Outermost, because an editor may nest hosts (a mention chip, a table
620
+ * cell), and the editor is the thing that owns the text. */
621
+ function editorOf(node) {
622
+ var el = elementOf(node);
623
+ if (!el || ours(el)) return null;
624
+ var found = null;
625
+ for (var n = el; n && n.nodeType === 1; n = n.parentElement) {
626
+ if (pageHost(n)) found = n;
627
+ }
628
+ return found;
629
+ }
630
+
631
+ function inField(node) { return !!editorOf(node) || isTextControl(node); }
632
+
633
+ // A dialog the page opened over its own content. A press inside one is about
634
+ // that dialog, never about the document behind it.
635
+ var LAYER = '[aria-modal="true"], dialog, [role="dialog"], [role="alertdialog"]';
636
+ function inLayer(node) {
637
+ var el = elementOf(node);
638
+ return !!(el && !ours(el) && el.closest && el.closest(LAYER));
639
+ }
640
+
641
+ // An icon inside a link or a button is the control's face, not content, so
642
+ // Ryker never picks it as an object (x.com draws every control with one).
643
+ var CONTROL = 'a, button, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"]';
644
+ function inControl(node) {
645
+ var el = elementOf(node);
646
+ return !!(el && el.closest && el.closest(CONTROL));
647
+ }
648
+
649
+ var LINE = /^(block|flex|grid|list-item|table|flow-root)$/;
650
+
651
+ /** The paragraph of a page editor under node: the nearest block-level element
652
+ * inside the editor, or the editor itself when its text is not split into
653
+ * blocks (plain text with line breaks). Draft.js gives each line its own
654
+ * block element, ProseMirror and Lexical a <p>. */
655
+ function lineOf(editor, node) {
656
+ for (var el = elementOf(node); el && el !== editor && editor.contains(el); el = el.parentElement) {
657
+ var display = '';
658
+ try { display = getComputedStyle(el).display; } catch (e) {}
659
+ if (LINE.test(display) && String(el.textContent || '').trim()) return el;
660
+ }
661
+ return editor;
662
+ }
663
+
664
+ /** Ctrl+click inside a page editor: select the paragraph under the pointer
665
+ * as ordinary text, so the page's own editor holds the selection and keeps
666
+ * it in its own state. A second Ctrl+click in the same editor stretches
667
+ * the selection over both paragraphs and everything between, which is the
668
+ * most a single text selection can hold. Returns true when it selected. */
669
+ function selectLine(editor, node) {
670
+ var line = lineOf(editor, node);
671
+ if (!String(line.textContent || '').trim()) return false;
672
+ var next = document.createRange();
673
+ next.selectNodeContents(line);
674
+ var sel = window.getSelection();
675
+ var was = sel && sel.rangeCount ? sel.getRangeAt(0) : null;
676
+ if (was && !was.collapsed && editor.contains(was.commonAncestorContainer)) {
677
+ if (was.compareBoundaryPoints(Range.START_TO_START, next) < 0) next.setStart(was.startContainer, was.startOffset);
678
+ if (was.compareBoundaryPoints(Range.END_TO_END, next) > 0) next.setEnd(was.endContainer, was.endOffset);
679
+ }
680
+ try { editor.focus({ preventScroll: true }); } catch (e) {}
681
+ sel.removeAllRanges();
682
+ sel.addRange(next);
683
+ return true;
684
+ }
685
+
686
+ return {
687
+ editorOf: editorOf, isTextControl: isTextControl, inField: inField,
688
+ inLayer: inLayer, inControl: inControl, lineOf: lineOf, selectLine: selectLine
689
+ };
690
+ })();
691
+
692
+
576
693
  /* ---- editor/blocks.js ------------------------------------------ */
577
694
  // Which parts of the report are editable, and how a block is named.
578
695
  //
@@ -632,6 +749,8 @@
632
749
  // Navigation is not content. Editing the table of contents would desync it
633
750
  // from the headings it points at.
634
751
  if (node.closest('nav, footer')) return true;
752
+ // A text box the page owns keeps its own state (editor/fields.js).
753
+ if (Ryker.fields && Ryker.fields.editorOf(node)) return true;
635
754
  // A <header> is usually site chrome, but the document's own title block is
636
755
  // also a header, and that one IS content. The test is where it sits rather
637
756
  // than what it is called: a header inside <main> belongs to the document.
@@ -749,7 +868,7 @@
749
868
 
750
869
  function atomic(node) {
751
870
  return !!(node && node.matches && node.matches(ATOMIC_SELECTOR) &&
752
- root().contains(node) && !excluded(node));
871
+ root().contains(node) && !excluded(node) && !Ryker.fields.inControl(node));
753
872
  }
754
873
 
755
874
  function atomicNodes() {
@@ -1470,10 +1589,19 @@
1470
1589
  exportBody.removeAttribute('data-ryker-pushed');
1471
1590
  if (!exportBody.getAttribute('style')) exportBody.removeAttribute('style');
1472
1591
  }
1592
+ // The attribute holds the author's own style attribute, which is usually
1593
+ // absent and was therefore indistinguishable from deleting the top the
1594
+ // toolbar wrote. It is not the same thing when the author wrote one: a
1595
+ // sticky nav with an inline top:0px came back with no style attribute at
1596
+ // all, which is a byte difference and, where the stylesheet supplied no top
1597
+ // of its own, a nav that stopped sticking. Restored as the attribute rather
1598
+ // than through the CSSOM, because setting the property back re-serialises
1599
+ // it and `top:0px` returns as `top: 0px;`. Same undo as shell.releaseOffset,
1600
+ // from the same attribute, on purpose.
1473
1601
  Array.prototype.forEach.call(doc.querySelectorAll('[data-ryker-offset]'), function (n) {
1602
+ var authored = n.getAttribute('data-ryker-offset');
1474
1603
  n.removeAttribute('data-ryker-offset');
1475
- n.style.removeProperty('top');
1476
- if (!n.getAttribute('style')) n.removeAttribute('style');
1604
+ if (authored) n.setAttribute('style', authored); else n.removeAttribute('style');
1477
1605
  });
1478
1606
  // Same leak a third time, on the element the clone IS rather than one it
1479
1607
  // contains, so neither the body pass above nor the querySelectorAll below
@@ -1657,6 +1785,47 @@
1657
1785
  return out;
1658
1786
  }
1659
1787
 
1788
+ // The inverse of inlineOf, for one line of inline Markdown. It lived in
1789
+ // extension/workspace.js until Rewrite needed it in the bundle too (sow-011),
1790
+ // and it moved rather than being copied so the two cannot drift apart.
1791
+ //
1792
+ // The text is escaped before any tag is made, so whatever arrives, Markdown or
1793
+ // markup, can only ever produce the tags written below. allowUrl decides which
1794
+ // link targets become links; anything it refuses stays as literal text. The
1795
+ // default is the workspace's rule exactly: http, https, mailto and #fragments.
1796
+ var DEFAULT_URL = /^(?:https?:\/\/|mailto:|#)./;
1797
+
1798
+ function inlineHtml(value, allowUrl) {
1799
+ var allow = typeof allowUrl === 'function' ? allowUrl
1800
+ : function (url) { return DEFAULT_URL.test(url); };
1801
+ var code = [];
1802
+ // The three private-use characters below are this function's own
1803
+ // placeholders. Text that arrives already carrying them could stand one
1804
+ // in for a piece of a link target, pass the check as one string and come
1805
+ // out as another, so they are removed before anything else happens.
1806
+ value = String(value == null ? '' : value).replace(/[\uE000-\uE002]/g, '');
1807
+ var escaped = Ryker.dom.escapeHtml(value).replace(/`([^`]+)`/g, function (_, contents) {
1808
+ var token = '' + code.length + '';
1809
+ code.push('<code>' + contents + '</code>');
1810
+ return token;
1811
+ });
1812
+ escaped = escaped
1813
+ .replace(/(^|[^*])\*\*([^*\s](?:[^*]*[^*\s])?)\*\*(?!\*)/g,
1814
+ '$1<strong>$2</strong>')
1815
+ .replace(/(^|[^\w_])__([^_\s](?:[^_]*[^_\s])?)__(?![\w_])/g,
1816
+ '$1<strong>$2</strong>')
1817
+ .replace(/(^|[^*])\*([^*\s](?:[^*]*[^*\s])?)\*(?!\*)/g,
1818
+ '$1<em>$2</em>')
1819
+ .replace(/(^|[^\w_])_([^_\s](?:[^_]*[^_\s])?)_(?![\w_])/g,
1820
+ '$1<em>$2</em>')
1821
+ .replace(/\[([^\]]+)\]\(([^\s)]+)\)/g, function (whole, text, url) {
1822
+ return allow(url) ? '<a href="' + url + '">' + text + '</a>' : whole;
1823
+ });
1824
+ return escaped.replace(/(\d+)/g, function (_, index) {
1825
+ return code[Number(index)] || '';
1826
+ });
1827
+ }
1828
+
1660
1829
  function cellsOf(tr) {
1661
1830
  return Array.prototype.map.call(tr.children, function (cell) {
1662
1831
  return inlineOf(cell).replace(/\|/g, '\\|').trim();
@@ -1879,7 +2048,7 @@
1879
2048
 
1880
2049
  return {
1881
2050
  adopt: adopt, available: available, build: build,
1882
- blockOf: blockOf, inlineOf: inlineOf
2051
+ blockOf: blockOf, inlineOf: inlineOf, inlineHtml: inlineHtml
1883
2052
  };
1884
2053
  })();
1885
2054
 
@@ -2632,6 +2801,67 @@
2632
2801
  '.acts{display:flex;gap:5px;flex-wrap:wrap}',
2633
2802
 
2634
2803
  // ---- fields -----------------------------------------------------------
2804
+ // The quote inside the comment dialog. Indented behind a rule rather than
2805
+ // boxed, so it reads as the document speaking and the field below it reads
2806
+ // as the reader answering.
2807
+ '.modal blockquote.comment-quote{margin:0 0 10px;padding:6px 0 6px 12px;',
2808
+ 'border-left:2px solid var(--rk-brand-color);color:var(--rk-muted);font-style:italic;',
2809
+ 'max-height:120px;overflow:auto;white-space:pre-line}',
2810
+ // The Rewrite popup (sow-011, extension only). textarea.rk and input.rk set
2811
+ // display:block, which beats the UA's [hidden] rule, hence the first line.
2812
+ '.rewrite [hidden]{display:none!important}',
2813
+ '.rewrite-connect{max-width:560px;margin:0 auto;padding:var(--rk-s4) 0;text-align:center}',
2814
+ '.rewrite-connect .note{text-align:left}.rewrite-lead{font-size:14px;color:var(--rk-fg)}',
2815
+ '.rewrite-connect-logo svg{display:block;margin:0 auto var(--rk-s3)}',
2816
+ // A table so the list shrinks to its text and centres, yet stays a block:
2817
+ // as inline-block, the button below flowed up beside the last step.
2818
+ '.rewrite-steps{display:table;margin:0 auto var(--rk-s4);padding-left:20px;text-align:left;line-height:1.9;color:var(--rk-fg)}',
2819
+ '.rewrite-connect-action{display:flex;justify-content:center}',
2820
+ // OpenAI's approved format: the black logo and "Continue with ChatGPT".
2821
+ 'button.rk.siwc-button{padding:10px 18px;border-radius:999px;background:#fff;color:#000;',
2822
+ ' border-color:#c9ccd1;font-size:13.5px;font-weight:600;gap:9px}',
2823
+ 'button.rk.siwc-button svg{display:block}.rewrite-fine{margin-top:var(--rk-s4)!important;font-size:11.5px}',
2824
+ '.rewrite-connect-status{min-height:1.4em;margin:var(--rk-s3) 0 0!important}',
2825
+ 'a.rk-button-link{display:inline-block;margin-left:10px;padding:3px 10px;border-radius:var(--rk-r-md);',
2826
+ ' background:var(--rk-brand-color);color:#fff!important;text-decoration:none;font-weight:600}',
2827
+ '.rewrite-plan{margin-right:auto;align-self:center;font-size:11.5px}',
2828
+ '.rewrite-row{display:flex;gap:8px;align-items:center;margin:0 0 10px}.rewrite-row input.rk{flex:1;width:auto}',
2829
+ // What is rewritten comes first, then the prompt: two tabs, the selection
2830
+ // open, the article as it is sent behind the second.
2831
+ '.rewrite-tabs{display:flex;gap:2px;border-bottom:1px solid var(--rk-line);margin:0 0 10px}',
2832
+ 'button.rewrite-tab{background:none;border:0;border-bottom:2px solid transparent;margin:0 0 -1px;',
2833
+ ' padding:6px 12px;color:var(--rk-muted);font:inherit;font-size:12.5px;font-weight:600;cursor:pointer}',
2834
+ 'button.rewrite-tab[aria-selected="true"]{color:var(--rk-fg);border-bottom-color:var(--rk-brand-color)}',
2835
+ 'button.rewrite-tab:focus-visible,.rewrite-article:focus-visible{outline:2px solid var(--rk-accent);outline-offset:1px}',
2836
+ '.rewrite-selection,.rewrite-article{overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;',
2837
+ ' border:1px solid var(--rk-line);border-radius:var(--rk-r-md);background:var(--rk-bg2);color:var(--rk-fg);',
2838
+ ' padding:9px 11px;margin:0 0 12px}',
2839
+ // Square on the left, so the red rule runs straight (the owner, 2026-11-10).
2840
+ '.rewrite-selection{max-height:12em;border-left:3px solid var(--rk-brand-color);',
2841
+ ' border-radius:0 var(--rk-r-md) var(--rk-r-md) 0;font-size:13.5px;line-height:1.55}',
2842
+ '.rewrite-sel-block+.rewrite-sel-block{margin-top:.7em}.rewrite-sel-heading{font-weight:650;font-size:14.5px}',
2843
+ '.rewrite-article{position:relative;max-height:24em;font-family:var(--rk-mono);font-size:12px;line-height:1.6}',
2844
+ 'mark.rewrite-mark{background:rgba(229,56,59,.16);color:inherit;border-radius:3px}',
2845
+ '.rewrite-article-note{margin:0 0 6px!important;font-size:11.5px}',
2846
+ // The prompt, then model and count, all before anything is asked.
2847
+ 'textarea.rewrite-guidance{min-height:3.4em;margin:0 0 10px;font-size:13.5px}.rewrite-settings{gap:14px}',
2848
+ '.rewrite-settings button.rk{margin-left:auto}',
2849
+ '.rewrite-count-label{display:flex;gap:6px;align-items:center;white-space:nowrap;color:var(--rk-muted)}',
2850
+ 'select.rk{background:var(--rk-field);color:var(--rk-fg);border:1px solid var(--rk-line2);border-radius:var(--rk-r-md);padding:6px 8px;font:inherit}',
2851
+ '.rewrite-settings{flex-wrap:wrap}.rewrite-profile-note{margin:-2px 0 10px;font-size:11.5px}',
2852
+ '.rewrite-profiles{display:flex;gap:14px;min-height:20em}',
2853
+ '.rewrite-profiles-list{flex:0 0 190px;display:flex;flex-direction:column;gap:4px;padding-right:14px;border-right:1px solid var(--rk-line)}',
2854
+ '.rewrite-profiles-item{text-align:left;color:var(--rk-fg)}.rewrite-profiles-item[aria-pressed="true"]{background:var(--rk-bg2);border-color:var(--rk-line2);font-weight:600}',
2855
+ '.rewrite-profiles-new{text-align:left;border-style:dashed;margin-top:4px}',
2856
+ '.rewrite-profiles-form{flex:1;min-width:0;display:flex;flex-direction:column;gap:7px}',
2857
+ '.rewrite-profiles-heading{font-size:10.5px;font-weight:600;letter-spacing:.07em;text-transform:uppercase;color:var(--rk-muted)}',
2858
+ '.rewrite-rule-row{display:flex;gap:6px;align-items:center}.rewrite-rule-row input.rk{flex:1;width:auto;padding:6px 9px}',
2859
+ '.rewrite-profiles-hint{margin:2px 0 0;font-size:11.5px}.rewrite-profile-delete{align-self:flex-start;margin-top:auto}',
2860
+ '.rewrite-profile-stays{margin-top:auto}.rewrite-profile-fixed{font-size:13px;padding:0 0 4px}',
2861
+ '.rewrite-nav{display:flex;gap:8px;align-items:center;justify-content:center;margin:0 0 8px}',
2862
+ '.rewrite-nav button.rk{font-size:20px;line-height:1;padding:2px 14px;color:var(--rk-fg)}',
2863
+ '.rewrite-nav .of{min-width:9em;text-align:center;font-variant-numeric:tabular-nums;color:var(--rk-fg)}',
2864
+ 'textarea.rewrite-text{min-height:16em;font-size:14px;line-height:1.6}.rewrite-hint{margin:6px 0 0;font-size:11.5px}',
2635
2865
  'textarea.rk,input.rk{display:block;width:100%;background:var(--rk-field);color:var(--rk-fg);',
2636
2866
  ' border:1px solid var(--rk-line2);border-radius:var(--rk-r-md);padding:9px 11px;',
2637
2867
  ' font:inherit;font-size:12.5px;line-height:1.55;resize:vertical;',
@@ -2650,6 +2880,10 @@
2650
2880
  ' padding:var(--rk-s5) var(--rk-s5) var(--rk-s5) var(--rk-s4);overflow-y:auto}',
2651
2881
  '.modal{background:var(--rk-bg);border:1px solid var(--rk-line);border-radius:var(--rk-r-xl);',
2652
2882
  ' width:100%;max-width:460px;box-shadow:var(--rk-sh-xl);overflow:hidden}',
2883
+ // Large and centred, for a dialog that is the workspace rather than a note
2884
+ // beside the text (dialog.js, opts.size).
2885
+ '.backdrop.center{justify-content:center;padding-left:var(--rk-s5)}.modal.large{max-width:880px}',
2886
+ '.modal.large .body{max-height:76vh}',
2653
2887
  '.modal header{padding:var(--rk-s4) var(--rk-s5);border-bottom:1px solid var(--rk-line);',
2654
2888
  ' background:var(--rk-bg2)}',
2655
2889
  '.modal header h2{margin:0;font-size:13.5px;font-weight:650;letter-spacing:.005em;color:var(--rk-fg)}',
@@ -2731,6 +2965,13 @@
2731
2965
  var shifted = [];
2732
2966
  var bodyPadding = {};
2733
2967
  var owner = Ryker.dom.uid('owner');
2968
+ // A real extension install seals its root: the page underneath can then
2969
+ // neither read Ryker's interface nor press its buttons, which matters once
2970
+ // those buttons can spend a ChatGPT plan and change the person's writing
2971
+ // profiles. The worker asks for it before start(). The drop-in runs as the
2972
+ // page's own script, where there is no such line to hold, and stays open.
2973
+ var sealed = false;
2974
+ function seal() { sealed = true; }
2734
2975
 
2735
2976
  function owns(node) {
2736
2977
  if (!host || !node) return false;
@@ -2777,7 +3018,7 @@
2777
3018
  host.setAttribute('data-ryker-lock', '');
2778
3019
  document.body.appendChild(host);
2779
3020
 
2780
- shadow = host.attachShadow({ mode: 'open' });
3021
+ shadow = host.attachShadow({ mode: sealed ? 'closed' : 'open' });
2781
3022
  var style = document.createElement('style');
2782
3023
  style.textContent = Ryker.styles.shadowCss;
2783
3024
  shadow.appendChild(style);
@@ -2823,8 +3064,13 @@
2823
3064
  releaseOffset();
2824
3065
  document.documentElement.style.setProperty('--ryker-offset', px + 'px');
2825
3066
  if (!px) return;
3067
+ // The whole authored style attribute, not just the top value. Putting a
3068
+ // property back through the CSSOM re-serialises the declaration, so an
3069
+ // author's `style="top:0px"` came back as `style="top: 0px;"`. That is a
3070
+ // byte difference in an export whose one promise is byte-identity, and it
3071
+ // is invisible on screen, which is the worst way for a promise to break.
2826
3072
  stickyCandidates().forEach(function (n) {
2827
- n.setAttribute('data-ryker-offset', n.style.top || '');
3073
+ n.setAttribute('data-ryker-offset', n.getAttribute('style') || '');
2828
3074
  n.style.top = px + 'px';
2829
3075
  shifted.push(n);
2830
3076
  });
@@ -2842,9 +3088,8 @@
2842
3088
  function releaseOffset() {
2843
3089
  shifted.forEach(function (n) {
2844
3090
  var prev = n.getAttribute('data-ryker-offset');
2845
- if (prev) n.style.top = prev; else n.style.removeProperty('top');
2846
3091
  n.removeAttribute('data-ryker-offset');
2847
- if (!n.getAttribute('style')) n.removeAttribute('style');
3092
+ if (prev) n.setAttribute('style', prev); else n.removeAttribute('style');
2848
3093
  });
2849
3094
  shifted = [];
2850
3095
  restoreBodyPadding('padding-top');
@@ -2953,7 +3198,7 @@
2953
3198
  setPanelSpace: setPanelSpace, releasePanelSpace: releasePanelSpace,
2954
3199
  setEdgeSpace: setEdgeSpace, releaseEdgeSpace: releaseEdgeSpace,
2955
3200
  originalBodyPadding: originalBodyPadding,
2956
- owns: owns, owner: function () { return owner; },
3201
+ owns: owns, owner: function () { return owner; }, seal: seal,
2957
3202
  shadow: function () { return shadow; },
2958
3203
  host: function () { return host; }
2959
3204
  };
@@ -3122,10 +3367,41 @@
3122
3367
 
3123
3368
  var stack = [];
3124
3369
 
3370
+ // A page that opened a modal of its own (x.com's post composer) may pull
3371
+ // focus back into it the moment focus leaves, which is what a focus trap
3372
+ // is for, and Ryker's fields would then hand every keystroke to the page.
3373
+ // While a Ryker dialog is up, each top-level layer holding a visible page
3374
+ // modal is made inert, so a trap has nothing to pull focus back to; the
3375
+ // last dialog to close puts them back. Only those layers, and only ones
3376
+ // this made inert. A report with no modal of its own is never touched.
3377
+ var benched = [];
3378
+ var PAGE_MODAL = '[aria-modal="true"], dialog[open]';
3379
+ function shown(n) { return !!(n.getClientRects && n.getClientRects().length); }
3380
+ function bench() {
3381
+ Array.prototype.forEach.call(document.body ? document.body.children : [], function (layer) {
3382
+ if (layer.inert || Ryker.shell.owns(layer) || benched.indexOf(layer) !== -1) return;
3383
+ var modals = [layer].filter(function (n) { return n.matches(PAGE_MODAL); })
3384
+ .concat(Array.prototype.slice.call(layer.querySelectorAll(PAGE_MODAL)));
3385
+ if (!modals.some(shown)) return;
3386
+ layer.inert = true;
3387
+ benched.push(layer);
3388
+ });
3389
+ }
3390
+ function unbench() {
3391
+ benched.forEach(function (layer) { layer.inert = false; });
3392
+ benched = [];
3393
+ }
3394
+
3395
+ // opts.size 'large' centres a wide dialog instead of docking a narrow one at
3396
+ // the right. The right-hand dock is for writing about text that must stay in
3397
+ // view; a dialog that is itself the place the text is worked on (Rewrite,
3398
+ // sow-011) wants the room, and the owner asked for it large and centred.
3125
3399
  function open(opts) {
3126
3400
  var d = Ryker.dom;
3127
- var backdrop = d.el('div', { class: 'backdrop', role: 'dialog', 'aria-modal': 'true' });
3401
+ var large = opts.size === 'large';
3402
+ var backdrop = d.el('div', { class: 'backdrop' + (large ? ' center' : ''), role: 'dialog', 'aria-modal': 'true' });
3128
3403
  var body = d.el('div', { class: 'body' });
3404
+ var heading = d.el('h2', { text: opts.title || 'Ryker' });
3129
3405
 
3130
3406
  if (typeof opts.body === 'string') body.innerHTML = opts.body;
3131
3407
  else if (opts.body) body.appendChild(opts.body);
@@ -3135,6 +3411,7 @@
3135
3411
  close: function () { close(backdrop); },
3136
3412
  body: body,
3137
3413
  foot: foot,
3414
+ setTitle: function (text) { heading.textContent = text || 'Ryker'; },
3138
3415
  setBody: function (node) {
3139
3416
  body.innerHTML = '';
3140
3417
  if (typeof node === 'string') body.innerHTML = node;
@@ -3167,8 +3444,8 @@
3167
3444
  foot.appendChild(d.el('button', { class: 'rk', text: 'Close', onclick: api.close }));
3168
3445
  }
3169
3446
 
3170
- var modal = d.el('div', { class: 'modal' }, [
3171
- d.el('header', {}, [d.el('h2', { text: opts.title || 'Ryker' })]),
3447
+ var modal = d.el('div', { class: 'modal' + (large ? ' large' : '') }, [
3448
+ d.el('header', {}, [heading]),
3172
3449
  body,
3173
3450
  foot
3174
3451
  ]);
@@ -3179,8 +3456,12 @@
3179
3456
  });
3180
3457
 
3181
3458
  Ryker.shell.add(backdrop);
3182
- stack.push({ node: backdrop, api: api });
3459
+ // opts.onClose runs however the dialog goes: a button, Escape, the
3460
+ // backdrop. Rewrite needs it to stop a sign-in wait or a request that
3461
+ // would otherwise keep running against the person's plan.
3462
+ stack.push({ node: backdrop, api: api, onClose: opts.onClose });
3183
3463
 
3464
+ bench();
3184
3465
  var focusable = modal.querySelector('button.rk, input, textarea');
3185
3466
  if (focusable) focusable.focus();
3186
3467
 
@@ -3191,7 +3472,9 @@
3191
3472
  for (var i = stack.length - 1; i >= 0; i--) {
3192
3473
  if (!node || stack[i].node === node) {
3193
3474
  if (stack[i].node.parentNode) stack[i].node.parentNode.removeChild(stack[i].node);
3194
- stack.splice(i, 1);
3475
+ var gone = stack.splice(i, 1)[0];
3476
+ if (!stack.length) unbench();
3477
+ if (gone.onClose) { try { gone.onClose(); } catch (e) {} }
3195
3478
  if (!node) return;
3196
3479
  }
3197
3480
  }
@@ -3322,17 +3605,26 @@
3322
3605
  if (anchor && anchor.nodeType === 1) anchor.setAttribute('aria-expanded', 'true');
3323
3606
  setTimeout(function () {
3324
3607
  document.addEventListener('mousedown', onAway, true);
3608
+ inside('addEventListener');
3325
3609
  document.addEventListener('keydown', onKey, true);
3326
3610
  }, 0);
3327
3611
  var first = list.querySelector('.menu-item');
3328
3612
  if (first) first.focus();
3329
3613
  }
3330
3614
 
3615
+ // The same listener on Ryker's own root. From the document a sealed root
3616
+ // shows only its host, so a press inside Ryker is judged from in here.
3617
+ function inside(method) {
3618
+ var root = Ryker.shell && Ryker.shell.shadow && Ryker.shell.shadow();
3619
+ if (root) root[method]('mousedown', onAway, true);
3620
+ }
3621
+
3331
3622
  function onAway(e) {
3332
3623
  if (!open) return;
3333
3624
  // The menu lives in a shadow root, so a click inside it reports the host as
3334
3625
  // its target in the light DOM. composedPath is the only reliable test.
3335
3626
  var path = e.composedPath ? e.composedPath() : [];
3627
+ if (e.currentTarget === document && path[0] === Ryker.shell.host()) return;
3336
3628
  if (path.indexOf(open.node) !== -1 || path.indexOf(open.anchor) !== -1) return;
3337
3629
  close();
3338
3630
  }
@@ -3349,6 +3641,7 @@
3349
3641
  }
3350
3642
  open = null;
3351
3643
  document.removeEventListener('mousedown', onAway, true);
3644
+ inside('removeEventListener');
3352
3645
  document.removeEventListener('keydown', onKey, true);
3353
3646
  }
3354
3647
 
@@ -3709,7 +4002,11 @@
3709
4002
  var clean = Ryker.sanitize.fromClipboard(e);
3710
4003
  if (clean == null) return;
3711
4004
  e.preventDefault();
4005
+ // A cancelled paste fires no beforeinput, and insertHtml moves nodes
4006
+ // with Range, which fires nothing either, so the stack has to be told.
4007
+ Ryker.history.textBefore(n);
3712
4008
  insertHtml(clean);
4009
+ Ryker.history.flush();
3713
4010
  mark(n, id);
3714
4011
  },
3715
4012
  drop: function (e) {
@@ -3748,7 +4045,9 @@
3748
4045
  // an edit.
3749
4046
  if (n.tagName === 'TD' || n.tagName === 'TH') {
3750
4047
  e.preventDefault();
4048
+ Ryker.history.textBefore(n);
3751
4049
  try { document.execCommand('insertLineBreak'); } catch (err) {}
4050
+ Ryker.history.flush();
3752
4051
  return;
3753
4052
  }
3754
4053
  e.preventDefault();
@@ -4112,10 +4411,14 @@
4112
4411
  var block = node.closest ? node.closest('[contenteditable="true"]') : null;
4113
4412
  if (!block) return false;
4114
4413
 
4414
+ // execCommand fires input but never beforeinput, so without this the stack
4415
+ // measured a bold against a document that already held it, and saw no change.
4416
+ Ryker.history.textBefore(block);
4115
4417
  try { document.execCommand('styleWithCSS', false, false); } catch (e) {}
4116
4418
  try { document.execCommand(cmd, false, value); } catch (e) { return false; }
4117
4419
 
4118
4420
  Ryker.sanitize.element(block);
4421
+ Ryker.history.flush();
4119
4422
  mark(block, Ryker.blocks.blockId(block));
4120
4423
  return true;
4121
4424
  }
@@ -4127,12 +4430,6 @@
4127
4430
  return Ryker.links.open();
4128
4431
  }
4129
4432
 
4130
- function restore(range) {
4131
- var sel = window.getSelection();
4132
- sel.removeAllRanges();
4133
- sel.addRange(range);
4134
- }
4135
-
4136
4433
  function insertHtml(html) {
4137
4434
  var sel = window.getSelection();
4138
4435
  if (!sel || !sel.rangeCount) return;
@@ -4248,7 +4545,7 @@
4248
4545
  enable: enable, disable: disable, isOn: isOn, changes: changes, isDirty: isDirty,
4249
4546
  baselineOf: baselineOf,
4250
4547
  rebase: rebase, revertAll: revertAll, revertBlock: revertBlock,
4251
- setBaseline: setBaseline, onChange: onChange, rebind: rebind, touch: emit,
4548
+ setBaseline: setBaseline, onChange: onChange, rebind: rebind, touch: emit, mark: mark,
4252
4549
  format: format, makeLink: makeLink, splitAt: splitAt,
4253
4550
  convert: convert, blockTypeOf: blockTypeOf, BLOCK_TYPES: BLOCK_TYPES
4254
4551
  };
@@ -4303,10 +4600,28 @@
4303
4600
  // Typing is collected into one entry per block per pause, so undo steps back
4304
4601
  // by a phrase rather than by a character. Finer granularity is not worth
4305
4602
  // eighty entries for one sentence.
4306
- function text(node) {
4307
- if (applying) return;
4603
+ //
4604
+ // The baseline is read here, from beforeinput, while the block still holds
4605
+ // the content the edit is about to replace. That is the only moment it is
4606
+ // truthful. It used to be read in the input handler instead, which fires
4607
+ // after the browser has already applied the character, and the feature came
4608
+ // apart on the off-by-one: a one-keystroke edit produced before === after and
4609
+ // was dropped entirely, so Ctrl+Z did nothing, and a longer burst undid to a
4610
+ // state that still held its first character. Formatting fared worst, because
4611
+ // a bold toggle is a single input event and so was never undoable at all.
4612
+ function textBefore(node) {
4613
+ if (applying || !node) return;
4308
4614
  if (pending && pending.node !== node) flushText();
4309
4615
  if (!pending) pending = { node: node, before: node.innerHTML };
4616
+ }
4617
+
4618
+ // Called from input, once the edit has landed. Only the idle timer moves; the
4619
+ // baseline is whatever beforeinput already captured. The delegation covers an
4620
+ // input with no beforeinput ahead of it, which yields a late baseline rather
4621
+ // than none, and a late one is still better than dropping the entry.
4622
+ function text(node) {
4623
+ if (applying) return;
4624
+ textBefore(node);
4310
4625
  clearTimeout(timer);
4311
4626
  timer = setTimeout(flushText, DEBOUNCE);
4312
4627
  }
@@ -4320,6 +4635,7 @@
4320
4635
  if (before === after) return;
4321
4636
  push({
4322
4637
  label: 'edit',
4638
+ node: node,
4323
4639
  undo: function () { node.innerHTML = before; place(node); },
4324
4640
  redo: function () { node.innerHTML = after; place(node); }
4325
4641
  });
@@ -4343,6 +4659,21 @@
4343
4659
  catch (e) { if (Ryker.log) Ryker.log('history ' + dir + ': ' + e.message); }
4344
4660
  applying = false;
4345
4661
  emit();
4662
+ // The editor's own change signal, which the toolbar, the outline and the
4663
+ // recovery draft listen to. Every other structural edit already sends it
4664
+ // (links, multi, table, move); undo and redo did not, so Save could stay
4665
+ // disabled over a redone edit until something unrelated resynced the bar,
4666
+ // and a block's edited mark outlived the undo that cleared it. Found by the
4667
+ // sow-011 suite: accept a rewrite, Ctrl+Z, Ctrl+Shift+Z, and Save was dead.
4668
+ // entry.nodes is an edit that changed several blocks as one step (a
4669
+ // rewrite of picked paragraphs), so one undo puts them all back.
4670
+ try {
4671
+ var touched = entry.nodes || (entry.node ? [entry.node] : []);
4672
+ touched.forEach(function (n) {
4673
+ if (Ryker.editable.mark) Ryker.editable.mark(n, Ryker.blocks.blockId(n));
4674
+ });
4675
+ Ryker.editable.touch();
4676
+ } catch (e) { if (Ryker.log) Ryker.log('history ' + dir + ' sync: ' + e.message); }
4346
4677
  }
4347
4678
 
4348
4679
  function undo() {
@@ -4475,6 +4806,15 @@
4475
4806
  // sometimes defers is worse than one that always does, because nobody can
4476
4807
  // predict what a second press will do.
4477
4808
  function bind() {
4809
+ // One capture listener on the document rather than one per block: it sees
4810
+ // every armed block, including blocks armed after this ran, and it keeps
4811
+ // the reasoning above next to the code it explains.
4812
+ document.addEventListener('beforeinput', function (e) {
4813
+ var node = e.target;
4814
+ var block = node && node.closest ? node.closest('.ryker-editing') : null;
4815
+ if (block) textBefore(block);
4816
+ }, true);
4817
+
4478
4818
  document.addEventListener('keydown', function (e) {
4479
4819
  if (!(e.ctrlKey || e.metaKey) || e.altKey) return;
4480
4820
  var k = (e.key || '').toLowerCase();
@@ -4484,6 +4824,10 @@
4484
4824
  // Ryker takes over only inside one of the document blocks it armed; doing
4485
4825
  // otherwise makes Ctrl+Z in a link/save dialog mutate the page behind it.
4486
4826
  var path = e.composedPath ? e.composedPath() : [];
4827
+ // A sealed root shows the document only its host, so the field holding
4828
+ // the caret inside Ryker is asked for by name.
4829
+ var root = Ryker.shell && Ryker.shell.shadow && Ryker.shell.shadow();
4830
+ if (root && root.activeElement) path = [root.activeElement].concat(path);
4487
4831
  for (var i = 0; i < path.length; i++) {
4488
4832
  var n = path[i];
4489
4833
  if (!n || !n.tagName) continue;
@@ -4497,7 +4841,8 @@
4497
4841
  }
4498
4842
 
4499
4843
  return {
4500
- record: record, text: text, flush: flushText, undo: undo, redo: redo,
4844
+ record: record, text: text, textBefore: textBefore, flush: flushText,
4845
+ undo: undo, redo: redo,
4501
4846
  clear: clear, canUndo: canUndo, canRedo: canRedo, depth: depth,
4502
4847
  isApplying: isApplying, bind: bind, onChange: onChange,
4503
4848
  captureBaseline: captureBaseline, restoreBaseline: restoreBaseline
@@ -4674,9 +5019,18 @@
4674
5019
  return Ryker.multi.covered();
4675
5020
  }
4676
5021
 
5022
+ // A selection or caret in a text box the page owns (editor/fields.js). Its
5023
+ // formatting, links and rows are the page's: a Ryker edit there would change
5024
+ // the DOM behind the page's own editor state.
5025
+ function inPageField() {
5026
+ var sel = window.getSelection();
5027
+ return !!(sel && sel.rangeCount && Ryker.fields.inField(sel.getRangeAt(0).commonAncestorContainer));
5028
+ }
5029
+
4677
5030
  function update() {
4678
5031
  // Not mid-drag: the bar would flash under the moving pointer.
4679
5032
  if (Ryker.pick && Ryker.pick.isEngaged()) { hide(); return; }
5033
+ if (inPageField()) { hide(); return; }
4680
5034
  var many = spanning();
4681
5035
  var range = editableSelection();
4682
5036
  var link = (!range && !many.length && Ryker.links) ? Ryker.links.at(null) : null;
@@ -4699,7 +5053,9 @@
4699
5053
  var block = range ? currentBlock() : null;
4700
5054
  var table = Ryker.multi && block ? Ryker.multi.tableAt(block) : null;
4701
5055
  var atomic = many.length === 1 && Ryker.blocks.atomic(many[0]);
4702
- var wide = many.length > 1 || atomic;
5056
+ // Any pick, one block included: a Ctrl+clicked paragraph has no Range for
5057
+ // bold or italic to act on, so the formatting set would be dead buttons.
5058
+ var wide = many.length > 0;
4703
5059
 
4704
5060
  // Four modes. A picked run of blocks gets only Delete, a caret resting in
4705
5061
  // a link gets only the link control, a caret resting in a cell gets only
@@ -4717,7 +5073,8 @@
4717
5073
  if (show) {
4718
5074
  Ryker.tooltip.attach(killBtn,
4719
5075
  atomic ? 'Delete this whole SVG' :
4720
- (many.length > 1 ? 'Delete the ' + many.length + ' selected blocks' : 'Delete this whole table'));
5076
+ (many.length > 1 ? 'Delete the ' + many.length + ' selected blocks'
5077
+ : (many.length === 1 ? 'Delete the selected block' : 'Delete this whole table')));
4721
5078
  Ryker.tooltip.attach(gridBtn, 'Add or remove a row or column');
4722
5079
  }
4723
5080
 
@@ -4971,7 +5328,7 @@
4971
5328
  // of our own surfaces is in the way and there is no block under the pointer.
4972
5329
  function blockAt(x, y) {
4973
5330
  var el = document.elementFromPoint(x, y);
4974
- if (!el || inShell(el)) return null;
5331
+ if (!el || inShell(el) || Ryker.fields.inField(el)) return null;
4975
5332
  var b = el.closest ? el.closest(Ryker.blocks.PICK_SELECTOR) : null;
4976
5333
  if (!b || inShell(b)) return null;
4977
5334
  if (Ryker.blocks.excluded(b)) return null;
@@ -4983,9 +5340,22 @@
4983
5340
  // Dragging down the page margin resolves no element at all, and without this
4984
5341
  // the whole gesture picks nothing. The 200px clamp is load bearing: unbounded,
4985
5342
  // a pointer in the margin grabs a block from the far end of the document.
5343
+ //
5344
+ // Margin means the document's own margin. A pointer over a dialog the page
5345
+ // opened, a text box it owns, or anything outside the document root is over
5346
+ // something else, and the nearest block is behind it (x.com, 2026-11-10: a
5347
+ // press in the post composer picked an icon in the timeline underneath).
5348
+ function margin(el) {
5349
+ if (!el) return true;
5350
+ var root = Ryker.blocks.root();
5351
+ if (el === root || el.contains(root)) return true;
5352
+ return root.contains(el) && !Ryker.fields.inLayer(el) && !Ryker.fields.inField(el);
5353
+ }
5354
+
4986
5355
  function blockNear(x, y) {
4987
5356
  var hit = blockAt(x, y);
4988
5357
  if (hit) return hit;
5358
+ if (!margin(document.elementFromPoint(x, y))) return null;
4989
5359
  var rr = Ryker.blocks.root().getBoundingClientRect();
4990
5360
  if (x < rr.left - 40 || x > rr.right + 40) return null;
4991
5361
  var list = seq || Ryker.blocks.pickSequence();
@@ -5081,11 +5451,67 @@
5081
5451
  raf = window.requestAnimationFrame(step);
5082
5452
  }
5083
5453
 
5454
+ // Ctrl+click, or Cmd+click on macOS, selects the whole of a heading or a
5455
+ // paragraph (sow-011). Cmd there because Ctrl+click on a Mac is a right-click.
5456
+ // Read per press rather than once at load, so a test can stand in for a Mac.
5457
+ function mac() { return /Mac|iPhone|iPad|iPod/.test(navigator.platform || ''); }
5458
+ function wholeKeyLabel() { return mac() ? 'Cmd' : 'Ctrl'; }
5459
+ function wholeGesture(e) {
5460
+ if (e.altKey || e.shiftKey) return false;
5461
+ return mac() ? e.metaKey : e.ctrlKey;
5462
+ }
5463
+
5464
+ // A heading or a paragraph that can be picked whole: armed, not atomic, and
5465
+ // holding some text. Comment and Rewrite read the pick through the same test,
5466
+ // so the gesture and the controls agree about what counts.
5467
+ function prose(n) {
5468
+ return !!(n && n.isConnected && /^(P|H[1-6])$/.test(n.tagName) && n.isContentEditable &&
5469
+ !Ryker.blocks.atomic(n) && String(n.textContent || '').trim());
5470
+ }
5471
+
5472
+ // Ctrl+click toggles a block in and out of the pick, the bordered set a drag
5473
+ // or Shift+click makes, so one block and several look the same and a second
5474
+ // Ctrl+click adds rather than replaces (the owner, 2026-11-09; the first
5475
+ // build made an ordinary text selection, which a second click replaced).
5476
+ // Gaps are allowed. Headings and paragraphs only, per the owner; every other
5477
+ // block keeps today's behaviour.
5478
+ function toggleWhole(e) {
5479
+ var block = blockAt(e.clientX, e.clientY);
5480
+ if (!prose(block)) return false;
5481
+ e.preventDefault();
5482
+ dropNative();
5483
+ var at = picked.indexOf(block);
5484
+ if (at === -1) { paint(picked.concat([block])); origin = block; }
5485
+ else paint(picked.slice(0, at).concat(picked.slice(at + 1)));
5486
+ return true;
5487
+ }
5488
+
5489
+ // The click that follows the press. Swallowed so that Ctrl+click on a link
5490
+ // inside the block picks the block rather than opening the link.
5491
+ var swallowClick = false;
5492
+
5084
5493
  function down(e) {
5494
+ swallowClick = false;
5085
5495
  if (e.button !== 0) return;
5086
5496
  if (inShell(e.target)) return;
5087
5497
  if (!Ryker.editable.isOn()) return;
5088
5498
 
5499
+ if (wholeGesture(e) && toggleWhole(e)) { swallowClick = true; return; }
5500
+
5501
+ // A text box the page owns gets the press untouched, so it can take the
5502
+ // caret and its own selection. Ctrl+click there selects the paragraph as
5503
+ // ordinary text (editor/fields.js), the closest a page's editor can come
5504
+ // to a pick, and Rewrite reads it from the selection.
5505
+ var editor = Ryker.fields.editorOf(e.target);
5506
+ if (editor || Ryker.fields.isTextControl(e.target)) {
5507
+ clear();
5508
+ if (editor && wholeGesture(e) && Ryker.fields.selectLine(editor, e.target)) {
5509
+ e.preventDefault();
5510
+ swallowClick = true;
5511
+ }
5512
+ return;
5513
+ }
5514
+
5089
5515
  if (e.shiftKey && picked.length) {
5090
5516
  var hit = blockNear(e.clientX, e.clientY);
5091
5517
  if (hit) { e.preventDefault(); dropNative(); extend(hit); }
@@ -5095,7 +5521,9 @@
5095
5521
  clear();
5096
5522
  seq = Ryker.blocks.pickSequence();
5097
5523
  origin = blockNear(e.clientX, e.clientY);
5098
- if (Ryker.blocks.atomic(origin)) {
5524
+ // A chart is picked by pressing on it. Reached through the margin it
5525
+ // would take the press away from whatever is actually under the pointer.
5526
+ if (Ryker.blocks.atomic(origin) && origin === blockAt(e.clientX, e.clientY)) {
5099
5527
  e.preventDefault();
5100
5528
  dropNative();
5101
5529
  paint([origin]);
@@ -5141,6 +5569,12 @@
5141
5569
  document.addEventListener('mousedown', down, true);
5142
5570
  document.addEventListener('mousemove', move, true);
5143
5571
  document.addEventListener('mouseup', up, true);
5572
+ document.addEventListener('click', function (e) {
5573
+ if (!swallowClick) return;
5574
+ swallowClick = false;
5575
+ e.preventDefault();
5576
+ e.stopPropagation();
5577
+ }, true);
5144
5578
  window.addEventListener('pointercancel', up, true);
5145
5579
  document.addEventListener('keydown', function (e) {
5146
5580
  if (e.key === 'Escape' && picked.length) clear();
@@ -5159,7 +5593,7 @@
5159
5593
  rect: rect, set: set, extend: extend, clear: clear,
5160
5594
  isEngaged: function () { return engaged; },
5161
5595
  has: function (n) { return picked.indexOf(n) !== -1; },
5162
- onChange: onChange
5596
+ onChange: onChange, wholeKeyLabel: wholeKeyLabel, prose: prose
5163
5597
  };
5164
5598
  })();
5165
5599
 
@@ -5294,9 +5728,13 @@
5294
5728
  }
5295
5729
 
5296
5730
  // The selection route: what someone gets from dragging across blocks.
5731
+ // One picked block is enough since Ctrl+click picks a single paragraph or
5732
+ // heading with the same borders a drag gives several (sow-011). The pick is
5733
+ // still only ever filled by a gesture Ryker tracked, so the select-all hazard
5734
+ // recorded above stays closed.
5297
5735
  function removeSelection() {
5298
5736
  var nodes = covered();
5299
- if (nodes.length < 2 && !(nodes.length === 1 && Ryker.blocks.atomic(nodes[0]))) return false;
5737
+ if (!nodes.length) return false;
5300
5738
  return removeNodes(collapse(nodes));
5301
5739
  }
5302
5740
 
@@ -5321,9 +5759,9 @@
5321
5759
  for (var i = 0; i < path.length; i++) {
5322
5760
  if (path[i] && Ryker.shell && Ryker.shell.owns(path[i])) return;
5323
5761
  if (path[i] && path[i].tagName === 'TEXTAREA') return;
5762
+ if (path[i] && path[i].nodeType === 1 && Ryker.fields.inField(path[i])) return;
5324
5763
  }
5325
- var picked = Ryker.pick.picked();
5326
- if (picked.length < 2 && !(picked.length === 1 && Ryker.blocks.atomic(picked[0]))) return;
5764
+ if (!Ryker.pick.picked().length) return;
5327
5765
  e.preventDefault();
5328
5766
  e.stopPropagation();
5329
5767
  removeSelection();
@@ -8212,7 +8650,13 @@
8212
8650
  function onChange(fn) { listeners.push(fn); }
8213
8651
  function emit() { listeners.forEach(function (f) { try { f(); } catch (e) {} }); }
8214
8652
 
8215
- function reset() { saved = null; savedTree = null; saves = 0; saveNotes = []; emit(); }
8653
+ function reset() {
8654
+ saved = null; savedTree = null; saves = 0; saveNotes = [];
8655
+ // Comments go with them. Clear document that left notes quoting blocks the
8656
+ // document no longer contains would be worse than losing them.
8657
+ if (Ryker.comments) Ryker.comments.reset();
8658
+ emit();
8659
+ }
8216
8660
  function originalOf(id) { return pristineHtml(id); }
8217
8661
  function saveCount() { return saves; }
8218
8662
 
@@ -8409,14 +8853,21 @@
8409
8853
  // instruction set that repeats it reads as deliberate unless something says
8410
8854
  // so. Named rather than silently deduplicated, because only the author knows
8411
8855
  // which copy was meant.
8412
- function suspicious(list) {
8856
+ //
8857
+ // The numbers have to be the numbers the reader will see. build() writes the
8858
+ // moves first and the steps after them, so a step's heading is base + i + 1
8859
+ // where base is the move count. Counting from 1 here named a move as the
8860
+ // duplicate paste and never named the last insert at all, and the preamble
8861
+ // tells an agent to delete the steps it does not want by number.
8862
+ function suspicious(list, base) {
8413
8863
  var out = [];
8414
8864
  var byText = {};
8865
+ base = base || 0;
8415
8866
  list.forEach(function (e, i) {
8416
8867
  if (e.kind !== 'insert') return;
8417
8868
  var k = text(e.after);
8418
8869
  if (!k) return;
8419
- (byText[k] = byText[k] || []).push(i + 1);
8870
+ (byText[k] = byText[k] || []).push(base + i + 1);
8420
8871
  });
8421
8872
  Object.keys(byText).forEach(function (k) {
8422
8873
  var steps = byText[k];
@@ -8435,10 +8886,12 @@
8435
8886
  if (lost.length < 40) return;
8436
8887
  var echoes = [];
8437
8888
  list.forEach(function (o, j) {
8438
- if (o.kind === 'insert' && text(o.after).indexOf(lost.slice(0, 40)) !== -1) echoes.push(j + 1);
8889
+ if (o.kind === 'insert' && text(o.after).indexOf(lost.slice(0, 40)) !== -1) {
8890
+ echoes.push(base + j + 1);
8891
+ }
8439
8892
  });
8440
8893
  if (echoes.length > 1) {
8441
- out.push('Step ' + (i + 1) + ' removes a sentence that steps ' + echoes.join(', ') +
8894
+ out.push('Step ' + (base + i + 1) + ' removes a sentence that steps ' + echoes.join(', ') +
8442
8895
  ' then add back. Check the split was intended once, not ' + echoes.length + ' times.');
8443
8896
  }
8444
8897
  });
@@ -8469,6 +8922,7 @@
8469
8922
  { where: where, text: text });
8470
8923
  var mv = moves();
8471
8924
  var out = [];
8925
+ var notesCount = Ryker.comments ? Ryker.comments.count() : 0;
8472
8926
 
8473
8927
  out.push('# Document edit instructions');
8474
8928
  out.push('');
@@ -8484,6 +8938,7 @@
8484
8938
  }
8485
8939
  out.push('Edits: ' + list.length + ' change(s)' +
8486
8940
  (mv.length ? ' and ' + mv.length + ' move(s)' : '') +
8941
+ (notesCount ? ' and ' + notesCount + ' comment(s)' : '') +
8487
8942
  ' across ' + saves + ' save(s) this session');
8488
8943
  out.push('');
8489
8944
 
@@ -8502,13 +8957,24 @@
8502
8957
  });
8503
8958
  }
8504
8959
 
8960
+ var comments = Ryker.comments ? Ryker.comments.render() : [];
8961
+ if (comments.length) out.push.apply(out, comments);
8962
+
8505
8963
  if (!list.length && !mv.length) {
8506
- out.push('No edits have been made yet. Edit the document and press Save to');
8507
- out.push('build a set of instructions here.');
8964
+ // A document carrying comments and no edits used to be told nothing had
8965
+ // been done, directly underneath the comments it was showing.
8966
+ if (notesCount) {
8967
+ out.push('No edits have been made. The comments above are the whole of this');
8968
+ out.push('document: read them, and change nothing on their account unless the');
8969
+ out.push('comment asks you to.');
8970
+ } else {
8971
+ out.push('No edits have been made yet. Edit the document and press Save to');
8972
+ out.push('build a set of instructions here.');
8973
+ }
8508
8974
  return out.join('\n');
8509
8975
  }
8510
8976
 
8511
- var warnings = suspicious(list);
8977
+ var warnings = suspicious(list, mv.length);
8512
8978
  if (warnings.length) {
8513
8979
  out.push('## Check these before applying');
8514
8980
  out.push('');
@@ -8599,7 +9065,8 @@
8599
9065
  out.push('---');
8600
9066
  out.push('');
8601
9067
  out.push('End of instructions. ' + list.length + ' edit(s)' +
8602
- (mv.length ? ' and ' + mv.length + ' move(s)' : '') + '.');
9068
+ (mv.length ? ' and ' + mv.length + ' move(s)' : '') +
9069
+ (notesCount ? ' and ' + notesCount + ' comment(s)' : '') + '.');
8603
9070
  return out.join('\n');
8604
9071
  }
8605
9072
 
@@ -8609,7 +9076,7 @@
8609
9076
  sessionId: sessionId, editingSessionId: editingSessionId,
8610
9077
  recoveryChanges: recoveryChanges, recoveryMoves: recoveryMoves,
8611
9078
  saveCount: saveCount, saveNotes: notes,
8612
- onChange: onChange, where: where, suspicious: suspicious
9079
+ onChange: onChange, touch: emit, where: where, suspicious: suspicious
8613
9080
  };
8614
9081
  })();
8615
9082
 
@@ -8658,6 +9125,12 @@
8658
9125
  return [];
8659
9126
  }
8660
9127
 
9128
+ // A record written before comments existed has no field, which is the normal
9129
+ // case for the whole logged corpus and not an error.
9130
+ function commentsOf(rec) {
9131
+ return Array.isArray(rec && rec.comments) ? rec.comments : [];
9132
+ }
9133
+
8661
9134
  function norm(html) {
8662
9135
  if (html == null) return '';
8663
9136
  return String(html).replace(/\s+/g, ' ').trim();
@@ -8867,6 +9340,20 @@
8867
9340
  });
8868
9341
  });
8869
9342
 
9343
+ // Same rule as the notes: a later save from the same session supersedes an
9344
+ // earlier one, so only the winner is read. Deduped by id across groups
9345
+ // because a record carries every comment standing when it was written, and
9346
+ // two groups from one page load would otherwise repeat all of them.
9347
+ var comments = [];
9348
+ var seenComment = {};
9349
+ groups.forEach(function (g) {
9350
+ commentsOf(g.winner).forEach(function (c) {
9351
+ if (!c || !c.id || seenComment[c.id] || !String(c.body || '').trim()) return;
9352
+ seenComment[c.id] = true;
9353
+ comments.push(c);
9354
+ });
9355
+ });
9356
+
8870
9357
  var warnings = [];
8871
9358
  if (promptOnly) {
8872
9359
  warnings.push(promptOnly + ' record(s) carry only a prose prompt with no structured ' +
@@ -8929,6 +9416,7 @@
8929
9416
  cancelled: cancelled,
8930
9417
  promptOnly: promptOnly,
8931
9418
  notes: notes,
9419
+ comments: comments,
8932
9420
  accounted: accounted,
8933
9421
  refused: refused,
8934
9422
  warnings: warnings.concat(dupes),
@@ -8979,6 +9467,12 @@
8979
9467
  out.push('');
8980
9468
  });
8981
9469
  }
9470
+ // Comments recovered from the folded records, in the same words the live
9471
+ // pane uses, because an agent should not have to learn two ways of being
9472
+ // told that a section is not a set of steps.
9473
+ if (r.comments && r.comments.length && Ryker.comments) {
9474
+ out.push.apply(out, Ryker.comments.renderList(r.comments));
9475
+ }
8982
9476
  out.push('---');
8983
9477
  out.push('');
8984
9478
  r.steps.forEach(function (s, i) {
@@ -9021,6 +9515,377 @@
9021
9515
  })();
9022
9516
 
9023
9517
 
9518
+ /* ---- comments/comments.js -------------------------------------- */
9519
+ // Comments on highlighted material: notes about the document rather than
9520
+ // instructions to change it.
9521
+ //
9522
+ // Nothing here touches the page. A comment is data, and only data: the block it
9523
+ // was made in, the words that were highlighted, and what the reader said about
9524
+ // them. Marking the selection instead, by wrapping it in an element, was
9525
+ // measured and rejected. blocks.snapshot() records a block's innerHTML verbatim
9526
+ // and diffSnapshots reports any string difference as a content change, so a
9527
+ // wrapper would manufacture an edit step telling an agent to alter text that
9528
+ // nobody altered. That is precisely the outcome this feature exists to avoid,
9529
+ // and it would also have to be added by hand to three separate strip lists to
9530
+ // keep the export clean.
9531
+ //
9532
+ // Comments were specified in sections 13 to 15 of the Phase 1 specification and
9533
+ // planned as sow-004 Phase 4, on top of an append-only journal that sow-006
9534
+ // retired. This is the same feature rebuilt on what Ryker actually has.
9535
+ Ryker.comments = (function () {
9536
+ 'use strict';
9537
+
9538
+ var list = [];
9539
+ var listeners = [];
9540
+ var offered = false;
9541
+
9542
+ // Enough of either side to tell two identical sentences apart, short enough
9543
+ // that the record stays small when a draft carries a hundred of them. Nothing
9544
+ // reads these yet. They are captured because they can only be captured now:
9545
+ // section 14's relocation needs them and the material will have moved by the
9546
+ // time anyone wants it.
9547
+ var CONTEXT = 40;
9548
+
9549
+ function onChange(fn) { listeners.push(fn); }
9550
+ function emit() { listeners.forEach(function (f) { try { f(); } catch (e) {} }); }
9551
+
9552
+ function flat(value) { return String(value == null ? '' : value).replace(/\s+/g, ' ').trim(); }
9553
+
9554
+ function hostOf(range) {
9555
+ if (!range) return null;
9556
+ var node = range.commonAncestorContainer;
9557
+ if (node && node.nodeType === 3) node = node.parentElement;
9558
+ if (!node || !node.closest) return null;
9559
+ return node.closest('[contenteditable="true"]');
9560
+ }
9561
+
9562
+ /** The live selection, cloned, or null when there is nothing to comment on.
9563
+ *
9564
+ * Cloned, and cloned synchronously by the caller, because by the time a
9565
+ * dialog button runs its action the selection is gone. Measured 2026-08-25
9566
+ * on the fixture: with fifteen characters highlighted, opening a dialog with
9567
+ * a textarea in it left `String(getSelection())` as the empty string, since
9568
+ * dialog.open focuses the first field in the modal and the editing host
9569
+ * drops its selection on losing focus. The highlight is still painted on
9570
+ * screen at that moment, so reading the selection in the confirm handler is
9571
+ * the worst kind of wrong: silent, plausible, and visible only in the
9572
+ * finished document.
9573
+ *
9574
+ * A range spanning two blocks never arrives here. Measured the same day: the
9575
+ * Selection clamps such a range to the first block, and its
9576
+ * commonAncestorContainer becomes the section rather than an editable, so
9577
+ * hostOf returns null. Single block is not a limitation this chose; it is
9578
+ * what highlighting means inside a per-block contenteditable. */
9579
+ function pending() {
9580
+ var sel = window.getSelection();
9581
+ if (!sel || !sel.rangeCount) return null;
9582
+ var range = sel.getRangeAt(0);
9583
+ if (range.collapsed) return null;
9584
+ if (!hostOf(range)) return null;
9585
+ if (!flat(range.toString())) return null;
9586
+ return range.cloneRange();
9587
+ }
9588
+
9589
+ /** The picked headings and paragraphs, in document order, or null.
9590
+ *
9591
+ * Ctrl+click picks whole blocks with borders rather than highlighting text
9592
+ * (sow-011, the owner, 2026-11-09), and several can be picked, so this is
9593
+ * the second thing a comment can be about. Every picked block must be a
9594
+ * heading or paragraph with text in it, by the same test the gesture uses;
9595
+ * a drag that took in a list item or a figure offers no comment, which is
9596
+ * what it offered before picks counted at all. A pick is checked first: the
9597
+ * gesture that makes one drops the text selection, so the two never mean
9598
+ * different things at once. */
9599
+ function pendingBlocks() {
9600
+ var list = Ryker.pick ? Ryker.pick.picked() : [];
9601
+ if (!list.length) return null;
9602
+ for (var i = 0; i < list.length; i++) if (!Ryker.pick.prose(list[i])) return null;
9603
+ return list.slice().sort(function (a, b) {
9604
+ return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
9605
+ });
9606
+ }
9607
+
9608
+ function available() { return !!pendingBlocks() || !!pending(); }
9609
+
9610
+ /** The text of a range as a reader sees it, on one line.
9611
+ *
9612
+ * Not `range.toString()`, which concatenates Text nodes and contributes
9613
+ * nothing at all for a `<br>`. A block holding `Revenue rose<br>in the second
9614
+ * half.` gave back "rosein" for a highlight the browser itself reported as
9615
+ * "rose\nin", so the record of what somebody highlighted was a word that does
9616
+ * not occur in the document. Line breaks are common inside one block: paste
9617
+ * puts one between unwrapped paragraphs, Shift+Enter makes one, and Enter in
9618
+ * a table cell makes one. The quote renders on a single "> " line, so a space
9619
+ * is what the break means here. */
9620
+ function textOfRange(range) {
9621
+ try {
9622
+ var holder = document.createElement('div');
9623
+ holder.appendChild(range.cloneContents());
9624
+ Array.prototype.forEach.call(holder.querySelectorAll('br'), function (br) {
9625
+ br.parentNode.replaceChild(document.createTextNode(' '), br);
9626
+ });
9627
+ return flat(holder.textContent);
9628
+ } catch (e) { return flat(range.toString()); }
9629
+ }
9630
+
9631
+ // The text between the block's start and the highlight, and between the
9632
+ // highlight and the block's end. Built from the block rather than the
9633
+ // document so a comment near a boundary cannot quietly capture a neighbour.
9634
+ function edge(host, range, side) {
9635
+ try {
9636
+ var r = document.createRange();
9637
+ r.selectNodeContents(host);
9638
+ if (side === 'before') r.setEnd(range.startContainer, range.startOffset);
9639
+ else r.setStart(range.endContainer, range.endOffset);
9640
+ return textOfRange(r);
9641
+ } catch (e) { return ''; }
9642
+ }
9643
+
9644
+ function capture(range) {
9645
+ var host = hostOf(range);
9646
+ if (!host) return null;
9647
+ var quote = textOfRange(range);
9648
+ if (!quote) return null;
9649
+ return {
9650
+ blockId: Ryker.blocks.blockId(host),
9651
+ quote: quote,
9652
+ prefix: edge(host, range, 'before').slice(-CONTEXT),
9653
+ suffix: edge(host, range, 'after').slice(0, CONTEXT)
9654
+ };
9655
+ }
9656
+
9657
+ /** A comment on whole picked blocks. One block is recorded exactly as a
9658
+ * highlight of all its text would be, so the record and the instructions
9659
+ * are unchanged for the common case. Several keep the first block as
9660
+ * blockId and add blocks, one { blockId, quote } each, which renderList
9661
+ * turns into one quote per block under where it sits. */
9662
+ function captureBlocks(nodes) {
9663
+ var parts = (nodes || []).map(function (n) {
9664
+ return { blockId: Ryker.blocks.blockId(n), quote: flat(n.innerText || n.textContent) };
9665
+ }).filter(function (b) { return b.blockId && b.quote; });
9666
+ if (!parts.length) return null;
9667
+ var anchor = { blockId: parts[0].blockId, prefix: '', suffix: '',
9668
+ quote: parts.map(function (b) { return b.quote; }).join('\n') };
9669
+ if (parts.length > 1) anchor.blocks = parts;
9670
+ return anchor;
9671
+ }
9672
+
9673
+ function copyBlocks(blocks) {
9674
+ if (!blocks || !blocks.length) return null;
9675
+ var out = blocks.filter(function (b) { return b && b.blockId && flat(b.quote); })
9676
+ .map(function (b) { return { blockId: String(b.blockId), quote: flat(b.quote) }; });
9677
+ return out.length > 1 ? out : null;
9678
+ }
9679
+
9680
+ function copy(c) {
9681
+ var out = { id: c.id, blockId: c.blockId, quote: c.quote, prefix: c.prefix,
9682
+ suffix: c.suffix, body: c.body, createdAt: c.createdAt };
9683
+ if (c.blocks) out.blocks = copyBlocks(c.blocks);
9684
+ return out;
9685
+ }
9686
+
9687
+ function all() { return list.map(copy); }
9688
+ function count() { return list.length; }
9689
+
9690
+ // One call reaches the pane, the toolbar count and the recovery checkpoint,
9691
+ // because all three already hang off the instruction change signal. Three
9692
+ // separate call sites here would be three things to keep in step.
9693
+ function changed() {
9694
+ emit();
9695
+ if (Ryker.instructions && Ryker.instructions.touch) Ryker.instructions.touch();
9696
+ }
9697
+
9698
+ function store(anchor, body) {
9699
+ body = String(body == null ? '' : body).trim();
9700
+ if (!anchor || !body) return null;
9701
+ var entry = {
9702
+ id: Ryker.dom.uid('comment'),
9703
+ blockId: anchor.blockId,
9704
+ quote: anchor.quote,
9705
+ prefix: anchor.prefix,
9706
+ suffix: anchor.suffix,
9707
+ body: body,
9708
+ createdAt: Ryker.dom.now()
9709
+ };
9710
+ var blocks = copyBlocks(anchor.blocks);
9711
+ if (blocks) entry.blocks = blocks;
9712
+ list.push(entry);
9713
+ changed();
9714
+ return entry;
9715
+ }
9716
+
9717
+ /** Records a comment against a range the caller captured. Separate from
9718
+ * open() so the store can be driven without a dialog, which is what a
9719
+ * restore does and what a test that is not about the dialog should do. */
9720
+ function add(range, body) {
9721
+ return store(capture(range), body);
9722
+ }
9723
+
9724
+ function remove(id) {
9725
+ for (var i = 0; i < list.length; i++) {
9726
+ if (list[i].id === id) { list.splice(i, 1); changed(); return true; }
9727
+ }
9728
+ return false;
9729
+ }
9730
+
9731
+ function reset() {
9732
+ if (!list.length) return;
9733
+ list.length = 0;
9734
+ changed();
9735
+ }
9736
+
9737
+ // Restoring a draft. Ids come back as they were so a second restore of the
9738
+ // same draft does not duplicate what is already here.
9739
+ function restore(saved) {
9740
+ if (!saved || !saved.length) return 0;
9741
+ var known = {};
9742
+ list.forEach(function (c) { known[c.id] = true; });
9743
+ var added = 0;
9744
+ saved.forEach(function (c) {
9745
+ if (!c || !c.id || known[c.id] || !flat(c.body)) return;
9746
+ var entry = {
9747
+ id: String(c.id), blockId: c.blockId ? String(c.blockId) : null,
9748
+ quote: String(c.quote || ''), prefix: String(c.prefix || ''),
9749
+ suffix: String(c.suffix || ''), body: String(c.body),
9750
+ createdAt: c.createdAt || Ryker.dom.now()
9751
+ };
9752
+ var blocks = copyBlocks(c.blocks);
9753
+ if (blocks) entry.blocks = blocks;
9754
+ list.push(entry);
9755
+ known[c.id] = true;
9756
+ added += 1;
9757
+ });
9758
+ if (added) changed();
9759
+ return added;
9760
+ }
9761
+
9762
+ function where(id) {
9763
+ try { return Ryker.instructions.where(id); } catch (e) { return null; }
9764
+ }
9765
+
9766
+ // Both the quote and the body are block quoted, the body included. A comment
9767
+ // beginning "- rewrite this" would otherwise put a bare list marker into the
9768
+ // document above the first step, and the Markdown instruction rules forbid
9769
+ // exactly that: a marker there reads as a step dictating a bullet for a list
9770
+ // the file already has, which is a change nobody asked for.
9771
+ function quote(out, text) {
9772
+ String(text).split(/\r?\n/).forEach(function (line) { out.push('> ' + line); });
9773
+ }
9774
+
9775
+ /** The section, as lines, for instructions.build() to splice in.
9776
+ *
9777
+ * It leads with what these are. An agent handed a document of imperatives
9778
+ * reads everything in it as one unless something says otherwise, and a
9779
+ * comment that gets applied as an edit is worse than no comment at all.
9780
+ *
9781
+ * Takes the list rather than reading the module's own, because merge.js
9782
+ * renders comments recovered from saved records across page loads and the
9783
+ * wording of this section must not exist in two places. */
9784
+ function renderList(items) {
9785
+ if (!items || !items.length) return [];
9786
+ var out = ['## Comments on the material', ''];
9787
+ out.push('Notes from the person who reviewed this document. Nothing in this section asks');
9788
+ out.push('for a change, and none of it is a step to apply. The quoted text records what');
9789
+ out.push('was highlighted when the note was written, so it says what the note is about');
9790
+ out.push('even after the document has moved on. It is not a string to search for.');
9791
+ out.push('');
9792
+ items.forEach(function (c) {
9793
+ var blocks = copyBlocks(c.blocks);
9794
+ if (blocks) {
9795
+ // Several picked blocks, perhaps with gaps between them, so each quote
9796
+ // says where it sits rather than one heading claiming a range.
9797
+ out.push('### On ' + blocks.length + ' blocks');
9798
+ out.push('');
9799
+ blocks.forEach(function (b) {
9800
+ out.push('Highlighted in ' + (where(b.blockId) || 'the document') + ':');
9801
+ out.push('');
9802
+ quote(out, b.quote);
9803
+ out.push('');
9804
+ });
9805
+ } else {
9806
+ out.push('### On ' + (where(c.blockId) || 'the document'));
9807
+ out.push('');
9808
+ out.push('Highlighted:');
9809
+ out.push('');
9810
+ quote(out, c.quote);
9811
+ out.push('');
9812
+ }
9813
+ out.push('Comment:');
9814
+ out.push('');
9815
+ quote(out, c.body);
9816
+ out.push('');
9817
+ });
9818
+ return out;
9819
+ }
9820
+
9821
+ function render() { return renderList(list); }
9822
+
9823
+ /** The dialog. The range is cloned before anything else happens, for the
9824
+ * reason pending() records at length. */
9825
+ function open() {
9826
+ var blocks = pendingBlocks();
9827
+ var range = blocks ? null : pending();
9828
+ var anchor = blocks ? captureBlocks(blocks) : (range && capture(range));
9829
+ if (!anchor) return false;
9830
+
9831
+ var field = Ryker.dom.el('textarea', {
9832
+ class: 'rk comment-body', rows: '5',
9833
+ 'aria-label': 'Your comment on the highlighted text',
9834
+ placeholder: 'What should the person reading this document know about the highlighted text?'
9835
+ });
9836
+ // text, never innerHTML: the quote is somebody's document and the body is
9837
+ // somebody's prose, and neither is markup Ryker should be rendering.
9838
+ var body = Ryker.dom.el('div', {}, [
9839
+ Ryker.dom.el('p', { text: 'Recorded as a note about the highlighted text. ' +
9840
+ 'It travels with the instructions and asks for no change.' }),
9841
+ Ryker.dom.el('blockquote', { class: 'comment-quote', text: anchor.quote }),
9842
+ field
9843
+ ]);
9844
+ var dialog = Ryker.dialog.open({
9845
+ title: 'Comment on the highlighted text',
9846
+ body: body,
9847
+ buttons: [
9848
+ { label: 'Cancel' },
9849
+ { label: 'Add comment', primary: true,
9850
+ action: function () { store(anchor, field.value); } }
9851
+ ]
9852
+ });
9853
+
9854
+ // Offered once there is something to add, the way the save note is. An
9855
+ // empty field makes the button a second Cancel wearing the brand colour.
9856
+ var confirm = dialog.buttons[1];
9857
+ function offer() { confirm.hidden = !field.value.trim(); }
9858
+ field.addEventListener('input', offer);
9859
+ offer();
9860
+ return true;
9861
+ }
9862
+
9863
+ // The control's enabled state follows the selection, and nothing else in
9864
+ // Ryker watches for that. Filtered to the transitions, because selectionchange
9865
+ // fires on every mouse move during a drag and each one would otherwise rebuild
9866
+ // the toolbar.
9867
+ function watch() {
9868
+ var now = available();
9869
+ if (now === offered) return;
9870
+ offered = now;
9871
+ emit();
9872
+ }
9873
+
9874
+ function bind() {
9875
+ document.addEventListener('selectionchange', watch, true);
9876
+ // A pick changes nothing the selection event sees.
9877
+ if (Ryker.pick) Ryker.pick.onChange(watch);
9878
+ }
9879
+
9880
+ return {
9881
+ bind: bind, open: open, add: add, all: all, count: count, remove: remove,
9882
+ reset: reset, restore: restore, render: render, renderList: renderList,
9883
+ available: available, pendingBlocks: pendingBlocks, captureBlocks: captureBlocks,
9884
+ pending: pending, capture: capture, onChange: onChange
9885
+ };
9886
+ })();
9887
+
9888
+
9024
9889
  /* ---- storage/fs.js --------------------------------------------- */
9025
9890
  // The one boundary around browser file access and persisted handles.
9026
9891
  //
@@ -9075,7 +9940,11 @@
9075
9940
  [
9076
9941
  ['saveNotes', 'preference:save-notes'],
9077
9942
  ['paneWidth', 'preference:pane-width'],
9078
- ['railWidth', 'preference:rail-width']
9943
+ ['railWidth', 'preference:rail-width'],
9944
+ ['rewriteCount', 'preference:rewrite-count'],
9945
+ ['rewriteModel', 'preference:rewrite-model'],
9946
+ ['rewriteProfiles', 'preference:rewrite-profiles'],
9947
+ ['rewriteProfile', 'preference:rewrite-profile']
9079
9948
  ].forEach(function (pair) {
9080
9949
  api.get(pair[1]).then(function (value) {
9081
9950
  if (value !== null && value !== undefined) {
@@ -9549,6 +10418,12 @@
9549
10418
  // Move records retain the container-crossing intent that a flat order
9550
10419
  // cannot express when a paragraph or section changes parent.
9551
10420
  moves: Ryker.instructions.recoveryMoves ? Ryker.instructions.recoveryMoves() : [],
10421
+ // Comments ride here as well as in the draft. The draft is the live
10422
+ // carrier and normally wins recovery, but it can be lost to a cleared
10423
+ // origin or a quota refusal, and the saved round is what is left. A
10424
+ // comment is the one thing in a record that exists nowhere else: an edit
10425
+ // can be re-derived from the document, and a note about it cannot.
10426
+ comments: Ryker.comments ? Ryker.comments.all() : [],
9552
10427
  // And the pairs behind it, which is the part worth training on.
9553
10428
  edits: edits.map(function (e) {
9554
10429
  return {
@@ -9815,7 +10690,10 @@
9815
10690
  if (!extensionOwned()) {
9816
10691
  return 'Records are JSON files in the folder you granted Ryker.';
9817
10692
  }
9818
- return 'Kept in this browser only. The page cannot read them and nothing is sent anywhere. ' +
10693
+ // "They", not "nothing": since Rewrite, the extension does send text to
10694
+ // ChatGPT when the person asks for variations. These records still go
10695
+ // nowhere, and the note says exactly that much.
10696
+ return 'Kept in this browser only. The page cannot read them and they are not sent anywhere. ' +
9819
10697
  'They stay until you clear them.';
9820
10698
  }
9821
10699
 
@@ -10474,11 +11352,18 @@
10474
11352
  catch (e) { return null; }
10475
11353
  }
10476
11354
 
11355
+ function notes(found) {
11356
+ return found && Array.isArray(found.comments) ? found.comments.length : 0;
11357
+ }
11358
+
10477
11359
  function fingerprint(found) {
10478
11360
  if (!found) return 'none';
10479
11361
  var count = Array.isArray(found.changes) ? found.changes.length : 0;
10480
11362
  var moves = Array.isArray(found.moves) ? found.moves.length : 0;
10481
- return found.kind + '@' + found.baselineId + '@' + found.savedAt + '@' + count + '@' + moves;
11363
+ // Comments are in the fingerprint or a draft that gained one is mistaken
11364
+ // for a draft already declined, and the offer never appears again.
11365
+ return found.kind + '@' + found.baselineId + '@' + found.savedAt + '@' + count +
11366
+ '@' + moves + '@' + notes(found);
10482
11367
  }
10483
11368
 
10484
11369
  function checkpoint() {
@@ -10489,7 +11374,8 @@
10489
11374
  // is rebased after Save, which would otherwise drop a saved move whenever
10490
11375
  // a later unsaved text edit caused the draft to win recovery selection.
10491
11376
  var moves = Ryker.instructions.recoveryMoves ? Ryker.instructions.recoveryMoves() : [];
10492
- if (!changes.length && !moves.length) {
11377
+ var comments = Ryker.comments ? Ryker.comments.all() : [];
11378
+ if (!changes.length && !moves.length && !comments.length) {
10493
11379
  // Nothing of this page's own to record. Removing here used to be
10494
11380
  // unconditional, and boot arms this timer before anyone has edited
10495
11381
  // anything: editable.enable() fires onChange, schedule() sets it, and
@@ -10508,7 +11394,7 @@
10508
11394
  sessionId: Ryker.instructions.sessionId ? Ryker.instructions.sessionId() : null,
10509
11395
  baselineId: Ryker.instructions.baselineId(),
10510
11396
  savedAt: new Date().toISOString(), changes: changes,
10511
- order: Object.keys(snapshot), moves: moves
11397
+ order: Object.keys(snapshot), moves: moves, comments: comments
10512
11398
  };
10513
11399
  return set(draftKey(), JSON.stringify(draft)).then(function (ok) {
10514
11400
  if (ok) wrote = true;
@@ -10534,7 +11420,8 @@
10534
11420
  return found && found.baselineId &&
10535
11421
  found.baselineId === Ryker.instructions.baselineId() &&
10536
11422
  Array.isArray(found.changes) &&
10537
- (found.changes.length || (Array.isArray(found.moves) && found.moves.length) ||
11423
+ (found.changes.length || notes(found) ||
11424
+ (Array.isArray(found.moves) && found.moves.length) ||
10538
11425
  (Array.isArray(found.order) && found.order.length));
10539
11426
  }
10540
11427
 
@@ -10563,7 +11450,8 @@
10563
11450
  return Ryker.logger.read(entries[i]).then(function (raw) {
10564
11451
  var found = parse(raw);
10565
11452
  if (!found || !Array.isArray(found.changes) ||
10566
- (!found.changes.length && !(Array.isArray(found.moves) && found.moves.length) &&
11453
+ (!found.changes.length && !notes(found) &&
11454
+ !(Array.isArray(found.moves) && found.moves.length) &&
10567
11455
  !(Array.isArray(found.order) && found.order.length))) {
10568
11456
  return next(i + 1);
10569
11457
  }
@@ -10633,7 +11521,8 @@
10633
11521
  applying = false;
10634
11522
  }
10635
11523
  settle(found);
10636
- if (!changes.length && !moveOut.applied) {
11524
+ var restoredNotes = Ryker.comments ? Ryker.comments.restore(found.comments) : 0;
11525
+ if (!changes.length && !moveOut.applied && !restoredNotes) {
10637
11526
  if (out.missed + moveOut.missed) {
10638
11527
  Ryker.dialog.alert('Changes could not be restored',
10639
11528
  (out.missed + moveOut.missed) +
@@ -10661,7 +11550,8 @@
10661
11550
  (moveOut.skipped.length > 1 ? 'them' : 'it') + '.'
10662
11551
  : '';
10663
11552
  Ryker.dialog.alert('Changes restored',
10664
- changes.length + ' block(s) and ' + moveOut.applied + ' move(s) were restored.' +
11553
+ changes.length + ' block(s), ' + moveOut.applied + ' move(s) and ' +
11554
+ restoredNotes + ' comment(s) were restored.' +
10665
11555
  (lost ? ' ' + lost + ' change(s) could not be placed and were skipped.' : '') +
10666
11556
  named, lost ? 'warn' : 'ok');
10667
11557
  return true;
@@ -10683,6 +11573,7 @@
10683
11573
  title: 'Restore earlier changes?',
10684
11574
  body: Ryker.dom.el('div', {}, [
10685
11575
  Ryker.dom.el('p', { text: found.changes.length + ' content change(s)' +
11576
+ (notes(found) ? ' plus ' + notes(found) + ' comment(s)' : '') +
10686
11577
  (found.moves && found.moves.length ? ' plus ' + found.moves.length + ' move(s)' :
10687
11578
  (found.order ? ' plus saved block order' : '')) + ' were found' + when + '.' }),
10688
11579
  Ryker.dom.el('p', { class: 'muted', text: 'The source matches their baseline. Nothing is applied unless you choose Restore.' })
@@ -10786,6 +11677,18 @@
10786
11677
  // No Edit toggle. Ryker exists to edit, and a mode switch that is always in
10787
11678
  // the same position is a control nobody ever needs to touch.
10788
11679
  els.save = d().el('button', { class: 'rk', text: 'Save', onclick: requestSave });
11680
+ // Beside Save, because both record something rather than change it. It keeps
11681
+ // its slot when there is no selection and disables instead of vanishing: the
11682
+ // bar is right-aligned behind a flex spacer, so a control that comes and goes
11683
+ // moves Save out from under the cursor at the moment someone reaches for it.
11684
+ els.comment = d().el('button', { class: 'rk', text: 'Comment',
11685
+ onclick: function () { Ryker.comments.open(); } });
11686
+ // Left of Comment, so Comment keeps its place beside Save (sow-011). Only in
11687
+ // the extension, and only where something can answer it.
11688
+ if (Ryker.rewrite && Ryker.rewrite.transport()) {
11689
+ els.rewrite = d().el('button', { class: 'rk', text: 'Rewrite',
11690
+ onclick: function () { Ryker.rewrite.open(); } });
11691
+ }
10789
11692
  els.pane = d().el('button', { class: 'rk count-only',
10790
11693
  onclick: function () { Ryker.pane.toggle(); } });
10791
11694
 
@@ -10821,10 +11724,12 @@
10821
11724
  Ryker.icons.brandMark(18),
10822
11725
  d().el('span', { class: 'brand', text: 'Ryker' }),
10823
11726
  d().el('span', { class: 'spacer' }),
10824
- els.note, els.more, els.pane, els.collapse, els.save
11727
+ els.note, els.more, els.pane, els.collapse, els.rewrite, els.comment, els.save
10825
11728
  ]);
10826
11729
 
10827
11730
  Ryker.tooltip.attach(els.save, 'Save the edits into the instructions (Ctrl+S)');
11731
+ Ryker.tooltip.attach(els.comment, 'Comment on the highlighted text');
11732
+ if (els.rewrite) Ryker.tooltip.attach(els.rewrite, 'Rewrite the highlighted text');
10828
11733
  Ryker.tooltip.attach(els.pane, 'Show or hide the instructions');
10829
11734
  Ryker.tooltip.attach(els.outline, 'Show or hide the outline');
10830
11735
  Ryker.tooltip.attach(els.more, 'More actions');
@@ -11081,6 +11986,20 @@
11081
11986
  els.save.disabled = !dirty;
11082
11987
  els.save.textContent = 'Save';
11083
11988
 
11989
+ if (els.comment) {
11990
+ var canComment = Ryker.comments ? Ryker.comments.available() : false;
11991
+ els.comment.disabled = !canComment;
11992
+ els.comment.setAttribute('aria-label', canComment
11993
+ ? 'Comment on the highlighted text'
11994
+ : 'Highlight text to comment on it');
11995
+ }
11996
+ if (els.rewrite) {
11997
+ var canRewrite = Ryker.rewrite.available();
11998
+ els.rewrite.disabled = !canRewrite;
11999
+ els.rewrite.setAttribute('aria-label', canRewrite ? 'Rewrite the highlighted text'
12000
+ : 'Select text, or ' + Ryker.pick.wholeKeyLabel() + '+click a heading or paragraph, to rewrite it');
12001
+ }
12002
+
11084
12003
  els.pane.textContent = '';
11085
12004
  els.pane.appendChild(d().el('span', {
11086
12005
  class: 'count' + (edits ? ' warn' : ''), text: String(edits)
@@ -11159,6 +12078,10 @@
11159
12078
  guard('multi', function () { Ryker.multi.init(); });
11160
12079
  guard('rail', function () { Ryker.rail.build(); Ryker.rail.init(); });
11161
12080
  guard('history', function () { Ryker.history.bind(); });
12081
+ guard('comments', function () {
12082
+ Ryker.comments.bind();
12083
+ Ryker.comments.onChange(sync);
12084
+ });
11162
12085
  guard('tooltip', function () { Ryker.tooltip.init(); });
11163
12086
 
11164
12087
  guard('wire', function () {