@refrakt-md/editor 0.36.0 → 0.37.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.
Files changed (28) hide show
  1. package/app/dist/assets/{index-Cy8SHKTP.js → index-9ujyVcSd.js} +1 -1
  2. package/app/dist/assets/{index-DYCG6l5R.js → index-B-Nqwh9r.js} +1 -1
  3. package/app/dist/assets/{index-CLUHSZy4.js → index-BJSd4e0w.js} +1 -1
  4. package/app/dist/assets/{index-BStHwnJ8.js → index-BMP7NAgu.js} +1 -1
  5. package/app/dist/assets/{index-D5YtJ4LJ.js → index-Ba0pinrU.js} +1 -1
  6. package/app/dist/assets/{index-Bbspx6Ur.js → index-BwD5rHjq.js} +1 -1
  7. package/app/dist/assets/{index-C3F_VUiN.js → index-C09jSI7S.js} +1 -1
  8. package/app/dist/assets/{index-8T6TFMsB.js → index-C6oO9hJ6.js} +1 -1
  9. package/app/dist/assets/{index-BGtbamGQ.js → index-CI0Mxq8C.js} +1 -1
  10. package/app/dist/assets/{index-DpOrSlMe.js → index-C_Xl9Mn4.js} +1 -1
  11. package/app/dist/assets/{index-BPuJGtbG.js → index-CfUfif1B.js} +1 -1
  12. package/app/dist/assets/{index-DbfDzZiB.js → index-CwLGppaK.js} +254 -232
  13. package/app/dist/assets/{index-ruvHLSAS.js → index-D2DeUyHw.js} +1 -1
  14. package/app/dist/assets/{index-r1WlBtjW.js → index-DJDKU1e6.js} +1 -1
  15. package/app/dist/assets/{index-B68rXuei.js → index-DLT3QRWM.js} +1 -1
  16. package/app/dist/assets/{index-w5B8WWbe.js → index-Dw8mijZd.js} +1 -1
  17. package/app/dist/assets/{index-CUxM-evq.js → index-TBNooa_y.js} +1 -1
  18. package/app/dist/assets/{index-DrYzuT16.js → index-Yw67oMz4.js} +1 -1
  19. package/app/dist/assets/{index-Bddm5eyK.js → index-eyO3ixFF.js} +1 -1
  20. package/app/dist/index.html +1 -1
  21. package/dist/server.d.ts.map +1 -1
  22. package/dist/server.js +10 -4
  23. package/dist/server.js.map +1 -1
  24. package/dist/stamp-on-insert.d.ts +35 -0
  25. package/dist/stamp-on-insert.d.ts.map +1 -0
  26. package/dist/stamp-on-insert.js +108 -0
  27. package/dist/stamp-on-insert.js.map +1 -0
  28. package/package.json +6 -6
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Stamp-on-insert (SPEC-134 phase 3, WORK-593).
3
+ *
4
+ * A snippet inserted by a human who just looked at the code is the one moment
5
+ * when a marker is unambiguously honest — it costs nothing and it is the only
6
+ * stamping that needs no review step.
7
+ *
8
+ * **It happens on save, not on template insertion.** The editor's rune
9
+ * templates are skeletons: at the moment a `{% snippet %}` is dropped into the
10
+ * document it has no `path=` yet, so there is no slice to hash. The first point
11
+ * at which the invocation names a real region is when the page is written, so
12
+ * that is where this runs.
13
+ *
14
+ * **It reuses the review CLI's stamping path rather than recomputing a hash
15
+ * here.** The normalization must not have two implementations: a marker written
16
+ * by the editor and one written by `refrakt snippet review` have to be the same
17
+ * value for the same content, or `--check` would fire on everything the editor
18
+ * touched.
19
+ *
20
+ * `expand` is never stamped — it embeds a whole document rather than a region,
21
+ * so there is nothing of the right shape to hash.
22
+ */
23
+ import { readFileSync } from 'node:fs';
24
+ import { join } from 'node:path';
25
+ import { BASE_LANGUAGES, formatMarker, hashSlice, maskSource, reindent, resolveAnchor, resolveLanguage, shouldReindent, } from '@refrakt-md/runes';
26
+ const TAG = /\{%\s*(snippet|file-ref)\b([^%]*?)(\/?)%\}/g;
27
+ function attr(attrs, name) {
28
+ return new RegExp(`\\b${name}\\s*=\\s*"([^"]*)"`).exec(attrs)?.[1];
29
+ }
30
+ /** Resolve an invocation's slice against the current file, or undefined when
31
+ * it cannot be resolved — in which case nothing is stamped. */
32
+ function sliceFor(projectRoot, path, attrs) {
33
+ let source;
34
+ try {
35
+ source = readFileSync(join(projectRoot, path), 'utf8');
36
+ }
37
+ catch {
38
+ return undefined;
39
+ }
40
+ const symbol = attr(attrs, 'symbol');
41
+ const match = attr(attrs, 'match');
42
+ const lines = attr(attrs, 'lines');
43
+ if (symbol || match) {
44
+ try {
45
+ const resolved = resolveAnchor(source, resolveLanguage(path), {
46
+ symbol,
47
+ match,
48
+ extent: attr(attrs, 'extent'),
49
+ until: attr(attrs, 'until'),
50
+ through: attr(attrs, 'through'),
51
+ }, path);
52
+ const raw = source
53
+ .split('\n')
54
+ .slice(resolved.start - 1, resolved.end)
55
+ .join('\n');
56
+ return shouldReindent(true, undefined) ? reindent(raw) : raw;
57
+ }
58
+ catch {
59
+ return undefined;
60
+ }
61
+ }
62
+ if (lines) {
63
+ const m = /^(\d*)-?(\d*)$/.exec(lines.trim());
64
+ if (!m)
65
+ return undefined;
66
+ const all = source.split('\n');
67
+ const start = m[1] ? Number(m[1]) : 1;
68
+ const end = m[2] ? Number(m[2]) : start;
69
+ return all.slice(start - 1, end).join('\n');
70
+ }
71
+ return source;
72
+ }
73
+ /**
74
+ * Add a `reviewed` marker to any unmarked `snippet` / `file-ref` invocation
75
+ * whose slice resolves.
76
+ *
77
+ * Existing markers are left alone: re-stamping on save would silently clear a
78
+ * marker that was asking for a review, which is the one thing this feature
79
+ * cannot do.
80
+ *
81
+ * Fenced invocations are skipped — they are examples of the syntax rather than
82
+ * references, and stamping one would claim a review nobody performed.
83
+ */
84
+ export function stampOnInsert(source, projectRoot) {
85
+ const maskedLines = maskSource(source, BASE_LANGUAGES.markdoc).split('\n');
86
+ const lines = source.split('\n');
87
+ const out = lines.map((line, i) => {
88
+ if (maskedLines[i] !== line)
89
+ return line;
90
+ TAG.lastIndex = 0;
91
+ return line.replace(TAG, (raw, _rune, attrs, selfClose) => {
92
+ if (attr(attrs, 'reviewed') !== undefined)
93
+ return raw;
94
+ const path = attr(attrs, 'path');
95
+ if (!path)
96
+ return raw;
97
+ const slice = sliceFor(projectRoot, path, attrs);
98
+ if (slice === undefined)
99
+ return raw;
100
+ const marker = ` reviewed="${formatMarker(hashSlice(slice))}"`;
101
+ // Rebuild rather than string-splice so the self-closing form is
102
+ // preserved exactly.
103
+ return `{%${attrs.replace(/\s+$/, '')}${marker} ${selfClose}%}`.replace(/\{%(\S)/, '{% $1');
104
+ });
105
+ });
106
+ return out.join('\n');
107
+ }
108
+ //# sourceMappingURL=stamp-on-insert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stamp-on-insert.js","sourceRoot":"","sources":["../src/stamp-on-insert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,cAAc,EACd,YAAY,EACZ,SAAS,EACT,UAAU,EACV,QAAQ,EACR,aAAa,EACb,eAAe,EACf,cAAc,GACd,MAAM,mBAAmB,CAAC;AAE3B,MAAM,GAAG,GAAG,6CAA6C,CAAC;AAE1D,SAAS,IAAI,CAAC,KAAa,EAAE,IAAY;IACxC,OAAO,IAAI,MAAM,CAAC,MAAM,IAAI,oBAAoB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC;AAED;gEACgE;AAChE,SAAS,QAAQ,CAAC,WAAmB,EAAE,IAAY,EAAE,KAAa;IACjE,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACJ,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAEnC,IAAI,MAAM,IAAI,KAA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SAAS,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC7F,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@refrakt-md/editor",
3
3
  "description": "Browser-based content editor for refrakt.md",
4
- "version": "0.36.0",
4
+ "version": "0.37.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -52,11 +52,11 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@markdoc/markdoc": "0.4.0",
55
- "@refrakt-md/content": "0.36.0",
56
- "@refrakt-md/highlight": "0.36.0",
57
- "@refrakt-md/runes": "0.36.0",
58
- "@refrakt-md/transform": "0.36.0",
59
- "@refrakt-md/types": "0.36.0"
55
+ "@refrakt-md/content": "0.37.0",
56
+ "@refrakt-md/highlight": "0.37.0",
57
+ "@refrakt-md/runes": "0.37.0",
58
+ "@refrakt-md/transform": "0.37.0",
59
+ "@refrakt-md/types": "0.37.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@codemirror/autocomplete": "^6.20.0",