@bitcobblers/wod-wiki-ui 0.51.2194 → 0.51.2196

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.
@@ -3,7 +3,7 @@ import { HighlightStyle, syntaxTree, sublanguageProp, LRLanguage, indentNodeProp
3
3
  import { tags, styleTags, Tag as Tag$1 } from '@lezer/highlight';
4
4
  import { RangeSetBuilder, Facet, StateEffect, StateField, Prec, EditorState, EditorSelection, countColumn } from '@codemirror/state';
5
5
  import { linter, forEachDiagnostic } from '@codemirror/lint';
6
- import { whiteboardScriptLanguage, EFFORT_DISCIPLINES, createParser, whiteboardScriptCompletionSource, metricPresentation, whiteboardScript } from '@bitcobblers/wod-wiki-lang';
6
+ import { whiteboardScriptLanguage, createParser, whiteboardScriptCompletionSource, EFFORT_DISCIPLINES, metricPresentation, whiteboardScript } from '@bitcobblers/wod-wiki-lang';
7
7
  import { mapNoteBlockChanges, validateNoteBlocks, reconcileNoteBlocks, parseDocumentSections, actionableSectionKind, patchFrontmatterProperty, MetricType, parseFrontmatter } from '@bitcobblers/wod-wiki-core';
8
8
  export { blockContentId } from '@bitcobblers/wod-wiki-core';
9
9
  import { invertedEffects, history, defaultKeymap, historyKeymap, indentWithTab, cursorPageUp, cursorPageDown, cursorDocStart, cursorDocEnd } from '@codemirror/commands';
@@ -1232,6 +1232,18 @@ var referenceIndexReload = StateEffect.define();
1232
1232
  var frontmatterVisibility = Facet.define({
1233
1233
  combine: (values2) => values2[0] ?? true
1234
1234
  });
1235
+ var frontmatterDebugMode = Facet.define({
1236
+ combine: (values2) => values2[0] ?? false
1237
+ });
1238
+ var INTERNAL_FRONTMATTER_KEYS = /* @__PURE__ */ new Set([
1239
+ "type",
1240
+ "id",
1241
+ "registrysource",
1242
+ "registry-source"
1243
+ ]);
1244
+ function isInternalFrontmatterKey(key) {
1245
+ return INTERNAL_FRONTMATTER_KEYS.has(key.trim().toLowerCase());
1246
+ }
1235
1247
  var setFrontmatterDetailed = StateEffect.define();
1236
1248
  var frontmatterDetailed = StateField.define({
1237
1249
  create: () => false,
@@ -1260,6 +1272,45 @@ var frontmatterSource = StateField.define({
1260
1272
  }
1261
1273
  });
1262
1274
  var pendingFocus = /* @__PURE__ */ new WeakMap();
1275
+ var persistedDetailed = /* @__PURE__ */ new WeakMap();
1276
+ function exitToEditorBody(view) {
1277
+ const { sections } = view.state.field(sectionField);
1278
+ const fm = sections.find((s) => s.type === "frontmatter");
1279
+ const targetPos = fm ? Math.min(view.state.doc.length, fm.to) : 0;
1280
+ view.dispatch({
1281
+ selection: { anchor: targetPos },
1282
+ scrollIntoView: true
1283
+ });
1284
+ view.focus();
1285
+ }
1286
+ function triggerAddOrEditProperty(view, root, _sectionId) {
1287
+ const { sections } = view.state.field(sectionField);
1288
+ const fm = sections.find((s) => s.type === "frontmatter");
1289
+ if (!fm) {
1290
+ pendingFocus.set(view, { kind: "key", key: "property" });
1291
+ patchPropertyInView(view, "new", ["property"], "", true);
1292
+ return;
1293
+ }
1294
+ if (!view.state.field(frontmatterDetailed)) {
1295
+ view.dispatch({ effects: setFrontmatterDetailed.of(true) });
1296
+ }
1297
+ const activeRoot = root ?? view.dom.querySelector(".cm-frontmatter-preview");
1298
+ const emptyKey = activeRoot?.querySelector(
1299
+ 'input[data-frontmatter-field="key"]:is([value=""], [value="property"])'
1300
+ );
1301
+ if (emptyKey) {
1302
+ emptyKey.focus();
1303
+ emptyKey.select?.();
1304
+ return;
1305
+ }
1306
+ const addBtn = activeRoot?.querySelector('button[aria-label="Add property"]');
1307
+ if (addBtn) {
1308
+ addBtn.click();
1309
+ return;
1310
+ }
1311
+ pendingFocus.set(view, { kind: "key", key: "property" });
1312
+ patchPropertyInView(view, fm.id, ["property"], "", true);
1313
+ }
1263
1314
  var widgetCleanup = /* @__PURE__ */ new WeakMap();
1264
1315
  var helperId = 0;
1265
1316
  var TAG_CATEGORY_SUMMARY_KEYS = {
@@ -1313,7 +1364,7 @@ function attachSuggestions(input, view, root, kind, key, excluded, commit, value
1313
1364
  if (!provider || !input.parentElement) return;
1314
1365
  const panel = new SuggestionPanel(input, {
1315
1366
  label: kind === "key" ? "Suggested properties" : suggestionListLabel(valueKind),
1316
- onPick: () => commit(),
1367
+ onPick: () => commit(true),
1317
1368
  // The popup floats over the properties panel; it must never cover the
1318
1369
  // metadata actions below it.
1319
1370
  avoid: () => root.querySelector("[data-frontmatter-actions]")
@@ -1337,16 +1388,31 @@ function attachSuggestions(input, view, root, kind, key, excluded, commit, value
1337
1388
  const entries = valueKind === "effort" ? catalog.efforts ?? [] : catalog.equipment ?? [];
1338
1389
  candidates = entries.map((entry) => ({
1339
1390
  value: entry.slug,
1340
- label: `${entry.label} (${entry.slug})`,
1391
+ label: entry.label.toLowerCase() === entry.slug.toLowerCase() ? entry.label : `${entry.label} (${entry.slug})`,
1341
1392
  haystack: [entry.label, entry.slug, ...entry.aliases].join(" ").toLowerCase()
1342
1393
  }));
1343
1394
  } else {
1344
- candidates = catalog.tags.filter((tag) => isTagProperty(key) || tag.type?.toLowerCase() === key.trim().toLowerCase()).map((tag) => ({ value: tag.label, label: tag.label, haystack: tag.label.toLowerCase() }));
1395
+ const normKey = key.trim().toLowerCase();
1396
+ const fromTags = catalog.tags.filter((tag) => isTagProperty(key) || tag.type?.toLowerCase() === normKey).map((tag) => ({ value: tag.label, label: tag.label, haystack: tag.label.toLowerCase() }));
1397
+ if (fromTags.length > 0) {
1398
+ candidates = fromTags;
1399
+ } else if (normKey === "discipline") {
1400
+ candidates = EFFORT_DISCIPLINES.map((d) => ({ value: d, label: d, haystack: d.toLowerCase() }));
1401
+ } else if (normKey === "intensitytier" || normKey === "intensity") {
1402
+ candidates = ["low", "moderate", "high"].map((t) => ({ value: t, label: t, haystack: t }));
1403
+ } else {
1404
+ candidates = [];
1405
+ }
1345
1406
  }
1346
1407
  const selected = new Set(excluded.map((label) => label.toLowerCase()));
1347
- const choices = candidates.filter(
1348
- (candidate) => (query === "" || candidate.haystack.includes(query)) && !selected.has(candidate.value.toLowerCase())
1349
- ).map((candidate) => ({ value: candidate.value, label: candidate.label }));
1408
+ const seenValues = /* @__PURE__ */ new Set();
1409
+ const choices = candidates.filter((candidate) => {
1410
+ const lower = candidate.value.toLowerCase();
1411
+ if (selected.has(lower) || seenValues.has(lower)) return false;
1412
+ if (query !== "" && !candidate.haystack.includes(query)) return false;
1413
+ seenValues.add(lower);
1414
+ return true;
1415
+ }).map((candidate) => ({ value: candidate.value, label: candidate.label }));
1350
1416
  panel.setChoices(choices);
1351
1417
  if (choices.length > 0) panel.open();
1352
1418
  } catch {
@@ -1401,8 +1467,12 @@ function patchPropertyInView(view, _sectionId, path, value, expandDetailed = fal
1401
1467
  if (expandDetailed) view.dispatch({ effects: setFrontmatterDetailed.of(true) });
1402
1468
  return;
1403
1469
  }
1470
+ const currentAnchor = view.state.selection.main.anchor;
1471
+ const fmEnd = next.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/)?.[0].length ?? 0;
1472
+ const safeAnchor = currentAnchor <= fmEnd ? fmEnd : Math.min(currentAnchor, next.length);
1404
1473
  view.dispatch({
1405
1474
  changes: { from: 0, to: wholeDoc.length, insert: next },
1475
+ selection: { anchor: safeAnchor },
1406
1476
  ...expandDetailed ? { effects: setFrontmatterDetailed.of(true) } : {}
1407
1477
  });
1408
1478
  }
@@ -1415,7 +1485,13 @@ function renamePropertyInView(view, _sectionId, fromKey, toKey, value) {
1415
1485
  null
1416
1486
  );
1417
1487
  if (next === wholeDoc) return;
1418
- view.dispatch({ changes: { from: 0, to: wholeDoc.length, insert: next } });
1488
+ const currentAnchor = view.state.selection.main.anchor;
1489
+ const fmEnd = next.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/)?.[0].length ?? 0;
1490
+ const safeAnchor = currentAnchor <= fmEnd ? fmEnd : Math.min(currentAnchor, next.length);
1491
+ view.dispatch({
1492
+ changes: { from: 0, to: wholeDoc.length, insert: next },
1493
+ selection: { anchor: safeAnchor }
1494
+ });
1419
1495
  }
1420
1496
  function detectDefinitionKind(meta) {
1421
1497
  const type = typeof meta.type === "string" ? meta.type.trim().toLowerCase() : "";
@@ -1424,42 +1500,9 @@ function detectDefinitionKind(meta) {
1424
1500
  if (meta.registrySource !== void 0 || meta.baseAttributes !== void 0) return "effort";
1425
1501
  return null;
1426
1502
  }
1427
- function readBaseAttributes(body, meta = {}) {
1428
- const out = {};
1429
- if (meta["metrics.met"] !== void 0 && !Array.isArray(meta["metrics.met"])) {
1430
- out.met = String(meta["metrics.met"]);
1431
- }
1432
- if (meta["discipline"] !== void 0 && !Array.isArray(meta["discipline"])) {
1433
- out.discipline = String(meta["discipline"]);
1434
- }
1435
- if (meta["intensityTier"] !== void 0 && !Array.isArray(meta["intensityTier"])) {
1436
- out.intensityTier = String(meta["intensityTier"]);
1437
- }
1438
- let inBase = false;
1439
- for (const line of body.split(/\r?\n/)) {
1440
- if (/^baseAttributes:\s*(#.*)?$/.test(line)) {
1441
- inBase = true;
1442
- out.hasBaseBlock = true;
1443
- continue;
1444
- }
1445
- if (!inBase) continue;
1446
- if (/^\S/.test(line)) break;
1447
- const match = line.match(/^\s+([\w-]+):\s*(.*)$/);
1448
- if (!match) continue;
1449
- if (match[1] === "met" || match[1] === "discipline" || match[1] === "intensityTier") {
1450
- out[match[1]] = unquoteYamlScalar(match[2].trim());
1451
- }
1452
- }
1453
- return out;
1454
- }
1455
- function unquoteYamlScalar(val) {
1456
- if (val.startsWith('"') && val.endsWith('"')) return val.slice(1, -1).replace(/\\(["\\])/g, "$1");
1457
- if (val.startsWith("'") && val.endsWith("'")) return val.slice(1, -1).replace(/\\'/g, "'");
1458
- return val;
1459
- }
1460
1503
  function referenceValueKind(key, docKind) {
1461
1504
  const normalized = key.trim().toLowerCase();
1462
- if (normalized === "metrics.effort") return "effort";
1505
+ if (normalized === "metrics.effort" || normalized === "effort") return "effort";
1463
1506
  if (normalized === "metrics.equipment" || normalized === "equipment") return "equipment";
1464
1507
  if (normalized === "aliases" && docKind === "equipment") return "equipment";
1465
1508
  if (normalized === "aliases" && docKind === "effort") return "effort";
@@ -1715,9 +1758,10 @@ function createSummaryDraftRow(view, commit) {
1715
1758
  const settle = (doCommit) => {
1716
1759
  if (settled) return;
1717
1760
  settled = true;
1718
- const rawKey = (keyInput.value.trim() || "summary").replace(/^summaries\./i, "");
1761
+ const keyTrim = keyInput.value.trim();
1762
+ const rawKey = (keyTrim || "summary").replace(/^summaries\./i, "");
1719
1763
  const rawExpr = valInput.value.trim();
1720
- if (doCommit && rawExpr) {
1764
+ if (doCommit && (rawExpr || keyTrim)) {
1721
1765
  commit([`summaries.${rawKey}`], rawExpr);
1722
1766
  }
1723
1767
  row.remove();
@@ -1749,7 +1793,7 @@ function createSummaryDraftRow(view, commit) {
1749
1793
  const onBlur = () => queueMicrotask(() => {
1750
1794
  if (!row.isConnected) return;
1751
1795
  if (row.contains(document.activeElement)) return;
1752
- settle(valInput.value.trim().length > 0);
1796
+ settle(keyInput.value.trim().length > 0 || valInput.value.trim().length > 0);
1753
1797
  });
1754
1798
  keyInput.addEventListener("blur", onBlur);
1755
1799
  valInput.addEventListener("blur", onBlur);
@@ -1884,7 +1928,13 @@ function createFrontmatterSummary(entries, onShowDetails) {
1884
1928
  { label: "Aliases", entries: entries.filter(([key]) => isAliasProperty(key)), hash: false }
1885
1929
  ];
1886
1930
  for (const group of groups) {
1887
- const values2 = group.entries.flatMap(([, value]) => parseTagList(value));
1931
+ const seen = /* @__PURE__ */ new Set();
1932
+ const values2 = group.entries.flatMap(([, value]) => parseTagList(value)).filter((val) => {
1933
+ const lower = val.toLowerCase();
1934
+ if (seen.has(lower)) return false;
1935
+ seen.add(lower);
1936
+ return true;
1937
+ });
1888
1938
  if (values2.length === 0) continue;
1889
1939
  const row = document.createElement("div");
1890
1940
  row.className = "flex flex-wrap items-center gap-1.5 px-3 py-2";
@@ -1936,15 +1986,17 @@ var DefaultFrontmatterWidget = class extends WidgetType {
1936
1986
  rawContent;
1937
1987
  readOnly;
1938
1988
  detailed;
1939
- constructor(sectionId, rawContent, readOnly = false, detailed = false) {
1989
+ debugMode;
1990
+ constructor(sectionId, rawContent, readOnly = false, detailed = false, debugMode = false) {
1940
1991
  super();
1941
1992
  this.sectionId = sectionId;
1942
1993
  this.rawContent = rawContent ?? "";
1943
1994
  this.readOnly = readOnly;
1944
1995
  this.detailed = detailed;
1996
+ this.debugMode = debugMode;
1945
1997
  }
1946
1998
  eq(other) {
1947
- return this.sectionId === other.sectionId && this.rawContent === other.rawContent && this.readOnly === other.readOnly && this.detailed === other.detailed;
1999
+ return this.sectionId === other.sectionId && this.rawContent === other.rawContent && this.readOnly === other.readOnly && this.detailed === other.detailed && this.debugMode === other.debugMode;
1948
2000
  }
1949
2001
  ignoreEvent() {
1950
2002
  return true;
@@ -1966,6 +2018,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
1966
2018
  summaryButton.className = "ml-auto px-1 py-0.5 text-[11px] font-normal hover:text-foreground cursor-pointer";
1967
2019
  summaryButton.textContent = "Hide details \u25B4";
1968
2020
  summaryButton.addEventListener("click", () => {
2021
+ persistedDetailed.set(view.dom, false);
1969
2022
  view.dispatch({ effects: setFrontmatterDetailed.of(false) });
1970
2023
  });
1971
2024
  heading.appendChild(summaryButton);
@@ -1977,12 +2030,13 @@ var DefaultFrontmatterWidget = class extends WidgetType {
1977
2030
  root.appendChild(box);
1978
2031
  const body = this.rawContent.replace(/^---\r?\n?/, "").replace(/\r?\n?---\r?$/, "");
1979
2032
  const meta = parseFrontmatterBody(body);
1980
- const entries = Object.entries(meta);
2033
+ const showInternal = this.debugMode || view.state.facet(frontmatterDebugMode);
2034
+ const entries = Object.entries(meta).filter(([key]) => showInternal || !isInternalFrontmatterKey(key));
1981
2035
  const docKind = detectDefinitionKind(meta);
1982
2036
  const referenceProvider = view.state.facet(frontmatterReferenceIndex)?.() ?? null;
1983
- const base = docKind === "effort" ? readBaseAttributes(body, meta) : {};
1984
2037
  if (!this.detailed) {
1985
2038
  box.appendChild(createFrontmatterSummary(entries, () => {
2039
+ persistedDetailed.set(view.dom, true);
1986
2040
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
1987
2041
  }));
1988
2042
  } else {
@@ -1993,10 +2047,13 @@ var DefaultFrontmatterWidget = class extends WidgetType {
1993
2047
  emptyRow.textContent = "No properties";
1994
2048
  box.appendChild(emptyRow);
1995
2049
  }
1996
- for (const [key, value] of entries) {
2050
+ const entryKeys = entries.map(([name]) => name);
2051
+ for (let idxInEntries = 0; idxInEntries < entries.length; idxInEntries++) {
2052
+ const [key, value] = entries[idxInEntries];
1997
2053
  const isTags = isTagProperty(key);
1998
2054
  const valueKind = referenceValueKind(key, docKind);
1999
2055
  const isReferenceList = (isReferenceKey(key, docKind) || key === "aliases") && Array.isArray(value);
2056
+ const isChipList = isTags || isReferenceList || Array.isArray(value);
2000
2057
  const nested = value === "" && ownsNestedBlock(body, key);
2001
2058
  const row = document.createElement("div");
2002
2059
  row.className = "flex items-center min-h-[34px] border-b border-dashed border-border last:border-b-0 group hover:bg-muted/10 transition-colors max-[479px]:flex-col max-[479px]:items-stretch";
@@ -2005,7 +2062,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2005
2062
  const keyCol = document.createElement("div");
2006
2063
  keyCol.className = "flex items-center gap-2 px-3 py-1.5 w-36 shrink-0 border-r border-dashed border-border text-muted-foreground max-[479px]:w-auto max-[479px]:border-r-0 max-[479px]:border-b";
2007
2064
  row.appendChild(keyCol);
2008
- keyCol.appendChild(isTags || isReferenceList ? createTagIcon() : createListIcon());
2065
+ keyCol.appendChild(isChipList ? createTagIcon() : createListIcon());
2009
2066
  if (this.readOnly || nested) {
2010
2067
  const keyLabel = document.createElement("span");
2011
2068
  keyLabel.className = "truncate font-medium text-foreground/90";
@@ -2027,16 +2084,22 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2027
2084
  ).id
2028
2085
  );
2029
2086
  let currentKey = key;
2030
- const commitKey = () => {
2087
+ const commitKey = (andFocusValue = false) => {
2031
2088
  const nextKey = keyInput.value.trim();
2032
2089
  if (!nextKey || nextKey === currentKey) {
2033
2090
  keyInput.value = currentKey;
2091
+ if (andFocusValue) {
2092
+ row.querySelector('input[data-frontmatter-field="value"]')?.focus();
2093
+ }
2034
2094
  return;
2035
2095
  }
2036
2096
  if (!/^[A-Za-z_][\w.-]*$/.test(nextKey) || nextKey in meta) {
2037
2097
  keyInput.value = currentKey;
2038
2098
  return;
2039
2099
  }
2100
+ if (andFocusValue) {
2101
+ pendingFocus.set(view, { kind: "value", key: nextKey });
2102
+ }
2040
2103
  renamePropertyInView(view, this.sectionId, currentKey, nextKey, value);
2041
2104
  delete meta[currentKey];
2042
2105
  meta[nextKey] = value;
@@ -2050,10 +2113,52 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2050
2113
  attachSuggestions(keyInput, view, root, "key", key, entries.map(([name]) => name), commitKey);
2051
2114
  keyInput.addEventListener("blur", commitKeyIfAttached);
2052
2115
  keyInput.addEventListener("keydown", (e) => {
2116
+ if ((e.metaKey || e.ctrlKey) && e.key === ";") {
2117
+ e.preventDefault();
2118
+ triggerAddOrEditProperty(view, root, this.sectionId);
2119
+ return;
2120
+ }
2053
2121
  if (e.defaultPrevented) return;
2122
+ if (e.key === "Tab") {
2123
+ e.preventDefault();
2124
+ if (!e.shiftKey) {
2125
+ commitKey(true);
2126
+ row.querySelector('input[data-frontmatter-field="value"]')?.focus();
2127
+ } else if (idxInEntries > 0) {
2128
+ commitKey(false);
2129
+ const prevKey = entryKeys[idxInEntries - 1];
2130
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="value"]`)?.focus();
2131
+ } else {
2132
+ commitKey(false);
2133
+ root.querySelector('button[aria-label="Show property summary"]')?.focus();
2134
+ }
2135
+ return;
2136
+ }
2054
2137
  if (e.key === "Enter") {
2055
2138
  e.preventDefault();
2056
- keyInput.blur();
2139
+ commitKey(true);
2140
+ row.querySelector('input[data-frontmatter-field="value"]')?.focus();
2141
+ return;
2142
+ }
2143
+ if (e.key === "ArrowDown") {
2144
+ if (keyInput.getAttribute("aria-expanded") === "true") return;
2145
+ e.preventDefault();
2146
+ if (idxInEntries < entries.length - 1) {
2147
+ const nextKey = entryKeys[idxInEntries + 1];
2148
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2149
+ } else {
2150
+ root.querySelector('button[aria-label="Add property"]')?.focus();
2151
+ }
2152
+ return;
2153
+ }
2154
+ if (e.key === "ArrowUp") {
2155
+ if (keyInput.getAttribute("aria-expanded") === "true") return;
2156
+ e.preventDefault();
2157
+ if (idxInEntries > 0) {
2158
+ const prevKey = entryKeys[idxInEntries - 1];
2159
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="key"]`)?.focus();
2160
+ }
2161
+ return;
2057
2162
  }
2058
2163
  });
2059
2164
  const focus = pendingFocus.get(view);
@@ -2077,7 +2182,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2077
2182
  if (!referenceProvider) return null;
2078
2183
  return valueKind === "effort" ? referenceProvider.resolveEffort(token) : valueKind === "equipment" ? referenceProvider.resolveEquipment(token) : null;
2079
2184
  };
2080
- if (isTags || isReferenceList) {
2185
+ if (isChipList) {
2081
2186
  const chips = parseTagList(value);
2082
2187
  const chipIsReference = valueKind !== "tags";
2083
2188
  const isAliasRow = isAliasProperty(key);
@@ -2085,24 +2190,25 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2085
2190
  const chip = chips[idx];
2086
2191
  const match = chipIsReference ? refMatch(chip) : null;
2087
2192
  const pill = document.createElement("span");
2088
- pill.className = match ? "inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium bg-muted/60 text-foreground border border-border/60" : chipIsReference ? "inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium bg-destructive/10 text-destructive border border-destructive/30" : "inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium bg-amber-500/10 text-amber-800 dark:text-amber-300 border border-amber-500/20 dark:border-amber-500/30";
2193
+ pill.className = match ? "group/pill inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-muted/50 text-foreground border border-border/60" : chipIsReference ? "group/pill inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-destructive/10 text-destructive border border-destructive/30" : "group/pill inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-muted/40 text-foreground/90 border border-border/60";
2089
2194
  const pillText = document.createElement("span");
2090
2195
  pillText.textContent = isAliasRow ? chip : match ? match.label : chip;
2091
2196
  pill.appendChild(pillText);
2092
- if (match && referenceProvider) {
2197
+ if (match && referenceProvider && (!isAliasRow || idx === 0)) {
2093
2198
  const openLink = document.createElement("a");
2094
2199
  openLink.href = referenceProvider.openHref(valueKind, match.slug);
2095
2200
  openLink.title = `Open ${match.label} page`;
2096
2201
  openLink.setAttribute("aria-label", `Open ${match.label} page`);
2097
- openLink.className = "inline-flex items-center justify-center text-muted-foreground/60 hover:text-foreground cursor-pointer";
2202
+ openLink.className = isAliasRow ? "inline-flex items-center justify-center text-muted-foreground/40 hover:text-foreground cursor-pointer" : "inline-flex items-center justify-center text-muted-foreground/60 hover:text-foreground cursor-pointer";
2098
2203
  openLink.appendChild(createExternalIcon());
2099
2204
  pill.appendChild(openLink);
2100
2205
  }
2101
2206
  if (!this.readOnly) {
2102
2207
  const rmBtn = document.createElement("button");
2103
2208
  rmBtn.type = "button";
2209
+ rmBtn.tabIndex = -1;
2104
2210
  rmBtn.setAttribute("aria-label", isTags ? `Remove tag ${chip}` : `Remove ${chip}`);
2105
- rmBtn.className = "inline-flex items-center justify-center text-muted-foreground/60 hover:text-foreground dark:hover:text-foreground cursor-pointer";
2211
+ rmBtn.className = "inline-flex items-center justify-center text-muted-foreground/50 hover:text-destructive cursor-pointer transition-colors";
2106
2212
  rmBtn.appendChild(createCloseIcon("sm"));
2107
2213
  rmBtn.addEventListener("click", (e) => {
2108
2214
  e.preventDefault();
@@ -2115,7 +2221,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2115
2221
  }
2116
2222
  if (!this.readOnly) {
2117
2223
  const chipInput = document.createElement("input");
2118
- chipInput.className = "flex-none w-44 max-w-full rounded-md border border-field-border bg-background/60 px-2 py-1 text-xs text-foreground outline-none placeholder:text-field-placeholder focus:border-ring focus:ring-1 focus:ring-ring";
2224
+ chipInput.className = "flex-1 min-w-[96px] bg-transparent px-1 py-0.5 text-xs text-foreground outline-none placeholder:text-field-placeholder focus:bg-background/80 focus:ring-1 focus:ring-ring rounded transition-colors";
2119
2225
  chipInput.placeholder = chips.length === 0 ? isReferenceList ? `Add ${valueKind === "effort" ? "effort" : "equipment"}\u2026` : "Add tags\u2026" : isTags ? "Add tag\u2026" : "Add\u2026";
2120
2226
  chipInput.setAttribute("aria-label", `Value for ${key}`);
2121
2227
  chipInput.dataset.frontmatterField = "value";
@@ -2138,21 +2244,78 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2138
2244
  valCol.appendChild(chipInput);
2139
2245
  attachSuggestions(chipInput, view, root, "value", key, chips, commitNewChip, valueKind);
2140
2246
  chipInput.addEventListener("keydown", (e) => {
2247
+ if ((e.metaKey || e.ctrlKey) && e.key === ";") {
2248
+ e.preventDefault();
2249
+ triggerAddOrEditProperty(view, root, this.sectionId);
2250
+ return;
2251
+ }
2141
2252
  if (e.defaultPrevented) return;
2142
- if (e.key === "Enter" || e.key === ",") {
2253
+ if ((e.key === "Enter" || e.key === ",") && chipInput.value.trim()) {
2143
2254
  e.preventDefault();
2144
2255
  commitNewChip();
2145
- } else if (e.key === "Backspace" && !chipInput.value && chips.length > 0) {
2256
+ return;
2257
+ }
2258
+ if (e.key === "Backspace" && !chipInput.value && chips.length > 0) {
2146
2259
  e.preventDefault();
2147
2260
  pendingFocus.set(view, { kind: "tag", key });
2148
2261
  commitList(chips.slice(0, -1));
2262
+ return;
2263
+ }
2264
+ if (e.key === "Tab") {
2265
+ if (chipInput.value.trim() && !e.shiftKey) {
2266
+ e.preventDefault();
2267
+ commitNewChip();
2268
+ return;
2269
+ }
2270
+ e.preventDefault();
2271
+ if (!e.shiftKey) {
2272
+ if (idxInEntries < entries.length - 1) {
2273
+ const nextKey = entryKeys[idxInEntries + 1];
2274
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2275
+ } else {
2276
+ root.querySelector('button[aria-label="Add property"]')?.focus();
2277
+ }
2278
+ } else {
2279
+ row.querySelector('input[data-frontmatter-field="key"]')?.focus();
2280
+ }
2281
+ return;
2282
+ }
2283
+ if (e.key === "Enter") {
2284
+ e.preventDefault();
2285
+ if (idxInEntries < entries.length - 1) {
2286
+ const nextKey = entryKeys[idxInEntries + 1];
2287
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2288
+ } else {
2289
+ root.querySelector('button[aria-label="Add property"]')?.click();
2290
+ }
2291
+ return;
2292
+ }
2293
+ if (e.key === "ArrowDown") {
2294
+ if (chipInput.getAttribute("aria-expanded") === "true") return;
2295
+ e.preventDefault();
2296
+ if (idxInEntries < entries.length - 1) {
2297
+ const nextKey = entryKeys[idxInEntries + 1];
2298
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="value"]`)?.focus();
2299
+ } else {
2300
+ exitToEditorBody(view);
2301
+ }
2302
+ return;
2303
+ }
2304
+ if (e.key === "ArrowUp") {
2305
+ if (chipInput.getAttribute("aria-expanded") === "true") return;
2306
+ e.preventDefault();
2307
+ if (idxInEntries > 0) {
2308
+ const prevKey = entryKeys[idxInEntries - 1];
2309
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="value"]`)?.focus();
2310
+ }
2311
+ return;
2149
2312
  }
2150
2313
  });
2151
2314
  chipInput.addEventListener("blur", () => queueMicrotask(() => {
2152
2315
  if (chipInput.isConnected && chipInput.value.trim()) commitNewChip();
2153
2316
  }));
2154
2317
  const focus = pendingFocus.get(view);
2155
- if (focus?.kind === "tag" && focus.key === key) {
2318
+ if ((focus?.kind === "tag" || focus?.kind === "value") && focus.key === key) {
2156
2319
  setTimeout(() => {
2157
2320
  if (chipInput.isConnected) chipInput.focus();
2158
2321
  }, 0);
@@ -2199,8 +2362,9 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2199
2362
  valCol.appendChild(valSpan);
2200
2363
  } else {
2201
2364
  const valInput = document.createElement("input");
2202
- valInput.className = "w-full rounded-md border border-field-border bg-background/60 px-2 py-1 text-xs text-foreground outline-none placeholder:text-field-placeholder focus:border-ring focus:ring-1 focus:ring-ring transition-colors";
2365
+ valInput.className = "w-full bg-transparent px-1.5 py-0.5 -mx-1.5 text-xs text-foreground outline-none placeholder:text-field-placeholder hover:bg-muted/30 focus:bg-background focus:ring-1 focus:ring-ring rounded transition-colors";
2203
2366
  valInput.value = strVal;
2367
+ valInput.placeholder = "Empty";
2204
2368
  valInput.spellcheck = false;
2205
2369
  valInput.setAttribute("aria-label", `Value for ${key}`);
2206
2370
  valInput.dataset.frontmatterField = "value";
@@ -2210,13 +2374,18 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2210
2374
  appendFieldHelper(valCol, "Property value. Press Enter to apply.").id
2211
2375
  );
2212
2376
  let committedVal = strVal;
2213
- const commitVal = () => {
2377
+ const commitVal = (pendingNextKey) => {
2214
2378
  const cur = valInput.value.trim();
2215
2379
  if (cur !== committedVal) {
2216
2380
  committedVal = cur;
2217
2381
  const num = Number(cur);
2218
2382
  const next = cur !== "" && !isNaN(num) ? num : cur;
2219
2383
  meta[key] = next;
2384
+ if (typeof pendingNextKey === "string") {
2385
+ pendingFocus.set(view, { kind: "key", key: pendingNextKey });
2386
+ } else if (pendingNextKey === true) {
2387
+ pendingFocus.set(view, { kind: "value", key });
2388
+ }
2220
2389
  patchPropertyInView(view, this.sectionId, [key], next);
2221
2390
  }
2222
2391
  };
@@ -2237,29 +2406,85 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2237
2406
  );
2238
2407
  valInput.addEventListener("blur", commitValIfAttached);
2239
2408
  valInput.addEventListener("keydown", (e) => {
2409
+ if ((e.metaKey || e.ctrlKey) && e.key === ";") {
2410
+ e.preventDefault();
2411
+ triggerAddOrEditProperty(view, root, this.sectionId);
2412
+ return;
2413
+ }
2240
2414
  if (e.defaultPrevented) return;
2415
+ if (e.key === "Tab") {
2416
+ e.preventDefault();
2417
+ if (!e.shiftKey) {
2418
+ if (idxInEntries < entries.length - 1) {
2419
+ const nextKey = entryKeys[idxInEntries + 1];
2420
+ commitVal(nextKey);
2421
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2422
+ } else {
2423
+ commitVal();
2424
+ root.querySelector('button[aria-label="Add property"]')?.focus();
2425
+ }
2426
+ } else {
2427
+ commitVal();
2428
+ row.querySelector('input[data-frontmatter-field="key"]')?.focus();
2429
+ }
2430
+ return;
2431
+ }
2241
2432
  if (e.key === "Enter") {
2242
2433
  e.preventDefault();
2243
- valInput.blur();
2434
+ if (idxInEntries < entries.length - 1) {
2435
+ const nextKey = entryKeys[idxInEntries + 1];
2436
+ commitVal(nextKey);
2437
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="key"]`)?.focus();
2438
+ } else {
2439
+ commitVal();
2440
+ root.querySelector('button[aria-label="Add property"]')?.click();
2441
+ }
2442
+ return;
2443
+ }
2444
+ if (e.key === "ArrowDown") {
2445
+ if (valInput.getAttribute("aria-expanded") === "true") return;
2446
+ e.preventDefault();
2447
+ if (idxInEntries < entries.length - 1) {
2448
+ const nextKey = entryKeys[idxInEntries + 1];
2449
+ box.querySelector(`[data-frontmatter-row="${nextKey}"] input[data-frontmatter-field="value"]`)?.focus();
2450
+ } else {
2451
+ exitToEditorBody(view);
2452
+ }
2453
+ return;
2454
+ }
2455
+ if (e.key === "ArrowUp") {
2456
+ if (valInput.getAttribute("aria-expanded") === "true") return;
2457
+ e.preventDefault();
2458
+ if (idxInEntries > 0) {
2459
+ const prevKey = entryKeys[idxInEntries - 1];
2460
+ box.querySelector(`[data-frontmatter-row="${prevKey}"] input[data-frontmatter-field="value"]`)?.focus();
2461
+ }
2462
+ return;
2244
2463
  }
2245
2464
  });
2465
+ const focus = pendingFocus.get(view);
2466
+ if (focus?.kind === "value" && focus.key === key) {
2467
+ setTimeout(() => {
2468
+ if (!valInput.isConnected) return;
2469
+ valInput.focus();
2470
+ valInput.select?.();
2471
+ }, 0);
2472
+ pendingFocus.delete(view);
2473
+ }
2246
2474
  if (key.trim().toLowerCase() === "metrics.effort" && referenceProvider) {
2247
2475
  const match = referenceProvider.resolveEffort(strVal);
2248
2476
  if (match) {
2249
- const pill = document.createElement("span");
2250
- pill.className = "inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs font-medium bg-muted/60 text-foreground border border-border/60 shrink-0";
2251
- const pillText = document.createElement("span");
2252
- pillText.textContent = match.label;
2253
- pill.appendChild(pillText);
2477
+ valInput.className = "flex-1 min-w-[70px] bg-transparent px-1.5 py-0.5 -mx-1.5 text-xs text-foreground outline-none placeholder:text-field-placeholder hover:bg-muted/30 focus:bg-background focus:ring-1 focus:ring-ring rounded transition-colors";
2254
2478
  const openLink = document.createElement("a");
2255
2479
  openLink.href = referenceProvider.openHref("effort", match.slug);
2256
2480
  openLink.title = `Open ${match.label} page`;
2257
2481
  openLink.setAttribute("aria-label", `Open ${match.label} page`);
2258
- openLink.className = "inline-flex items-center justify-center text-muted-foreground/60 hover:text-foreground cursor-pointer";
2482
+ openLink.className = "shrink-0 inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors cursor-pointer";
2483
+ const linkLabel = document.createElement("span");
2484
+ linkLabel.textContent = match.label;
2485
+ openLink.appendChild(linkLabel);
2259
2486
  openLink.appendChild(createExternalIcon());
2260
- pill.appendChild(openLink);
2261
- valCol.insertBefore(pill, valInput);
2262
- valInput.className = "flex-1 min-w-[70px] rounded-md border border-field-border bg-background/60 px-2 py-1 text-xs text-foreground outline-none placeholder:text-field-placeholder focus:border-ring focus:ring-1 focus:ring-ring transition-colors";
2487
+ valCol.appendChild(openLink);
2263
2488
  }
2264
2489
  const diag = renderEffortValueDiagnostics(
2265
2490
  referenceProvider,
@@ -2289,6 +2514,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2289
2514
  actionsCol.className = "flex items-center pr-2";
2290
2515
  const delBtn = document.createElement("button");
2291
2516
  delBtn.type = "button";
2517
+ delBtn.tabIndex = -1;
2292
2518
  delBtn.setAttribute("aria-label", `Remove property ${key}`);
2293
2519
  delBtn.className = "opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-muted-foreground/70 hover:text-destructive p-1 rounded transition-opacity cursor-pointer";
2294
2520
  delBtn.appendChild(createCloseIcon("md"));
@@ -2302,9 +2528,6 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2302
2528
  row.appendChild(actionsCol);
2303
2529
  }
2304
2530
  }
2305
- if (docKind === "effort" && !this.readOnly) {
2306
- box.appendChild(this.buildDefinitionRows(view, base));
2307
- }
2308
2531
  }
2309
2532
  if (!this.readOnly) {
2310
2533
  const existingTagKey = entries.find(([key]) => key.trim().toLowerCase() === "tags")?.[0] ?? entries.find(([key]) => isTagProperty(key))?.[0];
@@ -2322,6 +2545,10 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2322
2545
  addBtn.addEventListener("click", (e) => {
2323
2546
  e.preventDefault();
2324
2547
  e.stopPropagation();
2548
+ if (!this.detailed) {
2549
+ persistedDetailed.set(view.dom, true);
2550
+ view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2551
+ }
2325
2552
  let newKey = "property";
2326
2553
  let count2 = 1;
2327
2554
  while (newKey in meta) {
@@ -2329,13 +2556,24 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2329
2556
  newKey = `property_${count2}`;
2330
2557
  }
2331
2558
  pendingFocus.set(view, { kind: "key", key: newKey });
2332
- patchPropertyInView(view, this.sectionId, [newKey], "", !this.detailed);
2333
- const keyField = view.dom.querySelector(
2559
+ patchPropertyInView(view, this.sectionId, [newKey], "", true);
2560
+ const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2561
+ const keyField = activeRoot.querySelector(
2334
2562
  `[data-frontmatter-row="${newKey}"] [data-frontmatter-field="key"]`
2335
2563
  );
2336
2564
  keyField?.focus();
2337
2565
  keyField?.select();
2338
2566
  });
2567
+ addBtn.addEventListener("keydown", (e) => {
2568
+ if (e.key === "ArrowDown" || e.key === "Tab" && !e.shiftKey) {
2569
+ e.preventDefault();
2570
+ exitToEditorBody(view);
2571
+ } else if (e.key === "ArrowUp" || e.key === "Tab" && e.shiftKey) {
2572
+ e.preventDefault();
2573
+ const allInputs = box.querySelectorAll("input[data-frontmatter-field]:not([disabled])");
2574
+ allInputs[allInputs.length - 1]?.focus();
2575
+ }
2576
+ });
2339
2577
  actionsRow.appendChild(addBtn);
2340
2578
  {
2341
2579
  const addMetricBtn = document.createElement("button");
@@ -2350,6 +2588,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2350
2588
  addMetricBtn.addEventListener("click", (e) => {
2351
2589
  e.preventDefault();
2352
2590
  e.stopPropagation();
2591
+ persistedDetailed.set(view.dom, true);
2353
2592
  if (!this.detailed) {
2354
2593
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2355
2594
  }
@@ -2382,6 +2621,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2382
2621
  addSummaryBtn.addEventListener("click", (e) => {
2383
2622
  e.preventDefault();
2384
2623
  e.stopPropagation();
2624
+ persistedDetailed.set(view.dom, true);
2385
2625
  if (!this.detailed) {
2386
2626
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2387
2627
  }
@@ -2393,7 +2633,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2393
2633
  return;
2394
2634
  }
2395
2635
  const draftRow = createSummaryDraftRow(view, (path, value) => {
2396
- patchPropertyInView(view, this.sectionId, path, value);
2636
+ patchPropertyInView(view, this.sectionId, path, value, true);
2397
2637
  });
2398
2638
  activeBox.appendChild(draftRow);
2399
2639
  draftRow.querySelector("input")?.focus();
@@ -2413,6 +2653,7 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2413
2653
  addTagBtn.addEventListener("click", (e) => {
2414
2654
  e.preventDefault();
2415
2655
  e.stopPropagation();
2656
+ persistedDetailed.set(view.dom, true);
2416
2657
  if (!this.detailed) {
2417
2658
  view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2418
2659
  }
@@ -2462,90 +2703,18 @@ var DefaultFrontmatterWidget = class extends WidgetType {
2462
2703
  });
2463
2704
  view.focus();
2464
2705
  });
2706
+ editYamlBtn.addEventListener("keydown", (e) => {
2707
+ if (e.key === "ArrowDown" || e.key === "Tab" && !e.shiftKey) {
2708
+ e.preventDefault();
2709
+ exitToEditorBody(view);
2710
+ }
2711
+ });
2465
2712
  actionsRow.appendChild(editYamlBtn);
2466
2713
  }
2467
2714
  root.appendChild(actionsRow);
2468
2715
  }
2469
2716
  return root;
2470
2717
  }
2471
- /**
2472
- * Effort-definition attribute rows (MET / discipline / intensity tier).
2473
- * Values live in the nested baseAttributes block; each edit patches that
2474
- * one path, so unknown sibling keys and comments elsewhere survive.
2475
- */
2476
- buildDefinitionRows(view, base) {
2477
- const wrap = document.createElement("div");
2478
- wrap.setAttribute("data-frontmatter-definition", "true");
2479
- wrap.className = "border-t border-dashed border-border/60";
2480
- const header = document.createElement("div");
2481
- header.className = "px-3 pt-2 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground";
2482
- header.textContent = "Definition";
2483
- wrap.appendChild(header);
2484
- const commitField = (field, raw) => {
2485
- if (field === "met") {
2486
- const num = Number(raw);
2487
- const path2 = base.hasBaseBlock ? ["baseAttributes", "met"] : ["metrics.met"];
2488
- patchPropertyInView(view, this.sectionId, path2, raw !== "" && !Number.isNaN(num) ? num : null);
2489
- return;
2490
- }
2491
- const path = base.hasBaseBlock ? ["baseAttributes", field] : [field];
2492
- patchPropertyInView(view, this.sectionId, path, raw === "" ? null : raw);
2493
- };
2494
- const fieldRow = (label, child) => {
2495
- const row = document.createElement("label");
2496
- row.className = "flex items-center gap-2 px-3 py-1.5 min-h-[34px] border-b border-dashed border-border/60 last:border-b-0 max-[479px]:flex-col max-[479px]:items-stretch";
2497
- const name = document.createElement("span");
2498
- name.className = "w-28 shrink-0 text-muted-foreground";
2499
- name.textContent = label;
2500
- row.appendChild(name);
2501
- child.className = "flex-1 min-w-0 bg-transparent text-xs text-foreground outline-none py-0.5";
2502
- row.appendChild(child);
2503
- wrap.appendChild(row);
2504
- };
2505
- const met = document.createElement("input");
2506
- met.type = "number";
2507
- met.step = "0.1";
2508
- met.inputMode = "decimal";
2509
- met.value = base.met ?? "";
2510
- met.setAttribute("aria-label", "MET value");
2511
- met.addEventListener("change", () => queueMicrotask(() => {
2512
- if (met.isConnected) commitField("met", met.value.trim());
2513
- }));
2514
- fieldRow("MET", met);
2515
- const discipline = document.createElement("select");
2516
- discipline.setAttribute("aria-label", "Discipline");
2517
- discipline.className = "flex-1 min-w-0 rounded-md border border-input bg-background px-1.5 text-[11px] text-muted-foreground outline-none";
2518
- const unset = document.createElement("option");
2519
- unset.value = "";
2520
- unset.textContent = "Unset";
2521
- discipline.appendChild(unset);
2522
- for (const option of EFFORT_DISCIPLINES) {
2523
- const opt = document.createElement("option");
2524
- opt.value = option;
2525
- opt.textContent = option;
2526
- discipline.appendChild(opt);
2527
- }
2528
- discipline.value = base.discipline ?? "";
2529
- discipline.addEventListener("change", () => commitField("discipline", discipline.value));
2530
- fieldRow("Discipline", discipline);
2531
- const tier = document.createElement("select");
2532
- tier.setAttribute("aria-label", "Intensity tier");
2533
- tier.className = "flex-1 min-w-0 rounded-md border border-input bg-background px-1.5 text-[11px] text-muted-foreground outline-none";
2534
- const tierUnset = document.createElement("option");
2535
- tierUnset.value = "";
2536
- tierUnset.textContent = "Unset";
2537
- tier.appendChild(tierUnset);
2538
- for (const option of ["low", "moderate", "high"]) {
2539
- const opt = document.createElement("option");
2540
- opt.value = option;
2541
- opt.textContent = option;
2542
- tier.appendChild(opt);
2543
- }
2544
- tier.value = base.intensityTier ?? "";
2545
- tier.addEventListener("change", () => commitField("intensityTier", tier.value));
2546
- fieldRow("Intensity tier", tier);
2547
- return wrap;
2548
- }
2549
2718
  destroy(dom) {
2550
2719
  widgetCleanup.get(dom)?.forEach((close) => close());
2551
2720
  widgetCleanup.delete(dom);
@@ -2584,14 +2753,23 @@ var EmptyFrontmatterWidget = class extends WidgetType {
2584
2753
  addBtn.addEventListener("click", (e) => {
2585
2754
  e.preventDefault();
2586
2755
  e.stopPropagation();
2756
+ persistedDetailed.set(view.dom, true);
2757
+ view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2587
2758
  pendingFocus.set(view, { kind: "key", key: "property" });
2588
2759
  patchPropertyInView(view, "new", ["property"], "", true);
2589
- const keyField = view.dom.querySelector(
2760
+ const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2761
+ const keyField = activeRoot.querySelector(
2590
2762
  '[data-frontmatter-row="property"] [data-frontmatter-field="key"]'
2591
2763
  );
2592
2764
  keyField?.focus();
2593
2765
  keyField?.select();
2594
2766
  });
2767
+ addBtn.addEventListener("keydown", (e) => {
2768
+ if (e.key === "ArrowDown" || e.key === "Tab" && !e.shiftKey) {
2769
+ e.preventDefault();
2770
+ exitToEditorBody(view);
2771
+ }
2772
+ });
2595
2773
  actionsRow.appendChild(addBtn);
2596
2774
  const addMetricBtn = document.createElement("button");
2597
2775
  addMetricBtn.type = "button";
@@ -2605,6 +2783,7 @@ var EmptyFrontmatterWidget = class extends WidgetType {
2605
2783
  addMetricBtn.addEventListener("click", (e) => {
2606
2784
  e.preventDefault();
2607
2785
  e.stopPropagation();
2786
+ persistedDetailed.set(view.dom, true);
2608
2787
  if (!this.detailed) view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2609
2788
  const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2610
2789
  const existing = activeRoot.querySelector("[data-frontmatter-metric-draft] input");
@@ -2634,6 +2813,7 @@ var EmptyFrontmatterWidget = class extends WidgetType {
2634
2813
  addSummaryBtn.addEventListener("click", (e) => {
2635
2814
  e.preventDefault();
2636
2815
  e.stopPropagation();
2816
+ persistedDetailed.set(view.dom, true);
2637
2817
  if (!this.detailed) view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2638
2818
  const activeRoot = view.dom.querySelector(".cm-frontmatter-preview") ?? root;
2639
2819
  const existing = activeRoot.querySelector("[data-frontmatter-summary-draft] input");
@@ -2695,14 +2875,16 @@ function buildFrontmatterDecos(state) {
2695
2875
  builder.add(section.from, to, Decoration.replace({ block: true }));
2696
2876
  continue;
2697
2877
  }
2698
- const selected = !state.readOnly && (state.field(frontmatterSource) || state.selection.ranges.some((range) => range.from < section.to && range.to > section.from));
2878
+ const detailed = state.field(frontmatterDetailed);
2879
+ const selected = !state.readOnly && state.field(frontmatterSource);
2699
2880
  if (selected) continue;
2700
2881
  const rawContent = state.doc.sliceString(section.from, section.to);
2882
+ const debugMode = state.facet(frontmatterDebugMode);
2701
2883
  builder.add(
2702
2884
  section.from,
2703
2885
  section.to,
2704
2886
  Decoration.replace({
2705
- widget: new DefaultFrontmatterWidget(section.id, rawContent, state.readOnly, state.field(frontmatterDetailed)),
2887
+ widget: new DefaultFrontmatterWidget(section.id, rawContent, state.readOnly, detailed, debugMode),
2706
2888
  block: true
2707
2889
  })
2708
2890
  );
@@ -2737,7 +2919,85 @@ var frontmatterPreviewField = StateField.define({
2737
2919
  )
2738
2920
  ]
2739
2921
  });
2740
- var frontmatterPreview = [frontmatterDetailed, frontmatterSource, frontmatterPreviewField];
2922
+ var frontmatterDetailSync = EditorView.updateListener.of((update) => {
2923
+ const current = update.state.field(frontmatterDetailed);
2924
+ const prev = update.startState.field(frontmatterDetailed);
2925
+ if (current !== prev) {
2926
+ if (update.transactions.some((tr) => tr.effects.some((e) => e.is(setFrontmatterDetailed)))) {
2927
+ persistedDetailed.set(update.view.dom, current);
2928
+ } else if (persistedDetailed.get(update.view.dom) === true && !current) {
2929
+ queueMicrotask(() => {
2930
+ if (update.view.state.field(frontmatterDetailed) === false) {
2931
+ update.view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2932
+ }
2933
+ });
2934
+ }
2935
+ } else if (persistedDetailed.get(update.view.dom) === true && !current) {
2936
+ queueMicrotask(() => {
2937
+ if (update.view.state.field(frontmatterDetailed) === false) {
2938
+ update.view.dispatch({ effects: setFrontmatterDetailed.of(true) });
2939
+ }
2940
+ });
2941
+ }
2942
+ });
2943
+ var frontmatterKeymap = Prec.highest(
2944
+ keymap.of([
2945
+ {
2946
+ key: "Mod-;",
2947
+ run(view) {
2948
+ if (view.state.readOnly) return false;
2949
+ triggerAddOrEditProperty(view);
2950
+ return true;
2951
+ }
2952
+ },
2953
+ {
2954
+ key: "ArrowUp",
2955
+ run(view) {
2956
+ if (view.state.readOnly) return false;
2957
+ if (view.state.field(frontmatterSource)) return false;
2958
+ if (!view.state.facet(frontmatterVisibility)) return false;
2959
+ const { head } = view.state.selection.main;
2960
+ const { sections } = view.state.field(sectionField);
2961
+ const fm = sections.find((s) => s.type === "frontmatter");
2962
+ if (!fm) return false;
2963
+ const cursorLine = view.state.doc.lineAt(head);
2964
+ const fmEndLine = view.state.doc.lineAt(fm.to);
2965
+ if (cursorLine.number > fmEndLine.number + 1) return false;
2966
+ const allInputs = view.dom.querySelectorAll(
2967
+ ".cm-frontmatter-preview input[data-frontmatter-field]:not([disabled])"
2968
+ );
2969
+ if (allInputs.length === 0) {
2970
+ const addBtn = view.dom.querySelector(
2971
+ '.cm-frontmatter-preview button[aria-label="Add property"]'
2972
+ );
2973
+ if (addBtn) {
2974
+ addBtn.focus();
2975
+ return true;
2976
+ }
2977
+ const detailsBtn = view.dom.querySelector(
2978
+ '.cm-frontmatter-preview button[aria-label="Show property details"]'
2979
+ );
2980
+ if (detailsBtn) {
2981
+ detailsBtn.focus();
2982
+ return true;
2983
+ }
2984
+ return false;
2985
+ }
2986
+ const target = allInputs[allInputs.length - 1];
2987
+ target.focus();
2988
+ target.select?.();
2989
+ return true;
2990
+ }
2991
+ }
2992
+ ])
2993
+ );
2994
+ var frontmatterPreview = [
2995
+ frontmatterDetailed,
2996
+ frontmatterSource,
2997
+ frontmatterPreviewField,
2998
+ frontmatterDetailSync,
2999
+ frontmatterKeymap
3000
+ ];
2741
3001
  var HEADING_RE = /^(#{1,6}) /;
2742
3002
  var BOLD_RE = /\*\*([^*\n]+)\*\*/g;
2743
3003
  var ITALIC_STAR_RE = /(?<!\*)\*([^*\n]+)\*(?!\*)/g;
@@ -13783,6 +14043,6 @@ function editorPreset(optionsOrDialect = "markdown") {
13783
14043
  return extensions;
13784
14044
  }
13785
14045
 
13786
- export { AGG_OPTIONS, CANONICAL_BLOCK_TYPES, CLAUSE_META, ComposerRegistry, DEFAULT_DIAGNOSTICS_DEBOUNCE_MS, DEFAULT_OUTPUT_FILTERS, DEFAULT_PRIMARY_FILTER, DefaultFrontmatterWidget, EditorDialog, GROUPBY_OPTIONS, GoalRings, KIND_OPTIONS, METRIC_OPTIONS, MULTI_VALUE_TYPES, MetricBadge, OUTPUT_TYPE_CLASS, OUTPUT_TYPE_DOT, OutputFilterPills, OutputStatementsTable, PLANE_OPTIONS, ProposedMetricBadge, QueryBlockView, QueryValue, ROLLUP_OPTIONS, RowsResultsChrome, RowsTable, SERIES_COLORS, SOURCE_OPTIONS, SUGGESTION_BINDINGS, StackedBar, TARGET_OPTIONS, TIME_OPTIONS, TONE_CLASS, TokenSlotPill, TopList, UNIT_OPTIONS, WHERE_AGGREGATORS, WHERE_METRICS, WidgetChart, WidgetProblemBadge, WqlBars, WqlComposer, WqlDiagnosticsStrip, WqlEmptyState, WqlQueryInspectorModal, WqlTable, WqlTimeseries, ZoneDistribution, activeCursorSection, addRuntimePanel, autocompleteTooltipTheme, blockTypesFromBlocks, canonicalSuggestionItems, cn, compactNumber, composerRegistry, configureOverlayActions, createExecutorDocumentHost, cursorFocusExtension, customCompletionSources, dateRangeSlot, dispatchAddRuntimePanel, dispatchExpandRuntimePanel, dispatchGutterHighlights, dispatchRemoveRuntimePanel, editQueryClause, editingWidgetsField, editorPreset, editorTheme, embedPreviewDecorations, expandRuntimePanel, extractBlockQueries, extractMetricsByCategory, fenceCompletion, findQueryBlockSection, findWorkoutErrors, forceSectionParse, formatClockTime, formatMMSS, formatTimestamp, frontmatterDetailed, frontmatterPreview, frontmatterPreviewField, frontmatterReferenceIndex, frontmatterSource, frontmatterSuggestions, frontmatterVisibility, getClauseMeta, getCursorFocusState, getOverlayActions, getSuggestionBinding, gutterHighlightsField, gutterUnified, handleFenceAutoWrap, hashCode, inlineButtonDecoration, invalidateSuggestions, lineIdsExtension, linkOpen, linkPreview, loadSuggestions, markdownSyntaxHiding, markdownTablePreview, matchFilterTypeahead, mergeSeries, mergeSuggestionItems, mergeTagSuggestions, navigationFacet, nestedCompletion, nestedCompletionOptions, normalizeOutputFilter, notebookSlugsFromBlocks, outputToRunResult, patchBlockQuery, presentBadges, previewDecorations, queryBlockPreview, readSessionRpe, referenceIndexReload, registeredSectionWidgets, removeRuntimePanel, resolveCodeLanguage, resolveQueryDraft, runtimePanelField, saveBlockQuerySource, sectionAtPos, sectionField, sectionGeometry, sectionIdentity, sectionIdentityHistory, sectionMove, sectionRestore, sectionSaved, sessionQueryInsert, sessionQueryWql, setFrontmatterDetailed, setFrontmatterSource, setGutterHighlights, setSuggestionBinding, smartIncrement, summarizeAggregate, summarizeFind, summarizePipeline, tagsFromStaticBlocks, toChartResult, toggleWidgetEdit, tooltipTimestamp, urlAtPos, useChartShape, useComposerSlots, useSuggestions, useVisualViewportRect, useWqlStageCounts, widgetBlockPreview, wodAutoWrap, wodAutocompletion, wodCompletionSource, wodEditorKeymap, wodLinter, wodOverlayPanel, workoutLintSource, wqlToPills, wrapInTimeFence };
13787
- //# sourceMappingURL=chunk-OD5VWDT7.mjs.map
13788
- //# sourceMappingURL=chunk-OD5VWDT7.mjs.map
14046
+ export { AGG_OPTIONS, CANONICAL_BLOCK_TYPES, CLAUSE_META, ComposerRegistry, DEFAULT_DIAGNOSTICS_DEBOUNCE_MS, DEFAULT_OUTPUT_FILTERS, DEFAULT_PRIMARY_FILTER, DefaultFrontmatterWidget, EditorDialog, GROUPBY_OPTIONS, GoalRings, INTERNAL_FRONTMATTER_KEYS, KIND_OPTIONS, METRIC_OPTIONS, MULTI_VALUE_TYPES, MetricBadge, OUTPUT_TYPE_CLASS, OUTPUT_TYPE_DOT, OutputFilterPills, OutputStatementsTable, PLANE_OPTIONS, ProposedMetricBadge, QueryBlockView, QueryValue, ROLLUP_OPTIONS, RowsResultsChrome, RowsTable, SERIES_COLORS, SOURCE_OPTIONS, SUGGESTION_BINDINGS, StackedBar, TARGET_OPTIONS, TIME_OPTIONS, TONE_CLASS, TokenSlotPill, TopList, UNIT_OPTIONS, WHERE_AGGREGATORS, WHERE_METRICS, WidgetChart, WidgetProblemBadge, WqlBars, WqlComposer, WqlDiagnosticsStrip, WqlEmptyState, WqlQueryInspectorModal, WqlTable, WqlTimeseries, ZoneDistribution, activeCursorSection, addRuntimePanel, autocompleteTooltipTheme, blockTypesFromBlocks, canonicalSuggestionItems, cn, compactNumber, composerRegistry, configureOverlayActions, createExecutorDocumentHost, cursorFocusExtension, customCompletionSources, dateRangeSlot, dispatchAddRuntimePanel, dispatchExpandRuntimePanel, dispatchGutterHighlights, dispatchRemoveRuntimePanel, editQueryClause, editingWidgetsField, editorPreset, editorTheme, embedPreviewDecorations, expandRuntimePanel, extractBlockQueries, extractMetricsByCategory, fenceCompletion, findQueryBlockSection, findWorkoutErrors, forceSectionParse, formatClockTime, formatMMSS, formatTimestamp, frontmatterDebugMode, frontmatterDetailed, frontmatterKeymap, frontmatterPreview, frontmatterPreviewField, frontmatterReferenceIndex, frontmatterSource, frontmatterSuggestions, frontmatterVisibility, getClauseMeta, getCursorFocusState, getOverlayActions, getSuggestionBinding, gutterHighlightsField, gutterUnified, handleFenceAutoWrap, hashCode, inlineButtonDecoration, invalidateSuggestions, isInternalFrontmatterKey, lineIdsExtension, linkOpen, linkPreview, loadSuggestions, markdownSyntaxHiding, markdownTablePreview, matchFilterTypeahead, mergeSeries, mergeSuggestionItems, mergeTagSuggestions, navigationFacet, nestedCompletion, nestedCompletionOptions, normalizeOutputFilter, notebookSlugsFromBlocks, outputToRunResult, patchBlockQuery, presentBadges, previewDecorations, queryBlockPreview, readSessionRpe, referenceIndexReload, registeredSectionWidgets, removeRuntimePanel, resolveCodeLanguage, resolveQueryDraft, runtimePanelField, saveBlockQuerySource, sectionAtPos, sectionField, sectionGeometry, sectionIdentity, sectionIdentityHistory, sectionMove, sectionRestore, sectionSaved, sessionQueryInsert, sessionQueryWql, setFrontmatterDetailed, setFrontmatterSource, setGutterHighlights, setSuggestionBinding, smartIncrement, summarizeAggregate, summarizeFind, summarizePipeline, tagsFromStaticBlocks, toChartResult, toggleWidgetEdit, tooltipTimestamp, urlAtPos, useChartShape, useComposerSlots, useSuggestions, useVisualViewportRect, useWqlStageCounts, widgetBlockPreview, wodAutoWrap, wodAutocompletion, wodCompletionSource, wodEditorKeymap, wodLinter, wodOverlayPanel, workoutLintSource, wqlToPills, wrapInTimeFence };
14047
+ //# sourceMappingURL=chunk-7PGNDGU7.mjs.map
14048
+ //# sourceMappingURL=chunk-7PGNDGU7.mjs.map